blob: 05dcdeea352c661bf3fa98fe5ef0c64b3997dd83 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05302 * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: wlan_hdd_hostapd.c
21 *
22 * WLAN Host Device Driver implementation
23 */
24
25/* Include Files */
26
27#include <linux/version.h>
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/init.h>
31#include <linux/wireless.h>
32#include <linux/semaphore.h>
33#include <linux/compat.h>
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -080034#include <cdp_txrx_cmn.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080035#include <cds_api.h>
36#include <cds_sched.h>
37#include <linux/etherdevice.h>
Dustin Brown0e1e1622019-01-17 11:00:22 -080038#include "osif_sync.h"
Subrat Dash5f36fbe2019-02-12 16:28:14 +053039#include <linux/ethtool.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <wlan_hdd_includes.h>
41#include <qc_sap_ioctl.h>
Dustin Brown1d31b082018-11-22 14:41:20 +053042#include "osif_sync.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#include <wlan_hdd_hostapd.h>
Rachit Kankane0dc3e852018-05-07 17:33:42 +053044#include <wlan_hdd_hostapd_wext.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070045#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080046#include <sap_api.h>
47#include <sap_internal.h>
48#include <wlan_hdd_softap_tx_rx.h>
49#include <wlan_hdd_main.h>
50#include <wlan_hdd_ioctl.h>
51#include <wlan_hdd_stats.h>
52#include <linux/netdevice.h>
53#include <linux/rtnetlink.h>
54#include <linux/mmc/sdio_func.h>
55#include "wlan_hdd_p2p.h"
56#include <wlan_hdd_ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080057#include "wni_cfg.h"
58#include "wlan_hdd_misc.h"
59#include <cds_utils.h>
Yuanyuan Liu13738502016-04-06 17:41:37 -070060#include "pld_common.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080061#include "wma.h"
Srinivas Girigowda6147c582016-10-18 12:26:15 -070062#ifdef WLAN_DEBUG
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080063#include "wma_api.h"
64#endif
65#include "wlan_hdd_trace.h"
Dustin Brownd4241942018-02-26 12:51:37 -080066#include "qdf_str.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053067#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053068#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080069#include "wlan_hdd_cfg.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080070#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -070071#include "wlan_hdd_tsf.h"
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080072#include <cdp_txrx_misc.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -080073#include "wlan_hdd_object_manager.h"
Sandeep Puligillafdd201e2017-02-02 18:43:46 -080074#include <qca_vendor.h>
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -080075#include <cds_api.h>
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -080076#include "wlan_hdd_he.h"
Arif Hussaincd151632017-02-11 16:57:19 -080077#include "wlan_dfs_tgt_api.h"
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -070078#include <wlan_reg_ucfg_api.h>
Naveen Rawat08db88f2017-09-08 15:07:48 -070079#include "wlan_utility.h"
Wu Gaoc02785d2017-09-07 18:17:13 +080080#include <wlan_p2p_ucfg_api.h>
Naveen Rawatd8feac12017-09-08 15:08:39 -070081#include "sir_api.h"
Krunal Soni5e3f9622018-09-26 16:35:50 -070082#include "wlan_policy_mgr_ucfg.h"
Mukul Sharmaecf8e092017-12-19 22:36:31 +053083#include "sme_api.h"
84#include "wlan_hdd_regulatory.h"
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +053085#include <wlan_ipa_ucfg_api.h>
Yu Wangc0b46f82018-03-09 16:04:15 +080086#include <wlan_cp_stats_mc_ucfg_api.h>
Pragaspathi Thilagaraj48d273c2018-08-31 00:53:02 +053087#include "wlan_mlme_ucfg_api.h"
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -070088#include "cfg_ucfg_api.h"
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -070089#include "wlan_crypto_global_api.h"
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +053090#include "wlan_action_oui_ucfg_api.h"
Jeff Johnsone77641e2019-02-15 09:00:41 -080091#include "wlan_fwol_ucfg_api.h"
Nachiket Kukade089b9832018-12-12 16:38:17 +053092#include "nan_ucfg_api.h"
Ashish Kumar Dhanotiyaaa9fdbb2018-12-14 15:29:14 +053093#include <wlan_reg_services_api.h>
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -080094
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095#define ACS_SCAN_EXPIRY_TIMEOUT_S 4
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080096
Ashish Kumar Dhanotiya6025c702019-03-20 18:48:49 +053097/* Defines the BIT position of HT caps is support mode field of stainfo */
98#define HDD_HT_CAPS_PRESENT 0
99/* Defines the BIT position of VHT caps is support mode field of stainfo */
100#define HDD_VHT_CAPS_PRESENT 1
101/* Defines the BIT position of HE caps is support mode field of stainfo */
102#define HDD_HE_CAPS_PRESENT 2
103
Will Huang496b36c2017-07-11 16:38:50 +0800104/*
105 * 11B, 11G Rate table include Basic rate and Extended rate
106 * The IDX field is the rate index
107 * The HI field is the rate when RSSI is strong or being ignored
108 * (in this case we report actual rate)
109 * The MID field is the rate when RSSI is moderate
110 * (in this case we cap 11b rates at 5.5 and 11g rates at 24)
111 * The LO field is the rate when RSSI is low
112 * (in this case we don't report rates, actual current rate used)
113 */
114static const struct index_data_rate_type supported_data_rate[] = {
115 /* IDX HI HM LM LO (RSSI-based index */
116 {2, { 10, 10, 10, 0} },
117 {4, { 20, 20, 10, 0} },
118 {11, { 55, 20, 10, 0} },
119 {12, { 60, 55, 20, 0} },
120 {18, { 90, 55, 20, 0} },
121 {22, {110, 55, 20, 0} },
122 {24, {120, 90, 60, 0} },
123 {36, {180, 120, 60, 0} },
124 {44, {220, 180, 60, 0} },
125 {48, {240, 180, 90, 0} },
126 {66, {330, 180, 90, 0} },
127 {72, {360, 240, 90, 0} },
128 {96, {480, 240, 120, 0} },
129 {108, {540, 240, 120, 0} }
130};
131
132/* MCS Based rate table */
133/* HT MCS parameters with Nss = 1 */
134static const struct index_data_rate_type supported_mcs_rate_nss1[] = {
135 /* MCS L20 L40 S20 S40 */
136 {0, { 65, 135, 72, 150} },
137 {1, { 130, 270, 144, 300} },
138 {2, { 195, 405, 217, 450} },
139 {3, { 260, 540, 289, 600} },
140 {4, { 390, 810, 433, 900} },
141 {5, { 520, 1080, 578, 1200} },
142 {6, { 585, 1215, 650, 1350} },
143 {7, { 650, 1350, 722, 1500} }
144};
145
146/* HT MCS parameters with Nss = 2 */
147static const struct index_data_rate_type supported_mcs_rate_nss2[] = {
148 /* MCS L20 L40 S20 S40 */
149 {0, {130, 270, 144, 300} },
150 {1, {260, 540, 289, 600} },
151 {2, {390, 810, 433, 900} },
152 {3, {520, 1080, 578, 1200} },
153 {4, {780, 1620, 867, 1800} },
154 {5, {1040, 2160, 1156, 2400} },
155 {6, {1170, 2430, 1300, 2700} },
156 {7, {1300, 2700, 1444, 3000} }
157};
158
159/* MCS Based VHT rate table */
160/* MCS parameters with Nss = 1*/
161static const struct index_vht_data_rate_type supported_vht_mcs_rate_nss1[] = {
162 /* MCS L80 S80 L40 S40 L20 S40*/
163 {0, {293, 325}, {135, 150}, {65, 72} },
164 {1, {585, 650}, {270, 300}, {130, 144} },
165 {2, {878, 975}, {405, 450}, {195, 217} },
166 {3, {1170, 1300}, {540, 600}, {260, 289} },
167 {4, {1755, 1950}, {810, 900}, {390, 433} },
168 {5, {2340, 2600}, {1080, 1200}, {520, 578} },
169 {6, {2633, 2925}, {1215, 1350}, {585, 650} },
170 {7, {2925, 3250}, {1350, 1500}, {650, 722} },
171 {8, {3510, 3900}, {1620, 1800}, {780, 867} },
172 {9, {3900, 4333}, {1800, 2000}, {780, 867} }
173};
174
175/*MCS parameters with Nss = 2*/
176static const struct index_vht_data_rate_type supported_vht_mcs_rate_nss2[] = {
177 /* MCS L80 S80 L40 S40 L20 S40*/
178 {0, {585, 650}, {270, 300}, {130, 144} },
179 {1, {1170, 1300}, {540, 600}, {260, 289} },
180 {2, {1755, 1950}, {810, 900}, {390, 433} },
181 {3, {2340, 2600}, {1080, 1200}, {520, 578} },
182 {4, {3510, 3900}, {1620, 1800}, {780, 867} },
183 {5, {4680, 5200}, {2160, 2400}, {1040, 1156} },
184 {6, {5265, 5850}, {2430, 2700}, {1170, 1300} },
185 {7, {5850, 6500}, {2700, 3000}, {1300, 1444} },
186 {8, {7020, 7800}, {3240, 3600}, {1560, 1733} },
187 {9, {7800, 8667}, {3600, 4000}, {1560, 1733} }
188};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189
190/* Function definitions */
191
192/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700193 * hdd_sap_context_init() - Initialize SAP context.
194 * @hdd_ctx: HDD context.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800195 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700196 * Initialize SAP context.
197 *
198 * Return: 0 on success.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800199 */
Jeff Johnsonc54bbf92017-08-28 11:59:35 -0700200int hdd_sap_context_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800201{
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700202 qdf_wake_lock_create(&hdd_ctx->sap_dfs_wakelock, "sap_dfs_wakelock");
203 atomic_set(&hdd_ctx->sap_dfs_ref_cnt, 0);
204
205 mutex_init(&hdd_ctx->sap_lock);
206 qdf_wake_lock_create(&hdd_ctx->sap_wake_lock, "qcom_sap_wakelock");
207
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700208 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800209}
210
Krunal Sonib51eec72017-11-20 21:53:01 -0800211/**
212 * hdd_hostapd_init_sap_session() - To init the sap session completely
213 * @adapter: SAP/GO adapter
Abhishek Singhec7e31a2018-11-01 10:56:45 +0530214 * @reinit: if called as part of reinit
Krunal Sonib51eec72017-11-20 21:53:01 -0800215 *
216 * This API will do
217 * 1) sap_init_ctx()
218 *
219 * Return: 0 if success else non-zero value.
220 */
221static struct sap_context *
Abhishek Singhec7e31a2018-11-01 10:56:45 +0530222hdd_hostapd_init_sap_session(struct hdd_adapter *adapter, bool reinit)
Krunal Soni4a020c72017-10-30 20:58:40 -0700223{
224 struct sap_context *sap_ctx;
Krunal Soni4a020c72017-10-30 20:58:40 -0700225 QDF_STATUS status;
226
227 if (!adapter) {
228 hdd_err("invalid adapter");
229 return NULL;
230 }
Krunal Soni4a020c72017-10-30 20:58:40 -0700231
Krunal Sonib51eec72017-11-20 21:53:01 -0800232 sap_ctx = adapter->session.ap.sap_context;
Krunal Soni4a020c72017-10-30 20:58:40 -0700233
234 if (!sap_ctx) {
235 hdd_err("can't allocate the sap_ctx");
236 return NULL;
237 }
Krunal Soni59437652017-11-21 13:42:14 -0800238 status = sap_init_ctx(sap_ctx, adapter->device_mode,
Jeff Johnson1e851a12017-10-28 14:36:12 -0700239 adapter->mac_addr.bytes,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -0800240 adapter->vdev_id, reinit);
Krunal Soni4a020c72017-10-30 20:58:40 -0700241 if (QDF_IS_STATUS_ERROR(status)) {
242 hdd_err("wlansap_start failed!! status: %d", status);
Jeff Johnsonb9424862017-10-30 08:49:35 -0700243 adapter->session.ap.sap_context = NULL;
Krunal Soni4a020c72017-10-30 20:58:40 -0700244 goto error;
245 }
Krunal Soni4a020c72017-10-30 20:58:40 -0700246 return sap_ctx;
247error:
248 wlansap_context_put(sap_ctx);
249 hdd_err("releasing the sap context for session-id:%d",
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -0800250 adapter->vdev_id);
Krunal Soni4a020c72017-10-30 20:58:40 -0700251
252 return NULL;
253}
254
Krunal Sonib51eec72017-11-20 21:53:01 -0800255/**
256 * hdd_hostapd_deinit_sap_session() - To de-init the sap session completely
257 * @adapter: SAP/GO adapter
258 *
259 * This API will do
260 * 1) sap_init_ctx()
261 * 2) sap_destroy_ctx()
262 *
263 * Return: 0 if success else non-zero value.
264 */
265static int hdd_hostapd_deinit_sap_session(struct hdd_adapter *adapter)
Krunal Soni4a020c72017-10-30 20:58:40 -0700266{
267 struct sap_context *sap_ctx;
268 int status = 0;
269
270 if (!adapter) {
271 hdd_err("invalid adapter");
272 return -EINVAL;
273 }
274
275 sap_ctx = WLAN_HDD_GET_SAP_CTX_PTR(adapter);
276 if (!sap_ctx) {
277 hdd_debug("sap context already released, nothing to be done");
278 return 0;
279 }
280
Krunal Soni59437652017-11-21 13:42:14 -0800281 if (!QDF_IS_STATUS_SUCCESS(sap_deinit_ctx(sap_ctx))) {
Krunal Soni4a020c72017-10-30 20:58:40 -0700282 hdd_err("Error stopping the sap session");
283 status = -EINVAL;
284 }
Krunal Sonib51eec72017-11-20 21:53:01 -0800285
Krunal Soni59437652017-11-21 13:42:14 -0800286 if (!QDF_IS_STATUS_SUCCESS(sap_destroy_ctx(sap_ctx))) {
Krunal Soni4a020c72017-10-30 20:58:40 -0700287 hdd_err("Error closing the sap session");
288 status = -EINVAL;
289 }
Jeff Johnsonb9424862017-10-30 08:49:35 -0700290 adapter->session.ap.sap_context = NULL;
Krunal Soni4a020c72017-10-30 20:58:40 -0700291
Krunal Soni4a020c72017-10-30 20:58:40 -0700292 if (!QDF_IS_STATUS_SUCCESS(status))
293 hdd_debug("sap has issue closing the session");
294 else
295 hdd_debug("sap has been closed successfully");
296
297
298 return status;
299}
300
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800301/**
302 * hdd_hostapd_channel_allow_suspend() - allow suspend in a channel.
303 * Called when, 1. bss stopped, 2. channel switch
304 *
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700305 * @adapter: pointer to hdd adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800306 * @channel: current channel
307 *
308 * Return: None
309 */
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700310static void hdd_hostapd_channel_allow_suspend(struct hdd_adapter *adapter,
Jeff Johnsone4090f72016-10-05 16:00:23 -0700311 uint8_t channel)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800312{
313
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700314 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson5c19ade2017-10-04 09:52:12 -0700315 struct hdd_hostapd_state *hostapd_state =
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700316 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800317
Jeff Johnson0f9f87b2017-10-28 09:21:06 -0700318 hdd_debug("bss_state: %d, channel: %d, dfs_ref_cnt: %d",
319 hostapd_state->bss_state, channel,
Jeff Johnson23c3b842017-09-03 09:05:29 -0700320 atomic_read(&hdd_ctx->sap_dfs_ref_cnt));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800321
322 /* Return if BSS is already stopped */
Jeff Johnson0f9f87b2017-10-28 09:21:06 -0700323 if (hostapd_state->bss_state == BSS_STOP)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800324 return;
325
Dustin Brown07901ec2018-09-07 11:02:41 -0700326 if (wlan_reg_get_channel_state(hdd_ctx->pdev, channel) !=
327 CHANNEL_STATE_DFS)
Komal Seelam81cb1662016-09-29 12:39:08 +0530328 return;
329
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800330 /* Release wakelock when no more DFS channels are used */
Jeff Johnson23c3b842017-09-03 09:05:29 -0700331 if (atomic_dec_and_test(&hdd_ctx->sap_dfs_ref_cnt)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -0800332 hdd_err("DFS: allowing suspend (chan: %d)", channel);
Jeff Johnson23c3b842017-09-03 09:05:29 -0700333 qdf_wake_lock_release(&hdd_ctx->sap_dfs_wakelock,
Komal Seelam81cb1662016-09-29 12:39:08 +0530334 WIFI_POWER_EVENT_WAKELOCK_DFS);
Jeff Johnson23c3b842017-09-03 09:05:29 -0700335 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.dfs);
Komal Seelam81cb1662016-09-29 12:39:08 +0530336
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800337 }
338}
339
340/**
341 * hdd_hostapd_channel_prevent_suspend() - prevent suspend in a channel.
342 * Called when, 1. bss started, 2. channel switch
343 *
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700344 * @adapter: pointer to hdd adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345 * @channel: current channel
346 *
347 * Return - None
348 */
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700349static void hdd_hostapd_channel_prevent_suspend(struct hdd_adapter *adapter,
Jeff Johnsone4090f72016-10-05 16:00:23 -0700350 uint8_t channel)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800351{
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700352 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson5c19ade2017-10-04 09:52:12 -0700353 struct hdd_hostapd_state *hostapd_state =
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700354 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800355
Jeff Johnson0f9f87b2017-10-28 09:21:06 -0700356 hdd_debug("bss_state: %d, channel: %d, dfs_ref_cnt: %d",
357 hostapd_state->bss_state, channel,
Jeff Johnson23c3b842017-09-03 09:05:29 -0700358 atomic_read(&hdd_ctx->sap_dfs_ref_cnt));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800359
360 /* Return if BSS is already started && wakelock is acquired */
Jeff Johnson0f9f87b2017-10-28 09:21:06 -0700361 if ((hostapd_state->bss_state == BSS_START) &&
Jeff Johnson23c3b842017-09-03 09:05:29 -0700362 (atomic_read(&hdd_ctx->sap_dfs_ref_cnt) >= 1))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800363 return;
364
Dustin Brown07901ec2018-09-07 11:02:41 -0700365 if (wlan_reg_get_channel_state(hdd_ctx->pdev, channel) !=
366 CHANNEL_STATE_DFS)
Komal Seelam81cb1662016-09-29 12:39:08 +0530367 return;
368
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369 /* Acquire wakelock if we have at least one DFS channel in use */
Jeff Johnson23c3b842017-09-03 09:05:29 -0700370 if (atomic_inc_return(&hdd_ctx->sap_dfs_ref_cnt) == 1) {
Srinivas Girigowda55756882017-03-06 16:45:27 -0800371 hdd_err("DFS: preventing suspend (chan: %d)", channel);
Jeff Johnson23c3b842017-09-03 09:05:29 -0700372 qdf_runtime_pm_prevent_suspend(&hdd_ctx->runtime_context.dfs);
373 qdf_wake_lock_acquire(&hdd_ctx->sap_dfs_wakelock,
Komal Seelam81cb1662016-09-29 12:39:08 +0530374 WIFI_POWER_EVENT_WAKELOCK_DFS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800375 }
376}
377
378/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700379 * hdd_sap_context_destroy() - Destroy SAP context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700381 * @hdd_ctx: HDD context.
382 *
383 * Destroy SAP context.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800384 *
385 * Return: None
386 */
Jeff Johnsonc54bbf92017-08-28 11:59:35 -0700387void hdd_sap_context_destroy(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800388{
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700389 if (atomic_read(&hdd_ctx->sap_dfs_ref_cnt)) {
390 qdf_wake_lock_release(&hdd_ctx->sap_dfs_wakelock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800391 WIFI_POWER_EVENT_WAKELOCK_DRIVER_EXIT);
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700392
393 atomic_set(&hdd_ctx->sap_dfs_ref_cnt, 0);
Srinivas Girigowda55756882017-03-06 16:45:27 -0800394 hdd_debug("DFS: Allowing suspend");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800395 }
396
Prashanth Bhatta527fd752016-04-28 12:35:23 -0700397 qdf_wake_lock_destroy(&hdd_ctx->sap_dfs_wakelock);
398
399 mutex_destroy(&hdd_ctx->sap_lock);
400 qdf_wake_lock_destroy(&hdd_ctx->sap_wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800401}
402
403/**
404 * __hdd_hostapd_open() - hdd open function for hostapd interface
405 * This is called in response to ifconfig up
406 * @dev: pointer to net_device structure
407 *
408 * Return - 0 for success non-zero for failure
409 */
410static int __hdd_hostapd_open(struct net_device *dev)
411{
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700412 struct hdd_adapter *adapter = netdev_priv(dev);
413 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arunk Khandavalli702e1702016-12-06 18:01:55 +0530414 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800415
Dustin Brownfdf17c12018-03-14 12:55:34 -0700416 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800417
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +0530418 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
419 TRACE_CODE_HDD_HOSTAPD_OPEN_REQUEST,
420 NO_SESSION, 0);
421
Krunal Soni4a020c72017-10-30 20:58:40 -0700422 /* Nothing to be done if device is unloading */
423 if (cds_is_driver_unloading()) {
424 hdd_err("Driver is unloading can not open the hdd");
425 return -EBUSY;
426 }
427
428 if (cds_is_driver_recovering()) {
429 hdd_err("WLAN is currently recovering; Please try again.");
430 return -EBUSY;
431 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800432
Arunk Khandavalli702e1702016-12-06 18:01:55 +0530433 ret = wlan_hdd_validate_context(hdd_ctx);
434 if (ret)
435 return ret;
Arunk Khandavalli702e1702016-12-06 18:01:55 +0530436
Dustin Brown3ecc8782018-09-19 16:37:13 -0700437 /* ensure the physical soc is up */
438 ret = hdd_psoc_idle_restart(hdd_ctx);
Arunk Khandavalli702e1702016-12-06 18:01:55 +0530439 if (ret) {
440 hdd_err("Failed to start WLAN modules return");
441 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800442 }
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800443
Krunal Soni4a020c72017-10-30 20:58:40 -0700444 ret = hdd_start_adapter(adapter);
445 if (ret) {
446 hdd_err("Error Initializing the AP mode: %d", ret);
447 return ret;
448 }
449
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700450 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Krunal Soni4a020c72017-10-30 20:58:40 -0700451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800452 /* Enable all Tx queues */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -0700453 hdd_debug("Enabling queues");
Jeff Johnsonfd33cce2017-10-02 13:28:39 -0700454 wlan_hdd_netif_queue_control(adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800455 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
456 WLAN_CONTROL_PATH);
Dustin Browne74003f2018-03-14 12:51:58 -0700457 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800458 return 0;
459}
460
461/**
462 * hdd_hostapd_open() - SSR wrapper for __hdd_hostapd_open
463 * @dev: pointer to net device
464 *
465 * Return: 0 on success, error number otherwise
466 */
Dustin Brown0e1e1622019-01-17 11:00:22 -0800467static int hdd_hostapd_open(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800468{
Dustin Brown0e1e1622019-01-17 11:00:22 -0800469 int errno;
470 struct osif_vdev_sync *vdev_sync;
471
472 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
473 if (errno)
474 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800475
Dustin Brown0e1e1622019-01-17 11:00:22 -0800476 errno = __hdd_hostapd_open(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477
Dustin Brown0e1e1622019-01-17 11:00:22 -0800478 osif_vdev_sync_trans_stop(vdev_sync);
479
480 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800481}
482
483/**
484 * __hdd_hostapd_stop() - hdd stop function for hostapd interface
485 * This is called in response to ifconfig down
486 *
487 * @dev: pointer to net_device structure
488 *
489 * Return - 0 for success non-zero for failure
490 */
491static int __hdd_hostapd_stop(struct net_device *dev)
492{
Jeff Johnson866aca82017-09-10 15:27:20 -0700493 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsonc54bbf92017-08-28 11:59:35 -0700494 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manikandan Mohanfa7b7fe2017-02-15 14:53:31 -0800495 int ret;
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800496
Dustin Brownfdf17c12018-03-14 12:55:34 -0700497 hdd_enter_dev(dev);
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +0530498
499 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
500 TRACE_CODE_HDD_HOSTAPD_STOP_REQUEST,
501 NO_SESSION, 0);
502
Manikandan Mohanfa7b7fe2017-02-15 14:53:31 -0800503 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +0530504 if (ret) {
505 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Manikandan Mohanfa7b7fe2017-02-15 14:53:31 -0800506 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +0530507 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800508
Krunal Soni4a020c72017-10-30 20:58:40 -0700509 /*
Krunal Soni4a020c72017-10-30 20:58:40 -0700510 * Some tests requires to do "ifconfig down" only to bring
511 * down the SAP/GO without killing hostapd/wpa_supplicant.
512 * In such case, user will do "ifconfig up" to bring-back
513 * the SAP/GO session. to fulfill this requirement, driver
514 * needs to de-init the sap session here and re-init when
515 * __hdd_hostapd_open() API
516 */
Dustin Browndb2a8be2017-12-20 11:49:56 -0800517 hdd_stop_adapter(hdd_ctx, adapter);
Krunal Soni4a020c72017-10-30 20:58:40 -0700518 hdd_deinit_adapter(hdd_ctx, adapter, true);
Arun Khandavalli97f28382016-09-09 17:36:50 +0530519 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800520 /* Stop all tx queues */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -0700521 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +0530522 wlan_hdd_netif_queue_control(adapter,
523 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
524 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800525
Dustin Browne74003f2018-03-14 12:51:58 -0700526 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800527 return 0;
528}
529
530/**
531 * hdd_hostapd_stop() - SSR wrapper for__hdd_hostapd_stop
532 * @dev: pointer to net_device
533 *
534 * This is called in response to ifconfig down
535 *
536 * Return: 0 on success, error number otherwise
537 */
Dustin Brown0e1e1622019-01-17 11:00:22 -0800538int hdd_hostapd_stop(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800539{
Dustin Brown0e1e1622019-01-17 11:00:22 -0800540 int errno;
541 struct osif_vdev_sync *vdev_sync;
542
543 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
544 if (errno)
545 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800546
Dustin Brown0e1e1622019-01-17 11:00:22 -0800547 errno = __hdd_hostapd_stop(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548
Dustin Brown0e1e1622019-01-17 11:00:22 -0800549 osif_vdev_sync_trans_stop(vdev_sync);
550
551 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800552}
553
554/**
Dustin Brown96b98dd2019-03-06 12:39:37 -0800555 * hdd_hostapd_uninit() - hdd uninit function
556 * @dev: pointer to net_device structure
557 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558 * This is called during the netdev unregister to uninitialize all data
559 * associated with the device.
560 *
Dustin Brown96b98dd2019-03-06 12:39:37 -0800561 * This function must be protected by a transition
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 *
563 * Return: None
564 */
Dustin Brown96b98dd2019-03-06 12:39:37 -0800565static void hdd_hostapd_uninit(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800566{
Jeff Johnson866aca82017-09-10 15:27:20 -0700567 struct hdd_adapter *adapter = netdev_priv(dev);
Jeff Johnsonc54bbf92017-08-28 11:59:35 -0700568 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800569
Dustin Brownfdf17c12018-03-14 12:55:34 -0700570 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800571
Dustin Brown96b98dd2019-03-06 12:39:37 -0800572 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -0700573 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800574 return;
575 }
576
577 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown96b98dd2019-03-06 12:39:37 -0800578 if (!hdd_ctx) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -0700579 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580 return;
581 }
582
583 hdd_deinit_adapter(hdd_ctx, adapter, true);
584
585 /* after uninit our adapter structure will no longer be valid */
586 adapter->dev = NULL;
587 adapter->magic = 0;
588
Dustin Browne74003f2018-03-14 12:51:58 -0700589 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800590}
591
592/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800593 * __hdd_hostapd_change_mtu() - change mtu
594 * @dev: pointer to net_device
595 * @new_mtu: new mtu
596 *
597 * Return: 0 on success, error number otherwise
598 */
599static int __hdd_hostapd_change_mtu(struct net_device *dev, int new_mtu)
600{
Dustin Brownfdf17c12018-03-14 12:55:34 -0700601 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800602
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603 return 0;
604}
605
606/**
607 * hdd_hostapd_change_mtu() - SSR wrapper for __hdd_hostapd_change_mtu
Dustin Brown98f7c822019-03-06 12:25:49 -0800608 * @net_dev: pointer to net_device
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800609 * @new_mtu: new mtu
610 *
611 * Return: 0 on success, error number otherwise
612 */
Dustin Brown98f7c822019-03-06 12:25:49 -0800613static int hdd_hostapd_change_mtu(struct net_device *net_dev, int new_mtu)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800614{
Dustin Brown98f7c822019-03-06 12:25:49 -0800615 struct osif_vdev_sync *vdev_sync;
616 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800617
Dustin Brown98f7c822019-03-06 12:25:49 -0800618 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
619 if (errno)
620 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800621
Dustin Brown98f7c822019-03-06 12:25:49 -0800622 errno = __hdd_hostapd_change_mtu(net_dev, new_mtu);
623
624 osif_vdev_sync_op_stop(vdev_sync);
625
626 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800627}
628
629#ifdef QCA_HT_2040_COEX
Jeff Johnson9c4f93d2017-10-04 08:56:22 -0700630QDF_STATUS hdd_set_sap_ht2040_mode(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800631 uint8_t channel_type)
632{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530633 QDF_STATUS qdf_ret_status = QDF_STATUS_E_FAILURE;
Jeff Johnson89a0c742018-06-12 18:17:46 -0700634 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800635
Srinivas Girigowda55756882017-03-06 16:45:27 -0800636 hdd_debug("change HT20/40 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800637
Jeff Johnson9c4f93d2017-10-04 08:56:22 -0700638 if (QDF_SAP_MODE == adapter->device_mode) {
Jeff Johnson89a0c742018-06-12 18:17:46 -0700639 mac_handle = adapter->hdd_ctx->mac_handle;
640 if (!mac_handle) {
641 hdd_err("mac handle is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530642 return QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800643 }
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530644 qdf_ret_status =
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -0800645 sme_set_ht2040_mode(mac_handle, adapter->vdev_id,
Jeff Johnson89a0c742018-06-12 18:17:46 -0700646 channel_type, true);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530647 if (qdf_ret_status == QDF_STATUS_E_FAILURE) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -0700648 hdd_err("Failed to change HT20/40 mode");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530649 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800650 }
651 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530652 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800653}
654#endif
655
656/**
657 * __hdd_hostapd_set_mac_address() -
658 * This function sets the user specified mac address using
659 * the command ifconfig wlanX hw ether <mac address>.
660 *
661 * @dev: pointer to the net device.
662 * @addr: pointer to the sockaddr.
663 *
664 * Return: 0 for success, non zero for failure
665 */
666static int __hdd_hostapd_set_mac_address(struct net_device *dev, void *addr)
667{
668 struct sockaddr *psta_mac_addr = addr;
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +0530669 struct hdd_adapter *adapter, *adapter_temp;
Jeff Johnsonc54bbf92017-08-28 11:59:35 -0700670 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671 int ret = 0;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +0530672 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800673
Dustin Brownfdf17c12018-03-14 12:55:34 -0700674 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800675
676 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
677 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
678 ret = wlan_hdd_validate_context(hdd_ctx);
679 if (0 != ret)
680 return ret;
681
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +0530682 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +0530683 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
684 if (adapter_temp) {
685 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
686 return 0;
687 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
688 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +0530689 MAC_ADDR_ARRAY(mac_addr.bytes));
690 return -EINVAL;
691 }
692
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +0530693 if (qdf_is_macaddr_zero(&mac_addr)) {
694 hdd_err("MAC is all zero");
695 return -EINVAL;
696 }
697
698 if (qdf_is_macaddr_broadcast(&mac_addr)) {
699 hdd_err("MAC is Broadcast");
700 return -EINVAL;
701 }
702
703 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
704 hdd_err("MAC is Multicast");
705 return -EINVAL;
706 }
707
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +0530708 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of interface %s ",
709 MAC_ADDR_ARRAY(mac_addr.bytes),
710 dev->name);
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +0530711 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
712 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
Dustin Browne74003f2018-03-14 12:51:58 -0700714 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800715 return 0;
716}
717
718/**
719 * hdd_hostapd_set_mac_address() - set mac address
Dustin Brown98f7c822019-03-06 12:25:49 -0800720 * @net_dev: pointer to net_device
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800721 * @addr: mac address
722 *
723 * Return: 0 on success, error number otherwise
724 */
Dustin Brown98f7c822019-03-06 12:25:49 -0800725static int hdd_hostapd_set_mac_address(struct net_device *net_dev, void *addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726{
Dustin Brown98f7c822019-03-06 12:25:49 -0800727 struct osif_vdev_sync *vdev_sync;
728 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729
Dustin Brown98f7c822019-03-06 12:25:49 -0800730 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
731 if (errno)
732 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733
Dustin Brown98f7c822019-03-06 12:25:49 -0800734 errno = __hdd_hostapd_set_mac_address(net_dev, addr);
735
736 osif_vdev_sync_op_stop(vdev_sync);
737
738 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739}
740
Jeff Johnsone4b24872017-10-27 08:37:12 -0700741static void hdd_clear_sta(struct hdd_adapter *adapter, uint8_t sta_id)
742{
743 struct hdd_ap_ctx *ap_ctx;
744 struct hdd_station_info *sta_info;
Jeff Johnsone6bf7192017-11-07 15:16:09 -0800745 struct csr_del_sta_params del_sta_params;
Jeff Johnsone4b24872017-10-27 08:37:12 -0700746
747 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
748
749 if (sta_id == ap_ctx->broadcast_sta_id)
750 return;
751
752 sta_info = &adapter->sta_info[sta_id];
753 if (!sta_info->in_use)
754 return;
755
756 wlansap_populate_del_sta_params(sta_info->sta_mac.bytes,
757 eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
758 (SIR_MAC_MGMT_DISASSOC >> 4),
759 &del_sta_params);
760
761 hdd_softap_sta_disassoc(adapter, &del_sta_params);
762}
763
Jeff Johnsonb55bf512017-10-26 13:38:18 -0700764static void hdd_clear_all_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765{
Jeff Johnsone4b24872017-10-27 08:37:12 -0700766 uint8_t sta_id;
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -0700767
Dustin Brownfdf17c12018-03-14 12:55:34 -0700768 hdd_enter_dev(adapter->dev);
Jeff Johnsone4b24872017-10-27 08:37:12 -0700769 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++)
770 hdd_clear_sta(adapter, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771}
772
Jeff Johnson0604a362018-03-24 17:36:59 -0700773static int hdd_stop_bss_link(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774{
Jeff Johnson0604a362018-03-24 17:36:59 -0700775 struct hdd_context *hdd_ctx;
776 int errno;
777 QDF_STATUS status;
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -0700778
Dustin Brown491d54b2018-03-14 12:39:11 -0700779 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800780
Jeff Johnson9c4f93d2017-10-04 08:56:22 -0700781 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson0604a362018-03-24 17:36:59 -0700782 errno = wlan_hdd_validate_context(hdd_ctx);
783 if (errno)
784 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800785
Jeff Johnson9c4f93d2017-10-04 08:56:22 -0700786 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Dustin Brown5118e8e2016-09-13 15:54:23 -0700787 status = wlansap_stop_bss(
Jeff Johnson9c4f93d2017-10-04 08:56:22 -0700788 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530789 if (QDF_IS_STATUS_SUCCESS(status))
Srinivas Girigowda55756882017-03-06 16:45:27 -0800790 hdd_debug("Deleting SAP/P2P link!!!!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791
Jeff Johnson9c4f93d2017-10-04 08:56:22 -0700792 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -0700793 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -0700794 adapter->device_mode,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -0800795 adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -0700796 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +0530797 false);
Jeff Johnson0604a362018-03-24 17:36:59 -0700798 errno = (status == QDF_STATUS_SUCCESS) ? 0 : -EBUSY;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800799 }
Dustin Browne74003f2018-03-14 12:51:58 -0700800 hdd_exit();
Jeff Johnson0604a362018-03-24 17:36:59 -0700801 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800802}
803
804/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805 * hdd_chan_change_notify() - Function to notify hostapd about channel change
bings58ce8622017-07-10 15:55:36 +0800806 * @hostapd_adapter: hostapd adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800807 * @dev: Net device structure
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530808 * @chan_change: New channel change parameters
bings58ce8622017-07-10 15:55:36 +0800809 * @legacy_phymode: is the phymode legacy
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 *
811 * This function is used to notify hostapd about the channel change
812 *
813 * Return: Success on intimating userspace
814 *
815 */
Jeff Johnson866aca82017-09-10 15:27:20 -0700816QDF_STATUS hdd_chan_change_notify(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800817 struct net_device *dev,
bings58ce8622017-07-10 15:55:36 +0800818 struct hdd_chan_change_params chan_change,
819 bool legacy_phymode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820{
821 struct ieee80211_channel *chan;
822 struct cfg80211_chan_def chandef;
823 enum nl80211_channel_type channel_type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824 uint32_t freq;
Jeff Johnson89a0c742018-06-12 18:17:46 -0700825 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826
Jeff Johnson89a0c742018-06-12 18:17:46 -0700827 if (!mac_handle) {
828 hdd_err("mac_handle is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530829 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 }
831
Srinivas Girigowda55756882017-03-06 16:45:27 -0800832 hdd_debug("chan:%d width:%d sec_ch_offset:%d seg0:%d seg1:%d",
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530833 chan_change.chan, chan_change.chan_params.ch_width,
834 chan_change.chan_params.sec_ch_offset,
835 chan_change.chan_params.center_freq_seg0,
836 chan_change.chan_params.center_freq_seg1);
837
838 freq = cds_chan_to_freq(chan_change.chan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800839
Dustin Brown2eb1e452017-08-15 12:40:34 -0700840 chan = ieee80211_get_channel(adapter->wdev.wiphy, freq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841
842 if (!chan) {
843 hdd_err("Invalid input frequency for channel conversion");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530844 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 }
846
bings58ce8622017-07-10 15:55:36 +0800847 if (legacy_phymode) {
848 channel_type = NL80211_CHAN_NO_HT;
849 } else {
bingsbd6bc472017-06-23 10:14:40 +0800850 switch (chan_change.chan_params.sec_ch_offset) {
851 case PHY_SINGLE_CHANNEL_CENTERED:
852 channel_type = NL80211_CHAN_HT20;
853 break;
854 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY:
855 channel_type = NL80211_CHAN_HT40MINUS;
856 break;
857 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY:
858 channel_type = NL80211_CHAN_HT40PLUS;
859 break;
860 default:
861 channel_type = NL80211_CHAN_NO_HT;
862 break;
863 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864 }
865
866 cfg80211_chandef_create(&chandef, chan, channel_type);
867
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530868 /* cfg80211_chandef_create() does update of width and center_freq1
869 * only for NL80211_CHAN_NO_HT, NL80211_CHAN_HT20, NL80211_CHAN_HT40PLUS
870 * and NL80211_CHAN_HT40MINUS.
871 */
Ashish Kumar Dhanotiya5d781562018-10-31 18:35:05 +0530872 switch (chan_change.chan_params.ch_width) {
873 case CH_WIDTH_80MHZ:
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530874 chandef.width = NL80211_CHAN_WIDTH_80;
Ashish Kumar Dhanotiya5d781562018-10-31 18:35:05 +0530875 break;
876 case CH_WIDTH_80P80MHZ:
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530877 chandef.width = NL80211_CHAN_WIDTH_80P80;
Ashish Kumar Dhanotiya5d781562018-10-31 18:35:05 +0530878 if (chan_change.chan_params.center_freq_seg1)
879 chandef.center_freq2 = cds_chan_to_freq(
880 chan_change.chan_params.center_freq_seg1);
881 break;
882 case CH_WIDTH_160MHZ:
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530883 chandef.width = NL80211_CHAN_WIDTH_160;
Ashish Kumar Dhanotiya5d781562018-10-31 18:35:05 +0530884 break;
885 default:
886 break;
887 }
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530888
889 if ((chan_change.chan_params.ch_width == CH_WIDTH_80MHZ) ||
890 (chan_change.chan_params.ch_width == CH_WIDTH_80P80MHZ) ||
891 (chan_change.chan_params.ch_width == CH_WIDTH_160MHZ)) {
892 if (chan_change.chan_params.center_freq_seg0)
893 chandef.center_freq1 = cds_chan_to_freq(
894 chan_change.chan_params.center_freq_seg0);
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530895 }
896
Srinivas Girigowda55756882017-03-06 16:45:27 -0800897 hdd_debug("notify: chan:%d width:%d freq1:%d freq2:%d",
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +0530898 chandef.chan->center_freq, chandef.width, chandef.center_freq1,
899 chandef.center_freq2);
Wu Gao2c3a8002016-01-22 10:56:07 +0800900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 cfg80211_ch_switch_notify(dev, &chandef);
902
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530903 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904}
905
906/**
907 * hdd_send_radar_event() - Function to send radar events to user space
908 * @hdd_context: HDD context
909 * @event: Type of radar event
910 * @dfs_info: Structure containing DFS channel and country
911 * @wdev: Wireless device structure
912 *
913 * This function is used to send radar events such as CAC start, CAC
914 * end etc., to userspace
915 *
916 * Return: Success on sending notifying userspace
917 *
918 */
Jeff Johnsonc54bbf92017-08-28 11:59:35 -0700919static QDF_STATUS hdd_send_radar_event(struct hdd_context *hdd_context,
Jeff Johnsone4090f72016-10-05 16:00:23 -0700920 eSapHddEvent event,
921 struct wlan_dfs_info dfs_info,
922 struct wireless_dev *wdev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923{
924
925 struct sk_buff *vendor_event;
926 enum qca_nl80211_vendor_subcmds_index index;
927 uint32_t freq, ret;
928 uint32_t data_size;
929
930 if (!hdd_context) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -0700931 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530932 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 }
934
935 freq = cds_chan_to_freq(dfs_info.channel);
936
937 switch (event) {
938 case eSAP_DFS_CAC_START:
939 index =
940 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_STARTED_INDEX;
941 data_size = sizeof(uint32_t);
942 break;
943 case eSAP_DFS_CAC_END:
944 index =
945 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_CAC_FINISHED_INDEX;
946 data_size = sizeof(uint32_t);
947 break;
948 case eSAP_DFS_RADAR_DETECT:
949 index =
950 QCA_NL80211_VENDOR_SUBCMD_DFS_OFFLOAD_RADAR_DETECTED_INDEX;
951 data_size = sizeof(uint32_t);
952 break;
953 default:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530954 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955 }
956
957 vendor_event = cfg80211_vendor_event_alloc(hdd_context->wiphy,
958 wdev,
959 data_size + NLMSG_HDRLEN,
960 index,
961 GFP_KERNEL);
962 if (!vendor_event) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -0700963 hdd_err("cfg80211_vendor_event_alloc failed for %d", index);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530964 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800965 }
966
967 ret = nla_put_u32(vendor_event, NL80211_ATTR_WIPHY_FREQ, freq);
968
969 if (ret) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -0700970 hdd_err("NL80211_ATTR_WIPHY_FREQ put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971 kfree_skb(vendor_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530972 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 }
974
975 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530976 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977}
978
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +0530979/**
980 * hdd_send_conditional_chan_switch_status() - Send conditional channel switch
981 * status
982 * @hdd_ctx: HDD context
983 * @wdev: Wireless device structure
984 * @status: Status of conditional channel switch
985 * (0: Success, Non-zero: Failure)
986 *
987 * Sends the status of conditional channel switch to user space. This is named
988 * conditional channel switch because the SAP will move to the provided channel
989 * after some condition (pre-cac) is met.
990 *
991 * Return: None
992 */
Jeff Johnsonc54bbf92017-08-28 11:59:35 -0700993static void hdd_send_conditional_chan_switch_status(struct hdd_context *hdd_ctx,
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +0530994 struct wireless_dev *wdev,
995 bool status)
996{
997 struct sk_buff *event;
998
Dustin Brownfdf17c12018-03-14 12:55:34 -0700999 hdd_enter_dev(wdev->netdev);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301000
1001 if (!hdd_ctx) {
1002 hdd_err("Invalid HDD context pointer");
1003 return;
1004 }
1005
1006 event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
1007 wdev, sizeof(uint32_t) + NLMSG_HDRLEN,
1008 QCA_NL80211_VENDOR_SUBCMD_SAP_CONDITIONAL_CHAN_SWITCH_INDEX,
1009 GFP_KERNEL);
1010 if (!event) {
1011 hdd_err("cfg80211_vendor_event_alloc failed");
1012 return;
1013 }
1014
1015 if (nla_put_u32(event,
1016 QCA_WLAN_VENDOR_ATTR_SAP_CONDITIONAL_CHAN_SWITCH_STATUS,
1017 status)) {
1018 hdd_err("nla put failed");
1019 kfree_skb(event);
1020 return;
1021 }
1022
1023 cfg80211_vendor_event(event, GFP_KERNEL);
1024}
1025
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301026/**
1027 * wlan_hdd_set_pre_cac_complete_status() - Set pre cac complete status
1028 * @ap_adapter: AP adapter
1029 * @status: Status which can be true or false
1030 *
1031 * Sets the status of pre cac i.e., whether it is complete or not
1032 *
1033 * Return: Zero on success, non-zero on failure
1034 */
Jeff Johnson866aca82017-09-10 15:27:20 -07001035static int wlan_hdd_set_pre_cac_complete_status(struct hdd_adapter *ap_adapter,
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301036 bool status)
1037{
1038 QDF_STATUS ret;
1039
1040 ret = wlan_sap_set_pre_cac_complete_status(
1041 WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter), status);
1042 if (QDF_IS_STATUS_ERROR(ret))
1043 return -EINVAL;
1044
1045 return 0;
1046}
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301047
1048/**
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001049 * __wlan_hdd_sap_pre_cac_failure() - Process the pre cac failure
Dustin Brown8660dd32019-01-24 11:09:12 -08001050 * @adapter: AP adapter
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001051 *
1052 * Deletes the pre cac adapter
1053 *
1054 * Return: None
1055 */
Dustin Brown8660dd32019-01-24 11:09:12 -08001056static void __wlan_hdd_sap_pre_cac_failure(struct hdd_adapter *adapter)
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001057{
Jeff Johnsonc54bbf92017-08-28 11:59:35 -07001058 struct hdd_context *hdd_ctx;
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001059
Dustin Brown491d54b2018-03-14 12:39:11 -07001060 hdd_enter();
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001061
Jeff Johnson399c6272017-08-30 10:51:00 -07001062 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001063 if (wlan_hdd_validate_context(hdd_ctx)) {
1064 hdd_err("HDD context is null");
1065 return;
1066 }
1067
Dustin Brownb4260d52019-01-24 11:53:08 -08001068 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
1069 hdd_stop_adapter(hdd_ctx, adapter);
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001070 hdd_close_adapter(hdd_ctx, adapter, false);
Dustin Brown8660dd32019-01-24 11:09:12 -08001071
1072 hdd_exit();
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001073}
1074
1075/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301076 * wlan_hdd_sap_pre_cac_failure() - Process the pre cac failure
1077 * @data: AP adapter
1078 *
1079 * Deletes the pre cac adapter
1080 *
1081 * Return: None
1082 */
1083void wlan_hdd_sap_pre_cac_failure(void *data)
1084{
Dustin Brown8660dd32019-01-24 11:09:12 -08001085 struct hdd_adapter *adapter = data;
1086 struct osif_vdev_sync *vdev_sync;
1087 int errno;
1088
1089 errno = osif_vdev_sync_trans_start_wait(adapter->dev, &vdev_sync);
1090 if (errno)
1091 return;
1092
1093 osif_vdev_sync_unregister(adapter->dev);
1094 osif_vdev_sync_wait_for_ops(vdev_sync);
1095
Manikandan Mohan7ef504e2017-03-17 14:55:17 -07001096 __wlan_hdd_sap_pre_cac_failure(data);
Dustin Brown8660dd32019-01-24 11:09:12 -08001097
1098 osif_vdev_sync_trans_stop(vdev_sync);
1099 osif_vdev_sync_destroy(vdev_sync);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301100}
1101
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301102/**
Dustin Brown8660dd32019-01-24 11:09:12 -08001103 * __wlan_hdd_sap_pre_cac_success() - Process the pre cac result
1104 * @adapter: AP adapter
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301105 *
1106 * Deletes the pre cac adapter and moves the existing SAP to the pre cac
1107 * channel
1108 *
1109 * Return: None
1110 */
Dustin Brown8660dd32019-01-24 11:09:12 -08001111static void __wlan_hdd_sap_pre_cac_success(struct hdd_adapter *adapter)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301112{
Dustin Brown8660dd32019-01-24 11:09:12 -08001113 struct hdd_adapter *ap_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301114 int i;
Jeff Johnsonc54bbf92017-08-28 11:59:35 -07001115 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301116
Dustin Brown491d54b2018-03-14 12:39:11 -07001117 hdd_enter();
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301118
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001119 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301120 if (!hdd_ctx) {
1121 hdd_err("HDD context is null");
1122 return;
1123 }
1124
Dustin Brownb4260d52019-01-24 11:53:08 -08001125 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
1126 hdd_stop_adapter(hdd_ctx, adapter);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001127 hdd_close_adapter(hdd_ctx, adapter, false);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301128
1129 /* Prepare to switch AP from 2.4GHz channel to the pre CAC channel */
1130 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
1131 if (!ap_adapter) {
1132 hdd_err("failed to get SAP adapter, no restart on pre CAC channel");
1133 return;
1134 }
1135
1136 /*
1137 * Setting of the pre cac complete status will ensure that on channel
1138 * switch to the pre CAC DFS channel, there is no CAC again.
1139 */
1140 wlan_hdd_set_pre_cac_complete_status(ap_adapter, true);
1141 i = hdd_softap_set_channel_change(ap_adapter->dev,
1142 ap_adapter->pre_cac_chan,
Min Liu2fef5792018-01-19 17:59:42 +08001143 CH_WIDTH_MAX, false);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301144 if (0 != i) {
1145 hdd_err("failed to change channel");
1146 wlan_hdd_set_pre_cac_complete_status(ap_adapter, false);
1147 }
Dustin Brown8660dd32019-01-24 11:09:12 -08001148
1149 hdd_exit();
1150}
1151
1152static void wlan_hdd_sap_pre_cac_success(void *data)
1153{
1154 struct hdd_adapter *adapter = data;
1155 struct osif_vdev_sync *vdev_sync;
1156 int errno;
1157
1158 errno = osif_vdev_sync_trans_start_wait(adapter->dev, &vdev_sync);
1159 if (errno)
1160 return;
1161
1162 osif_vdev_sync_unregister(adapter->dev);
1163 osif_vdev_sync_wait_for_ops(vdev_sync);
1164
Dustin Brown8660dd32019-01-24 11:09:12 -08001165 __wlan_hdd_sap_pre_cac_success(adapter);
Dustin Brown8660dd32019-01-24 11:09:12 -08001166
1167 osif_vdev_sync_trans_stop(vdev_sync);
1168 osif_vdev_sync_destroy(vdev_sync);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05301169}
1170
Liangwei Dongaef84342016-10-21 05:28:00 -04001171#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
1172/**
1173 * hdd_handle_acs_scan_event() - handle acs scan event for SAP
1174 * @sap_event: tpSap_Event
Jeff Johnson866aca82017-09-10 15:27:20 -07001175 * @adapter: struct hdd_adapter for SAP
Liangwei Dongaef84342016-10-21 05:28:00 -04001176 *
1177 * The function is to handle the eSAP_ACS_SCAN_SUCCESS_EVENT event.
1178 * It will update scan result to cfg80211 and start a timer to flush the
1179 * cached acs scan result.
1180 *
1181 * Return: QDF_STATUS_SUCCESS on success,
1182 * other value on failure
1183 */
Jeff Johnson4338caa2019-03-08 11:19:51 -08001184static QDF_STATUS hdd_handle_acs_scan_event(struct sap_event *sap_event,
Jeff Johnson866aca82017-09-10 15:27:20 -07001185 struct hdd_adapter *adapter)
Liangwei Dongaef84342016-10-21 05:28:00 -04001186{
Jeff Johnsonc54bbf92017-08-28 11:59:35 -07001187 struct hdd_context *hdd_ctx;
Liangwei Dongaef84342016-10-21 05:28:00 -04001188 struct sap_acs_scan_complete_event *comp_evt;
1189 QDF_STATUS qdf_status;
1190 int chan_list_size;
1191
Jeff Johnson399c6272017-08-30 10:51:00 -07001192 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Liangwei Dongaef84342016-10-21 05:28:00 -04001193 if (!hdd_ctx) {
1194 hdd_err("HDD context is null");
1195 return QDF_STATUS_E_FAILURE;
1196 }
1197 comp_evt = &sap_event->sapevt.sap_acs_scan_comp;
1198 hdd_ctx->skip_acs_scan_status = eSAP_SKIP_ACS_SCAN;
1199 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
1200 qdf_mem_free(hdd_ctx->last_acs_channel_list);
1201 hdd_ctx->last_acs_channel_list = NULL;
1202 hdd_ctx->num_of_channels = 0;
1203 /* cache the previous ACS scan channel list .
1204 * If the following OBSS scan chan list is covered by ACS chan list,
1205 * we can skip OBSS Scan to save SAP starting total time.
1206 */
1207 if (comp_evt->num_of_channels && comp_evt->channellist) {
1208 chan_list_size = comp_evt->num_of_channels *
1209 sizeof(comp_evt->channellist[0]);
1210 hdd_ctx->last_acs_channel_list = qdf_mem_malloc(
1211 chan_list_size);
1212 if (hdd_ctx->last_acs_channel_list) {
1213 qdf_mem_copy(hdd_ctx->last_acs_channel_list,
1214 comp_evt->channellist,
1215 chan_list_size);
1216 hdd_ctx->num_of_channels = comp_evt->num_of_channels;
1217 }
1218 }
1219 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Liangwei Dongaef84342016-10-21 05:28:00 -04001220
Srinivas Girigowda55756882017-03-06 16:45:27 -08001221 hdd_debug("Reusing Last ACS scan result for %d sec",
Liangwei Dongaef84342016-10-21 05:28:00 -04001222 ACS_SCAN_EXPIRY_TIMEOUT_S);
1223 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
1224 qdf_status = qdf_mc_timer_start(&hdd_ctx->skip_acs_scan_timer,
1225 ACS_SCAN_EXPIRY_TIMEOUT_S * 1000);
1226 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
1227 hdd_err("Failed to start ACS scan expiry timer");
1228 return QDF_STATUS_SUCCESS;
1229}
1230#else
Jeff Johnson4338caa2019-03-08 11:19:51 -08001231static QDF_STATUS hdd_handle_acs_scan_event(struct sap_event *sap_event,
Jeff Johnson866aca82017-09-10 15:27:20 -07001232 struct hdd_adapter *adapter)
Liangwei Dongaef84342016-10-21 05:28:00 -04001233{
1234 return QDF_STATUS_SUCCESS;
1235}
1236#endif
1237
Will Huang496b36c2017-07-11 16:38:50 +08001238/**
1239 * get_max_rate_vht() - calculate max rate for VHT mode
1240 * @nss: num of streams
1241 * @ch_width: channel width
1242 * @sgi: short gi
1243 * @vht_mcs_map: vht mcs map
1244 *
1245 * This function calculate max rate for VHT mode
1246 *
1247 * Return: max rate
1248 */
1249static int get_max_rate_vht(int nss, int ch_width, int sgi, int vht_mcs_map)
1250{
1251 const struct index_vht_data_rate_type *supported_vht_mcs_rate;
1252 enum data_rate_11ac_max_mcs vht_max_mcs;
1253 int maxrate = 0;
1254 int maxidx;
1255
1256 if (nss == 1) {
1257 supported_vht_mcs_rate = supported_vht_mcs_rate_nss1;
1258 } else if (nss == 2) {
1259 supported_vht_mcs_rate = supported_vht_mcs_rate_nss2;
1260 } else {
1261 /* Not Supported */
1262 hdd_err("nss %d not supported", nss);
1263 return maxrate;
1264 }
1265
1266 vht_max_mcs =
1267 (enum data_rate_11ac_max_mcs)
1268 (vht_mcs_map & DATA_RATE_11AC_MCS_MASK);
1269
1270 if (vht_max_mcs == DATA_RATE_11AC_MAX_MCS_7) {
1271 maxidx = 7;
1272 } else if (vht_max_mcs == DATA_RATE_11AC_MAX_MCS_8) {
1273 maxidx = 8;
1274 } else if (vht_max_mcs == DATA_RATE_11AC_MAX_MCS_9) {
1275 if (ch_width == eHT_CHANNEL_WIDTH_20MHZ)
1276 /* MCS9 is not valid for VHT20 when nss=1,2 */
1277 maxidx = 8;
1278 else
1279 maxidx = 9;
1280 } else {
1281 hdd_err("vht mcs map %x not supported",
1282 vht_mcs_map & DATA_RATE_11AC_MCS_MASK);
1283 return maxrate;
1284 }
1285
1286 if (ch_width == eHT_CHANNEL_WIDTH_20MHZ) {
1287 maxrate =
1288 supported_vht_mcs_rate[maxidx].supported_VHT20_rate[sgi];
1289 } else if (ch_width == eHT_CHANNEL_WIDTH_40MHZ) {
1290 maxrate =
1291 supported_vht_mcs_rate[maxidx].supported_VHT40_rate[sgi];
1292 } else if (ch_width == eHT_CHANNEL_WIDTH_80MHZ) {
1293 maxrate =
1294 supported_vht_mcs_rate[maxidx].supported_VHT80_rate[sgi];
1295 } else {
1296 hdd_err("ch_width %d not supported", ch_width);
1297 return maxrate;
1298 }
1299
1300 return maxrate;
1301}
1302
1303/**
1304 * calculate_max_phy_rate() - calcuate maximum phy rate (100kbps)
1305 * @mode: phymode: Legacy, 11a/b/g, HT, VHT
1306 * @nss: num of stream (maximum num is 2)
1307 * @ch_width: channel width
1308 * @sgi: short gi enabled or not
1309 * @supp_idx: max supported idx
1310 * @ext_idx: max extended idx
1311 * @ht_mcs_idx: max mcs index for HT
1312 * @vht_mcs_map: mcs map for VHT
1313 *
1314 * return: maximum phy rate in 100kbps
1315 */
1316static int calcuate_max_phy_rate(int mode, int nss, int ch_width,
1317 int sgi, int supp_idx, int ext_idx,
1318 int ht_mcs_idx, int vht_mcs_map)
1319{
1320 const struct index_data_rate_type *supported_mcs_rate;
1321 int maxidx = 12; /*default 6M mode*/
1322 int maxrate = 0, tmprate;
1323 int i;
1324
1325 /* check supported rates */
1326 if (supp_idx != 0xff && maxidx < supp_idx)
1327 maxidx = supp_idx;
1328
1329 /* check extended rates */
1330 if (ext_idx != 0xff && maxidx < ext_idx)
1331 maxidx = ext_idx;
1332
1333 for (i = 0; i < QDF_ARRAY_SIZE(supported_data_rate); i++) {
1334 if (supported_data_rate[i].beacon_rate_index == maxidx)
1335 maxrate = supported_data_rate[i].supported_rate[0];
1336 }
1337
1338 if (mode == SIR_SME_PHY_MODE_HT) {
1339 /* check for HT Mode */
1340 maxidx = ht_mcs_idx;
1341 if (nss == 1) {
1342 supported_mcs_rate = supported_mcs_rate_nss1;
1343 } else if (nss == 2) {
1344 supported_mcs_rate = supported_mcs_rate_nss2;
1345 } else {
1346 /* Not Supported */
1347 hdd_err("nss %d not supported", nss);
1348 return maxrate;
1349 }
1350
1351 if (ch_width == eHT_CHANNEL_WIDTH_20MHZ) {
1352 tmprate = sgi ?
1353 supported_mcs_rate[maxidx].supported_rate[2] :
1354 supported_mcs_rate[maxidx].supported_rate[0];
1355 } else if (ch_width == eHT_CHANNEL_WIDTH_40MHZ) {
1356 tmprate = sgi ?
1357 supported_mcs_rate[maxidx].supported_rate[3] :
1358 supported_mcs_rate[maxidx].supported_rate[1];
1359 } else {
1360 hdd_err("invalid mode %d ch_width %d",
1361 mode, ch_width);
1362 return maxrate;
1363 }
1364
1365 if (maxrate < tmprate)
1366 maxrate = tmprate;
1367 }
1368
1369 if (mode == SIR_SME_PHY_MODE_VHT) {
1370 /* check for VHT Mode */
1371 tmprate = get_max_rate_vht(nss, ch_width, sgi, vht_mcs_map);
1372 if (maxrate < tmprate)
1373 maxrate = tmprate;
1374 }
1375
1376 return maxrate;
1377}
1378
1379/**
Ashish Kumar Dhanotiyad523f0d2017-10-26 14:15:48 +05301380 * hdd_convert_dot11mode_from_phymode() - get dot11 mode from phymode
1381 * @phymode: phymode of sta associated to SAP
1382 *
1383 * The function is to convert the phymode to corresponding dot11 mode
1384 *
1385 * Return: dot11mode.
1386 */
1387
1388
1389static int hdd_convert_dot11mode_from_phymode(int phymode)
1390{
1391
1392 switch (phymode) {
1393
1394 case MODE_11A:
1395 return QCA_WLAN_802_11_MODE_11A;
1396
1397 case MODE_11B:
1398 return QCA_WLAN_802_11_MODE_11B;
1399
1400 case MODE_11G:
1401 case MODE_11GONLY:
1402 return QCA_WLAN_802_11_MODE_11G;
1403
1404 case MODE_11NA_HT20:
1405 case MODE_11NG_HT20:
1406 case MODE_11NA_HT40:
1407 case MODE_11NG_HT40:
1408 return QCA_WLAN_802_11_MODE_11N;
1409
1410 case MODE_11AC_VHT20:
1411 case MODE_11AC_VHT40:
1412 case MODE_11AC_VHT80:
1413 case MODE_11AC_VHT20_2G:
1414 case MODE_11AC_VHT40_2G:
1415 case MODE_11AC_VHT80_2G:
1416#ifdef CONFIG_160MHZ_SUPPORT
1417 case MODE_11AC_VHT80_80:
1418 case MODE_11AC_VHT160:
1419#endif
1420 return QCA_WLAN_802_11_MODE_11AC;
1421
1422 default:
1423 return QCA_WLAN_802_11_MODE_INVALID;
1424 }
1425
1426}
1427
1428/**
Will Huang496b36c2017-07-11 16:38:50 +08001429 * hdd_fill_station_info() - fill stainfo once connected
1430 * @stainfo: peer stainfo associate to SAP
1431 * @event: associate/reassociate event received
1432 *
1433 * The function is to update rate stats to stainfo
1434 *
1435 * Return: None.
1436 */
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301437static void hdd_fill_station_info(struct hdd_adapter *adapter,
Will Huang496b36c2017-07-11 16:38:50 +08001438 tSap_StationAssocReassocCompleteEvent *event)
1439{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301440 struct hdd_station_info *stainfo;
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05301441 uint8_t i = 0, oldest_disassoc_sta_idx = WLAN_MAX_STA_COUNT + 1;
1442 qdf_time_t oldest_disassoc_sta_ts = 0;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301443
1444 if (event->staId >= WLAN_MAX_STA_COUNT) {
1445 hdd_err("invalid sta id");
1446 return;
1447 }
1448
1449 stainfo = &adapter->sta_info[event->staId];
1450
1451 if (!stainfo) {
1452 hdd_err("invalid stainfo");
1453 return;
1454 }
1455
Ashish Kumar Dhanotiyac6171062019-01-22 21:55:01 +05301456 qdf_mem_copy(&stainfo->capability, &event->capability_info,
1457 sizeof(uint16_t));
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301458 stainfo->freq = cds_chan_to_freq(event->chan_info.chan_id);
Jeff Johnsone7cc44c2017-10-21 16:27:41 -07001459 stainfo->sta_type = event->staType;
Ashish Kumar Dhanotiyad523f0d2017-10-26 14:15:48 +05301460 stainfo->dot11_mode =
1461 hdd_convert_dot11mode_from_phymode(event->chan_info.info);
1462
Will Huang496b36c2017-07-11 16:38:50 +08001463 stainfo->nss = event->chan_info.nss;
1464 stainfo->rate_flags = event->chan_info.rate_flags;
1465 stainfo->ampdu = event->ampdu;
1466 stainfo->sgi_enable = event->sgi_enable;
1467 stainfo->tx_stbc = event->tx_stbc;
1468 stainfo->rx_stbc = event->rx_stbc;
1469 stainfo->ch_width = event->ch_width;
1470 stainfo->mode = event->mode;
1471 stainfo->max_supp_idx = event->max_supp_idx;
1472 stainfo->max_ext_idx = event->max_ext_idx;
1473 stainfo->max_mcs_idx = event->max_mcs_idx;
1474 stainfo->rx_mcs_map = event->rx_mcs_map;
1475 stainfo->tx_mcs_map = event->tx_mcs_map;
1476 stainfo->assoc_ts = qdf_system_ticks();
1477 stainfo->max_phy_rate =
1478 calcuate_max_phy_rate(stainfo->mode,
1479 stainfo->nss,
1480 stainfo->ch_width,
1481 stainfo->sgi_enable,
1482 stainfo->max_supp_idx,
1483 stainfo->max_ext_idx,
1484 stainfo->max_mcs_idx,
1485 stainfo->rx_mcs_map);
1486 /* expect max_phy_rate report in kbps */
1487 stainfo->max_phy_rate *= 100;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301488
1489 if (event->vht_caps.present) {
1490 stainfo->vht_present = true;
1491 hdd_copy_vht_caps(&stainfo->vht_caps, &event->vht_caps);
Ashish Kumar Dhanotiya6025c702019-03-20 18:48:49 +05301492 stainfo->support_mode |=
1493 (stainfo->vht_present << HDD_VHT_CAPS_PRESENT);
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301494 }
1495 if (event->ht_caps.present) {
1496 stainfo->ht_present = true;
1497 hdd_copy_ht_caps(&stainfo->ht_caps, &event->ht_caps);
Ashish Kumar Dhanotiya6025c702019-03-20 18:48:49 +05301498 stainfo->support_mode |=
1499 (stainfo->ht_present << HDD_HT_CAPS_PRESENT);
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301500 }
Ashish Kumar Dhanotiya6025c702019-03-20 18:48:49 +05301501 stainfo->support_mode |=
1502 (event->he_caps_present << HDD_HE_CAPS_PRESENT);
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301503
Yun Parkc3e35562018-03-08 12:05:52 -08001504 /* Initialize DHCP info */
1505 stainfo->dhcp_phase = DHCP_PHASE_ACK;
1506 stainfo->dhcp_nego_status = DHCP_NEGO_STOP;
1507
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301508 while (i < WLAN_MAX_STA_COUNT) {
1509 if (!qdf_mem_cmp(adapter->cache_sta_info[i].sta_mac.bytes,
1510 event->staMac.bytes,
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05301511 QDF_MAC_ADDR_SIZE))
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301512 break;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301513 i++;
1514 }
1515 if (i >= WLAN_MAX_STA_COUNT) {
1516 i = 0;
1517 while (i < WLAN_MAX_STA_COUNT) {
1518 if (adapter->cache_sta_info[i].in_use != TRUE)
1519 break;
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05301520
1521 if (adapter->cache_sta_info[i].disassoc_ts &&
1522 (!oldest_disassoc_sta_ts ||
1523 (qdf_system_time_after(
1524 oldest_disassoc_sta_ts,
1525 adapter->
1526 cache_sta_info[i].disassoc_ts)))) {
1527 oldest_disassoc_sta_ts =
1528 adapter->
1529 cache_sta_info[i].disassoc_ts;
1530 oldest_disassoc_sta_idx = i;
1531 }
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301532 i++;
1533 }
1534 }
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05301535
1536 if ((i == WLAN_MAX_STA_COUNT) && oldest_disassoc_sta_ts) {
Jeff Johnson0a082d92019-03-04 12:25:49 -08001537 hdd_debug("reached max cached sta_id, removing oldest stainfo");
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05301538 i = oldest_disassoc_sta_idx;
1539 }
1540 if (i < WLAN_MAX_STA_COUNT) {
1541 qdf_mem_zero(&adapter->cache_sta_info[i],
1542 sizeof(*stainfo));
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301543 qdf_mem_copy(&adapter->cache_sta_info[i],
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05301544 stainfo, sizeof(struct hdd_station_info));
1545
1546 } else {
Jeff Johnson0a082d92019-03-04 12:25:49 -08001547 hdd_debug("reached max sta_id, stainfo can't be cached");
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05301548 }
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301549
Will Huang496b36c2017-07-11 16:38:50 +08001550 hdd_debug("cap %d %d %d %d %d %d %d %d %d %x %d",
1551 stainfo->ampdu,
1552 stainfo->sgi_enable,
1553 stainfo->tx_stbc,
1554 stainfo->rx_stbc,
Jeff Johnson65fda112017-10-21 13:46:10 -07001555 stainfo->is_qos_enabled,
Will Huang496b36c2017-07-11 16:38:50 +08001556 stainfo->ch_width,
1557 stainfo->mode,
1558 event->wmmEnabled,
1559 event->chan_info.nss,
1560 event->chan_info.rate_flags,
1561 stainfo->max_phy_rate);
1562 hdd_debug("rate info %d %d %d %d %d",
1563 stainfo->max_supp_idx,
1564 stainfo->max_ext_idx,
1565 stainfo->max_mcs_idx,
1566 stainfo->rx_mcs_map,
1567 stainfo->tx_mcs_map);
1568}
1569
Krunal Soni22208392017-09-29 18:10:34 -07001570/**
1571 * hdd_stop_sap_due_to_invalid_channel() - to stop sap in case of invalid chnl
1572 * @work: pointer to work structure
1573 *
1574 * Let's say SAP detected RADAR and trying to select the new channel and if no
1575 * valid channel is found due to none of the channels are available or
1576 * regulatory restriction then SAP needs to be stopped. so SAP state-machine
1577 * will create a work to stop the bss
1578 *
1579 * stop bss has to happen through worker thread because radar indication comes
1580 * from FW through mc thread or main host thread and if same thread is used to
1581 * do stopbss then waiting for stopbss to finish operation will halt mc thread
1582 * to freeze which will trigger stopbss timeout. Instead worker thread can do
1583 * the stopbss operation while mc thread waits for stopbss to finish.
1584 *
1585 * Return: none
1586 */
Dustin Brown98f7c822019-03-06 12:25:49 -08001587static void hdd_stop_sap_due_to_invalid_channel(struct work_struct *work)
Krunal Soni22208392017-09-29 18:10:34 -07001588{
Dustin Brown98f7c822019-03-06 12:25:49 -08001589 struct hdd_adapter *sap_adapter = container_of(work, struct hdd_adapter,
1590 sap_stop_bss_work);
1591 struct osif_vdev_sync *vdev_sync;
1592
1593 if (osif_vdev_sync_op_start(sap_adapter->dev, &vdev_sync))
Jeff Johnsonb8adae42018-02-27 16:12:00 -08001594 return;
Dustin Brown98f7c822019-03-06 12:25:49 -08001595
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08001596 hdd_debug("work started for sap session[%d]", sap_adapter->vdev_id);
Krunal Soni22208392017-09-29 18:10:34 -07001597 wlan_hdd_stop_sap(sap_adapter);
Krunal Soni22208392017-09-29 18:10:34 -07001598 wlansap_cleanup_cac_timer(WLAN_HDD_GET_SAP_CTX_PTR(sap_adapter));
1599 hdd_debug("work finished for sap");
Dustin Brown98f7c822019-03-06 12:25:49 -08001600
1601 osif_vdev_sync_op_stop(vdev_sync);
Krunal Soni22208392017-09-29 18:10:34 -07001602}
1603
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05301604/**
1605 * hdd_hostapd_apply_action_oui() - Check for action_ouis to be applied on peers
1606 * @hdd_ctx: pointer to hdd context
1607 * @adapter: pointer to adapter
1608 * @event: assoc complete params
1609 *
1610 * This function is used to check whether aggressive tx should be disabled
1611 * based on the soft-ap configuration and action_oui ini
1612 * gActionOUIDisableAggressiveTX
1613 *
1614 * Return: None
1615 */
1616static void
1617hdd_hostapd_apply_action_oui(struct hdd_context *hdd_ctx,
1618 struct hdd_adapter *adapter,
1619 tSap_StationAssocReassocCompleteEvent *event)
1620{
1621 bool found;
1622 uint32_t freq;
1623 tSirMacHTChannelWidth ch_width;
1624 enum sir_sme_phy_mode mode;
1625 struct action_oui_search_attr attr = {0};
1626 QDF_STATUS status;
1627
1628 ch_width = event->ch_width;
1629 if (ch_width != eHT_CHANNEL_WIDTH_20MHZ)
1630 return;
1631
1632 freq = cds_chan_to_freq(event->chan_info.chan_id);
1633 if (WLAN_REG_IS_24GHZ_CH_FREQ(freq))
1634 attr.enable_2g = true;
1635 else if (WLAN_REG_IS_5GHZ_CH_FREQ(freq))
1636 attr.enable_5g = true;
1637 else
1638 return;
1639
1640 mode = event->mode;
1641 if (event->vht_caps.present && mode == SIR_SME_PHY_MODE_VHT)
1642 attr.vht_cap = true;
1643 else if (event->ht_caps.present && mode == SIR_SME_PHY_MODE_HT)
1644 attr.ht_cap = true;
1645
1646 attr.mac_addr = (uint8_t *)(&event->staMac);
1647
1648 found = ucfg_action_oui_search(hdd_ctx->psoc,
1649 &attr,
1650 ACTION_OUI_DISABLE_AGGRESSIVE_TX);
1651 if (!found)
1652 return;
1653
1654 status = sme_set_peer_param(attr.mac_addr,
1655 WMI_PEER_PARAM_DISABLE_AGGRESSIVE_TX,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08001656 true, adapter->vdev_id);
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05301657 if (QDF_IS_STATUS_ERROR(status))
1658 hdd_err("Failed to disable aggregation for peer");
1659}
1660
Varun Reddy Yeturuff4c9982019-02-15 15:59:24 -08001661#ifdef CRYPTO_SET_KEY_CONVERGED
1662static void hdd_hostapd_set_sap_key(struct hdd_adapter *adapter)
1663{
1664 struct wlan_crypto_key *crypto_key;
1665
1666 crypto_key = wlan_crypto_get_key(adapter->vdev, 0);
1667 if (!crypto_key) {
1668 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
1669 "Crypto KEY is NULL");
1670 return;
1671 }
1672 ucfg_crypto_set_key_req(adapter->vdev, crypto_key,
1673 WLAN_CRYPTO_KEY_TYPE_UNICAST);
1674 wma_update_set_key(adapter->vdev_id, true, 1, crypto_key->cipher_type);
1675 ucfg_crypto_set_key_req(adapter->vdev, crypto_key,
1676 WLAN_CRYPTO_KEY_TYPE_GROUP);
1677
1678 wma_update_set_key(adapter->vdev_id, true, 0, crypto_key->cipher_type);
1679}
1680#else
1681static void hdd_hostapd_set_sap_key(struct hdd_adapter *adapter)
1682{
1683 struct hdd_ap_ctx *ap_ctx;
1684 QDF_STATUS status;
1685 uint8_t i;
1686
1687 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1688 /* Set group key / WEP key every time when BSS is restarted */
1689 if (ap_ctx->group_key.keyLength) {
1690 status = wlansap_set_key_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
1691 &ap_ctx->group_key);
1692 if (!QDF_IS_STATUS_SUCCESS(status))
1693 hdd_err("wlansap_set_key_sta failed");
1694 } else {
1695 for (i = 0; i < CSR_MAX_NUM_KEY; i++) {
1696 if (!ap_ctx->wep_key[i].keyLength)
1697 continue;
1698
1699 status = wlansap_set_key_sta(WLAN_HDD_GET_SAP_CTX_PTR
1700 (adapter),
1701 &ap_ctx->wep_key[i]);
1702 if (!QDF_IS_STATUS_SUCCESS(status))
1703 hdd_err("set_key failed idx: %d", i);
1704 }
1705 }
1706}
1707#endif
1708
Jeff Johnson4338caa2019-03-08 11:19:51 -08001709QDF_STATUS hdd_hostapd_sap_event_cb(struct sap_event *sap_event,
Jeff Johnson0604a362018-03-24 17:36:59 -07001710 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711{
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001712 struct hdd_adapter *adapter;
Jeff Johnson9bf24972017-10-04 09:26:58 -07001713 struct hdd_ap_ctx *ap_ctx;
Jeff Johnson5c19ade2017-10-04 09:52:12 -07001714 struct hdd_hostapd_state *hostapd_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001715 struct net_device *dev;
Jeff Johnsonfe31cf52019-03-09 19:46:01 -08001716 eSapHddEvent event_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001717 union iwreq_data wrqu;
1718 uint8_t *we_custom_event_generic = NULL;
1719 int we_event = 0;
1720 int i = 0;
Jeff Johnson0a082d92019-03-04 12:25:49 -08001721 uint8_t sta_id;
Anurag Chouhance0dc992016-02-16 18:18:03 +05301722 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723 bool bAuthRequired = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724 char unknownSTAEvent[IW_CUSTOM_MAX + 1];
1725 char maxAssocExceededEvent[IW_CUSTOM_MAX + 1];
1726 uint8_t we_custom_start_event[64];
1727 char *startBssEvent;
Jeff Johnson23c3b842017-09-03 09:05:29 -07001728 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729 struct iw_michaelmicfailure msg;
1730 uint8_t ignoreCAC = 0;
1731 struct hdd_config *cfg = NULL;
1732 struct wlan_dfs_info dfs_info;
1733 uint8_t cc_len = WLAN_SVC_COUNTRY_CODE_LEN;
Jeff Johnson866aca82017-09-10 15:27:20 -07001734 struct hdd_adapter *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301735 QDF_STATUS status = QDF_STATUS_SUCCESS;
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +05301736 struct hdd_chan_change_params chan_change;
Will Huang496b36c2017-07-11 16:38:50 +08001737 tSap_StationAssocReassocCompleteEvent *event;
Vignesh Viswanathan597d9012018-07-06 15:26:08 +05301738 tSap_StationSetKeyCompleteEvent *key_complete;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001739 int ret = 0;
bings61d5bec2017-06-27 14:13:40 +08001740 struct ch_params sap_ch_param = {0};
bings58ce8622017-07-10 15:55:36 +08001741 eCsrPhyMode phy_mode;
1742 bool legacy_phymode;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05301743 tSap_StationDisassocCompleteEvent *disassoc_comp;
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05301744 struct hdd_station_info *stainfo, *cache_stainfo;
Jeff Johnson89a0c742018-06-12 18:17:46 -07001745 mac_handle_t mac_handle;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07001746 struct sap_config *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001747
Jeff Johnson0604a362018-03-24 17:36:59 -07001748 dev = context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001749 if (!dev) {
Jeff Johnson0604a362018-03-24 17:36:59 -07001750 hdd_err("context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301751 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001752 }
1753
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001754 adapter = netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755
Jeff Johnsond36fa332019-03-18 13:42:25 -07001756 if ((!adapter) ||
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001757 (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -07001758 hdd_err("invalid adapter or adapter has invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301759 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001760 }
1761
Jeff Johnson5c19ade2017-10-04 09:52:12 -07001762 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Jeff Johnson9bf24972017-10-04 09:26:58 -07001763 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001764
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001765 if (!sap_event) {
1766 hdd_err("sap_event is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301767 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768 }
1769
Jeff Johnsonfe31cf52019-03-09 19:46:01 -08001770 event_id = sap_event->sapHddEventCode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771 memset(&wrqu, '\0', sizeof(wrqu));
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001772 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773
Jeff Johnson23c3b842017-09-03 09:05:29 -07001774 if (!hdd_ctx) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -07001775 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301776 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001777 }
1778
Jeff Johnson23c3b842017-09-03 09:05:29 -07001779 cfg = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780
1781 if (!cfg) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -07001782 hdd_err("HDD config is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301783 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784 }
1785
Jeff Johnson89a0c742018-06-12 18:17:46 -07001786 mac_handle = hdd_ctx->mac_handle;
Jeff Johnson01206862017-10-27 20:55:59 -07001787 dfs_info.channel = ap_ctx->operating_channel;
Jeff Johnson89a0c742018-06-12 18:17:46 -07001788 sme_get_country_code(mac_handle, dfs_info.country_code, &cc_len);
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001789 sta_id = sap_event->sapevt.sapStartBssCompleteEvent.staId;
Abhinav Kumar6f694482018-09-04 16:07:39 +05301790 sap_config = &adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001791
Jeff Johnsonfe31cf52019-03-09 19:46:01 -08001792 switch (event_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001793 case eSAP_START_BSS_EVENT:
Srinivas Girigowda55756882017-03-06 16:45:27 -08001794 hdd_debug("BSS status = %s, channel = %u, bc sta Id = %d",
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001795 sap_event->sapevt.sapStartBssCompleteEvent.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001796 status ? "eSAP_STATUS_FAILURE" : "eSAP_STATUS_SUCCESS",
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001797 sap_event->sapevt.sapStartBssCompleteEvent.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001798 operatingChannel,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001799 sap_event->sapevt.sapStartBssCompleteEvent.staId);
gaurank kathpalia379e05c2018-11-27 17:46:43 +05301800 ap_ctx->operating_channel =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001801 sap_event->sapevt.sapStartBssCompleteEvent
gaurank kathpalia379e05c2018-11-27 17:46:43 +05301802 .operatingChannel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001803
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08001804 adapter->vdev_id =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001805 sap_event->sapevt.sapStartBssCompleteEvent.sessionId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001806
Abhinav Kumar6f694482018-09-04 16:07:39 +05301807 sap_config->channel =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001808 sap_event->sapevt.sapStartBssCompleteEvent.
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05301809 operatingChannel;
Abhinav Kumar6f694482018-09-04 16:07:39 +05301810 sap_config->ch_params.ch_width =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001811 sap_event->sapevt.sapStartBssCompleteEvent.ch_width;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05301812
gaurank kathpalia379e05c2018-11-27 17:46:43 +05301813 sap_config->ch_params = ap_ctx->sap_context->ch_params;
1814 sap_config->sec_ch = ap_ctx->sap_context->secondary_ch;
Abhinav Kumar6f694482018-09-04 16:07:39 +05301815
Jeff Johnson5c19ade2017-10-04 09:52:12 -07001816 hostapd_state->qdf_status =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001817 sap_event->sapevt.sapStartBssCompleteEvent.status;
Arif Hussaine478b4d2017-03-30 13:55:48 -07001818
Abhinav Kumar338e57d2019-02-04 17:30:10 +05301819 qdf_atomic_set(&adapter->ch_switch_in_progress, 0);
Jeff Johnson89a0c742018-06-12 18:17:46 -07001820 wlansap_get_dfs_ignore_cac(mac_handle, &ignoreCAC);
Arif Hussaine478b4d2017-03-30 13:55:48 -07001821
1822 /* DFS requirement: DO NOT transmit during CAC. */
Dustin Brown07901ec2018-09-07 11:02:41 -07001823 if (CHANNEL_STATE_DFS !=
1824 wlan_reg_get_channel_state(hdd_ctx->pdev,
1825 ap_ctx->operating_channel)
Arif Hussaine478b4d2017-03-30 13:55:48 -07001826 || ignoreCAC
Jeff Johnson23c3b842017-09-03 09:05:29 -07001827 || hdd_ctx->dev_dfs_cac_status == DFS_CAC_ALREADY_DONE)
Jeff Johnson9bf24972017-10-04 09:26:58 -07001828 ap_ctx->dfs_cac_block_tx = false;
Arif Hussaine478b4d2017-03-30 13:55:48 -07001829 else
Jeff Johnson9bf24972017-10-04 09:26:58 -07001830 ap_ctx->dfs_cac_block_tx = true;
Arif Hussaine478b4d2017-03-30 13:55:48 -07001831
Dustin Brown07901ec2018-09-07 11:02:41 -07001832 ucfg_ipa_set_dfs_cac_tx(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301833 ap_ctx->dfs_cac_block_tx);
1834
Jeff Johnson36e74c42017-09-18 08:15:42 -07001835 hdd_debug("The value of dfs_cac_block_tx[%d] for ApCtx[%pK]:%d",
Jeff Johnson9bf24972017-10-04 09:26:58 -07001836 ap_ctx->dfs_cac_block_tx, ap_ctx,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08001837 adapter->vdev_id);
Arif Hussaine478b4d2017-03-30 13:55:48 -07001838
Jeff Johnson5c19ade2017-10-04 09:52:12 -07001839 if (hostapd_state->qdf_status) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08001840 hdd_err("startbss event failed!!");
Krunal Soni35fc8ea2016-10-26 18:52:38 -07001841 /*
1842 * Make sure to set the event before proceeding
1843 * for error handling otherwise caller thread will
1844 * wait till 10 secs and no other connection will
1845 * go through before that.
1846 */
Jeff Johnson0f9f87b2017-10-28 09:21:06 -07001847 hostapd_state->bss_state = BSS_STOP;
Jeff Johnson5c19ade2017-10-04 09:52:12 -07001848 qdf_event_set(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001849 goto stopbss;
1850 } else {
Jeff Johnson89a0c742018-06-12 18:17:46 -07001851 sme_ch_avoid_update_req(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852
Jeff Johnson42518cf2017-10-26 13:33:29 -07001853 ap_ctx->broadcast_sta_id =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001854 sap_event->sapevt.sapStartBssCompleteEvent.staId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855
Ajit Pal Singhd6c08f22018-04-25 16:55:26 +05301856 cdp_hl_fc_set_td_limit(
1857 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08001858 adapter->vdev_id,
Ajit Pal Singhd6c08f22018-04-25 16:55:26 +05301859 ap_ctx->operating_channel);
1860
1861 hdd_register_tx_flow_control(adapter,
1862 hdd_softap_tx_resume_timer_expired_handler,
1863 hdd_softap_tx_resume_cb,
1864 hdd_tx_flow_control_is_pause);
1865
Visweswara Tanukub5a61242019-03-26 12:24:13 +05301866 hdd_register_hl_netdev_fc_timer(
1867 adapter,
1868 hdd_tx_resume_timer_expired_handler);
1869
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001870 /* @@@ need wep logic here to set privacy bit */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301871 qdf_status =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001872 hdd_softap_register_bc_sta(adapter,
Jeff Johnsonc8d94a12017-10-27 14:02:53 -07001873 ap_ctx->privacy);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301874 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -07001875 hdd_warn("Failed to register BC STA %d",
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301876 qdf_status);
Jeff Johnson0604a362018-03-24 17:36:59 -07001877 hdd_stop_bss_link(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878 }
1879 }
1880
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301881 if (ucfg_ipa_is_enabled()) {
Dustin Brown07901ec2018-09-07 11:02:41 -07001882 status = ucfg_ipa_wlan_evt(hdd_ctx->pdev,
1883 adapter->dev,
1884 adapter->device_mode,
1885 ap_ctx->broadcast_sta_id,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08001886 adapter->vdev_id,
Dustin Brown07901ec2018-09-07 11:02:41 -07001887 WLAN_IPA_AP_CONNECT,
1888 adapter->dev->dev_addr);
Yun Parka9d0c112018-03-07 14:11:27 -08001889 if (status)
1890 hdd_err("WLAN_AP_CONNECT event failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891 }
1892
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Jeff Johnson23c3b842017-09-03 09:05:29 -07001894 wlan_hdd_auto_shutdown_enable(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895#endif
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001896 hdd_hostapd_channel_prevent_suspend(adapter,
Jeff Johnson01206862017-10-27 20:55:59 -07001897 ap_ctx->operating_channel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001898
Jeff Johnson0f9f87b2017-10-28 09:21:06 -07001899 hostapd_state->bss_state = BSS_START;
Subrat Dash5f36fbe2019-02-12 16:28:14 +05301900 hdd_start_tsf_sync(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001901
Kondabattini, Ganesh702d90e2016-09-03 01:54:22 +05301902 /* Set default key index */
Dustin Browna2868622018-03-20 11:38:14 -07001903 hdd_debug("default key index %hu", ap_ctx->wep_def_key_idx);
Kondabattini, Ganesh702d90e2016-09-03 01:54:22 +05301904
Jeff Johnson89a0c742018-06-12 18:17:46 -07001905 sme_roam_set_default_key_index(mac_handle,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08001906 adapter->vdev_id,
Jeff Johnson89a0c742018-06-12 18:17:46 -07001907 ap_ctx->wep_def_key_idx);
Kondabattini, Ganesh702d90e2016-09-03 01:54:22 +05301908
Varun Reddy Yeturuff4c9982019-02-15 15:59:24 -08001909 hdd_hostapd_set_sap_key(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07001911 /* Fill the params for sending IWEVCUSTOM Event
1912 * with SOFTAP.enabled
1913 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001914 startBssEvent = "SOFTAP.enabled";
1915 memset(&we_custom_start_event, '\0',
1916 sizeof(we_custom_start_event));
1917 memcpy(&we_custom_start_event, startBssEvent,
1918 strlen(startBssEvent));
1919 memset(&wrqu, 0, sizeof(wrqu));
1920 wrqu.data.length = strlen(startBssEvent);
1921 we_event = IWEVCUSTOM;
1922 we_custom_event_generic = we_custom_start_event;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001923 hdd_ipa_set_tx_flow_info();
Manishekar Chandrasekarancb052172016-04-22 12:19:04 +05301924
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08001925 if (policy_mgr_is_hw_mode_change_after_vdev_up(
Dustin Brown1dbefe62018-09-11 16:32:03 -07001926 hdd_ctx->psoc)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08001927 hdd_debug("check for possible hw mode change");
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08001928 status = policy_mgr_set_hw_mode_on_channel_switch(
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08001929 hdd_ctx->psoc, adapter->vdev_id);
Manishekar Chandrasekarancb052172016-04-22 12:19:04 +05301930 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda55756882017-03-06 16:45:27 -08001931 hdd_debug("set hw mode change not done");
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08001932 policy_mgr_set_do_hw_mode_change_flag(
Dustin Brown1dbefe62018-09-11 16:32:03 -07001933 hdd_ctx->psoc, false);
Manishekar Chandrasekarancb052172016-04-22 12:19:04 +05301934 }
Abhishek Singhbfaebe32019-03-19 13:37:55 +05301935 hdd_debug("check for SAP restart");
1936 policy_mgr_check_concurrent_intf_and_restart_sap(
1937 hdd_ctx->psoc);
Krunal Soni35fc8ea2016-10-26 18:52:38 -07001938 /*
1939 * set this event at the very end because once this events
1940 * get set, caller thread is waiting to do further processing.
1941 * so once this event gets set, current worker thread might get
1942 * pre-empted by caller thread.
1943 */
Jeff Johnson5c19ade2017-10-04 09:52:12 -07001944 qdf_status = qdf_event_set(&hostapd_state->qdf_event);
Krunal Soni35fc8ea2016-10-26 18:52:38 -07001945 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08001946 hdd_err("qdf_event_set failed! status: %d", qdf_status);
Krunal Soni35fc8ea2016-10-26 18:52:38 -07001947 goto stopbss;
1948 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001949 break; /* Event will be sent after Switch-Case stmt */
1950
1951 case eSAP_STOP_BSS_EVENT:
Srinivas Girigowda55756882017-03-06 16:45:27 -08001952 hdd_debug("BSS stop status = %s",
Jeff Johnson1cf299e2019-03-07 22:22:30 -08001953 sap_event->sapevt.sapStopBssCompleteEvent.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954 status ? "eSAP_STATUS_FAILURE" : "eSAP_STATUS_SUCCESS");
1955
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001956 hdd_hostapd_channel_allow_suspend(adapter,
Jeff Johnson01206862017-10-27 20:55:59 -07001957 ap_ctx->operating_channel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001958
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001959 /* Invalidate the channel info. */
Jeff Johnson01206862017-10-27 20:55:59 -07001960 ap_ctx->operating_channel = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001961
1962 /* reset the dfs_cac_status and dfs_cac_block_tx flag only when
1963 * the last BSS is stopped
1964 */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07001965 con_sap_adapter = hdd_get_con_sap_adapter(adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001966 if (!con_sap_adapter) {
Jeff Johnson9bf24972017-10-04 09:26:58 -07001967 ap_ctx->dfs_cac_block_tx = true;
Jeff Johnson23c3b842017-09-03 09:05:29 -07001968 hdd_ctx->dev_dfs_cac_status = DFS_CAC_NEVER_DONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001969 }
Jeff Johnson9bf24972017-10-04 09:26:58 -07001970 hdd_debug("bss_stop_reason=%d", ap_ctx->bss_stop_reason);
hqu73bccf22017-10-28 15:34:17 +08001971 if ((BSS_STOP_DUE_TO_MCC_SCC_SWITCH !=
1972 ap_ctx->bss_stop_reason) &&
1973 (BSS_STOP_DUE_TO_VENDOR_CONFIG_CHAN !=
1974 ap_ctx->bss_stop_reason)) {
1975 /*
1976 * when MCC to SCC switching or vendor subcmd
1977 * setting sap config channel happens, key storage
wadesong9b819072017-02-07 16:42:09 +08001978 * should not be cleared due to hostapd will not
1979 * repopulate the original keys
1980 */
Jeff Johnson413c15f2017-10-27 18:56:35 -07001981 ap_ctx->group_key.keyLength = 0;
wadesong9b819072017-02-07 16:42:09 +08001982 for (i = 0; i < CSR_MAX_NUM_KEY; i++)
Jeff Johnson3d731362017-10-27 19:06:41 -07001983 ap_ctx->wep_key[i].keyLength = 0;
wadesong9b819072017-02-07 16:42:09 +08001984 }
1985
1986 /* clear the reason code in case BSS is stopped
1987 * in another place
1988 */
Jeff Johnson9bf24972017-10-04 09:26:58 -07001989 ap_ctx->bss_stop_reason = BSS_STOP_REASON_INVALID;
Alok Kumar5011ee62018-09-26 14:16:38 +05301990 ap_ctx->ap_active = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001991 goto stopbss;
1992
1993 case eSAP_DFS_CAC_START:
Jeff Johnson23c3b842017-09-03 09:05:29 -07001994 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05301995 WLAN_SVC_DFS_CAC_START_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996 &dfs_info,
1997 sizeof(struct wlan_dfs_info));
Jeff Johnson23c3b842017-09-03 09:05:29 -07001998 hdd_ctx->dev_dfs_cac_status = DFS_CAC_IN_PROGRESS;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301999 if (QDF_STATUS_SUCCESS !=
Jeff Johnson23c3b842017-09-03 09:05:29 -07002000 hdd_send_radar_event(hdd_ctx, eSAP_DFS_CAC_START,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002001 dfs_info, &adapter->wdev)) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -07002002 hdd_err("Unable to indicate CAC start NL event");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002003 } else {
Srinivas Girigowda55756882017-03-06 16:45:27 -08002004 hdd_debug("Sent CAC start to user space");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302006
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302007 qdf_atomic_set(&adapter->ch_switch_in_progress, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002008 break;
2009 case eSAP_DFS_CAC_INTERRUPTED:
2010 /*
2011 * The CAC timer did not run completely and a radar was detected
2012 * during the CAC time. This new state will keep the tx path
2013 * blocked since we do not want any transmission on the DFS
2014 * channel. CAC end will only be reported here since the user
2015 * space applications are waiting on CAC end for their state
2016 * management.
2017 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302018 if (QDF_STATUS_SUCCESS !=
Jeff Johnson23c3b842017-09-03 09:05:29 -07002019 hdd_send_radar_event(hdd_ctx, eSAP_DFS_CAC_END,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002020 dfs_info, &adapter->wdev)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002021 hdd_err("Unable to indicate CAC end (interrupted) event");
2022 } else {
Srinivas Girigowda55756882017-03-06 16:45:27 -08002023 hdd_debug("Sent CAC end (interrupted) to user space");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024 }
2025 break;
2026 case eSAP_DFS_CAC_END:
Jeff Johnson23c3b842017-09-03 09:05:29 -07002027 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05302028 WLAN_SVC_DFS_CAC_END_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029 &dfs_info,
2030 sizeof(struct wlan_dfs_info));
Jeff Johnson9bf24972017-10-04 09:26:58 -07002031 ap_ctx->dfs_cac_block_tx = false;
Dustin Brown07901ec2018-09-07 11:02:41 -07002032 ucfg_ipa_set_dfs_cac_tx(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05302033 ap_ctx->dfs_cac_block_tx);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002034 hdd_ctx->dev_dfs_cac_status = DFS_CAC_ALREADY_DONE;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302035 if (QDF_STATUS_SUCCESS !=
Jeff Johnson23c3b842017-09-03 09:05:29 -07002036 hdd_send_radar_event(hdd_ctx, eSAP_DFS_CAC_END,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002037 dfs_info, &adapter->wdev)) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -07002038 hdd_err("Unable to indicate CAC end NL event");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002039 } else {
Srinivas Girigowda55756882017-03-06 16:45:27 -08002040 hdd_debug("Sent CAC end to user space");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002041 }
2042 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002043 case eSAP_DFS_RADAR_DETECT:
Kapil Guptac1224bf2017-06-22 21:22:40 +05302044 {
2045 int i;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07002046 struct sap_config *sap_config =
Jeff Johnsonb9424862017-10-30 08:49:35 -07002047 &adapter->session.ap.sap_config;
Kapil Guptac1224bf2017-06-22 21:22:40 +05302048
Jeff Johnson23c3b842017-09-03 09:05:29 -07002049 hdd_dfs_indicate_radar(hdd_ctx);
2050 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05302051 WLAN_SVC_DFS_RADAR_DETECT_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002052 &dfs_info,
2053 sizeof(struct wlan_dfs_info));
Jeff Johnson23c3b842017-09-03 09:05:29 -07002054 hdd_ctx->dev_dfs_cac_status = DFS_CAC_NEVER_DONE;
Kapil Guptac1224bf2017-06-22 21:22:40 +05302055 for (i = 0; i < sap_config->channel_info_count; i++) {
2056 if (sap_config->channel_info[i].ieee_chan_number
2057 == dfs_info.channel)
2058 sap_config->channel_info[i].flags |=
2059 IEEE80211_CHAN_RADAR_DFS;
2060 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302061 if (QDF_STATUS_SUCCESS !=
Jeff Johnson23c3b842017-09-03 09:05:29 -07002062 hdd_send_radar_event(hdd_ctx, eSAP_DFS_RADAR_DETECT,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002063 dfs_info, &adapter->wdev)) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -07002064 hdd_err("Unable to indicate Radar detect NL event");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 } else {
Srinivas Girigowda55756882017-03-06 16:45:27 -08002066 hdd_debug("Sent radar detected to user space");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002067 }
2068 break;
Kapil Guptac1224bf2017-06-22 21:22:40 +05302069 }
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05302070 case eSAP_DFS_RADAR_DETECT_DURING_PRE_CAC:
2071 hdd_debug("notification for radar detect during pre cac:%d",
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002072 adapter->vdev_id);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002073 hdd_send_conditional_chan_switch_status(hdd_ctx,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002074 &adapter->wdev, false);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002075 hdd_ctx->dev_dfs_cac_status = DFS_CAC_NEVER_DONE;
2076 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05302077 wlan_hdd_sap_pre_cac_failure,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002078 (void *)adapter);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002079 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05302080 break;
2081 case eSAP_DFS_PRE_CAC_END:
2082 hdd_debug("pre cac end notification received:%d",
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002083 adapter->vdev_id);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002084 hdd_send_conditional_chan_switch_status(hdd_ctx,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002085 &adapter->wdev, true);
Jeff Johnson9bf24972017-10-04 09:26:58 -07002086 ap_ctx->dfs_cac_block_tx = false;
Dustin Brown07901ec2018-09-07 11:02:41 -07002087 ucfg_ipa_set_dfs_cac_tx(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05302088 ap_ctx->dfs_cac_block_tx);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002089 hdd_ctx->dev_dfs_cac_status = DFS_CAC_ALREADY_DONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002090
Jeff Johnson23c3b842017-09-03 09:05:29 -07002091 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05302092 wlan_hdd_sap_pre_cac_success,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002093 (void *)adapter);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002094 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05302095 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002096 case eSAP_DFS_NO_AVAILABLE_CHANNEL:
2097 wlan_hdd_send_svc_nlink_msg
Jeff Johnson23c3b842017-09-03 09:05:29 -07002098 (hdd_ctx->radio_index,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05302099 WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND, &dfs_info,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002100 sizeof(struct wlan_dfs_info));
2101 break;
2102
2103 case eSAP_STA_SET_KEY_EVENT:
2104 /* TODO:
2105 * forward the message to hostapd once implementation
2106 * is done for now just print
2107 */
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002108 key_complete = &sap_event->sapevt.sapStationSetKeyCompleteEvent;
Srinivas Girigowda55756882017-03-06 16:45:27 -08002109 hdd_debug("SET Key: configured status = %s",
Vignesh Viswanathan597d9012018-07-06 15:26:08 +05302110 key_complete->status ?
2111 "eSAP_STATUS_FAILURE" : "eSAP_STATUS_SUCCESS");
2112
2113 if (QDF_IS_STATUS_SUCCESS(key_complete->status)) {
2114 hdd_softap_change_sta_state(adapter,
2115 &key_complete->peerMacAddr,
2116 OL_TXRX_PEER_STATE_AUTH);
Ashish Kumar Dhanotiya42b03782018-01-16 10:55:16 +05302117 status = wlan_hdd_send_sta_authorized_event(
2118 adapter, hdd_ctx,
2119 &key_complete->peerMacAddr);
2120
Vignesh Viswanathan597d9012018-07-06 15:26:08 +05302121 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302122 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002123 case eSAP_STA_MIC_FAILURE_EVENT:
2124 {
2125 memset(&msg, '\0', sizeof(msg));
2126 msg.src_addr.sa_family = ARPHRD_ETHER;
2127 memcpy(msg.src_addr.sa_data,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002128 &sap_event->sapevt.sapStationMICFailureEvent.
Anurag Chouhan6d760662016-02-20 16:05:43 +05302129 staMac, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda55756882017-03-06 16:45:27 -08002130 hdd_debug("MIC MAC " MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002131 MAC_ADDR_ARRAY(msg.src_addr.sa_data));
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002132 if (sap_event->sapevt.sapStationMICFailureEvent.
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002133 multicast == true)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002134 msg.flags = IW_MICFAILURE_GROUP;
2135 else
2136 msg.flags = IW_MICFAILURE_PAIRWISE;
2137 memset(&wrqu, 0, sizeof(wrqu));
2138 wrqu.data.length = sizeof(msg);
2139 we_event = IWEVMICHAELMICFAILURE;
2140 we_custom_event_generic = (uint8_t *) &msg;
2141 }
2142 /* inform mic failure to nl80211 */
2143 cfg80211_michael_mic_failure(dev,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002144 sap_event->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145 sapevt.sapStationMICFailureEvent.
2146 staMac.bytes,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002147 ((sap_event->sapevt.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002148 sapStationMICFailureEvent.
2149 multicast ==
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002150 true) ?
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002151 NL80211_KEYTYPE_GROUP :
2152 NL80211_KEYTYPE_PAIRWISE),
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002153 sap_event->sapevt.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002154 sapStationMICFailureEvent.keyId,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002155 sap_event->sapevt.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002156 sapStationMICFailureEvent.TSC,
2157 GFP_KERNEL);
2158 break;
2159
2160 case eSAP_STA_ASSOC_EVENT:
2161 case eSAP_STA_REASSOC_EVENT:
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002162 event = &sap_event->sapevt.sapStationAssocReassocCompleteEvent;
wadesonga8637bb2018-01-23 15:11:19 +08002163 if (eSAP_STATUS_FAILURE == event->status) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07002164 hdd_info("assoc failure: " MAC_ADDRESS_STR,
2165 MAC_ADDR_ARRAY(wrqu.addr.sa_data));
wadesonga8637bb2018-01-23 15:11:19 +08002166 break;
2167 }
2168
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05302169 hdd_hostapd_apply_action_oui(hdd_ctx, adapter, event);
2170
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002171 wrqu.addr.sa_family = ARPHRD_ETHER;
2172 memcpy(wrqu.addr.sa_data,
Will Huang496b36c2017-07-11 16:38:50 +08002173 &event->staMac, QDF_MAC_ADDR_SIZE);
Dustin Brown5e89ef82018-03-14 11:50:23 -07002174 hdd_info("associated " MAC_ADDRESS_STR,
2175 MAC_ADDR_ARRAY(wrqu.addr.sa_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002176 we_event = IWEVREGISTERED;
2177
Jeff Johnsona8e686b2017-10-27 15:05:18 -07002178 if ((eCSR_ENCRYPT_TYPE_NONE == ap_ctx->encryption_type) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002179 (eCSR_ENCRYPT_TYPE_WEP40_STATICKEY ==
Jeff Johnsona8e686b2017-10-27 15:05:18 -07002180 ap_ctx->encryption_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002181 || (eCSR_ENCRYPT_TYPE_WEP104_STATICKEY ==
Jeff Johnsona8e686b2017-10-27 15:05:18 -07002182 ap_ctx->encryption_type)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002183 bAuthRequired = false;
2184 }
2185
Jeff Johnson8b8d03d2017-09-20 13:56:27 -07002186 if (bAuthRequired) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302187 qdf_status = hdd_softap_register_sta(
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002188 adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002189 true,
Jeff Johnsonc8d94a12017-10-27 14:02:53 -07002190 ap_ctx->privacy,
Jeff Johnson3f6c89f2018-03-01 14:27:38 -08002191 event->staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05302192 (struct qdf_mac_addr *)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002193 wrqu.addr.sa_data,
Will Huang496b36c2017-07-11 16:38:50 +08002194 event->wmmEnabled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302195 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Srinivas Girigowda55756882017-03-06 16:45:27 -08002196 hdd_err("Failed to register STA %d "
Jeff Johnsoncfb85832016-06-30 13:46:10 -07002197 MAC_ADDRESS_STR "", qdf_status,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002198 MAC_ADDR_ARRAY(wrqu.addr.sa_data));
2199 } else {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302200 qdf_status = hdd_softap_register_sta(
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002201 adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002202 false,
Jeff Johnsonc8d94a12017-10-27 14:02:53 -07002203 ap_ctx->privacy,
Jeff Johnson3f6c89f2018-03-01 14:27:38 -08002204 event->staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05302205 (struct qdf_mac_addr *)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002206 wrqu.addr.sa_data,
Will Huang496b36c2017-07-11 16:38:50 +08002207 event->wmmEnabled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302208 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Srinivas Girigowda55756882017-03-06 16:45:27 -08002209 hdd_err("Failed to register STA %d "
Jeff Johnsoncfb85832016-06-30 13:46:10 -07002210 MAC_ADDRESS_STR "", qdf_status,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002211 MAC_ADDR_ARRAY(wrqu.addr.sa_data));
2212 }
2213
Jeff Johnson0a082d92019-03-04 12:25:49 -08002214 sta_id = event->staId;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05302215 if (QDF_IS_STATUS_SUCCESS(qdf_status))
2216 hdd_fill_station_info(adapter, event);
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05302217
Jeff Johnson0a082d92019-03-04 12:25:49 -08002218 adapter->sta_info[sta_id].ecsa_capable = event->ecsa_capable;
gaolezd16a2852018-01-10 11:08:20 +08002219
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302220 if (ucfg_ipa_is_enabled()) {
Dustin Brown07901ec2018-09-07 11:02:41 -07002221 status = ucfg_ipa_wlan_evt(hdd_ctx->pdev,
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302222 adapter->dev,
2223 adapter->device_mode,
2224 event->staId,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002225 adapter->vdev_id,
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302226 WLAN_IPA_CLIENT_CONNECT_EX,
2227 event->staMac.bytes);
Yun Parka9d0c112018-03-07 14:11:27 -08002228 if (status)
Jeff Johnsoncfb85832016-06-30 13:46:10 -07002229 hdd_err("WLAN_CLIENT_CONNECT_EX event failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002230 }
2231
Nirav Shah1da77682016-05-03 20:16:39 +05302232 DPTRACE(qdf_dp_trace_mgmt_pkt(QDF_DP_TRACE_MGMT_PACKET_RECORD,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002233 adapter->vdev_id,
Venkata Sharath Chandra Manchala0b9fc632017-05-15 14:35:15 -07002234 QDF_TRACE_DEFAULT_PDEV_ID,
Nirav Shah1da77682016-05-03 20:16:39 +05302235 QDF_PROTO_TYPE_MGMT, QDF_PROTO_MGMT_ASSOC));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002236
2237#ifdef MSM_PLATFORM
2238 /* start timer in sap/p2p_go */
Jeff Johnson136c51b2017-10-27 20:02:41 -07002239 if (ap_ctx->ap_active == false) {
Jeff Johnson23c3b842017-09-03 09:05:29 -07002240 spin_lock_bh(&hdd_ctx->bus_bw_lock);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002241 adapter->prev_tx_packets =
2242 adapter->stats.tx_packets;
2243 adapter->prev_rx_packets =
2244 adapter->stats.rx_packets;
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08002245
2246 cdp_get_intra_bss_fwd_pkts_count(
2247 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002248 adapter->vdev_id,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002249 &adapter->prev_fwd_tx_packets,
2250 &adapter->prev_fwd_rx_packets);
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08002251
Jeff Johnson23c3b842017-09-03 09:05:29 -07002252 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
2253 hdd_bus_bw_compute_timer_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002254 }
2255#endif
Jeff Johnson136c51b2017-10-27 20:02:41 -07002256 ap_ctx->ap_active = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002257#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Jeff Johnson23c3b842017-09-03 09:05:29 -07002258 wlan_hdd_auto_shutdown_enable(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002259#endif
Jeff Johnson23c3b842017-09-03 09:05:29 -07002260 cds_host_diag_log_work(&hdd_ctx->sap_wake_lock,
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05302261 HDD_SAP_WAKE_LOCK_DURATION,
2262 WIFI_POWER_EVENT_WAKELOCK_SAP);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002263 qdf_wake_lock_timeout_acquire(&hdd_ctx->sap_wake_lock,
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05302264 HDD_SAP_WAKE_LOCK_DURATION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002265 {
Manjeet Singhd295b1d2016-07-28 15:57:38 +05302266 struct station_info *sta_info;
Pragaspathi Thilagaraj2720d812019-01-30 16:58:04 +05302267 uint32_t ies_len = event->ies_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002268
Manjeet Singhd295b1d2016-07-28 15:57:38 +05302269 sta_info = qdf_mem_malloc(sizeof(*sta_info));
2270 if (!sta_info) {
2271 hdd_err("Failed to allocate station info");
2272 return QDF_STATUS_E_FAILURE;
2273 }
Pragaspathi Thilagaraj2720d812019-01-30 16:58:04 +05302274
2275 sta_info->assoc_req_ies = event->ies;
2276 sta_info->assoc_req_ies_len = ies_len;
Ryan Hsue7bc3a72016-01-18 12:08:22 -08002277#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)) && !defined(WITH_BACKPORTS)
Pragaspathi Thilagaraj2720d812019-01-30 16:58:04 +05302278 /*
2279 * After Kernel 4.0, it's no longer need to set
2280 * STATION_INFO_ASSOC_REQ_IES flag, as it
2281 * changed to use assoc_req_ies_len length to
2282 * check the existence of request IE.
2283 */
2284 sta_info->filled |= STATION_INFO_ASSOC_REQ_IES;
Ryan Hsue7bc3a72016-01-18 12:08:22 -08002285#endif
Pragaspathi Thilagaraj2720d812019-01-30 16:58:04 +05302286 cfg80211_new_sta(dev,
2287 (const u8 *)&event->staMac.bytes[0],
2288 sta_info, GFP_KERNEL);
Manjeet Singhd295b1d2016-07-28 15:57:38 +05302289 qdf_mem_free(sta_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002290 }
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07002291 /* Lets abort scan to ensure smooth authentication for client */
Dustin Brown89fa06e2018-09-07 10:47:27 -07002292 if (ucfg_scan_get_vdev_status(adapter->vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -07002293 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -07002294 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002295 adapter->vdev_id, INVALID_SCAN_ID,
Dustin Brown07901ec2018-09-07 11:02:41 -07002296 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002297 }
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002298 if (adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002299 /* send peer status indication to oem app */
Will Huang496b36c2017-07-11 16:38:50 +08002300 hdd_send_peer_status_ind_to_app(
2301 &event->staMac,
2302 ePeerConnected,
2303 event->timingMeasCap,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002304 adapter->vdev_id,
Will Huang496b36c2017-07-11 16:38:50 +08002305 &event->chan_info,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002306 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002307 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302308
Jeff Johnson8bb61112018-03-31 13:33:54 -07002309 hdd_green_ap_add_sta(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310 break;
2311
2312 case eSAP_STA_DISASSOC_EVENT:
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05302313 disassoc_comp =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002314 &sap_event->sapevt.sapStationDisassocCompleteEvent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002315 memcpy(wrqu.addr.sa_data,
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05302316 &disassoc_comp->staMac, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002317
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05302318 cache_stainfo = hdd_get_stainfo(adapter->cache_sta_info,
2319 disassoc_comp->staMac);
2320 if (cache_stainfo) {
2321 /* Cache the disassoc info */
2322 cache_stainfo->rssi = disassoc_comp->rssi;
2323 cache_stainfo->tx_rate = disassoc_comp->tx_rate;
2324 cache_stainfo->rx_rate = disassoc_comp->rx_rate;
2325 cache_stainfo->reason_code = disassoc_comp->reason_code;
2326 cache_stainfo->disassoc_ts = qdf_system_ticks();
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +05302327 }
Pragaspathi Thilagaraj961a8b82018-05-03 14:16:44 +05302328 hdd_info(" disassociated " MAC_ADDRESS_STR,
2329 MAC_ADDR_ARRAY(wrqu.addr.sa_data));
2330
Jeff Johnson5c19ade2017-10-04 09:52:12 -07002331 qdf_status = qdf_event_set(&hostapd_state->qdf_sta_disassoc_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05302332 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Srinivas Girigowda55756882017-03-06 16:45:27 -08002333 hdd_err("Station Deauth event Set failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002334
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002335 if (sap_event->sapevt.sapStationDisassocCompleteEvent.reason ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002336 eSAP_USR_INITATED_DISASSOC)
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002337 hdd_debug(" User initiated disassociation");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002338 else
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002339 hdd_debug(" MAC initiated disassociation");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002340 we_event = IWEVEXPIRED;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302341 qdf_status =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002342 hdd_softap_get_sta_id(adapter,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002343 &sap_event->sapevt.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002344 sapStationDisassocCompleteEvent.staMac,
Jeff Johnson0a082d92019-03-04 12:25:49 -08002345 &sta_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302346 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07002347 hdd_err("Failed to find sta id status: %d", qdf_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302348 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002349 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002350
Nirav Shah1da77682016-05-03 20:16:39 +05302351 DPTRACE(qdf_dp_trace_mgmt_pkt(QDF_DP_TRACE_MGMT_PACKET_RECORD,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002352 adapter->vdev_id,
Venkata Sharath Chandra Manchala0b9fc632017-05-15 14:35:15 -07002353 QDF_TRACE_DEFAULT_PDEV_ID,
Nirav Shah1da77682016-05-03 20:16:39 +05302354 QDF_PROTO_TYPE_MGMT, QDF_PROTO_MGMT_DISASSOC));
2355
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05302356 stainfo = hdd_get_stainfo(adapter->sta_info,
2357 disassoc_comp->staMac);
2358 if (stainfo) {
2359 /* Send DHCP STOP indication to FW */
2360 stainfo->dhcp_phase = DHCP_PHASE_ACK;
2361 if (stainfo->dhcp_nego_status ==
2362 DHCP_NEGO_IN_PROGRESS)
Jeff Johnson0a082d92019-03-04 12:25:49 -08002363 hdd_post_dhcp_ind(adapter, sta_id,
Ashish Kumar Dhanotiya2ef47902018-10-12 21:13:57 +05302364 WMA_DHCP_STOP_IND);
2365 stainfo->dhcp_nego_status = DHCP_NEGO_STOP;
2366 }
Jeff Johnson0a082d92019-03-04 12:25:49 -08002367 hdd_softap_deregister_sta(adapter, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002368
Jeff Johnson136c51b2017-10-27 20:02:41 -07002369 ap_ctx->ap_active = false;
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07002370 spin_lock_bh(&adapter->sta_info_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002371 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07002372 if (adapter->sta_info[i].in_use
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002373 && i !=
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002374 (WLAN_HDD_GET_AP_CTX_PTR(adapter))->
Jeff Johnson42518cf2017-10-26 13:33:29 -07002375 broadcast_sta_id) {
Jeff Johnson136c51b2017-10-27 20:02:41 -07002376 ap_ctx->ap_active = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002377 break;
2378 }
2379 }
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07002380 spin_unlock_bh(&adapter->sta_info_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002381
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002382#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Jeff Johnson23c3b842017-09-03 09:05:29 -07002383 wlan_hdd_auto_shutdown_enable(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002384#endif
2385
Jeff Johnson23c3b842017-09-03 09:05:29 -07002386 cds_host_diag_log_work(&hdd_ctx->sap_wake_lock,
Rajeev Kumarf98a5cc2017-07-28 08:42:46 -07002387 HDD_SAP_WAKE_LOCK_DURATION,
2388 WIFI_POWER_EVENT_WAKELOCK_SAP);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002389 qdf_wake_lock_timeout_acquire(&hdd_ctx->sap_wake_lock,
Rajeev Kumarf98a5cc2017-07-28 08:42:46 -07002390 HDD_SAP_CLIENT_DISCONNECT_WAKE_LOCK_DURATION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002391 cfg80211_del_sta(dev,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002392 (const u8 *)&sap_event->sapevt.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002393 sapStationDisassocCompleteEvent.staMac.
2394 bytes[0], GFP_KERNEL);
2395
2396 /* Update the beacon Interval if it is P2P GO */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08002397 qdf_status = policy_mgr_change_mcc_go_beacon_interval(
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002398 hdd_ctx->psoc, adapter->vdev_id,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002399 adapter->device_mode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302400 if (QDF_STATUS_SUCCESS != qdf_status) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08002401 hdd_err("Failed to update Beacon interval status: %d",
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302402 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002403 }
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002404 if (adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002405 /* send peer status indication to oem app */
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002406 hdd_send_peer_status_ind_to_app(&sap_event->sapevt.
Abhishek Singh1c676222016-05-09 14:20:28 +05302407 sapStationDisassocCompleteEvent.
2408 staMac, ePeerDisconnected,
2409 0,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002410 adapter->vdev_id,
Abhishek Singh1c676222016-05-09 14:20:28 +05302411 NULL,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002412 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002413 }
2414#ifdef MSM_PLATFORM
2415 /*stop timer in sap/p2p_go */
Jeff Johnson136c51b2017-10-27 20:02:41 -07002416 if (ap_ctx->ap_active == false) {
Jeff Johnson23c3b842017-09-03 09:05:29 -07002417 spin_lock_bh(&hdd_ctx->bus_bw_lock);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002418 adapter->prev_tx_packets = 0;
2419 adapter->prev_rx_packets = 0;
2420 adapter->prev_fwd_tx_packets = 0;
2421 adapter->prev_fwd_rx_packets = 0;
Jeff Johnson23c3b842017-09-03 09:05:29 -07002422 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
2423 hdd_bus_bw_compute_timer_try_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002424 }
2425#endif
Jeff Johnson8bb61112018-03-31 13:33:54 -07002426 hdd_green_ap_del_sta(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002427 break;
2428
2429 case eSAP_WPS_PBC_PROBE_REQ_EVENT:
Jeff Johnsonc98d41d2017-10-27 21:41:53 -07002430 hdd_debug("WPS PBC probe req");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302431 return QDF_STATUS_SUCCESS;
Jeff Johnsonc98d41d2017-10-27 21:41:53 -07002432
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002433 case eSAP_UNKNOWN_STA_JOIN:
2434 snprintf(unknownSTAEvent, IW_CUSTOM_MAX,
2435 "JOIN_UNKNOWN_STA-%02x:%02x:%02x:%02x:%02x:%02x",
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002436 sap_event->sapevt.sapUnknownSTAJoin.macaddr.bytes[0],
2437 sap_event->sapevt.sapUnknownSTAJoin.macaddr.bytes[1],
2438 sap_event->sapevt.sapUnknownSTAJoin.macaddr.bytes[2],
2439 sap_event->sapevt.sapUnknownSTAJoin.macaddr.bytes[3],
2440 sap_event->sapevt.sapUnknownSTAJoin.macaddr.bytes[4],
2441 sap_event->sapevt.sapUnknownSTAJoin.macaddr.bytes[5]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002442 we_event = IWEVCUSTOM; /* Discovered a new node (AP mode). */
2443 wrqu.data.pointer = unknownSTAEvent;
2444 wrqu.data.length = strlen(unknownSTAEvent);
2445 we_custom_event_generic = (uint8_t *) unknownSTAEvent;
Jeff Johnsoncfb85832016-06-30 13:46:10 -07002446 hdd_err("%s", unknownSTAEvent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002447 break;
2448
2449 case eSAP_MAX_ASSOC_EXCEEDED:
2450 snprintf(maxAssocExceededEvent, IW_CUSTOM_MAX,
2451 "Peer %02x:%02x:%02x:%02x:%02x:%02x denied"
2452 " assoc due to Maximum Mobile Hotspot connections reached. Please disconnect"
2453 " one or more devices to enable the new device connection",
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002454 sap_event->sapevt.sapMaxAssocExceeded.macaddr.bytes[0],
2455 sap_event->sapevt.sapMaxAssocExceeded.macaddr.bytes[1],
2456 sap_event->sapevt.sapMaxAssocExceeded.macaddr.bytes[2],
2457 sap_event->sapevt.sapMaxAssocExceeded.macaddr.bytes[3],
2458 sap_event->sapevt.sapMaxAssocExceeded.macaddr.bytes[4],
2459 sap_event->sapevt.sapMaxAssocExceeded.macaddr.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002460 bytes[5]);
2461 we_event = IWEVCUSTOM; /* Discovered a new node (AP mode). */
2462 wrqu.data.pointer = maxAssocExceededEvent;
2463 wrqu.data.length = strlen(maxAssocExceededEvent);
2464 we_custom_event_generic = (uint8_t *) maxAssocExceededEvent;
Srinivas Girigowda55756882017-03-06 16:45:27 -08002465 hdd_debug("%s", maxAssocExceededEvent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002466 break;
2467 case eSAP_STA_ASSOC_IND:
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002468 if (sap_event->sapevt.sapAssocIndication.owe_ie) {
Min Liue34708a2019-02-01 15:00:34 +08002469 hdd_send_update_owe_info_event(adapter,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002470 sap_event->sapevt.sapAssocIndication.staMac.bytes,
2471 sap_event->sapevt.sapAssocIndication.owe_ie,
2472 sap_event->sapevt.sapAssocIndication.owe_ie_len);
Min Liue34708a2019-02-01 15:00:34 +08002473 qdf_mem_free(
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002474 sap_event->sapevt.sapAssocIndication.owe_ie);
2475 sap_event->sapevt.sapAssocIndication.owe_ie = NULL;
2476 sap_event->sapevt.sapAssocIndication.owe_ie_len = 0;
Min Liue34708a2019-02-01 15:00:34 +08002477 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302478 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002479
2480 case eSAP_DISCONNECT_ALL_P2P_CLIENT:
Jeff Johnsonb55bf512017-10-26 13:38:18 -07002481 hdd_clear_all_sta(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302482 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002483
2484 case eSAP_MAC_TRIG_STOP_BSS_EVENT:
Jeff Johnson0604a362018-03-24 17:36:59 -07002485 ret = hdd_stop_bss_link(adapter);
2486 if (ret)
2487 hdd_warn("hdd_stop_bss_link failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302488 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002489
2490 case eSAP_CHANNEL_CHANGE_EVENT:
Srinivas Girigowda55756882017-03-06 16:45:27 -08002491 hdd_debug("Received eSAP_CHANNEL_CHANGE_EVENT event");
Jeff Johnson0f9f87b2017-10-28 09:21:06 -07002492 if (hostapd_state->bss_state != BSS_STOP) {
Liangwei Dong5047d512016-10-11 00:24:26 -04002493 /* Prevent suspend for new channel */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002494 hdd_hostapd_channel_prevent_suspend(adapter,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002495 sap_event->sapevt.sap_ch_selected.pri_ch);
Liangwei Dong5047d512016-10-11 00:24:26 -04002496 /* Allow suspend for old channel */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002497 hdd_hostapd_channel_allow_suspend(adapter,
Jeff Johnson01206862017-10-27 20:55:59 -07002498 ap_ctx->operating_channel);
Liangwei Dong5047d512016-10-11 00:24:26 -04002499 }
Jeff Johnsond3919a92017-01-12 09:47:22 -08002500 /* SME/PE is already updated for new operation
2501 * channel. So update HDD layer also here. This
2502 * resolves issue in AP-AP mode where AP1 channel is
2503 * changed due to RADAR then CAC is going on and
2504 * START_BSS on new channel has not come to HDD. At
2505 * this case if AP2 is started it needs current
2506 * operation channel for MCC DFS restriction
2507 */
Jeff Johnson01206862017-10-27 20:55:59 -07002508 ap_ctx->operating_channel =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002509 sap_event->sapevt.sap_ch_selected.pri_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002510 ap_ctx->sap_config.acs_cfg.pri_ch =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002511 sap_event->sapevt.sap_ch_selected.pri_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002512 ap_ctx->sap_config.acs_cfg.ht_sec_ch =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002513 sap_event->sapevt.sap_ch_selected.ht_sec_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002514 ap_ctx->sap_config.acs_cfg.vht_seg0_center_ch =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002515 sap_event->sapevt.sap_ch_selected.vht_seg0_center_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002516 ap_ctx->sap_config.acs_cfg.vht_seg1_center_ch =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002517 sap_event->sapevt.sap_ch_selected.vht_seg1_center_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002518 ap_ctx->sap_config.acs_cfg.ch_width =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002519 sap_event->sapevt.sap_ch_selected.ch_width;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002520
bings61d5bec2017-06-27 14:13:40 +08002521 sap_ch_param.ch_width =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002522 sap_event->sapevt.sap_ch_selected.ch_width;
bings61d5bec2017-06-27 14:13:40 +08002523 sap_ch_param.center_freq_seg0 =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002524 sap_event->sapevt.sap_ch_selected.vht_seg0_center_ch;
bings61d5bec2017-06-27 14:13:40 +08002525 sap_ch_param.center_freq_seg1 =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002526 sap_event->sapevt.sap_ch_selected.vht_seg1_center_ch;
Dustin Brown07901ec2018-09-07 11:02:41 -07002527 wlan_reg_set_channel_params(hdd_ctx->pdev,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002528 sap_event->sapevt.sap_ch_selected.pri_ch,
2529 sap_event->sapevt.sap_ch_selected.ht_sec_ch,
bings61d5bec2017-06-27 14:13:40 +08002530 &sap_ch_param);
Manishekar Chandrasekaranec267592016-05-26 19:10:04 +05302531
Ajit Pal Singhd6c08f22018-04-25 16:55:26 +05302532 cdp_hl_fc_set_td_limit(cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002533 adapter->vdev_id,
Ajit Pal Singhd6c08f22018-04-25 16:55:26 +05302534 ap_ctx->operating_channel);
2535
bings58ce8622017-07-10 15:55:36 +08002536 phy_mode = wlan_sap_get_phymode(
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002537 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
bings58ce8622017-07-10 15:55:36 +08002538
2539 switch (phy_mode) {
2540 case eCSR_DOT11_MODE_11n:
2541 case eCSR_DOT11_MODE_11n_ONLY:
2542 case eCSR_DOT11_MODE_11ac:
2543 case eCSR_DOT11_MODE_11ac_ONLY:
2544 legacy_phymode = false;
2545 break;
2546 default:
2547 legacy_phymode = true;
2548 break;
2549 }
2550
Jeff Johnson68755312017-02-10 11:46:55 -08002551 chan_change.chan =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002552 sap_event->sapevt.sap_ch_selected.pri_ch;
Jeff Johnson68755312017-02-10 11:46:55 -08002553 chan_change.chan_params.ch_width =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002554 sap_event->sapevt.sap_ch_selected.ch_width;
Jeff Johnson68755312017-02-10 11:46:55 -08002555 chan_change.chan_params.sec_ch_offset =
bings61d5bec2017-06-27 14:13:40 +08002556 sap_ch_param.sec_ch_offset;
Jeff Johnson68755312017-02-10 11:46:55 -08002557 chan_change.chan_params.center_freq_seg0 =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002558 sap_event->sapevt.sap_ch_selected.vht_seg0_center_ch;
Jeff Johnson68755312017-02-10 11:46:55 -08002559 chan_change.chan_params.center_freq_seg1 =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002560 sap_event->sapevt.sap_ch_selected.vht_seg1_center_ch;
Jeff Johnson68755312017-02-10 11:46:55 -08002561
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002562 return hdd_chan_change_notify(adapter, dev,
bings58ce8622017-07-10 15:55:36 +08002563 chan_change, legacy_phymode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002564 case eSAP_ACS_SCAN_SUCCESS_EVENT:
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002565 return hdd_handle_acs_scan_event(sap_event, adapter);
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07002566
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002567 case eSAP_ACS_CHANNEL_SELECTED:
Srinivas Girigowda55756882017-03-06 16:45:27 -08002568 hdd_debug("ACS Completed for wlan%d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002569 adapter->dev->ifindex);
2570 clear_bit(ACS_PENDING, &adapter->event_flags);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002571 clear_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags);
Jeff Johnson91df29d2017-10-27 19:29:50 -07002572 ap_ctx->sap_config.acs_cfg.pri_ch =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002573 sap_event->sapevt.sap_ch_selected.pri_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002574 ap_ctx->sap_config.acs_cfg.ht_sec_ch =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002575 sap_event->sapevt.sap_ch_selected.ht_sec_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002576 ap_ctx->sap_config.acs_cfg.vht_seg0_center_ch =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002577 sap_event->sapevt.sap_ch_selected.vht_seg0_center_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002578 ap_ctx->sap_config.acs_cfg.vht_seg1_center_ch =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002579 sap_event->sapevt.sap_ch_selected.vht_seg1_center_ch;
Jeff Johnson91df29d2017-10-27 19:29:50 -07002580 ap_ctx->sap_config.acs_cfg.ch_width =
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002581 sap_event->sapevt.sap_ch_selected.ch_width;
Himanshu Agarwalad4c0392018-05-08 16:53:36 +05302582 wlan_hdd_cfg80211_acs_ch_select_evt(adapter);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05302583 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302584 return QDF_STATUS_SUCCESS;
Abhishek Singh1bdb1572015-10-16 16:24:19 +05302585 case eSAP_ECSA_CHANGE_CHAN_IND:
Srinivas Girigowda55756882017-03-06 16:45:27 -08002586 hdd_debug("Channel change indication from peer for channel %d",
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002587 sap_event->sapevt.sap_chan_cng_ind.new_chan);
Abhishek Singh1bdb1572015-10-16 16:24:19 +05302588 if (hdd_softap_set_channel_change(dev,
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002589 sap_event->sapevt.sap_chan_cng_ind.new_chan,
Min Liu2fef5792018-01-19 17:59:42 +08002590 CH_WIDTH_MAX, false))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302591 return QDF_STATUS_E_FAILURE;
Abhishek Singh1bdb1572015-10-16 16:24:19 +05302592 else
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302593 return QDF_STATUS_SUCCESS;
Abhishek Singh1bdb1572015-10-16 16:24:19 +05302594
Kapil Gupta8878ad92017-02-13 11:56:04 +05302595 case eSAP_DFS_NEXT_CHANNEL_REQ:
Dustin Brown5e89ef82018-03-14 11:50:23 -07002596 hdd_debug("Sending next channel query to userspace");
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002597 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05302598 QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS);
2599 return QDF_STATUS_SUCCESS;
2600
Krunal Soni22208392017-09-29 18:10:34 -07002601 case eSAP_STOP_BSS_DUE_TO_NO_CHNL:
2602 hdd_debug("Stop sap session[%d]",
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002603 adapter->vdev_id);
Krunal Soni22208392017-09-29 18:10:34 -07002604 INIT_WORK(&adapter->sap_stop_bss_work,
2605 hdd_stop_sap_due_to_invalid_channel);
2606 schedule_work(&adapter->sap_stop_bss_work);
2607 return QDF_STATUS_SUCCESS;
2608
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302609 case eSAP_CHANNEL_CHANGE_RESP:
2610 hdd_debug("Channel change rsp status = %d",
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002611 sap_event->sapevt.ch_change_rsp_status);
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302612 /*
2613 * Set the ch_switch_in_progress flag to zero and also enable
2614 * roaming once channel change process (success/failure)
2615 * is completed
2616 */
2617 qdf_atomic_set(&adapter->ch_switch_in_progress, 0);
Abhishek Singh3bbf6cb2019-03-28 14:05:43 +05302618 policy_mgr_set_chan_switch_complete_evt(hdd_ctx->psoc);
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302619 wlan_hdd_enable_roaming(adapter);
2620 return QDF_STATUS_SUCCESS;
2621
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002622 default:
Srinivas Girigowda55756882017-03-06 16:45:27 -08002623 hdd_debug("SAP message is not handled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002624 goto stopbss;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302625 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002626 }
2627 wireless_send_event(dev, we_event, &wrqu,
2628 (char *)we_custom_event_generic);
Manjeet Singhd295b1d2016-07-28 15:57:38 +05302629
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302630 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002631
2632stopbss:
2633 {
2634 uint8_t we_custom_event[64];
2635 char *stopBssEvent = "STOP-BSS.response"; /* 17 */
2636 int event_len = strlen(stopBssEvent);
2637
Srinivas Girigowda55756882017-03-06 16:45:27 -08002638 hdd_debug("BSS stop status = %s",
Jeff Johnson1cf299e2019-03-07 22:22:30 -08002639 sap_event->sapevt.sapStopBssCompleteEvent.status ?
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002640 "eSAP_STATUS_FAILURE" : "eSAP_STATUS_SUCCESS");
2641
Jeff Johnsond3919a92017-01-12 09:47:22 -08002642 /* Change the BSS state now since, as we are shutting
2643 * things down, we don't want interfaces to become
2644 * re-enabled
2645 */
Jeff Johnson0f9f87b2017-10-28 09:21:06 -07002646 hostapd_state->bss_state = BSS_STOP;
Subrat Dash5f36fbe2019-02-12 16:28:14 +05302647 hdd_stop_tsf_sync(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002649#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Jeff Johnson23c3b842017-09-03 09:05:29 -07002650 wlan_hdd_auto_shutdown_enable(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002651#endif
2652
2653 /* Stop the pkts from n/w stack as we are going to free all of
Jeff Johnsond3919a92017-01-12 09:47:22 -08002654 * the TX WMM queues for all STAID's
2655 */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002656 hdd_debug("Disabling queues");
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002657 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302658 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2659 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002660
2661 /* reclaim all resources allocated to the BSS */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002662 qdf_status = hdd_softap_stop_bss(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302663 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsoncfb85832016-06-30 13:46:10 -07002664 hdd_warn("hdd_softap_stop_bss failed %d",
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302665 qdf_status);
Sravan Kumar Kairamce792eb2018-06-15 15:07:11 +05302666 if (ucfg_ipa_is_enabled()) {
Dustin Brown07901ec2018-09-07 11:02:41 -07002667 ucfg_ipa_uc_disconnect_ap(hdd_ctx->pdev,
Sravan Kumar Kairamce792eb2018-06-15 15:07:11 +05302668 adapter->dev);
Dustin Brown07901ec2018-09-07 11:02:41 -07002669 ucfg_ipa_cleanup_dev_iface(hdd_ctx->pdev,
Sravan Kumar Kairamce792eb2018-06-15 15:07:11 +05302670 adapter->dev);
2671 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002672 }
2673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002674 /* notify userspace that the BSS has stopped */
2675 memset(&we_custom_event, '\0', sizeof(we_custom_event));
2676 memcpy(&we_custom_event, stopBssEvent, event_len);
2677 memset(&wrqu, 0, sizeof(wrqu));
2678 wrqu.data.length = event_len;
2679 we_event = IWEVCUSTOM;
2680 we_custom_event_generic = we_custom_event;
2681 wireless_send_event(dev, we_event, &wrqu,
2682 (char *)we_custom_event_generic);
Nitesh Shahf5765be2017-02-22 20:36:59 +05302683
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002684 /* once the event is set, structure dev/adapter should
Nitesh Shahf5765be2017-02-22 20:36:59 +05302685 * not be touched since they are now subject to being deleted
2686 * by another thread
2687 */
Jeff Johnsonfe31cf52019-03-09 19:46:01 -08002688 if (eSAP_STOP_BSS_EVENT == event_id) {
Jeff Johnson5c19ade2017-10-04 09:52:12 -07002689 qdf_event_set(&hostapd_state->qdf_stop_bss_event);
Alok Kumar5011ee62018-09-26 14:16:38 +05302690 hdd_bus_bw_compute_timer_try_stop(hdd_ctx);
2691 }
Nitesh Shahf5765be2017-02-22 20:36:59 +05302692
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002693 hdd_ipa_set_tx_flow_info();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002694 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302695 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002696}
2697
Jeff Johnson89a0c742018-06-12 18:17:46 -07002698static int hdd_softap_unpack_ie(mac_handle_t mac_handle,
Jeff Johnsona376a032019-03-09 22:39:27 -08002699 eCsrEncryptionType *encrypt_type,
Jeff Johnsoncdde6c32019-03-09 23:03:49 -08002700 eCsrEncryptionType *mc_encrypt_type,
Min Liuddd23302018-12-05 16:17:48 +08002701 tCsrAuthList *akm_list,
Jeff Johnson17e89092019-03-09 23:22:19 -08002702 bool *mfp_capable,
Jeff Johnson10b4fbf2019-03-09 23:52:32 -08002703 bool *mfp_required,
Jeff Johnson89a0c742018-06-12 18:17:46 -07002704 uint16_t gen_ie_len, uint8_t *gen_ie)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705{
Naveen Rawat72475db2017-12-13 18:07:35 -08002706 uint32_t ret;
Jeff Johnsond062b8d2019-03-09 20:31:13 -08002707 uint8_t *rsn_ie;
Jeff Johnsonddd05cf2019-03-09 20:43:43 -08002708 uint16_t rsn_ie_len, i;
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002709 tDot11fIERSN dot11_rsn_ie = {0};
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002710 tDot11fIEWPA dot11_wpa_ie = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711
Jeff Johnsond36fa332019-03-18 13:42:25 -07002712 if (!mac_handle) {
Jeff Johnsonfb33cf52016-06-30 14:06:57 -07002713 hdd_err("Error haHandle returned NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002714 return -EINVAL;
2715 }
2716 /* Validity checks */
Anurag Chouhan6d760662016-02-20 16:05:43 +05302717 if ((gen_ie_len < QDF_MIN(DOT11F_IE_RSN_MIN_LEN, DOT11F_IE_WPA_MIN_LEN))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002718 || (gen_ie_len >
Anurag Chouhan6d760662016-02-20 16:05:43 +05302719 QDF_MAX(DOT11F_IE_RSN_MAX_LEN, DOT11F_IE_WPA_MAX_LEN)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002720 return -EINVAL;
2721 /* Type check */
2722 if (gen_ie[0] == DOT11F_EID_RSN) {
2723 /* Validity checks */
2724 if ((gen_ie_len < DOT11F_IE_RSN_MIN_LEN) ||
2725 (gen_ie_len > DOT11F_IE_RSN_MAX_LEN)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302726 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002727 }
2728 /* Skip past the EID byte and length byte */
Jeff Johnsond062b8d2019-03-09 20:31:13 -08002729 rsn_ie = gen_ie + 2;
Jeff Johnsonddd05cf2019-03-09 20:43:43 -08002730 rsn_ie_len = gen_ie_len - 2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002731 /* Unpack the RSN IE */
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002732 memset(&dot11_rsn_ie, 0, sizeof(tDot11fIERSN));
Jeff Johnsonddd05cf2019-03-09 20:43:43 -08002733 ret = sme_unpack_rsn_ie(mac_handle, rsn_ie, rsn_ie_len,
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002734 &dot11_rsn_ie, false);
Naveen Rawat72475db2017-12-13 18:07:35 -08002735 if (DOT11F_FAILED(ret)) {
2736 hdd_err("unpack failed, ret: 0x%x", ret);
2737 return -EINVAL;
2738 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002739 /* Copy out the encryption and authentication types */
Srinivas Girigowda55756882017-03-06 16:45:27 -08002740 hdd_debug("pairwise cipher suite count: %d",
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002741 dot11_rsn_ie.pwise_cipher_suite_count);
Srinivas Girigowda55756882017-03-06 16:45:27 -08002742 hdd_debug("authentication suite count: %d",
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002743 dot11_rsn_ie.akm_suite_cnt);
Jeff Johnsond3919a92017-01-12 09:47:22 -08002744 /*
Min Liuddd23302018-12-05 16:17:48 +08002745 * Translate akms in akm suite
Jeff Johnsond3919a92017-01-12 09:47:22 -08002746 */
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002747 for (i = 0; i < dot11_rsn_ie.akm_suite_cnt; i++)
Min Liuddd23302018-12-05 16:17:48 +08002748 akm_list->authType[i] =
2749 hdd_translate_rsn_to_csr_auth_type(
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002750 dot11_rsn_ie.akm_suite[i]);
2751 akm_list->numEntries = dot11_rsn_ie.akm_suite_cnt;
2752 /* dot11_rsn_ie.pwise_cipher_suite_count */
Jeff Johnsona376a032019-03-09 22:39:27 -08002753 *encrypt_type =
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002754 hdd_translate_rsn_to_csr_encryption_type(dot11_rsn_ie.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002755 pwise_cipher_suites[0]);
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002756 /* dot11_rsn_ie.gp_cipher_suite_count */
Jeff Johnsoncdde6c32019-03-09 23:03:49 -08002757 *mc_encrypt_type =
Jeff Johnsonb94e6492019-03-09 22:24:42 -08002758 hdd_translate_rsn_to_csr_encryption_type(dot11_rsn_ie.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002759 gp_cipher_suite);
2760 /* Set the PMKSA ID Cache for this interface */
Jeff Johnson17e89092019-03-09 23:22:19 -08002761 *mfp_capable = 0 != (dot11_rsn_ie.RSN_Cap[0] & 0x80);
Jeff Johnson10b4fbf2019-03-09 23:52:32 -08002762 *mfp_required = 0 != (dot11_rsn_ie.RSN_Cap[0] & 0x40);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002763 } else if (gen_ie[0] == DOT11F_EID_WPA) {
2764 /* Validity checks */
2765 if ((gen_ie_len < DOT11F_IE_WPA_MIN_LEN) ||
2766 (gen_ie_len > DOT11F_IE_WPA_MAX_LEN)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302767 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002768 }
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07002769 /* Skip past the EID byte and length byte and 4 byte WiFi OUI */
Jeff Johnsond062b8d2019-03-09 20:31:13 -08002770 rsn_ie = gen_ie + 2 + 4;
Jeff Johnsonddd05cf2019-03-09 20:43:43 -08002771 rsn_ie_len = gen_ie_len - (2 + 4);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002772 /* Unpack the WPA IE */
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002773 memset(&dot11_wpa_ie, 0, sizeof(tDot11fIEWPA));
Jeff Johnson034f3c92018-11-09 10:46:21 -08002774 ret = dot11f_unpack_ie_wpa(MAC_CONTEXT(mac_handle),
Jeff Johnsonddd05cf2019-03-09 20:43:43 -08002775 rsn_ie, rsn_ie_len,
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002776 &dot11_wpa_ie, false);
Naveen Rawat72475db2017-12-13 18:07:35 -08002777 if (DOT11F_FAILED(ret)) {
2778 hdd_err("unpack failed, ret: 0x%x", ret);
2779 return -EINVAL;
2780 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002781 /* Copy out the encryption and authentication types */
Srinivas Girigowda55756882017-03-06 16:45:27 -08002782 hdd_debug("WPA unicast cipher suite count: %d",
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002783 dot11_wpa_ie.unicast_cipher_count);
Srinivas Girigowda55756882017-03-06 16:45:27 -08002784 hdd_debug("WPA authentication suite count: %d",
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002785 dot11_wpa_ie.auth_suite_count);
2786 /* dot11_wpa_ie.auth_suite_count */
Min Liuddd23302018-12-05 16:17:48 +08002787 /*
2788 * Translate akms in akm suite
2789 */
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002790 for (i = 0; i < dot11_wpa_ie.auth_suite_count; i++)
Min Liuddd23302018-12-05 16:17:48 +08002791 akm_list->authType[i] =
2792 hdd_translate_wpa_to_csr_auth_type(
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002793 dot11_wpa_ie.auth_suites[i]);
2794 akm_list->numEntries = dot11_wpa_ie.auth_suite_count;
2795 /* dot11_wpa_ie.unicast_cipher_count */
Jeff Johnsona376a032019-03-09 22:39:27 -08002796 *encrypt_type =
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002797 hdd_translate_wpa_to_csr_encryption_type(dot11_wpa_ie.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002798 unicast_ciphers[0]);
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002799 /* dot11_wpa_ie.unicast_cipher_count */
Jeff Johnsoncdde6c32019-03-09 23:03:49 -08002800 *mc_encrypt_type =
Jeff Johnson6a2c0ca2019-03-09 22:08:45 -08002801 hdd_translate_wpa_to_csr_encryption_type(dot11_wpa_ie.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002802 multicast_cipher);
Jeff Johnson17e89092019-03-09 23:22:19 -08002803 *mfp_capable = false;
Jeff Johnson10b4fbf2019-03-09 23:52:32 -08002804 *mfp_required = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002805 } else {
Srinivas Girigowda55756882017-03-06 16:45:27 -08002806 hdd_err("gen_ie[0]: %d", gen_ie[0]);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302807 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002808 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302809 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002810}
2811
2812/**
Abhishek Singh5b454912019-01-28 22:54:00 +05302813 * hdd_is_any_sta_connecting() - check if any sta is connecting
2814 * @hdd_ctx: hdd context
2815 *
2816 * Return: true if any sta is connecting
2817 */
2818static bool hdd_is_any_sta_connecting(struct hdd_context *hdd_ctx)
2819{
2820 struct hdd_adapter *adapter = NULL;
2821 struct hdd_station_ctx *sta_ctx;
2822
2823 if (!hdd_ctx) {
2824 hdd_err("HDD context is NULL");
2825 return false;
2826 }
2827
2828 hdd_for_each_adapter(hdd_ctx, adapter) {
2829 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2830 if ((adapter->device_mode == QDF_STA_MODE) ||
2831 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
2832 (adapter->device_mode == QDF_P2P_DEVICE_MODE)) {
Jeff Johnsone7951512019-02-27 10:02:51 -08002833 if (sta_ctx->conn_info.conn_state ==
Abhishek Singh5b454912019-01-28 22:54:00 +05302834 eConnectionState_Connecting) {
2835 hdd_debug("vdev_id %d: connecting",
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002836 adapter->vdev_id);
Abhishek Singh5b454912019-01-28 22:54:00 +05302837 return true;
2838 }
2839 }
2840 }
2841
2842 return false;
2843}
2844
2845/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002846 * hdd_softap_set_channel_change() -
2847 * This function to support SAP channel change with CSA IE
2848 * set in the beacons.
2849 *
2850 * @dev: pointer to the net device.
2851 * @target_channel: target channel number.
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +05302852 * @target_bw: Target bandwidth to move.
2853 * If no bandwidth is specified, the value is CH_WIDTH_MAX
Min Liu2fef5792018-01-19 17:59:42 +08002854 * @forced: Force to switch channel, ignore SCC/MCC check
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855 *
2856 * Return: 0 for success, non zero for failure
2857 */
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +05302858int hdd_softap_set_channel_change(struct net_device *dev, int target_channel,
Min Liu2fef5792018-01-19 17:59:42 +08002859 enum phy_ch_width target_bw, bool forced)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002860{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302861 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002862 int ret = 0;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002863 struct hdd_adapter *adapter = (netdev_priv(dev));
Jeff Johnson23c3b842017-09-03 09:05:29 -07002864 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson866aca82017-09-10 15:27:20 -07002865 struct hdd_adapter *sta_adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002866 struct hdd_station_ctx *sta_ctx;
Krunal Sonid7ef8632018-09-27 11:17:33 -07002867 uint8_t conc_rule1 = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -08002868 uint8_t scc_on_lte_coex = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002870 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson23c3b842017-09-03 09:05:29 -07002871 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302872 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002873 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002874
Abhishek Singhf8364e12019-01-14 14:44:05 +05302875 /*
2876 * If sta connection is in progress do not allow SAP channel change from
2877 * user space as it may change the HW mode requirement, for which sta is
2878 * trying to connect.
2879 */
Abhishek Singh5b454912019-01-28 22:54:00 +05302880 if (hdd_is_any_sta_connecting(hdd_ctx)) {
Abhishek Singhf8364e12019-01-14 14:44:05 +05302881 hdd_err("STA connection is in progress");
2882 return -EBUSY;
2883 }
2884
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002885 ret = hdd_validate_channel_and_bandwidth(adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +05302886 target_channel, target_bw);
2887 if (ret) {
2888 hdd_err("Invalid CH and BW combo");
2889 return ret;
2890 }
2891
Jeff Johnson23c3b842017-09-03 09:05:29 -07002892 sta_adapter = hdd_get_adapter(hdd_ctx, QDF_STA_MODE);
Krunal Sonid7ef8632018-09-27 11:17:33 -07002893 ucfg_policy_mgr_get_conc_rule1(hdd_ctx->psoc, &conc_rule1);
Edhar, Mahesh Kumardf2ec122015-11-16 11:33:16 +05302894 /*
2895 * conc_custom_rule1:
2896 * Force SCC for SAP + STA
2897 * if STA is already connected then we shouldn't allow
2898 * channel switch in SAP interface.
2899 */
Krunal Sonid7ef8632018-09-27 11:17:33 -07002900 if (sta_adapter && conc_rule1) {
Edhar, Mahesh Kumardf2ec122015-11-16 11:33:16 +05302901 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(sta_adapter);
2902 if (hdd_conn_is_connected(sta_ctx)) {
2903 hdd_err("Channel switch not allowed after STA connection with conc_custom_rule1 enabled");
2904 return -EBUSY;
2905 }
2906 }
2907
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002908 /*
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302909 * Set the ch_switch_in_progress flag to mimic channel change
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002910 * when a radar is found. This will enable synchronizing
2911 * SAP and HDD states similar to that of radar indication.
2912 * Suspend the netif queues to stop queuing Tx frames
2913 * from upper layers. netif queues will be resumed
2914 * once the channel change is completed and SAP will
2915 * post eSAP_START_BSS_EVENT success event to HDD.
2916 */
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302917 if (qdf_atomic_inc_return(&adapter->ch_switch_in_progress) > 1) {
Arif Hussain2a7c1f32016-07-18 14:24:36 -07002918 hdd_err("Channel switch in progress!!");
2919 return -EBUSY;
2920 }
2921
Jianmin Zhuc39613c2018-08-20 10:46:15 +08002922 /*
2923 * Do SAP concurrency check to cover channel switch case as following:
2924 * There is already existing SAP+GO combination but due to upper layer
2925 * notifying LTE-COEX event or sending command to move one connection
2926 * to different channel. Before moving existing connection to new
2927 * channel, check if new channel can co-exist with the other existing
2928 * connection. For example, SAP1 is on channel-6 and SAP2 is on
2929 * channel-36 and lets say they are doing DBS, and upper layer sends
2930 * LTE-COEX to move SAP1 from channel-6 to channel-149. SAP1 and
2931 * SAP2 will end up doing MCC which may not be desirable result. It
2932 * should will be prevented.
2933 */
2934 if (!policy_mgr_allow_concurrency_csa(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002935 hdd_ctx->psoc,
Jianmin Zhu54cfab32018-08-09 10:04:32 +08002936 policy_mgr_convert_device_mode_to_qdf_type(
2937 adapter->device_mode),
2938 target_channel,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08002939 adapter->vdev_id)) {
Jianmin Zhu54cfab32018-08-09 10:04:32 +08002940 hdd_err("Channel switch failed due to concurrency check failure");
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302941 qdf_atomic_set(&adapter->ch_switch_in_progress, 0);
Jianmin Zhu54cfab32018-08-09 10:04:32 +08002942 return -EINVAL;
2943 }
2944
Krunal Sonidf29bc42018-11-15 13:26:29 -08002945 status =
2946 ucfg_policy_mgr_get_sta_sap_scc_lte_coex_chnl(hdd_ctx->psoc,
2947 &scc_on_lte_coex);
2948 if (!QDF_IS_STATUS_SUCCESS(status)) {
2949 hdd_err("can't get STA-SAP SCC on lte coex channel setting");
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302950 qdf_atomic_set(&adapter->ch_switch_in_progress, 0);
Krunal Sonidf29bc42018-11-15 13:26:29 -08002951 return -EINVAL;
2952 }
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302953
2954 /*
2955 * Reject channel change req if reassoc in progress on any adapter.
2956 * sme_is_any_session_in_middle_of_roaming is for LFR2 and
2957 * hdd_is_roaming_in_progress is for LFR3
2958 */
2959 if (sme_is_any_session_in_middle_of_roaming(hdd_ctx->mac_handle) ||
2960 hdd_is_roaming_in_progress(hdd_ctx)) {
2961 hdd_info("Channel switch not allowed as reassoc in progress");
2962 qdf_atomic_set(&adapter->ch_switch_in_progress, 0);
2963 return -EINVAL;
2964 }
2965 /* Disable Roaming on all adapters before doing channel change */
2966 wlan_hdd_disable_roaming(adapter);
2967
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002968 /*
2969 * Post the Channel Change request to SAP.
2970 */
2971 status = wlansap_set_channel_change_with_csa(
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07002972 WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Dustin Brown5118e8e2016-09-13 15:54:23 -07002973 (uint32_t)target_channel,
Zhu Jianmin72d32de2018-05-11 10:54:10 +08002974 target_bw,
Krunal Sonidf29bc42018-11-15 13:26:29 -08002975 forced && !scc_on_lte_coex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002976
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302977 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08002978 hdd_err("SAP set channel failed for channel: %d, bw: %d",
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +05302979 target_channel, target_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002980 /*
2981 * If channel change command fails then clear the
2982 * radar found flag and also restart the netif
2983 * queues.
2984 */
Abhinav Kumar338e57d2019-02-04 17:30:10 +05302985 qdf_atomic_set(&adapter->ch_switch_in_progress, 0);
2986
2987 /*
2988 * If Posting of the Channel Change request fails
2989 * enable roaming on all adapters
2990 */
2991 wlan_hdd_enable_roaming(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992
2993 ret = -EINVAL;
2994 }
2995
2996 return ret;
2997}
2998
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05302999#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
3000/**
3001 * hdd_sap_restart_with_channel_switch() - SAP channel change with E/CSA
3002 * @ap_adapter: HDD adapter
3003 * @target_channel: Channel to which switch must happen
3004 * @target_bw: Bandwidth of the target channel
Min Liu2fef5792018-01-19 17:59:42 +08003005 * @forced: Force to switch channel, ignore SCC/MCC check
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05303006 *
3007 * Invokes the necessary API to perform channel switch for the SAP or GO
3008 *
3009 * Return: None
3010 */
Jeff Johnson866aca82017-09-10 15:27:20 -07003011void hdd_sap_restart_with_channel_switch(struct hdd_adapter *ap_adapter,
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05303012 uint32_t target_channel,
Min Liu2fef5792018-01-19 17:59:42 +08003013 uint32_t target_bw,
3014 bool forced)
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05303015{
3016 struct net_device *dev = ap_adapter->dev;
3017 int ret;
3018
Dustin Brown491d54b2018-03-14 12:39:11 -07003019 hdd_enter();
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05303020
3021 if (!dev) {
3022 hdd_err("Invalid dev pointer");
3023 return;
3024 }
3025
Min Liu2fef5792018-01-19 17:59:42 +08003026 ret = hdd_softap_set_channel_change(dev, target_channel,
3027 target_bw, forced);
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05303028 if (ret) {
3029 hdd_err("channel switch failed");
3030 return;
3031 }
3032}
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003033
Jeff Johnson23812942017-10-06 11:33:55 -07003034void hdd_sap_restart_chan_switch_cb(struct wlan_objmgr_psoc *psoc,
3035 uint8_t vdev_id, uint32_t channel,
Min Liu2fef5792018-01-19 17:59:42 +08003036 uint32_t channel_bw,
3037 bool forced)
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003038{
Jeff Johnson23812942017-10-06 11:33:55 -07003039 struct hdd_adapter *ap_adapter =
3040 wlan_hdd_get_adapter_from_vdev(psoc, vdev_id);
3041
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003042 if (!ap_adapter) {
3043 hdd_err("Adapter is NULL");
3044 return;
3045 }
3046 hdd_sap_restart_with_channel_switch(ap_adapter, channel,
Min Liu2fef5792018-01-19 17:59:42 +08003047 channel_bw, forced);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003048}
3049
3050QDF_STATUS wlan_hdd_get_channel_for_sap_restart(
3051 struct wlan_objmgr_psoc *psoc,
3052 uint8_t vdev_id, uint8_t *channel,
Ajit Pal Singh9b0ebdb2017-06-08 11:26:43 +05303053 uint8_t *sec_ch)
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003054{
Jeff Johnson89a0c742018-06-12 18:17:46 -07003055 mac_handle_t mac_handle;
Jeff Johnson87251032017-08-29 13:31:11 -07003056 struct hdd_ap_ctx *hdd_ap_ctx;
Tushnim Bhattacharyya2479ba32017-07-07 11:56:29 -07003057 uint8_t intf_ch = 0;
Jeff Johnsonc54bbf92017-08-28 11:59:35 -07003058 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003059 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson866aca82017-09-10 15:27:20 -07003060 struct hdd_adapter *sta_adapter;
Krunal Soni5e3f9622018-09-26 16:35:50 -07003061 uint8_t mcc_to_scc_switch = 0;
gaurank kathpalia379e05c2018-11-27 17:46:43 +05303062 struct ch_params ch_params;
Jeff Johnson866aca82017-09-10 15:27:20 -07003063 struct hdd_adapter *ap_adapter = wlan_hdd_get_adapter_from_vdev(
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003064 psoc, vdev_id);
3065 if (!ap_adapter) {
Tushnim Bhattacharyya2df9de72017-08-04 16:59:50 -07003066 hdd_err("ap_adapter is NULL");
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003067 return QDF_STATUS_E_FAILURE;
3068 }
3069
Tushnim Bhattacharyyaed678f92017-06-28 15:09:25 -07003070 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
3071 if (!hdd_ctx) {
3072 hdd_err("hdd_ctx is NULL");
3073 return QDF_STATUS_E_FAILURE;
3074 }
3075
3076 /* TODO: need work for 3 port case with sta+sta */
3077 sta_adapter = hdd_get_adapter(hdd_ctx, QDF_STA_MODE);
3078 if (!sta_adapter) {
Tushnim Bhattacharyya2df9de72017-08-04 16:59:50 -07003079 hdd_err("sta_adapter is NULL");
Tushnim Bhattacharyyaed678f92017-06-28 15:09:25 -07003080 return QDF_STATUS_E_FAILURE;
3081 }
3082
Jeff Johnsond36fa332019-03-18 13:42:25 -07003083 if (!channel || !sec_ch) {
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003084 hdd_err("Null parameters");
Tushnim Bhattacharyya2df9de72017-08-04 16:59:50 -07003085 return QDF_STATUS_E_FAILURE;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003086 }
3087
Tushnim Bhattacharyya2df9de72017-08-04 16:59:50 -07003088 if (!test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
3089 hdd_err("SOFTAP_BSS_STARTED not set");
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003090 return QDF_STATUS_E_FAILURE;
Tushnim Bhattacharyya2df9de72017-08-04 16:59:50 -07003091 }
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003092
3093 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Tushnim Bhattacharyyaed678f92017-06-28 15:09:25 -07003094 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(sta_adapter);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003095
Jeff Johnson89a0c742018-06-12 18:17:46 -07003096 mac_handle = hdd_ctx->mac_handle;
3097 if (!mac_handle) {
3098 hdd_err("mac_handle is NULL");
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003099 return QDF_STATUS_E_FAILURE;
Tushnim Bhattacharyya2df9de72017-08-04 16:59:50 -07003100 }
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003101
Bala Venkatesh9f958142018-06-27 12:36:08 +05303102 if (policy_mgr_get_connection_count(psoc) == 1) {
3103 /*
3104 * If STA+SAP sessions are on DFS channel and STA+SAP SCC is
3105 * enabled on DFS channel then move the SAP out of DFS channel
3106 * as soon as STA gets disconnect.
3107 */
3108 if (policy_mgr_is_sap_restart_required_after_sta_disconnect(
3109 psoc, &intf_ch)) {
3110 hdd_debug("Move the sap to user configured channel %u",
3111 intf_ch);
3112 goto sap_restart;
3113 }
3114 }
Krunal Soni5e3f9622018-09-26 16:35:50 -07003115 ucfg_policy_mgr_get_mcc_scc_switch(hdd_ctx->psoc,
3116 &mcc_to_scc_switch);
Tushnim Bhattacharyyaed678f92017-06-28 15:09:25 -07003117 /*
3118 * Check if STA's channel is DFS or passive or part of LTE avoided
3119 * channel list. In that case move SAP to other band if DBS is
3120 * supported, return from here if DBS is not supported.
3121 * Need to take care of 3 port cases with 2 STA iface in future.
3122 */
Jeff Johnson0bbe66f2017-10-27 19:23:49 -07003123 intf_ch = wlansap_check_cc_intf(hdd_ap_ctx->sap_context);
Tushnim Bhattacharyya2479ba32017-07-07 11:56:29 -07003124 hdd_info("intf_ch: %d", intf_ch);
Jayachandran Sreekumaran9575dec2017-10-11 14:23:23 +05303125 if (QDF_MCC_TO_SCC_SWITCH_FORCE_PREFERRED_WITHOUT_DISCONNECTION !=
Krunal Soni5e3f9622018-09-26 16:35:50 -07003126 mcc_to_scc_switch) {
Jayachandran Sreekumaran9575dec2017-10-11 14:23:23 +05303127 if (QDF_IS_STATUS_ERROR(
3128 policy_mgr_valid_sap_conc_channel_check(
Dustin Brown1dbefe62018-09-11 16:32:03 -07003129 hdd_ctx->psoc,
Jayachandran Sreekumaran9575dec2017-10-11 14:23:23 +05303130 &intf_ch,
3131 policy_mgr_mode_specific_get_channel(
Dustin Brown1dbefe62018-09-11 16:32:03 -07003132 hdd_ctx->psoc, PM_SAP_MODE)))) {
Jayachandran Sreekumaran9575dec2017-10-11 14:23:23 +05303133 hdd_debug("can't move sap to %d",
Jeff Johnson8626e932019-02-27 18:35:22 -08003134 hdd_sta_ctx->conn_info.channel);
Jayachandran Sreekumaran9575dec2017-10-11 14:23:23 +05303135 return QDF_STATUS_E_FAILURE;
3136 }
Tushnim Bhattacharyyaed678f92017-06-28 15:09:25 -07003137 }
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003138
Bala Venkatesh9f958142018-06-27 12:36:08 +05303139sap_restart:
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003140 if (intf_ch == 0) {
Tushnim Bhattacharyya2479ba32017-07-07 11:56:29 -07003141 hdd_debug("interface channel is 0");
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003142 return QDF_STATUS_E_FAILURE;
3143 }
3144
3145 hdd_info("SAP restart orig chan: %d, new chan: %d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07003146 hdd_ap_ctx->sap_config.channel, intf_ch);
gaurank kathpalia379e05c2018-11-27 17:46:43 +05303147 ch_params.ch_width = CH_WIDTH_MAX;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003148 hdd_ap_ctx->bss_stop_reason = BSS_STOP_DUE_TO_MCC_SCC_SWITCH;
3149
Dustin Brown07901ec2018-09-07 11:02:41 -07003150 wlan_reg_set_channel_params(hdd_ctx->pdev,
gaurank kathpalia379e05c2018-11-27 17:46:43 +05303151 intf_ch,
3152 0,
3153 &ch_params);
3154
3155 wlansap_get_sec_channel(ch_params.sec_ch_offset, intf_ch, sec_ch);
3156
3157 *channel = intf_ch;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003158
Ajit Pal Singh9b0ebdb2017-06-08 11:26:43 +05303159 hdd_info("SAP channel change with CSA/ECSA");
Jeff Johnson23812942017-10-06 11:33:55 -07003160 hdd_sap_restart_chan_switch_cb(psoc, vdev_id,
gaurank kathpalia379e05c2018-11-27 17:46:43 +05303161 intf_ch,
3162 ch_params.ch_width, false);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07003163
3164 return QDF_STATUS_SUCCESS;
3165}
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05303166#endif
3167
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303168#ifdef WLAN_FEATURE_TSF_PTP
3169static const struct ethtool_ops wlan_hostapd_ethtool_ops = {
3170 .get_ts_info = wlan_get_ts_info,
3171};
3172#endif
3173
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07003174const struct net_device_ops net_ops_struct = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175 .ndo_open = hdd_hostapd_open,
3176 .ndo_stop = hdd_hostapd_stop,
3177 .ndo_uninit = hdd_hostapd_uninit,
3178 .ndo_start_xmit = hdd_softap_hard_start_xmit,
3179 .ndo_tx_timeout = hdd_softap_tx_timeout,
3180 .ndo_get_stats = hdd_get_stats,
3181 .ndo_set_mac_address = hdd_hostapd_set_mac_address,
3182 .ndo_do_ioctl = hdd_ioctl,
3183 .ndo_change_mtu = hdd_hostapd_change_mtu,
Manjunathappa Prakash71140072019-01-31 09:40:23 -08003184 .ndo_select_queue = hdd_select_queue,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003185};
3186
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303187#ifdef WLAN_FEATURE_TSF_PTP
3188void hdd_set_ap_ops(struct net_device *dev)
3189{
3190 dev->netdev_ops = &net_ops_struct;
3191 dev->ethtool_ops = &wlan_hostapd_ethtool_ops;
3192}
3193#else
Jeff Johnson15712092017-10-28 12:02:53 -07003194void hdd_set_ap_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003195{
Jeff Johnson15712092017-10-28 12:02:53 -07003196 dev->netdev_ops = &net_ops_struct;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003197}
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303198#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199
Krunal Soni59437652017-11-21 13:42:14 -08003200bool hdd_sap_create_ctx(struct hdd_adapter *adapter)
3201{
3202 hdd_debug("creating sap context");
3203 adapter->session.ap.sap_context = sap_create_ctx();
3204 if (adapter->session.ap.sap_context)
3205 return true;
3206
3207 return false;
3208}
3209
3210bool hdd_sap_destroy_ctx(struct hdd_adapter *adapter)
3211{
3212 hdd_debug("destroying sap context");
3213 sap_destroy_ctx(adapter->session.ap.sap_context);
3214 adapter->session.ap.sap_context = NULL;
3215
3216 return true;
3217}
3218
Jingxiang Ge3de02752019-01-29 15:47:03 +08003219void hdd_sap_destroy_ctx_all(struct hdd_context *hdd_ctx, bool is_ssr)
3220{
3221 struct hdd_adapter *adapter;
3222
3223 /* sap_ctx is not destroyed as it will be leveraged for sap restart */
3224 if (is_ssr)
3225 return;
3226
3227 hdd_debug("destroying all the sap context");
3228
3229 hdd_for_each_adapter(hdd_ctx, adapter) {
3230 if (adapter->device_mode == QDF_SAP_MODE)
3231 hdd_sap_destroy_ctx(adapter);
3232 }
3233}
3234
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003235QDF_STATUS hdd_init_ap_mode(struct hdd_adapter *adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003236{
Jeff Johnsonca2530c2017-09-30 18:25:40 -07003237 struct hdd_hostapd_state *phostapdBuf;
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003238 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Soni4a020c72017-10-30 20:58:40 -07003239 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Jeff Johnsonbc376d82019-03-08 15:40:37 -08003240 struct sap_context *sap_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241 int ret;
Agrawal Ashish65634612016-08-18 13:24:32 +05303242 enum dfs_mode acs_dfs_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243
Dustin Brown491d54b2018-03-14 12:39:11 -07003244 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003245
Arun Khandavallicc544b32017-01-30 19:52:16 +05303246 hdd_info("SSR in progress: %d", reinit);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05303247 qdf_atomic_init(&adapter->session.ap.acs_in_progress);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248
Jeff Johnsonbc376d82019-03-08 15:40:37 -08003249 sap_context = hdd_hostapd_init_sap_session(adapter, reinit);
3250 if (!sap_context) {
Krunal Soni4a020c72017-10-30 20:58:40 -07003251 hdd_err("Invalid sap_ctx");
Krunal Sonib51eec72017-11-20 21:53:01 -08003252 goto error_release_vdev;
Krunal Soni4a020c72017-10-30 20:58:40 -07003253 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003254
Krunal Soni4a020c72017-10-30 20:58:40 -07003255 if (!reinit) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07003256 adapter->session.ap.sap_config.channel =
Jeff Johnson23c3b842017-09-03 09:05:29 -07003257 hdd_ctx->acs_policy.acs_channel;
3258 acs_dfs_mode = hdd_ctx->acs_policy.acs_dfs_mode;
Jeff Johnsonb9424862017-10-30 08:49:35 -07003259 adapter->session.ap.sap_config.acs_dfs_mode =
Arun Khandavallicc544b32017-01-30 19:52:16 +05303260 wlan_hdd_get_dfs_mode(acs_dfs_mode);
3261 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263 /* Allocate the Wireless Extensions state structure */
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003264 phostapdBuf = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265
Jeff Johnson89a0c742018-06-12 18:17:46 -07003266 sme_set_curr_device_mode(hdd_ctx->mac_handle, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267 /* Zero the memory. This zeros the profile structure. */
Jeff Johnsonca2530c2017-09-30 18:25:40 -07003268 memset(phostapdBuf, 0, sizeof(struct hdd_hostapd_state));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303270 status = qdf_event_create(&phostapdBuf->qdf_event);
3271 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003272 hdd_err("Hostapd HDD qdf event init failed!!");
Krunal Sonib51eec72017-11-20 21:53:01 -08003273 goto error_release_sap_session;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003274 }
3275
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303276 status = qdf_event_create(&phostapdBuf->qdf_stop_bss_event);
3277 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003278 hdd_err("Hostapd HDD stop bss event init failed!!");
Krunal Sonib51eec72017-11-20 21:53:01 -08003279 goto error_release_sap_session;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280 }
3281
Wei Song2f76f642016-11-18 16:32:53 +08003282 status = qdf_event_create(&phostapdBuf->qdf_sta_disassoc_event);
3283 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003284 hdd_err("Hostapd HDD sta disassoc event init failed!!");
Krunal Sonib51eec72017-11-20 21:53:01 -08003285 goto error_release_sap_session;
Wei Song2f76f642016-11-18 16:32:53 +08003286 }
3287
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288 /* Register as a wireless device */
Rachit Kankane0dc3e852018-05-07 17:33:42 +05303289 hdd_register_hostapd_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003290
3291 /* Initialize the data path module */
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003292 status = hdd_softap_init_tx_rx(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003293 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003294 hdd_err("hdd_softap_init_tx_rx failed");
Krunal Sonib51eec72017-11-20 21:53:01 -08003295 goto error_release_sap_session;
3296 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003297
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003298 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303299 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003300 hdd_err("hdd_wmm_adapter_init() failed code: %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003301 status, status);
Krunal Sonib51eec72017-11-20 21:53:01 -08003302 goto error_release_wmm;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003303 }
3304
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003305 set_bit(WMM_INIT_DONE, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003306
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08003307 ret = wma_cli_set_command(adapter->vdev_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05303309 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310 PDEV_CMD);
3311
Srinivas Girigowda55756882017-03-06 16:45:27 -08003312 if (0 != ret)
3313 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed: %d", ret);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303314
Rakshith Suresh Patkar9f5c5862019-02-04 16:23:02 +05303315 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
3316 cfg_dp_enable_ip_tcp_udp_checksum_offload))
3317 adapter->dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3318 adapter->dev->features |= NETIF_F_RXCSUM;
3319
3320 hdd_set_tso_flags(hdd_ctx, adapter->dev);
3321
Arun Khandavallicc544b32017-01-30 19:52:16 +05303322 if (!reinit) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07003323 adapter->session.ap.sap_config.acs_cfg.acs_mode = false;
Himanshu Agarwal1b3be702018-02-20 12:16:57 +05303324 wlan_hdd_undo_acs(adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07003325 qdf_mem_zero(&adapter->session.ap.sap_config.acs_cfg,
Arun Khandavallicc544b32017-01-30 19:52:16 +05303326 sizeof(struct sap_acs_cfg));
3327 }
3328
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303329 /* rcpi info initialization */
3330 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3331
Dustin Browne74003f2018-03-14 12:51:58 -07003332 hdd_exit();
Dustin Brownd28772b2017-03-17 14:16:07 -07003333
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003334 return status;
3335
Krunal Sonib51eec72017-11-20 21:53:01 -08003336error_release_wmm:
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003337 hdd_softap_deinit_tx_rx(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003338error_release_sap_session:
Rachit Kankane0dc3e852018-05-07 17:33:42 +05303339 hdd_unregister_wext(adapter->dev);
Krunal Soni4a020c72017-10-30 20:58:40 -07003340 hdd_hostapd_deinit_sap_session(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003341error_release_vdev:
3342 QDF_BUG(!hdd_vdev_destroy(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003343
Dustin Browne74003f2018-03-14 12:51:58 -07003344 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003345 return status;
3346}
3347
Krunal Soni4a020c72017-10-30 20:58:40 -07003348void hdd_deinit_ap_mode(struct hdd_context *hdd_ctx,
3349 struct hdd_adapter *adapter,
3350 bool rtnl_held)
3351{
Dustin Brownfdf17c12018-03-14 12:55:34 -07003352 hdd_enter_dev(adapter->dev);
Krunal Soni4a020c72017-10-30 20:58:40 -07003353
3354 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3355 hdd_wmm_adapter_close(adapter);
3356 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3357 }
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05303358 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Krunal Soni4a020c72017-10-30 20:58:40 -07003359 wlan_hdd_undo_acs(adapter);
3360 hdd_softap_deinit_tx_rx(adapter);
3361 /*
3362 * if we are being called during driver unload,
3363 * then the dev has already been invalidated.
3364 * if we are being called at other times, then we can
3365 * detach the wireless device handlers
3366 */
3367 if (adapter->dev) {
3368 if (rtnl_held) {
3369 adapter->dev->wireless_handlers = NULL;
3370 } else {
3371 rtnl_lock();
3372 adapter->dev->wireless_handlers = NULL;
3373 rtnl_unlock();
3374 }
3375 }
3376 if (hdd_hostapd_deinit_sap_session(adapter))
3377 hdd_err("Failed:hdd_hostapd_deinit_sap_session");
Krunal Soni4a020c72017-10-30 20:58:40 -07003378
Dustin Browne74003f2018-03-14 12:51:58 -07003379 hdd_exit();
Krunal Soni4a020c72017-10-30 20:58:40 -07003380}
3381
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382/**
3383 * hdd_wlan_create_ap_dev() - create an AP-mode device
Jeff Johnson23c3b842017-09-03 09:05:29 -07003384 * @hdd_ctx: Global HDD context
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07003385 * @mac_addr: MAC address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003386 * @name_assign_type: the name of assign type of the netdev
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387 * @iface_name: User-visible name of the interface
3388 *
3389 * This function will allocate a Linux net_device and configuration it
3390 * for an AP mode of operation. Note that the device is NOT actually
3391 * registered with the kernel at this time.
3392 *
3393 * Return: A pointer to the private data portion of the net_device if
3394 * the allocation and initialization was successful, NULL otherwise.
3395 */
Jeff Johnson23c3b842017-09-03 09:05:29 -07003396struct hdd_adapter *hdd_wlan_create_ap_dev(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07003397 tSirMacAddr mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003398 unsigned char name_assign_type,
3399 uint8_t *iface_name)
3400{
Jeff Johnson15712092017-10-28 12:02:53 -07003401 struct net_device *dev;
3402 struct hdd_adapter *adapter;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303403 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404
Srinivas Girigowda55756882017-03-06 16:45:27 -08003405 hdd_debug("iface_name = %s", iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406
Jeff Johnson15712092017-10-28 12:02:53 -07003407 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), iface_name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003408#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3409 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410#endif
Ryan Hsu07495ea2016-01-21 15:25:39 -08003411 ether_setup, NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412
Jeff Johnson15712092017-10-28 12:02:53 -07003413 if (!dev)
3414 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003415
Jeff Johnson15712092017-10-28 12:02:53 -07003416 adapter = netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417
Jeff Johnson15712092017-10-28 12:02:53 -07003418 /* Init the net_device structure */
3419 ether_setup(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420
Jeff Johnson15712092017-10-28 12:02:53 -07003421 /* Initialize the adapter context to zeros. */
3422 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
3423 adapter->dev = dev;
3424 adapter->hdd_ctx = hdd_ctx;
3425 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson912b1bb2019-03-06 10:12:36 -08003426 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427
Jeff Johnson15712092017-10-28 12:02:53 -07003428 hdd_debug("dev = %pK, adapter = %pK, concurrency_mode=0x%x",
3429 dev, adapter,
Dustin Brown1dbefe62018-09-11 16:32:03 -07003430 (int)policy_mgr_get_concurrency_mode(hdd_ctx->psoc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431
Jeff Johnson15712092017-10-28 12:02:53 -07003432 /* Init the net_device structure */
3433 strlcpy(dev->name, (const char *)iface_name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434
Jeff Johnson15712092017-10-28 12:02:53 -07003435 hdd_set_ap_ops(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436
Jeff Johnson15712092017-10-28 12:02:53 -07003437 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3438 dev->mtu = HDD_DEFAULT_MTU;
3439 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
jge3e6f6382016-09-29 13:28:28 +08003440
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07003441 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3442 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443
Jeff Johnson15712092017-10-28 12:02:53 -07003444 adapter->offloads_configured = false;
3445 hdd_dev_setup_destructor(dev);
3446 dev->ieee80211_ptr = &adapter->wdev;
3447 adapter->wdev.wiphy = hdd_ctx->wiphy;
3448 adapter->wdev.netdev = dev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303449
3450 qdf_status = qdf_event_create(
3451 &adapter->qdf_session_open_event);
3452 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3453 hdd_err("failed to create session open QDF event!");
3454 free_netdev(adapter->dev);
3455 return NULL;
3456 }
3457
3458 qdf_status = qdf_event_create(
3459 &adapter->qdf_session_close_event);
3460 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3461 hdd_err("failed to create session close QDF event!");
3462 free_netdev(adapter->dev);
3463 return NULL;
3464 }
3465
Jeff Johnson15712092017-10-28 12:02:53 -07003466 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3467 spin_lock_init(&adapter->pause_map_lock);
3468 adapter->start_time = adapter->last_time = qdf_system_ticks();
3469
Abhinav Kumar338e57d2019-02-04 17:30:10 +05303470 qdf_atomic_init(&adapter->ch_switch_in_progress);
Min Liu2fef5792018-01-19 17:59:42 +08003471
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003472 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473}
3474
3475/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476 * wlan_hdd_rate_is_11g() - check if rate is 11g rate or not
3477 * @rate: Rate to be checked
3478 *
3479 * Return: true if rate if 11g else false
3480 */
3481static bool wlan_hdd_rate_is_11g(u8 rate)
3482{
3483 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72,
3484 96, 108}; /* actual rate * 2 */
3485 u8 i;
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07003486
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487 for (i = 0; i < 8; i++) {
3488 if (rate == gRateArray[i])
3489 return true;
3490 }
3491 return false;
3492}
3493
3494#ifdef QCA_HT_2040_COEX
3495/**
3496 * wlan_hdd_get_sap_obss() - Get SAP OBSS enable config based on HT_CAPAB IE
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003497 * @adapter: Pointer to hostapd adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 *
3499 * Return: HT support channel width config value
3500 */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003501static bool wlan_hdd_get_sap_obss(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003502{
Naveen Rawat72475db2017-12-13 18:07:35 -08003503 uint32_t ret;
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003504 const uint8_t *ie;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003505 uint8_t ht_cap_ie[DOT11F_IE_HTCAPS_MAX_LEN];
3506 tDot11fIEHTCaps dot11_ht_cap_ie = {0};
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003507 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07003508 struct hdd_beacon_data *beacon = adapter->session.ap.beacon;
Jeff Johnson89a0c742018-06-12 18:17:46 -07003509 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510
Jeff Johnson89a0c742018-06-12 18:17:46 -07003511 mac_handle = hdd_ctx->mac_handle;
Naveen Rawat08db88f2017-09-08 15:07:48 -07003512 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_HT_CAPABILITY,
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003513 beacon->tail, beacon->tail_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003514 if (ie && ie[1]) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303515 qdf_mem_copy(ht_cap_ie, &ie[2], DOT11F_IE_HTCAPS_MAX_LEN);
Jeff Johnson034f3c92018-11-09 10:46:21 -08003516 ret = dot11f_unpack_ie_ht_caps(MAC_CONTEXT(mac_handle),
Naveen Rawat72475db2017-12-13 18:07:35 -08003517 ht_cap_ie, ie[1],
3518 &dot11_ht_cap_ie, false);
3519 if (DOT11F_FAILED(ret)) {
3520 hdd_err("unpack failed, ret: 0x%x", ret);
3521 return false;
3522 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003523 return dot11_ht_cap_ie.supportedChannelWidthSet;
3524 }
3525
3526 return false;
3527}
3528#else
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003529static bool wlan_hdd_get_sap_obss(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530{
3531 return false;
3532}
3533#endif
3534/**
3535 * wlan_hdd_set_channel() - set channel in sap mode
3536 * @wiphy: Pointer to wiphy structure
3537 * @dev: Pointer to net_device structure
3538 * @chandef: Pointer to channel definition structure
3539 * @channel_type: Channel type
3540 *
3541 * Return: 0 for success non-zero for failure
3542 */
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05303543int wlan_hdd_set_channel(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003544 struct net_device *dev,
3545 struct cfg80211_chan_def *chandef,
3546 enum nl80211_channel_type channel_type)
3547{
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003548 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003549 uint32_t num_ch = 0;
3550 int channel = 0;
3551 int channel_seg2 = 0;
Jeff Johnson23c3b842017-09-03 09:05:29 -07003552 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553 int status;
Jeff Johnson89a0c742018-06-12 18:17:46 -07003554 mac_handle_t mac_handle;
Jeff Johnson46b4f0e2019-03-08 10:48:35 -08003555 struct sme_config_params *sme_config;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07003556 struct sap_config *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557
Dustin Brown491d54b2018-03-14 12:39:11 -07003558 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559
Jeff Johnsond36fa332019-03-18 13:42:25 -07003560 if (!dev) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003561 hdd_err("Called with dev = NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 return -ENODEV;
3563 }
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003564 adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003565
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303566 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3567 TRACE_CODE_HDD_CFG80211_SET_CHANNEL,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08003568 adapter->vdev_id, channel_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003569
Srinivas Girigowda55756882017-03-06 16:45:27 -08003570 hdd_debug("Device_mode %s(%d) freq = %d",
Dustin Brown458027c2018-10-19 12:26:27 -07003571 qdf_opmode_str(adapter->device_mode),
3572 adapter->device_mode, chandef->chan->center_freq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003573
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003574 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson23c3b842017-09-03 09:05:29 -07003575 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303576 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003577 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303578
Jeff Johnson89a0c742018-06-12 18:17:46 -07003579 mac_handle = hdd_ctx->mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580
3581 /*
3582 * Do freq to chan conversion
3583 * TODO: for 11a
3584 */
3585
3586 channel = ieee80211_frequency_to_channel(chandef->chan->center_freq);
Arif Hussain174c3fc2016-07-28 11:19:42 -07003587
Kiran Kumar Lokeref1f5e992016-06-20 16:48:50 -07003588 if (NL80211_CHAN_WIDTH_80P80 == chandef->width ||
Arif Hussain174c3fc2016-07-28 11:19:42 -07003589 NL80211_CHAN_WIDTH_160 == chandef->width) {
3590 if (chandef->center_freq2)
3591 channel_seg2 = ieee80211_frequency_to_channel(
3592 chandef->center_freq2);
3593 else
3594 hdd_err("Invalid center_freq2");
3595 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003596
3597 /* Check freq range */
3598 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
3599 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003600 hdd_err("Channel: %d is outside valid range from %d to %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003601 channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
3602 WNI_CFG_CURRENT_CHANNEL_STAMAX);
3603 return -EINVAL;
3604 }
3605
3606 /* Check freq range */
3607
3608 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel_seg2) ||
3609 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel_seg2)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003610 hdd_err("Channel: %d is outside valid range from %d to %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611 channel_seg2, WNI_CFG_CURRENT_CHANNEL_STAMIN,
3612 WNI_CFG_CURRENT_CHANNEL_STAMAX);
3613 return -EINVAL;
3614 }
3615
Wu Gao0821b0d2019-01-11 17:31:11 +08003616 num_ch = CFG_VALID_CHANNEL_LIST_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003617
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003618 if ((QDF_SAP_MODE != adapter->device_mode) &&
3619 (QDF_P2P_GO_MODE != adapter->device_mode)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303620 if (QDF_STATUS_SUCCESS !=
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003621 wlan_hdd_validate_operation_channel(adapter, channel)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003622 hdd_err("Invalid Channel: %d", channel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003623 return -EINVAL;
3624 }
Dustin Brown458027c2018-10-19 12:26:27 -07003625 hdd_debug("set channel to [%d] for device mode %s(%d)", channel,
3626 qdf_opmode_str(adapter->device_mode),
3627 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 }
3629
Jeff Johnson2b89f8b2018-03-14 12:37:14 -07003630 if ((adapter->device_mode == QDF_STA_MODE) ||
3631 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
3632 struct csr_roam_profile *roam_profile;
Jeff Johnsond377dce2017-10-04 10:32:42 -07003633 struct hdd_station_ctx *sta_ctx =
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003634 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635
3636 if (eConnectionState_IbssConnected ==
Jeff Johnsone7951512019-02-27 10:02:51 -08003637 sta_ctx->conn_info.conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003638 /* Link is up then return cant set channel */
Jeff Johnsonecd884e2016-06-30 14:52:25 -07003639 hdd_err("IBSS Associated, can't set the channel");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003640 return -EINVAL;
3641 }
3642
Jeff Johnson2b89f8b2018-03-14 12:37:14 -07003643 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson5b34fce2017-10-13 13:24:51 -07003644 num_ch = roam_profile->ChannelInfo.numOfChannels = 1;
Jeff Johnson8626e932019-02-27 18:35:22 -08003645 sta_ctx->conn_info.channel = channel;
Jeff Johnson5b34fce2017-10-13 13:24:51 -07003646 roam_profile->ChannelInfo.ChannelList =
Jeff Johnson8626e932019-02-27 18:35:22 -08003647 &sta_ctx->conn_info.channel;
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003648 } else if ((adapter->device_mode == QDF_SAP_MODE)
3649 || (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650 ) {
Jeff Johnson91df29d2017-10-27 19:29:50 -07003651 sap_config = &((WLAN_HDD_GET_AP_CTX_PTR(adapter))->sap_config);
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003652 if (QDF_P2P_GO_MODE == adapter->device_mode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303653 if (QDF_STATUS_SUCCESS !=
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003654 wlan_hdd_validate_operation_channel(adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 channel)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003656 hdd_err("Invalid Channel: %d", channel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003657 return -EINVAL;
3658 }
3659 sap_config->channel = channel;
3660 sap_config->ch_params.center_freq_seg1 = channel_seg2;
3661 } else {
3662 /* set channel to what hostapd configured */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303663 if (QDF_STATUS_SUCCESS !=
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003664 wlan_hdd_validate_operation_channel(adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665 channel)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003666 hdd_err("Invalid Channel: %d", channel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 return -EINVAL;
3668 }
3669
3670 sap_config->channel = channel;
3671 sap_config->ch_params.center_freq_seg1 = channel_seg2;
3672
Manjeet Singhaec78b52016-11-03 15:43:56 +05303673 sme_config = qdf_mem_malloc(sizeof(*sme_config));
3674
3675 if (!sme_config) {
3676 hdd_err("Unable to allocate memory for smeconfig!");
3677 return -ENOMEM;
3678 }
Jeff Johnson89a0c742018-06-12 18:17:46 -07003679 sme_get_config_param(mac_handle, sme_config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680 switch (channel_type) {
3681 case NL80211_CHAN_HT20:
3682 case NL80211_CHAN_NO_HT:
Jeff Johnsone94ccd02019-04-02 15:02:56 -07003683 sme_config->csr_config.obssEnabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684 sap_config->sec_ch = 0;
3685 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686 case NL80211_CHAN_HT40MINUS:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003687 sap_config->sec_ch = sap_config->channel - 4;
3688 break;
3689 case NL80211_CHAN_HT40PLUS:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003690 sap_config->sec_ch = sap_config->channel + 4;
3691 break;
3692 default:
Jeff Johnsonecd884e2016-06-30 14:52:25 -07003693 hdd_err("Error!!! Invalid HT20/40 mode !");
Manjeet Singhaec78b52016-11-03 15:43:56 +05303694 qdf_mem_free(sme_config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003695 return -EINVAL;
3696 }
Jeff Johnsone94ccd02019-04-02 15:02:56 -07003697 sme_config->csr_config.obssEnabled =
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003698 wlan_hdd_get_sap_obss(adapter);
Manjeet Singhaec78b52016-11-03 15:43:56 +05303699
Jeff Johnson89a0c742018-06-12 18:17:46 -07003700 sme_update_config(mac_handle, sme_config);
Manjeet Singhaec78b52016-11-03 15:43:56 +05303701 qdf_mem_free(sme_config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702 }
3703 } else {
Jeff Johnsonecd884e2016-06-30 14:52:25 -07003704 hdd_err("Invalid device mode failed to set valid channel");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003705 return -EINVAL;
3706 }
Dustin Browne74003f2018-03-14 12:51:58 -07003707 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003708 return status;
3709}
3710
3711/**
3712 * wlan_hdd_check_11gmode() - check for 11g mode
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003713 * @ie: Pointer to IE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003714 * @require_ht: Pointer to require ht
3715 * @require_vht: Pointer to require vht
3716 * @pCheckRatesfor11g: Pointer to check rates for 11g mode
3717 * @pSapHw_mode: SAP HW mode
3718 *
3719 * Check for 11g rate and set proper 11g only mode
3720 *
3721 * Return: none
3722 */
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003723static void wlan_hdd_check_11gmode(const u8 *ie, u8 *require_ht,
Naveen Rawat08db88f2017-09-08 15:07:48 -07003724 u8 *require_vht, u8 *pCheckRatesfor11g,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003725 eCsrPhyMode *pSapHw_mode)
3726{
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003727 u8 i, num_rates = ie[0];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003728
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003729 ie += 1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003730 for (i = 0; i < num_rates; i++) {
3731 if (*pCheckRatesfor11g
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003732 && (true == wlan_hdd_rate_is_11g(ie[i] & RATE_MASK))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733 /* If rate set have 11g rate than change the mode
3734 * to 11G
3735 */
3736 *pSapHw_mode = eCSR_DOT11_MODE_11g;
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003737 if (ie[i] & BASIC_RATE_MASK) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003738 /* If we have 11g rate as basic rate, it
3739 * means mode is 11g only mode.
3740 */
3741 *pSapHw_mode = eCSR_DOT11_MODE_11g_ONLY;
3742 *pCheckRatesfor11g = false;
3743 }
3744 } else {
3745 if ((BASIC_RATE_MASK |
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003746 WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == ie[i])
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747 *require_ht = true;
3748 else if ((BASIC_RATE_MASK |
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003749 WLAN_BSS_MEMBERSHIP_SELECTOR_VHT_PHY) == ie[i])
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750 *require_vht = true;
3751 }
3752 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003753}
3754
Naveen Rawatd8feac12017-09-08 15:08:39 -07003755#ifdef WLAN_FEATURE_11AX
3756/**
3757 * wlan_hdd_add_extn_ie() - add extension IE
3758 * @adapter: Pointer to hostapd adapter
3759 * @genie: Pointer to ie to be added
3760 * @total_ielen: Pointer to store total ie length
3761 * @oui: Pointer to oui
3762 * @oui_size: Size of oui
3763 *
3764 * Return: 0 for success non-zero for failure
3765 */
3766static int wlan_hdd_add_extn_ie(struct hdd_adapter *adapter, uint8_t *genie,
3767 uint16_t *total_ielen, uint8_t *oui,
3768 uint8_t oui_size)
3769{
3770 const uint8_t *ie;
3771 uint16_t ielen = 0;
Jeff Johnsonb9424862017-10-30 08:49:35 -07003772 struct hdd_beacon_data *beacon = adapter->session.ap.beacon;
Naveen Rawatd8feac12017-09-08 15:08:39 -07003773
3774 ie = wlan_get_ext_ie_ptr_from_ext_id(oui, oui_size,
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08003775 beacon->tail,
3776 beacon->tail_len);
Naveen Rawatd8feac12017-09-08 15:08:39 -07003777 if (ie) {
3778 ielen = ie[1] + 2;
3779 if ((*total_ielen + ielen) <= MAX_GENIE_LEN) {
3780 qdf_mem_copy(&genie[*total_ielen], ie, ielen);
3781 } else {
3782 hdd_err("**Ie Length is too big***");
3783 return -EINVAL;
3784 }
3785 *total_ielen += ielen;
3786 }
3787 return 0;
3788}
3789#endif
3790
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003791/**
Abhishek Singh86ea5c72017-09-01 16:08:09 +05303792 * wlan_hdd_add_hostapd_conf_vsie() - configure Vendor IE in sap mode
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003793 * @adapter: Pointer to hostapd adapter
Abhishek Singh86ea5c72017-09-01 16:08:09 +05303794 * @genie: Pointer to Vendor IE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003795 * @total_ielen: Pointer to store total ie length
3796 *
3797 * Return: none
3798 */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003799static void wlan_hdd_add_hostapd_conf_vsie(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003800 uint8_t *genie,
Liangwei Dongec9be932016-10-19 05:59:13 -04003801 uint16_t *total_ielen)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003802{
Jeff Johnsond5777132019-02-11 09:55:56 -08003803 struct hdd_beacon_data *beacon = adapter->session.ap.beacon;
3804 int left = beacon->tail_len;
3805 uint8_t *ptr = beacon->tail;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806 uint8_t elem_id, elem_len;
3807 uint16_t ielen = 0;
Abhishek Singh86ea5c72017-09-01 16:08:09 +05303808 bool skip_ie;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003809
Jeff Johnsond36fa332019-03-18 13:42:25 -07003810 if (!ptr || 0 == left)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811 return;
3812
3813 while (left >= 2) {
3814 elem_id = ptr[0];
3815 elem_len = ptr[1];
3816 left -= 2;
Ashish Kumar Dhanotiya20f09e42017-08-04 17:59:38 +05303817 if (elem_len > left) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003818 hdd_err("**Invalid IEs eid: %d elem_len: %d left: %d**",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819 elem_id, elem_len, left);
3820 return;
3821 }
Abhishek Singh86ea5c72017-09-01 16:08:09 +05303822 if (IE_EID_VENDOR == elem_id) {
3823 /*
3824 * skipping the Vendor IE's which we don't want to
3825 * include or it will be included by existing code.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 */
Abhishek Singh86ea5c72017-09-01 16:08:09 +05303827 if (elem_len >= WPS_OUI_TYPE_SIZE &&
3828 (!qdf_mem_cmp(&ptr[2], WHITELIST_OUI_TYPE,
3829 WPA_OUI_TYPE_SIZE) ||
3830 !qdf_mem_cmp(&ptr[2], BLACKLIST_OUI_TYPE,
3831 WPA_OUI_TYPE_SIZE) ||
3832 !qdf_mem_cmp(&ptr[2], "\x00\x50\xf2\x02",
3833 WPA_OUI_TYPE_SIZE) ||
3834 !qdf_mem_cmp(&ptr[2], WPA_OUI_TYPE,
3835 WPA_OUI_TYPE_SIZE)))
3836 skip_ie = true;
3837 else
3838 skip_ie = false;
3839
3840 if (!skip_ie) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841 ielen = ptr[1] + 2;
3842 if ((*total_ielen + ielen) <= MAX_GENIE_LEN) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303843 qdf_mem_copy(&genie[*total_ielen], ptr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844 ielen);
3845 *total_ielen += ielen;
3846 } else {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003847 hdd_err("IE Length is too big IEs eid: %d elem_len: %d total_ie_lent: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003848 elem_id, elem_len, *total_ielen);
3849 }
3850 }
3851 }
3852
3853 left -= elem_len;
3854 ptr += (elem_len + 2);
3855 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003856}
3857
3858/**
3859 * wlan_hdd_add_extra_ie() - add extra ies in beacon
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003860 * @adapter: Pointer to hostapd adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861 * @genie: Pointer to extra ie
3862 * @total_ielen: Pointer to store total ie length
3863 * @temp_ie_id: ID of extra ie
3864 *
3865 * Return: none
3866 */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07003867static void wlan_hdd_add_extra_ie(struct hdd_adapter *adapter,
Liangwei Dongec9be932016-10-19 05:59:13 -04003868 uint8_t *genie, uint16_t *total_ielen,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869 uint8_t temp_ie_id)
3870{
Jeff Johnsond5777132019-02-11 09:55:56 -08003871 struct hdd_beacon_data *beacon = adapter->session.ap.beacon;
3872 int left = beacon->tail_len;
3873 uint8_t *ptr = beacon->tail;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003874 uint8_t elem_id, elem_len;
3875 uint16_t ielen = 0;
3876
Jeff Johnsond36fa332019-03-18 13:42:25 -07003877 if (!ptr || 0 == left)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878 return;
3879
3880 while (left >= 2) {
3881 elem_id = ptr[0];
3882 elem_len = ptr[1];
3883 left -= 2;
3884 if (elem_len > left) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003885 hdd_err("**Invalid IEs eid: %d elem_len: %d left: %d**",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 elem_id, elem_len, left);
3887 return;
3888 }
3889
3890 if (temp_ie_id == elem_id) {
3891 ielen = ptr[1] + 2;
3892 if ((*total_ielen + ielen) <= MAX_GENIE_LEN) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303893 qdf_mem_copy(&genie[*total_ielen], ptr, ielen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003894 *total_ielen += ielen;
3895 } else {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003896 hdd_err("IE Length is too big IEs eid: %d elem_len: %d total_ie_len: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 elem_id, elem_len, *total_ielen);
3898 }
3899 }
3900
3901 left -= elem_len;
3902 ptr += (elem_len + 2);
3903 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003904}
3905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906/**
3907 * wlan_hdd_cfg80211_alloc_new_beacon() - alloc beacon in ap mode
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003908 * @adapter: Pointer to hostapd adapter
Jeff Johnson95d5bf52019-02-11 09:17:08 -08003909 * @out_beacon: Location to store newly allocated beacon data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003910 * @params: Pointer to beacon parameters
3911 * @dtim_period: DTIM period
3912 *
3913 * Return: 0 for success non-zero for failure
3914 */
Jeff Johnsone4090f72016-10-05 16:00:23 -07003915static int
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07003916wlan_hdd_cfg80211_alloc_new_beacon(struct hdd_adapter *adapter,
Jeff Johnson95d5bf52019-02-11 09:17:08 -08003917 struct hdd_beacon_data **out_beacon,
Jeff Johnsone4090f72016-10-05 16:00:23 -07003918 struct cfg80211_beacon_data *params,
3919 int dtim_period)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920{
3921 int size;
Jeff Johnson44e52172017-09-30 16:39:16 -07003922 struct hdd_beacon_data *beacon = NULL;
3923 struct hdd_beacon_data *old = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003924 int head_len, tail_len, proberesp_ies_len, assocresp_ies_len;
3925 const u8 *head, *tail, *proberesp_ies, *assocresp_ies;
3926
Dustin Brown491d54b2018-03-14 12:39:11 -07003927 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 if (params->head && !params->head_len) {
Jeff Johnsonecd884e2016-06-30 14:52:25 -07003929 hdd_err("head_len is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930 return -EINVAL;
3931 }
3932
Jeff Johnsonb9424862017-10-30 08:49:35 -07003933 old = adapter->session.ap.beacon;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003934
3935 if (!params->head && !old) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08003936 hdd_err("session: %d old and new heads points to NULL",
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08003937 adapter->vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938 return -EINVAL;
3939 }
3940
3941 if (params->head) {
3942 head_len = params->head_len;
3943 head = params->head;
3944 } else {
3945 head_len = old->head_len;
3946 head = old->head;
3947 }
3948
3949 if (params->tail || !old) {
3950 tail_len = params->tail_len;
3951 tail = params->tail;
3952 } else {
3953 tail_len = old->tail_len;
3954 tail = old->tail;
3955 }
3956
3957 if (params->proberesp_ies || !old) {
3958 proberesp_ies_len = params->proberesp_ies_len;
3959 proberesp_ies = params->proberesp_ies;
3960 } else {
3961 proberesp_ies_len = old->proberesp_ies_len;
3962 proberesp_ies = old->proberesp_ies;
3963 }
3964
3965 if (params->assocresp_ies || !old) {
3966 assocresp_ies_len = params->assocresp_ies_len;
3967 assocresp_ies = params->assocresp_ies;
3968 } else {
3969 assocresp_ies_len = old->assocresp_ies_len;
3970 assocresp_ies = old->assocresp_ies;
3971 }
3972
Jeff Johnson44e52172017-09-30 16:39:16 -07003973 size = sizeof(struct hdd_beacon_data) + head_len + tail_len +
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 proberesp_ies_len + assocresp_ies_len;
3975
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05303976 beacon = qdf_mem_malloc(size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003977
Jeff Johnsond36fa332019-03-18 13:42:25 -07003978 if (!beacon) {
Jeff Johnsonecd884e2016-06-30 14:52:25 -07003979 hdd_err("Mem allocation for beacon failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 return -ENOMEM;
3981 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003982 if (dtim_period)
3983 beacon->dtim_period = dtim_period;
3984 else if (old)
3985 beacon->dtim_period = old->dtim_period;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 /* -----------------------------------------------
3987 * | head | tail | proberesp_ies | assocresp_ies |
3988 * -----------------------------------------------
3989 */
Jeff Johnson44e52172017-09-30 16:39:16 -07003990 beacon->head = ((u8 *) beacon) + sizeof(struct hdd_beacon_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 beacon->tail = beacon->head + head_len;
3992 beacon->proberesp_ies = beacon->tail + tail_len;
3993 beacon->assocresp_ies = beacon->proberesp_ies + proberesp_ies_len;
3994
3995 beacon->head_len = head_len;
3996 beacon->tail_len = tail_len;
3997 beacon->proberesp_ies_len = proberesp_ies_len;
3998 beacon->assocresp_ies_len = assocresp_ies_len;
3999
4000 if (head && head_len)
4001 memcpy(beacon->head, head, head_len);
4002 if (tail && tail_len)
4003 memcpy(beacon->tail, tail, tail_len);
4004 if (proberesp_ies && proberesp_ies_len)
4005 memcpy(beacon->proberesp_ies, proberesp_ies, proberesp_ies_len);
4006 if (assocresp_ies && assocresp_ies_len)
4007 memcpy(beacon->assocresp_ies, assocresp_ies, assocresp_ies_len);
4008
Jeff Johnson95d5bf52019-02-11 09:17:08 -08004009 *out_beacon = beacon;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010
Jeff Johnsonb9424862017-10-30 08:49:35 -07004011 adapter->session.ap.beacon = NULL;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304012 qdf_mem_free(old);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013
4014 return 0;
4015
4016}
4017
Liangwei Dongec9be932016-10-19 05:59:13 -04004018#ifdef QCA_HT_2040_COEX
4019static void wlan_hdd_add_sap_obss_scan_ie(
Jeff Johnson866aca82017-09-10 15:27:20 -07004020 struct hdd_adapter *hostapd_adapter, uint8_t *ie_buf, uint16_t *ie_len)
Liangwei Dongec9be932016-10-19 05:59:13 -04004021{
4022 if (QDF_SAP_MODE == hostapd_adapter->device_mode) {
4023 if (wlan_hdd_get_sap_obss(hostapd_adapter))
4024 wlan_hdd_add_extra_ie(hostapd_adapter, ie_buf, ie_len,
4025 WLAN_EID_OVERLAP_BSS_SCAN_PARAM);
4026 }
4027}
4028#else
4029static void wlan_hdd_add_sap_obss_scan_ie(
Jeff Johnson866aca82017-09-10 15:27:20 -07004030 struct hdd_adapter *hostapd_adapter, uint8_t *ie_buf, uint16_t *ie_len)
Liangwei Dongec9be932016-10-19 05:59:13 -04004031{
4032}
4033#endif
4034
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035/**
Naveen Rawatd8feac12017-09-08 15:08:39 -07004036 * wlan_hdd_cfg80211_update_apies() - update ap mode 11ax ies
4037 * @adapter: Pointer to hostapd adapter
4038 * @genie: generic IE buffer
4039 * @total_ielen: out param to update total ielen
4040 *
4041 * Return: 0 for success non-zero for failure
4042 */
4043
4044#ifdef WLAN_FEATURE_11AX
4045static int hdd_update_11ax_apies(struct hdd_adapter *adapter,
4046 uint8_t *genie, uint16_t *total_ielen)
4047{
4048 if (wlan_hdd_add_extn_ie(adapter, genie, total_ielen,
4049 HE_CAP_OUI_TYPE, HE_CAP_OUI_SIZE)) {
4050 hdd_err("Adding HE Cap ie failed");
4051 return -EINVAL;
4052 }
4053
4054 if (wlan_hdd_add_extn_ie(adapter, genie, total_ielen,
4055 HE_OP_OUI_TYPE, HE_OP_OUI_SIZE)) {
4056 hdd_err("Adding HE Op ie failed");
4057 return -EINVAL;
4058 }
4059
4060 return 0;
4061}
4062#else
4063static int hdd_update_11ax_apies(struct hdd_adapter *adapter,
4064 uint8_t *genie, uint16_t *total_ielen)
4065{
4066 return 0;
4067}
4068#endif
4069
4070/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 * wlan_hdd_cfg80211_update_apies() - update ap mode ies
4072 * @adapter: Pointer to hostapd adapter
4073 *
4074 * Return: 0 for success non-zero for failure
4075 */
Jeff Johnson866aca82017-09-10 15:27:20 -07004076int wlan_hdd_cfg80211_update_apies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077{
4078 uint8_t *genie;
Liangwei Dongec9be932016-10-19 05:59:13 -04004079 uint16_t total_ielen = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080 int ret = 0;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07004081 struct sap_config *config;
Jeff Johnsonc565af12019-03-10 21:09:47 -07004082 tSirUpdateIE update_ie;
Jeff Johnson44e52172017-09-30 16:39:16 -07004083 struct hdd_beacon_data *beacon = NULL;
Liangwei Dongec9be932016-10-19 05:59:13 -04004084 uint16_t proberesp_ies_len;
4085 uint8_t *proberesp_ies = NULL;
Jeff Johnson89a0c742018-06-12 18:17:46 -07004086 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087
Jeff Johnson954903d2019-03-07 20:41:27 -08004088 config = &adapter->session.ap.sap_config;
Jeff Johnsonb9424862017-10-30 08:49:35 -07004089 beacon = adapter->session.ap.beacon;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08004090 if (!beacon) {
4091 hdd_err("Beacon is NULL !");
4092 return -EINVAL;
4093 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004094
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304095 genie = qdf_mem_malloc(MAX_GENIE_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004096
Jeff Johnsond36fa332019-03-18 13:42:25 -07004097 if (!genie)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 return -ENOMEM;
4099
Jeff Johnson89a0c742018-06-12 18:17:46 -07004100 mac_handle = adapter->hdd_ctx->mac_handle;
4101
Edhar, Mahesh Kumar14846232016-06-30 15:03:23 +05304102 wlan_hdd_add_extra_ie(adapter, genie, &total_ielen,
4103 WLAN_EID_VHT_TX_POWER_ENVELOPE);
4104
Vidyullatha Kanchanapally518c5d72016-09-30 11:04:16 +05304105 /* Extract and add the extended capabilities and interworking IE */
4106 wlan_hdd_add_extra_ie(adapter, genie, &total_ielen,
4107 WLAN_EID_EXT_CAPABILITY);
4108
4109 wlan_hdd_add_extra_ie(adapter, genie, &total_ielen,
4110 WLAN_EID_INTERWORKING);
4111
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112#ifdef FEATURE_WLAN_WAPI
Krunal Soni056ea0f2016-03-10 13:07:10 -08004113 if (QDF_SAP_MODE == adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 wlan_hdd_add_extra_ie(adapter, genie, &total_ielen,
Srinivas Girigowda61771262019-04-01 11:55:19 -07004115 WLAN_ELEMID_WAPI);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 }
4117#endif
4118
Abhishek Singh86ea5c72017-09-01 16:08:09 +05304119 wlan_hdd_add_hostapd_conf_vsie(adapter, genie,
4120 &total_ielen);
yeshwanth sriram guntukaf6059f22017-08-04 16:22:55 +05304121
Naveen Rawatd8feac12017-09-08 15:08:39 -07004122 ret = hdd_update_11ax_apies(adapter, genie, &total_ielen);
4123 if (ret)
4124 goto done;
4125
Liangwei Dongec9be932016-10-19 05:59:13 -04004126 wlan_hdd_add_sap_obss_scan_ie(adapter, genie, &total_ielen);
4127
Jeff Johnsonc565af12019-03-10 21:09:47 -07004128 qdf_copy_macaddr(&update_ie.bssid, &adapter->mac_addr);
4129 update_ie.smeSessionId = adapter->vdev_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130
4131 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Jeff Johnsonc565af12019-03-10 21:09:47 -07004132 update_ie.ieBufferlength = total_ielen;
4133 update_ie.pAdditionIEBuffer = genie;
4134 update_ie.append = false;
4135 update_ie.notify = true;
Jeff Johnson89a0c742018-06-12 18:17:46 -07004136 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07004137 &update_ie,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138 eUPDATE_IE_PROBE_BCN) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304139 QDF_STATUS_E_FAILURE) {
Jeff Johnsonecd884e2016-06-30 14:52:25 -07004140 hdd_err("Could not pass on Add Ie probe beacon data");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004141 ret = -EINVAL;
4142 goto done;
4143 }
Jeff Johnson954903d2019-03-07 20:41:27 -08004144 wlansap_reset_sap_config_add_ie(config, eUPDATE_IE_PROBE_BCN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145 } else {
Jeff Johnson954903d2019-03-07 20:41:27 -08004146 wlansap_update_sap_config_add_ie(config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004147 genie,
4148 total_ielen,
4149 eUPDATE_IE_PROBE_BCN);
4150 }
4151
4152 /* Added for Probe Response IE */
Liangwei Dongec9be932016-10-19 05:59:13 -04004153 proberesp_ies = qdf_mem_malloc(beacon->proberesp_ies_len +
4154 MAX_GENIE_LEN);
Jeff Johnsond36fa332019-03-18 13:42:25 -07004155 if (!proberesp_ies) {
Zhu Jianminded9d2d2017-06-22 09:39:36 +08004156 hdd_err("mem alloc failed for probe resp ies, size: %d",
4157 beacon->proberesp_ies_len + MAX_GENIE_LEN);
Liangwei Dongec9be932016-10-19 05:59:13 -04004158 ret = -EINVAL;
4159 goto done;
4160 }
4161 qdf_mem_copy(proberesp_ies, beacon->proberesp_ies,
4162 beacon->proberesp_ies_len);
4163 proberesp_ies_len = beacon->proberesp_ies_len;
4164
4165 wlan_hdd_add_sap_obss_scan_ie(adapter, proberesp_ies,
4166 &proberesp_ies_len);
4167
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Jeff Johnsonc565af12019-03-10 21:09:47 -07004169 update_ie.ieBufferlength = proberesp_ies_len;
4170 update_ie.pAdditionIEBuffer = proberesp_ies;
4171 update_ie.append = false;
4172 update_ie.notify = false;
Jeff Johnson89a0c742018-06-12 18:17:46 -07004173 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07004174 &update_ie,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175 eUPDATE_IE_PROBE_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304176 QDF_STATUS_E_FAILURE) {
Jeff Johnsonecd884e2016-06-30 14:52:25 -07004177 hdd_err("Could not pass on PROBE_RESP add Ie data");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004178 ret = -EINVAL;
4179 goto done;
4180 }
Jeff Johnson954903d2019-03-07 20:41:27 -08004181 wlansap_reset_sap_config_add_ie(config, eUPDATE_IE_PROBE_RESP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004182 } else {
Jeff Johnson954903d2019-03-07 20:41:27 -08004183 wlansap_update_sap_config_add_ie(config,
Liangwei Dongec9be932016-10-19 05:59:13 -04004184 proberesp_ies,
4185 proberesp_ies_len,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 eUPDATE_IE_PROBE_RESP);
4187 }
4188
4189 /* Assoc resp Add ie Data */
4190 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Jeff Johnsonc565af12019-03-10 21:09:47 -07004191 update_ie.ieBufferlength = beacon->assocresp_ies_len;
4192 update_ie.pAdditionIEBuffer = (uint8_t *) beacon->assocresp_ies;
4193 update_ie.append = false;
4194 update_ie.notify = false;
Jeff Johnson89a0c742018-06-12 18:17:46 -07004195 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07004196 &update_ie,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304198 QDF_STATUS_E_FAILURE) {
Jeff Johnsonecd884e2016-06-30 14:52:25 -07004199 hdd_err("Could not pass on Add Ie Assoc Response data");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200 ret = -EINVAL;
4201 goto done;
4202 }
Jeff Johnson954903d2019-03-07 20:41:27 -08004203 wlansap_reset_sap_config_add_ie(config, eUPDATE_IE_ASSOC_RESP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004204 } else {
Jeff Johnson954903d2019-03-07 20:41:27 -08004205 wlansap_update_sap_config_add_ie(config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206 beacon->assocresp_ies,
4207 beacon->assocresp_ies_len,
4208 eUPDATE_IE_ASSOC_RESP);
4209 }
4210
4211done:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304212 qdf_mem_free(genie);
Liangwei Dongec9be932016-10-19 05:59:13 -04004213 qdf_mem_free(proberesp_ies);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004214 return ret;
4215}
4216
4217/**
4218 * wlan_hdd_set_sap_hwmode() - set sap hw mode
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004219 * @adapter: Pointer to hostapd adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220 *
4221 * Return: none
4222 */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004223static void wlan_hdd_set_sap_hwmode(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224{
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07004225 struct sap_config *config = &adapter->session.ap.sap_config;
Jeff Johnsond5777132019-02-11 09:55:56 -08004226 struct hdd_beacon_data *beacon = adapter->session.ap.beacon;
Jeff Johnsonc6c35e32019-03-10 18:32:38 -07004227 struct ieee80211_mgmt *mgmt_frame =
Jeff Johnsond5777132019-02-11 09:55:56 -08004228 (struct ieee80211_mgmt *)beacon->head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004229 u8 checkRatesfor11g = true;
4230 u8 require_ht = false, require_vht = false;
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004231 const u8 *ie;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232
Jeff Johnson954903d2019-03-07 20:41:27 -08004233 config->SapHw_mode = eCSR_DOT11_MODE_11b;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004234
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004235 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_SUPP_RATES,
Jeff Johnsonc6c35e32019-03-10 18:32:38 -07004236 &mgmt_frame->u.beacon.variable[0],
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004237 beacon->head_len);
Jeff Johnsond36fa332019-03-18 13:42:25 -07004238 if (ie) {
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004239 ie += 1;
4240 wlan_hdd_check_11gmode(ie, &require_ht, &require_vht,
Jeff Johnson954903d2019-03-07 20:41:27 -08004241 &checkRatesfor11g, &config->SapHw_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004242 }
4243
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004244 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_EXT_SUPP_RATES,
4245 beacon->tail, beacon->tail_len);
Jeff Johnsond36fa332019-03-18 13:42:25 -07004246 if (ie) {
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004247 ie += 1;
4248 wlan_hdd_check_11gmode(ie, &require_ht, &require_vht,
Jeff Johnson954903d2019-03-07 20:41:27 -08004249 &checkRatesfor11g, &config->SapHw_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004250 }
4251
Jeff Johnson954903d2019-03-07 20:41:27 -08004252 if (config->channel > 14)
4253 config->SapHw_mode = eCSR_DOT11_MODE_11a;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004254
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004255 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_HT_CAPABILITY,
4256 beacon->tail, beacon->tail_len);
4257 if (ie) {
Jeff Johnson954903d2019-03-07 20:41:27 -08004258 config->SapHw_mode = eCSR_DOT11_MODE_11n;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259 if (require_ht)
Jeff Johnson954903d2019-03-07 20:41:27 -08004260 config->SapHw_mode = eCSR_DOT11_MODE_11n_ONLY;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004261 }
4262
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004263 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_VHT_CAPABILITY,
4264 beacon->tail, beacon->tail_len);
4265 if (ie) {
Jeff Johnson954903d2019-03-07 20:41:27 -08004266 config->SapHw_mode = eCSR_DOT11_MODE_11ac;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004267 if (require_vht)
Jeff Johnson954903d2019-03-07 20:41:27 -08004268 config->SapHw_mode = eCSR_DOT11_MODE_11ac_ONLY;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 }
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08004270
Jeff Johnson954903d2019-03-07 20:41:27 -08004271 wlan_hdd_check_11ax_support(beacon, config);
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08004272
Jeff Johnson954903d2019-03-07 20:41:27 -08004273 hdd_info("SAP hw_mode: %d", config->SapHw_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274}
4275
4276/**
4277 * wlan_hdd_config_acs() - config ACS needed parameters
4278 * @hdd_ctx: HDD context
4279 * @adapter: Adapter pointer
4280 *
Jeff Johnson60ed45a2018-05-06 15:28:49 -07004281 * This function get ACS related INI parameters and populated
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004282 * sap config and smeConfig for ACS needed configurations.
4283 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304284 * Return: The QDF_STATUS code associated with performing the operation.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285 */
Jeff Johnson89a0c742018-06-12 18:17:46 -07004286QDF_STATUS wlan_hdd_config_acs(struct hdd_context *hdd_ctx,
4287 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288{
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07004289 struct sap_config *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004290 struct hdd_config *ini_config;
Jeff Johnson89a0c742018-06-12 18:17:46 -07004291 mac_handle_t mac_handle;
Krunal Sonidf29bc42018-11-15 13:26:29 -08004292 uint8_t is_overlap_enable = 0;
4293 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004294
Jeff Johnson89a0c742018-06-12 18:17:46 -07004295 mac_handle = hdd_ctx->mac_handle;
Jeff Johnsonb9424862017-10-30 08:49:35 -07004296 sap_config = &adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297 ini_config = hdd_ctx->config;
4298
Krunal Sonidf29bc42018-11-15 13:26:29 -08004299 status = ucfg_policy_mgr_get_enable_overlap_chnl(hdd_ctx->psoc,
4300 &is_overlap_enable);
4301 if (status != QDF_STATUS_SUCCESS)
4302 hdd_err("can't get overlap channel INI value, using default");
4303 sap_config->enOverLapCh = !!is_overlap_enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304
Dustin Brown5118e8e2016-09-13 15:54:23 -07004305#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Jeff Johnson89a0c742018-06-12 18:17:46 -07004306 hdd_debug("HDD_ACS_SKIP_STATUS = %d", hdd_ctx->skip_acs_scan_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 if (hdd_ctx->skip_acs_scan_status == eSAP_SKIP_ACS_SCAN) {
Jeff Johnson866aca82017-09-10 15:27:20 -07004308 struct hdd_adapter *con_sap_adapter;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07004309 struct sap_config *con_sap_config = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004310
4311 con_sap_adapter = hdd_get_con_sap_adapter(adapter, false);
4312
4313 if (con_sap_adapter)
4314 con_sap_config =
Jeff Johnsonb9424862017-10-30 08:49:35 -07004315 &con_sap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004316
4317 sap_config->acs_cfg.skip_scan_status = eSAP_DO_NEW_ACS_SCAN;
4318
4319 if (con_sap_config &&
4320 con_sap_config->acs_cfg.acs_mode == true &&
4321 hdd_ctx->skip_acs_scan_status == eSAP_SKIP_ACS_SCAN &&
4322 con_sap_config->acs_cfg.hw_mode ==
4323 sap_config->acs_cfg.hw_mode) {
4324 uint8_t con_sap_st_ch, con_sap_end_ch;
4325 uint8_t cur_sap_st_ch, cur_sap_end_ch;
4326 uint8_t bandStartChannel, bandEndChannel;
4327
4328 con_sap_st_ch =
4329 con_sap_config->acs_cfg.start_ch;
4330 con_sap_end_ch =
4331 con_sap_config->acs_cfg.end_ch;
4332 cur_sap_st_ch = sap_config->acs_cfg.start_ch;
4333 cur_sap_end_ch = sap_config->acs_cfg.end_ch;
4334
Jeff Johnson89a0c742018-06-12 18:17:46 -07004335 wlansap_extend_to_acs_range(mac_handle, &cur_sap_st_ch,
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07004336 &cur_sap_end_ch, &bandStartChannel,
4337 &bandEndChannel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338
Jeff Johnson89a0c742018-06-12 18:17:46 -07004339 wlansap_extend_to_acs_range(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 &con_sap_st_ch, &con_sap_end_ch,
4341 &bandStartChannel, &bandEndChannel);
4342
4343 if (con_sap_st_ch <= cur_sap_st_ch &&
4344 con_sap_end_ch >= cur_sap_end_ch) {
4345 sap_config->acs_cfg.skip_scan_status =
4346 eSAP_SKIP_ACS_SCAN;
4347
4348 } else if (con_sap_st_ch >= cur_sap_st_ch &&
4349 con_sap_end_ch >= cur_sap_end_ch) {
4350 sap_config->acs_cfg.skip_scan_status =
4351 eSAP_DO_PAR_ACS_SCAN;
4352
4353 sap_config->acs_cfg.skip_scan_range1_stch =
4354 cur_sap_st_ch;
4355 sap_config->acs_cfg.skip_scan_range1_endch =
4356 con_sap_st_ch - 1;
4357 sap_config->acs_cfg.skip_scan_range2_stch =
4358 0;
4359 sap_config->acs_cfg.skip_scan_range2_endch =
4360 0;
4361
4362 } else if (con_sap_st_ch <= cur_sap_st_ch &&
4363 con_sap_end_ch <= cur_sap_end_ch) {
4364 sap_config->acs_cfg.skip_scan_status =
4365 eSAP_DO_PAR_ACS_SCAN;
4366
4367 sap_config->acs_cfg.skip_scan_range1_stch =
4368 con_sap_end_ch + 1;
4369 sap_config->acs_cfg.skip_scan_range1_endch =
4370 cur_sap_end_ch;
4371 sap_config->acs_cfg.skip_scan_range2_stch =
4372 0;
4373 sap_config->acs_cfg.skip_scan_range2_endch =
4374 0;
4375
4376 } else if (con_sap_st_ch >= cur_sap_st_ch &&
4377 con_sap_end_ch <= cur_sap_end_ch) {
4378 sap_config->acs_cfg.skip_scan_status =
4379 eSAP_DO_PAR_ACS_SCAN;
4380
4381 sap_config->acs_cfg.skip_scan_range1_stch =
4382 cur_sap_st_ch;
4383 sap_config->acs_cfg.skip_scan_range1_endch =
4384 con_sap_st_ch - 1;
4385 sap_config->acs_cfg.skip_scan_range2_stch =
4386 con_sap_end_ch;
4387 sap_config->acs_cfg.skip_scan_range2_endch =
4388 cur_sap_end_ch + 1;
4389
4390 } else
4391 sap_config->acs_cfg.skip_scan_status =
4392 eSAP_DO_NEW_ACS_SCAN;
4393
4394
Dustin Brownbacc48f2018-03-14 14:48:44 -07004395 hdd_debug("SecAP ACS Skip=%d, ACS CH RANGE=%d-%d, %d-%d",
4396 sap_config->acs_cfg.skip_scan_status,
4397 sap_config->acs_cfg.skip_scan_range1_stch,
4398 sap_config->acs_cfg.skip_scan_range1_endch,
4399 sap_config->acs_cfg.skip_scan_range2_stch,
4400 sap_config->acs_cfg.skip_scan_range2_endch);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004401 }
4402 }
4403#endif
4404
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304405 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406}
4407
4408/**
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05304409 * wlan_hdd_sap_p2p_11ac_overrides: API to overwrite 11ac config in case of
4410 * SAP or p2p go
4411 * @ap_adapter: pointer to adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412 *
4413 * This function overrides SAP / P2P Go configuration based on driver INI
4414 * parameters for 11AC override and ACS. This overrides are done to support
4415 * android legacy configuration method.
4416 *
4417 * NOTE: Non android platform supports concurrency and these overrides shall
4418 * not be used. Also future driver based overrides shall be consolidated in this
4419 * function only. Avoid random overrides in other location based on ini.
4420 *
4421 * Return: 0 for Success or Negative error codes.
4422 */
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05304423static int wlan_hdd_sap_p2p_11ac_overrides(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424{
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07004425 struct sap_config *sap_cfg = &ap_adapter->session.ap.sap_config;
Jeff Johnsonc54bbf92017-08-28 11:59:35 -07004426 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304427 uint8_t ch_width;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05304428 uint8_t sub_20_chan_width;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304429 QDF_STATUS status;
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05304430 bool sap_force_11n_for_11ac = 0;
4431 bool go_force_11n_for_11ac = 0;
Wu Gaoed616a12019-01-16 15:19:21 +08004432 uint32_t channel_bonding_mode;
Sandeep Puligilla34618782019-01-04 17:42:42 -08004433 bool go_11ac_override = 0;
4434 bool sap_11ac_override = 0;
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05304435
4436 ucfg_mlme_get_sap_force_11n_for_11ac(hdd_ctx->psoc,
4437 &sap_force_11n_for_11ac);
4438 ucfg_mlme_get_go_force_11n_for_11ac(hdd_ctx->psoc,
4439 &go_force_11n_for_11ac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441 /* Fixed channel 11AC override:
4442 * 11AC override in qcacld is introduced for following reasons:
4443 * 1. P2P GO also follows start_bss and since p2p GO could not be
4444 * configured to setup VHT channel width in wpa_supplicant
4445 * 2. Android UI does not provide advanced configuration options for SAP
4446 *
4447 * Default override enabled (for android). MDM shall disable this in ini
4448 */
Naveen Rawat216605a2017-01-04 16:36:28 -08004449 /*
4450 * sub_20 MHz channel width is incompatible with 11AC rates, hence do
4451 * not allow 11AC rates or more than 20 MHz channel width when
4452 * enable_sub_20_channel_width is non zero
4453 */
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05304454 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
4455 &sub_20_chan_width);
4456 if (QDF_IS_STATUS_ERROR(status)) {
4457 hdd_err("Failed to get sub_20_chan_width config");
4458 return -EIO;
4459 }
4460
Sandeep Puligilla34618782019-01-04 17:42:42 -08004461 ucfg_mlme_is_go_11ac_override(hdd_ctx->psoc,
4462 &go_11ac_override);
4463 ucfg_mlme_is_sap_11ac_override(hdd_ctx->psoc,
4464 &sap_11ac_override);
4465
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05304466 if (!sub_20_chan_width &&
4467 (sap_cfg->SapHw_mode == eCSR_DOT11_MODE_11n ||
4468 sap_cfg->SapHw_mode == eCSR_DOT11_MODE_11ac ||
4469 sap_cfg->SapHw_mode == eCSR_DOT11_MODE_11ac_ONLY ||
4470 sap_cfg->SapHw_mode == eCSR_DOT11_MODE_11ax ||
4471 sap_cfg->SapHw_mode == eCSR_DOT11_MODE_11ax_ONLY) &&
4472 ((ap_adapter->device_mode == QDF_SAP_MODE &&
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05304473 !sap_force_11n_for_11ac &&
Sandeep Puligilla34618782019-01-04 17:42:42 -08004474 sap_11ac_override) ||
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05304475 (ap_adapter->device_mode == QDF_P2P_GO_MODE &&
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05304476 !go_force_11n_for_11ac &&
Sandeep Puligilla34618782019-01-04 17:42:42 -08004477 go_11ac_override))) {
Bala Venkateshb9cf3362017-11-09 15:48:46 +05304478 hdd_debug("** Driver force 11AC override for SAP/Go **");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004479
4480 /* 11n only shall not be overridden since it may be on purpose*/
4481 if (sap_cfg->SapHw_mode == eCSR_DOT11_MODE_11n)
4482 sap_cfg->SapHw_mode = eCSR_DOT11_MODE_11ac;
4483
Abhishek Singh26a7b9f2017-04-06 16:23:05 +05304484 if (sap_cfg->channel >= 36) {
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304485 status =
4486 ucfg_mlme_get_vht_channel_width(hdd_ctx->psoc,
4487 &ch_width);
4488 if (!QDF_IS_STATUS_SUCCESS(status))
4489 hdd_err("Failed to set channel_width");
4490 sap_cfg->ch_width_orig = ch_width;
Abhishek Singh26a7b9f2017-04-06 16:23:05 +05304491 } else {
4492 /*
4493 * Allow 40 Mhz in 2.4 Ghz only if indicated by
4494 * supplicant after OBSS scan and if 2.4 Ghz channel
4495 * bonding is set in INI
4496 */
Wu Gaoed616a12019-01-16 15:19:21 +08004497 ucfg_mlme_get_channel_bonding_24ghz(
4498 hdd_ctx->psoc, &channel_bonding_mode);
Abhishek Singh26a7b9f2017-04-06 16:23:05 +05304499 if (sap_cfg->ch_width_orig >= eHT_CHANNEL_WIDTH_40MHZ &&
Wu Gaoed616a12019-01-16 15:19:21 +08004500 channel_bonding_mode)
Abhishek Singh26a7b9f2017-04-06 16:23:05 +05304501 sap_cfg->ch_width_orig =
4502 eHT_CHANNEL_WIDTH_40MHZ;
4503 else
4504 sap_cfg->ch_width_orig =
4505 eHT_CHANNEL_WIDTH_20MHZ;
4506 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004508
4509 return 0;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05304510}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05304512/**
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05304513 * wlan_hdd_setup_driver_overrides : Overrides SAP / P2P GO Params
4514 * @adapter: pointer to adapter struct
4515 *
4516 * This function overrides SAP / P2P Go configuration based on driver INI
4517 * parameters for 11AC override and ACS. These overrides are done to support
4518 * android legacy configuration method.
4519 *
4520 * NOTE: Non android platform supports concurrency and these overrides shall
4521 * not be used. Also future driver based overrides shall be consolidated in this
4522 * function only. Avoid random overrides in other location based on ini.
4523 *
4524 * Return: 0 for Success or Negative error codes.
4525 */
4526static int wlan_hdd_setup_driver_overrides(struct hdd_adapter *ap_adapter)
4527{
4528 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07004529 QDF_STATUS qdf_status;
4530 bool is_vendor_acs_support =
4531 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05304532
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07004533 qdf_status = ucfg_mlme_get_vendor_acs_support(hdd_ctx->psoc,
4534 &is_vendor_acs_support);
4535 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
4536 hdd_err("get_vendor_acs_support failed, set default");
4537
4538 if (!is_vendor_acs_support)
Himanshu Agarwalad4c0392018-05-08 16:53:36 +05304539 return wlan_hdd_sap_p2p_11ac_overrides(ap_adapter);
4540 else
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05304541 return 0;
4542}
4543
Ashish Kumar Dhanotiyadd5f74c2019-03-14 16:50:41 +05304544void hdd_check_and_disconnect_sta_on_invalid_channel(
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304545 struct hdd_context *hdd_ctx)
4546{
4547 struct hdd_adapter *sta_adapter;
4548 uint8_t sta_chan;
4549
4550 sta_chan = hdd_get_operating_channel(hdd_ctx, QDF_STA_MODE);
4551
4552 if (!sta_chan) {
4553 hdd_err("STA not connected");
4554 return;
4555 }
4556
4557 hdd_err("STA connected on chan %d", sta_chan);
4558
4559 if (sme_is_channel_valid(hdd_ctx->mac_handle, sta_chan)) {
4560 hdd_err("STA connected on chan %d and it is valid", sta_chan);
4561 return;
4562 }
4563
4564 sta_adapter = hdd_get_adapter(hdd_ctx, QDF_STA_MODE);
4565
4566 if (!sta_adapter) {
4567 hdd_err("STA adapter does not exist");
4568 return;
4569 }
4570
4571 hdd_err("chan %d not valid, issue disconnect", sta_chan);
4572 /* Issue Disconnect request */
4573 wlan_hdd_disconnect(sta_adapter, eCSR_DISCONNECT_REASON_DEAUTH);
4574}
4575
4576#ifdef DISABLE_CHANNEL_LIST
4577/**
4578 * wlan_hdd_get_wiphy_channel() - Get wiphy channel
4579 * @wiphy: Pointer to wiphy structure
4580 * @freq: Frequency of the channel for which the wiphy hw value is required
4581 *
4582 * Return: wiphy channel for valid frequency else return NULL
4583 */
4584static struct ieee80211_channel *wlan_hdd_get_wiphy_channel(
4585 struct wiphy *wiphy,
4586 uint32_t freq)
4587{
4588 uint32_t band_num, channel_num;
4589 struct ieee80211_channel *wiphy_channel = NULL;
4590
4591 for (band_num = 0; band_num < HDD_NUM_NL80211_BANDS; band_num++) {
4592 for (channel_num = 0; channel_num <
4593 wiphy->bands[band_num]->n_channels;
4594 channel_num++) {
4595 wiphy_channel = &(wiphy->bands[band_num]->
4596 channels[channel_num]);
4597 if (wiphy_channel->center_freq == freq)
4598 return wiphy_channel;
4599 }
4600 }
4601 return wiphy_channel;
4602}
4603
4604int wlan_hdd_restore_channels(struct hdd_context *hdd_ctx,
4605 bool notify_sap_event)
4606{
4607 struct hdd_cache_channels *cache_chann;
4608 struct wiphy *wiphy;
4609 int freq, status, rf_channel;
4610 int i;
4611 struct ieee80211_channel *wiphy_channel = NULL;
4612
4613 hdd_enter();
4614
4615 if (!hdd_ctx) {
4616 hdd_err("HDD Context is NULL");
4617 return -EINVAL;
4618 }
4619
4620 wiphy = hdd_ctx->wiphy;
4621 if (!wiphy) {
4622 hdd_err("Wiphy is NULL");
4623 return -EINVAL;
4624 }
4625
4626 qdf_mutex_acquire(&hdd_ctx->cache_channel_lock);
4627
4628 cache_chann = hdd_ctx->original_channels;
4629
4630 if (!cache_chann || !cache_chann->num_channels) {
4631 qdf_mutex_release(&hdd_ctx->cache_channel_lock);
4632 hdd_err("channel list is NULL or num channels are zero");
4633 return -EINVAL;
4634 }
4635
4636 for (i = 0; i < cache_chann->num_channels; i++) {
Ashish Kumar Dhanotiyaaa9fdbb2018-12-14 15:29:14 +05304637 freq = wlan_reg_chan_to_freq(
Dustin Brown07901ec2018-09-07 11:02:41 -07004638 hdd_ctx->pdev,
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304639 cache_chann->channel_info[i].channel_num);
4640 if (!freq)
4641 continue;
4642
4643 wiphy_channel = wlan_hdd_get_wiphy_channel(wiphy, freq);
4644 if (!wiphy_channel)
4645 continue;
4646 rf_channel = wiphy_channel->hw_value;
4647 /*
4648 * Restore the orginal states of the channels
4649 * only if we have cached non zero values
4650 */
Ashish Kumar Dhanotiyadd5f74c2019-03-14 16:50:41 +05304651 wiphy_channel->flags =
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304652 cache_chann->channel_info[i].wiphy_status;
Ashish Kumar Dhanotiyadd5f74c2019-03-14 16:50:41 +05304653
4654 hdd_debug("Restore channel %d reg_stat %d wiphy_stat 0x%x",
4655 cache_chann->channel_info[i].channel_num,
4656 cache_chann->channel_info[i].reg_status,
4657 wiphy_channel->flags);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304658 }
4659
4660 qdf_mutex_release(&hdd_ctx->cache_channel_lock);
4661 if (notify_sap_event)
Dustin Brown07901ec2018-09-07 11:02:41 -07004662 ucfg_reg_notify_sap_event(hdd_ctx->pdev, false);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304663 else
Dustin Brown07901ec2018-09-07 11:02:41 -07004664 ucfg_reg_restore_cached_channels(hdd_ctx->pdev);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304665 status = sme_update_channel_list(hdd_ctx->mac_handle);
4666 if (status)
4667 hdd_err("Can't Restore channel list");
4668 hdd_exit();
4669
4670 return 0;
4671}
4672
Ashish Kumar Dhanotiyadd5f74c2019-03-14 16:50:41 +05304673int wlan_hdd_disable_channels(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304674{
4675 struct hdd_cache_channels *cache_chann;
4676 struct wiphy *wiphy;
4677 int freq, status, rf_channel;
4678 int i;
4679 struct ieee80211_channel *wiphy_channel = NULL;
4680
4681 hdd_enter();
4682
4683 if (!hdd_ctx) {
4684 hdd_err("HDD Context is NULL");
4685 return -EINVAL;
4686 }
4687
4688 wiphy = hdd_ctx->wiphy;
4689 if (!wiphy) {
4690 hdd_err("Wiphy is NULL");
4691 return -EINVAL;
4692 }
4693
4694 qdf_mutex_acquire(&hdd_ctx->cache_channel_lock);
4695 cache_chann = hdd_ctx->original_channels;
4696
4697 if (!cache_chann || !cache_chann->num_channels) {
4698 qdf_mutex_release(&hdd_ctx->cache_channel_lock);
4699 hdd_err("channel list is NULL or num channels are zero");
4700 return -EINVAL;
4701 }
4702
4703 for (i = 0; i < cache_chann->num_channels; i++) {
Ashish Kumar Dhanotiyaaa9fdbb2018-12-14 15:29:14 +05304704 freq = wlan_reg_chan_to_freq(hdd_ctx->pdev,
4705 cache_chann->
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304706 channel_info[i].channel_num);
4707 if (!freq)
4708 continue;
4709 wiphy_channel = wlan_hdd_get_wiphy_channel(wiphy, freq);
4710 if (!wiphy_channel)
4711 continue;
4712 rf_channel = wiphy_channel->hw_value;
4713 /*
4714 * Cache the current states of
4715 * the channels
4716 */
4717 cache_chann->channel_info[i].reg_status =
Ashish Kumar Dhanotiyaaa9fdbb2018-12-14 15:29:14 +05304718 wlan_reg_get_channel_state(
Dustin Brown07901ec2018-09-07 11:02:41 -07004719 hdd_ctx->pdev,
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304720 rf_channel);
4721 cache_chann->channel_info[i].wiphy_status =
4722 wiphy_channel->flags;
4723 hdd_debug("Disable channel %d reg_stat %d wiphy_stat 0x%x",
4724 cache_chann->channel_info[i].channel_num,
4725 cache_chann->channel_info[i].reg_status,
4726 wiphy_channel->flags);
4727
4728 wiphy_channel->flags |= IEEE80211_CHAN_DISABLED;
4729 }
4730
4731 qdf_mutex_release(&hdd_ctx->cache_channel_lock);
Dustin Brown07901ec2018-09-07 11:02:41 -07004732 status = ucfg_reg_notify_sap_event(hdd_ctx->pdev, true);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304733 status = sme_update_channel_list(hdd_ctx->mac_handle);
4734
4735 hdd_exit();
4736 return status;
4737}
4738#else
Ashish Kumar Dhanotiyadd5f74c2019-03-14 16:50:41 +05304739int wlan_hdd_disable_channels(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05304740{
4741 return 0;
4742}
4743
4744int wlan_hdd_restore_channels(struct hdd_context *hdd_ctx,
4745 bool notify_sap_event)
4746{
4747 return 0;
4748}
4749#endif
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304750
Jeff Johnsone77641e2019-02-15 09:00:41 -08004751#ifdef DHCP_SERVER_OFFLOAD
4752static void wlan_hdd_set_dhcp_server_offload(struct hdd_adapter *adapter)
4753{
4754 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004755 struct dhcp_offload_info_params dhcp_srv_info;
4756 uint8_t num_entries = 0;
gaurank kathpalia566c81b2019-02-20 14:31:45 +05304757 uint8_t *srv_ip;
Jeff Johnsone77641e2019-02-15 09:00:41 -08004758 uint8_t num;
4759 uint32_t temp;
4760 uint32_t dhcp_max_num_clients;
4761 mac_handle_t mac_handle;
4762 QDF_STATUS status;
4763
gaurank kathpalia566c81b2019-02-20 14:31:45 +05304764 if (!hdd_ctx->config->dhcp_server_ip.is_dhcp_server_ip_valid)
4765 return;
4766
4767 srv_ip = hdd_ctx->config->dhcp_server_ip.dhcp_server_ip;
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004768 dhcp_srv_info.vdev_id = adapter->vdev_id;
4769 dhcp_srv_info.dhcp_offload_enabled = true;
Jeff Johnsone77641e2019-02-15 09:00:41 -08004770
4771 status = ucfg_fwol_get_dhcp_max_num_clients(hdd_ctx->psoc,
4772 &dhcp_max_num_clients);
4773 if (QDF_IS_STATUS_ERROR(status))
4774 return;
4775
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004776 dhcp_srv_info.dhcp_client_num = dhcp_max_num_clients;
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004777
Jeff Johnsone77641e2019-02-15 09:00:41 -08004778 if ((srv_ip[0] >= 224) && (srv_ip[0] <= 239)) {
gaurank kathpalia566c81b2019-02-20 14:31:45 +05304779 hdd_err("Invalid IP address (%d)! It could NOT be multicast IP address!",
4780 srv_ip[0]);
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004781 return;
Jeff Johnsone77641e2019-02-15 09:00:41 -08004782 }
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004783
Jeff Johnsone77641e2019-02-15 09:00:41 -08004784 if (srv_ip[IPADDR_NUM_ENTRIES - 1] >= 100) {
gaurank kathpalia566c81b2019-02-20 14:31:45 +05304785 hdd_err("Invalid IP address (%d)! The last field must be less than 100!",
4786 srv_ip[IPADDR_NUM_ENTRIES - 1]);
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004787 return;
Jeff Johnsone77641e2019-02-15 09:00:41 -08004788 }
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004789
4790 dhcp_srv_info.dhcp_srv_addr = 0;
4791 for (num = 0; num < num_entries; num++) {
Jeff Johnsone77641e2019-02-15 09:00:41 -08004792 temp = srv_ip[num];
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004793 dhcp_srv_info.dhcp_srv_addr |= (temp << (8 * num));
Jeff Johnsone77641e2019-02-15 09:00:41 -08004794 }
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004795
Jeff Johnsone77641e2019-02-15 09:00:41 -08004796 mac_handle = hdd_ctx->mac_handle;
Jeff Johnson8bfc29e2019-02-15 07:58:15 -08004797 status = sme_set_dhcp_srv_offload(mac_handle, &dhcp_srv_info);
4798 if (QDF_IS_STATUS_SUCCESS(status))
4799 hdd_debug("enable DHCP Server offload successfully!");
4800 else
4801 hdd_err("sme_set_dhcp_srv_offload fail!");
Jeff Johnsone77641e2019-02-15 09:00:41 -08004802}
4803
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304804/**
Jeff Johnsone77641e2019-02-15 09:00:41 -08004805 * wlan_hdd_dhcp_offload_enable: Enable DHCP offload
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304806 * @hdd_ctx: HDD context handler
4807 * @adapter: Adapter pointer
4808 *
Jeff Johnsone77641e2019-02-15 09:00:41 -08004809 * Enables the DHCP Offload feature in firmware if it has been configured.
4810 *
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304811 * Return: None
4812 */
Jeff Johnsone77641e2019-02-15 09:00:41 -08004813static void wlan_hdd_dhcp_offload_enable(struct hdd_context *hdd_ctx,
4814 struct hdd_adapter *adapter)
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304815{
4816 bool enable_dhcp_server_offload;
4817 QDF_STATUS status;
4818
4819 status = ucfg_fwol_get_enable_dhcp_server_offload(
4820 hdd_ctx->psoc,
4821 &enable_dhcp_server_offload);
4822 if (QDF_IS_STATUS_ERROR(status))
4823 return;
4824
4825 if (enable_dhcp_server_offload)
4826 wlan_hdd_set_dhcp_server_offload(adapter);
4827}
4828#else
Jeff Johnsone77641e2019-02-15 09:00:41 -08004829static void wlan_hdd_dhcp_offload_enable(struct hdd_context *hdd_ctx,
4830 struct hdd_adapter *adapter)
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304831{
4832}
Jeff Johnsone77641e2019-02-15 09:00:41 -08004833#endif /* DHCP_SERVER_OFFLOAD */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304834
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004835#ifdef WLAN_CONV_CRYPTO_SUPPORTED
4836/**
4837 * hdd_set_vdev_crypto_prarams_from_ie - Sets vdev crypto params from IE info
4838 * @vdev: vdev pointer
4839 * @ie_ptr: pointer to IE
4840 * @ie_len: IE length
4841 *
4842 * Return: QDF_STATUS_SUCCESS or error code
4843 */
4844static QDF_STATUS
4845hdd_set_vdev_crypto_prarams_from_ie(struct wlan_objmgr_vdev *vdev,
4846 uint8_t *ie_ptr, uint16_t ie_len)
4847{
4848 return wlan_set_vdev_crypto_prarams_from_ie(vdev, ie_ptr, ie_len);
4849}
4850#else
4851static QDF_STATUS
4852hdd_set_vdev_crypto_prarams_from_ie(struct wlan_objmgr_vdev *vdev,
4853 uint8_t *ie_ptr, uint16_t ie_len)
4854{
4855 return QDF_STATUS_SUCCESS;
4856}
4857#endif
4858
Krunal Sonid2c33e12018-12-06 15:02:37 -08004859#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
4860static void wlan_hdd_set_sap_mcc_chnl_avoid(struct hdd_context *hdd_ctx)
4861{
4862 uint8_t sap_mcc_avoid = 0;
jiada6df1a32018-12-07 11:57:26 +08004863 QDF_STATUS status;
Krunal Sonid2c33e12018-12-06 15:02:37 -08004864
4865 status = ucfg_mlme_get_sap_mcc_chnl_avoid(hdd_ctx->psoc,
4866 &sap_mcc_avoid);
4867 if (!QDF_IS_STATUS_SUCCESS(status))
4868 hdd_err("can't get sap mcc chnl avoid, use def");
4869 wlan_sap_set_channel_avoidance(hdd_ctx->mac_handle, sap_mcc_avoid);
4870}
4871#else
4872static void wlan_hdd_set_sap_mcc_chnl_avoid(struct hdd_context *hdd_ctx)
4873{
4874}
4875#endif
4876
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05304877/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004878 * wlan_hdd_cfg80211_start_bss() - start bss
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004879 * @adapter: Pointer to hostapd adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004880 * @params: Pointer to start bss beacon parameters
4881 * @ssid: Pointer ssid
4882 * @ssid_len: Length of ssid
4883 * @hidden_ssid: Hidden SSID parameter
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304884 * @check_for_concurrency: Flag to indicate if check for concurrency is needed
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 *
4886 * Return: 0 for success non-zero for failure
4887 */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004888int wlan_hdd_cfg80211_start_bss(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889 struct cfg80211_beacon_data *params,
4890 const u8 *ssid, size_t ssid_len,
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304891 enum nl80211_hidden_ssid hidden_ssid,
Mahesh Kumar Kalikot Veetilc637fc92017-09-27 16:06:21 -07004892 bool check_for_concurrency)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893{
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07004894 struct sap_config *config;
Jeff Johnsond5777132019-02-11 09:55:56 -08004895 struct hdd_beacon_data *beacon = NULL;
Jeff Johnsonc6c35e32019-03-10 18:32:38 -07004896 struct ieee80211_mgmt *mgmt_frame;
Dundi Raviteja5296f492018-11-12 17:51:37 +05304897 struct ieee80211_mgmt mgmt;
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08004898 const uint8_t *ie = NULL;
Jeff Johnson51203af2019-03-09 18:38:09 -08004899 eCsrEncryptionType rsn_encrypt_type;
4900 eCsrEncryptionType mc_rsn_encrypt_type;
Harprit Chhabadaa9ff69c2019-03-11 15:03:02 -07004901 uint16_t capab_info;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304902 int status = QDF_STATUS_SUCCESS, ret;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304903 int qdf_status = QDF_STATUS_SUCCESS;
Jeff Johnson7dcac7e2019-03-23 15:10:06 -07004904 sap_event_cb sap_event_callback;
Jeff Johnson5c19ade2017-10-04 09:52:12 -07004905 struct hdd_hostapd_state *hostapd_state;
Jeff Johnson89a0c742018-06-12 18:17:46 -07004906 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004907 int32_t i;
Min Liuddd23302018-12-05 16:17:48 +08004908 uint32_t ii;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004909 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonid7ef8632018-09-27 11:17:33 -07004910 uint8_t mcc_to_scc_switch = 0, conc_rule1 = 0;
Jeff Johnson46b4f0e2019-03-08 10:48:35 -08004911 struct sme_config_params *sme_config;
Jeff Johnson7e6f2912019-03-09 19:32:49 -08004912 bool mfp_capable = false;
Jeff Johnsonc17b9002019-03-09 19:35:06 -08004913 bool mfp_required = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914 uint16_t prev_rsn_length = 0;
Agrawal Ashish65634612016-08-18 13:24:32 +05304915 enum dfs_mode mode;
Arif Hussain224d3812018-11-16 17:58:38 -08004916 bool ignore_cac = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -08004917 uint8_t is_overlap_enable = 0, scc_on_dfs_chan = 0;
4918 uint8_t beacon_fixed_len, indoor_chnl_marking = 0;
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05304919 bool sap_force_11n_for_11ac = 0;
4920 bool go_force_11n_for_11ac = 0;
Harprit Chhabadaa9ff69c2019-03-11 15:03:02 -07004921 bool bval = false;
gaurank kathpalia97c070b2019-01-07 17:23:06 +05304922 bool enable_dfs_scan = true;
Agrawal Ashish65634612016-08-18 13:24:32 +05304923
Dustin Brown491d54b2018-03-14 12:39:11 -07004924 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004925
Dustin Brown89fa06e2018-09-07 10:47:27 -07004926 hdd_notify_teardown_tdls_links(adapter->vdev);
Kabilan Kannan1c1c4022017-04-06 22:49:26 -07004927
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05304928 ucfg_mlme_get_sap_force_11n_for_11ac(hdd_ctx->psoc,
4929 &sap_force_11n_for_11ac);
4930 ucfg_mlme_get_go_force_11n_for_11ac(hdd_ctx->psoc,
4931 &go_force_11n_for_11ac);
4932
Dustin Brown1dbefe62018-09-11 16:32:03 -07004933 if (policy_mgr_is_hw_mode_change_in_progress(hdd_ctx->psoc)) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004934 status = policy_mgr_wait_for_connection_update(
Dustin Brown1dbefe62018-09-11 16:32:03 -07004935 hdd_ctx->psoc);
Nitesh Shaha3dfea32017-02-09 19:18:57 +05304936 if (!QDF_IS_STATUS_SUCCESS(status)) {
4937 hdd_err("qdf wait for event failed!!");
4938 return -EINVAL;
4939 }
4940 }
4941
Himanshu Agarwal6c3607a2018-01-12 12:04:19 +05304942 /*
4943 * For STA+SAP concurrency support from GUI, first STA connection gets
4944 * triggered and while it is in progress, SAP start also comes up.
4945 * Once STA association is successful, STA connect event is sent to
4946 * kernel which gets queued in kernel workqueue and supplicant won't
4947 * process M1 received from AP and send M2 until this NL80211_CONNECT
4948 * event is received. Workqueue is not scheduled as RTNL lock is already
4949 * taken by hostapd thread which has issued start_bss command to driver.
4950 * Driver cannot complete start_bss as the pending command at the head
4951 * of the SME command pending list is hw_mode_update for STA session
4952 * which cannot be processed as SME is in WAITforKey state for STA
4953 * interface. The start_bss command for SAP interface is queued behind
4954 * the hw_mode_update command and so it cannot be processed until
4955 * hw_mode_update command is processed. This is causing a deadlock so
4956 * disconnect the STA interface first if connection or key exchange is
4957 * in progress and then start SAP interface.
4958 */
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05304959 hdd_abort_ongoing_sta_connection(hdd_ctx);
Himanshu Agarwal6c3607a2018-01-12 12:04:19 +05304960
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +05304961 /*
4962 * Reject start bss if reassoc in progress on any adapter.
4963 * sme_is_any_session_in_middle_of_roaming is for LFR2 and
4964 * hdd_is_roaming_in_progress is for LFR3
4965 */
Jeff Johnson89a0c742018-06-12 18:17:46 -07004966 mac_handle = hdd_ctx->mac_handle;
4967 if (sme_is_any_session_in_middle_of_roaming(mac_handle) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +05304968 hdd_is_roaming_in_progress(hdd_ctx)) {
4969 hdd_info("Reassociation in progress");
4970 return -EINVAL;
4971 }
4972
4973 /* Disable Roaming on all adapters before starting bss */
4974 wlan_hdd_disable_roaming(adapter);
4975
Sridhar Selvaraj48c47092017-07-31 18:18:14 +05304976 sme_config = qdf_mem_malloc(sizeof(*sme_config));
4977 if (!sme_config) {
4978 hdd_err("failed to allocate memory");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +05304979 ret = -ENOMEM;
4980 goto free;
Sridhar Selvaraj48c47092017-07-31 18:18:14 +05304981 }
4982
Jeff Johnson5c19ade2017-10-04 09:52:12 -07004983 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004984
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004985 clear_bit(ACS_PENDING, &adapter->event_flags);
Jeff Johnson23c3b842017-09-03 09:05:29 -07004986 clear_bit(ACS_IN_PROGRESS, &hdd_ctx->g_event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004987
Jeff Johnson954903d2019-03-07 20:41:27 -08004988 config = &adapter->session.ap.sap_config;
4989 if (!config->channel) {
Abhishek Singh53791fa2018-06-14 14:02:50 +05304990 hdd_err("Invalid channel");
4991 ret = -EINVAL;
4992 goto free;
4993 }
4994
Krunal Sonidf29bc42018-11-15 13:26:29 -08004995 if (QDF_STATUS_SUCCESS !=
4996 ucfg_policy_mgr_get_indoor_chnl_marking(hdd_ctx->psoc,
4997 &indoor_chnl_marking))
4998 hdd_err("can't get indoor channel marking, using default");
Mukul Sharmaecf8e092017-12-19 22:36:31 +05304999 /* Mark the indoor channel (passive) to disable */
Sourav Mohapatrafec6d6c2018-12-28 10:23:49 +05305000 if (indoor_chnl_marking && adapter->device_mode == QDF_SAP_MODE) {
Mukul Sharmaecf8e092017-12-19 22:36:31 +05305001 hdd_update_indoor_channel(hdd_ctx, true);
5002 if (QDF_IS_STATUS_ERROR(
Jeff Johnson89a0c742018-06-12 18:17:46 -07005003 sme_update_channel_list(mac_handle))) {
Mukul Sharmaecf8e092017-12-19 22:36:31 +05305004 hdd_update_indoor_channel(hdd_ctx, false);
5005 hdd_err("Can't start BSS: update channel list failed");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +05305006 ret = -EINVAL;
5007 goto free;
Mukul Sharmaecf8e092017-12-19 22:36:31 +05305008 }
Yeshwanth Sriram Guntuka1c555fc2018-02-14 14:57:35 +05305009
5010 /* check if STA is on indoor channel*/
5011 if (policy_mgr_is_force_scc(hdd_ctx->psoc))
5012 hdd_check_and_disconnect_sta_on_invalid_channel(
5013 hdd_ctx);
Mukul Sharmaecf8e092017-12-19 22:36:31 +05305014 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005015
Jeff Johnsond5777132019-02-11 09:55:56 -08005016 beacon = adapter->session.ap.beacon;
Dundi Raviteja5296f492018-11-12 17:51:37 +05305017
5018 /*
5019 * beacon_fixed_len is the fixed length of beacon
5020 * frame which includes only mac header length and
5021 * beacon manadatory fields like timestamp,
5022 * beacon_int and capab_info.
5023 * (From the reference of struct ieee80211_mgmt)
5024 */
5025 beacon_fixed_len = sizeof(mgmt) - sizeof(mgmt.u) +
5026 sizeof(mgmt.u.beacon);
Jeff Johnsond5777132019-02-11 09:55:56 -08005027 if (beacon->head_len < beacon_fixed_len) {
Dundi Raviteja5296f492018-11-12 17:51:37 +05305028 hdd_err("Invalid beacon head len");
5029 ret = -EINVAL;
5030 goto error;
5031 }
5032
Jeff Johnsonc6c35e32019-03-10 18:32:38 -07005033 mgmt_frame = (struct ieee80211_mgmt *)beacon->head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034
Jeff Johnsonc6c35e32019-03-10 18:32:38 -07005035 config->beacon_int = mgmt_frame->u.beacon.beacon_int;
Jeff Johnson954903d2019-03-07 20:41:27 -08005036 config->dfs_cac_offload = hdd_ctx->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005037
Krunal Sonidf29bc42018-11-15 13:26:29 -08005038 status = ucfg_policy_mgr_get_enable_overlap_chnl(hdd_ctx->psoc,
5039 &is_overlap_enable);
5040 if (!QDF_IS_STATUS_SUCCESS(status))
5041 hdd_err("can't get overlap channel INI value, using default");
Jeff Johnson954903d2019-03-07 20:41:27 -08005042 config->enOverLapCh = is_overlap_enable;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305043
Jeff Johnson954903d2019-03-07 20:41:27 -08005044 config->dtim_period = beacon->dtim_period;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305045
Jeff Johnson954903d2019-03-07 20:41:27 -08005046 hdd_debug("acs_mode %d", config->acs_cfg.acs_mode);
Kondabattini, Ganeshc846f3a2016-10-05 15:01:18 +05305047
Jeff Johnson954903d2019-03-07 20:41:27 -08005048 if (config->acs_cfg.acs_mode == true) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08005049 hdd_debug("acs_channel %d, acs_dfs_mode %d",
Jeff Johnson23c3b842017-09-03 09:05:29 -07005050 hdd_ctx->acs_policy.acs_channel,
5051 hdd_ctx->acs_policy.acs_dfs_mode);
Kondabattini, Ganeshc846f3a2016-10-05 15:01:18 +05305052
Jeff Johnson23c3b842017-09-03 09:05:29 -07005053 if (hdd_ctx->acs_policy.acs_channel)
Jeff Johnson954903d2019-03-07 20:41:27 -08005054 config->channel = hdd_ctx->acs_policy.acs_channel;
Jeff Johnson23c3b842017-09-03 09:05:29 -07005055 mode = hdd_ctx->acs_policy.acs_dfs_mode;
Jeff Johnson954903d2019-03-07 20:41:27 -08005056 config->acs_dfs_mode = wlan_hdd_get_dfs_mode(mode);
Kondabattini, Ganeshc846f3a2016-10-05 15:01:18 +05305057 }
5058
Dustin Brown1dbefe62018-09-11 16:32:03 -07005059 policy_mgr_update_user_config_sap_chan(hdd_ctx->psoc,
Jeff Johnson954903d2019-03-07 20:41:27 -08005060 config->channel);
5061 hdd_debug("config->channel %d, config->acs_dfs_mode %d",
5062 config->channel, config->acs_dfs_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005063
Jeff Johnson954903d2019-03-07 20:41:27 -08005064 hdd_debug("****config->dtim_period=%d***",
5065 config->dtim_period);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005066
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005067 if (adapter->device_mode == QDF_SAP_MODE) {
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005068 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_COUNTRY,
5069 beacon->tail, beacon->tail_len);
5070 if (ie) {
5071 if (ie[1] < IEEE80211_COUNTRY_IE_MIN_LEN) {
5072 hdd_err("Invalid Country IE len: %d", ie[1]);
Nachiket Kukadee24c4922017-11-29 15:06:20 +05305073 ret = -EINVAL;
5074 goto error;
5075 }
5076
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005077 if (!qdf_mem_cmp(hdd_ctx->reg.alpha2, &ie[2],
Amar Singhal05b103f2018-11-30 11:34:13 -08005078 REG_ALPHA2_LEN))
Jeff Johnson954903d2019-03-07 20:41:27 -08005079 config->ieee80211d = 1;
Amar Singhal05b103f2018-11-30 11:34:13 -08005080 else
Jeff Johnson954903d2019-03-07 20:41:27 -08005081 config->ieee80211d = 0;
Amar Singhal05b103f2018-11-30 11:34:13 -08005082 } else
Jeff Johnson954903d2019-03-07 20:41:27 -08005083 config->ieee80211d = 0;
Amar Singhal05b103f2018-11-30 11:34:13 -08005084
Jeff Johnson954903d2019-03-07 20:41:27 -08005085 config->countryCode[0] = hdd_ctx->reg.alpha2[0];
5086 config->countryCode[1] = hdd_ctx->reg.alpha2[1];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005087
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005088 ret = wlan_hdd_sap_cfg_dfs_override(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07005089 if (ret < 0)
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305090 goto error;
Dustin Brown07901ec2018-09-07 11:02:41 -07005091
Jeff Johnson954903d2019-03-07 20:41:27 -08005092 if (!ret && wlan_reg_is_dfs_ch(hdd_ctx->pdev, config->channel))
Dustin Brown07901ec2018-09-07 11:02:41 -07005093 hdd_ctx->dev_dfs_cac_status = DFS_CAC_NEVER_DONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094
Abhishek Singh53791fa2018-06-14 14:02:50 +05305095 if (QDF_STATUS_SUCCESS !=
5096 wlan_hdd_validate_operation_channel(adapter,
Jeff Johnson954903d2019-03-07 20:41:27 -08005097 config->channel)) {
5098 hdd_err("Invalid Channel: %d", config->channel);
Abhishek Singh53791fa2018-06-14 14:02:50 +05305099 ret = -EINVAL;
5100 goto error;
5101 }
gaurank kathpalia97c070b2019-01-07 17:23:06 +05305102 ucfg_scan_cfg_get_dfs_chan_scan_allowed(hdd_ctx->psoc,
5103 &enable_dfs_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005104
Abhishek Singh53791fa2018-06-14 14:02:50 +05305105 /* reject SAP if DFS channel scan is not allowed */
gaurank kathpalia97c070b2019-01-07 17:23:06 +05305106 if (!(enable_dfs_scan) &&
Abhishek Singh53791fa2018-06-14 14:02:50 +05305107 (CHANNEL_STATE_DFS ==
Dustin Brown07901ec2018-09-07 11:02:41 -07005108 wlan_reg_get_channel_state(hdd_ctx->pdev,
Jeff Johnson954903d2019-03-07 20:41:27 -08005109 config->channel))) {
Abhishek Singh53791fa2018-06-14 14:02:50 +05305110 hdd_err("No SAP start on DFS channel");
5111 ret = -EOPNOTSUPP;
5112 goto error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113 }
Bala Venkatesh5479cf82018-06-09 20:02:38 +05305114
Krunal Sonidf29bc42018-11-15 13:26:29 -08005115 status = ucfg_mlme_get_dfs_ignore_cac(hdd_ctx->psoc,
5116 &ignore_cac);
5117 if (!QDF_IS_STATUS_SUCCESS(status))
5118 hdd_err("can't get sta-sap scc on dfs chnl, use def");
5119 status =
5120 ucfg_policy_mgr_get_sta_sap_scc_on_dfs_chnl(hdd_ctx->psoc,
5121 &scc_on_dfs_chan);
5122
5123 if (!QDF_IS_STATUS_SUCCESS(status))
5124 hdd_err("can't get sta-sap scc on dfs chnl, use def");
5125
Harprit Chhabadaa9ff69c2019-03-11 15:03:02 -07005126 ucfg_policy_mgr_get_mcc_scc_switch(hdd_ctx->psoc,
5127 &mcc_to_scc_switch);
Arif Hussain224d3812018-11-16 17:58:38 -08005128 if (ignore_cac ||
Krunal Soni5e3f9622018-09-26 16:35:50 -07005129 ((mcc_to_scc_switch != QDF_MCC_TO_SCC_SWITCH_DISABLE) &&
Krunal Sonidf29bc42018-11-15 13:26:29 -08005130 scc_on_dfs_chan))
Bala Venkatesh5479cf82018-06-09 20:02:38 +05305131 ignore_cac = 1;
5132
5133 wlansap_set_dfs_ignore_cac(mac_handle, ignore_cac);
Harprit Chhabadabe221e62019-03-27 13:28:58 -07005134
5135 wlansap_set_dfs_preferred_channel_location(mac_handle);
5136
Krunal Sonid2c33e12018-12-06 15:02:37 -08005137 wlan_hdd_set_sap_mcc_chnl_avoid(hdd_ctx);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005138 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson954903d2019-03-07 20:41:27 -08005139 config->countryCode[0] = hdd_ctx->reg.alpha2[0];
5140 config->countryCode[1] = hdd_ctx->reg.alpha2[1];
5141 config->ieee80211d = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 } else {
Jeff Johnson954903d2019-03-07 20:41:27 -08005143 config->ieee80211d = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005144 }
5145
Harprit Chhabadaa9ff69c2019-03-11 15:03:02 -07005146 tgt_dfs_set_tx_leakage_threshold(hdd_ctx->pdev);
Yingying Tangb4832f72016-10-20 13:44:55 +08005147
Jeff Johnsonc6c35e32019-03-10 18:32:38 -07005148 capab_info = mgmt_frame->u.beacon.capab_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149
Jeff Johnsonc6c35e32019-03-10 18:32:38 -07005150 config->privacy = (mgmt_frame->u.beacon.capab_info &
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005151 WLAN_CAPABILITY_PRIVACY) ? true : false;
5152
Jeff Johnson954903d2019-03-07 20:41:27 -08005153 (WLAN_HDD_GET_AP_CTX_PTR(adapter))->privacy = config->privacy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005154
5155 /*Set wps station to configured */
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005156 ie = wlan_hdd_get_wps_ie_ptr(beacon->tail, beacon->tail_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005158 if (ie) {
5159 /* To access ie[15], length needs to be at least 14 */
5160 if (ie[1] < 14) {
Hanumanth Reddy Pothula04bad8f2018-06-13 18:32:02 +05305161 hdd_err("**Wps Ie Length(%hhu) is too small***",
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005162 ie[1]);
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305163 ret = -EINVAL;
5164 goto error;
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005165 } else if (memcmp(&ie[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166 0) {
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005167 hdd_debug("** WPS IE(len %d) ***", (ie[1] + 2));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005168 /* Check 15 bit of WPS IE as it contain information for
5169 * wps state
5170 */
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005171 if (SAP_WPS_ENABLED_UNCONFIGURED == ie[15]) {
Jeff Johnson954903d2019-03-07 20:41:27 -08005172 config->wps_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005173 SAP_WPS_ENABLED_UNCONFIGURED;
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005174 } else if (SAP_WPS_ENABLED_CONFIGURED == ie[15]) {
Jeff Johnson954903d2019-03-07 20:41:27 -08005175 config->wps_state = SAP_WPS_ENABLED_CONFIGURED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 }
5177 }
5178 } else {
Srinivas Girigowda55756882017-03-06 16:45:27 -08005179 hdd_debug("WPS disabled");
Jeff Johnson954903d2019-03-07 20:41:27 -08005180 config->wps_state = SAP_WPS_DISABLED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 }
5182 /* Forward WPS PBC probe request frame up */
Jeff Johnson954903d2019-03-07 20:41:27 -08005183 config->fwdWPSPBCProbeReq = 1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005184
Jeff Johnson954903d2019-03-07 20:41:27 -08005185 config->RSNEncryptType = eCSR_ENCRYPT_TYPE_NONE;
5186 config->mcRSNEncryptType = eCSR_ENCRYPT_TYPE_NONE;
Jeff Johnsona8e686b2017-10-27 15:05:18 -07005187 (WLAN_HDD_GET_AP_CTX_PTR(adapter))->encryption_type =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 eCSR_ENCRYPT_TYPE_NONE;
5189
Jeff Johnson954903d2019-03-07 20:41:27 -08005190 config->RSNWPAReqIELength = 0;
5191 memset(&config->RSNWPAReqIE[0], 0, sizeof(config->RSNWPAReqIE));
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005192 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_RSN, beacon->tail,
5193 beacon->tail_len);
5194 if (ie && ie[1]) {
5195 config->RSNWPAReqIELength = ie[1] + 2;
Jeff Johnson954903d2019-03-07 20:41:27 -08005196 if (config->RSNWPAReqIELength < sizeof(config->RSNWPAReqIE))
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005197 memcpy(&config->RSNWPAReqIE[0], ie,
Jeff Johnson954903d2019-03-07 20:41:27 -08005198 config->RSNWPAReqIELength);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 else
Jeff Johnsonecd884e2016-06-30 14:52:25 -07005200 hdd_err("RSNWPA IE MAX Length exceeded; length =%d",
Jeff Johnson954903d2019-03-07 20:41:27 -08005201 config->RSNWPAReqIELength);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202 /* The actual processing may eventually be more extensive than
Jeff Johnsond3919a92017-01-12 09:47:22 -08005203 * this. Right now, just consume any PMKIDs that are sent in
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005204 * by the app.
Jeff Johnsond3919a92017-01-12 09:47:22 -08005205 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005206 status =
5207 hdd_softap_unpack_ie(cds_get_context
Anurag Chouhan6d760662016-02-20 16:05:43 +05305208 (QDF_MODULE_ID_SME),
Jeff Johnson51203af2019-03-09 18:38:09 -08005209 &rsn_encrypt_type,
5210 &mc_rsn_encrypt_type,
Jeff Johnson954903d2019-03-07 20:41:27 -08005211 &config->akm_list,
Jeff Johnson7e6f2912019-03-09 19:32:49 -08005212 &mfp_capable,
Jeff Johnsonc17b9002019-03-09 19:35:06 -08005213 &mfp_required,
Jeff Johnson954903d2019-03-07 20:41:27 -08005214 config->RSNWPAReqIE[1] + 2,
5215 config->RSNWPAReqIE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305217 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 /* Now copy over all the security attributes you have
5219 * parsed out. Use the cipher type in the RSN IE
5220 */
Jeff Johnson51203af2019-03-09 18:38:09 -08005221 config->RSNEncryptType = rsn_encrypt_type;
5222 config->mcRSNEncryptType = mc_rsn_encrypt_type;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005223 (WLAN_HDD_GET_AP_CTX_PTR(adapter))->
Jeff Johnson51203af2019-03-09 18:38:09 -08005224 encryption_type = rsn_encrypt_type;
Min Liuddd23302018-12-05 16:17:48 +08005225 hdd_debug("CSR EncryptionType = %d mcEncryptionType = %d",
Jeff Johnson51203af2019-03-09 18:38:09 -08005226 rsn_encrypt_type, mc_rsn_encrypt_type);
Min Liuddd23302018-12-05 16:17:48 +08005227 hdd_debug("CSR AKM Suites %d",
Jeff Johnson954903d2019-03-07 20:41:27 -08005228 config->akm_list.numEntries);
5229 for (ii = 0; ii < config->akm_list.numEntries;
Min Liuddd23302018-12-05 16:17:48 +08005230 ii++)
5231 hdd_debug("CSR AKM Suite [%d] = %d", ii,
Jeff Johnson954903d2019-03-07 20:41:27 -08005232 config->akm_list.authType[ii]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233 }
5234 }
5235
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005236 ie = wlan_get_vendor_ie_ptr_from_oui(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
Jeff Johnsond5777132019-02-11 09:55:56 -08005237 beacon->tail, beacon->tail_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005238
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005239 if (ie && ie[1] && (ie[0] == DOT11F_EID_WPA)) {
Jeff Johnson954903d2019-03-07 20:41:27 -08005240 if (config->RSNWPAReqIE[0]) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 /*Mixed mode WPA/WPA2 */
Jeff Johnson954903d2019-03-07 20:41:27 -08005242 prev_rsn_length = config->RSNWPAReqIELength;
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005243 config->RSNWPAReqIELength += ie[1] + 2;
Jeff Johnson954903d2019-03-07 20:41:27 -08005244 if (config->RSNWPAReqIELength <
5245 sizeof(config->RSNWPAReqIE))
5246 memcpy(&config->RSNWPAReqIE[0] +
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005247 prev_rsn_length, ie, ie[1] + 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005248 else
Srinivas Girigowda55756882017-03-06 16:45:27 -08005249 hdd_err("RSNWPA IE MAX Length exceeded; length: %d",
Jeff Johnson954903d2019-03-07 20:41:27 -08005250 config->RSNWPAReqIELength);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005251 } else {
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005252 config->RSNWPAReqIELength = ie[1] + 2;
Jeff Johnson954903d2019-03-07 20:41:27 -08005253 if (config->RSNWPAReqIELength <
5254 sizeof(config->RSNWPAReqIE))
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005255 memcpy(&config->RSNWPAReqIE[0], ie,
Jeff Johnson954903d2019-03-07 20:41:27 -08005256 config->RSNWPAReqIELength);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005257 else
Srinivas Girigowda55756882017-03-06 16:45:27 -08005258 hdd_err("RSNWPA IE MAX Length exceeded; length: %d",
Jeff Johnson954903d2019-03-07 20:41:27 -08005259 config->RSNWPAReqIELength);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260 status = hdd_softap_unpack_ie
Anurag Chouhan6d760662016-02-20 16:05:43 +05305261 (cds_get_context(QDF_MODULE_ID_SME),
Jeff Johnson51203af2019-03-09 18:38:09 -08005262 &rsn_encrypt_type,
5263 &mc_rsn_encrypt_type,
Jeff Johnson954903d2019-03-07 20:41:27 -08005264 &config->akm_list,
Jeff Johnsonc17b9002019-03-09 19:35:06 -08005265 &mfp_capable, &mfp_required,
Jeff Johnson954903d2019-03-07 20:41:27 -08005266 config->RSNWPAReqIE[1] + 2,
5267 config->RSNWPAReqIE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305269 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270 /* Now copy over all the security attributes
5271 * you have parsed out. Use the cipher type
5272 * in the RSN IE
5273 */
Jeff Johnson51203af2019-03-09 18:38:09 -08005274 config->RSNEncryptType = rsn_encrypt_type;
5275 config->mcRSNEncryptType = mc_rsn_encrypt_type;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005276 (WLAN_HDD_GET_AP_CTX_PTR(adapter))->
Jeff Johnson51203af2019-03-09 18:38:09 -08005277 encryption_type = rsn_encrypt_type;
Min Liuddd23302018-12-05 16:17:48 +08005278 hdd_debug("CSR EncryptionType = %d mcEncryptionType = %d",
Jeff Johnson51203af2019-03-09 18:38:09 -08005279 rsn_encrypt_type,
5280 mc_rsn_encrypt_type);
Min Liuddd23302018-12-05 16:17:48 +08005281 hdd_debug("CSR AKM Suites %d",
Jeff Johnson954903d2019-03-07 20:41:27 -08005282 config->akm_list.numEntries);
5283 for (ii = 0; ii < config->akm_list.numEntries;
Min Liuddd23302018-12-05 16:17:48 +08005284 ii++)
5285 hdd_debug("CSR AKM Suite [%d] = %d", ii,
Jeff Johnson954903d2019-03-07 20:41:27 -08005286 config->akm_list.
Min Liuddd23302018-12-05 16:17:48 +08005287 authType[ii]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005288 }
5289 }
5290 }
5291
Jeff Johnson954903d2019-03-07 20:41:27 -08005292 if (config->RSNWPAReqIELength > sizeof(config->RSNWPAReqIE)) {
Jeff Johnsonecd884e2016-06-30 14:52:25 -07005293 hdd_err("**RSNWPAReqIELength is too large***");
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305294 ret = -EINVAL;
5295 goto error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005296 }
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005297 status = hdd_set_vdev_crypto_prarams_from_ie(adapter->vdev,
Jeff Johnson954903d2019-03-07 20:41:27 -08005298 config->RSNWPAReqIE,
5299 config->RSNWPAReqIELength
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005300 );
5301 if (QDF_IS_STATUS_ERROR(status))
5302 hdd_err("Failed to set crypto params from IE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303
Jeff Johnson954903d2019-03-07 20:41:27 -08005304 config->SSIDinfo.ssidHidden = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305
Jeff Johnsond36fa332019-03-18 13:42:25 -07005306 if (ssid) {
Jeff Johnson954903d2019-03-07 20:41:27 -08005307 qdf_mem_copy(config->SSIDinfo.ssid.ssId, ssid, ssid_len);
5308 config->SSIDinfo.ssid.length = ssid_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005309
5310 switch (hidden_ssid) {
5311 case NL80211_HIDDEN_SSID_NOT_IN_USE:
Srinivas Girigowda55756882017-03-06 16:45:27 -08005312 hdd_debug("HIDDEN_SSID_NOT_IN_USE");
Jeff Johnson954903d2019-03-07 20:41:27 -08005313 config->SSIDinfo.ssidHidden = eHIDDEN_SSID_NOT_IN_USE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 break;
5315 case NL80211_HIDDEN_SSID_ZERO_LEN:
Srinivas Girigowda55756882017-03-06 16:45:27 -08005316 hdd_debug("HIDDEN_SSID_ZERO_LEN");
Jeff Johnson954903d2019-03-07 20:41:27 -08005317 config->SSIDinfo.ssidHidden = eHIDDEN_SSID_ZERO_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005318 break;
5319 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
Srinivas Girigowda55756882017-03-06 16:45:27 -08005320 hdd_debug("HIDDEN_SSID_ZERO_CONTENTS");
Jeff Johnson954903d2019-03-07 20:41:27 -08005321 config->SSIDinfo.ssidHidden =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322 eHIDDEN_SSID_ZERO_CONTENTS;
5323 break;
5324 default:
Srinivas Girigowda55756882017-03-06 16:45:27 -08005325 hdd_err("Wrong hidden_ssid param: %d", hidden_ssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005326 break;
5327 }
5328 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005329
Jeff Johnson954903d2019-03-07 20:41:27 -08005330 qdf_mem_copy(config->self_macaddr.bytes,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005331 adapter->mac_addr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305332 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005333
5334 /* default value */
Jeff Johnson954903d2019-03-07 20:41:27 -08005335 config->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
5336 config->num_accept_mac = 0;
5337 config->num_deny_mac = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -08005338 status = ucfg_policy_mgr_get_conc_rule1(hdd_ctx->psoc, &conc_rule1);
5339 if (!QDF_IS_STATUS_SUCCESS(status))
5340 hdd_err("can't get ucfg_policy_mgr_get_conc_rule1, use def");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005341#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
5342 /*
5343 * We don't want P2PGO to follow STA's channel
5344 * so lets limit the logic for SAP only.
5345 * Later if we decide to make p2pgo follow STA's
5346 * channel then remove this check.
5347 */
Krunal Sonid7ef8632018-09-27 11:17:33 -07005348 if ((0 == conc_rule1) ||
5349 (conc_rule1 && (QDF_SAP_MODE == adapter->device_mode)))
Jeff Johnson954903d2019-03-07 20:41:27 -08005350 config->cc_switch_mode = mcc_to_scc_switch;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005351#endif
5352
Himanshu Agarwalad4c0392018-05-08 16:53:36 +05305353 if (!(ssid && qdf_str_len(PRE_CAC_SSID) == ssid_len &&
Houston Hoffman1942cae2017-08-24 16:59:35 -07005354 (0 == qdf_mem_cmp(ssid, PRE_CAC_SSID, ssid_len)))) {
Dundi Raviteja5296f492018-11-12 17:51:37 +05305355 uint16_t beacon_data_len;
5356
Jeff Johnsond5777132019-02-11 09:55:56 -08005357 beacon_data_len = beacon->head_len - beacon_fixed_len;
Dundi Raviteja5296f492018-11-12 17:51:37 +05305358
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005359 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_SUPP_RATES,
Jeff Johnsonc6c35e32019-03-10 18:32:38 -07005360 &mgmt_frame->u.beacon.variable[0],
Dundi Raviteja5296f492018-11-12 17:51:37 +05305361 beacon_data_len);
Agrawal Ashish06e76d22016-08-18 16:44:48 +05305362
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005363 if (ie) {
5364 ie++;
Srinivas Girigowda61771262019-04-01 11:55:19 -07005365 if (ie[0] > WLAN_SUPPORTED_RATES_IE_MAX_LEN) {
Dundi Raviteja561e3ed2018-10-08 11:55:00 +05305366 hdd_err("Invalid supported rates %d",
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005367 ie[0]);
Dundi Raviteja561e3ed2018-10-08 11:55:00 +05305368 ret = -EINVAL;
5369 goto error;
5370 }
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005371 config->supported_rates.numRates = ie[0];
5372 ie++;
Agrawal Ashish06e76d22016-08-18 16:44:48 +05305373 for (i = 0;
Jeff Johnson954903d2019-03-07 20:41:27 -08005374 i < config->supported_rates.numRates; i++) {
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005375 if (ie[i]) {
5376 config->supported_rates.rate[i] = ie[i];
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005377 hdd_debug("Configured Supported rate is %2x",
Jeff Johnson954903d2019-03-07 20:41:27 -08005378 config->supported_rates.rate[i]);
Agrawal Ashish06e76d22016-08-18 16:44:48 +05305379 }
5380 }
5381 }
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005382 ie = wlan_get_ie_ptr_from_eid(WLAN_EID_EXT_SUPP_RATES,
5383 beacon->tail,
5384 beacon->tail_len);
5385 if (ie) {
5386 ie++;
Srinivas Girigowda61771262019-04-01 11:55:19 -07005387 if (ie[0] > WLAN_SUPPORTED_RATES_IE_MAX_LEN) {
Dundi Raviteja561e3ed2018-10-08 11:55:00 +05305388 hdd_err("Invalid supported rates %d",
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005389 ie[0]);
Dundi Raviteja561e3ed2018-10-08 11:55:00 +05305390 ret = -EINVAL;
5391 goto error;
5392 }
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005393 config->extended_rates.numRates = ie[0];
5394 ie++;
Jeff Johnson954903d2019-03-07 20:41:27 -08005395 for (i = 0; i < config->extended_rates.numRates; i++) {
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005396 if (ie[i]) {
5397 config->extended_rates.rate[i] = ie[i];
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005398 hdd_debug("Configured ext Supported rate is %2x",
Jeff Johnson954903d2019-03-07 20:41:27 -08005399 config->extended_rates.rate[i]);
Agrawal Ashish06e76d22016-08-18 16:44:48 +05305400 }
5401 }
5402 }
5403 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005404
Naveen Rawat10b1c152017-01-18 11:16:06 -08005405 if (!cds_is_sub_20_mhz_enabled())
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005406 wlan_hdd_set_sap_hwmode(adapter);
Naveen Rawat10b1c152017-01-18 11:16:06 -08005407
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05305408 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
5409 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
5410 hdd_err("Failed to get vht_for_24ghz");
5411
Jeff Johnson954903d2019-03-07 20:41:27 -08005412 if (IS_24G_CH(config->channel) && bval &&
5413 (config->SapHw_mode == eCSR_DOT11_MODE_11n ||
5414 config->SapHw_mode == eCSR_DOT11_MODE_11n_ONLY))
5415 config->SapHw_mode = eCSR_DOT11_MODE_11ac;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05305416
Bala Venkateshb9cf3362017-11-09 15:48:46 +05305417 if (((adapter->device_mode == QDF_SAP_MODE) &&
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05305418 (sap_force_11n_for_11ac)) ||
Bala Venkateshb9cf3362017-11-09 15:48:46 +05305419 ((adapter->device_mode == QDF_P2P_GO_MODE) &&
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05305420 (go_force_11n_for_11ac))) {
Jeff Johnson954903d2019-03-07 20:41:27 -08005421 if (config->SapHw_mode == eCSR_DOT11_MODE_11ac ||
5422 config->SapHw_mode == eCSR_DOT11_MODE_11ac_ONLY)
5423 config->SapHw_mode = eCSR_DOT11_MODE_11n;
Rajeev Kumar Sirasanagandlab79b5462016-09-06 18:33:17 +05305424 }
5425
Sridhar Selvaraj48c47092017-07-31 18:18:14 +05305426 qdf_mem_zero(sme_config, sizeof(*sme_config));
Jeff Johnson89a0c742018-06-12 18:17:46 -07005427 sme_get_config_param(mac_handle, sme_config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005428 /* Override hostapd.conf wmm_enabled only for 11n and 11AC configs (IOT)
5429 * As per spec 11N/AC STA are QOS STA and may not connect or throughput
5430 * may not be good with non QOS 11N AP
5431 * Default: enable QOS for SAP unless WMM IE not present for 11bga
5432 */
Jeff Johnsone94ccd02019-04-02 15:02:56 -07005433 sme_config->csr_config.WMMSupportMode = eCsrRoamWmmAuto;
Jeff Johnsonaa8b13d82019-03-07 20:58:13 -08005434 ie = wlan_get_vendor_ie_ptr_from_oui(WMM_OUI_TYPE, WMM_OUI_TYPE_SIZE,
5435 beacon->tail, beacon->tail_len);
5436 if (!ie && (config->SapHw_mode == eCSR_DOT11_MODE_11a ||
Jeff Johnson954903d2019-03-07 20:41:27 -08005437 config->SapHw_mode == eCSR_DOT11_MODE_11g ||
5438 config->SapHw_mode == eCSR_DOT11_MODE_11b))
Jeff Johnsone94ccd02019-04-02 15:02:56 -07005439 sme_config->csr_config.WMMSupportMode = eCsrRoamWmmNoQos;
Jeff Johnson89a0c742018-06-12 18:17:46 -07005440 sme_update_config(mac_handle, sme_config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005441
Bala Venkateshb9cf3362017-11-09 15:48:46 +05305442 if (!((adapter->device_mode == QDF_SAP_MODE) &&
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05305443 (sap_force_11n_for_11ac)) ||
Bala Venkateshb9cf3362017-11-09 15:48:46 +05305444 ((adapter->device_mode == QDF_P2P_GO_MODE) &&
Bala Venkatesh3d786eb2018-11-20 12:59:31 +05305445 (go_force_11n_for_11ac))) {
Jeff Johnson954903d2019-03-07 20:41:27 -08005446 config->ch_width_orig =
5447 hdd_map_nl_chan_width(config->ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005448 } else {
Jeff Johnson954903d2019-03-07 20:41:27 -08005449 if (config->ch_width_orig >= NL80211_CHAN_WIDTH_40)
5450 config->ch_width_orig = CH_WIDTH_40MHZ;
Rajeev Kumar Sirasanagandlab79b5462016-09-06 18:33:17 +05305451 else
Jeff Johnson954903d2019-03-07 20:41:27 -08005452 config->ch_width_orig = CH_WIDTH_20MHZ;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005453 }
5454
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005455 if (wlan_hdd_setup_driver_overrides(adapter)) {
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305456 ret = -EINVAL;
5457 goto error;
5458 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005459
Jeff Johnson954903d2019-03-07 20:41:27 -08005460 config->ch_params.ch_width = config->ch_width_orig;
5461 wlan_reg_set_channel_params(hdd_ctx->pdev, config->channel,
5462 config->sec_ch, &config->ch_params);
Himanshu Agarwal57b7ee32018-06-11 15:09:52 +05305463
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005464 if (0 != wlan_hdd_cfg80211_update_apies(adapter)) {
Jeff Johnsonecd884e2016-06-30 14:52:25 -07005465 hdd_err("SAP Not able to set AP IEs");
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305466 ret = -EINVAL;
5467 goto error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005468 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005470#ifdef WLAN_FEATURE_11W
Jeff Johnson7e6f2912019-03-09 19:32:49 -08005471 config->mfpCapable = mfp_capable;
Jeff Johnsonc17b9002019-03-09 19:35:06 -08005472 config->mfpRequired = mfp_required;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005473 hdd_debug("Soft AP MFP capable %d, MFP required %d",
Jeff Johnsonc17b9002019-03-09 19:35:06 -08005474 config->mfpCapable, config->mfpRequired);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005475#endif
5476
Srinivas Girigowda55756882017-03-06 16:45:27 -08005477 hdd_debug("SOftAP macaddress : " MAC_ADDRESS_STR,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005478 MAC_ADDR_ARRAY(adapter->mac_addr.bytes));
Srinivas Girigowda55756882017-03-06 16:45:27 -08005479 hdd_debug("ssid =%s, beaconint=%d, channel=%d",
Jeff Johnson954903d2019-03-07 20:41:27 -08005480 config->SSIDinfo.ssid.ssId, (int)config->beacon_int,
5481 (int)config->channel);
Srinivas Girigowda55756882017-03-06 16:45:27 -08005482 hdd_debug("hw_mode=%x, privacy=%d, authType=%d",
Jeff Johnson954903d2019-03-07 20:41:27 -08005483 config->SapHw_mode, config->privacy, config->authType);
Harprit Chhabadaa9ff69c2019-03-11 15:03:02 -07005484 hdd_debug("RSN/WPALen=%d", (int)config->RSNWPAReqIELength);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005485
Tiger Yub2395d42018-05-15 15:05:44 +08005486 mutex_lock(&hdd_ctx->sap_lock);
5487 if (cds_is_driver_unloading()) {
5488 mutex_unlock(&hdd_ctx->sap_lock);
5489
5490 hdd_err("The driver is unloading, ignore the bss starting");
5491 ret = -EINVAL;
5492 goto error;
5493 }
5494
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005495 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Tiger Yub2395d42018-05-15 15:05:44 +08005496 mutex_unlock(&hdd_ctx->sap_lock);
5497
Jeff Johnson954903d2019-03-07 20:41:27 -08005498 wlansap_reset_sap_config_add_ie(config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005499 /* Bss already started. just return. */
5500 /* TODO Probably it should update some beacon params. */
Srinivas Girigowda55756882017-03-06 16:45:27 -08005501 hdd_debug("Bss Already started...Ignore the request");
Dustin Browne74003f2018-03-14 12:51:58 -07005502 hdd_exit();
Sridhar Selvaraj48c47092017-07-31 18:18:14 +05305503 ret = 0;
5504 goto free;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005505 }
5506
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305507 if (check_for_concurrency) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005508 if (!policy_mgr_allow_concurrency(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005509 policy_mgr_convert_device_mode_to_qdf_type(
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005510 adapter->device_mode),
Jeff Johnson954903d2019-03-07 20:41:27 -08005511 config->channel, HW_MODE_20_MHZ)) {
Tiger Yub2395d42018-05-15 15:05:44 +08005512 mutex_unlock(&hdd_ctx->sap_lock);
5513
Srinivas Girigowda55756882017-03-06 16:45:27 -08005514 hdd_err("This concurrency combination is not allowed");
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305515 ret = -EINVAL;
5516 goto error;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305517 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005518 }
5519
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005520 if (!hdd_set_connection_in_progress(true)) {
Tiger Yub2395d42018-05-15 15:05:44 +08005521 mutex_unlock(&hdd_ctx->sap_lock);
5522
Jeff Johnsone444c102018-05-06 16:04:21 -07005523 hdd_err("Can't start BSS: set connection in progress failed");
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305524 ret = -EINVAL;
5525 goto error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005526 }
5527
Jeff Johnson954903d2019-03-07 20:41:27 -08005528 config->persona = adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529
Jeff Johnsonca265782019-03-07 20:47:23 -08005530 sap_event_callback = hdd_hostapd_sap_event_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005531
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005532 (WLAN_HDD_GET_AP_CTX_PTR(adapter))->dfs_cac_block_tx = true;
5533 set_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005534
Jeff Johnson5c19ade2017-10-04 09:52:12 -07005535 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005536 status = wlansap_start_bss(
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005537 WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnsonca265782019-03-07 20:47:23 -08005538 sap_event_callback, config, adapter->dev);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305539 if (!QDF_IS_STATUS_SUCCESS(status)) {
Tiger Yub2395d42018-05-15 15:05:44 +08005540 mutex_unlock(&hdd_ctx->sap_lock);
5541
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005542 hdd_set_connection_in_progress(false);
Jeff Johnsonecd884e2016-06-30 14:52:25 -07005543 hdd_err("SAP Start Bss fail");
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305544 ret = -EINVAL;
5545 goto error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005546 }
5547
Srinivas Girigowda55756882017-03-06 16:45:27 -08005548 hdd_debug("Waiting for Scan to complete(auto mode) and BSS to start");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005549
Nachiket Kukade0396b732017-11-14 16:35:16 +05305550 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305551 SME_CMD_START_BSS_TIMEOUT);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005552
Jeff Johnson954903d2019-03-07 20:41:27 -08005553 wlansap_reset_sap_config_add_ie(config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554
Yeshwanth Sriram Guntukacba75492018-12-12 18:22:59 +05305555 if (!QDF_IS_STATUS_SUCCESS(qdf_status) ||
5556 !QDF_IS_STATUS_SUCCESS(hostapd_state->qdf_status)) {
Tiger Yub2395d42018-05-15 15:05:44 +08005557 mutex_unlock(&hdd_ctx->sap_lock);
5558
Srinivas Girigowda55756882017-03-06 16:45:27 -08005559 hdd_err("qdf wait for single_event failed!!");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005560 hdd_set_connection_in_progress(false);
Jeff Johnson89a0c742018-06-12 18:17:46 -07005561 sme_get_command_q_status(mac_handle);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005562 wlansap_stop_bss(WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305563 QDF_ASSERT(0);
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305564 ret = -EINVAL;
5565 goto error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005566 }
Jeff Johnson45ecc242018-05-06 17:12:48 -07005567 /* Successfully started Bss update the state bit. */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005568 set_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tiger Yub2395d42018-05-15 15:05:44 +08005569
5570 mutex_unlock(&hdd_ctx->sap_lock);
5571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572 /* Initialize WMM configuation */
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005573 hdd_wmm_init(adapter);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305574 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005575 policy_mgr_incr_active_session(hdd_ctx->psoc,
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005576 adapter->device_mode,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08005577 adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005578 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305579 true);
5580 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005581
Jeff Johnsone77641e2019-02-15 09:00:41 -08005582 wlan_hdd_dhcp_offload_enable(hdd_ctx, adapter);
Dustin Brown89fa06e2018-09-07 10:47:27 -07005583 ucfg_p2p_status_start_bss(adapter->vdev);
Wu Gaoc02785d2017-09-07 18:17:13 +08005584
Ashish Kumar Dhanotiya9298a8e2017-03-24 17:02:44 +05305585 /* Check and restart SAP if it is on unsafe channel */
Jeff Johnson23c3b842017-09-03 09:05:29 -07005586 hdd_unsafe_channel_restart_sap(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005588 hdd_set_connection_in_progress(false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005589
Sridhar Selvaraj48c47092017-07-31 18:18:14 +05305590 ret = 0;
5591 goto free;
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305592
5593error:
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05305594
Mukul Sharmaecf8e092017-12-19 22:36:31 +05305595 /* Revert the indoor to passive marking if START BSS fails */
Sourav Mohapatrafec6d6c2018-12-28 10:23:49 +05305596 if (indoor_chnl_marking && adapter->device_mode == QDF_SAP_MODE) {
Mukul Sharmaecf8e092017-12-19 22:36:31 +05305597 hdd_update_indoor_channel(hdd_ctx, false);
Jeff Johnson89a0c742018-06-12 18:17:46 -07005598 sme_update_channel_list(mac_handle);
Mukul Sharmaecf8e092017-12-19 22:36:31 +05305599 }
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005600 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305601 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Himanshu Agarwal1b3be702018-02-20 12:16:57 +05305602 wlan_hdd_undo_acs(adapter);
Jeff Johnson954903d2019-03-07 20:41:27 -08005603 wlansap_reset_sap_config_add_ie(config, eUPDATE_IE_ALL);
Sridhar Selvaraj48c47092017-07-31 18:18:14 +05305604
5605free:
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +05305606 /* Enable Roaming after start bss in case of failure/success */
5607 wlan_hdd_enable_roaming(adapter);
Sridhar Selvaraj48c47092017-07-31 18:18:14 +05305608 qdf_mem_free(sme_config);
Masti, Narayanraddi96d62ab2016-08-22 14:58:33 +05305609 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005610}
5611
Jeff Johnson866aca82017-09-10 15:27:20 -07005612int hdd_destroy_acs_timer(struct hdd_adapter *adapter)
Kapil Gupta63e75282017-05-18 20:55:10 +05305613{
5614 QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE;
5615
Jeff Johnsonb9424862017-10-30 08:49:35 -07005616 if (!adapter->session.ap.vendor_acs_timer_initialized)
Kapil Gupta63e75282017-05-18 20:55:10 +05305617 return 0;
5618
Jeff Johnsonb9424862017-10-30 08:49:35 -07005619 adapter->session.ap.vendor_acs_timer_initialized = false;
Kapil Gupta63e75282017-05-18 20:55:10 +05305620
Dustin Brown1faac912018-08-30 11:34:39 -07005621 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
Kapil Gupta63e75282017-05-18 20:55:10 +05305622 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07005623 adapter->session.ap.vendor_acs_timer.state) {
Kapil Gupta63e75282017-05-18 20:55:10 +05305624 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07005625 qdf_mc_timer_stop(&adapter->session.ap.
Kapil Gupta63e75282017-05-18 20:55:10 +05305626 vendor_acs_timer);
5627 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
5628 hdd_err("Failed to stop ACS timer");
5629 }
5630
Jeff Johnsonb9424862017-10-30 08:49:35 -07005631 if (adapter->session.ap.vendor_acs_timer.user_data)
5632 qdf_mem_free(adapter->session.ap.vendor_acs_timer.user_data);
Kapil Gupta63e75282017-05-18 20:55:10 +05305633
Jeff Johnsonb9424862017-10-30 08:49:35 -07005634 qdf_mc_timer_destroy(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta63e75282017-05-18 20:55:10 +05305635
5636 return 0;
5637}
5638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639/**
5640 * __wlan_hdd_cfg80211_stop_ap() - stop soft ap
5641 * @wiphy: Pointer to wiphy structure
5642 * @dev: Pointer to net_device structure
5643 *
5644 * Return: 0 for success non-zero for failure
5645 */
5646static int __wlan_hdd_cfg80211_stop_ap(struct wiphy *wiphy,
5647 struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648{
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005649 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson23c3b842017-09-03 09:05:29 -07005650 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305651 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305652 QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005653 tSirUpdateIE update_ie;
Jeff Johnson44e52172017-09-30 16:39:16 -07005654 struct hdd_beacon_data *old;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005655 int ret;
Jeff Johnson89a0c742018-06-12 18:17:46 -07005656 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657
Dustin Brown491d54b2018-03-14 12:39:11 -07005658 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659
Anurag Chouhan6d760662016-02-20 16:05:43 +05305660 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07005661 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005662 return -EINVAL;
5663 }
5664
Jeff Johnson23c3b842017-09-03 09:05:29 -07005665 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Brown6807c742017-02-01 17:43:03 -08005666 hdd_err("Driver module is closed; dropping request");
5667 return -EINVAL;
5668 }
5669
Jeff Johnson48363022019-02-24 16:26:51 -08005670 if (wlan_hdd_validate_vdev_id(adapter->vdev_id))
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05305671 return -EINVAL;
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05305672
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05305673 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
5674 TRACE_CODE_HDD_CFG80211_STOP_AP,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08005675 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005676
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005677 if (!(adapter->device_mode == QDF_SAP_MODE ||
5678 adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005679 return -EOPNOTSUPP;
5680 }
Srinivas Girigowda55756882017-03-06 16:45:27 -08005681
Manikandan Mohanf9b2dc12017-02-17 16:49:57 -08005682 /* Clear SOFTAP_INIT_DONE flag to mark stop_ap deinit. So that we do
5683 * not restart SAP after SSR as SAP is already stopped from user space.
5684 * This update is moved to start of this function to resolve stop_ap
5685 * call during SSR case. Adapter gets cleaned up as part of SSR.
5686 */
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005687 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Srinivas Girigowda55756882017-03-06 16:45:27 -08005688 hdd_debug("Device_mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005689 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005690
Jeff Johnson23c3b842017-09-03 09:05:29 -07005691 ret = wlan_hdd_validate_context(hdd_ctx);
Liangwei Dong8baf7c82016-10-11 01:26:59 -04005692 if (0 != ret)
Ganesh Kondabattiniff050662016-08-05 12:21:23 +05305693 return ret;
Ganesh Kondabattiniff050662016-08-05 12:21:23 +05305694
Vignesh Viswanathandd9cf622018-02-09 12:08:37 +05305695 /*
5696 * If a STA connection is in progress in another adapter, disconnect
5697 * the STA and complete the SAP operation. STA will reconnect
5698 * after SAP stop is done.
5699 */
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305700 hdd_abort_ongoing_sta_connection(hdd_ctx);
Vignesh Viswanathandd9cf622018-02-09 12:08:37 +05305701
Srinivas Dasari15412132019-01-22 15:25:31 +05305702 if (adapter->device_mode == QDF_SAP_MODE) {
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005703 wlan_hdd_del_station(adapter);
Srinivas Dasari15412132019-01-22 15:25:31 +05305704 mac_handle = hdd_ctx->mac_handle;
Liangwei Donga44d55b2019-03-20 03:22:08 -04005705 status = wlan_hdd_flush_pmksa_cache(adapter);
Srinivas Dasari15412132019-01-22 15:25:31 +05305706 if (QDF_IS_STATUS_ERROR(status))
5707 hdd_debug("Cannot flush PMKIDCache");
5708 }
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305709
Krunal Soni22208392017-09-29 18:10:34 -07005710 cds_flush_work(&adapter->sap_stop_bss_work);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005711 adapter->session.ap.sap_config.acs_cfg.acs_mode = false;
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305712 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005713 wlan_hdd_undo_acs(adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005714 qdf_mem_zero(&adapter->session.ap.sap_config.acs_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715 sizeof(struct sap_acs_cfg));
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005716 hdd_debug("Disabling queues");
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005717 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305718 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Arunk Khandavalli0dd8c012017-01-23 20:48:48 +05305719 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720
Jeff Johnsonb9424862017-10-30 08:49:35 -07005721 old = adapter->session.ap.beacon;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005722 if (!old) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08005723 hdd_err("Session id: %d beacon data points to NULL",
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08005724 adapter->vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005725 return -EINVAL;
5726 }
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005727 wlan_hdd_cleanup_actionframe(adapter);
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005728 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Jeff Johnson23c3b842017-09-03 09:05:29 -07005729 mutex_lock(&hdd_ctx->sap_lock);
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005730 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Jeff Johnson5c19ade2017-10-04 09:52:12 -07005731 struct hdd_hostapd_state *hostapd_state =
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005732 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005733
Jeff Johnson5c19ade2017-10-04 09:52:12 -07005734 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005735 status = wlansap_stop_bss(WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305736 if (QDF_IS_STATUS_SUCCESS(status)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +05305737 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305738 qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08005739 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305740 SME_CMD_STOP_BSS_TIMEOUT);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005741
Anurag Chouhance0dc992016-02-16 18:18:03 +05305742 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08005743 hdd_err("qdf wait for single_event failed!!");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305744 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005745 }
5746 }
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005747 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
yuanl5a287492018-10-26 15:42:30 +08005748 hdd_stop_tsf_sync(adapter);
Vignesh Viswanathan200f5c12018-02-27 14:01:59 +05305749
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005750 /*BSS stopped, clear the active sessions for this device mode*/
Dustin Brown1dbefe62018-09-11 16:32:03 -07005751 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005752 adapter->device_mode,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08005753 adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005754 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305755 false);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005756 adapter->session.ap.beacon = NULL;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305757 qdf_mem_free(old);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758 }
Jeff Johnson23c3b842017-09-03 09:05:29 -07005759 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005760
Jeff Johnson89a0c742018-06-12 18:17:46 -07005761 mac_handle = hdd_ctx->mac_handle;
5762 if (wlan_sap_is_pre_cac_active(mac_handle))
Jeff Johnson23c3b842017-09-03 09:05:29 -07005763 hdd_clean_up_pre_cac_interface(hdd_ctx);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305764
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305765 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07005766 hdd_err("Stopping the BSS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005767 return -EINVAL;
5768 }
5769
Jeff Johnsonc565af12019-03-10 21:09:47 -07005770 qdf_copy_macaddr(&update_ie.bssid, &adapter->mac_addr);
5771 update_ie.smeSessionId = adapter->vdev_id;
5772 update_ie.ieBufferlength = 0;
5773 update_ie.pAdditionIEBuffer = NULL;
5774 update_ie.append = true;
5775 update_ie.notify = true;
Jeff Johnson89a0c742018-06-12 18:17:46 -07005776 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07005777 &update_ie,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305778 eUPDATE_IE_PROBE_BCN) == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07005779 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005780 }
5781
Jeff Johnson89a0c742018-06-12 18:17:46 -07005782 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07005783 &update_ie,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305784 eUPDATE_IE_ASSOC_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07005785 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005786 }
5787 /* Reset WNI_CFG_PROBE_RSP Flags */
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005788 wlan_hdd_reset_prob_rspies(adapter);
5789 hdd_destroy_acs_timer(adapter);
Wu Gaoc02785d2017-09-07 18:17:13 +08005790
Dustin Brown89fa06e2018-09-07 10:47:27 -07005791 ucfg_p2p_status_stop_bss(adapter->vdev);
Wu Gaoc02785d2017-09-07 18:17:13 +08005792
Dustin Browne74003f2018-03-14 12:51:58 -07005793 hdd_exit();
Wu Gao0c45d6a2017-05-23 18:53:36 +08005794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005795 return ret;
5796}
5797
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005798/**
5799 * wlan_hdd_get_channel_bw() - get channel bandwidth
5800 * @width: input channel width in nl80211_chan_width value
5801 *
5802 * Return: channel width value defined by driver
5803 */
5804static enum hw_mode_bandwidth wlan_hdd_get_channel_bw(
5805 enum nl80211_chan_width width)
5806{
5807 enum hw_mode_bandwidth ch_bw = HW_MODE_20_MHZ;
5808
5809 switch (width) {
5810 case NL80211_CHAN_WIDTH_20_NOHT:
5811 case NL80211_CHAN_WIDTH_20:
5812 ch_bw = HW_MODE_20_MHZ;
5813 break;
5814 case NL80211_CHAN_WIDTH_40:
5815 ch_bw = HW_MODE_40_MHZ;
5816 break;
5817 case NL80211_CHAN_WIDTH_80:
5818 ch_bw = HW_MODE_80_MHZ;
5819 break;
5820 case NL80211_CHAN_WIDTH_80P80:
5821 ch_bw = HW_MODE_80_PLUS_80_MHZ;
5822 break;
5823 case NL80211_CHAN_WIDTH_160:
5824 ch_bw = HW_MODE_160_MHZ;
5825 break;
5826 default:
5827 hdd_err("Invalid width: %d, using default 20MHz", width);
5828 break;
5829 }
5830
5831 return ch_bw;
5832}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005833
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005834/**
5835 * wlan_hdd_cfg80211_stop_ap() - stop sap
5836 * @wiphy: Pointer to wiphy
5837 * @dev: Pointer to netdev
5838 *
5839 * Return: zero for success non-zero for failure
5840 */
5841int wlan_hdd_cfg80211_stop_ap(struct wiphy *wiphy,
5842 struct net_device *dev)
5843{
Dustin Brown1d31b082018-11-22 14:41:20 +05305844 int errno;
5845 struct osif_vdev_sync *vdev_sync;
5846
5847 errno = osif_vdev_sync_op_start(dev, &vdev_sync);
5848 if (errno)
5849 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005850
Dustin Brown1d31b082018-11-22 14:41:20 +05305851 errno = __wlan_hdd_cfg80211_stop_ap(wiphy, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005852
Dustin Brown1d31b082018-11-22 14:41:20 +05305853 osif_vdev_sync_op_stop(vdev_sync);
5854
5855 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005856}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005857
Jiachao Wu712d4fd2017-08-23 16:52:34 +08005858#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)) || \
5859 defined(CFG80211_BEACON_TX_RATE_CUSTOM_BACKPORT)
5860/**
5861 * hdd_get_data_rate_from_rate_mask() - convert mask to rate
5862 * @wiphy: Pointer to wiphy
5863 * @band: band
5864 * @bit_rate_mask: pointer to bit_rake_mask
5865 *
5866 * This function takes band and bit_rate_mask as input and
5867 * derives the beacon_tx_rate based on the supported rates
5868 * published as part of wiphy register.
5869 *
5870 * Return: data rate for success or zero for failure
5871 */
5872static uint16_t hdd_get_data_rate_from_rate_mask(struct wiphy *wiphy,
Dustin Brown76b92122017-09-20 17:35:39 -07005873 enum nl80211_band band,
Jiachao Wu712d4fd2017-08-23 16:52:34 +08005874 struct cfg80211_bitrate_mask *bit_rate_mask)
5875{
5876 struct ieee80211_supported_band *sband = wiphy->bands[band];
5877 int sband_n_bitrates;
5878 struct ieee80211_rate *sband_bitrates;
5879 int i;
5880
5881 if (sband) {
5882 sband_bitrates = sband->bitrates;
5883 sband_n_bitrates = sband->n_bitrates;
5884 for (i = 0; i < sband_n_bitrates; i++) {
5885 if (bit_rate_mask->control[band].legacy ==
5886 sband_bitrates[i].hw_value)
5887 return sband_bitrates[i].bitrate;
5888 }
5889 }
5890 return 0;
5891}
5892
5893/**
5894 * hdd_update_beacon_rate() - Update beacon tx rate
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005895 * @adapter: Pointer to hdd_adapter_t
Jiachao Wu712d4fd2017-08-23 16:52:34 +08005896 * @wiphy: Pointer to wiphy
5897 * @params: Pointet to cfg80211_ap_settings
5898 *
5899 * This function updates the beacon tx rate which is provided
Jeff Johnson91df29d2017-10-27 19:29:50 -07005900 * as part of cfg80211_ap_settions in to the sap_config
Jiachao Wu712d4fd2017-08-23 16:52:34 +08005901 * structure
5902 *
5903 * Return: none
5904 */
5905static void hdd_update_beacon_rate(struct hdd_adapter *adapter,
5906 struct wiphy *wiphy,
5907 struct cfg80211_ap_settings *params)
5908{
5909 struct cfg80211_bitrate_mask *beacon_rate_mask;
Dustin Brown76b92122017-09-20 17:35:39 -07005910 enum nl80211_band band;
Jiachao Wu712d4fd2017-08-23 16:52:34 +08005911
5912 band = params->chandef.chan->band;
5913 beacon_rate_mask = &params->beacon_rate;
5914 if (beacon_rate_mask->control[band].legacy) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07005915 adapter->session.ap.sap_config.beacon_tx_rate =
Jiachao Wu712d4fd2017-08-23 16:52:34 +08005916 hdd_get_data_rate_from_rate_mask(wiphy, band,
5917 beacon_rate_mask);
5918 hdd_debug("beacon mask value %u, rate %hu",
5919 params->beacon_rate.control[0].legacy,
Jeff Johnsonb9424862017-10-30 08:49:35 -07005920 adapter->session.ap.sap_config.beacon_tx_rate);
Jiachao Wu712d4fd2017-08-23 16:52:34 +08005921 }
5922}
5923#else
5924static void hdd_update_beacon_rate(struct hdd_adapter *adapter,
5925 struct wiphy *wiphy,
5926 struct cfg80211_ap_settings *params)
5927{
5928}
5929#endif
5930
5931
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005932/**
5933 * __wlan_hdd_cfg80211_start_ap() - start soft ap mode
5934 * @wiphy: Pointer to wiphy structure
5935 * @dev: Pointer to net_device structure
5936 * @params: Pointer to AP settings parameters
5937 *
5938 * Return: 0 for success non-zero for failure
5939 */
5940static int __wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
5941 struct net_device *dev,
5942 struct cfg80211_ap_settings *params)
5943{
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005944 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson23c3b842017-09-03 09:05:29 -07005945 struct hdd_context *hdd_ctx;
Chandrasekaran, Manishekar96c90962015-11-20 16:47:45 +05305946 enum hw_mode_bandwidth channel_width;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947 int status;
Agrawal, Ashish4e5fa1c2016-09-21 19:03:43 +05305948 struct sme_sta_inactivity_timeout *sta_inactivity_timer;
Krunal Sonidf29bc42018-11-15 13:26:29 -08005949 uint8_t channel, mandt_chnl_list = 0;
Bala Venkatesh5479cf82018-06-09 20:02:38 +05305950 bool sta_sap_scc_on_dfs_chan;
5951 uint16_t sta_cnt;
Pragaspathi Thilagaraj48d273c2018-08-31 00:53:02 +05305952 bool val;
hangtian5fe81f02018-10-23 17:53:46 +08005953 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dustin Brown491d54b2018-03-14 12:39:11 -07005954
5955 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005956
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005957 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Anurag Chouhan6d760662016-02-20 16:05:43 +05305958 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07005959 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005960 return -EINVAL;
5961 }
5962
Jeff Johnson48363022019-02-24 16:26:51 -08005963 if (wlan_hdd_validate_vdev_id(adapter->vdev_id))
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05305964 return -EINVAL;
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05305965
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05305966 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
5967 TRACE_CODE_HDD_CFG80211_START_AP,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08005968 adapter->vdev_id, params->beacon_interval);
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05305969
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005970 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07005971 hdd_err("HDD adapter magic is invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005972 return -ENODEV;
5973 }
5974
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005975 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson23c3b842017-09-03 09:05:29 -07005976 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05305977 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005978 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07005980 hdd_debug("adapter = %pK, Device mode %s(%d) sub20 %d",
Dustin Brown458027c2018-10-19 12:26:27 -07005981 adapter, qdf_opmode_str(adapter->device_mode),
5982 adapter->device_mode, cds_is_sub_20_mhz_enabled());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005983
Dustin Brown1dbefe62018-09-11 16:32:03 -07005984 if (policy_mgr_is_hw_mode_change_in_progress(hdd_ctx->psoc)) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005985 status = policy_mgr_wait_for_connection_update(
Dustin Brown1dbefe62018-09-11 16:32:03 -07005986 hdd_ctx->psoc);
Nitesh Shaha3dfea32017-02-09 19:18:57 +05305987 if (!QDF_IS_STATUS_SUCCESS(status)) {
5988 hdd_err("qdf wait for event failed!!");
5989 return -EINVAL;
5990 }
5991 }
5992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005993 channel_width = wlan_hdd_get_channel_bw(params->chandef.width);
5994 channel = ieee80211_frequency_to_channel(
5995 params->chandef.chan->center_freq);
Abhishek Singh53791fa2018-06-14 14:02:50 +05305996 if (!channel) {
5997 hdd_err("Invalid channel");
5998 return -EINVAL;
5999 }
6000
Krunal Sonidf29bc42018-11-15 13:26:29 -08006001 if (QDF_STATUS_SUCCESS !=
6002 ucfg_policy_mgr_get_sap_mandt_chnl(hdd_ctx->psoc, &mandt_chnl_list))
6003 hdd_err("can't get mandatory channel list");
6004 if (mandt_chnl_list) {
Bala Venkateshbe1f59f2018-08-21 18:50:34 +05306005 if (WLAN_REG_IS_5GHZ_CH(channel)) {
6006 hdd_debug("channel %hu, sap mandatory chan list enabled",
6007 channel);
6008 if (!policy_mgr_get_sap_mandatory_chan_list_len(
Dustin Brown1dbefe62018-09-11 16:32:03 -07006009 hdd_ctx->psoc))
Bala Venkateshbe1f59f2018-08-21 18:50:34 +05306010 policy_mgr_init_sap_mandatory_2g_chan(
Dustin Brown1dbefe62018-09-11 16:32:03 -07006011 hdd_ctx->psoc);
Bala Venkateshbe1f59f2018-08-21 18:50:34 +05306012
Dustin Brown1dbefe62018-09-11 16:32:03 -07006013 policy_mgr_add_sap_mandatory_chan(hdd_ctx->psoc,
Bala Venkateshbe1f59f2018-08-21 18:50:34 +05306014 channel);
6015 } else {
6016 policy_mgr_init_sap_mandatory_2g_chan(
Dustin Brown1dbefe62018-09-11 16:32:03 -07006017 hdd_ctx->psoc);
Bala Venkateshbe1f59f2018-08-21 18:50:34 +05306018 }
6019 }
6020
Himanshu Agarwal5fb304b2018-02-27 21:14:05 +05306021 adapter->session.ap.sap_config.ch_params.center_freq_seg0 =
6022 cds_freq_to_chan(params->chandef.center_freq1);
6023 adapter->session.ap.sap_config.ch_params.center_freq_seg1 =
6024 cds_freq_to_chan(params->chandef.center_freq2);
Amar Singhal01098f72015-10-08 11:55:32 -07006025
Bala Venkatesh5479cf82018-06-09 20:02:38 +05306026 sta_sap_scc_on_dfs_chan =
6027 policy_mgr_is_sta_sap_scc_allowed_on_dfs_chan(
Dustin Brown1dbefe62018-09-11 16:32:03 -07006028 hdd_ctx->psoc);
Bala Venkatesh5479cf82018-06-09 20:02:38 +05306029 sta_cnt =
6030 policy_mgr_mode_specific_connection_count(
Dustin Brown1dbefe62018-09-11 16:32:03 -07006031 hdd_ctx->psoc, PM_STA_MODE, NULL);
Bala Venkatesh5479cf82018-06-09 20:02:38 +05306032
6033 hdd_debug("sta_sap_scc_on_dfs_chan %u, sta_cnt %u",
6034 sta_sap_scc_on_dfs_chan, sta_cnt);
6035
6036 /* if sta_sap_scc_on_dfs_chan ini is set, DFS master capability is
6037 * assumed disabled in the driver.
6038 */
Ashish Kumar Dhanotiyaaa9fdbb2018-12-14 15:29:14 +05306039 if ((wlan_reg_get_channel_state(hdd_ctx->pdev, channel) ==
Abhishek Singh53791fa2018-06-14 14:02:50 +05306040 CHANNEL_STATE_DFS) && sta_sap_scc_on_dfs_chan && !sta_cnt) {
Bala Venkatesh5479cf82018-06-09 20:02:38 +05306041 hdd_err("SAP not allowed on DFS channel!!");
6042 return -EINVAL;
6043 }
Ashish Kumar Dhanotiyaaa9fdbb2018-12-14 15:29:14 +05306044 if (!wlan_reg_is_etsi13_srd_chan_allowed_master_mode(hdd_ctx->pdev) &&
6045 wlan_reg_is_etsi13_srd_chan(hdd_ctx->pdev, channel)) {
Abhinav Kumar1a15ed22018-08-23 21:42:56 +05306046 hdd_err("SAP not allowed on SRD channel.");
6047 return -EINVAL;
6048 }
Naveen Rawat64e477e2016-05-20 10:34:56 -07006049 if (cds_is_sub_20_mhz_enabled()) {
6050 enum channel_state ch_state;
6051 enum phy_ch_width sub_20_ch_width = CH_WIDTH_INVALID;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07006052 struct sap_config *sap_cfg = &adapter->session.ap.sap_config;
Naveen Rawat10b1c152017-01-18 11:16:06 -08006053
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006054 if (CHANNEL_STATE_DFS == wlan_reg_get_channel_state(
Dustin Brown07901ec2018-09-07 11:02:41 -07006055 hdd_ctx->pdev, channel)) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07006056 hdd_err("Can't start SAP-DFS (channel=%d)with sub 20 MHz ch wd",
6057 channel);
6058 return -EINVAL;
6059 }
6060 if (channel_width != HW_MODE_20_MHZ) {
6061 hdd_err("Hostapd (20+ MHz) conflits with config.ini (sub 20 MHz)");
6062 return -EINVAL;
6063 }
6064 if (cds_is_5_mhz_enabled())
6065 sub_20_ch_width = CH_WIDTH_5MHZ;
6066 if (cds_is_10_mhz_enabled())
6067 sub_20_ch_width = CH_WIDTH_10MHZ;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006068 if (WLAN_REG_IS_5GHZ_CH(channel))
6069 ch_state = wlan_reg_get_5g_bonded_channel_state(
Dustin Brown07901ec2018-09-07 11:02:41 -07006070 hdd_ctx->pdev, channel,
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006071 sub_20_ch_width);
Naveen Rawat64e477e2016-05-20 10:34:56 -07006072 else
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006073 ch_state = wlan_reg_get_2g_bonded_channel_state(
Dustin Brown07901ec2018-09-07 11:02:41 -07006074 hdd_ctx->pdev, channel,
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006075 sub_20_ch_width, 0);
Naveen Rawat64e477e2016-05-20 10:34:56 -07006076 if (CHANNEL_STATE_DISABLE == ch_state) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08006077 hdd_err("Given ch width not supported by reg domain");
Naveen Rawat64e477e2016-05-20 10:34:56 -07006078 return -EINVAL;
6079 }
Naveen Rawat10b1c152017-01-18 11:16:06 -08006080 sap_cfg->SapHw_mode = eCSR_DOT11_MODE_abg;
Naveen Rawat64e477e2016-05-20 10:34:56 -07006081 }
6082
Nachiket Kukade089b9832018-12-12 16:38:17 +05306083 /* Disable NAN Discovery before starting P2P GO */
6084 if (adapter->device_mode == QDF_P2P_GO_MODE)
6085 ucfg_nan_disable_concurrency(hdd_ctx->psoc);
6086
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006087 /* check if concurrency is allowed */
Dustin Brown1dbefe62018-09-11 16:32:03 -07006088 if (!policy_mgr_allow_concurrency(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006089 policy_mgr_convert_device_mode_to_qdf_type(
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006090 adapter->device_mode),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006091 channel,
6092 channel_width)) {
6093 hdd_err("Connection failed due to concurrency check failure");
6094 return -EINVAL;
6095 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006096
Dustin Brown1dbefe62018-09-11 16:32:03 -07006097 status = policy_mgr_reset_connection_update(hdd_ctx->psoc);
Krunal Soni3091bcc2016-06-23 12:28:21 -07006098 if (!QDF_IS_STATUS_SUCCESS(status))
6099 hdd_err("ERR: clear event failed");
6100
Himanshu Agarwal55972082018-04-18 14:26:39 +05306101 /*
gaurank kathpalia6e40bbc2018-07-05 14:58:40 +05306102 * For Start Ap, the driver checks whether the SAP comes up in a
6103 * different or same band( whether we require DBS or Not).
6104 * If we dont require DBS, then the driver does nothing assuming
6105 * the state would be already in non DBS mode, and just continues
6106 * with vdev up on same MAC, by stoping the opportunistic timer,
6107 * which results in a connection of 1x1 if already the state was in
6108 * DBS. So first stop timer, and check the current hw mode.
6109 * If the SAP comes up in band different from STA, DBS mode is already
6110 * set. IF not, then well check for upgrade, and shift the connection
6111 * back to single MAC 2x2 (if initial was 2x2).
Himanshu Agarwal55972082018-04-18 14:26:39 +05306112 */
gaurank kathpalia6e40bbc2018-07-05 14:58:40 +05306113
Dustin Brown1dbefe62018-09-11 16:32:03 -07006114 policy_mgr_checkn_update_hw_mode_single_mac_mode(hdd_ctx->psoc,
gaurank kathpalia6e40bbc2018-07-05 14:58:40 +05306115 channel);
Himanshu Agarwal55972082018-04-18 14:26:39 +05306116 if (status != QDF_STATUS_SUCCESS) {
6117 hdd_err("Failed to stop DBS opportunistic timer");
6118 return -EINVAL;
6119 }
6120
Dustin Brown1dbefe62018-09-11 16:32:03 -07006121 status = policy_mgr_current_connections_update(hdd_ctx->psoc,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08006122 adapter->vdev_id, channel,
Tushnim Bhattacharyya3b99f4b2018-03-26 14:19:24 -07006123 POLICY_MGR_UPDATE_REASON_START_AP);
Himanshu Agarwal55972082018-04-18 14:26:39 +05306124 if (status == QDF_STATUS_E_FAILURE) {
Krunal Soni3091bcc2016-06-23 12:28:21 -07006125 hdd_err("ERROR: connections update failed!!");
6126 return -EINVAL;
6127 }
6128
6129 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07006130 status = policy_mgr_wait_for_connection_update(hdd_ctx->psoc);
Krunal Soni3091bcc2016-06-23 12:28:21 -07006131 if (!QDF_IS_STATUS_SUCCESS(status)) {
6132 hdd_err("ERROR: qdf wait for event failed!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006133 return -EINVAL;
6134 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006135 }
bings612b9c42016-11-07 10:52:03 +08006136
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006137 if (adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson866aca82017-09-10 15:27:20 -07006138 struct hdd_adapter *p2p_adapter;
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07006139
Jeff Johnson23c3b842017-09-03 09:05:29 -07006140 p2p_adapter = hdd_get_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE);
Liangwei Dongb3f26cc2016-10-11 04:37:00 -04006141 if (p2p_adapter) {
Srinivas Girigowdadf88faa2017-03-24 22:05:44 -07006142 hdd_debug("Cancel active p2p device ROC before GO starting");
Liangwei Dongb3f26cc2016-10-11 04:37:00 -04006143 wlan_hdd_cancel_existing_remain_on_channel(
6144 p2p_adapter);
6145 }
6146 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006147
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006148 if ((adapter->device_mode == QDF_SAP_MODE)
6149 || (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150 ) {
Jeff Johnson44e52172017-09-30 16:39:16 -07006151 struct hdd_beacon_data *old, *new;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006152 enum nl80211_channel_type channel_type;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07006153 struct sap_config *sap_config =
Jeff Johnson91df29d2017-10-27 19:29:50 -07006154 &((WLAN_HDD_GET_AP_CTX_PTR(adapter))->sap_config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006155
Jeff Johnsonb9424862017-10-30 08:49:35 -07006156 old = adapter->session.ap.beacon;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006157
6158 if (old)
6159 return -EALREADY;
6160
6161 status =
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006162 wlan_hdd_cfg80211_alloc_new_beacon(adapter, &new,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006163 &params->beacon,
6164 params->dtim_period);
6165
6166 if (status != 0) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07006167 hdd_err("Error!!! Allocating the new beacon");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168 return -EINVAL;
6169 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07006170 adapter->session.ap.beacon = new;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006171
6172 if (params->chandef.width < NL80211_CHAN_WIDTH_80)
6173 channel_type = cfg80211_get_chandef_type(
6174 &(params->chandef));
6175 else
6176 channel_type = NL80211_CHAN_HT40PLUS;
6177
6178
6179 wlan_hdd_set_channel(wiphy, dev,
6180 &params->chandef,
6181 channel_type);
6182
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006183 hdd_update_beacon_rate(adapter, wiphy, params);
Jiachao Wu712d4fd2017-08-23 16:52:34 +08006184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185 /* set authentication type */
6186 switch (params->auth_type) {
6187 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Jeff Johnsonb9424862017-10-30 08:49:35 -07006188 adapter->session.ap.sap_config.authType =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006189 eSAP_OPEN_SYSTEM;
6190 break;
6191 case NL80211_AUTHTYPE_SHARED_KEY:
Jeff Johnsonb9424862017-10-30 08:49:35 -07006192 adapter->session.ap.sap_config.authType =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006193 eSAP_SHARED_KEY;
6194 break;
6195 default:
Jeff Johnsonb9424862017-10-30 08:49:35 -07006196 adapter->session.ap.sap_config.authType =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006197 eSAP_AUTO_SWITCH;
6198 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07006199 adapter->session.ap.sap_config.ch_width_orig =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006200 params->chandef.width;
Himanshu Agarwal5fb304b2018-02-27 21:14:05 +05306201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202 status =
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006203 wlan_hdd_cfg80211_start_bss(adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204 &params->beacon,
6205 params->ssid, params->ssid_len,
Mahesh Kumar Kalikot Veetilc637fc92017-09-27 16:06:21 -07006206 params->hidden_ssid, true);
Arunk Khandavallibbc301f2017-06-21 22:14:31 +05306207
6208 if (status != 0) {
6209 hdd_err("Error Start bss Failed");
6210 goto err_start_bss;
6211 }
6212
yuanl5a287492018-10-26 15:42:30 +08006213 hdd_start_tsf_sync(adapter);
6214
hangtian5fe81f02018-10-23 17:53:46 +08006215 if (wdev->chandef.chan->center_freq !=
6216 params->chandef.chan->center_freq)
6217 params->chandef = wdev->chandef;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05306218 /*
6219 * If Do_Not_Break_Stream enabled send avoid channel list
6220 * to application.
6221 */
Dustin Brown89fa06e2018-09-07 10:47:27 -07006222 if (policy_mgr_is_dnsc_set(adapter->vdev) &&
Ajit Pal Singh747b6802017-05-24 15:42:03 +05306223 sap_config->channel) {
Jeff Johnson23c3b842017-09-03 09:05:29 -07006224 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx,
Ajit Pal Singh747b6802017-05-24 15:42:03 +05306225 sap_config->channel);
6226 }
Pragaspathi Thilagaraj48d273c2018-08-31 00:53:02 +05306227
Dustin Brown1dbefe62018-09-11 16:32:03 -07006228 ucfg_mlme_get_sap_inactivity_override(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj48d273c2018-08-31 00:53:02 +05306229 if (val) {
Agrawal, Ashish4e5fa1c2016-09-21 19:03:43 +05306230 sta_inactivity_timer = qdf_mem_malloc(
6231 sizeof(*sta_inactivity_timer));
6232 if (!sta_inactivity_timer) {
6233 hdd_err("Failed to allocate Memory");
6234 return QDF_STATUS_E_FAILURE;
6235 }
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08006236 sta_inactivity_timer->session_id = adapter->vdev_id;
Agrawal, Ashish4e5fa1c2016-09-21 19:03:43 +05306237 sta_inactivity_timer->sta_inactivity_timeout =
6238 params->inactivity_timeout;
Jeff Johnson89a0c742018-06-12 18:17:46 -07006239 sme_update_sta_inactivity_timeout(hdd_ctx->mac_handle,
6240 sta_inactivity_timer);
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05306241 qdf_mem_free(sta_inactivity_timer);
Agrawal, Ashish4e5fa1c2016-09-21 19:03:43 +05306242 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006243 }
6244
Arunk Khandavallibbc301f2017-06-21 22:14:31 +05306245 goto success;
6246
6247err_start_bss:
Jeff Johnsonb9424862017-10-30 08:49:35 -07006248 if (adapter->session.ap.beacon)
6249 qdf_mem_free(adapter->session.ap.beacon);
6250 adapter->session.ap.beacon = NULL;
Arunk Khandavallibbc301f2017-06-21 22:14:31 +05306251
6252success:
Dustin Browne74003f2018-03-14 12:51:58 -07006253 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254 return status;
6255}
6256
6257/**
6258 * wlan_hdd_cfg80211_start_ap() - start sap
6259 * @wiphy: Pointer to wiphy
6260 * @dev: Pointer to netdev
6261 * @params: Pointer to start ap configuration parameters
6262 *
6263 * Return: zero for success non-zero for failure
6264 */
6265int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
6266 struct net_device *dev,
6267 struct cfg80211_ap_settings *params)
6268{
Dustin Brown1d31b082018-11-22 14:41:20 +05306269 int errno;
6270 struct osif_vdev_sync *vdev_sync;
6271
6272 errno = osif_vdev_sync_op_start(dev, &vdev_sync);
6273 if (errno)
6274 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006275
Dustin Brown1d31b082018-11-22 14:41:20 +05306276 errno = __wlan_hdd_cfg80211_start_ap(wiphy, dev, params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277
Dustin Brown1d31b082018-11-22 14:41:20 +05306278 osif_vdev_sync_op_stop(vdev_sync);
6279
6280 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006281}
6282
6283/**
6284 * __wlan_hdd_cfg80211_change_beacon() - change beacon for sofatap/p2p go
6285 * @wiphy: Pointer to wiphy structure
6286 * @dev: Pointer to net_device structure
6287 * @params: Pointer to change beacon parameters
6288 *
6289 * Return: 0 for success non-zero for failure
6290 */
6291static int __wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
6292 struct net_device *dev,
6293 struct cfg80211_beacon_data *params)
6294{
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006295 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson23c3b842017-09-03 09:05:29 -07006296 struct hdd_context *hdd_ctx;
Jeff Johnson44e52172017-09-30 16:39:16 -07006297 struct hdd_beacon_data *old, *new;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006298 int status;
6299
Dustin Brown491d54b2018-03-14 12:39:11 -07006300 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301
Anurag Chouhan6d760662016-02-20 16:05:43 +05306302 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07006303 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006304 return -EINVAL;
6305 }
6306
Jeff Johnson48363022019-02-24 16:26:51 -08006307 if (wlan_hdd_validate_vdev_id(adapter->vdev_id))
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05306308 return -EINVAL;
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05306309
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05306310 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
6311 TRACE_CODE_HDD_CFG80211_CHANGE_BEACON,
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08006312 adapter->vdev_id, adapter->device_mode);
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05306313
Srinivas Girigowda55756882017-03-06 16:45:27 -08006314 hdd_debug("Device_mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006315 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006316
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006317 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson23c3b842017-09-03 09:05:29 -07006318 status = wlan_hdd_validate_context(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006319
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05306320 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006321 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006322
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006323 if (!(adapter->device_mode == QDF_SAP_MODE ||
6324 adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325 return -EOPNOTSUPP;
6326 }
6327
Jeff Johnsonb9424862017-10-30 08:49:35 -07006328 old = adapter->session.ap.beacon;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006329
6330 if (!old) {
Srinivas Girigowda55756882017-03-06 16:45:27 -08006331 hdd_err("session id: %d beacon data points to NULL",
Jeff Johnsonc5b56bb2019-02-04 14:08:48 -08006332 adapter->vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006333 return -EINVAL;
6334 }
6335
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006336 status = wlan_hdd_cfg80211_alloc_new_beacon(adapter, &new, params, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306338 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb90586c2016-06-30 15:00:38 -07006339 hdd_err("new beacon alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006340 return -EINVAL;
6341 }
6342
Jeff Johnsonb9424862017-10-30 08:49:35 -07006343 adapter->session.ap.beacon = new;
Archana Ramachandran7498d372017-03-31 11:03:16 -07006344 hdd_debug("update beacon for P2P GO/SAP");
Jeff Johnsonfd33cce2017-10-02 13:28:39 -07006345 status = wlan_hdd_cfg80211_start_bss(adapter, params, NULL,
Mahesh Kumar Kalikot Veetilc637fc92017-09-27 16:06:21 -07006346 0, 0, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006347
Dustin Browne74003f2018-03-14 12:51:58 -07006348 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006349 return status;
6350}
6351
6352/**
6353 * wlan_hdd_cfg80211_change_beacon() - change beacon content in sap mode
6354 * @wiphy: Pointer to wiphy
6355 * @dev: Pointer to netdev
6356 * @params: Pointer to change beacon parameters
6357 *
6358 * Return: zero for success non-zero for failure
6359 */
6360int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
6361 struct net_device *dev,
6362 struct cfg80211_beacon_data *params)
6363{
Dustin Brown1d31b082018-11-22 14:41:20 +05306364 int errno;
6365 struct osif_vdev_sync *vdev_sync;
6366
6367 errno = osif_vdev_sync_op_start(dev, &vdev_sync);
6368 if (errno)
6369 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370
Dustin Brown1d31b082018-11-22 14:41:20 +05306371 errno = __wlan_hdd_cfg80211_change_beacon(wiphy, dev, params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372
Dustin Brown1d31b082018-11-22 14:41:20 +05306373 osif_vdev_sync_op_stop(vdev_sync);
6374
6375 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006376}
Arun Khandavallicc544b32017-01-30 19:52:16 +05306377
6378/**
6379 * hdd_sap_indicate_disconnect_for_sta() - Indicate disconnect indication
6380 * to supplicant, if there any clients connected to SAP interface.
6381 * @adapter: sap adapter context
6382 *
6383 * Return: nothing
6384 */
Jeff Johnson866aca82017-09-10 15:27:20 -07006385void hdd_sap_indicate_disconnect_for_sta(struct hdd_adapter *adapter)
Arun Khandavallicc544b32017-01-30 19:52:16 +05306386{
Jeff Johnson4338caa2019-03-08 11:19:51 -08006387 struct sap_event sap_event;
Arun Khandavallicc544b32017-01-30 19:52:16 +05306388 int sta_id;
Jeff Johnsonf1cd3c72017-09-14 07:18:06 -07006389 struct sap_context *sap_ctx;
Arun Khandavallicc544b32017-01-30 19:52:16 +05306390
Dustin Brown491d54b2018-03-14 12:39:11 -07006391 hdd_enter();
Arun Khandavallicc544b32017-01-30 19:52:16 +05306392
6393 sap_ctx = WLAN_HDD_GET_SAP_CTX_PTR(adapter);
6394 if (!sap_ctx) {
6395 hdd_err("invalid sap context");
6396 return;
6397 }
6398
6399 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07006400 if (adapter->sta_info[sta_id].in_use) {
Jeff Johnsonb105d052017-10-21 12:07:29 -07006401 hdd_debug("sta_id: %d in_use: %d %pK",
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07006402 sta_id, adapter->sta_info[sta_id].in_use,
Arun Khandavallicc544b32017-01-30 19:52:16 +05306403 adapter);
6404
6405 if (qdf_is_macaddr_broadcast(
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07006406 &adapter->sta_info[sta_id].sta_mac))
Arun Khandavallicc544b32017-01-30 19:52:16 +05306407 continue;
6408
6409 sap_event.sapHddEventCode = eSAP_STA_DISASSOC_EVENT;
6410 qdf_mem_copy(
6411 &sap_event.sapevt.
6412 sapStationDisassocCompleteEvent.staMac,
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07006413 &adapter->sta_info[sta_id].sta_mac,
Arun Khandavallicc544b32017-01-30 19:52:16 +05306414 sizeof(struct qdf_mac_addr));
6415 sap_event.sapevt.sapStationDisassocCompleteEvent.
6416 reason =
6417 eSAP_MAC_INITATED_DISASSOC;
6418 sap_event.sapevt.sapStationDisassocCompleteEvent.
6419 statusCode =
6420 QDF_STATUS_E_RESOURCES;
6421 hdd_hostapd_sap_event_cb(&sap_event,
Jeff Johnson2284ad92019-03-23 14:56:19 -07006422 sap_ctx->user_context);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306423 }
6424 }
6425
Dustin Browne74003f2018-03-14 12:51:58 -07006426 hdd_exit();
Arun Khandavallicc544b32017-01-30 19:52:16 +05306427}
6428
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05306429bool hdd_is_peer_associated(struct hdd_adapter *adapter,
6430 struct qdf_mac_addr *mac_addr)
6431{
6432 uint32_t cnt;
6433 struct hdd_station_info *sta_info;
6434
6435 if (!adapter || !mac_addr) {
6436 hdd_err("Invalid adapter or mac_addr");
6437 return false;
6438 }
6439
6440 sta_info = adapter->sta_info;
6441 spin_lock_bh(&adapter->sta_info_lock);
6442 for (cnt = 0; cnt < WLAN_MAX_STA_COUNT; cnt++) {
6443 if ((sta_info[cnt].in_use) &&
6444 !qdf_mem_cmp(&(sta_info[cnt].sta_mac), mac_addr,
6445 QDF_MAC_ADDR_SIZE))
6446 break;
6447 }
6448 spin_unlock_bh(&adapter->sta_info_lock);
6449 if (cnt != WLAN_MAX_STA_COUNT)
6450 return true;
6451
6452 return false;
6453}