blob: 0e198adeb6cb8b3ef3c7a8989b5cb90c86411308 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08002 * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_cfg80211.c
30 *
31 * WLAN Host Device Driver cfg80211 APIs implementation
32 *
33 */
34
Jeff Johnson9c50e782016-06-29 15:28:56 -070035/* denote that this file does not allow legacy hddLog */
36#define HDD_DISALLOW_LEGACY_HDDLOG 1
37
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080038#include <linux/version.h>
39#include <linux/module.h>
40#include <linux/kernel.h>
41#include <linux/init.h>
42#include <linux/etherdevice.h>
43#include <linux/wireless.h>
44#include <wlan_hdd_includes.h>
45#include <net/arp.h>
46#include <net/cfg80211.h>
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053047#include <qdf_trace.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080048#include <wlan_hdd_wowl.h>
49#include <ani_global.h>
50#include "sir_params.h"
51#include "dot11f.h"
52#include "wlan_hdd_assoc.h"
53#include "wlan_hdd_wext.h"
54#include "sme_api.h"
Peng Xu278d0122015-09-24 16:34:17 -070055#include "sme_power_save_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080056#include "wlan_hdd_p2p.h"
57#include "wlan_hdd_cfg80211.h"
58#include "wlan_hdd_hostapd.h"
59#include "wlan_hdd_softap_tx_rx.h"
60#include "wlan_hdd_main.h"
61#include "wlan_hdd_power.h"
62#include "wlan_hdd_trace.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053063#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053064#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080065#include "cds_utils.h"
66#include "cds_sched.h"
67#include "wlan_hdd_scan.h"
68#include <qc_sap_ioctl.h>
69#include "wlan_hdd_tdls.h"
70#include "wlan_hdd_wmm.h"
71#include "wma_types.h"
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053072#include "wma.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080073#include "wlan_hdd_misc.h"
74#include "wlan_hdd_nan.h"
75#include <wlan_hdd_ipa.h>
76#include "wlan_logging_sock_svc.h"
Agrawal Ashish65634612016-08-18 13:24:32 +053077#include "sap_api.h"
Agrawal Ashish21ba2572016-09-03 16:40:10 +053078#include "csr_api.h"
Agrawal Ashish467dde42016-09-08 18:44:22 +053079#include "pld_common.h"
Agrawal Ashish65634612016-08-18 13:24:32 +053080
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081
82#ifdef FEATURE_WLAN_EXTSCAN
83#include "wlan_hdd_ext_scan.h"
84#endif
85
86#ifdef WLAN_FEATURE_LINK_LAYER_STATS
87#include "wlan_hdd_stats.h"
88#endif
89#include "cds_concurrency.h"
90#include "qwlan_version.h"
91#include "wlan_hdd_memdump.h"
92
93#include "wlan_hdd_ocb.h"
Manikandan Mohan5356c2b2016-04-03 15:51:35 -070094#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095
Ravi Joshideb5a8d2015-11-09 19:11:43 -080096#include "wlan_hdd_subnet_detect.h"
Abhishek Singh3e6172f2016-05-04 16:56:48 +053097#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070098#include "wlan_hdd_lpass.h"
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070099#include "wlan_hdd_nan_datapath.h"
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530100#include "wlan_hdd_disa.h"
Ravi Joshideb5a8d2015-11-09 19:11:43 -0800101
Leo Changfdb45c32016-10-28 11:09:23 -0700102#include <cdp_txrx_cmn.h>
103#include <cdp_txrx_misc.h>
104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800105#define g_mode_rates_size (12)
106#define a_mode_rates_size (8)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800107#define GET_IE_LEN_IN_BSS_DESC(lenInBss) (lenInBss + sizeof(lenInBss) - \
108 ((uintptr_t)OFFSET_OF(tSirBssDescription, ieFields)))
109
110/*
111 * Android CTS verifier needs atleast this much wait time (in msec)
112 */
113#define MAX_REMAIN_ON_CHANNEL_DURATION (5000)
114
115/*
116 * Refer @tCfgProtection structure for definition of the bit map.
117 * below value is obtained by setting the following bit-fields.
118 * enable obss, fromllb, overlapOBSS and overlapFromllb protection.
119 */
120#define IBSS_CFG_PROTECTION_ENABLE_MASK 0x8282
121
122#define HDD2GHZCHAN(freq, chan, flag) { \
Dustin Browna30892e2016-10-12 17:28:36 -0700123 .band = NL80211_BAND_2GHZ, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800124 .center_freq = (freq), \
125 .hw_value = (chan), \
126 .flags = (flag), \
127 .max_antenna_gain = 0, \
128 .max_power = 30, \
129}
130
131#define HDD5GHZCHAN(freq, chan, flag) { \
Dustin Browna30892e2016-10-12 17:28:36 -0700132 .band = NL80211_BAND_5GHZ, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800133 .center_freq = (freq), \
134 .hw_value = (chan), \
135 .flags = (flag), \
136 .max_antenna_gain = 0, \
137 .max_power = 30, \
138}
139
140#define HDD_G_MODE_RATETAB(rate, rate_id, flag) \
141 { \
142 .bitrate = rate, \
143 .hw_value = rate_id, \
144 .flags = flag, \
145 }
146
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800147#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
148#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800149
150#define HDD_CHANNEL_14 14
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800151
Agrawal Ashish65634612016-08-18 13:24:32 +0530152#define IS_DFS_MODE_VALID(mode) ((mode >= DFS_MODE_NONE && \
153 mode <= DFS_MODE_DEPRIORITIZE))
154#define IS_CHANNEL_VALID(channel) ((channel >= 0 && channel < 15) \
155 || (channel >= 36 && channel <= 184))
156
Peng Xu4d67c8f2015-10-16 16:02:26 -0700157#define MAX_TXPOWER_SCALE 4
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +0530158#define CDS_MAX_FEATURE_SET 8
Peng Xu4d67c8f2015-10-16 16:02:26 -0700159
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800160static const u32 hdd_cipher_suites[] = {
161 WLAN_CIPHER_SUITE_WEP40,
162 WLAN_CIPHER_SUITE_WEP104,
163 WLAN_CIPHER_SUITE_TKIP,
164#ifdef FEATURE_WLAN_ESE
165#define WLAN_CIPHER_SUITE_BTK 0x004096fe /* use for BTK */
166#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
167 WLAN_CIPHER_SUITE_BTK,
168 WLAN_CIPHER_SUITE_KRK,
169 WLAN_CIPHER_SUITE_CCMP,
170#else
171 WLAN_CIPHER_SUITE_CCMP,
172#endif
173#ifdef FEATURE_WLAN_WAPI
174 WLAN_CIPHER_SUITE_SMS4,
175#endif
176#ifdef WLAN_FEATURE_11W
177 WLAN_CIPHER_SUITE_AES_CMAC,
178#endif
179};
180
Abhishek Singhf512bf32016-05-04 16:47:46 +0530181static const struct ieee80211_channel hdd_channels_2_4_ghz[] = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182 HDD2GHZCHAN(2412, 1, 0),
183 HDD2GHZCHAN(2417, 2, 0),
184 HDD2GHZCHAN(2422, 3, 0),
185 HDD2GHZCHAN(2427, 4, 0),
186 HDD2GHZCHAN(2432, 5, 0),
187 HDD2GHZCHAN(2437, 6, 0),
188 HDD2GHZCHAN(2442, 7, 0),
189 HDD2GHZCHAN(2447, 8, 0),
190 HDD2GHZCHAN(2452, 9, 0),
191 HDD2GHZCHAN(2457, 10, 0),
192 HDD2GHZCHAN(2462, 11, 0),
193 HDD2GHZCHAN(2467, 12, 0),
194 HDD2GHZCHAN(2472, 13, 0),
195 HDD2GHZCHAN(2484, 14, 0),
196};
197
Abhishek Singhf512bf32016-05-04 16:47:46 +0530198static const struct ieee80211_channel hdd_channels_5_ghz[] = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800199 HDD5GHZCHAN(5180, 36, 0),
200 HDD5GHZCHAN(5200, 40, 0),
201 HDD5GHZCHAN(5220, 44, 0),
202 HDD5GHZCHAN(5240, 48, 0),
203 HDD5GHZCHAN(5260, 52, 0),
204 HDD5GHZCHAN(5280, 56, 0),
205 HDD5GHZCHAN(5300, 60, 0),
206 HDD5GHZCHAN(5320, 64, 0),
207 HDD5GHZCHAN(5500, 100, 0),
208 HDD5GHZCHAN(5520, 104, 0),
209 HDD5GHZCHAN(5540, 108, 0),
210 HDD5GHZCHAN(5560, 112, 0),
211 HDD5GHZCHAN(5580, 116, 0),
212 HDD5GHZCHAN(5600, 120, 0),
213 HDD5GHZCHAN(5620, 124, 0),
214 HDD5GHZCHAN(5640, 128, 0),
215 HDD5GHZCHAN(5660, 132, 0),
216 HDD5GHZCHAN(5680, 136, 0),
217 HDD5GHZCHAN(5700, 140, 0),
218 HDD5GHZCHAN(5720, 144, 0),
219 HDD5GHZCHAN(5745, 149, 0),
220 HDD5GHZCHAN(5765, 153, 0),
221 HDD5GHZCHAN(5785, 157, 0),
222 HDD5GHZCHAN(5805, 161, 0),
223 HDD5GHZCHAN(5825, 165, 0),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800224 HDD5GHZCHAN(5852, 170, 0),
225 HDD5GHZCHAN(5855, 171, 0),
226 HDD5GHZCHAN(5860, 172, 0),
227 HDD5GHZCHAN(5865, 173, 0),
228 HDD5GHZCHAN(5870, 174, 0),
229 HDD5GHZCHAN(5875, 175, 0),
230 HDD5GHZCHAN(5880, 176, 0),
231 HDD5GHZCHAN(5885, 177, 0),
232 HDD5GHZCHAN(5890, 178, 0),
233 HDD5GHZCHAN(5895, 179, 0),
234 HDD5GHZCHAN(5900, 180, 0),
235 HDD5GHZCHAN(5905, 181, 0),
236 HDD5GHZCHAN(5910, 182, 0),
237 HDD5GHZCHAN(5915, 183, 0),
238 HDD5GHZCHAN(5920, 184, 0),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800239};
240
241static struct ieee80211_rate g_mode_rates[] = {
242 HDD_G_MODE_RATETAB(10, 0x1, 0),
243 HDD_G_MODE_RATETAB(20, 0x2, 0),
244 HDD_G_MODE_RATETAB(55, 0x4, 0),
245 HDD_G_MODE_RATETAB(110, 0x8, 0),
246 HDD_G_MODE_RATETAB(60, 0x10, 0),
247 HDD_G_MODE_RATETAB(90, 0x20, 0),
248 HDD_G_MODE_RATETAB(120, 0x40, 0),
249 HDD_G_MODE_RATETAB(180, 0x80, 0),
250 HDD_G_MODE_RATETAB(240, 0x100, 0),
251 HDD_G_MODE_RATETAB(360, 0x200, 0),
252 HDD_G_MODE_RATETAB(480, 0x400, 0),
253 HDD_G_MODE_RATETAB(540, 0x800, 0),
254};
255
256static struct ieee80211_rate a_mode_rates[] = {
257 HDD_G_MODE_RATETAB(60, 0x10, 0),
258 HDD_G_MODE_RATETAB(90, 0x20, 0),
259 HDD_G_MODE_RATETAB(120, 0x40, 0),
260 HDD_G_MODE_RATETAB(180, 0x80, 0),
261 HDD_G_MODE_RATETAB(240, 0x100, 0),
262 HDD_G_MODE_RATETAB(360, 0x200, 0),
263 HDD_G_MODE_RATETAB(480, 0x400, 0),
264 HDD_G_MODE_RATETAB(540, 0x800, 0),
265};
266
267static struct ieee80211_supported_band wlan_hdd_band_2_4_ghz = {
Abhishek Singhf512bf32016-05-04 16:47:46 +0530268 .channels = NULL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800269 .n_channels = ARRAY_SIZE(hdd_channels_2_4_ghz),
Dustin Browna30892e2016-10-12 17:28:36 -0700270 .band = NL80211_BAND_2GHZ,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800271 .bitrates = g_mode_rates,
272 .n_bitrates = g_mode_rates_size,
273 .ht_cap.ht_supported = 1,
274 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
275 | IEEE80211_HT_CAP_GRN_FLD
276 | IEEE80211_HT_CAP_DSSSCCK40
277 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
278 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
279 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
280 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
281 .ht_cap.mcs.rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
282 .ht_cap.mcs.rx_highest = cpu_to_le16(72),
283 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
284};
285
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800286static struct ieee80211_supported_band wlan_hdd_band_5_ghz = {
Abhishek Singhf512bf32016-05-04 16:47:46 +0530287 .channels = NULL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800288 .n_channels = ARRAY_SIZE(hdd_channels_5_ghz),
Dustin Browna30892e2016-10-12 17:28:36 -0700289 .band = NL80211_BAND_5GHZ,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800290 .bitrates = a_mode_rates,
291 .n_bitrates = a_mode_rates_size,
292 .ht_cap.ht_supported = 1,
293 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
294 | IEEE80211_HT_CAP_GRN_FLD
295 | IEEE80211_HT_CAP_DSSSCCK40
296 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
297 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
298 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
299 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
300 .ht_cap.mcs.rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
301 .ht_cap.mcs.rx_highest = cpu_to_le16(72),
302 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
303 .vht_cap.vht_supported = 1,
304};
305
306/* This structure contain information what kind of frame are expected in
307 TX/RX direction for each kind of interface */
308static const struct ieee80211_txrx_stypes
309 wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
310 [NL80211_IFTYPE_STATION] = {
311 .tx = 0xffff,
312 .rx = BIT(SIR_MAC_MGMT_ACTION) |
313 BIT(SIR_MAC_MGMT_PROBE_REQ),
314 },
315 [NL80211_IFTYPE_AP] = {
316 .tx = 0xffff,
317 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
318 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
319 BIT(SIR_MAC_MGMT_PROBE_REQ) |
320 BIT(SIR_MAC_MGMT_DISASSOC) |
321 BIT(SIR_MAC_MGMT_AUTH) |
322 BIT(SIR_MAC_MGMT_DEAUTH) |
323 BIT(SIR_MAC_MGMT_ACTION),
324 },
325 [NL80211_IFTYPE_ADHOC] = {
326 .tx = 0xffff,
327 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
328 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
329 BIT(SIR_MAC_MGMT_PROBE_REQ) |
330 BIT(SIR_MAC_MGMT_DISASSOC) |
331 BIT(SIR_MAC_MGMT_AUTH) |
332 BIT(SIR_MAC_MGMT_DEAUTH) |
333 BIT(SIR_MAC_MGMT_ACTION),
334 },
335 [NL80211_IFTYPE_P2P_CLIENT] = {
336 .tx = 0xffff,
337 .rx = BIT(SIR_MAC_MGMT_ACTION) |
338 BIT(SIR_MAC_MGMT_PROBE_REQ),
339 },
340 [NL80211_IFTYPE_P2P_GO] = {
341 /* This is also same as for SoftAP */
342 .tx = 0xffff,
343 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
344 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
345 BIT(SIR_MAC_MGMT_PROBE_REQ) |
346 BIT(SIR_MAC_MGMT_DISASSOC) |
347 BIT(SIR_MAC_MGMT_AUTH) |
348 BIT(SIR_MAC_MGMT_DEAUTH) |
349 BIT(SIR_MAC_MGMT_ACTION),
350 },
351};
352
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800353/* Interface limits and combinations registered by the driver */
354
355/* STA ( + STA ) combination */
356static const struct ieee80211_iface_limit
357 wlan_hdd_sta_iface_limit[] = {
358 {
359 .max = 3, /* p2p0 is a STA as well */
360 .types = BIT(NL80211_IFTYPE_STATION),
361 },
362};
363
364/* ADHOC (IBSS) limit */
365static const struct ieee80211_iface_limit
366 wlan_hdd_adhoc_iface_limit[] = {
367 {
368 .max = 1,
369 .types = BIT(NL80211_IFTYPE_STATION),
370 },
371 {
372 .max = 1,
373 .types = BIT(NL80211_IFTYPE_ADHOC),
374 },
375};
376
377/* AP ( + AP ) combination */
378static const struct ieee80211_iface_limit
379 wlan_hdd_ap_iface_limit[] = {
380 {
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530381 .max = (QDF_MAX_NO_OF_SAP_MODE + SAP_MAX_OBSS_STA_CNT),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800382 .types = BIT(NL80211_IFTYPE_AP),
383 },
384};
385
386/* P2P limit */
387static const struct ieee80211_iface_limit
388 wlan_hdd_p2p_iface_limit[] = {
389 {
390 .max = 1,
391 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
392 },
393 {
394 .max = 1,
395 .types = BIT(NL80211_IFTYPE_P2P_GO),
396 },
397};
398
399static const struct ieee80211_iface_limit
400 wlan_hdd_sta_ap_iface_limit[] = {
401 {
402 /* We need 1 extra STA interface for OBSS scan when SAP starts
403 * with HT40 in STA+SAP concurrency mode
404 */
405 .max = (1 + SAP_MAX_OBSS_STA_CNT),
406 .types = BIT(NL80211_IFTYPE_STATION),
407 },
408 {
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530409 .max = QDF_MAX_NO_OF_SAP_MODE,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800410 .types = BIT(NL80211_IFTYPE_AP),
411 },
412};
413
414/* STA + P2P combination */
415static const struct ieee80211_iface_limit
416 wlan_hdd_sta_p2p_iface_limit[] = {
417 {
418 /* One reserved for dedicated P2PDEV usage */
419 .max = 2,
420 .types = BIT(NL80211_IFTYPE_STATION)
421 },
422 {
423 /* Support for two identical (GO + GO or CLI + CLI)
424 * or dissimilar (GO + CLI) P2P interfaces
425 */
426 .max = 2,
427 .types = BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT),
428 },
429};
430
431/* STA + AP + P2PGO combination */
432static const struct ieee80211_iface_limit
433wlan_hdd_sta_ap_p2pgo_iface_limit[] = {
434 /* Support for AP+P2PGO interfaces */
435 {
436 .max = 2,
437 .types = BIT(NL80211_IFTYPE_STATION)
438 },
439 {
440 .max = 1,
441 .types = BIT(NL80211_IFTYPE_P2P_GO)
442 },
443 {
444 .max = 1,
445 .types = BIT(NL80211_IFTYPE_AP)
446 }
447};
448
449/* SAP + P2P combination */
450static const struct ieee80211_iface_limit
451wlan_hdd_sap_p2p_iface_limit[] = {
452 {
453 /* 1 dedicated for p2p0 which is a STA type */
454 .max = 1,
455 .types = BIT(NL80211_IFTYPE_STATION)
456 },
457 {
458 /* The p2p interface in SAP+P2P can be GO/CLI.
459 * The p2p connection can be formed on p2p0 or p2p-p2p0-x.
460 */
461 .max = 1,
462 .types = BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT)
463 },
464 {
465 /* SAP+GO to support only one SAP interface */
466 .max = 1,
467 .types = BIT(NL80211_IFTYPE_AP)
468 }
469};
470
471/* P2P + P2P combination */
472static const struct ieee80211_iface_limit
473wlan_hdd_p2p_p2p_iface_limit[] = {
474 {
475 /* 1 dedicated for p2p0 which is a STA type */
476 .max = 1,
477 .types = BIT(NL80211_IFTYPE_STATION)
478 },
479 {
480 /* The p2p interface in P2P+P2P can be GO/CLI.
481 * For P2P+P2P, the new interfaces are formed on p2p-p2p0-x.
482 */
483 .max = 2,
484 .types = BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT)
485 },
486};
487
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -0700488static const struct ieee80211_iface_limit
489 wlan_hdd_mon_iface_limit[] = {
490 {
491 .max = 3, /* Monitor interface */
492 .types = BIT(NL80211_IFTYPE_MONITOR),
493 },
494};
495
496static struct ieee80211_iface_combination
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 wlan_hdd_iface_combination[] = {
498 /* STA */
499 {
500 .limits = wlan_hdd_sta_iface_limit,
501 .num_different_channels = 2,
502 .max_interfaces = 3,
503 .n_limits = ARRAY_SIZE(wlan_hdd_sta_iface_limit),
504 },
505 /* ADHOC */
506 {
507 .limits = wlan_hdd_adhoc_iface_limit,
Krunal Soni2c68f232015-10-26 20:52:51 -0700508 .num_different_channels = 2,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800509 .max_interfaces = 2,
510 .n_limits = ARRAY_SIZE(wlan_hdd_adhoc_iface_limit),
511 },
512 /* AP */
513 {
514 .limits = wlan_hdd_ap_iface_limit,
515 .num_different_channels = 2,
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530516 .max_interfaces = (SAP_MAX_OBSS_STA_CNT + QDF_MAX_NO_OF_SAP_MODE),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800517 .n_limits = ARRAY_SIZE(wlan_hdd_ap_iface_limit),
518 },
519 /* P2P */
520 {
521 .limits = wlan_hdd_p2p_iface_limit,
522 .num_different_channels = 2,
523 .max_interfaces = 2,
524 .n_limits = ARRAY_SIZE(wlan_hdd_p2p_iface_limit),
525 },
526 /* STA + AP */
527 {
528 .limits = wlan_hdd_sta_ap_iface_limit,
529 .num_different_channels = 2,
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530530 .max_interfaces = (1 + SAP_MAX_OBSS_STA_CNT + QDF_MAX_NO_OF_SAP_MODE),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531 .n_limits = ARRAY_SIZE(wlan_hdd_sta_ap_iface_limit),
532 .beacon_int_infra_match = true,
533 },
534 /* STA + P2P */
535 {
536 .limits = wlan_hdd_sta_p2p_iface_limit,
537 .num_different_channels = 2,
538 /* one interface reserved for P2PDEV dedicated usage */
539 .max_interfaces = 4,
540 .n_limits = ARRAY_SIZE(wlan_hdd_sta_p2p_iface_limit),
541 .beacon_int_infra_match = true,
542 },
543 /* STA + P2P GO + SAP */
544 {
545 .limits = wlan_hdd_sta_ap_p2pgo_iface_limit,
546 /* we can allow 3 channels for three different persona
547 * but due to firmware limitation, allow max 2 concrnt channels.
548 */
549 .num_different_channels = 2,
550 /* one interface reserved for P2PDEV dedicated usage */
551 .max_interfaces = 4,
552 .n_limits = ARRAY_SIZE(wlan_hdd_sta_ap_p2pgo_iface_limit),
553 .beacon_int_infra_match = true,
554 },
555 /* SAP + P2P */
556 {
557 .limits = wlan_hdd_sap_p2p_iface_limit,
558 .num_different_channels = 2,
559 /* 1-p2p0 + 1-SAP + 1-P2P (on p2p0 or p2p-p2p0-x) */
560 .max_interfaces = 3,
561 .n_limits = ARRAY_SIZE(wlan_hdd_sap_p2p_iface_limit),
562 .beacon_int_infra_match = true,
563 },
564 /* P2P + P2P */
565 {
566 .limits = wlan_hdd_p2p_p2p_iface_limit,
567 .num_different_channels = 2,
568 /* 1-p2p0 + 2-P2P (on p2p-p2p0-x) */
569 .max_interfaces = 3,
570 .n_limits = ARRAY_SIZE(wlan_hdd_p2p_p2p_iface_limit),
571 .beacon_int_infra_match = true,
572 },
Arun Khandavallifae92942016-08-01 13:31:08 +0530573 /* Monitor */
574 {
575 .limits = wlan_hdd_mon_iface_limit,
576 .max_interfaces = 3,
577 .num_different_channels = 2,
578 .n_limits = ARRAY_SIZE(wlan_hdd_mon_iface_limit),
579 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800581
582static struct cfg80211_ops wlan_hdd_cfg80211_ops;
Arun Khandavalli2476ef52016-04-26 20:19:43 +0530583struct hdd_bpf_context bpf_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584
585#ifdef WLAN_NL80211_TESTMODE
586enum wlan_hdd_tm_attr {
587 WLAN_HDD_TM_ATTR_INVALID = 0,
588 WLAN_HDD_TM_ATTR_CMD = 1,
589 WLAN_HDD_TM_ATTR_DATA = 2,
590 WLAN_HDD_TM_ATTR_STREAM_ID = 3,
591 WLAN_HDD_TM_ATTR_TYPE = 4,
592 /* keep last */
593 WLAN_HDD_TM_ATTR_AFTER_LAST,
594 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
595};
596
597enum wlan_hdd_tm_cmd {
598 WLAN_HDD_TM_CMD_WLAN_FTM = 0,
599 WLAN_HDD_TM_CMD_WLAN_HB = 1,
600};
601
602#define WLAN_HDD_TM_DATA_MAX_LEN 5000
603
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +0530604enum wlan_hdd_vendor_ie_access_policy {
605 WLAN_HDD_VENDOR_IE_ACCESS_NONE = 0,
606 WLAN_HDD_VENDOR_IE_ACCESS_ALLOW_IF_LISTED,
607};
608
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800609static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] = {
610 [WLAN_HDD_TM_ATTR_CMD] = {.type = NLA_U32},
611 [WLAN_HDD_TM_ATTR_DATA] = {.type = NLA_BINARY,
612 .len = WLAN_HDD_TM_DATA_MAX_LEN},
613};
614#endif /* WLAN_NL80211_TESTMODE */
615
616#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
617static const struct wiphy_wowlan_support wowlan_support_cfg80211_init = {
618 .flags = WIPHY_WOWLAN_MAGIC_PKT,
619 .n_patterns = WOWL_MAX_PTRNS_ALLOWED,
620 .pattern_min_len = 1,
621 .pattern_max_len = WOWL_PTRN_MAX_SIZE,
622};
623#endif
624
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800625/**
Abhishek Singh1bdb1572015-10-16 16:24:19 +0530626 * hdd_add_channel_switch_support()- Adds Channel Switch flag if supported
627 * @flags: Pointer to the flags to Add channel switch flag.
628 *
629 * This Function adds Channel Switch support flag, if channel switch is
630 * supported by kernel.
631 * Return: void.
632 */
633#ifdef CHANNEL_SWITCH_SUPPORTED
634static inline void hdd_add_channel_switch_support(uint32_t *flags)
635{
Krishna Kumaar Natarajan8a8df262015-12-04 11:43:46 -0800636 *flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Abhishek Singh1bdb1572015-10-16 16:24:19 +0530637 return;
638}
639#else
640static inline void hdd_add_channel_switch_support(uint32_t *flags)
641{
642 return;
643}
644#endif
645
Manikandan Mohan22b83722015-12-15 15:03:23 -0800646#ifdef FEATURE_WLAN_TDLS
647
648/* TDLS capabilities params */
649#define PARAM_MAX_TDLS_SESSION \
650 QCA_WLAN_VENDOR_ATTR_TDLS_GET_CAPS_MAX_CONC_SESSIONS
651#define PARAM_TDLS_FEATURE_SUPPORT \
652 QCA_WLAN_VENDOR_ATTR_TDLS_GET_CAPS_FEATURES_SUPPORTED
653
Abhishek Singh1bdb1572015-10-16 16:24:19 +0530654/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800655 * __wlan_hdd_cfg80211_get_tdls_capabilities() - Provide TDLS Capabilites.
656 * @wiphy: WIPHY structure pointer
657 * @wdev: Wireless device structure pointer
658 * @data: Pointer to the data received
659 * @data_len: Length of the data received
660 *
661 * This function provides TDLS capabilities
662 *
663 * Return: 0 on success and errno on failure
664 */
665static int __wlan_hdd_cfg80211_get_tdls_capabilities(struct wiphy *wiphy,
666 struct wireless_dev *wdev,
667 const void *data,
668 int data_len)
669{
670 int status;
671 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
672 struct sk_buff *skb;
673 uint32_t set = 0;
674
Jeff Johnson1f61b612016-02-12 16:28:33 -0800675 ENTER_DEV(wdev->netdev);
676
Anurag Chouhan6d760662016-02-20 16:05:43 +0530677 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800678 hdd_err("Command not allowed in FTM mode");
679 return -EPERM;
680 }
681
682 status = wlan_hdd_validate_context(hdd_ctx);
683 if (status)
684 return status;
685
686 skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, (2 * sizeof(u32)) +
687 NLMSG_HDRLEN);
688 if (!skb) {
Jeff Johnson020db452016-06-29 14:37:26 -0700689 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690 goto fail;
691 }
692
693 if (false == hdd_ctx->config->fEnableTDLSSupport) {
Jeff Johnson020db452016-06-29 14:37:26 -0700694 hdd_err("TDLS feature not Enabled or Not supported in FW");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695 if (nla_put_u32(skb, PARAM_MAX_TDLS_SESSION, 0) ||
696 nla_put_u32(skb, PARAM_TDLS_FEATURE_SUPPORT, 0)) {
Jeff Johnson020db452016-06-29 14:37:26 -0700697 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698 goto fail;
699 }
700 } else {
701 set = set | WIFI_TDLS_SUPPORT;
702 set = set | (hdd_ctx->config->fTDLSExternalControl ?
703 WIFI_TDLS_EXTERNAL_CONTROL_SUPPORT : 0);
704 set = set | (hdd_ctx->config->fEnableTDLSOffChannel ?
705 WIIF_TDLS_OFFCHANNEL_SUPPORT : 0);
Jeff Johnson020db452016-06-29 14:37:26 -0700706 hdd_notice("TDLS Feature supported value %x", set);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800707 if (nla_put_u32(skb, PARAM_MAX_TDLS_SESSION,
708 hdd_ctx->max_num_tdls_sta) ||
709 nla_put_u32(skb, PARAM_TDLS_FEATURE_SUPPORT,
710 set)) {
Jeff Johnson020db452016-06-29 14:37:26 -0700711 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800712 goto fail;
713 }
714 }
715 return cfg80211_vendor_cmd_reply(skb);
716fail:
717 if (skb)
718 kfree_skb(skb);
719 return -EINVAL;
720}
721
722/**
723 * wlan_hdd_cfg80211_get_tdls_capabilities() - Provide TDLS Capabilites.
724 * @wiphy: WIPHY structure pointer
725 * @wdev: Wireless device structure pointer
726 * @data: Pointer to the data received
727 * @data_len: Length of the data received
728 *
729 * This function provides TDLS capabilities
730 *
731 * Return: 0 on success and errno on failure
732 */
733static int
734wlan_hdd_cfg80211_get_tdls_capabilities(struct wiphy *wiphy,
735 struct wireless_dev *wdev,
736 const void *data,
737 int data_len)
738{
739 int ret;
740
741 cds_ssr_protect(__func__);
742 ret = __wlan_hdd_cfg80211_get_tdls_capabilities(wiphy, wdev,
743 data, data_len);
744 cds_ssr_unprotect(__func__);
745
746 return ret;
747}
748#endif
749
750#ifdef QCA_HT_2040_COEX
751static void wlan_hdd_cfg80211_start_pending_acs(struct work_struct *work);
752#endif
753
754#if defined(FEATURE_WLAN_CH_AVOID) || defined(FEATURE_WLAN_FORCE_SAP_SCC)
755/*
756 * FUNCTION: wlan_hdd_send_avoid_freq_event
757 * This is called when wlan driver needs to send vendor specific
758 * avoid frequency range event to userspace
759 */
760int wlan_hdd_send_avoid_freq_event(hdd_context_t *pHddCtx,
761 tHddAvoidFreqList *pAvoidFreqList)
762{
763 struct sk_buff *vendor_event;
764
765 ENTER();
766
767 if (!pHddCtx) {
Jeff Johnson020db452016-06-29 14:37:26 -0700768 hdd_err("HDD context is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 return -EINVAL;
770 }
771
772 if (!pAvoidFreqList) {
Jeff Johnson020db452016-06-29 14:37:26 -0700773 hdd_err("pAvoidFreqList is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 return -EINVAL;
775 }
776
777 vendor_event = cfg80211_vendor_event_alloc(pHddCtx->wiphy,
778 NULL,
779 sizeof(tHddAvoidFreqList),
780 QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX,
781 GFP_KERNEL);
782 if (!vendor_event) {
Jeff Johnson020db452016-06-29 14:37:26 -0700783 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784 return -EINVAL;
785 }
786
787 memcpy(skb_put(vendor_event, sizeof(tHddAvoidFreqList)),
788 (void *)pAvoidFreqList, sizeof(tHddAvoidFreqList));
789
790 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
791
792 EXIT();
793 return 0;
794}
795#endif /* FEATURE_WLAN_CH_AVOID || FEATURE_WLAN_FORCE_SAP_SCC */
796
797/* vendor specific events */
798static const struct nl80211_vendor_cmd_info wlan_hdd_cfg80211_vendor_events[] = {
799#ifdef FEATURE_WLAN_CH_AVOID
800 [QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX] = {
801 .vendor_id =
802 QCA_NL80211_VENDOR_ID,
803 .subcmd =
804 QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY
805 },
806#endif /* FEATURE_WLAN_CH_AVOID */
807
808#ifdef WLAN_FEATURE_NAN
809 [QCA_NL80211_VENDOR_SUBCMD_NAN_INDEX] = {
810 .vendor_id =
811 QCA_NL80211_VENDOR_ID,
812 .subcmd =
813 QCA_NL80211_VENDOR_SUBCMD_NAN
814 },
815#endif
816
817#ifdef WLAN_FEATURE_STATS_EXT
818 [QCA_NL80211_VENDOR_SUBCMD_STATS_EXT_INDEX] = {
819 .vendor_id =
820 QCA_NL80211_VENDOR_ID,
821 .subcmd =
822 QCA_NL80211_VENDOR_SUBCMD_STATS_EXT
823 },
824#endif /* WLAN_FEATURE_STATS_EXT */
825#ifdef FEATURE_WLAN_EXTSCAN
826 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_START_INDEX] = {
827 .vendor_id =
828 QCA_NL80211_VENDOR_ID,
829 .subcmd =
830 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_START
831 },
832 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_STOP_INDEX] = {
833 .vendor_id =
834 QCA_NL80211_VENDOR_ID,
835 .subcmd =
836 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_STOP
837 },
838 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CAPABILITIES_INDEX] = {
839 .
840 vendor_id
841 =
842 QCA_NL80211_VENDOR_ID,
843 .subcmd =
844 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CAPABILITIES
845 },
846 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CACHED_RESULTS_INDEX] = {
847 .
848 vendor_id
849 =
850 QCA_NL80211_VENDOR_ID,
851 .
852 subcmd =
853 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CACHED_RESULTS
854 },
855 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SCAN_RESULTS_AVAILABLE_INDEX] = {
856 .
857 vendor_id
858 =
859 QCA_NL80211_VENDOR_ID,
860 .
861 subcmd
862 =
863 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SCAN_RESULTS_AVAILABLE
864 },
865 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_FULL_SCAN_RESULT_INDEX] = {
866 .
867 vendor_id
868 =
869 QCA_NL80211_VENDOR_ID,
870 .subcmd =
871 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_FULL_SCAN_RESULT
872 },
873 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SCAN_EVENT_INDEX] = {
874 .vendor_id =
875 QCA_NL80211_VENDOR_ID,
876 .subcmd =
877 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SCAN_EVENT
878 },
879 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_AP_FOUND_INDEX] = {
880 .
881 vendor_id
882 =
883 QCA_NL80211_VENDOR_ID,
884 .subcmd =
885 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_AP_FOUND
886 },
887 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_BSSID_HOTLIST_INDEX] = {
888 .
889 vendor_id
890 =
891 QCA_NL80211_VENDOR_ID,
892 .subcmd =
893 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_BSSID_HOTLIST
894 },
895 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_BSSID_HOTLIST_INDEX] = {
896 .
897 vendor_id
898 =
899 QCA_NL80211_VENDOR_ID,
900 .
901 subcmd
902 =
903 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_BSSID_HOTLIST
904 },
905 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SIGNIFICANT_CHANGE_INDEX] = {
906 .
907 vendor_id
908 =
909 QCA_NL80211_VENDOR_ID,
910 .
911 subcmd =
912 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SIGNIFICANT_CHANGE
913 },
914 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SIGNIFICANT_CHANGE_INDEX] = {
915 .
916 vendor_id
917 =
918 QCA_NL80211_VENDOR_ID,
919 .
920 subcmd
921 =
922 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SIGNIFICANT_CHANGE
923 },
924 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SIGNIFICANT_CHANGE_INDEX] = {
925 .
926 vendor_id
927 =
928 QCA_NL80211_VENDOR_ID,
929 .
930 subcmd
931 =
932 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SIGNIFICANT_CHANGE
933 },
934 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_SSID_FOUND_INDEX] = {
935 .vendor_id = QCA_NL80211_VENDOR_ID,
936 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_SSID_FOUND
937 },
938 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_SSID_LOST_INDEX] = {
939 .vendor_id = QCA_NL80211_VENDOR_ID,
940 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_SSID_LOST
941 },
942#endif /* FEATURE_WLAN_EXTSCAN */
943
944#ifdef WLAN_FEATURE_LINK_LAYER_STATS
945 [QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET_INDEX] = {
946 .vendor_id =
947 QCA_NL80211_VENDOR_ID,
948 .subcmd =
949 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET
950 },
951 [QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET_INDEX] = {
952 .vendor_id =
953 QCA_NL80211_VENDOR_ID,
954 .subcmd =
955 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET
956 },
957 [QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR_INDEX] = {
958 .vendor_id =
959 QCA_NL80211_VENDOR_ID,
960 .subcmd =
961 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR
962 },
963 [QCA_NL80211_VENDOR_SUBCMD_LL_RADIO_STATS_INDEX] = {
964 .vendor_id =
965 QCA_NL80211_VENDOR_ID,
966 .subcmd =
967 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_RADIO_RESULTS
968 },
969 [QCA_NL80211_VENDOR_SUBCMD_LL_IFACE_STATS_INDEX] = {
970 .vendor_id =
971 QCA_NL80211_VENDOR_ID,
972 .subcmd =
973 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_IFACE_RESULTS
974 },
975 [QCA_NL80211_VENDOR_SUBCMD_LL_PEER_INFO_STATS_INDEX] = {
976 .vendor_id =
977 QCA_NL80211_VENDOR_ID,
978 .subcmd =
979 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_PEERS_RESULTS
980 },
981#endif /* WLAN_FEATURE_LINK_LAYER_STATS */
982 [QCA_NL80211_VENDOR_SUBCMD_TDLS_STATE_CHANGE_INDEX] = {
983 .vendor_id =
984 QCA_NL80211_VENDOR_ID,
985 .subcmd =
986 QCA_NL80211_VENDOR_SUBCMD_TDLS_STATE
987 },
988 [QCA_NL80211_VENDOR_SUBCMD_DO_ACS_INDEX] = {
989 .vendor_id = QCA_NL80211_VENDOR_ID,
990 .subcmd = QCA_NL80211_VENDOR_SUBCMD_DO_ACS
991 },
992#ifdef WLAN_FEATURE_ROAM_OFFLOAD
993 [QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_ROAM_AUTH_INDEX] = {
994 .vendor_id =
995 QCA_NL80211_VENDOR_ID,
996 .subcmd =
997 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_ROAM_AUTH
998 },
999#endif
1000 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_STARTED_INDEX] = {
1001 .vendor_id =
1002 QCA_NL80211_VENDOR_ID,
1003 .subcmd =
1004 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_STARTED
1005 },
1006 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_FINISHED_INDEX] = {
1007 .vendor_id =
1008 QCA_NL80211_VENDOR_ID,
1009 .subcmd =
1010 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_FINISHED
1011 },
1012 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_ABORTED_INDEX] = {
1013 .vendor_id =
1014 QCA_NL80211_VENDOR_ID,
1015 .subcmd =
1016 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_ABORTED
1017 },
1018 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_NOP_FINISHED_INDEX] = {
1019 .vendor_id =
1020 QCA_NL80211_VENDOR_ID,
1021 .subcmd =
1022 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_NOP_FINISHED
1023 },
1024 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_RADAR_DETECTED_INDEX] = {
1025 .vendor_id =
1026 QCA_NL80211_VENDOR_ID,
1027 .subcmd =
1028 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_RADAR_DETECTED
1029 },
1030#ifdef FEATURE_WLAN_EXTSCAN
1031 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_NETWORK_FOUND_INDEX] = {
1032 .vendor_id = QCA_NL80211_VENDOR_ID,
1033 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_NETWORK_FOUND
1034 },
1035 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_PASSPOINT_NETWORK_FOUND_INDEX] = {
1036 .vendor_id = QCA_NL80211_VENDOR_ID,
1037 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_PASSPOINT_NETWORK_FOUND
1038 },
1039 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SSID_HOTLIST_INDEX] = {
1040 .vendor_id = QCA_NL80211_VENDOR_ID,
1041 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SSID_HOTLIST
1042 },
1043 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SSID_HOTLIST_INDEX] = {
1044 .vendor_id = QCA_NL80211_VENDOR_ID,
1045 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SSID_HOTLIST
1046 },
1047 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_AP_LOST_INDEX] = {
1048 .vendor_id = QCA_NL80211_VENDOR_ID,
1049 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_AP_LOST
1050 },
1051#endif /* FEATURE_WLAN_EXTSCAN */
1052 [QCA_NL80211_VENDOR_SUBCMD_MONITOR_RSSI_INDEX] = {
1053 .vendor_id = QCA_NL80211_VENDOR_ID,
1054 .subcmd = QCA_NL80211_VENDOR_SUBCMD_MONITOR_RSSI
1055 },
1056#ifdef WLAN_FEATURE_MEMDUMP
1057 [QCA_NL80211_VENDOR_SUBCMD_WIFI_LOGGER_MEMORY_DUMP_INDEX] = {
1058 .vendor_id = QCA_NL80211_VENDOR_ID,
1059 .subcmd = QCA_NL80211_VENDOR_SUBCMD_WIFI_LOGGER_MEMORY_DUMP
1060 },
1061#endif /* WLAN_FEATURE_MEMDUMP */
Manikandan Mohan5356c2b2016-04-03 15:51:35 -07001062#ifdef WLAN_FEATURE_TSF
1063 [QCA_NL80211_VENDOR_SUBCMD_TSF_INDEX] = {
1064 .vendor_id = QCA_NL80211_VENDOR_ID,
1065 .subcmd = QCA_NL80211_VENDOR_SUBCMD_TSF
1066 },
1067#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068 [QCA_NL80211_VENDOR_SUBCMD_SCAN_DONE_INDEX] = {
1069 .vendor_id = QCA_NL80211_VENDOR_ID,
1070 .subcmd = QCA_NL80211_VENDOR_SUBCMD_SCAN_DONE
1071 },
1072 [QCA_NL80211_VENDOR_SUBCMD_SCAN_INDEX] = {
1073 .vendor_id = QCA_NL80211_VENDOR_ID,
1074 .subcmd = QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN
1075 },
1076 /* OCB events */
1077 [QCA_NL80211_VENDOR_SUBCMD_DCC_STATS_EVENT_INDEX] = {
1078 .vendor_id = QCA_NL80211_VENDOR_ID,
1079 .subcmd = QCA_NL80211_VENDOR_SUBCMD_DCC_STATS_EVENT
1080 },
Ravi Joshideb5a8d2015-11-09 19:11:43 -08001081#ifdef FEATURE_LFR_SUBNET_DETECTION
1082 [QCA_NL80211_VENDOR_SUBCMD_GW_PARAM_CONFIG_INDEX] = {
1083 .vendor_id = QCA_NL80211_VENDOR_ID,
1084 .subcmd = QCA_NL80211_VENDOR_SUBCMD_GW_PARAM_CONFIG
1085 },
1086#endif /*FEATURE_LFR_SUBNET_DETECTION */
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001087
1088#ifdef WLAN_FEATURE_NAN_DATAPATH
1089 [QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX] = {
1090 .vendor_id = QCA_NL80211_VENDOR_ID,
1091 .subcmd = QCA_NL80211_VENDOR_SUBCMD_NDP
1092 },
1093#endif /* WLAN_FEATURE_NAN_DATAPATH */
Peng Xu8fdaa492016-06-22 10:20:47 -07001094
1095 [QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX] = {
1096 .vendor_id = QCA_NL80211_VENDOR_ID,
1097 .subcmd = QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP
1098 },
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301099 [QCA_NL80211_VENDOR_SUBCMD_SAP_CONDITIONAL_CHAN_SWITCH_INDEX] = {
1100 .vendor_id = QCA_NL80211_VENDOR_ID,
1101 .subcmd = QCA_NL80211_VENDOR_SUBCMD_SAP_CONDITIONAL_CHAN_SWITCH
1102 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103};
1104
1105/**
1106 * __is_driver_dfs_capable() - get driver DFS capability
1107 * @wiphy: pointer to wireless wiphy structure.
1108 * @wdev: pointer to wireless_dev structure.
1109 * @data: Pointer to the data to be passed via vendor interface
1110 * @data_len:Length of the data to be passed
1111 *
1112 * This function is called by userspace to indicate whether or not
1113 * the driver supports DFS offload.
1114 *
1115 * Return: 0 on success, negative errno on failure
1116 */
1117static int __is_driver_dfs_capable(struct wiphy *wiphy,
1118 struct wireless_dev *wdev,
1119 const void *data,
1120 int data_len)
1121{
1122 u32 dfs_capability = 0;
1123 struct sk_buff *temp_skbuff;
1124 int ret_val;
1125 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1126
Jeff Johnson1f61b612016-02-12 16:28:33 -08001127 ENTER_DEV(wdev->netdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128
1129 ret_val = wlan_hdd_validate_context(hdd_ctx);
1130 if (ret_val)
1131 return ret_val;
1132
Anurag Chouhan6d760662016-02-20 16:05:43 +05301133 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001134 hdd_err("Command not allowed in FTM mode");
1135 return -EPERM;
1136 }
1137
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 dfs_capability = !!(wiphy->flags & WIPHY_FLAG_DFS_OFFLOAD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001139
1140 temp_skbuff = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(u32) +
1141 NLMSG_HDRLEN);
1142
1143 if (temp_skbuff != NULL) {
1144 ret_val = nla_put_u32(temp_skbuff, QCA_WLAN_VENDOR_ATTR_DFS,
1145 dfs_capability);
1146 if (ret_val) {
Jeff Johnson020db452016-06-29 14:37:26 -07001147 hdd_err("QCA_WLAN_VENDOR_ATTR_DFS put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148 kfree_skb(temp_skbuff);
1149
1150 return ret_val;
1151 }
1152
1153 return cfg80211_vendor_cmd_reply(temp_skbuff);
1154 }
1155
Jeff Johnson020db452016-06-29 14:37:26 -07001156 hdd_err("dfs capability: buffer alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157 return -ENOMEM;
1158}
1159
1160/**
1161 * is_driver_dfs_capable() - get driver DFS capability
1162 * @wiphy: pointer to wireless wiphy structure.
1163 * @wdev: pointer to wireless_dev structure.
1164 * @data: Pointer to the data to be passed via vendor interface
1165 * @data_len:Length of the data to be passed
1166 *
1167 * This function is called by userspace to indicate whether or not
1168 * the driver supports DFS offload. This is an SSR-protected
1169 * wrapper function.
1170 *
1171 * Return: 0 on success, negative errno on failure
1172 */
1173static int is_driver_dfs_capable(struct wiphy *wiphy,
1174 struct wireless_dev *wdev,
1175 const void *data,
1176 int data_len)
1177{
1178 int ret;
1179
1180 cds_ssr_protect(__func__);
1181 ret = __is_driver_dfs_capable(wiphy, wdev, data, data_len);
1182 cds_ssr_unprotect(__func__);
1183
1184 return ret;
1185}
1186
1187/**
1188 * wlan_hdd_sap_cfg_dfs_override() - DFS MCC restriction check
1189 *
1190 * @adapter: SAP adapter pointer
1191 *
1192 * DFS in MCC is not supported for Multi bssid SAP mode due to single physical
1193 * radio. So in case of DFS MCC scenario override current SAP given config
1194 * to follow concurrent SAP DFS config
1195 *
1196 * Return: 0 - No DFS issue, 1 - Override done and negative error codes
1197 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001198int wlan_hdd_sap_cfg_dfs_override(hdd_adapter_t *adapter)
1199{
1200 hdd_adapter_t *con_sap_adapter;
1201 tsap_Config_t *sap_config, *con_sap_config;
1202 int con_ch;
1203
1204 /*
1205 * Check if AP+AP case, once primary AP chooses a DFS
1206 * channel secondary AP should always follow primary APs channel
1207 */
1208 if (!cds_concurrent_beaconing_sessions_running())
1209 return 0;
1210
1211 con_sap_adapter = hdd_get_con_sap_adapter(adapter, true);
1212 if (!con_sap_adapter)
1213 return 0;
1214
1215 sap_config = &adapter->sessionCtx.ap.sapConfig;
1216 con_sap_config = &con_sap_adapter->sessionCtx.ap.sapConfig;
1217 con_ch = con_sap_adapter->sessionCtx.ap.operatingChannel;
1218
1219 if (!CDS_IS_DFS_CH(con_ch))
1220 return 0;
1221
Jeff Johnson020db452016-06-29 14:37:26 -07001222 hdd_err("Only SCC AP-AP DFS Permitted (ch=%d, con_ch=%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223 sap_config->channel, con_ch);
Jeff Johnson020db452016-06-29 14:37:26 -07001224 hdd_notice("Overriding guest AP's channel");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001225 sap_config->channel = con_ch;
1226
1227 if (con_sap_config->acs_cfg.acs_mode == true) {
1228 if (con_ch != con_sap_config->acs_cfg.pri_ch &&
1229 con_ch != con_sap_config->acs_cfg.ht_sec_ch) {
Jeff Johnson020db452016-06-29 14:37:26 -07001230 hdd_err("Primary AP channel config error");
1231 hdd_err("Operating ch: %d ACS ch: %d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232 con_ch, con_sap_config->acs_cfg.pri_ch,
1233 con_sap_config->acs_cfg.ht_sec_ch);
1234 return -EINVAL;
1235 }
1236 /* Sec AP ACS info is overwritten with Pri AP due to DFS
1237 * MCC restriction. So free ch list allocated in do_acs
1238 * func for Sec AP and realloc for Pri AP ch list size
1239 */
1240 if (sap_config->acs_cfg.ch_list)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301241 qdf_mem_free(sap_config->acs_cfg.ch_list);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301243 qdf_mem_copy(&sap_config->acs_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244 &con_sap_config->acs_cfg,
1245 sizeof(struct sap_acs_cfg));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301246 sap_config->acs_cfg.ch_list = qdf_mem_malloc(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001247 sizeof(uint8_t) *
1248 con_sap_config->acs_cfg.ch_list_count);
1249 if (!sap_config->acs_cfg.ch_list) {
Jeff Johnson020db452016-06-29 14:37:26 -07001250 hdd_err("ACS config alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251 return -ENOMEM;
1252 }
1253
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301254 qdf_mem_copy(sap_config->acs_cfg.ch_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255 con_sap_config->acs_cfg.ch_list,
1256 con_sap_config->acs_cfg.ch_list_count);
1257
1258 } else {
1259 sap_config->acs_cfg.pri_ch = con_ch;
1260 if (sap_config->acs_cfg.ch_width > eHT_CHANNEL_WIDTH_20MHZ)
1261 sap_config->acs_cfg.ht_sec_ch = con_sap_config->sec_ch;
1262 }
1263
1264 return con_ch;
1265}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001266
1267/**
1268 * wlan_hdd_set_acs_ch_range : Start ACS channel range values
1269 * @sap_cfg: pointer to SAP config struct
1270 *
1271 * This function sets the default ACS start and end channel for the given band
1272 * and also parses the given ACS channel list.
1273 *
1274 * Return: None
1275 */
1276
1277static void wlan_hdd_set_acs_ch_range(tsap_Config_t *sap_cfg, bool ht_enabled,
1278 bool vht_enabled)
1279{
1280 int i;
1281 if (sap_cfg->acs_cfg.hw_mode == QCA_ACS_MODE_IEEE80211B) {
1282 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11b;
Amar Singhalb8d4f152016-02-10 10:21:43 -08001283 sap_cfg->acs_cfg.start_ch = CDS_CHANNEL_NUM(CHAN_ENUM_1);
1284 sap_cfg->acs_cfg.end_ch = CDS_CHANNEL_NUM(CHAN_ENUM_14);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285 } else if (sap_cfg->acs_cfg.hw_mode == QCA_ACS_MODE_IEEE80211G) {
1286 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11g;
Amar Singhalb8d4f152016-02-10 10:21:43 -08001287 sap_cfg->acs_cfg.start_ch = CDS_CHANNEL_NUM(CHAN_ENUM_1);
1288 sap_cfg->acs_cfg.end_ch = CDS_CHANNEL_NUM(CHAN_ENUM_13);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001289 } else if (sap_cfg->acs_cfg.hw_mode == QCA_ACS_MODE_IEEE80211A) {
1290 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11a;
Amar Singhalb8d4f152016-02-10 10:21:43 -08001291 sap_cfg->acs_cfg.start_ch = CDS_CHANNEL_NUM(CHAN_ENUM_36);
1292 sap_cfg->acs_cfg.end_ch = CDS_CHANNEL_NUM(CHAN_ENUM_165);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001293 } else if (sap_cfg->acs_cfg.hw_mode == QCA_ACS_MODE_IEEE80211ANY) {
1294 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_abg;
Amar Singhalb8d4f152016-02-10 10:21:43 -08001295 sap_cfg->acs_cfg.start_ch = CDS_CHANNEL_NUM(CHAN_ENUM_1);
1296 sap_cfg->acs_cfg.end_ch = CDS_CHANNEL_NUM(CHAN_ENUM_165);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001297 }
1298
1299 if (ht_enabled)
1300 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11n;
1301
1302 if (vht_enabled)
1303 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11ac;
1304
1305
1306 /* Parse ACS Chan list from hostapd */
1307 if (!sap_cfg->acs_cfg.ch_list)
1308 return;
1309
1310 sap_cfg->acs_cfg.start_ch = sap_cfg->acs_cfg.ch_list[0];
1311 sap_cfg->acs_cfg.end_ch =
1312 sap_cfg->acs_cfg.ch_list[sap_cfg->acs_cfg.ch_list_count - 1];
1313 for (i = 0; i < sap_cfg->acs_cfg.ch_list_count; i++) {
Manjeet Singh2d3b0c52016-09-02 13:31:48 +05301314 /* avoid channel as start channel */
1315 if (sap_cfg->acs_cfg.start_ch > sap_cfg->acs_cfg.ch_list[i] &&
1316 sap_cfg->acs_cfg.ch_list[i] != 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001317 sap_cfg->acs_cfg.start_ch = sap_cfg->acs_cfg.ch_list[i];
1318 if (sap_cfg->acs_cfg.end_ch < sap_cfg->acs_cfg.ch_list[i])
1319 sap_cfg->acs_cfg.end_ch = sap_cfg->acs_cfg.ch_list[i];
1320 }
1321}
1322
1323
1324static void wlan_hdd_cfg80211_start_pending_acs(struct work_struct *work);
1325
1326/**
1327 * wlan_hdd_cfg80211_start_acs : Start ACS Procedure for SAP
1328 * @adapter: pointer to SAP adapter struct
1329 *
1330 * This function starts the ACS procedure if there are no
1331 * constraints like MBSSID DFS restrictions.
1332 *
1333 * Return: Status of ACS Start procedure
1334 */
1335
1336static int wlan_hdd_cfg80211_start_acs(hdd_adapter_t *adapter)
1337{
1338
1339 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1340 tsap_Config_t *sap_config;
1341 tpWLAN_SAPEventCB acs_event_callback;
1342 int status;
1343
1344 sap_config = &adapter->sessionCtx.ap.sapConfig;
Agrawal Ashish65634612016-08-18 13:24:32 +05301345 if (hdd_ctx->acs_policy.acs_channel)
1346 sap_config->channel = hdd_ctx->acs_policy.acs_channel;
1347 else
1348 sap_config->channel = AUTO_CHANNEL_SELECT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001349
1350 status = wlan_hdd_sap_cfg_dfs_override(adapter);
1351 if (status < 0) {
1352 return status;
1353 } else {
1354 if (status > 0) {
1355 /*notify hostapd about channel override */
1356 wlan_hdd_cfg80211_acs_ch_select_evt(adapter);
1357 clear_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags);
1358 return 0;
1359 }
1360 }
1361 status = wlan_hdd_config_acs(hdd_ctx, adapter);
1362 if (status) {
Jeff Johnson020db452016-06-29 14:37:26 -07001363 hdd_err("ACS config failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364 return -EINVAL;
1365 }
1366
1367 acs_event_callback = hdd_hostapd_sap_event_cb;
1368
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301369 qdf_mem_copy(sap_config->self_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301370 adapter->macAddressCurrent.bytes, sizeof(struct qdf_mac_addr));
Jeff Johnson020db452016-06-29 14:37:26 -07001371 hdd_notice("ACS Started for wlan%d", adapter->dev->ifindex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001372 status = wlansap_acs_chselect(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 acs_event_callback, sap_config, adapter->dev);
1375
1376
1377 if (status) {
Jeff Johnson020db452016-06-29 14:37:26 -07001378 hdd_err("ACS channel select failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379 return -EINVAL;
1380 }
1381 sap_config->acs_cfg.acs_mode = true;
1382 set_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags);
1383
1384 return 0;
1385}
1386
1387/**
1388 * __wlan_hdd_cfg80211_do_acs : CFG80211 handler function for DO_ACS Vendor CMD
1389 * @wiphy: Linux wiphy struct pointer
1390 * @wdev: Linux wireless device struct pointer
1391 * @data: ACS information from hostapd
1392 * @data_len: ACS information length
1393 *
1394 * This function handle DO_ACS Vendor command from hostapd, parses ACS config
1395 * and starts ACS procedure.
1396 *
1397 * Return: ACS procedure start status
1398 */
1399
1400static int __wlan_hdd_cfg80211_do_acs(struct wiphy *wiphy,
1401 struct wireless_dev *wdev,
1402 const void *data, int data_len)
1403{
1404 struct net_device *ndev = wdev->netdev;
1405 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
1406 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1407 tsap_Config_t *sap_config;
1408 struct sk_buff *temp_skbuff;
1409 int status = -EINVAL, i = 0;
1410 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ACS_MAX + 1];
1411 bool ht_enabled, ht40_enabled, vht_enabled;
1412 uint8_t ch_width;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05301413 uint8_t weight_list[QDF_MAX_NUM_CHAN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414
1415 /* ***Note*** Donot set SME config related to ACS operation here because
1416 * ACS operation is not synchronouse and ACS for Second AP may come when
1417 * ACS operation for first AP is going on. So only do_acs is split to
1418 * seperate start_acs routine. Also SME-PMAC struct that is used to
1419 * pass paremeters from HDD to SAP is global. Thus All ACS related SME
1420 * config shall be set only from start_acs.
1421 */
1422
1423 /* nla_policy Policy template. Policy not applied as some attributes are
1424 * optional and QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST has variable length
1425 *
1426 * [QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE] = { .type = NLA_U8 },
1427 * [QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED] = { .type = NLA_FLAG },
1428 * [QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED] = { .type = NLA_FLAG },
1429 * [QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED] = { .type = NLA_FLAG },
1430 * [QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH] = { .type = NLA_U16 },
1431 * [QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST] = { .type = NLA_NESTED },
1432 */
1433
Jeff Johnson1f61b612016-02-12 16:28:33 -08001434 ENTER_DEV(ndev);
1435
Anurag Chouhan6d760662016-02-20 16:05:43 +05301436 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437 hdd_err("Command not allowed in FTM mode");
1438 return -EPERM;
1439 }
1440
1441 if (hdd_ctx->config->force_sap_acs) {
Jeff Johnson020db452016-06-29 14:37:26 -07001442 hdd_err("Hostapd ACS rejected as Driver ACS enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001443 return -EPERM;
1444 }
1445
1446 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301447 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 goto out;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301449
Naveen Rawat64e477e2016-05-20 10:34:56 -07001450 if (cds_is_sub_20_mhz_enabled()) {
1451 hdd_err("ACS not supported in sub 20 MHz ch wd.");
1452 status = -EINVAL;
1453 goto out;
1454 }
1455
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 sap_config = &adapter->sessionCtx.ap.sapConfig;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301457 qdf_mem_zero(&sap_config->acs_cfg, sizeof(struct sap_acs_cfg));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458
1459 status = nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ACS_MAX, data, data_len,
1460 NULL);
1461 if (status) {
Jeff Johnson020db452016-06-29 14:37:26 -07001462 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001463 goto out;
1464 }
1465
1466 if (!tb[QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE]) {
Jeff Johnson020db452016-06-29 14:37:26 -07001467 hdd_err("Attr hw_mode failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 goto out;
1469 }
1470 sap_config->acs_cfg.hw_mode = nla_get_u8(
1471 tb[QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE]);
1472
1473 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED])
1474 ht_enabled =
1475 nla_get_flag(tb[QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED]);
1476 else
1477 ht_enabled = 0;
1478
1479 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED])
1480 ht40_enabled =
1481 nla_get_flag(tb[QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED]);
1482 else
1483 ht40_enabled = 0;
1484
1485 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED])
1486 vht_enabled =
1487 nla_get_flag(tb[QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED]);
1488 else
1489 vht_enabled = 0;
1490
Rajeev Kumar Sirasanagandlab79b5462016-09-06 18:33:17 +05301491 if (hdd_ctx->config->sap_force_11n_for_11ac) {
1492 vht_enabled = 0;
1493 hdd_log(LOG1, FL("VHT is Disabled in ACS"));
1494 }
1495
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH]) {
1497 ch_width = nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH]);
1498 } else {
1499 if (ht_enabled && ht40_enabled)
1500 ch_width = 40;
1501 else
1502 ch_width = 20;
1503 }
Rajeev Kumar Sirasanagandlab79b5462016-09-06 18:33:17 +05301504
1505 /* this may be possible, when sap_force_11n_for_11ac is set */
1506 if ((ch_width == 80 || ch_width == 160) && !vht_enabled) {
1507 if (ht_enabled && ht40_enabled)
1508 ch_width = 40;
1509 else
1510 ch_width = 20;
1511 }
1512
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001513 if (ch_width == 80)
1514 sap_config->acs_cfg.ch_width = CH_WIDTH_80MHZ;
1515 else if (ch_width == 40)
1516 sap_config->acs_cfg.ch_width = CH_WIDTH_40MHZ;
1517 else
1518 sap_config->acs_cfg.ch_width = CH_WIDTH_20MHZ;
1519
1520 /* hw_mode = a/b/g: QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST and
1521 * QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST attrs are present, and
1522 * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST is used for obtaining the
1523 * channel list, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST is ignored
1524 * since it contains the frequency values of the channels in
1525 * the channel list.
1526 * hw_mode = any: only QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST attr
1527 * is present
1528 */
1529 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST]) {
1530 char *tmp = nla_data(tb[QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST]);
1531 sap_config->acs_cfg.ch_list_count = nla_len(
1532 tb[QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST]);
1533 if (sap_config->acs_cfg.ch_list_count) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301534 sap_config->acs_cfg.ch_list = qdf_mem_malloc(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001535 sizeof(uint8_t) *
1536 sap_config->acs_cfg.ch_list_count);
1537 if (sap_config->acs_cfg.ch_list == NULL)
1538 goto out;
1539
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301540 qdf_mem_copy(sap_config->acs_cfg.ch_list, tmp,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001541 sap_config->acs_cfg.ch_list_count);
1542 }
1543 } else if (tb[QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST]) {
1544 uint32_t *freq =
1545 nla_data(tb[QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST]);
1546 sap_config->acs_cfg.ch_list_count = nla_len(
1547 tb[QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST]) /
1548 sizeof(uint32_t);
1549 if (sap_config->acs_cfg.ch_list_count) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301550 sap_config->acs_cfg.ch_list = qdf_mem_malloc(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001551 sap_config->acs_cfg.ch_list_count);
1552 if (sap_config->acs_cfg.ch_list == NULL) {
Jeff Johnson020db452016-06-29 14:37:26 -07001553 hdd_err("ACS config alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001554 status = -ENOMEM;
1555 goto out;
1556 }
1557
1558 /* convert frequency to channel */
1559 for (i = 0; i < sap_config->acs_cfg.ch_list_count; i++)
1560 sap_config->acs_cfg.ch_list[i] =
1561 ieee80211_frequency_to_channel(freq[i]);
1562 }
1563 }
1564
1565 hdd_debug("get pcl for DO_ACS vendor command");
1566
1567 /* consult policy manager to get PCL */
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08001568 status = cds_get_pcl(CDS_SAP_MODE,
Manishekar Chandrasekaran7009f252016-04-21 19:14:15 +05301569 sap_config->acs_cfg.pcl_channels,
1570 &sap_config->acs_cfg.pcl_ch_count,
1571 weight_list, QDF_ARRAY_SIZE(weight_list));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301572 if (QDF_STATUS_SUCCESS != status)
Jeff Johnson020db452016-06-29 14:37:26 -07001573 hdd_err("Get PCL failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001574
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575 /* ACS override for android */
Rajeev Kumar Sirasanagandlab79b5462016-09-06 18:33:17 +05301576 if (hdd_ctx->config->sap_p2p_11ac_override && ht_enabled &&
1577 !hdd_ctx->config->sap_force_11n_for_11ac) {
Jeff Johnson020db452016-06-29 14:37:26 -07001578 hdd_notice("ACS Config override for 11AC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579 vht_enabled = 1;
1580 sap_config->acs_cfg.hw_mode = eCSR_DOT11_MODE_11ac;
1581 sap_config->acs_cfg.ch_width =
1582 hdd_ctx->config->vhtChannelWidth;
1583 /* No VHT80 in 2.4G so perform ACS accordingly */
1584 if (sap_config->acs_cfg.end_ch <= 14 &&
1585 sap_config->acs_cfg.ch_width == eHT_CHANNEL_WIDTH_80MHZ)
1586 sap_config->acs_cfg.ch_width = eHT_CHANNEL_WIDTH_40MHZ;
1587 }
1588
Manishekar Chandrasekaran44e334f2016-05-30 16:42:50 +05301589 wlan_hdd_set_acs_ch_range(sap_config, ht_enabled, vht_enabled);
1590
Jeff Johnson020db452016-06-29 14:37:26 -07001591 hdd_notice("ACS Config for wlan%d: HW_MODE: %d ACS_BW: %d HT: %d VHT: %d START_CH: %d END_CH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001592 adapter->dev->ifindex, sap_config->acs_cfg.hw_mode,
1593 ch_width, ht_enabled, vht_enabled,
1594 sap_config->acs_cfg.start_ch, sap_config->acs_cfg.end_ch);
1595
1596 if (sap_config->acs_cfg.ch_list_count) {
Jeff Johnson020db452016-06-29 14:37:26 -07001597 hdd_notice("ACS channel list: len: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598 sap_config->acs_cfg.ch_list_count);
1599 for (i = 0; i < sap_config->acs_cfg.ch_list_count; i++)
Jeff Johnson020db452016-06-29 14:37:26 -07001600 hdd_notice("%d ", sap_config->acs_cfg.ch_list[i]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001601 }
1602 sap_config->acs_cfg.acs_mode = true;
1603 if (test_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001604 /* ***Note*** Completion variable usage is not allowed
1605 * here since ACS scan operation may take max 2.2 sec
1606 * for 5G band:
1607 * 9 Active channel X 40 ms active scan time +
1608 * 16 Passive channel X 110ms passive scan time
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001609 * Since this CFG80211 call lock rtnl mutex, we cannot hold on
1610 * for this long. So we split up the scanning part.
1611 */
1612 set_bit(ACS_PENDING, &adapter->event_flags);
Jeff Johnson020db452016-06-29 14:37:26 -07001613 hdd_notice("ACS Pending for wlan%d", adapter->dev->ifindex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 status = 0;
1615 } else {
1616 status = wlan_hdd_cfg80211_start_acs(adapter);
1617 }
1618
1619out:
1620 if (0 == status) {
1621 temp_skbuff = cfg80211_vendor_cmd_alloc_reply_skb(wiphy,
1622 NLMSG_HDRLEN);
1623 if (temp_skbuff != NULL)
1624 return cfg80211_vendor_cmd_reply(temp_skbuff);
1625 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04001626 wlan_hdd_undo_acs(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001627 clear_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags);
1628
1629 return status;
1630}
1631
1632 /**
1633 * wlan_hdd_cfg80211_do_acs : CFG80211 handler function for DO_ACS Vendor CMD
1634 * @wiphy: Linux wiphy struct pointer
1635 * @wdev: Linux wireless device struct pointer
1636 * @data: ACS information from hostapd
1637 * @data_len: ACS information len
1638 *
1639 * This function handle DO_ACS Vendor command from hostapd, parses ACS config
1640 * and starts ACS procedure.
1641 *
1642 * Return: ACS procedure start status
1643 */
1644
1645static int wlan_hdd_cfg80211_do_acs(struct wiphy *wiphy,
1646 struct wireless_dev *wdev,
1647 const void *data, int data_len)
1648{
1649 int ret;
1650
1651 cds_ssr_protect(__func__);
1652 ret = __wlan_hdd_cfg80211_do_acs(wiphy, wdev, data, data_len);
1653 cds_ssr_unprotect(__func__);
1654
1655 return ret;
1656}
1657
1658/**
Liangwei Dong8baf7c82016-10-11 01:26:59 -04001659 * wlan_hdd_undo_acs : Do cleanup of DO_ACS
1660 * @adapter: Pointer to adapter struct
1661 *
1662 * This function handle cleanup of what was done in DO_ACS, including free
1663 * memory.
1664 *
1665 * Return: void
1666 */
1667
1668void wlan_hdd_undo_acs(hdd_adapter_t *adapter)
1669{
1670 if (adapter == NULL)
1671 return;
1672 if (adapter->sessionCtx.ap.sapConfig.acs_cfg.ch_list) {
1673 qdf_mem_free(adapter->sessionCtx.ap.sapConfig.acs_cfg.ch_list);
1674 adapter->sessionCtx.ap.sapConfig.acs_cfg.ch_list = NULL;
1675 }
1676}
1677
1678/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679 * wlan_hdd_cfg80211_start_pending_acs : Start pending ACS procedure for SAP
1680 * @work: Linux workqueue struct pointer for ACS work
1681 *
1682 * This function starts the ACS procedure which was marked pending when an ACS
1683 * procedure was in progress for a concurrent SAP interface.
1684 *
1685 * Return: None
1686 */
1687
1688static void wlan_hdd_cfg80211_start_pending_acs(struct work_struct *work)
1689{
1690 hdd_adapter_t *adapter = container_of(work, hdd_adapter_t,
1691 acs_pending_work.work);
1692 wlan_hdd_cfg80211_start_acs(adapter);
1693}
1694
1695/**
1696 * wlan_hdd_cfg80211_acs_ch_select_evt: Callback function for ACS evt
1697 * @adapter: Pointer to SAP adapter struct
1698 * @pri_channel: SAP ACS procedure selected Primary channel
1699 * @sec_channel: SAP ACS procedure selected secondary channel
1700 *
1701 * This is a callback function from SAP module on ACS procedure is completed.
1702 * This function send the ACS selected channel information to hostapd
1703 *
1704 * Return: None
1705 */
1706
1707void wlan_hdd_cfg80211_acs_ch_select_evt(hdd_adapter_t *adapter)
1708{
1709 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1710 tsap_Config_t *sap_cfg = &(WLAN_HDD_GET_AP_CTX_PTR(adapter))->sapConfig;
1711 struct sk_buff *vendor_event;
1712 int ret_val;
1713 hdd_adapter_t *con_sap_adapter;
1714 uint16_t ch_width;
1715
1716 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Ryan Hsu9206a4e2016-01-19 17:23:13 -08001717 &(adapter->wdev),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718 4 * sizeof(u8) + 1 * sizeof(u16) + 4 + NLMSG_HDRLEN,
1719 QCA_NL80211_VENDOR_SUBCMD_DO_ACS_INDEX,
1720 GFP_KERNEL);
1721
1722 if (!vendor_event) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001723 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724 return;
1725 }
1726
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001727 ret_val = nla_put_u8(vendor_event,
1728 QCA_WLAN_VENDOR_ATTR_ACS_PRIMARY_CHANNEL,
1729 sap_cfg->acs_cfg.pri_ch);
1730 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001731 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_PRIMARY_CHANNEL put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 kfree_skb(vendor_event);
1733 return;
1734 }
1735
1736 ret_val = nla_put_u8(vendor_event,
1737 QCA_WLAN_VENDOR_ATTR_ACS_SECONDARY_CHANNEL,
1738 sap_cfg->acs_cfg.ht_sec_ch);
1739 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001740 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_SECONDARY_CHANNEL put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001741 kfree_skb(vendor_event);
1742 return;
1743 }
1744
1745 ret_val = nla_put_u8(vendor_event,
1746 QCA_WLAN_VENDOR_ATTR_ACS_VHT_SEG0_CENTER_CHANNEL,
1747 sap_cfg->acs_cfg.vht_seg0_center_ch);
1748 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001749 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_VHT_SEG0_CENTER_CHANNEL put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750 kfree_skb(vendor_event);
1751 return;
1752 }
1753
1754 ret_val = nla_put_u8(vendor_event,
1755 QCA_WLAN_VENDOR_ATTR_ACS_VHT_SEG1_CENTER_CHANNEL,
1756 sap_cfg->acs_cfg.vht_seg1_center_ch);
1757 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001758 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_VHT_SEG1_CENTER_CHANNEL put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001759 kfree_skb(vendor_event);
1760 return;
1761 }
1762
1763 if (sap_cfg->acs_cfg.ch_width == CH_WIDTH_80MHZ)
1764 ch_width = 80;
1765 else if (sap_cfg->acs_cfg.ch_width == CH_WIDTH_40MHZ)
1766 ch_width = 40;
1767 else
1768 ch_width = 20;
1769
1770 ret_val = nla_put_u16(vendor_event,
1771 QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
1772 ch_width);
1773 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001774 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001775 kfree_skb(vendor_event);
1776 return;
1777 }
1778 if (sap_cfg->acs_cfg.pri_ch > 14)
1779 ret_val = nla_put_u8(vendor_event,
1780 QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE,
1781 QCA_ACS_MODE_IEEE80211A);
1782 else
1783 ret_val = nla_put_u8(vendor_event,
1784 QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE,
1785 QCA_ACS_MODE_IEEE80211G);
1786
1787 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001788 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001789 kfree_skb(vendor_event);
1790 return;
1791 }
1792
Jeff Johnson46b40792016-06-29 14:03:14 -07001793 hdd_notice("ACS result for wlan%d: PRI_CH: %d SEC_CH: %d VHT_SEG0: %d VHT_SEG1: %d ACS_BW: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794 adapter->dev->ifindex, sap_cfg->acs_cfg.pri_ch,
1795 sap_cfg->acs_cfg.ht_sec_ch, sap_cfg->acs_cfg.vht_seg0_center_ch,
1796 sap_cfg->acs_cfg.vht_seg1_center_ch, ch_width);
1797
1798 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1799 /* ***Note*** As already mentioned Completion variable usage is not
1800 * allowed here since ACS scan operation may take max 2.2 sec.
1801 * Further in AP-AP mode pending ACS is resumed here to serailize ACS
1802 * operation.
1803 * TODO: Delayed operation is used since SME-PMAC strut is global. Thus
1804 * when Primary AP ACS is complete and secondary AP ACS is started here
1805 * immediately, Primary AP start_bss may come inbetween ACS operation
1806 * and overwrite Sec AP ACS paramters. Thus Sec AP ACS is executed with
1807 * delay. This path and below constraint will be removed on sessionizing
1808 * SAP acs parameters and decoupling SAP from PMAC (WIP).
1809 * As per design constraint user space control application must take
1810 * care of serailizing hostapd start for each VIF in AP-AP mode to avoid
1811 * this code path. Sec AP hostapd should be started after Primary AP
1812 * start beaconing which can be confirmed by getchannel iwpriv command
1813 */
1814
1815 con_sap_adapter = hdd_get_con_sap_adapter(adapter, false);
1816 if (con_sap_adapter &&
1817 test_bit(ACS_PENDING, &con_sap_adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001818 INIT_DELAYED_WORK(&con_sap_adapter->acs_pending_work,
1819 wlan_hdd_cfg80211_start_pending_acs);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001820 /* Lets give 500ms for OBSS + START_BSS to complete */
1821 schedule_delayed_work(&con_sap_adapter->acs_pending_work,
1822 msecs_to_jiffies(500));
1823 clear_bit(ACS_PENDING, &con_sap_adapter->event_flags);
1824 }
1825
1826 return;
1827}
1828
1829static int
1830__wlan_hdd_cfg80211_get_supported_features(struct wiphy *wiphy,
1831 struct wireless_dev *wdev,
1832 const void *data,
1833 int data_len)
1834{
1835 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
1836 struct sk_buff *skb = NULL;
1837 uint32_t fset = 0;
1838 int ret;
1839
Srinivas Girigowdadbfb2642016-08-28 21:32:38 -07001840 /* ENTER_DEV() intentionally not used in a frequently invoked API */
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301841
Anurag Chouhan6d760662016-02-20 16:05:43 +05301842 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843 hdd_err("Command not allowed in FTM mode");
1844 return -EPERM;
1845 }
1846
1847 ret = wlan_hdd_validate_context(pHddCtx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301848 if (ret)
1849 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850
1851 if (wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001852 hdd_notice("Infra Station mode is supported by driver");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001853 fset |= WIFI_FEATURE_INFRA;
1854 }
1855 if (true == hdd_is_5g_supported(pHddCtx)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001856 hdd_notice("INFRA_5G is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001857 fset |= WIFI_FEATURE_INFRA_5G;
1858 }
1859#ifdef WLAN_FEATURE_P2P
1860 if ((wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) &&
1861 (wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_GO))) {
Jeff Johnson020db452016-06-29 14:37:26 -07001862 hdd_notice("WiFi-Direct is supported by driver");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863 fset |= WIFI_FEATURE_P2P;
1864 }
1865#endif
1866 fset |= WIFI_FEATURE_SOFT_AP;
1867
1868 /* HOTSPOT is a supplicant feature, enable it by default */
1869 fset |= WIFI_FEATURE_HOTSPOT;
1870
1871#ifdef FEATURE_WLAN_EXTSCAN
Manjeet Singh0f2ce5c2016-09-01 12:08:57 +05301872 if (pHddCtx->config->extscan_enabled &&
1873 sme_is_feature_supported_by_fw(EXTENDED_SCAN)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001874 hdd_notice("EXTScan is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875 fset |= WIFI_FEATURE_EXTSCAN | WIFI_FEATURE_HAL_EPNO;
1876 }
1877#endif
1878 if (wlan_hdd_nan_is_supported()) {
Jeff Johnson020db452016-06-29 14:37:26 -07001879 hdd_notice("NAN is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001880 fset |= WIFI_FEATURE_NAN;
1881 }
1882 if (sme_is_feature_supported_by_fw(RTT)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001883 hdd_notice("RTT is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001884 fset |= WIFI_FEATURE_D2D_RTT;
1885 fset |= WIFI_FEATURE_D2AP_RTT;
1886 }
1887#ifdef FEATURE_WLAN_SCAN_PNO
1888 if (pHddCtx->config->configPNOScanSupport &&
1889 sme_is_feature_supported_by_fw(PNO)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001890 hdd_notice("PNO is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891 fset |= WIFI_FEATURE_PNO;
1892 }
1893#endif
1894 fset |= WIFI_FEATURE_ADDITIONAL_STA;
1895#ifdef FEATURE_WLAN_TDLS
1896 if ((true == pHddCtx->config->fEnableTDLSSupport) &&
1897 sme_is_feature_supported_by_fw(TDLS)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001898 hdd_notice("TDLS is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899 fset |= WIFI_FEATURE_TDLS;
1900 }
1901 if (sme_is_feature_supported_by_fw(TDLS) &&
1902 (true == pHddCtx->config->fEnableTDLSOffChannel) &&
1903 sme_is_feature_supported_by_fw(TDLS_OFF_CHANNEL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001904 hdd_notice("TDLS off-channel is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001905 fset |= WIFI_FEATURE_TDLS_OFFCHANNEL;
1906 }
1907#endif
1908#ifdef WLAN_AP_STA_CONCURRENCY
1909 fset |= WIFI_FEATURE_AP_STA;
1910#endif
1911 fset |= WIFI_FEATURE_RSSI_MONITOR;
Srinivas Girigowdaa2cad3e2016-10-25 14:14:23 -07001912 fset |= WIFI_FEATURE_TX_TRANSMIT_POWER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913
1914 if (hdd_link_layer_stats_supported())
1915 fset |= WIFI_FEATURE_LINK_LAYER_STATS;
1916
1917 skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(fset) +
1918 NLMSG_HDRLEN);
1919 if (!skb) {
Jeff Johnson020db452016-06-29 14:37:26 -07001920 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001921 return -EINVAL;
1922 }
Jeff Johnson020db452016-06-29 14:37:26 -07001923 hdd_notice("Supported Features : 0x%x", fset);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001924 if (nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_FEATURE_SET, fset)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001925 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001926 goto nla_put_failure;
1927 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301928 ret = cfg80211_vendor_cmd_reply(skb);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301929 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930nla_put_failure:
1931 kfree_skb(skb);
1932 return -EINVAL;
1933}
1934
1935/**
1936 * wlan_hdd_cfg80211_get_supported_features() - get supported features
1937 * @wiphy: pointer to wireless wiphy structure.
1938 * @wdev: pointer to wireless_dev structure.
1939 * @data: Pointer to the data to be passed via vendor interface
1940 * @data_len:Length of the data to be passed
1941 *
1942 * Return: Return the Success or Failure code.
1943 */
1944static int
1945wlan_hdd_cfg80211_get_supported_features(struct wiphy *wiphy,
1946 struct wireless_dev *wdev,
1947 const void *data, int data_len)
1948{
1949 int ret = 0;
1950
1951 cds_ssr_protect(__func__);
1952 ret = __wlan_hdd_cfg80211_get_supported_features(wiphy, wdev,
1953 data, data_len);
1954 cds_ssr_unprotect(__func__);
1955
1956 return ret;
1957}
1958
1959/**
1960 * __wlan_hdd_cfg80211_set_scanning_mac_oui() - set scan MAC
1961 * @wiphy: pointer to wireless wiphy structure.
1962 * @wdev: pointer to wireless_dev structure.
1963 * @data: Pointer to the data to be passed via vendor interface
1964 * @data_len:Length of the data to be passed
1965 *
1966 * Set the MAC address that is to be used for scanning.
1967 *
1968 * Return: Return the Success or Failure code.
1969 */
1970static int
1971__wlan_hdd_cfg80211_set_scanning_mac_oui(struct wiphy *wiphy,
1972 struct wireless_dev *wdev,
1973 const void *data,
1974 int data_len)
1975{
1976 tpSirScanMacOui pReqMsg = NULL;
1977 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
1978 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SET_SCANNING_MAC_OUI_MAX + 1];
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301979 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001980 int ret;
1981
Jeff Johnson1f61b612016-02-12 16:28:33 -08001982 ENTER_DEV(wdev->netdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001983
Anurag Chouhan6d760662016-02-20 16:05:43 +05301984 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001985 hdd_err("Command not allowed in FTM mode");
1986 return -EPERM;
1987 }
1988
1989 ret = wlan_hdd_validate_context(pHddCtx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301990 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001991 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001992
1993 if (false == pHddCtx->config->enable_mac_spoofing) {
Jeff Johnson020db452016-06-29 14:37:26 -07001994 hdd_warn("MAC address spoofing is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001995 return -ENOTSUPP;
1996 }
1997
1998 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SET_SCANNING_MAC_OUI_MAX,
1999 data, data_len, NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002000 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002001 return -EINVAL;
2002 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302003 pReqMsg = qdf_mem_malloc(sizeof(*pReqMsg));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002004 if (!pReqMsg) {
Jeff Johnson020db452016-06-29 14:37:26 -07002005 hdd_err("qdf_mem_malloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 return -ENOMEM;
2007 }
2008 if (!tb[QCA_WLAN_VENDOR_ATTR_SET_SCANNING_MAC_OUI]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002009 hdd_err("attr mac oui failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002010 goto fail;
2011 }
2012 nla_memcpy(&pReqMsg->oui[0],
2013 tb[QCA_WLAN_VENDOR_ATTR_SET_SCANNING_MAC_OUI],
2014 sizeof(pReqMsg->oui));
Jeff Johnson020db452016-06-29 14:37:26 -07002015 hdd_notice("Oui (%02x:%02x:%02x)", pReqMsg->oui[0],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002016 pReqMsg->oui[1], pReqMsg->oui[2]);
2017 status = sme_set_scanning_mac_oui(pHddCtx->hHal, pReqMsg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302018 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002019 hdd_err("sme_set_scanning_mac_oui failed(err=%d)", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020 goto fail;
2021 }
2022 return 0;
2023fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302024 qdf_mem_free(pReqMsg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 return -EINVAL;
2026}
2027
2028/**
2029 * wlan_hdd_cfg80211_set_scanning_mac_oui() - set scan MAC
2030 * @wiphy: pointer to wireless wiphy structure.
2031 * @wdev: pointer to wireless_dev structure.
2032 * @data: Pointer to the data to be passed via vendor interface
2033 * @data_len:Length of the data to be passed
2034 *
2035 * Set the MAC address that is to be used for scanning. This is an
2036 * SSR-protecting wrapper function.
2037 *
2038 * Return: Return the Success or Failure code.
2039 */
2040static int
2041wlan_hdd_cfg80211_set_scanning_mac_oui(struct wiphy *wiphy,
2042 struct wireless_dev *wdev,
2043 const void *data,
2044 int data_len)
2045{
2046 int ret;
2047
2048 cds_ssr_protect(__func__);
2049 ret = __wlan_hdd_cfg80211_set_scanning_mac_oui(wiphy, wdev,
2050 data, data_len);
2051 cds_ssr_unprotect(__func__);
2052
2053 return ret;
2054}
2055
2056/**
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302057 * __wlan_hdd_cfg80211_get_concurrency_matrix() - to retrieve concurrency matrix
2058 * @wiphy: pointer phy adapter
2059 * @wdev: pointer to wireless device structure
2060 * @data: pointer to data buffer
2061 * @data_len: length of data
2062 *
2063 * This routine will give concurrency matrix
2064 *
2065 * Return: int status code
2066 */
2067static int __wlan_hdd_cfg80211_get_concurrency_matrix(struct wiphy *wiphy,
2068 struct wireless_dev *wdev,
2069 const void *data,
2070 int data_len)
2071{
2072 uint32_t feature_set_matrix[CDS_MAX_FEATURE_SET] = {0};
2073 uint8_t i, feature_sets, max_feature_sets;
2074 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_MAX + 1];
2075 struct sk_buff *reply_skb;
2076 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
2077 int ret;
2078
2079 ENTER_DEV(wdev->netdev);
2080
2081 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2082 hdd_err("Command not allowed in FTM mode");
2083 return -EPERM;
2084 }
2085
2086 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302087 if (ret)
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302088 return ret;
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302089
2090 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_MAX,
2091 data, data_len, NULL)) {
2092 hdd_err("Invalid ATTR");
2093 return -EINVAL;
2094 }
2095
2096 /* Parse and fetch max feature set */
2097 if (!tb[QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_CONFIG_PARAM_SET_SIZE_MAX]) {
2098 hdd_err("Attr max feature set size failed");
2099 return -EINVAL;
2100 }
2101 max_feature_sets = nla_get_u32(tb[
2102 QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_CONFIG_PARAM_SET_SIZE_MAX]);
2103 hdd_info("Max feature set size: %d", max_feature_sets);
2104
2105 /* Fill feature combination matrix */
2106 feature_sets = 0;
2107 feature_set_matrix[feature_sets++] = WIFI_FEATURE_INFRA |
Srinivas Girigowdaca422922016-08-17 18:29:42 -07002108 WIFI_FEATURE_P2P;
2109 feature_set_matrix[feature_sets++] = WIFI_FEATURE_INFRA |
2110 WIFI_FEATURE_NAN;
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302111 /* Add more feature combinations here */
2112
2113 feature_sets = QDF_MIN(feature_sets, max_feature_sets);
Srinivas Girigowdaca422922016-08-17 18:29:42 -07002114 hdd_info("Number of feature sets: %d", feature_sets);
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302115 hdd_info("Feature set matrix");
2116 for (i = 0; i < feature_sets; i++)
2117 hdd_info("[%d] 0x%02X", i, feature_set_matrix[i]);
2118
2119 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(u32) +
2120 sizeof(u32) * feature_sets + NLMSG_HDRLEN);
2121 if (!reply_skb) {
2122 hdd_err("Feature set matrix: buffer alloc fail");
2123 return -ENOMEM;
2124 }
2125
2126 if (nla_put_u32(reply_skb,
2127 QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_RESULTS_SET_SIZE,
2128 feature_sets) ||
2129 nla_put(reply_skb,
2130 QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_RESULTS_SET,
2131 sizeof(u32) * feature_sets,
2132 feature_set_matrix)) {
2133 hdd_err("nla put fail");
2134 kfree_skb(reply_skb);
2135 return -EINVAL;
2136 }
2137 return cfg80211_vendor_cmd_reply(reply_skb);
2138}
2139
2140/**
2141 * wlan_hdd_cfg80211_get_concurrency_matrix() - get concurrency matrix
2142 * @wiphy: pointer to wireless wiphy structure.
2143 * @wdev: pointer to wireless_dev structure.
2144 * @data: Pointer to the data to be passed via vendor interface
2145 * @data_len:Length of the data to be passed
2146 *
2147 * Retrieves the concurrency feature set matrix
2148 *
2149 * Return: 0 on success, negative errno on failure
2150 */
2151static int
2152wlan_hdd_cfg80211_get_concurrency_matrix(struct wiphy *wiphy,
2153 struct wireless_dev *wdev,
2154 const void *data,
2155 int data_len)
2156{
2157 int ret;
2158
2159 cds_ssr_protect(__func__);
2160 ret = __wlan_hdd_cfg80211_get_concurrency_matrix(wiphy, wdev,
2161 data, data_len);
2162 cds_ssr_unprotect(__func__);
2163
2164 return ret;
2165}
2166
2167/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002168 * wlan_hdd_cfg80211_set_feature() - Set the bitmask for supported features
2169 * @feature_flags: pointer to the byte array of features.
2170 * @feature: Feature to be turned ON in the byte array.
2171 *
2172 * Return: None
2173 *
2174 * This is called to turn ON or SET the feature flag for the requested feature.
2175 **/
2176#define NUM_BITS_IN_BYTE 8
Jeff Johnson8b8a04b2016-10-05 15:49:43 -07002177static void wlan_hdd_cfg80211_set_feature(uint8_t *feature_flags,
2178 uint8_t feature)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002179{
2180 uint32_t index;
2181 uint8_t bit_mask;
2182
2183 index = feature / NUM_BITS_IN_BYTE;
2184 bit_mask = 1 << (feature % NUM_BITS_IN_BYTE);
2185 feature_flags[index] |= bit_mask;
2186}
2187
2188/**
2189 * __wlan_hdd_cfg80211_get_features() - Get the Driver Supported features
2190 * @wiphy: pointer to wireless wiphy structure.
2191 * @wdev: pointer to wireless_dev structure.
2192 * @data: Pointer to the data to be passed via vendor interface
2193 * @data_len:Length of the data to be passed
2194 *
2195 * This is called when wlan driver needs to send supported feature set to
2196 * supplicant upon a request/query from the supplicant.
2197 *
2198 * Return: Return the Success or Failure code.
2199 **/
2200#define MAX_CONCURRENT_CHAN_ON_24G 2
2201#define MAX_CONCURRENT_CHAN_ON_5G 2
2202static int
2203__wlan_hdd_cfg80211_get_features(struct wiphy *wiphy,
2204 struct wireless_dev *wdev,
2205 const void *data, int data_len)
2206{
2207 struct sk_buff *skb = NULL;
2208 uint32_t dbs_capability = 0;
2209 bool one_by_one_dbs, two_by_two_dbs;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302210 QDF_STATUS ret = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002211 int ret_val;
2212
2213 uint8_t feature_flags[(NUM_QCA_WLAN_VENDOR_FEATURES + 7) / 8] = {0};
2214 hdd_context_t *hdd_ctx_ptr = wiphy_priv(wiphy);
2215
Jeff Johnson1f61b612016-02-12 16:28:33 -08002216 ENTER_DEV(wdev->netdev);
2217
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002218 ret_val = wlan_hdd_validate_context(hdd_ctx_ptr);
2219 if (ret_val)
2220 return ret_val;
2221
Anurag Chouhan6d760662016-02-20 16:05:43 +05302222 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002223 hdd_err("Command not allowed in FTM mode");
2224 return -EPERM;
2225 }
2226
Varun Reddy Yeturud351a6c2016-03-16 14:01:00 -07002227 if (roaming_offload_enabled(hdd_ctx_ptr)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002228 hdd_notice("Key Mgmt Offload is supported");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002229 wlan_hdd_cfg80211_set_feature(feature_flags,
2230 QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD);
2231 }
2232
2233 wlan_hdd_cfg80211_set_feature(feature_flags,
2234 QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY);
2235 if (wma_is_scan_simultaneous_capable())
2236 wlan_hdd_cfg80211_set_feature(feature_flags,
2237 QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS);
Peng Xu8fdaa492016-06-22 10:20:47 -07002238
2239 if (wma_is_p2p_lo_capable())
2240 wlan_hdd_cfg80211_set_feature(feature_flags,
2241 QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD);
2242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002243 skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(feature_flags) +
2244 NLMSG_HDRLEN);
2245
2246 if (!skb) {
Jeff Johnson020db452016-06-29 14:37:26 -07002247 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002248 return -ENOMEM;
2249 }
2250
2251 if (nla_put(skb, QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS,
2252 sizeof(feature_flags), feature_flags))
2253 goto nla_put_failure;
2254
2255 ret = wma_get_dbs_hw_modes(&one_by_one_dbs, &two_by_two_dbs);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302256 if (QDF_STATUS_SUCCESS == ret) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002257 if (one_by_one_dbs)
2258 dbs_capability = DRV_DBS_CAPABILITY_1X1;
2259
2260 if (two_by_two_dbs)
2261 dbs_capability = DRV_DBS_CAPABILITY_2X2;
2262
2263 if (!one_by_one_dbs && !two_by_two_dbs)
2264 dbs_capability = DRV_DBS_CAPABILITY_DISABLED;
2265 } else {
2266 hdd_err("wma_get_dbs_hw_mode failed");
2267 dbs_capability = DRV_DBS_CAPABILITY_DISABLED;
2268 }
2269
2270 hdd_info("dbs_capability is %d", dbs_capability);
2271
2272 if (nla_put_u32(skb,
2273 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND,
2274 MAX_CONCURRENT_CHAN_ON_24G))
2275 goto nla_put_failure;
2276
2277 if (nla_put_u32(skb,
2278 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND,
2279 MAX_CONCURRENT_CHAN_ON_5G))
2280 goto nla_put_failure;
2281
2282 return cfg80211_vendor_cmd_reply(skb);
2283
2284nla_put_failure:
2285 kfree_skb(skb);
2286 return -EINVAL;
2287}
2288
2289/**
2290 * wlan_hdd_cfg80211_get_features() - Get the Driver Supported features
2291 * @wiphy: pointer to wireless wiphy structure.
2292 * @wdev: pointer to wireless_dev structure.
2293 * @data: Pointer to the data to be passed via vendor interface
2294 * @data_len:Length of the data to be passed
2295 *
2296 * This is called when wlan driver needs to send supported feature set to
2297 * supplicant upon a request/query from the supplicant.
2298 *
2299 * Return: Return the Success or Failure code.
2300 */
2301static int
2302wlan_hdd_cfg80211_get_features(struct wiphy *wiphy,
2303 struct wireless_dev *wdev,
2304 const void *data, int data_len)
2305{
2306 int ret;
2307
2308 cds_ssr_protect(__func__);
2309 ret = __wlan_hdd_cfg80211_get_features(wiphy, wdev,
2310 data, data_len);
2311 cds_ssr_unprotect(__func__);
2312
2313 return ret;
2314}
2315
2316
2317/**
2318 * __wlan_hdd_cfg80211_set_ext_roam_params() - Settings for roaming parameters
2319 * @wiphy: The wiphy structure
2320 * @wdev: The wireless device
2321 * @data: Data passed by framework
2322 * @data_len: Parameters to be configured passed as data
2323 *
2324 * The roaming related parameters are configured by the framework
2325 * using this interface.
2326 *
2327 * Return: Return either success or failure code.
2328 */
2329static int
2330__wlan_hdd_cfg80211_set_ext_roam_params(struct wiphy *wiphy,
2331 struct wireless_dev *wdev, const void *data, int data_len)
2332{
2333 struct net_device *dev = wdev->netdev;
2334 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2335 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2336 uint8_t session_id;
2337 struct roam_ext_params roam_params;
2338 uint32_t cmd_type, req_id;
2339 struct nlattr *curr_attr;
2340 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX + 1];
2341 struct nlattr *tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX + 1];
2342 int rem, i;
2343 uint32_t buf_len = 0;
2344 int ret;
2345
Jeff Johnson1f61b612016-02-12 16:28:33 -08002346 ENTER_DEV(dev);
2347
Anurag Chouhan6d760662016-02-20 16:05:43 +05302348 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002349 hdd_err("Command not allowed in FTM mode");
2350 return -EPERM;
2351 }
2352
2353 ret = wlan_hdd_validate_context(pHddCtx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302354 if (ret)
2355 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002356
2357 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX,
2358 data, data_len,
2359 NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002360 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002361 return -EINVAL;
2362 }
2363 /* Parse and fetch Command Type*/
2364 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002365 hdd_err("roam cmd type failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002366 goto fail;
2367 }
2368 session_id = pAdapter->sessionId;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302369 qdf_mem_set(&roam_params, sizeof(roam_params), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002370 cmd_type = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD]);
2371 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002372 hdd_err("attr request id failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002373 goto fail;
2374 }
2375 req_id = nla_get_u32(
2376 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID]);
Jeff Johnson020db452016-06-29 14:37:26 -07002377 hdd_debug("Req Id (%d)", req_id);
2378 hdd_debug("Cmd Type (%d)", cmd_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002379 switch (cmd_type) {
2380 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SSID_WHITE_LIST:
2381 i = 0;
2382 nla_for_each_nested(curr_attr,
2383 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID_LIST],
2384 rem) {
2385 if (nla_parse(tb2,
2386 QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_MAX,
2387 nla_data(curr_attr), nla_len(curr_attr),
2388 NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002389 hdd_err("nla_parse failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002390 goto fail;
2391 }
2392 /* Parse and Fetch allowed SSID list*/
2393 if (!tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002394 hdd_err("attr allowed ssid failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002395 goto fail;
2396 }
2397 buf_len = nla_len(tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID]);
2398 /*
2399 * Upper Layers include a null termination character.
2400 * Check for the actual permissible length of SSID and
2401 * also ensure not to copy the NULL termination
2402 * character to the driver buffer.
2403 */
2404 if (buf_len && (i < MAX_SSID_ALLOWED_LIST) &&
2405 ((buf_len - 1) <= SIR_MAC_MAX_SSID_LENGTH)) {
2406 nla_memcpy(
2407 roam_params.ssid_allowed_list[i].ssId,
2408 tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID],
2409 buf_len - 1);
2410 roam_params.ssid_allowed_list[i].length =
2411 buf_len - 1;
Jeff Johnson020db452016-06-29 14:37:26 -07002412 hdd_debug("SSID[%d]: %.*s,length = %d", i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002413 roam_params.ssid_allowed_list[i].length,
2414 roam_params.ssid_allowed_list[i].ssId,
2415 roam_params.ssid_allowed_list[i].length);
2416 i++;
2417 } else {
Jeff Johnson020db452016-06-29 14:37:26 -07002418 hdd_err("Invalid buffer length");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002419 }
2420 }
2421 roam_params.num_ssid_allowed_list = i;
Jeff Johnson020db452016-06-29 14:37:26 -07002422 hdd_debug("Num of Allowed SSID %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002423 roam_params.num_ssid_allowed_list);
2424 sme_update_roam_params(pHddCtx->hHal, session_id,
2425 roam_params, REASON_ROAM_SET_SSID_ALLOWED);
2426 break;
2427 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_EXTSCAN_ROAM_PARAMS:
2428 /* Parse and fetch 5G Boost Threshold */
2429 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_BOOST_THRESHOLD]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002430 hdd_err("5G boost threshold failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002431 goto fail;
2432 }
2433 roam_params.raise_rssi_thresh_5g = nla_get_s32(
2434 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_BOOST_THRESHOLD]);
Jeff Johnson020db452016-06-29 14:37:26 -07002435 hdd_debug("5G Boost Threshold (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002436 roam_params.raise_rssi_thresh_5g);
2437 /* Parse and fetch 5G Penalty Threshold */
2438 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_PENALTY_THRESHOLD]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002439 hdd_err("5G penalty threshold failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002440 goto fail;
2441 }
2442 roam_params.drop_rssi_thresh_5g = nla_get_s32(
2443 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_PENALTY_THRESHOLD]);
Jeff Johnson020db452016-06-29 14:37:26 -07002444 hdd_debug("5G Penalty Threshold (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002445 roam_params.drop_rssi_thresh_5g);
2446 /* Parse and fetch 5G Boost Factor */
2447 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_BOOST_FACTOR]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002448 hdd_err("5G boost Factor failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002449 goto fail;
2450 }
2451 roam_params.raise_factor_5g = nla_get_u32(
2452 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_BOOST_FACTOR]);
Jeff Johnson020db452016-06-29 14:37:26 -07002453 hdd_debug("5G Boost Factor (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002454 roam_params.raise_factor_5g);
2455 /* Parse and fetch 5G Penalty factor */
2456 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_PENALTY_FACTOR]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002457 hdd_err("5G Penalty Factor failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002458 goto fail;
2459 }
2460 roam_params.drop_factor_5g = nla_get_u32(
2461 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_PENALTY_FACTOR]);
Jeff Johnson020db452016-06-29 14:37:26 -07002462 hdd_debug("5G Penalty factor (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002463 roam_params.drop_factor_5g);
2464 /* Parse and fetch 5G Max Boost */
2465 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_MAX_BOOST]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002466 hdd_err("5G Max Boost failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002467 goto fail;
2468 }
2469 roam_params.max_raise_rssi_5g = nla_get_u32(
2470 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_MAX_BOOST]);
Jeff Johnson020db452016-06-29 14:37:26 -07002471 hdd_debug("5G Max Boost (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002472 roam_params.max_raise_rssi_5g);
2473 /* Parse and fetch Rssi Diff */
2474 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_LAZY_ROAM_HISTERESYS]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002475 hdd_err("Rssi Diff failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002476 goto fail;
2477 }
2478 roam_params.rssi_diff = nla_get_s32(
2479 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_LAZY_ROAM_HISTERESYS]);
Jeff Johnson020db452016-06-29 14:37:26 -07002480 hdd_debug("RSSI Diff (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002481 roam_params.rssi_diff);
2482 /* Parse and fetch Alert Rssi Threshold */
2483 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_ALERT_ROAM_RSSI_TRIGGER]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002484 hdd_err("Alert Rssi Threshold failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002485 goto fail;
2486 }
2487 roam_params.alert_rssi_threshold = nla_get_u32(
2488 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_ALERT_ROAM_RSSI_TRIGGER]);
Jeff Johnson020db452016-06-29 14:37:26 -07002489 hdd_debug("Alert RSSI Threshold (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002490 roam_params.alert_rssi_threshold);
2491 sme_update_roam_params(pHddCtx->hHal, session_id,
2492 roam_params,
2493 REASON_ROAM_EXT_SCAN_PARAMS_CHANGED);
2494 break;
2495 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_LAZY_ROAM:
2496 /* Parse and fetch Activate Good Rssi Roam */
2497 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_ENABLE]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002498 hdd_err("Activate Good Rssi Roam failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002499 goto fail;
2500 }
2501 roam_params.good_rssi_roam = nla_get_s32(
2502 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_ENABLE]);
Jeff Johnson020db452016-06-29 14:37:26 -07002503 hdd_debug("Activate Good Rssi Roam (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002504 roam_params.good_rssi_roam);
2505 sme_update_roam_params(pHddCtx->hHal, session_id,
2506 roam_params, REASON_ROAM_GOOD_RSSI_CHANGED);
2507 break;
2508 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BSSID_PREFS:
2509 /* Parse and fetch number of preferred BSSID */
2510 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_NUM_BSSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002511 hdd_err("attr num of preferred bssid failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002512 goto fail;
2513 }
2514 roam_params.num_bssid_favored = nla_get_u32(
2515 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_NUM_BSSID]);
Jeff Johnson020db452016-06-29 14:37:26 -07002516 hdd_debug("Num of Preferred BSSID (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002517 roam_params.num_bssid_favored);
2518 i = 0;
2519 nla_for_each_nested(curr_attr,
2520 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PREFS],
2521 rem) {
2522 if (nla_parse(tb2,
2523 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX,
2524 nla_data(curr_attr), nla_len(curr_attr),
2525 NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002526 hdd_err("nla_parse failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002527 goto fail;
2528 }
2529 /* Parse and fetch MAC address */
2530 if (!tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_BSSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002531 hdd_err("attr mac address failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002532 goto fail;
2533 }
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002534 nla_memcpy(roam_params.bssid_favored[i].bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002535 tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_BSSID],
Anurag Chouhan6d760662016-02-20 16:05:43 +05302536 QDF_MAC_ADDR_SIZE);
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002537 hdd_debug(MAC_ADDRESS_STR,
2538 MAC_ADDR_ARRAY(roam_params.bssid_favored[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002539 /* Parse and fetch preference factor*/
2540 if (!tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_RSSI_MODIFIER]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002541 hdd_err("BSSID Preference score failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002542 goto fail;
2543 }
2544 roam_params.bssid_favored_factor[i] = nla_get_u32(
2545 tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_RSSI_MODIFIER]);
Jeff Johnson020db452016-06-29 14:37:26 -07002546 hdd_debug("BSSID Preference score (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002547 roam_params.bssid_favored_factor[i]);
2548 i++;
2549 }
2550 sme_update_roam_params(pHddCtx->hHal, session_id,
2551 roam_params, REASON_ROAM_SET_FAVORED_BSSID);
2552 break;
2553 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID:
2554 /* Parse and fetch number of blacklist BSSID */
2555 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002556 hdd_err("attr num of blacklist bssid failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002557 goto fail;
2558 }
2559 roam_params.num_bssid_avoid_list = nla_get_u32(
2560 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID]);
Jeff Johnson020db452016-06-29 14:37:26 -07002561 hdd_debug("Num of blacklist BSSID (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002562 roam_params.num_bssid_avoid_list);
2563 i = 0;
2564 nla_for_each_nested(curr_attr,
2565 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS],
2566 rem) {
2567 if (nla_parse(tb2,
2568 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX,
2569 nla_data(curr_attr), nla_len(curr_attr),
2570 NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002571 hdd_err("nla_parse failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002572 goto fail;
2573 }
2574 /* Parse and fetch MAC address */
2575 if (!tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002576 hdd_err("attr blacklist addr failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002577 goto fail;
2578 }
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002579 nla_memcpy(roam_params.bssid_avoid_list[i].bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580 tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID],
Anurag Chouhan6d760662016-02-20 16:05:43 +05302581 QDF_MAC_ADDR_SIZE);
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002582 hdd_debug(MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583 MAC_ADDR_ARRAY(
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002584 roam_params.bssid_avoid_list[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002585 i++;
2586 }
2587 sme_update_roam_params(pHddCtx->hHal, session_id,
2588 roam_params, REASON_ROAM_SET_BLACKLIST_BSSID);
2589 break;
2590 }
2591 return 0;
2592fail:
2593 return -EINVAL;
2594}
2595
2596/**
2597 * wlan_hdd_cfg80211_set_ext_roam_params() - set ext scan roam params
2598 * @wiphy: pointer to wireless wiphy structure.
2599 * @wdev: pointer to wireless_dev structure.
2600 * @data: Pointer to the data to be passed via vendor interface
2601 * @data_len:Length of the data to be passed
2602 *
2603 * Return: Return the Success or Failure code.
2604 */
2605static int
2606wlan_hdd_cfg80211_set_ext_roam_params(struct wiphy *wiphy,
2607 struct wireless_dev *wdev,
2608 const void *data,
2609 int data_len)
2610{
2611 int ret;
2612
2613 cds_ssr_protect(__func__);
2614 ret = __wlan_hdd_cfg80211_set_ext_roam_params(wiphy, wdev,
2615 data, data_len);
2616 cds_ssr_unprotect(__func__);
2617
2618 return ret;
2619}
2620
2621static const struct nla_policy
2622wlan_hdd_set_no_dfs_flag_config_policy[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX
2623 +1] = {
2624 [QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG] = {.type = NLA_U32 },
2625};
2626
2627/**
2628 * wlan_hdd_check_dfs_channel_for_adapter() - check dfs channel in adapter
2629 * @hdd_ctx: HDD context
2630 * @device_mode: device mode
2631 * Return: bool
2632 */
2633static bool wlan_hdd_check_dfs_channel_for_adapter(hdd_context_t *hdd_ctx,
Krunal Sonib4326f22016-03-10 13:05:51 -08002634 enum tQDF_ADAPTER_MODE device_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002635{
2636 hdd_adapter_t *adapter;
2637 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
2638 hdd_ap_ctx_t *ap_ctx;
2639 hdd_station_ctx_t *sta_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302640 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002641
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302642 qdf_status = hdd_get_front_adapter(hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002643 &adapter_node);
2644
2645 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302646 (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002647 adapter = adapter_node->pAdapter;
2648
2649 if ((device_mode == adapter->device_mode) &&
Krunal Sonib4326f22016-03-10 13:05:51 -08002650 (device_mode == QDF_SAP_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002651 ap_ctx =
2652 WLAN_HDD_GET_AP_CTX_PTR(adapter);
2653
2654 /*
2655 * if there is SAP already running on DFS channel,
2656 * do not disable scan on dfs channels. Note that
2657 * with SAP on DFS, there cannot be conurrency on
2658 * single radio. But then we can have multiple
2659 * radios !!
2660 */
2661 if (CHANNEL_STATE_DFS ==
2662 cds_get_channel_state(
2663 ap_ctx->operatingChannel)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002664 hdd_err("SAP running on DFS channel");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002665 return true;
2666 }
2667 }
2668
2669 if ((device_mode == adapter->device_mode) &&
Krunal Sonib4326f22016-03-10 13:05:51 -08002670 (device_mode == QDF_STA_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002671 sta_ctx =
2672 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2673
2674 /*
2675 * if STA is already connected on DFS channel,
2676 * do not disable scan on dfs channels
2677 */
2678 if (hdd_conn_is_connected(sta_ctx) &&
2679 (CHANNEL_STATE_DFS ==
2680 cds_get_channel_state(
2681 sta_ctx->conn_info.operationChannel))) {
Jeff Johnson020db452016-06-29 14:37:26 -07002682 hdd_err("client connected on DFS channel");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002683 return true;
2684 }
2685 }
2686
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302687 qdf_status = hdd_get_next_adapter(hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002688 adapter_node,
2689 &next);
2690 adapter_node = next;
2691 }
2692
2693 return false;
2694}
2695
2696/**
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002697 * wlan_hdd_disable_dfs_chan_scan() - disable/enable DFS channels
2698 * @hdd_ctx: HDD context within host driver
2699 * @adapter: Adapter pointer
2700 * @no_dfs_flag: If TRUE, DFS channels cannot be used for scanning
2701 *
2702 * Loops through devices to see who is operating on DFS channels
2703 * and then disables/enables DFS channels by calling SME API.
2704 * Fails the disable request if any device is active on a DFS channel.
2705 *
2706 * Return: 0 or other error codes.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002707 */
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002708
2709int wlan_hdd_disable_dfs_chan_scan(hdd_context_t *hdd_ctx,
2710 hdd_adapter_t *adapter,
2711 uint32_t no_dfs_flag)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002712{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002713 tHalHandle h_hal = WLAN_HDD_GET_HAL_CTX(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302714 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002715 int ret_val = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002716
2717 if (no_dfs_flag == hdd_ctx->config->enableDFSChnlScan) {
2718 if (no_dfs_flag) {
2719 status = wlan_hdd_check_dfs_channel_for_adapter(
Krunal Sonib4326f22016-03-10 13:05:51 -08002720 hdd_ctx, QDF_STA_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002721
2722 if (true == status)
2723 return -EOPNOTSUPP;
2724
2725 status = wlan_hdd_check_dfs_channel_for_adapter(
Krunal Sonib4326f22016-03-10 13:05:51 -08002726 hdd_ctx, QDF_SAP_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002727
2728 if (true == status)
2729 return -EOPNOTSUPP;
2730 }
2731
2732 hdd_ctx->config->enableDFSChnlScan = !no_dfs_flag;
2733
2734 hdd_abort_mac_scan_all_adapters(hdd_ctx);
2735
2736 /*
2737 * call the SME API to tunnel down the new channel list
2738 * to the firmware
2739 */
2740 status = sme_handle_dfs_chan_scan(
2741 h_hal, hdd_ctx->config->enableDFSChnlScan);
2742
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302743 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 ret_val = 0;
2745
2746 /*
2747 * Clear the SME scan cache also. Note that the
2748 * clearing of scan results is independent of session;
2749 * so no need to iterate over
2750 * all sessions
2751 */
2752 status = sme_scan_flush_result(h_hal);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302753 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002754 ret_val = -EPERM;
2755 }
2756
2757 } else {
Jeff Johnson020db452016-06-29 14:37:26 -07002758 hdd_notice(" the DFS flag has not changed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002759 ret_val = 0;
2760 }
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002761 return ret_val;
2762}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002763
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002764/**
2765 * __wlan_hdd_cfg80211_disable_dfs_chan_scan() - DFS channel configuration
2766 * @wiphy: corestack handler
2767 * @wdev: wireless device
2768 * @data: data
2769 * @data_len: data length
2770 * Return: success(0) or reason code for failure
2771 */
2772static int __wlan_hdd_cfg80211_disable_dfs_chan_scan(struct wiphy *wiphy,
2773 struct wireless_dev *wdev,
2774 const void *data,
2775 int data_len)
2776{
2777 struct net_device *dev = wdev->netdev;
2778 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2779 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
2780 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX + 1];
2781 int ret_val;
2782 uint32_t no_dfs_flag = 0;
2783
Jeff Johnson1f61b612016-02-12 16:28:33 -08002784 ENTER_DEV(dev);
2785
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002786 ret_val = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302787 if (ret_val)
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002788 return ret_val;
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002789
2790 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX,
2791 data, data_len,
2792 wlan_hdd_set_no_dfs_flag_config_policy)) {
2793 hdd_err("invalid attr");
2794 return -EINVAL;
2795 }
2796
2797 if (!tb[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG]) {
2798 hdd_err("attr dfs flag failed");
2799 return -EINVAL;
2800 }
2801
2802 no_dfs_flag = nla_get_u32(
2803 tb[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG]);
2804
Jeff Johnson020db452016-06-29 14:37:26 -07002805 hdd_notice(" DFS flag = %d", no_dfs_flag);
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002806
2807 if (no_dfs_flag > 1) {
Jeff Johnson020db452016-06-29 14:37:26 -07002808 hdd_err("invalid value of dfs flag");
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002809 return -EINVAL;
2810 }
2811
2812 ret_val = wlan_hdd_disable_dfs_chan_scan(hdd_ctx, adapter,
2813 no_dfs_flag);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814 return ret_val;
2815}
2816
2817/**
2818 * wlan_hdd_cfg80211_disable_dfs_chan_scan () - DFS scan vendor command
2819 *
2820 * @wiphy: wiphy device pointer
2821 * @wdev: wireless device pointer
Manikandan Mohan80dea792016-04-28 16:36:48 -07002822 * @data: Vendor command data buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002823 * @data_len: Buffer length
2824 *
2825 * Handles QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX. Validate it and
2826 * call wlan_hdd_disable_dfs_chan_scan to send it to firmware.
2827 *
2828 * Return: EOK or other error codes.
2829 */
2830
2831static int wlan_hdd_cfg80211_disable_dfs_chan_scan(struct wiphy *wiphy,
2832 struct wireless_dev *wdev,
2833 const void *data,
2834 int data_len)
2835{
2836 int ret;
2837
2838 cds_ssr_protect(__func__);
2839 ret = __wlan_hdd_cfg80211_disable_dfs_chan_scan(wiphy, wdev,
2840 data, data_len);
2841 cds_ssr_unprotect(__func__);
2842
2843 return ret;
2844}
2845
Manikandan Mohan80dea792016-04-28 16:36:48 -07002846static const struct nla_policy
2847wlan_hdd_wisa_cmd_policy[QCA_WLAN_VENDOR_ATTR_WISA_MAX + 1] = {
2848 [QCA_WLAN_VENDOR_ATTR_WISA_MODE] = {.type = NLA_U32 },
2849};
2850
2851/**
2852 * __wlan_hdd_cfg80211_handle_wisa_cmd() - Handle WISA vendor cmd
2853 * @wiphy: wiphy device pointer
2854 * @wdev: wireless device pointer
2855 * @data: Vendor command data buffer
2856 * @data_len: Buffer length
2857 *
2858 * Handles QCA_WLAN_VENDOR_SUBCMD_WISA. Validate cmd attributes and
2859 * setup WISA Mode features.
2860 *
2861 * Return: Success(0) or reason code for failure
2862 */
2863static int __wlan_hdd_cfg80211_handle_wisa_cmd(struct wiphy *wiphy,
2864 struct wireless_dev *wdev, const void *data, int data_len)
2865{
2866 struct net_device *dev = wdev->netdev;
2867 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2868 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
2869 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_WISA_MAX + 1];
2870 struct sir_wisa_params wisa;
2871 int ret_val;
2872 QDF_STATUS status;
2873 bool wisa_mode;
Leo Changfdb45c32016-10-28 11:09:23 -07002874 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2875 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Manikandan Mohan80dea792016-04-28 16:36:48 -07002876
2877 ENTER_DEV(dev);
2878 ret_val = wlan_hdd_validate_context(hdd_ctx);
2879 if (ret_val)
2880 goto err;
2881
2882 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2883 hdd_err("Command not allowed in FTM mode");
2884 return -EPERM;
2885 }
2886
2887 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_WISA_MAX, data, data_len,
2888 wlan_hdd_wisa_cmd_policy)) {
2889 hdd_err("Invalid WISA cmd attributes");
2890 ret_val = -EINVAL;
2891 goto err;
2892 }
2893 if (!tb[QCA_WLAN_VENDOR_ATTR_WISA_MODE]) {
2894 hdd_err("Invalid WISA mode");
2895 ret_val = -EINVAL;
2896 goto err;
2897 }
2898
2899 wisa_mode = !!nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_WISA_MODE]);
2900 hdd_info("WISA Mode: %d", wisa_mode);
2901 wisa.mode = wisa_mode;
2902 wisa.vdev_id = adapter->sessionId;
2903 status = sme_set_wisa_params(hdd_ctx->hHal, &wisa);
Manikandan Mohanb6315dd2016-05-10 16:16:36 -07002904 if (!QDF_IS_STATUS_SUCCESS(status)) {
2905 hdd_err("Unable to set WISA mode: %d to FW", wisa_mode);
Manikandan Mohan80dea792016-04-28 16:36:48 -07002906 ret_val = -EINVAL;
Manikandan Mohanb6315dd2016-05-10 16:16:36 -07002907 }
2908 if (QDF_IS_STATUS_SUCCESS(status) || wisa_mode == false)
Leo Changfdb45c32016-10-28 11:09:23 -07002909 cdp_set_wisa_mode(soc,
2910 cdp_get_vdev_from_vdev_id(soc, pdev,
2911 adapter->sessionId),
2912 wisa_mode);
Manikandan Mohan80dea792016-04-28 16:36:48 -07002913err:
2914 EXIT();
2915 return ret_val;
2916}
2917
2918/**
2919 * wlan_hdd_cfg80211_handle_wisa_cmd() - Handle WISA vendor cmd
2920 * @wiphy: corestack handler
2921 * @wdev: wireless device
2922 * @data: data
2923 * @data_len: data length
2924 *
2925 * Handles QCA_WLAN_VENDOR_SUBCMD_WISA. Validate cmd attributes and
2926 * setup WISA mode features.
2927 *
2928 * Return: Success(0) or reason code for failure
2929 */
2930static int wlan_hdd_cfg80211_handle_wisa_cmd(struct wiphy *wiphy,
2931 struct wireless_dev *wdev,
2932 const void *data,
2933 int data_len)
2934{
2935 int ret;
2936
2937 cds_ssr_protect(__func__);
2938 ret = __wlan_hdd_cfg80211_handle_wisa_cmd(wiphy, wdev, data, data_len);
2939 cds_ssr_unprotect(__func__);
2940
2941 return ret;
2942}
2943
Anurag Chouhan96919482016-07-13 16:36:57 +05302944/*
2945 * define short names for the global vendor params
2946 * used by __wlan_hdd_cfg80211_get_station_cmd()
2947 */
2948#define STATION_INVALID \
2949 QCA_WLAN_VENDOR_ATTR_GET_STATION_INVALID
2950#define STATION_INFO \
2951 QCA_WLAN_VENDOR_ATTR_GET_STATION_INFO
2952#define STATION_ASSOC_FAIL_REASON \
2953 QCA_WLAN_VENDOR_ATTR_GET_STATION_ASSOC_FAIL_REASON
2954#define STATION_MAX \
2955 QCA_WLAN_VENDOR_ATTR_GET_STATION_MAX
2956
2957static const struct nla_policy
2958hdd_get_station_policy[STATION_MAX + 1] = {
2959 [STATION_INFO] = {.type = NLA_FLAG},
2960 [STATION_ASSOC_FAIL_REASON] = {.type = NLA_FLAG},
2961};
2962
2963/**
2964 * hdd_get_station_assoc_fail() - Handle get station assoc fail
2965 * @hdd_ctx: HDD context within host driver
2966 * @wdev: wireless device
2967 *
2968 * Handles QCA_NL80211_VENDOR_SUBCMD_GET_STATION_ASSOC_FAIL.
2969 * Validate cmd attributes and send the station info to upper layers.
2970 *
2971 * Return: Success(0) or reason code for failure
2972 */
2973static int hdd_get_station_assoc_fail(hdd_context_t *hdd_ctx,
2974 hdd_adapter_t *adapter)
2975{
2976 struct sk_buff *skb = NULL;
2977 uint32_t nl_buf_len;
2978 hdd_station_ctx_t *hdd_sta_ctx;
2979
2980 nl_buf_len = NLMSG_HDRLEN;
2981 nl_buf_len += sizeof(uint32_t);
2982 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
2983
2984 if (!skb) {
2985 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
2986 return -ENOMEM;
2987 }
2988
2989 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2990
2991 if (nla_put_u32(skb, INFO_ASSOC_FAIL_REASON,
2992 hdd_sta_ctx->conn_info.assoc_status_code)) {
2993 hdd_err("put fail");
2994 goto fail;
2995 }
2996 return cfg80211_vendor_cmd_reply(skb);
2997fail:
2998 if (skb)
2999 kfree_skb(skb);
3000 return -EINVAL;
3001}
3002
3003/**
3004 * hdd_map_auth_type() - transform auth type specific to
3005 * vendor command
3006 * @auth_type: csr auth type
3007 *
3008 * Return: Success(0) or reason code for failure
3009 */
3010static int hdd_convert_auth_type(uint32_t auth_type)
3011{
3012 uint32_t ret_val;
3013
3014 switch (auth_type) {
3015 case eCSR_AUTH_TYPE_OPEN_SYSTEM:
3016 ret_val = QCA_WLAN_AUTH_TYPE_OPEN;
3017 break;
3018 case eCSR_AUTH_TYPE_SHARED_KEY:
3019 ret_val = QCA_WLAN_AUTH_TYPE_SHARED;
3020 break;
3021 case eCSR_AUTH_TYPE_WPA:
3022 ret_val = QCA_WLAN_AUTH_TYPE_WPA;
3023 break;
3024 case eCSR_AUTH_TYPE_WPA_PSK:
3025 ret_val = QCA_WLAN_AUTH_TYPE_WPA_PSK;
3026 break;
3027 case eCSR_AUTH_TYPE_AUTOSWITCH:
3028 ret_val = QCA_WLAN_AUTH_TYPE_AUTOSWITCH;
3029 break;
3030 case eCSR_AUTH_TYPE_WPA_NONE:
3031 ret_val = QCA_WLAN_AUTH_TYPE_WPA_NONE;
3032 break;
3033 case eCSR_AUTH_TYPE_RSN:
3034 ret_val = QCA_WLAN_AUTH_TYPE_RSN;
3035 break;
3036 case eCSR_AUTH_TYPE_RSN_PSK:
3037 ret_val = QCA_WLAN_AUTH_TYPE_RSN_PSK;
3038 break;
3039 case eCSR_AUTH_TYPE_FT_RSN:
3040 ret_val = QCA_WLAN_AUTH_TYPE_FT;
3041 break;
3042 case eCSR_AUTH_TYPE_FT_RSN_PSK:
3043 ret_val = QCA_WLAN_AUTH_TYPE_FT_PSK;
3044 break;
3045 case eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE:
3046 ret_val = QCA_WLAN_AUTH_TYPE_WAI;
3047 break;
3048 case eCSR_AUTH_TYPE_WAPI_WAI_PSK:
3049 ret_val = QCA_WLAN_AUTH_TYPE_WAI_PSK;
3050 break;
3051 case eCSR_AUTH_TYPE_CCKM_WPA:
3052 ret_val = QCA_WLAN_AUTH_TYPE_CCKM_WPA;
3053 break;
3054 case eCSR_AUTH_TYPE_CCKM_RSN:
3055 ret_val = QCA_WLAN_AUTH_TYPE_CCKM_RSN;
3056 break;
3057 case eCSR_AUTH_TYPE_RSN_PSK_SHA256:
3058 ret_val = QCA_WLAN_AUTH_TYPE_SHA256_PSK;
3059 break;
3060 case eCSR_AUTH_TYPE_RSN_8021X_SHA256:
3061 ret_val = QCA_WLAN_AUTH_TYPE_SHA256;
3062 break;
3063 case eCSR_NUM_OF_SUPPORT_AUTH_TYPE:
3064 case eCSR_AUTH_TYPE_FAILED:
3065 case eCSR_AUTH_TYPE_NONE:
3066 default:
3067 ret_val = QCA_WLAN_AUTH_TYPE_INVALID;
3068 break;
3069 }
3070 return ret_val;
3071}
3072
3073/**
3074 * hdd_map_dot_11_mode() - transform dot11mode type specific to
3075 * vendor command
3076 * @dot11mode: dot11mode
3077 *
3078 * Return: Success(0) or reason code for failure
3079 */
3080static int hdd_convert_dot11mode(uint32_t dot11mode)
3081{
3082 uint32_t ret_val;
3083
3084 switch (dot11mode) {
3085 case eCSR_CFG_DOT11_MODE_11A:
3086 ret_val = QCA_WLAN_802_11_MODE_11A;
3087 break;
3088 case eCSR_CFG_DOT11_MODE_11B:
3089 ret_val = QCA_WLAN_802_11_MODE_11B;
3090 break;
3091 case eCSR_CFG_DOT11_MODE_11G:
3092 ret_val = QCA_WLAN_802_11_MODE_11G;
3093 break;
3094 case eCSR_CFG_DOT11_MODE_11N:
3095 ret_val = QCA_WLAN_802_11_MODE_11N;
3096 break;
3097 case eCSR_CFG_DOT11_MODE_11AC:
3098 ret_val = QCA_WLAN_802_11_MODE_11AC;
3099 break;
3100 case eCSR_CFG_DOT11_MODE_AUTO:
3101 case eCSR_CFG_DOT11_MODE_ABG:
3102 default:
3103 ret_val = QCA_WLAN_802_11_MODE_INVALID;
3104 }
3105 return ret_val;
3106}
3107
3108/**
3109 * hdd_add_tx_bitrate() - add tx bitrate attribute
3110 * @skb: pointer to sk buff
3111 * @hdd_sta_ctx: pointer to hdd station context
3112 * @idx: attribute index
3113 *
3114 * Return: Success(0) or reason code for failure
3115 */
3116static int32_t hdd_add_tx_bitrate(struct sk_buff *skb,
3117 hdd_station_ctx_t *hdd_sta_ctx,
3118 int idx)
3119{
3120 struct nlattr *nla_attr;
3121 uint32_t bitrate, bitrate_compat;
3122
3123 nla_attr = nla_nest_start(skb, idx);
3124 if (!nla_attr)
3125 goto fail;
3126 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3127 bitrate = cfg80211_calculate_bitrate(&hdd_sta_ctx->conn_info.txrate);
3128
3129 /* report 16-bit bitrate only if we can */
3130 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
3131 if (bitrate > 0 &&
3132 nla_put_u32(skb, NL80211_RATE_INFO_BITRATE32, bitrate)) {
3133 hdd_err("put fail");
3134 goto fail;
3135 }
3136 if (bitrate_compat > 0 &&
3137 nla_put_u16(skb, NL80211_RATE_INFO_BITRATE, bitrate_compat)) {
3138 hdd_err("put fail");
3139 goto fail;
3140 }
3141 if (nla_put_u8(skb, NL80211_RATE_INFO_VHT_NSS,
3142 hdd_sta_ctx->conn_info.txrate.nss)) {
3143 hdd_err("put fail");
3144 goto fail;
3145 }
3146 nla_nest_end(skb, nla_attr);
3147 return 0;
3148fail:
3149 return -EINVAL;
3150}
3151
3152/**
3153 * hdd_add_sta_info() - add station info attribute
3154 * @skb: pointer to sk buff
3155 * @hdd_sta_ctx: pointer to hdd station context
3156 * @idx: attribute index
3157 *
3158 * Return: Success(0) or reason code for failure
3159 */
3160static int32_t hdd_add_sta_info(struct sk_buff *skb,
3161 hdd_station_ctx_t *hdd_sta_ctx, int idx)
3162{
3163 struct nlattr *nla_attr;
3164
3165 nla_attr = nla_nest_start(skb, idx);
3166 if (!nla_attr)
3167 goto fail;
3168 if (nla_put_u8(skb, NL80211_STA_INFO_SIGNAL,
3169 (hdd_sta_ctx->conn_info.signal + 100))) {
3170 hdd_err("put fail");
3171 goto fail;
3172 }
3173 if (hdd_add_tx_bitrate(skb, hdd_sta_ctx, NL80211_STA_INFO_TX_BITRATE))
3174 goto fail;
3175 nla_nest_end(skb, nla_attr);
3176 return 0;
3177fail:
3178 return -EINVAL;
3179}
3180
3181/**
3182 * hdd_add_survey_info() - add survey info attribute
3183 * @skb: pointer to sk buff
3184 * @hdd_sta_ctx: pointer to hdd station context
3185 * @idx: attribute index
3186 *
3187 * Return: Success(0) or reason code for failure
3188 */
3189static int32_t hdd_add_survey_info(struct sk_buff *skb,
3190 hdd_station_ctx_t *hdd_sta_ctx,
3191 int idx)
3192{
3193 struct nlattr *nla_attr;
3194
3195 nla_attr = nla_nest_start(skb, idx);
3196 if (!nla_attr)
3197 goto fail;
3198 if (nla_put_u32(skb, NL80211_SURVEY_INFO_FREQUENCY,
3199 hdd_sta_ctx->conn_info.freq) ||
3200 nla_put_u8(skb, NL80211_SURVEY_INFO_NOISE,
3201 (hdd_sta_ctx->conn_info.noise + 100))) {
3202 hdd_err("put fail");
3203 goto fail;
3204 }
3205 nla_nest_end(skb, nla_attr);
3206 return 0;
3207fail:
3208 return -EINVAL;
3209}
3210
3211/**
3212 * hdd_add_link_standard_info() - add link info attribute
3213 * @skb: pointer to sk buff
3214 * @hdd_sta_ctx: pointer to hdd station context
3215 * @idx: attribute index
3216 *
3217 * Return: Success(0) or reason code for failure
3218 */
3219static int32_t
3220hdd_add_link_standard_info(struct sk_buff *skb,
3221 hdd_station_ctx_t *hdd_sta_ctx, int idx)
3222{
3223 struct nlattr *nla_attr;
3224
3225 nla_attr = nla_nest_start(skb, idx);
3226 if (!nla_attr)
3227 goto fail;
3228 if (nla_put(skb,
3229 NL80211_ATTR_SSID,
3230 hdd_sta_ctx->conn_info.SSID.SSID.length,
3231 hdd_sta_ctx->conn_info.SSID.SSID.ssId)) {
3232 hdd_err("put fail");
3233 goto fail;
3234 }
3235 if (hdd_add_survey_info(skb, hdd_sta_ctx, NL80211_ATTR_SURVEY_INFO))
3236 goto fail;
3237 if (hdd_add_sta_info(skb, hdd_sta_ctx, NL80211_ATTR_STA_INFO))
3238 goto fail;
3239 nla_nest_end(skb, nla_attr);
3240 return 0;
3241fail:
3242 return -EINVAL;
3243}
3244
3245/**
3246 * hdd_add_ap_standard_info() - add ap info attribute
3247 * @skb: pointer to sk buff
3248 * @hdd_sta_ctx: pointer to hdd station context
3249 * @idx: attribute index
3250 *
3251 * Return: Success(0) or reason code for failure
3252 */
3253static int32_t
3254hdd_add_ap_standard_info(struct sk_buff *skb,
3255 hdd_station_ctx_t *hdd_sta_ctx, int idx)
3256{
3257 struct nlattr *nla_attr;
3258
3259 nla_attr = nla_nest_start(skb, idx);
3260 if (!nla_attr)
3261 goto fail;
3262 if (hdd_sta_ctx->conn_info.conn_flag.vht_present)
3263 if (nla_put(skb, NL80211_ATTR_VHT_CAPABILITY,
3264 sizeof(hdd_sta_ctx->conn_info.vht_caps),
3265 &hdd_sta_ctx->conn_info.vht_caps)) {
3266 hdd_err("put fail");
3267 goto fail;
3268 }
3269 if (hdd_sta_ctx->conn_info.conn_flag.ht_present)
3270 if (nla_put(skb, NL80211_ATTR_HT_CAPABILITY,
3271 sizeof(hdd_sta_ctx->conn_info.ht_caps),
3272 &hdd_sta_ctx->conn_info.ht_caps)) {
3273 hdd_err("put fail");
3274 goto fail;
3275 }
3276 nla_nest_end(skb, nla_attr);
3277 return 0;
3278fail:
3279 return -EINVAL;
3280}
3281
3282/**
3283 * hdd_get_station_info() - send BSS information to supplicant
3284 * @hdd_ctx: pointer to hdd context
3285 * @adapter: pointer to adapter
3286 *
3287 * Return: 0 if success else error status
3288 */
3289static int hdd_get_station_info(hdd_context_t *hdd_ctx,
3290 hdd_adapter_t *adapter)
3291{
3292 struct sk_buff *skb = NULL;
3293 uint8_t *tmp_hs20 = NULL;
3294 uint32_t nl_buf_len;
3295 hdd_station_ctx_t *hdd_sta_ctx;
3296
3297 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3298
3299 nl_buf_len = NLMSG_HDRLEN;
3300 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.SSID.SSID.length) +
3301 sizeof(hdd_sta_ctx->conn_info.freq) +
3302 sizeof(hdd_sta_ctx->conn_info.noise) +
3303 sizeof(hdd_sta_ctx->conn_info.signal) +
3304 (sizeof(uint32_t) * 2) +
3305 sizeof(hdd_sta_ctx->conn_info.txrate.nss) +
3306 sizeof(hdd_sta_ctx->conn_info.roam_count) +
3307 sizeof(hdd_sta_ctx->conn_info.authType) +
3308 sizeof(hdd_sta_ctx->conn_info.dot11Mode);
3309 if (hdd_sta_ctx->conn_info.conn_flag.vht_present)
3310 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.vht_caps);
3311 if (hdd_sta_ctx->conn_info.conn_flag.ht_present)
3312 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.ht_caps);
3313 if (hdd_sta_ctx->conn_info.conn_flag.hs20_present) {
3314 tmp_hs20 = (uint8_t *)&(hdd_sta_ctx->conn_info.hs20vendor_ie);
3315 nl_buf_len += (sizeof(hdd_sta_ctx->conn_info.hs20vendor_ie) -
3316 1);
3317 }
3318 if (hdd_sta_ctx->conn_info.conn_flag.ht_op_present)
3319 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.ht_operation);
3320 if (hdd_sta_ctx->conn_info.conn_flag.vht_op_present)
3321 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.vht_operation);
3322
3323
3324 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
3325 if (!skb) {
3326 hdd_err(FL("cfg80211_vendor_cmd_alloc_reply_skb failed"));
3327 return -ENOMEM;
3328 }
3329
3330 if (hdd_add_link_standard_info(skb, hdd_sta_ctx,
3331 LINK_INFO_STANDARD_NL80211_ATTR)) {
3332 hdd_err("put fail");
3333 goto fail;
3334 }
3335 if (hdd_add_ap_standard_info(skb, hdd_sta_ctx,
3336 AP_INFO_STANDARD_NL80211_ATTR)) {
3337 hdd_err("put fail");
3338 goto fail;
3339 }
3340 if (nla_put_u32(skb, INFO_ROAM_COUNT,
3341 hdd_sta_ctx->conn_info.roam_count) ||
3342 nla_put_u32(skb, INFO_AKM,
3343 hdd_convert_auth_type(
3344 hdd_sta_ctx->conn_info.authType)) ||
3345 nla_put_u32(skb, WLAN802_11_MODE,
3346 hdd_convert_dot11mode(
3347 hdd_sta_ctx->conn_info.dot11Mode))) {
3348 hdd_err("put fail");
3349 goto fail;
3350 }
3351 if (hdd_sta_ctx->conn_info.conn_flag.ht_op_present)
3352 if (nla_put(skb, HT_OPERATION,
3353 (sizeof(hdd_sta_ctx->conn_info.ht_operation)),
3354 &hdd_sta_ctx->conn_info.ht_operation)) {
3355 hdd_err("put fail");
3356 goto fail;
3357 }
3358 if (hdd_sta_ctx->conn_info.conn_flag.vht_op_present)
3359 if (nla_put(skb, VHT_OPERATION,
3360 (sizeof(hdd_sta_ctx->conn_info.vht_operation)),
3361 &hdd_sta_ctx->conn_info.vht_operation)) {
3362 hdd_err("put fail");
3363 goto fail;
3364 }
3365 if (hdd_sta_ctx->conn_info.conn_flag.hs20_present)
3366 if (nla_put(skb, AP_INFO_HS20_INDICATION,
3367 (sizeof(hdd_sta_ctx->conn_info.hs20vendor_ie) - 1),
3368 tmp_hs20 + 1)) {
3369 hdd_err("put fail");
3370 goto fail;
3371 }
3372
3373 return cfg80211_vendor_cmd_reply(skb);
3374fail:
3375 if (skb)
3376 kfree_skb(skb);
3377 return -EINVAL;
3378}
3379
3380/**
3381 * __hdd_cfg80211_get_station_cmd() - Handle get station vendor cmd
3382 * @wiphy: corestack handler
3383 * @wdev: wireless device
3384 * @data: data
3385 * @data_len: data length
3386 *
3387 * Handles QCA_NL80211_VENDOR_SUBCMD_GET_STATION.
3388 * Validate cmd attributes and send the station info to upper layers.
3389 *
3390 * Return: Success(0) or reason code for failure
3391 */
Anurag Chouhand939d3d2016-07-20 17:45:48 +05303392static int
Anurag Chouhan96919482016-07-13 16:36:57 +05303393__hdd_cfg80211_get_station_cmd(struct wiphy *wiphy,
3394 struct wireless_dev *wdev,
3395 const void *data,
3396 int data_len)
3397{
3398 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
3399 struct net_device *dev = wdev->netdev;
3400 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
3401 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GET_STATION_MAX + 1];
3402 int32_t status;
3403
3404 ENTER_DEV(dev);
3405 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
3406 hdd_err("Command not allowed in FTM mode");
3407 status = -EPERM;
3408 goto out;
3409 }
3410
3411 status = wlan_hdd_validate_context(hdd_ctx);
3412 if (0 != status)
3413 goto out;
3414
3415
3416 status = nla_parse(tb, QCA_WLAN_VENDOR_ATTR_GET_STATION_MAX,
3417 data, data_len, NULL);
3418 if (status) {
3419 hdd_err("Invalid ATTR");
3420 goto out;
3421 }
3422
3423 /* Parse and fetch Command Type*/
3424 if (tb[STATION_INFO]) {
3425 status = hdd_get_station_info(hdd_ctx, adapter);
3426 } else if (tb[STATION_ASSOC_FAIL_REASON]) {
3427 status = hdd_get_station_assoc_fail(hdd_ctx, adapter);
3428 } else {
3429 hdd_err("get station info cmd type failed");
3430 status = -EINVAL;
3431 goto out;
3432 }
3433 EXIT();
3434out:
3435 return status;
3436}
3437
3438/**
3439 * wlan_hdd_cfg80211_get_station_cmd() - Handle get station vendor cmd
3440 * @wiphy: corestack handler
3441 * @wdev: wireless device
3442 * @data: data
3443 * @data_len: data length
3444 *
3445 * Handles QCA_NL80211_VENDOR_SUBCMD_GET_STATION.
3446 * Validate cmd attributes and send the station info to upper layers.
3447 *
3448 * Return: Success(0) or reason code for failure
3449 */
3450static int32_t
3451hdd_cfg80211_get_station_cmd(struct wiphy *wiphy,
3452 struct wireless_dev *wdev,
3453 const void *data,
3454 int data_len)
3455{
3456 int ret;
3457
3458 cds_ssr_protect(__func__);
3459 ret = __hdd_cfg80211_get_station_cmd(wiphy, wdev, data, data_len);
3460 cds_ssr_unprotect(__func__);
3461
3462 return ret;
3463}
3464
3465/*
3466 * undef short names defined for get station command
3467 * used by __wlan_hdd_cfg80211_get_station_cmd()
3468 */
3469#undef STATION_INVALID
3470#undef STATION_INFO
3471#undef STATION_ASSOC_FAIL_REASON
3472#undef STATION_MAX
3473
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474#ifdef WLAN_FEATURE_ROAM_OFFLOAD
3475/**
3476 * __wlan_hdd_cfg80211_keymgmt_set_key() - Store the Keys in the driver session
3477 * @wiphy: pointer to wireless wiphy structure.
3478 * @wdev: pointer to wireless_dev structure.
3479 * @data: Pointer to the Key data
3480 * @data_len:Length of the data passed
3481 *
3482 * This is called when wlan driver needs to save the keys received via
3483 * vendor specific command.
3484 *
3485 * Return: Return the Success or Failure code.
3486 */
3487static int __wlan_hdd_cfg80211_keymgmt_set_key(struct wiphy *wiphy,
3488 struct wireless_dev *wdev,
3489 const void *data, int data_len)
3490{
3491 uint8_t local_pmk[SIR_ROAM_SCAN_PSK_SIZE];
3492 struct net_device *dev = wdev->netdev;
3493 hdd_adapter_t *hdd_adapter_ptr = WLAN_HDD_GET_PRIV_PTR(dev);
3494 hdd_context_t *hdd_ctx_ptr;
3495 int status;
3496
Jeff Johnson1f61b612016-02-12 16:28:33 -08003497 ENTER_DEV(dev);
3498
Anurag Chouhan6d760662016-02-20 16:05:43 +05303499 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500 hdd_err("Command not allowed in FTM mode");
3501 return -EPERM;
3502 }
3503
3504 if ((data == NULL) || (data_len == 0) ||
3505 (data_len > SIR_ROAM_SCAN_PSK_SIZE)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003506 hdd_err("Invalid data");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507 return -EINVAL;
3508 }
3509
3510 hdd_ctx_ptr = WLAN_HDD_GET_CTX(hdd_adapter_ptr);
3511 if (!hdd_ctx_ptr) {
Jeff Johnson020db452016-06-29 14:37:26 -07003512 hdd_err("HDD context is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513 return -EINVAL;
3514 }
3515
3516 status = wlan_hdd_validate_context(hdd_ctx_ptr);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303517 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003519 sme_update_roam_key_mgmt_offload_enabled(hdd_ctx_ptr->hHal,
3520 hdd_adapter_ptr->sessionId,
Deepak Dhamdheref2a7d8b2016-08-19 16:17:38 -07003521 true,
3522 hdd_is_okc_mode_enabled(hdd_ctx_ptr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303523 qdf_mem_zero(&local_pmk, SIR_ROAM_SCAN_PSK_SIZE);
3524 qdf_mem_copy(local_pmk, data, data_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003525 sme_roam_set_psk_pmk(WLAN_HDD_GET_HAL_CTX(hdd_adapter_ptr),
3526 hdd_adapter_ptr->sessionId, local_pmk, data_len);
3527 return 0;
3528}
3529
3530/**
3531 * wlan_hdd_cfg80211_keymgmt_set_key() - Store the Keys in the driver session
3532 * @wiphy: pointer to wireless wiphy structure.
3533 * @wdev: pointer to wireless_dev structure.
3534 * @data: Pointer to the Key data
3535 * @data_len:Length of the data passed
3536 *
3537 * This is called when wlan driver needs to save the keys received via
3538 * vendor specific command.
3539 *
3540 * Return: Return the Success or Failure code.
3541 */
3542static int wlan_hdd_cfg80211_keymgmt_set_key(struct wiphy *wiphy,
3543 struct wireless_dev *wdev,
3544 const void *data, int data_len)
3545{
3546 int ret;
3547
3548 cds_ssr_protect(__func__);
3549 ret = __wlan_hdd_cfg80211_keymgmt_set_key(wiphy, wdev, data, data_len);
3550 cds_ssr_unprotect(__func__);
3551
3552 return ret;
3553}
Varun Reddy Yeturubbbbe232016-02-29 14:01:57 -08003554#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555
3556static const struct nla_policy qca_wlan_vendor_get_wifi_info_policy[
3557 QCA_WLAN_VENDOR_ATTR_WIFI_INFO_GET_MAX + 1] = {
3558 [QCA_WLAN_VENDOR_ATTR_WIFI_INFO_DRIVER_VERSION] = {.type = NLA_U8 },
3559 [QCA_WLAN_VENDOR_ATTR_WIFI_INFO_FIRMWARE_VERSION] = {.type = NLA_U8 },
Ryan Hsu7ac88852016-04-28 10:20:34 -07003560 [QCA_WLAN_VENDOR_ATTR_WIFI_INFO_RADIO_INDEX] = {.type = NLA_U32 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003561};
3562
3563/**
3564 * __wlan_hdd_cfg80211_get_wifi_info() - Get the wifi driver related info
3565 * @wiphy: pointer to wireless wiphy structure.
3566 * @wdev: pointer to wireless_dev structure.
3567 * @data: Pointer to the data to be passed via vendor interface
3568 * @data_len:Length of the data to be passed
3569 *
3570 * This is called when wlan driver needs to send wifi driver related info
3571 * (driver/fw version) to the user space application upon request.
3572 *
3573 * Return: Return the Success or Failure code.
3574 */
3575static int
3576__wlan_hdd_cfg80211_get_wifi_info(struct wiphy *wiphy,
3577 struct wireless_dev *wdev,
3578 const void *data, int data_len)
3579{
3580 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
3581 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_GET_MAX + 1];
Ryan Hsu7ac88852016-04-28 10:20:34 -07003582 tSirVersionString driver_version;
3583 tSirVersionString firmware_version;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584 uint32_t major_spid = 0, minor_spid = 0, siid = 0, crmid = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585 int status;
Ryan Hsu7ac88852016-04-28 10:20:34 -07003586 struct sk_buff *reply_skb;
3587 uint32_t skb_len = 0, count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588
Jeff Johnson1f61b612016-02-12 16:28:33 -08003589 ENTER_DEV(wdev->netdev);
3590
Anurag Chouhan6d760662016-02-20 16:05:43 +05303591 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 hdd_err("Command not allowed in FTM mode");
3593 return -EPERM;
3594 }
3595
3596 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303597 if (status)
3598 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599
3600 if (nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_WIFI_INFO_GET_MAX, data,
3601 data_len, qca_wlan_vendor_get_wifi_info_policy)) {
Ryan Hsu7ac88852016-04-28 10:20:34 -07003602 hdd_err("WIFI_INFO_GET NL CMD parsing failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 return -EINVAL;
3604 }
3605
3606 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_DRIVER_VERSION]) {
Ryan Hsu7ac88852016-04-28 10:20:34 -07003607 hdd_err("Rcvd req for Driver version");
3608 strlcpy(driver_version, QWLAN_VERSIONSTR,
3609 sizeof(driver_version));
3610 skb_len += strlen(driver_version) + 1;
3611 count++;
3612 }
3613
3614 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_FIRMWARE_VERSION]) {
3615 hdd_info("Rcvd req for FW version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 hdd_get_fw_version(hdd_ctx, &major_spid, &minor_spid, &siid,
3617 &crmid);
Ryan Hsu7ac88852016-04-28 10:20:34 -07003618 snprintf(firmware_version, sizeof(firmware_version),
3619 "%d:%d:%d:%d", major_spid, minor_spid, siid, crmid);
3620 skb_len += strlen(firmware_version) + 1;
3621 count++;
3622 }
3623
3624 if (count == 0) {
3625 hdd_err("unknown attribute in get_wifi_info request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626 return -EINVAL;
3627 }
3628
Ryan Hsu7ac88852016-04-28 10:20:34 -07003629 skb_len += (NLA_HDRLEN * count) + NLMSG_HDRLEN;
3630 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, skb_len);
3631
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003632 if (!reply_skb) {
Ryan Hsu7ac88852016-04-28 10:20:34 -07003633 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634 return -ENOMEM;
3635 }
3636
Ryan Hsu7ac88852016-04-28 10:20:34 -07003637 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_DRIVER_VERSION]) {
3638 if (nla_put_string(reply_skb,
3639 QCA_WLAN_VENDOR_ATTR_WIFI_INFO_DRIVER_VERSION,
3640 driver_version))
3641 goto error_nla_fail;
3642 }
3643
Hanumanth Reddy Pothula1046ccc2016-10-14 14:33:44 +05303644 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_FIRMWARE_VERSION]) {
Ryan Hsu7ac88852016-04-28 10:20:34 -07003645 if (nla_put_string(reply_skb,
3646 QCA_WLAN_VENDOR_ATTR_WIFI_INFO_FIRMWARE_VERSION,
3647 firmware_version))
3648 goto error_nla_fail;
3649 }
3650
3651 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_RADIO_INDEX]) {
3652 if (nla_put_u32(reply_skb,
3653 QCA_WLAN_VENDOR_ATTR_WIFI_INFO_RADIO_INDEX,
3654 hdd_ctx->radio_index))
3655 goto error_nla_fail;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 }
3657
3658 return cfg80211_vendor_cmd_reply(reply_skb);
Ryan Hsu7ac88852016-04-28 10:20:34 -07003659
3660error_nla_fail:
3661 hdd_err("nla put fail");
3662 kfree_skb(reply_skb);
3663 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664}
3665
3666/**
3667 * wlan_hdd_cfg80211_get_wifi_info() - Get the wifi driver related info
3668 * @wiphy: pointer to wireless wiphy structure.
3669 * @wdev: pointer to wireless_dev structure.
3670 * @data: Pointer to the data to be passed via vendor interface
3671 * @data_len:Length of the data to be passed
3672 *
3673 * This is called when wlan driver needs to send wifi driver related info
3674 * (driver/fw version) to the user space application upon request.
3675 *
3676 * Return: Return the Success or Failure code.
3677 */
3678static int
3679wlan_hdd_cfg80211_get_wifi_info(struct wiphy *wiphy,
3680 struct wireless_dev *wdev,
3681 const void *data, int data_len)
3682{
3683 int ret;
3684
3685 cds_ssr_protect(__func__);
3686 ret = __wlan_hdd_cfg80211_get_wifi_info(wiphy, wdev, data, data_len);
3687 cds_ssr_unprotect(__func__);
3688
3689 return ret;
3690}
3691
3692/**
3693 * __wlan_hdd_cfg80211_get_logger_supp_feature() - Get the wifi logger features
3694 * @wiphy: pointer to wireless wiphy structure.
3695 * @wdev: pointer to wireless_dev structure.
3696 * @data: Pointer to the data to be passed via vendor interface
3697 * @data_len:Length of the data to be passed
3698 *
3699 * This is called by userspace to know the supported logger features
3700 *
3701 * Return: Return the Success or Failure code.
3702 */
3703static int
3704__wlan_hdd_cfg80211_get_logger_supp_feature(struct wiphy *wiphy,
3705 struct wireless_dev *wdev,
3706 const void *data, int data_len)
3707{
3708 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
3709 int status;
3710 uint32_t features;
3711 struct sk_buff *reply_skb = NULL;
3712
Jeff Johnson1f61b612016-02-12 16:28:33 -08003713 ENTER_DEV(wdev->netdev);
3714
Anurag Chouhan6d760662016-02-20 16:05:43 +05303715 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003716 hdd_err("Command not allowed in FTM mode");
3717 return -EPERM;
3718 }
3719
3720 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303721 if (status)
3722 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723
3724 features = 0;
3725
3726 if (hdd_is_memdump_supported())
3727 features |= WIFI_LOGGER_MEMORY_DUMP_SUPPORTED;
3728 features |= WIFI_LOGGER_PER_PACKET_TX_RX_STATUS_SUPPORTED;
3729 features |= WIFI_LOGGER_CONNECT_EVENT_SUPPORTED;
3730 features |= WIFI_LOGGER_WAKE_LOCK_SUPPORTED;
3731
3732 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy,
3733 sizeof(uint32_t) + NLA_HDRLEN + NLMSG_HDRLEN);
3734 if (!reply_skb) {
Jeff Johnson020db452016-06-29 14:37:26 -07003735 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003736 return -ENOMEM;
3737 }
3738
Jeff Johnson020db452016-06-29 14:37:26 -07003739 hdd_notice("Supported logger features: 0x%0x", features);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003740 if (nla_put_u32(reply_skb, QCA_WLAN_VENDOR_ATTR_LOGGER_SUPPORTED,
3741 features)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003742 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003743 kfree_skb(reply_skb);
3744 return -EINVAL;
3745 }
3746
3747 return cfg80211_vendor_cmd_reply(reply_skb);
3748}
3749
3750/**
3751 * wlan_hdd_cfg80211_get_logger_supp_feature() - Get the wifi logger features
3752 * @wiphy: pointer to wireless wiphy structure.
3753 * @wdev: pointer to wireless_dev structure.
3754 * @data: Pointer to the data to be passed via vendor interface
3755 * @data_len:Length of the data to be passed
3756 *
3757 * This is called by userspace to know the supported logger features
3758 *
3759 * Return: Return the Success or Failure code.
3760 */
3761static int
3762wlan_hdd_cfg80211_get_logger_supp_feature(struct wiphy *wiphy,
3763 struct wireless_dev *wdev,
3764 const void *data, int data_len)
3765{
3766 int ret;
3767
3768 cds_ssr_protect(__func__);
3769 ret = __wlan_hdd_cfg80211_get_logger_supp_feature(wiphy, wdev,
3770 data, data_len);
3771 cds_ssr_unprotect(__func__);
3772
3773 return ret;
3774}
3775
Varun Reddy Yeturubbbbe232016-02-29 14:01:57 -08003776#ifdef WLAN_FEATURE_ROAM_OFFLOAD
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003777/**
3778 * wlan_hdd_send_roam_auth_event() - Send the roamed and authorized event
3779 * @hdd_ctx_ptr: pointer to HDD Context.
3780 * @bssid: pointer to bssid of roamed AP.
3781 * @req_rsn_ie: Pointer to request RSN IE
3782 * @req_rsn_len: Length of the request RSN IE
3783 * @rsp_rsn_ie: Pointer to response RSN IE
3784 * @rsp_rsn_len: Length of the response RSN IE
3785 * @roam_info_ptr: Pointer to the roaming related information
3786 *
3787 * This is called when wlan driver needs to send the roaming and
3788 * authorization information after roaming.
3789 *
3790 * The information that would be sent is the request RSN IE, response
3791 * RSN IE and BSSID of the newly roamed AP.
3792 *
3793 * If the Authorized status is authenticated, then additional parameters
3794 * like PTK's KCK and KEK and Replay Counter would also be passed to the
3795 * supplicant.
3796 *
3797 * The supplicant upon receiving this event would ignore the legacy
3798 * cfg80211_roamed call and use the entire information from this event.
3799 * The cfg80211_roamed should still co-exist since the kernel will
3800 * make use of the parameters even if the supplicant ignores it.
3801 *
3802 * Return: Return the Success or Failure code.
3803 */
3804int wlan_hdd_send_roam_auth_event(hdd_context_t *hdd_ctx_ptr, uint8_t *bssid,
3805 uint8_t *req_rsn_ie, uint32_t req_rsn_len, uint8_t *rsp_rsn_ie,
3806 uint32_t rsp_rsn_len, tCsrRoamInfo *roam_info_ptr)
3807{
3808 struct sk_buff *skb = NULL;
Varun Reddy Yeturu16e8f012016-02-03 17:21:09 -08003809 eCsrAuthType auth_type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810 ENTER();
3811
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303812 if (wlan_hdd_validate_context(hdd_ctx_ptr))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003814
Varun Reddy Yeturud351a6c2016-03-16 14:01:00 -07003815 if (!roaming_offload_enabled(hdd_ctx_ptr) ||
Prashanth Bhattabfc25292015-11-05 11:16:21 -08003816 !roam_info_ptr->roamSynchInProgress)
3817 return 0;
3818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819 skb = cfg80211_vendor_event_alloc(hdd_ctx_ptr->wiphy,
3820 NULL,
3821 ETH_ALEN + req_rsn_len + rsp_rsn_len +
3822 sizeof(uint8_t) + SIR_REPLAY_CTR_LEN +
3823 SIR_KCK_KEY_LEN + SIR_KCK_KEY_LEN +
Ravi Joshi277ae9b2015-11-13 11:30:43 -08003824 sizeof(uint8_t) + (8 * NLMSG_HDRLEN),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003825 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_ROAM_AUTH_INDEX,
3826 GFP_KERNEL);
3827
3828 if (!skb) {
Jeff Johnson020db452016-06-29 14:37:26 -07003829 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 return -EINVAL;
3831 }
3832
3833 if (nla_put(skb, QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_BSSID,
3834 ETH_ALEN, bssid) ||
3835 nla_put(skb, QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_REQ_IE,
3836 req_rsn_len, req_rsn_ie) ||
3837 nla_put(skb, QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_RESP_IE,
3838 rsp_rsn_len, rsp_rsn_ie)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003839 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003840 goto nla_put_failure;
3841 }
Jeff Johnson020db452016-06-29 14:37:26 -07003842 hdd_debug("Auth Status = %d", roam_info_ptr->synchAuthStatus);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003843 if (roam_info_ptr->synchAuthStatus ==
3844 CSR_ROAM_AUTH_STATUS_AUTHENTICATED) {
Jeff Johnson020db452016-06-29 14:37:26 -07003845 hdd_debug("Include Auth Params TLV's");
Naveen Rawat14298b92015-11-25 16:27:41 -08003846 if (nla_put_u8(skb,
3847 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_AUTHORIZED, true)) {
3848 hdd_err("nla put fail");
3849 goto nla_put_failure;
3850 }
Varun Reddy Yeturu16e8f012016-02-03 17:21:09 -08003851 auth_type = roam_info_ptr->u.pConnectedProfile->AuthType;
3852 /* if FT or CCKM connection: dont send replay counter */
3853 if (auth_type != eCSR_AUTH_TYPE_FT_RSN &&
3854 auth_type != eCSR_AUTH_TYPE_FT_RSN_PSK &&
3855 auth_type != eCSR_AUTH_TYPE_CCKM_WPA &&
3856 auth_type != eCSR_AUTH_TYPE_CCKM_RSN &&
3857 nla_put(skb,
3858 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_KEY_REPLAY_CTR,
3859 SIR_REPLAY_CTR_LEN,
3860 roam_info_ptr->replay_ctr)) {
3861 hdd_err("non FT/non CCKM connection.");
Naveen Rawat14298b92015-11-25 16:27:41 -08003862 hdd_err("failed to send replay counter.");
3863 goto nla_put_failure;
3864 }
3865 if (nla_put(skb,
3866 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_PTK_KCK,
3867 SIR_KCK_KEY_LEN, roam_info_ptr->kck) ||
3868 nla_put(skb,
3869 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_PTK_KEK,
3870 SIR_KEK_KEY_LEN, roam_info_ptr->kek)) {
3871 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 goto nla_put_failure;
3873 }
3874 } else {
Jeff Johnson020db452016-06-29 14:37:26 -07003875 hdd_debug("No Auth Params TLV's");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876 if (nla_put_u8(skb, QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_AUTHORIZED,
3877 false)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003878 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879 goto nla_put_failure;
3880 }
3881 }
3882
Jeff Johnson020db452016-06-29 14:37:26 -07003883 hdd_debug("Subnet Change Status = %d",
Ravi Joshi277ae9b2015-11-13 11:30:43 -08003884 roam_info_ptr->subnet_change_status);
3885
3886 /*
3887 * Add subnet change status if subnet has changed
3888 * 0 = unchanged
3889 * 1 = changed
3890 * 2 = unknown
3891 */
3892 if (roam_info_ptr->subnet_change_status) {
3893 if (nla_put_u8(skb,
3894 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_SUBNET_STATUS,
3895 roam_info_ptr->subnet_change_status)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003896 hdd_err("nla put fail");
Ravi Joshi277ae9b2015-11-13 11:30:43 -08003897 goto nla_put_failure;
3898 }
3899 }
3900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003901 cfg80211_vendor_event(skb, GFP_KERNEL);
3902 return 0;
3903
3904nla_put_failure:
3905 kfree_skb(skb);
3906 return -EINVAL;
3907}
Varun Reddy Yeturubbbbe232016-02-29 14:01:57 -08003908#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909
3910static const struct nla_policy
3911wlan_hdd_wifi_config_policy[QCA_WLAN_VENDOR_ATTR_CONFIG_MAX + 1] = {
3912
3913 [QCA_WLAN_VENDOR_ATTR_CONFIG_MODULATED_DTIM] = {.type = NLA_U32 },
3914 [QCA_WLAN_VENDOR_ATTR_CONFIG_STATS_AVG_FACTOR] = {.type = NLA_U16 },
3915 [QCA_WLAN_VENDOR_ATTR_CONFIG_GUARD_TIME] = {.type = NLA_U32 },
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05303916 [QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_AVOIDANCE_IND] = {.type = NLA_U8 },
Padma, Santhosh Kumara7119672016-08-16 16:05:14 +05303917 [QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MPDU_AGGREGATION] = {.type = NLA_U8 },
3918 [QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MPDU_AGGREGATION] = {.type = NLA_U8 },
Zhang Qiana3bcbe02016-08-12 16:20:36 +08003919 [QCA_WLAN_VENDOR_ATTR_CONFIG_NON_AGG_RETRY] = {.type = NLA_U8 },
3920 [QCA_WLAN_VENDOR_ATTR_CONFIG_AGG_RETRY] = {.type = NLA_U8 },
3921 [QCA_WLAN_VENDOR_ATTR_CONFIG_MGMT_RETRY] = {.type = NLA_U8 },
3922 [QCA_WLAN_VENDOR_ATTR_CONFIG_CTRL_RETRY] = {.type = NLA_U8 },
3923 [QCA_WLAN_VENDOR_ATTR_CONFIG_PROPAGATION_DELAY] = {.type = NLA_U8 },
Agrawal, Ashishb45599a2016-10-27 14:55:30 +05303924 [QCA_WLAN_VENDOR_ATTR_CONFIG_TX_FAIL_COUNT] = {.type = NLA_U32 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925};
3926
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927/**
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303928 * wlan_hdd_save_default_scan_ies() - API to store the default scan IEs
3929 *
3930 * @adapter: Pointer to HDD adapter
3931 * @ie_data: Pointer to Scan IEs buffer
3932 * @ie_len: Length of Scan IEs
3933 *
3934 * Return: 0 on success; error number otherwise
3935 */
3936static int wlan_hdd_save_default_scan_ies(hdd_adapter_t *adapter,
3937 uint8_t *ie_data, uint8_t ie_len)
3938{
3939 hdd_scaninfo_t *scan_info = NULL;
3940 scan_info = &adapter->scan_info;
3941
3942 if (scan_info->default_scan_ies) {
3943 qdf_mem_free(scan_info->default_scan_ies);
3944 scan_info->default_scan_ies = NULL;
3945 }
3946
3947 scan_info->default_scan_ies = qdf_mem_malloc(ie_len);
3948 if (!scan_info->default_scan_ies)
3949 return -ENOMEM;
3950
3951 memcpy(scan_info->default_scan_ies, ie_data, ie_len);
3952 scan_info->default_scan_ies_len = ie_len;
3953 return 0;
3954}
3955
3956/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 * __wlan_hdd_cfg80211_wifi_configuration_set() - Wifi configuration
3958 * vendor command
3959 *
3960 * @wiphy: wiphy device pointer
3961 * @wdev: wireless device pointer
3962 * @data: Vendor command data buffer
3963 * @data_len: Buffer length
3964 *
3965 * Handles QCA_WLAN_VENDOR_ATTR_CONFIG_MAX.
3966 *
3967 * Return: Error code.
3968 */
3969static int
3970__wlan_hdd_cfg80211_wifi_configuration_set(struct wiphy *wiphy,
3971 struct wireless_dev *wdev,
3972 const void *data,
3973 int data_len)
3974{
3975 struct net_device *dev = wdev->netdev;
3976 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
3977 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
3978 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MAX + 1];
3979 int ret_val = 0;
3980 u32 modulated_dtim;
3981 u16 stats_avg_factor;
3982 u32 guard_time;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05303983 uint8_t set_value;
Krunal Sonie3531942016-04-12 17:43:53 -07003984 u32 ftm_capab;
Dustin Brown10a7b712016-10-07 10:31:16 -07003985 u8 qpower;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303986 QDF_STATUS status;
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05303987 int attr_len;
3988 int access_policy = 0;
3989 char vendor_ie[SIR_MAC_MAX_IE_LENGTH + 2];
3990 bool vendor_ie_present = false, access_policy_present = false;
Deepak Dhamdhereb106ae52016-08-10 20:55:30 +05303991 uint16_t scan_ie_len = 0;
3992 uint8_t *scan_ie;
Padma, Santhosh Kumara7119672016-08-16 16:05:14 +05303993 struct sir_set_tx_rx_aggregation_size request;
3994 QDF_STATUS qdf_status;
Zhang Qiana3bcbe02016-08-12 16:20:36 +08003995 uint8_t retry, delay;
3996 int param_id;
Agrawal, Ashishb45599a2016-10-27 14:55:30 +05303997 uint32_t tx_fail_count;
Deepak Dhamdhereb106ae52016-08-10 20:55:30 +05303998
Jeff Johnson1f61b612016-02-12 16:28:33 -08003999 ENTER_DEV(dev);
4000
Anurag Chouhan6d760662016-02-20 16:05:43 +05304001 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004002 hdd_err("Command not allowed in FTM mode");
4003 return -EPERM;
4004 }
4005
4006 ret_val = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304007 if (ret_val)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009
4010 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_CONFIG_MAX,
4011 data, data_len,
4012 wlan_hdd_wifi_config_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004013 hdd_err("invalid attr");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004014 return -EINVAL;
4015 }
4016
Krunal Sonie3531942016-04-12 17:43:53 -07004017 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_FINE_TIME_MEASUREMENT]) {
4018 ftm_capab = nla_get_u32(tb[
4019 QCA_WLAN_VENDOR_ATTR_CONFIG_FINE_TIME_MEASUREMENT]);
4020 hdd_ctx->config->fine_time_meas_cap =
4021 hdd_ctx->fine_time_meas_cap_target & ftm_capab;
4022 sme_update_fine_time_measurement_capab(hdd_ctx->hHal,
Selvaraj, Sridhar57bb4d02016-08-31 16:14:15 +05304023 adapter->sessionId,
Krunal Sonie3531942016-04-12 17:43:53 -07004024 hdd_ctx->config->fine_time_meas_cap);
4025 hdd_info("FTM capability: user value: 0x%x, target value: 0x%x, final value: 0x%x",
4026 ftm_capab, hdd_ctx->fine_time_meas_cap_target,
4027 hdd_ctx->config->fine_time_meas_cap);
4028 }
4029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MODULATED_DTIM]) {
4031 modulated_dtim = nla_get_u32(
4032 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MODULATED_DTIM]);
4033
4034 status = sme_configure_modulated_dtim(hdd_ctx->hHal,
4035 adapter->sessionId,
4036 modulated_dtim);
4037
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304038 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 ret_val = -EPERM;
4040 }
4041
Kapil Gupta6213c012016-09-02 19:39:09 +05304042 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_QPOWER]) {
4043 qpower = nla_get_u8(
4044 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_QPOWER]);
4045 if (hdd_set_qpower_config(hdd_ctx, adapter, qpower) != 0)
4046 ret_val = -EINVAL;
4047 }
4048
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_STATS_AVG_FACTOR]) {
4050 stats_avg_factor = nla_get_u16(
4051 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_STATS_AVG_FACTOR]);
4052 status = sme_configure_stats_avg_factor(hdd_ctx->hHal,
4053 adapter->sessionId,
4054 stats_avg_factor);
4055
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304056 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057 ret_val = -EPERM;
4058 }
4059
4060
4061 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_GUARD_TIME]) {
4062 guard_time = nla_get_u32(
4063 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_GUARD_TIME]);
4064 status = sme_configure_guard_time(hdd_ctx->hHal,
4065 adapter->sessionId,
4066 guard_time);
4067
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304068 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069 ret_val = -EPERM;
4070 }
4071
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304072 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY_IE_LIST]) {
4073 qdf_mem_zero(&vendor_ie[0], SIR_MAC_MAX_IE_LENGTH + 2);
4074 attr_len = nla_len(
4075 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY_IE_LIST]);
4076 if (attr_len < 0 || attr_len > SIR_MAC_MAX_IE_LENGTH + 2) {
4077 hdd_info("Invalid value. attr_len %d",
4078 attr_len);
4079 return -EINVAL;
4080 }
4081
4082 nla_memcpy(&vendor_ie,
4083 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY_IE_LIST],
4084 attr_len);
4085 vendor_ie_present = true;
4086 hdd_info("Access policy vendor ie present.attr_len %d",
4087 attr_len);
4088 qdf_trace_hex_dump(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
4089 &vendor_ie[0], attr_len);
4090 }
4091
4092 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY]) {
4093 access_policy = (int) nla_get_u32(
4094 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY]);
4095 if ((access_policy < QCA_ACCESS_POLICY_ACCEPT_UNLESS_LISTED) ||
4096 (access_policy >
4097 QCA_ACCESS_POLICY_DENY_UNLESS_LISTED)) {
4098 hdd_info("Invalid value. access_policy %d",
4099 access_policy);
4100 return -EINVAL;
4101 }
4102 access_policy_present = true;
4103 hdd_info("Access policy present. access_policy %d",
4104 access_policy);
4105 }
4106
Zhang Qiana3bcbe02016-08-12 16:20:36 +08004107 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_NON_AGG_RETRY]) {
4108 retry = nla_get_u8(tb[
4109 QCA_WLAN_VENDOR_ATTR_CONFIG_NON_AGG_RETRY]);
4110 retry = retry > CFG_NON_AGG_RETRY_MAX ?
4111 CFG_NON_AGG_RETRY_MAX : retry;
4112 param_id = WMI_PDEV_PARAM_NON_AGG_SW_RETRY_TH;
4113 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4114 retry, PDEV_CMD);
4115 }
4116
4117 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_AGG_RETRY]) {
4118 retry = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_CONFIG_AGG_RETRY]);
4119 retry = retry > CFG_AGG_RETRY_MAX ?
4120 CFG_AGG_RETRY_MAX : retry;
4121
4122 /* Value less than CFG_AGG_RETRY_MIN has side effect to t-put */
4123 retry = ((retry > 0) && (retry < CFG_AGG_RETRY_MIN)) ?
4124 CFG_AGG_RETRY_MIN : retry;
4125 param_id = WMI_PDEV_PARAM_AGG_SW_RETRY_TH;
4126 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4127 retry, PDEV_CMD);
4128 }
4129
4130 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MGMT_RETRY]) {
4131 retry = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MGMT_RETRY]);
4132 retry = retry > CFG_MGMT_RETRY_MAX ?
4133 CFG_MGMT_RETRY_MAX : retry;
4134 param_id = WMI_PDEV_PARAM_MGMT_RETRY_LIMIT;
4135 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4136 retry, PDEV_CMD);
4137 }
4138
4139 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_CTRL_RETRY]) {
4140 retry = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_CONFIG_CTRL_RETRY]);
4141 retry = retry > CFG_CTRL_RETRY_MAX ?
4142 CFG_CTRL_RETRY_MAX : retry;
4143 param_id = WMI_PDEV_PARAM_CTRL_RETRY_LIMIT;
4144 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4145 retry, PDEV_CMD);
4146 }
4147
4148 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_PROPAGATION_DELAY]) {
4149 delay = nla_get_u8(tb[
4150 QCA_WLAN_VENDOR_ATTR_CONFIG_PROPAGATION_DELAY]);
4151 delay = delay > CFG_PROPAGATION_DELAY_MAX ?
4152 CFG_PROPAGATION_DELAY_MAX : delay;
4153 param_id = WMI_PDEV_PARAM_PROPAGATION_DELAY;
4154 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4155 delay, PDEV_CMD);
4156 }
4157
Agrawal, Ashishb45599a2016-10-27 14:55:30 +05304158 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_FAIL_COUNT]) {
4159 tx_fail_count = nla_get_u32(
4160 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_FAIL_COUNT]);
4161 if (tx_fail_count) {
4162 status = sme_update_tx_fail_cnt_threshold(hdd_ctx->hHal,
4163 adapter->sessionId, tx_fail_count);
4164 if (QDF_STATUS_SUCCESS != status) {
4165 hdd_info("sme_update_tx_fail_cnt_threshold (err=%d)",
4166 status);
4167 return -EINVAL;
4168 }
4169 }
4170 }
4171
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304172 if (vendor_ie_present && access_policy_present) {
4173 if (access_policy == QCA_ACCESS_POLICY_DENY_UNLESS_LISTED) {
4174 access_policy =
4175 WLAN_HDD_VENDOR_IE_ACCESS_ALLOW_IF_LISTED;
Selvaraj, Sridharac4fcf32016-09-28 12:57:32 +05304176 } else {
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304177 access_policy = WLAN_HDD_VENDOR_IE_ACCESS_NONE;
Selvaraj, Sridharac4fcf32016-09-28 12:57:32 +05304178 }
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304179
Selvaraj, Sridharac4fcf32016-09-28 12:57:32 +05304180 hdd_info("calling sme_update_access_policy_vendor_ie");
4181 status = sme_update_access_policy_vendor_ie(hdd_ctx->hHal,
4182 adapter->sessionId, &vendor_ie[0],
4183 access_policy);
4184 if (QDF_STATUS_SUCCESS != status) {
4185 hdd_info("Failed to set vendor ie and access policy.");
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304186 return -EINVAL;
4187 }
4188 }
4189
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05304190 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_AVOIDANCE_IND]) {
4191 set_value = nla_get_u8(
4192 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_AVOIDANCE_IND]);
4193 hdd_info("set_value: %d", set_value);
4194 ret_val = hdd_enable_disable_ca_event(hdd_ctx, set_value);
4195 }
4196
Deepak Dhamdhereb106ae52016-08-10 20:55:30 +05304197 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_DEFAULT_IES]) {
4198 scan_ie_len = nla_len(
4199 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_DEFAULT_IES]);
4200 hdd_info("Received default scan IE of len %d session %d device mode %d",
4201 scan_ie_len, adapter->sessionId,
4202 adapter->device_mode);
4203 if (scan_ie_len && (scan_ie_len <= MAX_DEFAULT_SCAN_IE_LEN)) {
4204 scan_ie = (uint8_t *) nla_data(tb
4205 [QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_DEFAULT_IES]);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304206
4207 if (wlan_hdd_save_default_scan_ies(adapter, scan_ie,
4208 scan_ie_len))
4209 hdd_err("Failed to save default scan IEs");
4210
Deepak Dhamdhereb106ae52016-08-10 20:55:30 +05304211 if (adapter->device_mode == QDF_STA_MODE) {
4212 status = sme_set_default_scan_ie(hdd_ctx->hHal,
4213 adapter->sessionId, scan_ie,
4214 scan_ie_len);
4215 if (QDF_STATUS_SUCCESS != status)
4216 ret_val = -EPERM;
4217 }
4218 } else
4219 ret_val = -EPERM;
4220 }
Padma, Santhosh Kumara7119672016-08-16 16:05:14 +05304221
4222 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MPDU_AGGREGATION] ||
4223 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MPDU_AGGREGATION]) {
4224 /* if one is specified, both must be specified */
4225 if (!tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MPDU_AGGREGATION] ||
4226 !tb[QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MPDU_AGGREGATION]) {
4227 hdd_err("Both TX and RX MPDU Aggregation required");
4228 return -EINVAL;
4229 }
4230
4231 request.tx_aggregation_size = nla_get_u8(
4232 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MPDU_AGGREGATION]);
4233 request.rx_aggregation_size = nla_get_u8(
4234 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MPDU_AGGREGATION]);
4235 request.vdev_id = adapter->sessionId;
4236
4237 if (request.tx_aggregation_size >=
4238 CFG_TX_AGGREGATION_SIZE_MIN &&
4239 request.tx_aggregation_size <=
4240 CFG_TX_AGGREGATION_SIZE_MAX &&
4241 request.rx_aggregation_size >=
4242 CFG_RX_AGGREGATION_SIZE_MIN &&
4243 request.rx_aggregation_size <=
4244 CFG_RX_AGGREGATION_SIZE_MAX) {
4245 qdf_status = wma_set_tx_rx_aggregation_size(&request);
4246 if (qdf_status != QDF_STATUS_SUCCESS) {
4247 hdd_err("failed to set aggr sizes err %d",
4248 qdf_status);
4249 ret_val = -EPERM;
4250 }
4251 } else {
4252 hdd_err("TX %d RX %d MPDU aggr size not in range",
4253 request.tx_aggregation_size,
4254 request.rx_aggregation_size);
4255 ret_val = -EINVAL;
4256 }
4257 }
4258
Selvaraj, Sridharac4fcf32016-09-28 12:57:32 +05304259 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED]) {
4260 uint8_t ignore_assoc_disallowed;
4261
4262 ignore_assoc_disallowed
4263 = nla_get_u8(tb[
4264 QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED]);
4265 hdd_info("Set ignore_assoc_disallowed value - %d",
4266 ignore_assoc_disallowed);
4267 if ((ignore_assoc_disallowed <
4268 QCA_IGNORE_ASSOC_DISALLOWED_DISABLE) ||
4269 (ignore_assoc_disallowed >
4270 QCA_IGNORE_ASSOC_DISALLOWED_ENABLE))
4271 return -EPERM;
4272
4273 sme_update_session_param(hdd_ctx->hHal,
4274 adapter->sessionId,
4275 SIR_PARAM_IGNORE_ASSOC_DISALLOWED,
4276 ignore_assoc_disallowed);
4277 }
4278
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004279 return ret_val;
4280}
4281
4282/**
4283 * wlan_hdd_cfg80211_wifi_configuration_set() - Wifi configuration
4284 * vendor command
4285 *
4286 * @wiphy: wiphy device pointer
4287 * @wdev: wireless device pointer
4288 * @data: Vendor command data buffer
4289 * @data_len: Buffer length
4290 *
4291 * Handles QCA_WLAN_VENDOR_ATTR_CONFIG_MAX.
4292 *
4293 * Return: EOK or other error codes.
4294 */
4295static int wlan_hdd_cfg80211_wifi_configuration_set(struct wiphy *wiphy,
4296 struct wireless_dev *wdev,
4297 const void *data,
4298 int data_len)
4299{
4300 int ret;
4301
4302 cds_ssr_protect(__func__);
4303 ret = __wlan_hdd_cfg80211_wifi_configuration_set(wiphy, wdev,
4304 data, data_len);
4305 cds_ssr_unprotect(__func__);
4306
4307 return ret;
4308}
4309
4310static const struct
4311nla_policy
4312qca_wlan_vendor_wifi_logger_start_policy
4313[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_START_MAX + 1] = {
4314 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_RING_ID]
4315 = {.type = NLA_U32 },
4316 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_VERBOSE_LEVEL]
4317 = {.type = NLA_U32 },
4318 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_FLAGS]
4319 = {.type = NLA_U32 },
4320};
4321
4322/**
4323 * __wlan_hdd_cfg80211_wifi_logger_start() - This function is used to enable
4324 * or disable the collection of packet statistics from the firmware
4325 * @wiphy: WIPHY structure pointer
4326 * @wdev: Wireless device structure pointer
4327 * @data: Pointer to the data received
4328 * @data_len: Length of the data received
4329 *
4330 * This function enables or disables the collection of packet statistics from
4331 * the firmware
4332 *
4333 * Return: 0 on success and errno on failure
4334 */
4335static int __wlan_hdd_cfg80211_wifi_logger_start(struct wiphy *wiphy,
4336 struct wireless_dev *wdev,
4337 const void *data,
4338 int data_len)
4339{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304340 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
4342 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_START_MAX + 1];
4343 struct sir_wifi_start_log start_log;
4344
Jeff Johnson1f61b612016-02-12 16:28:33 -08004345 ENTER_DEV(wdev->netdev);
4346
Anurag Chouhan6d760662016-02-20 16:05:43 +05304347 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348 hdd_err("Command not allowed in FTM mode");
4349 return -EPERM;
4350 }
4351
4352 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304353 if (status)
4354 return status;
4355
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004356
4357 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_START_MAX,
4358 data, data_len,
4359 qca_wlan_vendor_wifi_logger_start_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004360 hdd_err("Invalid attribute");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004361 return -EINVAL;
4362 }
4363
4364 /* Parse and fetch ring id */
4365 if (!tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_RING_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004366 hdd_err("attr ATTR failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367 return -EINVAL;
4368 }
4369 start_log.ring_id = nla_get_u32(
4370 tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_RING_ID]);
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -08004371 hdd_info("Ring ID=%d", start_log.ring_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004372
4373 /* Parse and fetch verbose level */
4374 if (!tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_VERBOSE_LEVEL]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004375 hdd_err("attr verbose_level failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004376 return -EINVAL;
4377 }
4378 start_log.verbose_level = nla_get_u32(
4379 tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_VERBOSE_LEVEL]);
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -08004380 hdd_info("verbose_level=%d", start_log.verbose_level);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381
4382 /* Parse and fetch flag */
4383 if (!tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_FLAGS]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004384 hdd_err("attr flag failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 return -EINVAL;
4386 }
Poddar, Siddartheefe3482016-09-21 18:12:59 +05304387 start_log.is_iwpriv_command = nla_get_u32(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004388 tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_FLAGS]);
Poddar, Siddartheefe3482016-09-21 18:12:59 +05304389 hdd_info("is_iwpriv_command =%d", start_log.is_iwpriv_command);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004390
Poddar, Siddarth176c4362016-10-03 12:25:00 +05304391 /* size is buff size which can be set using iwpriv command*/
4392 start_log.size = 0;
4393
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394 cds_set_ring_log_level(start_log.ring_id, start_log.verbose_level);
4395
4396 if (start_log.ring_id == RING_ID_WAKELOCK) {
4397 /* Start/stop wakelock events */
4398 if (start_log.verbose_level > WLAN_LOG_LEVEL_OFF)
4399 cds_set_wakelock_logging(true);
4400 else
4401 cds_set_wakelock_logging(false);
4402 return 0;
4403 }
4404
4405 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304406 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004407 hdd_err("sme_wifi_start_logger failed(err=%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004408 status);
4409 return -EINVAL;
4410 }
4411 return 0;
4412}
4413
4414/**
4415 * wlan_hdd_cfg80211_wifi_logger_start() - Wrapper function used to enable
4416 * or disable the collection of packet statistics from the firmware
4417 * @wiphy: WIPHY structure pointer
4418 * @wdev: Wireless device structure pointer
4419 * @data: Pointer to the data received
4420 * @data_len: Length of the data received
4421 *
4422 * This function is used to enable or disable the collection of packet
4423 * statistics from the firmware
4424 *
4425 * Return: 0 on success and errno on failure
4426 */
4427static int wlan_hdd_cfg80211_wifi_logger_start(struct wiphy *wiphy,
4428 struct wireless_dev *wdev,
4429 const void *data,
4430 int data_len)
4431{
4432 int ret = 0;
4433
4434 cds_ssr_protect(__func__);
4435 ret = __wlan_hdd_cfg80211_wifi_logger_start(wiphy,
4436 wdev, data, data_len);
4437 cds_ssr_unprotect(__func__);
4438
4439 return ret;
4440}
4441
4442static const struct
4443nla_policy
4444qca_wlan_vendor_wifi_logger_get_ring_data_policy
4445[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_MAX + 1] = {
4446 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_ID]
4447 = {.type = NLA_U32 },
4448};
4449
4450/**
4451 * __wlan_hdd_cfg80211_wifi_logger_get_ring_data() - Flush per packet stats
4452 * @wiphy: WIPHY structure pointer
4453 * @wdev: Wireless device structure pointer
4454 * @data: Pointer to the data received
4455 * @data_len: Length of the data received
4456 *
4457 * This function is used to flush or retrieve the per packet statistics from
4458 * the driver
4459 *
4460 * Return: 0 on success and errno on failure
4461 */
4462static int __wlan_hdd_cfg80211_wifi_logger_get_ring_data(struct wiphy *wiphy,
4463 struct wireless_dev *wdev,
4464 const void *data,
4465 int data_len)
4466{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304467 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004468 uint32_t ring_id;
4469 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
4470 struct nlattr *tb
4471 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_MAX + 1];
4472
Jeff Johnson1f61b612016-02-12 16:28:33 -08004473 ENTER_DEV(wdev->netdev);
4474
Anurag Chouhan6d760662016-02-20 16:05:43 +05304475 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004476 hdd_err("Command not allowed in FTM mode");
4477 return -EPERM;
4478 }
4479
4480 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304481 if (status)
4482 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483
4484 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_MAX,
4485 data, data_len,
4486 qca_wlan_vendor_wifi_logger_get_ring_data_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004487 hdd_err("Invalid attribute");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004488 return -EINVAL;
4489 }
4490
4491 /* Parse and fetch ring id */
4492 if (!tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004493 hdd_err("attr ATTR failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004494 return -EINVAL;
4495 }
4496
4497 ring_id = nla_get_u32(
4498 tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_ID]);
4499
4500 if (ring_id == RING_ID_PER_PACKET_STATS) {
4501 wlan_logging_set_per_pkt_stats();
Jeff Johnson77848112016-06-29 14:52:06 -07004502 hdd_notice("Flushing/Retrieving packet stats");
Sreelakshmi Konamkic3815ba2016-08-18 12:01:57 +05304503 } else if (ring_id == RING_ID_DRIVER_DEBUG) {
4504 /*
4505 * As part of DRIVER ring ID, flush both driver and fw logs.
4506 * For other Ring ID's driver doesn't have any rings to flush
4507 */
4508 hdd_notice("Bug report triggered by framework");
4509
4510 status = cds_flush_logs(WLAN_LOG_TYPE_NON_FATAL,
4511 WLAN_LOG_INDICATOR_FRAMEWORK,
4512 WLAN_LOG_REASON_CODE_UNUSED,
4513 true, false);
4514 if (QDF_STATUS_SUCCESS != status) {
4515 hdd_err("Failed to trigger bug report");
4516 return -EINVAL;
4517 }
4518 } else {
4519 wlan_report_log_completion(WLAN_LOG_TYPE_NON_FATAL,
4520 WLAN_LOG_INDICATOR_FRAMEWORK,
4521 WLAN_LOG_REASON_CODE_UNUSED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004522 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004523 return 0;
4524}
4525
4526/**
4527 * wlan_hdd_cfg80211_wifi_logger_get_ring_data() - Wrapper to flush packet stats
4528 * @wiphy: WIPHY structure pointer
4529 * @wdev: Wireless device structure pointer
4530 * @data: Pointer to the data received
4531 * @data_len: Length of the data received
4532 *
4533 * This function is used to flush or retrieve the per packet statistics from
4534 * the driver
4535 *
4536 * Return: 0 on success and errno on failure
4537 */
4538static int wlan_hdd_cfg80211_wifi_logger_get_ring_data(struct wiphy *wiphy,
4539 struct wireless_dev *wdev,
4540 const void *data,
4541 int data_len)
4542{
4543 int ret = 0;
4544
4545 cds_ssr_protect(__func__);
4546 ret = __wlan_hdd_cfg80211_wifi_logger_get_ring_data(wiphy,
4547 wdev, data, data_len);
4548 cds_ssr_unprotect(__func__);
4549
4550 return ret;
4551}
4552
4553#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
4554/**
4555 * hdd_map_req_id_to_pattern_id() - map request id to pattern id
4556 * @hdd_ctx: HDD context
4557 * @request_id: [input] request id
4558 * @pattern_id: [output] pattern id
4559 *
4560 * This function loops through request id to pattern id array
4561 * if the slot is available, store the request id and return pattern id
4562 * if entry exists, return the pattern id
4563 *
4564 * Return: 0 on success and errno on failure
4565 */
4566static int hdd_map_req_id_to_pattern_id(hdd_context_t *hdd_ctx,
4567 uint32_t request_id,
4568 uint8_t *pattern_id)
4569{
4570 uint32_t i;
4571
4572 mutex_lock(&hdd_ctx->op_ctx.op_lock);
4573 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
4574 if (hdd_ctx->op_ctx.op_table[i].request_id == MAX_REQUEST_ID) {
4575 hdd_ctx->op_ctx.op_table[i].request_id = request_id;
4576 *pattern_id = hdd_ctx->op_ctx.op_table[i].pattern_id;
4577 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4578 return 0;
4579 } else if (hdd_ctx->op_ctx.op_table[i].request_id ==
4580 request_id) {
4581 *pattern_id = hdd_ctx->op_ctx.op_table[i].pattern_id;
4582 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4583 return 0;
4584 }
4585 }
4586 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4587 return -EINVAL;
4588}
4589
4590/**
4591 * hdd_unmap_req_id_to_pattern_id() - unmap request id to pattern id
4592 * @hdd_ctx: HDD context
4593 * @request_id: [input] request id
4594 * @pattern_id: [output] pattern id
4595 *
4596 * This function loops through request id to pattern id array
4597 * reset request id to 0 (slot available again) and
4598 * return pattern id
4599 *
4600 * Return: 0 on success and errno on failure
4601 */
4602static int hdd_unmap_req_id_to_pattern_id(hdd_context_t *hdd_ctx,
4603 uint32_t request_id,
4604 uint8_t *pattern_id)
4605{
4606 uint32_t i;
4607
4608 mutex_lock(&hdd_ctx->op_ctx.op_lock);
4609 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
4610 if (hdd_ctx->op_ctx.op_table[i].request_id == request_id) {
4611 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
4612 *pattern_id = hdd_ctx->op_ctx.op_table[i].pattern_id;
4613 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4614 return 0;
4615 }
4616 }
4617 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4618 return -EINVAL;
4619}
4620
4621
4622/*
4623 * define short names for the global vendor params
4624 * used by __wlan_hdd_cfg80211_offloaded_packets()
4625 */
4626#define PARAM_MAX QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_MAX
4627#define PARAM_REQUEST_ID \
4628 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_REQUEST_ID
4629#define PARAM_CONTROL \
4630 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_SENDING_CONTROL
4631#define PARAM_IP_PACKET \
4632 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_IP_PACKET_DATA
4633#define PARAM_SRC_MAC_ADDR \
4634 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_SRC_MAC_ADDR
4635#define PARAM_DST_MAC_ADDR \
4636 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_DST_MAC_ADDR
4637#define PARAM_PERIOD QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_PERIOD
4638
4639/**
4640 * wlan_hdd_add_tx_ptrn() - add tx pattern
4641 * @adapter: adapter pointer
4642 * @hdd_ctx: hdd context
4643 * @tb: nl attributes
4644 *
4645 * This function reads the NL attributes and forms a AddTxPtrn message
4646 * posts it to SME.
4647 *
4648 */
4649static int
4650wlan_hdd_add_tx_ptrn(hdd_adapter_t *adapter, hdd_context_t *hdd_ctx,
4651 struct nlattr **tb)
4652{
4653 struct sSirAddPeriodicTxPtrn *add_req;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304654 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655 uint32_t request_id, ret, len;
4656 uint8_t pattern_id = 0;
Anurag Chouhan6d760662016-02-20 16:05:43 +05304657 struct qdf_mac_addr dst_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004658 uint16_t eth_type = htons(ETH_P_IP);
4659
4660 if (!hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Jeff Johnson77848112016-06-29 14:52:06 -07004661 hdd_err("Not in Connected state!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 return -ENOTSUPP;
4663 }
4664
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304665 add_req = qdf_mem_malloc(sizeof(*add_req));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004666 if (!add_req) {
Jeff Johnson77848112016-06-29 14:52:06 -07004667 hdd_err("memory allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004668 return -ENOMEM;
4669 }
4670
4671 /* Parse and fetch request Id */
4672 if (!tb[PARAM_REQUEST_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004673 hdd_err("attr request id failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674 goto fail;
4675 }
4676
4677 request_id = nla_get_u32(tb[PARAM_REQUEST_ID]);
4678 if (request_id == MAX_REQUEST_ID) {
Jeff Johnson77848112016-06-29 14:52:06 -07004679 hdd_err("request_id cannot be MAX");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004680 return -EINVAL;
4681 }
Jeff Johnson77848112016-06-29 14:52:06 -07004682 hdd_notice("Request Id: %u", request_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004683
4684 if (!tb[PARAM_PERIOD]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004685 hdd_err("attr period failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004686 goto fail;
4687 }
4688 add_req->usPtrnIntervalMs = nla_get_u32(tb[PARAM_PERIOD]);
Jeff Johnson77848112016-06-29 14:52:06 -07004689 hdd_notice("Period: %u ms", add_req->usPtrnIntervalMs);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004690 if (add_req->usPtrnIntervalMs == 0) {
Jeff Johnson77848112016-06-29 14:52:06 -07004691 hdd_err("Invalid interval zero, return failure");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004692 goto fail;
4693 }
4694
4695 if (!tb[PARAM_SRC_MAC_ADDR]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004696 hdd_err("attr source mac address failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004697 goto fail;
4698 }
Srinivas Girigowda31896552015-11-18 22:59:52 -08004699 nla_memcpy(add_req->mac_address.bytes, tb[PARAM_SRC_MAC_ADDR],
Anurag Chouhan6d760662016-02-20 16:05:43 +05304700 QDF_MAC_ADDR_SIZE);
Jeff Johnson77848112016-06-29 14:52:06 -07004701 hdd_notice("input src mac address: "MAC_ADDRESS_STR,
Srinivas Girigowda31896552015-11-18 22:59:52 -08004702 MAC_ADDR_ARRAY(add_req->mac_address.bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004703
Anurag Chouhanc5548422016-02-24 18:33:27 +05304704 if (!qdf_is_macaddr_equal(&add_req->mac_address,
Srinivas Girigowda31896552015-11-18 22:59:52 -08004705 &adapter->macAddressCurrent)) {
4706 hdd_err("input src mac address and connected ap bssid are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004707 goto fail;
4708 }
4709
4710 if (!tb[PARAM_DST_MAC_ADDR]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004711 hdd_err("attr dst mac address failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712 goto fail;
4713 }
Anurag Chouhan6d760662016-02-20 16:05:43 +05304714 nla_memcpy(dst_addr.bytes, tb[PARAM_DST_MAC_ADDR], QDF_MAC_ADDR_SIZE);
Jeff Johnson77848112016-06-29 14:52:06 -07004715 hdd_notice("input dst mac address: "MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004716 MAC_ADDR_ARRAY(dst_addr.bytes));
4717
4718 if (!tb[PARAM_IP_PACKET]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004719 hdd_err("attr ip packet failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004720 goto fail;
4721 }
4722 add_req->ucPtrnSize = nla_len(tb[PARAM_IP_PACKET]);
Jeff Johnson77848112016-06-29 14:52:06 -07004723 hdd_notice("IP packet len: %u", add_req->ucPtrnSize);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004724
4725 if (add_req->ucPtrnSize < 0 ||
4726 add_req->ucPtrnSize > (PERIODIC_TX_PTRN_MAX_SIZE -
4727 ETH_HLEN)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004728 hdd_err("Invalid IP packet len: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 add_req->ucPtrnSize);
4730 goto fail;
4731 }
4732
4733 len = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304734 qdf_mem_copy(&add_req->ucPattern[0], dst_addr.bytes, QDF_MAC_ADDR_SIZE);
Anurag Chouhan6d760662016-02-20 16:05:43 +05304735 len += QDF_MAC_ADDR_SIZE;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304736 qdf_mem_copy(&add_req->ucPattern[len], add_req->mac_address.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304737 QDF_MAC_ADDR_SIZE);
4738 len += QDF_MAC_ADDR_SIZE;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304739 qdf_mem_copy(&add_req->ucPattern[len], &eth_type, 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 len += 2;
4741
4742 /*
4743 * This is the IP packet, add 14 bytes Ethernet (802.3) header
4744 * ------------------------------------------------------------
4745 * | 14 bytes Ethernet (802.3) header | IP header and payload |
4746 * ------------------------------------------------------------
4747 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304748 qdf_mem_copy(&add_req->ucPattern[len],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004749 nla_data(tb[PARAM_IP_PACKET]),
4750 add_req->ucPtrnSize);
4751 add_req->ucPtrnSize += len;
4752
4753 ret = hdd_map_req_id_to_pattern_id(hdd_ctx, request_id, &pattern_id);
4754 if (ret) {
Jeff Johnson77848112016-06-29 14:52:06 -07004755 hdd_warn("req id to pattern id failed (ret=%d)", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004756 goto fail;
4757 }
4758 add_req->ucPtrnId = pattern_id;
Jeff Johnson77848112016-06-29 14:52:06 -07004759 hdd_notice("pattern id: %d", add_req->ucPtrnId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004760
4761 status = sme_add_periodic_tx_ptrn(hdd_ctx->hHal, add_req);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304762 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004763 hdd_err("sme_add_periodic_tx_ptrn failed (err=%d)", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764 goto fail;
4765 }
4766
4767 EXIT();
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304768 qdf_mem_free(add_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769 return 0;
4770
4771fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304772 qdf_mem_free(add_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004773 return -EINVAL;
4774}
4775
4776/**
4777 * wlan_hdd_del_tx_ptrn() - delete tx pattern
4778 * @adapter: adapter pointer
4779 * @hdd_ctx: hdd context
4780 * @tb: nl attributes
4781 *
4782 * This function reads the NL attributes and forms a DelTxPtrn message
4783 * posts it to SME.
4784 *
4785 */
4786static int
4787wlan_hdd_del_tx_ptrn(hdd_adapter_t *adapter, hdd_context_t *hdd_ctx,
4788 struct nlattr **tb)
4789{
4790 struct sSirDelPeriodicTxPtrn *del_req;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304791 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004792 uint32_t request_id, ret;
4793 uint8_t pattern_id = 0;
4794
4795 /* Parse and fetch request Id */
4796 if (!tb[PARAM_REQUEST_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004797 hdd_err("attr request id failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004798 return -EINVAL;
4799 }
4800 request_id = nla_get_u32(tb[PARAM_REQUEST_ID]);
4801 if (request_id == MAX_REQUEST_ID) {
Jeff Johnson77848112016-06-29 14:52:06 -07004802 hdd_err("request_id cannot be MAX");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004803 return -EINVAL;
4804 }
4805
4806 ret = hdd_unmap_req_id_to_pattern_id(hdd_ctx, request_id, &pattern_id);
4807 if (ret) {
Jeff Johnson77848112016-06-29 14:52:06 -07004808 hdd_warn("req id to pattern id failed (ret=%d)", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004809 return -EINVAL;
4810 }
4811
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304812 del_req = qdf_mem_malloc(sizeof(*del_req));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004813 if (!del_req) {
Jeff Johnson77848112016-06-29 14:52:06 -07004814 hdd_err("memory allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004815 return -ENOMEM;
4816 }
4817
Anurag Chouhanc5548422016-02-24 18:33:27 +05304818 qdf_copy_macaddr(&del_req->mac_address, &adapter->macAddressCurrent);
Srinivas Girigowdaa5bba7a2015-11-18 22:44:36 -08004819 hdd_info(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(del_req->mac_address.bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820 del_req->ucPtrnId = pattern_id;
Jeff Johnson77848112016-06-29 14:52:06 -07004821 hdd_notice("Request Id: %u Pattern id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004822 request_id, del_req->ucPtrnId);
4823
4824 status = sme_del_periodic_tx_ptrn(hdd_ctx->hHal, del_req);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304825 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004826 hdd_err("sme_del_periodic_tx_ptrn failed (err=%d)", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827 goto fail;
4828 }
4829
4830 EXIT();
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304831 qdf_mem_free(del_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004832 return 0;
4833
4834fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304835 qdf_mem_free(del_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004836 return -EINVAL;
4837}
4838
4839
4840/**
4841 * __wlan_hdd_cfg80211_offloaded_packets() - send offloaded packets
4842 * @wiphy: Pointer to wireless phy
4843 * @wdev: Pointer to wireless device
4844 * @data: Pointer to data
4845 * @data_len: Data length
4846 *
4847 * Return: 0 on success, negative errno on failure
4848 */
4849static int
4850__wlan_hdd_cfg80211_offloaded_packets(struct wiphy *wiphy,
4851 struct wireless_dev *wdev,
4852 const void *data,
4853 int data_len)
4854{
4855 struct net_device *dev = wdev->netdev;
4856 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
4857 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
4858 struct nlattr *tb[PARAM_MAX + 1];
4859 uint8_t control;
4860 int ret;
4861 static const struct nla_policy policy[PARAM_MAX + 1] = {
4862 [PARAM_REQUEST_ID] = { .type = NLA_U32 },
4863 [PARAM_CONTROL] = { .type = NLA_U32 },
4864 [PARAM_SRC_MAC_ADDR] = { .type = NLA_BINARY,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304865 .len = QDF_MAC_ADDR_SIZE },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004866 [PARAM_DST_MAC_ADDR] = { .type = NLA_BINARY,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304867 .len = QDF_MAC_ADDR_SIZE },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 [PARAM_PERIOD] = { .type = NLA_U32 },
4869 };
4870
Jeff Johnson1f61b612016-02-12 16:28:33 -08004871 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004872
Anurag Chouhan6d760662016-02-20 16:05:43 +05304873 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004874 hdd_err("Command not allowed in FTM mode");
4875 return -EPERM;
4876 }
4877
4878 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304879 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004880 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004881
4882 if (!sme_is_feature_supported_by_fw(WLAN_PERIODIC_TX_PTRN)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004883 hdd_err("Periodic Tx Pattern Offload feature is not supported in FW!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004884 return -ENOTSUPP;
4885 }
4886
4887 if (nla_parse(tb, PARAM_MAX, data, data_len, policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004888 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889 return -EINVAL;
4890 }
4891
4892 if (!tb[PARAM_CONTROL]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004893 hdd_err("attr control failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004894 return -EINVAL;
4895 }
4896 control = nla_get_u32(tb[PARAM_CONTROL]);
Jeff Johnson77848112016-06-29 14:52:06 -07004897 hdd_notice("Control: %d", control);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004898
4899 if (control == WLAN_START_OFFLOADED_PACKETS)
4900 return wlan_hdd_add_tx_ptrn(adapter, hdd_ctx, tb);
4901 else if (control == WLAN_STOP_OFFLOADED_PACKETS)
4902 return wlan_hdd_del_tx_ptrn(adapter, hdd_ctx, tb);
4903 else {
Jeff Johnson77848112016-06-29 14:52:06 -07004904 hdd_err("Invalid control: %d", control);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004905 return -EINVAL;
4906 }
4907}
4908
4909/*
4910 * done with short names for the global vendor params
4911 * used by __wlan_hdd_cfg80211_offloaded_packets()
4912 */
4913#undef PARAM_MAX
4914#undef PARAM_REQUEST_ID
4915#undef PARAM_CONTROL
4916#undef PARAM_IP_PACKET
4917#undef PARAM_SRC_MAC_ADDR
4918#undef PARAM_DST_MAC_ADDR
4919#undef PARAM_PERIOD
4920
4921/**
4922 * wlan_hdd_cfg80211_offloaded_packets() - Wrapper to offload packets
4923 * @wiphy: wiphy structure pointer
4924 * @wdev: Wireless device structure pointer
4925 * @data: Pointer to the data received
4926 * @data_len: Length of @data
4927 *
4928 * Return: 0 on success; errno on failure
4929 */
4930static int wlan_hdd_cfg80211_offloaded_packets(struct wiphy *wiphy,
4931 struct wireless_dev *wdev,
4932 const void *data,
4933 int data_len)
4934{
4935 int ret = 0;
4936
4937 cds_ssr_protect(__func__);
4938 ret = __wlan_hdd_cfg80211_offloaded_packets(wiphy,
4939 wdev, data, data_len);
4940 cds_ssr_unprotect(__func__);
4941
4942 return ret;
4943}
4944#endif
4945
4946/*
4947 * define short names for the global vendor params
4948 * used by __wlan_hdd_cfg80211_monitor_rssi()
4949 */
4950#define PARAM_MAX QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_MAX
4951#define PARAM_REQUEST_ID QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_REQUEST_ID
4952#define PARAM_CONTROL QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_CONTROL
4953#define PARAM_MIN_RSSI QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_MIN_RSSI
4954#define PARAM_MAX_RSSI QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_MAX_RSSI
4955
4956/**
4957 * __wlan_hdd_cfg80211_monitor_rssi() - monitor rssi
4958 * @wiphy: Pointer to wireless phy
4959 * @wdev: Pointer to wireless device
4960 * @data: Pointer to data
4961 * @data_len: Data length
4962 *
4963 * Return: 0 on success, negative errno on failure
4964 */
4965static int
4966__wlan_hdd_cfg80211_monitor_rssi(struct wiphy *wiphy,
4967 struct wireless_dev *wdev,
4968 const void *data,
4969 int data_len)
4970{
4971 struct net_device *dev = wdev->netdev;
4972 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
4973 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
4974 struct nlattr *tb[PARAM_MAX + 1];
4975 struct rssi_monitor_req req;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304976 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977 int ret;
4978 uint32_t control;
4979 static const struct nla_policy policy[PARAM_MAX + 1] = {
4980 [PARAM_REQUEST_ID] = { .type = NLA_U32 },
4981 [PARAM_CONTROL] = { .type = NLA_U32 },
4982 [PARAM_MIN_RSSI] = { .type = NLA_S8 },
4983 [PARAM_MAX_RSSI] = { .type = NLA_S8 },
4984 };
4985
Jeff Johnson1f61b612016-02-12 16:28:33 -08004986 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004987
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05304988 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
4989 hdd_err("invalid session id: %d", adapter->sessionId);
4990 return -EINVAL;
4991 }
4992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004993 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304994 if (ret)
4995 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004996
4997 if (!hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Jeff Johnson77848112016-06-29 14:52:06 -07004998 hdd_err("Not in Connected state!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004999 return -ENOTSUPP;
5000 }
5001
5002 if (nla_parse(tb, PARAM_MAX, data, data_len, policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005003 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005004 return -EINVAL;
5005 }
5006
5007 if (!tb[PARAM_REQUEST_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005008 hdd_err("attr request id failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009 return -EINVAL;
5010 }
5011
5012 if (!tb[PARAM_CONTROL]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005013 hdd_err("attr control failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005014 return -EINVAL;
5015 }
5016
5017 req.request_id = nla_get_u32(tb[PARAM_REQUEST_ID]);
5018 req.session_id = adapter->sessionId;
5019 control = nla_get_u32(tb[PARAM_CONTROL]);
5020
5021 if (control == QCA_WLAN_RSSI_MONITORING_START) {
5022 req.control = true;
5023 if (!tb[PARAM_MIN_RSSI]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005024 hdd_err("attr min rssi failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005025 return -EINVAL;
5026 }
5027
5028 if (!tb[PARAM_MAX_RSSI]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005029 hdd_err("attr max rssi failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005030 return -EINVAL;
5031 }
5032
5033 req.min_rssi = nla_get_s8(tb[PARAM_MIN_RSSI]);
5034 req.max_rssi = nla_get_s8(tb[PARAM_MAX_RSSI]);
5035
5036 if (!(req.min_rssi < req.max_rssi)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005037 hdd_warn("min_rssi: %d must be less than max_rssi: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038 req.min_rssi, req.max_rssi);
5039 return -EINVAL;
5040 }
Jeff Johnson77848112016-06-29 14:52:06 -07005041 hdd_notice("Min_rssi: %d Max_rssi: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042 req.min_rssi, req.max_rssi);
5043
5044 } else if (control == QCA_WLAN_RSSI_MONITORING_STOP)
5045 req.control = false;
5046 else {
Jeff Johnson77848112016-06-29 14:52:06 -07005047 hdd_err("Invalid control cmd: %d", control);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005048 return -EINVAL;
5049 }
Jeff Johnson77848112016-06-29 14:52:06 -07005050 hdd_notice("Request Id: %u Session_id: %d Control: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005051 req.request_id, req.session_id, req.control);
5052
5053 status = sme_set_rssi_monitoring(hdd_ctx->hHal, &req);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305054 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005055 hdd_err("sme_set_rssi_monitoring failed(err=%d)", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 return -EINVAL;
5057 }
5058
5059 return 0;
5060}
5061
5062/*
5063 * done with short names for the global vendor params
5064 * used by __wlan_hdd_cfg80211_monitor_rssi()
5065 */
5066#undef PARAM_MAX
5067#undef PARAM_CONTROL
5068#undef PARAM_REQUEST_ID
5069#undef PARAM_MAX_RSSI
5070#undef PARAM_MIN_RSSI
5071
5072/**
5073 * wlan_hdd_cfg80211_monitor_rssi() - SSR wrapper to rssi monitoring
5074 * @wiphy: wiphy structure pointer
5075 * @wdev: Wireless device structure pointer
5076 * @data: Pointer to the data received
5077 * @data_len: Length of @data
5078 *
5079 * Return: 0 on success; errno on failure
5080 */
5081static int
5082wlan_hdd_cfg80211_monitor_rssi(struct wiphy *wiphy, struct wireless_dev *wdev,
5083 const void *data, int data_len)
5084{
5085 int ret;
5086
5087 cds_ssr_protect(__func__);
5088 ret = __wlan_hdd_cfg80211_monitor_rssi(wiphy, wdev, data, data_len);
5089 cds_ssr_unprotect(__func__);
5090
5091 return ret;
5092}
5093
5094/**
5095 * hdd_rssi_threshold_breached() - rssi breached NL event
5096 * @hddctx: HDD context
5097 * @data: rssi breached event data
5098 *
5099 * This function reads the rssi breached event %data and fill in the skb with
5100 * NL attributes and send up the NL event.
5101 *
5102 * Return: none
5103 */
5104void hdd_rssi_threshold_breached(void *hddctx,
5105 struct rssi_breach_event *data)
5106{
5107 hdd_context_t *hdd_ctx = hddctx;
5108 struct sk_buff *skb;
5109
5110 ENTER();
5111
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05305112 if (wlan_hdd_validate_context(hdd_ctx))
5113 return;
5114 if (!data) {
Jeff Johnson77848112016-06-29 14:52:06 -07005115 hdd_err("data is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 return;
5117 }
5118
5119 skb = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
5120 NULL,
5121 EXTSCAN_EVENT_BUF_SIZE + NLMSG_HDRLEN,
5122 QCA_NL80211_VENDOR_SUBCMD_MONITOR_RSSI_INDEX,
5123 GFP_KERNEL);
5124
5125 if (!skb) {
Jeff Johnson77848112016-06-29 14:52:06 -07005126 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005127 return;
5128 }
5129
Jeff Johnson77848112016-06-29 14:52:06 -07005130 hdd_notice("Req Id: %u Current rssi: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005131 data->request_id, data->curr_rssi);
Jeff Johnson77848112016-06-29 14:52:06 -07005132 hdd_notice("Current BSSID: "MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133 MAC_ADDR_ARRAY(data->curr_bssid.bytes));
5134
5135 if (nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_REQUEST_ID,
5136 data->request_id) ||
5137 nla_put(skb, QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_CUR_BSSID,
5138 sizeof(data->curr_bssid), data->curr_bssid.bytes) ||
5139 nla_put_s8(skb, QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_CUR_RSSI,
5140 data->curr_rssi)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005141 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 goto fail;
5143 }
5144
5145 cfg80211_vendor_event(skb, GFP_KERNEL);
5146 return;
5147
5148fail:
5149 kfree_skb(skb);
5150 return;
5151}
5152
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05305153static const struct nla_policy
5154ns_offload_set_policy[QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_MAX + 1] = {
5155 [QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_FLAG] = {.type = NLA_U8},
5156};
5157
5158/**
5159 * __wlan_hdd_cfg80211_set_ns_offload() - enable/disable NS offload
5160 * @wiphy: Pointer to wireless phy
5161 * @wdev: Pointer to wireless device
5162 * @data: Pointer to data
5163 * @data_len: Length of @data
5164 *
5165 * Return: 0 on success, negative errno on failure
5166 */
5167static int
5168__wlan_hdd_cfg80211_set_ns_offload(struct wiphy *wiphy,
5169 struct wireless_dev *wdev,
5170 const void *data, int data_len)
5171{
5172 int status;
5173 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_MAX + 1];
5174 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Dustin Brownd8279d22016-09-07 14:52:57 -07005175 struct net_device *dev = wdev->netdev;
5176 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05305177
5178 ENTER_DEV(wdev->netdev);
5179
5180 status = wlan_hdd_validate_context(pHddCtx);
5181 if (0 != status)
5182 return status;
5183 if (!pHddCtx->config->fhostNSOffload) {
5184 hdd_err("ND Offload not supported");
5185 return -EINVAL;
5186 }
5187
5188 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_MAX,
5189 (struct nlattr *)data,
5190 data_len, ns_offload_set_policy)) {
5191 hdd_err("nla_parse failed");
5192 return -EINVAL;
5193 }
5194
5195 if (!tb[QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_FLAG]) {
5196 hdd_err("ND Offload flag attribute not present");
5197 return -EINVAL;
5198 }
5199
5200 pHddCtx->ns_offload_enable =
5201 nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_FLAG]);
5202
Dustin Brownd8279d22016-09-07 14:52:57 -07005203 /* update ns offload in case it is already enabled/disabled */
5204 hdd_conf_ns_offload(adapter, pHddCtx->ns_offload_enable);
5205
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05305206 return 0;
5207}
5208
5209/**
5210 * wlan_hdd_cfg80211_set_ns_offload() - enable/disable NS offload
5211 * @wiphy: pointer to wireless wiphy structure.
5212 * @wdev: pointer to wireless_dev structure.
5213 * @data: Pointer to the data to be passed via vendor interface
5214 * @data_len:Length of the data to be passed
5215 *
5216 * Return: Return the Success or Failure code.
5217 */
5218static int wlan_hdd_cfg80211_set_ns_offload(struct wiphy *wiphy,
5219 struct wireless_dev *wdev,
5220 const void *data, int data_len)
5221{
5222 int ret;
5223
5224 cds_ssr_protect(__func__);
5225 ret = __wlan_hdd_cfg80211_set_ns_offload(wiphy, wdev, data, data_len);
5226 cds_ssr_unprotect(__func__);
5227
5228 return ret;
5229}
5230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231/** __wlan_hdd_cfg80211_get_preferred_freq_list() - get preferred frequency list
5232 * @wiphy: Pointer to wireless phy
5233 * @wdev: Pointer to wireless device
5234 * @data: Pointer to data
5235 * @data_len: Data length
5236 *
5237 * This function return the preferred frequency list generated by the policy
5238 * manager.
5239 *
5240 * Return: success or failure code
5241 */
5242static int __wlan_hdd_cfg80211_get_preferred_freq_list(struct wiphy *wiphy,
5243 struct wireless_dev
5244 *wdev, const void *data,
5245 int data_len)
5246{
5247 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5248 int i, ret = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305249 QDF_STATUS status;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05305250 uint8_t pcl[QDF_MAX_NUM_CHAN], weight_list[QDF_MAX_NUM_CHAN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005251 uint32_t pcl_len = 0;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05305252 uint32_t freq_list[QDF_MAX_NUM_CHAN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253 enum cds_con_mode intf_mode;
5254 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_MAX + 1];
5255 struct sk_buff *reply_skb;
5256
Jeff Johnson1f61b612016-02-12 16:28:33 -08005257 ENTER_DEV(wdev->netdev);
5258
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005259 ret = wlan_hdd_validate_context(hdd_ctx);
5260 if (ret)
5261 return -EINVAL;
5262
5263 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_MAX,
5264 data, data_len, NULL)) {
5265 hdd_err("Invalid ATTR");
5266 return -EINVAL;
5267 }
5268
5269 if (!tb[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]) {
5270 hdd_err("attr interface type failed");
5271 return -EINVAL;
5272 }
5273
5274 intf_mode = nla_get_u32(tb
5275 [QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]);
5276
5277 if (intf_mode < CDS_STA_MODE || intf_mode >= CDS_MAX_NUM_OF_MODE) {
5278 hdd_err("Invalid interface type");
5279 return -EINVAL;
5280 }
5281
5282 hdd_debug("Userspace requested pref freq list");
5283
Manishekar Chandrasekaran7009f252016-04-21 19:14:15 +05305284 status = cds_get_pcl(intf_mode, pcl, &pcl_len,
5285 weight_list, QDF_ARRAY_SIZE(weight_list));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305286 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 hdd_err("Get pcl failed");
5288 return -EINVAL;
5289 }
5290
5291 /* convert channel number to frequency */
5292 for (i = 0; i < pcl_len; i++) {
5293 if (pcl[i] <= ARRAY_SIZE(hdd_channels_2_4_ghz))
5294 freq_list[i] =
5295 ieee80211_channel_to_frequency(pcl[i],
Dustin Browna30892e2016-10-12 17:28:36 -07005296 NL80211_BAND_2GHZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297 else
5298 freq_list[i] =
5299 ieee80211_channel_to_frequency(pcl[i],
Dustin Browna30892e2016-10-12 17:28:36 -07005300 NL80211_BAND_5GHZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005301 }
5302
5303 /* send the freq_list back to supplicant */
5304 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(u32) +
5305 sizeof(u32) *
5306 pcl_len +
5307 NLMSG_HDRLEN);
5308
5309 if (!reply_skb) {
5310 hdd_err("Allocate reply_skb failed");
5311 return -EINVAL;
5312 }
5313
5314 if (nla_put_u32(reply_skb,
5315 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
5316 intf_mode) ||
5317 nla_put(reply_skb,
5318 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST,
5319 sizeof(uint32_t) * pcl_len,
5320 freq_list)) {
5321 hdd_err("nla put fail");
5322 kfree_skb(reply_skb);
5323 return -EINVAL;
5324 }
5325
5326 return cfg80211_vendor_cmd_reply(reply_skb);
5327}
5328
5329/** wlan_hdd_cfg80211_get_preferred_freq_list () - get preferred frequency list
5330 * @wiphy: Pointer to wireless phy
5331 * @wdev: Pointer to wireless device
5332 * @data: Pointer to data
5333 * @data_len: Data length
5334 *
5335 * This function return the preferred frequency list generated by the policy
5336 * manager.
5337 *
5338 * Return: success or failure code
5339 */
5340static int wlan_hdd_cfg80211_get_preferred_freq_list(struct wiphy *wiphy,
5341 struct wireless_dev
5342 *wdev, const void *data,
5343 int data_len)
5344{
5345 int ret = 0;
5346
5347 cds_ssr_protect(__func__);
5348 ret = __wlan_hdd_cfg80211_get_preferred_freq_list(wiphy, wdev,
5349 data, data_len);
5350 cds_ssr_unprotect(__func__);
5351
5352 return ret;
5353}
5354
5355/**
5356 * __wlan_hdd_cfg80211_set_probable_oper_channel () - set probable channel
5357 * @wiphy: Pointer to wireless phy
5358 * @wdev: Pointer to wireless device
5359 * @data: Pointer to data
5360 * @data_len: Data length
5361 *
5362 * Return: 0 on success, negative errno on failure
5363 */
5364static int __wlan_hdd_cfg80211_set_probable_oper_channel(struct wiphy *wiphy,
5365 struct wireless_dev *wdev,
5366 const void *data,
5367 int data_len)
5368{
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05305369 struct net_device *ndev = wdev->netdev;
5370 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005371 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5372 int ret = 0;
5373 enum cds_con_mode intf_mode;
5374 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_MAX + 1];
5375 uint32_t channel_hint;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005376
Jeff Johnson1f61b612016-02-12 16:28:33 -08005377 ENTER_DEV(ndev);
5378
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005379 ret = wlan_hdd_validate_context(hdd_ctx);
5380 if (ret)
5381 return ret;
5382
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005383 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_MAX,
5384 data, data_len, NULL)) {
5385 hdd_err("Invalid ATTR");
5386 return -EINVAL;
5387 }
5388
5389 if (!tb[QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE]) {
5390 hdd_err("attr interface type failed");
5391 return -EINVAL;
5392 }
5393
5394 intf_mode = nla_get_u32(tb
5395 [QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE]);
5396
5397 if (intf_mode < CDS_STA_MODE || intf_mode >= CDS_MAX_NUM_OF_MODE) {
5398 hdd_err("Invalid interface type");
5399 return -EINVAL;
5400 }
5401
5402 if (!tb[QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ]) {
5403 hdd_err("attr probable freq failed");
5404 return -EINVAL;
5405 }
5406
5407 channel_hint = cds_freq_to_chan(nla_get_u32(tb
5408 [QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ]));
5409
5410 /* check pcl table */
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08005411 if (!cds_allow_concurrency(intf_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412 channel_hint, HW_MODE_20_MHZ)) {
5413 hdd_err("Set channel hint failed due to concurrency check");
5414 return -EINVAL;
5415 }
5416
Krunal Soni09e55032016-06-07 10:06:55 -07005417 if (0 != wlan_hdd_check_remain_on_channel(adapter))
5418 hdd_warn("Remain On Channel Pending");
5419
Krunal Soni3091bcc2016-06-23 12:28:21 -07005420 ret = qdf_reset_connection_update();
5421 if (!QDF_IS_STATUS_SUCCESS(ret))
5422 hdd_err("clearing event failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005423
Krunal Soni3091bcc2016-06-23 12:28:21 -07005424 ret = cds_current_connections_update(adapter->sessionId,
5425 channel_hint,
5426 SIR_UPDATE_REASON_SET_OPER_CHAN);
5427 if (QDF_STATUS_E_FAILURE == ret) {
5428 /* return in the failure case */
5429 hdd_err("ERROR: connections update failed!!");
5430 return -EINVAL;
5431 }
5432
5433 if (QDF_STATUS_SUCCESS == ret) {
5434 /*
5435 * Success is the only case for which we expect hw mode
5436 * change to take place, hence we need to wait.
5437 * For any other return value it should be a pass
5438 * through
5439 */
5440 ret = qdf_wait_for_connection_update();
5441 if (!QDF_IS_STATUS_SUCCESS(ret)) {
5442 hdd_err("ERROR: qdf wait for event failed!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005443 return -EINVAL;
5444 }
5445
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005446 }
5447
5448 return 0;
5449}
5450
5451/**
5452 * wlan_hdd_cfg80211_set_probable_oper_channel () - set probable channel
5453 * @wiphy: Pointer to wireless phy
5454 * @wdev: Pointer to wireless device
5455 * @data: Pointer to data
5456 * @data_len: Data length
5457 *
5458 * Return: 0 on success, negative errno on failure
5459 */
5460static int wlan_hdd_cfg80211_set_probable_oper_channel(struct wiphy *wiphy,
5461 struct wireless_dev *wdev,
5462 const void *data,
5463 int data_len)
5464{
5465 int ret = 0;
5466
5467 cds_ssr_protect(__func__);
5468 ret = __wlan_hdd_cfg80211_set_probable_oper_channel(wiphy, wdev,
5469 data, data_len);
5470 cds_ssr_unprotect(__func__);
5471
5472 return ret;
5473}
5474
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305475static const struct
5476nla_policy
5477qca_wlan_vendor_attr_policy[QCA_WLAN_VENDOR_ATTR_MAX+1] = {
5478 [QCA_WLAN_VENDOR_ATTR_MAC_ADDR] = { .type = NLA_UNSPEC },
5479};
5480
5481/**
5482 * __wlan_hdd_cfg80211_get_link_properties() - Get link properties
5483 * @wiphy: WIPHY structure pointer
5484 * @wdev: Wireless device structure pointer
5485 * @data: Pointer to the data received
5486 * @data_len: Length of the data received
5487 *
5488 * This function is used to get link properties like nss, rate flags and
5489 * operating frequency for the active connection with the given peer.
5490 *
5491 * Return: 0 on success and errno on failure
5492 */
5493static int __wlan_hdd_cfg80211_get_link_properties(struct wiphy *wiphy,
5494 struct wireless_dev *wdev,
5495 const void *data,
5496 int data_len)
5497{
5498 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5499 struct net_device *dev = wdev->netdev;
5500 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5501 hdd_station_ctx_t *hdd_sta_ctx;
5502 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX+1];
Anurag Chouhan6d760662016-02-20 16:05:43 +05305503 uint8_t peer_mac[QDF_MAC_ADDR_SIZE];
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305504 uint32_t sta_id;
5505 struct sk_buff *reply_skb;
5506 uint32_t rate_flags = 0;
5507 uint8_t nss;
5508 uint8_t final_rate_flags = 0;
5509 uint32_t freq;
5510
Jeff Johnson1f61b612016-02-12 16:28:33 -08005511 ENTER_DEV(dev);
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305512
Anurag Chouhan6d760662016-02-20 16:05:43 +05305513 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305514 hdd_err("Command not allowed in FTM mode");
5515 return -EPERM;
5516 }
5517
5518 if (0 != wlan_hdd_validate_context(hdd_ctx))
5519 return -EINVAL;
5520
5521 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_MAX, data, data_len,
5522 qca_wlan_vendor_attr_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005523 hdd_err("Invalid attribute");
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305524 return -EINVAL;
5525 }
5526
5527 if (!tb[QCA_WLAN_VENDOR_ATTR_MAC_ADDR]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005528 hdd_err("Attribute peerMac not provided for mode=%d",
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305529 adapter->device_mode);
5530 return -EINVAL;
5531 }
5532
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305533 qdf_mem_copy(peer_mac, nla_data(tb[QCA_WLAN_VENDOR_ATTR_MAC_ADDR]),
Anurag Chouhan6d760662016-02-20 16:05:43 +05305534 QDF_MAC_ADDR_SIZE);
Jeff Johnson77848112016-06-29 14:52:06 -07005535 hdd_notice("peerMac="MAC_ADDRESS_STR" for device_mode:%d",
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305536 MAC_ADDR_ARRAY(peer_mac), adapter->device_mode);
5537
Krunal Sonib4326f22016-03-10 13:05:51 -08005538 if (adapter->device_mode == QDF_STA_MODE ||
5539 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305540 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5541 if ((hdd_sta_ctx->conn_info.connState !=
5542 eConnectionState_Associated) ||
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305543 qdf_mem_cmp(hdd_sta_ctx->conn_info.bssId.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305544 peer_mac, QDF_MAC_ADDR_SIZE)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005545 hdd_err("Not Associated to mac "MAC_ADDRESS_STR,
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305546 MAC_ADDR_ARRAY(peer_mac));
5547 return -EINVAL;
5548 }
5549
5550 nss = hdd_sta_ctx->conn_info.nss;
5551 freq = cds_chan_to_freq(
5552 hdd_sta_ctx->conn_info.operationChannel);
5553 rate_flags = hdd_sta_ctx->conn_info.rate_flags;
Krunal Sonib4326f22016-03-10 13:05:51 -08005554 } else if (adapter->device_mode == QDF_P2P_GO_MODE ||
5555 adapter->device_mode == QDF_SAP_MODE) {
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305556
5557 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5558 if (adapter->aStaInfo[sta_id].isUsed &&
Anurag Chouhanc5548422016-02-24 18:33:27 +05305559 !qdf_is_macaddr_broadcast(
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305560 &adapter->aStaInfo[sta_id].macAddrSTA) &&
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305561 !qdf_mem_cmp(
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305562 &adapter->aStaInfo[sta_id].macAddrSTA.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305563 peer_mac, QDF_MAC_ADDR_SIZE))
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305564 break;
5565 }
5566
5567 if (WLAN_MAX_STA_COUNT == sta_id) {
Jeff Johnson77848112016-06-29 14:52:06 -07005568 hdd_err("No active peer with mac="MAC_ADDRESS_STR,
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305569 MAC_ADDR_ARRAY(peer_mac));
5570 return -EINVAL;
5571 }
5572
5573 nss = adapter->aStaInfo[sta_id].nss;
5574 freq = cds_chan_to_freq(
5575 (WLAN_HDD_GET_AP_CTX_PTR(adapter))->operatingChannel);
5576 rate_flags = adapter->aStaInfo[sta_id].rate_flags;
5577 } else {
Jeff Johnson77848112016-06-29 14:52:06 -07005578 hdd_err("Not Associated! with mac "MAC_ADDRESS_STR,
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305579 MAC_ADDR_ARRAY(peer_mac));
5580 return -EINVAL;
5581 }
5582
5583 if (!(rate_flags & eHAL_TX_RATE_LEGACY)) {
5584 if (rate_flags & eHAL_TX_RATE_VHT80) {
5585 final_rate_flags |= RATE_INFO_FLAGS_VHT_MCS;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005586#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)) && !defined(WITH_BACKPORTS)
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305587 final_rate_flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005588#endif
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305589 } else if (rate_flags & eHAL_TX_RATE_VHT40) {
5590 final_rate_flags |= RATE_INFO_FLAGS_VHT_MCS;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005591#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)) && !defined(WITH_BACKPORTS)
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305592 final_rate_flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005593#endif
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305594 } else if (rate_flags & eHAL_TX_RATE_VHT20) {
5595 final_rate_flags |= RATE_INFO_FLAGS_VHT_MCS;
5596 } else if (rate_flags &
5597 (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40)) {
5598 final_rate_flags |= RATE_INFO_FLAGS_MCS;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005599#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)) && !defined(WITH_BACKPORTS)
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305600 if (rate_flags & eHAL_TX_RATE_HT40)
5601 final_rate_flags |=
5602 RATE_INFO_FLAGS_40_MHZ_WIDTH;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005603#endif
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305604 }
5605
5606 if (rate_flags & eHAL_TX_RATE_SGI) {
5607 if (!(final_rate_flags & RATE_INFO_FLAGS_VHT_MCS))
5608 final_rate_flags |= RATE_INFO_FLAGS_MCS;
5609 final_rate_flags |= RATE_INFO_FLAGS_SHORT_GI;
5610 }
5611 }
5612
5613 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy,
5614 sizeof(u8) + sizeof(u8) + sizeof(u32) + NLMSG_HDRLEN);
5615
5616 if (NULL == reply_skb) {
Jeff Johnson77848112016-06-29 14:52:06 -07005617 hdd_err("getLinkProperties: skb alloc failed");
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305618 return -EINVAL;
5619 }
5620
5621 if (nla_put_u8(reply_skb,
5622 QCA_WLAN_VENDOR_ATTR_LINK_PROPERTIES_NSS,
5623 nss) ||
5624 nla_put_u8(reply_skb,
5625 QCA_WLAN_VENDOR_ATTR_LINK_PROPERTIES_RATE_FLAGS,
5626 final_rate_flags) ||
5627 nla_put_u32(reply_skb,
5628 QCA_WLAN_VENDOR_ATTR_LINK_PROPERTIES_FREQ,
5629 freq)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005630 hdd_err("nla_put failed");
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305631 kfree_skb(reply_skb);
5632 return -EINVAL;
5633 }
5634
5635 return cfg80211_vendor_cmd_reply(reply_skb);
5636}
5637
5638/**
5639 * wlan_hdd_cfg80211_get_link_properties() - Wrapper function to get link
5640 * properties.
5641 * @wiphy: WIPHY structure pointer
5642 * @wdev: Wireless device structure pointer
5643 * @data: Pointer to the data received
5644 * @data_len: Length of the data received
5645 *
5646 * This function is used to get link properties like nss, rate flags and
5647 * operating frequency for the active connection with the given peer.
5648 *
5649 * Return: 0 on success and errno on failure
5650 */
5651static int wlan_hdd_cfg80211_get_link_properties(struct wiphy *wiphy,
5652 struct wireless_dev *wdev,
5653 const void *data,
5654 int data_len)
5655{
5656 int ret = 0;
5657
5658 cds_ssr_protect(__func__);
5659 ret = __wlan_hdd_cfg80211_get_link_properties(wiphy,
5660 wdev, data, data_len);
5661 cds_ssr_unprotect(__func__);
5662
5663 return ret;
5664}
5665
Peng Xu278d0122015-09-24 16:34:17 -07005666static const struct
5667nla_policy
5668qca_wlan_vendor_ota_test_policy
5669[QCA_WLAN_VENDOR_ATTR_OTA_TEST_MAX + 1] = {
5670 [QCA_WLAN_VENDOR_ATTR_OTA_TEST_ENABLE] = {.type = NLA_U8 },
5671};
5672
5673/**
5674 * __wlan_hdd_cfg80211_set_ota_test () - enable/disable OTA test
5675 * @wiphy: Pointer to wireless phy
5676 * @wdev: Pointer to wireless device
5677 * @data: Pointer to data
5678 * @data_len: Data length
5679 *
5680 * Return: 0 on success, negative errno on failure
5681 */
5682static int __wlan_hdd_cfg80211_set_ota_test(struct wiphy *wiphy,
5683 struct wireless_dev *wdev,
5684 const void *data,
5685 int data_len)
5686{
5687 struct net_device *dev = wdev->netdev;
5688 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5689 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
5690 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5691 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OTA_TEST_MAX + 1];
5692 uint8_t ota_enable = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305693 QDF_STATUS status;
Peng Xu278d0122015-09-24 16:34:17 -07005694 uint32_t current_roam_state;
5695
Jeff Johnson1f61b612016-02-12 16:28:33 -08005696 ENTER_DEV(dev);
5697
Anurag Chouhan6d760662016-02-20 16:05:43 +05305698 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Peng Xu278d0122015-09-24 16:34:17 -07005699 hdd_err("Command not allowed in FTM mode");
5700 return -EPERM;
5701 }
5702
5703 if (0 != wlan_hdd_validate_context(hdd_ctx))
5704 return -EINVAL;
5705
5706 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OTA_TEST_MAX,
5707 data, data_len,
5708 qca_wlan_vendor_ota_test_policy)) {
5709 hdd_err("invalid attr");
5710 return -EINVAL;
5711 }
5712
5713 if (!tb[QCA_WLAN_VENDOR_ATTR_OTA_TEST_ENABLE]) {
5714 hdd_err("attr ota test failed");
5715 return -EINVAL;
5716 }
5717
5718 ota_enable = nla_get_u8(
5719 tb[QCA_WLAN_VENDOR_ATTR_OTA_TEST_ENABLE]);
5720
5721 hdd_info(" OTA test enable = %d", ota_enable);
5722 if (ota_enable != 1) {
5723 hdd_err("Invalid value, only enable test mode is supported!");
5724 return -EINVAL;
5725 }
5726
5727 current_roam_state =
5728 sme_get_current_roam_state(hal, adapter->sessionId);
5729 status = sme_stop_roaming(hal, adapter->sessionId,
5730 eCsrHddIssued);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305731 if (status != QDF_STATUS_SUCCESS) {
Peng Xu278d0122015-09-24 16:34:17 -07005732 hdd_err("Enable/Disable roaming failed");
5733 return -EINVAL;
5734 }
5735
5736 status = sme_ps_enable_disable(hal, adapter->sessionId,
5737 SME_PS_DISABLE);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305738 if (status != QDF_STATUS_SUCCESS) {
Peng Xu278d0122015-09-24 16:34:17 -07005739 hdd_err("Enable/Disable power save failed");
5740 /* restore previous roaming setting */
5741 if (current_roam_state == eCSR_ROAMING_STATE_JOINING ||
5742 current_roam_state == eCSR_ROAMING_STATE_JOINED)
5743 status = sme_start_roaming(hal, adapter->sessionId,
5744 eCsrHddIssued);
5745 else if (current_roam_state == eCSR_ROAMING_STATE_STOP ||
5746 current_roam_state == eCSR_ROAMING_STATE_IDLE)
5747 status = sme_stop_roaming(hal, adapter->sessionId,
5748 eCsrHddIssued);
5749
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305750 if (status != QDF_STATUS_SUCCESS)
Peng Xu278d0122015-09-24 16:34:17 -07005751 hdd_err("Restoring roaming state failed");
5752
5753 return -EINVAL;
5754 }
5755
5756
5757 return 0;
5758}
5759
5760/**
5761 * wlan_hdd_cfg80211_set_ota_test () - Enable or disable OTA test
5762 * @wiphy: Pointer to wireless phy
5763 * @wdev: Pointer to wireless device
5764 * @data: Pointer to data
5765 * @data_len: Data length
5766 *
5767 * Return: 0 on success, negative errno on failure
5768 */
5769static int wlan_hdd_cfg80211_set_ota_test(struct wiphy *wiphy,
5770 struct wireless_dev *wdev,
5771 const void *data,
5772 int data_len)
5773{
5774 int ret = 0;
5775
5776 cds_ssr_protect(__func__);
5777 ret = __wlan_hdd_cfg80211_set_ota_test(wiphy, wdev, data, data_len);
5778 cds_ssr_unprotect(__func__);
5779
5780 return ret;
5781}
5782
Peng Xu4d67c8f2015-10-16 16:02:26 -07005783/**
5784 * __wlan_hdd_cfg80211_txpower_scale () - txpower scaling
5785 * @wiphy: Pointer to wireless phy
5786 * @wdev: Pointer to wireless device
5787 * @data: Pointer to data
5788 * @data_len: Data length
5789 *
5790 * Return: 0 on success, negative errno on failure
5791 */
5792static int __wlan_hdd_cfg80211_txpower_scale(struct wiphy *wiphy,
5793 struct wireless_dev *wdev,
5794 const void *data,
5795 int data_len)
5796{
5797 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5798 struct net_device *dev = wdev->netdev;
Peng Xu62c8c432016-05-09 15:23:02 -07005799 hdd_adapter_t *adapter;
5800 int ret;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005801 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_MAX + 1];
5802 uint8_t scale_value;
Peng Xu62c8c432016-05-09 15:23:02 -07005803 QDF_STATUS status;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005804
Jeff Johnson1f61b612016-02-12 16:28:33 -08005805 ENTER_DEV(dev);
5806
Peng Xu4d67c8f2015-10-16 16:02:26 -07005807 ret = wlan_hdd_validate_context(hdd_ctx);
5808 if (ret)
5809 return ret;
5810
5811 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5812
5813 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_MAX,
5814 data, data_len, NULL)) {
5815 hdd_err("Invalid ATTR");
5816 return -EINVAL;
5817 }
5818
5819 if (!tb[QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE]) {
5820 hdd_err("attr tx power scale failed");
5821 return -EINVAL;
5822 }
5823
5824 scale_value = nla_get_u8(tb
5825 [QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE]);
5826
5827 if (scale_value > MAX_TXPOWER_SCALE) {
5828 hdd_err("Invalid tx power scale level");
5829 return -EINVAL;
5830 }
5831
Peng Xu62c8c432016-05-09 15:23:02 -07005832 status = wma_set_tx_power_scale(adapter->sessionId, scale_value);
Peng Xu4d67c8f2015-10-16 16:02:26 -07005833
Peng Xu62c8c432016-05-09 15:23:02 -07005834 if (QDF_STATUS_SUCCESS != status) {
Peng Xu4d67c8f2015-10-16 16:02:26 -07005835 hdd_err("Set tx power scale failed");
5836 return -EINVAL;
5837 }
5838
5839 return 0;
5840}
5841
5842/**
5843 * wlan_hdd_cfg80211_txpower_scale () - txpower scaling
5844 * @wiphy: Pointer to wireless phy
5845 * @wdev: Pointer to wireless device
5846 * @data: Pointer to data
5847 * @data_len: Data length
5848 *
5849 * Return: 0 on success, negative errno on failure
5850 */
5851static int wlan_hdd_cfg80211_txpower_scale(struct wiphy *wiphy,
5852 struct wireless_dev *wdev,
5853 const void *data,
5854 int data_len)
5855{
Peng Xu62c8c432016-05-09 15:23:02 -07005856 int ret;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005857
5858 cds_ssr_protect(__func__);
5859 ret = __wlan_hdd_cfg80211_txpower_scale(wiphy, wdev,
5860 data, data_len);
5861 cds_ssr_unprotect(__func__);
5862
5863 return ret;
5864}
5865
5866/**
5867 * __wlan_hdd_cfg80211_txpower_scale_decr_db () - txpower scaling
5868 * @wiphy: Pointer to wireless phy
5869 * @wdev: Pointer to wireless device
5870 * @data: Pointer to data
5871 * @data_len: Data length
5872 *
5873 * Return: 0 on success, negative errno on failure
5874 */
5875static int __wlan_hdd_cfg80211_txpower_scale_decr_db(struct wiphy *wiphy,
5876 struct wireless_dev *wdev,
5877 const void *data,
5878 int data_len)
5879{
5880 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5881 struct net_device *dev = wdev->netdev;
Peng Xu62c8c432016-05-09 15:23:02 -07005882 hdd_adapter_t *adapter;
5883 int ret;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005884 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_DECR_DB_MAX + 1];
5885 uint8_t scale_value;
Peng Xu62c8c432016-05-09 15:23:02 -07005886 QDF_STATUS status;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005887
Jeff Johnson1f61b612016-02-12 16:28:33 -08005888 ENTER_DEV(dev);
5889
Peng Xu4d67c8f2015-10-16 16:02:26 -07005890 ret = wlan_hdd_validate_context(hdd_ctx);
5891 if (ret)
5892 return ret;
5893
5894 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5895
5896 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_DECR_DB_MAX,
5897 data, data_len, NULL)) {
5898 hdd_err("Invalid ATTR");
5899 return -EINVAL;
5900 }
5901
5902 if (!tb[QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_DECR_DB]) {
5903 hdd_err("attr tx power decrease db value failed");
5904 return -EINVAL;
5905 }
5906
5907 scale_value = nla_get_u8(tb
5908 [QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_DECR_DB]);
5909
Peng Xu62c8c432016-05-09 15:23:02 -07005910 status = wma_set_tx_power_scale_decr_db(adapter->sessionId,
5911 scale_value);
Peng Xu4d67c8f2015-10-16 16:02:26 -07005912
Peng Xu62c8c432016-05-09 15:23:02 -07005913 if (QDF_STATUS_SUCCESS != status) {
Peng Xu4d67c8f2015-10-16 16:02:26 -07005914 hdd_err("Set tx power decrease db failed");
5915 return -EINVAL;
5916 }
5917
5918 return 0;
5919}
5920
5921/**
5922 * wlan_hdd_cfg80211_txpower_scale_decr_db () - txpower scaling
5923 * @wiphy: Pointer to wireless phy
5924 * @wdev: Pointer to wireless device
5925 * @data: Pointer to data
5926 * @data_len: Data length
5927 *
5928 * Return: 0 on success, negative errno on failure
5929 */
5930static int wlan_hdd_cfg80211_txpower_scale_decr_db(struct wiphy *wiphy,
5931 struct wireless_dev *wdev,
5932 const void *data,
5933 int data_len)
5934{
Peng Xu62c8c432016-05-09 15:23:02 -07005935 int ret;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005936
5937 cds_ssr_protect(__func__);
5938 ret = __wlan_hdd_cfg80211_txpower_scale_decr_db(wiphy, wdev,
5939 data, data_len);
5940 cds_ssr_unprotect(__func__);
5941
5942 return ret;
5943}
Peng Xu8fdaa492016-06-22 10:20:47 -07005944
5945/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305946 * __wlan_hdd_cfg80211_conditional_chan_switch() - Conditional channel switch
5947 * @wiphy: Pointer to wireless phy
5948 * @wdev: Pointer to wireless device
5949 * @data: Pointer to data
5950 * @data_len: Data length
5951 *
5952 * Processes the conditional channel switch request and invokes the helper
5953 * APIs to process the channel switch request.
5954 *
5955 * Return: 0 on success, negative errno on failure
5956 */
5957static int __wlan_hdd_cfg80211_conditional_chan_switch(struct wiphy *wiphy,
5958 struct wireless_dev *wdev,
5959 const void *data,
5960 int data_len)
5961{
5962 int ret;
5963 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5964 struct net_device *dev = wdev->netdev;
5965 hdd_adapter_t *adapter;
5966 struct nlattr
5967 *tb[QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_MAX + 1];
5968 uint32_t freq_len, i;
5969 uint32_t *freq;
5970 uint8_t chans[QDF_MAX_NUM_CHAN];
5971
5972 ENTER_DEV(dev);
5973
5974 ret = wlan_hdd_validate_context(hdd_ctx);
5975 if (ret)
5976 return ret;
5977
5978 if (!hdd_ctx->config->enableDFSMasterCap) {
5979 hdd_err("DFS master capability is not present in the driver");
5980 return -EINVAL;
5981 }
5982
5983 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5984 hdd_err("Command not allowed in FTM mode");
5985 return -EPERM;
5986 }
5987
5988 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5989 if (adapter->device_mode != QDF_SAP_MODE) {
5990 hdd_err("Invalid device mode %d", adapter->device_mode);
5991 return -EINVAL;
5992 }
5993
5994 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_MAX,
5995 data, data_len, NULL)) {
5996 hdd_err("Invalid ATTR");
5997 return -EINVAL;
5998 }
5999
6000 if (!tb[QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_FREQ_LIST]) {
6001 hdd_err("Frequency list is missing");
6002 return -EINVAL;
6003 }
6004
6005 freq_len = nla_len(
6006 tb[QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_FREQ_LIST])/
6007 sizeof(uint32_t);
6008
6009 if (freq_len > QDF_MAX_NUM_CHAN) {
6010 hdd_err("insufficient space to hold channels");
6011 return -ENOMEM;
6012 }
6013
6014 hdd_debug("freq_len=%d", freq_len);
6015
6016 freq = nla_data(
6017 tb[QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_FREQ_LIST]);
6018
6019
6020 for (i = 0; i < freq_len; i++) {
6021 if (freq[i] == 0)
6022 chans[i] = 0;
6023 else
6024 chans[i] = ieee80211_frequency_to_channel(freq[i]);
6025
6026 hdd_debug("freq[%d]=%d", i, freq[i]);
6027 }
6028
6029 /*
6030 * The input frequency list from user space is designed to be a
6031 * priority based frequency list. This is only to accommodate any
6032 * future request. But, current requirement is only to perform CAC
6033 * on a single channel. So, the first entry from the list is picked.
6034 *
6035 * If channel is zero, any channel in the available outdoor regulatory
6036 * domain will be selected.
6037 */
6038 ret = wlan_hdd_request_pre_cac(chans[0]);
6039 if (ret) {
6040 hdd_err("pre cac request failed with reason:%d", ret);
6041 return ret;
6042 }
6043
6044 return 0;
6045}
6046
6047/**
Peng Xu8fdaa492016-06-22 10:20:47 -07006048 * __wlan_hdd_cfg80211_p2p_lo_start () - start P2P Listen Offload
6049 * @wiphy: Pointer to wireless phy
6050 * @wdev: Pointer to wireless device
6051 * @data: Pointer to data
6052 * @data_len: Data length
6053 *
6054 * This function is to process the p2p listen offload start vendor
6055 * command. It parses the input parameters and invoke WMA API to
6056 * send the command to firmware.
6057 *
6058 * Return: 0 on success, negative errno on failure
6059 */
6060static int __wlan_hdd_cfg80211_p2p_lo_start(struct wiphy *wiphy,
6061 struct wireless_dev *wdev,
6062 const void *data,
6063 int data_len)
6064{
6065 int ret;
6066 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
6067 struct net_device *dev = wdev->netdev;
6068 hdd_adapter_t *adapter;
6069 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_MAX + 1];
6070 struct sir_p2p_lo_start params;
6071 QDF_STATUS status;
6072
6073 ENTER_DEV(dev);
6074
6075 ret = wlan_hdd_validate_context(hdd_ctx);
6076 if (ret)
6077 return ret;
6078
6079 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
6080 hdd_err("Command not allowed in FTM mode");
6081 return -EPERM;
6082 }
6083
6084 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6085 if ((adapter->device_mode != QDF_P2P_DEVICE_MODE) &&
6086 (adapter->device_mode != QDF_P2P_CLIENT_MODE) &&
6087 (adapter->device_mode != QDF_P2P_GO_MODE)) {
6088 hdd_err("Invalid device mode %d", adapter->device_mode);
6089 return -EINVAL;
6090 }
6091
6092 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_MAX,
6093 data, data_len, NULL)) {
6094 hdd_err("Invalid ATTR");
6095 return -EINVAL;
6096 }
6097
6098 memset(&params, 0, sizeof(params));
6099
6100 if (!tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CTRL_FLAG])
6101 params.ctl_flags = 1; /* set to default value */
6102 else
6103 params.ctl_flags = nla_get_u32(tb
6104 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CTRL_FLAG]);
6105
6106 if (!tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL] ||
6107 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD] ||
6108 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL] ||
6109 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT] ||
6110 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES] ||
6111 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE]) {
6112 hdd_err("Attribute parsing failed");
6113 return -EINVAL;
6114 }
6115
6116 params.vdev_id = adapter->sessionId;
6117 params.freq = nla_get_u32(tb
6118 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL]);
6119 if ((params.freq != 2412) && (params.freq != 2437) &&
6120 (params.freq != 2462)) {
6121 hdd_err("Invalid listening channel: %d", params.freq);
6122 return -EINVAL;
6123 }
6124
6125 params.period = nla_get_u32(tb
6126 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD]);
6127 if (!((params.period > 0) && (params.period < UINT_MAX))) {
6128 hdd_err("Invalid period: %d", params.period);
6129 return -EINVAL;
6130 }
6131
6132 params.interval = nla_get_u32(tb
6133 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL]);
6134 if (!((params.interval > 0) && (params.interval < UINT_MAX))) {
6135 hdd_err("Invalid interval: %d", params.interval);
6136 return -EINVAL;
6137 }
6138
6139 params.count = nla_get_u32(tb
6140 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT]);
6141 if (!((params.count > 0) && (params.count < UINT_MAX))) {
6142 hdd_err("Invalid count: %d", params.count);
6143 return -EINVAL;
6144 }
6145
6146 params.device_types = nla_data(tb
6147 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES]);
6148 if (params.device_types == NULL) {
6149 hdd_err("Invalid device types");
6150 return -EINVAL;
6151 }
6152
6153 params.dev_types_len = nla_len(tb
6154 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES]);
6155 if (params.dev_types_len < 8) {
6156 hdd_err("Invalid device type length: %d", params.dev_types_len);
6157 return -EINVAL;
6158 }
6159
6160 params.probe_resp_tmplt = nla_data(tb
6161 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE]);
6162 if (params.probe_resp_tmplt == NULL) {
6163 hdd_err("Invalid probe response template");
6164 return -EINVAL;
6165 }
6166
6167 params.probe_resp_len = nla_len(tb
6168 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE]);
6169 if (params.probe_resp_len == 0) {
6170 hdd_err("Invalid probe resp template length: %d",
6171 params.probe_resp_len);
6172 return -EINVAL;
6173 }
6174
6175 hdd_debug("P2P LO params: freq=%d, period=%d, interval=%d, count=%d",
6176 params.freq, params.period, params.interval, params.count);
6177
6178 status = wma_p2p_lo_start(&params);
6179
6180 if (!QDF_IS_STATUS_SUCCESS(status)) {
6181 hdd_err("P2P LO start failed");
6182 return -EINVAL;
6183 }
6184
6185 return 0;
6186}
6187
6188
6189/**
6190 * wlan_hdd_cfg80211_p2p_lo_start () - start P2P Listen Offload
6191 * @wiphy: Pointer to wireless phy
6192 * @wdev: Pointer to wireless device
6193 * @data: Pointer to data
6194 * @data_len: Data length
6195 *
6196 * This function inovkes internal __wlan_hdd_cfg80211_p2p_lo_start()
6197 * to process p2p listen offload start vendor command.
6198 *
6199 * Return: 0 on success, negative errno on failure
6200 */
6201static int wlan_hdd_cfg80211_p2p_lo_start(struct wiphy *wiphy,
6202 struct wireless_dev *wdev,
6203 const void *data,
6204 int data_len)
6205{
6206 int ret = 0;
6207
6208 cds_ssr_protect(__func__);
6209 ret = __wlan_hdd_cfg80211_p2p_lo_start(wiphy, wdev,
6210 data, data_len);
6211 cds_ssr_unprotect(__func__);
6212
6213 return ret;
6214}
6215
6216/**
6217 * __wlan_hdd_cfg80211_p2p_lo_stop () - stop P2P Listen Offload
6218 * @wiphy: Pointer to wireless phy
6219 * @wdev: Pointer to wireless device
6220 * @data: Pointer to data
6221 * @data_len: Data length
6222 *
6223 * This function is to process the p2p listen offload stop vendor
6224 * command. It invokes WMA API to send command to firmware.
6225 *
6226 * Return: 0 on success, negative errno on failure
6227 */
6228static int __wlan_hdd_cfg80211_p2p_lo_stop(struct wiphy *wiphy,
6229 struct wireless_dev *wdev,
6230 const void *data,
6231 int data_len)
6232{
6233 QDF_STATUS status;
6234 hdd_adapter_t *adapter;
6235 struct net_device *dev = wdev->netdev;
6236
6237 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
6238 hdd_err("Command not allowed in FTM mode");
6239 return -EPERM;
6240 }
6241
6242 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6243 if ((adapter->device_mode != QDF_P2P_DEVICE_MODE) &&
6244 (adapter->device_mode != QDF_P2P_CLIENT_MODE) &&
6245 (adapter->device_mode != QDF_P2P_GO_MODE)) {
6246 hdd_err("Invalid device mode");
6247 return -EINVAL;
6248 }
6249
6250 status = wma_p2p_lo_stop(adapter->sessionId);
6251
6252 if (!QDF_IS_STATUS_SUCCESS(status)) {
6253 hdd_err("P2P LO stop failed");
6254 return -EINVAL;
6255 }
6256
6257 return 0;
6258}
6259
6260/**
6261 * wlan_hdd_cfg80211_p2p_lo_stop () - stop P2P Listen Offload
6262 * @wiphy: Pointer to wireless phy
6263 * @wdev: Pointer to wireless device
6264 * @data: Pointer to data
6265 * @data_len: Data length
6266 *
6267 * This function inovkes internal __wlan_hdd_cfg80211_p2p_lo_stop()
6268 * to process p2p listen offload stop vendor command.
6269 *
6270 * Return: 0 on success, negative errno on failure
6271 */
6272static int wlan_hdd_cfg80211_p2p_lo_stop(struct wiphy *wiphy,
6273 struct wireless_dev *wdev,
6274 const void *data,
6275 int data_len)
6276{
6277 int ret = 0;
6278
6279 cds_ssr_protect(__func__);
6280 ret = __wlan_hdd_cfg80211_p2p_lo_stop(wiphy, wdev,
6281 data, data_len);
6282 cds_ssr_unprotect(__func__);
6283
6284 return ret;
6285}
6286
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306287/**
6288 * wlan_hdd_cfg80211_conditional_chan_switch() - SAP conditional channel switch
6289 * @wiphy: Pointer to wireless phy
6290 * @wdev: Pointer to wireless device
6291 * @data: Pointer to data
6292 * @data_len: Data length
6293 *
6294 * Inovkes internal API __wlan_hdd_cfg80211_conditional_chan_switch()
6295 * to process the conditional channel switch request.
6296 *
6297 * Return: 0 on success, negative errno on failure
6298 */
6299static int wlan_hdd_cfg80211_conditional_chan_switch(struct wiphy *wiphy,
6300 struct wireless_dev *wdev,
6301 const void *data,
6302 int data_len)
6303{
6304 int ret;
6305
6306 cds_ssr_protect(__func__);
6307 ret = __wlan_hdd_cfg80211_conditional_chan_switch(wiphy, wdev,
6308 data, data_len);
6309 cds_ssr_unprotect(__func__);
6310
6311 return ret;
6312}
6313
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306314/*
6315 * define short names for the global vendor params
6316 * used by __wlan_hdd_cfg80211_bpf_offload()
6317 */
6318#define BPF_INVALID \
6319 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_INVALID
6320#define BPF_SET_RESET \
6321 QCA_WLAN_VENDOR_ATTR_SET_RESET_PACKET_FILTER
6322#define BPF_VERSION \
6323 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_VERSION
6324#define BPF_FILTER_ID \
6325 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_ID
6326#define BPF_PACKET_SIZE \
6327 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_SIZE
6328#define BPF_CURRENT_OFFSET \
6329 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_CURRENT_OFFSET
6330#define BPF_PROGRAM \
6331 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_PROGRAM
6332#define BPF_MAX \
6333 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_MAX
Peng Xu4d67c8f2015-10-16 16:02:26 -07006334
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306335static const struct nla_policy
6336wlan_hdd_bpf_offload_policy[BPF_MAX + 1] = {
6337 [BPF_SET_RESET] = {.type = NLA_U32},
6338 [BPF_VERSION] = {.type = NLA_U32},
6339 [BPF_FILTER_ID] = {.type = NLA_U32},
6340 [BPF_PACKET_SIZE] = {.type = NLA_U32},
6341 [BPF_CURRENT_OFFSET] = {.type = NLA_U32},
6342 [BPF_PROGRAM] = {.type = NLA_U8},
6343};
6344
6345/**
6346 * hdd_get_bpf_offload_cb() - Callback function to BPF Offload
6347 * @hdd_context: hdd_context
6348 * @bpf_get_offload: struct for get offload
6349 *
6350 * This function receives the response/data from the lower layer and
6351 * checks to see if the thread is still waiting then post the results to
6352 * upper layer, if the request has timed out then ignore.
6353 *
6354 * Return: None
6355 */
6356void hdd_get_bpf_offload_cb(void *hdd_context,
6357 struct sir_bpf_get_offload *data)
6358{
6359 hdd_context_t *hdd_ctx = hdd_context;
6360 struct hdd_bpf_context *context;
6361
6362 ENTER();
6363
6364 if (wlan_hdd_validate_context(hdd_ctx) || !data) {
Jeff Johnson77848112016-06-29 14:52:06 -07006365 hdd_err("HDD context is invalid or data(%p) is null",
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306366 data);
6367 return;
6368 }
6369
6370 spin_lock(&hdd_context_lock);
6371
6372 context = &bpf_context;
6373 /* The caller presumably timed out so there is nothing we can do */
6374 if (context->magic != BPF_CONTEXT_MAGIC) {
6375 spin_unlock(&hdd_context_lock);
6376 return;
6377 }
6378
6379 /* context is valid so caller is still waiting */
6380 /* paranoia: invalidate the magic */
6381 context->magic = 0;
6382
6383 context->capability_response = *data;
6384 complete(&context->completion);
6385
6386 spin_unlock(&hdd_context_lock);
6387
6388 return;
6389}
6390
6391/**
6392 * hdd_post_get_bpf_capabilities_rsp() - Callback function to BPF Offload
6393 * @hdd_context: hdd_context
6394 * @bpf_get_offload: struct for get offload
6395 *
6396 * Return: 0 on success, error number otherwise.
6397 */
6398static int hdd_post_get_bpf_capabilities_rsp(hdd_context_t *hdd_ctx,
6399 struct sir_bpf_get_offload *bpf_get_offload)
6400{
6401 struct sk_buff *skb;
6402 uint32_t nl_buf_len;
6403
6404 ENTER();
6405
6406 nl_buf_len = NLMSG_HDRLEN;
6407 nl_buf_len +=
6408 (sizeof(bpf_get_offload->max_bytes_for_bpf_inst) + NLA_HDRLEN) +
6409 (sizeof(bpf_get_offload->bpf_version) + NLA_HDRLEN);
6410
6411 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
6412 if (!skb) {
Jeff Johnson77848112016-06-29 14:52:06 -07006413 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306414 return -ENOMEM;
6415 }
6416
Jeff Johnson77848112016-06-29 14:52:06 -07006417 hdd_notice("BPF Version: %u BPF max bytes: %u",
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306418 bpf_get_offload->bpf_version,
6419 bpf_get_offload->max_bytes_for_bpf_inst);
6420
6421 if (nla_put_u32(skb, BPF_PACKET_SIZE,
6422 bpf_get_offload->max_bytes_for_bpf_inst) ||
6423 nla_put_u32(skb, BPF_VERSION, bpf_get_offload->bpf_version)) {
Jeff Johnson77848112016-06-29 14:52:06 -07006424 hdd_err("nla put failure");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306425 goto nla_put_failure;
6426 }
6427
6428 cfg80211_vendor_cmd_reply(skb);
6429 EXIT();
6430 return 0;
6431
6432nla_put_failure:
6433 kfree_skb(skb);
6434 return -EINVAL;
6435}
6436
6437/**
6438 * hdd_get_bpf_offload - Get BPF offload Capabilities
6439 * @hdd_ctx: Hdd context
6440 *
6441 * Return: 0 on success, errno on failure
6442 */
6443static int hdd_get_bpf_offload(hdd_context_t *hdd_ctx)
6444{
6445 unsigned long rc;
Houston Hoffman59c097f2016-11-09 15:50:25 -08006446 static struct hdd_bpf_context *context;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306447 QDF_STATUS status;
6448 int ret;
6449
6450 ENTER();
6451
6452 spin_lock(&hdd_context_lock);
6453 context = &bpf_context;
6454 context->magic = BPF_CONTEXT_MAGIC;
6455 INIT_COMPLETION(context->completion);
6456 spin_unlock(&hdd_context_lock);
6457
6458 status = sme_get_bpf_offload_capabilities(hdd_ctx->hHal);
6459 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07006460 hdd_err("Unable to retrieve BPF caps");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306461 return -EINVAL;
6462 }
6463 /* request was sent -- wait for the response */
6464 rc = wait_for_completion_timeout(&context->completion,
6465 msecs_to_jiffies(WLAN_WAIT_TIME_BPF));
6466 if (!rc) {
Jeff Johnson77848112016-06-29 14:52:06 -07006467 hdd_err("Target response timed out");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306468 spin_lock(&hdd_context_lock);
6469 context->magic = 0;
6470 spin_unlock(&hdd_context_lock);
6471
6472 return -ETIMEDOUT;
6473 }
6474 ret = hdd_post_get_bpf_capabilities_rsp(hdd_ctx,
6475 &bpf_context.capability_response);
6476 if (ret)
Jeff Johnson77848112016-06-29 14:52:06 -07006477 hdd_err("Failed to post get bpf capabilities");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306478
6479 EXIT();
6480 return ret;
6481}
6482
6483/**
6484 * hdd_set_reset_bpf_offload - Post set/reset bpf to SME
6485 * @hdd_ctx: Hdd context
6486 * @tb: Length of @data
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306487 * @adapter: pointer to adapter struct
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306488 *
6489 * Return: 0 on success; errno on failure
6490 */
6491static int hdd_set_reset_bpf_offload(hdd_context_t *hdd_ctx,
6492 struct nlattr **tb,
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306493 hdd_adapter_t *adapter)
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306494{
6495 struct sir_bpf_set_offload *bpf_set_offload;
6496 QDF_STATUS status;
6497 int prog_len;
Arun Khandavalli08500812016-07-25 14:58:42 +05306498 int ret = 0;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306499
6500 ENTER();
6501
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306502 if (adapter->device_mode == QDF_STA_MODE ||
6503 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
6504 if (!hdd_conn_is_connected(
6505 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
6506 hdd_err("Not in Connected state!");
6507 return -ENOTSUPP;
6508 }
6509 }
6510
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306511 bpf_set_offload = qdf_mem_malloc(sizeof(*bpf_set_offload));
6512 if (bpf_set_offload == NULL) {
Jeff Johnson77848112016-06-29 14:52:06 -07006513 hdd_err("qdf_mem_malloc failed for bpf_set_offload");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306514 return -ENOMEM;
6515 }
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306516
6517 /* Parse and fetch bpf packet size */
6518 if (!tb[BPF_PACKET_SIZE]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006519 hdd_err("attr bpf packet size failed");
Arun Khandavalli08500812016-07-25 14:58:42 +05306520 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306521 goto fail;
6522 }
6523 bpf_set_offload->total_length = nla_get_u32(tb[BPF_PACKET_SIZE]);
6524
6525 if (!bpf_set_offload->total_length) {
Jeff Johnson77848112016-06-29 14:52:06 -07006526 hdd_notice("BPF reset packet filter received");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306527 goto post_sme;
6528 }
6529
6530 /* Parse and fetch bpf program */
6531 if (!tb[BPF_PROGRAM]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006532 hdd_err("attr bpf program failed");
Arun Khandavalli08500812016-07-25 14:58:42 +05306533 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306534 goto fail;
6535 }
6536
6537 prog_len = nla_len(tb[BPF_PROGRAM]);
6538 bpf_set_offload->program = qdf_mem_malloc(sizeof(uint8_t) * prog_len);
Arun Khandavalli08500812016-07-25 14:58:42 +05306539
6540 if (bpf_set_offload->program == NULL) {
6541 hdd_err("qdf_mem_malloc failed for bpf offload program");
6542 ret = -ENOMEM;
6543 goto fail;
6544 }
6545
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306546 bpf_set_offload->current_length = prog_len;
6547 nla_memcpy(bpf_set_offload->program, tb[BPF_PROGRAM], prog_len);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306548 bpf_set_offload->session_id = adapter->sessionId;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306549
Rajeev Kumar Sirasanagandla62b63032016-08-22 14:56:57 +05306550 hdd_info("BPF set instructions");
6551 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
6552 bpf_set_offload->program, prog_len);
6553
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306554 /* Parse and fetch filter Id */
6555 if (!tb[BPF_FILTER_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006556 hdd_err("attr filter id failed");
Arun Khandavalli08500812016-07-25 14:58:42 +05306557 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306558 goto fail;
6559 }
6560 bpf_set_offload->filter_id = nla_get_u32(tb[BPF_FILTER_ID]);
6561
6562 /* Parse and fetch current offset */
6563 if (!tb[BPF_CURRENT_OFFSET]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006564 hdd_err("attr current offset failed");
Arun Khandavalli08500812016-07-25 14:58:42 +05306565 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306566 goto fail;
6567 }
6568 bpf_set_offload->current_offset = nla_get_u32(tb[BPF_CURRENT_OFFSET]);
6569
6570post_sme:
Jeff Johnson77848112016-06-29 14:52:06 -07006571 hdd_notice("Posting BPF SET/RESET to SME, session_id: %d Bpf Version: %d filter ID: %d total_length: %d current_length: %d current offset: %d",
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306572 bpf_set_offload->session_id,
6573 bpf_set_offload->version,
6574 bpf_set_offload->filter_id,
6575 bpf_set_offload->total_length,
6576 bpf_set_offload->current_length,
6577 bpf_set_offload->current_offset);
6578
6579 status = sme_set_bpf_instructions(hdd_ctx->hHal, bpf_set_offload);
6580 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07006581 hdd_err("sme_set_bpf_instructions failed(err=%d)", status);
Arun Khandavalli08500812016-07-25 14:58:42 +05306582 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306583 goto fail;
6584 }
6585 EXIT();
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306586
6587fail:
6588 if (bpf_set_offload->current_length)
6589 qdf_mem_free(bpf_set_offload->program);
6590 qdf_mem_free(bpf_set_offload);
Arun Khandavalli08500812016-07-25 14:58:42 +05306591 return ret;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306592}
6593
6594/**
6595 * wlan_hdd_cfg80211_bpf_offload() - Set/Reset to BPF Offload
6596 * @wiphy: wiphy structure pointer
6597 * @wdev: Wireless device structure pointer
6598 * @data: Pointer to the data received
6599 * @data_len: Length of @data
6600 *
6601 * Return: 0 on success; errno on failure
6602 */
6603static int
6604__wlan_hdd_cfg80211_bpf_offload(struct wiphy *wiphy,
6605 struct wireless_dev *wdev,
6606 const void *data, int data_len)
6607{
6608 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
6609 struct net_device *dev = wdev->netdev;
6610 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6611 struct nlattr *tb[BPF_MAX + 1];
6612 int ret_val, packet_filter_subcmd;
6613
6614 ENTER();
6615
6616 ret_val = wlan_hdd_validate_context(hdd_ctx);
6617 if (ret_val)
6618 return ret_val;
6619
6620 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson77848112016-06-29 14:52:06 -07006621 hdd_err("Command not allowed in FTM mode");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306622 return -EINVAL;
6623 }
6624
6625 if (!hdd_ctx->bpf_enabled) {
Rajeev Kumardd3bc602016-08-16 14:21:05 -07006626 hdd_err("BPF offload is not supported/enabled");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306627 return -ENOTSUPP;
6628 }
6629
6630 if (nla_parse(tb, BPF_MAX, data, data_len,
6631 wlan_hdd_bpf_offload_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07006632 hdd_err("Invalid ATTR");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306633 return -EINVAL;
6634 }
6635
6636 if (!tb[BPF_SET_RESET]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006637 hdd_err("attr bpf set reset failed");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306638 return -EINVAL;
6639 }
6640
6641 packet_filter_subcmd = nla_get_u32(tb[BPF_SET_RESET]);
6642
6643 if (packet_filter_subcmd == QCA_WLAN_GET_PACKET_FILTER)
6644 return hdd_get_bpf_offload(hdd_ctx);
6645 else
6646 return hdd_set_reset_bpf_offload(hdd_ctx, tb,
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306647 pAdapter);
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306648}
6649
6650/**
6651 * wlan_hdd_cfg80211_bpf_offload() - SSR Wrapper to BPF Offload
6652 * @wiphy: wiphy structure pointer
6653 * @wdev: Wireless device structure pointer
6654 * @data: Pointer to the data received
6655 * @data_len: Length of @data
6656 *
6657 * Return: 0 on success; errno on failure
6658 */
6659
6660static int wlan_hdd_cfg80211_bpf_offload(struct wiphy *wiphy,
6661 struct wireless_dev *wdev,
6662 const void *data, int data_len)
6663{
6664 int ret;
6665
6666 cds_ssr_protect(__func__);
6667 ret = __wlan_hdd_cfg80211_bpf_offload(wiphy, wdev, data, data_len);
6668 cds_ssr_unprotect(__func__);
6669
6670 return ret;
6671}
6672
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306673/**
6674 * wlan_hdd_set_pre_cac_status() - Set the pre cac status
6675 * @pre_cac_adapter: AP adapter used for pre cac
6676 * @status: Status (true or false)
6677 * @handle: Global handle
6678 *
6679 * Sets the status of pre cac i.e., whether the pre cac is active or not
6680 *
6681 * Return: Zero on success, non-zero on failure
6682 */
6683static int wlan_hdd_set_pre_cac_status(hdd_adapter_t *pre_cac_adapter,
6684 bool status, tHalHandle handle)
6685{
6686 QDF_STATUS ret;
6687
6688 ret = wlan_sap_set_pre_cac_status(
6689 WLAN_HDD_GET_SAP_CTX_PTR(pre_cac_adapter), status, handle);
6690 if (QDF_IS_STATUS_ERROR(ret))
6691 return -EINVAL;
6692
6693 return 0;
6694}
6695
6696/**
6697 * wlan_hdd_set_chan_before_pre_cac() - Save the channel before pre cac
6698 * @ap_adapter: AP adapter
6699 * @chan_before_pre_cac: Channel
6700 *
6701 * Saves the channel which the AP was beaconing on before moving to the pre
6702 * cac channel. If radar is detected on the pre cac channel, this saved
6703 * channel will be used for AP operations.
6704 *
6705 * Return: Zero on success, non-zero on failure
6706 */
6707static int wlan_hdd_set_chan_before_pre_cac(hdd_adapter_t *ap_adapter,
6708 uint8_t chan_before_pre_cac)
6709{
6710 QDF_STATUS ret;
6711
6712 ret = wlan_sap_set_chan_before_pre_cac(
6713 WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter), chan_before_pre_cac);
6714 if (QDF_IS_STATUS_ERROR(ret))
6715 return -EINVAL;
6716
6717 return 0;
6718}
6719
6720/**
6721 * wlan_hdd_sap_get_nol() - Get SAPs NOL
6722 * @ap_adapter: AP adapter
6723 * @nol: Non-occupancy list
6724 * @nol_len: Length of NOL
6725 *
6726 * Get the NOL for SAP
6727 *
6728 * Return: Zero on success, non-zero on failure
6729 */
6730static int wlan_hdd_sap_get_nol(hdd_adapter_t *ap_adapter, uint8_t *nol,
6731 uint32_t *nol_len)
6732{
6733 QDF_STATUS ret;
6734
6735 ret = wlansap_get_dfs_nol(WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter),
6736 nol, nol_len);
6737 if (QDF_IS_STATUS_ERROR(ret))
6738 return -EINVAL;
6739
6740 return 0;
6741}
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306742
6743/**
6744 * wlan_hdd_validate_and_get_pre_cac_ch() - Validate and get pre cac channel
6745 * @hdd_ctx: HDD context
6746 * @ap_adapter: AP adapter
6747 * @channel: Channel requested by userspace
6748 * @pre_cac_chan: Pointer to the pre CAC channel
6749 *
6750 * Validates the channel provided by userspace. If user provided channel 0,
6751 * a valid outdoor channel must be selected from the regulatory channel.
6752 *
6753 * Return: Zero on success and non zero value on error
6754 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -07006755static int wlan_hdd_validate_and_get_pre_cac_ch(hdd_context_t *hdd_ctx,
6756 hdd_adapter_t *ap_adapter,
6757 uint8_t channel,
6758 uint8_t *pre_cac_chan)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306759{
6760 uint32_t i, j;
6761 QDF_STATUS status;
6762 int ret;
6763 uint8_t nol[QDF_MAX_NUM_CHAN];
6764 uint32_t nol_len = 0, weight_len = 0;
6765 bool found;
6766 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6767 uint8_t channel_list[QDF_MAX_NUM_CHAN] = {0};
6768 uint8_t pcl_weights[QDF_MAX_NUM_CHAN] = {0};
6769
6770 if (0 == channel) {
6771 /* Channel is not obtained from PCL because PCL may not have
6772 * the entire channel list. For example: if SAP is up on
6773 * channel 6 and PCL is queried for the next SAP interface,
6774 * if SCC is preferred, the PCL will contain only the channel
6775 * 6. But, we are in need of a DFS channel. So, going with the
6776 * first channel from the valid channel list.
6777 */
6778 status = cds_get_valid_chans(channel_list, &len);
6779 if (QDF_IS_STATUS_ERROR(status)) {
6780 hdd_err("Failed to get channel list");
6781 return -EINVAL;
6782 }
6783 cds_update_with_safe_channel_list(channel_list, &len,
6784 pcl_weights, weight_len);
6785 ret = wlan_hdd_sap_get_nol(ap_adapter, nol, &nol_len);
6786 for (i = 0; i < len; i++) {
6787 found = false;
6788 for (j = 0; j < nol_len; j++) {
6789 if (channel_list[i] == nol[j]) {
6790 found = true;
6791 break;
6792 }
6793 }
6794 if (found)
6795 continue;
6796 if (CDS_IS_DFS_CH(channel_list[i])) {
6797 *pre_cac_chan = channel_list[i];
6798 break;
6799 }
6800 }
6801 if (*pre_cac_chan == 0) {
6802 hdd_err("unable to find outdoor channel");
6803 return -EINVAL;
6804 }
6805 } else {
6806 /* Only when driver selects a channel, check is done for
6807 * unnsafe and NOL channels. When user provides a fixed channel
6808 * the user is expected to take care of this.
6809 */
6810 if (!sme_is_channel_valid(hdd_ctx->hHal, channel) ||
6811 !CDS_IS_DFS_CH(channel)) {
6812 hdd_err("Invalid channel for pre cac:%d", channel);
6813 return -EINVAL;
6814 } else {
6815 *pre_cac_chan = channel;
6816 }
6817 }
6818 hdd_info("selected pre cac channel:%d", *pre_cac_chan);
6819 return 0;
6820}
6821
6822/**
6823 * wlan_hdd_request_pre_cac() - Start pre CAC in the driver
6824 * @channel: Channel option provided by userspace
6825 *
6826 * Sets the driver to the required hardware mode and start an adapater for
6827 * pre CAC which will mimic an AP.
6828 *
6829 * Return: Zero on success, non-zero value on error
6830 */
6831int wlan_hdd_request_pre_cac(uint8_t channel)
6832{
6833 uint8_t pre_cac_chan = 0;
6834 hdd_context_t *hdd_ctx;
6835 int ret;
6836 hdd_adapter_t *ap_adapter, *pre_cac_adapter;
6837 hdd_ap_ctx_t *hdd_ap_ctx;
6838 QDF_STATUS status;
6839 struct wiphy *wiphy;
6840 struct net_device *dev;
6841 struct cfg80211_chan_def chandef;
6842 enum nl80211_channel_type channel_type;
6843 uint32_t freq;
6844 struct ieee80211_channel *chan;
6845 tHalHandle handle;
6846 bool val;
6847
6848 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6849 if (0 != wlan_hdd_validate_context(hdd_ctx))
6850 return -EINVAL;
6851
6852 if (cds_get_connection_count() > 1) {
6853 hdd_err("pre cac not allowed in concurrency");
6854 return -EINVAL;
6855 }
6856
6857 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
6858 if (!ap_adapter) {
6859 hdd_err("unable to get SAP adapter");
6860 return -EINVAL;
6861 }
6862
6863 handle = WLAN_HDD_GET_HAL_CTX(ap_adapter);
6864 if (!handle) {
6865 hdd_err("Invalid handle");
6866 return -EINVAL;
6867 }
6868
6869 val = wlan_sap_is_pre_cac_active(handle);
6870 if (val) {
6871 hdd_err("pre cac is already in progress");
6872 return -EINVAL;
6873 }
6874
6875 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
6876 if (!hdd_ap_ctx) {
6877 hdd_err("SAP context is NULL");
6878 return -EINVAL;
6879 }
6880
6881 if (CDS_IS_DFS_CH(hdd_ap_ctx->operatingChannel)) {
6882 hdd_err("SAP is already on DFS channel:%d",
6883 hdd_ap_ctx->operatingChannel);
6884 return -EINVAL;
6885 }
6886
6887 if (!CDS_IS_CHANNEL_24GHZ(hdd_ap_ctx->operatingChannel)) {
6888 hdd_err("pre CAC alllowed only when SAP is in 2.4GHz:%d",
6889 hdd_ap_ctx->operatingChannel);
6890 return -EINVAL;
6891 }
6892
6893 hdd_info("channel:%d", channel);
6894
6895 ret = wlan_hdd_validate_and_get_pre_cac_ch(hdd_ctx, ap_adapter, channel,
6896 &pre_cac_chan);
6897 if (ret != 0)
6898 return ret;
6899
6900 /* Since current SAP is in 2.4GHz and pre CAC channel is in 5GHz, this
6901 * connection update should result in DBS mode
6902 */
6903 status = cds_update_and_wait_for_connection_update(
6904 ap_adapter->sessionId,
6905 pre_cac_chan,
6906 SIR_UPDATE_REASON_PRE_CAC);
6907 if (QDF_IS_STATUS_ERROR(status)) {
6908 hdd_err("error in moving to DBS mode");
6909 return -EINVAL;
6910 }
6911
6912 hdd_debug("starting pre cac SAP adapter");
6913
6914 /* Starting a SAP adapter:
6915 * Instead of opening an adapter, we could just do a SME open session
6916 * for AP type. But, start BSS would still need an adapter.
6917 * So, this option is not taken.
6918 *
6919 * hdd open adapter is going to register this precac interface with
6920 * user space. This interface though exposed to user space will be in
6921 * DOWN state. Consideration was done to avoid this registration to the
6922 * user space. But, as part of SAP operations multiple events are sent
6923 * to user space. Some of these events received from unregistered
6924 * interface was causing crashes. So, retaining the registration.
6925 *
6926 * So, this interface would remain registered and will remain in DOWN
6927 * state for the CAC duration. We will add notes in the feature
6928 * announcement to not use this temporary interface for any activity
6929 * from user space.
6930 */
6931 pre_cac_adapter = hdd_open_adapter(hdd_ctx, QDF_SAP_MODE, "precac%d",
6932 wlan_hdd_get_intf_addr(hdd_ctx),
6933 NET_NAME_UNKNOWN, true);
6934 if (!pre_cac_adapter) {
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05306935 hdd_err("error opening the pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306936 return -EINVAL;
6937 }
6938
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05306939 /*
6940 * This interface is internally created by the driver. So, no interface
6941 * up comes for this interface from user space and hence starting
6942 * the adapter internally.
6943 */
6944 if (hdd_start_adapter(pre_cac_adapter)) {
6945 hdd_err("error starting the pre cac adapter");
6946 goto close_pre_cac_adapter;
6947 }
6948
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306949 hdd_debug("preparing for start ap/bss on the pre cac adapter");
6950
6951 wiphy = hdd_ctx->wiphy;
6952 dev = pre_cac_adapter->dev;
6953
6954 /* Since this is only a dummy interface lets us use the IEs from the
6955 * other active SAP interface. In regular scenarios, these IEs would
6956 * come from the user space entity
6957 */
6958 pre_cac_adapter->sessionCtx.ap.beacon = qdf_mem_malloc(
6959 sizeof(*ap_adapter->sessionCtx.ap.beacon));
6960 if (!pre_cac_adapter->sessionCtx.ap.beacon) {
6961 hdd_err("failed to alloc mem for beacon");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05306962 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306963 }
6964 qdf_mem_copy(pre_cac_adapter->sessionCtx.ap.beacon,
6965 ap_adapter->sessionCtx.ap.beacon,
6966 sizeof(*pre_cac_adapter->sessionCtx.ap.beacon));
6967 pre_cac_adapter->sessionCtx.ap.sapConfig.ch_width_orig =
6968 ap_adapter->sessionCtx.ap.sapConfig.ch_width_orig;
6969 pre_cac_adapter->sessionCtx.ap.sapConfig.authType =
6970 ap_adapter->sessionCtx.ap.sapConfig.authType;
6971
6972 /* Premise is that on moving from 2.4GHz to 5GHz, the SAP will continue
6973 * to operate on the same bandwidth as that of the 2.4GHz operations.
6974 * Only bandwidths 20MHz/40MHz are possible on 2.4GHz band.
6975 */
6976 switch (ap_adapter->sessionCtx.ap.sapConfig.ch_width_orig) {
6977 case CH_WIDTH_20MHZ:
6978 channel_type = NL80211_CHAN_HT20;
6979 break;
6980 case CH_WIDTH_40MHZ:
6981 if (ap_adapter->sessionCtx.ap.sapConfig.sec_ch >
6982 ap_adapter->sessionCtx.ap.sapConfig.channel)
6983 channel_type = NL80211_CHAN_HT40PLUS;
6984 else
6985 channel_type = NL80211_CHAN_HT40MINUS;
6986 break;
6987 default:
6988 channel_type = NL80211_CHAN_NO_HT;
6989 break;
6990 }
6991
6992 freq = cds_chan_to_freq(pre_cac_chan);
6993 chan = __ieee80211_get_channel(wiphy, freq);
6994 if (!chan) {
6995 hdd_err("channel converion failed");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05306996 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306997 }
6998
6999 cfg80211_chandef_create(&chandef, chan, channel_type);
7000
7001 hdd_debug("orig width:%d channel_type:%d freq:%d",
7002 ap_adapter->sessionCtx.ap.sapConfig.ch_width_orig,
7003 channel_type, freq);
7004
7005 ret = wlan_hdd_set_channel(wiphy, dev, &chandef, channel_type);
7006 if (0 != ret) {
7007 hdd_err("failed to set channel");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307008 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307009 }
7010
7011 status = wlan_hdd_cfg80211_start_bss(pre_cac_adapter, NULL,
7012 PRE_CAC_SSID, qdf_str_len(PRE_CAC_SSID),
Archana Ramachandran1a5b6042016-11-08 16:36:50 -08007013 eHIDDEN_SSID_NOT_IN_USE, false, false);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307014 if (QDF_IS_STATUS_ERROR(status)) {
7015 hdd_err("start bss failed");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307016 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307017 }
7018
7019 /*
7020 * The pre cac status is set here. But, it would not be reset explicitly
7021 * anywhere, since after the pre cac success/failure, the pre cac
7022 * adapter itself would be removed.
7023 */
7024 ret = wlan_hdd_set_pre_cac_status(pre_cac_adapter, true, handle);
7025 if (0 != ret) {
7026 hdd_err("failed to set pre cac status");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307027 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307028 }
7029
7030 ret = wlan_hdd_set_chan_before_pre_cac(ap_adapter,
7031 hdd_ap_ctx->operatingChannel);
7032 if (0 != ret) {
7033 hdd_err("failed to set channel before pre cac");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307034 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307035 }
7036
7037 ap_adapter->pre_cac_chan = pre_cac_chan;
7038
7039 return 0;
7040
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307041stop_close_pre_cac_adapter:
7042 hdd_stop_adapter(hdd_ctx, pre_cac_adapter, true);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307043 qdf_mem_free(pre_cac_adapter->sessionCtx.ap.beacon);
7044 pre_cac_adapter->sessionCtx.ap.beacon = NULL;
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307045close_pre_cac_adapter:
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307046 hdd_close_adapter(hdd_ctx, pre_cac_adapter, false);
7047 return -EINVAL;
7048}
7049
Arun Khandavalli2476ef52016-04-26 20:19:43 +05307050/**
7051 * hdd_init_bpf_completion() - Initialize the completion event for bpf
7052 *
7053 * Return: None
7054 */
7055void hdd_init_bpf_completion(void)
7056{
7057 init_completion(&bpf_context.completion);
7058}
7059
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307060static const struct nla_policy
7061wlan_hdd_sap_config_policy[QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_MAX + 1] = {
7062 [QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHANNEL] = {.type = NLA_U8 },
7063};
7064
Agrawal Ashish65634612016-08-18 13:24:32 +05307065static const struct nla_policy
7066wlan_hdd_set_acs_dfs_config_policy[QCA_WLAN_VENDOR_ATTR_ACS_DFS_MAX + 1] = {
7067 [QCA_WLAN_VENDOR_ATTR_ACS_DFS_MODE] = {.type = NLA_U8 },
7068 [QCA_WLAN_VENDOR_ATTR_ACS_CHANNEL_HINT] = {.type = NLA_U8 },
7069};
7070
7071/**
7072 * __wlan_hdd_cfg80211_acs_dfs_mode() - set ACS DFS mode and channel
7073 * @wiphy: Pointer to wireless phy
7074 * @wdev: Pointer to wireless device
7075 * @data: Pointer to data
7076 * @data_len: Length of @data
7077 *
7078 * This function parses the incoming NL vendor command data attributes and
7079 * updates the SAP context about channel_hint and DFS mode.
7080 * If channel_hint is set, SAP will choose that channel
7081 * as operating channel.
7082 *
7083 * If DFS mode is enabled, driver will include DFS channels
7084 * in ACS else driver will skip DFS channels.
7085 *
7086 * Return: 0 on success, negative errno on failure
7087 */
7088static int
7089__wlan_hdd_cfg80211_acs_dfs_mode(struct wiphy *wiphy,
7090 struct wireless_dev *wdev,
7091 const void *data, int data_len)
7092{
7093 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7094 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ACS_DFS_MAX + 1];
7095 int ret;
7096 struct acs_dfs_policy *acs_policy;
7097 int mode = DFS_MODE_NONE;
7098 int channel_hint = 0;
7099
7100 ENTER_DEV(wdev->netdev);
7101
7102 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7103 hdd_err("Command not allowed in FTM mode");
7104 return -EINVAL;
7105 }
7106
7107 ret = wlan_hdd_validate_context(hdd_ctx);
7108 if (0 != ret)
7109 return ret;
7110
7111 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ACS_DFS_MAX,
7112 data, data_len,
7113 wlan_hdd_set_acs_dfs_config_policy)) {
7114 hdd_err("invalid attr");
7115 return -EINVAL;
7116 }
7117
7118 acs_policy = &hdd_ctx->acs_policy;
7119 /*
7120 * SCM sends this attribute to restrict SAP from choosing
7121 * DFS channels from ACS.
7122 */
7123 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_DFS_MODE])
7124 mode = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_ACS_DFS_MODE]);
7125
7126 if (!IS_DFS_MODE_VALID(mode)) {
7127 hdd_err("attr acs dfs mode is not valid");
7128 return -EINVAL;
7129 }
7130 acs_policy->acs_dfs_mode = mode;
7131
7132 /*
7133 * SCM sends this attribute to provide an active channel,
7134 * to skip redundant ACS between drivers, and save driver start up time
7135 */
7136 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_CHANNEL_HINT])
7137 channel_hint = nla_get_u8(
7138 tb[QCA_WLAN_VENDOR_ATTR_ACS_CHANNEL_HINT]);
7139
7140 if (!IS_CHANNEL_VALID(channel_hint)) {
7141 hdd_err("acs channel is not valid");
7142 return -EINVAL;
7143 }
7144 acs_policy->acs_channel = channel_hint;
7145
7146 return 0;
7147}
7148
7149/**
7150 * wlan_hdd_cfg80211_acs_dfs_mode() - Wrapper to set ACS DFS mode
7151 * @wiphy: wiphy structure pointer
7152 * @wdev: Wireless device structure pointer
7153 * @data: Pointer to the data received
7154 * @data_len: Length of @data
7155 *
7156 * This function parses the incoming NL vendor command data attributes and
7157 * updates the SAP context about channel_hint and DFS mode.
7158 *
7159 * Return: 0 on success; errno on failure
7160 */
7161static int wlan_hdd_cfg80211_acs_dfs_mode(struct wiphy *wiphy,
7162 struct wireless_dev *wdev,
7163 const void *data, int data_len)
7164{
7165 int ret;
7166
7167 cds_ssr_protect(__func__);
7168 ret = __wlan_hdd_cfg80211_acs_dfs_mode(wiphy, wdev, data, data_len);
7169 cds_ssr_unprotect(__func__);
7170
7171 return ret;
7172}
7173
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307174/**
Agrawal Ashish21ba2572016-09-03 16:40:10 +05307175 * wlan_hdd_get_sta_roam_dfs_mode() - get sta roam dfs mode policy
7176 * @mode : cfg80211 dfs mode
7177 *
7178 * Return: return csr sta roam dfs mode else return NONE
7179 */
7180static enum sta_roam_policy_dfs_mode wlan_hdd_get_sta_roam_dfs_mode(
7181 enum dfs_mode mode)
7182{
7183 switch (mode) {
7184 case DFS_MODE_ENABLE:
7185 return CSR_STA_ROAM_POLICY_DFS_ENABLED;
7186 break;
7187 case DFS_MODE_DISABLE:
7188 return CSR_STA_ROAM_POLICY_DFS_DISABLED;
7189 break;
7190 case DFS_MODE_DEPRIORITIZE:
7191 return CSR_STA_ROAM_POLICY_DFS_DEPRIORITIZE;
7192 break;
7193 default:
7194 hdd_err("STA Roam policy dfs mode is NONE");
7195 return CSR_STA_ROAM_POLICY_NONE;
7196 }
7197}
7198
7199static const struct nla_policy
7200wlan_hdd_set_sta_roam_config_policy[
7201QCA_WLAN_VENDOR_ATTR_STA_CONNECT_ROAM_POLICY_MAX + 1] = {
7202 [QCA_WLAN_VENDOR_ATTR_STA_DFS_MODE] = {.type = NLA_U8 },
7203 [QCA_WLAN_VENDOR_ATTR_STA_SKIP_UNSAFE_CHANNEL] = {.type = NLA_U8 },
7204};
7205
7206/**
7207 * __wlan_hdd_cfg80211_sta_roam_policy() - Set params to restrict scan channels
7208 * for station connection or roaming.
7209 * @wiphy: Pointer to wireless phy
7210 * @wdev: Pointer to wireless device
7211 * @data: Pointer to data
7212 * @data_len: Length of @data
7213 *
7214 * __wlan_hdd_cfg80211_sta_roam_policy will decide if DFS channels or unsafe
7215 * channels needs to be skipped in scanning or not.
7216 * If dfs_mode is disabled, driver will not scan DFS channels.
7217 * If skip_unsafe_channels is set, driver will skip unsafe channels
7218 * in Scanning.
7219 *
7220 * Return: 0 on success, negative errno on failure
7221 */
7222static int
7223__wlan_hdd_cfg80211_sta_roam_policy(struct wiphy *wiphy,
7224 struct wireless_dev *wdev,
7225 const void *data, int data_len)
7226{
7227 struct net_device *dev = wdev->netdev;
7228 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
7229 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7230 struct nlattr *tb[
7231 QCA_WLAN_VENDOR_ATTR_STA_CONNECT_ROAM_POLICY_MAX + 1];
7232 int ret;
7233 enum sta_roam_policy_dfs_mode sta_roam_dfs_mode;
7234 enum dfs_mode mode = DFS_MODE_NONE;
7235 bool skip_unsafe_channels = false;
7236 QDF_STATUS status;
7237
7238 ENTER_DEV(dev);
7239
7240 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7241 hdd_err("Command not allowed in FTM mode");
7242 return -EINVAL;
7243 }
7244
7245 ret = wlan_hdd_validate_context(hdd_ctx);
7246 if (0 != ret)
7247 return ret;
7248 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_STA_CONNECT_ROAM_POLICY_MAX,
7249 data, data_len,
7250 wlan_hdd_set_sta_roam_config_policy)) {
7251 hdd_err("invalid attr");
7252 return -EINVAL;
7253 }
7254 if (tb[QCA_WLAN_VENDOR_ATTR_STA_DFS_MODE])
7255 mode = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_STA_DFS_MODE]);
7256 if (!IS_DFS_MODE_VALID(mode)) {
7257 hdd_err("attr sta roam dfs mode policy is not valid");
7258 return -EINVAL;
7259 }
7260
7261 sta_roam_dfs_mode = wlan_hdd_get_sta_roam_dfs_mode(mode);
7262
7263 if (tb[QCA_WLAN_VENDOR_ATTR_STA_SKIP_UNSAFE_CHANNEL])
7264 skip_unsafe_channels = nla_get_u8(
7265 tb[QCA_WLAN_VENDOR_ATTR_STA_SKIP_UNSAFE_CHANNEL]);
7266
7267 status = sme_update_sta_roam_policy(hdd_ctx->hHal, sta_roam_dfs_mode,
7268 skip_unsafe_channels, adapter->sessionId);
7269
7270 if (!QDF_IS_STATUS_SUCCESS(status)) {
7271 hdd_err("sme_update_sta_roam_policy (err=%d)", status);
7272 return -EINVAL;
7273 }
7274 return 0;
7275}
7276
7277/**
7278 * wlan_hdd_cfg80211_sta_roam_policy() - Wrapper to restrict scan channels,
7279 * connection and roaming for station.
7280 * @wiphy: wiphy structure pointer
7281 * @wdev: Wireless device structure pointer
7282 * @data: Pointer to the data received
7283 * @data_len: Length of @data
7284 *
7285 * __wlan_hdd_cfg80211_sta_roam_policy will decide if DFS channels or unsafe
7286 * channels needs to be skipped in scanning or not.
7287 * If dfs_mode is disabled, driver will not scan DFS channels.
7288 * If skip_unsafe_channels is set, driver will skip unsafe channels
7289 * in Scanning.
7290 * Return: 0 on success; errno on failure
7291 */
7292static int wlan_hdd_cfg80211_sta_roam_policy(struct wiphy *wiphy,
7293 struct wireless_dev *wdev,
7294 const void *data, int data_len)
7295{
7296 int ret;
7297
7298 cds_ssr_protect(__func__);
7299 ret = __wlan_hdd_cfg80211_sta_roam_policy(wiphy, wdev, data, data_len);
7300 cds_ssr_unprotect(__func__);
7301
7302 return ret;
7303}
7304
Agrawal Ashish467dde42016-09-08 18:44:22 +05307305#ifdef FEATURE_WLAN_CH_AVOID
7306/**
7307 * __wlan_hdd_cfg80211_avoid_freq() - ask driver to restart SAP if SAP
7308 * is on unsafe channel.
7309 * @wiphy: wiphy structure pointer
7310 * @wdev: Wireless device structure pointer
7311 * @data: Pointer to the data received
7312 * @data_len: Length of @data
7313 *
7314 * wlan_hdd_cfg80211_avoid_freq do restart the sap if sap is already
7315 * on any of unsafe channels.
7316 * If sap is on any of unsafe channel, hdd_unsafe_channel_restart_sap
7317 * will send WLAN_SVC_LTE_COEX_IND indication to userspace to restart.
7318 *
7319 * Return: 0 on success; errno on failure
7320 */
7321static int
7322__wlan_hdd_cfg80211_avoid_freq(struct wiphy *wiphy,
7323 struct wireless_dev *wdev,
7324 const void *data, int data_len)
7325{
7326 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7327 int ret;
7328 uint16_t unsafe_channel_count;
7329 int unsafe_channel_index;
7330 qdf_device_t qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
7331
7332 ENTER_DEV(wdev->netdev);
7333
7334 if (!qdf_ctx) {
7335 cds_err("qdf_ctx is NULL");
7336 return -EINVAL;
7337 }
7338
7339 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7340 hdd_err("Command not allowed in FTM mode");
7341 return -EINVAL;
7342 }
7343
7344 ret = wlan_hdd_validate_context(hdd_ctx);
7345 if (0 != ret)
7346 return ret;
7347 pld_get_wlan_unsafe_channel(qdf_ctx->dev, hdd_ctx->unsafe_channel_list,
7348 &(hdd_ctx->unsafe_channel_count),
7349 sizeof(hdd_ctx->unsafe_channel_list));
7350
7351 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
7352 (uint16_t)NUM_CHANNELS);
7353 for (unsafe_channel_index = 0;
7354 unsafe_channel_index < unsafe_channel_count;
7355 unsafe_channel_index++) {
7356 hdd_info("Channel %d is not safe",
7357 hdd_ctx->unsafe_channel_list[unsafe_channel_index]);
7358 }
7359 hdd_unsafe_channel_restart_sap(hdd_ctx);
7360 return 0;
7361}
7362
7363/**
7364 * wlan_hdd_cfg80211_avoid_freq() - ask driver to restart SAP if SAP
7365 * is on unsafe channel.
7366 * @wiphy: wiphy structure pointer
7367 * @wdev: Wireless device structure pointer
7368 * @data: Pointer to the data received
7369 * @data_len: Length of @data
7370 *
7371 * wlan_hdd_cfg80211_avoid_freq do restart the sap if sap is already
7372 * on any of unsafe channels.
7373 * If sap is on any of unsafe channel, hdd_unsafe_channel_restart_sap
7374 * will send WLAN_SVC_LTE_COEX_IND indication to userspace to restart.
7375 *
7376 * Return: 0 on success; errno on failure
7377 */
7378static int wlan_hdd_cfg80211_avoid_freq(struct wiphy *wiphy,
7379 struct wireless_dev *wdev,
7380 const void *data, int data_len)
7381{
7382 int ret;
7383
7384 cds_ssr_protect(__func__);
7385 ret = __wlan_hdd_cfg80211_avoid_freq(wiphy, wdev, data, data_len);
7386 cds_ssr_unprotect(__func__);
7387
7388 return ret;
7389}
7390
7391#endif
Agrawal Ashish21ba2572016-09-03 16:40:10 +05307392/**
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307393 * __wlan_hdd_cfg80211_sap_configuration_set() - ask driver to restart SAP if
7394 * SAP is on unsafe channel.
7395 * @wiphy: wiphy structure pointer
7396 * @wdev: Wireless device structure pointer
7397 * @data: Pointer to the data received
7398 * @data_len: Length of @data
7399 *
7400 * __wlan_hdd_cfg80211_sap_configuration_set function set SAP params to
7401 * driver.
7402 * QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHAN will set sap config channel and
7403 * will initiate restart of sap.
7404 *
7405 * Return: 0 on success; errno on failure
7406 */
7407static int
7408__wlan_hdd_cfg80211_sap_configuration_set(struct wiphy *wiphy,
7409 struct wireless_dev *wdev,
7410 const void *data, int data_len)
7411{
7412 struct net_device *ndev = wdev->netdev;
7413 hdd_adapter_t *hostapd_adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
7414 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7415 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_MAX + 1];
7416 uint8_t config_channel = 0;
7417 hdd_ap_ctx_t *ap_ctx;
7418 int ret;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05307419 QDF_STATUS status;
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307420
7421 ENTER();
7422
7423 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson77848112016-06-29 14:52:06 -07007424 hdd_err("Command not allowed in FTM mode");
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307425 return -EINVAL;
7426 }
7427
7428 ret = wlan_hdd_validate_context(hdd_ctx);
7429 if (0 != ret)
7430 return -EINVAL;
7431
7432 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_MAX,
7433 data, data_len,
7434 wlan_hdd_sap_config_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07007435 hdd_err("invalid attr");
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307436 return -EINVAL;
7437 }
7438
7439 if (tb[QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHANNEL]) {
7440 if (!test_bit(SOFTAP_BSS_STARTED,
7441 &hostapd_adapter->event_flags)) {
7442 hdd_err("SAP is not started yet. Restart sap will be invalid");
7443 return -EINVAL;
7444 }
7445
7446 config_channel =
7447 nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHANNEL]);
7448
7449 if (!((IS_24G_CH(config_channel)) ||
7450 (IS_5G_CH(config_channel)))) {
7451 hdd_err("Channel %d is not valid to restart SAP",
7452 config_channel);
7453 return -ENOTSUPP;
7454 }
7455
7456 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(hostapd_adapter);
7457 ap_ctx->sapConfig.channel = config_channel;
7458 ap_ctx->sapConfig.ch_params.ch_width =
7459 ap_ctx->sapConfig.ch_width_orig;
7460
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -07007461 cds_set_channel_params(ap_ctx->sapConfig.channel,
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307462 ap_ctx->sapConfig.sec_ch,
7463 &ap_ctx->sapConfig.ch_params);
7464
7465 cds_restart_sap(hostapd_adapter);
7466 }
7467
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05307468 if (tb[QCA_WLAN_VENDOR_ATTR_SAP_MANDATORY_FREQUENCY_LIST]) {
7469 uint32_t freq_len, i;
7470 uint32_t *freq;
7471 uint8_t chans[QDF_MAX_NUM_CHAN];
7472
7473 hdd_debug("setting mandatory freq/chan list");
7474
7475 freq_len = nla_len(
7476 tb[QCA_WLAN_VENDOR_ATTR_SAP_MANDATORY_FREQUENCY_LIST])/
7477 sizeof(uint32_t);
7478
7479 if (freq_len > QDF_MAX_NUM_CHAN) {
7480 hdd_err("insufficient space to hold channels");
7481 return -ENOMEM;
7482 }
7483
7484 freq = nla_data(
7485 tb[QCA_WLAN_VENDOR_ATTR_SAP_MANDATORY_FREQUENCY_LIST]);
7486
7487 hdd_debug("freq_len=%d", freq_len);
7488
7489 for (i = 0; i < freq_len; i++) {
7490 chans[i] = ieee80211_frequency_to_channel(freq[i]);
7491 hdd_debug("freq[%d]=%d", i, freq[i]);
7492 }
7493
7494 status = cds_set_sap_mandatory_channels(chans, freq_len);
7495 if (QDF_IS_STATUS_ERROR(status))
7496 return -EINVAL;
7497 }
7498
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307499 return 0;
7500}
7501
7502/**
7503 * wlan_hdd_cfg80211_sap_configuration_set() - sap configuration vendor command
7504 * @wiphy: wiphy structure pointer
7505 * @wdev: Wireless device structure pointer
7506 * @data: Pointer to the data received
7507 * @data_len: Length of @data
7508 *
7509 * __wlan_hdd_cfg80211_sap_configuration_set function set SAP params to
7510 * driver.
7511 * QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHAN will set sap config channel and
7512 * will initiate restart of sap.
7513 *
7514 * Return: 0 on success; errno on failure
7515 */
7516static int wlan_hdd_cfg80211_sap_configuration_set(struct wiphy *wiphy,
7517 struct wireless_dev *wdev,
7518 const void *data, int data_len)
7519{
7520 int ret;
7521
7522 cds_ssr_protect(__func__);
7523 ret = __wlan_hdd_cfg80211_sap_configuration_set(wiphy,
7524 wdev, data, data_len);
7525 cds_ssr_unprotect(__func__);
7526
7527 return ret;
7528}
7529
Arun Khandavalli2476ef52016-04-26 20:19:43 +05307530#undef BPF_INVALID
7531#undef BPF_SET_RESET
7532#undef BPF_VERSION
7533#undef BPF_ID
7534#undef BPF_PACKET_SIZE
7535#undef BPF_CURRENT_OFFSET
7536#undef BPF_PROGRAM
7537#undef BPF_MAX
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307538
7539/**
7540 * define short names for the global vendor params
7541 * used by wlan_hdd_cfg80211_wakelock_stats_rsp_callback()
7542 */
7543#define PARAM_TOTAL_CMD_EVENT_WAKE \
7544 QCA_WLAN_VENDOR_ATTR_TOTAL_CMD_EVENT_WAKE
7545#define PARAM_CMD_EVENT_WAKE_CNT_PTR \
7546 QCA_WLAN_VENDOR_ATTR_CMD_EVENT_WAKE_CNT_PTR
7547#define PARAM_CMD_EVENT_WAKE_CNT_SZ \
7548 QCA_WLAN_VENDOR_ATTR_CMD_EVENT_WAKE_CNT_SZ
7549#define PARAM_TOTAL_DRIVER_FW_LOCAL_WAKE \
7550 QCA_WLAN_VENDOR_ATTR_TOTAL_DRIVER_FW_LOCAL_WAKE
7551#define PARAM_DRIVER_FW_LOCAL_WAKE_CNT_PTR \
7552 QCA_WLAN_VENDOR_ATTR_DRIVER_FW_LOCAL_WAKE_CNT_PTR
7553#define PARAM_DRIVER_FW_LOCAL_WAKE_CNT_SZ \
7554 QCA_WLAN_VENDOR_ATTR_DRIVER_FW_LOCAL_WAKE_CNT_SZ
7555#define PARAM_TOTAL_RX_DATA_WAKE \
7556 QCA_WLAN_VENDOR_ATTR_TOTAL_RX_DATA_WAKE
7557#define PARAM_RX_UNICAST_CNT \
7558 QCA_WLAN_VENDOR_ATTR_RX_UNICAST_CNT
7559#define PARAM_RX_MULTICAST_CNT \
7560 QCA_WLAN_VENDOR_ATTR_RX_MULTICAST_CNT
7561#define PARAM_RX_BROADCAST_CNT \
7562 QCA_WLAN_VENDOR_ATTR_RX_BROADCAST_CNT
7563#define PARAM_ICMP_PKT \
7564 QCA_WLAN_VENDOR_ATTR_ICMP_PKT
7565#define PARAM_ICMP6_PKT \
7566 QCA_WLAN_VENDOR_ATTR_ICMP6_PKT
7567#define PARAM_ICMP6_RA \
7568 QCA_WLAN_VENDOR_ATTR_ICMP6_RA
7569#define PARAM_ICMP6_NA \
7570 QCA_WLAN_VENDOR_ATTR_ICMP6_NA
7571#define PARAM_ICMP6_NS \
7572 QCA_WLAN_VENDOR_ATTR_ICMP6_NS
7573#define PARAM_ICMP4_RX_MULTICAST_CNT \
7574 QCA_WLAN_VENDOR_ATTR_ICMP4_RX_MULTICAST_CNT
7575#define PARAM_ICMP6_RX_MULTICAST_CNT \
7576 QCA_WLAN_VENDOR_ATTR_ICMP6_RX_MULTICAST_CNT
7577#define PARAM_OTHER_RX_MULTICAST_CNT \
7578 QCA_WLAN_VENDOR_ATTR_OTHER_RX_MULTICAST_CNT
7579
7580
7581/**
7582 * hdd_send_wakelock_stats() - API to send wakelock stats
7583 * @ctx: context to be passed to callback
7584 * @data: data passed to callback
7585 *
7586 * This function is used to send wake lock stats to HAL layer
7587 *
7588 * Return: 0 on success, error number otherwise.
7589 */
7590static uint32_t hdd_send_wakelock_stats(hdd_context_t *hdd_ctx,
7591 const struct sir_wake_lock_stats *data)
7592{
7593 struct sk_buff *skb;
7594 uint32_t nl_buf_len;
7595 uint32_t total_rx_data_wake, rx_multicast_cnt;
7596 uint32_t ipv6_rx_multicast_addr_cnt;
Sreelakshmi Konamkie1cd51f2016-08-19 16:58:24 +05307597 uint32_t icmpv6_cnt;
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307598
7599 ENTER();
7600
7601 nl_buf_len = NLMSG_HDRLEN;
7602 nl_buf_len +=
7603 QCA_WLAN_VENDOR_GET_WAKE_STATS_MAX *
7604 (NLMSG_HDRLEN + sizeof(uint32_t));
7605
7606 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
7607
7608 if (!skb) {
Jeff Johnson64943bd2016-08-23 13:14:06 -07007609 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307610 return -ENOMEM;
7611 }
7612
Jeff Johnson64943bd2016-08-23 13:14:06 -07007613 hdd_info("wow_ucast_wake_up_count %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307614 data->wow_ucast_wake_up_count);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007615 hdd_info("wow_bcast_wake_up_count %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307616 data->wow_bcast_wake_up_count);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007617 hdd_info("wow_ipv4_mcast_wake_up_count %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307618 data->wow_ipv4_mcast_wake_up_count);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007619 hdd_info("wow_ipv6_mcast_wake_up_count %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307620 data->wow_ipv6_mcast_wake_up_count);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007621 hdd_info("wow_ipv6_mcast_ra_stats %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307622 data->wow_ipv6_mcast_ra_stats);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007623 hdd_info("wow_ipv6_mcast_ns_stats %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307624 data->wow_ipv6_mcast_ns_stats);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007625 hdd_info("wow_ipv6_mcast_na_stats %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307626 data->wow_ipv6_mcast_na_stats);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007627 hdd_info("wow_icmpv4_count %d", data->wow_icmpv4_count);
7628 hdd_info("wow_icmpv6_count %d",
Himanshu Agarwal4574e282016-08-10 15:22:45 +05307629 data->wow_icmpv6_count);
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307630
7631 ipv6_rx_multicast_addr_cnt =
Himanshu Agarwal4574e282016-08-10 15:22:45 +05307632 data->wow_ipv6_mcast_wake_up_count;
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307633
Sreelakshmi Konamkie1cd51f2016-08-19 16:58:24 +05307634 icmpv6_cnt =
Himanshu Agarwal4574e282016-08-10 15:22:45 +05307635 data->wow_icmpv6_count;
Sreelakshmi Konamkie1cd51f2016-08-19 16:58:24 +05307636
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307637 rx_multicast_cnt =
7638 data->wow_ipv4_mcast_wake_up_count +
7639 ipv6_rx_multicast_addr_cnt;
7640
7641 total_rx_data_wake =
7642 data->wow_ucast_wake_up_count +
7643 data->wow_bcast_wake_up_count +
7644 rx_multicast_cnt;
7645
7646 if (nla_put_u32(skb, PARAM_TOTAL_CMD_EVENT_WAKE, 0) ||
7647 nla_put_u32(skb, PARAM_CMD_EVENT_WAKE_CNT_PTR, 0) ||
7648 nla_put_u32(skb, PARAM_CMD_EVENT_WAKE_CNT_SZ, 0) ||
7649 nla_put_u32(skb, PARAM_TOTAL_DRIVER_FW_LOCAL_WAKE, 0) ||
7650 nla_put_u32(skb, PARAM_DRIVER_FW_LOCAL_WAKE_CNT_PTR, 0) ||
7651 nla_put_u32(skb, PARAM_DRIVER_FW_LOCAL_WAKE_CNT_SZ, 0) ||
7652 nla_put_u32(skb, PARAM_TOTAL_RX_DATA_WAKE,
7653 total_rx_data_wake) ||
7654 nla_put_u32(skb, PARAM_RX_UNICAST_CNT,
7655 data->wow_ucast_wake_up_count) ||
7656 nla_put_u32(skb, PARAM_RX_MULTICAST_CNT,
7657 rx_multicast_cnt) ||
7658 nla_put_u32(skb, PARAM_RX_BROADCAST_CNT,
7659 data->wow_bcast_wake_up_count) ||
Sreelakshmi Konamkie1cd51f2016-08-19 16:58:24 +05307660 nla_put_u32(skb, PARAM_ICMP_PKT,
7661 data->wow_icmpv4_count) ||
7662 nla_put_u32(skb, PARAM_ICMP6_PKT,
7663 icmpv6_cnt) ||
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307664 nla_put_u32(skb, PARAM_ICMP6_RA,
7665 data->wow_ipv6_mcast_ra_stats) ||
7666 nla_put_u32(skb, PARAM_ICMP6_NA,
7667 data->wow_ipv6_mcast_na_stats) ||
7668 nla_put_u32(skb, PARAM_ICMP6_NS,
7669 data->wow_ipv6_mcast_ns_stats) ||
7670 nla_put_u32(skb, PARAM_ICMP4_RX_MULTICAST_CNT,
7671 data->wow_ipv4_mcast_wake_up_count) ||
7672 nla_put_u32(skb, PARAM_ICMP6_RX_MULTICAST_CNT,
7673 ipv6_rx_multicast_addr_cnt) ||
7674 nla_put_u32(skb, PARAM_OTHER_RX_MULTICAST_CNT, 0)) {
Jeff Johnson64943bd2016-08-23 13:14:06 -07007675 hdd_err("nla put fail");
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307676 goto nla_put_failure;
7677 }
7678
7679 cfg80211_vendor_cmd_reply(skb);
7680
7681 EXIT();
7682 return 0;
7683
7684nla_put_failure:
7685 kfree_skb(skb);
7686 return -EINVAL;
7687}
7688
7689/**
7690 * __wlan_hdd_cfg80211_get_wakelock_stats() - gets wake lock stats
7691 * @wiphy: wiphy pointer
7692 * @wdev: pointer to struct wireless_dev
7693 * @data: pointer to incoming NL vendor data
7694 * @data_len: length of @data
7695 *
7696 * This function parses the incoming NL vendor command data attributes and
7697 * invokes the SME Api and blocks on a completion variable.
7698 * WMA copies required data and invokes callback
7699 * wlan_hdd_cfg80211_wakelock_stats_rsp_callback to send wake lock stats.
7700 *
7701 * Return: 0 on success; error number otherwise.
7702 */
7703static int __wlan_hdd_cfg80211_get_wakelock_stats(struct wiphy *wiphy,
7704 struct wireless_dev *wdev,
7705 const void *data,
7706 int data_len)
7707{
7708 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7709 int status, ret;
7710 struct sir_wake_lock_stats wake_lock_stats;
7711 QDF_STATUS qdf_status;
7712
7713 ENTER();
7714
7715 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson64943bd2016-08-23 13:14:06 -07007716 hdd_err("Command not allowed in FTM mode");
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307717 return -EINVAL;
7718 }
7719
7720 status = wlan_hdd_validate_context(hdd_ctx);
7721 if (0 != status)
7722 return -EINVAL;
7723
7724 qdf_status = wma_get_wakelock_stats(&wake_lock_stats);
7725 if (qdf_status != QDF_STATUS_SUCCESS) {
Jeff Johnson64943bd2016-08-23 13:14:06 -07007726 hdd_err("failed to get wakelock stats(err=%d)", qdf_status);
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307727 return -EINVAL;
7728 }
7729
7730 ret = hdd_send_wakelock_stats(hdd_ctx,
7731 &wake_lock_stats);
7732 if (ret)
Jeff Johnson64943bd2016-08-23 13:14:06 -07007733 hdd_err("Failed to post wake lock stats");
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307734
7735 EXIT();
7736 return ret;
7737}
7738
7739/**
7740 * wlan_hdd_cfg80211_get_wakelock_stats() - gets wake lock stats
7741 * @wiphy: wiphy pointer
7742 * @wdev: pointer to struct wireless_dev
7743 * @data: pointer to incoming NL vendor data
7744 * @data_len: length of @data
7745 *
7746 * This function parses the incoming NL vendor command data attributes and
7747 * invokes the SME Api and blocks on a completion variable.
7748 * WMA copies required data and invokes callback
7749 * wlan_hdd_cfg80211_wakelock_stats_rsp_callback to send wake lock stats.
7750 *
7751 * Return: 0 on success; error number otherwise.
7752 */
7753static int wlan_hdd_cfg80211_get_wakelock_stats(struct wiphy *wiphy,
7754 struct wireless_dev *wdev,
7755 const void *data, int data_len)
7756{
7757 int ret;
7758
7759 cds_ssr_protect(__func__);
7760 ret = __wlan_hdd_cfg80211_get_wakelock_stats(wiphy, wdev, data,
7761 data_len);
Jeff Johnsonf3a64e62016-10-12 17:17:34 -07007762 cds_ssr_unprotect(__func__);
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307763
7764 return ret;
7765}
7766
Srinivas Dasari510e7fe2016-04-28 11:51:30 +05307767/**
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05307768 * __wlan_hdd_cfg80211_get_bus_size() - Get WMI Bus size
7769 * @wiphy: wiphy structure pointer
7770 * @wdev: Wireless device structure pointer
7771 * @data: Pointer to the data received
7772 * @data_len: Length of @data
7773 *
7774 * This function reads wmi max bus size and fill in the skb with
7775 * NL attributes and send up the NL event.
7776 * Return: 0 on success; errno on failure
7777 */
7778static int
7779__wlan_hdd_cfg80211_get_bus_size(struct wiphy *wiphy,
7780 struct wireless_dev *wdev,
7781 const void *data, int data_len)
7782{
7783 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7784 int ret_val;
7785 struct sk_buff *skb;
7786 uint32_t nl_buf_len;
7787
7788 ENTER();
7789
7790 ret_val = wlan_hdd_validate_context(hdd_ctx);
7791 if (ret_val)
7792 return ret_val;
7793
7794 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7795 hdd_err("Command not allowed in FTM mode");
7796 return -EINVAL;
7797 }
7798
7799 hdd_info("WMI Max Bus size: %d", hdd_ctx->wmi_max_len);
7800
7801 nl_buf_len = NLMSG_HDRLEN;
7802 nl_buf_len += (sizeof(hdd_ctx->wmi_max_len) + NLA_HDRLEN);
7803
7804 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
7805 if (!skb) {
7806 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
7807 return -ENOMEM;
7808 }
7809
7810 if (nla_put_u16(skb, QCA_WLAN_VENDOR_ATTR_DRV_INFO_BUS_SIZE,
7811 hdd_ctx->wmi_max_len)) {
7812 hdd_err("nla put failure");
7813 goto nla_put_failure;
7814 }
7815
7816 cfg80211_vendor_cmd_reply(skb);
7817
7818 EXIT();
7819
7820 return 0;
7821
7822nla_put_failure:
7823 kfree_skb(skb);
7824 return -EINVAL;
7825}
7826
7827/**
7828 * wlan_hdd_cfg80211_get_bus_size() - SSR Wrapper to Get Bus size
7829 * @wiphy: wiphy structure pointer
7830 * @wdev: Wireless device structure pointer
7831 * @data: Pointer to the data received
7832 * @data_len: Length of @data
7833 *
7834 * Return: 0 on success; errno on failure
7835 */
7836static int wlan_hdd_cfg80211_get_bus_size(struct wiphy *wiphy,
7837 struct wireless_dev *wdev,
7838 const void *data, int data_len)
7839{
7840 int ret;
7841
7842 cds_ssr_protect(__func__);
7843 ret = __wlan_hdd_cfg80211_get_bus_size(wiphy, wdev, data, data_len);
7844 cds_ssr_unprotect(__func__);
7845
7846 return ret;
7847}
7848
7849/**
Srinivas Dasari510e7fe2016-04-28 11:51:30 +05307850 *__wlan_hdd_cfg80211_setband() - set band
7851 * @wiphy: Pointer to wireless phy
7852 * @wdev: Pointer to wireless device
7853 * @data: Pointer to data
7854 * @data_len: Length of @data
7855 *
7856 * Return: 0 on success, negative errno on failure
7857 */
7858static int __wlan_hdd_cfg80211_setband(struct wiphy *wiphy,
7859 struct wireless_dev *wdev,
7860 const void *data, int data_len)
7861{
7862 struct net_device *dev = wdev->netdev;
7863 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7864 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1];
7865 int ret;
7866 static const struct nla_policy policy[QCA_WLAN_VENDOR_ATTR_MAX + 1]
7867 = {[QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE] = { .type = NLA_U32 } };
7868
7869 ENTER();
7870
7871 ret = wlan_hdd_validate_context(hdd_ctx);
7872 if (ret)
7873 return ret;
7874
7875 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_MAX, data, data_len, policy)) {
7876 hdd_err(FL("Invalid ATTR"));
7877 return -EINVAL;
7878 }
7879
7880 if (!tb[QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE]) {
7881 hdd_err(FL("attr SETBAND_VALUE failed"));
7882 return -EINVAL;
7883 }
7884
7885 ret = hdd_set_band(dev,
7886 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE]));
7887
7888 EXIT();
7889 return ret;
7890}
7891
7892/**
7893 * wlan_hdd_cfg80211_setband() - Wrapper to setband
7894 * @wiphy: wiphy structure pointer
7895 * @wdev: Wireless device structure pointer
7896 * @data: Pointer to the data received
7897 * @data_len: Length of @data
7898 *
7899 * Return: 0 on success; errno on failure
7900 */
7901static int wlan_hdd_cfg80211_setband(struct wiphy *wiphy,
7902 struct wireless_dev *wdev,
7903 const void *data, int data_len)
7904{
7905 int ret;
7906
7907 cds_ssr_protect(__func__);
7908 ret = __wlan_hdd_cfg80211_setband(wiphy, wdev, data, data_len);
7909 cds_ssr_unprotect(__func__);
7910
7911 return ret;
7912}
7913
Mukul Sharma69c44cd2016-09-12 18:33:57 +05307914static const struct
7915nla_policy qca_wlan_vendor_attr[QCA_WLAN_VENDOR_ATTR_MAX+1] = {
7916 [QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY] = {.type = NLA_U32},
7917 [QCA_WLAN_VENDOR_ATTR_MAC_ADDR] = {.type = NLA_BINARY,
7918 .len = QDF_MAC_ADDR_SIZE},
7919};
7920
7921/**
7922 * __wlan_hdd_cfg80211_set_fast_roaming() - enable/disable roaming
7923 * @wiphy: Pointer to wireless phy
7924 * @wdev: Pointer to wireless device
7925 * @data: Pointer to data
7926 * @data_len: Length of @data
7927 *
7928 * This function is used to enable/disable roaming using vendor commands
7929 *
7930 * Return: 0 on success, negative errno on failure
7931 */
7932static int __wlan_hdd_cfg80211_set_fast_roaming(struct wiphy *wiphy,
7933 struct wireless_dev *wdev,
7934 const void *data, int data_len)
7935{
7936 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7937 struct net_device *dev = wdev->netdev;
7938 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
7939 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1];
7940 uint32_t is_fast_roam_enabled;
7941 int ret;
7942
7943 ENTER_DEV(dev);
7944
7945 ret = wlan_hdd_validate_context(hdd_ctx);
7946 if (0 != ret)
7947 return ret;
7948
7949 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7950 hdd_err("Command not allowed in FTM mode");
7951 return -EINVAL;
7952 }
7953
7954 ret = nla_parse(tb, QCA_WLAN_VENDOR_ATTR_MAX, data, data_len,
7955 qca_wlan_vendor_attr);
7956 if (ret) {
7957 hdd_err("Invalid ATTR");
7958 return -EINVAL;
7959 }
7960
7961 /* Parse and fetch Enable flag */
7962 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY]) {
7963 hdd_err("attr enable failed");
7964 return -EINVAL;
7965 }
7966
7967 is_fast_roam_enabled = nla_get_u32(
7968 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY]);
7969 hdd_notice("isFastRoamEnabled %d", is_fast_roam_enabled);
7970
7971 /* Update roaming */
7972 ret = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
7973 is_fast_roam_enabled);
7974 if (ret)
7975 hdd_err("sme_config_fast_roaming failed");
7976 EXIT();
7977 return ret;
7978}
7979
7980/**
7981 * wlan_hdd_cfg80211_set_fast_roaming() - enable/disable roaming
7982 * @wiphy: Pointer to wireless phy
7983 * @wdev: Pointer to wireless device
7984 * @data: Pointer to data
7985 * @data_len: Length of @data
7986 *
7987 * Wrapper function of __wlan_hdd_cfg80211_set_fast_roaming()
7988 *
7989 * Return: 0 on success, negative errno on failure
7990 */
7991static int wlan_hdd_cfg80211_set_fast_roaming(struct wiphy *wiphy,
7992 struct wireless_dev *wdev,
7993 const void *data, int data_len)
7994{
7995 int ret;
7996
7997 cds_ssr_protect(__func__);
7998 ret = __wlan_hdd_cfg80211_set_fast_roaming(wiphy, wdev, data, data_len);
7999 cds_ssr_unprotect(__func__);
8000
8001 return ret;
8002}
8003
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008004const struct wiphy_vendor_command hdd_wiphy_vendor_commands[] = {
8005 {
8006 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8007 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY,
8008 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
Srinivas Dasari947abd72016-09-02 12:11:33 +05308009 WIPHY_VENDOR_CMD_NEED_NETDEV,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008010 .doit = is_driver_dfs_capable
8011 },
8012
8013#ifdef WLAN_FEATURE_NAN
8014 {
8015 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8016 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_NAN,
8017 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8018 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8019 .doit = wlan_hdd_cfg80211_nan_request
8020 },
8021#endif
8022
8023#ifdef WLAN_FEATURE_STATS_EXT
8024 {
8025 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8026 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_STATS_EXT,
8027 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8028 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8029 .doit = wlan_hdd_cfg80211_stats_ext_request
8030 },
8031#endif
8032#ifdef FEATURE_WLAN_EXTSCAN
8033 {
8034 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8035 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_START,
8036 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8037 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8038 .doit = wlan_hdd_cfg80211_extscan_start
8039 },
8040 {
8041 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8042 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_STOP,
8043 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8044 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8045 .doit = wlan_hdd_cfg80211_extscan_stop
8046 },
8047 {
8048 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8049 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_VALID_CHANNELS,
8050 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
8051 .doit = wlan_hdd_cfg80211_extscan_get_valid_channels
8052 },
8053 {
8054 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8055 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CAPABILITIES,
8056 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8057 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8058 .doit = wlan_hdd_cfg80211_extscan_get_capabilities
8059 },
8060 {
8061 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8062 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CACHED_RESULTS,
8063 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8064 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8065 .doit = wlan_hdd_cfg80211_extscan_get_cached_results
8066 },
8067 {
8068 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8069 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_BSSID_HOTLIST,
8070 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8071 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8072 .doit = wlan_hdd_cfg80211_extscan_set_bssid_hotlist
8073 },
8074 {
8075 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8076 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_BSSID_HOTLIST,
8077 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8078 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8079 .doit = wlan_hdd_cfg80211_extscan_reset_bssid_hotlist
8080 },
8081 {
8082 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8083 .info.subcmd =
8084 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SIGNIFICANT_CHANGE,
8085 .flags =
8086 WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV |
8087 WIPHY_VENDOR_CMD_NEED_RUNNING,
8088 .doit = wlan_hdd_cfg80211_extscan_set_significant_change
8089 },
8090 {
8091 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8092 .info.subcmd =
8093 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SIGNIFICANT_CHANGE,
8094 .flags =
8095 WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV |
8096 WIPHY_VENDOR_CMD_NEED_RUNNING,
8097 .doit = wlan_hdd_cfg80211_extscan_reset_significant_change
8098 },
8099 {
8100 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8101 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_SET_LIST,
8102 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8103 WIPHY_VENDOR_CMD_NEED_NETDEV |
8104 WIPHY_VENDOR_CMD_NEED_RUNNING,
8105 .doit = wlan_hdd_cfg80211_set_epno_list
8106 },
8107#endif /* FEATURE_WLAN_EXTSCAN */
8108
8109#ifdef WLAN_FEATURE_LINK_LAYER_STATS
8110 {
8111 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8112 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR,
8113 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8114 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8115 .doit = wlan_hdd_cfg80211_ll_stats_clear
8116 },
8117
8118 {
8119 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8120 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET,
8121 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8122 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8123 .doit = wlan_hdd_cfg80211_ll_stats_set
8124 },
8125
8126 {
8127 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8128 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET,
8129 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8130 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8131 .doit = wlan_hdd_cfg80211_ll_stats_get
8132 },
8133#endif /* WLAN_FEATURE_LINK_LAYER_STATS */
8134#ifdef FEATURE_WLAN_TDLS
8135 {
8136 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8137 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TDLS_ENABLE,
8138 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8139 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8140 .doit = wlan_hdd_cfg80211_exttdls_enable
8141 },
8142 {
8143 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8144 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TDLS_DISABLE,
8145 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8146 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8147 .doit = wlan_hdd_cfg80211_exttdls_disable
8148 },
8149 {
8150 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8151 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TDLS_GET_STATUS,
8152 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
8153 .doit = wlan_hdd_cfg80211_exttdls_get_status
8154 },
8155#endif
8156 {
8157 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8158 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_FEATURES,
8159 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
8160 .doit = wlan_hdd_cfg80211_get_supported_features
8161 },
8162 {
8163 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8164 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SCANNING_MAC_OUI,
8165 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
8166 .doit = wlan_hdd_cfg80211_set_scanning_mac_oui
8167 },
8168 {
8169 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8170 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_CONCURRENCY_MATRIX,
8171 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05308172 .doit = wlan_hdd_cfg80211_get_concurrency_matrix
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008173 },
8174 {
8175 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8176 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_NO_DFS_FLAG,
8177 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8178 WIPHY_VENDOR_CMD_NEED_NETDEV,
8179 .doit = wlan_hdd_cfg80211_disable_dfs_chan_scan
8180 },
Manikandan Mohan80dea792016-04-28 16:36:48 -07008181 {
8182 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8183 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_WISA,
8184 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8185 WIPHY_VENDOR_CMD_NEED_NETDEV,
8186 .doit = wlan_hdd_cfg80211_handle_wisa_cmd
8187 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008188 {
8189 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Anurag Chouhan96919482016-07-13 16:36:57 +05308190 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_STATION,
8191 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8192 WIPHY_VENDOR_CMD_NEED_NETDEV |
8193 WIPHY_VENDOR_CMD_NEED_RUNNING,
8194 .doit = hdd_cfg80211_get_station_cmd
8195 },
8196 {
8197 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008198 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DO_ACS,
8199 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8200 WIPHY_VENDOR_CMD_NEED_NETDEV |
8201 WIPHY_VENDOR_CMD_NEED_RUNNING,
8202 .doit = wlan_hdd_cfg80211_do_acs
8203 },
8204
8205 {
8206 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8207 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES,
8208 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8209 WIPHY_VENDOR_CMD_NEED_NETDEV,
8210 .doit = wlan_hdd_cfg80211_get_features
8211 },
8212#ifdef WLAN_FEATURE_ROAM_OFFLOAD
8213 {
8214 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8215 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY,
8216 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8217 WIPHY_VENDOR_CMD_NEED_NETDEV |
8218 WIPHY_VENDOR_CMD_NEED_RUNNING,
8219 .doit = wlan_hdd_cfg80211_keymgmt_set_key
8220 },
8221#endif
8222#ifdef FEATURE_WLAN_EXTSCAN
8223 {
8224 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8225 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_SET_PASSPOINT_LIST,
8226 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8227 WIPHY_VENDOR_CMD_NEED_NETDEV |
8228 WIPHY_VENDOR_CMD_NEED_RUNNING,
8229 .doit = wlan_hdd_cfg80211_set_passpoint_list
8230 },
8231 {
8232 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8233 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_RESET_PASSPOINT_LIST,
8234 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8235 WIPHY_VENDOR_CMD_NEED_NETDEV |
8236 WIPHY_VENDOR_CMD_NEED_RUNNING,
8237 .doit = wlan_hdd_cfg80211_reset_passpoint_list
8238 },
8239 {
8240 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8241 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SSID_HOTLIST,
8242 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8243 WIPHY_VENDOR_CMD_NEED_NETDEV |
8244 WIPHY_VENDOR_CMD_NEED_RUNNING,
8245 .doit = wlan_hdd_cfg80211_extscan_set_ssid_hotlist
8246 },
8247 {
8248 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8249 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SSID_HOTLIST,
8250 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8251 WIPHY_VENDOR_CMD_NEED_NETDEV |
8252 WIPHY_VENDOR_CMD_NEED_RUNNING,
8253 .doit = wlan_hdd_cfg80211_extscan_reset_ssid_hotlist
8254 },
8255#endif /* FEATURE_WLAN_EXTSCAN */
8256 {
8257 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8258 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_WIFI_INFO,
8259 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8260 WIPHY_VENDOR_CMD_NEED_NETDEV,
8261 .doit = wlan_hdd_cfg80211_get_wifi_info
8262 },
8263 {
8264 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8265 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION,
8266 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8267 WIPHY_VENDOR_CMD_NEED_NETDEV |
8268 WIPHY_VENDOR_CMD_NEED_RUNNING,
8269 .doit = wlan_hdd_cfg80211_wifi_configuration_set
8270 },
8271 {
8272 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8273 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ROAM,
8274 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8275 WIPHY_VENDOR_CMD_NEED_NETDEV,
8276 .doit = wlan_hdd_cfg80211_set_ext_roam_params
8277 },
8278 {
8279 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8280 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_WIFI_LOGGER_START,
8281 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8282 WIPHY_VENDOR_CMD_NEED_NETDEV,
8283 .doit = wlan_hdd_cfg80211_wifi_logger_start
8284 },
8285 {
8286 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8287 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_RING_DATA,
8288 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8289 WIPHY_VENDOR_CMD_NEED_NETDEV,
8290 .doit = wlan_hdd_cfg80211_wifi_logger_get_ring_data
8291 },
8292 {
8293 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8294 .info.subcmd =
8295 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST,
8296 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8297 WIPHY_VENDOR_CMD_NEED_NETDEV |
8298 WIPHY_VENDOR_CMD_NEED_RUNNING,
8299 .doit = wlan_hdd_cfg80211_get_preferred_freq_list
8300 },
8301 {
8302 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8303 .info.subcmd =
8304 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL,
8305 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8306 WIPHY_VENDOR_CMD_NEED_NETDEV |
8307 WIPHY_VENDOR_CMD_NEED_RUNNING,
8308 .doit = wlan_hdd_cfg80211_set_probable_oper_channel
8309 },
Manikandan Mohan5356c2b2016-04-03 15:51:35 -07008310#ifdef WLAN_FEATURE_TSF
8311 {
8312 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8313 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TSF,
8314 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8315 WIPHY_VENDOR_CMD_NEED_NETDEV |
8316 WIPHY_VENDOR_CMD_NEED_RUNNING,
8317 .doit = wlan_hdd_cfg80211_handle_tsf_cmd
8318 },
8319#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008320#ifdef FEATURE_WLAN_TDLS
8321 {
8322 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8323 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TDLS_GET_CAPABILITIES,
8324 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8325 WIPHY_VENDOR_CMD_NEED_NETDEV |
8326 WIPHY_VENDOR_CMD_NEED_RUNNING,
8327 .doit = wlan_hdd_cfg80211_get_tdls_capabilities
8328 },
8329#endif
8330#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8331 {
8332 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8333 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OFFLOADED_PACKETS,
8334 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8335 WIPHY_VENDOR_CMD_NEED_NETDEV |
8336 WIPHY_VENDOR_CMD_NEED_RUNNING,
8337 .doit = wlan_hdd_cfg80211_offloaded_packets
8338 },
8339#endif
8340 {
8341 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8342 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_MONITOR_RSSI,
8343 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8344 WIPHY_VENDOR_CMD_NEED_NETDEV |
8345 WIPHY_VENDOR_CMD_NEED_RUNNING,
8346 .doit = wlan_hdd_cfg80211_monitor_rssi
8347 },
8348 {
8349 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308350 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ND_OFFLOAD,
8351 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8352 WIPHY_VENDOR_CMD_NEED_NETDEV |
8353 WIPHY_VENDOR_CMD_NEED_RUNNING,
8354 .doit = wlan_hdd_cfg80211_set_ns_offload
8355 },
8356 {
8357 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008358 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_LOGGER_FEATURE_SET,
8359 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8360 WIPHY_VENDOR_CMD_NEED_NETDEV |
8361 WIPHY_VENDOR_CMD_NEED_RUNNING,
8362 .doit = wlan_hdd_cfg80211_get_logger_supp_feature
8363 },
8364#ifdef WLAN_FEATURE_MEMDUMP
8365 {
8366 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8367 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_WIFI_LOGGER_MEMORY_DUMP,
8368 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8369 WIPHY_VENDOR_CMD_NEED_NETDEV |
8370 WIPHY_VENDOR_CMD_NEED_RUNNING,
8371 .doit = wlan_hdd_cfg80211_get_fw_mem_dump
8372 },
8373#endif /* WLAN_FEATURE_MEMDUMP */
8374 {
8375 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8376 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN,
8377 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8378 WIPHY_VENDOR_CMD_NEED_NETDEV |
8379 WIPHY_VENDOR_CMD_NEED_RUNNING,
8380 .doit = wlan_hdd_cfg80211_vendor_scan
8381 },
8382
8383 /* OCB commands */
8384 {
8385 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8386 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OCB_SET_CONFIG,
8387 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8388 WIPHY_VENDOR_CMD_NEED_NETDEV |
8389 WIPHY_VENDOR_CMD_NEED_RUNNING,
8390 .doit = wlan_hdd_cfg80211_ocb_set_config
8391 },
8392 {
8393 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8394 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OCB_SET_UTC_TIME,
8395 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8396 WIPHY_VENDOR_CMD_NEED_NETDEV |
8397 WIPHY_VENDOR_CMD_NEED_RUNNING,
8398 .doit = wlan_hdd_cfg80211_ocb_set_utc_time
8399 },
8400 {
8401 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8402 .info.subcmd =
8403 QCA_NL80211_VENDOR_SUBCMD_OCB_START_TIMING_ADVERT,
8404 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8405 WIPHY_VENDOR_CMD_NEED_NETDEV |
8406 WIPHY_VENDOR_CMD_NEED_RUNNING,
8407 .doit = wlan_hdd_cfg80211_ocb_start_timing_advert
8408 },
8409 {
8410 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8411 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OCB_STOP_TIMING_ADVERT,
8412 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8413 WIPHY_VENDOR_CMD_NEED_NETDEV |
8414 WIPHY_VENDOR_CMD_NEED_RUNNING,
8415 .doit = wlan_hdd_cfg80211_ocb_stop_timing_advert
8416 },
8417 {
8418 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8419 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OCB_GET_TSF_TIMER,
8420 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8421 WIPHY_VENDOR_CMD_NEED_NETDEV |
8422 WIPHY_VENDOR_CMD_NEED_RUNNING,
8423 .doit = wlan_hdd_cfg80211_ocb_get_tsf_timer
8424 },
8425 {
8426 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8427 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DCC_GET_STATS,
8428 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8429 WIPHY_VENDOR_CMD_NEED_NETDEV |
8430 WIPHY_VENDOR_CMD_NEED_RUNNING,
8431 .doit = wlan_hdd_cfg80211_dcc_get_stats
8432 },
8433 {
8434 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8435 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DCC_CLEAR_STATS,
8436 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8437 WIPHY_VENDOR_CMD_NEED_NETDEV |
8438 WIPHY_VENDOR_CMD_NEED_RUNNING,
8439 .doit = wlan_hdd_cfg80211_dcc_clear_stats
8440 },
8441 {
8442 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8443 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DCC_UPDATE_NDL,
8444 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8445 WIPHY_VENDOR_CMD_NEED_NETDEV |
8446 WIPHY_VENDOR_CMD_NEED_RUNNING,
8447 .doit = wlan_hdd_cfg80211_dcc_update_ndl
8448 },
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05308449 {
8450 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8451 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_LINK_PROPERTIES,
8452 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8453 WIPHY_VENDOR_CMD_NEED_NETDEV |
8454 WIPHY_VENDOR_CMD_NEED_RUNNING,
8455 .doit = wlan_hdd_cfg80211_get_link_properties
8456 },
Peng Xu278d0122015-09-24 16:34:17 -07008457 {
Peng Xud2220962016-07-11 17:59:17 -07008458 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Peng Xu278d0122015-09-24 16:34:17 -07008459 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OTA_TEST,
8460 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8461 WIPHY_VENDOR_CMD_NEED_NETDEV |
8462 WIPHY_VENDOR_CMD_NEED_RUNNING,
8463 .doit = wlan_hdd_cfg80211_set_ota_test
8464 },
Ravi Joshideb5a8d2015-11-09 19:11:43 -08008465#ifdef FEATURE_LFR_SUBNET_DETECTION
8466 {
8467 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8468 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GW_PARAM_CONFIG,
8469 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8470 WIPHY_VENDOR_CMD_NEED_NETDEV |
8471 WIPHY_VENDOR_CMD_NEED_RUNNING,
8472 .doit = wlan_hdd_cfg80211_set_gateway_params
8473 },
8474#endif /* FEATURE_LFR_SUBNET_DETECTION */
Peng Xu4d67c8f2015-10-16 16:02:26 -07008475 {
Peng Xud2220962016-07-11 17:59:17 -07008476 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Peng Xu4d67c8f2015-10-16 16:02:26 -07008477 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SET_TXPOWER_SCALE,
8478 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8479 WIPHY_VENDOR_CMD_NEED_NETDEV |
8480 WIPHY_VENDOR_CMD_NEED_RUNNING,
8481 .doit = wlan_hdd_cfg80211_txpower_scale
8482 },
8483 {
8484 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8485 .info.subcmd =
8486 QCA_NL80211_VENDOR_SUBCMD_SET_TXPOWER_SCALE_DECR_DB,
8487 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8488 WIPHY_VENDOR_CMD_NEED_NETDEV |
8489 WIPHY_VENDOR_CMD_NEED_RUNNING,
8490 .doit = wlan_hdd_cfg80211_txpower_scale_decr_db
8491 },
Arun Khandavalli2476ef52016-04-26 20:19:43 +05308492 {
8493 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8494 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_PACKET_FILTER,
8495 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8496 WIPHY_VENDOR_CMD_NEED_NETDEV |
8497 WIPHY_VENDOR_CMD_NEED_RUNNING,
8498 .doit = wlan_hdd_cfg80211_bpf_offload
8499 },
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05308500 {
8501 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Agrawal Ashish65634612016-08-18 13:24:32 +05308502 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ACS_POLICY,
8503 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8504 WIPHY_VENDOR_CMD_NEED_NETDEV |
8505 WIPHY_VENDOR_CMD_NEED_RUNNING,
8506 .doit = wlan_hdd_cfg80211_acs_dfs_mode
8507 },
8508 {
8509 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Agrawal Ashish21ba2572016-09-03 16:40:10 +05308510 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_STA_CONNECT_ROAM_POLICY,
8511 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8512 WIPHY_VENDOR_CMD_NEED_NETDEV |
8513 WIPHY_VENDOR_CMD_NEED_RUNNING,
8514 .doit = wlan_hdd_cfg80211_sta_roam_policy
8515 },
Agrawal Ashish467dde42016-09-08 18:44:22 +05308516#ifdef FEATURE_WLAN_CH_AVOID
8517 {
8518 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8519 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY,
8520 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8521 WIPHY_VENDOR_CMD_NEED_NETDEV |
8522 WIPHY_VENDOR_CMD_NEED_RUNNING,
8523 .doit = wlan_hdd_cfg80211_avoid_freq
8524 },
8525#endif
Agrawal Ashish21ba2572016-09-03 16:40:10 +05308526 {
8527 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05308528 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SET_SAP_CONFIG,
8529 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8530 WIPHY_VENDOR_CMD_NEED_NETDEV |
8531 WIPHY_VENDOR_CMD_NEED_RUNNING,
8532 .doit = wlan_hdd_cfg80211_sap_configuration_set
8533 },
Peng Xu8fdaa492016-06-22 10:20:47 -07008534 {
Peng Xu4225c152016-07-14 21:18:14 -07008535 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Peng Xu8fdaa492016-06-22 10:20:47 -07008536 .info.subcmd =
8537 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START,
8538 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8539 WIPHY_VENDOR_CMD_NEED_NETDEV |
8540 WIPHY_VENDOR_CMD_NEED_RUNNING,
8541 .doit = wlan_hdd_cfg80211_p2p_lo_start
8542 },
8543 {
8544 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8545 .info.subcmd =
8546 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP,
8547 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8548 WIPHY_VENDOR_CMD_NEED_NETDEV |
8549 WIPHY_VENDOR_CMD_NEED_RUNNING,
8550 .doit = wlan_hdd_cfg80211_p2p_lo_stop
8551 },
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05308552 {
8553 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8554 .info.subcmd =
8555 QCA_NL80211_VENDOR_SUBCMD_SAP_CONDITIONAL_CHAN_SWITCH,
8556 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8557 WIPHY_VENDOR_CMD_NEED_NETDEV |
8558 WIPHY_VENDOR_CMD_NEED_RUNNING,
8559 .doit = wlan_hdd_cfg80211_conditional_chan_switch
8560 },
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07008561#ifdef WLAN_FEATURE_NAN_DATAPATH
8562 {
8563 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8564 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_NDP,
8565 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8566 WIPHY_VENDOR_CMD_NEED_NETDEV |
8567 WIPHY_VENDOR_CMD_NEED_RUNNING,
8568 .doit = wlan_hdd_cfg80211_process_ndp_cmd
8569 },
8570#endif
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05308571 {
8572 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8573 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_WAKE_REASON_STATS,
8574 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8575 WIPHY_VENDOR_CMD_NEED_NETDEV |
8576 WIPHY_VENDOR_CMD_NEED_RUNNING,
8577 .doit = wlan_hdd_cfg80211_get_wakelock_stats
8578 },
Srinivas Dasari510e7fe2016-04-28 11:51:30 +05308579 {
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05308580 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8581 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_BUS_SIZE,
8582 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8583 WIPHY_VENDOR_CMD_NEED_NETDEV |
8584 WIPHY_VENDOR_CMD_NEED_RUNNING,
8585 .doit = wlan_hdd_cfg80211_get_bus_size
8586 },
8587 {
Srinivas Dasari510e7fe2016-04-28 11:51:30 +05308588 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SETBAND,
8589 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8590 WIPHY_VENDOR_CMD_NEED_NETDEV |
8591 WIPHY_VENDOR_CMD_NEED_RUNNING,
8592 .doit = wlan_hdd_cfg80211_setband
Mukul Sharma69c44cd2016-09-12 18:33:57 +05308593 },
8594 {
8595 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8596 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ROAMING,
8597 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8598 WIPHY_VENDOR_CMD_NEED_NETDEV |
8599 WIPHY_VENDOR_CMD_NEED_RUNNING,
8600 .doit = wlan_hdd_cfg80211_set_fast_roaming
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +05308601 },
8602#ifdef WLAN_FEATURE_DISA
8603 {
8604 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8605 .info.subcmd =
8606 QCA_NL80211_VENDOR_SUBCMD_ENCRYPTION_TEST,
8607 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8608 WIPHY_VENDOR_CMD_NEED_NETDEV |
8609 WIPHY_VENDOR_CMD_NEED_RUNNING,
8610 .doit = wlan_hdd_cfg80211_encrypt_decrypt_msg
8611 },
8612#endif
Kabilan Kannand053aaf2016-10-26 02:06:14 -07008613#ifdef FEATURE_WLAN_TDLS
8614 {
8615 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8616 .info.subcmd =
8617 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS,
8618 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8619 WIPHY_VENDOR_CMD_NEED_NETDEV |
8620 WIPHY_VENDOR_CMD_NEED_RUNNING,
8621 .doit = wlan_hdd_cfg80211_configure_tdls_mode
8622 }
8623#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008624};
8625
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008626/**
8627 * hdd_cfg80211_wiphy_alloc() - Allocate wiphy context
8628 * @priv_size: Size of the hdd context.
8629 *
8630 * Allocate wiphy context and hdd context.
8631 *
8632 * Return: hdd context on success and NULL on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008633 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008634hdd_context_t *hdd_cfg80211_wiphy_alloc(int priv_size)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008635{
8636 struct wiphy *wiphy;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008637 hdd_context_t *hdd_ctx;
8638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008639 ENTER();
8640
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008641 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
8642
8643 if (!wiphy) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008644 hdd_err("wiphy init failed!\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008645 return NULL;
8646 }
8647
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008648 hdd_ctx = wiphy_priv(wiphy);
8649
8650 hdd_ctx->wiphy = wiphy;
8651
8652 return hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008653}
8654
8655/*
8656 * FUNCTION: wlan_hdd_cfg80211_update_band
8657 * This function is called from the supplicant through a
8658 * private ioctl to change the band value
8659 */
8660int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
8661{
8662 int i, j;
Amar Singhala297bfa2015-10-15 15:07:29 -07008663 enum channel_state channelEnabledState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008664
8665 ENTER();
8666
Dustin Browna30892e2016-10-12 17:28:36 -07008667 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008668
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -08008669 if (NULL == wiphy->bands[i])
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008670 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008671
8672 for (j = 0; j < wiphy->bands[i]->n_channels; j++) {
8673 struct ieee80211_supported_band *band = wiphy->bands[i];
8674
8675 channelEnabledState =
8676 cds_get_channel_state(band->channels[j].
8677 hw_value);
8678
Dustin Browna30892e2016-10-12 17:28:36 -07008679 if (NL80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008680 /* 5G only */
8681#ifdef WLAN_ENABLE_SOCIAL_CHANNELS_5G_ONLY
8682 /* Enable Social channels for P2P */
8683 if (WLAN_HDD_IS_SOCIAL_CHANNEL
8684 (band->channels[j].center_freq)
8685 && CHANNEL_STATE_ENABLE ==
8686 channelEnabledState)
8687 band->channels[j].flags &=
8688 ~IEEE80211_CHAN_DISABLED;
8689 else
8690#endif
8691 band->channels[j].flags |=
8692 IEEE80211_CHAN_DISABLED;
8693 continue;
Dustin Browna30892e2016-10-12 17:28:36 -07008694 } else if (NL80211_BAND_5GHZ == i &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008695 eCSR_BAND_24 == eBand) {
8696 /* 2G only */
8697 band->channels[j].flags |=
8698 IEEE80211_CHAN_DISABLED;
8699 continue;
8700 }
8701
Amar Singhal6842e8f2016-02-23 16:30:32 -08008702 if (CHANNEL_STATE_DISABLE != channelEnabledState)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008703 band->channels[j].flags &=
8704 ~IEEE80211_CHAN_DISABLED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008705 }
8706 }
8707 return 0;
8708}
8709
8710/*
8711 * FUNCTION: wlan_hdd_cfg80211_init
8712 * This function is called by hdd_wlan_startup()
8713 * during initialization.
8714 * This function is used to initialize and register wiphy structure.
8715 */
8716int wlan_hdd_cfg80211_init(struct device *dev,
8717 struct wiphy *wiphy, struct hdd_config *pCfg)
8718{
8719 int i, j;
8720 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8721
8722 ENTER();
8723
8724 /* Now bind the underlying wlan device with wiphy */
8725 set_wiphy_dev(wiphy, dev);
8726
8727 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
8728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008729#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
8730 wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS;
Amar Singhal01098f72015-10-08 11:55:32 -07008731 wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008732#else
8733 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhal01098f72015-10-08 11:55:32 -07008734 wiphy->country_ie_pref |= NL80211_COUNTRY_IE_IGNORE_CORE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008735#endif
8736
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008737 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
8738 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
8739 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
8740#ifdef FEATURE_WLAN_STA_4ADDR_SCHEME
8741 | WIPHY_FLAG_4ADDR_STATION
8742#endif
8743 | WIPHY_FLAG_OFFCHAN_TX;
8744
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008745#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
8746 wiphy->wowlan = &wowlan_support_cfg80211_init;
8747#else
8748 wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
8749 wiphy->wowlan.n_patterns = WOWL_MAX_PTRNS_ALLOWED;
8750 wiphy->wowlan.pattern_min_len = 1;
8751 wiphy->wowlan.pattern_max_len = WOWL_PTRN_MAX_SIZE;
8752#endif
8753
Deepak Dhamdherea2df6bb2015-10-29 15:11:06 -07008754 if (pCfg->isFastTransitionEnabled || pCfg->isFastRoamIniFeatureEnabled
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008755#ifdef FEATURE_WLAN_ESE
8756 || pCfg->isEseIniFeatureEnabled
8757#endif
8758 ) {
8759 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
8760 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008761#ifdef FEATURE_WLAN_TDLS
8762 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
8763 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
8764#endif
8765
8766 wiphy->features |= NL80211_FEATURE_HT_IBSS;
8767
Naveen Rawatc77e6e72016-08-05 15:19:03 -07008768#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0))
8769 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8770#endif
8771
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008772#ifdef FEATURE_WLAN_SCAN_PNO
8773 if (pCfg->configPNOScanSupport) {
8774 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
8775 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
8776 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
8777 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Ryan Hsub736bc52016-06-15 16:58:24 -07008778#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) || defined(WITH_BACKPORTS)
8779 wiphy->max_sched_scan_plans = SIR_PNO_MAX_PLAN_REQUEST;
8780#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008781 }
8782#endif /*FEATURE_WLAN_SCAN_PNO */
8783
8784#if defined QCA_WIFI_FTM
Anurag Chouhan6d760662016-02-20 16:05:43 +05308785 if (cds_get_conparam() != QDF_GLOBAL_FTM_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008786#endif
8787
8788 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
8789 driver can still register regulatory callback and
8790 it will get regulatory settings in wiphy->band[], but
8791 driver need to determine what to do with both
8792 regulatory settings */
8793
8794 wiphy->reg_notifier = hdd_reg_notifier;
8795
8796#if defined QCA_WIFI_FTM
8797}
8798#endif
8799
8800 wiphy->max_scan_ssids = MAX_SCAN_SSID;
8801
8802 wiphy->max_scan_ie_len = SIR_MAC_MAX_ADD_IE_LENGTH;
8803
8804 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
8805
Arun Khandavallifae92942016-08-01 13:31:08 +05308806 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
8807 | BIT(NL80211_IFTYPE_ADHOC)
8808 | BIT(NL80211_IFTYPE_P2P_CLIENT)
8809 | BIT(NL80211_IFTYPE_P2P_GO)
8810 | BIT(NL80211_IFTYPE_AP)
8811 | BIT(NL80211_IFTYPE_MONITOR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008812
Arun Khandavallifae92942016-08-01 13:31:08 +05308813 if (pCfg->advertiseConcurrentOperation) {
8814 if (pCfg->enableMCC) {
8815 int i;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07008816
Arun Khandavallifae92942016-08-01 13:31:08 +05308817 for (i = 0;
8818 i < ARRAY_SIZE(wlan_hdd_iface_combination);
8819 i++) {
8820 if (!pCfg->allowMCCGODiffBI)
8821 wlan_hdd_iface_combination[i].
8822 beacon_int_infra_match = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008823 }
8824 }
8825 wiphy->n_iface_combinations =
Arun Khandavallifae92942016-08-01 13:31:08 +05308826 ARRAY_SIZE(wlan_hdd_iface_combination);
8827 wiphy->iface_combinations = wlan_hdd_iface_combination;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008828 }
8829
8830 /* Before registering we need to update the ht capabilitied based
8831 * on ini values*/
8832 if (!pCfg->ShortGI20MhzEnable) {
8833 wlan_hdd_band_2_4_ghz.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
8834 wlan_hdd_band_5_ghz.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008835 }
8836
8837 if (!pCfg->ShortGI40MhzEnable) {
8838 wlan_hdd_band_5_ghz.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
8839 }
8840
8841 if (!pCfg->nChannelBondingMode5GHz) {
8842 wlan_hdd_band_5_ghz.ht_cap.cap &=
8843 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
8844 }
8845
Abhishek Singhf512bf32016-05-04 16:47:46 +05308846 /*
8847 * In case of static linked driver at the time of driver unload,
8848 * module exit doesn't happens. Module cleanup helps in cleaning
8849 * of static memory.
8850 * If driver load happens statically, at the time of driver unload,
8851 * wiphy flags don't get reset because of static memory.
8852 * It's better not to store channel in static memory.
8853 */
Dustin Browna30892e2016-10-12 17:28:36 -07008854 wiphy->bands[NL80211_BAND_2GHZ] = &wlan_hdd_band_2_4_ghz;
8855 wiphy->bands[NL80211_BAND_2GHZ]->channels =
Abhishek Singhf512bf32016-05-04 16:47:46 +05308856 qdf_mem_malloc(sizeof(hdd_channels_2_4_ghz));
Dustin Browna30892e2016-10-12 17:28:36 -07008857 if (wiphy->bands[NL80211_BAND_2GHZ]->channels == NULL) {
Abhishek Singhf512bf32016-05-04 16:47:46 +05308858 hdd_err("Not enough memory to allocate channels");
8859 return -ENOMEM;
8860 }
Dustin Browna30892e2016-10-12 17:28:36 -07008861 qdf_mem_copy(wiphy->bands[NL80211_BAND_2GHZ]->channels,
Abhishek Singhf512bf32016-05-04 16:47:46 +05308862 &hdd_channels_2_4_ghz[0],
8863 sizeof(hdd_channels_2_4_ghz));
Selvaraj, Sridharcd3cc702016-07-31 15:37:07 +05308864 if ((hdd_is_5g_supported(pHddCtx)) &&
8865 ((eHDD_DOT11_MODE_11b != pCfg->dot11Mode) &&
8866 (eHDD_DOT11_MODE_11g != pCfg->dot11Mode) &&
8867 (eHDD_DOT11_MODE_11b_ONLY != pCfg->dot11Mode) &&
8868 (eHDD_DOT11_MODE_11g_ONLY != pCfg->dot11Mode))) {
Dustin Browna30892e2016-10-12 17:28:36 -07008869 wiphy->bands[NL80211_BAND_5GHZ] = &wlan_hdd_band_5_ghz;
8870 wiphy->bands[NL80211_BAND_5GHZ]->channels =
Abhishek Singhf512bf32016-05-04 16:47:46 +05308871 qdf_mem_malloc(sizeof(hdd_channels_5_ghz));
Dustin Browna30892e2016-10-12 17:28:36 -07008872 if (wiphy->bands[NL80211_BAND_5GHZ]->channels == NULL) {
Abhishek Singhf512bf32016-05-04 16:47:46 +05308873 hdd_err("Not enough memory to allocate channels");
8874 qdf_mem_free(wiphy->
Dustin Browna30892e2016-10-12 17:28:36 -07008875 bands[NL80211_BAND_2GHZ]->channels);
8876 wiphy->bands[NL80211_BAND_2GHZ]->channels = NULL;
Abhishek Singhf512bf32016-05-04 16:47:46 +05308877 return -ENOMEM;
8878 }
Dustin Browna30892e2016-10-12 17:28:36 -07008879 qdf_mem_copy(wiphy->bands[NL80211_BAND_5GHZ]->channels,
Abhishek Singhf512bf32016-05-04 16:47:46 +05308880 &hdd_channels_5_ghz[0],
8881 sizeof(hdd_channels_5_ghz));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008882 }
8883
Dustin Browna30892e2016-10-12 17:28:36 -07008884 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008885
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -08008886 if (NULL == wiphy->bands[i])
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008887 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008888
8889 for (j = 0; j < wiphy->bands[i]->n_channels; j++) {
8890 struct ieee80211_supported_band *band = wiphy->bands[i];
8891
Dustin Browna30892e2016-10-12 17:28:36 -07008892 if (NL80211_BAND_2GHZ == i &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008893 eCSR_BAND_5G == pCfg->nBandCapability) {
8894 /* 5G only */
8895#ifdef WLAN_ENABLE_SOCIAL_CHANNELS_5G_ONLY
8896 /* Enable social channels for P2P */
8897 if (WLAN_HDD_IS_SOCIAL_CHANNEL
8898 (band->channels[j].center_freq))
8899 band->channels[j].flags &=
8900 ~IEEE80211_CHAN_DISABLED;
8901 else
8902#endif
8903 band->channels[j].flags |=
8904 IEEE80211_CHAN_DISABLED;
8905 continue;
Dustin Browna30892e2016-10-12 17:28:36 -07008906 } else if (NL80211_BAND_5GHZ == i &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008907 eCSR_BAND_24 == pCfg->nBandCapability) {
8908 /* 2G only */
8909 band->channels[j].flags |=
8910 IEEE80211_CHAN_DISABLED;
8911 continue;
8912 }
8913 }
8914 }
8915 /*Initialise the supported cipher suite details */
8916 wiphy->cipher_suites = hdd_cipher_suites;
8917 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
8918
8919 /*signal strength in mBm (100*dBm) */
8920 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
8921 wiphy->max_remain_on_channel_duration = MAX_REMAIN_ON_CHANNEL_DURATION;
8922
Anurag Chouhan6d760662016-02-20 16:05:43 +05308923 if (cds_get_conparam() != QDF_GLOBAL_FTM_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008924 wiphy->n_vendor_commands =
8925 ARRAY_SIZE(hdd_wiphy_vendor_commands);
8926 wiphy->vendor_commands = hdd_wiphy_vendor_commands;
8927
8928 wiphy->vendor_events = wlan_hdd_cfg80211_vendor_events;
8929 wiphy->n_vendor_events =
8930 ARRAY_SIZE(wlan_hdd_cfg80211_vendor_events);
8931 }
8932
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008933 if (pCfg->enableDFSMasterCap) {
8934 wiphy->flags |= WIPHY_FLAG_DFS_OFFLOAD;
8935 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008936
8937 wiphy->max_ap_assoc_sta = pCfg->maxNumberOfPeers;
8938
8939#ifdef QCA_HT_2040_COEX
8940 wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
8941#endif
Agrawal, Ashish4e5fa1c2016-09-21 19:03:43 +05308942 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
Abhishek Singh1bdb1572015-10-16 16:24:19 +05308943 hdd_add_channel_switch_support(&wiphy->flags);
8944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008945 EXIT();
8946 return 0;
8947}
8948
Abhishek Singhf512bf32016-05-04 16:47:46 +05308949/**
Yingying Tang80e15f32016-09-27 18:23:01 +08008950 * wlan_hdd_cfg80211_deinit() - Deinit cfg80211
8951 * @wiphy: the wiphy to validate against
Abhishek Singhf512bf32016-05-04 16:47:46 +05308952 *
8953 * this function deinit cfg80211 and cleanup the
Abhishek Singh3e6172f2016-05-04 16:56:48 +05308954 * memory allocated in wlan_hdd_cfg80211_init also
8955 * reset the global reg params.
Abhishek Singhf512bf32016-05-04 16:47:46 +05308956 *
8957 * Return: void
8958 */
8959void wlan_hdd_cfg80211_deinit(struct wiphy *wiphy)
8960{
8961 int i;
8962
Dustin Browna30892e2016-10-12 17:28:36 -07008963 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Abhishek Singhf512bf32016-05-04 16:47:46 +05308964 if (NULL != wiphy->bands[i] &&
8965 (NULL != wiphy->bands[i]->channels)) {
8966 qdf_mem_free(wiphy->bands[i]->channels);
8967 wiphy->bands[i]->channels = NULL;
8968 }
8969 }
Abhishek Singh3e6172f2016-05-04 16:56:48 +05308970 hdd_reset_global_reg_params();
Abhishek Singhf512bf32016-05-04 16:47:46 +05308971}
8972
Yingying Tang80e15f32016-09-27 18:23:01 +08008973/**
8974 * wlan_hdd_update_band_cap() - update capabilities for supported bands
8975 * @hdd_ctx: HDD context
8976 *
8977 * this function will update capabilities for supported bands
8978 *
8979 * Return: void
8980 */
8981static void wlan_hdd_update_band_cap(hdd_context_t *hdd_ctx)
8982{
8983 uint32_t val32;
8984 uint16_t val16;
8985 tSirMacHTCapabilityInfo *ht_cap_info;
8986 QDF_STATUS status;
8987
8988 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
8989 if (QDF_STATUS_SUCCESS != status) {
8990 hdd_err("could not get HT capability info");
8991 val32 = 0;
8992 }
8993 val16 = (uint16_t)val32;
8994 ht_cap_info = (tSirMacHTCapabilityInfo *)&val16;
8995
8996 if (ht_cap_info->txSTBC == true) {
8997 if (NULL != hdd_ctx->wiphy->bands[NL80211_BAND_2GHZ])
8998 hdd_ctx->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap |=
8999 IEEE80211_HT_CAP_TX_STBC;
9000 if (NULL != hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ])
9001 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.cap |=
9002 IEEE80211_HT_CAP_TX_STBC;
9003 }
9004}
9005
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009006/*
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309007 * In this function, wiphy structure is updated after QDF
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009008 * initialization. In wlan_hdd_cfg80211_init, only the
9009 * default values will be initialized. The final initialization
9010 * of all required members can be done here.
9011 */
Yingying Tang80e15f32016-09-27 18:23:01 +08009012void wlan_hdd_update_wiphy(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009013{
Yingying Tang80e15f32016-09-27 18:23:01 +08009014 hdd_ctx->wiphy->max_ap_assoc_sta = hdd_ctx->config->maxNumberOfPeers;
9015
9016 wlan_hdd_update_band_cap(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009017}
9018
9019/* In this function we are registering wiphy. */
9020int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
9021{
9022 ENTER();
9023 /* Register our wiphy dev with cfg80211 */
9024 if (0 > wiphy_register(wiphy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009025 hdd_err("wiphy register failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009026 return -EIO;
9027 }
9028
9029 EXIT();
9030 return 0;
9031}
9032
9033/*
9034 HDD function to update wiphy capability based on target offload status.
9035
9036 wlan_hdd_cfg80211_init() does initialization of all wiphy related
9037 capability even before downloading firmware to the target. In discrete
9038 case, host will get know certain offload capability (say sched_scan
9039 caps) only after downloading firmware to the target and target boots up.
9040 This function is used to override setting done in wlan_hdd_cfg80211_init()
9041 based on target capability.
9042 */
9043void wlan_hdd_cfg80211_update_wiphy_caps(struct wiphy *wiphy)
9044{
9045#ifdef FEATURE_WLAN_SCAN_PNO
9046 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9047 struct hdd_config *pCfg = pHddCtx->config;
9048
9049 /* wlan_hdd_cfg80211_init() sets sched_scan caps already in wiphy before
9050 * control comes here. Here just we need to clear it if firmware doesn't
9051 * have PNO support. */
9052 if (!pCfg->PnoOffload) {
9053 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
9054 wiphy->max_sched_scan_ssids = 0;
9055 wiphy->max_match_sets = 0;
9056 wiphy->max_sched_scan_ie_len = 0;
9057 }
9058#endif
9059}
9060
9061/* This function registers for all frame which supplicant is interested in */
9062void wlan_hdd_cfg80211_register_frames(hdd_adapter_t *pAdapter)
9063{
9064 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9065 /* Register for all P2P action, public action etc frames */
9066 uint16_t type = (SIR_MAC_MGMT_FRAME << 2) | (SIR_MAC_MGMT_ACTION << 4);
9067
9068 ENTER();
9069
Abhishek Singh7996eb72015-12-30 17:24:02 +05309070 /* Register frame indication call back */
9071 sme_register_mgmt_frame_ind_callback(hHal, hdd_indicate_mgmt_frame);
9072
Selvaraj, Sridhar4577a9b2016-09-04 15:17:07 +05309073 /* Register for p2p ack indication */
9074 sme_register_p2p_ack_ind_callback(hHal, hdd_send_action_cnf_cb);
9075
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009076 /* Right now we are registering these frame when driver is getting
9077 initialized. Once we will move to 2.6.37 kernel, in which we have
9078 frame register ops, we will move this code as a part of that */
9079 /* GAS Initial Request */
9080 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9081 (uint8_t *) GAS_INITIAL_REQ,
9082 GAS_INITIAL_REQ_SIZE);
9083
9084 /* GAS Initial Response */
9085 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9086 (uint8_t *) GAS_INITIAL_RSP,
9087 GAS_INITIAL_RSP_SIZE);
9088
9089 /* GAS Comeback Request */
9090 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9091 (uint8_t *) GAS_COMEBACK_REQ,
9092 GAS_COMEBACK_REQ_SIZE);
9093
9094 /* GAS Comeback Response */
9095 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9096 (uint8_t *) GAS_COMEBACK_RSP,
9097 GAS_COMEBACK_RSP_SIZE);
9098
9099 /* P2P Public Action */
9100 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9101 (uint8_t *) P2P_PUBLIC_ACTION_FRAME,
9102 P2P_PUBLIC_ACTION_FRAME_SIZE);
9103
9104 /* P2P Action */
9105 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9106 (uint8_t *) P2P_ACTION_FRAME,
9107 P2P_ACTION_FRAME_SIZE);
9108
9109 /* WNM BSS Transition Request frame */
9110 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9111 (uint8_t *) WNM_BSS_ACTION_FRAME,
9112 WNM_BSS_ACTION_FRAME_SIZE);
9113
9114 /* WNM-Notification */
9115 sme_register_mgmt_frame(hHal, pAdapter->sessionId, type,
9116 (uint8_t *) WNM_NOTIFICATION_FRAME,
9117 WNM_NOTIFICATION_FRAME_SIZE);
9118}
9119
9120void wlan_hdd_cfg80211_deregister_frames(hdd_adapter_t *pAdapter)
9121{
9122 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9123 /* Register for all P2P action, public action etc frames */
9124 uint16_t type = (SIR_MAC_MGMT_FRAME << 2) | (SIR_MAC_MGMT_ACTION << 4);
9125
9126 ENTER();
9127
9128 /* Right now we are registering these frame when driver is getting
9129 initialized. Once we will move to 2.6.37 kernel, in which we have
9130 frame register ops, we will move this code as a part of that */
9131 /* GAS Initial Request */
9132
9133 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9134 (uint8_t *) GAS_INITIAL_REQ,
9135 GAS_INITIAL_REQ_SIZE);
9136
9137 /* GAS Initial Response */
9138 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9139 (uint8_t *) GAS_INITIAL_RSP,
9140 GAS_INITIAL_RSP_SIZE);
9141
9142 /* GAS Comeback Request */
9143 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9144 (uint8_t *) GAS_COMEBACK_REQ,
9145 GAS_COMEBACK_REQ_SIZE);
9146
9147 /* GAS Comeback Response */
9148 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9149 (uint8_t *) GAS_COMEBACK_RSP,
9150 GAS_COMEBACK_RSP_SIZE);
9151
9152 /* P2P Public Action */
9153 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9154 (uint8_t *) P2P_PUBLIC_ACTION_FRAME,
9155 P2P_PUBLIC_ACTION_FRAME_SIZE);
9156
9157 /* P2P Action */
9158 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9159 (uint8_t *) P2P_ACTION_FRAME,
9160 P2P_ACTION_FRAME_SIZE);
9161
9162 /* WNM-Notification */
9163 sme_deregister_mgmt_frame(hHal, pAdapter->sessionId, type,
9164 (uint8_t *) WNM_NOTIFICATION_FRAME,
9165 WNM_NOTIFICATION_FRAME_SIZE);
9166}
9167
9168#ifdef FEATURE_WLAN_WAPI
9169void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t *pAdapter, uint8_t key_index,
9170 const uint8_t *mac_addr, const uint8_t *key,
9171 int key_Len)
9172{
9173 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9174 tCsrRoamSetKey setKey;
9175 bool isConnected = true;
9176 int status = 0;
9177 uint32_t roamId = 0xFF;
9178 uint8_t *pKeyPtr = NULL;
9179 int n = 0;
9180
Jeff Johnson46b40792016-06-29 14:03:14 -07009181 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009182 hdd_device_mode_to_string(pAdapter->device_mode),
9183 pAdapter->device_mode);
9184
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309185 qdf_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009186 setKey.keyId = key_index; /* Store Key ID */
9187 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; /* SET WAPI Encryption */
9188 setKey.keyDirection = eSIR_TX_RX; /* Key Directionn both TX and RX */
9189 setKey.paeRole = 0; /* the PAE role */
9190 if (!mac_addr || is_broadcast_ether_addr(mac_addr)) {
Anurag Chouhanc5548422016-02-24 18:33:27 +05309191 qdf_set_macaddr_broadcast(&setKey.peerMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009192 } else {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309193 qdf_mem_copy(setKey.peerMac.bytes, mac_addr, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009194 }
9195 setKey.keyLength = key_Len;
9196 pKeyPtr = setKey.Key;
9197 memcpy(pKeyPtr, key, key_Len);
9198
Jeff Johnson46b40792016-06-29 14:03:14 -07009199 hdd_notice("WAPI KEY LENGTH:0x%04x", key_Len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009200 for (n = 0; n < key_Len; n++)
Jeff Johnson46b40792016-06-29 14:03:14 -07009201 hdd_notice("WAPI KEY Data[%d]:%02x ",
9202 n, setKey.Key[n]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009203
9204 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
9205 if (isConnected) {
9206 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
9207 pAdapter->sessionId, &setKey, &roamId);
9208 }
9209 if (status != 0) {
Jeff Johnson46b40792016-06-29 14:03:14 -07009210 hdd_err("sme_roam_set_key returned ERROR status= %d",
9211 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009212 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
9213 }
9214}
9215#endif /* FEATURE_WLAN_WAPI */
9216
9217uint8_t *wlan_hdd_cfg80211_get_ie_ptr(const uint8_t *ies_ptr, int length,
9218 uint8_t eid)
9219{
9220 int left = length;
9221 uint8_t *ptr = (uint8_t *)ies_ptr;
9222 uint8_t elem_id, elem_len;
9223
9224 while (left >= 2) {
9225 elem_id = ptr[0];
9226 elem_len = ptr[1];
9227 left -= 2;
9228 if (elem_len > left) {
Jeff Johnson77848112016-06-29 14:52:06 -07009229 hdd_alert("Invalid IEs eid = %d elem_len=%d left=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009230 eid, elem_len, left);
9231 return NULL;
9232 }
9233 if (elem_id == eid) {
9234 return ptr;
9235 }
9236
9237 left -= elem_len;
9238 ptr += (elem_len + 2);
9239 }
9240 return NULL;
9241}
9242
9243/*
9244 * FUNCTION: wlan_hdd_validate_operation_channel
9245 * called by wlan_hdd_cfg80211_start_bss() and
9246 * wlan_hdd_set_channel()
9247 * This function validates whether given channel is part of valid
9248 * channel list.
9249 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309250QDF_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009251 int channel)
9252{
9253
9254 uint32_t num_ch = 0;
9255 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
9256 u32 indx = 0;
9257 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9258 uint8_t fValidChannel = false, count = 0;
9259 struct hdd_config *hdd_pConfig_ini = (WLAN_HDD_GET_CTX(pAdapter))->config;
9260
9261 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
9262
9263 if (hdd_pConfig_ini->sapAllowAllChannel) {
9264 /* Validate the channel */
Amar Singhalb8d4f152016-02-10 10:21:43 -08009265 for (count = CHAN_ENUM_1; count <= CHAN_ENUM_165; count++) {
Amar Singhal7a1726a2015-10-14 16:28:11 -07009266 if (channel == CDS_CHANNEL_NUM(count)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009267 fValidChannel = true;
9268 break;
9269 }
9270 }
9271 if (fValidChannel != true) {
Jeff Johnson77848112016-06-29 14:52:06 -07009272 hdd_err("Invalid Channel [%d]", channel);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309273 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009274 }
9275 } else {
9276 if (0 != sme_cfg_get_str(hHal, WNI_CFG_VALID_CHANNEL_LIST,
9277 valid_ch, &num_ch)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009278 hdd_err("failed to get valid channel list");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309279 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009280 }
9281 for (indx = 0; indx < num_ch; indx++) {
9282 if (channel == valid_ch[indx]) {
9283 break;
9284 }
9285 }
9286
9287 if (indx >= num_ch) {
Jeff Johnson77848112016-06-29 14:52:06 -07009288 hdd_err("Invalid Channel [%d]", channel);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309289 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009290 }
9291 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309292 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009293
9294}
9295
9296#ifdef DHCP_SERVER_OFFLOAD
9297static void wlan_hdd_set_dhcp_server_offload(hdd_adapter_t *pHostapdAdapter)
9298{
9299 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
9300 tpSirDhcpSrvOffloadInfo pDhcpSrvInfo;
9301 uint8_t numEntries = 0;
9302 uint8_t srv_ip[IPADDR_NUM_ENTRIES];
9303 uint8_t num;
9304 uint32_t temp;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309305 pDhcpSrvInfo = qdf_mem_malloc(sizeof(*pDhcpSrvInfo));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009306 if (NULL == pDhcpSrvInfo) {
Jeff Johnson77848112016-06-29 14:52:06 -07009307 hdd_err("could not allocate tDhcpSrvOffloadInfo!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009308 return;
9309 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009310 pDhcpSrvInfo->vdev_id = pHostapdAdapter->sessionId;
9311 pDhcpSrvInfo->dhcpSrvOffloadEnabled = true;
9312 pDhcpSrvInfo->dhcpClientNum = pHddCtx->config->dhcpMaxNumClients;
9313 hdd_string_to_u8_array(pHddCtx->config->dhcpServerIP,
9314 srv_ip, &numEntries, IPADDR_NUM_ENTRIES);
9315 if (numEntries != IPADDR_NUM_ENTRIES) {
Jeff Johnson77848112016-06-29 14:52:06 -07009316 hdd_err("incorrect IP address (%s) assigned for DHCP server!", pHddCtx->config->dhcpServerIP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009317 goto end;
9318 }
9319 if ((srv_ip[0] >= 224) && (srv_ip[0] <= 239)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009320 hdd_err("invalid IP address (%s)! It could NOT be multicast IP address!", pHddCtx->config->dhcpServerIP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009321 goto end;
9322 }
9323 if (srv_ip[IPADDR_NUM_ENTRIES - 1] >= 100) {
Jeff Johnson77848112016-06-29 14:52:06 -07009324 hdd_err("invalid IP address (%s)! The last field must be less than 100!", pHddCtx->config->dhcpServerIP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009325 goto end;
9326 }
9327 for (num = 0; num < numEntries; num++) {
9328 temp = srv_ip[num];
9329 pDhcpSrvInfo->dhcpSrvIP |= (temp << (8 * num));
9330 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309331 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009332 sme_set_dhcp_srv_offload(pHddCtx->hHal, pDhcpSrvInfo)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009333 hdd_err("sme_setDHCPSrvOffload fail!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009334 goto end;
9335 }
Jeff Johnson77848112016-06-29 14:52:06 -07009336 hdd_info("enable DHCP Server offload successfully!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009337end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309338 qdf_mem_free(pDhcpSrvInfo);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009339 return;
9340}
9341#endif /* DHCP_SERVER_OFFLOAD */
9342
9343static int __wlan_hdd_cfg80211_change_bss(struct wiphy *wiphy,
9344 struct net_device *dev,
9345 struct bss_parameters *params)
9346{
9347 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9348 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9349 int ret = 0;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309350 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009351
9352 ENTER();
9353
Anurag Chouhan6d760662016-02-20 16:05:43 +05309354 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson77848112016-06-29 14:52:06 -07009355 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009356 return -EINVAL;
9357 }
9358
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05309359 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
9360 hdd_err("invalid session id: %d", pAdapter->sessionId);
9361 return -EINVAL;
9362 }
9363
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05309364 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009365 TRACE_CODE_HDD_CFG80211_CHANGE_BSS,
9366 pAdapter->sessionId, params->ap_isolate));
Jeff Johnson77848112016-06-29 14:52:06 -07009367 hdd_notice("Device_mode %s(%d), ap_isolate = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009368 hdd_device_mode_to_string(pAdapter->device_mode),
9369 pAdapter->device_mode, params->ap_isolate);
9370
9371 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9372 ret = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05309373 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009374 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009375
Krunal Sonib4326f22016-03-10 13:05:51 -08009376 if (!(pAdapter->device_mode == QDF_SAP_MODE ||
9377 pAdapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009378 return -EOPNOTSUPP;
9379 }
9380
9381 /* ap_isolate == -1 means that in change bss, upper layer doesn't
9382 * want to update this parameter */
9383 if (-1 != params->ap_isolate) {
9384 pAdapter->sessionCtx.ap.apDisableIntraBssFwd =
9385 !!params->ap_isolate;
9386
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309387 qdf_ret_status = sme_ap_disable_intra_bss_fwd(pHddCtx->hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009388 pAdapter->sessionId,
9389 pAdapter->sessionCtx.
9390 ap.
9391 apDisableIntraBssFwd);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309392 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009393 ret = -EINVAL;
9394 }
9395 }
9396
9397 EXIT();
9398 return ret;
9399}
9400
Krunal Soni8c37e322016-02-03 16:08:37 -08009401/**
9402 * wlan_hdd_change_client_iface_to_new_mode() - to change iface to provided mode
9403 * @ndev: pointer to net device provided by supplicant
9404 * @type: type of the interface, upper layer wanted to change
9405 *
9406 * Upper layer provides the new interface mode that needs to be changed
9407 * for given net device
9408 *
9409 * Return: success or failure in terms of integer value
9410 */
9411static int wlan_hdd_change_client_iface_to_new_mode(struct net_device *ndev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009412 enum nl80211_iftype type)
9413{
Krunal Soni8c37e322016-02-03 16:08:37 -08009414 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
9415 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9416 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009417 hdd_wext_state_t *wext;
9418 struct wireless_dev *wdev;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05309419 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009420
9421 ENTER();
9422
Krunal Soni8c37e322016-02-03 16:08:37 -08009423 if (test_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009424 hdd_notice("ACS is in progress, don't change iface!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009425 return 0;
9426 }
9427
9428 wdev = ndev->ieee80211_ptr;
Krunal Soni8c37e322016-02-03 16:08:37 -08009429 hdd_stop_adapter(hdd_ctx, adapter, true);
9430 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009431 wdev->iftype = type;
9432 /*Check for sub-string p2p to confirm its a p2p interface */
9433 if (NULL != strnstr(ndev->name, "p2p", 3)) {
Krunal Soni8c37e322016-02-03 16:08:37 -08009434 adapter->device_mode =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009435 (type == NL80211_IFTYPE_STATION) ?
Krunal Sonib4326f22016-03-10 13:05:51 -08009436 QDF_P2P_DEVICE_MODE : QDF_P2P_CLIENT_MODE;
Krunal Soni8c37e322016-02-03 16:08:37 -08009437 } else if (type == NL80211_IFTYPE_ADHOC) {
Krunal Sonib4326f22016-03-10 13:05:51 -08009438 adapter->device_mode = QDF_IBSS_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009439 } else {
Krunal Soni8c37e322016-02-03 16:08:37 -08009440 adapter->device_mode =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009441 (type == NL80211_IFTYPE_STATION) ?
Krunal Sonib4326f22016-03-10 13:05:51 -08009442 QDF_STA_MODE : QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009443 }
Krunal Soni8c37e322016-02-03 16:08:37 -08009444 memset(&adapter->sessionCtx, 0, sizeof(adapter->sessionCtx));
9445 hdd_set_station_ops(adapter->dev);
Krunal Soni8c37e322016-02-03 16:08:37 -08009446 wext = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
9447 wext->roamProfile.pAddIEScan = adapter->scan_info.scanAddIE.addIEdata;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009448 wext->roamProfile.nAddIEScanLength =
Krunal Soni8c37e322016-02-03 16:08:37 -08009449 adapter->scan_info.scanAddIE.length;
9450 if (type == NL80211_IFTYPE_ADHOC) {
Arun Khandavallib2f6c262016-08-18 19:07:19 +05309451 status = hdd_init_station_mode(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08009452 wext->roamProfile.BSSType = eCSR_BSS_TYPE_START_IBSS;
9453 wext->roamProfile.phyMode =
9454 hdd_cfg_xlate_to_csr_phy_mode(config->dot11Mode);
9455 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009456 EXIT();
9457 return status;
9458}
9459
9460static int wlan_hdd_cfg80211_change_bss(struct wiphy *wiphy,
9461 struct net_device *dev,
9462 struct bss_parameters *params)
9463{
9464 int ret;
9465
9466 cds_ssr_protect(__func__);
9467 ret = __wlan_hdd_cfg80211_change_bss(wiphy, dev, params);
9468 cds_ssr_unprotect(__func__);
9469
9470 return ret;
9471}
9472
9473/* FUNCTION: wlan_hdd_change_country_code_cd
9474 * to wait for contry code completion
9475 */
9476void *wlan_hdd_change_country_code_cb(void *pAdapter)
9477{
9478 hdd_adapter_t *call_back_pAdapter = pAdapter;
9479 complete(&call_back_pAdapter->change_country_code);
9480 return NULL;
9481}
9482
Rajeev Kumar98edb772016-01-19 12:42:19 -08009483/**
9484 * __wlan_hdd_cfg80211_change_iface() - change interface cfg80211 op
9485 * @wiphy: Pointer to the wiphy structure
9486 * @ndev: Pointer to the net device
9487 * @type: Interface type
9488 * @flags: Flags for change interface
9489 * @params: Pointer to change interface parameters
9490 *
9491 * Return: 0 for success, error number on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009492 */
9493static int __wlan_hdd_cfg80211_change_iface(struct wiphy *wiphy,
9494 struct net_device *ndev,
9495 enum nl80211_iftype type,
9496 u32 *flags,
9497 struct vif_params *params)
9498{
9499 struct wireless_dev *wdev;
9500 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
9501 hdd_context_t *pHddCtx;
9502 tCsrRoamProfile *pRoamProfile = NULL;
9503 eCsrRoamBssType LastBSSType;
9504 struct hdd_config *pConfig = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309505 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009506 int status;
9507
9508 ENTER();
9509
Anurag Chouhan6d760662016-02-20 16:05:43 +05309510 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson77848112016-06-29 14:52:06 -07009511 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009512 return -EINVAL;
9513 }
9514
9515 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9516 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05309517 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009518 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009519
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05309520 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009521 TRACE_CODE_HDD_CFG80211_CHANGE_IFACE,
9522 pAdapter->sessionId, type));
9523
Jeff Johnson77848112016-06-29 14:52:06 -07009524 hdd_notice("Device_mode = %d, IFTYPE = 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009525 pAdapter->device_mode, type);
9526
Arun Khandavallifae92942016-08-01 13:31:08 +05309527 status = hdd_wlan_start_modules(pHddCtx, pAdapter, false);
9528 if (status) {
9529 hdd_err("Failed to start modules");
9530 return -EINVAL;
9531 }
9532
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08009533 if (!cds_allow_concurrency(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009534 wlan_hdd_convert_nl_iftype_to_hdd_type(type),
9535 0, HW_MODE_20_MHZ)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009536 hdd_debug("This concurrency combination is not allowed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009537 return -EINVAL;
9538 }
9539
9540 pConfig = pHddCtx->config;
9541 wdev = ndev->ieee80211_ptr;
9542
9543 /* Reset the current device mode bit mask */
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08009544 cds_clear_concurrency_mode(pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009545
9546 hdd_tdls_notify_mode_change(pAdapter, pHddCtx);
9547
Krunal Sonib4326f22016-03-10 13:05:51 -08009548 if ((pAdapter->device_mode == QDF_STA_MODE) ||
9549 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE) ||
9550 (pAdapter->device_mode == QDF_P2P_DEVICE_MODE) ||
9551 (pAdapter->device_mode == QDF_IBSS_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009552 hdd_wext_state_t *pWextState =
9553 WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
9554
9555 pRoamProfile = &pWextState->roamProfile;
9556 LastBSSType = pRoamProfile->BSSType;
9557
9558 switch (type) {
9559 case NL80211_IFTYPE_STATION:
9560 case NL80211_IFTYPE_P2P_CLIENT:
Krunal Soni8c37e322016-02-03 16:08:37 -08009561 case NL80211_IFTYPE_ADHOC:
9562 if (type == NL80211_IFTYPE_ADHOC) {
9563 wlan_hdd_tdls_exit(pAdapter);
9564 hdd_deregister_tx_flow_control(pAdapter);
Jeff Johnson77848112016-06-29 14:52:06 -07009565 hdd_notice("Setting interface Type to ADHOC");
Krunal Soni8c37e322016-02-03 16:08:37 -08009566 }
9567 vstatus = wlan_hdd_change_client_iface_to_new_mode(ndev,
9568 type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309569 if (vstatus != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009570 return -EINVAL;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05309571 if (hdd_start_adapter(pAdapter)) {
9572 hdd_err("Failed to start adapter :%d",
9573 pAdapter->device_mode);
9574 return -EINVAL;
9575 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009576 goto done;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009577 case NL80211_IFTYPE_AP:
9578 case NL80211_IFTYPE_P2P_GO:
9579 {
Jeff Johnson77848112016-06-29 14:52:06 -07009580 hdd_info("Setting interface Type to %s",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009581 (type ==
9582 NL80211_IFTYPE_AP) ? "SoftAP" :
9583 "P2pGo");
9584
9585 /* Cancel any remain on channel for GO mode */
9586 if (NL80211_IFTYPE_P2P_GO == type) {
9587 wlan_hdd_cancel_existing_remain_on_channel
9588 (pAdapter);
9589 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009590
Arun Khandavallifae92942016-08-01 13:31:08 +05309591 hdd_stop_adapter(pHddCtx, pAdapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009592 /* De-init the adapter */
9593 hdd_deinit_adapter(pHddCtx, pAdapter, true);
9594 memset(&pAdapter->sessionCtx, 0,
9595 sizeof(pAdapter->sessionCtx));
9596 pAdapter->device_mode =
9597 (type ==
Krunal Sonib4326f22016-03-10 13:05:51 -08009598 NL80211_IFTYPE_AP) ? QDF_SAP_MODE :
9599 QDF_P2P_GO_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009600
9601 /*
9602 * Fw will take care incase of concurrency
9603 */
9604
Krunal Sonib4326f22016-03-10 13:05:51 -08009605 if ((QDF_SAP_MODE == pAdapter->device_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009606 && (pConfig->apRandomBssidEnabled)) {
9607 /* To meet Android requirements create a randomized
9608 MAC address of the form 02:1A:11:Fx:xx:xx */
9609 get_random_bytes(&ndev->dev_addr[3], 3);
9610 ndev->dev_addr[0] = 0x02;
9611 ndev->dev_addr[1] = 0x1A;
9612 ndev->dev_addr[2] = 0x11;
9613 ndev->dev_addr[3] |= 0xF0;
9614 memcpy(pAdapter->macAddressCurrent.
9615 bytes, ndev->dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309616 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009617 pr_info("wlan: Generated HotSpot BSSID "
9618 MAC_ADDRESS_STR "\n",
9619 MAC_ADDR_ARRAY(ndev->dev_addr));
9620 }
9621
9622 hdd_set_ap_ops(pAdapter->dev);
9623
Arun Khandavallifae92942016-08-01 13:31:08 +05309624 if (hdd_start_adapter(pAdapter)) {
9625 hdd_err("Error initializing the ap mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009626 return -EINVAL;
9627 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009628 /* Interface type changed update in wiphy structure */
9629 if (wdev) {
9630 wdev->iftype = type;
9631 } else {
Jeff Johnson77848112016-06-29 14:52:06 -07009632 hdd_err("Wireless dev is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009633 return -EINVAL;
9634 }
9635 goto done;
9636 }
9637
9638 default:
Jeff Johnson77848112016-06-29 14:52:06 -07009639 hdd_err("Unsupported interface type (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009640 type);
9641 return -EOPNOTSUPP;
9642 }
Krunal Sonib4326f22016-03-10 13:05:51 -08009643 } else if ((pAdapter->device_mode == QDF_SAP_MODE) ||
9644 (pAdapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009645 switch (type) {
9646 case NL80211_IFTYPE_STATION:
9647 case NL80211_IFTYPE_P2P_CLIENT:
9648 case NL80211_IFTYPE_ADHOC:
Krunal Soni8c37e322016-02-03 16:08:37 -08009649 status = wlan_hdd_change_client_iface_to_new_mode(ndev,
9650 type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309651 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009652 return status;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05309653 if (hdd_start_adapter(pAdapter)) {
9654 hdd_err("Failed to start adapter :%d",
9655 pAdapter->device_mode);
9656 return -EINVAL;
9657 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009658 goto done;
9659
9660 case NL80211_IFTYPE_AP:
9661 case NL80211_IFTYPE_P2P_GO:
9662 wdev->iftype = type;
9663 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
Krunal Sonib4326f22016-03-10 13:05:51 -08009664 QDF_SAP_MODE : QDF_P2P_GO_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009665 goto done;
9666
9667 default:
Jeff Johnson77848112016-06-29 14:52:06 -07009668 hdd_err("Unsupported interface type(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009669 type);
9670 return -EOPNOTSUPP;
9671 }
9672 } else {
Jeff Johnson77848112016-06-29 14:52:06 -07009673 hdd_err("Unsupported device mode(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009674 pAdapter->device_mode);
9675 return -EOPNOTSUPP;
9676 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009677done:
9678 /* Set bitmask based on updated value */
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08009679 cds_set_concurrency_mode(pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009680
Jeff Johnson2ae6f712016-09-23 15:08:48 -07009681 hdd_lpass_notify_mode_change(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009682
9683 EXIT();
9684 return 0;
9685}
9686
Rajeev Kumar98edb772016-01-19 12:42:19 -08009687/**
9688 * wlan_hdd_cfg80211_change_iface() - change interface cfg80211 op
9689 * @wiphy: Pointer to the wiphy structure
9690 * @ndev: Pointer to the net device
9691 * @type: Interface type
9692 * @flags: Flags for change interface
9693 * @params: Pointer to change interface parameters
9694 *
9695 * Return: 0 for success, error number on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009696 */
9697static int wlan_hdd_cfg80211_change_iface(struct wiphy *wiphy,
9698 struct net_device *ndev,
9699 enum nl80211_iftype type,
9700 u32 *flags,
9701 struct vif_params *params)
9702{
9703 int ret;
9704
9705 cds_ssr_protect(__func__);
9706 ret =
9707 __wlan_hdd_cfg80211_change_iface(wiphy, ndev, type, flags, params);
9708 cds_ssr_unprotect(__func__);
9709
9710 return ret;
9711}
9712
9713#ifdef FEATURE_WLAN_TDLS
9714static bool wlan_hdd_is_duplicate_channel(uint8_t *arr,
9715 int index, uint8_t match)
9716{
9717 int i;
9718 for (i = 0; i < index; i++) {
9719 if (arr[i] == match)
9720 return true;
9721 }
9722 return false;
9723}
9724#endif
9725
9726/**
9727 * __wlan_hdd_change_station() - change station
9728 * @wiphy: Pointer to the wiphy structure
9729 * @dev: Pointer to the net device.
9730 * @mac: bssid
9731 * @params: Pointer to station parameters
9732 *
9733 * Return: 0 for success, error number on failure.
9734 */
9735#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
9736static int __wlan_hdd_change_station(struct wiphy *wiphy,
9737 struct net_device *dev,
9738 const uint8_t *mac,
9739 struct station_parameters *params)
9740#else
9741static int __wlan_hdd_change_station(struct wiphy *wiphy,
9742 struct net_device *dev,
9743 uint8_t *mac,
9744 struct station_parameters *params)
9745#endif
9746{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309747 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009748 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9749 hdd_context_t *pHddCtx;
9750 hdd_station_ctx_t *pHddStaCtx;
Anurag Chouhan6d760662016-02-20 16:05:43 +05309751 struct qdf_mac_addr STAMacAddress;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009752#ifdef FEATURE_WLAN_TDLS
9753 tCsrStaParams StaParams = { 0 };
9754 uint8_t isBufSta = 0;
9755 uint8_t isOffChannelSupported = 0;
Nitesh Shah99934ac2016-09-05 15:54:08 +05309756 bool is_qos_wmm_sta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009757#endif
9758 int ret;
9759
9760 ENTER();
9761
Anurag Chouhan6d760662016-02-20 16:05:43 +05309762 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009763 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009764 return -EINVAL;
9765 }
9766
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05309767 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009768 TRACE_CODE_HDD_CHANGE_STATION,
9769 pAdapter->sessionId, params->listen_interval));
9770
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05309771 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
9772 hdd_err("invalid session id: %d", pAdapter->sessionId);
9773 return -EINVAL;
9774 }
9775
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009776 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9777 ret = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05309778 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009779 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009780
9781 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9782
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309783 qdf_mem_copy(STAMacAddress.bytes, mac, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009784
Krunal Sonib4326f22016-03-10 13:05:51 -08009785 if ((pAdapter->device_mode == QDF_SAP_MODE) ||
9786 (pAdapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009787 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
9788 status =
9789 hdd_softap_change_sta_state(pAdapter,
9790 &STAMacAddress,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08009791 OL_TXRX_PEER_STATE_AUTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009792
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309793 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009794 hdd_notice("Not able to change TL state to AUTHENTICATED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009795 return -EINVAL;
9796 }
9797 }
Krunal Sonib4326f22016-03-10 13:05:51 -08009798 } else if ((pAdapter->device_mode == QDF_STA_MODE) ||
9799 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009800#ifdef FEATURE_WLAN_TDLS
9801 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07009802
9803 if (cds_is_sub_20_mhz_enabled()) {
9804 hdd_err("TDLS not allowed with sub 20 MHz");
9805 return -EINVAL;
9806 }
9807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009808 StaParams.capability = params->capability;
9809 StaParams.uapsd_queues = params->uapsd_queues;
9810 StaParams.max_sp = params->max_sp;
9811
9812 /* Convert (first channel , number of channels) tuple to
9813 * the total list of channels. This goes with the assumption
9814 * that if the first channel is < 14, then the next channels
9815 * are an incremental of 1 else an incremental of 4 till the number
9816 * of channels.
9817 */
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009818 hdd_notice("params->supported_channels_len: %d", params->supported_channels_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009819 if (0 != params->supported_channels_len) {
9820 int i = 0, j = 0, k = 0, no_of_channels = 0;
9821 int num_unique_channels;
9822 int next;
9823 for (i = 0;
9824 i < params->supported_channels_len
9825 && j < SIR_MAC_MAX_SUPP_CHANNELS; i += 2) {
9826 int wifi_chan_index;
9827 if (!wlan_hdd_is_duplicate_channel
9828 (StaParams.supported_channels, j,
9829 params->supported_channels[i])) {
9830 StaParams.
9831 supported_channels[j] =
9832 params->
9833 supported_channels[i];
9834 } else {
9835 continue;
9836 }
9837 wifi_chan_index =
9838 ((StaParams.supported_channels[j] <=
9839 HDD_CHANNEL_14) ? 1 : 4);
9840 no_of_channels =
9841 params->supported_channels[i + 1];
9842
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009843 hdd_notice("i: %d, j: %d, k: %d, StaParams.supported_channels[%d]: %d, wifi_chan_index: %d, no_of_channels: %d", i, j, k, j,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009844 StaParams.
9845 supported_channels[j],
9846 wifi_chan_index,
9847 no_of_channels);
9848 for (k = 1; k <= no_of_channels &&
9849 j < SIR_MAC_MAX_SUPP_CHANNELS - 1;
9850 k++) {
9851 next =
9852 StaParams.
9853 supported_channels[j] +
9854 wifi_chan_index;
9855 if (!wlan_hdd_is_duplicate_channel(StaParams.supported_channels, j + 1, next)) {
9856 StaParams.
9857 supported_channels[j
9858 +
9859 1]
9860 = next;
9861 } else {
9862 continue;
9863 }
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009864 hdd_notice("i: %d, j: %d, k: %d, StaParams.supported_channels[%d]: %d", i, j, k,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009865 j + 1,
9866 StaParams.
9867 supported_channels[j +
9868 1]);
9869 j += 1;
9870 }
9871 }
9872 num_unique_channels = j + 1;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009873 hdd_notice("Unique Channel List");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009874 for (i = 0; i < num_unique_channels; i++) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009875 hdd_notice("StaParams.supported_channels[%d]: %d,", i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009876 StaParams.
9877 supported_channels[i]);
9878 }
9879 if (MAX_CHANNEL < num_unique_channels)
9880 num_unique_channels = MAX_CHANNEL;
9881 StaParams.supported_channels_len =
9882 num_unique_channels;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009883 hdd_notice("After removing duplcates StaParams.supported_channels_len: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009884 StaParams.supported_channels_len);
9885 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309886 qdf_mem_copy(StaParams.supported_oper_classes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009887 params->supported_oper_classes,
9888 params->supported_oper_classes_len);
9889 StaParams.supported_oper_classes_len =
9890 params->supported_oper_classes_len;
9891
9892 if (0 != params->ext_capab_len)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309893 qdf_mem_copy(StaParams.extn_capability,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009894 params->ext_capab,
9895 sizeof(StaParams.extn_capability));
9896
9897 if (NULL != params->ht_capa) {
9898 StaParams.htcap_present = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309899 qdf_mem_copy(&StaParams.HTCap, params->ht_capa,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009900 sizeof(tSirHTCap));
9901 }
9902
9903 StaParams.supported_rates_len =
9904 params->supported_rates_len;
9905
9906 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
9907 * The supported_rates array , for all the structures propogating till Add Sta
9908 * to the firmware has to be modified , if the supplicant (ieee80211) is
9909 * modified to send more rates.
9910 */
9911
9912 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
9913 */
9914 if (StaParams.supported_rates_len >
9915 SIR_MAC_MAX_SUPP_RATES)
9916 StaParams.supported_rates_len =
9917 SIR_MAC_MAX_SUPP_RATES;
9918
9919 if (0 != StaParams.supported_rates_len) {
9920 int i = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309921 qdf_mem_copy(StaParams.supported_rates,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009922 params->supported_rates,
9923 StaParams.supported_rates_len);
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009924 hdd_notice("Supported Rates with Length %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009925 StaParams.supported_rates_len);
9926 for (i = 0; i < StaParams.supported_rates_len;
9927 i++)
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009928 hdd_notice("[%d]: %0x", i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009929 StaParams.supported_rates[i]);
9930 }
9931
9932 if (NULL != params->vht_capa) {
9933 StaParams.vhtcap_present = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309934 qdf_mem_copy(&StaParams.VHTCap,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009935 params->vht_capa,
9936 sizeof(tSirVHTCap));
9937 }
9938
9939 if (0 != params->ext_capab_len) {
9940 /*Define A Macro : TODO Sunil */
9941 if ((1 << 4) & StaParams.extn_capability[3]) {
9942 isBufSta = 1;
9943 }
9944 /* TDLS Channel Switching Support */
9945 if ((1 << 6) & StaParams.extn_capability[3]) {
9946 isOffChannelSupported = 1;
9947 }
9948 }
9949
Nitesh Shah99934ac2016-09-05 15:54:08 +05309950 if (pHddCtx->config->fEnableTDLSWmmMode &&
Nitesh Shahd8ff6322016-09-05 15:55:21 +05309951 (params->ht_capa || params->vht_capa ||
9952 (params->sta_flags_set & BIT(NL80211_STA_FLAG_WME))))
Nitesh Shah99934ac2016-09-05 15:54:08 +05309953 is_qos_wmm_sta = true;
9954
9955 hdd_notice("%s: TDLS Peer is QOS capable"
9956 " is_qos_wmm_sta= %d HTcapPresent = %d",
9957 __func__, is_qos_wmm_sta,
9958 StaParams.htcap_present);
9959
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009960 status = wlan_hdd_tdls_set_peer_caps(pAdapter, mac,
Nitesh Shah99934ac2016-09-05 15:54:08 +05309961 &StaParams,
9962 isBufSta,
9963 isOffChannelSupported,
9964 is_qos_wmm_sta);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309965 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009966 hdd_err("wlan_hdd_tdls_set_peer_caps failed!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009967 return -EINVAL;
9968 }
9969
9970 status =
9971 wlan_hdd_tdls_add_station(wiphy, dev, mac, 1,
9972 &StaParams);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309973 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -07009974 hdd_err("wlan_hdd_tdls_add_station failed!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009975 return -EINVAL;
9976 }
9977 }
9978#endif
9979 }
9980 EXIT();
9981 return ret;
9982}
9983
9984/**
9985 * wlan_hdd_change_station() - cfg80211 change station handler function
9986 * @wiphy: Pointer to the wiphy structure
9987 * @dev: Pointer to the net device.
9988 * @mac: bssid
9989 * @params: Pointer to station parameters
9990 *
9991 * This is the cfg80211 change station handler function which invokes
9992 * the internal function @__wlan_hdd_change_station with
9993 * SSR protection.
9994 *
9995 * Return: 0 for success, error number on failure.
9996 */
9997#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)) || defined(WITH_BACKPORTS)
9998static int wlan_hdd_change_station(struct wiphy *wiphy,
9999 struct net_device *dev,
10000 const u8 *mac,
10001 struct station_parameters *params)
10002#else
10003static int wlan_hdd_change_station(struct wiphy *wiphy,
10004 struct net_device *dev,
10005 u8 *mac,
10006 struct station_parameters *params)
10007#endif
10008{
10009 int ret;
10010
10011 cds_ssr_protect(__func__);
10012 ret = __wlan_hdd_change_station(wiphy, dev, mac, params);
10013 cds_ssr_unprotect(__func__);
10014
10015 return ret;
10016}
10017
10018/*
10019 * FUNCTION: __wlan_hdd_cfg80211_add_key
10020 * This function is used to initialize the key information
10021 */
10022static int __wlan_hdd_cfg80211_add_key(struct wiphy *wiphy,
10023 struct net_device *ndev,
10024 u8 key_index, bool pairwise,
10025 const u8 *mac_addr,
10026 struct key_params *params)
10027{
10028 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
10029 tCsrRoamSetKey setKey;
10030 int status;
10031 uint32_t roamId = 0xFF;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010032 hdd_hostapd_state_t *pHostapdState;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010033 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010034 hdd_context_t *pHddCtx;
10035 hdd_ap_ctx_t *ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
10036
10037 ENTER();
10038
Anurag Chouhan6d760662016-02-20 16:05:43 +053010039 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010040 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010041 return -EINVAL;
10042 }
10043
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053010044 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
10045 hdd_err("invalid session id: %d", pAdapter->sessionId);
10046 return -EINVAL;
10047 }
10048
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053010049 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010050 TRACE_CODE_HDD_CFG80211_ADD_KEY,
10051 pAdapter->sessionId, params->key_len));
10052 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10053 status = wlan_hdd_validate_context(pHddCtx);
10054
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010055 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010056 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010057
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010058 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010059 hdd_device_mode_to_string(pAdapter->device_mode),
10060 pAdapter->device_mode);
10061
10062 if (CSR_MAX_NUM_KEY <= key_index) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010063 hdd_err("Invalid key index %d", key_index);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010064
10065 return -EINVAL;
10066 }
10067
10068 if (CSR_MAX_KEY_LEN < params->key_len) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010069 hdd_err("Invalid key length %d", params->key_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010070
10071 return -EINVAL;
10072 }
10073
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010074 hdd_notice("called with key index = %d & key length %d", key_index, params->key_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010075
10076 /*extract key idx, key len and key */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010077 qdf_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010078 setKey.keyId = key_index;
10079 setKey.keyLength = params->key_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010080 qdf_mem_copy(&setKey.Key[0], params->key, params->key_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010081
10082 switch (params->cipher) {
10083 case WLAN_CIPHER_SUITE_WEP40:
10084 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
10085 break;
10086
10087 case WLAN_CIPHER_SUITE_WEP104:
10088 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
10089 break;
10090
10091 case WLAN_CIPHER_SUITE_TKIP:
10092 {
10093 u8 *pKey = &setKey.Key[0];
10094 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
10095
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010096 qdf_mem_zero(pKey, CSR_MAX_KEY_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010097
10098 /*Supplicant sends the 32bytes key in this order
10099
10100 |--------------|----------|----------|
10101 | Tk1 |TX-MIC | RX Mic |
10102 |||--------------|----------|----------|
10103 <---16bytes---><--8bytes--><--8bytes-->
10104
10105 */
10106 /*Sme expects the 32 bytes key to be in the below order
10107
10108 |--------------|----------|----------|
10109 | Tk1 |RX-MIC | TX Mic |
10110 |||--------------|----------|----------|
10111 <---16bytes---><--8bytes--><--8bytes-->
10112 */
10113 /* Copy the Temporal Key 1 (TK1) */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010114 qdf_mem_copy(pKey, params->key, 16);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010115
10116 /*Copy the rx mic first */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010117 qdf_mem_copy(&pKey[16], &params->key[24], 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010118
10119 /*Copy the tx mic */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010120 qdf_mem_copy(&pKey[24], &params->key[16], 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010121
10122 break;
10123 }
10124
10125 case WLAN_CIPHER_SUITE_CCMP:
10126 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
10127 break;
10128
10129#ifdef FEATURE_WLAN_WAPI
10130 case WLAN_CIPHER_SUITE_SMS4:
10131 {
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010132 qdf_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010133 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index,
10134 mac_addr, params->key,
10135 params->key_len);
10136 return 0;
10137 }
10138#endif
10139
10140#ifdef FEATURE_WLAN_ESE
10141 case WLAN_CIPHER_SUITE_KRK:
10142 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
10143 break;
10144#ifdef WLAN_FEATURE_ROAM_OFFLOAD
10145 case WLAN_CIPHER_SUITE_BTK:
10146 setKey.encType = eCSR_ENCRYPT_TYPE_BTK;
10147 break;
10148#endif
10149#endif
10150
10151#ifdef WLAN_FEATURE_11W
10152 case WLAN_CIPHER_SUITE_AES_CMAC:
10153 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
10154 break;
10155#endif
10156
10157 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010158 hdd_err("unsupported cipher type %u", params->cipher);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010159 return -EOPNOTSUPP;
10160 }
10161
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010162 hdd_info("encryption type %d", setKey.encType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010163
10164 if (!pairwise) {
10165 /* set group key */
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010166 hdd_notice("%s- %d: setting Broadcast key", __func__, __LINE__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010167 setKey.keyDirection = eSIR_RX_ONLY;
Anurag Chouhanc5548422016-02-24 18:33:27 +053010168 qdf_set_macaddr_broadcast(&setKey.peerMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010169 } else {
10170 /* set pairwise key */
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010171 hdd_notice("%s- %d: setting pairwise key", __func__, __LINE__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010172 setKey.keyDirection = eSIR_TX_RX;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010173 qdf_mem_copy(setKey.peerMac.bytes, mac_addr, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010174 }
Krunal Sonib4326f22016-03-10 13:05:51 -080010175 if ((QDF_IBSS_MODE == pAdapter->device_mode) && !pairwise) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010176 /* if a key is already installed, block all subsequent ones */
10177 if (pAdapter->sessionCtx.station.ibss_enc_key_installed) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010178 hdd_info("IBSS key installed already");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010179 return 0;
10180 }
10181
10182 setKey.keyDirection = eSIR_TX_RX;
10183 /*Set the group key */
10184 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
10185 pAdapter->sessionId, &setKey, &roamId);
10186
10187 if (0 != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010188 hdd_err("sme_roam_set_key failed, returned %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010189 return -EINVAL;
10190 }
10191 /*Save the keys here and call sme_roam_set_key for setting
10192 the PTK after peer joins the IBSS network */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010193 qdf_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010194 &setKey, sizeof(tCsrRoamSetKey));
10195
10196 pAdapter->sessionCtx.station.ibss_enc_key_installed = 1;
10197 return status;
10198 }
Krunal Sonib4326f22016-03-10 13:05:51 -080010199 if ((pAdapter->device_mode == QDF_SAP_MODE) ||
10200 (pAdapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010201 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
10202 if (pHostapdState->bssState == BSS_START) {
Dustin Brown6ba30a12016-09-13 13:59:43 -070010203 status = wlansap_set_key_sta(
10204 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), &setKey);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010205 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010206 hdd_err("[%4d] wlansap_set_key_sta returned ERROR status= %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010207 __LINE__, status);
10208 }
10209 }
10210
10211 /* Save the key in ap ctx for use on START_BASS and restart */
10212 if (pairwise ||
10213 eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
10214 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType)
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010215 qdf_mem_copy(&ap_ctx->wepKey[key_index], &setKey,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010216 sizeof(tCsrRoamSetKey));
10217 else
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010218 qdf_mem_copy(&ap_ctx->groupKey, &setKey,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010219 sizeof(tCsrRoamSetKey));
10220
Krunal Sonib4326f22016-03-10 13:05:51 -080010221 } else if ((pAdapter->device_mode == QDF_STA_MODE) ||
10222 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010223 hdd_wext_state_t *pWextState =
10224 WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
10225 hdd_station_ctx_t *pHddStaCtx =
10226 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
10227
10228 if (!pairwise) {
10229 /* set group key */
10230 if (pHddStaCtx->roam_info.deferKeyComplete) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010231 hdd_notice("%s- %d: Perform Set key Complete",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010232 __func__, __LINE__);
10233 hdd_perform_roam_set_key_complete(pAdapter);
10234 }
10235 }
10236
10237 pWextState->roamProfile.Keys.KeyLength[key_index] =
10238 (u8) params->key_len;
10239
10240 pWextState->roamProfile.Keys.defaultIndex = key_index;
10241
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010242 qdf_mem_copy(&pWextState->roamProfile.Keys.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010243 KeyMaterial[key_index][0], params->key,
10244 params->key_len);
10245
10246 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
10247
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010248 hdd_info("Set key for peerMac "MAC_ADDRESS_STR" direction %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010249 MAC_ADDR_ARRAY(setKey.peerMac.bytes),
10250 setKey.keyDirection);
10251
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010252 /* The supplicant may attempt to set the PTK once pre-authentication
10253 is done. Save the key in the UMAC and include it in the ADD BSS
10254 request */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010255 qdf_ret_status = sme_ft_update_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010256 pAdapter->sessionId, &setKey);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010257 if (qdf_ret_status == QDF_STATUS_FT_PREAUTH_KEY_SUCCESS) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010258 hdd_info("Update PreAuth Key success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010259 return 0;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010260 } else if (qdf_ret_status == QDF_STATUS_FT_PREAUTH_KEY_FAILED) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010261 hdd_err("Update PreAuth Key failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010262 return -EINVAL;
10263 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010264
10265 /* issue set key request to SME */
10266 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
10267 pAdapter->sessionId, &setKey, &roamId);
10268
10269 if (0 != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010270 hdd_err("sme_roam_set_key failed, returned %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010271 pHddStaCtx->roam_info.roamingState =
10272 HDD_ROAM_STATE_NONE;
10273 return -EINVAL;
10274 }
10275
10276 /* in case of IBSS as there was no information available about WEP keys during
10277 * IBSS join, group key intialized with NULL key, so re-initialize group key
10278 * with correct value*/
10279 if ((eCSR_BSS_TYPE_START_IBSS ==
10280 pWextState->roamProfile.BSSType)
10281 &&
10282 !((IW_AUTH_KEY_MGMT_802_1X ==
10283 (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
10284 && (eCSR_AUTH_TYPE_OPEN_SYSTEM ==
10285 pHddStaCtx->conn_info.authType)
10286 )
10287 && ((WLAN_CIPHER_SUITE_WEP40 == params->cipher)
10288 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
10289 )
10290 ) {
10291 setKey.keyDirection = eSIR_RX_ONLY;
Anurag Chouhanc5548422016-02-24 18:33:27 +053010292 qdf_set_macaddr_broadcast(&setKey.peerMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010293
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010294 hdd_info("Set key peerMac "MAC_ADDRESS_STR" direction %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010295 MAC_ADDR_ARRAY(setKey.peerMac.bytes),
10296 setKey.keyDirection);
10297
10298 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
10299 pAdapter->sessionId, &setKey,
10300 &roamId);
10301
10302 if (0 != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010303 hdd_err("sme_roam_set_key failed for group key (IBSS), returned %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010304 pHddStaCtx->roam_info.roamingState =
10305 HDD_ROAM_STATE_NONE;
10306 return -EINVAL;
10307 }
10308 }
10309 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010310 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010311 return 0;
10312}
10313
10314static int wlan_hdd_cfg80211_add_key(struct wiphy *wiphy,
10315 struct net_device *ndev,
10316 u8 key_index, bool pairwise,
10317 const u8 *mac_addr,
10318 struct key_params *params)
10319{
10320 int ret;
10321 cds_ssr_protect(__func__);
10322 ret = __wlan_hdd_cfg80211_add_key(wiphy, ndev, key_index, pairwise,
10323 mac_addr, params);
10324 cds_ssr_unprotect(__func__);
10325
10326 return ret;
10327}
10328
10329/*
10330 * FUNCTION: __wlan_hdd_cfg80211_get_key
10331 * This function is used to get the key information
10332 */
10333static int __wlan_hdd_cfg80211_get_key(struct wiphy *wiphy,
10334 struct net_device *ndev,
10335 u8 key_index, bool pairwise,
10336 const u8 *mac_addr, void *cookie,
10337 void (*callback)(void *cookie,
10338 struct key_params *)
10339 )
10340{
10341 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
10342 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
10343 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
10344 struct key_params params;
10345
10346 ENTER();
10347
Anurag Chouhan6d760662016-02-20 16:05:43 +053010348 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010349 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010350 return -EINVAL;
10351 }
10352
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010353 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010354 hdd_device_mode_to_string(pAdapter->device_mode),
10355 pAdapter->device_mode);
10356
10357 memset(&params, 0, sizeof(params));
10358
10359 if (CSR_MAX_NUM_KEY <= key_index) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010360 hdd_err("invalid key index %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010361 key_index);
10362 return -EINVAL;
10363 }
10364
10365 switch (pRoamProfile->EncryptionType.encryptionType[0]) {
10366 case eCSR_ENCRYPT_TYPE_NONE:
10367 params.cipher = IW_AUTH_CIPHER_NONE;
10368 break;
10369
10370 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
10371 case eCSR_ENCRYPT_TYPE_WEP40:
10372 params.cipher = WLAN_CIPHER_SUITE_WEP40;
10373 break;
10374
10375 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
10376 case eCSR_ENCRYPT_TYPE_WEP104:
10377 params.cipher = WLAN_CIPHER_SUITE_WEP104;
10378 break;
10379
10380 case eCSR_ENCRYPT_TYPE_TKIP:
10381 params.cipher = WLAN_CIPHER_SUITE_TKIP;
10382 break;
10383
10384 case eCSR_ENCRYPT_TYPE_AES:
10385 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
10386 break;
10387
10388 default:
10389 params.cipher = IW_AUTH_CIPHER_NONE;
10390 break;
10391 }
10392
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053010393 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010394 TRACE_CODE_HDD_CFG80211_GET_KEY,
10395 pAdapter->sessionId, params.cipher));
10396
10397 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
10398 params.seq_len = 0;
10399 params.seq = NULL;
10400 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
10401 callback(cookie, &params);
10402
10403 EXIT();
10404 return 0;
10405}
10406
10407static int wlan_hdd_cfg80211_get_key(struct wiphy *wiphy,
10408 struct net_device *ndev,
10409 u8 key_index, bool pairwise,
10410 const u8 *mac_addr, void *cookie,
10411 void (*callback)(void *cookie,
10412 struct key_params *)
10413 )
10414{
10415 int ret;
10416
10417 cds_ssr_protect(__func__);
10418 ret = __wlan_hdd_cfg80211_get_key(wiphy, ndev, key_index, pairwise,
10419 mac_addr, cookie, callback);
10420 cds_ssr_unprotect(__func__);
10421
10422 return ret;
10423}
10424
10425/**
10426 * __wlan_hdd_cfg80211_del_key() - Delete the encryption key for station
10427 * @wiphy: wiphy interface context
10428 * @ndev: pointer to net device
10429 * @key_index: Key index used in 802.11 frames
10430 * @unicast: true if it is unicast key
10431 * @multicast: true if it is multicast key
10432 *
10433 * This function is required for cfg80211_ops API.
10434 * It is used to delete the key information
10435 * Underlying hardware implementation does not have API to delete the
10436 * encryption key. It is automatically deleted when the peer is
10437 * removed. Hence this function currently does nothing.
10438 * Future implementation may interprete delete key operation to
10439 * replacing the key with a random junk value, effectively making it
10440 * useless.
10441 *
10442 * Return: status code, always 0.
10443 */
10444
10445static int __wlan_hdd_cfg80211_del_key(struct wiphy *wiphy,
10446 struct net_device *ndev,
10447 u8 key_index,
10448 bool pairwise, const u8 *mac_addr)
10449{
10450 EXIT();
10451 return 0;
10452}
10453
10454/**
10455 * wlan_hdd_cfg80211_del_key() - cfg80211 delete key handler function
10456 * @wiphy: Pointer to wiphy structure.
10457 * @dev: Pointer to net_device structure.
10458 * @key_index: key index
10459 * @pairwise: pairwise
10460 * @mac_addr: mac address
10461 *
10462 * This is the cfg80211 delete key handler function which invokes
10463 * the internal function @__wlan_hdd_cfg80211_del_key with
10464 * SSR protection.
10465 *
10466 * Return: 0 for success, error number on failure.
10467 */
10468static int wlan_hdd_cfg80211_del_key(struct wiphy *wiphy,
10469 struct net_device *dev,
10470 u8 key_index,
10471 bool pairwise, const u8 *mac_addr)
10472{
10473 int ret;
10474
10475 cds_ssr_protect(__func__);
10476 ret = __wlan_hdd_cfg80211_del_key(wiphy, dev, key_index,
10477 pairwise, mac_addr);
10478 cds_ssr_unprotect(__func__);
10479
10480 return ret;
10481}
10482
10483/*
10484 * FUNCTION: __wlan_hdd_cfg80211_set_default_key
10485 * This function is used to set the default tx key index
10486 */
10487static int __wlan_hdd_cfg80211_set_default_key(struct wiphy *wiphy,
10488 struct net_device *ndev,
10489 u8 key_index,
10490 bool unicast, bool multicast)
10491{
10492 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
10493 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
10494 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
10495 hdd_context_t *pHddCtx;
10496 int status;
10497
10498 ENTER();
10499
Anurag Chouhan6d760662016-02-20 16:05:43 +053010500 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010501 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010502 return -EINVAL;
10503 }
10504
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053010505 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
10506 hdd_err("invalid session id: %d", pAdapter->sessionId);
10507 return -EINVAL;
10508 }
10509
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053010510 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010511 TRACE_CODE_HDD_CFG80211_SET_DEFAULT_KEY,
10512 pAdapter->sessionId, key_index));
10513
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010514 hdd_notice("Device_mode %s(%d) key_index = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010515 hdd_device_mode_to_string(pAdapter->device_mode),
10516 pAdapter->device_mode, key_index);
10517
10518 if (CSR_MAX_NUM_KEY <= key_index) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010519 hdd_err("Invalid key index %d", key_index);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010520 return -EINVAL;
10521 }
10522
10523 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10524 status = wlan_hdd_validate_context(pHddCtx);
10525
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010526 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010527 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010528
Krunal Sonib4326f22016-03-10 13:05:51 -080010529 if ((pAdapter->device_mode == QDF_STA_MODE) ||
10530 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010531 if ((eCSR_ENCRYPT_TYPE_TKIP !=
10532 pHddStaCtx->conn_info.ucEncryptionType) &&
10533 (eCSR_ENCRYPT_TYPE_AES !=
10534 pHddStaCtx->conn_info.ucEncryptionType)) {
10535 /* If default key index is not same as previous one,
10536 * then update the default key index */
10537
10538 tCsrRoamSetKey setKey;
10539 uint32_t roamId = 0xFF;
10540 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
10541
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010542 hdd_info("Default tx key index %d", key_index);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010543
10544 Keys->defaultIndex = (u8) key_index;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010545 qdf_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010546 setKey.keyId = key_index;
10547 setKey.keyLength = Keys->KeyLength[key_index];
10548
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010549 qdf_mem_copy(&setKey.Key[0],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010550 &Keys->KeyMaterial[key_index][0],
10551 Keys->KeyLength[key_index]);
10552
10553 setKey.keyDirection = eSIR_TX_RX;
10554
Anurag Chouhanc5548422016-02-24 18:33:27 +053010555 qdf_copy_macaddr(&setKey.peerMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010556 &pHddStaCtx->conn_info.bssId);
10557
10558 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
10559 pWextState->roamProfile.EncryptionType.
10560 encryptionType[0] == eCSR_ENCRYPT_TYPE_WEP104) {
10561 /* In the case of dynamic wep supplicant hardcodes DWEP type
10562 * to eCSR_ENCRYPT_TYPE_WEP104 even though ap is configured for
10563 * WEP-40 encryption. In this canse the key length is 5 but the
10564 * encryption type is 104 hence checking the key langht(5) and
10565 * encryption type(104) and switching encryption type to 40*/
10566 pWextState->roamProfile.EncryptionType.
10567 encryptionType[0] = eCSR_ENCRYPT_TYPE_WEP40;
10568 pWextState->roamProfile.mcEncryptionType.
10569 encryptionType[0] = eCSR_ENCRYPT_TYPE_WEP40;
10570 }
10571
10572 setKey.encType =
10573 pWextState->roamProfile.EncryptionType.
10574 encryptionType[0];
10575
10576 /* Issue set key request */
10577 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
10578 pAdapter->sessionId, &setKey,
10579 &roamId);
10580
10581 if (0 != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010582 hdd_err("sme_roam_set_key failed, returned %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010583 status);
10584 return -EINVAL;
10585 }
10586 }
Krunal Sonib4326f22016-03-10 13:05:51 -080010587 } else if (QDF_SAP_MODE == pAdapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010588 /* In SoftAp mode setting key direction for default mode */
10589 if ((eCSR_ENCRYPT_TYPE_TKIP !=
10590 pWextState->roamProfile.EncryptionType.encryptionType[0])
10591 && (eCSR_ENCRYPT_TYPE_AES !=
10592 pWextState->roamProfile.EncryptionType.
10593 encryptionType[0])) {
10594 /* Saving key direction for default key index to TX default */
10595 hdd_ap_ctx_t *pAPCtx =
10596 WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
10597 pAPCtx->wepKey[key_index].keyDirection =
10598 eSIR_TX_DEFAULT;
Kondabattini, Ganesh702d90e2016-09-03 01:54:22 +053010599 hdd_info("WEP default key index set to SAP context %d",
Masti, Narayanraddiab712a72016-08-04 11:59:11 +053010600 key_index);
Kondabattini, Ganesh702d90e2016-09-03 01:54:22 +053010601 pAPCtx->wep_def_key_idx = key_index;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010602 }
10603 }
10604
10605 EXIT();
10606 return status;
10607}
10608
10609static int wlan_hdd_cfg80211_set_default_key(struct wiphy *wiphy,
10610 struct net_device *ndev,
10611 u8 key_index,
10612 bool unicast, bool multicast)
10613{
10614 int ret;
10615 cds_ssr_protect(__func__);
10616 ret =
10617 __wlan_hdd_cfg80211_set_default_key(wiphy, ndev, key_index, unicast,
10618 multicast);
10619 cds_ssr_unprotect(__func__);
10620
10621 return ret;
10622}
10623
Abhishek Singhc9941602016-08-09 16:06:22 +053010624/*
10625 * wlan_hdd_cfg80211_get_bss :to get the bss from kernel cache.
10626 * @wiphy: wiphy pointer
10627 * @channel: channel of the BSS
10628 * @bssid: Bssid of BSS
10629 * @ssid: Ssid of the BSS
10630 * @ssid_len: ssid length
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010631 *
Abhishek Singhc9941602016-08-09 16:06:22 +053010632 * Return: bss found in kernel cache
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010633 */
Abhishek Singhc9941602016-08-09 16:06:22 +053010634#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) && !defined(WITH_BACKPORTS)
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070010635static
Abhishek Singhc9941602016-08-09 16:06:22 +053010636struct cfg80211_bss *wlan_hdd_cfg80211_get_bss(struct wiphy *wiphy,
10637 struct ieee80211_channel *channel, const u8 *bssid,
10638 const u8 *ssid, size_t ssid_len)
10639{
10640 return cfg80211_get_bss(wiphy, channel, bssid,
10641 ssid,
10642 ssid_len,
10643 WLAN_CAPABILITY_ESS,
10644 WLAN_CAPABILITY_ESS);
10645}
10646#else
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070010647static
Abhishek Singhc9941602016-08-09 16:06:22 +053010648struct cfg80211_bss *wlan_hdd_cfg80211_get_bss(struct wiphy *wiphy,
10649 struct ieee80211_channel *channel, const u8 *bssid,
10650 const u8 *ssid, size_t ssid_len)
10651{
10652 return cfg80211_get_bss(wiphy, channel, bssid,
10653 ssid,
10654 ssid_len,
10655 IEEE80211_BSS_TYPE_ESS,
10656 IEEE80211_PRIVACY_ANY);
10657}
10658#endif
10659
10660
10661/*
10662 * wlan_hdd_cfg80211_update_bss_list :to inform nl80211
10663 * interface that BSS might have been lost.
10664 * @pAdapter: adaptor
10665 * @bssid: bssid which might have been lost
10666 *
10667 * Return: bss which is unlinked from kernel cache
10668 */
10669struct cfg80211_bss *wlan_hdd_cfg80211_update_bss_list(
10670 hdd_adapter_t *pAdapter, tSirMacAddr bssid)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010671{
10672 struct net_device *dev = pAdapter->dev;
10673 struct wireless_dev *wdev = dev->ieee80211_ptr;
10674 struct wiphy *wiphy = wdev->wiphy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010675 struct cfg80211_bss *bss = NULL;
10676
Abhishek Singhc9941602016-08-09 16:06:22 +053010677 bss = wlan_hdd_cfg80211_get_bss(wiphy, NULL, bssid,
10678 NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010679 if (bss == NULL) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010680 hdd_err("BSS not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010681 } else {
Abhishek Singhc9941602016-08-09 16:06:22 +053010682 hdd_info("cfg80211_unlink_bss called for BSSID "
10683 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(bssid));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010684 cfg80211_unlink_bss(wiphy, bss);
10685 }
10686 return bss;
10687}
10688
Abhishek Singhc9941602016-08-09 16:06:22 +053010689
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010690/**
10691 * wlan_hdd_cfg80211_inform_bss_frame() - inform bss details to NL80211
10692 * @pAdapter: Pointer to adapter
10693 * @bss_desc: Pointer to bss descriptor
10694 *
10695 * This function is used to inform the BSS details to nl80211 interface.
10696 *
10697 * Return: struct cfg80211_bss pointer
10698 */
Selvaraj, Sridharfe696d22016-08-03 21:34:51 +053010699struct cfg80211_bss *wlan_hdd_cfg80211_inform_bss_frame(hdd_adapter_t *pAdapter,
10700 tSirBssDescription *bss_desc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010701{
10702 /*
10703 * cfg80211_inform_bss() is not updating ie field of bss entry, if entry
10704 * already exists in bss data base of cfg80211 for that particular BSS
10705 * ID. Using cfg80211_inform_bss_frame to update the bss entry instead
10706 * of cfg80211_inform_bss, But this call expects mgmt packet as input.
10707 * As of now there is no possibility to get the mgmt(probe response)
10708 * frame from PE, converting bss_desc to ieee80211_mgmt(probe response)
10709 * and passing to cfg80211_inform_bss_frame.
10710 */
10711 struct net_device *dev = pAdapter->dev;
10712 struct wireless_dev *wdev = dev->ieee80211_ptr;
10713 struct wiphy *wiphy = wdev->wiphy;
10714 int chan_no = bss_desc->channelId;
10715#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
10716 qcom_ie_age *qie_age = NULL;
10717 int ie_length =
10718 GET_IE_LEN_IN_BSS_DESC(bss_desc->length) + sizeof(qcom_ie_age);
10719#else
10720 int ie_length = GET_IE_LEN_IN_BSS_DESC(bss_desc->length);
10721#endif
10722 const char *ie =
10723 ((ie_length != 0) ? (const char *)&bss_desc->ieFields : NULL);
10724 unsigned int freq;
10725 struct ieee80211_channel *chan;
10726 struct ieee80211_mgmt *mgmt = NULL;
10727 struct cfg80211_bss *bss_status = NULL;
10728 size_t frame_len = sizeof(struct ieee80211_mgmt) + ie_length;
10729 int rssi = 0;
10730 hdd_context_t *pHddCtx;
10731 int status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010732 struct timespec ts;
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -070010733 struct hdd_config *cfg_param;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010734
10735 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10736 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010737 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010738 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010739
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -070010740 cfg_param = pHddCtx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010741 mgmt = kzalloc((sizeof(struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
10742 if (!mgmt) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010743 hdd_err("memory allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010744 return NULL;
10745 }
10746
10747 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
10748
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010749 /* Android does not want the timestamp from the frame.
10750 Instead it wants a monotonic increasing value */
Yuanyuan Liu2e03b412016-04-06 14:36:15 -070010751 get_monotonic_boottime(&ts);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010752 mgmt->u.probe_resp.timestamp =
10753 ((u64) ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010754
10755 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
10756 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
10757
10758#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
10759 /* GPS Requirement: need age ie per entry. Using vendor specific. */
10760 /* Assuming this is the last IE, copy at the end */
10761 ie_length -= sizeof(qcom_ie_age);
10762 qie_age = (qcom_ie_age *) (mgmt->u.probe_resp.variable + ie_length);
10763 qie_age->element_id = QCOM_VENDOR_IE_ID;
10764 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
10765 qie_age->oui_1 = QCOM_OUI1;
10766 qie_age->oui_2 = QCOM_OUI2;
10767 qie_age->oui_3 = QCOM_OUI3;
10768 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
Deepthi Gowri6acee342016-10-28 15:00:38 +053010769 /*
10770 * Lowi expects the timestamp of bss in units of 1/10 ms. In driver
10771 * all bss related timestamp is in units of ms. Due to this when scan
10772 * results are sent to lowi the scan age is high.To address this,
10773 * send age in units of 1/10 ms.
10774 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010775 qie_age->age =
Sarada Prasanna Garnayakb3e06a62016-11-14 20:48:39 +053010776 (uint32_t)(qdf_mc_timer_get_system_time() - bss_desc->received_time)/10;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010777 qie_age->tsf_delta = bss_desc->tsf_delta;
Krishna Kumaar Natarajana4e12242016-04-01 18:44:39 -070010778 memcpy(&qie_age->beacon_tsf, bss_desc->timeStamp,
10779 sizeof(qie_age->beacon_tsf));
Krishna Kumaar Natarajan89a99d42016-08-04 15:44:38 -070010780 memcpy(&qie_age->seq_ctrl, &bss_desc->seq_ctrl,
10781 sizeof(qie_age->seq_ctrl));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010782#endif
10783
10784 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
10785 if (bss_desc->fProbeRsp) {
10786 mgmt->frame_control |=
10787 (u16) (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
10788 } else {
10789 mgmt->frame_control |=
10790 (u16) (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
10791 }
10792
10793 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_ghz) &&
Dustin Browna30892e2016-10-12 17:28:36 -070010794 (wiphy->bands[NL80211_BAND_2GHZ] != NULL)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010795 freq =
10796 ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -070010797 NL80211_BAND_2GHZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010798 } else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_ghz))
Dustin Browna30892e2016-10-12 17:28:36 -070010799 && (wiphy->bands[NL80211_BAND_5GHZ] != NULL)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010800 freq =
10801 ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -070010802 NL80211_BAND_5GHZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010803 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010804 hdd_err("Invalid chan_no %d", chan_no);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010805 kfree(mgmt);
10806 return NULL;
10807 }
10808
10809 chan = __ieee80211_get_channel(wiphy, freq);
10810 /* When the band is changed on the fly using the GUI, three things are done
10811 * 1. scan abort
10812 * 2. flush scan results from cache
10813 * 3. update the band with the new band user specified (refer to the
10814 * hdd_set_band_helper function) as part of the scan abort, message will be
10815 * queued to PE and we proceed with flushing and changinh the band.
10816 * PE will stop the scanning further and report back the results what ever
10817 * it had till now by calling the call back function.
10818 * if the time between update band and scandone call back is sufficient
10819 * enough the band change reflects in SME, SME validates the channels
10820 * and discards the channels correponding to previous band and calls back
10821 * with zero bss results. but if the time between band update and scan done
10822 * callback is very small then band change will not reflect in SME and SME
10823 * reports to HDD all the channels correponding to previous band.this is due
10824 * to race condition.but those channels are invalid to the new band and so
10825 * this function __ieee80211_get_channel will return NULL.Each time we
10826 * report scan result with this pointer null warning kernel trace is printed.
10827 * if the scan results contain large number of APs continuosly kernel
10828 * warning trace is printed and it will lead to apps watch dog bark.
10829 * So drop the bss and continue to next bss.
10830 */
10831 if (chan == NULL) {
Deepthi Gowri084c24d2016-09-01 15:55:09 +053010832 hdd_err("chan pointer is NULL, chan_no: %d freq: %d",
10833 chan_no, freq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010834 kfree(mgmt);
10835 return NULL;
10836 }
10837
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -070010838 /* Based on .ini configuration, raw rssi can be reported for bss.
10839 * Raw rssi is typically used for estimating power.
10840 */
10841
10842 rssi = (cfg_param->inform_bss_rssi_raw) ? bss_desc->rssi_raw :
10843 bss_desc->rssi;
10844
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010845 /* Supplicant takes the signal strength in terms of mBm(100*dBm) */
Anurag Chouhan6d760662016-02-20 16:05:43 +053010846 rssi = QDF_MIN(rssi, 0) * 100;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010847
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010848 hdd_notice("BSSID: " MAC_ADDRESS_STR " Channel:%d RSSI:%d TSF %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010849 MAC_ADDR_ARRAY(mgmt->bssid), chan->center_freq,
Sandeep Puligilla394da5d2016-05-06 01:26:29 -070010850 (int)(rssi / 100),
10851 bss_desc->timeStamp[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010852
10853 bss_status =
10854 cfg80211_inform_bss_frame(wiphy, chan, mgmt, frame_len, rssi,
10855 GFP_KERNEL);
10856 kfree(mgmt);
10857 return bss_status;
10858}
10859
10860/**
10861 * wlan_hdd_cfg80211_update_bss_db() - update bss database of CF80211
10862 * @pAdapter: Pointer to adapter
10863 * @pRoamInfo: Pointer to roam info
10864 *
10865 * This function is used to update the BSS data base of CFG8011
10866 *
10867 * Return: struct cfg80211_bss pointer
10868 */
10869struct cfg80211_bss *wlan_hdd_cfg80211_update_bss_db(hdd_adapter_t *pAdapter,
10870 tCsrRoamInfo *pRoamInfo)
10871{
10872 tCsrRoamConnectedProfile roamProfile;
10873 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
10874 struct cfg80211_bss *bss = NULL;
10875
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010876 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
10877 sme_roam_get_connect_profile(hHal, pAdapter->sessionId, &roamProfile);
10878
10879 if (NULL != roamProfile.pBssDesc) {
10880 bss = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
10881 roamProfile.pBssDesc);
10882
10883 if (NULL == bss)
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010884 hdd_notice("wlan_hdd_cfg80211_inform_bss_frame returned NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010885
Naveen Rawatdf0a7e72016-01-06 18:35:53 -080010886 sme_roam_free_connect_profile(&roamProfile);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010887 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010888 hdd_err("roamProfile.pBssDesc is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010889 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010890 return bss;
10891}
10892/**
10893 * wlan_hdd_cfg80211_update_bss() - update bss
10894 * @wiphy: Pointer to wiphy
10895 * @pAdapter: Pointer to adapter
10896 * @scan_time: scan request timestamp
10897 *
10898 * Return: zero if success, non-zero otherwise
10899 */
10900int wlan_hdd_cfg80211_update_bss(struct wiphy *wiphy,
10901 hdd_adapter_t *pAdapter,
10902 uint32_t scan_time)
10903{
10904 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
10905 tCsrScanResultInfo *pScanResult;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010906 QDF_STATUS status = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010907 tScanResultHandle pResult;
10908 struct cfg80211_bss *bss_status = NULL;
10909 hdd_context_t *pHddCtx;
10910 int ret;
10911
10912 ENTER();
10913
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053010914 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
10915 hdd_err("invalid session id: %d", pAdapter->sessionId);
10916 return -EINVAL;
10917 }
10918
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053010919 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010920 TRACE_CODE_HDD_CFG80211_UPDATE_BSS,
10921 NO_SESSION, pAdapter->sessionId));
10922
10923 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10924 ret = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010925 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010926 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010927
10928 /* start getting scan results and populate cgf80211 BSS database */
10929 status = sme_scan_get_result(hHal, pAdapter->sessionId, NULL, &pResult);
10930
10931 /* no scan results */
10932 if (NULL == pResult) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010933 hdd_err("No scan result Status %d", status);
Kapil Gupta0ed58dc2016-04-22 15:35:26 +053010934 return -EAGAIN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010935 }
10936
10937 pScanResult = sme_scan_result_get_first(hHal, pResult);
10938
10939 while (pScanResult) {
10940 /*
10941 * - cfg80211_inform_bss() is not updating ie field of bss
10942 * entry if entry already exists in bss data base of cfg80211
10943 * for that particular BSS ID. Using cfg80211_inform_bss_frame
10944 * to update thebss entry instead of cfg80211_inform_bss,
10945 * But this call expects mgmt packet as input. As of now
10946 * there is no possibility to get the mgmt(probe response)
10947 * frame from PE, converting bss_desc to
10948 * ieee80211_mgmt(probe response) and passing to c
10949 * fg80211_inform_bss_frame.
10950 * - Update BSS only if beacon timestamp is later than
10951 * scan request timestamp.
10952 */
10953 if ((scan_time == 0) ||
10954 (scan_time <
Deepthi Gowri6acee342016-10-28 15:00:38 +053010955 pScanResult->BssDescriptor.received_time)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010956 bss_status =
10957 wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
10958 &pScanResult->BssDescriptor);
10959
10960 if (NULL == bss_status) {
10961 hdd_info("NULL returned by cfg80211_inform_bss_frame");
10962 } else {
10963 cfg80211_put_bss(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010964 wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010965 bss_status);
10966 }
10967 } else {
10968 hdd_info("BSSID: " MAC_ADDRESS_STR " Skipped",
10969 MAC_ADDR_ARRAY(pScanResult->BssDescriptor.bssId));
10970 }
10971 pScanResult = sme_scan_result_get_next(hHal, pResult);
10972 }
10973
10974 sme_scan_result_purge(hHal, pResult);
10975 /*
10976 * For SAP mode, scan is invoked by hostapd during SAP start
10977 * if hostapd is restarted, we need to flush previous scan
10978 * result so that it will reflect environment change
10979 */
Krunal Sonib4326f22016-03-10 13:05:51 -080010980 if (pAdapter->device_mode == QDF_SAP_MODE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010981#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
10982 && pHddCtx->skip_acs_scan_status != eSAP_SKIP_ACS_SCAN
10983#endif
10984 )
10985 sme_scan_flush_result(hHal);
10986
10987 EXIT();
10988 return 0;
10989}
10990
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010991/**
10992 * wlan_hdd_cfg80211_pmksa_candidate_notify() - notify a new PMSKA candidate
10993 * @pAdapter: Pointer to adapter
10994 * @pRoamInfo: Pointer to roam info
10995 * @index: Index
10996 * @preauth: Preauth flag
10997 *
10998 * This function is used to notify the supplicant of a new PMKSA candidate.
10999 *
11000 * Return: 0 for success, non-zero for failure
11001 */
11002int wlan_hdd_cfg80211_pmksa_candidate_notify(hdd_adapter_t *pAdapter,
11003 tCsrRoamInfo *pRoamInfo,
11004 int index, bool preauth)
11005{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011006 struct net_device *dev = pAdapter->dev;
11007 hdd_context_t *pHddCtx = (hdd_context_t *) pAdapter->pHddCtx;
11008
11009 ENTER();
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011010 hdd_notice("is going to notify supplicant of:");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011011
11012 if (NULL == pRoamInfo) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011013 hdd_alert("pRoamInfo is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011014 return -EINVAL;
11015 }
11016
11017 if (true == hdd_is_okc_mode_enabled(pHddCtx)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011018 hdd_notice(MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011019 MAC_ADDR_ARRAY(pRoamInfo->bssid.bytes));
11020 cfg80211_pmksa_candidate_notify(dev, index,
11021 pRoamInfo->bssid.bytes,
11022 preauth, GFP_KERNEL);
11023 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011024 return 0;
11025}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011026
11027#ifdef FEATURE_WLAN_LFR_METRICS
11028/**
11029 * wlan_hdd_cfg80211_roam_metrics_preauth() - roam metrics preauth
11030 * @pAdapter: Pointer to adapter
11031 * @pRoamInfo: Pointer to roam info
11032 *
11033 * 802.11r/LFR metrics reporting function to report preauth initiation
11034 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011035 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011036 */
11037#define MAX_LFR_METRICS_EVENT_LENGTH 100
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011038QDF_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011039 tCsrRoamInfo *pRoamInfo)
11040{
11041 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
11042 union iwreq_data wrqu;
11043
11044 ENTER();
11045
11046 if (NULL == pAdapter) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011047 hdd_err("pAdapter is NULL!");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011048 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011049 }
11050
11051 /* create the event */
11052 memset(&wrqu, 0, sizeof(wrqu));
11053 memset(metrics_notification, 0, sizeof(metrics_notification));
11054
11055 wrqu.data.pointer = metrics_notification;
11056 wrqu.data.length = scnprintf(metrics_notification,
11057 sizeof(metrics_notification),
11058 "QCOM: LFR_PREAUTH_INIT " MAC_ADDRESS_STR,
11059 MAC_ADDR_ARRAY(pRoamInfo->bssid));
11060
11061 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu,
11062 metrics_notification);
11063
11064 EXIT();
11065
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011066 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011067}
11068
11069/**
11070 * wlan_hdd_cfg80211_roam_metrics_handover() - roam metrics hand over
11071 * @pAdapter: Pointer to adapter
11072 * @pRoamInfo: Pointer to roam info
11073 * @preauth_status: Preauth status
11074 *
11075 * 802.11r/LFR metrics reporting function to report handover initiation
11076 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011077 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011078 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011079QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011080wlan_hdd_cfg80211_roam_metrics_preauth_status(hdd_adapter_t *pAdapter,
11081 tCsrRoamInfo *pRoamInfo,
11082 bool preauth_status)
11083{
11084 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
11085 union iwreq_data wrqu;
11086
11087 ENTER();
11088
11089 if (NULL == pAdapter) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011090 hdd_err("pAdapter is NULL!");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011091 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011092 }
11093
11094 /* create the event */
11095 memset(&wrqu, 0, sizeof(wrqu));
11096 memset(metrics_notification, 0, sizeof(metrics_notification));
11097
11098 scnprintf(metrics_notification, sizeof(metrics_notification),
11099 "QCOM: LFR_PREAUTH_STATUS " MAC_ADDRESS_STR,
11100 MAC_ADDR_ARRAY(pRoamInfo->bssid));
11101
11102 if (1 == preauth_status)
11103 strlcat(metrics_notification, " true",
11104 sizeof(metrics_notification));
11105 else
11106 strlcat(metrics_notification, " false",
11107 sizeof(metrics_notification));
11108
11109 wrqu.data.pointer = metrics_notification;
11110 wrqu.data.length = strlen(metrics_notification);
11111
11112 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu,
11113 metrics_notification);
11114
11115 EXIT();
11116
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011117 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011118}
11119
11120/**
11121 * wlan_hdd_cfg80211_roam_metrics_handover() - roam metrics hand over
11122 * @pAdapter: Pointer to adapter
11123 * @pRoamInfo: Pointer to roam info
11124 *
11125 * 802.11r/LFR metrics reporting function to report handover initiation
11126 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011127 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011128 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011129QDF_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t *pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011130 tCsrRoamInfo *pRoamInfo)
11131{
11132 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
11133 union iwreq_data wrqu;
11134
11135 ENTER();
11136
11137 if (NULL == pAdapter) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011138 hdd_err("pAdapter is NULL!");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011139 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011140 }
11141
11142 /* create the event */
11143 memset(&wrqu, 0, sizeof(wrqu));
11144 memset(metrics_notification, 0, sizeof(metrics_notification));
11145
11146 wrqu.data.pointer = metrics_notification;
11147 wrqu.data.length = scnprintf(metrics_notification,
11148 sizeof(metrics_notification),
11149 "QCOM: LFR_PREAUTH_HANDOVER "
11150 MAC_ADDRESS_STR,
11151 MAC_ADDR_ARRAY(pRoamInfo->bssid));
11152
11153 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu,
11154 metrics_notification);
11155
11156 EXIT();
11157
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011158 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011159}
11160#endif
11161
11162/**
11163 * hdd_select_cbmode() - select channel bonding mode
11164 * @pAdapter: Pointer to adapter
11165 * @operatingChannel: Operating channel
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011166 * @ch_params: channel info struct to populate
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011167 *
11168 * Return: none
11169 */
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011170void hdd_select_cbmode(hdd_adapter_t *pAdapter, uint8_t operationChannel,
11171 struct ch_params_s *ch_params)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011172{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011173 hdd_station_ctx_t *station_ctx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011174 struct hdd_mon_set_ch_info *ch_info = &station_ctx->ch_info;
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070011175 uint8_t sec_ch = 0;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011176
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070011177 /*
11178 * CDS api expects secondary channel for calculating
11179 * the channel params
11180 */
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011181 if ((ch_params->ch_width == CH_WIDTH_40MHZ) &&
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070011182 (CDS_IS_CHANNEL_24GHZ(operationChannel))) {
11183 if (operationChannel >= 1 && operationChannel <= 5)
11184 sec_ch = operationChannel + 4;
11185 else if (operationChannel >= 6 && operationChannel <= 13)
11186 sec_ch = operationChannel - 4;
11187 }
11188
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011189 /* This call decides required channel bonding mode */
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011190 cds_set_channel_params(operationChannel, sec_ch, ch_params);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011191
11192 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam()) {
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011193 eHddDot11Mode hdd_dot11_mode;
11194 uint8_t iniDot11Mode =
11195 (WLAN_HDD_GET_CTX(pAdapter))->config->dot11Mode;
11196
11197 hdd_notice("Dot11Mode is %u", iniDot11Mode);
11198 switch (iniDot11Mode) {
11199 case eHDD_DOT11_MODE_AUTO:
11200 case eHDD_DOT11_MODE_11ac:
11201 case eHDD_DOT11_MODE_11ac_ONLY:
11202 if (sme_is_feature_supported_by_fw(DOT11AC))
11203 hdd_dot11_mode = eHDD_DOT11_MODE_11ac;
11204 else
11205 hdd_dot11_mode = eHDD_DOT11_MODE_11n;
11206 break;
11207 case eHDD_DOT11_MODE_11n:
11208 case eHDD_DOT11_MODE_11n_ONLY:
11209 hdd_dot11_mode = eHDD_DOT11_MODE_11n;
11210 break;
11211 default:
11212 hdd_dot11_mode = iniDot11Mode;
11213 break;
11214 }
11215 ch_info->channel_width = ch_params->ch_width;
11216 ch_info->phy_mode =
11217 hdd_cfg_xlate_to_csr_phy_mode(hdd_dot11_mode);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011218 ch_info->channel = operationChannel;
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011219 ch_info->cb_mode = ch_params->ch_width;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011220 hdd_info("ch_info width %d, phymode %d channel %d",
11221 ch_info->channel_width, ch_info->phy_mode,
11222 ch_info->channel);
11223 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011224}
11225
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070011226/**
11227 * wlan_hdd_handle_sap_sta_dfs_conc() - to handle SAP STA DFS conc
11228 * @adapter: STA adapter
11229 * @roam_profile: STA roam profile
11230 *
11231 * This routine will move SAP from dfs to non-dfs, if sta is coming up.
11232 *
11233 * Return: false if sta-sap conc is not allowed, else return true
11234 */
11235static bool wlan_hdd_handle_sap_sta_dfs_conc(hdd_adapter_t *adapter,
11236 tCsrRoamProfile *roam_profile)
11237{
11238 hdd_context_t *hdd_ctx;
11239 hdd_adapter_t *ap_adapter;
11240 hdd_ap_ctx_t *hdd_ap_ctx;
11241 hdd_hostapd_state_t *hostapd_state;
11242 uint8_t channel = 0;
11243 QDF_STATUS status;
11244
11245 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11246 if (!hdd_ctx) {
11247 hdd_err("HDD context is NULL");
11248 return true;
11249 }
11250
11251 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
11252 /* probably no sap running, no handling required */
11253 if (ap_adapter == NULL)
11254 return true;
11255
11256 /*
11257 * sap is not in started state, so it is fine to go ahead with sta.
11258 * if sap is currently doing CAC then don't allow sta to go further.
11259 */
11260 if (!test_bit(SOFTAP_BSS_STARTED, &(ap_adapter)->event_flags) &&
11261 (hdd_ctx->dev_dfs_cac_status != DFS_CAC_IN_PROGRESS))
11262 return true;
11263
11264 if (hdd_ctx->dev_dfs_cac_status == DFS_CAC_IN_PROGRESS) {
11265 hdd_err("Concurrent SAP is in CAC state, STA is not allowed");
11266 return false;
11267 }
11268
11269 /*
11270 * log and return error, if we allow STA to go through, we don't
11271 * know what is going to happen better stop sta connection
11272 */
11273 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11274 if (NULL == hdd_ap_ctx) {
11275 hdd_err("AP context not found");
11276 return false;
11277 }
11278
11279 /* sap is on non-dfs channel, nothing to handle */
11280 if (!CDS_IS_DFS_CH(hdd_ap_ctx->operatingChannel)) {
11281 hdd_info("sap is on non-dfs channel, sta is allowed");
11282 return true;
11283 }
11284 /*
11285 * find out by looking in to scan cache where sta is going to
Nitesh Shah59774522016-09-16 15:14:21 +053011286 * connect by passing its roam_profile.
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070011287 */
11288 status = cds_get_channel_from_scan_result(adapter,
11289 roam_profile, &channel);
11290
Nitesh Shah59774522016-09-16 15:14:21 +053011291 /*
11292 * If the STA's channel is 2.4 GHz, then set pcl with only 2.4 GHz
11293 * channels for roaming case.
11294 */
11295 if (CDS_IS_CHANNEL_24GHZ(channel)) {
11296 hdd_info("sap is on dfs, new sta conn on 2.4 is allowed");
11297 return true;
11298 }
11299
11300 /*
11301 * If channel is 0 or DFS then better to call pcl and find out the
11302 * best channel. If channel is non-dfs 5 GHz then better move SAP
11303 * to STA's channel to make scc, so we have room for 3port MCC
11304 * scenario.
11305 */
11306 if ((0 == channel) || CDS_IS_DFS_CH(channel))
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070011307 channel = cds_get_nondfs_preferred_channel(CDS_SAP_MODE,
11308 true);
11309
11310 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
11311 qdf_event_reset(&hostapd_state->qdf_event);
11312 status = wlansap_set_channel_change_with_csa(
11313 WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter), channel,
11314 hdd_ap_ctx->sapConfig.ch_width_orig);
11315
11316 if (QDF_STATUS_SUCCESS != status) {
11317 hdd_err("Set channel with CSA IE failed, can't allow STA");
11318 return false;
11319 }
11320
11321 /*
11322 * wait here for SAP to finish the channel switch. When channel
11323 * switch happens, SAP sends few beacons with CSA_IE. After
11324 * successfully Transmission of those beacons, it will move its
11325 * state from started to disconnected and move to new channel.
11326 * once it moves to new channel, sap again moves its state
11327 * machine from disconnected to started and set this event.
11328 * wait for 10 secs to finish this.
11329 */
11330 status = qdf_wait_single_event(&hostapd_state->qdf_event, 10000);
11331 if (!QDF_IS_STATUS_SUCCESS(status)) {
11332 hdd_err("wait for qdf_event failed, STA not allowed!!");
11333 return false;
11334 }
11335
11336 return true;
11337}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011338
Krunal Soni31949422016-07-29 17:17:53 -070011339/**
11340 * wlan_hdd_cfg80211_connect_start() - to start the association process
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341 * @pAdapter: Pointer to adapter
Krunal Soni31949422016-07-29 17:17:53 -070011342 * @ssid: Pointer to ssid
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011343 * @ssid_len: Length of ssid
11344 * @bssid: Pointer to bssid
Krunal Soni31949422016-07-29 17:17:53 -070011345 * @bssid_hint: Pointer to bssid hint
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011346 * @operatingChannel: Operating channel
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011347 * @ch_width: channel width. this is needed only for IBSS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011348 *
11349 * This function is used to start the association process
11350 *
11351 * Return: 0 for success, non-zero for failure
11352 */
Krunal Soni31949422016-07-29 17:17:53 -070011353static int wlan_hdd_cfg80211_connect_start(hdd_adapter_t *pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011354 const u8 *ssid, size_t ssid_len,
Krunal Soni31949422016-07-29 17:17:53 -070011355 const u8 *bssid, const u8 *bssid_hint,
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011356 u8 operatingChannel,
11357 enum nl80211_chan_width ch_width)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011358{
11359 int status = 0;
11360 hdd_wext_state_t *pWextState;
11361 hdd_context_t *pHddCtx;
Anurag Chouhan5de8d172016-07-13 14:44:28 +053011362 hdd_station_ctx_t *hdd_sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011363 uint32_t roamId;
11364 tCsrRoamProfile *pRoamProfile;
11365 eCsrAuthType RSNAuthType;
11366 tSmeConfigParams *sme_config;
Nitesh Shah044fd672016-10-13 18:53:25 +053011367 uint8_t channel = 0;
11368 struct sir_hw_mode_params hw_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011369
11370 ENTER();
11371
11372 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11373 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Anurag Chouhan5de8d172016-07-13 14:44:28 +053011374 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011375
11376 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053011377 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011378 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011379
11380 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011381 hdd_err("wrong SSID len");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011382 return -EINVAL;
11383 }
11384
11385 pRoamProfile = &pWextState->roamProfile;
Anurag Chouhand939d3d2016-07-20 17:45:48 +053011386 qdf_mem_zero(&hdd_sta_ctx->conn_info.conn_flag,
11387 sizeof(hdd_sta_ctx->conn_info.conn_flag));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011388
11389 if (pRoamProfile) {
11390 hdd_station_ctx_t *pHddStaCtx;
11391 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11392
11393 if (HDD_WMM_USER_MODE_NO_QOS ==
11394 (WLAN_HDD_GET_CTX(pAdapter))->config->WmmMode) {
11395 /*QoS not enabled in cfg file */
11396 pRoamProfile->uapsd_mask = 0;
11397 } else {
11398 /*QoS enabled, update uapsd mask from cfg file */
11399 pRoamProfile->uapsd_mask =
11400 (WLAN_HDD_GET_CTX(pAdapter))->config->UapsdMask;
11401 }
11402
11403 pRoamProfile->SSIDs.numOfSSIDs = 1;
11404 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011405 qdf_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011406 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011407 qdf_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011408 ssid, ssid_len);
11409
Sreelakshmi Konamkibda5bbf2016-09-12 18:38:10 +053011410 pRoamProfile->do_not_roam = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011411 if (bssid) {
11412 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
Sreelakshmi Konamkibda5bbf2016-09-12 18:38:10 +053011413 pRoamProfile->do_not_roam = true;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011414 qdf_mem_copy((void *)(pRoamProfile->BSSIDs.bssid),
Anurag Chouhan6d760662016-02-20 16:05:43 +053011415 bssid, QDF_MAC_ADDR_SIZE);
Krunal Soni31949422016-07-29 17:17:53 -070011416 /*
11417 * Save BSSID in seperate variable as
11418 * pRoamProfile's BSSID is getting zeroed out in the
11419 * association process. In case of join failure
11420 * we should send valid BSSID to supplicant
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011421 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011422 qdf_mem_copy((void *)(pWextState->req_bssId.bytes),
Anurag Chouhan6d760662016-02-20 16:05:43 +053011423 bssid, QDF_MAC_ADDR_SIZE);
Krunal Soni35b404c2016-07-14 23:36:00 -070011424 hdd_info("bssid is given by upper layer %pM", bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011425 } else if (bssid_hint) {
11426 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011427 qdf_mem_copy((void *)(pRoamProfile->BSSIDs.bssid),
Anurag Chouhan6d760662016-02-20 16:05:43 +053011428 bssid_hint, QDF_MAC_ADDR_SIZE);
Krunal Soni31949422016-07-29 17:17:53 -070011429 /*
11430 * Save BSSID in a separate variable as
11431 * pRoamProfile's BSSID is getting zeroed out in the
11432 * association process. In case of join failure
11433 * we should send valid BSSID to supplicant
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011434 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011435 qdf_mem_copy((void *)(pWextState->req_bssId.bytes),
Anurag Chouhan6d760662016-02-20 16:05:43 +053011436 bssid_hint, QDF_MAC_ADDR_SIZE);
Krunal Soni35b404c2016-07-14 23:36:00 -070011437 hdd_info("bssid_hint is given by upper layer %pM",
11438 bssid_hint);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011439 } else {
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011440 qdf_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),
Anurag Chouhan6d760662016-02-20 16:05:43 +053011441 QDF_MAC_ADDR_SIZE);
Krunal Soni35b404c2016-07-14 23:36:00 -070011442 hdd_info("no bssid given by upper layer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011443 }
11444
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011445 hdd_notice("Connect to SSID: %.*s operating Channel: %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011446 pRoamProfile->SSIDs.SSIDList->SSID.length,
11447 pRoamProfile->SSIDs.SSIDList->SSID.ssId,
11448 operatingChannel);
11449
11450 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
11451 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011452 hdd_set_genie_to_csr(pAdapter, &RSNAuthType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011453 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
11454 }
11455#ifdef FEATURE_WLAN_WAPI
11456 if (pAdapter->wapi_info.nWapiMode) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011457 hdd_notice("Setting WAPI AUTH Type and Encryption Mode values");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011458 switch (pAdapter->wapi_info.wapiAuthMode) {
11459 case WAPI_AUTH_MODE_PSK:
11460 {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011461 hdd_notice("WAPI AUTH TYPE: PSK: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011462 pAdapter->wapi_info.wapiAuthMode);
11463 pRoamProfile->AuthType.authType[0] =
11464 eCSR_AUTH_TYPE_WAPI_WAI_PSK;
11465 break;
11466 }
11467 case WAPI_AUTH_MODE_CERT:
11468 {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011469 hdd_notice("WAPI AUTH TYPE: CERT: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011470 pAdapter->wapi_info.wapiAuthMode);
11471 pRoamProfile->AuthType.authType[0] =
11472 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
11473 break;
11474 }
11475 } /* End of switch */
11476 if (pAdapter->wapi_info.wapiAuthMode ==
11477 WAPI_AUTH_MODE_PSK
11478 || pAdapter->wapi_info.wapiAuthMode ==
11479 WAPI_AUTH_MODE_CERT) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011480 hdd_notice("WAPI PAIRWISE/GROUP ENCRYPTION: WPI");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011481 pRoamProfile->AuthType.numEntries = 1;
11482 pRoamProfile->EncryptionType.numEntries = 1;
11483 pRoamProfile->EncryptionType.encryptionType[0] =
11484 eCSR_ENCRYPT_TYPE_WPI;
11485 pRoamProfile->mcEncryptionType.numEntries = 1;
11486 pRoamProfile->mcEncryptionType.
11487 encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
11488 }
11489 }
Krunal Soni31949422016-07-29 17:17:53 -070011490#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011491#ifdef WLAN_FEATURE_GTK_OFFLOAD
11492 /* Initializing gtkOffloadReqParams */
Krunal Sonib4326f22016-03-10 13:05:51 -080011493 if ((QDF_STA_MODE == pAdapter->device_mode) ||
11494 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011495 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
11496 sizeof(tSirGtkOffloadParams));
11497 pHddStaCtx->gtkOffloadReqParams.ulFlags =
11498 GTK_OFFLOAD_DISABLE;
11499 }
11500#endif
11501 pRoamProfile->csrPersona = pAdapter->device_mode;
11502
11503 if (operatingChannel) {
11504 pRoamProfile->ChannelInfo.ChannelList =
11505 &operatingChannel;
11506 pRoamProfile->ChannelInfo.numOfChannels = 1;
11507 } else {
11508 pRoamProfile->ChannelInfo.ChannelList = NULL;
11509 pRoamProfile->ChannelInfo.numOfChannels = 0;
11510 }
Krunal Sonib4326f22016-03-10 13:05:51 -080011511 if ((QDF_IBSS_MODE == pAdapter->device_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011512 && operatingChannel) {
11513 /*
11514 * Need to post the IBSS power save parameters
11515 * to WMA. WMA will configure this parameters
11516 * to firmware if power save is enabled by the
11517 * firmware.
11518 */
11519 status = hdd_set_ibss_power_save_params(pAdapter);
11520
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011521 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011522 hdd_err("Set IBSS Power Save Params Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011523 return -EINVAL;
11524 }
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011525 pRoamProfile->ch_params.ch_width =
11526 hdd_map_nl_chan_width(ch_width);
Nitesh Shah87335a52016-09-05 15:47:32 +053011527 /*
11528 * In IBSS mode while operating in 2.4 GHz,
11529 * the device supports only 20 MHz.
11530 */
11531 if (CDS_IS_CHANNEL_24GHZ(operatingChannel))
11532 pRoamProfile->ch_params.ch_width =
11533 CH_WIDTH_20MHZ;
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011534 hdd_select_cbmode(pAdapter, operatingChannel,
11535 &pRoamProfile->ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011536 }
Abhishek Singh99bce862016-06-20 15:10:51 +053011537 /*
11538 * if MFPEnabled is set but the peer AP is non-PMF i.e 80211w=2
11539 * or pmf=2 is an explicit configuration in the supplicant
11540 * configuration, drop the connection request.
11541 */
11542 if (pWextState->roamProfile.MFPEnabled &&
11543 !(pWextState->roamProfile.MFPRequired ||
11544 pWextState->roamProfile.MFPCapable)) {
11545 hdd_err("Drop connect req as supplicant has indicated PMF req for a non-PMF peer. MFPEnabled %d MFPRequired %d MFPCapable %d",
11546 pWextState->roamProfile.MFPEnabled,
11547 pWextState->roamProfile.MFPRequired,
11548 pWextState->roamProfile.MFPCapable);
11549 return -EINVAL;
11550 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011551
Krunal Soni3091bcc2016-06-23 12:28:21 -070011552 if (true == cds_is_connection_in_progress()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011553 hdd_err("Connection refused: conn in progress");
11554 return -EINVAL;
11555 }
11556
Krunal Soni31949422016-07-29 17:17:53 -070011557 /*
11558 * After 8-way handshake supplicant should give the scan command
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011559 * in that it update the additional IEs, But because of scan
Krunal Soni31949422016-07-29 17:17:53 -070011560 * enhancements, the supplicant is not issuing the scan command
11561 * now. So the unicast frames which are sent from the host are
11562 * not having the additional IEs. If it is P2P CLIENT and there
11563 * is no additional IE present in roamProfile, then use the
11564 * addtional IE form scan_info
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011565 */
11566
Krunal Sonib4326f22016-03-10 13:05:51 -080011567 if ((pAdapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011568 (!pRoamProfile->pAddIEScan)) {
11569 pRoamProfile->pAddIEScan =
11570 &pAdapter->scan_info.scanAddIE.addIEdata[0];
11571 pRoamProfile->nAddIEScanLength =
11572 pAdapter->scan_info.scanAddIE.length;
11573 }
11574 /*
11575 * When policy manager is enabled from ini file, we shouldn't
11576 * check for other concurrency rules.
11577 */
Krunal Soni3091bcc2016-06-23 12:28:21 -070011578 if (wma_is_hw_dbs_capable() == false) {
Tushnim Bhattacharyya4adb3682016-01-07 15:07:12 -080011579 cds_handle_conc_rule1(pAdapter, pRoamProfile);
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080011580 if (true != cds_handle_conc_rule2(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011581 pAdapter, pRoamProfile, &roamId))
11582 return 0;
11583 }
11584
Krunal Soni3091bcc2016-06-23 12:28:21 -070011585 if ((wma_is_hw_dbs_capable() == true) &&
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070011586 (false == wlan_hdd_handle_sap_sta_dfs_conc(pAdapter,
11587 pRoamProfile))) {
11588 hdd_err("sap-sta conc will fail, can't allow sta");
11589 hdd_conn_set_connection_state(pAdapter,
11590 eConnectionState_NotConnected);
11591 return -ENOMEM;
11592 }
11593
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011594 sme_config = qdf_mem_malloc(sizeof(*sme_config));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011595 if (!sme_config) {
11596 hdd_err("unable to allocate sme_config");
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070011597 hdd_conn_set_connection_state(pAdapter,
11598 eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011599 return -ENOMEM;
11600 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011601 sme_get_config_param(pHddCtx->hHal, sme_config);
11602 /* These values are not sessionized. So, any change in these SME
11603 * configs on an older or parallel interface will affect the
11604 * cb mode. So, restoring the default INI params before starting
11605 * interfaces such as sta, cli etc.,
11606 */
11607 sme_config->csrConfig.channelBondingMode5GHz =
11608 pHddCtx->config->nChannelBondingMode5GHz;
11609 sme_config->csrConfig.channelBondingMode24GHz =
11610 pHddCtx->config->nChannelBondingMode24GHz;
11611 sme_update_config(pHddCtx->hHal, sme_config);
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011612 qdf_mem_free(sme_config);
Agrawal Ashish6b015762016-05-05 11:22:18 +053011613 /*
11614 * Change conn_state to connecting before sme_roam_connect(),
11615 * because sme_roam_connect() has a direct path to call
11616 * hdd_sme_roam_callback(), which will change the conn_state
11617 * If direct path, conn_state will be accordingly changed to
11618 * NotConnected or Associated by either
11619 * hdd_association_completion_handler() or
11620 * hdd_dis_connect_handler() in sme_RoamCallback()if
11621 * sme_RomConnect is to be queued,
11622 * Connecting state will remain until it is completed.
11623 *
11624 * If connection state is not changed, connection state will
11625 * remain in eConnectionState_NotConnected state.
11626 * In hdd_association_completion_handler, "hddDisconInProgress"
11627 * is set to true if conn state is
11628 * eConnectionState_NotConnected.
11629 * If "hddDisconInProgress" is set to true then cfg80211 layer
11630 * is not informed of connect result indication which
11631 * is an issue.
11632 */
11633 if (QDF_STA_MODE == pAdapter->device_mode ||
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011634 QDF_P2P_CLIENT_MODE == pAdapter->device_mode)
Agrawal Ashish6b015762016-05-05 11:22:18 +053011635 hdd_conn_set_connection_state(pAdapter,
11636 eConnectionState_Connecting);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011637
Komal Seelama89be8d2016-09-29 11:09:26 +053011638 qdf_runtime_pm_prevent_suspend(pAdapter->connect_rpm_ctx.
11639 connect);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011640 status = sme_roam_connect(WLAN_HDD_GET_HAL_CTX(pAdapter),
11641 pAdapter->sessionId, pRoamProfile,
11642 &roamId);
11643
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011644 if ((QDF_STATUS_SUCCESS != status) &&
Krunal Sonib4326f22016-03-10 13:05:51 -080011645 (QDF_STA_MODE == pAdapter->device_mode ||
11646 QDF_P2P_CLIENT_MODE == pAdapter->device_mode)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011647 hdd_err("sme_roam_connect (session %d) failed with "
11648 "status %d. -> NotConnected",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011649 pAdapter->sessionId, status);
11650 /* change back to NotAssociated */
11651 hdd_conn_set_connection_state(pAdapter,
11652 eConnectionState_NotConnected);
Komal Seelama89be8d2016-09-29 11:09:26 +053011653 qdf_runtime_pm_allow_suspend(pAdapter->connect_rpm_ctx.
11654 connect);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011655 }
11656
11657 pRoamProfile->ChannelInfo.ChannelList = NULL;
11658 pRoamProfile->ChannelInfo.numOfChannels = 0;
11659
Nitesh Shah044fd672016-10-13 18:53:25 +053011660 if (!QDF_IS_STATUS_SUCCESS(
11661 wma_get_current_hw_mode(&hw_mode))) {
11662 hdd_err("wma_get_current_hw_mode failed");
11663 return status;
11664 }
11665
11666 if ((QDF_STA_MODE == pAdapter->device_mode)
11667 && hw_mode.dbs_cap) {
11668 cds_get_channel_from_scan_result(pAdapter,
11669 pRoamProfile, &channel);
11670 if (channel)
11671 cds_checkn_update_hw_mode_single_mac_mode
11672 (channel);
11673 }
11674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011675 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011676 hdd_err("No valid Roam profile");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011677 return -EINVAL;
11678 }
11679 EXIT();
11680 return status;
11681}
11682
11683/**
11684 * wlan_hdd_cfg80211_set_auth_type() - set auth type
11685 * @pAdapter: Pointer to adapter
11686 * @auth_type: Auth type
11687 *
11688 * This function is used to set the authentication type (OPEN/SHARED).
11689 *
11690 * Return: 0 for success, non-zero for failure
11691 */
11692static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
11693 enum nl80211_auth_type auth_type)
11694{
11695 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11696 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11697
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011698 /*set authentication type */
11699 switch (auth_type) {
11700 case NL80211_AUTHTYPE_AUTOMATIC:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011701 hdd_notice("set authentication type to AUTOSWITCH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011702 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
11703 break;
11704
11705 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011706 case NL80211_AUTHTYPE_FT:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011707 hdd_notice("set authentication type to OPEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011708 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
11709 break;
11710
11711 case NL80211_AUTHTYPE_SHARED_KEY:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011712 hdd_notice("set authentication type to SHARED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011713 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
11714 break;
11715#ifdef FEATURE_WLAN_ESE
11716 case NL80211_AUTHTYPE_NETWORK_EAP:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011717 hdd_notice("set authentication type to CCKM WPA");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011718 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;
11719 break;
11720#endif
11721
11722 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011723 hdd_err("Unsupported authentication type %d", auth_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011724 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
11725 return -EINVAL;
11726 }
11727
11728 pWextState->roamProfile.AuthType.authType[0] =
11729 pHddStaCtx->conn_info.authType;
11730 return 0;
11731}
11732
11733/**
11734 * wlan_hdd_set_akm_suite() - set key management type
11735 * @pAdapter: Pointer to adapter
11736 * @key_mgmt: Key management type
11737 *
11738 * This function is used to set the key mgmt type(PSK/8021x).
11739 *
11740 * Return: 0 for success, non-zero for failure
11741 */
11742static int wlan_hdd_set_akm_suite(hdd_adapter_t *pAdapter, u32 key_mgmt)
11743{
11744 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011746#define WLAN_AKM_SUITE_8021X_SHA256 0x000FAC05
11747#define WLAN_AKM_SUITE_PSK_SHA256 0x000FAC06
11748 /*set key mgmt type */
11749 switch (key_mgmt) {
11750 case WLAN_AKM_SUITE_PSK:
11751 case WLAN_AKM_SUITE_PSK_SHA256:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011752 case WLAN_AKM_SUITE_FT_PSK:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011753 hdd_notice("setting key mgmt type to PSK");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011754 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
11755 break;
11756
11757 case WLAN_AKM_SUITE_8021X_SHA256:
11758 case WLAN_AKM_SUITE_8021X:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011759 case WLAN_AKM_SUITE_FT_8021X:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011760 hdd_notice("setting key mgmt type to 8021x");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011761 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
11762 break;
11763#ifdef FEATURE_WLAN_ESE
11764#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
11765#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
11766 case WLAN_AKM_SUITE_CCKM:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011767 hdd_notice("setting key mgmt type to CCKM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011768 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
11769 break;
11770#endif
11771#ifndef WLAN_AKM_SUITE_OSEN
11772#define WLAN_AKM_SUITE_OSEN 0x506f9a01 /* Should be in ieee802_11_defs.h */
11773#endif
11774 case WLAN_AKM_SUITE_OSEN:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011775 hdd_notice("setting key mgmt type to OSEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011776 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
11777 break;
11778
11779 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011780 hdd_err("Unsupported key mgmt type %d", key_mgmt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011781 return -EINVAL;
11782
11783 }
11784 return 0;
11785}
11786
11787/**
11788 * wlan_hdd_cfg80211_set_cipher() - set encryption type
11789 * @pAdapter: Pointer to adapter
11790 * @cipher: Cipher type
11791 * @ucast: Unicast flag
11792 *
11793 * This function is used to set the encryption type
11794 * (NONE/WEP40/WEP104/TKIP/CCMP).
11795 *
11796 * Return: 0 for success, non-zero for failure
11797 */
11798static int wlan_hdd_cfg80211_set_cipher(hdd_adapter_t *pAdapter,
11799 u32 cipher, bool ucast)
11800{
11801 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
11802 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11803 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011805 if (!cipher) {
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -080011806 hdd_info("received cipher %d - considering none", cipher);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011807 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
11808 } else {
11809
11810 /*set encryption method */
11811 switch (cipher) {
11812 case IW_AUTH_CIPHER_NONE:
11813 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
11814 break;
11815
11816 case WLAN_CIPHER_SUITE_WEP40:
11817 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
11818 break;
11819
11820 case WLAN_CIPHER_SUITE_WEP104:
11821 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
11822 break;
11823
11824 case WLAN_CIPHER_SUITE_TKIP:
11825 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
11826 break;
11827
11828 case WLAN_CIPHER_SUITE_CCMP:
11829 encryptionType = eCSR_ENCRYPT_TYPE_AES;
11830 break;
11831#ifdef FEATURE_WLAN_WAPI
11832 case WLAN_CIPHER_SUITE_SMS4:
11833 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
11834 break;
11835#endif
11836
11837#ifdef FEATURE_WLAN_ESE
11838 case WLAN_CIPHER_SUITE_KRK:
11839 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
11840 break;
11841#ifdef WLAN_FEATURE_ROAM_OFFLOAD
11842 case WLAN_CIPHER_SUITE_BTK:
11843 encryptionType = eCSR_ENCRYPT_TYPE_BTK;
11844 break;
11845#endif
11846#endif
11847 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011848 hdd_err("Unsupported cipher type %d", cipher);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011849 return -EOPNOTSUPP;
11850 }
11851 }
11852
11853 if (ucast) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011854 hdd_notice("setting unicast cipher type to %d", encryptionType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011855 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
11856 pWextState->roamProfile.EncryptionType.numEntries = 1;
11857 pWextState->roamProfile.EncryptionType.encryptionType[0] =
11858 encryptionType;
11859 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011860 hdd_notice("setting mcast cipher type to %d", encryptionType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011861 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
11862 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
11863 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
11864 encryptionType;
11865 }
11866
11867 return 0;
11868}
11869
11870/**
Selvaraj, Sridhara7fc7632016-09-04 13:13:38 +053011871 * wlan_hdd_add_assoc_ie() - Add Assoc IE to roamProfile
11872 * @wext_state: Pointer to wext state
11873 * @gen_ie: Pointer to IE data
11874 * @len: length of IE data
11875 *
11876 * Return: 0 for success, non-zero for failure
11877 */
11878static int wlan_hdd_add_assoc_ie(hdd_wext_state_t *wext_state,
11879 const uint8_t *gen_ie, uint16_t len)
11880{
11881 uint16_t cur_add_ie_len =
11882 wext_state->assocAddIE.length;
11883
11884 if (SIR_MAC_MAX_ADD_IE_LENGTH <
11885 (wext_state->assocAddIE.length + len)) {
11886 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
11887 QDF_ASSERT(0);
11888 return -ENOMEM;
11889 }
11890 memcpy(wext_state->assocAddIE.addIEdata +
11891 cur_add_ie_len, gen_ie, len);
11892 wext_state->assocAddIE.length += len;
11893
11894 wext_state->roamProfile.pAddIEAssoc =
11895 wext_state->assocAddIE.addIEdata;
11896 wext_state->roamProfile.nAddIEAssocLength =
11897 wext_state->assocAddIE.length;
11898 return 0;
11899}
11900
11901/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011902 * wlan_hdd_cfg80211_set_ie() - set IEs
11903 * @pAdapter: Pointer to adapter
11904 * @ie: Pointer ot ie
11905 * @ie: IE length
11906 *
11907 * Return: 0 for success, non-zero for failure
11908 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070011909static int wlan_hdd_cfg80211_set_ie(hdd_adapter_t *pAdapter, const uint8_t *ie,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011910 size_t ie_len)
11911{
11912 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11913 const uint8_t *genie = ie;
11914 uint16_t remLen = ie_len;
11915#ifdef FEATURE_WLAN_WAPI
11916 uint32_t akmsuite[MAX_NUM_AKM_SUITES];
11917 u16 *tmp;
11918 uint16_t akmsuiteCount;
11919 int *akmlist;
11920#endif
Selvaraj, Sridhara7fc7632016-09-04 13:13:38 +053011921 int status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011922
11923 /* clear previous assocAddIE */
11924 pWextState->assocAddIE.length = 0;
11925 pWextState->roamProfile.bWPSAssociation = false;
11926 pWextState->roamProfile.bOSENAssociation = false;
11927
11928 while (remLen >= 2) {
11929 uint16_t eLen = 0;
11930 uint8_t elementId;
11931 elementId = *genie++;
11932 eLen = *genie++;
11933 remLen -= 2;
11934
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011935 hdd_notice("IE[0x%X], LEN[%d]", elementId, eLen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011936
11937 switch (elementId) {
11938 case DOT11F_EID_WPA:
11939 if (4 > eLen) { /* should have at least OUI which is 4 bytes so extra 2 bytes not needed */
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011940 hdd_err("Invalid WPA IE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011941 return -EINVAL;
11942 } else if (0 ==
11943 memcmp(&genie[0], "\x00\x50\xf2\x04", 4)) {
11944 uint16_t curAddIELen =
11945 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011946 hdd_notice("Set WPS IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011947
11948 if (SIR_MAC_MAX_ADD_IE_LENGTH <
11949 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011950 hdd_err("Cannot accommodate assocAddIE. Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053011951 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011952 return -ENOMEM;
11953 }
11954 /* WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE */
11955 memcpy(pWextState->assocAddIE.addIEdata +
11956 curAddIELen, genie - 2, eLen + 2);
11957 pWextState->assocAddIE.length += eLen + 2;
11958
11959 pWextState->roamProfile.bWPSAssociation = true;
11960 pWextState->roamProfile.pAddIEAssoc =
11961 pWextState->assocAddIE.addIEdata;
11962 pWextState->roamProfile.nAddIEAssocLength =
11963 pWextState->assocAddIE.length;
11964 } else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011965 hdd_notice("Set WPA IE (len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011966 memset(pWextState->WPARSNIE, 0,
11967 MAX_WPA_RSN_IE_LEN);
11968 memcpy(pWextState->WPARSNIE, genie - 2,
11969 (eLen + 2));
11970 pWextState->roamProfile.pWPAReqIE =
11971 pWextState->WPARSNIE;
11972 pWextState->roamProfile.nWPAReqIELength = eLen + 2; /* ie_len; */
11973 } else if ((0 == memcmp(&genie[0], P2P_OUI_TYPE,
11974 P2P_OUI_TYPE_SIZE))) {
11975 uint16_t curAddIELen =
11976 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011977 hdd_notice("Set P2P IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011978
11979 if (SIR_MAC_MAX_ADD_IE_LENGTH <
11980 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011981 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053011982 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011983 return -ENOMEM;
11984 }
11985 /* P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE */
11986 memcpy(pWextState->assocAddIE.addIEdata +
11987 curAddIELen, genie - 2, eLen + 2);
11988 pWextState->assocAddIE.length += eLen + 2;
11989
11990 pWextState->roamProfile.pAddIEAssoc =
11991 pWextState->assocAddIE.addIEdata;
11992 pWextState->roamProfile.nAddIEAssocLength =
11993 pWextState->assocAddIE.length;
11994 }
11995#ifdef WLAN_FEATURE_WFD
11996 else if ((0 == memcmp(&genie[0], WFD_OUI_TYPE,
11997 WFD_OUI_TYPE_SIZE)) &&
11998 /* Consider WFD IE, only for P2P Client */
Krunal Sonib4326f22016-03-10 13:05:51 -080011999 (QDF_P2P_CLIENT_MODE ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012000 pAdapter->device_mode)) {
12001 uint16_t curAddIELen =
12002 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012003 hdd_notice("Set WFD IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012004
12005 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12006 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012007 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012008 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012009 return -ENOMEM;
12010 }
12011 /* WFD IE is saved to Additional IE ; it should
12012 * be accumulated to handle WPS IE + P2P IE +
12013 * WFD IE */
12014 memcpy(pWextState->assocAddIE.addIEdata +
12015 curAddIELen, genie - 2, eLen + 2);
12016 pWextState->assocAddIE.length += eLen + 2;
12017
12018 pWextState->roamProfile.pAddIEAssoc =
12019 pWextState->assocAddIE.addIEdata;
12020 pWextState->roamProfile.nAddIEAssocLength =
12021 pWextState->assocAddIE.length;
12022 }
12023#endif
12024 /* Appending HS 2.0 Indication Element in Assiciation Request */
12025 else if ((0 == memcmp(&genie[0], HS20_OUI_TYPE,
12026 HS20_OUI_TYPE_SIZE))) {
12027 uint16_t curAddIELen =
12028 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012029 hdd_notice("Set HS20 IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012030
12031 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12032 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012033 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012034 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012035 return -ENOMEM;
12036 }
12037 memcpy(pWextState->assocAddIE.addIEdata +
12038 curAddIELen, genie - 2, eLen + 2);
12039 pWextState->assocAddIE.length += eLen + 2;
12040
12041 pWextState->roamProfile.pAddIEAssoc =
12042 pWextState->assocAddIE.addIEdata;
12043 pWextState->roamProfile.nAddIEAssocLength =
12044 pWextState->assocAddIE.length;
12045 }
12046 /* Appending OSEN Information Element in Assiciation Request */
12047 else if ((0 == memcmp(&genie[0], OSEN_OUI_TYPE,
12048 OSEN_OUI_TYPE_SIZE))) {
12049 uint16_t curAddIELen =
12050 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012051 hdd_notice("Set OSEN IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012052
12053 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12054 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012055 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012056 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012057 return -ENOMEM;
12058 }
12059 memcpy(pWextState->assocAddIE.addIEdata +
12060 curAddIELen, genie - 2, eLen + 2);
12061 pWextState->assocAddIE.length += eLen + 2;
12062
12063 pWextState->roamProfile.bOSENAssociation = true;
12064 pWextState->roamProfile.pAddIEAssoc =
12065 pWextState->assocAddIE.addIEdata;
12066 pWextState->roamProfile.nAddIEAssocLength =
12067 pWextState->assocAddIE.length;
Selvaraj, Sridhara7fc7632016-09-04 13:13:38 +053012068 } else if ((0 == memcmp(&genie[0], MBO_OUI_TYPE,
12069 MBO_OUI_TYPE_SIZE))){
12070 hdd_info("Set MBO IE(len %d)", eLen + 2);
12071 status = wlan_hdd_add_assoc_ie(pWextState,
12072 genie - 2, eLen + 2);
12073 if (status)
12074 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012075 } else {
12076 uint16_t add_ie_len =
12077 pWextState->assocAddIE.length;
12078
12079 hdd_info("Set OSEN IE(len %d)", eLen + 2);
12080
12081 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12082 (pWextState->assocAddIE.length + eLen)) {
12083 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012084 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012085 return -ENOMEM;
12086 }
12087
12088 memcpy(pWextState->assocAddIE.addIEdata +
12089 add_ie_len, genie - 2, eLen + 2);
12090 pWextState->assocAddIE.length += eLen + 2;
12091
12092 pWextState->roamProfile.pAddIEAssoc =
12093 pWextState->assocAddIE.addIEdata;
12094 pWextState->roamProfile.nAddIEAssocLength =
12095 pWextState->assocAddIE.length;
12096 }
12097 break;
12098 case DOT11F_EID_RSN:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012099 hdd_notice("Set RSN IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012100 memset(pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN);
12101 memcpy(pWextState->WPARSNIE, genie - 2,
12102 (eLen + 2));
12103 pWextState->roamProfile.pRSNReqIE =
12104 pWextState->WPARSNIE;
12105 pWextState->roamProfile.nRSNReqIELength = eLen + 2; /* ie_len; */
12106 break;
12107 /*
12108 * Appending Extended Capabilities with Interworking bit set
12109 * in Assoc Req.
12110 *
12111 * In assoc req this EXT Cap will only be taken into account if
12112 * interworkingService bit is set to 1. Currently
12113 * driver is only interested in interworkingService capability
12114 * from supplicant. If in future any other EXT Cap info is
12115 * required from supplicat, it needs to be handled while
12116 * sending Assoc Req in LIM.
12117 */
12118 case DOT11F_EID_EXTCAP:
12119 {
12120 uint16_t curAddIELen =
12121 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012122 hdd_notice("Set Extended CAPS IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012123
12124 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12125 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012126 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012127 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012128 return -ENOMEM;
12129 }
12130 memcpy(pWextState->assocAddIE.addIEdata +
12131 curAddIELen, genie - 2, eLen + 2);
12132 pWextState->assocAddIE.length += eLen + 2;
12133
12134 pWextState->roamProfile.pAddIEAssoc =
12135 pWextState->assocAddIE.addIEdata;
12136 pWextState->roamProfile.nAddIEAssocLength =
12137 pWextState->assocAddIE.length;
12138 break;
12139 }
12140#ifdef FEATURE_WLAN_WAPI
12141 case WLAN_EID_WAPI:
12142 /* Setting WAPI Mode to ON=1 */
12143 pAdapter->wapi_info.nWapiMode = 1;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012144 hdd_notice("WAPI MODE IS %u", pAdapter->wapi_info.nWapiMode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012145 tmp = (u16 *) ie;
12146 tmp = tmp + 2; /* Skip element Id and Len, Version */
12147 akmsuiteCount = WPA_GET_LE16(tmp);
12148 tmp = tmp + 1;
12149 akmlist = (int *)(tmp);
12150 if (akmsuiteCount <= MAX_NUM_AKM_SUITES) {
12151 memcpy(akmsuite, akmlist, (4 * akmsuiteCount));
12152 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012153 hdd_err("Invalid akmSuite count");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012154 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012155 return -EINVAL;
12156 }
12157
12158 if (WAPI_PSK_AKM_SUITE == akmsuite[0]) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012159 hdd_notice("WAPI AUTH MODE SET TO PSK");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012160 pAdapter->wapi_info.wapiAuthMode =
12161 WAPI_AUTH_MODE_PSK;
12162 }
12163 if (WAPI_CERT_AKM_SUITE == akmsuite[0]) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012164 hdd_notice("WAPI AUTH MODE SET TO CERTIFICATE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012165 pAdapter->wapi_info.wapiAuthMode =
12166 WAPI_AUTH_MODE_CERT;
12167 }
12168 break;
12169#endif
Selvaraj, Sridhara7fc7632016-09-04 13:13:38 +053012170 case DOT11F_EID_SUPPOPERATINGCLASSES:
12171 {
12172 hdd_info("Set Supported Operating Classes IE(len %d)", eLen + 2);
12173 status = wlan_hdd_add_assoc_ie(pWextState,
12174 genie - 2, eLen + 2);
12175 if (status)
12176 return status;
12177 break;
12178 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012179 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012180 hdd_err("Set UNKNOWN IE %X", elementId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012181 /* when Unknown IE is received we should break and continue
12182 * to the next IE in the buffer instead we were returning
12183 * so changing this to break */
12184 break;
12185 }
12186 genie += eLen;
12187 remLen -= eLen;
12188 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012189 return 0;
12190}
12191
12192/**
12193 * hdd_is_wpaie_present() - check for WPA ie
12194 * @ie: Pointer to ie
12195 * @ie_len: Ie length
12196 *
12197 * Parse the received IE to find the WPA IE
12198 *
12199 * Return: true if wpa ie is found else false
12200 */
12201static bool hdd_is_wpaie_present(const uint8_t *ie, uint8_t ie_len)
12202{
12203 uint8_t eLen = 0;
12204 uint16_t remLen = ie_len;
12205 uint8_t elementId = 0;
12206
12207 while (remLen >= 2) {
12208 elementId = *ie++;
12209 eLen = *ie++;
12210 remLen -= 2;
12211 if (eLen > remLen) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012212 hdd_err("IE length is wrong %d", eLen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012213 return false;
12214 }
12215 if ((elementId == DOT11F_EID_WPA) && (remLen > 5)) {
12216 /* OUI - 0x00 0X50 0XF2
12217 * WPA Information Element - 0x01
12218 * WPA version - 0x01
12219 */
12220 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
12221 return true;
12222 }
12223 ie += eLen;
12224 remLen -= eLen;
12225 }
12226 return false;
12227}
12228
12229/**
12230 * wlan_hdd_cfg80211_set_privacy() - set security parameters during connection
12231 * @pAdapter: Pointer to adapter
12232 * @req: Pointer to security parameters
12233 *
12234 * Return: 0 for success, non-zero for failure
12235 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070012236static int wlan_hdd_cfg80211_set_privacy(hdd_adapter_t *pAdapter,
12237 struct cfg80211_connect_params *req)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012238{
12239 int status = 0;
12240 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
12241 ENTER();
12242
12243 /*set wpa version */
12244 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
12245
12246 if (req->crypto.wpa_versions) {
12247 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions) {
12248 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
12249 } else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions) {
12250 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
12251 }
12252 }
12253
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012254 hdd_notice("set wpa version to %d", pWextState->wpaVersion);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012255
12256 /*set authentication type */
12257 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
12258
12259 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012260 hdd_err("failed to set authentication type ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012261 return status;
12262 }
12263
12264 /*set key mgmt type */
12265 if (req->crypto.n_akm_suites) {
12266 status =
12267 wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
12268 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012269 hdd_err("failed to set akm suite");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012270 return status;
12271 }
12272 }
12273
12274 /*set pairwise cipher type */
12275 if (req->crypto.n_ciphers_pairwise) {
12276 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
12277 req->crypto.
12278 ciphers_pairwise[0],
12279 true);
12280 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012281 hdd_err("failed to set unicast cipher type");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012282 return status;
12283 }
12284 } else {
12285 /*Reset previous cipher suite to none */
12286 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
12287 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012288 hdd_err("failed to set unicast cipher type");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012289 return status;
12290 }
12291 }
12292
12293 /*set group cipher type */
12294 status =
12295 wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
12296 false);
12297
12298 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012299 hdd_err("failed to set mcast cipher type");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012300 return status;
12301 }
12302#ifdef WLAN_FEATURE_11W
12303 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
12304#endif
12305
12306 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile */
12307 if (req->ie_len) {
12308 status =
12309 wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
12310 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012311 hdd_err("failed to parse the WPA/RSN IE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012312 return status;
12313 }
12314 }
12315
12316 /*incase of WEP set default key information */
12317 if (req->key && req->key_len) {
12318 if ((WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
12319 || (WLAN_CIPHER_SUITE_WEP104 ==
12320 req->crypto.ciphers_pairwise[0])
12321 ) {
12322 if (IW_AUTH_KEY_MGMT_802_1X
12323 ==
12324 (pWextState->
12325 authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012326 hdd_err("Dynamic WEP not supported");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012327 return -EOPNOTSUPP;
12328 } else {
12329 u8 key_len = req->key_len;
12330 u8 key_idx = req->key_idx;
12331
12332 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >=
12333 key_len)
12334 && (CSR_MAX_NUM_KEY > key_idx)
12335 ) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012336 hdd_notice("setting default wep key, key_idx = %hu key_len %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012337 key_idx, key_len);
Anurag Chouhan600c3a02016-03-01 10:33:54 +053012338 qdf_mem_copy(&pWextState->roamProfile.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012339 Keys.
12340 KeyMaterial[key_idx][0],
12341 req->key, key_len);
12342 pWextState->roamProfile.Keys.
12343 KeyLength[key_idx] = (u8) key_len;
12344 pWextState->roamProfile.Keys.
12345 defaultIndex = (u8) key_idx;
12346 }
12347 }
12348 }
12349 }
12350
12351 return status;
12352}
12353
12354/**
12355 * wlan_hdd_try_disconnect() - try disconnnect from previous connection
12356 * @pAdapter: Pointer to adapter
12357 *
12358 * This function is used to disconnect from previous connection
12359 *
12360 * Return: 0 for success, non-zero for failure
12361 */
12362static int wlan_hdd_try_disconnect(hdd_adapter_t *pAdapter)
12363{
12364 unsigned long rc;
12365 hdd_station_ctx_t *pHddStaCtx;
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012366 int status, result = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012367
12368 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
12369
Jeff Johnson9edf9572016-10-03 15:24:49 -070012370 if ((QDF_IBSS_MODE == pAdapter->device_mode) ||
Abhishek Singh03f992e2016-01-07 18:07:06 +053012371 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
12372 (eConnectionState_Connecting == pHddStaCtx->conn_info.connState) ||
12373 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012374 hdd_conn_set_connection_state(pAdapter,
12375 eConnectionState_Disconnecting);
12376 /* Issue disconnect to CSR */
12377 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012378
12379 status = sme_roam_disconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
12380 pAdapter->sessionId,
12381 eCSR_DISCONNECT_REASON_UNSPECIFIED);
12382 /*
12383 * Wait here instead of returning directly, this will block the
12384 * next connect command and allow processing of the scan for
12385 * ssid and the previous connect command in CSR. Else we might
12386 * hit some race conditions leading to SME and HDD out of sync.
12387 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012388 if (QDF_STATUS_CMD_NOT_QUEUED == status) {
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012389 hdd_info("Already disconnected or connect was in sme/roam pending list and removed by disconnect");
12390 } else if (0 != status) {
12391 hdd_err("csrRoamDisconnect failure, returned %d",
12392 (int)status);
12393 pHddStaCtx->staDebugState = status;
12394 result = -EINVAL;
12395 goto disconnected;
12396 }
12397
12398 rc = wait_for_completion_timeout(
12399 &pAdapter->disconnect_comp_var,
12400 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012401 if (!rc && (QDF_STATUS_CMD_NOT_QUEUED != status)) {
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012402 hdd_err("Sme disconnect event timed out session Id %d staDebugState %d",
12403 pAdapter->sessionId, pHddStaCtx->staDebugState);
12404 result = -ETIMEDOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012405 }
12406 } else if (eConnectionState_Disconnecting ==
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012407 pHddStaCtx->conn_info.connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012408 rc = wait_for_completion_timeout(&pAdapter->disconnect_comp_var,
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012409 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012410 if (!rc) {
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012411 hdd_err("Disconnect event timed out session Id %d staDebugState %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012412 pAdapter->sessionId, pHddStaCtx->staDebugState);
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012413 result = -ETIMEDOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012414 }
12415 }
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012416disconnected:
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012417 hdd_conn_set_connection_state(pAdapter, eConnectionState_NotConnected);
12418 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012419}
12420
12421/**
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012422 * wlan_hdd_reassoc_bssid_hint() - Start reassociation if bssid is present
12423 * @adapter: Pointer to the HDD adapter
12424 * @req: Pointer to the structure cfg_connect_params receieved from user space
Naveen Rawat07332902016-07-27 09:13:17 -070012425 * @status: out variable for status of reassoc request
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012426 *
Selvaraj, Sridhar353be2f2016-09-27 15:01:41 +053012427 * This function will start reassociation if prev_bssid is set and bssid/
12428 * bssid_hint, channel/channel_hint parameters are present in connect request.
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012429 *
Naveen Rawat07332902016-07-27 09:13:17 -070012430 * Return: true if connect was for ReAssociation, false otherwise
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012431 */
Selvaraj, Sridhara11edcb2016-09-07 18:49:14 +053012432#if defined(CFG80211_CONNECT_PREV_BSSID) || \
12433 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
Naveen Rawat07332902016-07-27 09:13:17 -070012434static bool wlan_hdd_reassoc_bssid_hint(hdd_adapter_t *adapter,
12435 struct cfg80211_connect_params *req,
12436 int *status)
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012437{
Naveen Rawat07332902016-07-27 09:13:17 -070012438 bool reassoc = false;
Selvaraj, Sridhar353be2f2016-09-27 15:01:41 +053012439 const uint8_t *bssid = NULL;
12440 uint16_t channel = 0;
12441
12442 if (req->bssid)
12443 bssid = req->bssid;
12444 else if (req->bssid_hint)
12445 bssid = req->bssid_hint;
12446
12447 if (req->channel)
12448 channel = req->channel->hw_value;
12449 else if (req->channel_hint)
12450 channel = req->channel_hint->hw_value;
12451
12452 if (bssid && channel && req->prev_bssid) {
Naveen Rawat07332902016-07-27 09:13:17 -070012453 reassoc = true;
12454 hdd_info(FL("REASSOC Attempt on channel %d to "MAC_ADDRESS_STR),
Selvaraj, Sridhar353be2f2016-09-27 15:01:41 +053012455 channel, MAC_ADDR_ARRAY(bssid));
12456 *status = hdd_reassoc(adapter, bssid, channel,
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012457 CONNECT_CMD_USERSPACE);
Naveen Rawat07332902016-07-27 09:13:17 -070012458 hdd_debug("hdd_reassoc: status: %d", *status);
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012459 }
Naveen Rawat07332902016-07-27 09:13:17 -070012460 return reassoc;
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012461}
12462#else
Naveen Rawat07332902016-07-27 09:13:17 -070012463static bool wlan_hdd_reassoc_bssid_hint(hdd_adapter_t *adapter,
12464 struct cfg80211_connect_params *req,
12465 int *status)
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012466{
Naveen Rawat07332902016-07-27 09:13:17 -070012467 return false;
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012468}
12469#endif
12470
12471/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012472 * __wlan_hdd_cfg80211_connect() - cfg80211 connect api
12473 * @wiphy: Pointer to wiphy
12474 * @dev: Pointer to network device
12475 * @req: Pointer to cfg80211 connect request
12476 *
12477 * This function is used to start the association process
12478 *
12479 * Return: 0 for success, non-zero for failure
12480 */
12481static int __wlan_hdd_cfg80211_connect(struct wiphy *wiphy,
12482 struct net_device *ndev,
12483 struct cfg80211_connect_params *req)
12484{
12485 int status;
Sreelakshmi Konamki6bd8a2e2015-11-03 16:30:32 +053012486 u16 channel;
12487#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
12488 const u8 *bssid_hint = req->bssid_hint;
12489#else
12490 const u8 *bssid_hint = NULL;
12491#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012492 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
12493 hdd_context_t *pHddCtx;
12494
12495 ENTER();
12496
Anurag Chouhan6d760662016-02-20 16:05:43 +053012497 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012498 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012499 return -EINVAL;
12500 }
12501
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053012502 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
12503 hdd_err("invalid session id: %d", pAdapter->sessionId);
12504 return -EINVAL;
12505 }
12506
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012507 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012508 TRACE_CODE_HDD_CFG80211_CONNECT,
12509 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012510 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012511 hdd_device_mode_to_string(pAdapter->device_mode),
12512 pAdapter->device_mode);
12513
Krunal Sonib4326f22016-03-10 13:05:51 -080012514 if (pAdapter->device_mode != QDF_STA_MODE &&
12515 pAdapter->device_mode != QDF_P2P_CLIENT_MODE) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012516 hdd_err("Device_mode %s(%d) is not supported",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012517 hdd_device_mode_to_string(pAdapter->device_mode),
12518 pAdapter->device_mode);
12519 return -EINVAL;
12520 }
12521
12522 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
12523 if (!pHddCtx) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012524 hdd_err("HDD context is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012525 return -EINVAL;
12526 }
12527
12528 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053012529 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012530 return status;
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012531
Naveen Rawat07332902016-07-27 09:13:17 -070012532 if (true == wlan_hdd_reassoc_bssid_hint(pAdapter, req, &status))
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012533 return status;
12534
Agrawal Ashishf156e942016-08-04 14:54:47 +053012535 wlan_hdd_disable_roaming(pAdapter);
12536
12537 /* Try disconnecting if already in connected state */
12538 status = wlan_hdd_try_disconnect(pAdapter);
12539 if (0 > status) {
12540 hdd_err("Failed to disconnect the existing connection");
12541 return -EALREADY;
12542 }
12543
12544 /* Check for max concurrent connections after doing disconnect if any */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012545 if (req->channel) {
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080012546 if (!cds_allow_concurrency(
Krunal Sonib4326f22016-03-10 13:05:51 -080012547 cds_convert_device_mode_to_qdf_type(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012548 pAdapter->device_mode),
12549 req->channel->hw_value, HW_MODE_20_MHZ)) {
12550 hdd_err("This concurrency combination is not allowed");
12551 return -ECONNREFUSED;
12552 }
12553 } else {
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080012554 if (!cds_allow_concurrency(
Krunal Sonib4326f22016-03-10 13:05:51 -080012555 cds_convert_device_mode_to_qdf_type(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012556 pAdapter->device_mode), 0, HW_MODE_20_MHZ)) {
12557 hdd_err("This concurrency combination is not allowed");
12558 return -ECONNREFUSED;
12559 }
12560 }
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012561
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012562 /*initialise security parameters */
12563 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
12564
12565 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012566 hdd_err("failed to set security params");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012567 return status;
12568 }
12569
Sreelakshmi Konamki6bd8a2e2015-11-03 16:30:32 +053012570 if (req->channel)
12571 channel = req->channel->hw_value;
12572 else
12573 channel = 0;
12574 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
12575 req->ssid_len, req->bssid,
Naveen Rawatc77e6e72016-08-05 15:19:03 -070012576 bssid_hint, channel, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012577 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012578 hdd_err("connect failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012579 return status;
12580 }
12581 EXIT();
12582 return status;
12583}
12584
12585/**
12586 * wlan_hdd_cfg80211_connect() - cfg80211 connect api
12587 * @wiphy: Pointer to wiphy
12588 * @dev: Pointer to network device
12589 * @req: Pointer to cfg80211 connect request
12590 *
12591 * Return: 0 for success, non-zero for failure
12592 */
12593static int wlan_hdd_cfg80211_connect(struct wiphy *wiphy,
12594 struct net_device *ndev,
12595 struct cfg80211_connect_params *req)
12596{
12597 int ret;
12598 cds_ssr_protect(__func__);
12599 ret = __wlan_hdd_cfg80211_connect(wiphy, ndev, req);
12600 cds_ssr_unprotect(__func__);
12601
12602 return ret;
12603}
12604
12605/**
12606 * wlan_hdd_disconnect() - hdd disconnect api
12607 * @pAdapter: Pointer to adapter
12608 * @reason: Disconnect reason code
12609 *
12610 * This function is used to issue a disconnect request to SME
12611 *
12612 * Return: 0 for success, non-zero for failure
12613 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070012614static int wlan_hdd_disconnect(hdd_adapter_t *pAdapter, u16 reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012615{
12616 int status, result = 0;
12617 unsigned long rc;
12618 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
12619 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
12620
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053012621 ENTER();
12622
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012623 status = wlan_hdd_validate_context(pHddCtx);
12624
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053012625 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012626 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012627
12628 /*stop tx queues */
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012629 hdd_notice("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012630 wlan_hdd_netif_queue_control(pAdapter, WLAN_NETIF_TX_DISABLE_N_CARRIER,
12631 WLAN_CONTROL_PATH);
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012632 hdd_notice("Set HDD connState to eConnectionState_Disconnecting");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012633 pHddStaCtx->conn_info.connState = eConnectionState_Disconnecting;
12634 INIT_COMPLETION(pAdapter->disconnect_comp_var);
12635
12636 /*issue disconnect */
12637
12638 status = sme_roam_disconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
12639 pAdapter->sessionId, reason);
Abhishek Singhacfdc922015-12-30 17:31:21 +053012640 /*
12641 * Wait here instead of returning directly, this will block the next
12642 * connect command and allow processing of the scan for ssid and
12643 * the previous connect command in CSR. Else we might hit some
12644 * race conditions leading to SME and HDD out of sync.
12645 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012646 if (QDF_STATUS_CMD_NOT_QUEUED == status) {
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012647 hdd_info("Already disconnected or connect was in sme/roam pending list and removed by disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012648 } else if (0 != status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012649 hdd_err("csr_roam_disconnect failure, returned %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012650 (int)status);
12651 pHddStaCtx->staDebugState = status;
12652 result = -EINVAL;
12653 goto disconnected;
12654 }
12655 rc = wait_for_completion_timeout(&pAdapter->disconnect_comp_var,
12656 msecs_to_jiffies
12657 (WLAN_WAIT_TIME_DISCONNECT));
12658
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012659 if (!rc && (QDF_STATUS_CMD_NOT_QUEUED != status)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012660 hdd_err("Failed to disconnect, timed out");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012661 result = -ETIMEDOUT;
12662 }
12663disconnected:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012664 hdd_conn_set_connection_state(pAdapter, eConnectionState_NotConnected);
12665#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)
12666 /* Sending disconnect event to userspace for kernel version < 3.11
12667 * is handled by __cfg80211_disconnect call to __cfg80211_disconnected
12668 */
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012669 hdd_notice("Send disconnected event to userspace");
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +053012670 wlan_hdd_cfg80211_indicate_disconnect(pAdapter->dev, true,
12671 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012672#endif
12673
12674 return result;
12675}
12676
12677/**
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -080012678 * hdd_ieee80211_reason_code_to_str() - return string conversion of reason code
12679 * @reason: ieee80211 reason code.
12680 *
12681 * This utility function helps log string conversion of reason code.
12682 *
12683 * Return: string conversion of reason code, if match found;
12684 * "Unknown" otherwise.
12685 */
12686static const char *hdd_ieee80211_reason_code_to_str(uint16_t reason)
12687{
12688 switch (reason) {
12689 CASE_RETURN_STRING(WLAN_REASON_UNSPECIFIED);
12690 CASE_RETURN_STRING(WLAN_REASON_PREV_AUTH_NOT_VALID);
12691 CASE_RETURN_STRING(WLAN_REASON_DEAUTH_LEAVING);
12692 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
12693 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_AP_BUSY);
12694 CASE_RETURN_STRING(WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
12695 CASE_RETURN_STRING(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
12696 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_STA_HAS_LEFT);
12697 CASE_RETURN_STRING(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
12698 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_BAD_POWER);
12699 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_BAD_SUPP_CHAN);
12700 CASE_RETURN_STRING(WLAN_REASON_INVALID_IE);
12701 CASE_RETURN_STRING(WLAN_REASON_MIC_FAILURE);
12702 CASE_RETURN_STRING(WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT);
12703 CASE_RETURN_STRING(WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT);
12704 CASE_RETURN_STRING(WLAN_REASON_IE_DIFFERENT);
12705 CASE_RETURN_STRING(WLAN_REASON_INVALID_GROUP_CIPHER);
12706 CASE_RETURN_STRING(WLAN_REASON_INVALID_PAIRWISE_CIPHER);
12707 CASE_RETURN_STRING(WLAN_REASON_INVALID_AKMP);
12708 CASE_RETURN_STRING(WLAN_REASON_UNSUPP_RSN_VERSION);
12709 CASE_RETURN_STRING(WLAN_REASON_INVALID_RSN_IE_CAP);
12710 CASE_RETURN_STRING(WLAN_REASON_IEEE8021X_FAILED);
12711 CASE_RETURN_STRING(WLAN_REASON_CIPHER_SUITE_REJECTED);
12712 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_UNSPECIFIED_QOS);
12713 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH);
12714 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_LOW_ACK);
12715 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP);
12716 CASE_RETURN_STRING(WLAN_REASON_QSTA_LEAVE_QBSS);
12717 CASE_RETURN_STRING(WLAN_REASON_QSTA_NOT_USE);
12718 CASE_RETURN_STRING(WLAN_REASON_QSTA_REQUIRE_SETUP);
12719 CASE_RETURN_STRING(WLAN_REASON_QSTA_TIMEOUT);
12720 CASE_RETURN_STRING(WLAN_REASON_QSTA_CIPHER_NOT_SUPP);
12721 CASE_RETURN_STRING(WLAN_REASON_MESH_PEER_CANCELED);
12722 CASE_RETURN_STRING(WLAN_REASON_MESH_MAX_PEERS);
12723 CASE_RETURN_STRING(WLAN_REASON_MESH_CONFIG);
12724 CASE_RETURN_STRING(WLAN_REASON_MESH_CLOSE);
12725 CASE_RETURN_STRING(WLAN_REASON_MESH_MAX_RETRIES);
12726 CASE_RETURN_STRING(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
12727 CASE_RETURN_STRING(WLAN_REASON_MESH_INVALID_GTK);
12728 CASE_RETURN_STRING(WLAN_REASON_MESH_INCONSISTENT_PARAM);
12729 CASE_RETURN_STRING(WLAN_REASON_MESH_INVALID_SECURITY);
12730 CASE_RETURN_STRING(WLAN_REASON_MESH_PATH_ERROR);
12731 CASE_RETURN_STRING(WLAN_REASON_MESH_PATH_NOFORWARD);
12732 CASE_RETURN_STRING(WLAN_REASON_MESH_PATH_DEST_UNREACHABLE);
12733 CASE_RETURN_STRING(WLAN_REASON_MAC_EXISTS_IN_MBSS);
12734 CASE_RETURN_STRING(WLAN_REASON_MESH_CHAN_REGULATORY);
12735 CASE_RETURN_STRING(WLAN_REASON_MESH_CHAN);
12736 default:
12737 return "Unknown";
12738 }
12739}
12740
12741/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012742 * __wlan_hdd_cfg80211_disconnect() - cfg80211 disconnect api
12743 * @wiphy: Pointer to wiphy
12744 * @dev: Pointer to network device
12745 * @reason: Disconnect reason code
12746 *
12747 * This function is used to issue a disconnect request to SME
12748 *
12749 * Return: 0 for success, non-zero for failure
12750 */
12751static int __wlan_hdd_cfg80211_disconnect(struct wiphy *wiphy,
12752 struct net_device *dev, u16 reason)
12753{
12754 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
12755 int status;
12756 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
12757 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
12758#ifdef FEATURE_WLAN_TDLS
12759 uint8_t staIdx;
12760#endif
12761
12762 ENTER();
12763
Anurag Chouhan6d760662016-02-20 16:05:43 +053012764 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012765 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012766 return -EINVAL;
12767 }
12768
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053012769 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
12770 hdd_err("invalid session id: %d", pAdapter->sessionId);
12771 return -EINVAL;
12772 }
12773
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012774 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012775 TRACE_CODE_HDD_CFG80211_DISCONNECT,
12776 pAdapter->sessionId, reason));
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012777 hdd_notice("Device_mode %s(%d) reason code(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012778 hdd_device_mode_to_string(pAdapter->device_mode),
12779 pAdapter->device_mode, reason);
12780
12781 status = wlan_hdd_validate_context(pHddCtx);
12782
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053012783 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012784 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012785
12786 /* Issue disconnect request to SME, if station is in connected state */
12787 if ((pHddStaCtx->conn_info.connState == eConnectionState_Associated) ||
12788 (pHddStaCtx->conn_info.connState == eConnectionState_Connecting)) {
12789 eCsrRoamDisconnectReason reasonCode =
12790 eCSR_DISCONNECT_REASON_UNSPECIFIED;
12791 hdd_scaninfo_t *pScanInfo;
12792
12793 switch (reason) {
12794 case WLAN_REASON_MIC_FAILURE:
12795 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
12796 break;
12797
12798 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
12799 case WLAN_REASON_DISASSOC_AP_BUSY:
12800 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
12801 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
12802 break;
12803
12804 case WLAN_REASON_PREV_AUTH_NOT_VALID:
12805 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
12806 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
12807 break;
12808
12809 case WLAN_REASON_DEAUTH_LEAVING:
12810 reasonCode =
12811 pHddCtx->config->
12812 gEnableDeauthToDisassocMap ?
12813 eCSR_DISCONNECT_REASON_STA_HAS_LEFT :
12814 eCSR_DISCONNECT_REASON_DEAUTH;
12815 break;
12816 case WLAN_REASON_DISASSOC_STA_HAS_LEFT:
12817 reasonCode = eCSR_DISCONNECT_REASON_STA_HAS_LEFT;
12818 break;
12819 default:
12820 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
12821 break;
12822 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012823 hdd_notice("convert to internal reason %d to reasonCode %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012824 reason, reasonCode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012825 pScanInfo = &pAdapter->scan_info;
12826 if (pScanInfo->mScanPending) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012827 hdd_notice("Disconnect is in progress, Aborting Scan");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012828 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId,
12829 eCSR_SCAN_ABORT_DEFAULT);
12830 }
Edhar, Mahesh Kumar732f6982016-07-01 11:23:06 +053012831 wlan_hdd_cleanup_remain_on_channel_ctx(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012832#ifdef FEATURE_WLAN_TDLS
12833 /* First clean up the tdls peers if any */
12834 for (staIdx = 0; staIdx < pHddCtx->max_num_tdls_sta; staIdx++) {
12835 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId ==
12836 pAdapter->sessionId)
12837 && (pHddCtx->tdlsConnInfo[staIdx].staId)) {
12838 uint8_t *mac;
12839 mac =
12840 pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012841 hdd_notice("call sme_delete_tdls_peer_sta staId %d sessionId %d "
12842 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012843 pHddCtx->tdlsConnInfo[staIdx].staId,
12844 pAdapter->sessionId,
12845 MAC_ADDR_ARRAY(mac));
12846 sme_delete_tdls_peer_sta(WLAN_HDD_GET_HAL_CTX
12847 (pAdapter),
12848 pAdapter->sessionId, mac);
12849 }
12850 }
12851#endif
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012852 hdd_notice("Disconnecting with reasoncode:%u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012853 reasonCode);
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -080012854 hdd_info("Disconnect request from user space with reason: %s",
12855 hdd_ieee80211_reason_code_to_str(reason));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012856 status = wlan_hdd_disconnect(pAdapter, reasonCode);
12857 if (0 != status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012858 hdd_err("failure, returned %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012859 return -EINVAL;
12860 }
12861 } else {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012862 hdd_err("unexpected cfg disconnect called while in state (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012863 pHddStaCtx->conn_info.connState);
12864 }
12865
12866 return status;
12867}
12868
12869/**
12870 * wlan_hdd_cfg80211_disconnect() - cfg80211 disconnect api
12871 * @wiphy: Pointer to wiphy
12872 * @dev: Pointer to network device
12873 * @reason: Disconnect reason code
12874 *
12875 * Return: 0 for success, non-zero for failure
12876 */
12877static int wlan_hdd_cfg80211_disconnect(struct wiphy *wiphy,
12878 struct net_device *dev, u16 reason)
12879{
12880 int ret;
12881 cds_ssr_protect(__func__);
12882 ret = __wlan_hdd_cfg80211_disconnect(wiphy, dev, reason);
12883 cds_ssr_unprotect(__func__);
12884
12885 return ret;
12886}
12887
12888/**
12889 * wlan_hdd_cfg80211_set_privacy_ibss() - set ibss privacy
12890 * @pAdapter: Pointer to adapter
12891 * @param: Pointer to IBSS parameters
12892 *
12893 * This function is used to initialize the security settings in IBSS mode
12894 *
12895 * Return: 0 for success, non-zero for failure
12896 */
12897static int wlan_hdd_cfg80211_set_privacy_ibss(hdd_adapter_t *pAdapter,
12898 struct cfg80211_ibss_params
12899 *params)
12900{
12901 int status = 0;
12902 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
12903 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
12904 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
12905
12906 ENTER();
12907
12908 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053012909 qdf_mem_zero(&pHddStaCtx->ibss_enc_key, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012910 pHddStaCtx->ibss_enc_key_installed = 0;
12911
12912 if (params->ie_len && (NULL != params->ie)) {
12913 if (wlan_hdd_cfg80211_get_ie_ptr(params->ie,
12914 params->ie_len, WLAN_EID_RSN)) {
12915 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
12916 encryptionType = eCSR_ENCRYPT_TYPE_AES;
12917 } else if (hdd_is_wpaie_present(params->ie, params->ie_len)) {
12918 tDot11fIEWPA dot11WPAIE;
12919 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
12920 u8 *ie;
12921
12922 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
12923 ie = wlan_hdd_cfg80211_get_ie_ptr(params->ie,
12924 params->ie_len,
12925 DOT11F_EID_WPA);
12926 if (NULL != ie) {
12927 pWextState->wpaVersion =
12928 IW_AUTH_WPA_VERSION_WPA;
12929 /* Unpack the WPA IE */
12930 /* Skip past the EID byte and length byte - and four byte WiFi OUI */
12931 dot11f_unpack_ie_wpa((tpAniSirGlobal) halHandle,
12932 &ie[2 + 4],
12933 ie[1] - 4, &dot11WPAIE);
12934 /*Extract the multicast cipher, the encType for unicast
12935 cipher for wpa-none is none */
12936 encryptionType =
12937 hdd_translate_wpa_to_csr_encryption_type
12938 (dot11WPAIE.multicast_cipher);
12939 }
12940 }
12941
12942 status =
12943 wlan_hdd_cfg80211_set_ie(pAdapter, params->ie,
12944 params->ie_len);
12945
12946 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012947 hdd_err("failed to parse WPA/RSN IE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012948 return status;
12949 }
12950 }
12951
12952 pWextState->roamProfile.AuthType.authType[0] =
12953 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
12954
12955 if (params->privacy) {
12956 /* Security enabled IBSS, At this time there is no information
12957 * available about the security paramters, so initialise the
12958 * encryption type to eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
12959 * The correct security parameters will be updated later in
12960 * wlan_hdd_cfg80211_add_key Hal expects encryption type to be
12961 * set inorder enable privacy bit in beacons
12962 */
12963
12964 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
12965 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012966 hdd_info("encryptionType=%d", encryptionType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012967 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
12968 pWextState->roamProfile.EncryptionType.numEntries = 1;
12969 pWextState->roamProfile.EncryptionType.encryptionType[0] =
12970 encryptionType;
12971 return status;
12972}
12973
12974/**
12975 * __wlan_hdd_cfg80211_join_ibss() - join ibss
12976 * @wiphy: Pointer to wiphy
12977 * @dev: Pointer to network device
12978 * @param: Pointer to IBSS join parameters
12979 *
12980 * This function is used to create/join an IBSS network
12981 *
12982 * Return: 0 for success, non-zero for failure
12983 */
12984static int __wlan_hdd_cfg80211_join_ibss(struct wiphy *wiphy,
12985 struct net_device *dev,
12986 struct cfg80211_ibss_params *params)
12987{
12988 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
12989 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
12990 tCsrRoamProfile *pRoamProfile;
12991 int status;
12992 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
12993 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Anurag Chouhan6d760662016-02-20 16:05:43 +053012994 struct qdf_mac_addr bssid;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012995 u8 channelNum = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012996
12997 ENTER();
12998
Anurag Chouhan6d760662016-02-20 16:05:43 +053012999 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013000 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013001 return -EINVAL;
13002 }
13003
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013004 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13005 hdd_err("invalid session id: %d", pAdapter->sessionId);
13006 return -EINVAL;
13007 }
13008
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013009 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013010 TRACE_CODE_HDD_CFG80211_JOIN_IBSS,
13011 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013012 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013013 hdd_device_mode_to_string(pAdapter->device_mode),
13014 pAdapter->device_mode);
13015
13016 status = wlan_hdd_validate_context(pHddCtx);
13017
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013018 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013019 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013020
13021 if (NULL !=
Anurag Chouhance0dc992016-02-16 18:18:03 +053013022 params->chandef.chan) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013023 uint32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
13024 uint8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
13025 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
13026 int indx;
13027
13028 /* Get channel number */
13029 channelNum = ieee80211_frequency_to_channel(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013030 params->
13031 chandef.
13032 chan->
13033 center_freq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013034
13035 if (0 != sme_cfg_get_str(hHal, WNI_CFG_VALID_CHANNEL_LIST,
13036 validChan, &numChans)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013037 hdd_err("No valid channel list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013038 return -EOPNOTSUPP;
13039 }
13040
13041 for (indx = 0; indx < numChans; indx++) {
13042 if (channelNum == validChan[indx]) {
13043 break;
13044 }
13045 }
13046 if (indx >= numChans) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013047 hdd_err("Not valid Channel %d", channelNum);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013048 return -EINVAL;
13049 }
13050 }
13051
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080013052 if (!cds_allow_concurrency(CDS_IBSS_MODE, channelNum,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013053 HW_MODE_20_MHZ)) {
13054 hdd_err("This concurrency combination is not allowed");
13055 return -ECONNREFUSED;
13056 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013057
Krunal Soni3091bcc2016-06-23 12:28:21 -070013058 status = qdf_reset_connection_update();
13059 if (!QDF_IS_STATUS_SUCCESS(status))
13060 hdd_err("ERR: clear event failed");
13061
13062 status = cds_current_connections_update(pAdapter->sessionId,
13063 channelNum,
13064 SIR_UPDATE_REASON_JOIN_IBSS);
13065 if (QDF_STATUS_E_FAILURE == status) {
13066 hdd_err("ERROR: connections update failed!!");
13067 return -EINVAL;
13068 }
13069
13070 if (QDF_STATUS_SUCCESS == status) {
13071 status = qdf_wait_for_connection_update();
13072 if (!QDF_IS_STATUS_SUCCESS(status)) {
13073 hdd_err("ERROR: qdf wait for event failed!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013074 return -EINVAL;
13075 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013076 }
13077
13078 /*Try disconnecting if already in connected state */
13079 status = wlan_hdd_try_disconnect(pAdapter);
13080 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013081 hdd_err("Failed to disconnect the existing IBSS connection");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013082 return -EALREADY;
13083 }
13084
13085 pRoamProfile = &pWextState->roamProfile;
13086
13087 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013088 hdd_err("Interface type is not set to IBSS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013089 return -EINVAL;
13090 }
13091
13092 /* enable selected protection checks in IBSS mode */
13093 pRoamProfile->cfg_protection = IBSS_CFG_PROTECTION_ENABLE_MASK;
13094
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013095 if (QDF_STATUS_E_FAILURE == sme_cfg_set_int(pHddCtx->hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013096 WNI_CFG_IBSS_ATIM_WIN_SIZE,
13097 pHddCtx->config->
13098 ibssATIMWinSize)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013099 hdd_err("Could not pass on WNI_CFG_IBSS_ATIM_WIN_SIZE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013100 }
13101
13102 /* BSSID is provided by upper layers hence no need to AUTO generate */
13103 if (NULL != params->bssid) {
13104 if (sme_cfg_set_int(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013105 == QDF_STATUS_E_FAILURE) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013106 hdd_err("ccmCfgStInt failed for WNI_CFG_IBSS_AUTO_BSSID");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013107 return -EIO;
13108 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +053013109 qdf_mem_copy(bssid.bytes, params->bssid, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013110 } else if (pHddCtx->config->isCoalesingInIBSSAllowed == 0) {
13111 if (sme_cfg_set_int(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013112 == QDF_STATUS_E_FAILURE) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013113 hdd_err("ccmCfgStInt failed for WNI_CFG_IBSS_AUTO_BSSID");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013114 return -EIO;
13115 }
Anurag Chouhanc5548422016-02-24 18:33:27 +053013116 qdf_copy_macaddr(&bssid, &pHddCtx->config->IbssBssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013117 }
13118 if ((params->beacon_interval > CFG_BEACON_INTERVAL_MIN)
13119 && (params->beacon_interval <= CFG_BEACON_INTERVAL_MAX))
13120 pRoamProfile->beaconInterval = params->beacon_interval;
13121 else {
13122 pRoamProfile->beaconInterval = CFG_BEACON_INTERVAL_DEFAULT;
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013123 hdd_info("input beacon interval %d TU is invalid, use default %d TU",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013124 params->beacon_interval, pRoamProfile->beaconInterval);
13125 }
13126
13127 /* Set Channel */
13128 if (channelNum) {
13129 /* Set the Operational Channel */
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013130 hdd_info("set channel %d", channelNum);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013131 pRoamProfile->ChannelInfo.numOfChannels = 1;
13132 pHddStaCtx->conn_info.operationChannel = channelNum;
13133 pRoamProfile->ChannelInfo.ChannelList =
13134 &pHddStaCtx->conn_info.operationChannel;
13135 }
13136
13137 /* Initialize security parameters */
13138 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
13139 if (status < 0) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013140 hdd_err("failed to set security parameters");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013141 return status;
13142 }
13143
13144 /* Issue connect start */
13145 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
13146 params->ssid_len,
Naveen Rawatc77e6e72016-08-05 15:19:03 -070013147 bssid.bytes, NULL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013148 pHddStaCtx->conn_info.
Naveen Rawatc77e6e72016-08-05 15:19:03 -070013149 operationChannel,
13150 params->chandef.width);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013151
13152 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013153 hdd_err("connect failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013154 return status;
13155 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013156 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013157 return 0;
13158}
13159
13160/**
13161 * wlan_hdd_cfg80211_join_ibss() - join ibss
13162 * @wiphy: Pointer to wiphy
13163 * @dev: Pointer to network device
13164 * @param: Pointer to IBSS join parameters
13165 *
13166 * This function is used to create/join an IBSS network
13167 *
13168 * Return: 0 for success, non-zero for failure
13169 */
13170static int wlan_hdd_cfg80211_join_ibss(struct wiphy *wiphy,
13171 struct net_device *dev,
13172 struct cfg80211_ibss_params *params)
13173{
13174 int ret = 0;
13175
13176 cds_ssr_protect(__func__);
13177 ret = __wlan_hdd_cfg80211_join_ibss(wiphy, dev, params);
13178 cds_ssr_unprotect(__func__);
13179
13180 return ret;
13181}
13182
13183/**
13184 * __wlan_hdd_cfg80211_leave_ibss() - leave ibss
13185 * @wiphy: Pointer to wiphy
13186 * @dev: Pointer to network device
13187 *
13188 * This function is used to leave an IBSS network
13189 *
13190 * Return: 0 for success, non-zero for failure
13191 */
13192static int __wlan_hdd_cfg80211_leave_ibss(struct wiphy *wiphy,
13193 struct net_device *dev)
13194{
13195 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13196 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
13197 tCsrRoamProfile *pRoamProfile;
13198 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
13199 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013200 QDF_STATUS hal_status;
Chandrasekaran, Manishekar12a818a2015-12-18 11:44:56 +053013201 unsigned long rc;
Rajeev Kumar8e3e2832015-11-06 16:02:54 -080013202 tSirUpdateIE updateIE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013203
13204 ENTER();
13205
Anurag Chouhan6d760662016-02-20 16:05:43 +053013206 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013207 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013208 return -EINVAL;
13209 }
13210
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013211 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13212 hdd_err("invalid session id: %d", pAdapter->sessionId);
13213 return -EINVAL;
13214 }
13215
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013216 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013217 TRACE_CODE_HDD_CFG80211_LEAVE_IBSS,
13218 pAdapter->sessionId,
13219 eCSR_DISCONNECT_REASON_IBSS_LEAVE));
13220 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013221 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013222 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013223
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013224 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013225 hdd_device_mode_to_string(pAdapter->device_mode),
13226 pAdapter->device_mode);
13227 if (NULL == pWextState) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013228 hdd_err("Data Storage Corruption");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013229 return -EIO;
13230 }
13231
13232 pRoamProfile = &pWextState->roamProfile;
13233
13234 /* Issue disconnect only if interface type is set to IBSS */
13235 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013236 hdd_err("BSS Type is not set to IBSS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013237 return -EINVAL;
13238 }
Rajeev Kumar8e3e2832015-11-06 16:02:54 -080013239 /* Clearing add IE of beacon */
13240 qdf_mem_copy(updateIE.bssid.bytes, pAdapter->macAddressCurrent.bytes,
13241 sizeof(tSirMacAddr));
13242 updateIE.smeSessionId = pAdapter->sessionId;
13243 updateIE.ieBufferlength = 0;
13244 updateIE.pAdditionIEBuffer = NULL;
13245 updateIE.append = true;
13246 updateIE.notify = true;
13247 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pAdapter),
13248 &updateIE,
13249 eUPDATE_IE_PROBE_BCN) == QDF_STATUS_E_FAILURE) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013250 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -080013251 }
13252
13253 /* Reset WNI_CFG_PROBE_RSP Flags */
13254 wlan_hdd_reset_prob_rspies(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013255
13256 /* Issue Disconnect request */
13257 INIT_COMPLETION(pAdapter->disconnect_comp_var);
13258 hal_status = sme_roam_disconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
13259 pAdapter->sessionId,
13260 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013261 if (!QDF_IS_STATUS_SUCCESS(hal_status)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013262 hdd_err("sme_roam_disconnect failed hal_status(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013263 hal_status);
13264 return -EAGAIN;
13265 }
Chandrasekaran, Manishekar12a818a2015-12-18 11:44:56 +053013266
13267 /* wait for mc thread to cleanup and then return to upper stack
13268 * so by the time upper layer calls the change interface, we are
13269 * all set to proceed further
13270 */
13271 rc = wait_for_completion_timeout(&pAdapter->disconnect_comp_var,
13272 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
13273 if (!rc) {
13274 hdd_err("Failed to disconnect, timed out");
13275 return -ETIMEDOUT;
13276 }
13277
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013278 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013279 return 0;
13280}
13281
13282/**
13283 * wlan_hdd_cfg80211_leave_ibss() - leave ibss
13284 * @wiphy: Pointer to wiphy
13285 * @dev: Pointer to network device
13286 *
13287 * This function is used to leave an IBSS network
13288 *
13289 * Return: 0 for success, non-zero for failure
13290 */
13291static int wlan_hdd_cfg80211_leave_ibss(struct wiphy *wiphy,
13292 struct net_device *dev)
13293{
13294 int ret = 0;
13295
13296 cds_ssr_protect(__func__);
13297 ret = __wlan_hdd_cfg80211_leave_ibss(wiphy, dev);
13298 cds_ssr_unprotect(__func__);
13299
13300 return ret;
13301}
13302
13303/**
13304 * __wlan_hdd_cfg80211_set_wiphy_params() - set wiphy parameters
13305 * @wiphy: Pointer to wiphy
13306 * @changed: Parameters changed
13307 *
13308 * This function is used to set the phy parameters. RTS Threshold/FRAG
13309 * Threshold/Retry Count etc.
13310 *
13311 * Return: 0 for success, non-zero for failure
13312 */
13313static int __wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
13314 u32 changed)
13315{
13316 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
13317 tHalHandle hHal = pHddCtx->hHal;
13318 int status;
13319
13320 ENTER();
13321
Anurag Chouhan6d760662016-02-20 16:05:43 +053013322 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013323 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013324 return -EINVAL;
13325 }
13326
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013327 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013328 TRACE_CODE_HDD_CFG80211_SET_WIPHY_PARAMS,
13329 NO_SESSION, wiphy->rts_threshold));
13330 status = wlan_hdd_validate_context(pHddCtx);
13331
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013332 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013333 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013334
13335 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
13336 u32 rts_threshold = (wiphy->rts_threshold == -1) ?
13337 WNI_CFG_RTS_THRESHOLD_STAMAX : wiphy->rts_threshold;
13338
13339 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
13340 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013341 hdd_err("Invalid RTS Threshold value %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013342 rts_threshold);
13343 return -EINVAL;
13344 }
13345
13346 if (0 != sme_cfg_set_int(hHal, WNI_CFG_RTS_THRESHOLD,
13347 rts_threshold)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013348 hdd_err("sme_cfg_set_int failed for rts_threshold value %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013349 rts_threshold);
13350 return -EIO;
13351 }
13352
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013353 hdd_info("set rts threshold %u", rts_threshold);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013354 }
13355
13356 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
13357 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
13358 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
13359 wiphy->frag_threshold;
13360
13361 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold) ||
13362 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013363 hdd_err("Invalid frag_threshold value %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013364 frag_threshold);
13365 return -EINVAL;
13366 }
13367
13368 if (0 != sme_cfg_set_int(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
13369 frag_threshold)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013370 hdd_err("sme_cfg_set_int failed for frag_threshold value %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013371 frag_threshold);
13372 return -EIO;
13373 }
13374
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013375 hdd_info("set frag threshold %hu", frag_threshold);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013376 }
13377
13378 if ((changed & WIPHY_PARAM_RETRY_SHORT)
13379 || (changed & WIPHY_PARAM_RETRY_LONG)) {
13380 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
13381 wiphy->retry_short : wiphy->retry_long;
13382
13383 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
13384 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013385 hdd_err("Invalid Retry count %hu", retry_value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013386 return -EINVAL;
13387 }
13388
13389 if (changed & WIPHY_PARAM_RETRY_SHORT) {
13390 if (0 != sme_cfg_set_int(hHal,
13391 WNI_CFG_LONG_RETRY_LIMIT,
13392 retry_value)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013393 hdd_err("sme_cfg_set_int failed for long retry count %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013394 retry_value);
13395 return -EIO;
13396 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013397 hdd_info("set long retry count %hu", retry_value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013398 } else if (changed & WIPHY_PARAM_RETRY_SHORT) {
13399 if (0 != sme_cfg_set_int(hHal,
13400 WNI_CFG_SHORT_RETRY_LIMIT,
13401 retry_value)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013402 hdd_err("sme_cfg_set_int failed for short retry count %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013403 retry_value);
13404 return -EIO;
13405 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013406 hdd_info("set short retry count %hu", retry_value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013407 }
13408 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013409 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013410 return 0;
13411}
13412
13413/**
13414 * wlan_hdd_cfg80211_set_wiphy_params() - set wiphy parameters
13415 * @wiphy: Pointer to wiphy
13416 * @changed: Parameters changed
13417 *
13418 * Return: 0 for success, non-zero for failure
13419 */
13420static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
13421{
13422 int ret;
13423
13424 cds_ssr_protect(__func__);
13425 ret = __wlan_hdd_cfg80211_set_wiphy_params(wiphy, changed);
13426 cds_ssr_unprotect(__func__);
13427
13428 return ret;
13429}
13430
13431/**
13432 * __wlan_hdd_set_default_mgmt_key() - dummy implementation of set default mgmt
13433 * key
13434 * @wiphy: Pointer to wiphy
13435 * @dev: Pointer to network device
13436 * @key_index: Key index
13437 *
13438 * Return: 0
13439 */
13440static int __wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
13441 struct net_device *netdev,
13442 u8 key_index)
13443{
13444 ENTER();
13445 return 0;
13446}
13447
13448/**
13449 * wlan_hdd_set_default_mgmt_key() - SSR wrapper for
13450 * wlan_hdd_set_default_mgmt_key
13451 * @wiphy: pointer to wiphy
13452 * @netdev: pointer to net_device structure
13453 * @key_index: key index
13454 *
13455 * Return: 0 on success, error number on failure
13456 */
13457static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
13458 struct net_device *netdev,
13459 u8 key_index)
13460{
13461 int ret;
13462
13463 cds_ssr_protect(__func__);
13464 ret = __wlan_hdd_set_default_mgmt_key(wiphy, netdev, key_index);
13465 cds_ssr_unprotect(__func__);
13466
13467 return ret;
13468}
13469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013470/**
13471 * __wlan_hdd_set_txq_params() - dummy implementation of set tx queue params
13472 * @wiphy: Pointer to wiphy
13473 * @dev: Pointer to network device
13474 * @params: Pointer to tx queue parameters
13475 *
13476 * Return: 0
13477 */
13478static int __wlan_hdd_set_txq_params(struct wiphy *wiphy,
13479 struct net_device *dev,
13480 struct ieee80211_txq_params *params)
13481{
13482 ENTER();
13483 return 0;
13484}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013485
13486/**
13487 * wlan_hdd_set_txq_params() - SSR wrapper for wlan_hdd_set_txq_params
13488 * @wiphy: pointer to wiphy
13489 * @netdev: pointer to net_device structure
13490 * @params: pointer to ieee80211_txq_params
13491 *
13492 * Return: 0 on success, error number on failure
13493 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013494static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
13495 struct net_device *dev,
13496 struct ieee80211_txq_params *params)
13497{
13498 int ret;
13499
13500 cds_ssr_protect(__func__);
13501 ret = __wlan_hdd_set_txq_params(wiphy, dev, params);
13502 cds_ssr_unprotect(__func__);
13503
13504 return ret;
13505}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013506
13507/**
13508 * __wlan_hdd_cfg80211_del_station() - delete station v2
13509 * @wiphy: Pointer to wiphy
13510 * @param: Pointer to delete station parameter
13511 *
13512 * Return: 0 for success, non-zero for failure
13513 */
13514static
13515int __wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
13516 struct net_device *dev,
13517 struct tagCsrDelStaParams *pDelStaParams)
13518{
13519 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13520 hdd_context_t *pHddCtx;
Anurag Chouhance0dc992016-02-16 18:18:03 +053013521 QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013522 hdd_hostapd_state_t *hapd_state;
13523 int status;
13524 uint8_t staId;
13525 uint8_t *mac;
13526
13527 ENTER();
13528
Anurag Chouhan6d760662016-02-20 16:05:43 +053013529 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013530 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013531 return -EINVAL;
13532 }
13533
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013534 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13535 hdd_err("invalid session id: %d", pAdapter->sessionId);
13536 return -EINVAL;
13537 }
13538
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013539 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013540 TRACE_CODE_HDD_CFG80211_DEL_STA,
13541 pAdapter->sessionId, pAdapter->device_mode));
13542
13543 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
13544 status = wlan_hdd_validate_context(pHddCtx);
13545
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013546 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013547 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013548
13549 mac = (uint8_t *) pDelStaParams->peerMacAddr.bytes;
13550
Krunal Sonib4326f22016-03-10 13:05:51 -080013551 if ((QDF_SAP_MODE == pAdapter->device_mode) ||
13552 (QDF_P2P_GO_MODE == pAdapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013553
13554 hapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
13555 if (!hapd_state) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013556 hdd_err("Hostapd State is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013557 return 0;
13558 }
13559
Anurag Chouhanc5548422016-02-24 18:33:27 +053013560 if (qdf_is_macaddr_broadcast((struct qdf_mac_addr *) mac)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013561 uint16_t i;
13562 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
13563 if ((pAdapter->aStaInfo[i].isUsed) &&
13564 (!pAdapter->aStaInfo[i].
13565 isDeauthInProgress)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +053013566 qdf_mem_copy(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013567 mac,
13568 pAdapter->aStaInfo[i].
13569 macAddrSTA.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +053013570 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013571 if (hdd_ipa_uc_is_enabled(pHddCtx)) {
13572 hdd_ipa_wlan_evt(pAdapter,
13573 pAdapter->
13574 aStaInfo[i].
13575 ucSTAId,
Mohit Khannafa99aea2016-05-12 21:43:13 -070013576 HDD_IPA_CLIENT_DISCONNECT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013577 mac);
13578 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013579 hdd_notice("Delete STA with MAC::"
13580 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013581 MAC_ADDR_ARRAY(mac));
13582
13583 if (pHddCtx->dev_dfs_cac_status ==
13584 DFS_CAC_IN_PROGRESS)
13585 goto fn_end;
13586
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053013587 qdf_event_reset(&hapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013588 hdd_softap_sta_disassoc(pAdapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053013589 pDelStaParams);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013590 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013591 hdd_softap_sta_deauth(pAdapter,
13592 pDelStaParams);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013593 if (QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013594 pAdapter->aStaInfo[i].
13595 isDeauthInProgress = true;
Anurag Chouhance0dc992016-02-16 18:18:03 +053013596 qdf_status =
13597 qdf_wait_single_event(
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053013598 &hapd_state->qdf_event,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013599 1000);
Anurag Chouhance0dc992016-02-16 18:18:03 +053013600 if (!QDF_IS_STATUS_SUCCESS(
13601 qdf_status))
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013602 hdd_err("Deauth wait time expired");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013603 }
13604 }
13605 }
13606 } else {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013607 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013608 hdd_softap_get_sta_id(pAdapter,
Anurag Chouhan6d760662016-02-20 16:05:43 +053013609 (struct qdf_mac_addr *) mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013610 &staId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013611 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013612 hdd_notice("Skip DEL STA as this is not used::"
13613 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013614 MAC_ADDR_ARRAY(mac));
13615 return -ENOENT;
13616 }
13617
13618 if (hdd_ipa_uc_is_enabled(pHddCtx)) {
13619 hdd_ipa_wlan_evt(pAdapter, staId,
Mohit Khannafa99aea2016-05-12 21:43:13 -070013620 HDD_IPA_CLIENT_DISCONNECT, mac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013621 }
13622
13623 if (pAdapter->aStaInfo[staId].isDeauthInProgress ==
13624 true) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013625 hdd_notice("Skip DEL STA as deauth is in progress::"
13626 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013627 MAC_ADDR_ARRAY(mac));
13628 return -ENOENT;
13629 }
13630
13631 pAdapter->aStaInfo[staId].isDeauthInProgress = true;
13632
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013633 hdd_notice("Delete STA with MAC::" MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013634 MAC_ADDR_ARRAY(mac));
13635
13636 /* Case: SAP in ACS selected DFS ch and client connected
13637 * Now Radar detected. Then if random channel is another
13638 * DFS ch then new CAC is initiated and no TX allowed.
13639 * So do not send any mgmt frames as it will timeout
13640 * during CAC.
13641 */
13642
13643 if (pHddCtx->dev_dfs_cac_status == DFS_CAC_IN_PROGRESS)
13644 goto fn_end;
13645
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053013646 qdf_event_reset(&hapd_state->qdf_event);
Kondabattini, Ganesh3f2d02c2016-09-13 12:23:47 +053013647 sme_send_disassoc_req_frame(WLAN_HDD_GET_HAL_CTX
13648 (pAdapter), pAdapter->sessionId,
13649 (uint8_t *)&pDelStaParams->peerMacAddr,
13650 pDelStaParams->reason_code, 0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013651 qdf_status = hdd_softap_sta_deauth(pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013652 pDelStaParams);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013653 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013654 pAdapter->aStaInfo[staId].isDeauthInProgress =
13655 false;
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013656 hdd_notice("STA removal failed for ::"
13657 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013658 MAC_ADDR_ARRAY(mac));
13659 return -ENOENT;
13660 } else {
Anurag Chouhance0dc992016-02-16 18:18:03 +053013661 qdf_status = qdf_wait_single_event(
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053013662 &hapd_state->qdf_event,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013663 1000);
Anurag Chouhance0dc992016-02-16 18:18:03 +053013664 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013665 hdd_err("Deauth wait time expired");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013666 }
13667 }
13668 }
13669
13670fn_end:
13671 EXIT();
13672 return 0;
13673}
13674
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080013675#if defined(USE_CFG80211_DEL_STA_V2)
13676/**
13677 * wlan_hdd_del_station() - delete station wrapper
13678 * @adapter: pointer to the hdd adapter
13679 *
13680 * Return: None
13681 */
13682void wlan_hdd_del_station(hdd_adapter_t *adapter)
13683{
13684 struct station_del_parameters del_sta;
13685 del_sta.mac = NULL;
13686 del_sta.subtype = SIR_MAC_MGMT_DEAUTH >> 4;
13687 del_sta.reason_code = eCsrForcedDeauthSta;
13688
13689 wlan_hdd_cfg80211_del_station(adapter->wdev.wiphy, adapter->dev,
13690 &del_sta);
13691}
13692#else
13693void wlan_hdd_del_station(hdd_adapter_t *adapter)
13694{
13695 wlan_hdd_cfg80211_del_station(adapter->wdev.wiphy, adapter->dev, NULL);
13696}
13697#endif
13698
13699#if defined(USE_CFG80211_DEL_STA_V2)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013700/**
13701 * wlan_hdd_cfg80211_del_station() - delete station v2
13702 * @wiphy: Pointer to wiphy
13703 * @param: Pointer to delete station parameter
13704 *
13705 * Return: 0 for success, non-zero for failure
13706 */
13707int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
13708 struct net_device *dev,
13709 struct station_del_parameters *param)
13710#else
13711/**
13712 * wlan_hdd_cfg80211_del_station() - delete station
13713 * @wiphy: Pointer to wiphy
13714 * @mac: Pointer to station mac address
13715 *
13716 * Return: 0 for success, non-zero for failure
13717 */
13718#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
13719int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
13720 struct net_device *dev,
13721 const uint8_t *mac)
13722#else
13723int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
13724 struct net_device *dev,
13725 uint8_t *mac)
13726#endif
13727#endif
13728{
13729 int ret;
13730 struct tagCsrDelStaParams delStaParams;
13731
13732 cds_ssr_protect(__func__);
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080013733#if defined(USE_CFG80211_DEL_STA_V2)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013734 if (NULL == param) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080013735 hdd_err("Invalid argument passed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013736 return -EINVAL;
13737 }
13738 wlansap_populate_del_sta_params(param->mac, param->reason_code,
13739 param->subtype, &delStaParams);
13740#else
13741 wlansap_populate_del_sta_params(mac, eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
13742 (SIR_MAC_MGMT_DEAUTH >> 4),
13743 &delStaParams);
13744#endif
13745 ret = __wlan_hdd_cfg80211_del_station(wiphy, dev, &delStaParams);
13746 cds_ssr_unprotect(__func__);
13747
13748 return ret;
13749}
13750
13751/**
13752 * __wlan_hdd_cfg80211_add_station() - add station
13753 * @wiphy: Pointer to wiphy
13754 * @mac: Pointer to station mac address
13755 * @pmksa: Pointer to add station parameter
13756 *
13757 * Return: 0 for success, non-zero for failure
13758 */
13759static int __wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
13760 struct net_device *dev,
13761 const uint8_t *mac,
13762 struct station_parameters *params)
13763{
13764 int status = -EPERM;
13765#ifdef FEATURE_WLAN_TDLS
13766 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13767 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
13768 u32 mask, set;
13769
13770 ENTER();
13771
Anurag Chouhan6d760662016-02-20 16:05:43 +053013772 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013773 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013774 return -EINVAL;
13775 }
13776
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013777 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13778 hdd_err("invalid session id: %d", pAdapter->sessionId);
13779 return -EINVAL;
13780 }
13781
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013782 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013783 TRACE_CODE_HDD_CFG80211_ADD_STA,
13784 pAdapter->sessionId, params->listen_interval));
13785
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013786 if (0 != wlan_hdd_validate_context(pHddCtx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013787 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013788
13789 mask = params->sta_flags_mask;
13790
13791 set = params->sta_flags_set;
13792
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013793 hdd_notice("mask 0x%x set 0x%x " MAC_ADDRESS_STR, mask, set,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013794 MAC_ADDR_ARRAY(mac));
13795
13796 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
13797 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
13798 status =
13799 wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
13800 }
13801 }
13802#endif
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013803 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013804 return status;
13805}
13806
13807/**
13808 * wlan_hdd_cfg80211_add_station() - add station
13809 * @wiphy: Pointer to wiphy
13810 * @mac: Pointer to station mac address
13811 * @pmksa: Pointer to add station parameter
13812 *
13813 * Return: 0 for success, non-zero for failure
13814 */
13815#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
13816static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
13817 struct net_device *dev,
13818 const uint8_t *mac,
13819 struct station_parameters *params)
13820#else
13821static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
13822 struct net_device *dev, uint8_t *mac,
13823 struct station_parameters *params)
13824#endif
13825{
13826 int ret;
13827
13828 cds_ssr_protect(__func__);
13829 ret = __wlan_hdd_cfg80211_add_station(wiphy, dev, mac, params);
13830 cds_ssr_unprotect(__func__);
13831
13832 return ret;
13833}
13834
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013835/**
13836 * __wlan_hdd_cfg80211_set_pmksa() - set pmksa
13837 * @wiphy: Pointer to wiphy
13838 * @dev: Pointer to network device
13839 * @pmksa: Pointer to set pmksa parameter
13840 *
13841 * Return: 0 for success, non-zero for failure
13842 */
13843static int __wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy,
13844 struct net_device *dev,
13845 struct cfg80211_pmksa *pmksa)
13846{
13847 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13848 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
13849 tHalHandle halHandle;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013850 QDF_STATUS result = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013851 int status;
13852 tPmkidCacheInfo pmk_id;
13853
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013854 ENTER();
13855
Anurag Chouhan6d760662016-02-20 16:05:43 +053013856 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013857 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013858 return -EINVAL;
13859 }
13860
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013861 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13862 hdd_err("invalid session id: %d", pAdapter->sessionId);
13863 return -EINVAL;
13864 }
13865
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013866 if (!pmksa) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013867 hdd_err("pmksa is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013868 return -EINVAL;
13869 }
13870
13871 if (!pmksa->bssid || !pmksa->pmkid) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013872 hdd_err("pmksa->bssid(%p) or pmksa->pmkid(%p) is NULL",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013873 pmksa->bssid, pmksa->pmkid);
13874 return -EINVAL;
13875 }
13876
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013877 hdd_warn("set PMKSA for " MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013878 MAC_ADDR_ARRAY(pmksa->bssid));
13879
13880 status = wlan_hdd_validate_context(pHddCtx);
13881
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013882 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013883 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013884
13885 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
13886
Anurag Chouhan600c3a02016-03-01 10:33:54 +053013887 qdf_mem_copy(pmk_id.BSSID.bytes, pmksa->bssid, QDF_MAC_ADDR_SIZE);
13888 qdf_mem_copy(pmk_id.PMKID, pmksa->pmkid, CSR_RSN_PMKID_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013889
13890 /* Add to the PMKSA ID Cache in CSR */
13891 result = sme_roam_set_pmkid_cache(halHandle, pAdapter->sessionId,
13892 &pmk_id, 1, false);
13893
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013894 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013895 TRACE_CODE_HDD_CFG80211_SET_PMKSA,
13896 pAdapter->sessionId, result));
13897
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013898 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013899 return QDF_IS_STATUS_SUCCESS(result) ? 0 : -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013900}
13901
13902/**
13903 * wlan_hdd_cfg80211_set_pmksa() - set pmksa
13904 * @wiphy: Pointer to wiphy
13905 * @dev: Pointer to network device
13906 * @pmksa: Pointer to set pmksa parameter
13907 *
13908 * Return: 0 for success, non-zero for failure
13909 */
13910static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy,
13911 struct net_device *dev,
13912 struct cfg80211_pmksa *pmksa)
13913{
13914 int ret;
13915
13916 cds_ssr_protect(__func__);
13917 ret = __wlan_hdd_cfg80211_set_pmksa(wiphy, dev, pmksa);
13918 cds_ssr_unprotect(__func__);
13919
13920 return ret;
13921}
13922
13923/**
13924 * __wlan_hdd_cfg80211_del_pmksa() - delete pmksa
13925 * @wiphy: Pointer to wiphy
13926 * @dev: Pointer to network device
13927 * @pmksa: Pointer to pmksa parameter
13928 *
13929 * Return: 0 for success, non-zero for failure
13930 */
13931static int __wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy,
13932 struct net_device *dev,
13933 struct cfg80211_pmksa *pmksa)
13934{
13935 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13936 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
13937 tHalHandle halHandle;
13938 int status = 0;
13939
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013940 ENTER();
13941
Anurag Chouhan6d760662016-02-20 16:05:43 +053013942 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013943 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013944 return -EINVAL;
13945 }
13946
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013947 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13948 hdd_err("invalid session id: %d", pAdapter->sessionId);
13949 return -EINVAL;
13950 }
13951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013952 if (!pmksa) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013953 hdd_err("pmksa is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013954 return -EINVAL;
13955 }
13956
13957 if (!pmksa->bssid) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013958 hdd_err("pmksa->bssid is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013959 return -EINVAL;
13960 }
13961
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013962 hdd_debug("Deleting PMKSA for " MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013963 MAC_ADDR_ARRAY(pmksa->bssid));
13964
13965 status = wlan_hdd_validate_context(pHddCtx);
13966
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013967 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013968 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013969
13970 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
13971
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013972 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +053013973 TRACE_CODE_HDD_CFG80211_DEL_PMKSA,
13974 pAdapter->sessionId, 0));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013975 /* Delete the PMKID CSR cache */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013976 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013977 sme_roam_del_pmkid_from_cache(halHandle,
13978 pAdapter->sessionId, pmksa->bssid,
13979 false)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013980 hdd_err("Failed to delete PMKSA for " MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013981 MAC_ADDR_ARRAY(pmksa->bssid));
13982 status = -EINVAL;
13983 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013984 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013985 return status;
13986}
13987
13988/**
13989 * wlan_hdd_cfg80211_del_pmksa() - delete pmksa
13990 * @wiphy: Pointer to wiphy
13991 * @dev: Pointer to network device
13992 * @pmksa: Pointer to pmksa parameter
13993 *
13994 * Return: 0 for success, non-zero for failure
13995 */
13996static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy,
13997 struct net_device *dev,
13998 struct cfg80211_pmksa *pmksa)
13999{
14000 int ret;
14001
14002 cds_ssr_protect(__func__);
14003 ret = __wlan_hdd_cfg80211_del_pmksa(wiphy, dev, pmksa);
14004 cds_ssr_unprotect(__func__);
14005
14006 return ret;
14007
14008}
14009
14010/**
14011 * __wlan_hdd_cfg80211_flush_pmksa() - flush pmksa
14012 * @wiphy: Pointer to wiphy
14013 * @dev: Pointer to network device
14014 *
14015 * Return: 0 for success, non-zero for failure
14016 */
14017static int __wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy,
14018 struct net_device *dev)
14019{
14020 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14021 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14022 tHalHandle halHandle;
14023 int status = 0;
14024
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014025 ENTER();
14026
Anurag Chouhan6d760662016-02-20 16:05:43 +053014027 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014028 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014029 return -EINVAL;
14030 }
14031
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014032 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14033 hdd_err("invalid session id: %d", pAdapter->sessionId);
14034 return -EINVAL;
14035 }
14036
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014037 hdd_warn("Flushing PMKSA");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014038
14039 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14040 status = wlan_hdd_validate_context(pHddCtx);
14041
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014042 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014043 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014044
14045 /* Retrieve halHandle */
14046 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
14047
14048 /* Flush the PMKID cache in CSR */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014049 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014050 sme_roam_del_pmkid_from_cache(halHandle, pAdapter->sessionId, NULL,
14051 true)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014052 hdd_err("Cannot flush PMKIDCache");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014053 status = -EINVAL;
14054 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014055 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014056 return status;
14057}
14058
14059/**
14060 * wlan_hdd_cfg80211_flush_pmksa() - flush pmksa
14061 * @wiphy: Pointer to wiphy
14062 * @dev: Pointer to network device
14063 *
14064 * Return: 0 for success, non-zero for failure
14065 */
14066static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy,
14067 struct net_device *dev)
14068{
14069 int ret;
14070
14071 cds_ssr_protect(__func__);
14072 ret = __wlan_hdd_cfg80211_flush_pmksa(wiphy, dev);
14073 cds_ssr_unprotect(__func__);
14074
14075 return ret;
14076}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014077
Deepak Dhamdhere9f09e752016-01-09 23:17:25 -080014078#if defined(KERNEL_SUPPORT_11R_CFG80211)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014079/**
14080 * __wlan_hdd_cfg80211_update_ft_ies() - update fast transition ies
14081 * @wiphy: Pointer to wiphy
14082 * @dev: Pointer to network device
14083 * @ftie: Pointer to fast transition ie parameter
14084 *
14085 * Return: 0 for success, non-zero for failure
14086 */
14087static int
14088__wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
14089 struct net_device *dev,
14090 struct cfg80211_update_ft_ies_params *ftie)
14091{
14092 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
14093 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14094 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
14095 int status;
14096
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014097 ENTER();
14098
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014099 status = wlan_hdd_validate_context(hdd_ctx);
14100 if (status)
14101 return status;
14102
Anurag Chouhan6d760662016-02-20 16:05:43 +053014103 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014104 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014105 return -EINVAL;
14106 }
14107
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014108 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14109 hdd_err("invalid session id: %d", pAdapter->sessionId);
14110 return -EINVAL;
14111 }
14112
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014113 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014114 TRACE_CODE_HDD_CFG80211_UPDATE_FT_IES,
14115 pAdapter->sessionId, pHddStaCtx->conn_info.connState));
14116 /* Added for debug on reception of Re-assoc Req. */
14117 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014118 hdd_err("Called with Ie of length = %zu when not associated",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014119 ftie->ie_len);
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014120 hdd_err("Should be Re-assoc Req IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014121 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014122 hdd_notice("%s called with Ie of length = %zu", __func__,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014123 ftie->ie_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014124
14125 /* Pass the received FT IEs to SME */
14126 sme_set_ft_ies(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
14127 (const u8 *)ftie->ie, ftie->ie_len);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014128 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014129 return 0;
14130}
14131
14132/**
14133 * wlan_hdd_cfg80211_update_ft_ies() - update fast transition ies
14134 * @wiphy: Pointer to wiphy
14135 * @dev: Pointer to network device
14136 * @ftie: Pointer to fast transition ie parameter
14137 *
14138 * Return: 0 for success, non-zero for failure
14139 */
14140static int
14141wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
14142 struct net_device *dev,
14143 struct cfg80211_update_ft_ies_params *ftie)
14144{
14145 int ret;
14146
14147 cds_ssr_protect(__func__);
14148 ret = __wlan_hdd_cfg80211_update_ft_ies(wiphy, dev, ftie);
14149 cds_ssr_unprotect(__func__);
14150
14151 return ret;
14152}
14153#endif
14154
14155#ifdef WLAN_FEATURE_GTK_OFFLOAD
14156/**
14157 * wlan_hdd_cfg80211_update_replay_counter_callback() - replay counter callback
14158 * @callbackContext: Callback context
14159 * @pGtkOffloadGetInfoRsp: Pointer to gtk offload response parameter
14160 *
14161 * Callback rountine called upon receiving response for get offload info
14162 *
14163 * Return: none
14164 */
14165void wlan_hdd_cfg80211_update_replay_counter_callback(void *callbackContext,
14166 tpSirGtkOffloadGetInfoRspParams
14167 pGtkOffloadGetInfoRsp)
14168{
14169 hdd_adapter_t *pAdapter = (hdd_adapter_t *) callbackContext;
14170 uint8_t tempReplayCounter[8];
14171 hdd_station_ctx_t *pHddStaCtx;
14172
14173 ENTER();
14174
14175 if (NULL == pAdapter) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014176 hdd_err("HDD adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014177 return;
14178 }
14179
14180 if (NULL == pGtkOffloadGetInfoRsp) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014181 hdd_err("pGtkOffloadGetInfoRsp is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014182 return;
14183 }
14184
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014185 if (QDF_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014186 hdd_err("wlan Failed to get replay counter value");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014187 return;
14188 }
14189
14190 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
14191 /* Update replay counter */
14192 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
14193 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
14194
14195 {
14196 /* changing from little to big endian since supplicant
14197 * works on big endian format
14198 */
14199 int i;
14200 uint8_t *p =
14201 (uint8_t *) &pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
14202
14203 for (i = 0; i < 8; i++) {
14204 tempReplayCounter[7 - i] = (uint8_t) p[i];
14205 }
14206 }
14207
14208 /* Update replay counter to NL */
Srinivas Girigowda2213b1d2015-11-20 17:10:11 -080014209 cfg80211_gtk_rekey_notify(pAdapter->dev,
14210 pGtkOffloadGetInfoRsp->bssid.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014211 tempReplayCounter, GFP_KERNEL);
14212}
14213
14214/**
14215 * __wlan_hdd_cfg80211_set_rekey_data() - set rekey data
14216 * @wiphy: Pointer to wiphy
14217 * @dev: Pointer to network device
14218 * @data: Pointer to rekey data
14219 *
14220 * This function is used to offload GTK rekeying job to the firmware.
14221 *
14222 * Return: 0 for success, non-zero for failure
14223 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070014224static
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014225int __wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy,
14226 struct net_device *dev,
14227 struct cfg80211_gtk_rekey_data *data)
14228{
14229 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14230 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
14231 hdd_station_ctx_t *pHddStaCtx;
14232 tHalHandle hHal;
14233 int result;
14234 tSirGtkOffloadParams hddGtkOffloadReqParams;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014235 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014236
14237 ENTER();
14238
Anurag Chouhan6d760662016-02-20 16:05:43 +053014239 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014240 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014241 return -EINVAL;
14242 }
14243
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014244 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14245 hdd_err("invalid session id: %d", pAdapter->sessionId);
14246 return -EINVAL;
14247 }
14248
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014249 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014250 TRACE_CODE_HDD_CFG80211_SET_REKEY_DATA,
14251 pAdapter->sessionId, pAdapter->device_mode));
14252
14253 result = wlan_hdd_validate_context(pHddCtx);
14254
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014255 if (0 != result)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014256 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014257
14258 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
14259 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
14260 if (NULL == hHal) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014261 hdd_err("HAL context is Null!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014262 return -EAGAIN;
14263 }
14264
14265 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
14266 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck,
14267 NL80211_KCK_LEN);
14268 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek,
14269 NL80211_KEK_LEN);
Anurag Chouhanc5548422016-02-24 18:33:27 +053014270 qdf_copy_macaddr(&pHddStaCtx->gtkOffloadReqParams.bssid,
Srinivas Girigowda2213b1d2015-11-20 17:10:11 -080014271 &pHddStaCtx->conn_info.bssId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014272 {
14273 /* changing from big to little endian since driver
14274 * works on little endian format
14275 */
14276 uint8_t *p =
14277 (uint8_t *) &pHddStaCtx->gtkOffloadReqParams.
14278 ullKeyReplayCounter;
14279 int i;
14280
14281 for (i = 0; i < 8; i++) {
14282 p[7 - i] = data->replay_ctr[i];
14283 }
14284 }
14285
14286 if (true == pHddCtx->hdd_wlan_suspended) {
14287 /* if wlan is suspended, enable GTK offload directly from here */
14288 memcpy(&hddGtkOffloadReqParams,
14289 &pHddStaCtx->gtkOffloadReqParams,
14290 sizeof(tSirGtkOffloadParams));
14291 status =
14292 sme_set_gtk_offload(hHal, &hddGtkOffloadReqParams,
14293 pAdapter->sessionId);
14294
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014295 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014296 hdd_err("sme_set_gtk_offload failed, status(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014297 status);
14298 return -EINVAL;
14299 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014300 hdd_notice("sme_set_gtk_offload successful");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014301 } else {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014302 hdd_notice("wlan not suspended GTKOffload request is stored");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014303 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014304 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014305 return result;
14306}
14307
14308/**
14309 * wlan_hdd_cfg80211_set_rekey_data() - set rekey data
14310 * @wiphy: Pointer to wiphy
14311 * @dev: Pointer to network device
14312 * @data: Pointer to rekey data
14313 *
14314 * This function is used to offload GTK rekeying job to the firmware.
14315 *
14316 * Return: 0 for success, non-zero for failure
14317 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070014318static
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014319int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy,
14320 struct net_device *dev,
14321 struct cfg80211_gtk_rekey_data *data)
14322{
14323 int ret;
14324
14325 cds_ssr_protect(__func__);
14326 ret = __wlan_hdd_cfg80211_set_rekey_data(wiphy, dev, data);
14327 cds_ssr_unprotect(__func__);
14328
14329 return ret;
14330}
14331#endif /*WLAN_FEATURE_GTK_OFFLOAD */
14332
14333/**
14334 * __wlan_hdd_cfg80211_set_mac_acl() - set access control policy
14335 * @wiphy: Pointer to wiphy
14336 * @dev: Pointer to network device
14337 * @param: Pointer to access control parameter
14338 *
14339 * Return: 0 for success, non-zero for failure
14340 */
14341static int __wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
14342 struct net_device *dev,
14343 const struct cfg80211_acl_data *params)
14344{
14345 int i;
14346 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14347 hdd_hostapd_state_t *pHostapdState;
14348 tsap_Config_t *pConfig;
14349 v_CONTEXT_t p_cds_context = NULL;
14350 hdd_context_t *pHddCtx;
14351 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014352 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014353
14354 ENTER();
14355
Anurag Chouhan6d760662016-02-20 16:05:43 +053014356 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014357 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014358 return -EINVAL;
14359 }
14360
14361 if (NULL == params) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014362 hdd_err("params is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014363 return -EINVAL;
14364 }
14365
14366 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14367 status = wlan_hdd_validate_context(pHddCtx);
14368
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014369 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014370 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014371
14372 p_cds_context = pHddCtx->pcds_context;
14373 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
14374
14375 if (NULL == pHostapdState) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014376 hdd_err("pHostapdState is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014377 return -EINVAL;
14378 }
14379
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014380 hdd_err("acl policy: = %d no acl entries = %d", params->acl_policy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014381 params->n_acl_entries);
14382
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014383 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +053014384 TRACE_CODE_HDD_CFG80211_SET_MAC_ACL,
14385 pAdapter->sessionId, pAdapter->device_mode));
Krunal Sonib4326f22016-03-10 13:05:51 -080014386 if (QDF_SAP_MODE == pAdapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014387 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
14388
14389 /* default value */
14390 pConfig->num_accept_mac = 0;
14391 pConfig->num_deny_mac = 0;
14392
14393 /**
14394 * access control policy
14395 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
14396 * listed in hostapd.deny file.
14397 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
14398 * listed in hostapd.accept file.
14399 */
14400 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy) {
14401 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
14402 } else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED ==
14403 params->acl_policy) {
14404 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
14405 } else {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014406 hdd_err("Acl Policy : %d is not supported",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014407 params->acl_policy);
14408 return -ENOTSUPP;
14409 }
14410
14411 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl) {
14412 pConfig->num_accept_mac = params->n_acl_entries;
14413 for (i = 0; i < params->n_acl_entries; i++) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014414 hdd_notice("** Add ACL MAC entry %i in WhiletList :"
14415 MAC_ADDRESS_STR, i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014416 MAC_ADDR_ARRAY(
14417 params->mac_addrs[i].addr));
14418
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014419 qdf_mem_copy(&pConfig->accept_mac[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014420 params->mac_addrs[i].addr,
14421 sizeof(qcmacaddr));
14422 }
14423 } else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl) {
14424 pConfig->num_deny_mac = params->n_acl_entries;
14425 for (i = 0; i < params->n_acl_entries; i++) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014426 hdd_notice("** Add ACL MAC entry %i in BlackList :"
14427 MAC_ADDRESS_STR, i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014428 MAC_ADDR_ARRAY(
14429 params->mac_addrs[i].addr));
14430
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014431 qdf_mem_copy(&pConfig->deny_mac[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014432 params->mac_addrs[i].addr,
14433 sizeof(qcmacaddr));
14434 }
14435 }
Dustin Brown6ba30a12016-09-13 13:59:43 -070014436 qdf_status = wlansap_set_mac_acl(
14437 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), pConfig);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014438 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014439 hdd_err("SAP Set Mac Acl fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014440 return -EINVAL;
14441 }
14442 } else {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014443 hdd_notice("Invalid device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014444 hdd_device_mode_to_string(pAdapter->device_mode),
14445 pAdapter->device_mode);
14446 return -EINVAL;
14447 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014448 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014449 return 0;
14450}
14451
14452/**
14453 * wlan_hdd_cfg80211_set_mac_acl() - SSR wrapper for
14454 * __wlan_hdd_cfg80211_set_mac_acl
14455 * @wiphy: pointer to wiphy structure
14456 * @dev: pointer to net_device
14457 * @params: pointer to cfg80211_acl_data
14458 *
14459 * Return; 0 on success, error number otherwise
14460 */
14461static int
14462wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
14463 struct net_device *dev,
14464 const struct cfg80211_acl_data *params)
14465{
14466 int ret;
14467
14468 cds_ssr_protect(__func__);
14469 ret = __wlan_hdd_cfg80211_set_mac_acl(wiphy, dev, params);
14470 cds_ssr_unprotect(__func__);
14471
14472 return ret;
14473}
14474
14475#ifdef WLAN_NL80211_TESTMODE
14476#ifdef FEATURE_WLAN_LPHB
14477/**
14478 * wlan_hdd_cfg80211_lphb_ind_handler() - handle low power heart beat indication
14479 * @pHddCtx: Pointer to hdd context
14480 * @lphbInd: Pointer to low power heart beat indication parameter
14481 *
14482 * Return: none
14483 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070014484static void wlan_hdd_cfg80211_lphb_ind_handler(void *pHddCtx,
14485 tSirLPHBInd *lphbInd)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014486{
14487 struct sk_buff *skb;
14488
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014489 hdd_err("LPHB indication arrived");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014490
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014491 if (0 != wlan_hdd_validate_context((hdd_context_t *) pHddCtx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014492 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014493
14494 if (NULL == lphbInd) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014495 hdd_err("invalid argument lphbInd");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014496 return;
14497 }
14498
14499 skb = cfg80211_testmode_alloc_event_skb(((hdd_context_t *) pHddCtx)->
14500 wiphy, sizeof(tSirLPHBInd),
14501 GFP_ATOMIC);
14502 if (!skb) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014503 hdd_err("LPHB timeout, NL buffer alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014504 return;
14505 }
14506
14507 if (nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014508 hdd_err("WLAN_HDD_TM_ATTR_CMD put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014509 goto nla_put_failure;
14510 }
14511 if (nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014512 hdd_err("WLAN_HDD_TM_ATTR_TYPE put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014513 goto nla_put_failure;
14514 }
14515 if (nla_put(skb, WLAN_HDD_TM_ATTR_DATA, sizeof(tSirLPHBInd), lphbInd)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014516 hdd_err("WLAN_HDD_TM_ATTR_DATA put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014517 goto nla_put_failure;
14518 }
14519 cfg80211_testmode_event(skb, GFP_ATOMIC);
14520 return;
14521
14522nla_put_failure:
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014523 hdd_err("NLA Put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014524 kfree_skb(skb);
14525
14526 return;
14527}
14528#endif /* FEATURE_WLAN_LPHB */
14529
14530/**
14531 * __wlan_hdd_cfg80211_testmode() - test mode
14532 * @wiphy: Pointer to wiphy
14533 * @data: Data pointer
14534 * @len: Data length
14535 *
14536 * Return: 0 for success, non-zero for failure
14537 */
14538static int __wlan_hdd_cfg80211_testmode(struct wiphy *wiphy,
14539 void *data, int len)
14540{
14541 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
14542 int err;
14543 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
14544
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014545 ENTER();
14546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014547 err = wlan_hdd_validate_context(pHddCtx);
14548 if (err)
14549 return err;
14550
14551 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data,
14552 len, wlan_hdd_tm_policy);
14553 if (err) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014554 hdd_err("Testmode INV ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014555 return err;
14556 }
14557
14558 if (!tb[WLAN_HDD_TM_ATTR_CMD]) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014559 hdd_err("Testmode INV CMD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014560 return -EINVAL;
14561 }
14562
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014563 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +053014564 TRACE_CODE_HDD_CFG80211_TESTMODE,
14565 NO_SESSION, nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD])));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014566 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD])) {
14567#ifdef FEATURE_WLAN_LPHB
14568 /* Low Power Heartbeat configuration request */
14569 case WLAN_HDD_TM_CMD_WLAN_HB:
14570 {
14571 int buf_len;
14572 void *buf;
14573 tSirLPHBReq *hb_params = NULL;
14574 tSirLPHBReq *hb_params_temp = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014575 QDF_STATUS smeStatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014576
14577 if (!tb[WLAN_HDD_TM_ATTR_DATA]) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014578 hdd_err("Testmode INV DATA");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014579 return -EINVAL;
14580 }
14581
14582 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
14583 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
14584
14585 hb_params_temp = (tSirLPHBReq *) buf;
14586 if ((hb_params_temp->cmd == LPHB_SET_TCP_PARAMS_INDID)
14587 && (hb_params_temp->params.lphbTcpParamReq.
14588 timePeriodSec == 0))
14589 return -EINVAL;
14590
14591 hb_params =
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014592 (tSirLPHBReq *) qdf_mem_malloc(sizeof(tSirLPHBReq));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014593 if (NULL == hb_params) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014594 hdd_err("Request Buffer Alloc Fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014595 return -ENOMEM;
14596 }
14597
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014598 qdf_mem_copy(hb_params, buf, buf_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014599 smeStatus =
14600 sme_lphb_config_req((tHalHandle) (pHddCtx->hHal),
14601 hb_params,
14602 wlan_hdd_cfg80211_lphb_ind_handler);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014603 if (QDF_STATUS_SUCCESS != smeStatus) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014604 hdd_err("LPHB Config Fail, disable");
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014605 qdf_mem_free(hb_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014606 }
14607 return 0;
14608 }
14609#endif /* FEATURE_WLAN_LPHB */
14610
14611#if defined(QCA_WIFI_FTM)
14612 case WLAN_HDD_TM_CMD_WLAN_FTM:
14613 {
14614 int buf_len;
14615 void *buf;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014616 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014617 if (!tb[WLAN_HDD_TM_ATTR_DATA]) {
Ryan Hsucfef0ae2016-04-28 10:20:46 -070014618 hdd_err("WLAN_HDD_TM_ATTR_DATA attribute is invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014619 return -EINVAL;
14620 }
14621
14622 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
14623 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
14624
Ryan Hsucfef0ae2016-04-28 10:20:46 -070014625 hdd_info("****FTM Tx cmd len = %d*****", buf_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014626
14627 status = wlan_hdd_ftm_testmode_cmd(buf, buf_len);
14628
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014629 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014630 err = -EBUSY;
14631 break;
14632 }
14633#endif
14634
14635 default:
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014636 hdd_err("command %d not supported",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014637 nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]));
14638 return -EOPNOTSUPP;
14639 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014640 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014641 return err;
14642}
14643
14644/**
14645 * wlan_hdd_cfg80211_testmode() - test mode
14646 * @wiphy: Pointer to wiphy
14647 * @dev: Pointer to network device
14648 * @data: Data pointer
14649 * @len: Data length
14650 *
14651 * Return: 0 for success, non-zero for failure
14652 */
14653static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy,
14654#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0))
14655 struct wireless_dev *wdev,
14656#endif
14657 void *data, int len)
14658{
14659 int ret;
14660
14661 cds_ssr_protect(__func__);
14662 ret = __wlan_hdd_cfg80211_testmode(wiphy, data, len);
14663 cds_ssr_unprotect(__func__);
14664
14665 return ret;
14666}
14667
14668#if defined(QCA_WIFI_FTM)
14669/**
14670 * wlan_hdd_testmode_rx_event() - test mode rx event handler
14671 * @buf: Pointer to buffer
14672 * @buf_len: Buffer length
14673 *
14674 * Return: none
14675 */
14676void wlan_hdd_testmode_rx_event(void *buf, size_t buf_len)
14677{
14678 struct sk_buff *skb;
14679 hdd_context_t *hdd_ctx;
14680
14681 if (!buf || !buf_len) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014682 hdd_err("buf or buf_len invalid, buf = %p buf_len = %zu", buf, buf_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014683 return;
14684 }
14685
Anurag Chouhan6d760662016-02-20 16:05:43 +053014686 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014687 if (!hdd_ctx) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014688 hdd_err("hdd context invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014689 return;
14690 }
14691
14692 skb = cfg80211_testmode_alloc_event_skb(hdd_ctx->wiphy,
14693 buf_len, GFP_KERNEL);
14694 if (!skb) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014695 hdd_err("failed to allocate testmode rx skb!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014696 return;
14697 }
14698
14699 if (nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_FTM) ||
14700 nla_put(skb, WLAN_HDD_TM_ATTR_DATA, buf_len, buf))
14701 goto nla_put_failure;
14702
Ryan Hsucfef0ae2016-04-28 10:20:46 -070014703 hdd_info("****FTM Rx cmd len = %zu*****", buf_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014704
14705 cfg80211_testmode_event(skb, GFP_KERNEL);
14706 return;
14707
14708nla_put_failure:
14709 kfree_skb(skb);
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014710 hdd_err("nla_put failed on testmode rx skb!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014711}
14712#endif
14713#endif /* CONFIG_NL80211_TESTMODE */
14714
14715#ifdef QCA_HT_2040_COEX
14716/**
14717 * __wlan_hdd_cfg80211_set_ap_channel_width() - set ap channel bandwidth
14718 * @wiphy: Pointer to wiphy
14719 * @dev: Pointer to network device
14720 * @chandef: Pointer to channel definition parameter
14721 *
14722 * Return: 0 for success, non-zero for failure
14723 */
14724static int
14725__wlan_hdd_cfg80211_set_ap_channel_width(struct wiphy *wiphy,
14726 struct net_device *dev,
14727 struct cfg80211_chan_def *chandef)
14728{
14729 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14730 hdd_context_t *pHddCtx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014731 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014732 tSmeConfigParams sme_config;
Anurag Chouhan00ed5272016-10-17 17:22:55 +053014733 bool cbModeChange = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014734
Anurag Chouhan6d760662016-02-20 16:05:43 +053014735 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014736 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014737 return -EINVAL;
14738 }
14739
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014740 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14741 hdd_err("invalid session id: %d", pAdapter->sessionId);
14742 return -EINVAL;
14743 }
14744
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014745 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14746 status = wlan_hdd_validate_context(pHddCtx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053014747 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014748 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014749
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014750 qdf_mem_zero(&sme_config, sizeof(tSmeConfigParams));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014751 sme_get_config_param(pHddCtx->hHal, &sme_config);
14752 switch (chandef->width) {
14753 case NL80211_CHAN_WIDTH_20:
14754 if (sme_config.csrConfig.channelBondingMode24GHz !=
14755 eCSR_INI_SINGLE_CHANNEL_CENTERED) {
14756 sme_config.csrConfig.channelBondingMode24GHz =
14757 eCSR_INI_SINGLE_CHANNEL_CENTERED;
14758 sme_update_config(pHddCtx->hHal, &sme_config);
14759 cbModeChange = true;
14760 }
14761 break;
14762
14763 case NL80211_CHAN_WIDTH_40:
14764 if (sme_config.csrConfig.channelBondingMode24GHz ==
14765 eCSR_INI_SINGLE_CHANNEL_CENTERED) {
14766 if (NL80211_CHAN_HT40MINUS ==
14767 cfg80211_get_chandef_type(chandef))
14768 sme_config.csrConfig.channelBondingMode24GHz =
14769 eCSR_INI_DOUBLE_CHANNEL_HIGH_PRIMARY;
14770 else
14771 sme_config.csrConfig.channelBondingMode24GHz =
14772 eCSR_INI_DOUBLE_CHANNEL_LOW_PRIMARY;
14773 sme_update_config(pHddCtx->hHal, &sme_config);
14774 cbModeChange = true;
14775 }
14776 break;
14777
14778 default:
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014779 hdd_err("Error!!! Invalid HT20/40 mode !");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014780 return -EINVAL;
14781 }
14782
14783 if (!cbModeChange)
14784 return 0;
14785
Krunal Sonib4326f22016-03-10 13:05:51 -080014786 if (QDF_SAP_MODE != pAdapter->device_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014787 return 0;
14788
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014789 hdd_notice("Channel bonding changed to %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014790 sme_config.csrConfig.channelBondingMode24GHz);
14791
14792 /* Change SAP ht2040 mode */
14793 status = hdd_set_sap_ht2040_mode(pAdapter,
14794 cfg80211_get_chandef_type(chandef));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014795 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014796 hdd_err("Error!!! Cannot set SAP HT20/40 mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014797 return -EINVAL;
14798 }
14799
14800 return 0;
14801}
14802
14803/**
14804 * wlan_hdd_cfg80211_set_ap_channel_width() - set ap channel bandwidth
14805 * @wiphy: Pointer to wiphy
14806 * @dev: Pointer to network device
14807 * @chandef: Pointer to channel definition parameter
14808 *
14809 * Return: 0 for success, non-zero for failure
14810 */
14811static int
14812wlan_hdd_cfg80211_set_ap_channel_width(struct wiphy *wiphy,
14813 struct net_device *dev,
14814 struct cfg80211_chan_def *chandef)
14815{
14816 int ret;
14817
14818 cds_ssr_protect(__func__);
14819 ret = __wlan_hdd_cfg80211_set_ap_channel_width(wiphy, dev, chandef);
14820 cds_ssr_unprotect(__func__);
14821
14822 return ret;
14823}
14824#endif
14825
Abhishek Singh1bdb1572015-10-16 16:24:19 +053014826#ifdef CHANNEL_SWITCH_SUPPORTED
14827/**
14828 * __wlan_hdd_cfg80211_channel_switch()- function to switch
14829 * channel in SAP/GO
14830 * @wiphy: wiphy pointer
14831 * @dev: dev pointer.
14832 * @csa_params: Change channel params
14833 *
14834 * This function is called to switch channel in SAP/GO
14835 *
14836 * Return: 0 if success else return non zero
14837 */
14838static int __wlan_hdd_cfg80211_channel_switch(struct wiphy *wiphy,
14839 struct net_device *dev,
14840 struct cfg80211_csa_settings *csa_params)
14841{
14842 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
14843 hdd_context_t *hdd_ctx;
14844 uint8_t channel;
14845 uint16_t freq;
14846 int ret;
Kiran Kumar Lokere13644672016-02-29 15:40:10 -080014847 enum phy_ch_width ch_width;
Abhishek Singh1bdb1572015-10-16 16:24:19 +053014848
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014849 hdd_notice("Set Freq %d",
Abhishek Singh1bdb1572015-10-16 16:24:19 +053014850 csa_params->chandef.chan->center_freq);
14851
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014852 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
14853 hdd_err("invalid session id: %d", adapter->sessionId);
14854 return -EINVAL;
14855 }
14856
Abhishek Singh1bdb1572015-10-16 16:24:19 +053014857 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14858 ret = wlan_hdd_validate_context(hdd_ctx);
14859
14860 if (0 != ret)
14861 return ret;
14862
Krunal Sonib4326f22016-03-10 13:05:51 -080014863 if ((QDF_P2P_GO_MODE != adapter->device_mode) &&
14864 (QDF_SAP_MODE != adapter->device_mode))
Abhishek Singh1bdb1572015-10-16 16:24:19 +053014865 return -ENOTSUPP;
14866
14867 freq = csa_params->chandef.chan->center_freq;
14868 channel = cds_freq_to_chan(freq);
14869
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +053014870 ch_width = hdd_map_nl_chan_width(csa_params->chandef.width);
14871
14872 ret = hdd_softap_set_channel_change(dev, channel, ch_width);
Abhishek Singh1bdb1572015-10-16 16:24:19 +053014873 return ret;
14874}
14875
14876/**
14877 * wlan_hdd_cfg80211_channel_switch()- function to switch
14878 * channel in SAP/GO
14879 * @wiphy: wiphy pointer
14880 * @dev: dev pointer.
14881 * @csa_params: Change channel params
14882 *
14883 * This function is called to switch channel in SAP/GO
14884 *
14885 * Return: 0 if success else return non zero
14886 */
14887static int wlan_hdd_cfg80211_channel_switch(struct wiphy *wiphy,
14888 struct net_device *dev,
14889 struct cfg80211_csa_settings *csa_params)
14890{
14891 int ret;
14892
14893 cds_ssr_protect(__func__);
14894 ret = __wlan_hdd_cfg80211_channel_switch(wiphy, dev, csa_params);
14895 cds_ssr_unprotect(__func__);
14896 return ret;
14897}
14898#endif
14899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014900/**
14901 * wlan_hdd_convert_nl_iftype_to_hdd_type() - provides the type
14902 * translation from NL to policy manager type
14903 * @type: Generic connection mode type defined in NL
14904 *
14905 *
14906 * This function provides the type translation
14907 *
14908 * Return: cds_con_mode enum
14909 */
14910enum cds_con_mode wlan_hdd_convert_nl_iftype_to_hdd_type(
14911 enum nl80211_iftype type)
14912{
14913 enum cds_con_mode mode = CDS_MAX_NUM_OF_MODE;
14914 switch (type) {
14915 case NL80211_IFTYPE_STATION:
14916 mode = CDS_STA_MODE;
14917 break;
14918 case NL80211_IFTYPE_P2P_CLIENT:
14919 mode = CDS_P2P_CLIENT_MODE;
14920 break;
14921 case NL80211_IFTYPE_P2P_GO:
14922 mode = CDS_P2P_GO_MODE;
14923 break;
14924 case NL80211_IFTYPE_AP:
14925 mode = CDS_SAP_MODE;
14926 break;
14927 case NL80211_IFTYPE_ADHOC:
14928 mode = CDS_IBSS_MODE;
14929 break;
14930 default:
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014931 hdd_err("Unsupported interface type (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014932 type);
14933 }
14934 return mode;
14935}
14936
14937/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070014938 * wlan_hdd_cfg80211_set_mon_ch() - Set monitor mode capture channel
14939 * @wiphy: Handle to struct wiphy to get handle to module context.
14940 * @chandef: Contains information about the capture channel to be set.
14941 *
14942 * This interface is called if and only if monitor mode interface alone is
14943 * active.
14944 *
14945 * Return: 0 success or error code on failure.
14946 */
14947static int __wlan_hdd_cfg80211_set_mon_ch(struct wiphy *wiphy,
14948 struct cfg80211_chan_def *chandef)
14949{
14950 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
14951 hdd_adapter_t *adapter;
14952 hdd_station_ctx_t *sta_ctx;
14953 struct hdd_mon_set_ch_info *ch_info;
14954 QDF_STATUS status;
14955 tHalHandle hal_hdl;
14956 struct qdf_mac_addr bssid;
14957 tCsrRoamProfile roam_profile;
14958 struct ch_params_s ch_params;
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070014959 uint8_t sec_ch = 0;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070014960 int ret;
14961 uint16_t chan_num = cds_freq_to_chan(chandef->chan->center_freq);
14962
14963 ENTER();
14964
14965 ret = wlan_hdd_validate_context(hdd_ctx);
14966 if (ret)
14967 return ret;
14968
14969 hal_hdl = hdd_ctx->hHal;
14970
14971 adapter = hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
14972 if (!adapter)
14973 return -EIO;
14974
14975 hdd_info("%s: set monitor mode Channel %d and freq %d",
14976 adapter->dev->name, chan_num, chandef->chan->center_freq);
14977
14978 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14979 ch_info = &sta_ctx->ch_info;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070014980 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
14981 roam_profile.ChannelInfo.numOfChannels = 1;
14982 roam_profile.phyMode = ch_info->phy_mode;
14983 roam_profile.ch_params.ch_width = chandef->width;
Naveen Rawatc77e6e72016-08-05 15:19:03 -070014984 hdd_select_cbmode(adapter, chan_num, &roam_profile.ch_params);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070014985
14986 qdf_mem_copy(bssid.bytes, adapter->macAddressCurrent.bytes,
14987 QDF_MAC_ADDR_SIZE);
14988
14989 ch_params.ch_width = chandef->width;
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070014990 /*
14991 * CDS api expects secondary channel for calculating
14992 * the channel params
14993 */
14994 if ((ch_params.ch_width == CH_WIDTH_40MHZ) &&
14995 (CDS_IS_CHANNEL_24GHZ(chan_num))) {
14996 if (chan_num >= 1 && chan_num <= 5)
14997 sec_ch = chan_num + 4;
14998 else if (chan_num >= 6 && chan_num <= 13)
14999 sec_ch = chan_num - 4;
15000 }
15001 cds_set_channel_params(chan_num, sec_ch, &ch_params);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070015002 status = sme_roam_channel_change_req(hal_hdl, bssid, &ch_params,
15003 &roam_profile);
15004 if (status) {
15005 hdd_err("Status: %d Failed to set sme_RoamChannel for monitor mode",
15006 status);
15007 ret = qdf_status_to_os_return(status);
15008 return ret;
15009 }
15010 EXIT();
15011 return 0;
15012}
15013
15014/**
15015 * wlan_hdd_cfg80211_set_mon_ch() - Set monitor mode capture channel
15016 * @wiphy: Handle to struct wiphy to get handle to module context.
15017 * @chandef: Contains information about the capture channel to be set.
15018 *
15019 * This interface is called if and only if monitor mode interface alone is
15020 * active.
15021 *
15022 * Return: 0 success or error code on failure.
15023 */
15024static int wlan_hdd_cfg80211_set_mon_ch(struct wiphy *wiphy,
15025 struct cfg80211_chan_def *chandef)
15026{
15027 int ret;
15028
15029 cds_ssr_protect(__func__);
15030 ret = __wlan_hdd_cfg80211_set_mon_ch(wiphy, chandef);
15031 cds_ssr_unprotect(__func__);
15032 return ret;
15033}
15034
15035/**
Mahesh A Saptasagar6dda2022016-09-03 12:59:09 +053015036 * wlan_hdd_clear_link_layer_stats() - clear link layer stats
15037 * @adapter: pointer to adapter
15038 *
15039 * Wrapper function to clear link layer stats.
15040 * return - void
15041 */
15042void wlan_hdd_clear_link_layer_stats(hdd_adapter_t *adapter)
15043{
15044 tSirLLStatsClearReq link_layer_stats_clear_req;
15045 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
15046
Mukul Sharma491021c2016-09-29 21:39:19 +053015047 link_layer_stats_clear_req.statsClearReqMask = WIFI_STATS_IFACE_AC |
15048 WIFI_STATS_IFACE_ALL_PEER;
Mahesh A Saptasagar6dda2022016-09-03 12:59:09 +053015049 link_layer_stats_clear_req.stopReq = 0;
15050 link_layer_stats_clear_req.reqId = 1;
15051 link_layer_stats_clear_req.staId = adapter->sessionId;
15052 sme_ll_stats_clear_req(hal, &link_layer_stats_clear_req);
15053
15054 return;
15055}
15056
15057/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015058 * struct cfg80211_ops - cfg80211_ops
15059 *
15060 * @add_virtual_intf: Add virtual interface
15061 * @del_virtual_intf: Delete virtual interface
15062 * @change_virtual_intf: Change virtual interface
15063 * @change_station: Change station
15064 * @add_beacon: Add beacon in sap mode
15065 * @del_beacon: Delete beacon in sap mode
15066 * @set_beacon: Set beacon in sap mode
15067 * @start_ap: Start ap
15068 * @change_beacon: Change beacon
15069 * @stop_ap: Stop ap
15070 * @change_bss: Change bss
15071 * @add_key: Add key
15072 * @get_key: Get key
15073 * @del_key: Delete key
15074 * @set_default_key: Set default key
15075 * @set_channel: Set channel
15076 * @scan: Scan
15077 * @connect: Connect
15078 * @disconnect: Disconnect
15079 * @join_ibss = Join ibss
15080 * @leave_ibss = Leave ibss
15081 * @set_wiphy_params = Set wiphy params
15082 * @set_tx_power = Set tx power
15083 * @get_tx_power = get tx power
15084 * @remain_on_channel = Remain on channel
15085 * @cancel_remain_on_channel = Cancel remain on channel
15086 * @mgmt_tx = Tx management frame
15087 * @mgmt_tx_cancel_wait = Cancel management tx wait
15088 * @set_default_mgmt_key = Set default management key
15089 * @set_txq_params = Set tx queue parameters
15090 * @get_station = Get station
15091 * @set_power_mgmt = Set power management
15092 * @del_station = Delete station
15093 * @add_station = Add station
15094 * @set_pmksa = Set pmksa
15095 * @del_pmksa = Delete pmksa
15096 * @flush_pmksa = Flush pmksa
15097 * @update_ft_ies = Update FT IEs
15098 * @tdls_mgmt = Tdls management
15099 * @tdls_oper = Tdls operation
15100 * @set_rekey_data = Set rekey data
15101 * @sched_scan_start = Scheduled scan start
15102 * @sched_scan_stop = Scheduled scan stop
15103 * @resume = Resume wlan
15104 * @suspend = Suspend wlan
15105 * @set_mac_acl = Set mac acl
15106 * @testmode_cmd = Test mode command
15107 * @set_ap_chanwidth = Set AP channel bandwidth
15108 * @dump_survey = Dump survey
15109 * @key_mgmt_set_pmk = Set pmk key management
15110 */
15111static struct cfg80211_ops wlan_hdd_cfg80211_ops = {
15112 .add_virtual_intf = wlan_hdd_add_virtual_intf,
15113 .del_virtual_intf = wlan_hdd_del_virtual_intf,
15114 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
15115 .change_station = wlan_hdd_change_station,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015116 .start_ap = wlan_hdd_cfg80211_start_ap,
15117 .change_beacon = wlan_hdd_cfg80211_change_beacon,
15118 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015119 .change_bss = wlan_hdd_cfg80211_change_bss,
15120 .add_key = wlan_hdd_cfg80211_add_key,
15121 .get_key = wlan_hdd_cfg80211_get_key,
15122 .del_key = wlan_hdd_cfg80211_del_key,
15123 .set_default_key = wlan_hdd_cfg80211_set_default_key,
15124 .scan = wlan_hdd_cfg80211_scan,
15125 .connect = wlan_hdd_cfg80211_connect,
15126 .disconnect = wlan_hdd_cfg80211_disconnect,
15127 .join_ibss = wlan_hdd_cfg80211_join_ibss,
15128 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
15129 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
15130 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
15131 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
15132 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
15133 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
15134 .mgmt_tx = wlan_hdd_mgmt_tx,
15135 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
15136 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
15137 .set_txq_params = wlan_hdd_set_txq_params,
Himanshu Agarwal37e42412016-07-21 14:35:09 +053015138 .dump_station = wlan_hdd_cfg80211_dump_station,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015139 .get_station = wlan_hdd_cfg80211_get_station,
15140 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
15141 .del_station = wlan_hdd_cfg80211_del_station,
15142 .add_station = wlan_hdd_cfg80211_add_station,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015143 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
15144 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
15145 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
Deepak Dhamdhere9f09e752016-01-09 23:17:25 -080015146#if defined(KERNEL_SUPPORT_11R_CFG80211)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015147 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
15148#endif
15149#ifdef FEATURE_WLAN_TDLS
15150 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
15151 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
15152#endif
15153#ifdef WLAN_FEATURE_GTK_OFFLOAD
15154 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
15155#endif /* WLAN_FEATURE_GTK_OFFLOAD */
15156#ifdef FEATURE_WLAN_SCAN_PNO
15157 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
15158 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
15159#endif /*FEATURE_WLAN_SCAN_PNO */
15160 .resume = wlan_hdd_cfg80211_resume_wlan,
15161 .suspend = wlan_hdd_cfg80211_suspend_wlan,
15162 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
15163#ifdef WLAN_NL80211_TESTMODE
15164 .testmode_cmd = wlan_hdd_cfg80211_testmode,
15165#endif
15166#ifdef QCA_HT_2040_COEX
15167 .set_ap_chanwidth = wlan_hdd_cfg80211_set_ap_channel_width,
15168#endif
15169 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Abhishek Singh1bdb1572015-10-16 16:24:19 +053015170#ifdef CHANNEL_SWITCH_SUPPORTED
15171 .channel_switch = wlan_hdd_cfg80211_channel_switch,
15172#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070015173 .set_monitor_channel = wlan_hdd_cfg80211_set_mon_ch,
Vidyullatha, Kanchanapally528789e2016-05-11 20:38:37 +053015174#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)) || \
15175 defined(CFG80211_ABORT_SCAN)
15176 .abort_scan = wlan_hdd_cfg80211_abort_scan,
15177#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015178};