blob: 5e7f8e78bfdd21cce61047200b4fd021bd902f69 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Paul Zhang3a210c52016-12-08 10:18:12 +08002 * Copyright (c) 2012-2017 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
35#include <linux/version.h>
36#include <linux/module.h>
37#include <linux/kernel.h>
38#include <linux/init.h>
39#include <linux/etherdevice.h>
40#include <linux/wireless.h>
41#include <wlan_hdd_includes.h>
42#include <net/arp.h>
43#include <net/cfg80211.h>
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053044#include <qdf_trace.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080045#include <wlan_hdd_wowl.h>
46#include <ani_global.h>
47#include "sir_params.h"
48#include "dot11f.h"
49#include "wlan_hdd_assoc.h"
50#include "wlan_hdd_wext.h"
51#include "sme_api.h"
Peng Xu278d0122015-09-24 16:34:17 -070052#include "sme_power_save_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080053#include "wlan_hdd_p2p.h"
54#include "wlan_hdd_cfg80211.h"
55#include "wlan_hdd_hostapd.h"
56#include "wlan_hdd_softap_tx_rx.h"
57#include "wlan_hdd_main.h"
58#include "wlan_hdd_power.h"
59#include "wlan_hdd_trace.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053060#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053061#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062#include "cds_utils.h"
63#include "cds_sched.h"
64#include "wlan_hdd_scan.h"
65#include <qc_sap_ioctl.h>
66#include "wlan_hdd_tdls.h"
67#include "wlan_hdd_wmm.h"
68#include "wma_types.h"
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053069#include "wma.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080070#include "wlan_hdd_misc.h"
71#include "wlan_hdd_nan.h"
72#include <wlan_hdd_ipa.h>
73#include "wlan_logging_sock_svc.h"
Agrawal Ashish65634612016-08-18 13:24:32 +053074#include "sap_api.h"
Agrawal Ashish21ba2572016-09-03 16:40:10 +053075#include "csr_api.h"
Agrawal Ashish467dde42016-09-08 18:44:22 +053076#include "pld_common.h"
Agrawal Ashish65634612016-08-18 13:24:32 +053077
Paul Zhang3a210c52016-12-08 10:18:12 +080078#ifdef WLAN_UMAC_CONVERGENCE
79#include "wlan_cfg80211.h"
80#endif
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
Jeff Johnsonf3826e12017-01-12 09:49:40 -0800307 * TX/RX direction for each kind of interface
308 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800309static const struct ieee80211_txrx_stypes
310 wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
311 [NL80211_IFTYPE_STATION] = {
312 .tx = 0xffff,
313 .rx = BIT(SIR_MAC_MGMT_ACTION) |
314 BIT(SIR_MAC_MGMT_PROBE_REQ),
315 },
316 [NL80211_IFTYPE_AP] = {
317 .tx = 0xffff,
318 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
319 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
320 BIT(SIR_MAC_MGMT_PROBE_REQ) |
321 BIT(SIR_MAC_MGMT_DISASSOC) |
322 BIT(SIR_MAC_MGMT_AUTH) |
323 BIT(SIR_MAC_MGMT_DEAUTH) |
324 BIT(SIR_MAC_MGMT_ACTION),
325 },
326 [NL80211_IFTYPE_ADHOC] = {
327 .tx = 0xffff,
328 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
329 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
330 BIT(SIR_MAC_MGMT_PROBE_REQ) |
331 BIT(SIR_MAC_MGMT_DISASSOC) |
332 BIT(SIR_MAC_MGMT_AUTH) |
333 BIT(SIR_MAC_MGMT_DEAUTH) |
334 BIT(SIR_MAC_MGMT_ACTION),
335 },
336 [NL80211_IFTYPE_P2P_CLIENT] = {
337 .tx = 0xffff,
338 .rx = BIT(SIR_MAC_MGMT_ACTION) |
339 BIT(SIR_MAC_MGMT_PROBE_REQ),
340 },
341 [NL80211_IFTYPE_P2P_GO] = {
342 /* This is also same as for SoftAP */
343 .tx = 0xffff,
344 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
345 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
346 BIT(SIR_MAC_MGMT_PROBE_REQ) |
347 BIT(SIR_MAC_MGMT_DISASSOC) |
348 BIT(SIR_MAC_MGMT_AUTH) |
349 BIT(SIR_MAC_MGMT_DEAUTH) |
350 BIT(SIR_MAC_MGMT_ACTION),
351 },
352};
353
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800354/* Interface limits and combinations registered by the driver */
355
356/* STA ( + STA ) combination */
357static const struct ieee80211_iface_limit
358 wlan_hdd_sta_iface_limit[] = {
359 {
360 .max = 3, /* p2p0 is a STA as well */
361 .types = BIT(NL80211_IFTYPE_STATION),
362 },
363};
364
365/* ADHOC (IBSS) limit */
366static const struct ieee80211_iface_limit
367 wlan_hdd_adhoc_iface_limit[] = {
368 {
369 .max = 1,
370 .types = BIT(NL80211_IFTYPE_STATION),
371 },
372 {
373 .max = 1,
374 .types = BIT(NL80211_IFTYPE_ADHOC),
375 },
376};
377
378/* AP ( + AP ) combination */
379static const struct ieee80211_iface_limit
380 wlan_hdd_ap_iface_limit[] = {
381 {
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530382 .max = (QDF_MAX_NO_OF_SAP_MODE + SAP_MAX_OBSS_STA_CNT),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 .types = BIT(NL80211_IFTYPE_AP),
384 },
385};
386
387/* P2P limit */
388static const struct ieee80211_iface_limit
389 wlan_hdd_p2p_iface_limit[] = {
390 {
391 .max = 1,
392 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
393 },
394 {
395 .max = 1,
396 .types = BIT(NL80211_IFTYPE_P2P_GO),
397 },
398};
399
400static const struct ieee80211_iface_limit
401 wlan_hdd_sta_ap_iface_limit[] = {
402 {
403 /* We need 1 extra STA interface for OBSS scan when SAP starts
404 * with HT40 in STA+SAP concurrency mode
405 */
406 .max = (1 + SAP_MAX_OBSS_STA_CNT),
407 .types = BIT(NL80211_IFTYPE_STATION),
408 },
409 {
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530410 .max = QDF_MAX_NO_OF_SAP_MODE,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800411 .types = BIT(NL80211_IFTYPE_AP),
412 },
413};
414
415/* STA + P2P combination */
416static const struct ieee80211_iface_limit
417 wlan_hdd_sta_p2p_iface_limit[] = {
418 {
419 /* One reserved for dedicated P2PDEV usage */
420 .max = 2,
421 .types = BIT(NL80211_IFTYPE_STATION)
422 },
423 {
424 /* Support for two identical (GO + GO or CLI + CLI)
425 * or dissimilar (GO + CLI) P2P interfaces
426 */
427 .max = 2,
428 .types = BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT),
429 },
430};
431
432/* STA + AP + P2PGO combination */
433static const struct ieee80211_iface_limit
434wlan_hdd_sta_ap_p2pgo_iface_limit[] = {
435 /* Support for AP+P2PGO interfaces */
436 {
437 .max = 2,
438 .types = BIT(NL80211_IFTYPE_STATION)
439 },
440 {
441 .max = 1,
442 .types = BIT(NL80211_IFTYPE_P2P_GO)
443 },
444 {
445 .max = 1,
446 .types = BIT(NL80211_IFTYPE_AP)
447 }
448};
449
450/* SAP + P2P combination */
451static const struct ieee80211_iface_limit
452wlan_hdd_sap_p2p_iface_limit[] = {
453 {
454 /* 1 dedicated for p2p0 which is a STA type */
455 .max = 1,
456 .types = BIT(NL80211_IFTYPE_STATION)
457 },
458 {
459 /* The p2p interface in SAP+P2P can be GO/CLI.
460 * The p2p connection can be formed on p2p0 or p2p-p2p0-x.
461 */
462 .max = 1,
463 .types = BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT)
464 },
465 {
466 /* SAP+GO to support only one SAP interface */
467 .max = 1,
468 .types = BIT(NL80211_IFTYPE_AP)
469 }
470};
471
472/* P2P + P2P combination */
473static const struct ieee80211_iface_limit
474wlan_hdd_p2p_p2p_iface_limit[] = {
475 {
476 /* 1 dedicated for p2p0 which is a STA type */
477 .max = 1,
478 .types = BIT(NL80211_IFTYPE_STATION)
479 },
480 {
481 /* The p2p interface in P2P+P2P can be GO/CLI.
482 * For P2P+P2P, the new interfaces are formed on p2p-p2p0-x.
483 */
484 .max = 2,
485 .types = BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT)
486 },
487};
488
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -0700489static const struct ieee80211_iface_limit
490 wlan_hdd_mon_iface_limit[] = {
491 {
492 .max = 3, /* Monitor interface */
493 .types = BIT(NL80211_IFTYPE_MONITOR),
494 },
495};
496
497static struct ieee80211_iface_combination
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498 wlan_hdd_iface_combination[] = {
499 /* STA */
500 {
501 .limits = wlan_hdd_sta_iface_limit,
502 .num_different_channels = 2,
503 .max_interfaces = 3,
504 .n_limits = ARRAY_SIZE(wlan_hdd_sta_iface_limit),
505 },
506 /* ADHOC */
507 {
508 .limits = wlan_hdd_adhoc_iface_limit,
Krunal Soni2c68f232015-10-26 20:52:51 -0700509 .num_different_channels = 2,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800510 .max_interfaces = 2,
511 .n_limits = ARRAY_SIZE(wlan_hdd_adhoc_iface_limit),
512 },
513 /* AP */
514 {
515 .limits = wlan_hdd_ap_iface_limit,
516 .num_different_channels = 2,
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530517 .max_interfaces = (SAP_MAX_OBSS_STA_CNT + QDF_MAX_NO_OF_SAP_MODE),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800518 .n_limits = ARRAY_SIZE(wlan_hdd_ap_iface_limit),
519 },
520 /* P2P */
521 {
522 .limits = wlan_hdd_p2p_iface_limit,
523 .num_different_channels = 2,
524 .max_interfaces = 2,
525 .n_limits = ARRAY_SIZE(wlan_hdd_p2p_iface_limit),
526 },
527 /* STA + AP */
528 {
529 .limits = wlan_hdd_sta_ap_iface_limit,
530 .num_different_channels = 2,
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530531 .max_interfaces = (1 + SAP_MAX_OBSS_STA_CNT + QDF_MAX_NO_OF_SAP_MODE),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800532 .n_limits = ARRAY_SIZE(wlan_hdd_sta_ap_iface_limit),
533 .beacon_int_infra_match = true,
534 },
535 /* STA + P2P */
536 {
537 .limits = wlan_hdd_sta_p2p_iface_limit,
538 .num_different_channels = 2,
539 /* one interface reserved for P2PDEV dedicated usage */
540 .max_interfaces = 4,
541 .n_limits = ARRAY_SIZE(wlan_hdd_sta_p2p_iface_limit),
542 .beacon_int_infra_match = true,
543 },
544 /* STA + P2P GO + SAP */
545 {
546 .limits = wlan_hdd_sta_ap_p2pgo_iface_limit,
547 /* we can allow 3 channels for three different persona
548 * but due to firmware limitation, allow max 2 concrnt channels.
549 */
550 .num_different_channels = 2,
551 /* one interface reserved for P2PDEV dedicated usage */
552 .max_interfaces = 4,
553 .n_limits = ARRAY_SIZE(wlan_hdd_sta_ap_p2pgo_iface_limit),
554 .beacon_int_infra_match = true,
555 },
556 /* SAP + P2P */
557 {
558 .limits = wlan_hdd_sap_p2p_iface_limit,
559 .num_different_channels = 2,
560 /* 1-p2p0 + 1-SAP + 1-P2P (on p2p0 or p2p-p2p0-x) */
561 .max_interfaces = 3,
562 .n_limits = ARRAY_SIZE(wlan_hdd_sap_p2p_iface_limit),
563 .beacon_int_infra_match = true,
564 },
565 /* P2P + P2P */
566 {
567 .limits = wlan_hdd_p2p_p2p_iface_limit,
568 .num_different_channels = 2,
569 /* 1-p2p0 + 2-P2P (on p2p-p2p0-x) */
570 .max_interfaces = 3,
571 .n_limits = ARRAY_SIZE(wlan_hdd_p2p_p2p_iface_limit),
572 .beacon_int_infra_match = true,
573 },
Arun Khandavallifae92942016-08-01 13:31:08 +0530574 /* Monitor */
575 {
576 .limits = wlan_hdd_mon_iface_limit,
577 .max_interfaces = 3,
578 .num_different_channels = 2,
579 .n_limits = ARRAY_SIZE(wlan_hdd_mon_iface_limit),
580 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800581};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800582
583static struct cfg80211_ops wlan_hdd_cfg80211_ops;
Arun Khandavalli2476ef52016-04-26 20:19:43 +0530584struct hdd_bpf_context bpf_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800585
586#ifdef WLAN_NL80211_TESTMODE
587enum wlan_hdd_tm_attr {
588 WLAN_HDD_TM_ATTR_INVALID = 0,
589 WLAN_HDD_TM_ATTR_CMD = 1,
590 WLAN_HDD_TM_ATTR_DATA = 2,
591 WLAN_HDD_TM_ATTR_STREAM_ID = 3,
592 WLAN_HDD_TM_ATTR_TYPE = 4,
593 /* keep last */
594 WLAN_HDD_TM_ATTR_AFTER_LAST,
595 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
596};
597
598enum wlan_hdd_tm_cmd {
599 WLAN_HDD_TM_CMD_WLAN_FTM = 0,
600 WLAN_HDD_TM_CMD_WLAN_HB = 1,
601};
602
603#define WLAN_HDD_TM_DATA_MAX_LEN 5000
604
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +0530605enum wlan_hdd_vendor_ie_access_policy {
606 WLAN_HDD_VENDOR_IE_ACCESS_NONE = 0,
607 WLAN_HDD_VENDOR_IE_ACCESS_ALLOW_IF_LISTED,
608};
609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800610static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] = {
611 [WLAN_HDD_TM_ATTR_CMD] = {.type = NLA_U32},
612 [WLAN_HDD_TM_ATTR_DATA] = {.type = NLA_BINARY,
613 .len = WLAN_HDD_TM_DATA_MAX_LEN},
614};
615#endif /* WLAN_NL80211_TESTMODE */
616
617#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
618static const struct wiphy_wowlan_support wowlan_support_cfg80211_init = {
619 .flags = WIPHY_WOWLAN_MAGIC_PKT,
620 .n_patterns = WOWL_MAX_PTRNS_ALLOWED,
621 .pattern_min_len = 1,
622 .pattern_max_len = WOWL_PTRN_MAX_SIZE,
623};
624#endif
625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626/**
Abhishek Singh1bdb1572015-10-16 16:24:19 +0530627 * hdd_add_channel_switch_support()- Adds Channel Switch flag if supported
628 * @flags: Pointer to the flags to Add channel switch flag.
629 *
630 * This Function adds Channel Switch support flag, if channel switch is
631 * supported by kernel.
632 * Return: void.
633 */
634#ifdef CHANNEL_SWITCH_SUPPORTED
635static inline void hdd_add_channel_switch_support(uint32_t *flags)
636{
Krishna Kumaar Natarajan8a8df262015-12-04 11:43:46 -0800637 *flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Abhishek Singh1bdb1572015-10-16 16:24:19 +0530638 return;
639}
640#else
641static inline void hdd_add_channel_switch_support(uint32_t *flags)
642{
643 return;
644}
645#endif
646
Manikandan Mohan22b83722015-12-15 15:03:23 -0800647#ifdef FEATURE_WLAN_TDLS
648
649/* TDLS capabilities params */
650#define PARAM_MAX_TDLS_SESSION \
651 QCA_WLAN_VENDOR_ATTR_TDLS_GET_CAPS_MAX_CONC_SESSIONS
652#define PARAM_TDLS_FEATURE_SUPPORT \
653 QCA_WLAN_VENDOR_ATTR_TDLS_GET_CAPS_FEATURES_SUPPORTED
654
Abhishek Singh1bdb1572015-10-16 16:24:19 +0530655/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800656 * __wlan_hdd_cfg80211_get_tdls_capabilities() - Provide TDLS Capabilites.
657 * @wiphy: WIPHY structure pointer
658 * @wdev: Wireless device structure pointer
659 * @data: Pointer to the data received
660 * @data_len: Length of the data received
661 *
662 * This function provides TDLS capabilities
663 *
664 * Return: 0 on success and errno on failure
665 */
666static int __wlan_hdd_cfg80211_get_tdls_capabilities(struct wiphy *wiphy,
667 struct wireless_dev *wdev,
668 const void *data,
669 int data_len)
670{
671 int status;
672 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
673 struct sk_buff *skb;
674 uint32_t set = 0;
675
Jeff Johnson1f61b612016-02-12 16:28:33 -0800676 ENTER_DEV(wdev->netdev);
677
Anurag Chouhan6d760662016-02-20 16:05:43 +0530678 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800679 hdd_err("Command not allowed in FTM mode");
680 return -EPERM;
681 }
682
683 status = wlan_hdd_validate_context(hdd_ctx);
684 if (status)
685 return status;
686
687 skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, (2 * sizeof(u32)) +
688 NLMSG_HDRLEN);
689 if (!skb) {
Jeff Johnson020db452016-06-29 14:37:26 -0700690 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 goto fail;
692 }
693
694 if (false == hdd_ctx->config->fEnableTDLSSupport) {
Jeff Johnson020db452016-06-29 14:37:26 -0700695 hdd_err("TDLS feature not Enabled or Not supported in FW");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800696 if (nla_put_u32(skb, PARAM_MAX_TDLS_SESSION, 0) ||
697 nla_put_u32(skb, PARAM_TDLS_FEATURE_SUPPORT, 0)) {
Jeff Johnson020db452016-06-29 14:37:26 -0700698 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800699 goto fail;
700 }
701 } else {
702 set = set | WIFI_TDLS_SUPPORT;
703 set = set | (hdd_ctx->config->fTDLSExternalControl ?
704 WIFI_TDLS_EXTERNAL_CONTROL_SUPPORT : 0);
705 set = set | (hdd_ctx->config->fEnableTDLSOffChannel ?
706 WIIF_TDLS_OFFCHANNEL_SUPPORT : 0);
Jeff Johnson020db452016-06-29 14:37:26 -0700707 hdd_notice("TDLS Feature supported value %x", set);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800708 if (nla_put_u32(skb, PARAM_MAX_TDLS_SESSION,
709 hdd_ctx->max_num_tdls_sta) ||
710 nla_put_u32(skb, PARAM_TDLS_FEATURE_SUPPORT,
711 set)) {
Jeff Johnson020db452016-06-29 14:37:26 -0700712 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713 goto fail;
714 }
715 }
716 return cfg80211_vendor_cmd_reply(skb);
717fail:
718 if (skb)
719 kfree_skb(skb);
720 return -EINVAL;
721}
722
723/**
724 * wlan_hdd_cfg80211_get_tdls_capabilities() - Provide TDLS Capabilites.
725 * @wiphy: WIPHY structure pointer
726 * @wdev: Wireless device structure pointer
727 * @data: Pointer to the data received
728 * @data_len: Length of the data received
729 *
730 * This function provides TDLS capabilities
731 *
732 * Return: 0 on success and errno on failure
733 */
734static int
735wlan_hdd_cfg80211_get_tdls_capabilities(struct wiphy *wiphy,
736 struct wireless_dev *wdev,
737 const void *data,
738 int data_len)
739{
740 int ret;
741
742 cds_ssr_protect(__func__);
743 ret = __wlan_hdd_cfg80211_get_tdls_capabilities(wiphy, wdev,
744 data, data_len);
745 cds_ssr_unprotect(__func__);
746
747 return ret;
748}
749#endif
750
751#ifdef QCA_HT_2040_COEX
752static void wlan_hdd_cfg80211_start_pending_acs(struct work_struct *work);
753#endif
754
755#if defined(FEATURE_WLAN_CH_AVOID) || defined(FEATURE_WLAN_FORCE_SAP_SCC)
756/*
757 * FUNCTION: wlan_hdd_send_avoid_freq_event
758 * This is called when wlan driver needs to send vendor specific
759 * avoid frequency range event to userspace
760 */
761int wlan_hdd_send_avoid_freq_event(hdd_context_t *pHddCtx,
762 tHddAvoidFreqList *pAvoidFreqList)
763{
764 struct sk_buff *vendor_event;
765
766 ENTER();
767
768 if (!pHddCtx) {
Jeff Johnson020db452016-06-29 14:37:26 -0700769 hdd_err("HDD context is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770 return -EINVAL;
771 }
772
773 if (!pAvoidFreqList) {
Jeff Johnson020db452016-06-29 14:37:26 -0700774 hdd_err("pAvoidFreqList is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 return -EINVAL;
776 }
777
778 vendor_event = cfg80211_vendor_event_alloc(pHddCtx->wiphy,
779 NULL,
780 sizeof(tHddAvoidFreqList),
781 QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX,
782 GFP_KERNEL);
783 if (!vendor_event) {
Jeff Johnson020db452016-06-29 14:37:26 -0700784 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800785 return -EINVAL;
786 }
787
788 memcpy(skb_put(vendor_event, sizeof(tHddAvoidFreqList)),
789 (void *)pAvoidFreqList, sizeof(tHddAvoidFreqList));
790
791 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
792
793 EXIT();
794 return 0;
795}
796#endif /* FEATURE_WLAN_CH_AVOID || FEATURE_WLAN_FORCE_SAP_SCC */
797
798/* vendor specific events */
799static const struct nl80211_vendor_cmd_info wlan_hdd_cfg80211_vendor_events[] = {
800#ifdef FEATURE_WLAN_CH_AVOID
801 [QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX] = {
802 .vendor_id =
803 QCA_NL80211_VENDOR_ID,
804 .subcmd =
805 QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY
806 },
807#endif /* FEATURE_WLAN_CH_AVOID */
808
809#ifdef WLAN_FEATURE_NAN
810 [QCA_NL80211_VENDOR_SUBCMD_NAN_INDEX] = {
811 .vendor_id =
812 QCA_NL80211_VENDOR_ID,
813 .subcmd =
814 QCA_NL80211_VENDOR_SUBCMD_NAN
815 },
816#endif
817
818#ifdef WLAN_FEATURE_STATS_EXT
819 [QCA_NL80211_VENDOR_SUBCMD_STATS_EXT_INDEX] = {
820 .vendor_id =
821 QCA_NL80211_VENDOR_ID,
822 .subcmd =
823 QCA_NL80211_VENDOR_SUBCMD_STATS_EXT
824 },
825#endif /* WLAN_FEATURE_STATS_EXT */
826#ifdef FEATURE_WLAN_EXTSCAN
827 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_START_INDEX] = {
828 .vendor_id =
829 QCA_NL80211_VENDOR_ID,
830 .subcmd =
831 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_START
832 },
833 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_STOP_INDEX] = {
834 .vendor_id =
835 QCA_NL80211_VENDOR_ID,
836 .subcmd =
837 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_STOP
838 },
839 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CAPABILITIES_INDEX] = {
840 .
841 vendor_id
842 =
843 QCA_NL80211_VENDOR_ID,
844 .subcmd =
845 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CAPABILITIES
846 },
847 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CACHED_RESULTS_INDEX] = {
848 .
849 vendor_id
850 =
851 QCA_NL80211_VENDOR_ID,
852 .
853 subcmd =
854 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CACHED_RESULTS
855 },
856 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SCAN_RESULTS_AVAILABLE_INDEX] = {
857 .
858 vendor_id
859 =
860 QCA_NL80211_VENDOR_ID,
861 .
862 subcmd
863 =
864 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SCAN_RESULTS_AVAILABLE
865 },
866 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_FULL_SCAN_RESULT_INDEX] = {
867 .
868 vendor_id
869 =
870 QCA_NL80211_VENDOR_ID,
871 .subcmd =
872 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_FULL_SCAN_RESULT
873 },
874 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SCAN_EVENT_INDEX] = {
875 .vendor_id =
876 QCA_NL80211_VENDOR_ID,
877 .subcmd =
878 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SCAN_EVENT
879 },
880 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_AP_FOUND_INDEX] = {
881 .
882 vendor_id
883 =
884 QCA_NL80211_VENDOR_ID,
885 .subcmd =
886 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_AP_FOUND
887 },
888 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_BSSID_HOTLIST_INDEX] = {
889 .
890 vendor_id
891 =
892 QCA_NL80211_VENDOR_ID,
893 .subcmd =
894 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_BSSID_HOTLIST
895 },
896 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_BSSID_HOTLIST_INDEX] = {
897 .
898 vendor_id
899 =
900 QCA_NL80211_VENDOR_ID,
901 .
902 subcmd
903 =
904 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_BSSID_HOTLIST
905 },
906 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SIGNIFICANT_CHANGE_INDEX] = {
907 .
908 vendor_id
909 =
910 QCA_NL80211_VENDOR_ID,
911 .
912 subcmd =
913 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SIGNIFICANT_CHANGE
914 },
915 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SIGNIFICANT_CHANGE_INDEX] = {
916 .
917 vendor_id
918 =
919 QCA_NL80211_VENDOR_ID,
920 .
921 subcmd
922 =
923 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SIGNIFICANT_CHANGE
924 },
925 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SIGNIFICANT_CHANGE_INDEX] = {
926 .
927 vendor_id
928 =
929 QCA_NL80211_VENDOR_ID,
930 .
931 subcmd
932 =
933 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SIGNIFICANT_CHANGE
934 },
935 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_SSID_FOUND_INDEX] = {
936 .vendor_id = QCA_NL80211_VENDOR_ID,
937 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_SSID_FOUND
938 },
939 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_SSID_LOST_INDEX] = {
940 .vendor_id = QCA_NL80211_VENDOR_ID,
941 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_SSID_LOST
942 },
943#endif /* FEATURE_WLAN_EXTSCAN */
944
945#ifdef WLAN_FEATURE_LINK_LAYER_STATS
946 [QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET_INDEX] = {
947 .vendor_id =
948 QCA_NL80211_VENDOR_ID,
949 .subcmd =
950 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET
951 },
952 [QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET_INDEX] = {
953 .vendor_id =
954 QCA_NL80211_VENDOR_ID,
955 .subcmd =
956 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET
957 },
958 [QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR_INDEX] = {
959 .vendor_id =
960 QCA_NL80211_VENDOR_ID,
961 .subcmd =
962 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR
963 },
964 [QCA_NL80211_VENDOR_SUBCMD_LL_RADIO_STATS_INDEX] = {
965 .vendor_id =
966 QCA_NL80211_VENDOR_ID,
967 .subcmd =
968 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_RADIO_RESULTS
969 },
970 [QCA_NL80211_VENDOR_SUBCMD_LL_IFACE_STATS_INDEX] = {
971 .vendor_id =
972 QCA_NL80211_VENDOR_ID,
973 .subcmd =
974 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_IFACE_RESULTS
975 },
976 [QCA_NL80211_VENDOR_SUBCMD_LL_PEER_INFO_STATS_INDEX] = {
977 .vendor_id =
978 QCA_NL80211_VENDOR_ID,
979 .subcmd =
980 QCA_NL80211_VENDOR_SUBCMD_LL_STATS_PEERS_RESULTS
981 },
982#endif /* WLAN_FEATURE_LINK_LAYER_STATS */
983 [QCA_NL80211_VENDOR_SUBCMD_TDLS_STATE_CHANGE_INDEX] = {
984 .vendor_id =
985 QCA_NL80211_VENDOR_ID,
986 .subcmd =
987 QCA_NL80211_VENDOR_SUBCMD_TDLS_STATE
988 },
989 [QCA_NL80211_VENDOR_SUBCMD_DO_ACS_INDEX] = {
990 .vendor_id = QCA_NL80211_VENDOR_ID,
991 .subcmd = QCA_NL80211_VENDOR_SUBCMD_DO_ACS
992 },
993#ifdef WLAN_FEATURE_ROAM_OFFLOAD
994 [QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_ROAM_AUTH_INDEX] = {
995 .vendor_id =
996 QCA_NL80211_VENDOR_ID,
997 .subcmd =
998 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_ROAM_AUTH
999 },
1000#endif
1001 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_STARTED_INDEX] = {
1002 .vendor_id =
1003 QCA_NL80211_VENDOR_ID,
1004 .subcmd =
1005 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_STARTED
1006 },
1007 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_FINISHED_INDEX] = {
1008 .vendor_id =
1009 QCA_NL80211_VENDOR_ID,
1010 .subcmd =
1011 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_FINISHED
1012 },
1013 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_ABORTED_INDEX] = {
1014 .vendor_id =
1015 QCA_NL80211_VENDOR_ID,
1016 .subcmd =
1017 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_ABORTED
1018 },
1019 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_NOP_FINISHED_INDEX] = {
1020 .vendor_id =
1021 QCA_NL80211_VENDOR_ID,
1022 .subcmd =
1023 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_NOP_FINISHED
1024 },
1025 [QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_RADAR_DETECTED_INDEX] = {
1026 .vendor_id =
1027 QCA_NL80211_VENDOR_ID,
1028 .subcmd =
1029 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_RADAR_DETECTED
1030 },
1031#ifdef FEATURE_WLAN_EXTSCAN
1032 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_NETWORK_FOUND_INDEX] = {
1033 .vendor_id = QCA_NL80211_VENDOR_ID,
1034 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_NETWORK_FOUND
1035 },
1036 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_PASSPOINT_NETWORK_FOUND_INDEX] = {
1037 .vendor_id = QCA_NL80211_VENDOR_ID,
1038 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_PASSPOINT_NETWORK_FOUND
1039 },
1040 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SSID_HOTLIST_INDEX] = {
1041 .vendor_id = QCA_NL80211_VENDOR_ID,
1042 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SSID_HOTLIST
1043 },
1044 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SSID_HOTLIST_INDEX] = {
1045 .vendor_id = QCA_NL80211_VENDOR_ID,
1046 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SSID_HOTLIST
1047 },
1048 [QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_AP_LOST_INDEX] = {
1049 .vendor_id = QCA_NL80211_VENDOR_ID,
1050 .subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_HOTLIST_AP_LOST
1051 },
1052#endif /* FEATURE_WLAN_EXTSCAN */
1053 [QCA_NL80211_VENDOR_SUBCMD_MONITOR_RSSI_INDEX] = {
1054 .vendor_id = QCA_NL80211_VENDOR_ID,
1055 .subcmd = QCA_NL80211_VENDOR_SUBCMD_MONITOR_RSSI
1056 },
1057#ifdef WLAN_FEATURE_MEMDUMP
1058 [QCA_NL80211_VENDOR_SUBCMD_WIFI_LOGGER_MEMORY_DUMP_INDEX] = {
1059 .vendor_id = QCA_NL80211_VENDOR_ID,
1060 .subcmd = QCA_NL80211_VENDOR_SUBCMD_WIFI_LOGGER_MEMORY_DUMP
1061 },
1062#endif /* WLAN_FEATURE_MEMDUMP */
Manikandan Mohan5356c2b2016-04-03 15:51:35 -07001063#ifdef WLAN_FEATURE_TSF
1064 [QCA_NL80211_VENDOR_SUBCMD_TSF_INDEX] = {
1065 .vendor_id = QCA_NL80211_VENDOR_ID,
1066 .subcmd = QCA_NL80211_VENDOR_SUBCMD_TSF
1067 },
1068#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001069 [QCA_NL80211_VENDOR_SUBCMD_SCAN_DONE_INDEX] = {
1070 .vendor_id = QCA_NL80211_VENDOR_ID,
1071 .subcmd = QCA_NL80211_VENDOR_SUBCMD_SCAN_DONE
1072 },
1073 [QCA_NL80211_VENDOR_SUBCMD_SCAN_INDEX] = {
1074 .vendor_id = QCA_NL80211_VENDOR_ID,
1075 .subcmd = QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN
1076 },
1077 /* OCB events */
1078 [QCA_NL80211_VENDOR_SUBCMD_DCC_STATS_EVENT_INDEX] = {
1079 .vendor_id = QCA_NL80211_VENDOR_ID,
1080 .subcmd = QCA_NL80211_VENDOR_SUBCMD_DCC_STATS_EVENT
1081 },
Ravi Joshideb5a8d2015-11-09 19:11:43 -08001082#ifdef FEATURE_LFR_SUBNET_DETECTION
1083 [QCA_NL80211_VENDOR_SUBCMD_GW_PARAM_CONFIG_INDEX] = {
1084 .vendor_id = QCA_NL80211_VENDOR_ID,
1085 .subcmd = QCA_NL80211_VENDOR_SUBCMD_GW_PARAM_CONFIG
1086 },
1087#endif /*FEATURE_LFR_SUBNET_DETECTION */
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001088
1089#ifdef WLAN_FEATURE_NAN_DATAPATH
1090 [QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX] = {
1091 .vendor_id = QCA_NL80211_VENDOR_ID,
1092 .subcmd = QCA_NL80211_VENDOR_SUBCMD_NDP
1093 },
1094#endif /* WLAN_FEATURE_NAN_DATAPATH */
Peng Xu8fdaa492016-06-22 10:20:47 -07001095
1096 [QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX] = {
1097 .vendor_id = QCA_NL80211_VENDOR_ID,
1098 .subcmd = QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP
1099 },
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301100 [QCA_NL80211_VENDOR_SUBCMD_SAP_CONDITIONAL_CHAN_SWITCH_INDEX] = {
1101 .vendor_id = QCA_NL80211_VENDOR_ID,
1102 .subcmd = QCA_NL80211_VENDOR_SUBCMD_SAP_CONDITIONAL_CHAN_SWITCH
1103 },
Paul Zhang3a210c52016-12-08 10:18:12 +08001104#ifdef WLAN_UMAC_CONVERGENCE
1105 COMMON_VENDOR_EVENTS
1106#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001107};
1108
1109/**
1110 * __is_driver_dfs_capable() - get driver DFS capability
1111 * @wiphy: pointer to wireless wiphy structure.
1112 * @wdev: pointer to wireless_dev structure.
1113 * @data: Pointer to the data to be passed via vendor interface
1114 * @data_len:Length of the data to be passed
1115 *
1116 * This function is called by userspace to indicate whether or not
1117 * the driver supports DFS offload.
1118 *
1119 * Return: 0 on success, negative errno on failure
1120 */
1121static int __is_driver_dfs_capable(struct wiphy *wiphy,
1122 struct wireless_dev *wdev,
1123 const void *data,
1124 int data_len)
1125{
1126 u32 dfs_capability = 0;
1127 struct sk_buff *temp_skbuff;
1128 int ret_val;
1129 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1130
Jeff Johnson1f61b612016-02-12 16:28:33 -08001131 ENTER_DEV(wdev->netdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001132
1133 ret_val = wlan_hdd_validate_context(hdd_ctx);
1134 if (ret_val)
1135 return ret_val;
1136
Anurag Chouhan6d760662016-02-20 16:05:43 +05301137 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 hdd_err("Command not allowed in FTM mode");
1139 return -EPERM;
1140 }
1141
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001142 dfs_capability = !!(wiphy->flags & WIPHY_FLAG_DFS_OFFLOAD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001143
1144 temp_skbuff = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(u32) +
1145 NLMSG_HDRLEN);
1146
1147 if (temp_skbuff != NULL) {
1148 ret_val = nla_put_u32(temp_skbuff, QCA_WLAN_VENDOR_ATTR_DFS,
1149 dfs_capability);
1150 if (ret_val) {
Jeff Johnson020db452016-06-29 14:37:26 -07001151 hdd_err("QCA_WLAN_VENDOR_ATTR_DFS put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001152 kfree_skb(temp_skbuff);
1153
1154 return ret_val;
1155 }
1156
1157 return cfg80211_vendor_cmd_reply(temp_skbuff);
1158 }
1159
Jeff Johnson020db452016-06-29 14:37:26 -07001160 hdd_err("dfs capability: buffer alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 return -ENOMEM;
1162}
1163
1164/**
1165 * is_driver_dfs_capable() - get driver DFS capability
1166 * @wiphy: pointer to wireless wiphy structure.
1167 * @wdev: pointer to wireless_dev structure.
1168 * @data: Pointer to the data to be passed via vendor interface
1169 * @data_len:Length of the data to be passed
1170 *
1171 * This function is called by userspace to indicate whether or not
1172 * the driver supports DFS offload. This is an SSR-protected
1173 * wrapper function.
1174 *
1175 * Return: 0 on success, negative errno on failure
1176 */
1177static int is_driver_dfs_capable(struct wiphy *wiphy,
1178 struct wireless_dev *wdev,
1179 const void *data,
1180 int data_len)
1181{
1182 int ret;
1183
1184 cds_ssr_protect(__func__);
1185 ret = __is_driver_dfs_capable(wiphy, wdev, data, data_len);
1186 cds_ssr_unprotect(__func__);
1187
1188 return ret;
1189}
1190
1191/**
1192 * wlan_hdd_sap_cfg_dfs_override() - DFS MCC restriction check
1193 *
1194 * @adapter: SAP adapter pointer
1195 *
1196 * DFS in MCC is not supported for Multi bssid SAP mode due to single physical
1197 * radio. So in case of DFS MCC scenario override current SAP given config
1198 * to follow concurrent SAP DFS config
1199 *
1200 * Return: 0 - No DFS issue, 1 - Override done and negative error codes
1201 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202int wlan_hdd_sap_cfg_dfs_override(hdd_adapter_t *adapter)
1203{
1204 hdd_adapter_t *con_sap_adapter;
1205 tsap_Config_t *sap_config, *con_sap_config;
1206 int con_ch;
1207
1208 /*
1209 * Check if AP+AP case, once primary AP chooses a DFS
1210 * channel secondary AP should always follow primary APs channel
1211 */
1212 if (!cds_concurrent_beaconing_sessions_running())
1213 return 0;
1214
1215 con_sap_adapter = hdd_get_con_sap_adapter(adapter, true);
1216 if (!con_sap_adapter)
1217 return 0;
1218
1219 sap_config = &adapter->sessionCtx.ap.sapConfig;
1220 con_sap_config = &con_sap_adapter->sessionCtx.ap.sapConfig;
1221 con_ch = con_sap_adapter->sessionCtx.ap.operatingChannel;
1222
1223 if (!CDS_IS_DFS_CH(con_ch))
1224 return 0;
1225
Jeff Johnson020db452016-06-29 14:37:26 -07001226 hdd_err("Only SCC AP-AP DFS Permitted (ch=%d, con_ch=%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001227 sap_config->channel, con_ch);
Jeff Johnson020db452016-06-29 14:37:26 -07001228 hdd_notice("Overriding guest AP's channel");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001229 sap_config->channel = con_ch;
1230
1231 if (con_sap_config->acs_cfg.acs_mode == true) {
1232 if (con_ch != con_sap_config->acs_cfg.pri_ch &&
1233 con_ch != con_sap_config->acs_cfg.ht_sec_ch) {
Jeff Johnson020db452016-06-29 14:37:26 -07001234 hdd_err("Primary AP channel config error");
1235 hdd_err("Operating ch: %d ACS ch: %d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 con_ch, con_sap_config->acs_cfg.pri_ch,
1237 con_sap_config->acs_cfg.ht_sec_ch);
1238 return -EINVAL;
1239 }
1240 /* Sec AP ACS info is overwritten with Pri AP due to DFS
1241 * MCC restriction. So free ch list allocated in do_acs
1242 * func for Sec AP and realloc for Pri AP ch list size
1243 */
1244 if (sap_config->acs_cfg.ch_list)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301245 qdf_mem_free(sap_config->acs_cfg.ch_list);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001246
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301247 qdf_mem_copy(&sap_config->acs_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 &con_sap_config->acs_cfg,
1249 sizeof(struct sap_acs_cfg));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301250 sap_config->acs_cfg.ch_list = qdf_mem_malloc(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251 sizeof(uint8_t) *
1252 con_sap_config->acs_cfg.ch_list_count);
1253 if (!sap_config->acs_cfg.ch_list) {
Jeff Johnson020db452016-06-29 14:37:26 -07001254 hdd_err("ACS config alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255 return -ENOMEM;
1256 }
1257
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301258 qdf_mem_copy(sap_config->acs_cfg.ch_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001259 con_sap_config->acs_cfg.ch_list,
1260 con_sap_config->acs_cfg.ch_list_count);
1261
1262 } else {
1263 sap_config->acs_cfg.pri_ch = con_ch;
1264 if (sap_config->acs_cfg.ch_width > eHT_CHANNEL_WIDTH_20MHZ)
1265 sap_config->acs_cfg.ht_sec_ch = con_sap_config->sec_ch;
1266 }
1267
1268 return con_ch;
1269}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001270
1271/**
1272 * wlan_hdd_set_acs_ch_range : Start ACS channel range values
1273 * @sap_cfg: pointer to SAP config struct
1274 *
1275 * This function sets the default ACS start and end channel for the given band
1276 * and also parses the given ACS channel list.
1277 *
1278 * Return: None
1279 */
1280
1281static void wlan_hdd_set_acs_ch_range(tsap_Config_t *sap_cfg, bool ht_enabled,
1282 bool vht_enabled)
1283{
1284 int i;
1285 if (sap_cfg->acs_cfg.hw_mode == QCA_ACS_MODE_IEEE80211B) {
1286 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11b;
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_14);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001289 } else if (sap_cfg->acs_cfg.hw_mode == QCA_ACS_MODE_IEEE80211G) {
1290 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11g;
Amar Singhalb8d4f152016-02-10 10:21:43 -08001291 sap_cfg->acs_cfg.start_ch = CDS_CHANNEL_NUM(CHAN_ENUM_1);
1292 sap_cfg->acs_cfg.end_ch = CDS_CHANNEL_NUM(CHAN_ENUM_13);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001293 } else if (sap_cfg->acs_cfg.hw_mode == QCA_ACS_MODE_IEEE80211A) {
1294 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11a;
Amar Singhalb8d4f152016-02-10 10:21:43 -08001295 sap_cfg->acs_cfg.start_ch = CDS_CHANNEL_NUM(CHAN_ENUM_36);
1296 sap_cfg->acs_cfg.end_ch = CDS_CHANNEL_NUM(CHAN_ENUM_165);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001297 } else if (sap_cfg->acs_cfg.hw_mode == QCA_ACS_MODE_IEEE80211ANY) {
1298 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_abg;
Amar Singhalb8d4f152016-02-10 10:21:43 -08001299 sap_cfg->acs_cfg.start_ch = CDS_CHANNEL_NUM(CHAN_ENUM_1);
1300 sap_cfg->acs_cfg.end_ch = CDS_CHANNEL_NUM(CHAN_ENUM_165);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001301 }
1302
1303 if (ht_enabled)
1304 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11n;
1305
1306 if (vht_enabled)
1307 sap_cfg->acs_cfg.hw_mode = eCSR_DOT11_MODE_11ac;
1308
1309
1310 /* Parse ACS Chan list from hostapd */
1311 if (!sap_cfg->acs_cfg.ch_list)
1312 return;
1313
1314 sap_cfg->acs_cfg.start_ch = sap_cfg->acs_cfg.ch_list[0];
1315 sap_cfg->acs_cfg.end_ch =
1316 sap_cfg->acs_cfg.ch_list[sap_cfg->acs_cfg.ch_list_count - 1];
1317 for (i = 0; i < sap_cfg->acs_cfg.ch_list_count; i++) {
Manjeet Singh2d3b0c52016-09-02 13:31:48 +05301318 /* avoid channel as start channel */
1319 if (sap_cfg->acs_cfg.start_ch > sap_cfg->acs_cfg.ch_list[i] &&
1320 sap_cfg->acs_cfg.ch_list[i] != 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321 sap_cfg->acs_cfg.start_ch = sap_cfg->acs_cfg.ch_list[i];
1322 if (sap_cfg->acs_cfg.end_ch < sap_cfg->acs_cfg.ch_list[i])
1323 sap_cfg->acs_cfg.end_ch = sap_cfg->acs_cfg.ch_list[i];
1324 }
1325}
1326
1327
1328static void wlan_hdd_cfg80211_start_pending_acs(struct work_struct *work);
1329
1330/**
1331 * wlan_hdd_cfg80211_start_acs : Start ACS Procedure for SAP
1332 * @adapter: pointer to SAP adapter struct
1333 *
1334 * This function starts the ACS procedure if there are no
1335 * constraints like MBSSID DFS restrictions.
1336 *
1337 * Return: Status of ACS Start procedure
1338 */
1339
1340static int wlan_hdd_cfg80211_start_acs(hdd_adapter_t *adapter)
1341{
1342
1343 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1344 tsap_Config_t *sap_config;
1345 tpWLAN_SAPEventCB acs_event_callback;
1346 int status;
1347
1348 sap_config = &adapter->sessionCtx.ap.sapConfig;
Agrawal Ashish65634612016-08-18 13:24:32 +05301349 if (hdd_ctx->acs_policy.acs_channel)
1350 sap_config->channel = hdd_ctx->acs_policy.acs_channel;
1351 else
1352 sap_config->channel = AUTO_CHANNEL_SELECT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001353
1354 status = wlan_hdd_sap_cfg_dfs_override(adapter);
1355 if (status < 0) {
1356 return status;
1357 } else {
1358 if (status > 0) {
1359 /*notify hostapd about channel override */
1360 wlan_hdd_cfg80211_acs_ch_select_evt(adapter);
1361 clear_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags);
1362 return 0;
1363 }
1364 }
1365 status = wlan_hdd_config_acs(hdd_ctx, adapter);
1366 if (status) {
Jeff Johnson020db452016-06-29 14:37:26 -07001367 hdd_err("ACS config failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368 return -EINVAL;
1369 }
1370
1371 acs_event_callback = hdd_hostapd_sap_event_cb;
1372
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301373 qdf_mem_copy(sap_config->self_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301374 adapter->macAddressCurrent.bytes, sizeof(struct qdf_mac_addr));
Jeff Johnson020db452016-06-29 14:37:26 -07001375 hdd_notice("ACS Started for wlan%d", adapter->dev->ifindex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 status = wlansap_acs_chselect(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001377 WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378 acs_event_callback, sap_config, adapter->dev);
1379
1380
1381 if (status) {
Jeff Johnson020db452016-06-29 14:37:26 -07001382 hdd_err("ACS channel select failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383 return -EINVAL;
1384 }
bings394afdd2017-01-09 11:22:38 +08001385 if (sap_is_auto_channel_select(WLAN_HDD_GET_SAP_CTX_PTR(adapter)))
1386 sap_config->acs_cfg.acs_mode = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 set_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags);
1388
1389 return 0;
1390}
1391
1392/**
1393 * __wlan_hdd_cfg80211_do_acs : CFG80211 handler function for DO_ACS Vendor CMD
1394 * @wiphy: Linux wiphy struct pointer
1395 * @wdev: Linux wireless device struct pointer
1396 * @data: ACS information from hostapd
1397 * @data_len: ACS information length
1398 *
1399 * This function handle DO_ACS Vendor command from hostapd, parses ACS config
1400 * and starts ACS procedure.
1401 *
1402 * Return: ACS procedure start status
1403 */
1404
1405static int __wlan_hdd_cfg80211_do_acs(struct wiphy *wiphy,
1406 struct wireless_dev *wdev,
1407 const void *data, int data_len)
1408{
1409 struct net_device *ndev = wdev->netdev;
1410 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
1411 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1412 tsap_Config_t *sap_config;
1413 struct sk_buff *temp_skbuff;
1414 int status = -EINVAL, i = 0;
1415 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ACS_MAX + 1];
1416 bool ht_enabled, ht40_enabled, vht_enabled;
1417 uint8_t ch_width;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05301418 uint8_t weight_list[QDF_MAX_NUM_CHAN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419
1420 /* ***Note*** Donot set SME config related to ACS operation here because
1421 * ACS operation is not synchronouse and ACS for Second AP may come when
1422 * ACS operation for first AP is going on. So only do_acs is split to
1423 * seperate start_acs routine. Also SME-PMAC struct that is used to
1424 * pass paremeters from HDD to SAP is global. Thus All ACS related SME
1425 * config shall be set only from start_acs.
1426 */
1427
1428 /* nla_policy Policy template. Policy not applied as some attributes are
1429 * optional and QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST has variable length
1430 *
1431 * [QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE] = { .type = NLA_U8 },
1432 * [QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED] = { .type = NLA_FLAG },
1433 * [QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED] = { .type = NLA_FLAG },
1434 * [QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED] = { .type = NLA_FLAG },
1435 * [QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH] = { .type = NLA_U16 },
1436 * [QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST] = { .type = NLA_NESTED },
1437 */
1438
Jeff Johnson1f61b612016-02-12 16:28:33 -08001439 ENTER_DEV(ndev);
1440
Anurag Chouhan6d760662016-02-20 16:05:43 +05301441 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 hdd_err("Command not allowed in FTM mode");
1443 return -EPERM;
1444 }
1445
1446 if (hdd_ctx->config->force_sap_acs) {
Jeff Johnson020db452016-06-29 14:37:26 -07001447 hdd_err("Hostapd ACS rejected as Driver ACS enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 return -EPERM;
1449 }
1450
1451 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301452 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001453 goto out;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301454
Naveen Rawat64e477e2016-05-20 10:34:56 -07001455 if (cds_is_sub_20_mhz_enabled()) {
1456 hdd_err("ACS not supported in sub 20 MHz ch wd.");
1457 status = -EINVAL;
1458 goto out;
1459 }
1460
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461 sap_config = &adapter->sessionCtx.ap.sapConfig;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301462 qdf_mem_zero(&sap_config->acs_cfg, sizeof(struct sap_acs_cfg));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001463
1464 status = nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ACS_MAX, data, data_len,
1465 NULL);
1466 if (status) {
Jeff Johnson020db452016-06-29 14:37:26 -07001467 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 goto out;
1469 }
1470
1471 if (!tb[QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE]) {
Jeff Johnson020db452016-06-29 14:37:26 -07001472 hdd_err("Attr hw_mode failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001473 goto out;
1474 }
1475 sap_config->acs_cfg.hw_mode = nla_get_u8(
1476 tb[QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE]);
1477
1478 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED])
1479 ht_enabled =
1480 nla_get_flag(tb[QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED]);
1481 else
1482 ht_enabled = 0;
1483
1484 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED])
1485 ht40_enabled =
1486 nla_get_flag(tb[QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED]);
1487 else
1488 ht40_enabled = 0;
1489
1490 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED])
1491 vht_enabled =
1492 nla_get_flag(tb[QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED]);
1493 else
1494 vht_enabled = 0;
1495
Rajeev Kumar Sirasanagandlab79b5462016-09-06 18:33:17 +05301496 if (hdd_ctx->config->sap_force_11n_for_11ac) {
1497 vht_enabled = 0;
1498 hdd_log(LOG1, FL("VHT is Disabled in ACS"));
1499 }
1500
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001501 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH]) {
1502 ch_width = nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH]);
1503 } else {
1504 if (ht_enabled && ht40_enabled)
1505 ch_width = 40;
1506 else
1507 ch_width = 20;
1508 }
Rajeev Kumar Sirasanagandlab79b5462016-09-06 18:33:17 +05301509
1510 /* this may be possible, when sap_force_11n_for_11ac is set */
1511 if ((ch_width == 80 || ch_width == 160) && !vht_enabled) {
1512 if (ht_enabled && ht40_enabled)
1513 ch_width = 40;
1514 else
1515 ch_width = 20;
1516 }
1517
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001518 if (ch_width == 80)
1519 sap_config->acs_cfg.ch_width = CH_WIDTH_80MHZ;
1520 else if (ch_width == 40)
1521 sap_config->acs_cfg.ch_width = CH_WIDTH_40MHZ;
1522 else
1523 sap_config->acs_cfg.ch_width = CH_WIDTH_20MHZ;
1524
1525 /* hw_mode = a/b/g: QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST and
1526 * QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST attrs are present, and
1527 * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST is used for obtaining the
1528 * channel list, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST is ignored
1529 * since it contains the frequency values of the channels in
1530 * the channel list.
1531 * hw_mode = any: only QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST attr
1532 * is present
1533 */
1534 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST]) {
1535 char *tmp = nla_data(tb[QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST]);
1536 sap_config->acs_cfg.ch_list_count = nla_len(
1537 tb[QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST]);
1538 if (sap_config->acs_cfg.ch_list_count) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301539 sap_config->acs_cfg.ch_list = qdf_mem_malloc(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001540 sizeof(uint8_t) *
1541 sap_config->acs_cfg.ch_list_count);
1542 if (sap_config->acs_cfg.ch_list == NULL)
1543 goto out;
1544
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301545 qdf_mem_copy(sap_config->acs_cfg.ch_list, tmp,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001546 sap_config->acs_cfg.ch_list_count);
1547 }
1548 } else if (tb[QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST]) {
1549 uint32_t *freq =
1550 nla_data(tb[QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST]);
1551 sap_config->acs_cfg.ch_list_count = nla_len(
1552 tb[QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST]) /
1553 sizeof(uint32_t);
1554 if (sap_config->acs_cfg.ch_list_count) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301555 sap_config->acs_cfg.ch_list = qdf_mem_malloc(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556 sap_config->acs_cfg.ch_list_count);
1557 if (sap_config->acs_cfg.ch_list == NULL) {
Jeff Johnson020db452016-06-29 14:37:26 -07001558 hdd_err("ACS config alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001559 status = -ENOMEM;
1560 goto out;
1561 }
1562
1563 /* convert frequency to channel */
1564 for (i = 0; i < sap_config->acs_cfg.ch_list_count; i++)
1565 sap_config->acs_cfg.ch_list[i] =
1566 ieee80211_frequency_to_channel(freq[i]);
1567 }
1568 }
1569
1570 hdd_debug("get pcl for DO_ACS vendor command");
1571
1572 /* consult policy manager to get PCL */
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08001573 status = cds_get_pcl(CDS_SAP_MODE,
Manishekar Chandrasekaran7009f252016-04-21 19:14:15 +05301574 sap_config->acs_cfg.pcl_channels,
1575 &sap_config->acs_cfg.pcl_ch_count,
1576 weight_list, QDF_ARRAY_SIZE(weight_list));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301577 if (QDF_STATUS_SUCCESS != status)
Jeff Johnson020db452016-06-29 14:37:26 -07001578 hdd_err("Get PCL failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580 /* ACS override for android */
Rajeev Kumar Sirasanagandlab79b5462016-09-06 18:33:17 +05301581 if (hdd_ctx->config->sap_p2p_11ac_override && ht_enabled &&
1582 !hdd_ctx->config->sap_force_11n_for_11ac) {
Jeff Johnson020db452016-06-29 14:37:26 -07001583 hdd_notice("ACS Config override for 11AC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584 vht_enabled = 1;
1585 sap_config->acs_cfg.hw_mode = eCSR_DOT11_MODE_11ac;
1586 sap_config->acs_cfg.ch_width =
1587 hdd_ctx->config->vhtChannelWidth;
1588 /* No VHT80 in 2.4G so perform ACS accordingly */
1589 if (sap_config->acs_cfg.end_ch <= 14 &&
1590 sap_config->acs_cfg.ch_width == eHT_CHANNEL_WIDTH_80MHZ)
1591 sap_config->acs_cfg.ch_width = eHT_CHANNEL_WIDTH_40MHZ;
1592 }
1593
Manishekar Chandrasekaran44e334f2016-05-30 16:42:50 +05301594 wlan_hdd_set_acs_ch_range(sap_config, ht_enabled, vht_enabled);
1595
Jeff Johnson020db452016-06-29 14:37:26 -07001596 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 -08001597 adapter->dev->ifindex, sap_config->acs_cfg.hw_mode,
1598 ch_width, ht_enabled, vht_enabled,
1599 sap_config->acs_cfg.start_ch, sap_config->acs_cfg.end_ch);
1600
1601 if (sap_config->acs_cfg.ch_list_count) {
Jeff Johnson020db452016-06-29 14:37:26 -07001602 hdd_notice("ACS channel list: len: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001603 sap_config->acs_cfg.ch_list_count);
1604 for (i = 0; i < sap_config->acs_cfg.ch_list_count; i++)
Jeff Johnson020db452016-06-29 14:37:26 -07001605 hdd_notice("%d ", sap_config->acs_cfg.ch_list[i]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606 }
1607 sap_config->acs_cfg.acs_mode = true;
1608 if (test_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001609 /* ***Note*** Completion variable usage is not allowed
1610 * here since ACS scan operation may take max 2.2 sec
1611 * for 5G band:
1612 * 9 Active channel X 40 ms active scan time +
1613 * 16 Passive channel X 110ms passive scan time
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 * Since this CFG80211 call lock rtnl mutex, we cannot hold on
1615 * for this long. So we split up the scanning part.
1616 */
1617 set_bit(ACS_PENDING, &adapter->event_flags);
Jeff Johnson020db452016-06-29 14:37:26 -07001618 hdd_notice("ACS Pending for wlan%d", adapter->dev->ifindex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619 status = 0;
1620 } else {
1621 status = wlan_hdd_cfg80211_start_acs(adapter);
1622 }
1623
1624out:
1625 if (0 == status) {
1626 temp_skbuff = cfg80211_vendor_cmd_alloc_reply_skb(wiphy,
1627 NLMSG_HDRLEN);
1628 if (temp_skbuff != NULL)
1629 return cfg80211_vendor_cmd_reply(temp_skbuff);
1630 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04001631 wlan_hdd_undo_acs(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 clear_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags);
1633
1634 return status;
1635}
1636
Jeff Johnsonf3826e12017-01-12 09:49:40 -08001637/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638 * wlan_hdd_cfg80211_do_acs : CFG80211 handler function for DO_ACS Vendor CMD
1639 * @wiphy: Linux wiphy struct pointer
1640 * @wdev: Linux wireless device struct pointer
1641 * @data: ACS information from hostapd
1642 * @data_len: ACS information len
1643 *
1644 * This function handle DO_ACS Vendor command from hostapd, parses ACS config
1645 * and starts ACS procedure.
1646 *
1647 * Return: ACS procedure start status
1648 */
1649
1650static int wlan_hdd_cfg80211_do_acs(struct wiphy *wiphy,
1651 struct wireless_dev *wdev,
1652 const void *data, int data_len)
1653{
1654 int ret;
1655
1656 cds_ssr_protect(__func__);
1657 ret = __wlan_hdd_cfg80211_do_acs(wiphy, wdev, data, data_len);
1658 cds_ssr_unprotect(__func__);
1659
1660 return ret;
1661}
1662
1663/**
Liangwei Dong8baf7c82016-10-11 01:26:59 -04001664 * wlan_hdd_undo_acs : Do cleanup of DO_ACS
1665 * @adapter: Pointer to adapter struct
1666 *
1667 * This function handle cleanup of what was done in DO_ACS, including free
1668 * memory.
1669 *
1670 * Return: void
1671 */
1672
1673void wlan_hdd_undo_acs(hdd_adapter_t *adapter)
1674{
1675 if (adapter == NULL)
1676 return;
1677 if (adapter->sessionCtx.ap.sapConfig.acs_cfg.ch_list) {
1678 qdf_mem_free(adapter->sessionCtx.ap.sapConfig.acs_cfg.ch_list);
1679 adapter->sessionCtx.ap.sapConfig.acs_cfg.ch_list = NULL;
1680 }
1681}
1682
1683/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 * wlan_hdd_cfg80211_start_pending_acs : Start pending ACS procedure for SAP
1685 * @work: Linux workqueue struct pointer for ACS work
1686 *
1687 * This function starts the ACS procedure which was marked pending when an ACS
1688 * procedure was in progress for a concurrent SAP interface.
1689 *
1690 * Return: None
1691 */
1692
1693static void wlan_hdd_cfg80211_start_pending_acs(struct work_struct *work)
1694{
1695 hdd_adapter_t *adapter = container_of(work, hdd_adapter_t,
1696 acs_pending_work.work);
1697 wlan_hdd_cfg80211_start_acs(adapter);
1698}
1699
1700/**
1701 * wlan_hdd_cfg80211_acs_ch_select_evt: Callback function for ACS evt
1702 * @adapter: Pointer to SAP adapter struct
1703 * @pri_channel: SAP ACS procedure selected Primary channel
1704 * @sec_channel: SAP ACS procedure selected secondary channel
1705 *
1706 * This is a callback function from SAP module on ACS procedure is completed.
1707 * This function send the ACS selected channel information to hostapd
1708 *
1709 * Return: None
1710 */
1711
1712void wlan_hdd_cfg80211_acs_ch_select_evt(hdd_adapter_t *adapter)
1713{
1714 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1715 tsap_Config_t *sap_cfg = &(WLAN_HDD_GET_AP_CTX_PTR(adapter))->sapConfig;
1716 struct sk_buff *vendor_event;
1717 int ret_val;
1718 hdd_adapter_t *con_sap_adapter;
1719 uint16_t ch_width;
1720
1721 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Ryan Hsu9206a4e2016-01-19 17:23:13 -08001722 &(adapter->wdev),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723 4 * sizeof(u8) + 1 * sizeof(u16) + 4 + NLMSG_HDRLEN,
1724 QCA_NL80211_VENDOR_SUBCMD_DO_ACS_INDEX,
1725 GFP_KERNEL);
1726
1727 if (!vendor_event) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001728 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729 return;
1730 }
1731
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 ret_val = nla_put_u8(vendor_event,
1733 QCA_WLAN_VENDOR_ATTR_ACS_PRIMARY_CHANNEL,
1734 sap_cfg->acs_cfg.pri_ch);
1735 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001736 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_PRIMARY_CHANNEL put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001737 kfree_skb(vendor_event);
1738 return;
1739 }
1740
1741 ret_val = nla_put_u8(vendor_event,
1742 QCA_WLAN_VENDOR_ATTR_ACS_SECONDARY_CHANNEL,
1743 sap_cfg->acs_cfg.ht_sec_ch);
1744 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001745 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_SECONDARY_CHANNEL put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001746 kfree_skb(vendor_event);
1747 return;
1748 }
1749
1750 ret_val = nla_put_u8(vendor_event,
1751 QCA_WLAN_VENDOR_ATTR_ACS_VHT_SEG0_CENTER_CHANNEL,
1752 sap_cfg->acs_cfg.vht_seg0_center_ch);
1753 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001754 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_VHT_SEG0_CENTER_CHANNEL put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755 kfree_skb(vendor_event);
1756 return;
1757 }
1758
1759 ret_val = nla_put_u8(vendor_event,
1760 QCA_WLAN_VENDOR_ATTR_ACS_VHT_SEG1_CENTER_CHANNEL,
1761 sap_cfg->acs_cfg.vht_seg1_center_ch);
1762 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001763 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_VHT_SEG1_CENTER_CHANNEL put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001764 kfree_skb(vendor_event);
1765 return;
1766 }
1767
1768 if (sap_cfg->acs_cfg.ch_width == CH_WIDTH_80MHZ)
1769 ch_width = 80;
1770 else if (sap_cfg->acs_cfg.ch_width == CH_WIDTH_40MHZ)
1771 ch_width = 40;
1772 else
1773 ch_width = 20;
1774
1775 ret_val = nla_put_u16(vendor_event,
1776 QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
1777 ch_width);
1778 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001779 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780 kfree_skb(vendor_event);
1781 return;
1782 }
1783 if (sap_cfg->acs_cfg.pri_ch > 14)
1784 ret_val = nla_put_u8(vendor_event,
1785 QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE,
1786 QCA_ACS_MODE_IEEE80211A);
1787 else
1788 ret_val = nla_put_u8(vendor_event,
1789 QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE,
1790 QCA_ACS_MODE_IEEE80211G);
1791
1792 if (ret_val) {
Jeff Johnson46b40792016-06-29 14:03:14 -07001793 hdd_err("QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794 kfree_skb(vendor_event);
1795 return;
1796 }
1797
Jeff Johnson46b40792016-06-29 14:03:14 -07001798 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 -08001799 adapter->dev->ifindex, sap_cfg->acs_cfg.pri_ch,
1800 sap_cfg->acs_cfg.ht_sec_ch, sap_cfg->acs_cfg.vht_seg0_center_ch,
1801 sap_cfg->acs_cfg.vht_seg1_center_ch, ch_width);
1802
1803 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1804 /* ***Note*** As already mentioned Completion variable usage is not
1805 * allowed here since ACS scan operation may take max 2.2 sec.
1806 * Further in AP-AP mode pending ACS is resumed here to serailize ACS
1807 * operation.
1808 * TODO: Delayed operation is used since SME-PMAC strut is global. Thus
1809 * when Primary AP ACS is complete and secondary AP ACS is started here
1810 * immediately, Primary AP start_bss may come inbetween ACS operation
1811 * and overwrite Sec AP ACS paramters. Thus Sec AP ACS is executed with
1812 * delay. This path and below constraint will be removed on sessionizing
1813 * SAP acs parameters and decoupling SAP from PMAC (WIP).
1814 * As per design constraint user space control application must take
1815 * care of serailizing hostapd start for each VIF in AP-AP mode to avoid
1816 * this code path. Sec AP hostapd should be started after Primary AP
1817 * start beaconing which can be confirmed by getchannel iwpriv command
1818 */
1819
1820 con_sap_adapter = hdd_get_con_sap_adapter(adapter, false);
1821 if (con_sap_adapter &&
1822 test_bit(ACS_PENDING, &con_sap_adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001823 INIT_DELAYED_WORK(&con_sap_adapter->acs_pending_work,
1824 wlan_hdd_cfg80211_start_pending_acs);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001825 /* Lets give 500ms for OBSS + START_BSS to complete */
1826 schedule_delayed_work(&con_sap_adapter->acs_pending_work,
1827 msecs_to_jiffies(500));
1828 clear_bit(ACS_PENDING, &con_sap_adapter->event_flags);
1829 }
1830
1831 return;
1832}
1833
1834static int
1835__wlan_hdd_cfg80211_get_supported_features(struct wiphy *wiphy,
1836 struct wireless_dev *wdev,
1837 const void *data,
1838 int data_len)
1839{
1840 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
1841 struct sk_buff *skb = NULL;
1842 uint32_t fset = 0;
1843 int ret;
1844
Srinivas Girigowdadbfb2642016-08-28 21:32:38 -07001845 /* ENTER_DEV() intentionally not used in a frequently invoked API */
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301846
Anurag Chouhan6d760662016-02-20 16:05:43 +05301847 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848 hdd_err("Command not allowed in FTM mode");
1849 return -EPERM;
1850 }
1851
1852 ret = wlan_hdd_validate_context(pHddCtx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301853 if (ret)
1854 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855
1856 if (wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001857 hdd_notice("Infra Station mode is supported by driver");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001858 fset |= WIFI_FEATURE_INFRA;
1859 }
1860 if (true == hdd_is_5g_supported(pHddCtx)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001861 hdd_notice("INFRA_5G is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001862 fset |= WIFI_FEATURE_INFRA_5G;
1863 }
1864#ifdef WLAN_FEATURE_P2P
1865 if ((wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) &&
1866 (wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_GO))) {
Jeff Johnson020db452016-06-29 14:37:26 -07001867 hdd_notice("WiFi-Direct is supported by driver");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001868 fset |= WIFI_FEATURE_P2P;
1869 }
1870#endif
1871 fset |= WIFI_FEATURE_SOFT_AP;
1872
1873 /* HOTSPOT is a supplicant feature, enable it by default */
1874 fset |= WIFI_FEATURE_HOTSPOT;
1875
1876#ifdef FEATURE_WLAN_EXTSCAN
Manjeet Singh0f2ce5c2016-09-01 12:08:57 +05301877 if (pHddCtx->config->extscan_enabled &&
1878 sme_is_feature_supported_by_fw(EXTENDED_SCAN)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001879 hdd_notice("EXTScan is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001880 fset |= WIFI_FEATURE_EXTSCAN | WIFI_FEATURE_HAL_EPNO;
1881 }
1882#endif
1883 if (wlan_hdd_nan_is_supported()) {
Jeff Johnson020db452016-06-29 14:37:26 -07001884 hdd_notice("NAN is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001885 fset |= WIFI_FEATURE_NAN;
1886 }
1887 if (sme_is_feature_supported_by_fw(RTT)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001888 hdd_notice("RTT is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001889 fset |= WIFI_FEATURE_D2D_RTT;
1890 fset |= WIFI_FEATURE_D2AP_RTT;
1891 }
1892#ifdef FEATURE_WLAN_SCAN_PNO
1893 if (pHddCtx->config->configPNOScanSupport &&
1894 sme_is_feature_supported_by_fw(PNO)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001895 hdd_notice("PNO is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001896 fset |= WIFI_FEATURE_PNO;
1897 }
1898#endif
1899 fset |= WIFI_FEATURE_ADDITIONAL_STA;
1900#ifdef FEATURE_WLAN_TDLS
1901 if ((true == pHddCtx->config->fEnableTDLSSupport) &&
1902 sme_is_feature_supported_by_fw(TDLS)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001903 hdd_notice("TDLS is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001904 fset |= WIFI_FEATURE_TDLS;
1905 }
1906 if (sme_is_feature_supported_by_fw(TDLS) &&
1907 (true == pHddCtx->config->fEnableTDLSOffChannel) &&
1908 sme_is_feature_supported_by_fw(TDLS_OFF_CHANNEL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001909 hdd_notice("TDLS off-channel is supported by firmware");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910 fset |= WIFI_FEATURE_TDLS_OFFCHANNEL;
1911 }
1912#endif
1913#ifdef WLAN_AP_STA_CONCURRENCY
1914 fset |= WIFI_FEATURE_AP_STA;
1915#endif
1916 fset |= WIFI_FEATURE_RSSI_MONITOR;
Srinivas Girigowdaa2cad3e2016-10-25 14:14:23 -07001917 fset |= WIFI_FEATURE_TX_TRANSMIT_POWER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001918
1919 if (hdd_link_layer_stats_supported())
1920 fset |= WIFI_FEATURE_LINK_LAYER_STATS;
1921
1922 skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(fset) +
1923 NLMSG_HDRLEN);
1924 if (!skb) {
Jeff Johnson020db452016-06-29 14:37:26 -07001925 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001926 return -EINVAL;
1927 }
Jeff Johnson020db452016-06-29 14:37:26 -07001928 hdd_notice("Supported Features : 0x%x", fset);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001929 if (nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_FEATURE_SET, fset)) {
Jeff Johnson020db452016-06-29 14:37:26 -07001930 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001931 goto nla_put_failure;
1932 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301933 ret = cfg80211_vendor_cmd_reply(skb);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301934 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935nla_put_failure:
1936 kfree_skb(skb);
1937 return -EINVAL;
1938}
1939
1940/**
1941 * wlan_hdd_cfg80211_get_supported_features() - get supported features
1942 * @wiphy: pointer to wireless wiphy structure.
1943 * @wdev: pointer to wireless_dev structure.
1944 * @data: Pointer to the data to be passed via vendor interface
1945 * @data_len:Length of the data to be passed
1946 *
1947 * Return: Return the Success or Failure code.
1948 */
1949static int
1950wlan_hdd_cfg80211_get_supported_features(struct wiphy *wiphy,
1951 struct wireless_dev *wdev,
1952 const void *data, int data_len)
1953{
1954 int ret = 0;
1955
1956 cds_ssr_protect(__func__);
1957 ret = __wlan_hdd_cfg80211_get_supported_features(wiphy, wdev,
1958 data, data_len);
1959 cds_ssr_unprotect(__func__);
1960
1961 return ret;
1962}
1963
1964/**
1965 * __wlan_hdd_cfg80211_set_scanning_mac_oui() - set scan MAC
1966 * @wiphy: pointer to wireless wiphy structure.
1967 * @wdev: pointer to wireless_dev structure.
1968 * @data: Pointer to the data to be passed via vendor interface
1969 * @data_len:Length of the data to be passed
1970 *
1971 * Set the MAC address that is to be used for scanning.
1972 *
1973 * Return: Return the Success or Failure code.
1974 */
1975static int
1976__wlan_hdd_cfg80211_set_scanning_mac_oui(struct wiphy *wiphy,
1977 struct wireless_dev *wdev,
1978 const void *data,
1979 int data_len)
1980{
1981 tpSirScanMacOui pReqMsg = NULL;
1982 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
1983 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SET_SCANNING_MAC_OUI_MAX + 1];
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301984 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001985 int ret;
1986
Jeff Johnson1f61b612016-02-12 16:28:33 -08001987 ENTER_DEV(wdev->netdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001988
Anurag Chouhan6d760662016-02-20 16:05:43 +05301989 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001990 hdd_err("Command not allowed in FTM mode");
1991 return -EPERM;
1992 }
1993
1994 ret = wlan_hdd_validate_context(pHddCtx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301995 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001997
1998 if (false == pHddCtx->config->enable_mac_spoofing) {
Jeff Johnson020db452016-06-29 14:37:26 -07001999 hdd_warn("MAC address spoofing is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002000 return -ENOTSUPP;
2001 }
2002
2003 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SET_SCANNING_MAC_OUI_MAX,
2004 data, data_len, NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002005 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 return -EINVAL;
2007 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302008 pReqMsg = qdf_mem_malloc(sizeof(*pReqMsg));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009 if (!pReqMsg) {
Jeff Johnson020db452016-06-29 14:37:26 -07002010 hdd_err("qdf_mem_malloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002011 return -ENOMEM;
2012 }
2013 if (!tb[QCA_WLAN_VENDOR_ATTR_SET_SCANNING_MAC_OUI]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002014 hdd_err("attr mac oui failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015 goto fail;
2016 }
2017 nla_memcpy(&pReqMsg->oui[0],
2018 tb[QCA_WLAN_VENDOR_ATTR_SET_SCANNING_MAC_OUI],
2019 sizeof(pReqMsg->oui));
Jeff Johnson020db452016-06-29 14:37:26 -07002020 hdd_notice("Oui (%02x:%02x:%02x)", pReqMsg->oui[0],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002021 pReqMsg->oui[1], pReqMsg->oui[2]);
2022 status = sme_set_scanning_mac_oui(pHddCtx->hHal, pReqMsg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302023 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002024 hdd_err("sme_set_scanning_mac_oui failed(err=%d)", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 goto fail;
2026 }
2027 return 0;
2028fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302029 qdf_mem_free(pReqMsg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002030 return -EINVAL;
2031}
2032
2033/**
2034 * wlan_hdd_cfg80211_set_scanning_mac_oui() - set scan MAC
2035 * @wiphy: pointer to wireless wiphy structure.
2036 * @wdev: pointer to wireless_dev structure.
2037 * @data: Pointer to the data to be passed via vendor interface
2038 * @data_len:Length of the data to be passed
2039 *
2040 * Set the MAC address that is to be used for scanning. This is an
2041 * SSR-protecting wrapper function.
2042 *
2043 * Return: Return the Success or Failure code.
2044 */
2045static int
2046wlan_hdd_cfg80211_set_scanning_mac_oui(struct wiphy *wiphy,
2047 struct wireless_dev *wdev,
2048 const void *data,
2049 int data_len)
2050{
2051 int ret;
2052
2053 cds_ssr_protect(__func__);
2054 ret = __wlan_hdd_cfg80211_set_scanning_mac_oui(wiphy, wdev,
2055 data, data_len);
2056 cds_ssr_unprotect(__func__);
2057
2058 return ret;
2059}
2060
2061/**
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302062 * __wlan_hdd_cfg80211_get_concurrency_matrix() - to retrieve concurrency matrix
2063 * @wiphy: pointer phy adapter
2064 * @wdev: pointer to wireless device structure
2065 * @data: pointer to data buffer
2066 * @data_len: length of data
2067 *
2068 * This routine will give concurrency matrix
2069 *
2070 * Return: int status code
2071 */
2072static int __wlan_hdd_cfg80211_get_concurrency_matrix(struct wiphy *wiphy,
2073 struct wireless_dev *wdev,
2074 const void *data,
2075 int data_len)
2076{
2077 uint32_t feature_set_matrix[CDS_MAX_FEATURE_SET] = {0};
2078 uint8_t i, feature_sets, max_feature_sets;
2079 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_MAX + 1];
2080 struct sk_buff *reply_skb;
2081 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
2082 int ret;
2083
2084 ENTER_DEV(wdev->netdev);
2085
2086 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2087 hdd_err("Command not allowed in FTM mode");
2088 return -EPERM;
2089 }
2090
2091 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302092 if (ret)
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302093 return ret;
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302094
2095 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_MAX,
2096 data, data_len, NULL)) {
2097 hdd_err("Invalid ATTR");
2098 return -EINVAL;
2099 }
2100
2101 /* Parse and fetch max feature set */
2102 if (!tb[QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_CONFIG_PARAM_SET_SIZE_MAX]) {
2103 hdd_err("Attr max feature set size failed");
2104 return -EINVAL;
2105 }
2106 max_feature_sets = nla_get_u32(tb[
2107 QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_CONFIG_PARAM_SET_SIZE_MAX]);
2108 hdd_info("Max feature set size: %d", max_feature_sets);
2109
2110 /* Fill feature combination matrix */
2111 feature_sets = 0;
2112 feature_set_matrix[feature_sets++] = WIFI_FEATURE_INFRA |
Srinivas Girigowdaca422922016-08-17 18:29:42 -07002113 WIFI_FEATURE_P2P;
2114 feature_set_matrix[feature_sets++] = WIFI_FEATURE_INFRA |
2115 WIFI_FEATURE_NAN;
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302116 /* Add more feature combinations here */
2117
2118 feature_sets = QDF_MIN(feature_sets, max_feature_sets);
Srinivas Girigowdaca422922016-08-17 18:29:42 -07002119 hdd_info("Number of feature sets: %d", feature_sets);
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05302120 hdd_info("Feature set matrix");
2121 for (i = 0; i < feature_sets; i++)
2122 hdd_info("[%d] 0x%02X", i, feature_set_matrix[i]);
2123
2124 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(u32) +
2125 sizeof(u32) * feature_sets + NLMSG_HDRLEN);
2126 if (!reply_skb) {
2127 hdd_err("Feature set matrix: buffer alloc fail");
2128 return -ENOMEM;
2129 }
2130
2131 if (nla_put_u32(reply_skb,
2132 QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_RESULTS_SET_SIZE,
2133 feature_sets) ||
2134 nla_put(reply_skb,
2135 QCA_WLAN_VENDOR_ATTR_GET_CONCURRENCY_MATRIX_RESULTS_SET,
2136 sizeof(u32) * feature_sets,
2137 feature_set_matrix)) {
2138 hdd_err("nla put fail");
2139 kfree_skb(reply_skb);
2140 return -EINVAL;
2141 }
2142 return cfg80211_vendor_cmd_reply(reply_skb);
2143}
2144
2145/**
2146 * wlan_hdd_cfg80211_get_concurrency_matrix() - get concurrency matrix
2147 * @wiphy: pointer to wireless wiphy structure.
2148 * @wdev: pointer to wireless_dev structure.
2149 * @data: Pointer to the data to be passed via vendor interface
2150 * @data_len:Length of the data to be passed
2151 *
2152 * Retrieves the concurrency feature set matrix
2153 *
2154 * Return: 0 on success, negative errno on failure
2155 */
2156static int
2157wlan_hdd_cfg80211_get_concurrency_matrix(struct wiphy *wiphy,
2158 struct wireless_dev *wdev,
2159 const void *data,
2160 int data_len)
2161{
2162 int ret;
2163
2164 cds_ssr_protect(__func__);
2165 ret = __wlan_hdd_cfg80211_get_concurrency_matrix(wiphy, wdev,
2166 data, data_len);
2167 cds_ssr_unprotect(__func__);
2168
2169 return ret;
2170}
2171
2172/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002173 * wlan_hdd_cfg80211_set_feature() - Set the bitmask for supported features
2174 * @feature_flags: pointer to the byte array of features.
2175 * @feature: Feature to be turned ON in the byte array.
2176 *
2177 * Return: None
2178 *
2179 * This is called to turn ON or SET the feature flag for the requested feature.
2180 **/
2181#define NUM_BITS_IN_BYTE 8
Jeff Johnson8b8a04b2016-10-05 15:49:43 -07002182static void wlan_hdd_cfg80211_set_feature(uint8_t *feature_flags,
2183 uint8_t feature)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002184{
2185 uint32_t index;
2186 uint8_t bit_mask;
2187
2188 index = feature / NUM_BITS_IN_BYTE;
2189 bit_mask = 1 << (feature % NUM_BITS_IN_BYTE);
2190 feature_flags[index] |= bit_mask;
2191}
2192
2193/**
2194 * __wlan_hdd_cfg80211_get_features() - Get the Driver Supported features
2195 * @wiphy: pointer to wireless wiphy structure.
2196 * @wdev: pointer to wireless_dev structure.
2197 * @data: Pointer to the data to be passed via vendor interface
2198 * @data_len:Length of the data to be passed
2199 *
2200 * This is called when wlan driver needs to send supported feature set to
2201 * supplicant upon a request/query from the supplicant.
2202 *
2203 * Return: Return the Success or Failure code.
2204 **/
2205#define MAX_CONCURRENT_CHAN_ON_24G 2
2206#define MAX_CONCURRENT_CHAN_ON_5G 2
2207static int
2208__wlan_hdd_cfg80211_get_features(struct wiphy *wiphy,
2209 struct wireless_dev *wdev,
2210 const void *data, int data_len)
2211{
2212 struct sk_buff *skb = NULL;
2213 uint32_t dbs_capability = 0;
2214 bool one_by_one_dbs, two_by_two_dbs;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302215 QDF_STATUS ret = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002216 int ret_val;
2217
2218 uint8_t feature_flags[(NUM_QCA_WLAN_VENDOR_FEATURES + 7) / 8] = {0};
2219 hdd_context_t *hdd_ctx_ptr = wiphy_priv(wiphy);
2220
Jeff Johnson1f61b612016-02-12 16:28:33 -08002221 ENTER_DEV(wdev->netdev);
2222
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002223 ret_val = wlan_hdd_validate_context(hdd_ctx_ptr);
2224 if (ret_val)
2225 return ret_val;
2226
Anurag Chouhan6d760662016-02-20 16:05:43 +05302227 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002228 hdd_err("Command not allowed in FTM mode");
2229 return -EPERM;
2230 }
2231
Varun Reddy Yeturud351a6c2016-03-16 14:01:00 -07002232 if (roaming_offload_enabled(hdd_ctx_ptr)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002233 hdd_notice("Key Mgmt Offload is supported");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002234 wlan_hdd_cfg80211_set_feature(feature_flags,
2235 QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD);
2236 }
2237
2238 wlan_hdd_cfg80211_set_feature(feature_flags,
2239 QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY);
2240 if (wma_is_scan_simultaneous_capable())
2241 wlan_hdd_cfg80211_set_feature(feature_flags,
2242 QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS);
Peng Xu8fdaa492016-06-22 10:20:47 -07002243
2244 if (wma_is_p2p_lo_capable())
2245 wlan_hdd_cfg80211_set_feature(feature_flags,
2246 QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD);
2247
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002248 skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(feature_flags) +
2249 NLMSG_HDRLEN);
2250
2251 if (!skb) {
Jeff Johnson020db452016-06-29 14:37:26 -07002252 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002253 return -ENOMEM;
2254 }
2255
2256 if (nla_put(skb, QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS,
2257 sizeof(feature_flags), feature_flags))
2258 goto nla_put_failure;
2259
2260 ret = wma_get_dbs_hw_modes(&one_by_one_dbs, &two_by_two_dbs);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302261 if (QDF_STATUS_SUCCESS == ret) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002262 if (one_by_one_dbs)
2263 dbs_capability = DRV_DBS_CAPABILITY_1X1;
2264
2265 if (two_by_two_dbs)
2266 dbs_capability = DRV_DBS_CAPABILITY_2X2;
2267
2268 if (!one_by_one_dbs && !two_by_two_dbs)
2269 dbs_capability = DRV_DBS_CAPABILITY_DISABLED;
2270 } else {
2271 hdd_err("wma_get_dbs_hw_mode failed");
2272 dbs_capability = DRV_DBS_CAPABILITY_DISABLED;
2273 }
2274
2275 hdd_info("dbs_capability is %d", dbs_capability);
2276
2277 if (nla_put_u32(skb,
2278 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND,
2279 MAX_CONCURRENT_CHAN_ON_24G))
2280 goto nla_put_failure;
2281
2282 if (nla_put_u32(skb,
2283 QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND,
2284 MAX_CONCURRENT_CHAN_ON_5G))
2285 goto nla_put_failure;
2286
2287 return cfg80211_vendor_cmd_reply(skb);
2288
2289nla_put_failure:
2290 kfree_skb(skb);
2291 return -EINVAL;
2292}
2293
2294/**
2295 * wlan_hdd_cfg80211_get_features() - Get the Driver Supported features
2296 * @wiphy: pointer to wireless wiphy structure.
2297 * @wdev: pointer to wireless_dev structure.
2298 * @data: Pointer to the data to be passed via vendor interface
2299 * @data_len:Length of the data to be passed
2300 *
2301 * This is called when wlan driver needs to send supported feature set to
2302 * supplicant upon a request/query from the supplicant.
2303 *
2304 * Return: Return the Success or Failure code.
2305 */
2306static int
2307wlan_hdd_cfg80211_get_features(struct wiphy *wiphy,
2308 struct wireless_dev *wdev,
2309 const void *data, int data_len)
2310{
2311 int ret;
2312
2313 cds_ssr_protect(__func__);
2314 ret = __wlan_hdd_cfg80211_get_features(wiphy, wdev,
2315 data, data_len);
2316 cds_ssr_unprotect(__func__);
2317
2318 return ret;
2319}
2320
2321
2322/**
2323 * __wlan_hdd_cfg80211_set_ext_roam_params() - Settings for roaming parameters
2324 * @wiphy: The wiphy structure
2325 * @wdev: The wireless device
2326 * @data: Data passed by framework
2327 * @data_len: Parameters to be configured passed as data
2328 *
2329 * The roaming related parameters are configured by the framework
2330 * using this interface.
2331 *
2332 * Return: Return either success or failure code.
2333 */
2334static int
2335__wlan_hdd_cfg80211_set_ext_roam_params(struct wiphy *wiphy,
2336 struct wireless_dev *wdev, const void *data, int data_len)
2337{
2338 struct net_device *dev = wdev->netdev;
2339 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2340 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2341 uint8_t session_id;
2342 struct roam_ext_params roam_params;
2343 uint32_t cmd_type, req_id;
2344 struct nlattr *curr_attr;
2345 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX + 1];
2346 struct nlattr *tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX + 1];
2347 int rem, i;
2348 uint32_t buf_len = 0;
Prakash Dhavali075334e2016-11-29 07:22:08 -08002349 uint32_t count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002350 int ret;
2351
Jeff Johnson1f61b612016-02-12 16:28:33 -08002352 ENTER_DEV(dev);
2353
Anurag Chouhan6d760662016-02-20 16:05:43 +05302354 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002355 hdd_err("Command not allowed in FTM mode");
2356 return -EPERM;
2357 }
2358
2359 ret = wlan_hdd_validate_context(pHddCtx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302360 if (ret)
2361 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002362
2363 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX,
2364 data, data_len,
2365 NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002366 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002367 return -EINVAL;
2368 }
2369 /* Parse and fetch Command Type*/
2370 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002371 hdd_err("roam cmd type failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002372 goto fail;
2373 }
2374 session_id = pAdapter->sessionId;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302375 qdf_mem_set(&roam_params, sizeof(roam_params), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002376 cmd_type = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD]);
2377 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002378 hdd_err("attr request id failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002379 goto fail;
2380 }
2381 req_id = nla_get_u32(
2382 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID]);
Jeff Johnson020db452016-06-29 14:37:26 -07002383 hdd_debug("Req Id (%d)", req_id);
2384 hdd_debug("Cmd Type (%d)", cmd_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002385 switch (cmd_type) {
2386 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SSID_WHITE_LIST:
2387 i = 0;
2388 nla_for_each_nested(curr_attr,
2389 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID_LIST],
2390 rem) {
2391 if (nla_parse(tb2,
2392 QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_MAX,
2393 nla_data(curr_attr), nla_len(curr_attr),
2394 NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002395 hdd_err("nla_parse failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002396 goto fail;
2397 }
2398 /* Parse and Fetch allowed SSID list*/
2399 if (!tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002400 hdd_err("attr allowed ssid failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002401 goto fail;
2402 }
2403 buf_len = nla_len(tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID]);
2404 /*
2405 * Upper Layers include a null termination character.
2406 * Check for the actual permissible length of SSID and
2407 * also ensure not to copy the NULL termination
2408 * character to the driver buffer.
2409 */
2410 if (buf_len && (i < MAX_SSID_ALLOWED_LIST) &&
2411 ((buf_len - 1) <= SIR_MAC_MAX_SSID_LENGTH)) {
2412 nla_memcpy(
2413 roam_params.ssid_allowed_list[i].ssId,
2414 tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID],
2415 buf_len - 1);
2416 roam_params.ssid_allowed_list[i].length =
2417 buf_len - 1;
Jeff Johnson020db452016-06-29 14:37:26 -07002418 hdd_debug("SSID[%d]: %.*s,length = %d", i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002419 roam_params.ssid_allowed_list[i].length,
2420 roam_params.ssid_allowed_list[i].ssId,
2421 roam_params.ssid_allowed_list[i].length);
2422 i++;
2423 } else {
Jeff Johnson020db452016-06-29 14:37:26 -07002424 hdd_err("Invalid buffer length");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002425 }
2426 }
2427 roam_params.num_ssid_allowed_list = i;
Jeff Johnson020db452016-06-29 14:37:26 -07002428 hdd_debug("Num of Allowed SSID %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002429 roam_params.num_ssid_allowed_list);
2430 sme_update_roam_params(pHddCtx->hHal, session_id,
2431 roam_params, REASON_ROAM_SET_SSID_ALLOWED);
2432 break;
2433 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_EXTSCAN_ROAM_PARAMS:
2434 /* Parse and fetch 5G Boost Threshold */
2435 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_BOOST_THRESHOLD]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002436 hdd_err("5G boost threshold failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002437 goto fail;
2438 }
2439 roam_params.raise_rssi_thresh_5g = nla_get_s32(
2440 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_BOOST_THRESHOLD]);
Jeff Johnson020db452016-06-29 14:37:26 -07002441 hdd_debug("5G Boost Threshold (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002442 roam_params.raise_rssi_thresh_5g);
2443 /* Parse and fetch 5G Penalty Threshold */
2444 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_PENALTY_THRESHOLD]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002445 hdd_err("5G penalty threshold failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002446 goto fail;
2447 }
2448 roam_params.drop_rssi_thresh_5g = nla_get_s32(
2449 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_PENALTY_THRESHOLD]);
Jeff Johnson020db452016-06-29 14:37:26 -07002450 hdd_debug("5G Penalty Threshold (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002451 roam_params.drop_rssi_thresh_5g);
2452 /* Parse and fetch 5G Boost Factor */
2453 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_BOOST_FACTOR]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002454 hdd_err("5G boost Factor failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002455 goto fail;
2456 }
2457 roam_params.raise_factor_5g = nla_get_u32(
2458 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_BOOST_FACTOR]);
Jeff Johnson020db452016-06-29 14:37:26 -07002459 hdd_debug("5G Boost Factor (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002460 roam_params.raise_factor_5g);
2461 /* Parse and fetch 5G Penalty factor */
2462 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_PENALTY_FACTOR]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002463 hdd_err("5G Penalty Factor failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002464 goto fail;
2465 }
2466 roam_params.drop_factor_5g = nla_get_u32(
2467 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_PENALTY_FACTOR]);
Jeff Johnson020db452016-06-29 14:37:26 -07002468 hdd_debug("5G Penalty factor (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002469 roam_params.drop_factor_5g);
2470 /* Parse and fetch 5G Max Boost */
2471 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_MAX_BOOST]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002472 hdd_err("5G Max Boost failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002473 goto fail;
2474 }
2475 roam_params.max_raise_rssi_5g = nla_get_u32(
2476 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_A_BAND_MAX_BOOST]);
Jeff Johnson020db452016-06-29 14:37:26 -07002477 hdd_debug("5G Max Boost (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002478 roam_params.max_raise_rssi_5g);
2479 /* Parse and fetch Rssi Diff */
2480 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_LAZY_ROAM_HISTERESYS]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002481 hdd_err("Rssi Diff failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002482 goto fail;
2483 }
2484 roam_params.rssi_diff = nla_get_s32(
2485 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_LAZY_ROAM_HISTERESYS]);
Jeff Johnson020db452016-06-29 14:37:26 -07002486 hdd_debug("RSSI Diff (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002487 roam_params.rssi_diff);
2488 /* Parse and fetch Alert Rssi Threshold */
2489 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_ALERT_ROAM_RSSI_TRIGGER]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002490 hdd_err("Alert Rssi Threshold failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491 goto fail;
2492 }
2493 roam_params.alert_rssi_threshold = nla_get_u32(
2494 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_ALERT_ROAM_RSSI_TRIGGER]);
Jeff Johnson020db452016-06-29 14:37:26 -07002495 hdd_debug("Alert RSSI Threshold (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002496 roam_params.alert_rssi_threshold);
2497 sme_update_roam_params(pHddCtx->hHal, session_id,
2498 roam_params,
2499 REASON_ROAM_EXT_SCAN_PARAMS_CHANGED);
2500 break;
2501 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_LAZY_ROAM:
2502 /* Parse and fetch Activate Good Rssi Roam */
2503 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_ENABLE]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002504 hdd_err("Activate Good Rssi Roam failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002505 goto fail;
2506 }
2507 roam_params.good_rssi_roam = nla_get_s32(
2508 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_ENABLE]);
Jeff Johnson020db452016-06-29 14:37:26 -07002509 hdd_debug("Activate Good Rssi Roam (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002510 roam_params.good_rssi_roam);
2511 sme_update_roam_params(pHddCtx->hHal, session_id,
2512 roam_params, REASON_ROAM_GOOD_RSSI_CHANGED);
2513 break;
2514 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BSSID_PREFS:
2515 /* Parse and fetch number of preferred BSSID */
2516 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_NUM_BSSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002517 hdd_err("attr num of preferred bssid failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002518 goto fail;
2519 }
Prakash Dhavali075334e2016-11-29 07:22:08 -08002520 count = nla_get_u32(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002521 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_NUM_BSSID]);
Prakash Dhavali075334e2016-11-29 07:22:08 -08002522 if (count > MAX_BSSID_FAVORED) {
2523 hdd_err("Preferred BSSID count %u exceeds max %u",
2524 count, MAX_BSSID_FAVORED);
2525 goto fail;
2526 }
2527 hdd_debug("Num of Preferred BSSID (%d)", count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002528 i = 0;
2529 nla_for_each_nested(curr_attr,
2530 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PREFS],
2531 rem) {
Prakash Dhavali075334e2016-11-29 07:22:08 -08002532
2533 if (i == count) {
2534 hdd_warn("Ignoring excess Preferred BSSID");
2535 break;
2536 }
2537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002538 if (nla_parse(tb2,
2539 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX,
2540 nla_data(curr_attr), nla_len(curr_attr),
2541 NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002542 hdd_err("nla_parse failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002543 goto fail;
2544 }
2545 /* Parse and fetch MAC address */
2546 if (!tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_BSSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002547 hdd_err("attr mac address failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548 goto fail;
2549 }
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002550 nla_memcpy(roam_params.bssid_favored[i].bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002551 tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_BSSID],
Anurag Chouhan6d760662016-02-20 16:05:43 +05302552 QDF_MAC_ADDR_SIZE);
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002553 hdd_debug(MAC_ADDRESS_STR,
2554 MAC_ADDR_ARRAY(roam_params.bssid_favored[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002555 /* Parse and fetch preference factor*/
2556 if (!tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_RSSI_MODIFIER]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002557 hdd_err("BSSID Preference score failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002558 goto fail;
2559 }
2560 roam_params.bssid_favored_factor[i] = nla_get_u32(
2561 tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_LAZY_ROAM_RSSI_MODIFIER]);
Jeff Johnson020db452016-06-29 14:37:26 -07002562 hdd_debug("BSSID Preference score (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002563 roam_params.bssid_favored_factor[i]);
2564 i++;
2565 }
Prakash Dhavali075334e2016-11-29 07:22:08 -08002566 if (i < count)
2567 hdd_warn("Num Preferred BSSID %u less than expected %u",
2568 i, count);
2569 roam_params.num_bssid_favored = i;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002570 sme_update_roam_params(pHddCtx->hHal, session_id,
2571 roam_params, REASON_ROAM_SET_FAVORED_BSSID);
2572 break;
2573 case QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID:
2574 /* Parse and fetch number of blacklist BSSID */
2575 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002576 hdd_err("attr num of blacklist bssid failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002577 goto fail;
2578 }
Prakash Dhavali075334e2016-11-29 07:22:08 -08002579 count = nla_get_u32(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID]);
Prakash Dhavali075334e2016-11-29 07:22:08 -08002581 if (count > MAX_BSSID_AVOID_LIST) {
2582 hdd_err("Blacklist BSSID count %u exceeds max %u",
2583 count, MAX_BSSID_AVOID_LIST);
2584 goto fail;
2585 }
2586 hdd_debug("Num of blacklist BSSID (%d)", count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002587 i = 0;
2588 nla_for_each_nested(curr_attr,
2589 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS],
2590 rem) {
Prakash Dhavali075334e2016-11-29 07:22:08 -08002591
2592 if (i == count) {
2593 hdd_warn("Ignoring excess Blacklist BSSID");
2594 break;
2595 }
2596
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002597 if (nla_parse(tb2,
2598 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_MAX,
2599 nla_data(curr_attr), nla_len(curr_attr),
2600 NULL)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002601 hdd_err("nla_parse failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002602 goto fail;
2603 }
2604 /* Parse and fetch MAC address */
2605 if (!tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID]) {
Jeff Johnson020db452016-06-29 14:37:26 -07002606 hdd_err("attr blacklist addr failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002607 goto fail;
2608 }
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002609 nla_memcpy(roam_params.bssid_avoid_list[i].bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002610 tb2[QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID],
Anurag Chouhan6d760662016-02-20 16:05:43 +05302611 QDF_MAC_ADDR_SIZE);
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002612 hdd_debug(MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002613 MAC_ADDR_ARRAY(
Srinivas Girigowdab0532392015-11-24 11:50:16 -08002614 roam_params.bssid_avoid_list[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615 i++;
2616 }
Prakash Dhavali075334e2016-11-29 07:22:08 -08002617 if (i < count)
2618 hdd_warn("Num Blacklist BSSID %u less than expected %u",
2619 i, count);
2620 roam_params.num_bssid_avoid_list = i;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002621 sme_update_roam_params(pHddCtx->hHal, session_id,
2622 roam_params, REASON_ROAM_SET_BLACKLIST_BSSID);
2623 break;
2624 }
2625 return 0;
2626fail:
2627 return -EINVAL;
2628}
2629
2630/**
2631 * wlan_hdd_cfg80211_set_ext_roam_params() - set ext scan roam params
2632 * @wiphy: pointer to wireless wiphy structure.
2633 * @wdev: pointer to wireless_dev structure.
2634 * @data: Pointer to the data to be passed via vendor interface
2635 * @data_len:Length of the data to be passed
2636 *
2637 * Return: Return the Success or Failure code.
2638 */
2639static int
2640wlan_hdd_cfg80211_set_ext_roam_params(struct wiphy *wiphy,
2641 struct wireless_dev *wdev,
2642 const void *data,
2643 int data_len)
2644{
2645 int ret;
2646
2647 cds_ssr_protect(__func__);
2648 ret = __wlan_hdd_cfg80211_set_ext_roam_params(wiphy, wdev,
2649 data, data_len);
2650 cds_ssr_unprotect(__func__);
2651
2652 return ret;
2653}
2654
2655static const struct nla_policy
2656wlan_hdd_set_no_dfs_flag_config_policy[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX
2657 +1] = {
2658 [QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG] = {.type = NLA_U32 },
2659};
2660
2661/**
2662 * wlan_hdd_check_dfs_channel_for_adapter() - check dfs channel in adapter
2663 * @hdd_ctx: HDD context
2664 * @device_mode: device mode
2665 * Return: bool
2666 */
2667static bool wlan_hdd_check_dfs_channel_for_adapter(hdd_context_t *hdd_ctx,
Krunal Sonib4326f22016-03-10 13:05:51 -08002668 enum tQDF_ADAPTER_MODE device_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002669{
2670 hdd_adapter_t *adapter;
2671 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
2672 hdd_ap_ctx_t *ap_ctx;
2673 hdd_station_ctx_t *sta_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302674 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002675
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302676 qdf_status = hdd_get_front_adapter(hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002677 &adapter_node);
2678
2679 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302680 (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002681 adapter = adapter_node->pAdapter;
2682
2683 if ((device_mode == adapter->device_mode) &&
Krunal Sonib4326f22016-03-10 13:05:51 -08002684 (device_mode == QDF_SAP_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002685 ap_ctx =
2686 WLAN_HDD_GET_AP_CTX_PTR(adapter);
2687
2688 /*
2689 * if there is SAP already running on DFS channel,
2690 * do not disable scan on dfs channels. Note that
2691 * with SAP on DFS, there cannot be conurrency on
2692 * single radio. But then we can have multiple
2693 * radios !!
2694 */
2695 if (CHANNEL_STATE_DFS ==
2696 cds_get_channel_state(
2697 ap_ctx->operatingChannel)) {
Jeff Johnson020db452016-06-29 14:37:26 -07002698 hdd_err("SAP running on DFS channel");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002699 return true;
2700 }
2701 }
2702
2703 if ((device_mode == adapter->device_mode) &&
Krunal Sonib4326f22016-03-10 13:05:51 -08002704 (device_mode == QDF_STA_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705 sta_ctx =
2706 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2707
2708 /*
2709 * if STA is already connected on DFS channel,
2710 * do not disable scan on dfs channels
2711 */
2712 if (hdd_conn_is_connected(sta_ctx) &&
2713 (CHANNEL_STATE_DFS ==
2714 cds_get_channel_state(
2715 sta_ctx->conn_info.operationChannel))) {
Jeff Johnson020db452016-06-29 14:37:26 -07002716 hdd_err("client connected on DFS channel");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002717 return true;
2718 }
2719 }
2720
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302721 qdf_status = hdd_get_next_adapter(hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722 adapter_node,
2723 &next);
2724 adapter_node = next;
2725 }
2726
2727 return false;
2728}
2729
2730/**
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002731 * wlan_hdd_disable_dfs_chan_scan() - disable/enable DFS channels
2732 * @hdd_ctx: HDD context within host driver
2733 * @adapter: Adapter pointer
2734 * @no_dfs_flag: If TRUE, DFS channels cannot be used for scanning
2735 *
2736 * Loops through devices to see who is operating on DFS channels
2737 * and then disables/enables DFS channels by calling SME API.
2738 * Fails the disable request if any device is active on a DFS channel.
2739 *
2740 * Return: 0 or other error codes.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002741 */
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002742
2743int wlan_hdd_disable_dfs_chan_scan(hdd_context_t *hdd_ctx,
2744 hdd_adapter_t *adapter,
2745 uint32_t no_dfs_flag)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002746{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002747 tHalHandle h_hal = WLAN_HDD_GET_HAL_CTX(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302748 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002749 int ret_val = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002750
2751 if (no_dfs_flag == hdd_ctx->config->enableDFSChnlScan) {
2752 if (no_dfs_flag) {
2753 status = wlan_hdd_check_dfs_channel_for_adapter(
Krunal Sonib4326f22016-03-10 13:05:51 -08002754 hdd_ctx, QDF_STA_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002755
2756 if (true == status)
2757 return -EOPNOTSUPP;
2758
2759 status = wlan_hdd_check_dfs_channel_for_adapter(
Krunal Sonib4326f22016-03-10 13:05:51 -08002760 hdd_ctx, QDF_SAP_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002761
2762 if (true == status)
2763 return -EOPNOTSUPP;
2764 }
2765
2766 hdd_ctx->config->enableDFSChnlScan = !no_dfs_flag;
2767
2768 hdd_abort_mac_scan_all_adapters(hdd_ctx);
2769
2770 /*
2771 * call the SME API to tunnel down the new channel list
2772 * to the firmware
2773 */
2774 status = sme_handle_dfs_chan_scan(
2775 h_hal, hdd_ctx->config->enableDFSChnlScan);
2776
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302777 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778 ret_val = 0;
2779
2780 /*
2781 * Clear the SME scan cache also. Note that the
2782 * clearing of scan results is independent of session;
2783 * so no need to iterate over
2784 * all sessions
2785 */
2786 status = sme_scan_flush_result(h_hal);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302787 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788 ret_val = -EPERM;
2789 }
2790
2791 } else {
Jeff Johnson020db452016-06-29 14:37:26 -07002792 hdd_notice(" the DFS flag has not changed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002793 ret_val = 0;
2794 }
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002795 return ret_val;
2796}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002797
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002798/**
2799 * __wlan_hdd_cfg80211_disable_dfs_chan_scan() - DFS channel configuration
2800 * @wiphy: corestack handler
2801 * @wdev: wireless device
2802 * @data: data
2803 * @data_len: data length
2804 * Return: success(0) or reason code for failure
2805 */
2806static int __wlan_hdd_cfg80211_disable_dfs_chan_scan(struct wiphy *wiphy,
2807 struct wireless_dev *wdev,
2808 const void *data,
2809 int data_len)
2810{
2811 struct net_device *dev = wdev->netdev;
2812 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2813 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
2814 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX + 1];
2815 int ret_val;
2816 uint32_t no_dfs_flag = 0;
2817
Jeff Johnson1f61b612016-02-12 16:28:33 -08002818 ENTER_DEV(dev);
2819
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002820 ret_val = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302821 if (ret_val)
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002822 return ret_val;
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002823
2824 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX,
2825 data, data_len,
2826 wlan_hdd_set_no_dfs_flag_config_policy)) {
2827 hdd_err("invalid attr");
2828 return -EINVAL;
2829 }
2830
2831 if (!tb[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG]) {
2832 hdd_err("attr dfs flag failed");
2833 return -EINVAL;
2834 }
2835
2836 no_dfs_flag = nla_get_u32(
2837 tb[QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG]);
2838
Jeff Johnson020db452016-06-29 14:37:26 -07002839 hdd_notice(" DFS flag = %d", no_dfs_flag);
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002840
2841 if (no_dfs_flag > 1) {
Jeff Johnson020db452016-06-29 14:37:26 -07002842 hdd_err("invalid value of dfs flag");
Deepak Dhamdhere29b3b2f2015-01-22 11:09:55 -08002843 return -EINVAL;
2844 }
2845
2846 ret_val = wlan_hdd_disable_dfs_chan_scan(hdd_ctx, adapter,
2847 no_dfs_flag);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002848 return ret_val;
2849}
2850
2851/**
2852 * wlan_hdd_cfg80211_disable_dfs_chan_scan () - DFS scan vendor command
2853 *
2854 * @wiphy: wiphy device pointer
2855 * @wdev: wireless device pointer
Manikandan Mohan80dea792016-04-28 16:36:48 -07002856 * @data: Vendor command data buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002857 * @data_len: Buffer length
2858 *
2859 * Handles QCA_WLAN_VENDOR_ATTR_SET_NO_DFS_FLAG_MAX. Validate it and
2860 * call wlan_hdd_disable_dfs_chan_scan to send it to firmware.
2861 *
2862 * Return: EOK or other error codes.
2863 */
2864
2865static int wlan_hdd_cfg80211_disable_dfs_chan_scan(struct wiphy *wiphy,
2866 struct wireless_dev *wdev,
2867 const void *data,
2868 int data_len)
2869{
2870 int ret;
2871
2872 cds_ssr_protect(__func__);
2873 ret = __wlan_hdd_cfg80211_disable_dfs_chan_scan(wiphy, wdev,
2874 data, data_len);
2875 cds_ssr_unprotect(__func__);
2876
2877 return ret;
2878}
2879
Manikandan Mohan80dea792016-04-28 16:36:48 -07002880static const struct nla_policy
2881wlan_hdd_wisa_cmd_policy[QCA_WLAN_VENDOR_ATTR_WISA_MAX + 1] = {
2882 [QCA_WLAN_VENDOR_ATTR_WISA_MODE] = {.type = NLA_U32 },
2883};
2884
2885/**
2886 * __wlan_hdd_cfg80211_handle_wisa_cmd() - Handle WISA vendor cmd
2887 * @wiphy: wiphy device pointer
2888 * @wdev: wireless device pointer
2889 * @data: Vendor command data buffer
2890 * @data_len: Buffer length
2891 *
2892 * Handles QCA_WLAN_VENDOR_SUBCMD_WISA. Validate cmd attributes and
2893 * setup WISA Mode features.
2894 *
2895 * Return: Success(0) or reason code for failure
2896 */
2897static int __wlan_hdd_cfg80211_handle_wisa_cmd(struct wiphy *wiphy,
2898 struct wireless_dev *wdev, const void *data, int data_len)
2899{
2900 struct net_device *dev = wdev->netdev;
2901 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2902 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
2903 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_WISA_MAX + 1];
2904 struct sir_wisa_params wisa;
2905 int ret_val;
2906 QDF_STATUS status;
2907 bool wisa_mode;
Leo Changfdb45c32016-10-28 11:09:23 -07002908 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2909 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Manikandan Mohan80dea792016-04-28 16:36:48 -07002910
2911 ENTER_DEV(dev);
2912 ret_val = wlan_hdd_validate_context(hdd_ctx);
2913 if (ret_val)
2914 goto err;
2915
2916 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2917 hdd_err("Command not allowed in FTM mode");
2918 return -EPERM;
2919 }
2920
2921 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_WISA_MAX, data, data_len,
2922 wlan_hdd_wisa_cmd_policy)) {
2923 hdd_err("Invalid WISA cmd attributes");
2924 ret_val = -EINVAL;
2925 goto err;
2926 }
2927 if (!tb[QCA_WLAN_VENDOR_ATTR_WISA_MODE]) {
2928 hdd_err("Invalid WISA mode");
2929 ret_val = -EINVAL;
2930 goto err;
2931 }
2932
2933 wisa_mode = !!nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_WISA_MODE]);
2934 hdd_info("WISA Mode: %d", wisa_mode);
2935 wisa.mode = wisa_mode;
2936 wisa.vdev_id = adapter->sessionId;
2937 status = sme_set_wisa_params(hdd_ctx->hHal, &wisa);
Manikandan Mohanb6315dd2016-05-10 16:16:36 -07002938 if (!QDF_IS_STATUS_SUCCESS(status)) {
2939 hdd_err("Unable to set WISA mode: %d to FW", wisa_mode);
Manikandan Mohan80dea792016-04-28 16:36:48 -07002940 ret_val = -EINVAL;
Manikandan Mohanb6315dd2016-05-10 16:16:36 -07002941 }
2942 if (QDF_IS_STATUS_SUCCESS(status) || wisa_mode == false)
Leo Changfdb45c32016-10-28 11:09:23 -07002943 cdp_set_wisa_mode(soc,
2944 cdp_get_vdev_from_vdev_id(soc, pdev,
2945 adapter->sessionId),
2946 wisa_mode);
Manikandan Mohan80dea792016-04-28 16:36:48 -07002947err:
2948 EXIT();
2949 return ret_val;
2950}
2951
2952/**
2953 * wlan_hdd_cfg80211_handle_wisa_cmd() - Handle WISA vendor cmd
2954 * @wiphy: corestack handler
2955 * @wdev: wireless device
2956 * @data: data
2957 * @data_len: data length
2958 *
2959 * Handles QCA_WLAN_VENDOR_SUBCMD_WISA. Validate cmd attributes and
2960 * setup WISA mode features.
2961 *
2962 * Return: Success(0) or reason code for failure
2963 */
2964static int wlan_hdd_cfg80211_handle_wisa_cmd(struct wiphy *wiphy,
2965 struct wireless_dev *wdev,
2966 const void *data,
2967 int data_len)
2968{
2969 int ret;
2970
2971 cds_ssr_protect(__func__);
2972 ret = __wlan_hdd_cfg80211_handle_wisa_cmd(wiphy, wdev, data, data_len);
2973 cds_ssr_unprotect(__func__);
2974
2975 return ret;
2976}
2977
Anurag Chouhan96919482016-07-13 16:36:57 +05302978/*
2979 * define short names for the global vendor params
2980 * used by __wlan_hdd_cfg80211_get_station_cmd()
2981 */
2982#define STATION_INVALID \
2983 QCA_WLAN_VENDOR_ATTR_GET_STATION_INVALID
2984#define STATION_INFO \
2985 QCA_WLAN_VENDOR_ATTR_GET_STATION_INFO
2986#define STATION_ASSOC_FAIL_REASON \
2987 QCA_WLAN_VENDOR_ATTR_GET_STATION_ASSOC_FAIL_REASON
2988#define STATION_MAX \
2989 QCA_WLAN_VENDOR_ATTR_GET_STATION_MAX
2990
2991static const struct nla_policy
2992hdd_get_station_policy[STATION_MAX + 1] = {
2993 [STATION_INFO] = {.type = NLA_FLAG},
2994 [STATION_ASSOC_FAIL_REASON] = {.type = NLA_FLAG},
2995};
2996
2997/**
2998 * hdd_get_station_assoc_fail() - Handle get station assoc fail
2999 * @hdd_ctx: HDD context within host driver
3000 * @wdev: wireless device
3001 *
3002 * Handles QCA_NL80211_VENDOR_SUBCMD_GET_STATION_ASSOC_FAIL.
3003 * Validate cmd attributes and send the station info to upper layers.
3004 *
3005 * Return: Success(0) or reason code for failure
3006 */
3007static int hdd_get_station_assoc_fail(hdd_context_t *hdd_ctx,
3008 hdd_adapter_t *adapter)
3009{
3010 struct sk_buff *skb = NULL;
3011 uint32_t nl_buf_len;
3012 hdd_station_ctx_t *hdd_sta_ctx;
3013
3014 nl_buf_len = NLMSG_HDRLEN;
3015 nl_buf_len += sizeof(uint32_t);
3016 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
3017
3018 if (!skb) {
3019 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
3020 return -ENOMEM;
3021 }
3022
3023 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3024
3025 if (nla_put_u32(skb, INFO_ASSOC_FAIL_REASON,
3026 hdd_sta_ctx->conn_info.assoc_status_code)) {
3027 hdd_err("put fail");
3028 goto fail;
3029 }
3030 return cfg80211_vendor_cmd_reply(skb);
3031fail:
3032 if (skb)
3033 kfree_skb(skb);
3034 return -EINVAL;
3035}
3036
3037/**
3038 * hdd_map_auth_type() - transform auth type specific to
3039 * vendor command
3040 * @auth_type: csr auth type
3041 *
3042 * Return: Success(0) or reason code for failure
3043 */
3044static int hdd_convert_auth_type(uint32_t auth_type)
3045{
3046 uint32_t ret_val;
3047
3048 switch (auth_type) {
3049 case eCSR_AUTH_TYPE_OPEN_SYSTEM:
3050 ret_val = QCA_WLAN_AUTH_TYPE_OPEN;
3051 break;
3052 case eCSR_AUTH_TYPE_SHARED_KEY:
3053 ret_val = QCA_WLAN_AUTH_TYPE_SHARED;
3054 break;
3055 case eCSR_AUTH_TYPE_WPA:
3056 ret_val = QCA_WLAN_AUTH_TYPE_WPA;
3057 break;
3058 case eCSR_AUTH_TYPE_WPA_PSK:
3059 ret_val = QCA_WLAN_AUTH_TYPE_WPA_PSK;
3060 break;
3061 case eCSR_AUTH_TYPE_AUTOSWITCH:
3062 ret_val = QCA_WLAN_AUTH_TYPE_AUTOSWITCH;
3063 break;
3064 case eCSR_AUTH_TYPE_WPA_NONE:
3065 ret_val = QCA_WLAN_AUTH_TYPE_WPA_NONE;
3066 break;
3067 case eCSR_AUTH_TYPE_RSN:
3068 ret_val = QCA_WLAN_AUTH_TYPE_RSN;
3069 break;
3070 case eCSR_AUTH_TYPE_RSN_PSK:
3071 ret_val = QCA_WLAN_AUTH_TYPE_RSN_PSK;
3072 break;
3073 case eCSR_AUTH_TYPE_FT_RSN:
3074 ret_val = QCA_WLAN_AUTH_TYPE_FT;
3075 break;
3076 case eCSR_AUTH_TYPE_FT_RSN_PSK:
3077 ret_val = QCA_WLAN_AUTH_TYPE_FT_PSK;
3078 break;
3079 case eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE:
3080 ret_val = QCA_WLAN_AUTH_TYPE_WAI;
3081 break;
3082 case eCSR_AUTH_TYPE_WAPI_WAI_PSK:
3083 ret_val = QCA_WLAN_AUTH_TYPE_WAI_PSK;
3084 break;
3085 case eCSR_AUTH_TYPE_CCKM_WPA:
3086 ret_val = QCA_WLAN_AUTH_TYPE_CCKM_WPA;
3087 break;
3088 case eCSR_AUTH_TYPE_CCKM_RSN:
3089 ret_val = QCA_WLAN_AUTH_TYPE_CCKM_RSN;
3090 break;
3091 case eCSR_AUTH_TYPE_RSN_PSK_SHA256:
3092 ret_val = QCA_WLAN_AUTH_TYPE_SHA256_PSK;
3093 break;
3094 case eCSR_AUTH_TYPE_RSN_8021X_SHA256:
3095 ret_val = QCA_WLAN_AUTH_TYPE_SHA256;
3096 break;
3097 case eCSR_NUM_OF_SUPPORT_AUTH_TYPE:
3098 case eCSR_AUTH_TYPE_FAILED:
3099 case eCSR_AUTH_TYPE_NONE:
3100 default:
3101 ret_val = QCA_WLAN_AUTH_TYPE_INVALID;
3102 break;
3103 }
3104 return ret_val;
3105}
3106
3107/**
3108 * hdd_map_dot_11_mode() - transform dot11mode type specific to
3109 * vendor command
3110 * @dot11mode: dot11mode
3111 *
3112 * Return: Success(0) or reason code for failure
3113 */
3114static int hdd_convert_dot11mode(uint32_t dot11mode)
3115{
3116 uint32_t ret_val;
3117
3118 switch (dot11mode) {
3119 case eCSR_CFG_DOT11_MODE_11A:
3120 ret_val = QCA_WLAN_802_11_MODE_11A;
3121 break;
3122 case eCSR_CFG_DOT11_MODE_11B:
3123 ret_val = QCA_WLAN_802_11_MODE_11B;
3124 break;
3125 case eCSR_CFG_DOT11_MODE_11G:
3126 ret_val = QCA_WLAN_802_11_MODE_11G;
3127 break;
3128 case eCSR_CFG_DOT11_MODE_11N:
3129 ret_val = QCA_WLAN_802_11_MODE_11N;
3130 break;
3131 case eCSR_CFG_DOT11_MODE_11AC:
3132 ret_val = QCA_WLAN_802_11_MODE_11AC;
3133 break;
3134 case eCSR_CFG_DOT11_MODE_AUTO:
3135 case eCSR_CFG_DOT11_MODE_ABG:
3136 default:
3137 ret_val = QCA_WLAN_802_11_MODE_INVALID;
3138 }
3139 return ret_val;
3140}
3141
3142/**
3143 * hdd_add_tx_bitrate() - add tx bitrate attribute
3144 * @skb: pointer to sk buff
3145 * @hdd_sta_ctx: pointer to hdd station context
3146 * @idx: attribute index
3147 *
3148 * Return: Success(0) or reason code for failure
3149 */
3150static int32_t hdd_add_tx_bitrate(struct sk_buff *skb,
3151 hdd_station_ctx_t *hdd_sta_ctx,
3152 int idx)
3153{
3154 struct nlattr *nla_attr;
3155 uint32_t bitrate, bitrate_compat;
3156
3157 nla_attr = nla_nest_start(skb, idx);
3158 if (!nla_attr)
3159 goto fail;
3160 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3161 bitrate = cfg80211_calculate_bitrate(&hdd_sta_ctx->conn_info.txrate);
3162
3163 /* report 16-bit bitrate only if we can */
3164 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
3165 if (bitrate > 0 &&
3166 nla_put_u32(skb, NL80211_RATE_INFO_BITRATE32, bitrate)) {
3167 hdd_err("put fail");
3168 goto fail;
3169 }
3170 if (bitrate_compat > 0 &&
3171 nla_put_u16(skb, NL80211_RATE_INFO_BITRATE, bitrate_compat)) {
3172 hdd_err("put fail");
3173 goto fail;
3174 }
3175 if (nla_put_u8(skb, NL80211_RATE_INFO_VHT_NSS,
3176 hdd_sta_ctx->conn_info.txrate.nss)) {
3177 hdd_err("put fail");
3178 goto fail;
3179 }
3180 nla_nest_end(skb, nla_attr);
3181 return 0;
3182fail:
3183 return -EINVAL;
3184}
3185
3186/**
3187 * hdd_add_sta_info() - add station info attribute
3188 * @skb: pointer to sk buff
3189 * @hdd_sta_ctx: pointer to hdd station context
3190 * @idx: attribute index
3191 *
3192 * Return: Success(0) or reason code for failure
3193 */
3194static int32_t hdd_add_sta_info(struct sk_buff *skb,
3195 hdd_station_ctx_t *hdd_sta_ctx, int idx)
3196{
3197 struct nlattr *nla_attr;
3198
3199 nla_attr = nla_nest_start(skb, idx);
3200 if (!nla_attr)
3201 goto fail;
3202 if (nla_put_u8(skb, NL80211_STA_INFO_SIGNAL,
3203 (hdd_sta_ctx->conn_info.signal + 100))) {
3204 hdd_err("put fail");
3205 goto fail;
3206 }
3207 if (hdd_add_tx_bitrate(skb, hdd_sta_ctx, NL80211_STA_INFO_TX_BITRATE))
3208 goto fail;
3209 nla_nest_end(skb, nla_attr);
3210 return 0;
3211fail:
3212 return -EINVAL;
3213}
3214
3215/**
3216 * hdd_add_survey_info() - add survey info attribute
3217 * @skb: pointer to sk buff
3218 * @hdd_sta_ctx: pointer to hdd station context
3219 * @idx: attribute index
3220 *
3221 * Return: Success(0) or reason code for failure
3222 */
3223static int32_t hdd_add_survey_info(struct sk_buff *skb,
3224 hdd_station_ctx_t *hdd_sta_ctx,
3225 int idx)
3226{
3227 struct nlattr *nla_attr;
3228
3229 nla_attr = nla_nest_start(skb, idx);
3230 if (!nla_attr)
3231 goto fail;
3232 if (nla_put_u32(skb, NL80211_SURVEY_INFO_FREQUENCY,
3233 hdd_sta_ctx->conn_info.freq) ||
3234 nla_put_u8(skb, NL80211_SURVEY_INFO_NOISE,
3235 (hdd_sta_ctx->conn_info.noise + 100))) {
3236 hdd_err("put fail");
3237 goto fail;
3238 }
3239 nla_nest_end(skb, nla_attr);
3240 return 0;
3241fail:
3242 return -EINVAL;
3243}
3244
3245/**
3246 * hdd_add_link_standard_info() - add link 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_link_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 (nla_put(skb,
3263 NL80211_ATTR_SSID,
3264 hdd_sta_ctx->conn_info.SSID.SSID.length,
3265 hdd_sta_ctx->conn_info.SSID.SSID.ssId)) {
3266 hdd_err("put fail");
3267 goto fail;
3268 }
3269 if (hdd_add_survey_info(skb, hdd_sta_ctx, NL80211_ATTR_SURVEY_INFO))
3270 goto fail;
3271 if (hdd_add_sta_info(skb, hdd_sta_ctx, NL80211_ATTR_STA_INFO))
3272 goto fail;
3273 nla_nest_end(skb, nla_attr);
3274 return 0;
3275fail:
3276 return -EINVAL;
3277}
3278
3279/**
3280 * hdd_add_ap_standard_info() - add ap info attribute
3281 * @skb: pointer to sk buff
3282 * @hdd_sta_ctx: pointer to hdd station context
3283 * @idx: attribute index
3284 *
3285 * Return: Success(0) or reason code for failure
3286 */
3287static int32_t
3288hdd_add_ap_standard_info(struct sk_buff *skb,
3289 hdd_station_ctx_t *hdd_sta_ctx, int idx)
3290{
3291 struct nlattr *nla_attr;
3292
3293 nla_attr = nla_nest_start(skb, idx);
3294 if (!nla_attr)
3295 goto fail;
3296 if (hdd_sta_ctx->conn_info.conn_flag.vht_present)
3297 if (nla_put(skb, NL80211_ATTR_VHT_CAPABILITY,
3298 sizeof(hdd_sta_ctx->conn_info.vht_caps),
3299 &hdd_sta_ctx->conn_info.vht_caps)) {
3300 hdd_err("put fail");
3301 goto fail;
3302 }
3303 if (hdd_sta_ctx->conn_info.conn_flag.ht_present)
3304 if (nla_put(skb, NL80211_ATTR_HT_CAPABILITY,
3305 sizeof(hdd_sta_ctx->conn_info.ht_caps),
3306 &hdd_sta_ctx->conn_info.ht_caps)) {
3307 hdd_err("put fail");
3308 goto fail;
3309 }
3310 nla_nest_end(skb, nla_attr);
3311 return 0;
3312fail:
3313 return -EINVAL;
3314}
3315
3316/**
3317 * hdd_get_station_info() - send BSS information to supplicant
3318 * @hdd_ctx: pointer to hdd context
3319 * @adapter: pointer to adapter
3320 *
3321 * Return: 0 if success else error status
3322 */
3323static int hdd_get_station_info(hdd_context_t *hdd_ctx,
3324 hdd_adapter_t *adapter)
3325{
3326 struct sk_buff *skb = NULL;
3327 uint8_t *tmp_hs20 = NULL;
3328 uint32_t nl_buf_len;
3329 hdd_station_ctx_t *hdd_sta_ctx;
3330
3331 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3332
3333 nl_buf_len = NLMSG_HDRLEN;
3334 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.SSID.SSID.length) +
3335 sizeof(hdd_sta_ctx->conn_info.freq) +
3336 sizeof(hdd_sta_ctx->conn_info.noise) +
3337 sizeof(hdd_sta_ctx->conn_info.signal) +
3338 (sizeof(uint32_t) * 2) +
3339 sizeof(hdd_sta_ctx->conn_info.txrate.nss) +
3340 sizeof(hdd_sta_ctx->conn_info.roam_count) +
3341 sizeof(hdd_sta_ctx->conn_info.authType) +
3342 sizeof(hdd_sta_ctx->conn_info.dot11Mode);
3343 if (hdd_sta_ctx->conn_info.conn_flag.vht_present)
3344 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.vht_caps);
3345 if (hdd_sta_ctx->conn_info.conn_flag.ht_present)
3346 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.ht_caps);
3347 if (hdd_sta_ctx->conn_info.conn_flag.hs20_present) {
3348 tmp_hs20 = (uint8_t *)&(hdd_sta_ctx->conn_info.hs20vendor_ie);
3349 nl_buf_len += (sizeof(hdd_sta_ctx->conn_info.hs20vendor_ie) -
3350 1);
3351 }
3352 if (hdd_sta_ctx->conn_info.conn_flag.ht_op_present)
3353 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.ht_operation);
3354 if (hdd_sta_ctx->conn_info.conn_flag.vht_op_present)
3355 nl_buf_len += sizeof(hdd_sta_ctx->conn_info.vht_operation);
3356
3357
3358 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
3359 if (!skb) {
3360 hdd_err(FL("cfg80211_vendor_cmd_alloc_reply_skb failed"));
3361 return -ENOMEM;
3362 }
3363
3364 if (hdd_add_link_standard_info(skb, hdd_sta_ctx,
3365 LINK_INFO_STANDARD_NL80211_ATTR)) {
3366 hdd_err("put fail");
3367 goto fail;
3368 }
3369 if (hdd_add_ap_standard_info(skb, hdd_sta_ctx,
3370 AP_INFO_STANDARD_NL80211_ATTR)) {
3371 hdd_err("put fail");
3372 goto fail;
3373 }
3374 if (nla_put_u32(skb, INFO_ROAM_COUNT,
3375 hdd_sta_ctx->conn_info.roam_count) ||
3376 nla_put_u32(skb, INFO_AKM,
3377 hdd_convert_auth_type(
3378 hdd_sta_ctx->conn_info.authType)) ||
3379 nla_put_u32(skb, WLAN802_11_MODE,
3380 hdd_convert_dot11mode(
3381 hdd_sta_ctx->conn_info.dot11Mode))) {
3382 hdd_err("put fail");
3383 goto fail;
3384 }
3385 if (hdd_sta_ctx->conn_info.conn_flag.ht_op_present)
3386 if (nla_put(skb, HT_OPERATION,
3387 (sizeof(hdd_sta_ctx->conn_info.ht_operation)),
3388 &hdd_sta_ctx->conn_info.ht_operation)) {
3389 hdd_err("put fail");
3390 goto fail;
3391 }
3392 if (hdd_sta_ctx->conn_info.conn_flag.vht_op_present)
3393 if (nla_put(skb, VHT_OPERATION,
3394 (sizeof(hdd_sta_ctx->conn_info.vht_operation)),
3395 &hdd_sta_ctx->conn_info.vht_operation)) {
3396 hdd_err("put fail");
3397 goto fail;
3398 }
3399 if (hdd_sta_ctx->conn_info.conn_flag.hs20_present)
3400 if (nla_put(skb, AP_INFO_HS20_INDICATION,
3401 (sizeof(hdd_sta_ctx->conn_info.hs20vendor_ie) - 1),
3402 tmp_hs20 + 1)) {
3403 hdd_err("put fail");
3404 goto fail;
3405 }
3406
3407 return cfg80211_vendor_cmd_reply(skb);
3408fail:
3409 if (skb)
3410 kfree_skb(skb);
3411 return -EINVAL;
3412}
3413
3414/**
3415 * __hdd_cfg80211_get_station_cmd() - Handle get station vendor cmd
3416 * @wiphy: corestack handler
3417 * @wdev: wireless device
3418 * @data: data
3419 * @data_len: data length
3420 *
3421 * Handles QCA_NL80211_VENDOR_SUBCMD_GET_STATION.
3422 * Validate cmd attributes and send the station info to upper layers.
3423 *
3424 * Return: Success(0) or reason code for failure
3425 */
Anurag Chouhand939d3d2016-07-20 17:45:48 +05303426static int
Anurag Chouhan96919482016-07-13 16:36:57 +05303427__hdd_cfg80211_get_station_cmd(struct wiphy *wiphy,
3428 struct wireless_dev *wdev,
3429 const void *data,
3430 int data_len)
3431{
3432 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
3433 struct net_device *dev = wdev->netdev;
3434 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
3435 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GET_STATION_MAX + 1];
3436 int32_t status;
3437
3438 ENTER_DEV(dev);
3439 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
3440 hdd_err("Command not allowed in FTM mode");
3441 status = -EPERM;
3442 goto out;
3443 }
3444
3445 status = wlan_hdd_validate_context(hdd_ctx);
3446 if (0 != status)
3447 goto out;
3448
3449
3450 status = nla_parse(tb, QCA_WLAN_VENDOR_ATTR_GET_STATION_MAX,
3451 data, data_len, NULL);
3452 if (status) {
3453 hdd_err("Invalid ATTR");
3454 goto out;
3455 }
3456
3457 /* Parse and fetch Command Type*/
3458 if (tb[STATION_INFO]) {
3459 status = hdd_get_station_info(hdd_ctx, adapter);
3460 } else if (tb[STATION_ASSOC_FAIL_REASON]) {
3461 status = hdd_get_station_assoc_fail(hdd_ctx, adapter);
3462 } else {
3463 hdd_err("get station info cmd type failed");
3464 status = -EINVAL;
3465 goto out;
3466 }
3467 EXIT();
3468out:
3469 return status;
3470}
3471
3472/**
3473 * wlan_hdd_cfg80211_get_station_cmd() - Handle get station vendor cmd
3474 * @wiphy: corestack handler
3475 * @wdev: wireless device
3476 * @data: data
3477 * @data_len: data length
3478 *
3479 * Handles QCA_NL80211_VENDOR_SUBCMD_GET_STATION.
3480 * Validate cmd attributes and send the station info to upper layers.
3481 *
3482 * Return: Success(0) or reason code for failure
3483 */
3484static int32_t
3485hdd_cfg80211_get_station_cmd(struct wiphy *wiphy,
3486 struct wireless_dev *wdev,
3487 const void *data,
3488 int data_len)
3489{
3490 int ret;
3491
3492 cds_ssr_protect(__func__);
3493 ret = __hdd_cfg80211_get_station_cmd(wiphy, wdev, data, data_len);
3494 cds_ssr_unprotect(__func__);
3495
3496 return ret;
3497}
3498
3499/*
3500 * undef short names defined for get station command
3501 * used by __wlan_hdd_cfg80211_get_station_cmd()
3502 */
3503#undef STATION_INVALID
3504#undef STATION_INFO
3505#undef STATION_ASSOC_FAIL_REASON
3506#undef STATION_MAX
3507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003508#ifdef WLAN_FEATURE_ROAM_OFFLOAD
3509/**
3510 * __wlan_hdd_cfg80211_keymgmt_set_key() - Store the Keys in the driver session
3511 * @wiphy: pointer to wireless wiphy structure.
3512 * @wdev: pointer to wireless_dev structure.
3513 * @data: Pointer to the Key data
3514 * @data_len:Length of the data passed
3515 *
3516 * This is called when wlan driver needs to save the keys received via
3517 * vendor specific command.
3518 *
3519 * Return: Return the Success or Failure code.
3520 */
3521static int __wlan_hdd_cfg80211_keymgmt_set_key(struct wiphy *wiphy,
3522 struct wireless_dev *wdev,
3523 const void *data, int data_len)
3524{
3525 uint8_t local_pmk[SIR_ROAM_SCAN_PSK_SIZE];
3526 struct net_device *dev = wdev->netdev;
3527 hdd_adapter_t *hdd_adapter_ptr = WLAN_HDD_GET_PRIV_PTR(dev);
3528 hdd_context_t *hdd_ctx_ptr;
3529 int status;
3530
Jeff Johnson1f61b612016-02-12 16:28:33 -08003531 ENTER_DEV(dev);
3532
Anurag Chouhan6d760662016-02-20 16:05:43 +05303533 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003534 hdd_err("Command not allowed in FTM mode");
3535 return -EPERM;
3536 }
3537
3538 if ((data == NULL) || (data_len == 0) ||
3539 (data_len > SIR_ROAM_SCAN_PSK_SIZE)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003540 hdd_err("Invalid data");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541 return -EINVAL;
3542 }
3543
3544 hdd_ctx_ptr = WLAN_HDD_GET_CTX(hdd_adapter_ptr);
3545 if (!hdd_ctx_ptr) {
Jeff Johnson020db452016-06-29 14:37:26 -07003546 hdd_err("HDD context is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003547 return -EINVAL;
3548 }
3549
3550 status = wlan_hdd_validate_context(hdd_ctx_ptr);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303551 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553 sme_update_roam_key_mgmt_offload_enabled(hdd_ctx_ptr->hHal,
3554 hdd_adapter_ptr->sessionId,
Deepak Dhamdheref2a7d8b2016-08-19 16:17:38 -07003555 true,
3556 hdd_is_okc_mode_enabled(hdd_ctx_ptr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303557 qdf_mem_zero(&local_pmk, SIR_ROAM_SCAN_PSK_SIZE);
3558 qdf_mem_copy(local_pmk, data, data_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559 sme_roam_set_psk_pmk(WLAN_HDD_GET_HAL_CTX(hdd_adapter_ptr),
3560 hdd_adapter_ptr->sessionId, local_pmk, data_len);
3561 return 0;
3562}
3563
3564/**
3565 * wlan_hdd_cfg80211_keymgmt_set_key() - Store the Keys in the driver session
3566 * @wiphy: pointer to wireless wiphy structure.
3567 * @wdev: pointer to wireless_dev structure.
3568 * @data: Pointer to the Key data
3569 * @data_len:Length of the data passed
3570 *
3571 * This is called when wlan driver needs to save the keys received via
3572 * vendor specific command.
3573 *
3574 * Return: Return the Success or Failure code.
3575 */
3576static int wlan_hdd_cfg80211_keymgmt_set_key(struct wiphy *wiphy,
3577 struct wireless_dev *wdev,
3578 const void *data, int data_len)
3579{
3580 int ret;
3581
3582 cds_ssr_protect(__func__);
3583 ret = __wlan_hdd_cfg80211_keymgmt_set_key(wiphy, wdev, data, data_len);
3584 cds_ssr_unprotect(__func__);
3585
3586 return ret;
3587}
Varun Reddy Yeturubbbbe232016-02-29 14:01:57 -08003588#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589
3590static const struct nla_policy qca_wlan_vendor_get_wifi_info_policy[
3591 QCA_WLAN_VENDOR_ATTR_WIFI_INFO_GET_MAX + 1] = {
3592 [QCA_WLAN_VENDOR_ATTR_WIFI_INFO_DRIVER_VERSION] = {.type = NLA_U8 },
3593 [QCA_WLAN_VENDOR_ATTR_WIFI_INFO_FIRMWARE_VERSION] = {.type = NLA_U8 },
Ryan Hsu7ac88852016-04-28 10:20:34 -07003594 [QCA_WLAN_VENDOR_ATTR_WIFI_INFO_RADIO_INDEX] = {.type = NLA_U32 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595};
3596
3597/**
3598 * __wlan_hdd_cfg80211_get_wifi_info() - Get the wifi driver related info
3599 * @wiphy: pointer to wireless wiphy structure.
3600 * @wdev: pointer to wireless_dev structure.
3601 * @data: Pointer to the data to be passed via vendor interface
3602 * @data_len:Length of the data to be passed
3603 *
3604 * This is called when wlan driver needs to send wifi driver related info
3605 * (driver/fw version) to the user space application upon request.
3606 *
3607 * Return: Return the Success or Failure code.
3608 */
3609static int
3610__wlan_hdd_cfg80211_get_wifi_info(struct wiphy *wiphy,
3611 struct wireless_dev *wdev,
3612 const void *data, int data_len)
3613{
3614 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
3615 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_GET_MAX + 1];
Ryan Hsu7ac88852016-04-28 10:20:34 -07003616 tSirVersionString driver_version;
3617 tSirVersionString firmware_version;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 uint32_t major_spid = 0, minor_spid = 0, siid = 0, crmid = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003619 int status;
Ryan Hsu7ac88852016-04-28 10:20:34 -07003620 struct sk_buff *reply_skb;
3621 uint32_t skb_len = 0, count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622
Jeff Johnson1f61b612016-02-12 16:28:33 -08003623 ENTER_DEV(wdev->netdev);
3624
Anurag Chouhan6d760662016-02-20 16:05:43 +05303625 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626 hdd_err("Command not allowed in FTM mode");
3627 return -EPERM;
3628 }
3629
3630 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303631 if (status)
3632 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003633
3634 if (nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_WIFI_INFO_GET_MAX, data,
3635 data_len, qca_wlan_vendor_get_wifi_info_policy)) {
Ryan Hsu7ac88852016-04-28 10:20:34 -07003636 hdd_err("WIFI_INFO_GET NL CMD parsing failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637 return -EINVAL;
3638 }
3639
3640 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_DRIVER_VERSION]) {
Ryan Hsu7ac88852016-04-28 10:20:34 -07003641 hdd_err("Rcvd req for Driver version");
3642 strlcpy(driver_version, QWLAN_VERSIONSTR,
3643 sizeof(driver_version));
3644 skb_len += strlen(driver_version) + 1;
3645 count++;
3646 }
3647
3648 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_FIRMWARE_VERSION]) {
3649 hdd_info("Rcvd req for FW version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650 hdd_get_fw_version(hdd_ctx, &major_spid, &minor_spid, &siid,
3651 &crmid);
Ryan Hsu7ac88852016-04-28 10:20:34 -07003652 snprintf(firmware_version, sizeof(firmware_version),
3653 "%d:%d:%d:%d", major_spid, minor_spid, siid, crmid);
3654 skb_len += strlen(firmware_version) + 1;
3655 count++;
3656 }
3657
3658 if (count == 0) {
3659 hdd_err("unknown attribute in get_wifi_info request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 return -EINVAL;
3661 }
3662
Ryan Hsu7ac88852016-04-28 10:20:34 -07003663 skb_len += (NLA_HDRLEN * count) + NLMSG_HDRLEN;
3664 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, skb_len);
3665
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003666 if (!reply_skb) {
Ryan Hsu7ac88852016-04-28 10:20:34 -07003667 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003668 return -ENOMEM;
3669 }
3670
Ryan Hsu7ac88852016-04-28 10:20:34 -07003671 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_DRIVER_VERSION]) {
3672 if (nla_put_string(reply_skb,
3673 QCA_WLAN_VENDOR_ATTR_WIFI_INFO_DRIVER_VERSION,
3674 driver_version))
3675 goto error_nla_fail;
3676 }
3677
Hanumanth Reddy Pothula1046ccc2016-10-14 14:33:44 +05303678 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_FIRMWARE_VERSION]) {
Ryan Hsu7ac88852016-04-28 10:20:34 -07003679 if (nla_put_string(reply_skb,
3680 QCA_WLAN_VENDOR_ATTR_WIFI_INFO_FIRMWARE_VERSION,
3681 firmware_version))
3682 goto error_nla_fail;
3683 }
3684
3685 if (tb_vendor[QCA_WLAN_VENDOR_ATTR_WIFI_INFO_RADIO_INDEX]) {
3686 if (nla_put_u32(reply_skb,
3687 QCA_WLAN_VENDOR_ATTR_WIFI_INFO_RADIO_INDEX,
3688 hdd_ctx->radio_index))
3689 goto error_nla_fail;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003690 }
3691
3692 return cfg80211_vendor_cmd_reply(reply_skb);
Ryan Hsu7ac88852016-04-28 10:20:34 -07003693
3694error_nla_fail:
3695 hdd_err("nla put fail");
3696 kfree_skb(reply_skb);
3697 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003698}
3699
3700/**
3701 * wlan_hdd_cfg80211_get_wifi_info() - Get the wifi driver related info
3702 * @wiphy: pointer to wireless wiphy structure.
3703 * @wdev: pointer to wireless_dev structure.
3704 * @data: Pointer to the data to be passed via vendor interface
3705 * @data_len:Length of the data to be passed
3706 *
3707 * This is called when wlan driver needs to send wifi driver related info
3708 * (driver/fw version) to the user space application upon request.
3709 *
3710 * Return: Return the Success or Failure code.
3711 */
3712static int
3713wlan_hdd_cfg80211_get_wifi_info(struct wiphy *wiphy,
3714 struct wireless_dev *wdev,
3715 const void *data, int data_len)
3716{
3717 int ret;
3718
3719 cds_ssr_protect(__func__);
3720 ret = __wlan_hdd_cfg80211_get_wifi_info(wiphy, wdev, data, data_len);
3721 cds_ssr_unprotect(__func__);
3722
3723 return ret;
3724}
3725
3726/**
3727 * __wlan_hdd_cfg80211_get_logger_supp_feature() - Get the wifi logger features
3728 * @wiphy: pointer to wireless wiphy structure.
3729 * @wdev: pointer to wireless_dev structure.
3730 * @data: Pointer to the data to be passed via vendor interface
3731 * @data_len:Length of the data to be passed
3732 *
3733 * This is called by userspace to know the supported logger features
3734 *
3735 * Return: Return the Success or Failure code.
3736 */
3737static int
3738__wlan_hdd_cfg80211_get_logger_supp_feature(struct wiphy *wiphy,
3739 struct wireless_dev *wdev,
3740 const void *data, int data_len)
3741{
3742 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
3743 int status;
3744 uint32_t features;
3745 struct sk_buff *reply_skb = NULL;
3746
Jeff Johnson1f61b612016-02-12 16:28:33 -08003747 ENTER_DEV(wdev->netdev);
3748
Anurag Chouhan6d760662016-02-20 16:05:43 +05303749 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750 hdd_err("Command not allowed in FTM mode");
3751 return -EPERM;
3752 }
3753
3754 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303755 if (status)
3756 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003757
3758 features = 0;
3759
3760 if (hdd_is_memdump_supported())
3761 features |= WIFI_LOGGER_MEMORY_DUMP_SUPPORTED;
3762 features |= WIFI_LOGGER_PER_PACKET_TX_RX_STATUS_SUPPORTED;
3763 features |= WIFI_LOGGER_CONNECT_EVENT_SUPPORTED;
3764 features |= WIFI_LOGGER_WAKE_LOCK_SUPPORTED;
3765
3766 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy,
3767 sizeof(uint32_t) + NLA_HDRLEN + NLMSG_HDRLEN);
3768 if (!reply_skb) {
Jeff Johnson020db452016-06-29 14:37:26 -07003769 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003770 return -ENOMEM;
3771 }
3772
Jeff Johnson020db452016-06-29 14:37:26 -07003773 hdd_notice("Supported logger features: 0x%0x", features);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774 if (nla_put_u32(reply_skb, QCA_WLAN_VENDOR_ATTR_LOGGER_SUPPORTED,
3775 features)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003776 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003777 kfree_skb(reply_skb);
3778 return -EINVAL;
3779 }
3780
3781 return cfg80211_vendor_cmd_reply(reply_skb);
3782}
3783
3784/**
3785 * wlan_hdd_cfg80211_get_logger_supp_feature() - Get the wifi logger features
3786 * @wiphy: pointer to wireless wiphy structure.
3787 * @wdev: pointer to wireless_dev structure.
3788 * @data: Pointer to the data to be passed via vendor interface
3789 * @data_len:Length of the data to be passed
3790 *
3791 * This is called by userspace to know the supported logger features
3792 *
3793 * Return: Return the Success or Failure code.
3794 */
3795static int
3796wlan_hdd_cfg80211_get_logger_supp_feature(struct wiphy *wiphy,
3797 struct wireless_dev *wdev,
3798 const void *data, int data_len)
3799{
3800 int ret;
3801
3802 cds_ssr_protect(__func__);
3803 ret = __wlan_hdd_cfg80211_get_logger_supp_feature(wiphy, wdev,
3804 data, data_len);
3805 cds_ssr_unprotect(__func__);
3806
3807 return ret;
3808}
3809
Varun Reddy Yeturubbbbe232016-02-29 14:01:57 -08003810#ifdef WLAN_FEATURE_ROAM_OFFLOAD
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811/**
3812 * wlan_hdd_send_roam_auth_event() - Send the roamed and authorized event
Prakash Dhavali989127d2016-11-29 14:56:44 +05303813 * @adapter: Pointer to adapter struct
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003814 * @bssid: pointer to bssid of roamed AP.
3815 * @req_rsn_ie: Pointer to request RSN IE
3816 * @req_rsn_len: Length of the request RSN IE
3817 * @rsp_rsn_ie: Pointer to response RSN IE
3818 * @rsp_rsn_len: Length of the response RSN IE
3819 * @roam_info_ptr: Pointer to the roaming related information
3820 *
3821 * This is called when wlan driver needs to send the roaming and
3822 * authorization information after roaming.
3823 *
3824 * The information that would be sent is the request RSN IE, response
3825 * RSN IE and BSSID of the newly roamed AP.
3826 *
3827 * If the Authorized status is authenticated, then additional parameters
3828 * like PTK's KCK and KEK and Replay Counter would also be passed to the
3829 * supplicant.
3830 *
3831 * The supplicant upon receiving this event would ignore the legacy
3832 * cfg80211_roamed call and use the entire information from this event.
3833 * The cfg80211_roamed should still co-exist since the kernel will
3834 * make use of the parameters even if the supplicant ignores it.
3835 *
3836 * Return: Return the Success or Failure code.
3837 */
Prakash Dhavali989127d2016-11-29 14:56:44 +05303838int wlan_hdd_send_roam_auth_event(hdd_adapter_t *adapter, uint8_t *bssid,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839 uint8_t *req_rsn_ie, uint32_t req_rsn_len, uint8_t *rsp_rsn_ie,
3840 uint32_t rsp_rsn_len, tCsrRoamInfo *roam_info_ptr)
3841{
Prakash Dhavali989127d2016-11-29 14:56:44 +05303842 hdd_context_t *hdd_ctx_ptr = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003843 struct sk_buff *skb = NULL;
Varun Reddy Yeturu16e8f012016-02-03 17:21:09 -08003844 eCsrAuthType auth_type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845 ENTER();
3846
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303847 if (wlan_hdd_validate_context(hdd_ctx_ptr))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003848 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003849
Varun Reddy Yeturud351a6c2016-03-16 14:01:00 -07003850 if (!roaming_offload_enabled(hdd_ctx_ptr) ||
Prashanth Bhattabfc25292015-11-05 11:16:21 -08003851 !roam_info_ptr->roamSynchInProgress)
3852 return 0;
3853
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854 skb = cfg80211_vendor_event_alloc(hdd_ctx_ptr->wiphy,
Prakash Dhavali989127d2016-11-29 14:56:44 +05303855 &(adapter->wdev),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003856 ETH_ALEN + req_rsn_len + rsp_rsn_len +
3857 sizeof(uint8_t) + SIR_REPLAY_CTR_LEN +
3858 SIR_KCK_KEY_LEN + SIR_KCK_KEY_LEN +
Ravi Joshi277ae9b2015-11-13 11:30:43 -08003859 sizeof(uint8_t) + (8 * NLMSG_HDRLEN),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_ROAM_AUTH_INDEX,
3861 GFP_KERNEL);
3862
3863 if (!skb) {
Jeff Johnson020db452016-06-29 14:37:26 -07003864 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003865 return -EINVAL;
3866 }
3867
3868 if (nla_put(skb, QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_BSSID,
3869 ETH_ALEN, bssid) ||
3870 nla_put(skb, QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_REQ_IE,
3871 req_rsn_len, req_rsn_ie) ||
3872 nla_put(skb, QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_RESP_IE,
3873 rsp_rsn_len, rsp_rsn_ie)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003874 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003875 goto nla_put_failure;
3876 }
Jeff Johnson020db452016-06-29 14:37:26 -07003877 hdd_debug("Auth Status = %d", roam_info_ptr->synchAuthStatus);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878 if (roam_info_ptr->synchAuthStatus ==
3879 CSR_ROAM_AUTH_STATUS_AUTHENTICATED) {
Jeff Johnson020db452016-06-29 14:37:26 -07003880 hdd_debug("Include Auth Params TLV's");
Naveen Rawat14298b92015-11-25 16:27:41 -08003881 if (nla_put_u8(skb,
3882 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_AUTHORIZED, true)) {
3883 hdd_err("nla put fail");
3884 goto nla_put_failure;
3885 }
Varun Reddy Yeturu16e8f012016-02-03 17:21:09 -08003886 auth_type = roam_info_ptr->u.pConnectedProfile->AuthType;
3887 /* if FT or CCKM connection: dont send replay counter */
3888 if (auth_type != eCSR_AUTH_TYPE_FT_RSN &&
3889 auth_type != eCSR_AUTH_TYPE_FT_RSN_PSK &&
3890 auth_type != eCSR_AUTH_TYPE_CCKM_WPA &&
3891 auth_type != eCSR_AUTH_TYPE_CCKM_RSN &&
3892 nla_put(skb,
3893 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_KEY_REPLAY_CTR,
3894 SIR_REPLAY_CTR_LEN,
3895 roam_info_ptr->replay_ctr)) {
3896 hdd_err("non FT/non CCKM connection.");
Naveen Rawat14298b92015-11-25 16:27:41 -08003897 hdd_err("failed to send replay counter.");
3898 goto nla_put_failure;
3899 }
3900 if (nla_put(skb,
3901 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_PTK_KCK,
3902 SIR_KCK_KEY_LEN, roam_info_ptr->kck) ||
3903 nla_put(skb,
3904 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_PTK_KEK,
3905 SIR_KEK_KEY_LEN, roam_info_ptr->kek)) {
3906 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 goto nla_put_failure;
3908 }
3909 } else {
Jeff Johnson020db452016-06-29 14:37:26 -07003910 hdd_debug("No Auth Params TLV's");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911 if (nla_put_u8(skb, QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_AUTHORIZED,
3912 false)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003913 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 goto nla_put_failure;
3915 }
3916 }
3917
Jeff Johnson020db452016-06-29 14:37:26 -07003918 hdd_debug("Subnet Change Status = %d",
Ravi Joshi277ae9b2015-11-13 11:30:43 -08003919 roam_info_ptr->subnet_change_status);
3920
3921 /*
3922 * Add subnet change status if subnet has changed
3923 * 0 = unchanged
3924 * 1 = changed
3925 * 2 = unknown
3926 */
3927 if (roam_info_ptr->subnet_change_status) {
3928 if (nla_put_u8(skb,
3929 QCA_WLAN_VENDOR_ATTR_ROAM_AUTH_SUBNET_STATUS,
3930 roam_info_ptr->subnet_change_status)) {
Jeff Johnson020db452016-06-29 14:37:26 -07003931 hdd_err("nla put fail");
Ravi Joshi277ae9b2015-11-13 11:30:43 -08003932 goto nla_put_failure;
3933 }
3934 }
3935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 cfg80211_vendor_event(skb, GFP_KERNEL);
3937 return 0;
3938
3939nla_put_failure:
3940 kfree_skb(skb);
3941 return -EINVAL;
3942}
Varun Reddy Yeturubbbbe232016-02-29 14:01:57 -08003943#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944
3945static const struct nla_policy
3946wlan_hdd_wifi_config_policy[QCA_WLAN_VENDOR_ATTR_CONFIG_MAX + 1] = {
3947
3948 [QCA_WLAN_VENDOR_ATTR_CONFIG_MODULATED_DTIM] = {.type = NLA_U32 },
3949 [QCA_WLAN_VENDOR_ATTR_CONFIG_STATS_AVG_FACTOR] = {.type = NLA_U16 },
3950 [QCA_WLAN_VENDOR_ATTR_CONFIG_GUARD_TIME] = {.type = NLA_U32 },
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05303951 [QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_AVOIDANCE_IND] = {.type = NLA_U8 },
Padma, Santhosh Kumara7119672016-08-16 16:05:14 +05303952 [QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MPDU_AGGREGATION] = {.type = NLA_U8 },
3953 [QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MPDU_AGGREGATION] = {.type = NLA_U8 },
Zhang Qiana3bcbe02016-08-12 16:20:36 +08003954 [QCA_WLAN_VENDOR_ATTR_CONFIG_NON_AGG_RETRY] = {.type = NLA_U8 },
3955 [QCA_WLAN_VENDOR_ATTR_CONFIG_AGG_RETRY] = {.type = NLA_U8 },
3956 [QCA_WLAN_VENDOR_ATTR_CONFIG_MGMT_RETRY] = {.type = NLA_U8 },
3957 [QCA_WLAN_VENDOR_ATTR_CONFIG_CTRL_RETRY] = {.type = NLA_U8 },
3958 [QCA_WLAN_VENDOR_ATTR_CONFIG_PROPAGATION_DELAY] = {.type = NLA_U8 },
Agrawal, Ashishb45599a2016-10-27 14:55:30 +05303959 [QCA_WLAN_VENDOR_ATTR_CONFIG_TX_FAIL_COUNT] = {.type = NLA_U32 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960};
3961
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962/**
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303963 * wlan_hdd_save_default_scan_ies() - API to store the default scan IEs
3964 *
3965 * @adapter: Pointer to HDD adapter
3966 * @ie_data: Pointer to Scan IEs buffer
3967 * @ie_len: Length of Scan IEs
3968 *
3969 * Return: 0 on success; error number otherwise
3970 */
3971static int wlan_hdd_save_default_scan_ies(hdd_adapter_t *adapter,
3972 uint8_t *ie_data, uint8_t ie_len)
3973{
3974 hdd_scaninfo_t *scan_info = NULL;
3975 scan_info = &adapter->scan_info;
3976
3977 if (scan_info->default_scan_ies) {
3978 qdf_mem_free(scan_info->default_scan_ies);
3979 scan_info->default_scan_ies = NULL;
3980 }
3981
3982 scan_info->default_scan_ies = qdf_mem_malloc(ie_len);
3983 if (!scan_info->default_scan_ies)
3984 return -ENOMEM;
3985
3986 memcpy(scan_info->default_scan_ies, ie_data, ie_len);
3987 scan_info->default_scan_ies_len = ie_len;
3988 return 0;
3989}
3990
3991/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992 * __wlan_hdd_cfg80211_wifi_configuration_set() - Wifi configuration
3993 * vendor command
3994 *
3995 * @wiphy: wiphy device pointer
3996 * @wdev: wireless device pointer
3997 * @data: Vendor command data buffer
3998 * @data_len: Buffer length
3999 *
4000 * Handles QCA_WLAN_VENDOR_ATTR_CONFIG_MAX.
4001 *
4002 * Return: Error code.
4003 */
4004static int
4005__wlan_hdd_cfg80211_wifi_configuration_set(struct wiphy *wiphy,
4006 struct wireless_dev *wdev,
4007 const void *data,
4008 int data_len)
4009{
4010 struct net_device *dev = wdev->netdev;
4011 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
4012 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
4013 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MAX + 1];
4014 int ret_val = 0;
4015 u32 modulated_dtim;
4016 u16 stats_avg_factor;
4017 u32 guard_time;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05304018 uint8_t set_value;
Krunal Sonie3531942016-04-12 17:43:53 -07004019 u32 ftm_capab;
Dustin Brown10a7b712016-10-07 10:31:16 -07004020 u8 qpower;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304021 QDF_STATUS status;
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304022 int attr_len;
4023 int access_policy = 0;
4024 char vendor_ie[SIR_MAC_MAX_IE_LENGTH + 2];
4025 bool vendor_ie_present = false, access_policy_present = false;
Deepak Dhamdhereb106ae52016-08-10 20:55:30 +05304026 uint16_t scan_ie_len = 0;
4027 uint8_t *scan_ie;
Padma, Santhosh Kumara7119672016-08-16 16:05:14 +05304028 struct sir_set_tx_rx_aggregation_size request;
4029 QDF_STATUS qdf_status;
Zhang Qiana3bcbe02016-08-12 16:20:36 +08004030 uint8_t retry, delay;
4031 int param_id;
Agrawal, Ashishb45599a2016-10-27 14:55:30 +05304032 uint32_t tx_fail_count;
Deepak Dhamdhereb106ae52016-08-10 20:55:30 +05304033
Jeff Johnson1f61b612016-02-12 16:28:33 -08004034 ENTER_DEV(dev);
4035
Anurag Chouhan6d760662016-02-20 16:05:43 +05304036 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037 hdd_err("Command not allowed in FTM mode");
4038 return -EPERM;
4039 }
4040
4041 ret_val = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304042 if (ret_val)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044
4045 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_CONFIG_MAX,
4046 data, data_len,
4047 wlan_hdd_wifi_config_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004048 hdd_err("invalid attr");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 return -EINVAL;
4050 }
4051
Krunal Sonie3531942016-04-12 17:43:53 -07004052 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_FINE_TIME_MEASUREMENT]) {
4053 ftm_capab = nla_get_u32(tb[
4054 QCA_WLAN_VENDOR_ATTR_CONFIG_FINE_TIME_MEASUREMENT]);
4055 hdd_ctx->config->fine_time_meas_cap =
4056 hdd_ctx->fine_time_meas_cap_target & ftm_capab;
4057 sme_update_fine_time_measurement_capab(hdd_ctx->hHal,
Selvaraj, Sridhar57bb4d02016-08-31 16:14:15 +05304058 adapter->sessionId,
Krunal Sonie3531942016-04-12 17:43:53 -07004059 hdd_ctx->config->fine_time_meas_cap);
4060 hdd_info("FTM capability: user value: 0x%x, target value: 0x%x, final value: 0x%x",
4061 ftm_capab, hdd_ctx->fine_time_meas_cap_target,
4062 hdd_ctx->config->fine_time_meas_cap);
4063 }
4064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MODULATED_DTIM]) {
4066 modulated_dtim = nla_get_u32(
4067 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MODULATED_DTIM]);
4068
4069 status = sme_configure_modulated_dtim(hdd_ctx->hHal,
4070 adapter->sessionId,
4071 modulated_dtim);
4072
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304073 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074 ret_val = -EPERM;
4075 }
4076
Kapil Gupta6213c012016-09-02 19:39:09 +05304077 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_QPOWER]) {
4078 qpower = nla_get_u8(
4079 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_QPOWER]);
4080 if (hdd_set_qpower_config(hdd_ctx, adapter, qpower) != 0)
4081 ret_val = -EINVAL;
4082 }
4083
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004084 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_STATS_AVG_FACTOR]) {
4085 stats_avg_factor = nla_get_u16(
4086 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_STATS_AVG_FACTOR]);
4087 status = sme_configure_stats_avg_factor(hdd_ctx->hHal,
4088 adapter->sessionId,
4089 stats_avg_factor);
4090
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304091 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004092 ret_val = -EPERM;
4093 }
4094
4095
4096 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_GUARD_TIME]) {
4097 guard_time = nla_get_u32(
4098 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_GUARD_TIME]);
4099 status = sme_configure_guard_time(hdd_ctx->hHal,
4100 adapter->sessionId,
4101 guard_time);
4102
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304103 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104 ret_val = -EPERM;
4105 }
4106
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304107 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY_IE_LIST]) {
4108 qdf_mem_zero(&vendor_ie[0], SIR_MAC_MAX_IE_LENGTH + 2);
4109 attr_len = nla_len(
4110 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY_IE_LIST]);
4111 if (attr_len < 0 || attr_len > SIR_MAC_MAX_IE_LENGTH + 2) {
4112 hdd_info("Invalid value. attr_len %d",
4113 attr_len);
4114 return -EINVAL;
4115 }
4116
4117 nla_memcpy(&vendor_ie,
4118 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY_IE_LIST],
4119 attr_len);
4120 vendor_ie_present = true;
4121 hdd_info("Access policy vendor ie present.attr_len %d",
4122 attr_len);
4123 qdf_trace_hex_dump(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
4124 &vendor_ie[0], attr_len);
4125 }
4126
4127 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY]) {
4128 access_policy = (int) nla_get_u32(
4129 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_ACCESS_POLICY]);
4130 if ((access_policy < QCA_ACCESS_POLICY_ACCEPT_UNLESS_LISTED) ||
4131 (access_policy >
4132 QCA_ACCESS_POLICY_DENY_UNLESS_LISTED)) {
4133 hdd_info("Invalid value. access_policy %d",
4134 access_policy);
4135 return -EINVAL;
4136 }
4137 access_policy_present = true;
4138 hdd_info("Access policy present. access_policy %d",
4139 access_policy);
4140 }
4141
Zhang Qiana3bcbe02016-08-12 16:20:36 +08004142 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_NON_AGG_RETRY]) {
4143 retry = nla_get_u8(tb[
4144 QCA_WLAN_VENDOR_ATTR_CONFIG_NON_AGG_RETRY]);
4145 retry = retry > CFG_NON_AGG_RETRY_MAX ?
4146 CFG_NON_AGG_RETRY_MAX : retry;
4147 param_id = WMI_PDEV_PARAM_NON_AGG_SW_RETRY_TH;
4148 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4149 retry, PDEV_CMD);
4150 }
4151
4152 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_AGG_RETRY]) {
4153 retry = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_CONFIG_AGG_RETRY]);
4154 retry = retry > CFG_AGG_RETRY_MAX ?
4155 CFG_AGG_RETRY_MAX : retry;
4156
4157 /* Value less than CFG_AGG_RETRY_MIN has side effect to t-put */
4158 retry = ((retry > 0) && (retry < CFG_AGG_RETRY_MIN)) ?
4159 CFG_AGG_RETRY_MIN : retry;
4160 param_id = WMI_PDEV_PARAM_AGG_SW_RETRY_TH;
4161 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4162 retry, PDEV_CMD);
4163 }
4164
4165 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MGMT_RETRY]) {
4166 retry = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_CONFIG_MGMT_RETRY]);
4167 retry = retry > CFG_MGMT_RETRY_MAX ?
4168 CFG_MGMT_RETRY_MAX : retry;
4169 param_id = WMI_PDEV_PARAM_MGMT_RETRY_LIMIT;
4170 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4171 retry, PDEV_CMD);
4172 }
4173
4174 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_CTRL_RETRY]) {
4175 retry = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_CONFIG_CTRL_RETRY]);
4176 retry = retry > CFG_CTRL_RETRY_MAX ?
4177 CFG_CTRL_RETRY_MAX : retry;
4178 param_id = WMI_PDEV_PARAM_CTRL_RETRY_LIMIT;
4179 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4180 retry, PDEV_CMD);
4181 }
4182
4183 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_PROPAGATION_DELAY]) {
4184 delay = nla_get_u8(tb[
4185 QCA_WLAN_VENDOR_ATTR_CONFIG_PROPAGATION_DELAY]);
4186 delay = delay > CFG_PROPAGATION_DELAY_MAX ?
4187 CFG_PROPAGATION_DELAY_MAX : delay;
4188 param_id = WMI_PDEV_PARAM_PROPAGATION_DELAY;
4189 ret_val = wma_cli_set_command(adapter->sessionId, param_id,
4190 delay, PDEV_CMD);
4191 }
4192
Agrawal, Ashishb45599a2016-10-27 14:55:30 +05304193 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_FAIL_COUNT]) {
4194 tx_fail_count = nla_get_u32(
4195 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_FAIL_COUNT]);
4196 if (tx_fail_count) {
4197 status = sme_update_tx_fail_cnt_threshold(hdd_ctx->hHal,
4198 adapter->sessionId, tx_fail_count);
4199 if (QDF_STATUS_SUCCESS != status) {
4200 hdd_info("sme_update_tx_fail_cnt_threshold (err=%d)",
4201 status);
4202 return -EINVAL;
4203 }
4204 }
4205 }
4206
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304207 if (vendor_ie_present && access_policy_present) {
4208 if (access_policy == QCA_ACCESS_POLICY_DENY_UNLESS_LISTED) {
4209 access_policy =
4210 WLAN_HDD_VENDOR_IE_ACCESS_ALLOW_IF_LISTED;
Selvaraj, Sridharac4fcf32016-09-28 12:57:32 +05304211 } else {
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304212 access_policy = WLAN_HDD_VENDOR_IE_ACCESS_NONE;
Selvaraj, Sridharac4fcf32016-09-28 12:57:32 +05304213 }
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304214
Selvaraj, Sridharac4fcf32016-09-28 12:57:32 +05304215 hdd_info("calling sme_update_access_policy_vendor_ie");
4216 status = sme_update_access_policy_vendor_ie(hdd_ctx->hHal,
4217 adapter->sessionId, &vendor_ie[0],
4218 access_policy);
4219 if (QDF_STATUS_SUCCESS != status) {
4220 hdd_info("Failed to set vendor ie and access policy.");
Kondabattini, Ganesh44f6a212016-09-05 15:14:25 +05304221 return -EINVAL;
4222 }
4223 }
4224
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05304225 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_AVOIDANCE_IND]) {
4226 set_value = nla_get_u8(
4227 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_AVOIDANCE_IND]);
4228 hdd_info("set_value: %d", set_value);
4229 ret_val = hdd_enable_disable_ca_event(hdd_ctx, set_value);
4230 }
4231
Deepak Dhamdhereb106ae52016-08-10 20:55:30 +05304232 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_DEFAULT_IES]) {
4233 scan_ie_len = nla_len(
4234 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_DEFAULT_IES]);
4235 hdd_info("Received default scan IE of len %d session %d device mode %d",
4236 scan_ie_len, adapter->sessionId,
4237 adapter->device_mode);
4238 if (scan_ie_len && (scan_ie_len <= MAX_DEFAULT_SCAN_IE_LEN)) {
4239 scan_ie = (uint8_t *) nla_data(tb
4240 [QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_DEFAULT_IES]);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304241
4242 if (wlan_hdd_save_default_scan_ies(adapter, scan_ie,
4243 scan_ie_len))
4244 hdd_err("Failed to save default scan IEs");
4245
Deepak Dhamdhereb106ae52016-08-10 20:55:30 +05304246 if (adapter->device_mode == QDF_STA_MODE) {
4247 status = sme_set_default_scan_ie(hdd_ctx->hHal,
4248 adapter->sessionId, scan_ie,
4249 scan_ie_len);
4250 if (QDF_STATUS_SUCCESS != status)
4251 ret_val = -EPERM;
4252 }
4253 } else
4254 ret_val = -EPERM;
4255 }
Padma, Santhosh Kumara7119672016-08-16 16:05:14 +05304256
4257 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MPDU_AGGREGATION] ||
4258 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MPDU_AGGREGATION]) {
4259 /* if one is specified, both must be specified */
4260 if (!tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MPDU_AGGREGATION] ||
4261 !tb[QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MPDU_AGGREGATION]) {
4262 hdd_err("Both TX and RX MPDU Aggregation required");
4263 return -EINVAL;
4264 }
4265
4266 request.tx_aggregation_size = nla_get_u8(
4267 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MPDU_AGGREGATION]);
4268 request.rx_aggregation_size = nla_get_u8(
4269 tb[QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MPDU_AGGREGATION]);
4270 request.vdev_id = adapter->sessionId;
4271
4272 if (request.tx_aggregation_size >=
4273 CFG_TX_AGGREGATION_SIZE_MIN &&
4274 request.tx_aggregation_size <=
4275 CFG_TX_AGGREGATION_SIZE_MAX &&
4276 request.rx_aggregation_size >=
4277 CFG_RX_AGGREGATION_SIZE_MIN &&
4278 request.rx_aggregation_size <=
4279 CFG_RX_AGGREGATION_SIZE_MAX) {
4280 qdf_status = wma_set_tx_rx_aggregation_size(&request);
4281 if (qdf_status != QDF_STATUS_SUCCESS) {
4282 hdd_err("failed to set aggr sizes err %d",
4283 qdf_status);
4284 ret_val = -EPERM;
4285 }
4286 } else {
4287 hdd_err("TX %d RX %d MPDU aggr size not in range",
4288 request.tx_aggregation_size,
4289 request.rx_aggregation_size);
4290 ret_val = -EINVAL;
4291 }
4292 }
4293
Selvaraj, Sridharac4fcf32016-09-28 12:57:32 +05304294 if (tb[QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED]) {
4295 uint8_t ignore_assoc_disallowed;
4296
4297 ignore_assoc_disallowed
4298 = nla_get_u8(tb[
4299 QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED]);
4300 hdd_info("Set ignore_assoc_disallowed value - %d",
4301 ignore_assoc_disallowed);
4302 if ((ignore_assoc_disallowed <
4303 QCA_IGNORE_ASSOC_DISALLOWED_DISABLE) ||
4304 (ignore_assoc_disallowed >
4305 QCA_IGNORE_ASSOC_DISALLOWED_ENABLE))
4306 return -EPERM;
4307
4308 sme_update_session_param(hdd_ctx->hHal,
4309 adapter->sessionId,
4310 SIR_PARAM_IGNORE_ASSOC_DISALLOWED,
4311 ignore_assoc_disallowed);
4312 }
4313
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314 return ret_val;
4315}
4316
4317/**
4318 * wlan_hdd_cfg80211_wifi_configuration_set() - Wifi configuration
4319 * vendor command
4320 *
4321 * @wiphy: wiphy device pointer
4322 * @wdev: wireless device pointer
4323 * @data: Vendor command data buffer
4324 * @data_len: Buffer length
4325 *
4326 * Handles QCA_WLAN_VENDOR_ATTR_CONFIG_MAX.
4327 *
4328 * Return: EOK or other error codes.
4329 */
4330static int wlan_hdd_cfg80211_wifi_configuration_set(struct wiphy *wiphy,
4331 struct wireless_dev *wdev,
4332 const void *data,
4333 int data_len)
4334{
4335 int ret;
4336
4337 cds_ssr_protect(__func__);
4338 ret = __wlan_hdd_cfg80211_wifi_configuration_set(wiphy, wdev,
4339 data, data_len);
4340 cds_ssr_unprotect(__func__);
4341
4342 return ret;
4343}
4344
4345static const struct
4346nla_policy
4347qca_wlan_vendor_wifi_logger_start_policy
4348[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_START_MAX + 1] = {
4349 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_RING_ID]
4350 = {.type = NLA_U32 },
4351 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_VERBOSE_LEVEL]
4352 = {.type = NLA_U32 },
4353 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_FLAGS]
4354 = {.type = NLA_U32 },
4355};
4356
4357/**
4358 * __wlan_hdd_cfg80211_wifi_logger_start() - This function is used to enable
4359 * or disable the collection of packet statistics from the firmware
4360 * @wiphy: WIPHY structure pointer
4361 * @wdev: Wireless device structure pointer
4362 * @data: Pointer to the data received
4363 * @data_len: Length of the data received
4364 *
4365 * This function enables or disables the collection of packet statistics from
4366 * the firmware
4367 *
4368 * Return: 0 on success and errno on failure
4369 */
4370static int __wlan_hdd_cfg80211_wifi_logger_start(struct wiphy *wiphy,
4371 struct wireless_dev *wdev,
4372 const void *data,
4373 int data_len)
4374{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304375 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004376 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
4377 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_START_MAX + 1];
4378 struct sir_wifi_start_log start_log;
4379
Jeff Johnson1f61b612016-02-12 16:28:33 -08004380 ENTER_DEV(wdev->netdev);
4381
Anurag Chouhan6d760662016-02-20 16:05:43 +05304382 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 hdd_err("Command not allowed in FTM mode");
4384 return -EPERM;
4385 }
4386
4387 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304388 if (status)
4389 return status;
4390
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004391
4392 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_START_MAX,
4393 data, data_len,
4394 qca_wlan_vendor_wifi_logger_start_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004395 hdd_err("Invalid attribute");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 return -EINVAL;
4397 }
4398
4399 /* Parse and fetch ring id */
4400 if (!tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_RING_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004401 hdd_err("attr ATTR failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 return -EINVAL;
4403 }
4404 start_log.ring_id = nla_get_u32(
4405 tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_RING_ID]);
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -08004406 hdd_info("Ring ID=%d", start_log.ring_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004407
4408 /* Parse and fetch verbose level */
4409 if (!tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_VERBOSE_LEVEL]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004410 hdd_err("attr verbose_level failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411 return -EINVAL;
4412 }
4413 start_log.verbose_level = nla_get_u32(
4414 tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_VERBOSE_LEVEL]);
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -08004415 hdd_info("verbose_level=%d", start_log.verbose_level);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416
4417 /* Parse and fetch flag */
4418 if (!tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_FLAGS]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004419 hdd_err("attr flag failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420 return -EINVAL;
4421 }
Poddar, Siddartheefe3482016-09-21 18:12:59 +05304422 start_log.is_iwpriv_command = nla_get_u32(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004423 tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_FLAGS]);
Poddar, Siddartheefe3482016-09-21 18:12:59 +05304424 hdd_info("is_iwpriv_command =%d", start_log.is_iwpriv_command);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425
Poddar, Siddarth176c4362016-10-03 12:25:00 +05304426 /* size is buff size which can be set using iwpriv command*/
4427 start_log.size = 0;
4428
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429 cds_set_ring_log_level(start_log.ring_id, start_log.verbose_level);
4430
4431 if (start_log.ring_id == RING_ID_WAKELOCK) {
4432 /* Start/stop wakelock events */
4433 if (start_log.verbose_level > WLAN_LOG_LEVEL_OFF)
4434 cds_set_wakelock_logging(true);
4435 else
4436 cds_set_wakelock_logging(false);
4437 return 0;
4438 }
4439
4440 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304441 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004442 hdd_err("sme_wifi_start_logger failed(err=%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443 status);
4444 return -EINVAL;
4445 }
4446 return 0;
4447}
4448
4449/**
4450 * wlan_hdd_cfg80211_wifi_logger_start() - Wrapper function used to enable
4451 * or disable the collection of packet statistics from the firmware
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 enable or disable the collection of packet
4458 * statistics from the firmware
4459 *
4460 * Return: 0 on success and errno on failure
4461 */
4462static int wlan_hdd_cfg80211_wifi_logger_start(struct wiphy *wiphy,
4463 struct wireless_dev *wdev,
4464 const void *data,
4465 int data_len)
4466{
4467 int ret = 0;
4468
4469 cds_ssr_protect(__func__);
4470 ret = __wlan_hdd_cfg80211_wifi_logger_start(wiphy,
4471 wdev, data, data_len);
4472 cds_ssr_unprotect(__func__);
4473
4474 return ret;
4475}
4476
4477static const struct
4478nla_policy
4479qca_wlan_vendor_wifi_logger_get_ring_data_policy
4480[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_MAX + 1] = {
4481 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_ID]
4482 = {.type = NLA_U32 },
4483};
4484
4485/**
4486 * __wlan_hdd_cfg80211_wifi_logger_get_ring_data() - Flush per packet stats
4487 * @wiphy: WIPHY structure pointer
4488 * @wdev: Wireless device structure pointer
4489 * @data: Pointer to the data received
4490 * @data_len: Length of the data received
4491 *
4492 * This function is used to flush or retrieve the per packet statistics from
4493 * the driver
4494 *
4495 * Return: 0 on success and errno on failure
4496 */
4497static int __wlan_hdd_cfg80211_wifi_logger_get_ring_data(struct wiphy *wiphy,
4498 struct wireless_dev *wdev,
4499 const void *data,
4500 int data_len)
4501{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304502 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004503 uint32_t ring_id;
4504 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
4505 struct nlattr *tb
4506 [QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_MAX + 1];
4507
Jeff Johnson1f61b612016-02-12 16:28:33 -08004508 ENTER_DEV(wdev->netdev);
4509
Anurag Chouhan6d760662016-02-20 16:05:43 +05304510 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511 hdd_err("Command not allowed in FTM mode");
4512 return -EPERM;
4513 }
4514
4515 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304516 if (status)
4517 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518
4519 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_MAX,
4520 data, data_len,
4521 qca_wlan_vendor_wifi_logger_get_ring_data_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004522 hdd_err("Invalid attribute");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004523 return -EINVAL;
4524 }
4525
4526 /* Parse and fetch ring id */
4527 if (!tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004528 hdd_err("attr ATTR failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004529 return -EINVAL;
4530 }
4531
4532 ring_id = nla_get_u32(
4533 tb[QCA_WLAN_VENDOR_ATTR_WIFI_LOGGER_GET_RING_DATA_ID]);
4534
4535 if (ring_id == RING_ID_PER_PACKET_STATS) {
4536 wlan_logging_set_per_pkt_stats();
Jeff Johnson77848112016-06-29 14:52:06 -07004537 hdd_notice("Flushing/Retrieving packet stats");
Sreelakshmi Konamkic3815ba2016-08-18 12:01:57 +05304538 } else if (ring_id == RING_ID_DRIVER_DEBUG) {
4539 /*
4540 * As part of DRIVER ring ID, flush both driver and fw logs.
4541 * For other Ring ID's driver doesn't have any rings to flush
4542 */
4543 hdd_notice("Bug report triggered by framework");
4544
4545 status = cds_flush_logs(WLAN_LOG_TYPE_NON_FATAL,
4546 WLAN_LOG_INDICATOR_FRAMEWORK,
4547 WLAN_LOG_REASON_CODE_UNUSED,
4548 true, false);
4549 if (QDF_STATUS_SUCCESS != status) {
4550 hdd_err("Failed to trigger bug report");
4551 return -EINVAL;
4552 }
4553 } else {
4554 wlan_report_log_completion(WLAN_LOG_TYPE_NON_FATAL,
4555 WLAN_LOG_INDICATOR_FRAMEWORK,
4556 WLAN_LOG_REASON_CODE_UNUSED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004557 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004558 return 0;
4559}
4560
4561/**
4562 * wlan_hdd_cfg80211_wifi_logger_get_ring_data() - Wrapper to flush packet stats
4563 * @wiphy: WIPHY structure pointer
4564 * @wdev: Wireless device structure pointer
4565 * @data: Pointer to the data received
4566 * @data_len: Length of the data received
4567 *
4568 * This function is used to flush or retrieve the per packet statistics from
4569 * the driver
4570 *
4571 * Return: 0 on success and errno on failure
4572 */
4573static int wlan_hdd_cfg80211_wifi_logger_get_ring_data(struct wiphy *wiphy,
4574 struct wireless_dev *wdev,
4575 const void *data,
4576 int data_len)
4577{
4578 int ret = 0;
4579
4580 cds_ssr_protect(__func__);
4581 ret = __wlan_hdd_cfg80211_wifi_logger_get_ring_data(wiphy,
4582 wdev, data, data_len);
4583 cds_ssr_unprotect(__func__);
4584
4585 return ret;
4586}
4587
4588#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
4589/**
4590 * hdd_map_req_id_to_pattern_id() - map request id to pattern id
4591 * @hdd_ctx: HDD context
4592 * @request_id: [input] request id
4593 * @pattern_id: [output] pattern id
4594 *
4595 * This function loops through request id to pattern id array
4596 * if the slot is available, store the request id and return pattern id
4597 * if entry exists, return the pattern id
4598 *
4599 * Return: 0 on success and errno on failure
4600 */
4601static int hdd_map_req_id_to_pattern_id(hdd_context_t *hdd_ctx,
4602 uint32_t request_id,
4603 uint8_t *pattern_id)
4604{
4605 uint32_t i;
4606
4607 mutex_lock(&hdd_ctx->op_ctx.op_lock);
4608 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
4609 if (hdd_ctx->op_ctx.op_table[i].request_id == MAX_REQUEST_ID) {
4610 hdd_ctx->op_ctx.op_table[i].request_id = request_id;
4611 *pattern_id = hdd_ctx->op_ctx.op_table[i].pattern_id;
4612 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4613 return 0;
4614 } else if (hdd_ctx->op_ctx.op_table[i].request_id ==
4615 request_id) {
4616 *pattern_id = hdd_ctx->op_ctx.op_table[i].pattern_id;
4617 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4618 return 0;
4619 }
4620 }
4621 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4622 return -EINVAL;
4623}
4624
4625/**
4626 * hdd_unmap_req_id_to_pattern_id() - unmap request id to pattern id
4627 * @hdd_ctx: HDD context
4628 * @request_id: [input] request id
4629 * @pattern_id: [output] pattern id
4630 *
4631 * This function loops through request id to pattern id array
4632 * reset request id to 0 (slot available again) and
4633 * return pattern id
4634 *
4635 * Return: 0 on success and errno on failure
4636 */
4637static int hdd_unmap_req_id_to_pattern_id(hdd_context_t *hdd_ctx,
4638 uint32_t request_id,
4639 uint8_t *pattern_id)
4640{
4641 uint32_t i;
4642
4643 mutex_lock(&hdd_ctx->op_ctx.op_lock);
4644 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
4645 if (hdd_ctx->op_ctx.op_table[i].request_id == request_id) {
4646 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
4647 *pattern_id = hdd_ctx->op_ctx.op_table[i].pattern_id;
4648 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4649 return 0;
4650 }
4651 }
4652 mutex_unlock(&hdd_ctx->op_ctx.op_lock);
4653 return -EINVAL;
4654}
4655
4656
4657/*
4658 * define short names for the global vendor params
4659 * used by __wlan_hdd_cfg80211_offloaded_packets()
4660 */
4661#define PARAM_MAX QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_MAX
4662#define PARAM_REQUEST_ID \
4663 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_REQUEST_ID
4664#define PARAM_CONTROL \
4665 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_SENDING_CONTROL
4666#define PARAM_IP_PACKET \
4667 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_IP_PACKET_DATA
4668#define PARAM_SRC_MAC_ADDR \
4669 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_SRC_MAC_ADDR
4670#define PARAM_DST_MAC_ADDR \
4671 QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_DST_MAC_ADDR
4672#define PARAM_PERIOD QCA_WLAN_VENDOR_ATTR_OFFLOADED_PACKETS_PERIOD
4673
4674/**
4675 * wlan_hdd_add_tx_ptrn() - add tx pattern
4676 * @adapter: adapter pointer
4677 * @hdd_ctx: hdd context
4678 * @tb: nl attributes
4679 *
4680 * This function reads the NL attributes and forms a AddTxPtrn message
4681 * posts it to SME.
4682 *
4683 */
4684static int
4685wlan_hdd_add_tx_ptrn(hdd_adapter_t *adapter, hdd_context_t *hdd_ctx,
4686 struct nlattr **tb)
4687{
4688 struct sSirAddPeriodicTxPtrn *add_req;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304689 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004690 uint32_t request_id, ret, len;
4691 uint8_t pattern_id = 0;
Anurag Chouhan6d760662016-02-20 16:05:43 +05304692 struct qdf_mac_addr dst_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004693 uint16_t eth_type = htons(ETH_P_IP);
4694
4695 if (!hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Jeff Johnson77848112016-06-29 14:52:06 -07004696 hdd_err("Not in Connected state!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004697 return -ENOTSUPP;
4698 }
4699
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304700 add_req = qdf_mem_malloc(sizeof(*add_req));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004701 if (!add_req) {
Jeff Johnson77848112016-06-29 14:52:06 -07004702 hdd_err("memory allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004703 return -ENOMEM;
4704 }
4705
4706 /* Parse and fetch request Id */
4707 if (!tb[PARAM_REQUEST_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004708 hdd_err("attr request id failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004709 goto fail;
4710 }
4711
4712 request_id = nla_get_u32(tb[PARAM_REQUEST_ID]);
4713 if (request_id == MAX_REQUEST_ID) {
Jeff Johnson77848112016-06-29 14:52:06 -07004714 hdd_err("request_id cannot be MAX");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004715 return -EINVAL;
4716 }
Jeff Johnson77848112016-06-29 14:52:06 -07004717 hdd_notice("Request Id: %u", request_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718
4719 if (!tb[PARAM_PERIOD]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004720 hdd_err("attr period failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721 goto fail;
4722 }
4723 add_req->usPtrnIntervalMs = nla_get_u32(tb[PARAM_PERIOD]);
Jeff Johnson77848112016-06-29 14:52:06 -07004724 hdd_notice("Period: %u ms", add_req->usPtrnIntervalMs);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004725 if (add_req->usPtrnIntervalMs == 0) {
Jeff Johnson77848112016-06-29 14:52:06 -07004726 hdd_err("Invalid interval zero, return failure");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004727 goto fail;
4728 }
4729
4730 if (!tb[PARAM_SRC_MAC_ADDR]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004731 hdd_err("attr source mac address failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004732 goto fail;
4733 }
Srinivas Girigowda31896552015-11-18 22:59:52 -08004734 nla_memcpy(add_req->mac_address.bytes, tb[PARAM_SRC_MAC_ADDR],
Anurag Chouhan6d760662016-02-20 16:05:43 +05304735 QDF_MAC_ADDR_SIZE);
Jeff Johnson77848112016-06-29 14:52:06 -07004736 hdd_notice("input src mac address: "MAC_ADDRESS_STR,
Srinivas Girigowda31896552015-11-18 22:59:52 -08004737 MAC_ADDR_ARRAY(add_req->mac_address.bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004738
Anurag Chouhanc5548422016-02-24 18:33:27 +05304739 if (!qdf_is_macaddr_equal(&add_req->mac_address,
Srinivas Girigowda31896552015-11-18 22:59:52 -08004740 &adapter->macAddressCurrent)) {
4741 hdd_err("input src mac address and connected ap bssid are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004742 goto fail;
4743 }
4744
4745 if (!tb[PARAM_DST_MAC_ADDR]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004746 hdd_err("attr dst mac address failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004747 goto fail;
4748 }
Anurag Chouhan6d760662016-02-20 16:05:43 +05304749 nla_memcpy(dst_addr.bytes, tb[PARAM_DST_MAC_ADDR], QDF_MAC_ADDR_SIZE);
Jeff Johnson77848112016-06-29 14:52:06 -07004750 hdd_notice("input dst mac address: "MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004751 MAC_ADDR_ARRAY(dst_addr.bytes));
4752
4753 if (!tb[PARAM_IP_PACKET]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004754 hdd_err("attr ip packet failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004755 goto fail;
4756 }
4757 add_req->ucPtrnSize = nla_len(tb[PARAM_IP_PACKET]);
Jeff Johnson77848112016-06-29 14:52:06 -07004758 hdd_notice("IP packet len: %u", add_req->ucPtrnSize);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004759
4760 if (add_req->ucPtrnSize < 0 ||
4761 add_req->ucPtrnSize > (PERIODIC_TX_PTRN_MAX_SIZE -
4762 ETH_HLEN)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004763 hdd_err("Invalid IP packet len: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764 add_req->ucPtrnSize);
4765 goto fail;
4766 }
4767
4768 len = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304769 qdf_mem_copy(&add_req->ucPattern[0], dst_addr.bytes, QDF_MAC_ADDR_SIZE);
Anurag Chouhan6d760662016-02-20 16:05:43 +05304770 len += QDF_MAC_ADDR_SIZE;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304771 qdf_mem_copy(&add_req->ucPattern[len], add_req->mac_address.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304772 QDF_MAC_ADDR_SIZE);
4773 len += QDF_MAC_ADDR_SIZE;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304774 qdf_mem_copy(&add_req->ucPattern[len], &eth_type, 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775 len += 2;
4776
4777 /*
4778 * This is the IP packet, add 14 bytes Ethernet (802.3) header
4779 * ------------------------------------------------------------
4780 * | 14 bytes Ethernet (802.3) header | IP header and payload |
4781 * ------------------------------------------------------------
4782 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304783 qdf_mem_copy(&add_req->ucPattern[len],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004784 nla_data(tb[PARAM_IP_PACKET]),
4785 add_req->ucPtrnSize);
4786 add_req->ucPtrnSize += len;
4787
4788 ret = hdd_map_req_id_to_pattern_id(hdd_ctx, request_id, &pattern_id);
4789 if (ret) {
Jeff Johnson77848112016-06-29 14:52:06 -07004790 hdd_warn("req id to pattern id failed (ret=%d)", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791 goto fail;
4792 }
4793 add_req->ucPtrnId = pattern_id;
Jeff Johnson77848112016-06-29 14:52:06 -07004794 hdd_notice("pattern id: %d", add_req->ucPtrnId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004795
4796 status = sme_add_periodic_tx_ptrn(hdd_ctx->hHal, add_req);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304797 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004798 hdd_err("sme_add_periodic_tx_ptrn failed (err=%d)", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004799 goto fail;
4800 }
4801
4802 EXIT();
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304803 qdf_mem_free(add_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004804 return 0;
4805
4806fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304807 qdf_mem_free(add_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808 return -EINVAL;
4809}
4810
4811/**
4812 * wlan_hdd_del_tx_ptrn() - delete tx pattern
4813 * @adapter: adapter pointer
4814 * @hdd_ctx: hdd context
4815 * @tb: nl attributes
4816 *
4817 * This function reads the NL attributes and forms a DelTxPtrn message
4818 * posts it to SME.
4819 *
4820 */
4821static int
4822wlan_hdd_del_tx_ptrn(hdd_adapter_t *adapter, hdd_context_t *hdd_ctx,
4823 struct nlattr **tb)
4824{
4825 struct sSirDelPeriodicTxPtrn *del_req;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304826 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827 uint32_t request_id, ret;
4828 uint8_t pattern_id = 0;
4829
4830 /* Parse and fetch request Id */
4831 if (!tb[PARAM_REQUEST_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004832 hdd_err("attr request id failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004833 return -EINVAL;
4834 }
4835 request_id = nla_get_u32(tb[PARAM_REQUEST_ID]);
4836 if (request_id == MAX_REQUEST_ID) {
Jeff Johnson77848112016-06-29 14:52:06 -07004837 hdd_err("request_id cannot be MAX");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004838 return -EINVAL;
4839 }
4840
4841 ret = hdd_unmap_req_id_to_pattern_id(hdd_ctx, request_id, &pattern_id);
4842 if (ret) {
Jeff Johnson77848112016-06-29 14:52:06 -07004843 hdd_warn("req id to pattern id failed (ret=%d)", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004844 return -EINVAL;
4845 }
4846
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304847 del_req = qdf_mem_malloc(sizeof(*del_req));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004848 if (!del_req) {
Jeff Johnson77848112016-06-29 14:52:06 -07004849 hdd_err("memory allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 return -ENOMEM;
4851 }
4852
Anurag Chouhanc5548422016-02-24 18:33:27 +05304853 qdf_copy_macaddr(&del_req->mac_address, &adapter->macAddressCurrent);
Srinivas Girigowdaa5bba7a2015-11-18 22:44:36 -08004854 hdd_info(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(del_req->mac_address.bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004855 del_req->ucPtrnId = pattern_id;
Jeff Johnson77848112016-06-29 14:52:06 -07004856 hdd_notice("Request Id: %u Pattern id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857 request_id, del_req->ucPtrnId);
4858
4859 status = sme_del_periodic_tx_ptrn(hdd_ctx->hHal, del_req);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304860 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004861 hdd_err("sme_del_periodic_tx_ptrn failed (err=%d)", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004862 goto fail;
4863 }
4864
4865 EXIT();
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304866 qdf_mem_free(del_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004867 return 0;
4868
4869fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304870 qdf_mem_free(del_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871 return -EINVAL;
4872}
4873
4874
4875/**
4876 * __wlan_hdd_cfg80211_offloaded_packets() - send offloaded packets
4877 * @wiphy: Pointer to wireless phy
4878 * @wdev: Pointer to wireless device
4879 * @data: Pointer to data
4880 * @data_len: Data length
4881 *
4882 * Return: 0 on success, negative errno on failure
4883 */
4884static int
4885__wlan_hdd_cfg80211_offloaded_packets(struct wiphy *wiphy,
4886 struct wireless_dev *wdev,
4887 const void *data,
4888 int data_len)
4889{
4890 struct net_device *dev = wdev->netdev;
4891 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
4892 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
4893 struct nlattr *tb[PARAM_MAX + 1];
4894 uint8_t control;
4895 int ret;
4896 static const struct nla_policy policy[PARAM_MAX + 1] = {
4897 [PARAM_REQUEST_ID] = { .type = NLA_U32 },
4898 [PARAM_CONTROL] = { .type = NLA_U32 },
4899 [PARAM_SRC_MAC_ADDR] = { .type = NLA_BINARY,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304900 .len = QDF_MAC_ADDR_SIZE },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004901 [PARAM_DST_MAC_ADDR] = { .type = NLA_BINARY,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304902 .len = QDF_MAC_ADDR_SIZE },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004903 [PARAM_PERIOD] = { .type = NLA_U32 },
4904 };
4905
Jeff Johnson1f61b612016-02-12 16:28:33 -08004906 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004907
Anurag Chouhan6d760662016-02-20 16:05:43 +05304908 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004909 hdd_err("Command not allowed in FTM mode");
4910 return -EPERM;
4911 }
4912
4913 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304914 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004915 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004916
4917 if (!sme_is_feature_supported_by_fw(WLAN_PERIODIC_TX_PTRN)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004918 hdd_err("Periodic Tx Pattern Offload feature is not supported in FW!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004919 return -ENOTSUPP;
4920 }
4921
4922 if (nla_parse(tb, PARAM_MAX, data, data_len, policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07004923 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004924 return -EINVAL;
4925 }
4926
4927 if (!tb[PARAM_CONTROL]) {
Jeff Johnson77848112016-06-29 14:52:06 -07004928 hdd_err("attr control failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004929 return -EINVAL;
4930 }
4931 control = nla_get_u32(tb[PARAM_CONTROL]);
Jeff Johnson77848112016-06-29 14:52:06 -07004932 hdd_notice("Control: %d", control);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004933
4934 if (control == WLAN_START_OFFLOADED_PACKETS)
4935 return wlan_hdd_add_tx_ptrn(adapter, hdd_ctx, tb);
4936 else if (control == WLAN_STOP_OFFLOADED_PACKETS)
4937 return wlan_hdd_del_tx_ptrn(adapter, hdd_ctx, tb);
4938 else {
Jeff Johnson77848112016-06-29 14:52:06 -07004939 hdd_err("Invalid control: %d", control);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004940 return -EINVAL;
4941 }
4942}
4943
4944/*
4945 * done with short names for the global vendor params
4946 * used by __wlan_hdd_cfg80211_offloaded_packets()
4947 */
4948#undef PARAM_MAX
4949#undef PARAM_REQUEST_ID
4950#undef PARAM_CONTROL
4951#undef PARAM_IP_PACKET
4952#undef PARAM_SRC_MAC_ADDR
4953#undef PARAM_DST_MAC_ADDR
4954#undef PARAM_PERIOD
4955
4956/**
4957 * wlan_hdd_cfg80211_offloaded_packets() - Wrapper to offload packets
4958 * @wiphy: wiphy structure pointer
4959 * @wdev: Wireless device structure pointer
4960 * @data: Pointer to the data received
4961 * @data_len: Length of @data
4962 *
4963 * Return: 0 on success; errno on failure
4964 */
4965static int wlan_hdd_cfg80211_offloaded_packets(struct wiphy *wiphy,
4966 struct wireless_dev *wdev,
4967 const void *data,
4968 int data_len)
4969{
4970 int ret = 0;
4971
4972 cds_ssr_protect(__func__);
4973 ret = __wlan_hdd_cfg80211_offloaded_packets(wiphy,
4974 wdev, data, data_len);
4975 cds_ssr_unprotect(__func__);
4976
4977 return ret;
4978}
4979#endif
4980
4981/*
4982 * define short names for the global vendor params
4983 * used by __wlan_hdd_cfg80211_monitor_rssi()
4984 */
4985#define PARAM_MAX QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_MAX
4986#define PARAM_REQUEST_ID QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_REQUEST_ID
4987#define PARAM_CONTROL QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_CONTROL
4988#define PARAM_MIN_RSSI QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_MIN_RSSI
4989#define PARAM_MAX_RSSI QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_MAX_RSSI
4990
4991/**
4992 * __wlan_hdd_cfg80211_monitor_rssi() - monitor rssi
4993 * @wiphy: Pointer to wireless phy
4994 * @wdev: Pointer to wireless device
4995 * @data: Pointer to data
4996 * @data_len: Data length
4997 *
4998 * Return: 0 on success, negative errno on failure
4999 */
5000static int
5001__wlan_hdd_cfg80211_monitor_rssi(struct wiphy *wiphy,
5002 struct wireless_dev *wdev,
5003 const void *data,
5004 int data_len)
5005{
5006 struct net_device *dev = wdev->netdev;
5007 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5008 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5009 struct nlattr *tb[PARAM_MAX + 1];
5010 struct rssi_monitor_req req;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305011 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005012 int ret;
5013 uint32_t control;
5014 static const struct nla_policy policy[PARAM_MAX + 1] = {
5015 [PARAM_REQUEST_ID] = { .type = NLA_U32 },
5016 [PARAM_CONTROL] = { .type = NLA_U32 },
5017 [PARAM_MIN_RSSI] = { .type = NLA_S8 },
5018 [PARAM_MAX_RSSI] = { .type = NLA_S8 },
5019 };
5020
Jeff Johnson1f61b612016-02-12 16:28:33 -08005021 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005022
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05305023 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
5024 hdd_err("invalid session id: %d", adapter->sessionId);
5025 return -EINVAL;
5026 }
5027
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305029 if (ret)
5030 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031
5032 if (!hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Jeff Johnson77848112016-06-29 14:52:06 -07005033 hdd_err("Not in Connected state!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034 return -ENOTSUPP;
5035 }
5036
5037 if (nla_parse(tb, PARAM_MAX, data, data_len, policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005038 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005039 return -EINVAL;
5040 }
5041
5042 if (!tb[PARAM_REQUEST_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005043 hdd_err("attr request id failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005044 return -EINVAL;
5045 }
5046
5047 if (!tb[PARAM_CONTROL]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005048 hdd_err("attr control failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049 return -EINVAL;
5050 }
5051
5052 req.request_id = nla_get_u32(tb[PARAM_REQUEST_ID]);
5053 req.session_id = adapter->sessionId;
5054 control = nla_get_u32(tb[PARAM_CONTROL]);
5055
5056 if (control == QCA_WLAN_RSSI_MONITORING_START) {
5057 req.control = true;
5058 if (!tb[PARAM_MIN_RSSI]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005059 hdd_err("attr min rssi failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005060 return -EINVAL;
5061 }
5062
5063 if (!tb[PARAM_MAX_RSSI]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005064 hdd_err("attr max rssi failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005065 return -EINVAL;
5066 }
5067
5068 req.min_rssi = nla_get_s8(tb[PARAM_MIN_RSSI]);
5069 req.max_rssi = nla_get_s8(tb[PARAM_MAX_RSSI]);
5070
5071 if (!(req.min_rssi < req.max_rssi)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005072 hdd_warn("min_rssi: %d must be less than max_rssi: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073 req.min_rssi, req.max_rssi);
5074 return -EINVAL;
5075 }
Jeff Johnson77848112016-06-29 14:52:06 -07005076 hdd_notice("Min_rssi: %d Max_rssi: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077 req.min_rssi, req.max_rssi);
5078
5079 } else if (control == QCA_WLAN_RSSI_MONITORING_STOP)
5080 req.control = false;
5081 else {
Jeff Johnson77848112016-06-29 14:52:06 -07005082 hdd_err("Invalid control cmd: %d", control);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083 return -EINVAL;
5084 }
Jeff Johnson77848112016-06-29 14:52:06 -07005085 hdd_notice("Request Id: %u Session_id: %d Control: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005086 req.request_id, req.session_id, req.control);
5087
5088 status = sme_set_rssi_monitoring(hdd_ctx->hHal, &req);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305089 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005090 hdd_err("sme_set_rssi_monitoring failed(err=%d)", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005091 return -EINVAL;
5092 }
5093
5094 return 0;
5095}
5096
5097/*
5098 * done with short names for the global vendor params
5099 * used by __wlan_hdd_cfg80211_monitor_rssi()
5100 */
5101#undef PARAM_MAX
5102#undef PARAM_CONTROL
5103#undef PARAM_REQUEST_ID
5104#undef PARAM_MAX_RSSI
5105#undef PARAM_MIN_RSSI
5106
5107/**
5108 * wlan_hdd_cfg80211_monitor_rssi() - SSR wrapper to rssi monitoring
5109 * @wiphy: wiphy structure pointer
5110 * @wdev: Wireless device structure pointer
5111 * @data: Pointer to the data received
5112 * @data_len: Length of @data
5113 *
5114 * Return: 0 on success; errno on failure
5115 */
5116static int
5117wlan_hdd_cfg80211_monitor_rssi(struct wiphy *wiphy, struct wireless_dev *wdev,
5118 const void *data, int data_len)
5119{
5120 int ret;
5121
5122 cds_ssr_protect(__func__);
5123 ret = __wlan_hdd_cfg80211_monitor_rssi(wiphy, wdev, data, data_len);
5124 cds_ssr_unprotect(__func__);
5125
5126 return ret;
5127}
5128
5129/**
5130 * hdd_rssi_threshold_breached() - rssi breached NL event
5131 * @hddctx: HDD context
5132 * @data: rssi breached event data
5133 *
5134 * This function reads the rssi breached event %data and fill in the skb with
5135 * NL attributes and send up the NL event.
5136 *
5137 * Return: none
5138 */
5139void hdd_rssi_threshold_breached(void *hddctx,
5140 struct rssi_breach_event *data)
5141{
5142 hdd_context_t *hdd_ctx = hddctx;
5143 struct sk_buff *skb;
5144
5145 ENTER();
5146
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05305147 if (wlan_hdd_validate_context(hdd_ctx))
5148 return;
5149 if (!data) {
Jeff Johnson77848112016-06-29 14:52:06 -07005150 hdd_err("data is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005151 return;
5152 }
5153
5154 skb = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
5155 NULL,
5156 EXTSCAN_EVENT_BUF_SIZE + NLMSG_HDRLEN,
5157 QCA_NL80211_VENDOR_SUBCMD_MONITOR_RSSI_INDEX,
5158 GFP_KERNEL);
5159
5160 if (!skb) {
Jeff Johnson77848112016-06-29 14:52:06 -07005161 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005162 return;
5163 }
5164
Jeff Johnson77848112016-06-29 14:52:06 -07005165 hdd_notice("Req Id: %u Current rssi: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166 data->request_id, data->curr_rssi);
Jeff Johnson77848112016-06-29 14:52:06 -07005167 hdd_notice("Current BSSID: "MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005168 MAC_ADDR_ARRAY(data->curr_bssid.bytes));
5169
5170 if (nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_REQUEST_ID,
5171 data->request_id) ||
5172 nla_put(skb, QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_CUR_BSSID,
5173 sizeof(data->curr_bssid), data->curr_bssid.bytes) ||
5174 nla_put_s8(skb, QCA_WLAN_VENDOR_ATTR_RSSI_MONITORING_CUR_RSSI,
5175 data->curr_rssi)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005176 hdd_err("nla put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005177 goto fail;
5178 }
5179
5180 cfg80211_vendor_event(skb, GFP_KERNEL);
5181 return;
5182
5183fail:
5184 kfree_skb(skb);
5185 return;
5186}
5187
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05305188static const struct nla_policy
5189ns_offload_set_policy[QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_MAX + 1] = {
5190 [QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_FLAG] = {.type = NLA_U8},
5191};
5192
5193/**
5194 * __wlan_hdd_cfg80211_set_ns_offload() - enable/disable NS offload
5195 * @wiphy: Pointer to wireless phy
5196 * @wdev: Pointer to wireless device
5197 * @data: Pointer to data
5198 * @data_len: Length of @data
5199 *
5200 * Return: 0 on success, negative errno on failure
5201 */
5202static int
5203__wlan_hdd_cfg80211_set_ns_offload(struct wiphy *wiphy,
5204 struct wireless_dev *wdev,
5205 const void *data, int data_len)
5206{
5207 int status;
5208 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_MAX + 1];
5209 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Dustin Brownd8279d22016-09-07 14:52:57 -07005210 struct net_device *dev = wdev->netdev;
5211 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05305212
5213 ENTER_DEV(wdev->netdev);
5214
5215 status = wlan_hdd_validate_context(pHddCtx);
5216 if (0 != status)
5217 return status;
5218 if (!pHddCtx->config->fhostNSOffload) {
5219 hdd_err("ND Offload not supported");
5220 return -EINVAL;
5221 }
5222
5223 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_MAX,
5224 (struct nlattr *)data,
5225 data_len, ns_offload_set_policy)) {
5226 hdd_err("nla_parse failed");
5227 return -EINVAL;
5228 }
5229
5230 if (!tb[QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_FLAG]) {
5231 hdd_err("ND Offload flag attribute not present");
5232 return -EINVAL;
5233 }
5234
5235 pHddCtx->ns_offload_enable =
5236 nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_ND_OFFLOAD_FLAG]);
5237
Dustin Brownd8279d22016-09-07 14:52:57 -07005238 /* update ns offload in case it is already enabled/disabled */
5239 hdd_conf_ns_offload(adapter, pHddCtx->ns_offload_enable);
5240
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05305241 return 0;
5242}
5243
5244/**
5245 * wlan_hdd_cfg80211_set_ns_offload() - enable/disable NS offload
5246 * @wiphy: pointer to wireless wiphy structure.
5247 * @wdev: pointer to wireless_dev structure.
5248 * @data: Pointer to the data to be passed via vendor interface
5249 * @data_len:Length of the data to be passed
5250 *
5251 * Return: Return the Success or Failure code.
5252 */
5253static int wlan_hdd_cfg80211_set_ns_offload(struct wiphy *wiphy,
5254 struct wireless_dev *wdev,
5255 const void *data, int data_len)
5256{
5257 int ret;
5258
5259 cds_ssr_protect(__func__);
5260 ret = __wlan_hdd_cfg80211_set_ns_offload(wiphy, wdev, data, data_len);
5261 cds_ssr_unprotect(__func__);
5262
5263 return ret;
5264}
5265
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005266/** __wlan_hdd_cfg80211_get_preferred_freq_list() - get preferred frequency list
5267 * @wiphy: Pointer to wireless phy
5268 * @wdev: Pointer to wireless device
5269 * @data: Pointer to data
5270 * @data_len: Data length
5271 *
5272 * This function return the preferred frequency list generated by the policy
5273 * manager.
5274 *
5275 * Return: success or failure code
5276 */
5277static int __wlan_hdd_cfg80211_get_preferred_freq_list(struct wiphy *wiphy,
5278 struct wireless_dev
5279 *wdev, const void *data,
5280 int data_len)
5281{
5282 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5283 int i, ret = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305284 QDF_STATUS status;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05305285 uint8_t pcl[QDF_MAX_NUM_CHAN], weight_list[QDF_MAX_NUM_CHAN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005286 uint32_t pcl_len = 0;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05305287 uint32_t freq_list[QDF_MAX_NUM_CHAN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005288 enum cds_con_mode intf_mode;
5289 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_MAX + 1];
5290 struct sk_buff *reply_skb;
5291
Jeff Johnson1f61b612016-02-12 16:28:33 -08005292 ENTER_DEV(wdev->netdev);
5293
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005294 ret = wlan_hdd_validate_context(hdd_ctx);
5295 if (ret)
5296 return -EINVAL;
5297
5298 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_MAX,
5299 data, data_len, NULL)) {
5300 hdd_err("Invalid ATTR");
5301 return -EINVAL;
5302 }
5303
5304 if (!tb[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]) {
5305 hdd_err("attr interface type failed");
5306 return -EINVAL;
5307 }
5308
5309 intf_mode = nla_get_u32(tb
5310 [QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]);
5311
5312 if (intf_mode < CDS_STA_MODE || intf_mode >= CDS_MAX_NUM_OF_MODE) {
5313 hdd_err("Invalid interface type");
5314 return -EINVAL;
5315 }
5316
5317 hdd_debug("Userspace requested pref freq list");
5318
Manishekar Chandrasekaran7009f252016-04-21 19:14:15 +05305319 status = cds_get_pcl(intf_mode, pcl, &pcl_len,
5320 weight_list, QDF_ARRAY_SIZE(weight_list));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305321 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322 hdd_err("Get pcl failed");
5323 return -EINVAL;
5324 }
5325
5326 /* convert channel number to frequency */
5327 for (i = 0; i < pcl_len; i++) {
5328 if (pcl[i] <= ARRAY_SIZE(hdd_channels_2_4_ghz))
5329 freq_list[i] =
5330 ieee80211_channel_to_frequency(pcl[i],
Dustin Browna30892e2016-10-12 17:28:36 -07005331 NL80211_BAND_2GHZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332 else
5333 freq_list[i] =
5334 ieee80211_channel_to_frequency(pcl[i],
Dustin Browna30892e2016-10-12 17:28:36 -07005335 NL80211_BAND_5GHZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005336 }
5337
5338 /* send the freq_list back to supplicant */
5339 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(u32) +
5340 sizeof(u32) *
5341 pcl_len +
5342 NLMSG_HDRLEN);
5343
5344 if (!reply_skb) {
5345 hdd_err("Allocate reply_skb failed");
5346 return -EINVAL;
5347 }
5348
5349 if (nla_put_u32(reply_skb,
5350 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
5351 intf_mode) ||
5352 nla_put(reply_skb,
5353 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST,
5354 sizeof(uint32_t) * pcl_len,
5355 freq_list)) {
5356 hdd_err("nla put fail");
5357 kfree_skb(reply_skb);
5358 return -EINVAL;
5359 }
5360
5361 return cfg80211_vendor_cmd_reply(reply_skb);
5362}
5363
5364/** wlan_hdd_cfg80211_get_preferred_freq_list () - get preferred frequency list
5365 * @wiphy: Pointer to wireless phy
5366 * @wdev: Pointer to wireless device
5367 * @data: Pointer to data
5368 * @data_len: Data length
5369 *
5370 * This function return the preferred frequency list generated by the policy
5371 * manager.
5372 *
5373 * Return: success or failure code
5374 */
5375static int wlan_hdd_cfg80211_get_preferred_freq_list(struct wiphy *wiphy,
5376 struct wireless_dev
5377 *wdev, const void *data,
5378 int data_len)
5379{
5380 int ret = 0;
5381
5382 cds_ssr_protect(__func__);
5383 ret = __wlan_hdd_cfg80211_get_preferred_freq_list(wiphy, wdev,
5384 data, data_len);
5385 cds_ssr_unprotect(__func__);
5386
5387 return ret;
5388}
5389
5390/**
5391 * __wlan_hdd_cfg80211_set_probable_oper_channel () - set probable channel
5392 * @wiphy: Pointer to wireless phy
5393 * @wdev: Pointer to wireless device
5394 * @data: Pointer to data
5395 * @data_len: Data length
5396 *
5397 * Return: 0 on success, negative errno on failure
5398 */
5399static int __wlan_hdd_cfg80211_set_probable_oper_channel(struct wiphy *wiphy,
5400 struct wireless_dev *wdev,
5401 const void *data,
5402 int data_len)
5403{
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05305404 struct net_device *ndev = wdev->netdev;
5405 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005406 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5407 int ret = 0;
5408 enum cds_con_mode intf_mode;
5409 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_MAX + 1];
5410 uint32_t channel_hint;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005411
Jeff Johnson1f61b612016-02-12 16:28:33 -08005412 ENTER_DEV(ndev);
5413
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414 ret = wlan_hdd_validate_context(hdd_ctx);
5415 if (ret)
5416 return ret;
5417
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005418 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_MAX,
5419 data, data_len, NULL)) {
5420 hdd_err("Invalid ATTR");
5421 return -EINVAL;
5422 }
5423
5424 if (!tb[QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE]) {
5425 hdd_err("attr interface type failed");
5426 return -EINVAL;
5427 }
5428
5429 intf_mode = nla_get_u32(tb
5430 [QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE]);
5431
5432 if (intf_mode < CDS_STA_MODE || intf_mode >= CDS_MAX_NUM_OF_MODE) {
5433 hdd_err("Invalid interface type");
5434 return -EINVAL;
5435 }
5436
5437 if (!tb[QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ]) {
5438 hdd_err("attr probable freq failed");
5439 return -EINVAL;
5440 }
5441
5442 channel_hint = cds_freq_to_chan(nla_get_u32(tb
5443 [QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ]));
5444
5445 /* check pcl table */
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08005446 if (!cds_allow_concurrency(intf_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447 channel_hint, HW_MODE_20_MHZ)) {
5448 hdd_err("Set channel hint failed due to concurrency check");
5449 return -EINVAL;
5450 }
5451
Krunal Soni09e55032016-06-07 10:06:55 -07005452 if (0 != wlan_hdd_check_remain_on_channel(adapter))
5453 hdd_warn("Remain On Channel Pending");
5454
Krunal Soni3091bcc2016-06-23 12:28:21 -07005455 ret = qdf_reset_connection_update();
5456 if (!QDF_IS_STATUS_SUCCESS(ret))
5457 hdd_err("clearing event failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005458
Krunal Soni3091bcc2016-06-23 12:28:21 -07005459 ret = cds_current_connections_update(adapter->sessionId,
5460 channel_hint,
5461 SIR_UPDATE_REASON_SET_OPER_CHAN);
5462 if (QDF_STATUS_E_FAILURE == ret) {
5463 /* return in the failure case */
5464 hdd_err("ERROR: connections update failed!!");
5465 return -EINVAL;
5466 }
5467
5468 if (QDF_STATUS_SUCCESS == ret) {
5469 /*
5470 * Success is the only case for which we expect hw mode
5471 * change to take place, hence we need to wait.
5472 * For any other return value it should be a pass
5473 * through
5474 */
5475 ret = qdf_wait_for_connection_update();
5476 if (!QDF_IS_STATUS_SUCCESS(ret)) {
5477 hdd_err("ERROR: qdf wait for event failed!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005478 return -EINVAL;
5479 }
5480
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005481 }
5482
5483 return 0;
5484}
5485
5486/**
5487 * wlan_hdd_cfg80211_set_probable_oper_channel () - set probable channel
5488 * @wiphy: Pointer to wireless phy
5489 * @wdev: Pointer to wireless device
5490 * @data: Pointer to data
5491 * @data_len: Data length
5492 *
5493 * Return: 0 on success, negative errno on failure
5494 */
5495static int wlan_hdd_cfg80211_set_probable_oper_channel(struct wiphy *wiphy,
5496 struct wireless_dev *wdev,
5497 const void *data,
5498 int data_len)
5499{
5500 int ret = 0;
5501
5502 cds_ssr_protect(__func__);
5503 ret = __wlan_hdd_cfg80211_set_probable_oper_channel(wiphy, wdev,
5504 data, data_len);
5505 cds_ssr_unprotect(__func__);
5506
5507 return ret;
5508}
5509
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305510static const struct
5511nla_policy
5512qca_wlan_vendor_attr_policy[QCA_WLAN_VENDOR_ATTR_MAX+1] = {
5513 [QCA_WLAN_VENDOR_ATTR_MAC_ADDR] = { .type = NLA_UNSPEC },
5514};
5515
5516/**
5517 * __wlan_hdd_cfg80211_get_link_properties() - Get link properties
5518 * @wiphy: WIPHY structure pointer
5519 * @wdev: Wireless device structure pointer
5520 * @data: Pointer to the data received
5521 * @data_len: Length of the data received
5522 *
5523 * This function is used to get link properties like nss, rate flags and
5524 * operating frequency for the active connection with the given peer.
5525 *
5526 * Return: 0 on success and errno on failure
5527 */
5528static int __wlan_hdd_cfg80211_get_link_properties(struct wiphy *wiphy,
5529 struct wireless_dev *wdev,
5530 const void *data,
5531 int data_len)
5532{
5533 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5534 struct net_device *dev = wdev->netdev;
5535 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5536 hdd_station_ctx_t *hdd_sta_ctx;
5537 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX+1];
Anurag Chouhan6d760662016-02-20 16:05:43 +05305538 uint8_t peer_mac[QDF_MAC_ADDR_SIZE];
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305539 uint32_t sta_id;
5540 struct sk_buff *reply_skb;
5541 uint32_t rate_flags = 0;
5542 uint8_t nss;
5543 uint8_t final_rate_flags = 0;
5544 uint32_t freq;
5545
Jeff Johnson1f61b612016-02-12 16:28:33 -08005546 ENTER_DEV(dev);
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305547
Anurag Chouhan6d760662016-02-20 16:05:43 +05305548 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305549 hdd_err("Command not allowed in FTM mode");
5550 return -EPERM;
5551 }
5552
5553 if (0 != wlan_hdd_validate_context(hdd_ctx))
5554 return -EINVAL;
5555
5556 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_MAX, data, data_len,
5557 qca_wlan_vendor_attr_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005558 hdd_err("Invalid attribute");
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305559 return -EINVAL;
5560 }
5561
5562 if (!tb[QCA_WLAN_VENDOR_ATTR_MAC_ADDR]) {
Jeff Johnson77848112016-06-29 14:52:06 -07005563 hdd_err("Attribute peerMac not provided for mode=%d",
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305564 adapter->device_mode);
5565 return -EINVAL;
5566 }
5567
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305568 qdf_mem_copy(peer_mac, nla_data(tb[QCA_WLAN_VENDOR_ATTR_MAC_ADDR]),
Anurag Chouhan6d760662016-02-20 16:05:43 +05305569 QDF_MAC_ADDR_SIZE);
Jeff Johnson77848112016-06-29 14:52:06 -07005570 hdd_notice("peerMac="MAC_ADDRESS_STR" for device_mode:%d",
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305571 MAC_ADDR_ARRAY(peer_mac), adapter->device_mode);
5572
Krunal Sonib4326f22016-03-10 13:05:51 -08005573 if (adapter->device_mode == QDF_STA_MODE ||
5574 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305575 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5576 if ((hdd_sta_ctx->conn_info.connState !=
5577 eConnectionState_Associated) ||
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305578 qdf_mem_cmp(hdd_sta_ctx->conn_info.bssId.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305579 peer_mac, QDF_MAC_ADDR_SIZE)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005580 hdd_err("Not Associated to mac "MAC_ADDRESS_STR,
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305581 MAC_ADDR_ARRAY(peer_mac));
5582 return -EINVAL;
5583 }
5584
5585 nss = hdd_sta_ctx->conn_info.nss;
5586 freq = cds_chan_to_freq(
5587 hdd_sta_ctx->conn_info.operationChannel);
5588 rate_flags = hdd_sta_ctx->conn_info.rate_flags;
Krunal Sonib4326f22016-03-10 13:05:51 -08005589 } else if (adapter->device_mode == QDF_P2P_GO_MODE ||
5590 adapter->device_mode == QDF_SAP_MODE) {
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305591
5592 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5593 if (adapter->aStaInfo[sta_id].isUsed &&
Anurag Chouhanc5548422016-02-24 18:33:27 +05305594 !qdf_is_macaddr_broadcast(
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305595 &adapter->aStaInfo[sta_id].macAddrSTA) &&
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305596 !qdf_mem_cmp(
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305597 &adapter->aStaInfo[sta_id].macAddrSTA.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305598 peer_mac, QDF_MAC_ADDR_SIZE))
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305599 break;
5600 }
5601
5602 if (WLAN_MAX_STA_COUNT == sta_id) {
Jeff Johnson77848112016-06-29 14:52:06 -07005603 hdd_err("No active peer with mac="MAC_ADDRESS_STR,
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305604 MAC_ADDR_ARRAY(peer_mac));
5605 return -EINVAL;
5606 }
5607
5608 nss = adapter->aStaInfo[sta_id].nss;
5609 freq = cds_chan_to_freq(
5610 (WLAN_HDD_GET_AP_CTX_PTR(adapter))->operatingChannel);
5611 rate_flags = adapter->aStaInfo[sta_id].rate_flags;
5612 } else {
Jeff Johnson77848112016-06-29 14:52:06 -07005613 hdd_err("Not Associated! with mac "MAC_ADDRESS_STR,
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305614 MAC_ADDR_ARRAY(peer_mac));
5615 return -EINVAL;
5616 }
5617
5618 if (!(rate_flags & eHAL_TX_RATE_LEGACY)) {
5619 if (rate_flags & eHAL_TX_RATE_VHT80) {
5620 final_rate_flags |= RATE_INFO_FLAGS_VHT_MCS;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005621#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)) && !defined(WITH_BACKPORTS)
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305622 final_rate_flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005623#endif
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305624 } else if (rate_flags & eHAL_TX_RATE_VHT40) {
5625 final_rate_flags |= RATE_INFO_FLAGS_VHT_MCS;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005626#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)) && !defined(WITH_BACKPORTS)
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305627 final_rate_flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005628#endif
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305629 } else if (rate_flags & eHAL_TX_RATE_VHT20) {
5630 final_rate_flags |= RATE_INFO_FLAGS_VHT_MCS;
5631 } else if (rate_flags &
5632 (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40)) {
5633 final_rate_flags |= RATE_INFO_FLAGS_MCS;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005634#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)) && !defined(WITH_BACKPORTS)
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305635 if (rate_flags & eHAL_TX_RATE_HT40)
5636 final_rate_flags |=
5637 RATE_INFO_FLAGS_40_MHZ_WIDTH;
Ryan Hsu3a0f5232016-01-21 14:40:11 -08005638#endif
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305639 }
5640
5641 if (rate_flags & eHAL_TX_RATE_SGI) {
5642 if (!(final_rate_flags & RATE_INFO_FLAGS_VHT_MCS))
5643 final_rate_flags |= RATE_INFO_FLAGS_MCS;
5644 final_rate_flags |= RATE_INFO_FLAGS_SHORT_GI;
5645 }
5646 }
5647
5648 reply_skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy,
5649 sizeof(u8) + sizeof(u8) + sizeof(u32) + NLMSG_HDRLEN);
5650
5651 if (NULL == reply_skb) {
Jeff Johnson77848112016-06-29 14:52:06 -07005652 hdd_err("getLinkProperties: skb alloc failed");
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305653 return -EINVAL;
5654 }
5655
5656 if (nla_put_u8(reply_skb,
5657 QCA_WLAN_VENDOR_ATTR_LINK_PROPERTIES_NSS,
5658 nss) ||
5659 nla_put_u8(reply_skb,
5660 QCA_WLAN_VENDOR_ATTR_LINK_PROPERTIES_RATE_FLAGS,
5661 final_rate_flags) ||
5662 nla_put_u32(reply_skb,
5663 QCA_WLAN_VENDOR_ATTR_LINK_PROPERTIES_FREQ,
5664 freq)) {
Jeff Johnson77848112016-06-29 14:52:06 -07005665 hdd_err("nla_put failed");
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05305666 kfree_skb(reply_skb);
5667 return -EINVAL;
5668 }
5669
5670 return cfg80211_vendor_cmd_reply(reply_skb);
5671}
5672
5673/**
5674 * wlan_hdd_cfg80211_get_link_properties() - Wrapper function to get link
5675 * properties.
5676 * @wiphy: WIPHY structure pointer
5677 * @wdev: Wireless device structure pointer
5678 * @data: Pointer to the data received
5679 * @data_len: Length of the data received
5680 *
5681 * This function is used to get link properties like nss, rate flags and
5682 * operating frequency for the active connection with the given peer.
5683 *
5684 * Return: 0 on success and errno on failure
5685 */
5686static int wlan_hdd_cfg80211_get_link_properties(struct wiphy *wiphy,
5687 struct wireless_dev *wdev,
5688 const void *data,
5689 int data_len)
5690{
5691 int ret = 0;
5692
5693 cds_ssr_protect(__func__);
5694 ret = __wlan_hdd_cfg80211_get_link_properties(wiphy,
5695 wdev, data, data_len);
5696 cds_ssr_unprotect(__func__);
5697
5698 return ret;
5699}
5700
Peng Xu278d0122015-09-24 16:34:17 -07005701static const struct
5702nla_policy
5703qca_wlan_vendor_ota_test_policy
5704[QCA_WLAN_VENDOR_ATTR_OTA_TEST_MAX + 1] = {
5705 [QCA_WLAN_VENDOR_ATTR_OTA_TEST_ENABLE] = {.type = NLA_U8 },
5706};
5707
5708/**
5709 * __wlan_hdd_cfg80211_set_ota_test () - enable/disable OTA test
5710 * @wiphy: Pointer to wireless phy
5711 * @wdev: Pointer to wireless device
5712 * @data: Pointer to data
5713 * @data_len: Data length
5714 *
5715 * Return: 0 on success, negative errno on failure
5716 */
5717static int __wlan_hdd_cfg80211_set_ota_test(struct wiphy *wiphy,
5718 struct wireless_dev *wdev,
5719 const void *data,
5720 int data_len)
5721{
5722 struct net_device *dev = wdev->netdev;
5723 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5724 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
5725 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5726 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OTA_TEST_MAX + 1];
5727 uint8_t ota_enable = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305728 QDF_STATUS status;
Peng Xu278d0122015-09-24 16:34:17 -07005729 uint32_t current_roam_state;
5730
Jeff Johnson1f61b612016-02-12 16:28:33 -08005731 ENTER_DEV(dev);
5732
Anurag Chouhan6d760662016-02-20 16:05:43 +05305733 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Peng Xu278d0122015-09-24 16:34:17 -07005734 hdd_err("Command not allowed in FTM mode");
5735 return -EPERM;
5736 }
5737
5738 if (0 != wlan_hdd_validate_context(hdd_ctx))
5739 return -EINVAL;
5740
5741 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OTA_TEST_MAX,
5742 data, data_len,
5743 qca_wlan_vendor_ota_test_policy)) {
5744 hdd_err("invalid attr");
5745 return -EINVAL;
5746 }
5747
5748 if (!tb[QCA_WLAN_VENDOR_ATTR_OTA_TEST_ENABLE]) {
5749 hdd_err("attr ota test failed");
5750 return -EINVAL;
5751 }
5752
5753 ota_enable = nla_get_u8(
5754 tb[QCA_WLAN_VENDOR_ATTR_OTA_TEST_ENABLE]);
5755
5756 hdd_info(" OTA test enable = %d", ota_enable);
5757 if (ota_enable != 1) {
5758 hdd_err("Invalid value, only enable test mode is supported!");
5759 return -EINVAL;
5760 }
5761
5762 current_roam_state =
5763 sme_get_current_roam_state(hal, adapter->sessionId);
5764 status = sme_stop_roaming(hal, adapter->sessionId,
5765 eCsrHddIssued);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305766 if (status != QDF_STATUS_SUCCESS) {
Peng Xu278d0122015-09-24 16:34:17 -07005767 hdd_err("Enable/Disable roaming failed");
5768 return -EINVAL;
5769 }
5770
5771 status = sme_ps_enable_disable(hal, adapter->sessionId,
5772 SME_PS_DISABLE);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305773 if (status != QDF_STATUS_SUCCESS) {
Peng Xu278d0122015-09-24 16:34:17 -07005774 hdd_err("Enable/Disable power save failed");
5775 /* restore previous roaming setting */
5776 if (current_roam_state == eCSR_ROAMING_STATE_JOINING ||
5777 current_roam_state == eCSR_ROAMING_STATE_JOINED)
5778 status = sme_start_roaming(hal, adapter->sessionId,
5779 eCsrHddIssued);
5780 else if (current_roam_state == eCSR_ROAMING_STATE_STOP ||
5781 current_roam_state == eCSR_ROAMING_STATE_IDLE)
5782 status = sme_stop_roaming(hal, adapter->sessionId,
5783 eCsrHddIssued);
5784
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305785 if (status != QDF_STATUS_SUCCESS)
Peng Xu278d0122015-09-24 16:34:17 -07005786 hdd_err("Restoring roaming state failed");
5787
5788 return -EINVAL;
5789 }
5790
5791
5792 return 0;
5793}
5794
5795/**
5796 * wlan_hdd_cfg80211_set_ota_test () - Enable or disable OTA test
5797 * @wiphy: Pointer to wireless phy
5798 * @wdev: Pointer to wireless device
5799 * @data: Pointer to data
5800 * @data_len: Data length
5801 *
5802 * Return: 0 on success, negative errno on failure
5803 */
5804static int wlan_hdd_cfg80211_set_ota_test(struct wiphy *wiphy,
5805 struct wireless_dev *wdev,
5806 const void *data,
5807 int data_len)
5808{
5809 int ret = 0;
5810
5811 cds_ssr_protect(__func__);
5812 ret = __wlan_hdd_cfg80211_set_ota_test(wiphy, wdev, data, data_len);
5813 cds_ssr_unprotect(__func__);
5814
5815 return ret;
5816}
5817
Peng Xu4d67c8f2015-10-16 16:02:26 -07005818/**
5819 * __wlan_hdd_cfg80211_txpower_scale () - txpower scaling
5820 * @wiphy: Pointer to wireless phy
5821 * @wdev: Pointer to wireless device
5822 * @data: Pointer to data
5823 * @data_len: Data length
5824 *
5825 * Return: 0 on success, negative errno on failure
5826 */
5827static int __wlan_hdd_cfg80211_txpower_scale(struct wiphy *wiphy,
5828 struct wireless_dev *wdev,
5829 const void *data,
5830 int data_len)
5831{
5832 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5833 struct net_device *dev = wdev->netdev;
Peng Xu62c8c432016-05-09 15:23:02 -07005834 hdd_adapter_t *adapter;
5835 int ret;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005836 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_MAX + 1];
5837 uint8_t scale_value;
Peng Xu62c8c432016-05-09 15:23:02 -07005838 QDF_STATUS status;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005839
Jeff Johnson1f61b612016-02-12 16:28:33 -08005840 ENTER_DEV(dev);
5841
Peng Xu4d67c8f2015-10-16 16:02:26 -07005842 ret = wlan_hdd_validate_context(hdd_ctx);
5843 if (ret)
5844 return ret;
5845
5846 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5847
5848 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_MAX,
5849 data, data_len, NULL)) {
5850 hdd_err("Invalid ATTR");
5851 return -EINVAL;
5852 }
5853
5854 if (!tb[QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE]) {
5855 hdd_err("attr tx power scale failed");
5856 return -EINVAL;
5857 }
5858
5859 scale_value = nla_get_u8(tb
5860 [QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE]);
5861
5862 if (scale_value > MAX_TXPOWER_SCALE) {
5863 hdd_err("Invalid tx power scale level");
5864 return -EINVAL;
5865 }
5866
Peng Xu62c8c432016-05-09 15:23:02 -07005867 status = wma_set_tx_power_scale(adapter->sessionId, scale_value);
Peng Xu4d67c8f2015-10-16 16:02:26 -07005868
Peng Xu62c8c432016-05-09 15:23:02 -07005869 if (QDF_STATUS_SUCCESS != status) {
Peng Xu4d67c8f2015-10-16 16:02:26 -07005870 hdd_err("Set tx power scale failed");
5871 return -EINVAL;
5872 }
5873
5874 return 0;
5875}
5876
5877/**
5878 * wlan_hdd_cfg80211_txpower_scale () - txpower scaling
5879 * @wiphy: Pointer to wireless phy
5880 * @wdev: Pointer to wireless device
5881 * @data: Pointer to data
5882 * @data_len: Data length
5883 *
5884 * Return: 0 on success, negative errno on failure
5885 */
5886static int wlan_hdd_cfg80211_txpower_scale(struct wiphy *wiphy,
5887 struct wireless_dev *wdev,
5888 const void *data,
5889 int data_len)
5890{
Peng Xu62c8c432016-05-09 15:23:02 -07005891 int ret;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005892
5893 cds_ssr_protect(__func__);
5894 ret = __wlan_hdd_cfg80211_txpower_scale(wiphy, wdev,
5895 data, data_len);
5896 cds_ssr_unprotect(__func__);
5897
5898 return ret;
5899}
5900
5901/**
5902 * __wlan_hdd_cfg80211_txpower_scale_decr_db () - txpower scaling
5903 * @wiphy: Pointer to wireless phy
5904 * @wdev: Pointer to wireless device
5905 * @data: Pointer to data
5906 * @data_len: Data length
5907 *
5908 * Return: 0 on success, negative errno on failure
5909 */
5910static int __wlan_hdd_cfg80211_txpower_scale_decr_db(struct wiphy *wiphy,
5911 struct wireless_dev *wdev,
5912 const void *data,
5913 int data_len)
5914{
5915 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5916 struct net_device *dev = wdev->netdev;
Peng Xu62c8c432016-05-09 15:23:02 -07005917 hdd_adapter_t *adapter;
5918 int ret;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005919 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_DECR_DB_MAX + 1];
5920 uint8_t scale_value;
Peng Xu62c8c432016-05-09 15:23:02 -07005921 QDF_STATUS status;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005922
Jeff Johnson1f61b612016-02-12 16:28:33 -08005923 ENTER_DEV(dev);
5924
Peng Xu4d67c8f2015-10-16 16:02:26 -07005925 ret = wlan_hdd_validate_context(hdd_ctx);
5926 if (ret)
5927 return ret;
5928
5929 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5930
5931 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_DECR_DB_MAX,
5932 data, data_len, NULL)) {
5933 hdd_err("Invalid ATTR");
5934 return -EINVAL;
5935 }
5936
5937 if (!tb[QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_DECR_DB]) {
5938 hdd_err("attr tx power decrease db value failed");
5939 return -EINVAL;
5940 }
5941
5942 scale_value = nla_get_u8(tb
5943 [QCA_WLAN_VENDOR_ATTR_TXPOWER_SCALE_DECR_DB]);
5944
Peng Xu62c8c432016-05-09 15:23:02 -07005945 status = wma_set_tx_power_scale_decr_db(adapter->sessionId,
5946 scale_value);
Peng Xu4d67c8f2015-10-16 16:02:26 -07005947
Peng Xu62c8c432016-05-09 15:23:02 -07005948 if (QDF_STATUS_SUCCESS != status) {
Peng Xu4d67c8f2015-10-16 16:02:26 -07005949 hdd_err("Set tx power decrease db failed");
5950 return -EINVAL;
5951 }
5952
5953 return 0;
5954}
5955
5956/**
5957 * wlan_hdd_cfg80211_txpower_scale_decr_db () - txpower scaling
5958 * @wiphy: Pointer to wireless phy
5959 * @wdev: Pointer to wireless device
5960 * @data: Pointer to data
5961 * @data_len: Data length
5962 *
5963 * Return: 0 on success, negative errno on failure
5964 */
5965static int wlan_hdd_cfg80211_txpower_scale_decr_db(struct wiphy *wiphy,
5966 struct wireless_dev *wdev,
5967 const void *data,
5968 int data_len)
5969{
Peng Xu62c8c432016-05-09 15:23:02 -07005970 int ret;
Peng Xu4d67c8f2015-10-16 16:02:26 -07005971
5972 cds_ssr_protect(__func__);
5973 ret = __wlan_hdd_cfg80211_txpower_scale_decr_db(wiphy, wdev,
5974 data, data_len);
5975 cds_ssr_unprotect(__func__);
5976
5977 return ret;
5978}
Peng Xu8fdaa492016-06-22 10:20:47 -07005979
5980/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305981 * __wlan_hdd_cfg80211_conditional_chan_switch() - Conditional channel switch
5982 * @wiphy: Pointer to wireless phy
5983 * @wdev: Pointer to wireless device
5984 * @data: Pointer to data
5985 * @data_len: Data length
5986 *
5987 * Processes the conditional channel switch request and invokes the helper
5988 * APIs to process the channel switch request.
5989 *
5990 * Return: 0 on success, negative errno on failure
5991 */
5992static int __wlan_hdd_cfg80211_conditional_chan_switch(struct wiphy *wiphy,
5993 struct wireless_dev *wdev,
5994 const void *data,
5995 int data_len)
5996{
5997 int ret;
5998 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
5999 struct net_device *dev = wdev->netdev;
6000 hdd_adapter_t *adapter;
6001 struct nlattr
6002 *tb[QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_MAX + 1];
6003 uint32_t freq_len, i;
6004 uint32_t *freq;
6005 uint8_t chans[QDF_MAX_NUM_CHAN];
6006
6007 ENTER_DEV(dev);
6008
6009 ret = wlan_hdd_validate_context(hdd_ctx);
6010 if (ret)
6011 return ret;
6012
6013 if (!hdd_ctx->config->enableDFSMasterCap) {
6014 hdd_err("DFS master capability is not present in the driver");
6015 return -EINVAL;
6016 }
6017
6018 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
6019 hdd_err("Command not allowed in FTM mode");
6020 return -EPERM;
6021 }
6022
6023 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6024 if (adapter->device_mode != QDF_SAP_MODE) {
6025 hdd_err("Invalid device mode %d", adapter->device_mode);
6026 return -EINVAL;
6027 }
6028
6029 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_MAX,
6030 data, data_len, NULL)) {
6031 hdd_err("Invalid ATTR");
6032 return -EINVAL;
6033 }
6034
6035 if (!tb[QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_FREQ_LIST]) {
6036 hdd_err("Frequency list is missing");
6037 return -EINVAL;
6038 }
6039
6040 freq_len = nla_len(
6041 tb[QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_FREQ_LIST])/
6042 sizeof(uint32_t);
6043
6044 if (freq_len > QDF_MAX_NUM_CHAN) {
6045 hdd_err("insufficient space to hold channels");
6046 return -ENOMEM;
6047 }
6048
6049 hdd_debug("freq_len=%d", freq_len);
6050
6051 freq = nla_data(
6052 tb[QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_FREQ_LIST]);
6053
6054
6055 for (i = 0; i < freq_len; i++) {
6056 if (freq[i] == 0)
6057 chans[i] = 0;
6058 else
6059 chans[i] = ieee80211_frequency_to_channel(freq[i]);
6060
6061 hdd_debug("freq[%d]=%d", i, freq[i]);
6062 }
6063
6064 /*
6065 * The input frequency list from user space is designed to be a
6066 * priority based frequency list. This is only to accommodate any
6067 * future request. But, current requirement is only to perform CAC
6068 * on a single channel. So, the first entry from the list is picked.
6069 *
6070 * If channel is zero, any channel in the available outdoor regulatory
6071 * domain will be selected.
6072 */
6073 ret = wlan_hdd_request_pre_cac(chans[0]);
6074 if (ret) {
6075 hdd_err("pre cac request failed with reason:%d", ret);
6076 return ret;
6077 }
6078
6079 return 0;
6080}
6081
6082/**
Peng Xu8fdaa492016-06-22 10:20:47 -07006083 * __wlan_hdd_cfg80211_p2p_lo_start () - start P2P Listen Offload
6084 * @wiphy: Pointer to wireless phy
6085 * @wdev: Pointer to wireless device
6086 * @data: Pointer to data
6087 * @data_len: Data length
6088 *
6089 * This function is to process the p2p listen offload start vendor
6090 * command. It parses the input parameters and invoke WMA API to
6091 * send the command to firmware.
6092 *
6093 * Return: 0 on success, negative errno on failure
6094 */
6095static int __wlan_hdd_cfg80211_p2p_lo_start(struct wiphy *wiphy,
6096 struct wireless_dev *wdev,
6097 const void *data,
6098 int data_len)
6099{
6100 int ret;
6101 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
6102 struct net_device *dev = wdev->netdev;
6103 hdd_adapter_t *adapter;
6104 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_MAX + 1];
6105 struct sir_p2p_lo_start params;
6106 QDF_STATUS status;
6107
6108 ENTER_DEV(dev);
6109
6110 ret = wlan_hdd_validate_context(hdd_ctx);
6111 if (ret)
6112 return ret;
6113
6114 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
6115 hdd_err("Command not allowed in FTM mode");
6116 return -EPERM;
6117 }
6118
6119 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6120 if ((adapter->device_mode != QDF_P2P_DEVICE_MODE) &&
6121 (adapter->device_mode != QDF_P2P_CLIENT_MODE) &&
6122 (adapter->device_mode != QDF_P2P_GO_MODE)) {
6123 hdd_err("Invalid device mode %d", adapter->device_mode);
6124 return -EINVAL;
6125 }
6126
6127 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_MAX,
6128 data, data_len, NULL)) {
6129 hdd_err("Invalid ATTR");
6130 return -EINVAL;
6131 }
6132
6133 memset(&params, 0, sizeof(params));
6134
6135 if (!tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CTRL_FLAG])
6136 params.ctl_flags = 1; /* set to default value */
6137 else
6138 params.ctl_flags = nla_get_u32(tb
6139 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CTRL_FLAG]);
6140
6141 if (!tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL] ||
6142 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD] ||
6143 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL] ||
6144 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT] ||
6145 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES] ||
6146 !tb[QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE]) {
6147 hdd_err("Attribute parsing failed");
6148 return -EINVAL;
6149 }
6150
6151 params.vdev_id = adapter->sessionId;
6152 params.freq = nla_get_u32(tb
6153 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL]);
6154 if ((params.freq != 2412) && (params.freq != 2437) &&
6155 (params.freq != 2462)) {
6156 hdd_err("Invalid listening channel: %d", params.freq);
6157 return -EINVAL;
6158 }
6159
6160 params.period = nla_get_u32(tb
6161 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD]);
6162 if (!((params.period > 0) && (params.period < UINT_MAX))) {
6163 hdd_err("Invalid period: %d", params.period);
6164 return -EINVAL;
6165 }
6166
6167 params.interval = nla_get_u32(tb
6168 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL]);
6169 if (!((params.interval > 0) && (params.interval < UINT_MAX))) {
6170 hdd_err("Invalid interval: %d", params.interval);
6171 return -EINVAL;
6172 }
6173
6174 params.count = nla_get_u32(tb
6175 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT]);
Peng Xu6d578ef2017-01-10 06:22:21 -08006176 if (!((params.count >= 0) && (params.count < UINT_MAX))) {
Peng Xu8fdaa492016-06-22 10:20:47 -07006177 hdd_err("Invalid count: %d", params.count);
6178 return -EINVAL;
6179 }
6180
6181 params.device_types = nla_data(tb
6182 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES]);
6183 if (params.device_types == NULL) {
6184 hdd_err("Invalid device types");
6185 return -EINVAL;
6186 }
6187
6188 params.dev_types_len = nla_len(tb
6189 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES]);
6190 if (params.dev_types_len < 8) {
6191 hdd_err("Invalid device type length: %d", params.dev_types_len);
6192 return -EINVAL;
6193 }
6194
6195 params.probe_resp_tmplt = nla_data(tb
6196 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE]);
6197 if (params.probe_resp_tmplt == NULL) {
6198 hdd_err("Invalid probe response template");
6199 return -EINVAL;
6200 }
6201
6202 params.probe_resp_len = nla_len(tb
6203 [QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE]);
6204 if (params.probe_resp_len == 0) {
6205 hdd_err("Invalid probe resp template length: %d",
6206 params.probe_resp_len);
6207 return -EINVAL;
6208 }
6209
6210 hdd_debug("P2P LO params: freq=%d, period=%d, interval=%d, count=%d",
6211 params.freq, params.period, params.interval, params.count);
6212
6213 status = wma_p2p_lo_start(&params);
6214
6215 if (!QDF_IS_STATUS_SUCCESS(status)) {
6216 hdd_err("P2P LO start failed");
6217 return -EINVAL;
6218 }
6219
6220 return 0;
6221}
6222
6223
6224/**
6225 * wlan_hdd_cfg80211_p2p_lo_start () - start P2P Listen Offload
6226 * @wiphy: Pointer to wireless phy
6227 * @wdev: Pointer to wireless device
6228 * @data: Pointer to data
6229 * @data_len: Data length
6230 *
6231 * This function inovkes internal __wlan_hdd_cfg80211_p2p_lo_start()
6232 * to process p2p listen offload start vendor command.
6233 *
6234 * Return: 0 on success, negative errno on failure
6235 */
6236static int wlan_hdd_cfg80211_p2p_lo_start(struct wiphy *wiphy,
6237 struct wireless_dev *wdev,
6238 const void *data,
6239 int data_len)
6240{
6241 int ret = 0;
6242
6243 cds_ssr_protect(__func__);
6244 ret = __wlan_hdd_cfg80211_p2p_lo_start(wiphy, wdev,
6245 data, data_len);
6246 cds_ssr_unprotect(__func__);
6247
6248 return ret;
6249}
6250
6251/**
6252 * __wlan_hdd_cfg80211_p2p_lo_stop () - stop P2P Listen Offload
6253 * @wiphy: Pointer to wireless phy
6254 * @wdev: Pointer to wireless device
6255 * @data: Pointer to data
6256 * @data_len: Data length
6257 *
6258 * This function is to process the p2p listen offload stop vendor
6259 * command. It invokes WMA API to send command to firmware.
6260 *
6261 * Return: 0 on success, negative errno on failure
6262 */
6263static int __wlan_hdd_cfg80211_p2p_lo_stop(struct wiphy *wiphy,
6264 struct wireless_dev *wdev,
6265 const void *data,
6266 int data_len)
6267{
6268 QDF_STATUS status;
6269 hdd_adapter_t *adapter;
6270 struct net_device *dev = wdev->netdev;
6271
6272 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
6273 hdd_err("Command not allowed in FTM mode");
6274 return -EPERM;
6275 }
6276
6277 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6278 if ((adapter->device_mode != QDF_P2P_DEVICE_MODE) &&
6279 (adapter->device_mode != QDF_P2P_CLIENT_MODE) &&
6280 (adapter->device_mode != QDF_P2P_GO_MODE)) {
6281 hdd_err("Invalid device mode");
6282 return -EINVAL;
6283 }
6284
6285 status = wma_p2p_lo_stop(adapter->sessionId);
6286
6287 if (!QDF_IS_STATUS_SUCCESS(status)) {
6288 hdd_err("P2P LO stop failed");
6289 return -EINVAL;
6290 }
6291
6292 return 0;
6293}
6294
6295/**
6296 * wlan_hdd_cfg80211_p2p_lo_stop () - stop P2P Listen Offload
6297 * @wiphy: Pointer to wireless phy
6298 * @wdev: Pointer to wireless device
6299 * @data: Pointer to data
6300 * @data_len: Data length
6301 *
6302 * This function inovkes internal __wlan_hdd_cfg80211_p2p_lo_stop()
6303 * to process p2p listen offload stop vendor command.
6304 *
6305 * Return: 0 on success, negative errno on failure
6306 */
6307static int wlan_hdd_cfg80211_p2p_lo_stop(struct wiphy *wiphy,
6308 struct wireless_dev *wdev,
6309 const void *data,
6310 int data_len)
6311{
6312 int ret = 0;
6313
6314 cds_ssr_protect(__func__);
6315 ret = __wlan_hdd_cfg80211_p2p_lo_stop(wiphy, wdev,
6316 data, data_len);
6317 cds_ssr_unprotect(__func__);
6318
6319 return ret;
6320}
6321
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306322/**
6323 * wlan_hdd_cfg80211_conditional_chan_switch() - SAP conditional channel switch
6324 * @wiphy: Pointer to wireless phy
6325 * @wdev: Pointer to wireless device
6326 * @data: Pointer to data
6327 * @data_len: Data length
6328 *
6329 * Inovkes internal API __wlan_hdd_cfg80211_conditional_chan_switch()
6330 * to process the conditional channel switch request.
6331 *
6332 * Return: 0 on success, negative errno on failure
6333 */
6334static int wlan_hdd_cfg80211_conditional_chan_switch(struct wiphy *wiphy,
6335 struct wireless_dev *wdev,
6336 const void *data,
6337 int data_len)
6338{
6339 int ret;
6340
6341 cds_ssr_protect(__func__);
6342 ret = __wlan_hdd_cfg80211_conditional_chan_switch(wiphy, wdev,
6343 data, data_len);
6344 cds_ssr_unprotect(__func__);
6345
6346 return ret;
6347}
6348
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306349/*
6350 * define short names for the global vendor params
6351 * used by __wlan_hdd_cfg80211_bpf_offload()
6352 */
6353#define BPF_INVALID \
6354 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_INVALID
6355#define BPF_SET_RESET \
6356 QCA_WLAN_VENDOR_ATTR_SET_RESET_PACKET_FILTER
6357#define BPF_VERSION \
6358 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_VERSION
6359#define BPF_FILTER_ID \
6360 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_ID
6361#define BPF_PACKET_SIZE \
6362 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_SIZE
6363#define BPF_CURRENT_OFFSET \
6364 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_CURRENT_OFFSET
6365#define BPF_PROGRAM \
6366 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_PROGRAM
6367#define BPF_MAX \
6368 QCA_WLAN_VENDOR_ATTR_PACKET_FILTER_MAX
Peng Xu4d67c8f2015-10-16 16:02:26 -07006369
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306370static const struct nla_policy
6371wlan_hdd_bpf_offload_policy[BPF_MAX + 1] = {
6372 [BPF_SET_RESET] = {.type = NLA_U32},
6373 [BPF_VERSION] = {.type = NLA_U32},
6374 [BPF_FILTER_ID] = {.type = NLA_U32},
6375 [BPF_PACKET_SIZE] = {.type = NLA_U32},
6376 [BPF_CURRENT_OFFSET] = {.type = NLA_U32},
6377 [BPF_PROGRAM] = {.type = NLA_U8},
6378};
6379
6380/**
6381 * hdd_get_bpf_offload_cb() - Callback function to BPF Offload
6382 * @hdd_context: hdd_context
6383 * @bpf_get_offload: struct for get offload
6384 *
6385 * This function receives the response/data from the lower layer and
6386 * checks to see if the thread is still waiting then post the results to
6387 * upper layer, if the request has timed out then ignore.
6388 *
6389 * Return: None
6390 */
Jeff Johnsona867e0c2017-01-26 13:43:51 -08006391static void hdd_get_bpf_offload_cb(void *hdd_context,
6392 struct sir_bpf_get_offload *data)
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306393{
6394 hdd_context_t *hdd_ctx = hdd_context;
6395 struct hdd_bpf_context *context;
6396
6397 ENTER();
6398
6399 if (wlan_hdd_validate_context(hdd_ctx) || !data) {
Jeff Johnson77848112016-06-29 14:52:06 -07006400 hdd_err("HDD context is invalid or data(%p) is null",
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306401 data);
6402 return;
6403 }
6404
6405 spin_lock(&hdd_context_lock);
6406
6407 context = &bpf_context;
6408 /* The caller presumably timed out so there is nothing we can do */
6409 if (context->magic != BPF_CONTEXT_MAGIC) {
6410 spin_unlock(&hdd_context_lock);
6411 return;
6412 }
6413
6414 /* context is valid so caller is still waiting */
6415 /* paranoia: invalidate the magic */
6416 context->magic = 0;
6417
6418 context->capability_response = *data;
6419 complete(&context->completion);
6420
6421 spin_unlock(&hdd_context_lock);
6422
6423 return;
6424}
6425
6426/**
6427 * hdd_post_get_bpf_capabilities_rsp() - Callback function to BPF Offload
6428 * @hdd_context: hdd_context
6429 * @bpf_get_offload: struct for get offload
6430 *
6431 * Return: 0 on success, error number otherwise.
6432 */
6433static int hdd_post_get_bpf_capabilities_rsp(hdd_context_t *hdd_ctx,
6434 struct sir_bpf_get_offload *bpf_get_offload)
6435{
6436 struct sk_buff *skb;
6437 uint32_t nl_buf_len;
6438
6439 ENTER();
6440
6441 nl_buf_len = NLMSG_HDRLEN;
6442 nl_buf_len +=
6443 (sizeof(bpf_get_offload->max_bytes_for_bpf_inst) + NLA_HDRLEN) +
6444 (sizeof(bpf_get_offload->bpf_version) + NLA_HDRLEN);
6445
6446 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
6447 if (!skb) {
Jeff Johnson77848112016-06-29 14:52:06 -07006448 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306449 return -ENOMEM;
6450 }
6451
Jeff Johnson77848112016-06-29 14:52:06 -07006452 hdd_notice("BPF Version: %u BPF max bytes: %u",
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306453 bpf_get_offload->bpf_version,
6454 bpf_get_offload->max_bytes_for_bpf_inst);
6455
6456 if (nla_put_u32(skb, BPF_PACKET_SIZE,
6457 bpf_get_offload->max_bytes_for_bpf_inst) ||
6458 nla_put_u32(skb, BPF_VERSION, bpf_get_offload->bpf_version)) {
Jeff Johnson77848112016-06-29 14:52:06 -07006459 hdd_err("nla put failure");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306460 goto nla_put_failure;
6461 }
6462
6463 cfg80211_vendor_cmd_reply(skb);
6464 EXIT();
6465 return 0;
6466
6467nla_put_failure:
6468 kfree_skb(skb);
6469 return -EINVAL;
6470}
6471
6472/**
6473 * hdd_get_bpf_offload - Get BPF offload Capabilities
6474 * @hdd_ctx: Hdd context
6475 *
6476 * Return: 0 on success, errno on failure
6477 */
6478static int hdd_get_bpf_offload(hdd_context_t *hdd_ctx)
6479{
6480 unsigned long rc;
Houston Hoffman59c097f2016-11-09 15:50:25 -08006481 static struct hdd_bpf_context *context;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306482 QDF_STATUS status;
6483 int ret;
6484
6485 ENTER();
6486
6487 spin_lock(&hdd_context_lock);
6488 context = &bpf_context;
6489 context->magic = BPF_CONTEXT_MAGIC;
6490 INIT_COMPLETION(context->completion);
6491 spin_unlock(&hdd_context_lock);
6492
Jeff Johnsona867e0c2017-01-26 13:43:51 -08006493 status = sme_get_bpf_offload_capabilities(hdd_ctx->hHal,
6494 hdd_get_bpf_offload_cb,
6495 hdd_ctx);
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306496 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07006497 hdd_err("Unable to retrieve BPF caps");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306498 return -EINVAL;
6499 }
6500 /* request was sent -- wait for the response */
6501 rc = wait_for_completion_timeout(&context->completion,
6502 msecs_to_jiffies(WLAN_WAIT_TIME_BPF));
6503 if (!rc) {
Jeff Johnson77848112016-06-29 14:52:06 -07006504 hdd_err("Target response timed out");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306505 spin_lock(&hdd_context_lock);
6506 context->magic = 0;
6507 spin_unlock(&hdd_context_lock);
6508
6509 return -ETIMEDOUT;
6510 }
6511 ret = hdd_post_get_bpf_capabilities_rsp(hdd_ctx,
6512 &bpf_context.capability_response);
6513 if (ret)
Jeff Johnson77848112016-06-29 14:52:06 -07006514 hdd_err("Failed to post get bpf capabilities");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306515
6516 EXIT();
6517 return ret;
6518}
6519
6520/**
6521 * hdd_set_reset_bpf_offload - Post set/reset bpf to SME
6522 * @hdd_ctx: Hdd context
6523 * @tb: Length of @data
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306524 * @adapter: pointer to adapter struct
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306525 *
6526 * Return: 0 on success; errno on failure
6527 */
6528static int hdd_set_reset_bpf_offload(hdd_context_t *hdd_ctx,
6529 struct nlattr **tb,
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306530 hdd_adapter_t *adapter)
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306531{
6532 struct sir_bpf_set_offload *bpf_set_offload;
6533 QDF_STATUS status;
6534 int prog_len;
Arun Khandavalli08500812016-07-25 14:58:42 +05306535 int ret = 0;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306536
6537 ENTER();
6538
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306539 if (adapter->device_mode == QDF_STA_MODE ||
6540 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
6541 if (!hdd_conn_is_connected(
6542 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
6543 hdd_err("Not in Connected state!");
6544 return -ENOTSUPP;
6545 }
6546 }
6547
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306548 bpf_set_offload = qdf_mem_malloc(sizeof(*bpf_set_offload));
6549 if (bpf_set_offload == NULL) {
Jeff Johnson77848112016-06-29 14:52:06 -07006550 hdd_err("qdf_mem_malloc failed for bpf_set_offload");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306551 return -ENOMEM;
6552 }
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306553
6554 /* Parse and fetch bpf packet size */
6555 if (!tb[BPF_PACKET_SIZE]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006556 hdd_err("attr bpf packet size 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->total_length = nla_get_u32(tb[BPF_PACKET_SIZE]);
6561
6562 if (!bpf_set_offload->total_length) {
Jeff Johnson77848112016-06-29 14:52:06 -07006563 hdd_notice("BPF reset packet filter received");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306564 goto post_sme;
6565 }
6566
6567 /* Parse and fetch bpf program */
6568 if (!tb[BPF_PROGRAM]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006569 hdd_err("attr bpf program failed");
Arun Khandavalli08500812016-07-25 14:58:42 +05306570 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306571 goto fail;
6572 }
6573
6574 prog_len = nla_len(tb[BPF_PROGRAM]);
6575 bpf_set_offload->program = qdf_mem_malloc(sizeof(uint8_t) * prog_len);
Arun Khandavalli08500812016-07-25 14:58:42 +05306576
6577 if (bpf_set_offload->program == NULL) {
6578 hdd_err("qdf_mem_malloc failed for bpf offload program");
6579 ret = -ENOMEM;
6580 goto fail;
6581 }
6582
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306583 bpf_set_offload->current_length = prog_len;
6584 nla_memcpy(bpf_set_offload->program, tb[BPF_PROGRAM], prog_len);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306585 bpf_set_offload->session_id = adapter->sessionId;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306586
Rajeev Kumar Sirasanagandla62b63032016-08-22 14:56:57 +05306587 hdd_info("BPF set instructions");
6588 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
6589 bpf_set_offload->program, prog_len);
6590
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306591 /* Parse and fetch filter Id */
6592 if (!tb[BPF_FILTER_ID]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006593 hdd_err("attr filter id failed");
Arun Khandavalli08500812016-07-25 14:58:42 +05306594 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306595 goto fail;
6596 }
6597 bpf_set_offload->filter_id = nla_get_u32(tb[BPF_FILTER_ID]);
6598
6599 /* Parse and fetch current offset */
6600 if (!tb[BPF_CURRENT_OFFSET]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006601 hdd_err("attr current offset failed");
Arun Khandavalli08500812016-07-25 14:58:42 +05306602 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306603 goto fail;
6604 }
6605 bpf_set_offload->current_offset = nla_get_u32(tb[BPF_CURRENT_OFFSET]);
6606
6607post_sme:
Jeff Johnson77848112016-06-29 14:52:06 -07006608 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 +05306609 bpf_set_offload->session_id,
6610 bpf_set_offload->version,
6611 bpf_set_offload->filter_id,
6612 bpf_set_offload->total_length,
6613 bpf_set_offload->current_length,
6614 bpf_set_offload->current_offset);
6615
6616 status = sme_set_bpf_instructions(hdd_ctx->hHal, bpf_set_offload);
6617 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson77848112016-06-29 14:52:06 -07006618 hdd_err("sme_set_bpf_instructions failed(err=%d)", status);
Arun Khandavalli08500812016-07-25 14:58:42 +05306619 ret = -EINVAL;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306620 goto fail;
6621 }
6622 EXIT();
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306623
6624fail:
6625 if (bpf_set_offload->current_length)
6626 qdf_mem_free(bpf_set_offload->program);
6627 qdf_mem_free(bpf_set_offload);
Arun Khandavalli08500812016-07-25 14:58:42 +05306628 return ret;
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306629}
6630
6631/**
6632 * wlan_hdd_cfg80211_bpf_offload() - Set/Reset to BPF Offload
6633 * @wiphy: wiphy structure pointer
6634 * @wdev: Wireless device structure pointer
6635 * @data: Pointer to the data received
6636 * @data_len: Length of @data
6637 *
6638 * Return: 0 on success; errno on failure
6639 */
6640static int
6641__wlan_hdd_cfg80211_bpf_offload(struct wiphy *wiphy,
6642 struct wireless_dev *wdev,
6643 const void *data, int data_len)
6644{
6645 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
6646 struct net_device *dev = wdev->netdev;
6647 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6648 struct nlattr *tb[BPF_MAX + 1];
6649 int ret_val, packet_filter_subcmd;
6650
6651 ENTER();
6652
6653 ret_val = wlan_hdd_validate_context(hdd_ctx);
6654 if (ret_val)
6655 return ret_val;
6656
6657 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson77848112016-06-29 14:52:06 -07006658 hdd_err("Command not allowed in FTM mode");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306659 return -EINVAL;
6660 }
6661
6662 if (!hdd_ctx->bpf_enabled) {
Rajeev Kumardd3bc602016-08-16 14:21:05 -07006663 hdd_err("BPF offload is not supported/enabled");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306664 return -ENOTSUPP;
6665 }
6666
6667 if (nla_parse(tb, BPF_MAX, data, data_len,
6668 wlan_hdd_bpf_offload_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07006669 hdd_err("Invalid ATTR");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306670 return -EINVAL;
6671 }
6672
6673 if (!tb[BPF_SET_RESET]) {
Jeff Johnson77848112016-06-29 14:52:06 -07006674 hdd_err("attr bpf set reset failed");
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306675 return -EINVAL;
6676 }
6677
6678 packet_filter_subcmd = nla_get_u32(tb[BPF_SET_RESET]);
6679
6680 if (packet_filter_subcmd == QCA_WLAN_GET_PACKET_FILTER)
6681 return hdd_get_bpf_offload(hdd_ctx);
6682 else
6683 return hdd_set_reset_bpf_offload(hdd_ctx, tb,
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05306684 pAdapter);
Arun Khandavalli2476ef52016-04-26 20:19:43 +05306685}
6686
6687/**
6688 * wlan_hdd_cfg80211_bpf_offload() - SSR Wrapper to BPF Offload
6689 * @wiphy: wiphy structure pointer
6690 * @wdev: Wireless device structure pointer
6691 * @data: Pointer to the data received
6692 * @data_len: Length of @data
6693 *
6694 * Return: 0 on success; errno on failure
6695 */
6696
6697static int wlan_hdd_cfg80211_bpf_offload(struct wiphy *wiphy,
6698 struct wireless_dev *wdev,
6699 const void *data, int data_len)
6700{
6701 int ret;
6702
6703 cds_ssr_protect(__func__);
6704 ret = __wlan_hdd_cfg80211_bpf_offload(wiphy, wdev, data, data_len);
6705 cds_ssr_unprotect(__func__);
6706
6707 return ret;
6708}
6709
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306710/**
6711 * wlan_hdd_set_pre_cac_status() - Set the pre cac status
6712 * @pre_cac_adapter: AP adapter used for pre cac
6713 * @status: Status (true or false)
6714 * @handle: Global handle
6715 *
6716 * Sets the status of pre cac i.e., whether the pre cac is active or not
6717 *
6718 * Return: Zero on success, non-zero on failure
6719 */
6720static int wlan_hdd_set_pre_cac_status(hdd_adapter_t *pre_cac_adapter,
6721 bool status, tHalHandle handle)
6722{
6723 QDF_STATUS ret;
6724
6725 ret = wlan_sap_set_pre_cac_status(
6726 WLAN_HDD_GET_SAP_CTX_PTR(pre_cac_adapter), status, handle);
6727 if (QDF_IS_STATUS_ERROR(ret))
6728 return -EINVAL;
6729
6730 return 0;
6731}
6732
6733/**
6734 * wlan_hdd_set_chan_before_pre_cac() - Save the channel before pre cac
6735 * @ap_adapter: AP adapter
6736 * @chan_before_pre_cac: Channel
6737 *
6738 * Saves the channel which the AP was beaconing on before moving to the pre
6739 * cac channel. If radar is detected on the pre cac channel, this saved
6740 * channel will be used for AP operations.
6741 *
6742 * Return: Zero on success, non-zero on failure
6743 */
6744static int wlan_hdd_set_chan_before_pre_cac(hdd_adapter_t *ap_adapter,
6745 uint8_t chan_before_pre_cac)
6746{
6747 QDF_STATUS ret;
6748
6749 ret = wlan_sap_set_chan_before_pre_cac(
6750 WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter), chan_before_pre_cac);
6751 if (QDF_IS_STATUS_ERROR(ret))
6752 return -EINVAL;
6753
6754 return 0;
6755}
6756
6757/**
6758 * wlan_hdd_sap_get_nol() - Get SAPs NOL
6759 * @ap_adapter: AP adapter
6760 * @nol: Non-occupancy list
6761 * @nol_len: Length of NOL
6762 *
6763 * Get the NOL for SAP
6764 *
6765 * Return: Zero on success, non-zero on failure
6766 */
6767static int wlan_hdd_sap_get_nol(hdd_adapter_t *ap_adapter, uint8_t *nol,
6768 uint32_t *nol_len)
6769{
6770 QDF_STATUS ret;
6771
6772 ret = wlansap_get_dfs_nol(WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter),
6773 nol, nol_len);
6774 if (QDF_IS_STATUS_ERROR(ret))
6775 return -EINVAL;
6776
6777 return 0;
6778}
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306779
6780/**
6781 * wlan_hdd_validate_and_get_pre_cac_ch() - Validate and get pre cac channel
6782 * @hdd_ctx: HDD context
6783 * @ap_adapter: AP adapter
6784 * @channel: Channel requested by userspace
6785 * @pre_cac_chan: Pointer to the pre CAC channel
6786 *
6787 * Validates the channel provided by userspace. If user provided channel 0,
6788 * a valid outdoor channel must be selected from the regulatory channel.
6789 *
6790 * Return: Zero on success and non zero value on error
6791 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -07006792static int wlan_hdd_validate_and_get_pre_cac_ch(hdd_context_t *hdd_ctx,
6793 hdd_adapter_t *ap_adapter,
6794 uint8_t channel,
6795 uint8_t *pre_cac_chan)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306796{
6797 uint32_t i, j;
6798 QDF_STATUS status;
6799 int ret;
6800 uint8_t nol[QDF_MAX_NUM_CHAN];
6801 uint32_t nol_len = 0, weight_len = 0;
6802 bool found;
6803 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6804 uint8_t channel_list[QDF_MAX_NUM_CHAN] = {0};
6805 uint8_t pcl_weights[QDF_MAX_NUM_CHAN] = {0};
6806
6807 if (0 == channel) {
6808 /* Channel is not obtained from PCL because PCL may not have
6809 * the entire channel list. For example: if SAP is up on
6810 * channel 6 and PCL is queried for the next SAP interface,
6811 * if SCC is preferred, the PCL will contain only the channel
6812 * 6. But, we are in need of a DFS channel. So, going with the
6813 * first channel from the valid channel list.
6814 */
6815 status = cds_get_valid_chans(channel_list, &len);
6816 if (QDF_IS_STATUS_ERROR(status)) {
6817 hdd_err("Failed to get channel list");
6818 return -EINVAL;
6819 }
6820 cds_update_with_safe_channel_list(channel_list, &len,
6821 pcl_weights, weight_len);
6822 ret = wlan_hdd_sap_get_nol(ap_adapter, nol, &nol_len);
6823 for (i = 0; i < len; i++) {
6824 found = false;
6825 for (j = 0; j < nol_len; j++) {
6826 if (channel_list[i] == nol[j]) {
6827 found = true;
6828 break;
6829 }
6830 }
6831 if (found)
6832 continue;
6833 if (CDS_IS_DFS_CH(channel_list[i])) {
6834 *pre_cac_chan = channel_list[i];
6835 break;
6836 }
6837 }
6838 if (*pre_cac_chan == 0) {
6839 hdd_err("unable to find outdoor channel");
6840 return -EINVAL;
6841 }
6842 } else {
6843 /* Only when driver selects a channel, check is done for
6844 * unnsafe and NOL channels. When user provides a fixed channel
6845 * the user is expected to take care of this.
6846 */
6847 if (!sme_is_channel_valid(hdd_ctx->hHal, channel) ||
6848 !CDS_IS_DFS_CH(channel)) {
6849 hdd_err("Invalid channel for pre cac:%d", channel);
6850 return -EINVAL;
6851 } else {
6852 *pre_cac_chan = channel;
6853 }
6854 }
6855 hdd_info("selected pre cac channel:%d", *pre_cac_chan);
6856 return 0;
6857}
6858
6859/**
6860 * wlan_hdd_request_pre_cac() - Start pre CAC in the driver
6861 * @channel: Channel option provided by userspace
6862 *
6863 * Sets the driver to the required hardware mode and start an adapater for
6864 * pre CAC which will mimic an AP.
6865 *
6866 * Return: Zero on success, non-zero value on error
6867 */
6868int wlan_hdd_request_pre_cac(uint8_t channel)
6869{
Krunal Sonib37bb352016-12-20 14:12:21 -08006870 uint8_t pre_cac_chan = 0, *mac_addr;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306871 hdd_context_t *hdd_ctx;
6872 int ret;
6873 hdd_adapter_t *ap_adapter, *pre_cac_adapter;
6874 hdd_ap_ctx_t *hdd_ap_ctx;
6875 QDF_STATUS status;
6876 struct wiphy *wiphy;
6877 struct net_device *dev;
6878 struct cfg80211_chan_def chandef;
6879 enum nl80211_channel_type channel_type;
6880 uint32_t freq;
6881 struct ieee80211_channel *chan;
6882 tHalHandle handle;
6883 bool val;
6884
6885 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6886 if (0 != wlan_hdd_validate_context(hdd_ctx))
6887 return -EINVAL;
6888
6889 if (cds_get_connection_count() > 1) {
6890 hdd_err("pre cac not allowed in concurrency");
6891 return -EINVAL;
6892 }
6893
6894 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
6895 if (!ap_adapter) {
6896 hdd_err("unable to get SAP adapter");
6897 return -EINVAL;
6898 }
6899
6900 handle = WLAN_HDD_GET_HAL_CTX(ap_adapter);
6901 if (!handle) {
6902 hdd_err("Invalid handle");
6903 return -EINVAL;
6904 }
6905
6906 val = wlan_sap_is_pre_cac_active(handle);
6907 if (val) {
6908 hdd_err("pre cac is already in progress");
6909 return -EINVAL;
6910 }
6911
6912 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
6913 if (!hdd_ap_ctx) {
6914 hdd_err("SAP context is NULL");
6915 return -EINVAL;
6916 }
6917
6918 if (CDS_IS_DFS_CH(hdd_ap_ctx->operatingChannel)) {
6919 hdd_err("SAP is already on DFS channel:%d",
6920 hdd_ap_ctx->operatingChannel);
6921 return -EINVAL;
6922 }
6923
6924 if (!CDS_IS_CHANNEL_24GHZ(hdd_ap_ctx->operatingChannel)) {
6925 hdd_err("pre CAC alllowed only when SAP is in 2.4GHz:%d",
6926 hdd_ap_ctx->operatingChannel);
6927 return -EINVAL;
6928 }
6929
Krunal Sonib37bb352016-12-20 14:12:21 -08006930 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx);
6931 if (!mac_addr) {
6932 hdd_err("can't add virtual intf: Not getting valid mac addr");
6933 return -EINVAL;
6934 }
6935
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306936 hdd_info("channel:%d", channel);
6937
6938 ret = wlan_hdd_validate_and_get_pre_cac_ch(hdd_ctx, ap_adapter, channel,
6939 &pre_cac_chan);
Krunal Sonib37bb352016-12-20 14:12:21 -08006940 if (ret != 0) {
6941 hdd_err("can't validate pre-cac channel");
6942 goto release_intf_addr_and_return_failure;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306943 }
6944
6945 hdd_debug("starting pre cac SAP adapter");
6946
6947 /* Starting a SAP adapter:
6948 * Instead of opening an adapter, we could just do a SME open session
6949 * for AP type. But, start BSS would still need an adapter.
6950 * So, this option is not taken.
6951 *
6952 * hdd open adapter is going to register this precac interface with
6953 * user space. This interface though exposed to user space will be in
6954 * DOWN state. Consideration was done to avoid this registration to the
6955 * user space. But, as part of SAP operations multiple events are sent
6956 * to user space. Some of these events received from unregistered
6957 * interface was causing crashes. So, retaining the registration.
6958 *
6959 * So, this interface would remain registered and will remain in DOWN
6960 * state for the CAC duration. We will add notes in the feature
6961 * announcement to not use this temporary interface for any activity
6962 * from user space.
6963 */
6964 pre_cac_adapter = hdd_open_adapter(hdd_ctx, QDF_SAP_MODE, "precac%d",
Krunal Sonib37bb352016-12-20 14:12:21 -08006965 mac_addr, NET_NAME_UNKNOWN, true);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306966 if (!pre_cac_adapter) {
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05306967 hdd_err("error opening the pre cac adapter");
Krunal Sonib37bb352016-12-20 14:12:21 -08006968 goto release_intf_addr_and_return_failure;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306969 }
6970
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05306971 /*
6972 * This interface is internally created by the driver. So, no interface
6973 * up comes for this interface from user space and hence starting
6974 * the adapter internally.
6975 */
6976 if (hdd_start_adapter(pre_cac_adapter)) {
6977 hdd_err("error starting the pre cac adapter");
6978 goto close_pre_cac_adapter;
6979 }
6980
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306981 hdd_debug("preparing for start ap/bss on the pre cac adapter");
6982
6983 wiphy = hdd_ctx->wiphy;
6984 dev = pre_cac_adapter->dev;
6985
6986 /* Since this is only a dummy interface lets us use the IEs from the
6987 * other active SAP interface. In regular scenarios, these IEs would
6988 * come from the user space entity
6989 */
6990 pre_cac_adapter->sessionCtx.ap.beacon = qdf_mem_malloc(
6991 sizeof(*ap_adapter->sessionCtx.ap.beacon));
6992 if (!pre_cac_adapter->sessionCtx.ap.beacon) {
6993 hdd_err("failed to alloc mem for beacon");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05306994 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05306995 }
6996 qdf_mem_copy(pre_cac_adapter->sessionCtx.ap.beacon,
6997 ap_adapter->sessionCtx.ap.beacon,
6998 sizeof(*pre_cac_adapter->sessionCtx.ap.beacon));
6999 pre_cac_adapter->sessionCtx.ap.sapConfig.ch_width_orig =
7000 ap_adapter->sessionCtx.ap.sapConfig.ch_width_orig;
7001 pre_cac_adapter->sessionCtx.ap.sapConfig.authType =
7002 ap_adapter->sessionCtx.ap.sapConfig.authType;
7003
7004 /* Premise is that on moving from 2.4GHz to 5GHz, the SAP will continue
7005 * to operate on the same bandwidth as that of the 2.4GHz operations.
7006 * Only bandwidths 20MHz/40MHz are possible on 2.4GHz band.
7007 */
7008 switch (ap_adapter->sessionCtx.ap.sapConfig.ch_width_orig) {
7009 case CH_WIDTH_20MHZ:
7010 channel_type = NL80211_CHAN_HT20;
7011 break;
7012 case CH_WIDTH_40MHZ:
7013 if (ap_adapter->sessionCtx.ap.sapConfig.sec_ch >
7014 ap_adapter->sessionCtx.ap.sapConfig.channel)
7015 channel_type = NL80211_CHAN_HT40PLUS;
7016 else
7017 channel_type = NL80211_CHAN_HT40MINUS;
7018 break;
7019 default:
7020 channel_type = NL80211_CHAN_NO_HT;
7021 break;
7022 }
7023
7024 freq = cds_chan_to_freq(pre_cac_chan);
7025 chan = __ieee80211_get_channel(wiphy, freq);
7026 if (!chan) {
7027 hdd_err("channel converion failed");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307028 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307029 }
7030
7031 cfg80211_chandef_create(&chandef, chan, channel_type);
7032
7033 hdd_debug("orig width:%d channel_type:%d freq:%d",
7034 ap_adapter->sessionCtx.ap.sapConfig.ch_width_orig,
7035 channel_type, freq);
Krunal Sonib37bb352016-12-20 14:12:21 -08007036 /*
7037 * Doing update after opening and starting pre-cac adapter will make
7038 * sure that driver won't do hardware mode change if there are any
7039 * initial hick-ups or issues in pre-cac adapter's configuration.
7040 * Since current SAP is in 2.4GHz and pre CAC channel is in 5GHz, this
7041 * connection update should result in DBS mode
7042 */
7043 status = cds_update_and_wait_for_connection_update(
7044 ap_adapter->sessionId,
7045 pre_cac_chan,
7046 SIR_UPDATE_REASON_PRE_CAC);
7047 if (QDF_IS_STATUS_ERROR(status)) {
7048 hdd_err("error in moving to DBS mode");
7049 goto stop_close_pre_cac_adapter;
7050 }
7051
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307052
7053 ret = wlan_hdd_set_channel(wiphy, dev, &chandef, channel_type);
7054 if (0 != ret) {
7055 hdd_err("failed to set channel");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307056 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307057 }
7058
7059 status = wlan_hdd_cfg80211_start_bss(pre_cac_adapter, NULL,
7060 PRE_CAC_SSID, qdf_str_len(PRE_CAC_SSID),
Archana Ramachandran1a5b6042016-11-08 16:36:50 -08007061 eHIDDEN_SSID_NOT_IN_USE, false, false);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307062 if (QDF_IS_STATUS_ERROR(status)) {
7063 hdd_err("start bss failed");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307064 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307065 }
7066
7067 /*
7068 * The pre cac status is set here. But, it would not be reset explicitly
7069 * anywhere, since after the pre cac success/failure, the pre cac
7070 * adapter itself would be removed.
7071 */
7072 ret = wlan_hdd_set_pre_cac_status(pre_cac_adapter, true, handle);
7073 if (0 != ret) {
7074 hdd_err("failed to set pre cac status");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307075 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307076 }
7077
7078 ret = wlan_hdd_set_chan_before_pre_cac(ap_adapter,
7079 hdd_ap_ctx->operatingChannel);
7080 if (0 != ret) {
7081 hdd_err("failed to set channel before pre cac");
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307082 goto stop_close_pre_cac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307083 }
7084
7085 ap_adapter->pre_cac_chan = pre_cac_chan;
7086
7087 return 0;
7088
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307089stop_close_pre_cac_adapter:
7090 hdd_stop_adapter(hdd_ctx, pre_cac_adapter, true);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307091 qdf_mem_free(pre_cac_adapter->sessionCtx.ap.beacon);
7092 pre_cac_adapter->sessionCtx.ap.beacon = NULL;
Manishekar Chandrasekarandfdf2a82016-08-24 16:16:16 +05307093close_pre_cac_adapter:
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307094 hdd_close_adapter(hdd_ctx, pre_cac_adapter, false);
Krunal Sonib37bb352016-12-20 14:12:21 -08007095release_intf_addr_and_return_failure:
7096 /*
7097 * Release the interface address as the adapter
7098 * failed to start, if you don't release then next
7099 * adapter which is trying to come wouldn't get valid
7100 * mac address. Remember we have limited pool of mac addresses
7101 */
7102 wlan_hdd_release_intf_addr(hdd_ctx, mac_addr);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05307103 return -EINVAL;
7104}
7105
Arun Khandavalli2476ef52016-04-26 20:19:43 +05307106/**
7107 * hdd_init_bpf_completion() - Initialize the completion event for bpf
7108 *
7109 * Return: None
7110 */
7111void hdd_init_bpf_completion(void)
7112{
7113 init_completion(&bpf_context.completion);
7114}
7115
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307116static const struct nla_policy
7117wlan_hdd_sap_config_policy[QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_MAX + 1] = {
7118 [QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHANNEL] = {.type = NLA_U8 },
7119};
7120
Agrawal Ashish65634612016-08-18 13:24:32 +05307121static const struct nla_policy
7122wlan_hdd_set_acs_dfs_config_policy[QCA_WLAN_VENDOR_ATTR_ACS_DFS_MAX + 1] = {
7123 [QCA_WLAN_VENDOR_ATTR_ACS_DFS_MODE] = {.type = NLA_U8 },
7124 [QCA_WLAN_VENDOR_ATTR_ACS_CHANNEL_HINT] = {.type = NLA_U8 },
7125};
7126
7127/**
7128 * __wlan_hdd_cfg80211_acs_dfs_mode() - set ACS DFS mode and channel
7129 * @wiphy: Pointer to wireless phy
7130 * @wdev: Pointer to wireless device
7131 * @data: Pointer to data
7132 * @data_len: Length of @data
7133 *
7134 * This function parses the incoming NL vendor command data attributes and
7135 * updates the SAP context about channel_hint and DFS mode.
7136 * If channel_hint is set, SAP will choose that channel
7137 * as operating channel.
7138 *
7139 * If DFS mode is enabled, driver will include DFS channels
7140 * in ACS else driver will skip DFS channels.
7141 *
7142 * Return: 0 on success, negative errno on failure
7143 */
7144static int
7145__wlan_hdd_cfg80211_acs_dfs_mode(struct wiphy *wiphy,
7146 struct wireless_dev *wdev,
7147 const void *data, int data_len)
7148{
7149 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7150 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ACS_DFS_MAX + 1];
7151 int ret;
7152 struct acs_dfs_policy *acs_policy;
7153 int mode = DFS_MODE_NONE;
7154 int channel_hint = 0;
7155
7156 ENTER_DEV(wdev->netdev);
7157
7158 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7159 hdd_err("Command not allowed in FTM mode");
7160 return -EINVAL;
7161 }
7162
7163 ret = wlan_hdd_validate_context(hdd_ctx);
7164 if (0 != ret)
7165 return ret;
7166
7167 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ACS_DFS_MAX,
7168 data, data_len,
7169 wlan_hdd_set_acs_dfs_config_policy)) {
7170 hdd_err("invalid attr");
7171 return -EINVAL;
7172 }
7173
7174 acs_policy = &hdd_ctx->acs_policy;
7175 /*
7176 * SCM sends this attribute to restrict SAP from choosing
7177 * DFS channels from ACS.
7178 */
7179 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_DFS_MODE])
7180 mode = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_ACS_DFS_MODE]);
7181
7182 if (!IS_DFS_MODE_VALID(mode)) {
7183 hdd_err("attr acs dfs mode is not valid");
7184 return -EINVAL;
7185 }
7186 acs_policy->acs_dfs_mode = mode;
7187
7188 /*
7189 * SCM sends this attribute to provide an active channel,
7190 * to skip redundant ACS between drivers, and save driver start up time
7191 */
7192 if (tb[QCA_WLAN_VENDOR_ATTR_ACS_CHANNEL_HINT])
7193 channel_hint = nla_get_u8(
7194 tb[QCA_WLAN_VENDOR_ATTR_ACS_CHANNEL_HINT]);
7195
7196 if (!IS_CHANNEL_VALID(channel_hint)) {
7197 hdd_err("acs channel is not valid");
7198 return -EINVAL;
7199 }
7200 acs_policy->acs_channel = channel_hint;
7201
7202 return 0;
7203}
7204
7205/**
7206 * wlan_hdd_cfg80211_acs_dfs_mode() - Wrapper to set ACS DFS mode
7207 * @wiphy: wiphy structure pointer
7208 * @wdev: Wireless device structure pointer
7209 * @data: Pointer to the data received
7210 * @data_len: Length of @data
7211 *
7212 * This function parses the incoming NL vendor command data attributes and
7213 * updates the SAP context about channel_hint and DFS mode.
7214 *
7215 * Return: 0 on success; errno on failure
7216 */
7217static int wlan_hdd_cfg80211_acs_dfs_mode(struct wiphy *wiphy,
7218 struct wireless_dev *wdev,
7219 const void *data, int data_len)
7220{
7221 int ret;
7222
7223 cds_ssr_protect(__func__);
7224 ret = __wlan_hdd_cfg80211_acs_dfs_mode(wiphy, wdev, data, data_len);
7225 cds_ssr_unprotect(__func__);
7226
7227 return ret;
7228}
7229
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307230/**
Agrawal Ashish21ba2572016-09-03 16:40:10 +05307231 * wlan_hdd_get_sta_roam_dfs_mode() - get sta roam dfs mode policy
7232 * @mode : cfg80211 dfs mode
7233 *
7234 * Return: return csr sta roam dfs mode else return NONE
7235 */
7236static enum sta_roam_policy_dfs_mode wlan_hdd_get_sta_roam_dfs_mode(
7237 enum dfs_mode mode)
7238{
7239 switch (mode) {
7240 case DFS_MODE_ENABLE:
7241 return CSR_STA_ROAM_POLICY_DFS_ENABLED;
7242 break;
7243 case DFS_MODE_DISABLE:
7244 return CSR_STA_ROAM_POLICY_DFS_DISABLED;
7245 break;
7246 case DFS_MODE_DEPRIORITIZE:
7247 return CSR_STA_ROAM_POLICY_DFS_DEPRIORITIZE;
7248 break;
7249 default:
7250 hdd_err("STA Roam policy dfs mode is NONE");
7251 return CSR_STA_ROAM_POLICY_NONE;
7252 }
7253}
7254
Agrawal, Ashish9f84c402016-11-30 16:19:44 +05307255/*
7256 * hdd_get_sap_operating_band: Get current operating channel
7257 * for sap.
7258 * @hdd_ctx: hdd context
7259 *
7260 * Return : Corresponding band for SAP operating channel
7261 */
7262uint8_t hdd_get_sap_operating_band(hdd_context_t *hdd_ctx)
7263{
7264 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
7265 QDF_STATUS status;
7266 hdd_adapter_t *adapter;
7267 uint8_t operating_channel = 0;
7268 uint8_t sap_operating_band = 0;
7269 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
7270 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
7271 adapter = adapter_node->pAdapter;
7272
7273 if (!(adapter && (QDF_SAP_MODE == adapter->device_mode))) {
7274 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
7275 &next);
7276 adapter_node = next;
7277 continue;
7278 }
7279 operating_channel = adapter->sessionCtx.ap.operatingChannel;
7280 if (IS_24G_CH(operating_channel))
7281 sap_operating_band = eCSR_BAND_24;
7282 else if (IS_5G_CH(operating_channel))
7283 sap_operating_band = eCSR_BAND_5G;
7284 else
7285 sap_operating_band = eCSR_BAND_ALL;
7286 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
7287 &next);
bings373b99b2017-01-23 10:35:08 +08007288 adapter_node = next;
Agrawal, Ashish9f84c402016-11-30 16:19:44 +05307289 }
7290 return sap_operating_band;
7291}
7292
Agrawal Ashish21ba2572016-09-03 16:40:10 +05307293static const struct nla_policy
7294wlan_hdd_set_sta_roam_config_policy[
7295QCA_WLAN_VENDOR_ATTR_STA_CONNECT_ROAM_POLICY_MAX + 1] = {
7296 [QCA_WLAN_VENDOR_ATTR_STA_DFS_MODE] = {.type = NLA_U8 },
7297 [QCA_WLAN_VENDOR_ATTR_STA_SKIP_UNSAFE_CHANNEL] = {.type = NLA_U8 },
7298};
7299
7300/**
7301 * __wlan_hdd_cfg80211_sta_roam_policy() - Set params to restrict scan channels
7302 * for station connection or roaming.
7303 * @wiphy: Pointer to wireless phy
7304 * @wdev: Pointer to wireless device
7305 * @data: Pointer to data
7306 * @data_len: Length of @data
7307 *
7308 * __wlan_hdd_cfg80211_sta_roam_policy will decide if DFS channels or unsafe
7309 * channels needs to be skipped in scanning or not.
7310 * If dfs_mode is disabled, driver will not scan DFS channels.
7311 * If skip_unsafe_channels is set, driver will skip unsafe channels
7312 * in Scanning.
7313 *
7314 * Return: 0 on success, negative errno on failure
7315 */
7316static int
7317__wlan_hdd_cfg80211_sta_roam_policy(struct wiphy *wiphy,
7318 struct wireless_dev *wdev,
7319 const void *data, int data_len)
7320{
7321 struct net_device *dev = wdev->netdev;
7322 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
7323 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7324 struct nlattr *tb[
7325 QCA_WLAN_VENDOR_ATTR_STA_CONNECT_ROAM_POLICY_MAX + 1];
7326 int ret;
7327 enum sta_roam_policy_dfs_mode sta_roam_dfs_mode;
7328 enum dfs_mode mode = DFS_MODE_NONE;
7329 bool skip_unsafe_channels = false;
7330 QDF_STATUS status;
Agrawal, Ashish9f84c402016-11-30 16:19:44 +05307331 uint8_t sap_operating_band;
Agrawal Ashish21ba2572016-09-03 16:40:10 +05307332
7333 ENTER_DEV(dev);
7334
7335 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7336 hdd_err("Command not allowed in FTM mode");
7337 return -EINVAL;
7338 }
7339
7340 ret = wlan_hdd_validate_context(hdd_ctx);
7341 if (0 != ret)
7342 return ret;
7343 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_STA_CONNECT_ROAM_POLICY_MAX,
7344 data, data_len,
7345 wlan_hdd_set_sta_roam_config_policy)) {
7346 hdd_err("invalid attr");
7347 return -EINVAL;
7348 }
7349 if (tb[QCA_WLAN_VENDOR_ATTR_STA_DFS_MODE])
7350 mode = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_STA_DFS_MODE]);
7351 if (!IS_DFS_MODE_VALID(mode)) {
7352 hdd_err("attr sta roam dfs mode policy is not valid");
7353 return -EINVAL;
7354 }
7355
7356 sta_roam_dfs_mode = wlan_hdd_get_sta_roam_dfs_mode(mode);
7357
7358 if (tb[QCA_WLAN_VENDOR_ATTR_STA_SKIP_UNSAFE_CHANNEL])
7359 skip_unsafe_channels = nla_get_u8(
7360 tb[QCA_WLAN_VENDOR_ATTR_STA_SKIP_UNSAFE_CHANNEL]);
Agrawal, Ashish9f84c402016-11-30 16:19:44 +05307361 sap_operating_band = hdd_get_sap_operating_band(hdd_ctx);
Agrawal Ashish21ba2572016-09-03 16:40:10 +05307362 status = sme_update_sta_roam_policy(hdd_ctx->hHal, sta_roam_dfs_mode,
Agrawal, Ashish9f84c402016-11-30 16:19:44 +05307363 skip_unsafe_channels, adapter->sessionId,
7364 sap_operating_band);
Agrawal Ashish21ba2572016-09-03 16:40:10 +05307365
7366 if (!QDF_IS_STATUS_SUCCESS(status)) {
7367 hdd_err("sme_update_sta_roam_policy (err=%d)", status);
7368 return -EINVAL;
7369 }
7370 return 0;
7371}
7372
7373/**
7374 * wlan_hdd_cfg80211_sta_roam_policy() - Wrapper to restrict scan channels,
7375 * connection and roaming for station.
7376 * @wiphy: wiphy structure pointer
7377 * @wdev: Wireless device structure pointer
7378 * @data: Pointer to the data received
7379 * @data_len: Length of @data
7380 *
7381 * __wlan_hdd_cfg80211_sta_roam_policy will decide if DFS channels or unsafe
7382 * channels needs to be skipped in scanning or not.
7383 * If dfs_mode is disabled, driver will not scan DFS channels.
7384 * If skip_unsafe_channels is set, driver will skip unsafe channels
7385 * in Scanning.
7386 * Return: 0 on success; errno on failure
7387 */
7388static int wlan_hdd_cfg80211_sta_roam_policy(struct wiphy *wiphy,
7389 struct wireless_dev *wdev,
7390 const void *data, int data_len)
7391{
7392 int ret;
7393
7394 cds_ssr_protect(__func__);
7395 ret = __wlan_hdd_cfg80211_sta_roam_policy(wiphy, wdev, data, data_len);
7396 cds_ssr_unprotect(__func__);
7397
7398 return ret;
7399}
7400
Agrawal Ashish467dde42016-09-08 18:44:22 +05307401#ifdef FEATURE_WLAN_CH_AVOID
7402/**
7403 * __wlan_hdd_cfg80211_avoid_freq() - ask driver to restart SAP if SAP
7404 * is on unsafe channel.
7405 * @wiphy: wiphy structure pointer
7406 * @wdev: Wireless device structure pointer
7407 * @data: Pointer to the data received
7408 * @data_len: Length of @data
7409 *
7410 * wlan_hdd_cfg80211_avoid_freq do restart the sap if sap is already
7411 * on any of unsafe channels.
7412 * If sap is on any of unsafe channel, hdd_unsafe_channel_restart_sap
7413 * will send WLAN_SVC_LTE_COEX_IND indication to userspace to restart.
7414 *
7415 * Return: 0 on success; errno on failure
7416 */
7417static int
7418__wlan_hdd_cfg80211_avoid_freq(struct wiphy *wiphy,
7419 struct wireless_dev *wdev,
7420 const void *data, int data_len)
7421{
7422 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7423 int ret;
7424 uint16_t unsafe_channel_count;
7425 int unsafe_channel_index;
7426 qdf_device_t qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
7427
7428 ENTER_DEV(wdev->netdev);
7429
7430 if (!qdf_ctx) {
7431 cds_err("qdf_ctx is NULL");
7432 return -EINVAL;
7433 }
7434
7435 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7436 hdd_err("Command not allowed in FTM mode");
7437 return -EINVAL;
7438 }
7439
7440 ret = wlan_hdd_validate_context(hdd_ctx);
7441 if (0 != ret)
7442 return ret;
7443 pld_get_wlan_unsafe_channel(qdf_ctx->dev, hdd_ctx->unsafe_channel_list,
7444 &(hdd_ctx->unsafe_channel_count),
7445 sizeof(hdd_ctx->unsafe_channel_list));
7446
7447 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
7448 (uint16_t)NUM_CHANNELS);
7449 for (unsafe_channel_index = 0;
7450 unsafe_channel_index < unsafe_channel_count;
7451 unsafe_channel_index++) {
7452 hdd_info("Channel %d is not safe",
7453 hdd_ctx->unsafe_channel_list[unsafe_channel_index]);
7454 }
7455 hdd_unsafe_channel_restart_sap(hdd_ctx);
7456 return 0;
7457}
7458
7459/**
7460 * wlan_hdd_cfg80211_avoid_freq() - ask driver to restart SAP if SAP
7461 * is on unsafe channel.
7462 * @wiphy: wiphy structure pointer
7463 * @wdev: Wireless device structure pointer
7464 * @data: Pointer to the data received
7465 * @data_len: Length of @data
7466 *
7467 * wlan_hdd_cfg80211_avoid_freq do restart the sap if sap is already
7468 * on any of unsafe channels.
7469 * If sap is on any of unsafe channel, hdd_unsafe_channel_restart_sap
7470 * will send WLAN_SVC_LTE_COEX_IND indication to userspace to restart.
7471 *
7472 * Return: 0 on success; errno on failure
7473 */
7474static int wlan_hdd_cfg80211_avoid_freq(struct wiphy *wiphy,
7475 struct wireless_dev *wdev,
7476 const void *data, int data_len)
7477{
7478 int ret;
7479
7480 cds_ssr_protect(__func__);
7481 ret = __wlan_hdd_cfg80211_avoid_freq(wiphy, wdev, data, data_len);
7482 cds_ssr_unprotect(__func__);
7483
7484 return ret;
7485}
7486
7487#endif
Agrawal Ashish21ba2572016-09-03 16:40:10 +05307488/**
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307489 * __wlan_hdd_cfg80211_sap_configuration_set() - ask driver to restart SAP if
7490 * SAP is on unsafe channel.
7491 * @wiphy: wiphy structure pointer
7492 * @wdev: Wireless device structure pointer
7493 * @data: Pointer to the data received
7494 * @data_len: Length of @data
7495 *
7496 * __wlan_hdd_cfg80211_sap_configuration_set function set SAP params to
7497 * driver.
7498 * QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHAN will set sap config channel and
7499 * will initiate restart of sap.
7500 *
7501 * Return: 0 on success; errno on failure
7502 */
7503static int
7504__wlan_hdd_cfg80211_sap_configuration_set(struct wiphy *wiphy,
7505 struct wireless_dev *wdev,
7506 const void *data, int data_len)
7507{
7508 struct net_device *ndev = wdev->netdev;
7509 hdd_adapter_t *hostapd_adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
7510 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7511 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_MAX + 1];
7512 uint8_t config_channel = 0;
7513 hdd_ap_ctx_t *ap_ctx;
7514 int ret;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05307515 QDF_STATUS status;
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307516
7517 ENTER();
7518
7519 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson77848112016-06-29 14:52:06 -07007520 hdd_err("Command not allowed in FTM mode");
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307521 return -EINVAL;
7522 }
7523
7524 ret = wlan_hdd_validate_context(hdd_ctx);
7525 if (0 != ret)
7526 return -EINVAL;
7527
7528 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_MAX,
7529 data, data_len,
7530 wlan_hdd_sap_config_policy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07007531 hdd_err("invalid attr");
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307532 return -EINVAL;
7533 }
7534
7535 if (tb[QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHANNEL]) {
7536 if (!test_bit(SOFTAP_BSS_STARTED,
7537 &hostapd_adapter->event_flags)) {
7538 hdd_err("SAP is not started yet. Restart sap will be invalid");
7539 return -EINVAL;
7540 }
7541
7542 config_channel =
7543 nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHANNEL]);
7544
7545 if (!((IS_24G_CH(config_channel)) ||
7546 (IS_5G_CH(config_channel)))) {
7547 hdd_err("Channel %d is not valid to restart SAP",
7548 config_channel);
7549 return -ENOTSUPP;
7550 }
7551
7552 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(hostapd_adapter);
7553 ap_ctx->sapConfig.channel = config_channel;
7554 ap_ctx->sapConfig.ch_params.ch_width =
7555 ap_ctx->sapConfig.ch_width_orig;
7556
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -07007557 cds_set_channel_params(ap_ctx->sapConfig.channel,
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307558 ap_ctx->sapConfig.sec_ch,
7559 &ap_ctx->sapConfig.ch_params);
7560
7561 cds_restart_sap(hostapd_adapter);
7562 }
7563
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05307564 if (tb[QCA_WLAN_VENDOR_ATTR_SAP_MANDATORY_FREQUENCY_LIST]) {
7565 uint32_t freq_len, i;
7566 uint32_t *freq;
7567 uint8_t chans[QDF_MAX_NUM_CHAN];
7568
7569 hdd_debug("setting mandatory freq/chan list");
7570
7571 freq_len = nla_len(
7572 tb[QCA_WLAN_VENDOR_ATTR_SAP_MANDATORY_FREQUENCY_LIST])/
7573 sizeof(uint32_t);
7574
7575 if (freq_len > QDF_MAX_NUM_CHAN) {
7576 hdd_err("insufficient space to hold channels");
7577 return -ENOMEM;
7578 }
7579
7580 freq = nla_data(
7581 tb[QCA_WLAN_VENDOR_ATTR_SAP_MANDATORY_FREQUENCY_LIST]);
7582
7583 hdd_debug("freq_len=%d", freq_len);
7584
7585 for (i = 0; i < freq_len; i++) {
7586 chans[i] = ieee80211_frequency_to_channel(freq[i]);
7587 hdd_debug("freq[%d]=%d", i, freq[i]);
7588 }
7589
7590 status = cds_set_sap_mandatory_channels(chans, freq_len);
7591 if (QDF_IS_STATUS_ERROR(status))
7592 return -EINVAL;
7593 }
7594
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05307595 return 0;
7596}
7597
7598/**
7599 * wlan_hdd_cfg80211_sap_configuration_set() - sap configuration vendor command
7600 * @wiphy: wiphy structure pointer
7601 * @wdev: Wireless device structure pointer
7602 * @data: Pointer to the data received
7603 * @data_len: Length of @data
7604 *
7605 * __wlan_hdd_cfg80211_sap_configuration_set function set SAP params to
7606 * driver.
7607 * QCA_WLAN_VENDOR_ATTR_SAP_CONFIG_CHAN will set sap config channel and
7608 * will initiate restart of sap.
7609 *
7610 * Return: 0 on success; errno on failure
7611 */
7612static int wlan_hdd_cfg80211_sap_configuration_set(struct wiphy *wiphy,
7613 struct wireless_dev *wdev,
7614 const void *data, int data_len)
7615{
7616 int ret;
7617
7618 cds_ssr_protect(__func__);
7619 ret = __wlan_hdd_cfg80211_sap_configuration_set(wiphy,
7620 wdev, data, data_len);
7621 cds_ssr_unprotect(__func__);
7622
7623 return ret;
7624}
7625
Arun Khandavalli2476ef52016-04-26 20:19:43 +05307626#undef BPF_INVALID
7627#undef BPF_SET_RESET
7628#undef BPF_VERSION
7629#undef BPF_ID
7630#undef BPF_PACKET_SIZE
7631#undef BPF_CURRENT_OFFSET
7632#undef BPF_PROGRAM
7633#undef BPF_MAX
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307634
7635/**
7636 * define short names for the global vendor params
7637 * used by wlan_hdd_cfg80211_wakelock_stats_rsp_callback()
7638 */
7639#define PARAM_TOTAL_CMD_EVENT_WAKE \
7640 QCA_WLAN_VENDOR_ATTR_TOTAL_CMD_EVENT_WAKE
7641#define PARAM_CMD_EVENT_WAKE_CNT_PTR \
7642 QCA_WLAN_VENDOR_ATTR_CMD_EVENT_WAKE_CNT_PTR
7643#define PARAM_CMD_EVENT_WAKE_CNT_SZ \
7644 QCA_WLAN_VENDOR_ATTR_CMD_EVENT_WAKE_CNT_SZ
7645#define PARAM_TOTAL_DRIVER_FW_LOCAL_WAKE \
7646 QCA_WLAN_VENDOR_ATTR_TOTAL_DRIVER_FW_LOCAL_WAKE
7647#define PARAM_DRIVER_FW_LOCAL_WAKE_CNT_PTR \
7648 QCA_WLAN_VENDOR_ATTR_DRIVER_FW_LOCAL_WAKE_CNT_PTR
7649#define PARAM_DRIVER_FW_LOCAL_WAKE_CNT_SZ \
7650 QCA_WLAN_VENDOR_ATTR_DRIVER_FW_LOCAL_WAKE_CNT_SZ
7651#define PARAM_TOTAL_RX_DATA_WAKE \
7652 QCA_WLAN_VENDOR_ATTR_TOTAL_RX_DATA_WAKE
7653#define PARAM_RX_UNICAST_CNT \
7654 QCA_WLAN_VENDOR_ATTR_RX_UNICAST_CNT
7655#define PARAM_RX_MULTICAST_CNT \
7656 QCA_WLAN_VENDOR_ATTR_RX_MULTICAST_CNT
7657#define PARAM_RX_BROADCAST_CNT \
7658 QCA_WLAN_VENDOR_ATTR_RX_BROADCAST_CNT
7659#define PARAM_ICMP_PKT \
7660 QCA_WLAN_VENDOR_ATTR_ICMP_PKT
7661#define PARAM_ICMP6_PKT \
7662 QCA_WLAN_VENDOR_ATTR_ICMP6_PKT
7663#define PARAM_ICMP6_RA \
7664 QCA_WLAN_VENDOR_ATTR_ICMP6_RA
7665#define PARAM_ICMP6_NA \
7666 QCA_WLAN_VENDOR_ATTR_ICMP6_NA
7667#define PARAM_ICMP6_NS \
7668 QCA_WLAN_VENDOR_ATTR_ICMP6_NS
7669#define PARAM_ICMP4_RX_MULTICAST_CNT \
7670 QCA_WLAN_VENDOR_ATTR_ICMP4_RX_MULTICAST_CNT
7671#define PARAM_ICMP6_RX_MULTICAST_CNT \
7672 QCA_WLAN_VENDOR_ATTR_ICMP6_RX_MULTICAST_CNT
7673#define PARAM_OTHER_RX_MULTICAST_CNT \
7674 QCA_WLAN_VENDOR_ATTR_OTHER_RX_MULTICAST_CNT
Poddar, Siddarthc01681a2016-12-21 18:36:30 +05307675#define PARAM_RSSI_BREACH_CNT \
7676 QCA_WLAN_VENDOR_ATTR_RSSI_BREACH_CNT
7677#define PARAM_LOW_RSSI_CNT \
7678 QCA_WLAN_VENDOR_ATTR_LOW_RSSI_CNT
7679#define PARAM_GSCAN_CNT \
7680 QCA_WLAN_VENDOR_ATTR_GSCAN_CNT
7681#define PARAM_PNO_COMPLETE_CNT \
7682 QCA_WLAN_VENDOR_ATTR_PNO_COMPLETE_CNT
7683#define PARAM_PNO_MATCH_CNT \
7684 QCA_WLAN_VENDOR_ATTR_PNO_MATCH_CNT
7685
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307686
7687
7688/**
7689 * hdd_send_wakelock_stats() - API to send wakelock stats
7690 * @ctx: context to be passed to callback
7691 * @data: data passed to callback
7692 *
7693 * This function is used to send wake lock stats to HAL layer
7694 *
7695 * Return: 0 on success, error number otherwise.
7696 */
7697static uint32_t hdd_send_wakelock_stats(hdd_context_t *hdd_ctx,
7698 const struct sir_wake_lock_stats *data)
7699{
7700 struct sk_buff *skb;
7701 uint32_t nl_buf_len;
7702 uint32_t total_rx_data_wake, rx_multicast_cnt;
7703 uint32_t ipv6_rx_multicast_addr_cnt;
Sreelakshmi Konamkie1cd51f2016-08-19 16:58:24 +05307704 uint32_t icmpv6_cnt;
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307705
7706 ENTER();
7707
7708 nl_buf_len = NLMSG_HDRLEN;
7709 nl_buf_len +=
7710 QCA_WLAN_VENDOR_GET_WAKE_STATS_MAX *
7711 (NLMSG_HDRLEN + sizeof(uint32_t));
7712
7713 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
7714
7715 if (!skb) {
Jeff Johnson64943bd2016-08-23 13:14:06 -07007716 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307717 return -ENOMEM;
7718 }
7719
Jeff Johnson64943bd2016-08-23 13:14:06 -07007720 hdd_info("wow_ucast_wake_up_count %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307721 data->wow_ucast_wake_up_count);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007722 hdd_info("wow_bcast_wake_up_count %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307723 data->wow_bcast_wake_up_count);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007724 hdd_info("wow_ipv4_mcast_wake_up_count %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307725 data->wow_ipv4_mcast_wake_up_count);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007726 hdd_info("wow_ipv6_mcast_wake_up_count %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307727 data->wow_ipv6_mcast_wake_up_count);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007728 hdd_info("wow_ipv6_mcast_ra_stats %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307729 data->wow_ipv6_mcast_ra_stats);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007730 hdd_info("wow_ipv6_mcast_ns_stats %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307731 data->wow_ipv6_mcast_ns_stats);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007732 hdd_info("wow_ipv6_mcast_na_stats %d",
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307733 data->wow_ipv6_mcast_na_stats);
Jeff Johnson64943bd2016-08-23 13:14:06 -07007734 hdd_info("wow_icmpv4_count %d", data->wow_icmpv4_count);
7735 hdd_info("wow_icmpv6_count %d",
Himanshu Agarwal4574e282016-08-10 15:22:45 +05307736 data->wow_icmpv6_count);
Poddar, Siddarthc01681a2016-12-21 18:36:30 +05307737 hdd_info("wow_rssi_breach_wake_up_count %d",
7738 data->wow_rssi_breach_wake_up_count);
7739 hdd_info("wow_low_rssi_wake_up_count %d",
7740 data->wow_low_rssi_wake_up_count);
7741 hdd_info("wow_gscan_wake_up_count %d",
7742 data->wow_gscan_wake_up_count);
7743 hdd_info("wow_pno_complete_wake_up_count %d",
7744 data->wow_pno_complete_wake_up_count);
7745 hdd_info("wow_pno_match_wake_up_count %d",
7746 data->wow_pno_match_wake_up_count);
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307747
7748 ipv6_rx_multicast_addr_cnt =
Himanshu Agarwal4574e282016-08-10 15:22:45 +05307749 data->wow_ipv6_mcast_wake_up_count;
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307750
Sreelakshmi Konamkie1cd51f2016-08-19 16:58:24 +05307751 icmpv6_cnt =
Himanshu Agarwal4574e282016-08-10 15:22:45 +05307752 data->wow_icmpv6_count;
Sreelakshmi Konamkie1cd51f2016-08-19 16:58:24 +05307753
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307754 rx_multicast_cnt =
7755 data->wow_ipv4_mcast_wake_up_count +
7756 ipv6_rx_multicast_addr_cnt;
7757
7758 total_rx_data_wake =
7759 data->wow_ucast_wake_up_count +
7760 data->wow_bcast_wake_up_count +
7761 rx_multicast_cnt;
7762
7763 if (nla_put_u32(skb, PARAM_TOTAL_CMD_EVENT_WAKE, 0) ||
7764 nla_put_u32(skb, PARAM_CMD_EVENT_WAKE_CNT_PTR, 0) ||
7765 nla_put_u32(skb, PARAM_CMD_EVENT_WAKE_CNT_SZ, 0) ||
7766 nla_put_u32(skb, PARAM_TOTAL_DRIVER_FW_LOCAL_WAKE, 0) ||
7767 nla_put_u32(skb, PARAM_DRIVER_FW_LOCAL_WAKE_CNT_PTR, 0) ||
7768 nla_put_u32(skb, PARAM_DRIVER_FW_LOCAL_WAKE_CNT_SZ, 0) ||
7769 nla_put_u32(skb, PARAM_TOTAL_RX_DATA_WAKE,
7770 total_rx_data_wake) ||
7771 nla_put_u32(skb, PARAM_RX_UNICAST_CNT,
7772 data->wow_ucast_wake_up_count) ||
7773 nla_put_u32(skb, PARAM_RX_MULTICAST_CNT,
7774 rx_multicast_cnt) ||
7775 nla_put_u32(skb, PARAM_RX_BROADCAST_CNT,
7776 data->wow_bcast_wake_up_count) ||
Sreelakshmi Konamkie1cd51f2016-08-19 16:58:24 +05307777 nla_put_u32(skb, PARAM_ICMP_PKT,
7778 data->wow_icmpv4_count) ||
7779 nla_put_u32(skb, PARAM_ICMP6_PKT,
7780 icmpv6_cnt) ||
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307781 nla_put_u32(skb, PARAM_ICMP6_RA,
7782 data->wow_ipv6_mcast_ra_stats) ||
7783 nla_put_u32(skb, PARAM_ICMP6_NA,
7784 data->wow_ipv6_mcast_na_stats) ||
7785 nla_put_u32(skb, PARAM_ICMP6_NS,
7786 data->wow_ipv6_mcast_ns_stats) ||
7787 nla_put_u32(skb, PARAM_ICMP4_RX_MULTICAST_CNT,
7788 data->wow_ipv4_mcast_wake_up_count) ||
7789 nla_put_u32(skb, PARAM_ICMP6_RX_MULTICAST_CNT,
7790 ipv6_rx_multicast_addr_cnt) ||
Poddar, Siddarthc01681a2016-12-21 18:36:30 +05307791 nla_put_u32(skb, PARAM_OTHER_RX_MULTICAST_CNT, 0) ||
7792 nla_put_u32(skb, PARAM_RSSI_BREACH_CNT,
7793 data->wow_rssi_breach_wake_up_count) ||
7794 nla_put_u32(skb, PARAM_LOW_RSSI_CNT,
7795 data->wow_low_rssi_wake_up_count) ||
7796 nla_put_u32(skb, PARAM_GSCAN_CNT,
7797 data->wow_gscan_wake_up_count) ||
7798 nla_put_u32(skb, PARAM_PNO_COMPLETE_CNT,
7799 data->wow_pno_complete_wake_up_count) ||
7800 nla_put_u32(skb, PARAM_PNO_MATCH_CNT,
7801 data->wow_pno_match_wake_up_count)) {
Jeff Johnson64943bd2016-08-23 13:14:06 -07007802 hdd_err("nla put fail");
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307803 goto nla_put_failure;
7804 }
7805
7806 cfg80211_vendor_cmd_reply(skb);
7807
7808 EXIT();
7809 return 0;
7810
7811nla_put_failure:
7812 kfree_skb(skb);
7813 return -EINVAL;
7814}
7815
7816/**
7817 * __wlan_hdd_cfg80211_get_wakelock_stats() - gets wake lock stats
7818 * @wiphy: wiphy pointer
7819 * @wdev: pointer to struct wireless_dev
7820 * @data: pointer to incoming NL vendor data
7821 * @data_len: length of @data
7822 *
7823 * This function parses the incoming NL vendor command data attributes and
7824 * invokes the SME Api and blocks on a completion variable.
7825 * WMA copies required data and invokes callback
7826 * wlan_hdd_cfg80211_wakelock_stats_rsp_callback to send wake lock stats.
7827 *
7828 * Return: 0 on success; error number otherwise.
7829 */
7830static int __wlan_hdd_cfg80211_get_wakelock_stats(struct wiphy *wiphy,
7831 struct wireless_dev *wdev,
7832 const void *data,
7833 int data_len)
7834{
7835 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7836 int status, ret;
7837 struct sir_wake_lock_stats wake_lock_stats;
7838 QDF_STATUS qdf_status;
7839
7840 ENTER();
7841
7842 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson64943bd2016-08-23 13:14:06 -07007843 hdd_err("Command not allowed in FTM mode");
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307844 return -EINVAL;
7845 }
7846
7847 status = wlan_hdd_validate_context(hdd_ctx);
7848 if (0 != status)
7849 return -EINVAL;
7850
7851 qdf_status = wma_get_wakelock_stats(&wake_lock_stats);
7852 if (qdf_status != QDF_STATUS_SUCCESS) {
Jeff Johnson64943bd2016-08-23 13:14:06 -07007853 hdd_err("failed to get wakelock stats(err=%d)", qdf_status);
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307854 return -EINVAL;
7855 }
7856
7857 ret = hdd_send_wakelock_stats(hdd_ctx,
7858 &wake_lock_stats);
7859 if (ret)
Jeff Johnson64943bd2016-08-23 13:14:06 -07007860 hdd_err("Failed to post wake lock stats");
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307861
7862 EXIT();
7863 return ret;
7864}
7865
7866/**
7867 * wlan_hdd_cfg80211_get_wakelock_stats() - gets wake lock stats
7868 * @wiphy: wiphy pointer
7869 * @wdev: pointer to struct wireless_dev
7870 * @data: pointer to incoming NL vendor data
7871 * @data_len: length of @data
7872 *
7873 * This function parses the incoming NL vendor command data attributes and
7874 * invokes the SME Api and blocks on a completion variable.
7875 * WMA copies required data and invokes callback
7876 * wlan_hdd_cfg80211_wakelock_stats_rsp_callback to send wake lock stats.
7877 *
7878 * Return: 0 on success; error number otherwise.
7879 */
7880static int wlan_hdd_cfg80211_get_wakelock_stats(struct wiphy *wiphy,
7881 struct wireless_dev *wdev,
7882 const void *data, int data_len)
7883{
7884 int ret;
7885
7886 cds_ssr_protect(__func__);
7887 ret = __wlan_hdd_cfg80211_get_wakelock_stats(wiphy, wdev, data,
7888 data_len);
Jeff Johnsonf3a64e62016-10-12 17:17:34 -07007889 cds_ssr_unprotect(__func__);
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05307890
7891 return ret;
7892}
7893
Srinivas Dasari510e7fe2016-04-28 11:51:30 +05307894/**
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05307895 * __wlan_hdd_cfg80211_get_bus_size() - Get WMI Bus size
7896 * @wiphy: wiphy structure pointer
7897 * @wdev: Wireless device structure pointer
7898 * @data: Pointer to the data received
7899 * @data_len: Length of @data
7900 *
7901 * This function reads wmi max bus size and fill in the skb with
7902 * NL attributes and send up the NL event.
7903 * Return: 0 on success; errno on failure
7904 */
7905static int
7906__wlan_hdd_cfg80211_get_bus_size(struct wiphy *wiphy,
7907 struct wireless_dev *wdev,
7908 const void *data, int data_len)
7909{
7910 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7911 int ret_val;
7912 struct sk_buff *skb;
7913 uint32_t nl_buf_len;
7914
7915 ENTER();
7916
7917 ret_val = wlan_hdd_validate_context(hdd_ctx);
7918 if (ret_val)
7919 return ret_val;
7920
7921 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
7922 hdd_err("Command not allowed in FTM mode");
7923 return -EINVAL;
7924 }
7925
7926 hdd_info("WMI Max Bus size: %d", hdd_ctx->wmi_max_len);
7927
7928 nl_buf_len = NLMSG_HDRLEN;
7929 nl_buf_len += (sizeof(hdd_ctx->wmi_max_len) + NLA_HDRLEN);
7930
7931 skb = cfg80211_vendor_cmd_alloc_reply_skb(hdd_ctx->wiphy, nl_buf_len);
7932 if (!skb) {
7933 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
7934 return -ENOMEM;
7935 }
7936
7937 if (nla_put_u16(skb, QCA_WLAN_VENDOR_ATTR_DRV_INFO_BUS_SIZE,
7938 hdd_ctx->wmi_max_len)) {
7939 hdd_err("nla put failure");
7940 goto nla_put_failure;
7941 }
7942
7943 cfg80211_vendor_cmd_reply(skb);
7944
7945 EXIT();
7946
7947 return 0;
7948
7949nla_put_failure:
7950 kfree_skb(skb);
7951 return -EINVAL;
7952}
7953
7954/**
7955 * wlan_hdd_cfg80211_get_bus_size() - SSR Wrapper to Get Bus size
7956 * @wiphy: wiphy structure pointer
7957 * @wdev: Wireless device structure pointer
7958 * @data: Pointer to the data received
7959 * @data_len: Length of @data
7960 *
7961 * Return: 0 on success; errno on failure
7962 */
7963static int wlan_hdd_cfg80211_get_bus_size(struct wiphy *wiphy,
7964 struct wireless_dev *wdev,
7965 const void *data, int data_len)
7966{
7967 int ret;
7968
7969 cds_ssr_protect(__func__);
7970 ret = __wlan_hdd_cfg80211_get_bus_size(wiphy, wdev, data, data_len);
7971 cds_ssr_unprotect(__func__);
7972
7973 return ret;
7974}
7975
7976/**
Srinivas Dasari510e7fe2016-04-28 11:51:30 +05307977 *__wlan_hdd_cfg80211_setband() - set band
7978 * @wiphy: Pointer to wireless phy
7979 * @wdev: Pointer to wireless device
7980 * @data: Pointer to data
7981 * @data_len: Length of @data
7982 *
7983 * Return: 0 on success, negative errno on failure
7984 */
7985static int __wlan_hdd_cfg80211_setband(struct wiphy *wiphy,
7986 struct wireless_dev *wdev,
7987 const void *data, int data_len)
7988{
7989 struct net_device *dev = wdev->netdev;
7990 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
7991 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1];
7992 int ret;
7993 static const struct nla_policy policy[QCA_WLAN_VENDOR_ATTR_MAX + 1]
7994 = {[QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE] = { .type = NLA_U32 } };
7995
7996 ENTER();
7997
7998 ret = wlan_hdd_validate_context(hdd_ctx);
7999 if (ret)
8000 return ret;
8001
8002 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_MAX, data, data_len, policy)) {
8003 hdd_err(FL("Invalid ATTR"));
8004 return -EINVAL;
8005 }
8006
8007 if (!tb[QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE]) {
8008 hdd_err(FL("attr SETBAND_VALUE failed"));
8009 return -EINVAL;
8010 }
8011
8012 ret = hdd_set_band(dev,
8013 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE]));
8014
8015 EXIT();
8016 return ret;
8017}
8018
8019/**
8020 * wlan_hdd_cfg80211_setband() - Wrapper to setband
8021 * @wiphy: wiphy structure pointer
8022 * @wdev: Wireless device structure pointer
8023 * @data: Pointer to the data received
8024 * @data_len: Length of @data
8025 *
8026 * Return: 0 on success; errno on failure
8027 */
8028static int wlan_hdd_cfg80211_setband(struct wiphy *wiphy,
8029 struct wireless_dev *wdev,
8030 const void *data, int data_len)
8031{
8032 int ret;
8033
8034 cds_ssr_protect(__func__);
8035 ret = __wlan_hdd_cfg80211_setband(wiphy, wdev, data, data_len);
8036 cds_ssr_unprotect(__func__);
8037
8038 return ret;
8039}
8040
Kabilan Kannan3c0a7352016-12-02 18:49:38 -08008041/**
8042 * wlan_hdd_cfg80211_sar_convert_limit_set() - Convert limit set value
8043 * @nl80211_value: Vendor command attribute value
8044 * @wmi_value: Pointer to return converted WMI return value
8045 *
8046 * Convert NL80211 vendor command value for SAR limit set to WMI value
8047 * Return: 0 on success, -1 on invalid value
8048 */
8049static int wlan_hdd_cfg80211_sar_convert_limit_set(u32 nl80211_value,
8050 u32 *wmi_value)
8051{
8052 int ret = 0;
8053
8054 switch (nl80211_value) {
8055 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_NONE:
8056 *wmi_value = WMI_SAR_FEATURE_OFF;
8057 break;
8058 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF0:
8059 *wmi_value = WMI_SAR_FEATURE_ON_SET_0;
8060 break;
8061 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF1:
8062 *wmi_value = WMI_SAR_FEATURE_ON_SET_1;
8063 break;
8064 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF2:
8065 *wmi_value = WMI_SAR_FEATURE_ON_SET_2;
8066 break;
8067 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF3:
8068 *wmi_value = WMI_SAR_FEATURE_ON_SET_3;
8069 break;
8070 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF4:
8071 *wmi_value = WMI_SAR_FEATURE_ON_SET_4;
8072 break;
8073 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_USER:
8074 *wmi_value = WMI_SAR_FEATURE_ON_USER_DEFINED;
8075 break;
8076 default:
8077 ret = -1;
8078 }
8079 return ret;
8080}
8081
8082/**
8083 * wlan_hdd_cfg80211_sar_convert_band() - Convert WLAN band value
8084 * @nl80211_value: Vendor command attribute value
8085 * @wmi_value: Pointer to return converted WMI return value
8086 *
8087 * Convert NL80211 vendor command value for SAR BAND to WMI value
8088 * Return: 0 on success, -1 on invalid value
8089 */
8090static int wlan_hdd_cfg80211_sar_convert_band(u32 nl80211_value, u32 *wmi_value)
8091{
8092 int ret = 0;
8093
8094 switch (nl80211_value) {
8095 case NL80211_BAND_2GHZ:
8096 *wmi_value = WMI_SAR_2G_ID;
8097 break;
8098 case NL80211_BAND_5GHZ:
8099 *wmi_value = WMI_SAR_5G_ID;
8100 break;
8101 default:
8102 ret = -1;
8103 }
8104 return ret;
8105}
8106
8107/**
8108 * wlan_hdd_cfg80211_sar_convert_modulation() - Convert WLAN modulation value
8109 * @nl80211_value: Vendor command attribute value
8110 * @wmi_value: Pointer to return converted WMI return value
8111 *
8112 * Convert NL80211 vendor command value for SAR Modulation to WMI value
8113 * Return: 0 on success, -1 on invalid value
8114 */
8115static int wlan_hdd_cfg80211_sar_convert_modulation(u32 nl80211_value,
8116 u32 *wmi_value)
8117{
8118 int ret = 0;
8119
8120 switch (nl80211_value) {
8121 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_MODULATION_CCK:
8122 *wmi_value = WMI_SAR_MOD_CCK;
8123 break;
8124 case QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_MODULATION_OFDM:
8125 *wmi_value = WMI_SAR_MOD_OFDM;
8126 break;
8127 default:
8128 ret = -1;
8129 }
8130 return ret;
8131}
8132
8133
8134/**
8135 * __wlan_hdd_set_sar_power_limits() - Set SAR power limits
8136 * @wiphy: Pointer to wireless phy
8137 * @wdev: Pointer to wireless device
8138 * @data: Pointer to data
8139 * @data_len: Length of @data
8140 *
8141 * This function is used to setup Specific Absorption Rate limit specs.
8142 *
8143 * Return: 0 on success, negative errno on failure
8144 */
8145static int __wlan_hdd_set_sar_power_limits(struct wiphy *wiphy,
8146 struct wireless_dev *wdev,
8147 const void *data, int data_len)
8148{
8149 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
8150 struct nlattr *sar_spec[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_MAX + 1],
8151 *tb[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_MAX + 1],
8152 *sar_spec_list;
8153 struct sar_limit_cmd_params sar_limit_cmd = {0};
8154 int ret = -EINVAL, i = 0, rem = 0;
8155
8156 ENTER();
8157
8158 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
8159 hdd_err("Command not allowed in FTM mode");
8160 return -EPERM;
8161 }
8162
8163 if (wlan_hdd_validate_context(hdd_ctx))
8164 return -EINVAL;
8165
8166 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_MAX,
8167 data, data_len, NULL)) {
8168 hdd_err("Invalid SAR attributes");
8169 return -EINVAL;
8170 }
8171
8172 /* Vendor command manadates all SAR Specs in single call */
8173 sar_limit_cmd.commit_limits = 1;
8174 sar_limit_cmd.sar_enable = WMI_SAR_FEATURE_NO_CHANGE;
8175 if (tb[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SAR_ENABLE]) {
8176 if (wlan_hdd_cfg80211_sar_convert_limit_set(nla_get_u32(
8177 tb[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SAR_ENABLE]),
8178 &sar_limit_cmd.sar_enable) < 0) {
8179 hdd_err("Invalid SAR Enable attr");
8180 goto fail;
8181 }
8182 }
8183 hdd_info("attr sar sar_enable %d", sar_limit_cmd.sar_enable);
8184
8185 if (tb[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_NUM_SPECS]) {
8186 sar_limit_cmd.num_limit_rows = nla_get_u32(
8187 tb[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_NUM_SPECS]);
8188 hdd_info("attr sar num_limit_rows %d",
8189 sar_limit_cmd.num_limit_rows);
8190 }
8191 if (sar_limit_cmd.num_limit_rows > MAX_SAR_LIMIT_ROWS_SUPPORTED) {
8192 hdd_err("SAR Spec list exceed supported size");
8193 goto fail;
8194 }
8195 if (sar_limit_cmd.num_limit_rows == 0)
8196 goto send_sar_limits;
8197 sar_limit_cmd.sar_limit_row_list = qdf_mem_malloc(sizeof(
8198 struct sar_limit_cmd_row) *
8199 sar_limit_cmd.num_limit_rows);
8200 if (!sar_limit_cmd.sar_limit_row_list) {
8201 ret = -ENOMEM;
8202 goto fail;
8203 }
8204 if (!tb[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC]) {
8205 hdd_err("Invalid SAR SPECs list");
8206 goto fail;
8207 }
8208
8209 nla_for_each_nested(sar_spec_list,
8210 tb[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC], rem) {
8211 if (i == sar_limit_cmd.num_limit_rows) {
8212 hdd_warn("SAR Cmd has excess SPECs in list");
8213 break;
8214 }
8215
8216 if (nla_parse(sar_spec, QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_MAX,
8217 nla_data(sar_spec_list), nla_len(sar_spec_list),
8218 NULL)) {
8219 hdd_err("nla_parse failed for SAR Spec list");
8220 goto fail;
8221 }
8222 sar_limit_cmd.sar_limit_row_list[i].validity_bitmap = 0;
8223 if (sar_spec[
8224 QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_POWER_LIMIT]) {
8225 sar_limit_cmd.sar_limit_row_list[i].limit_value =
8226 nla_get_u32(sar_spec[
8227 QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_POWER_LIMIT]);
8228 } else {
8229 hdd_err("SAR Spec does not have power limit value");
8230 goto fail;
8231 }
8232
8233 if (sar_spec[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_BAND]) {
8234 if (wlan_hdd_cfg80211_sar_convert_band(nla_get_u32(
8235 sar_spec[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_BAND]),
8236 &sar_limit_cmd.sar_limit_row_list[i].band_id)
8237 < 0) {
8238 hdd_err("Invalid SAR Band attr");
8239 goto fail;
8240 }
8241 sar_limit_cmd.sar_limit_row_list[i].validity_bitmap |=
8242 WMI_SAR_BAND_ID_VALID_MASK;
8243 }
8244 if (sar_spec[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_CHAIN]) {
8245 sar_limit_cmd.sar_limit_row_list[i].chain_id =
8246 nla_get_u32(sar_spec[
8247 QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_CHAIN]);
8248 sar_limit_cmd.sar_limit_row_list[i].validity_bitmap |=
8249 WMI_SAR_CHAIN_ID_VALID_MASK;
8250 }
8251 if (sar_spec[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_MODULATION]) {
8252 if (wlan_hdd_cfg80211_sar_convert_modulation(nla_get_u32(
8253 sar_spec[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_MODULATION]),
8254 &sar_limit_cmd.sar_limit_row_list[i].mod_id)
8255 < 0) {
8256 hdd_err("Invalid SAR Modulation attr");
8257 goto fail;
8258 }
8259 sar_limit_cmd.sar_limit_row_list[i].validity_bitmap |=
8260 WMI_SAR_MOD_ID_VALID_MASK;
8261 }
8262 hdd_info("Spec_ID: %d, Band: %d Chain: %d Mod: %d POW_Limit: %d Validity_Bitmap: %d",
8263 i, sar_limit_cmd.sar_limit_row_list[i].band_id,
8264 sar_limit_cmd.sar_limit_row_list[i].chain_id,
8265 sar_limit_cmd.sar_limit_row_list[i].mod_id,
8266 sar_limit_cmd.sar_limit_row_list[i].limit_value,
8267 sar_limit_cmd.sar_limit_row_list[i].validity_bitmap);
8268 i++;
8269 }
8270
8271 if (i < sar_limit_cmd.num_limit_rows) {
8272 hdd_warn("SAR Cmd has less SPECs in list");
8273 sar_limit_cmd.num_limit_rows = i;
8274 }
8275
8276send_sar_limits:
8277 if (sme_set_sar_power_limits(hdd_ctx->hHal, &sar_limit_cmd) ==
8278 QDF_STATUS_SUCCESS)
8279 ret = 0;
8280fail:
8281 qdf_mem_free(sar_limit_cmd.sar_limit_row_list);
8282 return ret;
8283}
8284
8285/**
8286 * wlan_hdd_cfg80211_set_sar_power_limits() - Set SAR power limits
8287 * @wiphy: Pointer to wireless phy
8288 * @wdev: Pointer to wireless device
8289 * @data: Pointer to data
8290 * @data_len: Length of @data
8291 *
8292 * Wrapper function of __wlan_hdd_cfg80211_set_sar_power_limits()
8293 *
8294 * Return: 0 on success, negative errno on failure
8295 */
8296static int wlan_hdd_cfg80211_set_sar_power_limits(struct wiphy *wiphy,
8297 struct wireless_dev *wdev,
8298 const void *data,
8299 int data_len)
8300{
8301 int ret;
8302
8303 cds_ssr_protect(__func__);
8304 ret = __wlan_hdd_set_sar_power_limits(wiphy, wdev, data,
8305 data_len);
8306 cds_ssr_unprotect(__func__);
8307
8308 return ret;
8309}
8310
Mukul Sharma69c44cd2016-09-12 18:33:57 +05308311static const struct
8312nla_policy qca_wlan_vendor_attr[QCA_WLAN_VENDOR_ATTR_MAX+1] = {
8313 [QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY] = {.type = NLA_U32},
8314 [QCA_WLAN_VENDOR_ATTR_MAC_ADDR] = {.type = NLA_BINARY,
8315 .len = QDF_MAC_ADDR_SIZE},
8316};
8317
8318/**
8319 * __wlan_hdd_cfg80211_set_fast_roaming() - enable/disable roaming
8320 * @wiphy: Pointer to wireless phy
8321 * @wdev: Pointer to wireless device
8322 * @data: Pointer to data
8323 * @data_len: Length of @data
8324 *
8325 * This function is used to enable/disable roaming using vendor commands
8326 *
8327 * Return: 0 on success, negative errno on failure
8328 */
8329static int __wlan_hdd_cfg80211_set_fast_roaming(struct wiphy *wiphy,
8330 struct wireless_dev *wdev,
8331 const void *data, int data_len)
8332{
8333 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
8334 struct net_device *dev = wdev->netdev;
8335 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
8336 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1];
8337 uint32_t is_fast_roam_enabled;
8338 int ret;
Selvaraj, Sridhard753e7c2017-01-12 20:19:27 +05308339 QDF_STATUS qdf_status;
Mukul Sharma69c44cd2016-09-12 18:33:57 +05308340
8341 ENTER_DEV(dev);
8342
8343 ret = wlan_hdd_validate_context(hdd_ctx);
8344 if (0 != ret)
8345 return ret;
8346
8347 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
8348 hdd_err("Command not allowed in FTM mode");
8349 return -EINVAL;
8350 }
8351
8352 ret = nla_parse(tb, QCA_WLAN_VENDOR_ATTR_MAX, data, data_len,
8353 qca_wlan_vendor_attr);
8354 if (ret) {
8355 hdd_err("Invalid ATTR");
8356 return -EINVAL;
8357 }
8358
8359 /* Parse and fetch Enable flag */
8360 if (!tb[QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY]) {
8361 hdd_err("attr enable failed");
8362 return -EINVAL;
8363 }
8364
8365 is_fast_roam_enabled = nla_get_u32(
8366 tb[QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY]);
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008367 hdd_notice("isFastRoamEnabled %d fast_roaming_allowed %d",
8368 is_fast_roam_enabled, adapter->fast_roaming_allowed);
Mukul Sharma69c44cd2016-09-12 18:33:57 +05308369
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008370 if (!adapter->fast_roaming_allowed) {
8371 hdd_err("fast roaming not allowed on %s interface",
8372 adapter->dev->name);
8373 return -EINVAL;
8374 }
Mukul Sharma69c44cd2016-09-12 18:33:57 +05308375 /* Update roaming */
Selvaraj, Sridhard753e7c2017-01-12 20:19:27 +05308376 qdf_status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008377 (is_fast_roam_enabled &&
8378 adapter->fast_roaming_allowed));
Selvaraj, Sridhard753e7c2017-01-12 20:19:27 +05308379 if (qdf_status != QDF_STATUS_SUCCESS)
8380 hdd_err("sme_config_fast_roaming failed with status=%d",
8381 qdf_status);
8382 ret = qdf_status_to_os_return(qdf_status);
8383
Mukul Sharma69c44cd2016-09-12 18:33:57 +05308384 EXIT();
8385 return ret;
8386}
8387
8388/**
8389 * wlan_hdd_cfg80211_set_fast_roaming() - enable/disable roaming
8390 * @wiphy: Pointer to wireless phy
8391 * @wdev: Pointer to wireless device
8392 * @data: Pointer to data
8393 * @data_len: Length of @data
8394 *
8395 * Wrapper function of __wlan_hdd_cfg80211_set_fast_roaming()
8396 *
8397 * Return: 0 on success, negative errno on failure
8398 */
8399static int wlan_hdd_cfg80211_set_fast_roaming(struct wiphy *wiphy,
8400 struct wireless_dev *wdev,
8401 const void *data, int data_len)
8402{
8403 int ret;
8404
8405 cds_ssr_protect(__func__);
8406 ret = __wlan_hdd_cfg80211_set_fast_roaming(wiphy, wdev, data, data_len);
8407 cds_ssr_unprotect(__func__);
8408
8409 return ret;
8410}
8411
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008412const struct wiphy_vendor_command hdd_wiphy_vendor_commands[] = {
8413 {
8414 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8415 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY,
8416 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
Srinivas Dasari947abd72016-09-02 12:11:33 +05308417 WIPHY_VENDOR_CMD_NEED_NETDEV,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008418 .doit = is_driver_dfs_capable
8419 },
8420
8421#ifdef WLAN_FEATURE_NAN
8422 {
8423 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8424 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_NAN,
8425 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8426 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8427 .doit = wlan_hdd_cfg80211_nan_request
8428 },
8429#endif
8430
8431#ifdef WLAN_FEATURE_STATS_EXT
8432 {
8433 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8434 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_STATS_EXT,
8435 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8436 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8437 .doit = wlan_hdd_cfg80211_stats_ext_request
8438 },
8439#endif
8440#ifdef FEATURE_WLAN_EXTSCAN
8441 {
8442 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8443 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_START,
8444 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8445 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8446 .doit = wlan_hdd_cfg80211_extscan_start
8447 },
8448 {
8449 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8450 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_STOP,
8451 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8452 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8453 .doit = wlan_hdd_cfg80211_extscan_stop
8454 },
8455 {
8456 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8457 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_VALID_CHANNELS,
8458 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
8459 .doit = wlan_hdd_cfg80211_extscan_get_valid_channels
8460 },
8461 {
8462 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8463 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CAPABILITIES,
8464 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8465 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8466 .doit = wlan_hdd_cfg80211_extscan_get_capabilities
8467 },
8468 {
8469 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8470 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_GET_CACHED_RESULTS,
8471 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8472 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8473 .doit = wlan_hdd_cfg80211_extscan_get_cached_results
8474 },
8475 {
8476 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8477 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_BSSID_HOTLIST,
8478 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8479 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8480 .doit = wlan_hdd_cfg80211_extscan_set_bssid_hotlist
8481 },
8482 {
8483 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8484 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_BSSID_HOTLIST,
8485 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8486 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8487 .doit = wlan_hdd_cfg80211_extscan_reset_bssid_hotlist
8488 },
8489 {
8490 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8491 .info.subcmd =
8492 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SIGNIFICANT_CHANGE,
8493 .flags =
8494 WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV |
8495 WIPHY_VENDOR_CMD_NEED_RUNNING,
8496 .doit = wlan_hdd_cfg80211_extscan_set_significant_change
8497 },
8498 {
8499 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8500 .info.subcmd =
8501 QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SIGNIFICANT_CHANGE,
8502 .flags =
8503 WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV |
8504 WIPHY_VENDOR_CMD_NEED_RUNNING,
8505 .doit = wlan_hdd_cfg80211_extscan_reset_significant_change
8506 },
8507 {
8508 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8509 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_SET_LIST,
8510 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8511 WIPHY_VENDOR_CMD_NEED_NETDEV |
8512 WIPHY_VENDOR_CMD_NEED_RUNNING,
8513 .doit = wlan_hdd_cfg80211_set_epno_list
8514 },
8515#endif /* FEATURE_WLAN_EXTSCAN */
8516
8517#ifdef WLAN_FEATURE_LINK_LAYER_STATS
8518 {
8519 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8520 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR,
8521 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8522 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8523 .doit = wlan_hdd_cfg80211_ll_stats_clear
8524 },
8525
8526 {
8527 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8528 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET,
8529 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8530 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8531 .doit = wlan_hdd_cfg80211_ll_stats_set
8532 },
8533
8534 {
8535 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8536 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET,
8537 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8538 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8539 .doit = wlan_hdd_cfg80211_ll_stats_get
8540 },
8541#endif /* WLAN_FEATURE_LINK_LAYER_STATS */
8542#ifdef FEATURE_WLAN_TDLS
8543 {
8544 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8545 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TDLS_ENABLE,
8546 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8547 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8548 .doit = wlan_hdd_cfg80211_exttdls_enable
8549 },
8550 {
8551 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8552 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TDLS_DISABLE,
8553 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8554 WIPHY_VENDOR_CMD_NEED_NETDEV | WIPHY_VENDOR_CMD_NEED_RUNNING,
8555 .doit = wlan_hdd_cfg80211_exttdls_disable
8556 },
8557 {
8558 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8559 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TDLS_GET_STATUS,
8560 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
8561 .doit = wlan_hdd_cfg80211_exttdls_get_status
8562 },
8563#endif
8564 {
8565 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8566 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_FEATURES,
8567 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
8568 .doit = wlan_hdd_cfg80211_get_supported_features
8569 },
8570 {
8571 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8572 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SCANNING_MAC_OUI,
8573 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
8574 .doit = wlan_hdd_cfg80211_set_scanning_mac_oui
8575 },
8576 {
8577 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8578 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_CONCURRENCY_MATRIX,
8579 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
Chandrasekaran, Manishekar6e9aa1b2015-12-02 18:04:00 +05308580 .doit = wlan_hdd_cfg80211_get_concurrency_matrix
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008581 },
8582 {
8583 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8584 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_NO_DFS_FLAG,
8585 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8586 WIPHY_VENDOR_CMD_NEED_NETDEV,
8587 .doit = wlan_hdd_cfg80211_disable_dfs_chan_scan
8588 },
Manikandan Mohan80dea792016-04-28 16:36:48 -07008589 {
8590 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8591 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_WISA,
8592 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8593 WIPHY_VENDOR_CMD_NEED_NETDEV,
8594 .doit = wlan_hdd_cfg80211_handle_wisa_cmd
8595 },
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008596 {
8597 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Anurag Chouhan96919482016-07-13 16:36:57 +05308598 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_STATION,
8599 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8600 WIPHY_VENDOR_CMD_NEED_NETDEV |
8601 WIPHY_VENDOR_CMD_NEED_RUNNING,
8602 .doit = hdd_cfg80211_get_station_cmd
8603 },
8604 {
8605 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008606 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DO_ACS,
8607 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8608 WIPHY_VENDOR_CMD_NEED_NETDEV |
8609 WIPHY_VENDOR_CMD_NEED_RUNNING,
8610 .doit = wlan_hdd_cfg80211_do_acs
8611 },
8612
8613 {
8614 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8615 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES,
8616 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8617 WIPHY_VENDOR_CMD_NEED_NETDEV,
8618 .doit = wlan_hdd_cfg80211_get_features
8619 },
8620#ifdef WLAN_FEATURE_ROAM_OFFLOAD
8621 {
8622 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8623 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY,
8624 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8625 WIPHY_VENDOR_CMD_NEED_NETDEV |
8626 WIPHY_VENDOR_CMD_NEED_RUNNING,
8627 .doit = wlan_hdd_cfg80211_keymgmt_set_key
8628 },
8629#endif
8630#ifdef FEATURE_WLAN_EXTSCAN
8631 {
8632 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8633 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_SET_PASSPOINT_LIST,
8634 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8635 WIPHY_VENDOR_CMD_NEED_NETDEV |
8636 WIPHY_VENDOR_CMD_NEED_RUNNING,
8637 .doit = wlan_hdd_cfg80211_set_passpoint_list
8638 },
8639 {
8640 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8641 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_PNO_RESET_PASSPOINT_LIST,
8642 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8643 WIPHY_VENDOR_CMD_NEED_NETDEV |
8644 WIPHY_VENDOR_CMD_NEED_RUNNING,
8645 .doit = wlan_hdd_cfg80211_reset_passpoint_list
8646 },
8647 {
8648 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8649 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_SET_SSID_HOTLIST,
8650 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8651 WIPHY_VENDOR_CMD_NEED_NETDEV |
8652 WIPHY_VENDOR_CMD_NEED_RUNNING,
8653 .doit = wlan_hdd_cfg80211_extscan_set_ssid_hotlist
8654 },
8655 {
8656 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8657 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_EXTSCAN_RESET_SSID_HOTLIST,
8658 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8659 WIPHY_VENDOR_CMD_NEED_NETDEV |
8660 WIPHY_VENDOR_CMD_NEED_RUNNING,
8661 .doit = wlan_hdd_cfg80211_extscan_reset_ssid_hotlist
8662 },
8663#endif /* FEATURE_WLAN_EXTSCAN */
8664 {
8665 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8666 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_WIFI_INFO,
8667 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8668 WIPHY_VENDOR_CMD_NEED_NETDEV,
8669 .doit = wlan_hdd_cfg80211_get_wifi_info
8670 },
Paul Zhang3a210c52016-12-08 10:18:12 +08008671#ifndef WLAN_UMAC_CONVERGENCE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008672 {
8673 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8674 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION,
8675 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8676 WIPHY_VENDOR_CMD_NEED_NETDEV |
8677 WIPHY_VENDOR_CMD_NEED_RUNNING,
8678 .doit = wlan_hdd_cfg80211_wifi_configuration_set
8679 },
Paul Zhang3a210c52016-12-08 10:18:12 +08008680#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008681 {
8682 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8683 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ROAM,
8684 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8685 WIPHY_VENDOR_CMD_NEED_NETDEV,
8686 .doit = wlan_hdd_cfg80211_set_ext_roam_params
8687 },
8688 {
8689 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8690 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_WIFI_LOGGER_START,
8691 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8692 WIPHY_VENDOR_CMD_NEED_NETDEV,
8693 .doit = wlan_hdd_cfg80211_wifi_logger_start
8694 },
8695 {
8696 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8697 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_RING_DATA,
8698 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8699 WIPHY_VENDOR_CMD_NEED_NETDEV,
8700 .doit = wlan_hdd_cfg80211_wifi_logger_get_ring_data
8701 },
8702 {
8703 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8704 .info.subcmd =
8705 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST,
8706 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8707 WIPHY_VENDOR_CMD_NEED_NETDEV |
8708 WIPHY_VENDOR_CMD_NEED_RUNNING,
8709 .doit = wlan_hdd_cfg80211_get_preferred_freq_list
8710 },
8711 {
8712 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8713 .info.subcmd =
8714 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL,
8715 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8716 WIPHY_VENDOR_CMD_NEED_NETDEV |
8717 WIPHY_VENDOR_CMD_NEED_RUNNING,
8718 .doit = wlan_hdd_cfg80211_set_probable_oper_channel
8719 },
Manikandan Mohan5356c2b2016-04-03 15:51:35 -07008720#ifdef WLAN_FEATURE_TSF
8721 {
8722 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8723 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TSF,
8724 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8725 WIPHY_VENDOR_CMD_NEED_NETDEV |
8726 WIPHY_VENDOR_CMD_NEED_RUNNING,
8727 .doit = wlan_hdd_cfg80211_handle_tsf_cmd
8728 },
8729#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008730#ifdef FEATURE_WLAN_TDLS
8731 {
8732 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8733 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TDLS_GET_CAPABILITIES,
8734 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8735 WIPHY_VENDOR_CMD_NEED_NETDEV |
8736 WIPHY_VENDOR_CMD_NEED_RUNNING,
8737 .doit = wlan_hdd_cfg80211_get_tdls_capabilities
8738 },
8739#endif
8740#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8741 {
8742 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8743 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OFFLOADED_PACKETS,
8744 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8745 WIPHY_VENDOR_CMD_NEED_NETDEV |
8746 WIPHY_VENDOR_CMD_NEED_RUNNING,
8747 .doit = wlan_hdd_cfg80211_offloaded_packets
8748 },
8749#endif
8750 {
8751 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8752 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_MONITOR_RSSI,
8753 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8754 WIPHY_VENDOR_CMD_NEED_NETDEV |
8755 WIPHY_VENDOR_CMD_NEED_RUNNING,
8756 .doit = wlan_hdd_cfg80211_monitor_rssi
8757 },
8758 {
8759 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308760 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ND_OFFLOAD,
8761 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8762 WIPHY_VENDOR_CMD_NEED_NETDEV |
8763 WIPHY_VENDOR_CMD_NEED_RUNNING,
8764 .doit = wlan_hdd_cfg80211_set_ns_offload
8765 },
8766 {
8767 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008768 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_LOGGER_FEATURE_SET,
8769 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8770 WIPHY_VENDOR_CMD_NEED_NETDEV |
8771 WIPHY_VENDOR_CMD_NEED_RUNNING,
8772 .doit = wlan_hdd_cfg80211_get_logger_supp_feature
8773 },
8774#ifdef WLAN_FEATURE_MEMDUMP
8775 {
8776 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8777 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_WIFI_LOGGER_MEMORY_DUMP,
8778 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8779 WIPHY_VENDOR_CMD_NEED_NETDEV |
8780 WIPHY_VENDOR_CMD_NEED_RUNNING,
8781 .doit = wlan_hdd_cfg80211_get_fw_mem_dump
8782 },
8783#endif /* WLAN_FEATURE_MEMDUMP */
8784 {
8785 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8786 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN,
8787 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8788 WIPHY_VENDOR_CMD_NEED_NETDEV |
8789 WIPHY_VENDOR_CMD_NEED_RUNNING,
8790 .doit = wlan_hdd_cfg80211_vendor_scan
8791 },
8792
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05308793 /* Vendor abort scan */
8794 {
8795 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8796 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ABORT_SCAN,
8797 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8798 WIPHY_VENDOR_CMD_NEED_NETDEV |
8799 WIPHY_VENDOR_CMD_NEED_RUNNING,
8800 .doit = wlan_hdd_vendor_abort_scan
8801 },
8802
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008803 /* OCB commands */
8804 {
8805 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8806 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OCB_SET_CONFIG,
8807 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8808 WIPHY_VENDOR_CMD_NEED_NETDEV |
8809 WIPHY_VENDOR_CMD_NEED_RUNNING,
8810 .doit = wlan_hdd_cfg80211_ocb_set_config
8811 },
8812 {
8813 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8814 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OCB_SET_UTC_TIME,
8815 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8816 WIPHY_VENDOR_CMD_NEED_NETDEV |
8817 WIPHY_VENDOR_CMD_NEED_RUNNING,
8818 .doit = wlan_hdd_cfg80211_ocb_set_utc_time
8819 },
8820 {
8821 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8822 .info.subcmd =
8823 QCA_NL80211_VENDOR_SUBCMD_OCB_START_TIMING_ADVERT,
8824 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8825 WIPHY_VENDOR_CMD_NEED_NETDEV |
8826 WIPHY_VENDOR_CMD_NEED_RUNNING,
8827 .doit = wlan_hdd_cfg80211_ocb_start_timing_advert
8828 },
8829 {
8830 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8831 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OCB_STOP_TIMING_ADVERT,
8832 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8833 WIPHY_VENDOR_CMD_NEED_NETDEV |
8834 WIPHY_VENDOR_CMD_NEED_RUNNING,
8835 .doit = wlan_hdd_cfg80211_ocb_stop_timing_advert
8836 },
8837 {
8838 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8839 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OCB_GET_TSF_TIMER,
8840 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8841 WIPHY_VENDOR_CMD_NEED_NETDEV |
8842 WIPHY_VENDOR_CMD_NEED_RUNNING,
8843 .doit = wlan_hdd_cfg80211_ocb_get_tsf_timer
8844 },
8845 {
8846 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8847 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DCC_GET_STATS,
8848 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8849 WIPHY_VENDOR_CMD_NEED_NETDEV |
8850 WIPHY_VENDOR_CMD_NEED_RUNNING,
8851 .doit = wlan_hdd_cfg80211_dcc_get_stats
8852 },
8853 {
8854 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8855 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DCC_CLEAR_STATS,
8856 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8857 WIPHY_VENDOR_CMD_NEED_NETDEV |
8858 WIPHY_VENDOR_CMD_NEED_RUNNING,
8859 .doit = wlan_hdd_cfg80211_dcc_clear_stats
8860 },
8861 {
8862 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8863 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DCC_UPDATE_NDL,
8864 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8865 WIPHY_VENDOR_CMD_NEED_NETDEV |
8866 WIPHY_VENDOR_CMD_NEED_RUNNING,
8867 .doit = wlan_hdd_cfg80211_dcc_update_ndl
8868 },
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05308869 {
8870 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8871 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_LINK_PROPERTIES,
8872 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8873 WIPHY_VENDOR_CMD_NEED_NETDEV |
8874 WIPHY_VENDOR_CMD_NEED_RUNNING,
8875 .doit = wlan_hdd_cfg80211_get_link_properties
8876 },
Peng Xu278d0122015-09-24 16:34:17 -07008877 {
Peng Xud2220962016-07-11 17:59:17 -07008878 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Peng Xu278d0122015-09-24 16:34:17 -07008879 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OTA_TEST,
8880 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8881 WIPHY_VENDOR_CMD_NEED_NETDEV |
8882 WIPHY_VENDOR_CMD_NEED_RUNNING,
8883 .doit = wlan_hdd_cfg80211_set_ota_test
8884 },
Ravi Joshideb5a8d2015-11-09 19:11:43 -08008885#ifdef FEATURE_LFR_SUBNET_DETECTION
8886 {
8887 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8888 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GW_PARAM_CONFIG,
8889 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8890 WIPHY_VENDOR_CMD_NEED_NETDEV |
8891 WIPHY_VENDOR_CMD_NEED_RUNNING,
8892 .doit = wlan_hdd_cfg80211_set_gateway_params
8893 },
8894#endif /* FEATURE_LFR_SUBNET_DETECTION */
Peng Xu4d67c8f2015-10-16 16:02:26 -07008895 {
Peng Xud2220962016-07-11 17:59:17 -07008896 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Peng Xu4d67c8f2015-10-16 16:02:26 -07008897 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SET_TXPOWER_SCALE,
8898 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8899 WIPHY_VENDOR_CMD_NEED_NETDEV |
8900 WIPHY_VENDOR_CMD_NEED_RUNNING,
8901 .doit = wlan_hdd_cfg80211_txpower_scale
8902 },
8903 {
8904 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8905 .info.subcmd =
8906 QCA_NL80211_VENDOR_SUBCMD_SET_TXPOWER_SCALE_DECR_DB,
8907 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8908 WIPHY_VENDOR_CMD_NEED_NETDEV |
8909 WIPHY_VENDOR_CMD_NEED_RUNNING,
8910 .doit = wlan_hdd_cfg80211_txpower_scale_decr_db
8911 },
Arun Khandavalli2476ef52016-04-26 20:19:43 +05308912 {
8913 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8914 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_PACKET_FILTER,
8915 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8916 WIPHY_VENDOR_CMD_NEED_NETDEV |
8917 WIPHY_VENDOR_CMD_NEED_RUNNING,
8918 .doit = wlan_hdd_cfg80211_bpf_offload
8919 },
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05308920 {
8921 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Agrawal Ashish65634612016-08-18 13:24:32 +05308922 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ACS_POLICY,
8923 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8924 WIPHY_VENDOR_CMD_NEED_NETDEV |
8925 WIPHY_VENDOR_CMD_NEED_RUNNING,
8926 .doit = wlan_hdd_cfg80211_acs_dfs_mode
8927 },
8928 {
8929 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Agrawal Ashish21ba2572016-09-03 16:40:10 +05308930 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_STA_CONNECT_ROAM_POLICY,
8931 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8932 WIPHY_VENDOR_CMD_NEED_NETDEV |
8933 WIPHY_VENDOR_CMD_NEED_RUNNING,
8934 .doit = wlan_hdd_cfg80211_sta_roam_policy
8935 },
Agrawal Ashish467dde42016-09-08 18:44:22 +05308936#ifdef FEATURE_WLAN_CH_AVOID
8937 {
8938 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8939 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY,
8940 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8941 WIPHY_VENDOR_CMD_NEED_NETDEV |
8942 WIPHY_VENDOR_CMD_NEED_RUNNING,
8943 .doit = wlan_hdd_cfg80211_avoid_freq
8944 },
8945#endif
Agrawal Ashish21ba2572016-09-03 16:40:10 +05308946 {
8947 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Agrawal Ashishc9ddbab2016-05-25 12:04:47 +05308948 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SET_SAP_CONFIG,
8949 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8950 WIPHY_VENDOR_CMD_NEED_NETDEV |
8951 WIPHY_VENDOR_CMD_NEED_RUNNING,
8952 .doit = wlan_hdd_cfg80211_sap_configuration_set
8953 },
Peng Xu8fdaa492016-06-22 10:20:47 -07008954 {
Peng Xu4225c152016-07-14 21:18:14 -07008955 .info.vendor_id = QCA_NL80211_VENDOR_ID,
Peng Xu8fdaa492016-06-22 10:20:47 -07008956 .info.subcmd =
8957 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START,
8958 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8959 WIPHY_VENDOR_CMD_NEED_NETDEV |
8960 WIPHY_VENDOR_CMD_NEED_RUNNING,
8961 .doit = wlan_hdd_cfg80211_p2p_lo_start
8962 },
8963 {
8964 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8965 .info.subcmd =
8966 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP,
8967 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8968 WIPHY_VENDOR_CMD_NEED_NETDEV |
8969 WIPHY_VENDOR_CMD_NEED_RUNNING,
8970 .doit = wlan_hdd_cfg80211_p2p_lo_stop
8971 },
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05308972 {
8973 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8974 .info.subcmd =
8975 QCA_NL80211_VENDOR_SUBCMD_SAP_CONDITIONAL_CHAN_SWITCH,
8976 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8977 WIPHY_VENDOR_CMD_NEED_NETDEV |
8978 WIPHY_VENDOR_CMD_NEED_RUNNING,
8979 .doit = wlan_hdd_cfg80211_conditional_chan_switch
8980 },
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07008981#ifdef WLAN_FEATURE_NAN_DATAPATH
8982 {
8983 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8984 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_NDP,
8985 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8986 WIPHY_VENDOR_CMD_NEED_NETDEV |
8987 WIPHY_VENDOR_CMD_NEED_RUNNING,
8988 .doit = wlan_hdd_cfg80211_process_ndp_cmd
8989 },
8990#endif
Padma, Santhosh Kumar5e33beb2016-08-08 19:07:06 +05308991 {
8992 .info.vendor_id = QCA_NL80211_VENDOR_ID,
8993 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_WAKE_REASON_STATS,
8994 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
8995 WIPHY_VENDOR_CMD_NEED_NETDEV |
8996 WIPHY_VENDOR_CMD_NEED_RUNNING,
8997 .doit = wlan_hdd_cfg80211_get_wakelock_stats
8998 },
Srinivas Dasari510e7fe2016-04-28 11:51:30 +05308999 {
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05309000 .info.vendor_id = QCA_NL80211_VENDOR_ID,
9001 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_BUS_SIZE,
9002 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
9003 WIPHY_VENDOR_CMD_NEED_NETDEV |
9004 WIPHY_VENDOR_CMD_NEED_RUNNING,
9005 .doit = wlan_hdd_cfg80211_get_bus_size
9006 },
9007 {
Srinivas Dasari510e7fe2016-04-28 11:51:30 +05309008 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SETBAND,
9009 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
9010 WIPHY_VENDOR_CMD_NEED_NETDEV |
9011 WIPHY_VENDOR_CMD_NEED_RUNNING,
9012 .doit = wlan_hdd_cfg80211_setband
Mukul Sharma69c44cd2016-09-12 18:33:57 +05309013 },
9014 {
9015 .info.vendor_id = QCA_NL80211_VENDOR_ID,
9016 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ROAMING,
9017 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
9018 WIPHY_VENDOR_CMD_NEED_NETDEV |
9019 WIPHY_VENDOR_CMD_NEED_RUNNING,
9020 .doit = wlan_hdd_cfg80211_set_fast_roaming
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +05309021 },
9022#ifdef WLAN_FEATURE_DISA
9023 {
9024 .info.vendor_id = QCA_NL80211_VENDOR_ID,
9025 .info.subcmd =
9026 QCA_NL80211_VENDOR_SUBCMD_ENCRYPTION_TEST,
9027 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
9028 WIPHY_VENDOR_CMD_NEED_NETDEV |
9029 WIPHY_VENDOR_CMD_NEED_RUNNING,
9030 .doit = wlan_hdd_cfg80211_encrypt_decrypt_msg
9031 },
9032#endif
Kabilan Kannand053aaf2016-10-26 02:06:14 -07009033#ifdef FEATURE_WLAN_TDLS
9034 {
9035 .info.vendor_id = QCA_NL80211_VENDOR_ID,
9036 .info.subcmd =
9037 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS,
9038 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
9039 WIPHY_VENDOR_CMD_NEED_NETDEV |
9040 WIPHY_VENDOR_CMD_NEED_RUNNING,
9041 .doit = wlan_hdd_cfg80211_configure_tdls_mode
Kabilan Kannan3c0a7352016-12-02 18:49:38 -08009042 },
Kabilan Kannand053aaf2016-10-26 02:06:14 -07009043#endif
Kabilan Kannan3c0a7352016-12-02 18:49:38 -08009044 {
9045 .info.vendor_id = QCA_NL80211_VENDOR_ID,
9046 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SET_SAR_LIMITS,
9047 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
9048 WIPHY_VENDOR_CMD_NEED_RUNNING,
9049 .doit = wlan_hdd_cfg80211_set_sar_power_limits
9050 },
Paul Zhang3a210c52016-12-08 10:18:12 +08009051#ifdef WLAN_UMAC_CONVERGENCE
9052 COMMON_VENDOR_COMMANDS
9053#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009054};
9055
Anurag Chouhan7c01cc42016-12-16 21:33:43 +05309056#if ((LINUX_VERSION_CODE > KERNEL_VERSION(4, 4, 0)) || \
9057 defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT)) && \
9058 defined(FEATURE_WLAN_SCAN_PNO)
9059/**
9060 * hdd_config_sched_scan_plans_to_wiphy() - configure sched scan plans to wiphy
9061 * @wiphy: pointer to wiphy
9062 * @config: pointer to config
9063 *
9064 * Return: None
9065 */
9066static void hdd_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy,
9067 struct hdd_config *config)
9068{
9069 if (config->configPNOScanSupport) {
9070 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
9071 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
9072 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
9073 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
9074 wiphy->max_sched_scan_plans = SIR_PNO_MAX_PLAN_REQUEST;
9075 if (config->max_sched_scan_plan_interval)
9076 wiphy->max_sched_scan_plan_interval =
9077 config->max_sched_scan_plan_interval;
9078 if (config->max_sched_scan_plan_iterations)
9079 wiphy->max_sched_scan_plan_iterations =
9080 config->max_sched_scan_plan_iterations;
9081 }
9082}
9083#else
9084static void hdd_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy,
9085 struct hdd_config *config)
9086{
9087}
9088#endif
9089
9090
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009091/**
9092 * hdd_cfg80211_wiphy_alloc() - Allocate wiphy context
9093 * @priv_size: Size of the hdd context.
9094 *
9095 * Allocate wiphy context and hdd context.
9096 *
9097 * Return: hdd context on success and NULL on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009098 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009099hdd_context_t *hdd_cfg80211_wiphy_alloc(int priv_size)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009100{
9101 struct wiphy *wiphy;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009102 hdd_context_t *hdd_ctx;
9103
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009104 ENTER();
9105
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009106 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
9107
9108 if (!wiphy) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009109 hdd_err("wiphy init failed!\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009110 return NULL;
9111 }
9112
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009113 hdd_ctx = wiphy_priv(wiphy);
9114
9115 hdd_ctx->wiphy = wiphy;
9116
9117 return hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009118}
9119
9120/*
9121 * FUNCTION: wlan_hdd_cfg80211_update_band
9122 * This function is called from the supplicant through a
9123 * private ioctl to change the band value
9124 */
9125int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
9126{
9127 int i, j;
Amar Singhala297bfa2015-10-15 15:07:29 -07009128 enum channel_state channelEnabledState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009129
9130 ENTER();
9131
Dustin Browna30892e2016-10-12 17:28:36 -07009132 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009133
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -08009134 if (NULL == wiphy->bands[i])
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009135 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009136
9137 for (j = 0; j < wiphy->bands[i]->n_channels; j++) {
9138 struct ieee80211_supported_band *band = wiphy->bands[i];
9139
9140 channelEnabledState =
9141 cds_get_channel_state(band->channels[j].
9142 hw_value);
9143
Dustin Browna30892e2016-10-12 17:28:36 -07009144 if (NL80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009145 /* 5G only */
9146#ifdef WLAN_ENABLE_SOCIAL_CHANNELS_5G_ONLY
9147 /* Enable Social channels for P2P */
9148 if (WLAN_HDD_IS_SOCIAL_CHANNEL
9149 (band->channels[j].center_freq)
9150 && CHANNEL_STATE_ENABLE ==
9151 channelEnabledState)
9152 band->channels[j].flags &=
9153 ~IEEE80211_CHAN_DISABLED;
9154 else
9155#endif
9156 band->channels[j].flags |=
9157 IEEE80211_CHAN_DISABLED;
9158 continue;
Dustin Browna30892e2016-10-12 17:28:36 -07009159 } else if (NL80211_BAND_5GHZ == i &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009160 eCSR_BAND_24 == eBand) {
9161 /* 2G only */
9162 band->channels[j].flags |=
9163 IEEE80211_CHAN_DISABLED;
9164 continue;
9165 }
9166
Amar Singhal6842e8f2016-02-23 16:30:32 -08009167 if (CHANNEL_STATE_DISABLE != channelEnabledState)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009168 band->channels[j].flags &=
9169 ~IEEE80211_CHAN_DISABLED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009170 }
9171 }
9172 return 0;
9173}
9174
Peng Xuacfdda12017-02-06 16:15:38 -08009175#define WLAN_HDD_MAX_NUM_CSA_COUNTERS 2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009176/*
9177 * FUNCTION: wlan_hdd_cfg80211_init
9178 * This function is called by hdd_wlan_startup()
9179 * during initialization.
9180 * This function is used to initialize and register wiphy structure.
9181 */
9182int wlan_hdd_cfg80211_init(struct device *dev,
9183 struct wiphy *wiphy, struct hdd_config *pCfg)
9184{
9185 int i, j;
9186 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9187
9188 ENTER();
9189
9190 /* Now bind the underlying wlan device with wiphy */
9191 set_wiphy_dev(wiphy, dev);
9192
9193 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
9194
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009195#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
9196 wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS;
Amar Singhal01098f72015-10-08 11:55:32 -07009197 wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009198#else
9199 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhal01098f72015-10-08 11:55:32 -07009200 wiphy->country_ie_pref |= NL80211_COUNTRY_IE_IGNORE_CORE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009201#endif
9202
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009203 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
9204 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
9205 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
9206#ifdef FEATURE_WLAN_STA_4ADDR_SCHEME
9207 | WIPHY_FLAG_4ADDR_STATION
9208#endif
9209 | WIPHY_FLAG_OFFCHAN_TX;
9210
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009211#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
9212 wiphy->wowlan = &wowlan_support_cfg80211_init;
9213#else
9214 wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
9215 wiphy->wowlan.n_patterns = WOWL_MAX_PTRNS_ALLOWED;
9216 wiphy->wowlan.pattern_min_len = 1;
9217 wiphy->wowlan.pattern_max_len = WOWL_PTRN_MAX_SIZE;
9218#endif
9219
Deepak Dhamdherea2df6bb2015-10-29 15:11:06 -07009220 if (pCfg->isFastTransitionEnabled || pCfg->isFastRoamIniFeatureEnabled
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009221#ifdef FEATURE_WLAN_ESE
9222 || pCfg->isEseIniFeatureEnabled
9223#endif
9224 ) {
9225 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
9226 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009227#ifdef FEATURE_WLAN_TDLS
9228 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
9229 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
9230#endif
9231
9232 wiphy->features |= NL80211_FEATURE_HT_IBSS;
9233
Naveen Rawatc77e6e72016-08-05 15:19:03 -07009234#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0))
9235 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
9236#endif
9237
Anurag Chouhan7c01cc42016-12-16 21:33:43 +05309238 hdd_config_sched_scan_plans_to_wiphy(wiphy, pCfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009239
9240#if defined QCA_WIFI_FTM
Anurag Chouhan6d760662016-02-20 16:05:43 +05309241 if (cds_get_conparam() != QDF_GLOBAL_FTM_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009242#endif
9243
9244 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
Jeff Johnsonf3826e12017-01-12 09:49:40 -08009245 * driver can still register regulatory callback and
9246 * it will get regulatory settings in wiphy->band[], but
9247 * driver need to determine what to do with both
9248 * regulatory settings
9249 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009250
9251 wiphy->reg_notifier = hdd_reg_notifier;
9252
9253#if defined QCA_WIFI_FTM
9254}
9255#endif
9256
9257 wiphy->max_scan_ssids = MAX_SCAN_SSID;
9258
9259 wiphy->max_scan_ie_len = SIR_MAC_MAX_ADD_IE_LENGTH;
9260
9261 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
9262
Arun Khandavallifae92942016-08-01 13:31:08 +05309263 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
9264 | BIT(NL80211_IFTYPE_ADHOC)
9265 | BIT(NL80211_IFTYPE_P2P_CLIENT)
9266 | BIT(NL80211_IFTYPE_P2P_GO)
9267 | BIT(NL80211_IFTYPE_AP)
9268 | BIT(NL80211_IFTYPE_MONITOR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009269
Arun Khandavallifae92942016-08-01 13:31:08 +05309270 if (pCfg->advertiseConcurrentOperation) {
9271 if (pCfg->enableMCC) {
9272 int i;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07009273
Arun Khandavallifae92942016-08-01 13:31:08 +05309274 for (i = 0;
9275 i < ARRAY_SIZE(wlan_hdd_iface_combination);
9276 i++) {
9277 if (!pCfg->allowMCCGODiffBI)
9278 wlan_hdd_iface_combination[i].
9279 beacon_int_infra_match = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009280 }
9281 }
9282 wiphy->n_iface_combinations =
Arun Khandavallifae92942016-08-01 13:31:08 +05309283 ARRAY_SIZE(wlan_hdd_iface_combination);
9284 wiphy->iface_combinations = wlan_hdd_iface_combination;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009285 }
9286
9287 /* Before registering we need to update the ht capabilitied based
Jeff Johnsonf3826e12017-01-12 09:49:40 -08009288 * on ini values
9289 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009290 if (!pCfg->ShortGI20MhzEnable) {
9291 wlan_hdd_band_2_4_ghz.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
9292 wlan_hdd_band_5_ghz.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009293 }
9294
9295 if (!pCfg->ShortGI40MhzEnable) {
9296 wlan_hdd_band_5_ghz.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
9297 }
9298
9299 if (!pCfg->nChannelBondingMode5GHz) {
9300 wlan_hdd_band_5_ghz.ht_cap.cap &=
9301 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
9302 }
9303
Abhishek Singhf512bf32016-05-04 16:47:46 +05309304 /*
9305 * In case of static linked driver at the time of driver unload,
9306 * module exit doesn't happens. Module cleanup helps in cleaning
9307 * of static memory.
9308 * If driver load happens statically, at the time of driver unload,
9309 * wiphy flags don't get reset because of static memory.
9310 * It's better not to store channel in static memory.
9311 */
Dustin Browna30892e2016-10-12 17:28:36 -07009312 wiphy->bands[NL80211_BAND_2GHZ] = &wlan_hdd_band_2_4_ghz;
9313 wiphy->bands[NL80211_BAND_2GHZ]->channels =
Abhishek Singhf512bf32016-05-04 16:47:46 +05309314 qdf_mem_malloc(sizeof(hdd_channels_2_4_ghz));
Dustin Browna30892e2016-10-12 17:28:36 -07009315 if (wiphy->bands[NL80211_BAND_2GHZ]->channels == NULL) {
Abhishek Singhf512bf32016-05-04 16:47:46 +05309316 hdd_err("Not enough memory to allocate channels");
9317 return -ENOMEM;
9318 }
Dustin Browna30892e2016-10-12 17:28:36 -07009319 qdf_mem_copy(wiphy->bands[NL80211_BAND_2GHZ]->channels,
Abhishek Singhf512bf32016-05-04 16:47:46 +05309320 &hdd_channels_2_4_ghz[0],
9321 sizeof(hdd_channels_2_4_ghz));
Selvaraj, Sridharcd3cc702016-07-31 15:37:07 +05309322 if ((hdd_is_5g_supported(pHddCtx)) &&
9323 ((eHDD_DOT11_MODE_11b != pCfg->dot11Mode) &&
9324 (eHDD_DOT11_MODE_11g != pCfg->dot11Mode) &&
9325 (eHDD_DOT11_MODE_11b_ONLY != pCfg->dot11Mode) &&
9326 (eHDD_DOT11_MODE_11g_ONLY != pCfg->dot11Mode))) {
Dustin Browna30892e2016-10-12 17:28:36 -07009327 wiphy->bands[NL80211_BAND_5GHZ] = &wlan_hdd_band_5_ghz;
9328 wiphy->bands[NL80211_BAND_5GHZ]->channels =
Abhishek Singhf512bf32016-05-04 16:47:46 +05309329 qdf_mem_malloc(sizeof(hdd_channels_5_ghz));
Dustin Browna30892e2016-10-12 17:28:36 -07009330 if (wiphy->bands[NL80211_BAND_5GHZ]->channels == NULL) {
Abhishek Singhf512bf32016-05-04 16:47:46 +05309331 hdd_err("Not enough memory to allocate channels");
9332 qdf_mem_free(wiphy->
Dustin Browna30892e2016-10-12 17:28:36 -07009333 bands[NL80211_BAND_2GHZ]->channels);
9334 wiphy->bands[NL80211_BAND_2GHZ]->channels = NULL;
Abhishek Singhf512bf32016-05-04 16:47:46 +05309335 return -ENOMEM;
9336 }
Dustin Browna30892e2016-10-12 17:28:36 -07009337 qdf_mem_copy(wiphy->bands[NL80211_BAND_5GHZ]->channels,
Abhishek Singhf512bf32016-05-04 16:47:46 +05309338 &hdd_channels_5_ghz[0],
9339 sizeof(hdd_channels_5_ghz));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009340 }
9341
Dustin Browna30892e2016-10-12 17:28:36 -07009342 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009343
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -08009344 if (NULL == wiphy->bands[i])
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009345 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009346
9347 for (j = 0; j < wiphy->bands[i]->n_channels; j++) {
9348 struct ieee80211_supported_band *band = wiphy->bands[i];
9349
Dustin Browna30892e2016-10-12 17:28:36 -07009350 if (NL80211_BAND_2GHZ == i &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009351 eCSR_BAND_5G == pCfg->nBandCapability) {
9352 /* 5G only */
9353#ifdef WLAN_ENABLE_SOCIAL_CHANNELS_5G_ONLY
9354 /* Enable social channels for P2P */
9355 if (WLAN_HDD_IS_SOCIAL_CHANNEL
9356 (band->channels[j].center_freq))
9357 band->channels[j].flags &=
9358 ~IEEE80211_CHAN_DISABLED;
9359 else
9360#endif
9361 band->channels[j].flags |=
9362 IEEE80211_CHAN_DISABLED;
9363 continue;
Dustin Browna30892e2016-10-12 17:28:36 -07009364 } else if (NL80211_BAND_5GHZ == i &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009365 eCSR_BAND_24 == pCfg->nBandCapability) {
9366 /* 2G only */
9367 band->channels[j].flags |=
9368 IEEE80211_CHAN_DISABLED;
9369 continue;
9370 }
9371 }
9372 }
9373 /*Initialise the supported cipher suite details */
9374 wiphy->cipher_suites = hdd_cipher_suites;
9375 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
9376
9377 /*signal strength in mBm (100*dBm) */
9378 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
9379 wiphy->max_remain_on_channel_duration = MAX_REMAIN_ON_CHANNEL_DURATION;
9380
Anurag Chouhan6d760662016-02-20 16:05:43 +05309381 if (cds_get_conparam() != QDF_GLOBAL_FTM_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009382 wiphy->n_vendor_commands =
9383 ARRAY_SIZE(hdd_wiphy_vendor_commands);
9384 wiphy->vendor_commands = hdd_wiphy_vendor_commands;
9385
9386 wiphy->vendor_events = wlan_hdd_cfg80211_vendor_events;
9387 wiphy->n_vendor_events =
9388 ARRAY_SIZE(wlan_hdd_cfg80211_vendor_events);
9389 }
9390
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009391 if (pCfg->enableDFSMasterCap) {
9392 wiphy->flags |= WIPHY_FLAG_DFS_OFFLOAD;
9393 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009394
9395 wiphy->max_ap_assoc_sta = pCfg->maxNumberOfPeers;
9396
9397#ifdef QCA_HT_2040_COEX
9398 wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
9399#endif
Agrawal, Ashish4e5fa1c2016-09-21 19:03:43 +05309400 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
Abhishek Singh1bdb1572015-10-16 16:24:19 +05309401 hdd_add_channel_switch_support(&wiphy->flags);
Peng Xuacfdda12017-02-06 16:15:38 -08009402 wiphy->max_num_csa_counters = WLAN_HDD_MAX_NUM_CSA_COUNTERS;
Abhishek Singh1bdb1572015-10-16 16:24:19 +05309403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009404 EXIT();
9405 return 0;
9406}
9407
Abhishek Singhf512bf32016-05-04 16:47:46 +05309408/**
Yingying Tang80e15f32016-09-27 18:23:01 +08009409 * wlan_hdd_cfg80211_deinit() - Deinit cfg80211
9410 * @wiphy: the wiphy to validate against
Abhishek Singhf512bf32016-05-04 16:47:46 +05309411 *
9412 * this function deinit cfg80211 and cleanup the
Abhishek Singh3e6172f2016-05-04 16:56:48 +05309413 * memory allocated in wlan_hdd_cfg80211_init also
9414 * reset the global reg params.
Abhishek Singhf512bf32016-05-04 16:47:46 +05309415 *
9416 * Return: void
9417 */
9418void wlan_hdd_cfg80211_deinit(struct wiphy *wiphy)
9419{
9420 int i;
9421
Dustin Browna30892e2016-10-12 17:28:36 -07009422 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Abhishek Singhf512bf32016-05-04 16:47:46 +05309423 if (NULL != wiphy->bands[i] &&
9424 (NULL != wiphy->bands[i]->channels)) {
9425 qdf_mem_free(wiphy->bands[i]->channels);
9426 wiphy->bands[i]->channels = NULL;
9427 }
9428 }
Abhishek Singh3e6172f2016-05-04 16:56:48 +05309429 hdd_reset_global_reg_params();
Abhishek Singhf512bf32016-05-04 16:47:46 +05309430}
9431
Yingying Tang80e15f32016-09-27 18:23:01 +08009432/**
9433 * wlan_hdd_update_band_cap() - update capabilities for supported bands
9434 * @hdd_ctx: HDD context
9435 *
9436 * this function will update capabilities for supported bands
9437 *
9438 * Return: void
9439 */
9440static void wlan_hdd_update_band_cap(hdd_context_t *hdd_ctx)
9441{
9442 uint32_t val32;
9443 uint16_t val16;
9444 tSirMacHTCapabilityInfo *ht_cap_info;
9445 QDF_STATUS status;
9446
9447 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
9448 if (QDF_STATUS_SUCCESS != status) {
9449 hdd_err("could not get HT capability info");
9450 val32 = 0;
9451 }
9452 val16 = (uint16_t)val32;
9453 ht_cap_info = (tSirMacHTCapabilityInfo *)&val16;
9454
9455 if (ht_cap_info->txSTBC == true) {
9456 if (NULL != hdd_ctx->wiphy->bands[NL80211_BAND_2GHZ])
9457 hdd_ctx->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap |=
9458 IEEE80211_HT_CAP_TX_STBC;
9459 if (NULL != hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ])
9460 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.cap |=
9461 IEEE80211_HT_CAP_TX_STBC;
9462 }
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009463
9464 if (!sme_is_feature_supported_by_fw(DOT11AC)) {
9465 hdd_ctx->wiphy->bands[NL80211_BAND_2GHZ]->
9466 vht_cap.vht_supported = 0;
9467 hdd_ctx->wiphy->bands[NL80211_BAND_2GHZ]->vht_cap.cap = 0;
9468 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ]->
9469 vht_cap.vht_supported = 0;
9470 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap = 0;
9471 }
Yingying Tang80e15f32016-09-27 18:23:01 +08009472}
9473
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009474/*
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309475 * In this function, wiphy structure is updated after QDF
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009476 * initialization. In wlan_hdd_cfg80211_init, only the
9477 * default values will be initialized. The final initialization
9478 * of all required members can be done here.
9479 */
Yingying Tang80e15f32016-09-27 18:23:01 +08009480void wlan_hdd_update_wiphy(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009481{
Yingying Tang80e15f32016-09-27 18:23:01 +08009482 hdd_ctx->wiphy->max_ap_assoc_sta = hdd_ctx->config->maxNumberOfPeers;
9483
9484 wlan_hdd_update_band_cap(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009485}
9486
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009487/**
9488 * wlan_hdd_update_11n_mode - update 11n mode in hdd cfg
9489 * @cfg: hdd cfg
9490 *
9491 * this function update 11n mode in hdd cfg
9492 *
9493 * Return: void
9494 */
9495void wlan_hdd_update_11n_mode(struct hdd_config *cfg)
9496{
9497 if (sme_is_feature_supported_by_fw(DOT11AC)) {
9498 hdd_notice("support 11ac");
9499 } else {
9500 hdd_notice("not support 11ac");
9501 if ((cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) ||
9502 (cfg->dot11Mode == eHDD_DOT11_MODE_11ac)) {
9503 cfg->dot11Mode = eHDD_DOT11_MODE_11n;
9504 cfg->sap_p2p_11ac_override = 0;
9505 }
9506 }
9507}
9508
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009509/* In this function we are registering wiphy. */
9510int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
9511{
9512 ENTER();
9513 /* Register our wiphy dev with cfg80211 */
9514 if (0 > wiphy_register(wiphy)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009515 hdd_err("wiphy register failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009516 return -EIO;
9517 }
9518
9519 EXIT();
9520 return 0;
9521}
9522
9523/*
Jeff Johnsonf3826e12017-01-12 09:49:40 -08009524 * HDD function to update wiphy capability based on target offload status.
9525 *
9526 * wlan_hdd_cfg80211_init() does initialization of all wiphy related
9527 * capability even before downloading firmware to the target. In discrete
9528 * case, host will get know certain offload capability (say sched_scan
9529 * caps) only after downloading firmware to the target and target boots up.
9530 * This function is used to override setting done in wlan_hdd_cfg80211_init()
9531 * based on target capability.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009532 */
9533void wlan_hdd_cfg80211_update_wiphy_caps(struct wiphy *wiphy)
9534{
9535#ifdef FEATURE_WLAN_SCAN_PNO
9536 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9537 struct hdd_config *pCfg = pHddCtx->config;
9538
9539 /* wlan_hdd_cfg80211_init() sets sched_scan caps already in wiphy before
9540 * control comes here. Here just we need to clear it if firmware doesn't
Jeff Johnsonf3826e12017-01-12 09:49:40 -08009541 * have PNO support.
9542 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009543 if (!pCfg->PnoOffload) {
9544 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
9545 wiphy->max_sched_scan_ssids = 0;
9546 wiphy->max_match_sets = 0;
9547 wiphy->max_sched_scan_ie_len = 0;
9548 }
9549#endif
9550}
9551
9552/* This function registers for all frame which supplicant is interested in */
9553void wlan_hdd_cfg80211_register_frames(hdd_adapter_t *pAdapter)
9554{
9555 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9556 /* Register for all P2P action, public action etc frames */
9557 uint16_t type = (SIR_MAC_MGMT_FRAME << 2) | (SIR_MAC_MGMT_ACTION << 4);
9558
9559 ENTER();
9560
Abhishek Singh7996eb72015-12-30 17:24:02 +05309561 /* Register frame indication call back */
9562 sme_register_mgmt_frame_ind_callback(hHal, hdd_indicate_mgmt_frame);
9563
Selvaraj, Sridhar4577a9b2016-09-04 15:17:07 +05309564 /* Register for p2p ack indication */
9565 sme_register_p2p_ack_ind_callback(hHal, hdd_send_action_cnf_cb);
9566
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009567 /* Right now we are registering these frame when driver is getting
Jeff Johnsonf3826e12017-01-12 09:49:40 -08009568 * initialized. Once we will move to 2.6.37 kernel, in which we have
9569 * frame register ops, we will move this code as a part of that
9570 */
9571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009572 /* GAS Initial Request */
9573 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9574 (uint8_t *) GAS_INITIAL_REQ,
9575 GAS_INITIAL_REQ_SIZE);
9576
9577 /* GAS Initial Response */
9578 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9579 (uint8_t *) GAS_INITIAL_RSP,
9580 GAS_INITIAL_RSP_SIZE);
9581
9582 /* GAS Comeback Request */
9583 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9584 (uint8_t *) GAS_COMEBACK_REQ,
9585 GAS_COMEBACK_REQ_SIZE);
9586
9587 /* GAS Comeback Response */
9588 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9589 (uint8_t *) GAS_COMEBACK_RSP,
9590 GAS_COMEBACK_RSP_SIZE);
9591
9592 /* P2P Public Action */
9593 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9594 (uint8_t *) P2P_PUBLIC_ACTION_FRAME,
9595 P2P_PUBLIC_ACTION_FRAME_SIZE);
9596
9597 /* P2P Action */
9598 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9599 (uint8_t *) P2P_ACTION_FRAME,
9600 P2P_ACTION_FRAME_SIZE);
9601
9602 /* WNM BSS Transition Request frame */
9603 sme_register_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9604 (uint8_t *) WNM_BSS_ACTION_FRAME,
9605 WNM_BSS_ACTION_FRAME_SIZE);
9606
9607 /* WNM-Notification */
9608 sme_register_mgmt_frame(hHal, pAdapter->sessionId, type,
9609 (uint8_t *) WNM_NOTIFICATION_FRAME,
9610 WNM_NOTIFICATION_FRAME_SIZE);
9611}
9612
9613void wlan_hdd_cfg80211_deregister_frames(hdd_adapter_t *pAdapter)
9614{
9615 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9616 /* Register for all P2P action, public action etc frames */
9617 uint16_t type = (SIR_MAC_MGMT_FRAME << 2) | (SIR_MAC_MGMT_ACTION << 4);
9618
9619 ENTER();
9620
9621 /* Right now we are registering these frame when driver is getting
Jeff Johnsonf3826e12017-01-12 09:49:40 -08009622 * initialized. Once we will move to 2.6.37 kernel, in which we have
9623 * frame register ops, we will move this code as a part of that
9624 */
9625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009626 /* GAS Initial Request */
9627
9628 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9629 (uint8_t *) GAS_INITIAL_REQ,
9630 GAS_INITIAL_REQ_SIZE);
9631
9632 /* GAS Initial Response */
9633 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9634 (uint8_t *) GAS_INITIAL_RSP,
9635 GAS_INITIAL_RSP_SIZE);
9636
9637 /* GAS Comeback Request */
9638 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9639 (uint8_t *) GAS_COMEBACK_REQ,
9640 GAS_COMEBACK_REQ_SIZE);
9641
9642 /* GAS Comeback Response */
9643 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9644 (uint8_t *) GAS_COMEBACK_RSP,
9645 GAS_COMEBACK_RSP_SIZE);
9646
9647 /* P2P Public Action */
9648 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9649 (uint8_t *) P2P_PUBLIC_ACTION_FRAME,
9650 P2P_PUBLIC_ACTION_FRAME_SIZE);
9651
9652 /* P2P Action */
9653 sme_deregister_mgmt_frame(hHal, SME_SESSION_ID_ANY, type,
9654 (uint8_t *) P2P_ACTION_FRAME,
9655 P2P_ACTION_FRAME_SIZE);
9656
9657 /* WNM-Notification */
9658 sme_deregister_mgmt_frame(hHal, pAdapter->sessionId, type,
9659 (uint8_t *) WNM_NOTIFICATION_FRAME,
9660 WNM_NOTIFICATION_FRAME_SIZE);
9661}
9662
9663#ifdef FEATURE_WLAN_WAPI
9664void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t *pAdapter, uint8_t key_index,
9665 const uint8_t *mac_addr, const uint8_t *key,
9666 int key_Len)
9667{
9668 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9669 tCsrRoamSetKey setKey;
9670 bool isConnected = true;
9671 int status = 0;
9672 uint32_t roamId = 0xFF;
9673 uint8_t *pKeyPtr = NULL;
9674 int n = 0;
9675
Jeff Johnson46b40792016-06-29 14:03:14 -07009676 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009677 hdd_device_mode_to_string(pAdapter->device_mode),
9678 pAdapter->device_mode);
9679
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309680 qdf_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009681 setKey.keyId = key_index; /* Store Key ID */
9682 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; /* SET WAPI Encryption */
9683 setKey.keyDirection = eSIR_TX_RX; /* Key Directionn both TX and RX */
9684 setKey.paeRole = 0; /* the PAE role */
9685 if (!mac_addr || is_broadcast_ether_addr(mac_addr)) {
Anurag Chouhanc5548422016-02-24 18:33:27 +05309686 qdf_set_macaddr_broadcast(&setKey.peerMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009687 } else {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309688 qdf_mem_copy(setKey.peerMac.bytes, mac_addr, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009689 }
9690 setKey.keyLength = key_Len;
9691 pKeyPtr = setKey.Key;
9692 memcpy(pKeyPtr, key, key_Len);
9693
Jeff Johnson46b40792016-06-29 14:03:14 -07009694 hdd_notice("WAPI KEY LENGTH:0x%04x", key_Len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009695 for (n = 0; n < key_Len; n++)
Jeff Johnson46b40792016-06-29 14:03:14 -07009696 hdd_notice("WAPI KEY Data[%d]:%02x ",
9697 n, setKey.Key[n]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009698
9699 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
9700 if (isConnected) {
9701 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
9702 pAdapter->sessionId, &setKey, &roamId);
9703 }
9704 if (status != 0) {
Jeff Johnson46b40792016-06-29 14:03:14 -07009705 hdd_err("sme_roam_set_key returned ERROR status= %d",
9706 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009707 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
9708 }
9709}
9710#endif /* FEATURE_WLAN_WAPI */
9711
9712uint8_t *wlan_hdd_cfg80211_get_ie_ptr(const uint8_t *ies_ptr, int length,
9713 uint8_t eid)
9714{
9715 int left = length;
9716 uint8_t *ptr = (uint8_t *)ies_ptr;
9717 uint8_t elem_id, elem_len;
9718
9719 while (left >= 2) {
9720 elem_id = ptr[0];
9721 elem_len = ptr[1];
9722 left -= 2;
9723 if (elem_len > left) {
Jeff Johnson77848112016-06-29 14:52:06 -07009724 hdd_alert("Invalid IEs eid = %d elem_len=%d left=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009725 eid, elem_len, left);
9726 return NULL;
9727 }
9728 if (elem_id == eid) {
9729 return ptr;
9730 }
9731
9732 left -= elem_len;
9733 ptr += (elem_len + 2);
9734 }
9735 return NULL;
9736}
9737
9738/*
9739 * FUNCTION: wlan_hdd_validate_operation_channel
9740 * called by wlan_hdd_cfg80211_start_bss() and
9741 * wlan_hdd_set_channel()
9742 * This function validates whether given channel is part of valid
9743 * channel list.
9744 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309745QDF_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009746 int channel)
9747{
9748
9749 uint32_t num_ch = 0;
9750 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
9751 u32 indx = 0;
9752 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9753 uint8_t fValidChannel = false, count = 0;
9754 struct hdd_config *hdd_pConfig_ini = (WLAN_HDD_GET_CTX(pAdapter))->config;
9755
9756 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
9757
9758 if (hdd_pConfig_ini->sapAllowAllChannel) {
9759 /* Validate the channel */
Amar Singhalb8d4f152016-02-10 10:21:43 -08009760 for (count = CHAN_ENUM_1; count <= CHAN_ENUM_165; count++) {
Amar Singhal7a1726a2015-10-14 16:28:11 -07009761 if (channel == CDS_CHANNEL_NUM(count)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009762 fValidChannel = true;
9763 break;
9764 }
9765 }
9766 if (fValidChannel != true) {
Jeff Johnson77848112016-06-29 14:52:06 -07009767 hdd_err("Invalid Channel [%d]", channel);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309768 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009769 }
9770 } else {
9771 if (0 != sme_cfg_get_str(hHal, WNI_CFG_VALID_CHANNEL_LIST,
9772 valid_ch, &num_ch)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009773 hdd_err("failed to get valid channel list");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309774 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009775 }
9776 for (indx = 0; indx < num_ch; indx++) {
9777 if (channel == valid_ch[indx]) {
9778 break;
9779 }
9780 }
9781
9782 if (indx >= num_ch) {
Jeff Johnson77848112016-06-29 14:52:06 -07009783 hdd_err("Invalid Channel [%d]", channel);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309784 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009785 }
9786 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309787 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009788
9789}
9790
9791#ifdef DHCP_SERVER_OFFLOAD
9792static void wlan_hdd_set_dhcp_server_offload(hdd_adapter_t *pHostapdAdapter)
9793{
9794 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
9795 tpSirDhcpSrvOffloadInfo pDhcpSrvInfo;
9796 uint8_t numEntries = 0;
9797 uint8_t srv_ip[IPADDR_NUM_ENTRIES];
9798 uint8_t num;
9799 uint32_t temp;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309800 pDhcpSrvInfo = qdf_mem_malloc(sizeof(*pDhcpSrvInfo));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009801 if (NULL == pDhcpSrvInfo) {
Jeff Johnson77848112016-06-29 14:52:06 -07009802 hdd_err("could not allocate tDhcpSrvOffloadInfo!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009803 return;
9804 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009805 pDhcpSrvInfo->vdev_id = pHostapdAdapter->sessionId;
9806 pDhcpSrvInfo->dhcpSrvOffloadEnabled = true;
9807 pDhcpSrvInfo->dhcpClientNum = pHddCtx->config->dhcpMaxNumClients;
9808 hdd_string_to_u8_array(pHddCtx->config->dhcpServerIP,
9809 srv_ip, &numEntries, IPADDR_NUM_ENTRIES);
9810 if (numEntries != IPADDR_NUM_ENTRIES) {
Jeff Johnson77848112016-06-29 14:52:06 -07009811 hdd_err("incorrect IP address (%s) assigned for DHCP server!", pHddCtx->config->dhcpServerIP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009812 goto end;
9813 }
9814 if ((srv_ip[0] >= 224) && (srv_ip[0] <= 239)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009815 hdd_err("invalid IP address (%s)! It could NOT be multicast IP address!", pHddCtx->config->dhcpServerIP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009816 goto end;
9817 }
9818 if (srv_ip[IPADDR_NUM_ENTRIES - 1] >= 100) {
Jeff Johnson77848112016-06-29 14:52:06 -07009819 hdd_err("invalid IP address (%s)! The last field must be less than 100!", pHddCtx->config->dhcpServerIP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009820 goto end;
9821 }
9822 for (num = 0; num < numEntries; num++) {
9823 temp = srv_ip[num];
9824 pDhcpSrvInfo->dhcpSrvIP |= (temp << (8 * num));
9825 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309826 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009827 sme_set_dhcp_srv_offload(pHddCtx->hHal, pDhcpSrvInfo)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009828 hdd_err("sme_setDHCPSrvOffload fail!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009829 goto end;
9830 }
Jeff Johnson77848112016-06-29 14:52:06 -07009831 hdd_info("enable DHCP Server offload successfully!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009832end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309833 qdf_mem_free(pDhcpSrvInfo);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009834 return;
9835}
9836#endif /* DHCP_SERVER_OFFLOAD */
9837
9838static int __wlan_hdd_cfg80211_change_bss(struct wiphy *wiphy,
9839 struct net_device *dev,
9840 struct bss_parameters *params)
9841{
9842 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9843 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9844 int ret = 0;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309845 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009846
9847 ENTER();
9848
Anurag Chouhan6d760662016-02-20 16:05:43 +05309849 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson77848112016-06-29 14:52:06 -07009850 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009851 return -EINVAL;
9852 }
9853
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05309854 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
9855 hdd_err("invalid session id: %d", pAdapter->sessionId);
9856 return -EINVAL;
9857 }
9858
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05309859 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009860 TRACE_CODE_HDD_CFG80211_CHANGE_BSS,
9861 pAdapter->sessionId, params->ap_isolate));
Jeff Johnson77848112016-06-29 14:52:06 -07009862 hdd_notice("Device_mode %s(%d), ap_isolate = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009863 hdd_device_mode_to_string(pAdapter->device_mode),
9864 pAdapter->device_mode, params->ap_isolate);
9865
9866 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9867 ret = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05309868 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009869 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009870
Krunal Sonib4326f22016-03-10 13:05:51 -08009871 if (!(pAdapter->device_mode == QDF_SAP_MODE ||
9872 pAdapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009873 return -EOPNOTSUPP;
9874 }
9875
9876 /* ap_isolate == -1 means that in change bss, upper layer doesn't
Jeff Johnsonf3826e12017-01-12 09:49:40 -08009877 * want to update this parameter
9878 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009879 if (-1 != params->ap_isolate) {
9880 pAdapter->sessionCtx.ap.apDisableIntraBssFwd =
9881 !!params->ap_isolate;
9882
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309883 qdf_ret_status = sme_ap_disable_intra_bss_fwd(pHddCtx->hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009884 pAdapter->sessionId,
9885 pAdapter->sessionCtx.
9886 ap.
9887 apDisableIntraBssFwd);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309888 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009889 ret = -EINVAL;
9890 }
9891 }
9892
9893 EXIT();
9894 return ret;
9895}
9896
Krunal Soni8c37e322016-02-03 16:08:37 -08009897/**
9898 * wlan_hdd_change_client_iface_to_new_mode() - to change iface to provided mode
9899 * @ndev: pointer to net device provided by supplicant
9900 * @type: type of the interface, upper layer wanted to change
9901 *
9902 * Upper layer provides the new interface mode that needs to be changed
9903 * for given net device
9904 *
9905 * Return: success or failure in terms of integer value
9906 */
9907static int wlan_hdd_change_client_iface_to_new_mode(struct net_device *ndev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009908 enum nl80211_iftype type)
9909{
Krunal Soni8c37e322016-02-03 16:08:37 -08009910 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
9911 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9912 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009913 hdd_wext_state_t *wext;
9914 struct wireless_dev *wdev;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05309915 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009916
9917 ENTER();
9918
Krunal Soni8c37e322016-02-03 16:08:37 -08009919 if (test_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags)) {
Jeff Johnson77848112016-06-29 14:52:06 -07009920 hdd_notice("ACS is in progress, don't change iface!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009921 return 0;
9922 }
9923
9924 wdev = ndev->ieee80211_ptr;
Krunal Soni8c37e322016-02-03 16:08:37 -08009925 hdd_stop_adapter(hdd_ctx, adapter, true);
9926 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009927 wdev->iftype = type;
9928 /*Check for sub-string p2p to confirm its a p2p interface */
9929 if (NULL != strnstr(ndev->name, "p2p", 3)) {
Krunal Soni8c37e322016-02-03 16:08:37 -08009930 adapter->device_mode =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009931 (type == NL80211_IFTYPE_STATION) ?
Krunal Sonib4326f22016-03-10 13:05:51 -08009932 QDF_P2P_DEVICE_MODE : QDF_P2P_CLIENT_MODE;
Krunal Soni8c37e322016-02-03 16:08:37 -08009933 } else if (type == NL80211_IFTYPE_ADHOC) {
Krunal Sonib4326f22016-03-10 13:05:51 -08009934 adapter->device_mode = QDF_IBSS_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009935 } else {
Krunal Soni8c37e322016-02-03 16:08:37 -08009936 adapter->device_mode =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009937 (type == NL80211_IFTYPE_STATION) ?
Krunal Sonib4326f22016-03-10 13:05:51 -08009938 QDF_STA_MODE : QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009939 }
Krunal Soni8c37e322016-02-03 16:08:37 -08009940 memset(&adapter->sessionCtx, 0, sizeof(adapter->sessionCtx));
9941 hdd_set_station_ops(adapter->dev);
Krunal Soni8c37e322016-02-03 16:08:37 -08009942 wext = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
9943 wext->roamProfile.pAddIEScan = adapter->scan_info.scanAddIE.addIEdata;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009944 wext->roamProfile.nAddIEScanLength =
Krunal Soni8c37e322016-02-03 16:08:37 -08009945 adapter->scan_info.scanAddIE.length;
9946 if (type == NL80211_IFTYPE_ADHOC) {
Arun Khandavallib2f6c262016-08-18 19:07:19 +05309947 status = hdd_init_station_mode(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08009948 wext->roamProfile.BSSType = eCSR_BSS_TYPE_START_IBSS;
9949 wext->roamProfile.phyMode =
9950 hdd_cfg_xlate_to_csr_phy_mode(config->dot11Mode);
9951 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009952 EXIT();
9953 return status;
9954}
9955
9956static int wlan_hdd_cfg80211_change_bss(struct wiphy *wiphy,
9957 struct net_device *dev,
9958 struct bss_parameters *params)
9959{
9960 int ret;
9961
9962 cds_ssr_protect(__func__);
9963 ret = __wlan_hdd_cfg80211_change_bss(wiphy, dev, params);
9964 cds_ssr_unprotect(__func__);
9965
9966 return ret;
9967}
9968
9969/* FUNCTION: wlan_hdd_change_country_code_cd
9970 * to wait for contry code completion
9971 */
9972void *wlan_hdd_change_country_code_cb(void *pAdapter)
9973{
9974 hdd_adapter_t *call_back_pAdapter = pAdapter;
9975 complete(&call_back_pAdapter->change_country_code);
9976 return NULL;
9977}
9978
Rajeev Kumar98edb772016-01-19 12:42:19 -08009979/**
9980 * __wlan_hdd_cfg80211_change_iface() - change interface cfg80211 op
9981 * @wiphy: Pointer to the wiphy structure
9982 * @ndev: Pointer to the net device
9983 * @type: Interface type
9984 * @flags: Flags for change interface
9985 * @params: Pointer to change interface parameters
9986 *
9987 * Return: 0 for success, error number on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009988 */
9989static int __wlan_hdd_cfg80211_change_iface(struct wiphy *wiphy,
9990 struct net_device *ndev,
9991 enum nl80211_iftype type,
9992 u32 *flags,
9993 struct vif_params *params)
9994{
9995 struct wireless_dev *wdev;
9996 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
9997 hdd_context_t *pHddCtx;
9998 tCsrRoamProfile *pRoamProfile = NULL;
9999 eCsrRoamBssType LastBSSType;
10000 struct hdd_config *pConfig = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010001 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010002 int status;
10003
10004 ENTER();
10005
Anurag Chouhan6d760662016-02-20 16:05:43 +053010006 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson77848112016-06-29 14:52:06 -070010007 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010008 return -EINVAL;
10009 }
10010
10011 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10012 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010013 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010014 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010015
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053010016 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010017 TRACE_CODE_HDD_CFG80211_CHANGE_IFACE,
10018 pAdapter->sessionId, type));
10019
Jeff Johnson77848112016-06-29 14:52:06 -070010020 hdd_notice("Device_mode = %d, IFTYPE = 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010021 pAdapter->device_mode, type);
10022
Arun Khandavallifae92942016-08-01 13:31:08 +053010023 status = hdd_wlan_start_modules(pHddCtx, pAdapter, false);
10024 if (status) {
10025 hdd_err("Failed to start modules");
10026 return -EINVAL;
10027 }
10028
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080010029 if (!cds_allow_concurrency(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010030 wlan_hdd_convert_nl_iftype_to_hdd_type(type),
10031 0, HW_MODE_20_MHZ)) {
Jeff Johnson77848112016-06-29 14:52:06 -070010032 hdd_debug("This concurrency combination is not allowed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010033 return -EINVAL;
10034 }
10035
10036 pConfig = pHddCtx->config;
10037 wdev = ndev->ieee80211_ptr;
10038
10039 /* Reset the current device mode bit mask */
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080010040 cds_clear_concurrency_mode(pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010041
10042 hdd_tdls_notify_mode_change(pAdapter, pHddCtx);
10043
Krunal Sonib4326f22016-03-10 13:05:51 -080010044 if ((pAdapter->device_mode == QDF_STA_MODE) ||
10045 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE) ||
10046 (pAdapter->device_mode == QDF_P2P_DEVICE_MODE) ||
10047 (pAdapter->device_mode == QDF_IBSS_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010048 hdd_wext_state_t *pWextState =
10049 WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
10050
10051 pRoamProfile = &pWextState->roamProfile;
10052 LastBSSType = pRoamProfile->BSSType;
10053
10054 switch (type) {
10055 case NL80211_IFTYPE_STATION:
10056 case NL80211_IFTYPE_P2P_CLIENT:
Krunal Soni8c37e322016-02-03 16:08:37 -080010057 case NL80211_IFTYPE_ADHOC:
10058 if (type == NL80211_IFTYPE_ADHOC) {
10059 wlan_hdd_tdls_exit(pAdapter);
10060 hdd_deregister_tx_flow_control(pAdapter);
Jeff Johnson77848112016-06-29 14:52:06 -070010061 hdd_notice("Setting interface Type to ADHOC");
Krunal Soni8c37e322016-02-03 16:08:37 -080010062 }
10063 vstatus = wlan_hdd_change_client_iface_to_new_mode(ndev,
10064 type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010065 if (vstatus != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010066 return -EINVAL;
Arun Khandavallib2f6c262016-08-18 19:07:19 +053010067 if (hdd_start_adapter(pAdapter)) {
10068 hdd_err("Failed to start adapter :%d",
10069 pAdapter->device_mode);
10070 return -EINVAL;
10071 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010072 goto done;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010073 case NL80211_IFTYPE_AP:
10074 case NL80211_IFTYPE_P2P_GO:
10075 {
Jeff Johnson77848112016-06-29 14:52:06 -070010076 hdd_info("Setting interface Type to %s",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010077 (type ==
10078 NL80211_IFTYPE_AP) ? "SoftAP" :
10079 "P2pGo");
10080
10081 /* Cancel any remain on channel for GO mode */
10082 if (NL80211_IFTYPE_P2P_GO == type) {
10083 wlan_hdd_cancel_existing_remain_on_channel
10084 (pAdapter);
10085 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010086
Arun Khandavallifae92942016-08-01 13:31:08 +053010087 hdd_stop_adapter(pHddCtx, pAdapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010088 /* De-init the adapter */
10089 hdd_deinit_adapter(pHddCtx, pAdapter, true);
10090 memset(&pAdapter->sessionCtx, 0,
10091 sizeof(pAdapter->sessionCtx));
10092 pAdapter->device_mode =
10093 (type ==
Krunal Sonib4326f22016-03-10 13:05:51 -080010094 NL80211_IFTYPE_AP) ? QDF_SAP_MODE :
10095 QDF_P2P_GO_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010096
10097 /*
10098 * Fw will take care incase of concurrency
10099 */
10100
Krunal Sonib4326f22016-03-10 13:05:51 -080010101 if ((QDF_SAP_MODE == pAdapter->device_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010102 && (pConfig->apRandomBssidEnabled)) {
Jeff Johnsonf3826e12017-01-12 09:49:40 -080010103 /* To meet Android requirements create
10104 * a randomized MAC address of the
10105 * form 02:1A:11:Fx:xx:xx
10106 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010107 get_random_bytes(&ndev->dev_addr[3], 3);
10108 ndev->dev_addr[0] = 0x02;
10109 ndev->dev_addr[1] = 0x1A;
10110 ndev->dev_addr[2] = 0x11;
10111 ndev->dev_addr[3] |= 0xF0;
10112 memcpy(pAdapter->macAddressCurrent.
10113 bytes, ndev->dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010114 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010115 pr_info("wlan: Generated HotSpot BSSID "
10116 MAC_ADDRESS_STR "\n",
10117 MAC_ADDR_ARRAY(ndev->dev_addr));
10118 }
10119
10120 hdd_set_ap_ops(pAdapter->dev);
10121
Arun Khandavallifae92942016-08-01 13:31:08 +053010122 if (hdd_start_adapter(pAdapter)) {
10123 hdd_err("Error initializing the ap mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010124 return -EINVAL;
10125 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010126 /* Interface type changed update in wiphy structure */
10127 if (wdev) {
10128 wdev->iftype = type;
10129 } else {
Jeff Johnson77848112016-06-29 14:52:06 -070010130 hdd_err("Wireless dev is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010131 return -EINVAL;
10132 }
10133 goto done;
10134 }
10135
10136 default:
Jeff Johnson77848112016-06-29 14:52:06 -070010137 hdd_err("Unsupported interface type (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010138 type);
10139 return -EOPNOTSUPP;
10140 }
Krunal Sonib4326f22016-03-10 13:05:51 -080010141 } else if ((pAdapter->device_mode == QDF_SAP_MODE) ||
10142 (pAdapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010143 switch (type) {
10144 case NL80211_IFTYPE_STATION:
10145 case NL80211_IFTYPE_P2P_CLIENT:
10146 case NL80211_IFTYPE_ADHOC:
Krunal Soni8c37e322016-02-03 16:08:37 -080010147 status = wlan_hdd_change_client_iface_to_new_mode(ndev,
10148 type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010149 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010150 return status;
Arun Khandavallib2f6c262016-08-18 19:07:19 +053010151 if (hdd_start_adapter(pAdapter)) {
10152 hdd_err("Failed to start adapter :%d",
10153 pAdapter->device_mode);
10154 return -EINVAL;
10155 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010156 goto done;
10157
10158 case NL80211_IFTYPE_AP:
10159 case NL80211_IFTYPE_P2P_GO:
10160 wdev->iftype = type;
10161 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
Krunal Sonib4326f22016-03-10 13:05:51 -080010162 QDF_SAP_MODE : QDF_P2P_GO_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010163 goto done;
10164
10165 default:
Jeff Johnson77848112016-06-29 14:52:06 -070010166 hdd_err("Unsupported interface type(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010167 type);
10168 return -EOPNOTSUPP;
10169 }
10170 } else {
Jeff Johnson77848112016-06-29 14:52:06 -070010171 hdd_err("Unsupported device mode(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010172 pAdapter->device_mode);
10173 return -EOPNOTSUPP;
10174 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010175done:
10176 /* Set bitmask based on updated value */
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080010177 cds_set_concurrency_mode(pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010178
Jeff Johnson2ae6f712016-09-23 15:08:48 -070010179 hdd_lpass_notify_mode_change(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010180
10181 EXIT();
10182 return 0;
10183}
10184
Rajeev Kumar98edb772016-01-19 12:42:19 -080010185/**
10186 * wlan_hdd_cfg80211_change_iface() - change interface cfg80211 op
10187 * @wiphy: Pointer to the wiphy structure
10188 * @ndev: Pointer to the net device
10189 * @type: Interface type
10190 * @flags: Flags for change interface
10191 * @params: Pointer to change interface parameters
10192 *
10193 * Return: 0 for success, error number on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010194 */
10195static int wlan_hdd_cfg80211_change_iface(struct wiphy *wiphy,
10196 struct net_device *ndev,
10197 enum nl80211_iftype type,
10198 u32 *flags,
10199 struct vif_params *params)
10200{
10201 int ret;
10202
10203 cds_ssr_protect(__func__);
10204 ret =
10205 __wlan_hdd_cfg80211_change_iface(wiphy, ndev, type, flags, params);
10206 cds_ssr_unprotect(__func__);
10207
10208 return ret;
10209}
10210
10211#ifdef FEATURE_WLAN_TDLS
10212static bool wlan_hdd_is_duplicate_channel(uint8_t *arr,
10213 int index, uint8_t match)
10214{
10215 int i;
10216 for (i = 0; i < index; i++) {
10217 if (arr[i] == match)
10218 return true;
10219 }
10220 return false;
10221}
10222#endif
10223
10224/**
10225 * __wlan_hdd_change_station() - change station
10226 * @wiphy: Pointer to the wiphy structure
10227 * @dev: Pointer to the net device.
10228 * @mac: bssid
10229 * @params: Pointer to station parameters
10230 *
10231 * Return: 0 for success, error number on failure.
10232 */
10233#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
10234static int __wlan_hdd_change_station(struct wiphy *wiphy,
10235 struct net_device *dev,
10236 const uint8_t *mac,
10237 struct station_parameters *params)
10238#else
10239static int __wlan_hdd_change_station(struct wiphy *wiphy,
10240 struct net_device *dev,
10241 uint8_t *mac,
10242 struct station_parameters *params)
10243#endif
10244{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010245 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010246 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
10247 hdd_context_t *pHddCtx;
10248 hdd_station_ctx_t *pHddStaCtx;
Anurag Chouhan6d760662016-02-20 16:05:43 +053010249 struct qdf_mac_addr STAMacAddress;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010250#ifdef FEATURE_WLAN_TDLS
10251 tCsrStaParams StaParams = { 0 };
10252 uint8_t isBufSta = 0;
10253 uint8_t isOffChannelSupported = 0;
Nitesh Shah99934ac2016-09-05 15:54:08 +053010254 bool is_qos_wmm_sta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010255#endif
10256 int ret;
10257
10258 ENTER();
10259
Anurag Chouhan6d760662016-02-20 16:05:43 +053010260 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010261 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010262 return -EINVAL;
10263 }
10264
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053010265 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010266 TRACE_CODE_HDD_CHANGE_STATION,
10267 pAdapter->sessionId, params->listen_interval));
10268
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053010269 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
10270 hdd_err("invalid session id: %d", pAdapter->sessionId);
10271 return -EINVAL;
10272 }
10273
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010274 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10275 ret = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010276 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010277 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010278
10279 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
10280
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010281 qdf_mem_copy(STAMacAddress.bytes, mac, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010282
Krunal Sonib4326f22016-03-10 13:05:51 -080010283 if ((pAdapter->device_mode == QDF_SAP_MODE) ||
10284 (pAdapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010285 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
10286 status =
10287 hdd_softap_change_sta_state(pAdapter,
10288 &STAMacAddress,
Dhanashri Atreb08959a2016-03-01 17:28:03 -080010289 OL_TXRX_PEER_STATE_AUTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010290
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010291 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010292 hdd_notice("Not able to change TL state to AUTHENTICATED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010293 return -EINVAL;
10294 }
10295 }
Krunal Sonib4326f22016-03-10 13:05:51 -080010296 } else if ((pAdapter->device_mode == QDF_STA_MODE) ||
10297 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010298#ifdef FEATURE_WLAN_TDLS
10299 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Naveen Rawat64e477e2016-05-20 10:34:56 -070010300
10301 if (cds_is_sub_20_mhz_enabled()) {
10302 hdd_err("TDLS not allowed with sub 20 MHz");
10303 return -EINVAL;
10304 }
10305
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010306 StaParams.capability = params->capability;
10307 StaParams.uapsd_queues = params->uapsd_queues;
10308 StaParams.max_sp = params->max_sp;
10309
10310 /* Convert (first channel , number of channels) tuple to
10311 * the total list of channels. This goes with the assumption
10312 * that if the first channel is < 14, then the next channels
10313 * are an incremental of 1 else an incremental of 4 till the number
10314 * of channels.
10315 */
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010316 hdd_notice("params->supported_channels_len: %d", params->supported_channels_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010317 if (0 != params->supported_channels_len) {
10318 int i = 0, j = 0, k = 0, no_of_channels = 0;
10319 int num_unique_channels;
10320 int next;
10321 for (i = 0;
10322 i < params->supported_channels_len
10323 && j < SIR_MAC_MAX_SUPP_CHANNELS; i += 2) {
10324 int wifi_chan_index;
10325 if (!wlan_hdd_is_duplicate_channel
10326 (StaParams.supported_channels, j,
10327 params->supported_channels[i])) {
10328 StaParams.
10329 supported_channels[j] =
10330 params->
10331 supported_channels[i];
10332 } else {
10333 continue;
10334 }
10335 wifi_chan_index =
10336 ((StaParams.supported_channels[j] <=
10337 HDD_CHANNEL_14) ? 1 : 4);
10338 no_of_channels =
10339 params->supported_channels[i + 1];
10340
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010341 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 -080010342 StaParams.
10343 supported_channels[j],
10344 wifi_chan_index,
10345 no_of_channels);
10346 for (k = 1; k <= no_of_channels &&
10347 j < SIR_MAC_MAX_SUPP_CHANNELS - 1;
10348 k++) {
10349 next =
10350 StaParams.
10351 supported_channels[j] +
10352 wifi_chan_index;
10353 if (!wlan_hdd_is_duplicate_channel(StaParams.supported_channels, j + 1, next)) {
10354 StaParams.
10355 supported_channels[j
10356 +
10357 1]
10358 = next;
10359 } else {
10360 continue;
10361 }
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010362 hdd_notice("i: %d, j: %d, k: %d, StaParams.supported_channels[%d]: %d", i, j, k,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010363 j + 1,
10364 StaParams.
10365 supported_channels[j +
10366 1]);
10367 j += 1;
10368 }
10369 }
10370 num_unique_channels = j + 1;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010371 hdd_notice("Unique Channel List");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010372 for (i = 0; i < num_unique_channels; i++) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010373 hdd_notice("StaParams.supported_channels[%d]: %d,", i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010374 StaParams.
10375 supported_channels[i]);
10376 }
10377 if (MAX_CHANNEL < num_unique_channels)
10378 num_unique_channels = MAX_CHANNEL;
10379 StaParams.supported_channels_len =
10380 num_unique_channels;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010381 hdd_notice("After removing duplcates StaParams.supported_channels_len: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010382 StaParams.supported_channels_len);
10383 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010384 qdf_mem_copy(StaParams.supported_oper_classes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010385 params->supported_oper_classes,
10386 params->supported_oper_classes_len);
10387 StaParams.supported_oper_classes_len =
10388 params->supported_oper_classes_len;
10389
10390 if (0 != params->ext_capab_len)
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010391 qdf_mem_copy(StaParams.extn_capability,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010392 params->ext_capab,
10393 sizeof(StaParams.extn_capability));
10394
10395 if (NULL != params->ht_capa) {
10396 StaParams.htcap_present = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010397 qdf_mem_copy(&StaParams.HTCap, params->ht_capa,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010398 sizeof(tSirHTCap));
10399 }
10400
10401 StaParams.supported_rates_len =
10402 params->supported_rates_len;
10403
10404 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
10405 * The supported_rates array , for all the structures propogating till Add Sta
10406 * to the firmware has to be modified , if the supplicant (ieee80211) is
10407 * modified to send more rates.
10408 */
10409
10410 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
10411 */
10412 if (StaParams.supported_rates_len >
10413 SIR_MAC_MAX_SUPP_RATES)
10414 StaParams.supported_rates_len =
10415 SIR_MAC_MAX_SUPP_RATES;
10416
10417 if (0 != StaParams.supported_rates_len) {
10418 int i = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010419 qdf_mem_copy(StaParams.supported_rates,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010420 params->supported_rates,
10421 StaParams.supported_rates_len);
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010422 hdd_notice("Supported Rates with Length %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010423 StaParams.supported_rates_len);
10424 for (i = 0; i < StaParams.supported_rates_len;
10425 i++)
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010426 hdd_notice("[%d]: %0x", i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010427 StaParams.supported_rates[i]);
10428 }
10429
10430 if (NULL != params->vht_capa) {
10431 StaParams.vhtcap_present = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010432 qdf_mem_copy(&StaParams.VHTCap,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010433 params->vht_capa,
10434 sizeof(tSirVHTCap));
10435 }
10436
10437 if (0 != params->ext_capab_len) {
10438 /*Define A Macro : TODO Sunil */
10439 if ((1 << 4) & StaParams.extn_capability[3]) {
10440 isBufSta = 1;
10441 }
10442 /* TDLS Channel Switching Support */
10443 if ((1 << 6) & StaParams.extn_capability[3]) {
10444 isOffChannelSupported = 1;
10445 }
10446 }
10447
Nitesh Shah99934ac2016-09-05 15:54:08 +053010448 if (pHddCtx->config->fEnableTDLSWmmMode &&
Nitesh Shahd8ff6322016-09-05 15:55:21 +053010449 (params->ht_capa || params->vht_capa ||
10450 (params->sta_flags_set & BIT(NL80211_STA_FLAG_WME))))
Nitesh Shah99934ac2016-09-05 15:54:08 +053010451 is_qos_wmm_sta = true;
10452
10453 hdd_notice("%s: TDLS Peer is QOS capable"
10454 " is_qos_wmm_sta= %d HTcapPresent = %d",
10455 __func__, is_qos_wmm_sta,
10456 StaParams.htcap_present);
10457
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010458 status = wlan_hdd_tdls_set_peer_caps(pAdapter, mac,
Nitesh Shah99934ac2016-09-05 15:54:08 +053010459 &StaParams,
10460 isBufSta,
10461 isOffChannelSupported,
10462 is_qos_wmm_sta);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010463 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010464 hdd_err("wlan_hdd_tdls_set_peer_caps failed!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010465 return -EINVAL;
10466 }
10467
10468 status =
10469 wlan_hdd_tdls_add_station(wiphy, dev, mac, 1,
10470 &StaParams);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010471 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010472 hdd_err("wlan_hdd_tdls_add_station failed!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010473 return -EINVAL;
10474 }
10475 }
10476#endif
10477 }
10478 EXIT();
10479 return ret;
10480}
10481
10482/**
10483 * wlan_hdd_change_station() - cfg80211 change station handler function
10484 * @wiphy: Pointer to the wiphy structure
10485 * @dev: Pointer to the net device.
10486 * @mac: bssid
10487 * @params: Pointer to station parameters
10488 *
10489 * This is the cfg80211 change station handler function which invokes
10490 * the internal function @__wlan_hdd_change_station with
10491 * SSR protection.
10492 *
10493 * Return: 0 for success, error number on failure.
10494 */
10495#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)) || defined(WITH_BACKPORTS)
10496static int wlan_hdd_change_station(struct wiphy *wiphy,
10497 struct net_device *dev,
10498 const u8 *mac,
10499 struct station_parameters *params)
10500#else
10501static int wlan_hdd_change_station(struct wiphy *wiphy,
10502 struct net_device *dev,
10503 u8 *mac,
10504 struct station_parameters *params)
10505#endif
10506{
10507 int ret;
10508
10509 cds_ssr_protect(__func__);
10510 ret = __wlan_hdd_change_station(wiphy, dev, mac, params);
10511 cds_ssr_unprotect(__func__);
10512
10513 return ret;
10514}
10515
10516/*
10517 * FUNCTION: __wlan_hdd_cfg80211_add_key
10518 * This function is used to initialize the key information
10519 */
10520static int __wlan_hdd_cfg80211_add_key(struct wiphy *wiphy,
10521 struct net_device *ndev,
10522 u8 key_index, bool pairwise,
10523 const u8 *mac_addr,
10524 struct key_params *params)
10525{
10526 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
10527 tCsrRoamSetKey setKey;
10528 int status;
10529 uint32_t roamId = 0xFF;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010530 hdd_hostapd_state_t *pHostapdState;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010531 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010532 hdd_context_t *pHddCtx;
10533 hdd_ap_ctx_t *ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
10534
10535 ENTER();
10536
Anurag Chouhan6d760662016-02-20 16:05:43 +053010537 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010538 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010539 return -EINVAL;
10540 }
10541
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053010542 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
10543 hdd_err("invalid session id: %d", pAdapter->sessionId);
10544 return -EINVAL;
10545 }
10546
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053010547 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010548 TRACE_CODE_HDD_CFG80211_ADD_KEY,
10549 pAdapter->sessionId, params->key_len));
10550 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10551 status = wlan_hdd_validate_context(pHddCtx);
10552
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010553 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010554 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010555
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010556 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010557 hdd_device_mode_to_string(pAdapter->device_mode),
10558 pAdapter->device_mode);
10559
10560 if (CSR_MAX_NUM_KEY <= key_index) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010561 hdd_err("Invalid key index %d", key_index);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010562
10563 return -EINVAL;
10564 }
10565
10566 if (CSR_MAX_KEY_LEN < params->key_len) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010567 hdd_err("Invalid key length %d", params->key_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010568
10569 return -EINVAL;
10570 }
10571
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010572 hdd_notice("called with key index = %d & key length %d", key_index, params->key_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010573
10574 /*extract key idx, key len and key */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010575 qdf_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010576 setKey.keyId = key_index;
10577 setKey.keyLength = params->key_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010578 qdf_mem_copy(&setKey.Key[0], params->key, params->key_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010579
10580 switch (params->cipher) {
10581 case WLAN_CIPHER_SUITE_WEP40:
10582 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
10583 break;
10584
10585 case WLAN_CIPHER_SUITE_WEP104:
10586 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
10587 break;
10588
10589 case WLAN_CIPHER_SUITE_TKIP:
10590 {
10591 u8 *pKey = &setKey.Key[0];
10592 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
10593
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010594 qdf_mem_zero(pKey, CSR_MAX_KEY_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010595
Jeff Johnsonf3826e12017-01-12 09:49:40 -080010596 /* Supplicant sends the 32bytes key in this order
10597 *
10598 * |--------------|----------|----------|
10599 * | Tk1 |TX-MIC | RX Mic |
10600 * |--------------|----------|----------|
10601 * <---16bytes---><--8bytes--><--8bytes-->
10602 *
10603 * Sme expects the 32 bytes key to be in the below order
10604 *
10605 * |--------------|----------|----------|
10606 * | Tk1 |RX-MIC | TX Mic |
10607 * |--------------|----------|----------|
10608 * <---16bytes---><--8bytes--><--8bytes-->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010609 */
10610 /* Copy the Temporal Key 1 (TK1) */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010611 qdf_mem_copy(pKey, params->key, 16);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010612
10613 /*Copy the rx mic first */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010614 qdf_mem_copy(&pKey[16], &params->key[24], 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010615
10616 /*Copy the tx mic */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010617 qdf_mem_copy(&pKey[24], &params->key[16], 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010618
10619 break;
10620 }
10621
10622 case WLAN_CIPHER_SUITE_CCMP:
10623 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
10624 break;
10625
10626#ifdef FEATURE_WLAN_WAPI
10627 case WLAN_CIPHER_SUITE_SMS4:
10628 {
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010629 qdf_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010630 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index,
10631 mac_addr, params->key,
10632 params->key_len);
10633 return 0;
10634 }
10635#endif
10636
10637#ifdef FEATURE_WLAN_ESE
10638 case WLAN_CIPHER_SUITE_KRK:
10639 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
10640 break;
10641#ifdef WLAN_FEATURE_ROAM_OFFLOAD
10642 case WLAN_CIPHER_SUITE_BTK:
10643 setKey.encType = eCSR_ENCRYPT_TYPE_BTK;
10644 break;
10645#endif
10646#endif
10647
10648#ifdef WLAN_FEATURE_11W
10649 case WLAN_CIPHER_SUITE_AES_CMAC:
10650 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
10651 break;
10652#endif
10653
10654 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010655 hdd_err("unsupported cipher type %u", params->cipher);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010656 return -EOPNOTSUPP;
10657 }
10658
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010659 hdd_info("encryption type %d", setKey.encType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010660
10661 if (!pairwise) {
10662 /* set group key */
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010663 hdd_notice("%s- %d: setting Broadcast key", __func__, __LINE__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010664 setKey.keyDirection = eSIR_RX_ONLY;
Anurag Chouhanc5548422016-02-24 18:33:27 +053010665 qdf_set_macaddr_broadcast(&setKey.peerMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010666 } else {
10667 /* set pairwise key */
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010668 hdd_notice("%s- %d: setting pairwise key", __func__, __LINE__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010669 setKey.keyDirection = eSIR_TX_RX;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010670 qdf_mem_copy(setKey.peerMac.bytes, mac_addr, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010671 }
Krunal Sonib4326f22016-03-10 13:05:51 -080010672 if ((QDF_IBSS_MODE == pAdapter->device_mode) && !pairwise) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010673 /* if a key is already installed, block all subsequent ones */
10674 if (pAdapter->sessionCtx.station.ibss_enc_key_installed) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010675 hdd_info("IBSS key installed already");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010676 return 0;
10677 }
10678
10679 setKey.keyDirection = eSIR_TX_RX;
10680 /*Set the group key */
10681 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
10682 pAdapter->sessionId, &setKey, &roamId);
10683
10684 if (0 != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010685 hdd_err("sme_roam_set_key failed, returned %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010686 return -EINVAL;
10687 }
Jeff Johnsonf3826e12017-01-12 09:49:40 -080010688 /* Save the keys here and call sme_roam_set_key for setting
10689 * the PTK after peer joins the IBSS network
10690 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010691 qdf_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010692 &setKey, sizeof(tCsrRoamSetKey));
10693
10694 pAdapter->sessionCtx.station.ibss_enc_key_installed = 1;
10695 return status;
10696 }
Krunal Sonib4326f22016-03-10 13:05:51 -080010697 if ((pAdapter->device_mode == QDF_SAP_MODE) ||
10698 (pAdapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010699 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
10700 if (pHostapdState->bssState == BSS_START) {
Dustin Brown6ba30a12016-09-13 13:59:43 -070010701 status = wlansap_set_key_sta(
10702 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), &setKey);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010703 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010704 hdd_err("[%4d] wlansap_set_key_sta returned ERROR status= %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010705 __LINE__, status);
10706 }
10707 }
10708
10709 /* Save the key in ap ctx for use on START_BASS and restart */
10710 if (pairwise ||
10711 eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
10712 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType)
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010713 qdf_mem_copy(&ap_ctx->wepKey[key_index], &setKey,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010714 sizeof(tCsrRoamSetKey));
10715 else
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010716 qdf_mem_copy(&ap_ctx->groupKey, &setKey,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010717 sizeof(tCsrRoamSetKey));
10718
Krunal Sonib4326f22016-03-10 13:05:51 -080010719 } else if ((pAdapter->device_mode == QDF_STA_MODE) ||
10720 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010721 hdd_wext_state_t *pWextState =
10722 WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
10723 hdd_station_ctx_t *pHddStaCtx =
10724 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
10725
10726 if (!pairwise) {
10727 /* set group key */
10728 if (pHddStaCtx->roam_info.deferKeyComplete) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010729 hdd_notice("%s- %d: Perform Set key Complete",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010730 __func__, __LINE__);
10731 hdd_perform_roam_set_key_complete(pAdapter);
10732 }
10733 }
10734
10735 pWextState->roamProfile.Keys.KeyLength[key_index] =
10736 (u8) params->key_len;
10737
10738 pWextState->roamProfile.Keys.defaultIndex = key_index;
10739
Anurag Chouhan600c3a02016-03-01 10:33:54 +053010740 qdf_mem_copy(&pWextState->roamProfile.Keys.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010741 KeyMaterial[key_index][0], params->key,
10742 params->key_len);
10743
10744 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
10745
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010746 hdd_info("Set key for peerMac "MAC_ADDRESS_STR" direction %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010747 MAC_ADDR_ARRAY(setKey.peerMac.bytes),
10748 setKey.keyDirection);
10749
Jeff Johnsonf3826e12017-01-12 09:49:40 -080010750 /* The supplicant may attempt to set the PTK once
10751 * pre-authentication is done. Save the key in the
10752 * UMAC and include it in the ADD BSS request
10753 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010754 qdf_ret_status = sme_ft_update_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010755 pAdapter->sessionId, &setKey);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010756 if (qdf_ret_status == QDF_STATUS_FT_PREAUTH_KEY_SUCCESS) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010757 hdd_info("Update PreAuth Key success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010758 return 0;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010759 } else if (qdf_ret_status == QDF_STATUS_FT_PREAUTH_KEY_FAILED) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010760 hdd_err("Update PreAuth Key failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010761 return -EINVAL;
10762 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010763
10764 /* issue set key request to SME */
10765 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
10766 pAdapter->sessionId, &setKey, &roamId);
10767
10768 if (0 != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010769 hdd_err("sme_roam_set_key failed, returned %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010770 pHddStaCtx->roam_info.roamingState =
10771 HDD_ROAM_STATE_NONE;
10772 return -EINVAL;
10773 }
10774
Jeff Johnsonf3826e12017-01-12 09:49:40 -080010775 /* in case of IBSS as there was no information
10776 * available about WEP keys during IBSS join, group
10777 * key intialized with NULL key, so re-initialize
10778 * group key with correct value
10779 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780 if ((eCSR_BSS_TYPE_START_IBSS ==
10781 pWextState->roamProfile.BSSType)
10782 &&
10783 !((IW_AUTH_KEY_MGMT_802_1X ==
10784 (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
10785 && (eCSR_AUTH_TYPE_OPEN_SYSTEM ==
10786 pHddStaCtx->conn_info.authType)
10787 )
10788 && ((WLAN_CIPHER_SUITE_WEP40 == params->cipher)
10789 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
10790 )
10791 ) {
10792 setKey.keyDirection = eSIR_RX_ONLY;
Anurag Chouhanc5548422016-02-24 18:33:27 +053010793 qdf_set_macaddr_broadcast(&setKey.peerMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010794
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010795 hdd_info("Set key peerMac "MAC_ADDRESS_STR" direction %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010796 MAC_ADDR_ARRAY(setKey.peerMac.bytes),
10797 setKey.keyDirection);
10798
10799 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
10800 pAdapter->sessionId, &setKey,
10801 &roamId);
10802
10803 if (0 != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010804 hdd_err("sme_roam_set_key failed for group key (IBSS), returned %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010805 pHddStaCtx->roam_info.roamingState =
10806 HDD_ROAM_STATE_NONE;
10807 return -EINVAL;
10808 }
10809 }
10810 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053010811 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010812 return 0;
10813}
10814
10815static int wlan_hdd_cfg80211_add_key(struct wiphy *wiphy,
10816 struct net_device *ndev,
10817 u8 key_index, bool pairwise,
10818 const u8 *mac_addr,
10819 struct key_params *params)
10820{
10821 int ret;
10822 cds_ssr_protect(__func__);
10823 ret = __wlan_hdd_cfg80211_add_key(wiphy, ndev, key_index, pairwise,
10824 mac_addr, params);
10825 cds_ssr_unprotect(__func__);
10826
10827 return ret;
10828}
10829
10830/*
10831 * FUNCTION: __wlan_hdd_cfg80211_get_key
10832 * This function is used to get the key information
10833 */
10834static int __wlan_hdd_cfg80211_get_key(struct wiphy *wiphy,
10835 struct net_device *ndev,
10836 u8 key_index, bool pairwise,
10837 const u8 *mac_addr, void *cookie,
10838 void (*callback)(void *cookie,
10839 struct key_params *)
10840 )
10841{
10842 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
10843 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
10844 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
10845 struct key_params params;
10846
10847 ENTER();
10848
Anurag Chouhan6d760662016-02-20 16:05:43 +053010849 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010850 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010851 return -EINVAL;
10852 }
10853
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010854 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010855 hdd_device_mode_to_string(pAdapter->device_mode),
10856 pAdapter->device_mode);
10857
10858 memset(&params, 0, sizeof(params));
10859
10860 if (CSR_MAX_NUM_KEY <= key_index) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070010861 hdd_err("invalid key index %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010862 key_index);
10863 return -EINVAL;
10864 }
10865
10866 switch (pRoamProfile->EncryptionType.encryptionType[0]) {
10867 case eCSR_ENCRYPT_TYPE_NONE:
10868 params.cipher = IW_AUTH_CIPHER_NONE;
10869 break;
10870
10871 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
10872 case eCSR_ENCRYPT_TYPE_WEP40:
10873 params.cipher = WLAN_CIPHER_SUITE_WEP40;
10874 break;
10875
10876 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
10877 case eCSR_ENCRYPT_TYPE_WEP104:
10878 params.cipher = WLAN_CIPHER_SUITE_WEP104;
10879 break;
10880
10881 case eCSR_ENCRYPT_TYPE_TKIP:
10882 params.cipher = WLAN_CIPHER_SUITE_TKIP;
10883 break;
10884
10885 case eCSR_ENCRYPT_TYPE_AES:
10886 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
10887 break;
10888
10889 default:
10890 params.cipher = IW_AUTH_CIPHER_NONE;
10891 break;
10892 }
10893
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053010894 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010895 TRACE_CODE_HDD_CFG80211_GET_KEY,
10896 pAdapter->sessionId, params.cipher));
10897
10898 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
10899 params.seq_len = 0;
10900 params.seq = NULL;
10901 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
10902 callback(cookie, &params);
10903
10904 EXIT();
10905 return 0;
10906}
10907
10908static int wlan_hdd_cfg80211_get_key(struct wiphy *wiphy,
10909 struct net_device *ndev,
10910 u8 key_index, bool pairwise,
10911 const u8 *mac_addr, void *cookie,
10912 void (*callback)(void *cookie,
10913 struct key_params *)
10914 )
10915{
10916 int ret;
10917
10918 cds_ssr_protect(__func__);
10919 ret = __wlan_hdd_cfg80211_get_key(wiphy, ndev, key_index, pairwise,
10920 mac_addr, cookie, callback);
10921 cds_ssr_unprotect(__func__);
10922
10923 return ret;
10924}
10925
10926/**
10927 * __wlan_hdd_cfg80211_del_key() - Delete the encryption key for station
10928 * @wiphy: wiphy interface context
10929 * @ndev: pointer to net device
10930 * @key_index: Key index used in 802.11 frames
10931 * @unicast: true if it is unicast key
10932 * @multicast: true if it is multicast key
10933 *
10934 * This function is required for cfg80211_ops API.
10935 * It is used to delete the key information
10936 * Underlying hardware implementation does not have API to delete the
10937 * encryption key. It is automatically deleted when the peer is
10938 * removed. Hence this function currently does nothing.
10939 * Future implementation may interprete delete key operation to
10940 * replacing the key with a random junk value, effectively making it
10941 * useless.
10942 *
10943 * Return: status code, always 0.
10944 */
10945
10946static int __wlan_hdd_cfg80211_del_key(struct wiphy *wiphy,
10947 struct net_device *ndev,
10948 u8 key_index,
10949 bool pairwise, const u8 *mac_addr)
10950{
10951 EXIT();
10952 return 0;
10953}
10954
10955/**
10956 * wlan_hdd_cfg80211_del_key() - cfg80211 delete key handler function
10957 * @wiphy: Pointer to wiphy structure.
10958 * @dev: Pointer to net_device structure.
10959 * @key_index: key index
10960 * @pairwise: pairwise
10961 * @mac_addr: mac address
10962 *
10963 * This is the cfg80211 delete key handler function which invokes
10964 * the internal function @__wlan_hdd_cfg80211_del_key with
10965 * SSR protection.
10966 *
10967 * Return: 0 for success, error number on failure.
10968 */
10969static int wlan_hdd_cfg80211_del_key(struct wiphy *wiphy,
10970 struct net_device *dev,
10971 u8 key_index,
10972 bool pairwise, const u8 *mac_addr)
10973{
10974 int ret;
10975
10976 cds_ssr_protect(__func__);
10977 ret = __wlan_hdd_cfg80211_del_key(wiphy, dev, key_index,
10978 pairwise, mac_addr);
10979 cds_ssr_unprotect(__func__);
10980
10981 return ret;
10982}
10983
10984/*
10985 * FUNCTION: __wlan_hdd_cfg80211_set_default_key
10986 * This function is used to set the default tx key index
10987 */
10988static int __wlan_hdd_cfg80211_set_default_key(struct wiphy *wiphy,
10989 struct net_device *ndev,
10990 u8 key_index,
10991 bool unicast, bool multicast)
10992{
10993 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
10994 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
10995 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
10996 hdd_context_t *pHddCtx;
10997 int status;
10998
10999 ENTER();
11000
Anurag Chouhan6d760662016-02-20 16:05:43 +053011001 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011002 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011003 return -EINVAL;
11004 }
11005
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053011006 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
11007 hdd_err("invalid session id: %d", pAdapter->sessionId);
11008 return -EINVAL;
11009 }
11010
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053011011 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011012 TRACE_CODE_HDD_CFG80211_SET_DEFAULT_KEY,
11013 pAdapter->sessionId, key_index));
11014
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011015 hdd_notice("Device_mode %s(%d) key_index = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011016 hdd_device_mode_to_string(pAdapter->device_mode),
11017 pAdapter->device_mode, key_index);
11018
11019 if (CSR_MAX_NUM_KEY <= key_index) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011020 hdd_err("Invalid key index %d", key_index);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011021 return -EINVAL;
11022 }
11023
11024 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11025 status = wlan_hdd_validate_context(pHddCtx);
11026
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053011027 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011028 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011029
Krunal Sonib4326f22016-03-10 13:05:51 -080011030 if ((pAdapter->device_mode == QDF_STA_MODE) ||
11031 (pAdapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011032 if ((eCSR_ENCRYPT_TYPE_TKIP !=
11033 pHddStaCtx->conn_info.ucEncryptionType) &&
11034 (eCSR_ENCRYPT_TYPE_AES !=
11035 pHddStaCtx->conn_info.ucEncryptionType)) {
11036 /* If default key index is not same as previous one,
Jeff Johnsonf3826e12017-01-12 09:49:40 -080011037 * then update the default key index
11038 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011039
11040 tCsrRoamSetKey setKey;
11041 uint32_t roamId = 0xFF;
11042 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
11043
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011044 hdd_info("Default tx key index %d", key_index);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011045
11046 Keys->defaultIndex = (u8) key_index;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011047 qdf_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011048 setKey.keyId = key_index;
11049 setKey.keyLength = Keys->KeyLength[key_index];
11050
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011051 qdf_mem_copy(&setKey.Key[0],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011052 &Keys->KeyMaterial[key_index][0],
11053 Keys->KeyLength[key_index]);
11054
11055 setKey.keyDirection = eSIR_TX_RX;
11056
Anurag Chouhanc5548422016-02-24 18:33:27 +053011057 qdf_copy_macaddr(&setKey.peerMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011058 &pHddStaCtx->conn_info.bssId);
11059
11060 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
11061 pWextState->roamProfile.EncryptionType.
11062 encryptionType[0] == eCSR_ENCRYPT_TYPE_WEP104) {
Jeff Johnsonf3826e12017-01-12 09:49:40 -080011063 /* In the case of dynamic wep
11064 * supplicant hardcodes DWEP type to
11065 * eCSR_ENCRYPT_TYPE_WEP104 even
11066 * though ap is configured for WEP-40
11067 * encryption. In this canse the key
11068 * length is 5 but the encryption type
11069 * is 104 hence checking the key
11070 * lenght(5) and encryption type(104)
11071 * and switching encryption type to 40
11072 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011073 pWextState->roamProfile.EncryptionType.
11074 encryptionType[0] = eCSR_ENCRYPT_TYPE_WEP40;
11075 pWextState->roamProfile.mcEncryptionType.
11076 encryptionType[0] = eCSR_ENCRYPT_TYPE_WEP40;
11077 }
11078
11079 setKey.encType =
11080 pWextState->roamProfile.EncryptionType.
11081 encryptionType[0];
11082
11083 /* Issue set key request */
11084 status = sme_roam_set_key(WLAN_HDD_GET_HAL_CTX(pAdapter),
11085 pAdapter->sessionId, &setKey,
11086 &roamId);
11087
11088 if (0 != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011089 hdd_err("sme_roam_set_key failed, returned %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011090 status);
11091 return -EINVAL;
11092 }
11093 }
Krunal Sonib4326f22016-03-10 13:05:51 -080011094 } else if (QDF_SAP_MODE == pAdapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011095 /* In SoftAp mode setting key direction for default mode */
11096 if ((eCSR_ENCRYPT_TYPE_TKIP !=
11097 pWextState->roamProfile.EncryptionType.encryptionType[0])
11098 && (eCSR_ENCRYPT_TYPE_AES !=
11099 pWextState->roamProfile.EncryptionType.
11100 encryptionType[0])) {
11101 /* Saving key direction for default key index to TX default */
11102 hdd_ap_ctx_t *pAPCtx =
11103 WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
11104 pAPCtx->wepKey[key_index].keyDirection =
11105 eSIR_TX_DEFAULT;
Kondabattini, Ganesh702d90e2016-09-03 01:54:22 +053011106 hdd_info("WEP default key index set to SAP context %d",
Masti, Narayanraddiab712a72016-08-04 11:59:11 +053011107 key_index);
Kondabattini, Ganesh702d90e2016-09-03 01:54:22 +053011108 pAPCtx->wep_def_key_idx = key_index;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011109 }
11110 }
11111
11112 EXIT();
11113 return status;
11114}
11115
11116static int wlan_hdd_cfg80211_set_default_key(struct wiphy *wiphy,
11117 struct net_device *ndev,
11118 u8 key_index,
11119 bool unicast, bool multicast)
11120{
11121 int ret;
11122 cds_ssr_protect(__func__);
11123 ret =
11124 __wlan_hdd_cfg80211_set_default_key(wiphy, ndev, key_index, unicast,
11125 multicast);
11126 cds_ssr_unprotect(__func__);
11127
11128 return ret;
11129}
11130
Abhishek Singhc9941602016-08-09 16:06:22 +053011131/*
Abhishek Singhc9941602016-08-09 16:06:22 +053011132 * wlan_hdd_cfg80211_update_bss_list :to inform nl80211
11133 * interface that BSS might have been lost.
11134 * @pAdapter: adaptor
11135 * @bssid: bssid which might have been lost
11136 *
11137 * Return: bss which is unlinked from kernel cache
11138 */
11139struct cfg80211_bss *wlan_hdd_cfg80211_update_bss_list(
11140 hdd_adapter_t *pAdapter, tSirMacAddr bssid)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011141{
11142 struct net_device *dev = pAdapter->dev;
11143 struct wireless_dev *wdev = dev->ieee80211_ptr;
11144 struct wiphy *wiphy = wdev->wiphy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011145 struct cfg80211_bss *bss = NULL;
11146
Abhishek Singhb5e38ef2017-01-02 12:09:34 +053011147 bss = hdd_cfg80211_get_bss(wiphy, NULL, bssid,
Abhishek Singhc9941602016-08-09 16:06:22 +053011148 NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011149 if (bss == NULL) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011150 hdd_err("BSS not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011151 } else {
Abhishek Singhc9941602016-08-09 16:06:22 +053011152 hdd_info("cfg80211_unlink_bss called for BSSID "
11153 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(bssid));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011154 cfg80211_unlink_bss(wiphy, bss);
11155 }
11156 return bss;
11157}
11158
Abhishek Singhc9941602016-08-09 16:06:22 +053011159
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011160/**
11161 * wlan_hdd_cfg80211_inform_bss_frame() - inform bss details to NL80211
11162 * @pAdapter: Pointer to adapter
11163 * @bss_desc: Pointer to bss descriptor
11164 *
11165 * This function is used to inform the BSS details to nl80211 interface.
11166 *
11167 * Return: struct cfg80211_bss pointer
11168 */
Selvaraj, Sridharfe696d22016-08-03 21:34:51 +053011169struct cfg80211_bss *wlan_hdd_cfg80211_inform_bss_frame(hdd_adapter_t *pAdapter,
11170 tSirBssDescription *bss_desc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011171{
11172 /*
11173 * cfg80211_inform_bss() is not updating ie field of bss entry, if entry
11174 * already exists in bss data base of cfg80211 for that particular BSS
11175 * ID. Using cfg80211_inform_bss_frame to update the bss entry instead
11176 * of cfg80211_inform_bss, But this call expects mgmt packet as input.
11177 * As of now there is no possibility to get the mgmt(probe response)
11178 * frame from PE, converting bss_desc to ieee80211_mgmt(probe response)
11179 * and passing to cfg80211_inform_bss_frame.
11180 */
11181 struct net_device *dev = pAdapter->dev;
11182 struct wireless_dev *wdev = dev->ieee80211_ptr;
11183 struct wiphy *wiphy = wdev->wiphy;
11184 int chan_no = bss_desc->channelId;
11185#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
11186 qcom_ie_age *qie_age = NULL;
11187 int ie_length =
11188 GET_IE_LEN_IN_BSS_DESC(bss_desc->length) + sizeof(qcom_ie_age);
11189#else
11190 int ie_length = GET_IE_LEN_IN_BSS_DESC(bss_desc->length);
11191#endif
11192 const char *ie =
11193 ((ie_length != 0) ? (const char *)&bss_desc->ieFields : NULL);
11194 unsigned int freq;
11195 struct ieee80211_channel *chan;
11196 struct ieee80211_mgmt *mgmt = NULL;
11197 struct cfg80211_bss *bss_status = NULL;
11198 size_t frame_len = sizeof(struct ieee80211_mgmt) + ie_length;
11199 int rssi = 0;
11200 hdd_context_t *pHddCtx;
11201 int status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011202 struct timespec ts;
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -070011203 struct hdd_config *cfg_param;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011204
11205 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11206 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053011207 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011208 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011209
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -070011210 cfg_param = pHddCtx->config;
Mahesh Kumar Kalikot Veetil9c656182016-11-02 10:28:03 -070011211 mgmt = qdf_mem_malloc((sizeof(struct ieee80211_mgmt) + ie_length));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011212 if (!mgmt) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011213 hdd_err("memory allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011214 return NULL;
11215 }
11216
11217 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
11218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011219 /* Android does not want the timestamp from the frame.
Jeff Johnsonf3826e12017-01-12 09:49:40 -080011220 * Instead it wants a monotonic increasing value
11221 */
Yuanyuan Liu2e03b412016-04-06 14:36:15 -070011222 get_monotonic_boottime(&ts);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011223 mgmt->u.probe_resp.timestamp =
11224 ((u64) ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011225
11226 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
11227 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
11228
11229#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
11230 /* GPS Requirement: need age ie per entry. Using vendor specific. */
11231 /* Assuming this is the last IE, copy at the end */
11232 ie_length -= sizeof(qcom_ie_age);
11233 qie_age = (qcom_ie_age *) (mgmt->u.probe_resp.variable + ie_length);
11234 qie_age->element_id = QCOM_VENDOR_IE_ID;
11235 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
11236 qie_age->oui_1 = QCOM_OUI1;
11237 qie_age->oui_2 = QCOM_OUI2;
11238 qie_age->oui_3 = QCOM_OUI3;
11239 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
Deepthi Gowri6acee342016-10-28 15:00:38 +053011240 /*
11241 * Lowi expects the timestamp of bss in units of 1/10 ms. In driver
11242 * all bss related timestamp is in units of ms. Due to this when scan
11243 * results are sent to lowi the scan age is high.To address this,
11244 * send age in units of 1/10 ms.
11245 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011246 qie_age->age =
Sarada Prasanna Garnayakb3e06a62016-11-14 20:48:39 +053011247 (uint32_t)(qdf_mc_timer_get_system_time() - bss_desc->received_time)/10;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011248 qie_age->tsf_delta = bss_desc->tsf_delta;
Krishna Kumaar Natarajana4e12242016-04-01 18:44:39 -070011249 memcpy(&qie_age->beacon_tsf, bss_desc->timeStamp,
11250 sizeof(qie_age->beacon_tsf));
Krishna Kumaar Natarajan89a99d42016-08-04 15:44:38 -070011251 memcpy(&qie_age->seq_ctrl, &bss_desc->seq_ctrl,
11252 sizeof(qie_age->seq_ctrl));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011253#endif
11254
11255 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
11256 if (bss_desc->fProbeRsp) {
11257 mgmt->frame_control |=
11258 (u16) (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
11259 } else {
11260 mgmt->frame_control |=
11261 (u16) (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
11262 }
11263
11264 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_ghz) &&
Dustin Browna30892e2016-10-12 17:28:36 -070011265 (wiphy->bands[NL80211_BAND_2GHZ] != NULL)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011266 freq =
11267 ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -070011268 NL80211_BAND_2GHZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011269 } else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_ghz))
Dustin Browna30892e2016-10-12 17:28:36 -070011270 && (wiphy->bands[NL80211_BAND_5GHZ] != NULL)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011271 freq =
11272 ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -070011273 NL80211_BAND_5GHZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011274 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011275 hdd_err("Invalid chan_no %d", chan_no);
Mahesh Kumar Kalikot Veetil9c656182016-11-02 10:28:03 -070011276 qdf_mem_free(mgmt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011277 return NULL;
11278 }
11279
11280 chan = __ieee80211_get_channel(wiphy, freq);
11281 /* When the band is changed on the fly using the GUI, three things are done
11282 * 1. scan abort
11283 * 2. flush scan results from cache
11284 * 3. update the band with the new band user specified (refer to the
11285 * hdd_set_band_helper function) as part of the scan abort, message will be
11286 * queued to PE and we proceed with flushing and changinh the band.
11287 * PE will stop the scanning further and report back the results what ever
11288 * it had till now by calling the call back function.
11289 * if the time between update band and scandone call back is sufficient
11290 * enough the band change reflects in SME, SME validates the channels
11291 * and discards the channels correponding to previous band and calls back
11292 * with zero bss results. but if the time between band update and scan done
11293 * callback is very small then band change will not reflect in SME and SME
11294 * reports to HDD all the channels correponding to previous band.this is due
11295 * to race condition.but those channels are invalid to the new band and so
11296 * this function __ieee80211_get_channel will return NULL.Each time we
11297 * report scan result with this pointer null warning kernel trace is printed.
11298 * if the scan results contain large number of APs continuosly kernel
11299 * warning trace is printed and it will lead to apps watch dog bark.
11300 * So drop the bss and continue to next bss.
11301 */
11302 if (chan == NULL) {
Deepthi Gowri084c24d2016-09-01 15:55:09 +053011303 hdd_err("chan pointer is NULL, chan_no: %d freq: %d",
11304 chan_no, freq);
Mahesh Kumar Kalikot Veetil9c656182016-11-02 10:28:03 -070011305 qdf_mem_free(mgmt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011306 return NULL;
11307 }
11308
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -070011309 /* Based on .ini configuration, raw rssi can be reported for bss.
11310 * Raw rssi is typically used for estimating power.
11311 */
11312
11313 rssi = (cfg_param->inform_bss_rssi_raw) ? bss_desc->rssi_raw :
11314 bss_desc->rssi;
11315
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011316 /* Supplicant takes the signal strength in terms of mBm(100*dBm) */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011317 rssi = QDF_MIN(rssi, 0) * 100;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011318
SaidiReddy Yenuga1fa40972016-11-15 13:44:15 +053011319 hdd_log(LOG1, "BSSID: " MAC_ADDRESS_STR " Channel:%d RSSI:%d TSF %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011320 MAC_ADDR_ARRAY(mgmt->bssid), chan->center_freq,
Sandeep Puligilla394da5d2016-05-06 01:26:29 -070011321 (int)(rssi / 100),
11322 bss_desc->timeStamp[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011323
11324 bss_status =
11325 cfg80211_inform_bss_frame(wiphy, chan, mgmt, frame_len, rssi,
11326 GFP_KERNEL);
Padma, Santhosh Kumar31bac742017-01-16 19:34:45 +053011327 pHddCtx->beacon_probe_rsp_cnt_per_scan++;
Mahesh Kumar Kalikot Veetil9c656182016-11-02 10:28:03 -070011328 qdf_mem_free(mgmt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011329 return bss_status;
11330}
11331
11332/**
11333 * wlan_hdd_cfg80211_update_bss_db() - update bss database of CF80211
11334 * @pAdapter: Pointer to adapter
11335 * @pRoamInfo: Pointer to roam info
11336 *
11337 * This function is used to update the BSS data base of CFG8011
11338 *
11339 * Return: struct cfg80211_bss pointer
11340 */
11341struct cfg80211_bss *wlan_hdd_cfg80211_update_bss_db(hdd_adapter_t *pAdapter,
11342 tCsrRoamInfo *pRoamInfo)
11343{
11344 tCsrRoamConnectedProfile roamProfile;
11345 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
11346 struct cfg80211_bss *bss = NULL;
11347
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011348 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
11349 sme_roam_get_connect_profile(hHal, pAdapter->sessionId, &roamProfile);
11350
11351 if (NULL != roamProfile.pBssDesc) {
11352 bss = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
11353 roamProfile.pBssDesc);
11354
11355 if (NULL == bss)
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011356 hdd_notice("wlan_hdd_cfg80211_inform_bss_frame returned NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011357
Naveen Rawatdf0a7e72016-01-06 18:35:53 -080011358 sme_roam_free_connect_profile(&roamProfile);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011359 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011360 hdd_err("roamProfile.pBssDesc is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011361 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011362 return bss;
11363}
11364/**
11365 * wlan_hdd_cfg80211_update_bss() - update bss
11366 * @wiphy: Pointer to wiphy
11367 * @pAdapter: Pointer to adapter
11368 * @scan_time: scan request timestamp
11369 *
11370 * Return: zero if success, non-zero otherwise
11371 */
11372int wlan_hdd_cfg80211_update_bss(struct wiphy *wiphy,
11373 hdd_adapter_t *pAdapter,
11374 uint32_t scan_time)
11375{
11376 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
11377 tCsrScanResultInfo *pScanResult;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011378 QDF_STATUS status = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011379 tScanResultHandle pResult;
11380 struct cfg80211_bss *bss_status = NULL;
11381 hdd_context_t *pHddCtx;
11382 int ret;
11383
11384 ENTER();
11385
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053011386 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
11387 hdd_err("invalid session id: %d", pAdapter->sessionId);
11388 return -EINVAL;
11389 }
11390
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053011391 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011392 TRACE_CODE_HDD_CFG80211_UPDATE_BSS,
11393 NO_SESSION, pAdapter->sessionId));
11394
11395 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11396 ret = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053011397 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011398 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011399
11400 /* start getting scan results and populate cgf80211 BSS database */
11401 status = sme_scan_get_result(hHal, pAdapter->sessionId, NULL, &pResult);
11402
11403 /* no scan results */
11404 if (NULL == pResult) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011405 hdd_err("No scan result Status %d", status);
Kapil Gupta0ed58dc2016-04-22 15:35:26 +053011406 return -EAGAIN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011407 }
11408
11409 pScanResult = sme_scan_result_get_first(hHal, pResult);
11410
11411 while (pScanResult) {
11412 /*
11413 * - cfg80211_inform_bss() is not updating ie field of bss
11414 * entry if entry already exists in bss data base of cfg80211
11415 * for that particular BSS ID. Using cfg80211_inform_bss_frame
11416 * to update thebss entry instead of cfg80211_inform_bss,
11417 * But this call expects mgmt packet as input. As of now
11418 * there is no possibility to get the mgmt(probe response)
11419 * frame from PE, converting bss_desc to
11420 * ieee80211_mgmt(probe response) and passing to c
11421 * fg80211_inform_bss_frame.
11422 * - Update BSS only if beacon timestamp is later than
11423 * scan request timestamp.
11424 */
11425 if ((scan_time == 0) ||
11426 (scan_time <
Deepthi Gowri6acee342016-10-28 15:00:38 +053011427 pScanResult->BssDescriptor.received_time)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011428 bss_status =
11429 wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
11430 &pScanResult->BssDescriptor);
11431
11432 if (NULL == bss_status) {
11433 hdd_info("NULL returned by cfg80211_inform_bss_frame");
11434 } else {
11435 cfg80211_put_bss(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011436 wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011437 bss_status);
11438 }
11439 } else {
11440 hdd_info("BSSID: " MAC_ADDRESS_STR " Skipped",
11441 MAC_ADDR_ARRAY(pScanResult->BssDescriptor.bssId));
11442 }
11443 pScanResult = sme_scan_result_get_next(hHal, pResult);
11444 }
11445
11446 sme_scan_result_purge(hHal, pResult);
11447 /*
11448 * For SAP mode, scan is invoked by hostapd during SAP start
11449 * if hostapd is restarted, we need to flush previous scan
11450 * result so that it will reflect environment change
11451 */
Krunal Sonib4326f22016-03-10 13:05:51 -080011452 if (pAdapter->device_mode == QDF_SAP_MODE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011453#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
11454 && pHddCtx->skip_acs_scan_status != eSAP_SKIP_ACS_SCAN
11455#endif
11456 )
11457 sme_scan_flush_result(hHal);
11458
11459 EXIT();
11460 return 0;
11461}
11462
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011463/**
11464 * wlan_hdd_cfg80211_pmksa_candidate_notify() - notify a new PMSKA candidate
11465 * @pAdapter: Pointer to adapter
11466 * @pRoamInfo: Pointer to roam info
11467 * @index: Index
11468 * @preauth: Preauth flag
11469 *
11470 * This function is used to notify the supplicant of a new PMKSA candidate.
11471 *
11472 * Return: 0 for success, non-zero for failure
11473 */
11474int wlan_hdd_cfg80211_pmksa_candidate_notify(hdd_adapter_t *pAdapter,
11475 tCsrRoamInfo *pRoamInfo,
11476 int index, bool preauth)
11477{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011478 struct net_device *dev = pAdapter->dev;
11479 hdd_context_t *pHddCtx = (hdd_context_t *) pAdapter->pHddCtx;
11480
11481 ENTER();
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011482 hdd_notice("is going to notify supplicant of:");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011483
11484 if (NULL == pRoamInfo) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011485 hdd_alert("pRoamInfo is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011486 return -EINVAL;
11487 }
11488
11489 if (true == hdd_is_okc_mode_enabled(pHddCtx)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011490 hdd_notice(MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011491 MAC_ADDR_ARRAY(pRoamInfo->bssid.bytes));
11492 cfg80211_pmksa_candidate_notify(dev, index,
11493 pRoamInfo->bssid.bytes,
11494 preauth, GFP_KERNEL);
11495 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011496 return 0;
11497}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011498
11499#ifdef FEATURE_WLAN_LFR_METRICS
11500/**
11501 * wlan_hdd_cfg80211_roam_metrics_preauth() - roam metrics preauth
11502 * @pAdapter: Pointer to adapter
11503 * @pRoamInfo: Pointer to roam info
11504 *
11505 * 802.11r/LFR metrics reporting function to report preauth initiation
11506 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011507 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011508 */
11509#define MAX_LFR_METRICS_EVENT_LENGTH 100
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011510QDF_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011511 tCsrRoamInfo *pRoamInfo)
11512{
11513 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
11514 union iwreq_data wrqu;
11515
11516 ENTER();
11517
11518 if (NULL == pAdapter) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011519 hdd_err("pAdapter is NULL!");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011520 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011521 }
11522
11523 /* create the event */
11524 memset(&wrqu, 0, sizeof(wrqu));
11525 memset(metrics_notification, 0, sizeof(metrics_notification));
11526
11527 wrqu.data.pointer = metrics_notification;
11528 wrqu.data.length = scnprintf(metrics_notification,
11529 sizeof(metrics_notification),
11530 "QCOM: LFR_PREAUTH_INIT " MAC_ADDRESS_STR,
11531 MAC_ADDR_ARRAY(pRoamInfo->bssid));
11532
11533 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu,
11534 metrics_notification);
11535
11536 EXIT();
11537
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011538 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011539}
11540
11541/**
11542 * wlan_hdd_cfg80211_roam_metrics_handover() - roam metrics hand over
11543 * @pAdapter: Pointer to adapter
11544 * @pRoamInfo: Pointer to roam info
11545 * @preauth_status: Preauth status
11546 *
11547 * 802.11r/LFR metrics reporting function to report handover initiation
11548 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011549 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011550 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011551QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011552wlan_hdd_cfg80211_roam_metrics_preauth_status(hdd_adapter_t *pAdapter,
11553 tCsrRoamInfo *pRoamInfo,
11554 bool preauth_status)
11555{
11556 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
11557 union iwreq_data wrqu;
11558
11559 ENTER();
11560
11561 if (NULL == pAdapter) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011562 hdd_err("pAdapter is NULL!");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011563 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011564 }
11565
11566 /* create the event */
11567 memset(&wrqu, 0, sizeof(wrqu));
11568 memset(metrics_notification, 0, sizeof(metrics_notification));
11569
11570 scnprintf(metrics_notification, sizeof(metrics_notification),
11571 "QCOM: LFR_PREAUTH_STATUS " MAC_ADDRESS_STR,
11572 MAC_ADDR_ARRAY(pRoamInfo->bssid));
11573
11574 if (1 == preauth_status)
11575 strlcat(metrics_notification, " true",
11576 sizeof(metrics_notification));
11577 else
11578 strlcat(metrics_notification, " false",
11579 sizeof(metrics_notification));
11580
11581 wrqu.data.pointer = metrics_notification;
11582 wrqu.data.length = strlen(metrics_notification);
11583
11584 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu,
11585 metrics_notification);
11586
11587 EXIT();
11588
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011589 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011590}
11591
11592/**
11593 * wlan_hdd_cfg80211_roam_metrics_handover() - roam metrics hand over
11594 * @pAdapter: Pointer to adapter
11595 * @pRoamInfo: Pointer to roam info
11596 *
11597 * 802.11r/LFR metrics reporting function to report handover initiation
11598 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011599 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011600 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011601QDF_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t *pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011602 tCsrRoamInfo *pRoamInfo)
11603{
11604 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
11605 union iwreq_data wrqu;
11606
11607 ENTER();
11608
11609 if (NULL == pAdapter) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011610 hdd_err("pAdapter is NULL!");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011611 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011612 }
11613
11614 /* create the event */
11615 memset(&wrqu, 0, sizeof(wrqu));
11616 memset(metrics_notification, 0, sizeof(metrics_notification));
11617
11618 wrqu.data.pointer = metrics_notification;
11619 wrqu.data.length = scnprintf(metrics_notification,
11620 sizeof(metrics_notification),
11621 "QCOM: LFR_PREAUTH_HANDOVER "
11622 MAC_ADDRESS_STR,
11623 MAC_ADDR_ARRAY(pRoamInfo->bssid));
11624
11625 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu,
11626 metrics_notification);
11627
11628 EXIT();
11629
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011630 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011631}
11632#endif
11633
11634/**
11635 * hdd_select_cbmode() - select channel bonding mode
11636 * @pAdapter: Pointer to adapter
11637 * @operatingChannel: Operating channel
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011638 * @ch_params: channel info struct to populate
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011639 *
11640 * Return: none
11641 */
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011642void hdd_select_cbmode(hdd_adapter_t *pAdapter, uint8_t operationChannel,
11643 struct ch_params_s *ch_params)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011644{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011645 hdd_station_ctx_t *station_ctx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011646 struct hdd_mon_set_ch_info *ch_info = &station_ctx->ch_info;
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070011647 uint8_t sec_ch = 0;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011648
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070011649 /*
11650 * CDS api expects secondary channel for calculating
11651 * the channel params
11652 */
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011653 if ((ch_params->ch_width == CH_WIDTH_40MHZ) &&
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070011654 (CDS_IS_CHANNEL_24GHZ(operationChannel))) {
11655 if (operationChannel >= 1 && operationChannel <= 5)
11656 sec_ch = operationChannel + 4;
11657 else if (operationChannel >= 6 && operationChannel <= 13)
11658 sec_ch = operationChannel - 4;
11659 }
11660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011661 /* This call decides required channel bonding mode */
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011662 cds_set_channel_params(operationChannel, sec_ch, ch_params);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011663
11664 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam()) {
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011665 eHddDot11Mode hdd_dot11_mode;
11666 uint8_t iniDot11Mode =
11667 (WLAN_HDD_GET_CTX(pAdapter))->config->dot11Mode;
11668
11669 hdd_notice("Dot11Mode is %u", iniDot11Mode);
11670 switch (iniDot11Mode) {
11671 case eHDD_DOT11_MODE_AUTO:
11672 case eHDD_DOT11_MODE_11ac:
11673 case eHDD_DOT11_MODE_11ac_ONLY:
11674 if (sme_is_feature_supported_by_fw(DOT11AC))
11675 hdd_dot11_mode = eHDD_DOT11_MODE_11ac;
11676 else
11677 hdd_dot11_mode = eHDD_DOT11_MODE_11n;
11678 break;
11679 case eHDD_DOT11_MODE_11n:
11680 case eHDD_DOT11_MODE_11n_ONLY:
11681 hdd_dot11_mode = eHDD_DOT11_MODE_11n;
11682 break;
11683 default:
11684 hdd_dot11_mode = iniDot11Mode;
11685 break;
11686 }
11687 ch_info->channel_width = ch_params->ch_width;
11688 ch_info->phy_mode =
11689 hdd_cfg_xlate_to_csr_phy_mode(hdd_dot11_mode);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011690 ch_info->channel = operationChannel;
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011691 ch_info->cb_mode = ch_params->ch_width;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070011692 hdd_info("ch_info width %d, phymode %d channel %d",
11693 ch_info->channel_width, ch_info->phy_mode,
11694 ch_info->channel);
11695 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011696}
11697
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070011698/**
11699 * wlan_hdd_handle_sap_sta_dfs_conc() - to handle SAP STA DFS conc
11700 * @adapter: STA adapter
11701 * @roam_profile: STA roam profile
11702 *
11703 * This routine will move SAP from dfs to non-dfs, if sta is coming up.
11704 *
11705 * Return: false if sta-sap conc is not allowed, else return true
11706 */
11707static bool wlan_hdd_handle_sap_sta_dfs_conc(hdd_adapter_t *adapter,
11708 tCsrRoamProfile *roam_profile)
11709{
11710 hdd_context_t *hdd_ctx;
11711 hdd_adapter_t *ap_adapter;
11712 hdd_ap_ctx_t *hdd_ap_ctx;
11713 hdd_hostapd_state_t *hostapd_state;
11714 uint8_t channel = 0;
11715 QDF_STATUS status;
11716
11717 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11718 if (!hdd_ctx) {
11719 hdd_err("HDD context is NULL");
11720 return true;
11721 }
11722
11723 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
11724 /* probably no sap running, no handling required */
11725 if (ap_adapter == NULL)
11726 return true;
11727
11728 /*
11729 * sap is not in started state, so it is fine to go ahead with sta.
11730 * if sap is currently doing CAC then don't allow sta to go further.
11731 */
11732 if (!test_bit(SOFTAP_BSS_STARTED, &(ap_adapter)->event_flags) &&
11733 (hdd_ctx->dev_dfs_cac_status != DFS_CAC_IN_PROGRESS))
11734 return true;
11735
11736 if (hdd_ctx->dev_dfs_cac_status == DFS_CAC_IN_PROGRESS) {
11737 hdd_err("Concurrent SAP is in CAC state, STA is not allowed");
11738 return false;
11739 }
11740
11741 /*
11742 * log and return error, if we allow STA to go through, we don't
11743 * know what is going to happen better stop sta connection
11744 */
11745 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11746 if (NULL == hdd_ap_ctx) {
11747 hdd_err("AP context not found");
11748 return false;
11749 }
11750
11751 /* sap is on non-dfs channel, nothing to handle */
11752 if (!CDS_IS_DFS_CH(hdd_ap_ctx->operatingChannel)) {
11753 hdd_info("sap is on non-dfs channel, sta is allowed");
11754 return true;
11755 }
11756 /*
11757 * find out by looking in to scan cache where sta is going to
Nitesh Shah59774522016-09-16 15:14:21 +053011758 * connect by passing its roam_profile.
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070011759 */
11760 status = cds_get_channel_from_scan_result(adapter,
11761 roam_profile, &channel);
11762
Nitesh Shah59774522016-09-16 15:14:21 +053011763 /*
11764 * If the STA's channel is 2.4 GHz, then set pcl with only 2.4 GHz
11765 * channels for roaming case.
11766 */
11767 if (CDS_IS_CHANNEL_24GHZ(channel)) {
11768 hdd_info("sap is on dfs, new sta conn on 2.4 is allowed");
11769 return true;
11770 }
11771
11772 /*
11773 * If channel is 0 or DFS then better to call pcl and find out the
11774 * best channel. If channel is non-dfs 5 GHz then better move SAP
11775 * to STA's channel to make scc, so we have room for 3port MCC
11776 * scenario.
11777 */
11778 if ((0 == channel) || CDS_IS_DFS_CH(channel))
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070011779 channel = cds_get_nondfs_preferred_channel(CDS_SAP_MODE,
11780 true);
11781
11782 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
11783 qdf_event_reset(&hostapd_state->qdf_event);
11784 status = wlansap_set_channel_change_with_csa(
11785 WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter), channel,
11786 hdd_ap_ctx->sapConfig.ch_width_orig);
11787
11788 if (QDF_STATUS_SUCCESS != status) {
11789 hdd_err("Set channel with CSA IE failed, can't allow STA");
11790 return false;
11791 }
11792
11793 /*
11794 * wait here for SAP to finish the channel switch. When channel
11795 * switch happens, SAP sends few beacons with CSA_IE. After
11796 * successfully Transmission of those beacons, it will move its
11797 * state from started to disconnected and move to new channel.
11798 * once it moves to new channel, sap again moves its state
11799 * machine from disconnected to started and set this event.
11800 * wait for 10 secs to finish this.
11801 */
11802 status = qdf_wait_single_event(&hostapd_state->qdf_event, 10000);
11803 if (!QDF_IS_STATUS_SUCCESS(status)) {
11804 hdd_err("wait for qdf_event failed, STA not allowed!!");
11805 return false;
11806 }
11807
11808 return true;
11809}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011810
Krunal Soni31949422016-07-29 17:17:53 -070011811/**
11812 * wlan_hdd_cfg80211_connect_start() - to start the association process
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011813 * @pAdapter: Pointer to adapter
Krunal Soni31949422016-07-29 17:17:53 -070011814 * @ssid: Pointer to ssid
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011815 * @ssid_len: Length of ssid
11816 * @bssid: Pointer to bssid
Krunal Soni31949422016-07-29 17:17:53 -070011817 * @bssid_hint: Pointer to bssid hint
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011818 * @operatingChannel: Operating channel
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011819 * @ch_width: channel width. this is needed only for IBSS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011820 *
11821 * This function is used to start the association process
11822 *
11823 * Return: 0 for success, non-zero for failure
11824 */
Krunal Soni31949422016-07-29 17:17:53 -070011825static int wlan_hdd_cfg80211_connect_start(hdd_adapter_t *pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011826 const u8 *ssid, size_t ssid_len,
Krunal Soni31949422016-07-29 17:17:53 -070011827 const u8 *bssid, const u8 *bssid_hint,
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011828 u8 operatingChannel,
11829 enum nl80211_chan_width ch_width)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011830{
11831 int status = 0;
Rajeev Kumard31e1542017-01-13 14:37:42 -080011832 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011833 hdd_wext_state_t *pWextState;
11834 hdd_context_t *pHddCtx;
Anurag Chouhan5de8d172016-07-13 14:44:28 +053011835 hdd_station_ctx_t *hdd_sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011836 uint32_t roamId;
11837 tCsrRoamProfile *pRoamProfile;
11838 eCsrAuthType RSNAuthType;
11839 tSmeConfigParams *sme_config;
Nitesh Shah044fd672016-10-13 18:53:25 +053011840 uint8_t channel = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011841
11842 ENTER();
11843
11844 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11845 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Anurag Chouhan5de8d172016-07-13 14:44:28 +053011846 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011847
11848 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053011849 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011850 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011851
11852 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011853 hdd_err("wrong SSID len");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011854 return -EINVAL;
11855 }
11856
11857 pRoamProfile = &pWextState->roamProfile;
Anurag Chouhand939d3d2016-07-20 17:45:48 +053011858 qdf_mem_zero(&hdd_sta_ctx->conn_info.conn_flag,
11859 sizeof(hdd_sta_ctx->conn_info.conn_flag));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011860
11861 if (pRoamProfile) {
11862 hdd_station_ctx_t *pHddStaCtx;
11863 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11864
11865 if (HDD_WMM_USER_MODE_NO_QOS ==
11866 (WLAN_HDD_GET_CTX(pAdapter))->config->WmmMode) {
11867 /*QoS not enabled in cfg file */
11868 pRoamProfile->uapsd_mask = 0;
11869 } else {
11870 /*QoS enabled, update uapsd mask from cfg file */
11871 pRoamProfile->uapsd_mask =
11872 (WLAN_HDD_GET_CTX(pAdapter))->config->UapsdMask;
11873 }
11874
11875 pRoamProfile->SSIDs.numOfSSIDs = 1;
11876 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011877 qdf_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011878 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011879 qdf_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011880 ssid, ssid_len);
11881
Deepak Dhamdherea2785822016-11-17 01:17:45 -080011882 pRoamProfile->do_not_roam = !pAdapter->fast_roaming_allowed;
Abhishek Singh3c9910e2017-01-06 17:56:47 +053011883 /* cleanup bssid hint */
11884 qdf_mem_zero(pRoamProfile->bssid_hint.bytes,
11885 QDF_MAC_ADDR_SIZE);
11886 qdf_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),
11887 QDF_MAC_ADDR_SIZE);
11888
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011889 if (bssid) {
11890 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
Sreelakshmi Konamkibda5bbf2016-09-12 18:38:10 +053011891 pRoamProfile->do_not_roam = true;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011892 qdf_mem_copy((void *)(pRoamProfile->BSSIDs.bssid),
Anurag Chouhan6d760662016-02-20 16:05:43 +053011893 bssid, QDF_MAC_ADDR_SIZE);
Krunal Soni31949422016-07-29 17:17:53 -070011894 /*
11895 * Save BSSID in seperate variable as
11896 * pRoamProfile's BSSID is getting zeroed out in the
11897 * association process. In case of join failure
11898 * we should send valid BSSID to supplicant
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011899 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011900 qdf_mem_copy((void *)(pWextState->req_bssId.bytes),
Anurag Chouhan6d760662016-02-20 16:05:43 +053011901 bssid, QDF_MAC_ADDR_SIZE);
Krunal Soni35b404c2016-07-14 23:36:00 -070011902 hdd_info("bssid is given by upper layer %pM", bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011903 } else if (bssid_hint) {
Abhishek Singh3c9910e2017-01-06 17:56:47 +053011904 qdf_mem_copy(pRoamProfile->bssid_hint.bytes,
11905 bssid_hint, QDF_MAC_ADDR_SIZE);
Krunal Soni31949422016-07-29 17:17:53 -070011906 /*
11907 * Save BSSID in a separate variable as
11908 * pRoamProfile's BSSID is getting zeroed out in the
11909 * association process. In case of join failure
11910 * we should send valid BSSID to supplicant
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011911 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +053011912 qdf_mem_copy((void *)(pWextState->req_bssId.bytes),
Anurag Chouhan6d760662016-02-20 16:05:43 +053011913 bssid_hint, QDF_MAC_ADDR_SIZE);
Krunal Soni35b404c2016-07-14 23:36:00 -070011914 hdd_info("bssid_hint is given by upper layer %pM",
11915 bssid_hint);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011916 }
11917
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011918 hdd_notice("Connect to SSID: %.*s operating Channel: %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011919 pRoamProfile->SSIDs.SSIDList->SSID.length,
11920 pRoamProfile->SSIDs.SSIDList->SSID.ssId,
11921 operatingChannel);
11922
11923 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
11924 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011925 hdd_set_genie_to_csr(pAdapter, &RSNAuthType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011926 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
11927 }
11928#ifdef FEATURE_WLAN_WAPI
11929 if (pAdapter->wapi_info.nWapiMode) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011930 hdd_notice("Setting WAPI AUTH Type and Encryption Mode values");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011931 switch (pAdapter->wapi_info.wapiAuthMode) {
11932 case WAPI_AUTH_MODE_PSK:
11933 {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011934 hdd_notice("WAPI AUTH TYPE: PSK: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011935 pAdapter->wapi_info.wapiAuthMode);
11936 pRoamProfile->AuthType.authType[0] =
11937 eCSR_AUTH_TYPE_WAPI_WAI_PSK;
11938 break;
11939 }
11940 case WAPI_AUTH_MODE_CERT:
11941 {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011942 hdd_notice("WAPI AUTH TYPE: CERT: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011943 pAdapter->wapi_info.wapiAuthMode);
11944 pRoamProfile->AuthType.authType[0] =
11945 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
11946 break;
11947 }
11948 } /* End of switch */
11949 if (pAdapter->wapi_info.wapiAuthMode ==
11950 WAPI_AUTH_MODE_PSK
11951 || pAdapter->wapi_info.wapiAuthMode ==
11952 WAPI_AUTH_MODE_CERT) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011953 hdd_notice("WAPI PAIRWISE/GROUP ENCRYPTION: WPI");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011954 pRoamProfile->AuthType.numEntries = 1;
11955 pRoamProfile->EncryptionType.numEntries = 1;
11956 pRoamProfile->EncryptionType.encryptionType[0] =
11957 eCSR_ENCRYPT_TYPE_WPI;
11958 pRoamProfile->mcEncryptionType.numEntries = 1;
11959 pRoamProfile->mcEncryptionType.
11960 encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
11961 }
11962 }
Krunal Soni31949422016-07-29 17:17:53 -070011963#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011964#ifdef WLAN_FEATURE_GTK_OFFLOAD
11965 /* Initializing gtkOffloadReqParams */
Krunal Sonib4326f22016-03-10 13:05:51 -080011966 if ((QDF_STA_MODE == pAdapter->device_mode) ||
11967 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011968 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
11969 sizeof(tSirGtkOffloadParams));
11970 pHddStaCtx->gtkOffloadReqParams.ulFlags =
11971 GTK_OFFLOAD_DISABLE;
11972 }
11973#endif
11974 pRoamProfile->csrPersona = pAdapter->device_mode;
11975
11976 if (operatingChannel) {
11977 pRoamProfile->ChannelInfo.ChannelList =
11978 &operatingChannel;
11979 pRoamProfile->ChannelInfo.numOfChannels = 1;
11980 } else {
11981 pRoamProfile->ChannelInfo.ChannelList = NULL;
11982 pRoamProfile->ChannelInfo.numOfChannels = 0;
11983 }
Krunal Sonib4326f22016-03-10 13:05:51 -080011984 if ((QDF_IBSS_MODE == pAdapter->device_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011985 && operatingChannel) {
11986 /*
11987 * Need to post the IBSS power save parameters
11988 * to WMA. WMA will configure this parameters
11989 * to firmware if power save is enabled by the
11990 * firmware.
11991 */
11992 status = hdd_set_ibss_power_save_params(pAdapter);
11993
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011994 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070011995 hdd_err("Set IBSS Power Save Params Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011996 return -EINVAL;
11997 }
Naveen Rawatc77e6e72016-08-05 15:19:03 -070011998 pRoamProfile->ch_params.ch_width =
11999 hdd_map_nl_chan_width(ch_width);
Nitesh Shah87335a52016-09-05 15:47:32 +053012000 /*
12001 * In IBSS mode while operating in 2.4 GHz,
12002 * the device supports only 20 MHz.
12003 */
12004 if (CDS_IS_CHANNEL_24GHZ(operatingChannel))
12005 pRoamProfile->ch_params.ch_width =
12006 CH_WIDTH_20MHZ;
Naveen Rawatc77e6e72016-08-05 15:19:03 -070012007 hdd_select_cbmode(pAdapter, operatingChannel,
12008 &pRoamProfile->ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012009 }
Abhishek Singh99bce862016-06-20 15:10:51 +053012010 /*
12011 * if MFPEnabled is set but the peer AP is non-PMF i.e 80211w=2
12012 * or pmf=2 is an explicit configuration in the supplicant
12013 * configuration, drop the connection request.
12014 */
12015 if (pWextState->roamProfile.MFPEnabled &&
12016 !(pWextState->roamProfile.MFPRequired ||
12017 pWextState->roamProfile.MFPCapable)) {
12018 hdd_err("Drop connect req as supplicant has indicated PMF req for a non-PMF peer. MFPEnabled %d MFPRequired %d MFPCapable %d",
12019 pWextState->roamProfile.MFPEnabled,
12020 pWextState->roamProfile.MFPRequired,
12021 pWextState->roamProfile.MFPCapable);
12022 return -EINVAL;
12023 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012024
Krunal Soni3091bcc2016-06-23 12:28:21 -070012025 if (true == cds_is_connection_in_progress()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012026 hdd_err("Connection refused: conn in progress");
12027 return -EINVAL;
12028 }
12029
Krunal Soni31949422016-07-29 17:17:53 -070012030 /*
12031 * After 8-way handshake supplicant should give the scan command
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012032 * in that it update the additional IEs, But because of scan
Krunal Soni31949422016-07-29 17:17:53 -070012033 * enhancements, the supplicant is not issuing the scan command
12034 * now. So the unicast frames which are sent from the host are
12035 * not having the additional IEs. If it is P2P CLIENT and there
12036 * is no additional IE present in roamProfile, then use the
12037 * addtional IE form scan_info
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012038 */
12039
Krunal Sonib4326f22016-03-10 13:05:51 -080012040 if ((pAdapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012041 (!pRoamProfile->pAddIEScan)) {
12042 pRoamProfile->pAddIEScan =
12043 &pAdapter->scan_info.scanAddIE.addIEdata[0];
12044 pRoamProfile->nAddIEScanLength =
12045 pAdapter->scan_info.scanAddIE.length;
12046 }
12047 /*
12048 * When policy manager is enabled from ini file, we shouldn't
12049 * check for other concurrency rules.
12050 */
Krunal Soni3091bcc2016-06-23 12:28:21 -070012051 if (wma_is_hw_dbs_capable() == false) {
Tushnim Bhattacharyya4adb3682016-01-07 15:07:12 -080012052 cds_handle_conc_rule1(pAdapter, pRoamProfile);
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080012053 if (true != cds_handle_conc_rule2(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012054 pAdapter, pRoamProfile, &roamId))
12055 return 0;
12056 }
12057
Krunal Soni3091bcc2016-06-23 12:28:21 -070012058 if ((wma_is_hw_dbs_capable() == true) &&
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070012059 (false == wlan_hdd_handle_sap_sta_dfs_conc(pAdapter,
12060 pRoamProfile))) {
12061 hdd_err("sap-sta conc will fail, can't allow sta");
12062 hdd_conn_set_connection_state(pAdapter,
12063 eConnectionState_NotConnected);
12064 return -ENOMEM;
12065 }
12066
Anurag Chouhan600c3a02016-03-01 10:33:54 +053012067 sme_config = qdf_mem_malloc(sizeof(*sme_config));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012068 if (!sme_config) {
12069 hdd_err("unable to allocate sme_config");
Rajeev Kumar249ea8d2016-04-15 16:57:46 -070012070 hdd_conn_set_connection_state(pAdapter,
12071 eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012072 return -ENOMEM;
12073 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012074 sme_get_config_param(pHddCtx->hHal, sme_config);
12075 /* These values are not sessionized. So, any change in these SME
12076 * configs on an older or parallel interface will affect the
12077 * cb mode. So, restoring the default INI params before starting
12078 * interfaces such as sta, cli etc.,
12079 */
12080 sme_config->csrConfig.channelBondingMode5GHz =
12081 pHddCtx->config->nChannelBondingMode5GHz;
12082 sme_config->csrConfig.channelBondingMode24GHz =
12083 pHddCtx->config->nChannelBondingMode24GHz;
12084 sme_update_config(pHddCtx->hHal, sme_config);
Anurag Chouhan600c3a02016-03-01 10:33:54 +053012085 qdf_mem_free(sme_config);
Agrawal Ashish6b015762016-05-05 11:22:18 +053012086 /*
12087 * Change conn_state to connecting before sme_roam_connect(),
12088 * because sme_roam_connect() has a direct path to call
12089 * hdd_sme_roam_callback(), which will change the conn_state
12090 * If direct path, conn_state will be accordingly changed to
12091 * NotConnected or Associated by either
12092 * hdd_association_completion_handler() or
12093 * hdd_dis_connect_handler() in sme_RoamCallback()if
12094 * sme_RomConnect is to be queued,
12095 * Connecting state will remain until it is completed.
12096 *
12097 * If connection state is not changed, connection state will
12098 * remain in eConnectionState_NotConnected state.
12099 * In hdd_association_completion_handler, "hddDisconInProgress"
12100 * is set to true if conn state is
12101 * eConnectionState_NotConnected.
12102 * If "hddDisconInProgress" is set to true then cfg80211 layer
12103 * is not informed of connect result indication which
12104 * is an issue.
12105 */
12106 if (QDF_STA_MODE == pAdapter->device_mode ||
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012107 QDF_P2P_CLIENT_MODE == pAdapter->device_mode)
Agrawal Ashish6b015762016-05-05 11:22:18 +053012108 hdd_conn_set_connection_state(pAdapter,
12109 eConnectionState_Connecting);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012110
Komal Seelama89be8d2016-09-29 11:09:26 +053012111 qdf_runtime_pm_prevent_suspend(pAdapter->connect_rpm_ctx.
12112 connect);
Rajeev Kumard31e1542017-01-13 14:37:42 -080012113 qdf_status = sme_roam_connect(WLAN_HDD_GET_HAL_CTX(pAdapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012114 pAdapter->sessionId, pRoamProfile,
12115 &roamId);
12116
Rajeev Kumard31e1542017-01-13 14:37:42 -080012117 if ((QDF_STATUS_SUCCESS != qdf_status) &&
Krunal Sonib4326f22016-03-10 13:05:51 -080012118 (QDF_STA_MODE == pAdapter->device_mode ||
12119 QDF_P2P_CLIENT_MODE == pAdapter->device_mode)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012120 hdd_err("sme_roam_connect (session %d) failed with "
Rajeev Kumard31e1542017-01-13 14:37:42 -080012121 "qdf_status %d. -> NotConnected",
12122 pAdapter->sessionId, qdf_status);
12123 status = qdf_status_to_os_return(qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012124 /* change back to NotAssociated */
12125 hdd_conn_set_connection_state(pAdapter,
12126 eConnectionState_NotConnected);
Komal Seelama89be8d2016-09-29 11:09:26 +053012127 qdf_runtime_pm_allow_suspend(pAdapter->connect_rpm_ctx.
12128 connect);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012129 }
12130
12131 pRoamProfile->ChannelInfo.ChannelList = NULL;
12132 pRoamProfile->ChannelInfo.numOfChannels = 0;
12133
Nitesh Shah044fd672016-10-13 18:53:25 +053012134 if ((QDF_STA_MODE == pAdapter->device_mode)
Krunal Soni4274f362016-12-14 19:55:25 -080012135 && wma_is_current_hwmode_dbs()) {
Nitesh Shah044fd672016-10-13 18:53:25 +053012136 cds_get_channel_from_scan_result(pAdapter,
12137 pRoamProfile, &channel);
12138 if (channel)
12139 cds_checkn_update_hw_mode_single_mac_mode
12140 (channel);
12141 }
12142
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012143 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012144 hdd_err("No valid Roam profile");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012145 return -EINVAL;
12146 }
12147 EXIT();
12148 return status;
12149}
12150
12151/**
12152 * wlan_hdd_cfg80211_set_auth_type() - set auth type
12153 * @pAdapter: Pointer to adapter
12154 * @auth_type: Auth type
12155 *
12156 * This function is used to set the authentication type (OPEN/SHARED).
12157 *
12158 * Return: 0 for success, non-zero for failure
12159 */
12160static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
12161 enum nl80211_auth_type auth_type)
12162{
12163 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
12164 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
12165
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012166 /*set authentication type */
12167 switch (auth_type) {
12168 case NL80211_AUTHTYPE_AUTOMATIC:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012169 hdd_notice("set authentication type to AUTOSWITCH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012170 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
12171 break;
12172
12173 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012174 case NL80211_AUTHTYPE_FT:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012175 hdd_notice("set authentication type to OPEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012176 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
12177 break;
12178
12179 case NL80211_AUTHTYPE_SHARED_KEY:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012180 hdd_notice("set authentication type to SHARED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012181 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
12182 break;
12183#ifdef FEATURE_WLAN_ESE
12184 case NL80211_AUTHTYPE_NETWORK_EAP:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012185 hdd_notice("set authentication type to CCKM WPA");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012186 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;
12187 break;
12188#endif
12189
12190 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012191 hdd_err("Unsupported authentication type %d", auth_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012192 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
12193 return -EINVAL;
12194 }
12195
12196 pWextState->roamProfile.AuthType.authType[0] =
12197 pHddStaCtx->conn_info.authType;
12198 return 0;
12199}
12200
12201/**
12202 * wlan_hdd_set_akm_suite() - set key management type
12203 * @pAdapter: Pointer to adapter
12204 * @key_mgmt: Key management type
12205 *
12206 * This function is used to set the key mgmt type(PSK/8021x).
12207 *
12208 * Return: 0 for success, non-zero for failure
12209 */
12210static int wlan_hdd_set_akm_suite(hdd_adapter_t *pAdapter, u32 key_mgmt)
12211{
12212 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
12213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012214#define WLAN_AKM_SUITE_8021X_SHA256 0x000FAC05
12215#define WLAN_AKM_SUITE_PSK_SHA256 0x000FAC06
12216 /*set key mgmt type */
12217 switch (key_mgmt) {
12218 case WLAN_AKM_SUITE_PSK:
12219 case WLAN_AKM_SUITE_PSK_SHA256:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012220 case WLAN_AKM_SUITE_FT_PSK:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012221 hdd_notice("setting key mgmt type to PSK");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012222 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
12223 break;
12224
12225 case WLAN_AKM_SUITE_8021X_SHA256:
12226 case WLAN_AKM_SUITE_8021X:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012227 case WLAN_AKM_SUITE_FT_8021X:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012228 hdd_notice("setting key mgmt type to 8021x");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012229 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
12230 break;
12231#ifdef FEATURE_WLAN_ESE
12232#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
12233#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
12234 case WLAN_AKM_SUITE_CCKM:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012235 hdd_notice("setting key mgmt type to CCKM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012236 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
12237 break;
12238#endif
12239#ifndef WLAN_AKM_SUITE_OSEN
12240#define WLAN_AKM_SUITE_OSEN 0x506f9a01 /* Should be in ieee802_11_defs.h */
12241#endif
12242 case WLAN_AKM_SUITE_OSEN:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012243 hdd_notice("setting key mgmt type to OSEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012244 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
12245 break;
12246
12247 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012248 hdd_err("Unsupported key mgmt type %d", key_mgmt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012249 return -EINVAL;
12250
12251 }
12252 return 0;
12253}
12254
12255/**
12256 * wlan_hdd_cfg80211_set_cipher() - set encryption type
12257 * @pAdapter: Pointer to adapter
12258 * @cipher: Cipher type
12259 * @ucast: Unicast flag
12260 *
12261 * This function is used to set the encryption type
12262 * (NONE/WEP40/WEP104/TKIP/CCMP).
12263 *
12264 * Return: 0 for success, non-zero for failure
12265 */
12266static int wlan_hdd_cfg80211_set_cipher(hdd_adapter_t *pAdapter,
12267 u32 cipher, bool ucast)
12268{
12269 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
12270 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
12271 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
12272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012273 if (!cipher) {
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -080012274 hdd_info("received cipher %d - considering none", cipher);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012275 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
12276 } else {
12277
12278 /*set encryption method */
12279 switch (cipher) {
12280 case IW_AUTH_CIPHER_NONE:
12281 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
12282 break;
12283
12284 case WLAN_CIPHER_SUITE_WEP40:
12285 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
12286 break;
12287
12288 case WLAN_CIPHER_SUITE_WEP104:
12289 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
12290 break;
12291
12292 case WLAN_CIPHER_SUITE_TKIP:
12293 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
12294 break;
12295
12296 case WLAN_CIPHER_SUITE_CCMP:
12297 encryptionType = eCSR_ENCRYPT_TYPE_AES;
12298 break;
12299#ifdef FEATURE_WLAN_WAPI
12300 case WLAN_CIPHER_SUITE_SMS4:
12301 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
12302 break;
12303#endif
12304
12305#ifdef FEATURE_WLAN_ESE
12306 case WLAN_CIPHER_SUITE_KRK:
12307 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
12308 break;
12309#ifdef WLAN_FEATURE_ROAM_OFFLOAD
12310 case WLAN_CIPHER_SUITE_BTK:
12311 encryptionType = eCSR_ENCRYPT_TYPE_BTK;
12312 break;
12313#endif
12314#endif
12315 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012316 hdd_err("Unsupported cipher type %d", cipher);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012317 return -EOPNOTSUPP;
12318 }
12319 }
12320
12321 if (ucast) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012322 hdd_notice("setting unicast cipher type to %d", encryptionType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012323 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
12324 pWextState->roamProfile.EncryptionType.numEntries = 1;
12325 pWextState->roamProfile.EncryptionType.encryptionType[0] =
12326 encryptionType;
12327 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012328 hdd_notice("setting mcast cipher type to %d", encryptionType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012329 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
12330 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
12331 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
12332 encryptionType;
12333 }
12334
12335 return 0;
12336}
12337
12338/**
Selvaraj, Sridhara7fc7632016-09-04 13:13:38 +053012339 * wlan_hdd_add_assoc_ie() - Add Assoc IE to roamProfile
12340 * @wext_state: Pointer to wext state
12341 * @gen_ie: Pointer to IE data
12342 * @len: length of IE data
12343 *
12344 * Return: 0 for success, non-zero for failure
12345 */
12346static int wlan_hdd_add_assoc_ie(hdd_wext_state_t *wext_state,
12347 const uint8_t *gen_ie, uint16_t len)
12348{
12349 uint16_t cur_add_ie_len =
12350 wext_state->assocAddIE.length;
12351
12352 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12353 (wext_state->assocAddIE.length + len)) {
12354 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
12355 QDF_ASSERT(0);
12356 return -ENOMEM;
12357 }
12358 memcpy(wext_state->assocAddIE.addIEdata +
12359 cur_add_ie_len, gen_ie, len);
12360 wext_state->assocAddIE.length += len;
12361
12362 wext_state->roamProfile.pAddIEAssoc =
12363 wext_state->assocAddIE.addIEdata;
12364 wext_state->roamProfile.nAddIEAssocLength =
12365 wext_state->assocAddIE.length;
12366 return 0;
12367}
12368
12369/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012370 * wlan_hdd_cfg80211_set_ie() - set IEs
12371 * @pAdapter: Pointer to adapter
12372 * @ie: Pointer ot ie
12373 * @ie: IE length
12374 *
12375 * Return: 0 for success, non-zero for failure
12376 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070012377static int wlan_hdd_cfg80211_set_ie(hdd_adapter_t *pAdapter, const uint8_t *ie,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012378 size_t ie_len)
12379{
12380 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
12381 const uint8_t *genie = ie;
12382 uint16_t remLen = ie_len;
12383#ifdef FEATURE_WLAN_WAPI
12384 uint32_t akmsuite[MAX_NUM_AKM_SUITES];
12385 u16 *tmp;
12386 uint16_t akmsuiteCount;
12387 int *akmlist;
12388#endif
Selvaraj, Sridhara7fc7632016-09-04 13:13:38 +053012389 int status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012390
12391 /* clear previous assocAddIE */
12392 pWextState->assocAddIE.length = 0;
12393 pWextState->roamProfile.bWPSAssociation = false;
12394 pWextState->roamProfile.bOSENAssociation = false;
12395
12396 while (remLen >= 2) {
12397 uint16_t eLen = 0;
12398 uint8_t elementId;
12399 elementId = *genie++;
12400 eLen = *genie++;
12401 remLen -= 2;
12402
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012403 hdd_notice("IE[0x%X], LEN[%d]", elementId, eLen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012404
12405 switch (elementId) {
12406 case DOT11F_EID_WPA:
12407 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 -070012408 hdd_err("Invalid WPA IE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012409 return -EINVAL;
12410 } else if (0 ==
12411 memcmp(&genie[0], "\x00\x50\xf2\x04", 4)) {
12412 uint16_t curAddIELen =
12413 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012414 hdd_notice("Set WPS IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012415
12416 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12417 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012418 hdd_err("Cannot accommodate assocAddIE. Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012419 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012420 return -ENOMEM;
12421 }
12422 /* WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE */
12423 memcpy(pWextState->assocAddIE.addIEdata +
12424 curAddIELen, genie - 2, eLen + 2);
12425 pWextState->assocAddIE.length += eLen + 2;
12426
12427 pWextState->roamProfile.bWPSAssociation = true;
12428 pWextState->roamProfile.pAddIEAssoc =
12429 pWextState->assocAddIE.addIEdata;
12430 pWextState->roamProfile.nAddIEAssocLength =
12431 pWextState->assocAddIE.length;
12432 } else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012433 hdd_notice("Set WPA IE (len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012434 memset(pWextState->WPARSNIE, 0,
12435 MAX_WPA_RSN_IE_LEN);
12436 memcpy(pWextState->WPARSNIE, genie - 2,
12437 (eLen + 2));
12438 pWextState->roamProfile.pWPAReqIE =
12439 pWextState->WPARSNIE;
12440 pWextState->roamProfile.nWPAReqIELength = eLen + 2; /* ie_len; */
12441 } else if ((0 == memcmp(&genie[0], P2P_OUI_TYPE,
12442 P2P_OUI_TYPE_SIZE))) {
12443 uint16_t curAddIELen =
12444 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012445 hdd_notice("Set P2P IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012446
12447 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12448 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012449 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012450 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012451 return -ENOMEM;
12452 }
12453 /* P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE */
12454 memcpy(pWextState->assocAddIE.addIEdata +
12455 curAddIELen, genie - 2, eLen + 2);
12456 pWextState->assocAddIE.length += eLen + 2;
12457
12458 pWextState->roamProfile.pAddIEAssoc =
12459 pWextState->assocAddIE.addIEdata;
12460 pWextState->roamProfile.nAddIEAssocLength =
12461 pWextState->assocAddIE.length;
12462 }
12463#ifdef WLAN_FEATURE_WFD
12464 else if ((0 == memcmp(&genie[0], WFD_OUI_TYPE,
12465 WFD_OUI_TYPE_SIZE)) &&
12466 /* Consider WFD IE, only for P2P Client */
Krunal Sonib4326f22016-03-10 13:05:51 -080012467 (QDF_P2P_CLIENT_MODE ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012468 pAdapter->device_mode)) {
12469 uint16_t curAddIELen =
12470 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012471 hdd_notice("Set WFD IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012472
12473 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12474 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012475 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012476 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012477 return -ENOMEM;
12478 }
12479 /* WFD IE is saved to Additional IE ; it should
12480 * be accumulated to handle WPS IE + P2P IE +
Jeff Johnsonf3826e12017-01-12 09:49:40 -080012481 * WFD IE
12482 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012483 memcpy(pWextState->assocAddIE.addIEdata +
12484 curAddIELen, genie - 2, eLen + 2);
12485 pWextState->assocAddIE.length += eLen + 2;
12486
12487 pWextState->roamProfile.pAddIEAssoc =
12488 pWextState->assocAddIE.addIEdata;
12489 pWextState->roamProfile.nAddIEAssocLength =
12490 pWextState->assocAddIE.length;
12491 }
12492#endif
12493 /* Appending HS 2.0 Indication Element in Assiciation Request */
12494 else if ((0 == memcmp(&genie[0], HS20_OUI_TYPE,
12495 HS20_OUI_TYPE_SIZE))) {
12496 uint16_t curAddIELen =
12497 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012498 hdd_notice("Set HS20 IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012499
12500 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12501 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012502 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012503 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012504 return -ENOMEM;
12505 }
12506 memcpy(pWextState->assocAddIE.addIEdata +
12507 curAddIELen, genie - 2, eLen + 2);
12508 pWextState->assocAddIE.length += eLen + 2;
12509
12510 pWextState->roamProfile.pAddIEAssoc =
12511 pWextState->assocAddIE.addIEdata;
12512 pWextState->roamProfile.nAddIEAssocLength =
12513 pWextState->assocAddIE.length;
12514 }
12515 /* Appending OSEN Information Element in Assiciation Request */
12516 else if ((0 == memcmp(&genie[0], OSEN_OUI_TYPE,
12517 OSEN_OUI_TYPE_SIZE))) {
12518 uint16_t curAddIELen =
12519 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012520 hdd_notice("Set OSEN IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012521
12522 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12523 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012524 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012525 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012526 return -ENOMEM;
12527 }
12528 memcpy(pWextState->assocAddIE.addIEdata +
12529 curAddIELen, genie - 2, eLen + 2);
12530 pWextState->assocAddIE.length += eLen + 2;
12531
12532 pWextState->roamProfile.bOSENAssociation = true;
12533 pWextState->roamProfile.pAddIEAssoc =
12534 pWextState->assocAddIE.addIEdata;
12535 pWextState->roamProfile.nAddIEAssocLength =
12536 pWextState->assocAddIE.length;
Selvaraj, Sridhara7fc7632016-09-04 13:13:38 +053012537 } else if ((0 == memcmp(&genie[0], MBO_OUI_TYPE,
12538 MBO_OUI_TYPE_SIZE))){
12539 hdd_info("Set MBO IE(len %d)", eLen + 2);
12540 status = wlan_hdd_add_assoc_ie(pWextState,
12541 genie - 2, eLen + 2);
12542 if (status)
12543 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012544 } else {
12545 uint16_t add_ie_len =
12546 pWextState->assocAddIE.length;
12547
12548 hdd_info("Set OSEN IE(len %d)", eLen + 2);
12549
12550 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12551 (pWextState->assocAddIE.length + eLen)) {
12552 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012553 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012554 return -ENOMEM;
12555 }
12556
12557 memcpy(pWextState->assocAddIE.addIEdata +
12558 add_ie_len, genie - 2, eLen + 2);
12559 pWextState->assocAddIE.length += eLen + 2;
12560
12561 pWextState->roamProfile.pAddIEAssoc =
12562 pWextState->assocAddIE.addIEdata;
12563 pWextState->roamProfile.nAddIEAssocLength =
12564 pWextState->assocAddIE.length;
12565 }
12566 break;
12567 case DOT11F_EID_RSN:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012568 hdd_notice("Set RSN IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012569 memset(pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN);
12570 memcpy(pWextState->WPARSNIE, genie - 2,
12571 (eLen + 2));
12572 pWextState->roamProfile.pRSNReqIE =
12573 pWextState->WPARSNIE;
12574 pWextState->roamProfile.nRSNReqIELength = eLen + 2; /* ie_len; */
12575 break;
12576 /*
12577 * Appending Extended Capabilities with Interworking bit set
12578 * in Assoc Req.
12579 *
12580 * In assoc req this EXT Cap will only be taken into account if
12581 * interworkingService bit is set to 1. Currently
12582 * driver is only interested in interworkingService capability
12583 * from supplicant. If in future any other EXT Cap info is
12584 * required from supplicat, it needs to be handled while
12585 * sending Assoc Req in LIM.
12586 */
12587 case DOT11F_EID_EXTCAP:
12588 {
12589 uint16_t curAddIELen =
12590 pWextState->assocAddIE.length;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012591 hdd_notice("Set Extended CAPS IE(len %d)", eLen + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012592
12593 if (SIR_MAC_MAX_ADD_IE_LENGTH <
12594 (pWextState->assocAddIE.length + eLen)) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012595 hdd_err("Cannot accommodate assocAddIE Need bigger buffer space");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012596 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012597 return -ENOMEM;
12598 }
12599 memcpy(pWextState->assocAddIE.addIEdata +
12600 curAddIELen, genie - 2, eLen + 2);
12601 pWextState->assocAddIE.length += eLen + 2;
12602
12603 pWextState->roamProfile.pAddIEAssoc =
12604 pWextState->assocAddIE.addIEdata;
12605 pWextState->roamProfile.nAddIEAssocLength =
12606 pWextState->assocAddIE.length;
12607 break;
12608 }
12609#ifdef FEATURE_WLAN_WAPI
12610 case WLAN_EID_WAPI:
12611 /* Setting WAPI Mode to ON=1 */
12612 pAdapter->wapi_info.nWapiMode = 1;
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012613 hdd_notice("WAPI MODE IS %u", pAdapter->wapi_info.nWapiMode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012614 tmp = (u16 *) ie;
12615 tmp = tmp + 2; /* Skip element Id and Len, Version */
12616 akmsuiteCount = WPA_GET_LE16(tmp);
12617 tmp = tmp + 1;
12618 akmlist = (int *)(tmp);
12619 if (akmsuiteCount <= MAX_NUM_AKM_SUITES) {
12620 memcpy(akmsuite, akmlist, (4 * akmsuiteCount));
12621 } else {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012622 hdd_err("Invalid akmSuite count");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012623 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012624 return -EINVAL;
12625 }
12626
12627 if (WAPI_PSK_AKM_SUITE == akmsuite[0]) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012628 hdd_notice("WAPI AUTH MODE SET TO PSK");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012629 pAdapter->wapi_info.wapiAuthMode =
12630 WAPI_AUTH_MODE_PSK;
12631 }
12632 if (WAPI_CERT_AKM_SUITE == akmsuite[0]) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012633 hdd_notice("WAPI AUTH MODE SET TO CERTIFICATE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012634 pAdapter->wapi_info.wapiAuthMode =
12635 WAPI_AUTH_MODE_CERT;
12636 }
12637 break;
12638#endif
Selvaraj, Sridhara7fc7632016-09-04 13:13:38 +053012639 case DOT11F_EID_SUPPOPERATINGCLASSES:
12640 {
12641 hdd_info("Set Supported Operating Classes IE(len %d)", eLen + 2);
12642 status = wlan_hdd_add_assoc_ie(pWextState,
12643 genie - 2, eLen + 2);
12644 if (status)
12645 return status;
12646 break;
12647 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012648 default:
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012649 hdd_err("Set UNKNOWN IE %X", elementId);
Jeff Johnsonf3826e12017-01-12 09:49:40 -080012650 /* when Unknown IE is received we break
12651 * and continue to the next IE in the buffer
12652 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012653 break;
12654 }
12655 genie += eLen;
12656 remLen -= eLen;
12657 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012658 return 0;
12659}
12660
12661/**
12662 * hdd_is_wpaie_present() - check for WPA ie
12663 * @ie: Pointer to ie
12664 * @ie_len: Ie length
12665 *
12666 * Parse the received IE to find the WPA IE
12667 *
12668 * Return: true if wpa ie is found else false
12669 */
12670static bool hdd_is_wpaie_present(const uint8_t *ie, uint8_t ie_len)
12671{
12672 uint8_t eLen = 0;
12673 uint16_t remLen = ie_len;
12674 uint8_t elementId = 0;
12675
12676 while (remLen >= 2) {
12677 elementId = *ie++;
12678 eLen = *ie++;
12679 remLen -= 2;
12680 if (eLen > remLen) {
Jeff Johnsonff5b9aa2016-06-29 15:10:30 -070012681 hdd_err("IE length is wrong %d", eLen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012682 return false;
12683 }
12684 if ((elementId == DOT11F_EID_WPA) && (remLen > 5)) {
12685 /* OUI - 0x00 0X50 0XF2
12686 * WPA Information Element - 0x01
12687 * WPA version - 0x01
12688 */
12689 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
12690 return true;
12691 }
12692 ie += eLen;
12693 remLen -= eLen;
12694 }
12695 return false;
12696}
12697
12698/**
12699 * wlan_hdd_cfg80211_set_privacy() - set security parameters during connection
12700 * @pAdapter: Pointer to adapter
12701 * @req: Pointer to security parameters
12702 *
12703 * Return: 0 for success, non-zero for failure
12704 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070012705static int wlan_hdd_cfg80211_set_privacy(hdd_adapter_t *pAdapter,
12706 struct cfg80211_connect_params *req)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012707{
12708 int status = 0;
12709 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
12710 ENTER();
12711
12712 /*set wpa version */
12713 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
12714
12715 if (req->crypto.wpa_versions) {
12716 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions) {
12717 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
12718 } else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions) {
12719 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
12720 }
12721 }
12722
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012723 hdd_notice("set wpa version to %d", pWextState->wpaVersion);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012724
12725 /*set authentication type */
12726 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
12727
12728 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012729 hdd_err("failed to set authentication type ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012730 return status;
12731 }
12732
12733 /*set key mgmt type */
12734 if (req->crypto.n_akm_suites) {
12735 status =
12736 wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
12737 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012738 hdd_err("failed to set akm suite");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012739 return status;
12740 }
12741 }
12742
12743 /*set pairwise cipher type */
12744 if (req->crypto.n_ciphers_pairwise) {
12745 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
12746 req->crypto.
12747 ciphers_pairwise[0],
12748 true);
12749 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012750 hdd_err("failed to set unicast cipher type");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012751 return status;
12752 }
12753 } else {
12754 /*Reset previous cipher suite to none */
12755 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
12756 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012757 hdd_err("failed to set unicast cipher type");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012758 return status;
12759 }
12760 }
12761
12762 /*set group cipher type */
12763 status =
12764 wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
12765 false);
12766
12767 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012768 hdd_err("failed to set mcast cipher type");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012769 return status;
12770 }
12771#ifdef WLAN_FEATURE_11W
12772 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
12773#endif
12774
12775 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile */
12776 if (req->ie_len) {
12777 status =
12778 wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
12779 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012780 hdd_err("failed to parse the WPA/RSN IE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012781 return status;
12782 }
12783 }
12784
12785 /*incase of WEP set default key information */
12786 if (req->key && req->key_len) {
12787 if ((WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
12788 || (WLAN_CIPHER_SUITE_WEP104 ==
12789 req->crypto.ciphers_pairwise[0])
12790 ) {
12791 if (IW_AUTH_KEY_MGMT_802_1X
12792 ==
12793 (pWextState->
12794 authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012795 hdd_err("Dynamic WEP not supported");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012796 return -EOPNOTSUPP;
12797 } else {
12798 u8 key_len = req->key_len;
12799 u8 key_idx = req->key_idx;
12800
12801 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >=
12802 key_len)
12803 && (CSR_MAX_NUM_KEY > key_idx)
12804 ) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012805 hdd_notice("setting default wep key, key_idx = %hu key_len %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012806 key_idx, key_len);
Anurag Chouhan600c3a02016-03-01 10:33:54 +053012807 qdf_mem_copy(&pWextState->roamProfile.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012808 Keys.
12809 KeyMaterial[key_idx][0],
12810 req->key, key_len);
12811 pWextState->roamProfile.Keys.
12812 KeyLength[key_idx] = (u8) key_len;
12813 pWextState->roamProfile.Keys.
12814 defaultIndex = (u8) key_idx;
12815 }
12816 }
12817 }
12818 }
12819
12820 return status;
12821}
12822
12823/**
12824 * wlan_hdd_try_disconnect() - try disconnnect from previous connection
12825 * @pAdapter: Pointer to adapter
12826 *
12827 * This function is used to disconnect from previous connection
12828 *
12829 * Return: 0 for success, non-zero for failure
12830 */
12831static int wlan_hdd_try_disconnect(hdd_adapter_t *pAdapter)
12832{
12833 unsigned long rc;
12834 hdd_station_ctx_t *pHddStaCtx;
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012835 int status, result = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012836
12837 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
12838
Jeff Johnson9edf9572016-10-03 15:24:49 -070012839 if ((QDF_IBSS_MODE == pAdapter->device_mode) ||
Abhishek Singh03f992e2016-01-07 18:07:06 +053012840 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
12841 (eConnectionState_Connecting == pHddStaCtx->conn_info.connState) ||
12842 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012843 hdd_conn_set_connection_state(pAdapter,
12844 eConnectionState_Disconnecting);
12845 /* Issue disconnect to CSR */
12846 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012847
12848 status = sme_roam_disconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
12849 pAdapter->sessionId,
12850 eCSR_DISCONNECT_REASON_UNSPECIFIED);
12851 /*
12852 * Wait here instead of returning directly, this will block the
12853 * next connect command and allow processing of the scan for
12854 * ssid and the previous connect command in CSR. Else we might
12855 * hit some race conditions leading to SME and HDD out of sync.
12856 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012857 if (QDF_STATUS_CMD_NOT_QUEUED == status) {
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012858 hdd_info("Already disconnected or connect was in sme/roam pending list and removed by disconnect");
12859 } else if (0 != status) {
12860 hdd_err("csrRoamDisconnect failure, returned %d",
12861 (int)status);
12862 pHddStaCtx->staDebugState = status;
12863 result = -EINVAL;
12864 goto disconnected;
12865 }
12866
12867 rc = wait_for_completion_timeout(
12868 &pAdapter->disconnect_comp_var,
12869 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012870 if (!rc && (QDF_STATUS_CMD_NOT_QUEUED != status)) {
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012871 hdd_err("Sme disconnect event timed out session Id %d staDebugState %d",
12872 pAdapter->sessionId, pHddStaCtx->staDebugState);
12873 result = -ETIMEDOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012874 }
12875 } else if (eConnectionState_Disconnecting ==
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012876 pHddStaCtx->conn_info.connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012877 rc = wait_for_completion_timeout(&pAdapter->disconnect_comp_var,
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012878 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012879 if (!rc) {
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012880 hdd_err("Disconnect event timed out session Id %d staDebugState %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012881 pAdapter->sessionId, pHddStaCtx->staDebugState);
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012882 result = -ETIMEDOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012883 }
12884 }
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012885disconnected:
Abhishek Singhbe1849b2016-01-19 14:12:00 +053012886 hdd_conn_set_connection_state(pAdapter, eConnectionState_NotConnected);
12887 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012888}
12889
12890/**
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012891 * wlan_hdd_reassoc_bssid_hint() - Start reassociation if bssid is present
12892 * @adapter: Pointer to the HDD adapter
12893 * @req: Pointer to the structure cfg_connect_params receieved from user space
Naveen Rawat07332902016-07-27 09:13:17 -070012894 * @status: out variable for status of reassoc request
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012895 *
Selvaraj, Sridhar353be2f2016-09-27 15:01:41 +053012896 * This function will start reassociation if prev_bssid is set and bssid/
12897 * bssid_hint, channel/channel_hint parameters are present in connect request.
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012898 *
Naveen Rawat07332902016-07-27 09:13:17 -070012899 * Return: true if connect was for ReAssociation, false otherwise
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012900 */
Selvaraj, Sridhara11edcb2016-09-07 18:49:14 +053012901#if defined(CFG80211_CONNECT_PREV_BSSID) || \
12902 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
Naveen Rawat07332902016-07-27 09:13:17 -070012903static bool wlan_hdd_reassoc_bssid_hint(hdd_adapter_t *adapter,
12904 struct cfg80211_connect_params *req,
12905 int *status)
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012906{
Naveen Rawat07332902016-07-27 09:13:17 -070012907 bool reassoc = false;
Selvaraj, Sridhar353be2f2016-09-27 15:01:41 +053012908 const uint8_t *bssid = NULL;
12909 uint16_t channel = 0;
12910
12911 if (req->bssid)
12912 bssid = req->bssid;
12913 else if (req->bssid_hint)
12914 bssid = req->bssid_hint;
12915
12916 if (req->channel)
12917 channel = req->channel->hw_value;
12918 else if (req->channel_hint)
12919 channel = req->channel_hint->hw_value;
12920
12921 if (bssid && channel && req->prev_bssid) {
Naveen Rawat07332902016-07-27 09:13:17 -070012922 reassoc = true;
12923 hdd_info(FL("REASSOC Attempt on channel %d to "MAC_ADDRESS_STR),
Selvaraj, Sridhar353be2f2016-09-27 15:01:41 +053012924 channel, MAC_ADDR_ARRAY(bssid));
12925 *status = hdd_reassoc(adapter, bssid, channel,
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012926 CONNECT_CMD_USERSPACE);
Naveen Rawat07332902016-07-27 09:13:17 -070012927 hdd_debug("hdd_reassoc: status: %d", *status);
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012928 }
Naveen Rawat07332902016-07-27 09:13:17 -070012929 return reassoc;
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012930}
12931#else
Naveen Rawat07332902016-07-27 09:13:17 -070012932static bool wlan_hdd_reassoc_bssid_hint(hdd_adapter_t *adapter,
12933 struct cfg80211_connect_params *req,
12934 int *status)
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012935{
Naveen Rawat07332902016-07-27 09:13:17 -070012936 return false;
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070012937}
12938#endif
12939
12940/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012941 * __wlan_hdd_cfg80211_connect() - cfg80211 connect api
12942 * @wiphy: Pointer to wiphy
12943 * @dev: Pointer to network device
12944 * @req: Pointer to cfg80211 connect request
12945 *
12946 * This function is used to start the association process
12947 *
12948 * Return: 0 for success, non-zero for failure
12949 */
12950static int __wlan_hdd_cfg80211_connect(struct wiphy *wiphy,
12951 struct net_device *ndev,
12952 struct cfg80211_connect_params *req)
12953{
12954 int status;
Sreelakshmi Konamki6bd8a2e2015-11-03 16:30:32 +053012955 u16 channel;
12956#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
12957 const u8 *bssid_hint = req->bssid_hint;
12958#else
12959 const u8 *bssid_hint = NULL;
12960#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012961 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev);
12962 hdd_context_t *pHddCtx;
12963
12964 ENTER();
12965
Anurag Chouhan6d760662016-02-20 16:05:43 +053012966 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012967 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012968 return -EINVAL;
12969 }
12970
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053012971 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
12972 hdd_err("invalid session id: %d", pAdapter->sessionId);
12973 return -EINVAL;
12974 }
12975
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053012976 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012977 TRACE_CODE_HDD_CFG80211_CONNECT,
12978 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012979 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012980 hdd_device_mode_to_string(pAdapter->device_mode),
12981 pAdapter->device_mode);
12982
Krunal Sonib4326f22016-03-10 13:05:51 -080012983 if (pAdapter->device_mode != QDF_STA_MODE &&
12984 pAdapter->device_mode != QDF_P2P_CLIENT_MODE) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012985 hdd_err("Device_mode %s(%d) is not supported",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012986 hdd_device_mode_to_string(pAdapter->device_mode),
12987 pAdapter->device_mode);
12988 return -EINVAL;
12989 }
12990
12991 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
12992 if (!pHddCtx) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070012993 hdd_err("HDD context is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012994 return -EINVAL;
12995 }
12996
12997 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053012998 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012999 return status;
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070013000
Naveen Rawat07332902016-07-27 09:13:17 -070013001 if (true == wlan_hdd_reassoc_bssid_hint(pAdapter, req, &status))
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070013002 return status;
13003
Agrawal Ashishf156e942016-08-04 14:54:47 +053013004 /* Try disconnecting if already in connected state */
13005 status = wlan_hdd_try_disconnect(pAdapter);
13006 if (0 > status) {
13007 hdd_err("Failed to disconnect the existing connection");
13008 return -EALREADY;
13009 }
13010
13011 /* Check for max concurrent connections after doing disconnect if any */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013012 if (req->channel) {
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080013013 if (!cds_allow_concurrency(
Krunal Sonib4326f22016-03-10 13:05:51 -080013014 cds_convert_device_mode_to_qdf_type(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013015 pAdapter->device_mode),
13016 req->channel->hw_value, HW_MODE_20_MHZ)) {
13017 hdd_err("This concurrency combination is not allowed");
13018 return -ECONNREFUSED;
13019 }
13020 } else {
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080013021 if (!cds_allow_concurrency(
Krunal Sonib4326f22016-03-10 13:05:51 -080013022 cds_convert_device_mode_to_qdf_type(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013023 pAdapter->device_mode), 0, HW_MODE_20_MHZ)) {
13024 hdd_err("This concurrency combination is not allowed");
13025 return -ECONNREFUSED;
13026 }
13027 }
Varun Reddy Yeturu3e91dad2016-07-18 15:58:47 -070013028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013029 /*initialise security parameters */
13030 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
13031
13032 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013033 hdd_err("failed to set security params");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013034 return status;
13035 }
13036
Sreelakshmi Konamki6bd8a2e2015-11-03 16:30:32 +053013037 if (req->channel)
13038 channel = req->channel->hw_value;
13039 else
13040 channel = 0;
13041 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
13042 req->ssid_len, req->bssid,
Naveen Rawatc77e6e72016-08-05 15:19:03 -070013043 bssid_hint, channel, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013044 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013045 hdd_err("connect failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013046 return status;
13047 }
13048 EXIT();
13049 return status;
13050}
13051
13052/**
13053 * wlan_hdd_cfg80211_connect() - cfg80211 connect api
13054 * @wiphy: Pointer to wiphy
13055 * @dev: Pointer to network device
13056 * @req: Pointer to cfg80211 connect request
13057 *
13058 * Return: 0 for success, non-zero for failure
13059 */
13060static int wlan_hdd_cfg80211_connect(struct wiphy *wiphy,
13061 struct net_device *ndev,
13062 struct cfg80211_connect_params *req)
13063{
13064 int ret;
13065 cds_ssr_protect(__func__);
13066 ret = __wlan_hdd_cfg80211_connect(wiphy, ndev, req);
13067 cds_ssr_unprotect(__func__);
13068
13069 return ret;
13070}
13071
13072/**
13073 * wlan_hdd_disconnect() - hdd disconnect api
13074 * @pAdapter: Pointer to adapter
13075 * @reason: Disconnect reason code
13076 *
13077 * This function is used to issue a disconnect request to SME
13078 *
13079 * Return: 0 for success, non-zero for failure
13080 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070013081static int wlan_hdd_disconnect(hdd_adapter_t *pAdapter, u16 reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013082{
13083 int status, result = 0;
13084 unsigned long rc;
13085 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
13086 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
13087
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013088 ENTER();
13089
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013090 status = wlan_hdd_validate_context(pHddCtx);
13091
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013092 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013093 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013094
13095 /*stop tx queues */
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013096 hdd_notice("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013097 wlan_hdd_netif_queue_control(pAdapter, WLAN_NETIF_TX_DISABLE_N_CARRIER,
13098 WLAN_CONTROL_PATH);
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013099 hdd_notice("Set HDD connState to eConnectionState_Disconnecting");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013100 pHddStaCtx->conn_info.connState = eConnectionState_Disconnecting;
13101 INIT_COMPLETION(pAdapter->disconnect_comp_var);
13102
13103 /*issue disconnect */
13104
13105 status = sme_roam_disconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
13106 pAdapter->sessionId, reason);
Abhishek Singhacfdc922015-12-30 17:31:21 +053013107 /*
13108 * Wait here instead of returning directly, this will block the next
13109 * connect command and allow processing of the scan for ssid and
13110 * the previous connect command in CSR. Else we might hit some
13111 * race conditions leading to SME and HDD out of sync.
13112 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013113 if (QDF_STATUS_CMD_NOT_QUEUED == status) {
Abhishek Singhbe1849b2016-01-19 14:12:00 +053013114 hdd_info("Already disconnected or connect was in sme/roam pending list and removed by disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013115 } else if (0 != status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013116 hdd_err("csr_roam_disconnect failure, returned %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013117 (int)status);
13118 pHddStaCtx->staDebugState = status;
13119 result = -EINVAL;
13120 goto disconnected;
13121 }
13122 rc = wait_for_completion_timeout(&pAdapter->disconnect_comp_var,
13123 msecs_to_jiffies
13124 (WLAN_WAIT_TIME_DISCONNECT));
13125
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013126 if (!rc && (QDF_STATUS_CMD_NOT_QUEUED != status)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013127 hdd_err("Failed to disconnect, timed out");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013128 result = -ETIMEDOUT;
13129 }
13130disconnected:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013131 hdd_conn_set_connection_state(pAdapter, eConnectionState_NotConnected);
13132#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)
13133 /* Sending disconnect event to userspace for kernel version < 3.11
13134 * is handled by __cfg80211_disconnect call to __cfg80211_disconnected
13135 */
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013136 hdd_notice("Send disconnected event to userspace");
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +053013137 wlan_hdd_cfg80211_indicate_disconnect(pAdapter->dev, true,
13138 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013139#endif
13140
13141 return result;
13142}
13143
13144/**
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -080013145 * hdd_ieee80211_reason_code_to_str() - return string conversion of reason code
13146 * @reason: ieee80211 reason code.
13147 *
13148 * This utility function helps log string conversion of reason code.
13149 *
13150 * Return: string conversion of reason code, if match found;
13151 * "Unknown" otherwise.
13152 */
13153static const char *hdd_ieee80211_reason_code_to_str(uint16_t reason)
13154{
13155 switch (reason) {
13156 CASE_RETURN_STRING(WLAN_REASON_UNSPECIFIED);
13157 CASE_RETURN_STRING(WLAN_REASON_PREV_AUTH_NOT_VALID);
13158 CASE_RETURN_STRING(WLAN_REASON_DEAUTH_LEAVING);
13159 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
13160 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_AP_BUSY);
13161 CASE_RETURN_STRING(WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
13162 CASE_RETURN_STRING(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
13163 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_STA_HAS_LEFT);
13164 CASE_RETURN_STRING(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
13165 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_BAD_POWER);
13166 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_BAD_SUPP_CHAN);
13167 CASE_RETURN_STRING(WLAN_REASON_INVALID_IE);
13168 CASE_RETURN_STRING(WLAN_REASON_MIC_FAILURE);
13169 CASE_RETURN_STRING(WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT);
13170 CASE_RETURN_STRING(WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT);
13171 CASE_RETURN_STRING(WLAN_REASON_IE_DIFFERENT);
13172 CASE_RETURN_STRING(WLAN_REASON_INVALID_GROUP_CIPHER);
13173 CASE_RETURN_STRING(WLAN_REASON_INVALID_PAIRWISE_CIPHER);
13174 CASE_RETURN_STRING(WLAN_REASON_INVALID_AKMP);
13175 CASE_RETURN_STRING(WLAN_REASON_UNSUPP_RSN_VERSION);
13176 CASE_RETURN_STRING(WLAN_REASON_INVALID_RSN_IE_CAP);
13177 CASE_RETURN_STRING(WLAN_REASON_IEEE8021X_FAILED);
13178 CASE_RETURN_STRING(WLAN_REASON_CIPHER_SUITE_REJECTED);
13179 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_UNSPECIFIED_QOS);
13180 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH);
13181 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_LOW_ACK);
13182 CASE_RETURN_STRING(WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP);
13183 CASE_RETURN_STRING(WLAN_REASON_QSTA_LEAVE_QBSS);
13184 CASE_RETURN_STRING(WLAN_REASON_QSTA_NOT_USE);
13185 CASE_RETURN_STRING(WLAN_REASON_QSTA_REQUIRE_SETUP);
13186 CASE_RETURN_STRING(WLAN_REASON_QSTA_TIMEOUT);
13187 CASE_RETURN_STRING(WLAN_REASON_QSTA_CIPHER_NOT_SUPP);
13188 CASE_RETURN_STRING(WLAN_REASON_MESH_PEER_CANCELED);
13189 CASE_RETURN_STRING(WLAN_REASON_MESH_MAX_PEERS);
13190 CASE_RETURN_STRING(WLAN_REASON_MESH_CONFIG);
13191 CASE_RETURN_STRING(WLAN_REASON_MESH_CLOSE);
13192 CASE_RETURN_STRING(WLAN_REASON_MESH_MAX_RETRIES);
13193 CASE_RETURN_STRING(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
13194 CASE_RETURN_STRING(WLAN_REASON_MESH_INVALID_GTK);
13195 CASE_RETURN_STRING(WLAN_REASON_MESH_INCONSISTENT_PARAM);
13196 CASE_RETURN_STRING(WLAN_REASON_MESH_INVALID_SECURITY);
13197 CASE_RETURN_STRING(WLAN_REASON_MESH_PATH_ERROR);
13198 CASE_RETURN_STRING(WLAN_REASON_MESH_PATH_NOFORWARD);
13199 CASE_RETURN_STRING(WLAN_REASON_MESH_PATH_DEST_UNREACHABLE);
13200 CASE_RETURN_STRING(WLAN_REASON_MAC_EXISTS_IN_MBSS);
13201 CASE_RETURN_STRING(WLAN_REASON_MESH_CHAN_REGULATORY);
13202 CASE_RETURN_STRING(WLAN_REASON_MESH_CHAN);
13203 default:
13204 return "Unknown";
13205 }
13206}
13207
13208/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013209 * __wlan_hdd_cfg80211_disconnect() - cfg80211 disconnect api
13210 * @wiphy: Pointer to wiphy
13211 * @dev: Pointer to network device
13212 * @reason: Disconnect reason code
13213 *
13214 * This function is used to issue a disconnect request to SME
13215 *
13216 * Return: 0 for success, non-zero for failure
13217 */
13218static int __wlan_hdd_cfg80211_disconnect(struct wiphy *wiphy,
13219 struct net_device *dev, u16 reason)
13220{
13221 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13222 int status;
13223 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
13224 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
13225#ifdef FEATURE_WLAN_TDLS
13226 uint8_t staIdx;
13227#endif
13228
13229 ENTER();
13230
Anurag Chouhan6d760662016-02-20 16:05:43 +053013231 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013232 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013233 return -EINVAL;
13234 }
13235
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013236 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13237 hdd_err("invalid session id: %d", pAdapter->sessionId);
13238 return -EINVAL;
13239 }
13240
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013241 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013242 TRACE_CODE_HDD_CFG80211_DISCONNECT,
13243 pAdapter->sessionId, reason));
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013244 hdd_notice("Device_mode %s(%d) reason code(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013245 hdd_device_mode_to_string(pAdapter->device_mode),
13246 pAdapter->device_mode, reason);
13247
13248 status = wlan_hdd_validate_context(pHddCtx);
13249
Varun Reddy Yeturu3e213e52016-11-24 16:24:15 -080013250 if (hdd_is_roaming_in_progress()) {
13251 hdd_err("Roaming In Progress. Ignore!!!");
13252 return -EAGAIN;
13253 }
13254
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013255 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013256 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013257
13258 /* Issue disconnect request to SME, if station is in connected state */
13259 if ((pHddStaCtx->conn_info.connState == eConnectionState_Associated) ||
13260 (pHddStaCtx->conn_info.connState == eConnectionState_Connecting)) {
13261 eCsrRoamDisconnectReason reasonCode =
13262 eCSR_DISCONNECT_REASON_UNSPECIFIED;
13263 hdd_scaninfo_t *pScanInfo;
13264
13265 switch (reason) {
13266 case WLAN_REASON_MIC_FAILURE:
13267 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
13268 break;
13269
13270 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
13271 case WLAN_REASON_DISASSOC_AP_BUSY:
13272 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
13273 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
13274 break;
13275
13276 case WLAN_REASON_PREV_AUTH_NOT_VALID:
13277 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
13278 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
13279 break;
13280
13281 case WLAN_REASON_DEAUTH_LEAVING:
13282 reasonCode =
13283 pHddCtx->config->
13284 gEnableDeauthToDisassocMap ?
13285 eCSR_DISCONNECT_REASON_STA_HAS_LEFT :
13286 eCSR_DISCONNECT_REASON_DEAUTH;
13287 break;
13288 case WLAN_REASON_DISASSOC_STA_HAS_LEFT:
13289 reasonCode = eCSR_DISCONNECT_REASON_STA_HAS_LEFT;
13290 break;
13291 default:
13292 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
13293 break;
13294 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013295 hdd_notice("convert to internal reason %d to reasonCode %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013296 reason, reasonCode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013297 pScanInfo = &pAdapter->scan_info;
13298 if (pScanInfo->mScanPending) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013299 hdd_notice("Disconnect is in progress, Aborting Scan");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013300 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +053013301 INVALID_SCAN_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013302 eCSR_SCAN_ABORT_DEFAULT);
13303 }
Edhar, Mahesh Kumar732f6982016-07-01 11:23:06 +053013304 wlan_hdd_cleanup_remain_on_channel_ctx(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013305#ifdef FEATURE_WLAN_TDLS
13306 /* First clean up the tdls peers if any */
13307 for (staIdx = 0; staIdx < pHddCtx->max_num_tdls_sta; staIdx++) {
13308 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId ==
13309 pAdapter->sessionId)
13310 && (pHddCtx->tdlsConnInfo[staIdx].staId)) {
13311 uint8_t *mac;
13312 mac =
13313 pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013314 hdd_notice("call sme_delete_tdls_peer_sta staId %d sessionId %d "
13315 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013316 pHddCtx->tdlsConnInfo[staIdx].staId,
13317 pAdapter->sessionId,
13318 MAC_ADDR_ARRAY(mac));
13319 sme_delete_tdls_peer_sta(WLAN_HDD_GET_HAL_CTX
13320 (pAdapter),
13321 pAdapter->sessionId, mac);
13322 }
13323 }
13324#endif
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013325 hdd_notice("Disconnecting with reasoncode:%u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013326 reasonCode);
Srinivas Girigowdaf2599dd2015-11-16 18:20:46 -080013327 hdd_info("Disconnect request from user space with reason: %s",
13328 hdd_ieee80211_reason_code_to_str(reason));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013329 status = wlan_hdd_disconnect(pAdapter, reasonCode);
13330 if (0 != status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013331 hdd_err("failure, returned %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013332 return -EINVAL;
13333 }
13334 } else {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013335 hdd_err("unexpected cfg disconnect called while in state (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013336 pHddStaCtx->conn_info.connState);
13337 }
13338
13339 return status;
13340}
13341
13342/**
13343 * wlan_hdd_cfg80211_disconnect() - cfg80211 disconnect api
13344 * @wiphy: Pointer to wiphy
13345 * @dev: Pointer to network device
13346 * @reason: Disconnect reason code
13347 *
13348 * Return: 0 for success, non-zero for failure
13349 */
13350static int wlan_hdd_cfg80211_disconnect(struct wiphy *wiphy,
13351 struct net_device *dev, u16 reason)
13352{
13353 int ret;
13354 cds_ssr_protect(__func__);
13355 ret = __wlan_hdd_cfg80211_disconnect(wiphy, dev, reason);
13356 cds_ssr_unprotect(__func__);
13357
13358 return ret;
13359}
13360
13361/**
13362 * wlan_hdd_cfg80211_set_privacy_ibss() - set ibss privacy
13363 * @pAdapter: Pointer to adapter
13364 * @param: Pointer to IBSS parameters
13365 *
13366 * This function is used to initialize the security settings in IBSS mode
13367 *
13368 * Return: 0 for success, non-zero for failure
13369 */
13370static int wlan_hdd_cfg80211_set_privacy_ibss(hdd_adapter_t *pAdapter,
13371 struct cfg80211_ibss_params
13372 *params)
13373{
13374 int status = 0;
13375 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
13376 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
13377 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
13378
13379 ENTER();
13380
13381 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
Anurag Chouhan600c3a02016-03-01 10:33:54 +053013382 qdf_mem_zero(&pHddStaCtx->ibss_enc_key, sizeof(tCsrRoamSetKey));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013383 pHddStaCtx->ibss_enc_key_installed = 0;
13384
13385 if (params->ie_len && (NULL != params->ie)) {
13386 if (wlan_hdd_cfg80211_get_ie_ptr(params->ie,
13387 params->ie_len, WLAN_EID_RSN)) {
13388 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
13389 encryptionType = eCSR_ENCRYPT_TYPE_AES;
13390 } else if (hdd_is_wpaie_present(params->ie, params->ie_len)) {
13391 tDot11fIEWPA dot11WPAIE;
13392 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
13393 u8 *ie;
13394
13395 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
13396 ie = wlan_hdd_cfg80211_get_ie_ptr(params->ie,
13397 params->ie_len,
13398 DOT11F_EID_WPA);
13399 if (NULL != ie) {
13400 pWextState->wpaVersion =
13401 IW_AUTH_WPA_VERSION_WPA;
Jeff Johnsonf3826e12017-01-12 09:49:40 -080013402 /* Unpack the WPA IE
13403 * Skip past the EID byte and length byte
13404 * and four byte WiFi OUI
13405 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013406 dot11f_unpack_ie_wpa((tpAniSirGlobal) halHandle,
13407 &ie[2 + 4],
13408 ie[1] - 4, &dot11WPAIE);
Jeff Johnsonf3826e12017-01-12 09:49:40 -080013409 /* Extract the multicast cipher, the
13410 * encType for unicast cipher for
13411 * wpa-none is none
13412 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013413 encryptionType =
13414 hdd_translate_wpa_to_csr_encryption_type
13415 (dot11WPAIE.multicast_cipher);
13416 }
13417 }
13418
13419 status =
13420 wlan_hdd_cfg80211_set_ie(pAdapter, params->ie,
13421 params->ie_len);
13422
13423 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013424 hdd_err("failed to parse WPA/RSN IE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013425 return status;
13426 }
13427 }
13428
13429 pWextState->roamProfile.AuthType.authType[0] =
13430 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
13431
13432 if (params->privacy) {
13433 /* Security enabled IBSS, At this time there is no information
13434 * available about the security paramters, so initialise the
13435 * encryption type to eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
13436 * The correct security parameters will be updated later in
13437 * wlan_hdd_cfg80211_add_key Hal expects encryption type to be
13438 * set inorder enable privacy bit in beacons
13439 */
13440
13441 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
13442 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013443 hdd_info("encryptionType=%d", encryptionType);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013444 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
13445 pWextState->roamProfile.EncryptionType.numEntries = 1;
13446 pWextState->roamProfile.EncryptionType.encryptionType[0] =
13447 encryptionType;
13448 return status;
13449}
13450
13451/**
13452 * __wlan_hdd_cfg80211_join_ibss() - join ibss
13453 * @wiphy: Pointer to wiphy
13454 * @dev: Pointer to network device
13455 * @param: Pointer to IBSS join parameters
13456 *
13457 * This function is used to create/join an IBSS network
13458 *
13459 * Return: 0 for success, non-zero for failure
13460 */
13461static int __wlan_hdd_cfg80211_join_ibss(struct wiphy *wiphy,
13462 struct net_device *dev,
13463 struct cfg80211_ibss_params *params)
13464{
13465 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13466 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
13467 tCsrRoamProfile *pRoamProfile;
13468 int status;
13469 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
13470 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Anurag Chouhan6d760662016-02-20 16:05:43 +053013471 struct qdf_mac_addr bssid;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013472 u8 channelNum = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013473
13474 ENTER();
13475
Anurag Chouhan6d760662016-02-20 16:05:43 +053013476 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013477 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013478 return -EINVAL;
13479 }
13480
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013481 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13482 hdd_err("invalid session id: %d", pAdapter->sessionId);
13483 return -EINVAL;
13484 }
13485
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013486 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013487 TRACE_CODE_HDD_CFG80211_JOIN_IBSS,
13488 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013489 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013490 hdd_device_mode_to_string(pAdapter->device_mode),
13491 pAdapter->device_mode);
13492
13493 status = wlan_hdd_validate_context(pHddCtx);
13494
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013495 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013496 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013497
13498 if (NULL !=
Anurag Chouhance0dc992016-02-16 18:18:03 +053013499 params->chandef.chan) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013500 uint32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
13501 uint8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
13502 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
13503 int indx;
13504
13505 /* Get channel number */
13506 channelNum = ieee80211_frequency_to_channel(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013507 params->
13508 chandef.
13509 chan->
13510 center_freq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013511
13512 if (0 != sme_cfg_get_str(hHal, WNI_CFG_VALID_CHANNEL_LIST,
13513 validChan, &numChans)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013514 hdd_err("No valid channel list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013515 return -EOPNOTSUPP;
13516 }
13517
13518 for (indx = 0; indx < numChans; indx++) {
13519 if (channelNum == validChan[indx]) {
13520 break;
13521 }
13522 }
13523 if (indx >= numChans) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013524 hdd_err("Not valid Channel %d", channelNum);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013525 return -EINVAL;
13526 }
13527 }
13528
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -080013529 if (!cds_allow_concurrency(CDS_IBSS_MODE, channelNum,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013530 HW_MODE_20_MHZ)) {
13531 hdd_err("This concurrency combination is not allowed");
13532 return -ECONNREFUSED;
13533 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013534
Krunal Soni3091bcc2016-06-23 12:28:21 -070013535 status = qdf_reset_connection_update();
13536 if (!QDF_IS_STATUS_SUCCESS(status))
13537 hdd_err("ERR: clear event failed");
13538
13539 status = cds_current_connections_update(pAdapter->sessionId,
13540 channelNum,
13541 SIR_UPDATE_REASON_JOIN_IBSS);
13542 if (QDF_STATUS_E_FAILURE == status) {
13543 hdd_err("ERROR: connections update failed!!");
13544 return -EINVAL;
13545 }
13546
13547 if (QDF_STATUS_SUCCESS == status) {
13548 status = qdf_wait_for_connection_update();
13549 if (!QDF_IS_STATUS_SUCCESS(status)) {
13550 hdd_err("ERROR: qdf wait for event failed!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013551 return -EINVAL;
13552 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013553 }
13554
13555 /*Try disconnecting if already in connected state */
13556 status = wlan_hdd_try_disconnect(pAdapter);
13557 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013558 hdd_err("Failed to disconnect the existing IBSS connection");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013559 return -EALREADY;
13560 }
13561
13562 pRoamProfile = &pWextState->roamProfile;
13563
13564 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013565 hdd_err("Interface type is not set to IBSS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013566 return -EINVAL;
13567 }
13568
13569 /* enable selected protection checks in IBSS mode */
13570 pRoamProfile->cfg_protection = IBSS_CFG_PROTECTION_ENABLE_MASK;
13571
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013572 if (QDF_STATUS_E_FAILURE == sme_cfg_set_int(pHddCtx->hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013573 WNI_CFG_IBSS_ATIM_WIN_SIZE,
13574 pHddCtx->config->
13575 ibssATIMWinSize)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013576 hdd_err("Could not pass on WNI_CFG_IBSS_ATIM_WIN_SIZE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013577 }
13578
13579 /* BSSID is provided by upper layers hence no need to AUTO generate */
13580 if (NULL != params->bssid) {
13581 if (sme_cfg_set_int(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013582 == QDF_STATUS_E_FAILURE) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013583 hdd_err("ccmCfgStInt failed for WNI_CFG_IBSS_AUTO_BSSID");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013584 return -EIO;
13585 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +053013586 qdf_mem_copy(bssid.bytes, params->bssid, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013587 } else if (pHddCtx->config->isCoalesingInIBSSAllowed == 0) {
13588 if (sme_cfg_set_int(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013589 == QDF_STATUS_E_FAILURE) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013590 hdd_err("ccmCfgStInt failed for WNI_CFG_IBSS_AUTO_BSSID");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013591 return -EIO;
13592 }
Anurag Chouhanc5548422016-02-24 18:33:27 +053013593 qdf_copy_macaddr(&bssid, &pHddCtx->config->IbssBssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013594 }
13595 if ((params->beacon_interval > CFG_BEACON_INTERVAL_MIN)
13596 && (params->beacon_interval <= CFG_BEACON_INTERVAL_MAX))
13597 pRoamProfile->beaconInterval = params->beacon_interval;
13598 else {
13599 pRoamProfile->beaconInterval = CFG_BEACON_INTERVAL_DEFAULT;
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013600 hdd_info("input beacon interval %d TU is invalid, use default %d TU",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013601 params->beacon_interval, pRoamProfile->beaconInterval);
13602 }
13603
13604 /* Set Channel */
13605 if (channelNum) {
13606 /* Set the Operational Channel */
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013607 hdd_info("set channel %d", channelNum);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013608 pRoamProfile->ChannelInfo.numOfChannels = 1;
13609 pHddStaCtx->conn_info.operationChannel = channelNum;
13610 pRoamProfile->ChannelInfo.ChannelList =
13611 &pHddStaCtx->conn_info.operationChannel;
13612 }
13613
13614 /* Initialize security parameters */
13615 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
13616 if (status < 0) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013617 hdd_err("failed to set security parameters");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013618 return status;
13619 }
13620
13621 /* Issue connect start */
13622 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
13623 params->ssid_len,
Naveen Rawatc77e6e72016-08-05 15:19:03 -070013624 bssid.bytes, NULL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013625 pHddStaCtx->conn_info.
Naveen Rawatc77e6e72016-08-05 15:19:03 -070013626 operationChannel,
13627 params->chandef.width);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013628
13629 if (0 > status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013630 hdd_err("connect failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013631 return status;
13632 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013633 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013634 return 0;
13635}
13636
13637/**
13638 * wlan_hdd_cfg80211_join_ibss() - join ibss
13639 * @wiphy: Pointer to wiphy
13640 * @dev: Pointer to network device
13641 * @param: Pointer to IBSS join parameters
13642 *
13643 * This function is used to create/join an IBSS network
13644 *
13645 * Return: 0 for success, non-zero for failure
13646 */
13647static int wlan_hdd_cfg80211_join_ibss(struct wiphy *wiphy,
13648 struct net_device *dev,
13649 struct cfg80211_ibss_params *params)
13650{
13651 int ret = 0;
13652
13653 cds_ssr_protect(__func__);
13654 ret = __wlan_hdd_cfg80211_join_ibss(wiphy, dev, params);
13655 cds_ssr_unprotect(__func__);
13656
13657 return ret;
13658}
13659
13660/**
13661 * __wlan_hdd_cfg80211_leave_ibss() - leave ibss
13662 * @wiphy: Pointer to wiphy
13663 * @dev: Pointer to network device
13664 *
13665 * This function is used to leave an IBSS network
13666 *
13667 * Return: 0 for success, non-zero for failure
13668 */
13669static int __wlan_hdd_cfg80211_leave_ibss(struct wiphy *wiphy,
13670 struct net_device *dev)
13671{
13672 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13673 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
13674 tCsrRoamProfile *pRoamProfile;
13675 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
13676 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013677 QDF_STATUS hal_status;
Chandrasekaran, Manishekar12a818a2015-12-18 11:44:56 +053013678 unsigned long rc;
Rajeev Kumar8e3e2832015-11-06 16:02:54 -080013679 tSirUpdateIE updateIE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013680
13681 ENTER();
13682
Anurag Chouhan6d760662016-02-20 16:05:43 +053013683 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013684 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013685 return -EINVAL;
13686 }
13687
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053013688 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
13689 hdd_err("invalid session id: %d", pAdapter->sessionId);
13690 return -EINVAL;
13691 }
13692
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013693 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013694 TRACE_CODE_HDD_CFG80211_LEAVE_IBSS,
13695 pAdapter->sessionId,
13696 eCSR_DISCONNECT_REASON_IBSS_LEAVE));
13697 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013698 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013699 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013700
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013701 hdd_notice("Device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013702 hdd_device_mode_to_string(pAdapter->device_mode),
13703 pAdapter->device_mode);
13704 if (NULL == pWextState) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013705 hdd_err("Data Storage Corruption");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013706 return -EIO;
13707 }
13708
13709 pRoamProfile = &pWextState->roamProfile;
13710
13711 /* Issue disconnect only if interface type is set to IBSS */
13712 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013713 hdd_err("BSS Type is not set to IBSS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013714 return -EINVAL;
13715 }
Rajeev Kumar8e3e2832015-11-06 16:02:54 -080013716 /* Clearing add IE of beacon */
13717 qdf_mem_copy(updateIE.bssid.bytes, pAdapter->macAddressCurrent.bytes,
13718 sizeof(tSirMacAddr));
13719 updateIE.smeSessionId = pAdapter->sessionId;
13720 updateIE.ieBufferlength = 0;
13721 updateIE.pAdditionIEBuffer = NULL;
13722 updateIE.append = true;
13723 updateIE.notify = true;
13724 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pAdapter),
13725 &updateIE,
13726 eUPDATE_IE_PROBE_BCN) == QDF_STATUS_E_FAILURE) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013727 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -080013728 }
13729
13730 /* Reset WNI_CFG_PROBE_RSP Flags */
13731 wlan_hdd_reset_prob_rspies(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013732
13733 /* Issue Disconnect request */
13734 INIT_COMPLETION(pAdapter->disconnect_comp_var);
13735 hal_status = sme_roam_disconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
13736 pAdapter->sessionId,
13737 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053013738 if (!QDF_IS_STATUS_SUCCESS(hal_status)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013739 hdd_err("sme_roam_disconnect failed hal_status(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013740 hal_status);
13741 return -EAGAIN;
13742 }
Chandrasekaran, Manishekar12a818a2015-12-18 11:44:56 +053013743
13744 /* wait for mc thread to cleanup and then return to upper stack
13745 * so by the time upper layer calls the change interface, we are
13746 * all set to proceed further
13747 */
13748 rc = wait_for_completion_timeout(&pAdapter->disconnect_comp_var,
13749 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
13750 if (!rc) {
13751 hdd_err("Failed to disconnect, timed out");
13752 return -ETIMEDOUT;
13753 }
13754
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013755 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013756 return 0;
13757}
13758
13759/**
13760 * wlan_hdd_cfg80211_leave_ibss() - leave ibss
13761 * @wiphy: Pointer to wiphy
13762 * @dev: Pointer to network device
13763 *
13764 * This function is used to leave an IBSS network
13765 *
13766 * Return: 0 for success, non-zero for failure
13767 */
13768static int wlan_hdd_cfg80211_leave_ibss(struct wiphy *wiphy,
13769 struct net_device *dev)
13770{
13771 int ret = 0;
13772
13773 cds_ssr_protect(__func__);
13774 ret = __wlan_hdd_cfg80211_leave_ibss(wiphy, dev);
13775 cds_ssr_unprotect(__func__);
13776
13777 return ret;
13778}
13779
13780/**
13781 * __wlan_hdd_cfg80211_set_wiphy_params() - set wiphy parameters
13782 * @wiphy: Pointer to wiphy
13783 * @changed: Parameters changed
13784 *
13785 * This function is used to set the phy parameters. RTS Threshold/FRAG
13786 * Threshold/Retry Count etc.
13787 *
13788 * Return: 0 for success, non-zero for failure
13789 */
13790static int __wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
13791 u32 changed)
13792{
13793 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
13794 tHalHandle hHal = pHddCtx->hHal;
13795 int status;
13796
13797 ENTER();
13798
Anurag Chouhan6d760662016-02-20 16:05:43 +053013799 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013800 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013801 return -EINVAL;
13802 }
13803
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053013804 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013805 TRACE_CODE_HDD_CFG80211_SET_WIPHY_PARAMS,
13806 NO_SESSION, wiphy->rts_threshold));
13807 status = wlan_hdd_validate_context(pHddCtx);
13808
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013809 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013810 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013811
13812 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
13813 u32 rts_threshold = (wiphy->rts_threshold == -1) ?
13814 WNI_CFG_RTS_THRESHOLD_STAMAX : wiphy->rts_threshold;
13815
13816 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
13817 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013818 hdd_err("Invalid RTS Threshold value %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013819 rts_threshold);
13820 return -EINVAL;
13821 }
13822
13823 if (0 != sme_cfg_set_int(hHal, WNI_CFG_RTS_THRESHOLD,
13824 rts_threshold)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013825 hdd_err("sme_cfg_set_int failed for rts_threshold value %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013826 rts_threshold);
13827 return -EIO;
13828 }
13829
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013830 hdd_info("set rts threshold %u", rts_threshold);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013831 }
13832
13833 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
13834 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
13835 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
13836 wiphy->frag_threshold;
13837
13838 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold) ||
13839 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013840 hdd_err("Invalid frag_threshold value %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013841 frag_threshold);
13842 return -EINVAL;
13843 }
13844
13845 if (0 != sme_cfg_set_int(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
13846 frag_threshold)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013847 hdd_err("sme_cfg_set_int failed for frag_threshold value %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013848 frag_threshold);
13849 return -EIO;
13850 }
13851
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013852 hdd_info("set frag threshold %hu", frag_threshold);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013853 }
13854
13855 if ((changed & WIPHY_PARAM_RETRY_SHORT)
13856 || (changed & WIPHY_PARAM_RETRY_LONG)) {
13857 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
13858 wiphy->retry_short : wiphy->retry_long;
13859
13860 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
13861 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013862 hdd_err("Invalid Retry count %hu", retry_value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013863 return -EINVAL;
13864 }
13865
13866 if (changed & WIPHY_PARAM_RETRY_SHORT) {
13867 if (0 != sme_cfg_set_int(hHal,
13868 WNI_CFG_LONG_RETRY_LIMIT,
13869 retry_value)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013870 hdd_err("sme_cfg_set_int failed for long retry count %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013871 retry_value);
13872 return -EIO;
13873 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013874 hdd_info("set long retry count %hu", retry_value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013875 } else if (changed & WIPHY_PARAM_RETRY_SHORT) {
13876 if (0 != sme_cfg_set_int(hHal,
13877 WNI_CFG_SHORT_RETRY_LIMIT,
13878 retry_value)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013879 hdd_err("sme_cfg_set_int failed for short retry count %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013880 retry_value);
13881 return -EIO;
13882 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070013883 hdd_info("set short retry count %hu", retry_value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013884 }
13885 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053013886 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013887 return 0;
13888}
13889
13890/**
13891 * wlan_hdd_cfg80211_set_wiphy_params() - set wiphy parameters
13892 * @wiphy: Pointer to wiphy
13893 * @changed: Parameters changed
13894 *
13895 * Return: 0 for success, non-zero for failure
13896 */
13897static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
13898{
13899 int ret;
13900
13901 cds_ssr_protect(__func__);
13902 ret = __wlan_hdd_cfg80211_set_wiphy_params(wiphy, changed);
13903 cds_ssr_unprotect(__func__);
13904
13905 return ret;
13906}
13907
13908/**
13909 * __wlan_hdd_set_default_mgmt_key() - dummy implementation of set default mgmt
13910 * key
13911 * @wiphy: Pointer to wiphy
13912 * @dev: Pointer to network device
13913 * @key_index: Key index
13914 *
13915 * Return: 0
13916 */
13917static int __wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
13918 struct net_device *netdev,
13919 u8 key_index)
13920{
13921 ENTER();
13922 return 0;
13923}
13924
13925/**
13926 * wlan_hdd_set_default_mgmt_key() - SSR wrapper for
13927 * wlan_hdd_set_default_mgmt_key
13928 * @wiphy: pointer to wiphy
13929 * @netdev: pointer to net_device structure
13930 * @key_index: key index
13931 *
13932 * Return: 0 on success, error number on failure
13933 */
13934static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
13935 struct net_device *netdev,
13936 u8 key_index)
13937{
13938 int ret;
13939
13940 cds_ssr_protect(__func__);
13941 ret = __wlan_hdd_set_default_mgmt_key(wiphy, netdev, key_index);
13942 cds_ssr_unprotect(__func__);
13943
13944 return ret;
13945}
13946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013947/**
13948 * __wlan_hdd_set_txq_params() - dummy implementation of set tx queue params
13949 * @wiphy: Pointer to wiphy
13950 * @dev: Pointer to network device
13951 * @params: Pointer to tx queue parameters
13952 *
13953 * Return: 0
13954 */
13955static int __wlan_hdd_set_txq_params(struct wiphy *wiphy,
13956 struct net_device *dev,
13957 struct ieee80211_txq_params *params)
13958{
13959 ENTER();
13960 return 0;
13961}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013962
13963/**
13964 * wlan_hdd_set_txq_params() - SSR wrapper for wlan_hdd_set_txq_params
13965 * @wiphy: pointer to wiphy
13966 * @netdev: pointer to net_device structure
13967 * @params: pointer to ieee80211_txq_params
13968 *
13969 * Return: 0 on success, error number on failure
13970 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013971static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
13972 struct net_device *dev,
13973 struct ieee80211_txq_params *params)
13974{
13975 int ret;
13976
13977 cds_ssr_protect(__func__);
13978 ret = __wlan_hdd_set_txq_params(wiphy, dev, params);
13979 cds_ssr_unprotect(__func__);
13980
13981 return ret;
13982}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013983
13984/**
13985 * __wlan_hdd_cfg80211_del_station() - delete station v2
13986 * @wiphy: Pointer to wiphy
13987 * @param: Pointer to delete station parameter
13988 *
13989 * Return: 0 for success, non-zero for failure
13990 */
13991static
13992int __wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
13993 struct net_device *dev,
13994 struct tagCsrDelStaParams *pDelStaParams)
13995{
13996 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
13997 hdd_context_t *pHddCtx;
Anurag Chouhance0dc992016-02-16 18:18:03 +053013998 QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013999 hdd_hostapd_state_t *hapd_state;
14000 int status;
14001 uint8_t staId;
14002 uint8_t *mac;
14003
14004 ENTER();
14005
Anurag Chouhan6d760662016-02-20 16:05:43 +053014006 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014007 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014008 return -EINVAL;
14009 }
14010
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014011 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14012 hdd_err("invalid session id: %d", pAdapter->sessionId);
14013 return -EINVAL;
14014 }
14015
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014016 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014017 TRACE_CODE_HDD_CFG80211_DEL_STA,
14018 pAdapter->sessionId, pAdapter->device_mode));
14019
14020 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14021 status = wlan_hdd_validate_context(pHddCtx);
14022
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014023 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014024 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014025
14026 mac = (uint8_t *) pDelStaParams->peerMacAddr.bytes;
14027
Krunal Sonib4326f22016-03-10 13:05:51 -080014028 if ((QDF_SAP_MODE == pAdapter->device_mode) ||
14029 (QDF_P2P_GO_MODE == pAdapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014030
14031 hapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
14032 if (!hapd_state) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014033 hdd_err("Hostapd State is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014034 return 0;
14035 }
14036
Anurag Chouhanc5548422016-02-24 18:33:27 +053014037 if (qdf_is_macaddr_broadcast((struct qdf_mac_addr *) mac)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014038 uint16_t i;
14039 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
14040 if ((pAdapter->aStaInfo[i].isUsed) &&
14041 (!pAdapter->aStaInfo[i].
14042 isDeauthInProgress)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014043 qdf_mem_copy(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014044 mac,
14045 pAdapter->aStaInfo[i].
14046 macAddrSTA.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +053014047 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014048 if (hdd_ipa_uc_is_enabled(pHddCtx)) {
14049 hdd_ipa_wlan_evt(pAdapter,
14050 pAdapter->
14051 aStaInfo[i].
14052 ucSTAId,
Mohit Khannafa99aea2016-05-12 21:43:13 -070014053 HDD_IPA_CLIENT_DISCONNECT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014054 mac);
14055 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014056 hdd_notice("Delete STA with MAC::"
14057 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014058 MAC_ADDR_ARRAY(mac));
14059
14060 if (pHddCtx->dev_dfs_cac_status ==
14061 DFS_CAC_IN_PROGRESS)
14062 goto fn_end;
14063
Wei Song2f76f642016-11-18 16:32:53 +080014064 qdf_event_reset(&hapd_state->qdf_sta_disassoc_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014065 hdd_softap_sta_disassoc(pAdapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053014066 pDelStaParams);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014067 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014068 hdd_softap_sta_deauth(pAdapter,
14069 pDelStaParams);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014070 if (QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014071 pAdapter->aStaInfo[i].
14072 isDeauthInProgress = true;
Anurag Chouhance0dc992016-02-16 18:18:03 +053014073 qdf_status =
14074 qdf_wait_single_event(
Naveen Rawatb56880c2016-12-13 17:56:03 -080014075 &hapd_state->
14076 qdf_sta_disassoc_event,
14077 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053014078 if (!QDF_IS_STATUS_SUCCESS(
14079 qdf_status))
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014080 hdd_err("Deauth wait time expired");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014081 }
14082 }
14083 }
14084 } else {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014085 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014086 hdd_softap_get_sta_id(pAdapter,
Anurag Chouhan6d760662016-02-20 16:05:43 +053014087 (struct qdf_mac_addr *) mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014088 &staId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014089 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014090 hdd_notice("Skip DEL STA as this is not used::"
14091 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014092 MAC_ADDR_ARRAY(mac));
14093 return -ENOENT;
14094 }
14095
14096 if (hdd_ipa_uc_is_enabled(pHddCtx)) {
14097 hdd_ipa_wlan_evt(pAdapter, staId,
Mohit Khannafa99aea2016-05-12 21:43:13 -070014098 HDD_IPA_CLIENT_DISCONNECT, mac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014099 }
14100
14101 if (pAdapter->aStaInfo[staId].isDeauthInProgress ==
14102 true) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014103 hdd_notice("Skip DEL STA as deauth is in progress::"
14104 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014105 MAC_ADDR_ARRAY(mac));
14106 return -ENOENT;
14107 }
14108
14109 pAdapter->aStaInfo[staId].isDeauthInProgress = true;
14110
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014111 hdd_notice("Delete STA with MAC::" MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014112 MAC_ADDR_ARRAY(mac));
14113
14114 /* Case: SAP in ACS selected DFS ch and client connected
14115 * Now Radar detected. Then if random channel is another
14116 * DFS ch then new CAC is initiated and no TX allowed.
14117 * So do not send any mgmt frames as it will timeout
14118 * during CAC.
14119 */
14120
14121 if (pHddCtx->dev_dfs_cac_status == DFS_CAC_IN_PROGRESS)
14122 goto fn_end;
14123
Wei Song2f76f642016-11-18 16:32:53 +080014124 qdf_event_reset(&hapd_state->qdf_sta_disassoc_event);
Kondabattini, Ganesh3f2d02c2016-09-13 12:23:47 +053014125 sme_send_disassoc_req_frame(WLAN_HDD_GET_HAL_CTX
14126 (pAdapter), pAdapter->sessionId,
14127 (uint8_t *)&pDelStaParams->peerMacAddr,
14128 pDelStaParams->reason_code, 0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014129 qdf_status = hdd_softap_sta_deauth(pAdapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014130 pDelStaParams);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014131 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014132 pAdapter->aStaInfo[staId].isDeauthInProgress =
14133 false;
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014134 hdd_notice("STA removal failed for ::"
14135 MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014136 MAC_ADDR_ARRAY(mac));
14137 return -ENOENT;
14138 } else {
Anurag Chouhance0dc992016-02-16 18:18:03 +053014139 qdf_status = qdf_wait_single_event(
Naveen Rawatb56880c2016-12-13 17:56:03 -080014140 &hapd_state->
14141 qdf_sta_disassoc_event,
14142 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053014143 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014144 hdd_err("Deauth wait time expired");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014145 }
14146 }
14147 }
14148
14149fn_end:
14150 EXIT();
14151 return 0;
14152}
14153
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080014154#if defined(USE_CFG80211_DEL_STA_V2)
14155/**
14156 * wlan_hdd_del_station() - delete station wrapper
14157 * @adapter: pointer to the hdd adapter
14158 *
14159 * Return: None
14160 */
14161void wlan_hdd_del_station(hdd_adapter_t *adapter)
14162{
14163 struct station_del_parameters del_sta;
14164 del_sta.mac = NULL;
14165 del_sta.subtype = SIR_MAC_MGMT_DEAUTH >> 4;
14166 del_sta.reason_code = eCsrForcedDeauthSta;
14167
14168 wlan_hdd_cfg80211_del_station(adapter->wdev.wiphy, adapter->dev,
14169 &del_sta);
14170}
14171#else
14172void wlan_hdd_del_station(hdd_adapter_t *adapter)
14173{
14174 wlan_hdd_cfg80211_del_station(adapter->wdev.wiphy, adapter->dev, NULL);
14175}
14176#endif
14177
14178#if defined(USE_CFG80211_DEL_STA_V2)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014179/**
14180 * wlan_hdd_cfg80211_del_station() - delete station v2
14181 * @wiphy: Pointer to wiphy
14182 * @param: Pointer to delete station parameter
14183 *
14184 * Return: 0 for success, non-zero for failure
14185 */
14186int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
14187 struct net_device *dev,
14188 struct station_del_parameters *param)
14189#else
14190/**
14191 * wlan_hdd_cfg80211_del_station() - delete station
14192 * @wiphy: Pointer to wiphy
14193 * @mac: Pointer to station mac address
14194 *
14195 * Return: 0 for success, non-zero for failure
14196 */
14197#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
14198int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
14199 struct net_device *dev,
14200 const uint8_t *mac)
14201#else
14202int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
14203 struct net_device *dev,
14204 uint8_t *mac)
14205#endif
14206#endif
14207{
14208 int ret;
14209 struct tagCsrDelStaParams delStaParams;
14210
14211 cds_ssr_protect(__func__);
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080014212#if defined(USE_CFG80211_DEL_STA_V2)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014213 if (NULL == param) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080014214 hdd_err("Invalid argument passed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014215 return -EINVAL;
14216 }
14217 wlansap_populate_del_sta_params(param->mac, param->reason_code,
14218 param->subtype, &delStaParams);
14219#else
14220 wlansap_populate_del_sta_params(mac, eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
14221 (SIR_MAC_MGMT_DEAUTH >> 4),
14222 &delStaParams);
14223#endif
14224 ret = __wlan_hdd_cfg80211_del_station(wiphy, dev, &delStaParams);
14225 cds_ssr_unprotect(__func__);
14226
14227 return ret;
14228}
14229
14230/**
14231 * __wlan_hdd_cfg80211_add_station() - add station
14232 * @wiphy: Pointer to wiphy
14233 * @mac: Pointer to station mac address
14234 * @pmksa: Pointer to add station parameter
14235 *
14236 * Return: 0 for success, non-zero for failure
14237 */
14238static int __wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
14239 struct net_device *dev,
14240 const uint8_t *mac,
14241 struct station_parameters *params)
14242{
14243 int status = -EPERM;
14244#ifdef FEATURE_WLAN_TDLS
14245 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14246 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
14247 u32 mask, set;
14248
14249 ENTER();
14250
Anurag Chouhan6d760662016-02-20 16:05:43 +053014251 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014252 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014253 return -EINVAL;
14254 }
14255
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014256 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14257 hdd_err("invalid session id: %d", pAdapter->sessionId);
14258 return -EINVAL;
14259 }
14260
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014261 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014262 TRACE_CODE_HDD_CFG80211_ADD_STA,
14263 pAdapter->sessionId, params->listen_interval));
14264
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014265 if (0 != wlan_hdd_validate_context(pHddCtx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014266 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014267
14268 mask = params->sta_flags_mask;
14269
14270 set = params->sta_flags_set;
14271
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014272 hdd_notice("mask 0x%x set 0x%x " MAC_ADDRESS_STR, mask, set,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014273 MAC_ADDR_ARRAY(mac));
14274
14275 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
14276 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
14277 status =
14278 wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
14279 }
14280 }
14281#endif
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014282 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014283 return status;
14284}
14285
14286/**
14287 * wlan_hdd_cfg80211_add_station() - add station
14288 * @wiphy: Pointer to wiphy
14289 * @mac: Pointer to station mac address
14290 * @pmksa: Pointer to add station parameter
14291 *
14292 * Return: 0 for success, non-zero for failure
14293 */
14294#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
14295static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
14296 struct net_device *dev,
14297 const uint8_t *mac,
14298 struct station_parameters *params)
14299#else
14300static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
14301 struct net_device *dev, uint8_t *mac,
14302 struct station_parameters *params)
14303#endif
14304{
14305 int ret;
14306
14307 cds_ssr_protect(__func__);
14308 ret = __wlan_hdd_cfg80211_add_station(wiphy, dev, mac, params);
14309 cds_ssr_unprotect(__func__);
14310
14311 return ret;
14312}
14313
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014314/**
14315 * __wlan_hdd_cfg80211_set_pmksa() - set pmksa
14316 * @wiphy: Pointer to wiphy
14317 * @dev: Pointer to network device
14318 * @pmksa: Pointer to set pmksa parameter
14319 *
14320 * Return: 0 for success, non-zero for failure
14321 */
14322static int __wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy,
14323 struct net_device *dev,
14324 struct cfg80211_pmksa *pmksa)
14325{
14326 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14327 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14328 tHalHandle halHandle;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014329 QDF_STATUS result = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014330 int status;
14331 tPmkidCacheInfo pmk_id;
14332
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014333 ENTER();
14334
Anurag Chouhan6d760662016-02-20 16:05:43 +053014335 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014336 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014337 return -EINVAL;
14338 }
14339
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014340 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14341 hdd_err("invalid session id: %d", pAdapter->sessionId);
14342 return -EINVAL;
14343 }
14344
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014345 if (!pmksa) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014346 hdd_err("pmksa is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014347 return -EINVAL;
14348 }
14349
14350 if (!pmksa->bssid || !pmksa->pmkid) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014351 hdd_err("pmksa->bssid(%p) or pmksa->pmkid(%p) is NULL",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014352 pmksa->bssid, pmksa->pmkid);
14353 return -EINVAL;
14354 }
14355
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014356 hdd_warn("set PMKSA for " MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014357 MAC_ADDR_ARRAY(pmksa->bssid));
14358
14359 status = wlan_hdd_validate_context(pHddCtx);
14360
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014361 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014362 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014363
14364 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
14365
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014366 qdf_mem_copy(pmk_id.BSSID.bytes, pmksa->bssid, QDF_MAC_ADDR_SIZE);
14367 qdf_mem_copy(pmk_id.PMKID, pmksa->pmkid, CSR_RSN_PMKID_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014368
14369 /* Add to the PMKSA ID Cache in CSR */
14370 result = sme_roam_set_pmkid_cache(halHandle, pAdapter->sessionId,
14371 &pmk_id, 1, false);
14372
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014373 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014374 TRACE_CODE_HDD_CFG80211_SET_PMKSA,
14375 pAdapter->sessionId, result));
14376
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014377 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014378 return QDF_IS_STATUS_SUCCESS(result) ? 0 : -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014379}
14380
14381/**
14382 * wlan_hdd_cfg80211_set_pmksa() - set pmksa
14383 * @wiphy: Pointer to wiphy
14384 * @dev: Pointer to network device
14385 * @pmksa: Pointer to set pmksa parameter
14386 *
14387 * Return: 0 for success, non-zero for failure
14388 */
14389static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy,
14390 struct net_device *dev,
14391 struct cfg80211_pmksa *pmksa)
14392{
14393 int ret;
14394
14395 cds_ssr_protect(__func__);
14396 ret = __wlan_hdd_cfg80211_set_pmksa(wiphy, dev, pmksa);
14397 cds_ssr_unprotect(__func__);
14398
14399 return ret;
14400}
14401
14402/**
14403 * __wlan_hdd_cfg80211_del_pmksa() - delete pmksa
14404 * @wiphy: Pointer to wiphy
14405 * @dev: Pointer to network device
14406 * @pmksa: Pointer to pmksa parameter
14407 *
14408 * Return: 0 for success, non-zero for failure
14409 */
14410static int __wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy,
14411 struct net_device *dev,
14412 struct cfg80211_pmksa *pmksa)
14413{
14414 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14415 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14416 tHalHandle halHandle;
14417 int status = 0;
14418
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014419 ENTER();
14420
Anurag Chouhan6d760662016-02-20 16:05:43 +053014421 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014422 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014423 return -EINVAL;
14424 }
14425
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014426 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14427 hdd_err("invalid session id: %d", pAdapter->sessionId);
14428 return -EINVAL;
14429 }
14430
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014431 if (!pmksa) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014432 hdd_err("pmksa is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014433 return -EINVAL;
14434 }
14435
14436 if (!pmksa->bssid) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014437 hdd_err("pmksa->bssid is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014438 return -EINVAL;
14439 }
14440
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014441 hdd_debug("Deleting PMKSA for " MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014442 MAC_ADDR_ARRAY(pmksa->bssid));
14443
14444 status = wlan_hdd_validate_context(pHddCtx);
14445
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014446 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014447 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014448
14449 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
14450
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014451 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +053014452 TRACE_CODE_HDD_CFG80211_DEL_PMKSA,
14453 pAdapter->sessionId, 0));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014454 /* Delete the PMKID CSR cache */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014455 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014456 sme_roam_del_pmkid_from_cache(halHandle,
14457 pAdapter->sessionId, pmksa->bssid,
14458 false)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014459 hdd_err("Failed to delete PMKSA for " MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014460 MAC_ADDR_ARRAY(pmksa->bssid));
14461 status = -EINVAL;
14462 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014463 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014464 return status;
14465}
14466
14467/**
14468 * wlan_hdd_cfg80211_del_pmksa() - delete pmksa
14469 * @wiphy: Pointer to wiphy
14470 * @dev: Pointer to network device
14471 * @pmksa: Pointer to pmksa parameter
14472 *
14473 * Return: 0 for success, non-zero for failure
14474 */
14475static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy,
14476 struct net_device *dev,
14477 struct cfg80211_pmksa *pmksa)
14478{
14479 int ret;
14480
14481 cds_ssr_protect(__func__);
14482 ret = __wlan_hdd_cfg80211_del_pmksa(wiphy, dev, pmksa);
14483 cds_ssr_unprotect(__func__);
14484
14485 return ret;
14486
14487}
14488
14489/**
14490 * __wlan_hdd_cfg80211_flush_pmksa() - flush pmksa
14491 * @wiphy: Pointer to wiphy
14492 * @dev: Pointer to network device
14493 *
14494 * Return: 0 for success, non-zero for failure
14495 */
14496static int __wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy,
14497 struct net_device *dev)
14498{
14499 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14500 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14501 tHalHandle halHandle;
14502 int status = 0;
14503
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014504 ENTER();
14505
Anurag Chouhan6d760662016-02-20 16:05:43 +053014506 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014507 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014508 return -EINVAL;
14509 }
14510
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014511 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14512 hdd_err("invalid session id: %d", pAdapter->sessionId);
14513 return -EINVAL;
14514 }
14515
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014516 hdd_warn("Flushing PMKSA");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014517
14518 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14519 status = wlan_hdd_validate_context(pHddCtx);
14520
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014521 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014522 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014523
14524 /* Retrieve halHandle */
14525 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
14526
14527 /* Flush the PMKID cache in CSR */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014528 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014529 sme_roam_del_pmkid_from_cache(halHandle, pAdapter->sessionId, NULL,
14530 true)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014531 hdd_err("Cannot flush PMKIDCache");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014532 status = -EINVAL;
14533 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014534 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014535 return status;
14536}
14537
14538/**
14539 * wlan_hdd_cfg80211_flush_pmksa() - flush pmksa
14540 * @wiphy: Pointer to wiphy
14541 * @dev: Pointer to network device
14542 *
14543 * Return: 0 for success, non-zero for failure
14544 */
14545static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy,
14546 struct net_device *dev)
14547{
14548 int ret;
14549
14550 cds_ssr_protect(__func__);
14551 ret = __wlan_hdd_cfg80211_flush_pmksa(wiphy, dev);
14552 cds_ssr_unprotect(__func__);
14553
14554 return ret;
14555}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014556
Deepak Dhamdhere9f09e752016-01-09 23:17:25 -080014557#if defined(KERNEL_SUPPORT_11R_CFG80211)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014558/**
14559 * __wlan_hdd_cfg80211_update_ft_ies() - update fast transition ies
14560 * @wiphy: Pointer to wiphy
14561 * @dev: Pointer to network device
14562 * @ftie: Pointer to fast transition ie parameter
14563 *
14564 * Return: 0 for success, non-zero for failure
14565 */
14566static int
14567__wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
14568 struct net_device *dev,
14569 struct cfg80211_update_ft_ies_params *ftie)
14570{
14571 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
14572 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14573 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
14574 int status;
14575
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014576 ENTER();
14577
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014578 status = wlan_hdd_validate_context(hdd_ctx);
14579 if (status)
14580 return status;
14581
Anurag Chouhan6d760662016-02-20 16:05:43 +053014582 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014583 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014584 return -EINVAL;
14585 }
14586
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014587 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14588 hdd_err("invalid session id: %d", pAdapter->sessionId);
14589 return -EINVAL;
14590 }
14591
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014592 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014593 TRACE_CODE_HDD_CFG80211_UPDATE_FT_IES,
14594 pAdapter->sessionId, pHddStaCtx->conn_info.connState));
14595 /* Added for debug on reception of Re-assoc Req. */
14596 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014597 hdd_err("Called with Ie of length = %zu when not associated",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014598 ftie->ie_len);
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014599 hdd_err("Should be Re-assoc Req IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014600 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014601 hdd_notice("%s called with Ie of length = %zu", __func__,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014602 ftie->ie_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014603
14604 /* Pass the received FT IEs to SME */
14605 sme_set_ft_ies(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
14606 (const u8 *)ftie->ie, ftie->ie_len);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014607 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014608 return 0;
14609}
14610
14611/**
14612 * wlan_hdd_cfg80211_update_ft_ies() - update fast transition ies
14613 * @wiphy: Pointer to wiphy
14614 * @dev: Pointer to network device
14615 * @ftie: Pointer to fast transition ie parameter
14616 *
14617 * Return: 0 for success, non-zero for failure
14618 */
14619static int
14620wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
14621 struct net_device *dev,
14622 struct cfg80211_update_ft_ies_params *ftie)
14623{
14624 int ret;
14625
14626 cds_ssr_protect(__func__);
14627 ret = __wlan_hdd_cfg80211_update_ft_ies(wiphy, dev, ftie);
14628 cds_ssr_unprotect(__func__);
14629
14630 return ret;
14631}
14632#endif
14633
14634#ifdef WLAN_FEATURE_GTK_OFFLOAD
14635/**
14636 * wlan_hdd_cfg80211_update_replay_counter_callback() - replay counter callback
14637 * @callbackContext: Callback context
14638 * @pGtkOffloadGetInfoRsp: Pointer to gtk offload response parameter
14639 *
14640 * Callback rountine called upon receiving response for get offload info
14641 *
14642 * Return: none
14643 */
14644void wlan_hdd_cfg80211_update_replay_counter_callback(void *callbackContext,
14645 tpSirGtkOffloadGetInfoRspParams
14646 pGtkOffloadGetInfoRsp)
14647{
14648 hdd_adapter_t *pAdapter = (hdd_adapter_t *) callbackContext;
14649 uint8_t tempReplayCounter[8];
14650 hdd_station_ctx_t *pHddStaCtx;
14651
14652 ENTER();
14653
14654 if (NULL == pAdapter) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014655 hdd_err("HDD adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014656 return;
14657 }
14658
14659 if (NULL == pGtkOffloadGetInfoRsp) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014660 hdd_err("pGtkOffloadGetInfoRsp is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014661 return;
14662 }
14663
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014664 if (QDF_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014665 hdd_err("wlan Failed to get replay counter value");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014666 return;
14667 }
14668
14669 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
14670 /* Update replay counter */
14671 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
14672 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
14673
14674 {
14675 /* changing from little to big endian since supplicant
14676 * works on big endian format
14677 */
14678 int i;
14679 uint8_t *p =
14680 (uint8_t *) &pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
14681
14682 for (i = 0; i < 8; i++) {
14683 tempReplayCounter[7 - i] = (uint8_t) p[i];
14684 }
14685 }
14686
14687 /* Update replay counter to NL */
Srinivas Girigowda2213b1d2015-11-20 17:10:11 -080014688 cfg80211_gtk_rekey_notify(pAdapter->dev,
14689 pGtkOffloadGetInfoRsp->bssid.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014690 tempReplayCounter, GFP_KERNEL);
14691}
14692
14693/**
14694 * __wlan_hdd_cfg80211_set_rekey_data() - set rekey data
14695 * @wiphy: Pointer to wiphy
14696 * @dev: Pointer to network device
14697 * @data: Pointer to rekey data
14698 *
14699 * This function is used to offload GTK rekeying job to the firmware.
14700 *
14701 * Return: 0 for success, non-zero for failure
14702 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070014703static
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014704int __wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy,
14705 struct net_device *dev,
14706 struct cfg80211_gtk_rekey_data *data)
14707{
14708 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14709 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
14710 hdd_station_ctx_t *pHddStaCtx;
14711 tHalHandle hHal;
14712 int result;
14713 tSirGtkOffloadParams hddGtkOffloadReqParams;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014714 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014715
14716 ENTER();
14717
Anurag Chouhan6d760662016-02-20 16:05:43 +053014718 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014719 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014720 return -EINVAL;
14721 }
14722
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053014723 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
14724 hdd_err("invalid session id: %d", pAdapter->sessionId);
14725 return -EINVAL;
14726 }
14727
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014728 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014729 TRACE_CODE_HDD_CFG80211_SET_REKEY_DATA,
14730 pAdapter->sessionId, pAdapter->device_mode));
14731
14732 result = wlan_hdd_validate_context(pHddCtx);
14733
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014734 if (0 != result)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014735 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014736
14737 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
14738 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
14739 if (NULL == hHal) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014740 hdd_err("HAL context is Null!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014741 return -EAGAIN;
14742 }
14743
14744 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
14745 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck,
14746 NL80211_KCK_LEN);
14747 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek,
14748 NL80211_KEK_LEN);
Anurag Chouhanc5548422016-02-24 18:33:27 +053014749 qdf_copy_macaddr(&pHddStaCtx->gtkOffloadReqParams.bssid,
Srinivas Girigowda2213b1d2015-11-20 17:10:11 -080014750 &pHddStaCtx->conn_info.bssId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014751 {
14752 /* changing from big to little endian since driver
14753 * works on little endian format
14754 */
14755 uint8_t *p =
14756 (uint8_t *) &pHddStaCtx->gtkOffloadReqParams.
14757 ullKeyReplayCounter;
14758 int i;
14759
14760 for (i = 0; i < 8; i++) {
14761 p[7 - i] = data->replay_ctr[i];
14762 }
14763 }
14764
14765 if (true == pHddCtx->hdd_wlan_suspended) {
14766 /* if wlan is suspended, enable GTK offload directly from here */
14767 memcpy(&hddGtkOffloadReqParams,
14768 &pHddStaCtx->gtkOffloadReqParams,
14769 sizeof(tSirGtkOffloadParams));
14770 status =
14771 sme_set_gtk_offload(hHal, &hddGtkOffloadReqParams,
14772 pAdapter->sessionId);
14773
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014774 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014775 hdd_err("sme_set_gtk_offload failed, status(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014776 status);
14777 return -EINVAL;
14778 }
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014779 hdd_notice("sme_set_gtk_offload successful");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014780 } else {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014781 hdd_notice("wlan not suspended GTKOffload request is stored");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014782 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014783 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014784 return result;
14785}
14786
14787/**
14788 * wlan_hdd_cfg80211_set_rekey_data() - set rekey data
14789 * @wiphy: Pointer to wiphy
14790 * @dev: Pointer to network device
14791 * @data: Pointer to rekey data
14792 *
14793 * This function is used to offload GTK rekeying job to the firmware.
14794 *
14795 * Return: 0 for success, non-zero for failure
14796 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070014797static
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014798int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy,
14799 struct net_device *dev,
14800 struct cfg80211_gtk_rekey_data *data)
14801{
14802 int ret;
14803
14804 cds_ssr_protect(__func__);
14805 ret = __wlan_hdd_cfg80211_set_rekey_data(wiphy, dev, data);
14806 cds_ssr_unprotect(__func__);
14807
14808 return ret;
14809}
14810#endif /*WLAN_FEATURE_GTK_OFFLOAD */
14811
14812/**
14813 * __wlan_hdd_cfg80211_set_mac_acl() - set access control policy
14814 * @wiphy: Pointer to wiphy
14815 * @dev: Pointer to network device
14816 * @param: Pointer to access control parameter
14817 *
14818 * Return: 0 for success, non-zero for failure
14819 */
14820static int __wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
14821 struct net_device *dev,
14822 const struct cfg80211_acl_data *params)
14823{
14824 int i;
14825 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
14826 hdd_hostapd_state_t *pHostapdState;
14827 tsap_Config_t *pConfig;
14828 v_CONTEXT_t p_cds_context = NULL;
14829 hdd_context_t *pHddCtx;
14830 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014831 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014832
14833 ENTER();
14834
Anurag Chouhan6d760662016-02-20 16:05:43 +053014835 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014836 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014837 return -EINVAL;
14838 }
14839
14840 if (NULL == params) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014841 hdd_err("params is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014842 return -EINVAL;
14843 }
14844
14845 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
14846 status = wlan_hdd_validate_context(pHddCtx);
14847
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014848 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014849 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014850
14851 p_cds_context = pHddCtx->pcds_context;
14852 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
14853
14854 if (NULL == pHostapdState) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014855 hdd_err("pHostapdState is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014856 return -EINVAL;
14857 }
14858
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014859 hdd_err("acl policy: = %d no acl entries = %d", params->acl_policy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014860 params->n_acl_entries);
14861
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053014862 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +053014863 TRACE_CODE_HDD_CFG80211_SET_MAC_ACL,
14864 pAdapter->sessionId, pAdapter->device_mode));
Krunal Sonib4326f22016-03-10 13:05:51 -080014865 if (QDF_SAP_MODE == pAdapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014866 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
14867
14868 /* default value */
14869 pConfig->num_accept_mac = 0;
14870 pConfig->num_deny_mac = 0;
14871
14872 /**
14873 * access control policy
14874 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
14875 * listed in hostapd.deny file.
14876 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
14877 * listed in hostapd.accept file.
14878 */
14879 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy) {
14880 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
14881 } else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED ==
14882 params->acl_policy) {
14883 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
14884 } else {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014885 hdd_err("Acl Policy : %d is not supported",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014886 params->acl_policy);
14887 return -ENOTSUPP;
14888 }
14889
14890 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl) {
14891 pConfig->num_accept_mac = params->n_acl_entries;
14892 for (i = 0; i < params->n_acl_entries; i++) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014893 hdd_notice("** Add ACL MAC entry %i in WhiletList :"
14894 MAC_ADDRESS_STR, i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014895 MAC_ADDR_ARRAY(
14896 params->mac_addrs[i].addr));
14897
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014898 qdf_mem_copy(&pConfig->accept_mac[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014899 params->mac_addrs[i].addr,
14900 sizeof(qcmacaddr));
14901 }
14902 } else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl) {
14903 pConfig->num_deny_mac = params->n_acl_entries;
14904 for (i = 0; i < params->n_acl_entries; i++) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014905 hdd_notice("** Add ACL MAC entry %i in BlackList :"
14906 MAC_ADDRESS_STR, i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014907 MAC_ADDR_ARRAY(
14908 params->mac_addrs[i].addr));
14909
Anurag Chouhan600c3a02016-03-01 10:33:54 +053014910 qdf_mem_copy(&pConfig->deny_mac[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014911 params->mac_addrs[i].addr,
14912 sizeof(qcmacaddr));
14913 }
14914 }
Dustin Brown6ba30a12016-09-13 13:59:43 -070014915 qdf_status = wlansap_set_mac_acl(
14916 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), pConfig);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053014917 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014918 hdd_err("SAP Set Mac Acl fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014919 return -EINVAL;
14920 }
14921 } else {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014922 hdd_notice("Invalid device_mode %s(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014923 hdd_device_mode_to_string(pAdapter->device_mode),
14924 pAdapter->device_mode);
14925 return -EINVAL;
14926 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014927 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014928 return 0;
14929}
14930
14931/**
14932 * wlan_hdd_cfg80211_set_mac_acl() - SSR wrapper for
14933 * __wlan_hdd_cfg80211_set_mac_acl
14934 * @wiphy: pointer to wiphy structure
14935 * @dev: pointer to net_device
14936 * @params: pointer to cfg80211_acl_data
14937 *
14938 * Return; 0 on success, error number otherwise
14939 */
14940static int
14941wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
14942 struct net_device *dev,
14943 const struct cfg80211_acl_data *params)
14944{
14945 int ret;
14946
14947 cds_ssr_protect(__func__);
14948 ret = __wlan_hdd_cfg80211_set_mac_acl(wiphy, dev, params);
14949 cds_ssr_unprotect(__func__);
14950
14951 return ret;
14952}
14953
14954#ifdef WLAN_NL80211_TESTMODE
14955#ifdef FEATURE_WLAN_LPHB
14956/**
14957 * wlan_hdd_cfg80211_lphb_ind_handler() - handle low power heart beat indication
14958 * @pHddCtx: Pointer to hdd context
14959 * @lphbInd: Pointer to low power heart beat indication parameter
14960 *
14961 * Return: none
14962 */
Jeff Johnson8b8a04b2016-10-05 15:49:43 -070014963static void wlan_hdd_cfg80211_lphb_ind_handler(void *pHddCtx,
14964 tSirLPHBInd *lphbInd)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014965{
14966 struct sk_buff *skb;
14967
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014968 hdd_err("LPHB indication arrived");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014969
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053014970 if (0 != wlan_hdd_validate_context((hdd_context_t *) pHddCtx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014971 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014972
14973 if (NULL == lphbInd) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014974 hdd_err("invalid argument lphbInd");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014975 return;
14976 }
14977
14978 skb = cfg80211_testmode_alloc_event_skb(((hdd_context_t *) pHddCtx)->
14979 wiphy, sizeof(tSirLPHBInd),
14980 GFP_ATOMIC);
14981 if (!skb) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014982 hdd_err("LPHB timeout, NL buffer alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014983 return;
14984 }
14985
14986 if (nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014987 hdd_err("WLAN_HDD_TM_ATTR_CMD put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014988 goto nla_put_failure;
14989 }
14990 if (nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014991 hdd_err("WLAN_HDD_TM_ATTR_TYPE put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014992 goto nla_put_failure;
14993 }
14994 if (nla_put(skb, WLAN_HDD_TM_ATTR_DATA, sizeof(tSirLPHBInd), lphbInd)) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070014995 hdd_err("WLAN_HDD_TM_ATTR_DATA put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014996 goto nla_put_failure;
14997 }
14998 cfg80211_testmode_event(skb, GFP_ATOMIC);
14999 return;
15000
15001nla_put_failure:
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015002 hdd_err("NLA Put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015003 kfree_skb(skb);
15004
15005 return;
15006}
15007#endif /* FEATURE_WLAN_LPHB */
15008
15009/**
15010 * __wlan_hdd_cfg80211_testmode() - test mode
15011 * @wiphy: Pointer to wiphy
15012 * @data: Data pointer
15013 * @len: Data length
15014 *
15015 * Return: 0 for success, non-zero for failure
15016 */
15017static int __wlan_hdd_cfg80211_testmode(struct wiphy *wiphy,
15018 void *data, int len)
15019{
15020 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
15021 int err;
15022 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
15023
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053015024 ENTER();
15025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015026 err = wlan_hdd_validate_context(pHddCtx);
15027 if (err)
15028 return err;
15029
15030 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data,
15031 len, wlan_hdd_tm_policy);
15032 if (err) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015033 hdd_err("Testmode INV ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015034 return err;
15035 }
15036
15037 if (!tb[WLAN_HDD_TM_ATTR_CMD]) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015038 hdd_err("Testmode INV CMD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015039 return -EINVAL;
15040 }
15041
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053015042 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +053015043 TRACE_CODE_HDD_CFG80211_TESTMODE,
15044 NO_SESSION, nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD])));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015045 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD])) {
15046#ifdef FEATURE_WLAN_LPHB
15047 /* Low Power Heartbeat configuration request */
15048 case WLAN_HDD_TM_CMD_WLAN_HB:
15049 {
15050 int buf_len;
15051 void *buf;
15052 tSirLPHBReq *hb_params = NULL;
15053 tSirLPHBReq *hb_params_temp = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053015054 QDF_STATUS smeStatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015055
15056 if (!tb[WLAN_HDD_TM_ATTR_DATA]) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015057 hdd_err("Testmode INV DATA");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015058 return -EINVAL;
15059 }
15060
15061 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
15062 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
15063
15064 hb_params_temp = (tSirLPHBReq *) buf;
15065 if ((hb_params_temp->cmd == LPHB_SET_TCP_PARAMS_INDID)
15066 && (hb_params_temp->params.lphbTcpParamReq.
15067 timePeriodSec == 0))
15068 return -EINVAL;
15069
15070 hb_params =
Anurag Chouhan600c3a02016-03-01 10:33:54 +053015071 (tSirLPHBReq *) qdf_mem_malloc(sizeof(tSirLPHBReq));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015072 if (NULL == hb_params) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015073 hdd_err("Request Buffer Alloc Fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015074 return -ENOMEM;
15075 }
15076
Anurag Chouhan600c3a02016-03-01 10:33:54 +053015077 qdf_mem_copy(hb_params, buf, buf_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015078 smeStatus =
15079 sme_lphb_config_req((tHalHandle) (pHddCtx->hHal),
15080 hb_params,
15081 wlan_hdd_cfg80211_lphb_ind_handler);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053015082 if (QDF_STATUS_SUCCESS != smeStatus) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015083 hdd_err("LPHB Config Fail, disable");
Anurag Chouhan600c3a02016-03-01 10:33:54 +053015084 qdf_mem_free(hb_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015085 }
15086 return 0;
15087 }
15088#endif /* FEATURE_WLAN_LPHB */
15089
15090#if defined(QCA_WIFI_FTM)
15091 case WLAN_HDD_TM_CMD_WLAN_FTM:
15092 {
15093 int buf_len;
15094 void *buf;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053015095 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015096 if (!tb[WLAN_HDD_TM_ATTR_DATA]) {
Ryan Hsucfef0ae2016-04-28 10:20:46 -070015097 hdd_err("WLAN_HDD_TM_ATTR_DATA attribute is invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015098 return -EINVAL;
15099 }
15100
15101 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
15102 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
15103
Ryan Hsucfef0ae2016-04-28 10:20:46 -070015104 hdd_info("****FTM Tx cmd len = %d*****", buf_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015105
15106 status = wlan_hdd_ftm_testmode_cmd(buf, buf_len);
15107
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053015108 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015109 err = -EBUSY;
15110 break;
15111 }
15112#endif
15113
15114 default:
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015115 hdd_err("command %d not supported",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015116 nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]));
15117 return -EOPNOTSUPP;
15118 }
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +053015119 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015120 return err;
15121}
15122
15123/**
15124 * wlan_hdd_cfg80211_testmode() - test mode
15125 * @wiphy: Pointer to wiphy
15126 * @dev: Pointer to network device
15127 * @data: Data pointer
15128 * @len: Data length
15129 *
15130 * Return: 0 for success, non-zero for failure
15131 */
15132static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy,
15133#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0))
15134 struct wireless_dev *wdev,
15135#endif
15136 void *data, int len)
15137{
15138 int ret;
15139
15140 cds_ssr_protect(__func__);
15141 ret = __wlan_hdd_cfg80211_testmode(wiphy, data, len);
15142 cds_ssr_unprotect(__func__);
15143
15144 return ret;
15145}
15146
15147#if defined(QCA_WIFI_FTM)
15148/**
15149 * wlan_hdd_testmode_rx_event() - test mode rx event handler
15150 * @buf: Pointer to buffer
15151 * @buf_len: Buffer length
15152 *
15153 * Return: none
15154 */
15155void wlan_hdd_testmode_rx_event(void *buf, size_t buf_len)
15156{
15157 struct sk_buff *skb;
15158 hdd_context_t *hdd_ctx;
15159
15160 if (!buf || !buf_len) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015161 hdd_err("buf or buf_len invalid, buf = %p buf_len = %zu", buf, buf_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015162 return;
15163 }
15164
Anurag Chouhan6d760662016-02-20 16:05:43 +053015165 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015166 if (!hdd_ctx) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015167 hdd_err("hdd context invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015168 return;
15169 }
15170
15171 skb = cfg80211_testmode_alloc_event_skb(hdd_ctx->wiphy,
15172 buf_len, GFP_KERNEL);
15173 if (!skb) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015174 hdd_err("failed to allocate testmode rx skb!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015175 return;
15176 }
15177
15178 if (nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_FTM) ||
15179 nla_put(skb, WLAN_HDD_TM_ATTR_DATA, buf_len, buf))
15180 goto nla_put_failure;
15181
Ryan Hsucfef0ae2016-04-28 10:20:46 -070015182 hdd_info("****FTM Rx cmd len = %zu*****", buf_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015183
15184 cfg80211_testmode_event(skb, GFP_KERNEL);
15185 return;
15186
15187nla_put_failure:
15188 kfree_skb(skb);
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015189 hdd_err("nla_put failed on testmode rx skb!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015190}
15191#endif
15192#endif /* CONFIG_NL80211_TESTMODE */
15193
15194#ifdef QCA_HT_2040_COEX
15195/**
15196 * __wlan_hdd_cfg80211_set_ap_channel_width() - set ap channel bandwidth
15197 * @wiphy: Pointer to wiphy
15198 * @dev: Pointer to network device
15199 * @chandef: Pointer to channel definition parameter
15200 *
15201 * Return: 0 for success, non-zero for failure
15202 */
15203static int
15204__wlan_hdd_cfg80211_set_ap_channel_width(struct wiphy *wiphy,
15205 struct net_device *dev,
15206 struct cfg80211_chan_def *chandef)
15207{
15208 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
15209 hdd_context_t *pHddCtx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053015210 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015211 tSmeConfigParams sme_config;
Anurag Chouhan00ed5272016-10-17 17:22:55 +053015212 bool cbModeChange = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015213
Anurag Chouhan6d760662016-02-20 16:05:43 +053015214 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015215 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015216 return -EINVAL;
15217 }
15218
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053015219 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
15220 hdd_err("invalid session id: %d", pAdapter->sessionId);
15221 return -EINVAL;
15222 }
15223
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015224 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
15225 status = wlan_hdd_validate_context(pHddCtx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053015226 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015227 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015228
Anurag Chouhan600c3a02016-03-01 10:33:54 +053015229 qdf_mem_zero(&sme_config, sizeof(tSmeConfigParams));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015230 sme_get_config_param(pHddCtx->hHal, &sme_config);
15231 switch (chandef->width) {
15232 case NL80211_CHAN_WIDTH_20:
15233 if (sme_config.csrConfig.channelBondingMode24GHz !=
15234 eCSR_INI_SINGLE_CHANNEL_CENTERED) {
15235 sme_config.csrConfig.channelBondingMode24GHz =
15236 eCSR_INI_SINGLE_CHANNEL_CENTERED;
15237 sme_update_config(pHddCtx->hHal, &sme_config);
15238 cbModeChange = true;
15239 }
15240 break;
15241
15242 case NL80211_CHAN_WIDTH_40:
15243 if (sme_config.csrConfig.channelBondingMode24GHz ==
15244 eCSR_INI_SINGLE_CHANNEL_CENTERED) {
15245 if (NL80211_CHAN_HT40MINUS ==
15246 cfg80211_get_chandef_type(chandef))
15247 sme_config.csrConfig.channelBondingMode24GHz =
15248 eCSR_INI_DOUBLE_CHANNEL_HIGH_PRIMARY;
15249 else
15250 sme_config.csrConfig.channelBondingMode24GHz =
15251 eCSR_INI_DOUBLE_CHANNEL_LOW_PRIMARY;
15252 sme_update_config(pHddCtx->hHal, &sme_config);
15253 cbModeChange = true;
15254 }
15255 break;
15256
15257 default:
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015258 hdd_err("Error!!! Invalid HT20/40 mode !");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015259 return -EINVAL;
15260 }
15261
15262 if (!cbModeChange)
15263 return 0;
15264
Krunal Sonib4326f22016-03-10 13:05:51 -080015265 if (QDF_SAP_MODE != pAdapter->device_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015266 return 0;
15267
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015268 hdd_notice("Channel bonding changed to %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015269 sme_config.csrConfig.channelBondingMode24GHz);
15270
15271 /* Change SAP ht2040 mode */
15272 status = hdd_set_sap_ht2040_mode(pAdapter,
15273 cfg80211_get_chandef_type(chandef));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053015274 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015275 hdd_err("Error!!! Cannot set SAP HT20/40 mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015276 return -EINVAL;
15277 }
15278
15279 return 0;
15280}
15281
15282/**
15283 * wlan_hdd_cfg80211_set_ap_channel_width() - set ap channel bandwidth
15284 * @wiphy: Pointer to wiphy
15285 * @dev: Pointer to network device
15286 * @chandef: Pointer to channel definition parameter
15287 *
15288 * Return: 0 for success, non-zero for failure
15289 */
15290static int
15291wlan_hdd_cfg80211_set_ap_channel_width(struct wiphy *wiphy,
15292 struct net_device *dev,
15293 struct cfg80211_chan_def *chandef)
15294{
15295 int ret;
15296
15297 cds_ssr_protect(__func__);
15298 ret = __wlan_hdd_cfg80211_set_ap_channel_width(wiphy, dev, chandef);
15299 cds_ssr_unprotect(__func__);
15300
15301 return ret;
15302}
15303#endif
15304
Abhishek Singh1bdb1572015-10-16 16:24:19 +053015305#ifdef CHANNEL_SWITCH_SUPPORTED
15306/**
15307 * __wlan_hdd_cfg80211_channel_switch()- function to switch
15308 * channel in SAP/GO
15309 * @wiphy: wiphy pointer
15310 * @dev: dev pointer.
15311 * @csa_params: Change channel params
15312 *
15313 * This function is called to switch channel in SAP/GO
15314 *
15315 * Return: 0 if success else return non zero
15316 */
15317static int __wlan_hdd_cfg80211_channel_switch(struct wiphy *wiphy,
15318 struct net_device *dev,
15319 struct cfg80211_csa_settings *csa_params)
15320{
15321 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
15322 hdd_context_t *hdd_ctx;
15323 uint8_t channel;
15324 uint16_t freq;
15325 int ret;
Kiran Kumar Lokere13644672016-02-29 15:40:10 -080015326 enum phy_ch_width ch_width;
Abhishek Singh1bdb1572015-10-16 16:24:19 +053015327
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015328 hdd_notice("Set Freq %d",
Abhishek Singh1bdb1572015-10-16 16:24:19 +053015329 csa_params->chandef.chan->center_freq);
15330
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +053015331 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
15332 hdd_err("invalid session id: %d", adapter->sessionId);
15333 return -EINVAL;
15334 }
15335
Abhishek Singh1bdb1572015-10-16 16:24:19 +053015336 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
15337 ret = wlan_hdd_validate_context(hdd_ctx);
15338
15339 if (0 != ret)
15340 return ret;
15341
Krunal Sonib4326f22016-03-10 13:05:51 -080015342 if ((QDF_P2P_GO_MODE != adapter->device_mode) &&
15343 (QDF_SAP_MODE != adapter->device_mode))
Abhishek Singh1bdb1572015-10-16 16:24:19 +053015344 return -ENOTSUPP;
15345
15346 freq = csa_params->chandef.chan->center_freq;
15347 channel = cds_freq_to_chan(freq);
15348
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +053015349 ch_width = hdd_map_nl_chan_width(csa_params->chandef.width);
15350
15351 ret = hdd_softap_set_channel_change(dev, channel, ch_width);
Abhishek Singh1bdb1572015-10-16 16:24:19 +053015352 return ret;
15353}
15354
15355/**
15356 * wlan_hdd_cfg80211_channel_switch()- function to switch
15357 * channel in SAP/GO
15358 * @wiphy: wiphy pointer
15359 * @dev: dev pointer.
15360 * @csa_params: Change channel params
15361 *
15362 * This function is called to switch channel in SAP/GO
15363 *
15364 * Return: 0 if success else return non zero
15365 */
15366static int wlan_hdd_cfg80211_channel_switch(struct wiphy *wiphy,
15367 struct net_device *dev,
15368 struct cfg80211_csa_settings *csa_params)
15369{
15370 int ret;
15371
15372 cds_ssr_protect(__func__);
15373 ret = __wlan_hdd_cfg80211_channel_switch(wiphy, dev, csa_params);
15374 cds_ssr_unprotect(__func__);
15375 return ret;
15376}
15377#endif
15378
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015379/**
15380 * wlan_hdd_convert_nl_iftype_to_hdd_type() - provides the type
15381 * translation from NL to policy manager type
15382 * @type: Generic connection mode type defined in NL
15383 *
15384 *
15385 * This function provides the type translation
15386 *
15387 * Return: cds_con_mode enum
15388 */
15389enum cds_con_mode wlan_hdd_convert_nl_iftype_to_hdd_type(
15390 enum nl80211_iftype type)
15391{
15392 enum cds_con_mode mode = CDS_MAX_NUM_OF_MODE;
15393 switch (type) {
15394 case NL80211_IFTYPE_STATION:
15395 mode = CDS_STA_MODE;
15396 break;
15397 case NL80211_IFTYPE_P2P_CLIENT:
15398 mode = CDS_P2P_CLIENT_MODE;
15399 break;
15400 case NL80211_IFTYPE_P2P_GO:
15401 mode = CDS_P2P_GO_MODE;
15402 break;
15403 case NL80211_IFTYPE_AP:
15404 mode = CDS_SAP_MODE;
15405 break;
15406 case NL80211_IFTYPE_ADHOC:
15407 mode = CDS_IBSS_MODE;
15408 break;
15409 default:
Jeff Johnson3d8ac552016-06-29 15:21:37 -070015410 hdd_err("Unsupported interface type (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015411 type);
15412 }
15413 return mode;
15414}
15415
15416/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070015417 * wlan_hdd_cfg80211_set_mon_ch() - Set monitor mode capture channel
15418 * @wiphy: Handle to struct wiphy to get handle to module context.
15419 * @chandef: Contains information about the capture channel to be set.
15420 *
15421 * This interface is called if and only if monitor mode interface alone is
15422 * active.
15423 *
15424 * Return: 0 success or error code on failure.
15425 */
15426static int __wlan_hdd_cfg80211_set_mon_ch(struct wiphy *wiphy,
15427 struct cfg80211_chan_def *chandef)
15428{
15429 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
15430 hdd_adapter_t *adapter;
15431 hdd_station_ctx_t *sta_ctx;
15432 struct hdd_mon_set_ch_info *ch_info;
15433 QDF_STATUS status;
15434 tHalHandle hal_hdl;
15435 struct qdf_mac_addr bssid;
15436 tCsrRoamProfile roam_profile;
15437 struct ch_params_s ch_params;
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070015438 uint8_t sec_ch = 0;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070015439 int ret;
15440 uint16_t chan_num = cds_freq_to_chan(chandef->chan->center_freq);
15441
15442 ENTER();
15443
15444 ret = wlan_hdd_validate_context(hdd_ctx);
15445 if (ret)
15446 return ret;
15447
15448 hal_hdl = hdd_ctx->hHal;
15449
15450 adapter = hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
15451 if (!adapter)
15452 return -EIO;
15453
15454 hdd_info("%s: set monitor mode Channel %d and freq %d",
15455 adapter->dev->name, chan_num, chandef->chan->center_freq);
15456
15457 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
15458 ch_info = &sta_ctx->ch_info;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070015459 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
15460 roam_profile.ChannelInfo.numOfChannels = 1;
15461 roam_profile.phyMode = ch_info->phy_mode;
15462 roam_profile.ch_params.ch_width = chandef->width;
Naveen Rawatc77e6e72016-08-05 15:19:03 -070015463 hdd_select_cbmode(adapter, chan_num, &roam_profile.ch_params);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070015464
15465 qdf_mem_copy(bssid.bytes, adapter->macAddressCurrent.bytes,
15466 QDF_MAC_ADDR_SIZE);
15467
15468 ch_params.ch_width = chandef->width;
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -070015469 /*
15470 * CDS api expects secondary channel for calculating
15471 * the channel params
15472 */
15473 if ((ch_params.ch_width == CH_WIDTH_40MHZ) &&
15474 (CDS_IS_CHANNEL_24GHZ(chan_num))) {
15475 if (chan_num >= 1 && chan_num <= 5)
15476 sec_ch = chan_num + 4;
15477 else if (chan_num >= 6 && chan_num <= 13)
15478 sec_ch = chan_num - 4;
15479 }
15480 cds_set_channel_params(chan_num, sec_ch, &ch_params);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070015481 status = sme_roam_channel_change_req(hal_hdl, bssid, &ch_params,
15482 &roam_profile);
15483 if (status) {
15484 hdd_err("Status: %d Failed to set sme_RoamChannel for monitor mode",
15485 status);
15486 ret = qdf_status_to_os_return(status);
15487 return ret;
15488 }
15489 EXIT();
15490 return 0;
15491}
15492
15493/**
15494 * wlan_hdd_cfg80211_set_mon_ch() - Set monitor mode capture channel
15495 * @wiphy: Handle to struct wiphy to get handle to module context.
15496 * @chandef: Contains information about the capture channel to be set.
15497 *
15498 * This interface is called if and only if monitor mode interface alone is
15499 * active.
15500 *
15501 * Return: 0 success or error code on failure.
15502 */
15503static int wlan_hdd_cfg80211_set_mon_ch(struct wiphy *wiphy,
15504 struct cfg80211_chan_def *chandef)
15505{
15506 int ret;
15507
15508 cds_ssr_protect(__func__);
15509 ret = __wlan_hdd_cfg80211_set_mon_ch(wiphy, chandef);
15510 cds_ssr_unprotect(__func__);
15511 return ret;
15512}
15513
15514/**
Mahesh A Saptasagar6dda2022016-09-03 12:59:09 +053015515 * wlan_hdd_clear_link_layer_stats() - clear link layer stats
15516 * @adapter: pointer to adapter
15517 *
15518 * Wrapper function to clear link layer stats.
15519 * return - void
15520 */
15521void wlan_hdd_clear_link_layer_stats(hdd_adapter_t *adapter)
15522{
15523 tSirLLStatsClearReq link_layer_stats_clear_req;
15524 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
15525
Mukul Sharma491021c2016-09-29 21:39:19 +053015526 link_layer_stats_clear_req.statsClearReqMask = WIFI_STATS_IFACE_AC |
15527 WIFI_STATS_IFACE_ALL_PEER;
Mahesh A Saptasagar6dda2022016-09-03 12:59:09 +053015528 link_layer_stats_clear_req.stopReq = 0;
15529 link_layer_stats_clear_req.reqId = 1;
15530 link_layer_stats_clear_req.staId = adapter->sessionId;
15531 sme_ll_stats_clear_req(hal, &link_layer_stats_clear_req);
15532
15533 return;
15534}
15535
15536/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015537 * struct cfg80211_ops - cfg80211_ops
15538 *
15539 * @add_virtual_intf: Add virtual interface
15540 * @del_virtual_intf: Delete virtual interface
15541 * @change_virtual_intf: Change virtual interface
15542 * @change_station: Change station
15543 * @add_beacon: Add beacon in sap mode
15544 * @del_beacon: Delete beacon in sap mode
15545 * @set_beacon: Set beacon in sap mode
15546 * @start_ap: Start ap
15547 * @change_beacon: Change beacon
15548 * @stop_ap: Stop ap
15549 * @change_bss: Change bss
15550 * @add_key: Add key
15551 * @get_key: Get key
15552 * @del_key: Delete key
15553 * @set_default_key: Set default key
15554 * @set_channel: Set channel
15555 * @scan: Scan
15556 * @connect: Connect
15557 * @disconnect: Disconnect
15558 * @join_ibss = Join ibss
15559 * @leave_ibss = Leave ibss
15560 * @set_wiphy_params = Set wiphy params
15561 * @set_tx_power = Set tx power
15562 * @get_tx_power = get tx power
15563 * @remain_on_channel = Remain on channel
15564 * @cancel_remain_on_channel = Cancel remain on channel
15565 * @mgmt_tx = Tx management frame
15566 * @mgmt_tx_cancel_wait = Cancel management tx wait
15567 * @set_default_mgmt_key = Set default management key
15568 * @set_txq_params = Set tx queue parameters
15569 * @get_station = Get station
15570 * @set_power_mgmt = Set power management
15571 * @del_station = Delete station
15572 * @add_station = Add station
15573 * @set_pmksa = Set pmksa
15574 * @del_pmksa = Delete pmksa
15575 * @flush_pmksa = Flush pmksa
15576 * @update_ft_ies = Update FT IEs
15577 * @tdls_mgmt = Tdls management
15578 * @tdls_oper = Tdls operation
15579 * @set_rekey_data = Set rekey data
15580 * @sched_scan_start = Scheduled scan start
15581 * @sched_scan_stop = Scheduled scan stop
15582 * @resume = Resume wlan
15583 * @suspend = Suspend wlan
15584 * @set_mac_acl = Set mac acl
15585 * @testmode_cmd = Test mode command
15586 * @set_ap_chanwidth = Set AP channel bandwidth
15587 * @dump_survey = Dump survey
15588 * @key_mgmt_set_pmk = Set pmk key management
15589 */
15590static struct cfg80211_ops wlan_hdd_cfg80211_ops = {
15591 .add_virtual_intf = wlan_hdd_add_virtual_intf,
15592 .del_virtual_intf = wlan_hdd_del_virtual_intf,
15593 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
15594 .change_station = wlan_hdd_change_station,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015595 .start_ap = wlan_hdd_cfg80211_start_ap,
15596 .change_beacon = wlan_hdd_cfg80211_change_beacon,
15597 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015598 .change_bss = wlan_hdd_cfg80211_change_bss,
15599 .add_key = wlan_hdd_cfg80211_add_key,
15600 .get_key = wlan_hdd_cfg80211_get_key,
15601 .del_key = wlan_hdd_cfg80211_del_key,
15602 .set_default_key = wlan_hdd_cfg80211_set_default_key,
15603 .scan = wlan_hdd_cfg80211_scan,
15604 .connect = wlan_hdd_cfg80211_connect,
15605 .disconnect = wlan_hdd_cfg80211_disconnect,
15606 .join_ibss = wlan_hdd_cfg80211_join_ibss,
15607 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
15608 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
15609 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
15610 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
15611 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
15612 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
15613 .mgmt_tx = wlan_hdd_mgmt_tx,
15614 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
15615 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
15616 .set_txq_params = wlan_hdd_set_txq_params,
Himanshu Agarwal37e42412016-07-21 14:35:09 +053015617 .dump_station = wlan_hdd_cfg80211_dump_station,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015618 .get_station = wlan_hdd_cfg80211_get_station,
15619 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
15620 .del_station = wlan_hdd_cfg80211_del_station,
15621 .add_station = wlan_hdd_cfg80211_add_station,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015622 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
15623 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
15624 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
Deepak Dhamdhere9f09e752016-01-09 23:17:25 -080015625#if defined(KERNEL_SUPPORT_11R_CFG80211)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015626 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
15627#endif
15628#ifdef FEATURE_WLAN_TDLS
15629 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
15630 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
15631#endif
15632#ifdef WLAN_FEATURE_GTK_OFFLOAD
15633 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
15634#endif /* WLAN_FEATURE_GTK_OFFLOAD */
15635#ifdef FEATURE_WLAN_SCAN_PNO
15636 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
15637 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
15638#endif /*FEATURE_WLAN_SCAN_PNO */
15639 .resume = wlan_hdd_cfg80211_resume_wlan,
15640 .suspend = wlan_hdd_cfg80211_suspend_wlan,
15641 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
15642#ifdef WLAN_NL80211_TESTMODE
15643 .testmode_cmd = wlan_hdd_cfg80211_testmode,
15644#endif
15645#ifdef QCA_HT_2040_COEX
15646 .set_ap_chanwidth = wlan_hdd_cfg80211_set_ap_channel_width,
15647#endif
15648 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Abhishek Singh1bdb1572015-10-16 16:24:19 +053015649#ifdef CHANNEL_SWITCH_SUPPORTED
15650 .channel_switch = wlan_hdd_cfg80211_channel_switch,
15651#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -070015652 .set_monitor_channel = wlan_hdd_cfg80211_set_mon_ch,
Vidyullatha, Kanchanapally528789e2016-05-11 20:38:37 +053015653#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)) || \
15654 defined(CFG80211_ABORT_SCAN)
15655 .abort_scan = wlan_hdd_cfg80211_abort_scan,
15656#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015657};