blob: 0034d5c7975008eb97b886ad2b0129c76cc2b78a [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Arunk Khandavalli95608be2019-01-22 13:12:54 +05302 * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved.
Kiet Lam842dad02014-02-18 18:44:02 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
Kiet Lama7f454d2014-07-24 12:04:06 -070023 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080026 */
Kiet Lam842dad02014-02-18 18:44:02 -080027
28
Kiet Lama7f454d2014-07-24 12:04:06 -070029
30
Jeff Johnson295189b2012-06-20 16:38:30 -070031/*========================================================================
32
33 \file wlan_hdd_main.c
34
35 \brief WLAN Host Device Driver implementation
36
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38 ========================================================================*/
39
40/**=========================================================================
41
42 EDIT HISTORY FOR FILE
43
44
45 This section contains comments describing changes made to the module.
46 Notice that changes are listed in reverse chronological order.
47
48
49 $Header:$ $DateTime: $ $Author: $
50
51
52 when who what, where, why
53 -------- --- --------------------------------------------------------
54 04/5/09 Shailender Created module.
55 02/24/10 Sudhir.S.Kohalli Added to support param for SoftAP module
56 06/03/10 js - Added support to hostapd driven deauth/disassoc/mic failure
57 ==========================================================================*/
58
59/*--------------------------------------------------------------------------
60 Include Files
61 ------------------------------------------------------------------------*/
62//#include <wlan_qct_driver.h>
63#include <wlan_hdd_includes.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070064#include <vos_api.h>
Rajeev Kumar Sirasanagandlaf8fc27c2018-12-06 14:56:43 +053065#include <vos_nvitem.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070066#include <vos_sched.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070067#include <linux/etherdevice.h>
68#include <linux/firmware.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070069#ifdef ANI_BUS_TYPE_PLATFORM
70#include <linux/wcnss_wlan.h>
71#endif //ANI_BUS_TYPE_PLATFORM
72#ifdef ANI_BUS_TYPE_PCI
73#include "wcnss_wlan.h"
74#endif /* ANI_BUS_TYPE_PCI */
75#include <wlan_hdd_tx_rx.h>
76#include <palTimer.h>
77#include <wniApi.h>
78#include <wlan_nlink_srv.h>
79#include <wlan_btc_svc.h>
80#include <wlan_hdd_cfg.h>
81#include <wlan_ptt_sock_svc.h>
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053082#include <wlan_logging_sock_svc.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070083#include <wlan_hdd_wowl.h>
84#include <wlan_hdd_misc.h>
85#include <wlan_hdd_wext.h>
86#ifdef WLAN_BTAMP_FEATURE
87#include <bap_hdd_main.h>
88#include <bapInternal.h>
89#endif // WLAN_BTAMP_FEATURE
Sushant Kaushik4b7cb302014-01-06 17:45:01 +053090#include "wlan_hdd_trace.h"
91#include "vos_types.h"
92#include "vos_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070093#include <linux/wireless.h>
94#include <net/cfg80211.h>
Vinay Krishna Erannad9cbdb32014-01-16 12:59:10 +053095#include <linux/inetdevice.h>
96#include <net/addrconf.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070097#include "wlan_hdd_cfg80211.h"
98#include "wlan_hdd_p2p.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070099#include <linux/rtnetlink.h>
Jeff Johnson295189b2012-06-20 16:38:30 -0700100int wlan_hdd_ftm_start(hdd_context_t *pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -0700101#include "sapApi.h"
102#include <linux/semaphore.h>
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -0700103#include <linux/ctype.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530104#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
105#include <soc/qcom/subsystem_restart.h>
106#else
Jeff Johnson295189b2012-06-20 16:38:30 -0700107#include <mach/subsystem_restart.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530108#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700109#include <wlan_hdd_hostapd.h>
110#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson295189b2012-06-20 16:38:30 -0700111#include "cfgApi.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700112#include "wlan_hdd_dev_pwr.h"
113#ifdef WLAN_BTAMP_FEATURE
114#include "bap_hdd_misc.h"
115#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700116#include "wlan_qct_pal_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700117#include "qwlan_version.h"
Yathish9f22e662012-12-10 14:21:35 -0800118#include "wlan_qct_wda.h"
Chilam NG571c65a2013-01-19 12:27:36 +0530119#ifdef FEATURE_WLAN_TDLS
120#include "wlan_hdd_tdls.h"
121#endif
Yue Ma0d4891e2013-08-06 17:01:45 -0700122#include "wlan_hdd_debugfs.h"
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +0530123#include "sapInternal.h"
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +0530124#include "wlan_hdd_request_manager.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700125
126#ifdef MODULE
127#define WLAN_MODULE_NAME module_name(THIS_MODULE)
128#else
129#define WLAN_MODULE_NAME "wlan"
130#endif
131
132#ifdef TIMER_MANAGER
133#define TIMER_MANAGER_STR " +TIMER_MANAGER"
134#else
135#define TIMER_MANAGER_STR ""
136#endif
137
138#ifdef MEMORY_DEBUG
139#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
140#else
141#define MEMORY_DEBUG_STR ""
142#endif
Kaushik, Sushant7005e372014-04-08 11:36:54 +0530143#define MAX_WAIT_FOR_ROC_COMPLETION 3
Jeff Johnson295189b2012-06-20 16:38:30 -0700144/* the Android framework expects this param even though we don't use it */
145#define BUF_LEN 20
Jeff Johnson76052702013-04-16 13:55:05 -0700146static char fwpath_buffer[BUF_LEN];
147static struct kparam_string fwpath = {
148 .string = fwpath_buffer,
149 .maxlen = BUF_LEN,
150};
Arif Hussain66559122013-11-21 10:11:40 -0800151
152static char *country_code;
153static int enable_11d = -1;
154static int enable_dfs_chan_scan = -1;
155
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700156#ifndef MODULE
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700157static int wlan_hdd_inited;
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700158#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700159
Jeff Johnsone7245742012-09-05 17:12:55 -0700160/*
Jeff Johnson72a40512013-12-19 10:14:15 -0800161 * spinlock for synchronizing asynchronous request/response
162 * (full description of use in wlan_hdd_main.h)
163 */
164DEFINE_SPINLOCK(hdd_context_lock);
165
166/*
Jeff Johnsone7245742012-09-05 17:12:55 -0700167 * The rate at which the driver sends RESTART event to supplicant
168 * once the function 'vos_wlanRestart()' is called
169 *
170 */
171#define WLAN_HDD_RESTART_RETRY_DELAY_MS 5000 /* 5 second */
172#define WLAN_HDD_RESTART_RETRY_MAX_CNT 5 /* 5 retries */
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -0700173
174/*
175 * Size of Driver command strings from upper layer
176 */
177#define SIZE_OF_SETROAMMODE 11 /* size of SETROAMMODE */
178#define SIZE_OF_GETROAMMODE 11 /* size of GETROAMMODE */
179
Abhishek Singh00b71972016-01-07 10:51:04 +0530180#ifdef WLAN_FEATURE_RMC
181/*
182 * Ibss prop IE from command will be of size:
183 * size = sizeof(oui) + sizeof(oui_data) + 1(Element ID) + 1(EID Length)
184 * OUI_DATA should be at least 3 bytes long
185 */
186#define WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH (3)
187#endif
188
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800189#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700190#define TID_MIN_VALUE 0
191#define TID_MAX_VALUE 15
192static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
193 tAniTrafStrmMetrics* pTsmMetrics);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800194static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
195 tCsrEseBeaconReq *pEseBcnReq);
196#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700197
Atul Mittal1d722422014-03-19 11:15:07 +0530198/*
199 * Maximum buffer size used for returning the data back to user space
200 */
201#define WLAN_MAX_BUF_SIZE 1024
202#define WLAN_PRIV_DATA_MAX_LEN 8192
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -0700203
Abhishek Singh00b71972016-01-07 10:51:04 +0530204/*
205 * When ever we need to print IBSSPEERINFOALL for morethan 16 STA
206 * we will split the printing.
207 */
208#define NUM_OF_STA_DATA_TO_PRINT 16
209
210#ifdef WLAN_FEATURE_RMC
211#define WLAN_NLINK_CESIUM 30
212#endif
213
c_hpothu92367912014-05-01 15:18:17 +0530214//wait time for beacon miss rate.
215#define BCN_MISS_RATE_TIME 500
216
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +0530217/*
218 * Android DRIVER command structures
219 */
220struct android_wifi_reassoc_params {
221 unsigned char bssid[18];
222 int channel;
223};
224
Sushant Kaushik83392fa2015-05-05 17:44:40 +0530225static vos_wake_lock_t wlan_wake_lock;
226
Jeff Johnson295189b2012-06-20 16:38:30 -0700227/* set when SSR is needed after unload */
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -0700228static e_hdd_ssr_required isSsrRequired = HDD_SSR_NOT_REQUIRED;
Jeff Johnson295189b2012-06-20 16:38:30 -0700229
230//internal function declaration
Jeff Johnsone7245742012-09-05 17:12:55 -0700231static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx);
232static void wlan_hdd_restart_init(hdd_context_t *pHddCtx);
233static void wlan_hdd_restart_deinit(hdd_context_t *pHddCtx);
Abhishek Singh00b71972016-01-07 10:51:04 +0530234
235#ifdef WLAN_FEATURE_RMC
236static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo);
237
238static int hdd_open_cesium_nl_sock(void);
239static void hdd_close_cesium_nl_sock(void);
240static struct sock *cesium_nl_srv_sock;
241static v_U16_t cesium_pid;
242
243static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
244 tANI_U8 *tx_fail_count,
245 tANI_U16 *pid);
246
247static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg);
248
249#endif /* WLAN_FEATURE_RMC */
Jeff Johnsone7245742012-09-05 17:12:55 -0700250void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback);
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800251void hdd_set_wlan_suspend_mode(bool suspend);
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530252void hdd_set_vowifi_mode(hdd_context_t *hdd_ctx, bool enable);
Jeff Johnsone7245742012-09-05 17:12:55 -0700253
Jeff Johnson295189b2012-06-20 16:38:30 -0700254v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +0530255 struct sk_buff *skb
256#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
257 , void *accel_priv
258#endif
259#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
260 , select_queue_fallback_t fallback
261#endif
262);
Jeff Johnson295189b2012-06-20 16:38:30 -0700263
264#ifdef WLAN_FEATURE_PACKET_FILTERING
265static void hdd_set_multicast_list(struct net_device *dev);
266#endif
267
268void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter);
269
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800270#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -0800271void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand);
272static VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels);
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700273static VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid,
274 tANI_U8 *pChannel, tANI_U8 *pDwellTime,
275 tANI_U8 **pBuf, tANI_U8 *pBufLen);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +0530276static int hdd_parse_reassoc_command_v1_data(const tANI_U8 *pValue,
277 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel);
Srinivas Girigowdade697412013-02-14 16:31:48 -0800278#endif
Ratheesh S P21280412015-05-19 14:21:52 +0530279
280/* Store WLAN driver info in a global variable such that crash debugger
281 can extract it from driver debug symbol and crashdump for post processing */
282tANI_U8 g_wlan_driver[ ] = "pronto_driver";
283
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800284#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700285VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe, tANI_U8 *pCckmIeLen);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800286#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700287
Mihir Shetee1093ba2014-01-21 20:13:32 +0530288static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx);
Sushant Kaushik8bc7df22014-04-09 17:55:29 +0530289const char * hdd_device_modetoString(v_U8_t device_mode)
290{
291 switch(device_mode)
292 {
293 CASE_RETURN_STRING( WLAN_HDD_INFRA_STATION );
294 CASE_RETURN_STRING( WLAN_HDD_SOFTAP );
295 CASE_RETURN_STRING( WLAN_HDD_P2P_CLIENT );
296 CASE_RETURN_STRING( WLAN_HDD_P2P_GO );
297 CASE_RETURN_STRING( WLAN_HDD_MONITOR);
298 CASE_RETURN_STRING( WLAN_HDD_FTM );
299 CASE_RETURN_STRING( WLAN_HDD_IBSS );
300 CASE_RETURN_STRING( WLAN_HDD_P2P_DEVICE );
301 default:
302 return "device_mode Unknown";
303 }
304}
Mihir Shetee1093ba2014-01-21 20:13:32 +0530305
Mukul Sharmaa78cf6b2015-02-24 16:59:01 +0530306static int __hdd_netdev_notifier_call(struct notifier_block * nb,
Jeff Johnson295189b2012-06-20 16:38:30 -0700307 unsigned long state,
308 void *ndev)
309{
Yeshwanth Sriram Guntukadb04f472019-08-08 16:58:23 +0530310#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
311 struct netdev_notifier_info *info = ndev;
312 struct net_device *dev = info->dev;
313#else
Jeff Johnson295189b2012-06-20 16:38:30 -0700314 struct net_device *dev = ndev;
Yeshwanth Sriram Guntukadb04f472019-08-08 16:58:23 +0530315#endif
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700316 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson27cee452013-03-27 11:10:24 -0700317 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -0700318#ifdef WLAN_BTAMP_FEATURE
319 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -0700320#endif
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530321 long result;
Jeff Johnson295189b2012-06-20 16:38:30 -0700322
323 //Make sure that this callback corresponds to our device.
Jeff Johnson27cee452013-03-27 11:10:24 -0700324 if ((strncmp(dev->name, "wlan", 4)) &&
Amar Singhal4c723bd2013-03-25 18:14:15 -0700325 (strncmp(dev->name, "p2p", 3)))
326 return NOTIFY_DONE;
327
Jeff Johnson295189b2012-06-20 16:38:30 -0700328 if (!dev->ieee80211_ptr)
Jeff Johnson27cee452013-03-27 11:10:24 -0700329 return NOTIFY_DONE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700330
Jeff Johnson27cee452013-03-27 11:10:24 -0700331 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700332 {
Jeff Johnsona8a1a482012-12-12 16:49:33 -0800333 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Adapter Null Pointer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700334 VOS_ASSERT(0);
335 return NOTIFY_DONE;
336 }
337
Jeff Johnson27cee452013-03-27 11:10:24 -0700338 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
339 if (NULL == pHddCtx)
340 {
341 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Context Null Pointer", __func__);
342 VOS_ASSERT(0);
343 return NOTIFY_DONE;
344 }
Sameer Thalappil14067972014-01-23 14:54:54 -0800345 if (pHddCtx->isLogpInProgress)
346 return NOTIFY_DONE;
347
Jeff Johnson27cee452013-03-27 11:10:24 -0700348
349 hddLog(VOS_TRACE_LEVEL_INFO, "%s: %s New Net Device State = %lu",
350 __func__, dev->name, state);
Jeff Johnson295189b2012-06-20 16:38:30 -0700351
352 switch (state) {
353 case NETDEV_REGISTER:
354 break;
355
356 case NETDEV_UNREGISTER:
357 break;
358
359 case NETDEV_UP:
360 break;
361
362 case NETDEV_DOWN:
363 break;
364
365 case NETDEV_CHANGE:
Jeff Johnsone7245742012-09-05 17:12:55 -0700366 if(TRUE == pAdapter->isLinkUpSvcNeeded)
367 complete(&pAdapter->linkup_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700368 break;
369
370 case NETDEV_GOING_DOWN:
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530371 result = wlan_hdd_scan_abort(pAdapter);
Girish Gowli4bf7a632014-06-12 13:42:11 +0530372 if (result < 0)
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530373 {
374 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
375 "%s: Timeout occurred while waiting for abortscan %ld",
376 __func__, result);
Jeff Johnson295189b2012-06-20 16:38:30 -0700377 }
378 else
379 {
380 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530381 "%s: Scan Abort Successful" , __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700382 }
383#ifdef WLAN_BTAMP_FEATURE
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700384 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s: disabling AMP", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700385 status = WLANBAP_StopAmp();
386 if(VOS_STATUS_SUCCESS != status )
387 {
388 pHddCtx->isAmpAllowed = VOS_TRUE;
389 hddLog(VOS_TRACE_LEVEL_FATAL,
390 "%s: Failed to stop AMP", __func__);
391 }
392 else
393 {
394 //a state m/c implementation in PAL is TBD to avoid this delay
395 msleep(500);
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700396 if ( pHddCtx->isAmpAllowed )
397 {
398 WLANBAP_DeregisterFromHCI();
399 pHddCtx->isAmpAllowed = VOS_FALSE;
400 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700401 }
402#endif //WLAN_BTAMP_FEATURE
403 break;
404
405 default:
406 break;
407 }
408
409 return NOTIFY_DONE;
410}
411
Mukul Sharmaa78cf6b2015-02-24 16:59:01 +0530412static int hdd_netdev_notifier_call(struct notifier_block * nb,
413 unsigned long state,
414 void *ndev)
415{
416 int ret;
417 vos_ssr_protect(__func__);
418 ret = __hdd_netdev_notifier_call( nb, state, ndev);
419 vos_ssr_unprotect(__func__);
420 return ret;
421}
422
Jeff Johnson295189b2012-06-20 16:38:30 -0700423struct notifier_block hdd_netdev_notifier = {
424 .notifier_call = hdd_netdev_notifier_call,
425};
426
427/*---------------------------------------------------------------------------
428 * Function definitions
429 *-------------------------------------------------------------------------*/
Jeff Johnson295189b2012-06-20 16:38:30 -0700430void hdd_unregister_mcast_bcast_filter(hdd_context_t *pHddCtx);
431void hdd_register_mcast_bcast_filter(hdd_context_t *pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -0700432//variable to hold the insmod parameters
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700433static int con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -0700434#ifndef MODULE
435/* current con_mode - used only for statically linked driver
436 * con_mode is changed by userspace to indicate a mode change which will
437 * result in calling the module exit and init functions. The module
438 * exit function will clean up based on the value of con_mode prior to it
439 * being changed by userspace. So curr_con_mode records the current con_mode
440 * for exit when con_mode becomes the next mode for init
441 */
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700442static int curr_con_mode;
Jeff Johnson295189b2012-06-20 16:38:30 -0700443#endif
444
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +0530445#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
446/**
447 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
448 * @hdd_ctx: hdd global context
449 *
450 * Return: none
451 */
452static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
453{
454 uint8_t i;
455
456 mutex_init(&hdd_ctx->op_ctx.op_lock);
457 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++)
458 {
459 hdd_ctx->op_ctx.op_table[i].request_id = 0;
460 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
461 }
462}
463#else
464static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
465{
466}
467#endif
468
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -0800469/**---------------------------------------------------------------------------
470
471 \brief hdd_vos_trace_enable() - Configure initial VOS Trace enable
472
473 Called immediately after the cfg.ini is read in order to configure
474 the desired trace levels.
475
476 \param - moduleId - module whose trace level is being configured
477 \param - bitmask - bitmask of log levels to be enabled
478
479 \return - void
480
481 --------------------------------------------------------------------------*/
482static void hdd_vos_trace_enable(VOS_MODULE_ID moduleId, v_U32_t bitmask)
483{
484 wpt_tracelevel level;
485
486 /* if the bitmask is the default value, then a bitmask was not
487 specified in cfg.ini, so leave the logging level alone (it
488 will remain at the "compiled in" default value) */
489 if (CFG_VOS_TRACE_ENABLE_DEFAULT == bitmask)
490 {
491 return;
492 }
493
494 /* a mask was specified. start by disabling all logging */
495 vos_trace_setValue(moduleId, VOS_TRACE_LEVEL_NONE, 0);
496
497 /* now cycle through the bitmask until all "set" bits are serviced */
498 level = VOS_TRACE_LEVEL_FATAL;
499 while (0 != bitmask)
500 {
501 if (bitmask & 1)
502 {
503 vos_trace_setValue(moduleId, level, 1);
504 }
505 level++;
506 bitmask >>= 1;
507 }
508}
509
510
Jeff Johnson295189b2012-06-20 16:38:30 -0700511/**---------------------------------------------------------------------------
512
513 \brief hdd_wdi_trace_enable() - Configure initial WDI Trace enable
514
515 Called immediately after the cfg.ini is read in order to configure
516 the desired trace levels in the WDI.
517
518 \param - moduleId - module whose trace level is being configured
519 \param - bitmask - bitmask of log levels to be enabled
520
521 \return - void
522
523 --------------------------------------------------------------------------*/
524static void hdd_wdi_trace_enable(wpt_moduleid moduleId, v_U32_t bitmask)
525{
526 wpt_tracelevel level;
527
528 /* if the bitmask is the default value, then a bitmask was not
529 specified in cfg.ini, so leave the logging level alone (it
530 will remain at the "compiled in" default value) */
531 if (CFG_WDI_TRACE_ENABLE_DEFAULT == bitmask)
532 {
533 return;
534 }
535
536 /* a mask was specified. start by disabling all logging */
537 wpalTraceSetLevel(moduleId, eWLAN_PAL_TRACE_LEVEL_NONE, 0);
538
539 /* now cycle through the bitmask until all "set" bits are serviced */
540 level = eWLAN_PAL_TRACE_LEVEL_FATAL;
541 while (0 != bitmask)
542 {
543 if (bitmask & 1)
544 {
545 wpalTraceSetLevel(moduleId, level, 1);
546 }
547 level++;
548 bitmask >>= 1;
549 }
550}
Jeff Johnson295189b2012-06-20 16:38:30 -0700551
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530552/*
553 * FUNCTION: wlan_hdd_validate_context
554 * This function is used to check the HDD context
555 */
556int wlan_hdd_validate_context(hdd_context_t *pHddCtx)
557{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530558
559 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
560 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530561 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530562 "%s: HDD context is Null", __func__);
563 return -ENODEV;
564 }
565
566 if (pHddCtx->isLogpInProgress)
567 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530568 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu8adb97b2014-12-08 19:38:20 +0530569 "%s: LOGP %s. Ignore!!", __func__,
570 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)
571 ?"failed":"in Progress");
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530572 return -EAGAIN;
573 }
574
Mihir Shete18156292014-03-11 15:38:30 +0530575 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530576 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530577 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530578 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
579 return -EAGAIN;
580 }
581 return 0;
582}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700583#ifdef CONFIG_ENABLE_LINUX_REG
584void hdd_checkandupdate_phymode( hdd_context_t *pHddCtx)
585{
586 hdd_adapter_t *pAdapter = NULL;
587 hdd_station_ctx_t *pHddStaCtx = NULL;
588 eCsrPhyMode phyMode;
589 hdd_config_t *cfg_param = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530590
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700591 if (NULL == pHddCtx)
592 {
593 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
594 "HDD Context is null !!");
595 return ;
596 }
597
598 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
599 if (NULL == pAdapter)
600 {
601 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
602 "pAdapter is null !!");
603 return ;
604 }
605
606 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
607 if (NULL == pHddStaCtx)
608 {
609 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
610 "pHddStaCtx is null !!");
611 return ;
612 }
613
614 cfg_param = pHddCtx->cfg_ini;
615 if (NULL == cfg_param)
616 {
617 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
618 "cfg_params not available !!");
619 return ;
620 }
621
622 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
623
624 if (!pHddCtx->isVHT80Allowed)
625 {
626 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
627 (eCSR_DOT11_MODE_11ac == phyMode) ||
628 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
629 {
630 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
631 "Setting phymode to 11n!!");
632 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
633 }
634 }
635 else
636 {
637 /*New country Supports 11ac as well resetting value back from .ini*/
638 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
639 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
640 return ;
641 }
642
643 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
644 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
645 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
646 {
647 VOS_STATUS vosStatus;
648
649 // need to issue a disconnect to CSR.
650 INIT_COMPLETION(pAdapter->disconnect_comp_var);
651 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
652 pAdapter->sessionId,
653 eCSR_DISCONNECT_REASON_UNSPECIFIED );
654
655 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530656 {
657 long ret;
658
659 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700660 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530661 if (0 >= ret)
662 hddLog(LOGE, FL("failure waiting for disconnect_comp_var %ld"),
663 ret);
664 }
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700665
666 }
667}
668#else
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530669void hdd_checkandupdate_phymode( hdd_adapter_t *pAdapter, char *country_code)
670{
671 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
672 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
673 hdd_config_t *cfg_param;
674 eCsrPhyMode phyMode;
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530675 long ret;
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530676
677 if (NULL == pHddCtx)
678 {
679 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
680 "HDD Context is null !!");
681 return ;
682 }
683
684 cfg_param = pHddCtx->cfg_ini;
685
686 if (NULL == cfg_param)
687 {
688 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
689 "cfg_params not available !!");
690 return ;
691 }
692
693 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
694
695 if (NULL != strstr(cfg_param->listOfNon11acCountryCode, country_code))
696 {
697 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
698 (eCSR_DOT11_MODE_11ac == phyMode) ||
699 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
700 {
701 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
702 "Setting phymode to 11n!!");
703 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
704 }
705 }
706 else
707 {
708 /*New country Supports 11ac as well resetting value back from .ini*/
709 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
710 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
711 return ;
712 }
713
714 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
715 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
716 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
717 {
718 VOS_STATUS vosStatus;
719
720 // need to issue a disconnect to CSR.
721 INIT_COMPLETION(pAdapter->disconnect_comp_var);
722 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
723 pAdapter->sessionId,
724 eCSR_DISCONNECT_REASON_UNSPECIFIED );
725
726 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530727 {
728 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530729 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530730 if (ret <= 0)
731 {
732 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
733 "wait on disconnect_comp_var is failed %ld", ret);
734 }
735 }
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530736
737 }
738}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700739#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530740
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700741void hdd_checkandupdate_dfssetting( hdd_adapter_t *pAdapter, char *country_code)
742{
743 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
744 hdd_config_t *cfg_param;
745
746 if (NULL == pHddCtx)
747 {
748 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
749 "HDD Context is null !!");
750 return ;
751 }
752
753 cfg_param = pHddCtx->cfg_ini;
754
755 if (NULL == cfg_param)
756 {
757 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
758 "cfg_params not available !!");
759 return ;
760 }
761
Agarwal Ashish738843c2014-09-25 12:27:56 +0530762 if (NULL != strstr(cfg_param->listOfNonDfsCountryCode, country_code) ||
763 pHddCtx->disable_dfs_flag == TRUE)
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700764 {
765 /*New country doesn't support DFS */
766 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
767 }
Ashish Kumar Dhanotiya445b3b92018-06-07 12:38:12 +0530768 else
769 {
770 /* New country Supports DFS as well resetting value back from .ini */
771 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter),
772 cfg_param->enableDFSChnlScan);
773 }
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700774
775}
776
Abhishek Singh00b71972016-01-07 10:51:04 +0530777#ifdef WLAN_FEATURE_RMC
778static int hdd_parse_setrmcenable_command(tANI_U8 *pValue, tANI_U8 *pRmcEnable)
779{
780 tANI_U8 *inPtr = pValue;
781 int tempInt;
782 int v = 0;
783 char buf[32];
784 *pRmcEnable = 0;
785
786 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
787 /*no argument after the command*/
788 if (NULL == inPtr)
789 {
790 return 0;
791 }
792
793 /*no space after the command*/
794 else if (SPACE_ASCII_VALUE != *inPtr)
795 {
796 return 0;
797 }
798
799 /*removing empty spaces*/
800 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
801
802 /*no argument followed by spaces*/
803 if ('\0' == *inPtr)
804 {
805 return 0;
806 }
807
808 /* getting the first argument which enables or disables RMC
809 * for input IP v4 address*/
Ashish Kumar Dhanotiya54d31a32017-08-04 17:12:44 +0530810 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530811 v = kstrtos32(buf, 10, &tempInt);
812 if ( v < 0)
813 {
814 return -EINVAL;
815 }
816
817 *pRmcEnable = tempInt;
818
819 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
820 "ucRmcEnable: %d", *pRmcEnable);
821
822 return 0;
823}
824
825/* Function header left blank Intentionally */
826static int hdd_parse_setrmcactionperiod_command(tANI_U8 *pValue,
827 tANI_U32 *pActionPeriod)
828{
829 tANI_U8 *inPtr = pValue;
830 int tempInt;
831 int v = 0;
832 char buf[32];
833 *pActionPeriod = 0;
834
835 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
836 /*no argument after the command*/
837 if (NULL == inPtr)
838 {
839 return -EINVAL;
840 }
841
842 /*no space after the command*/
843 else if (SPACE_ASCII_VALUE != *inPtr)
844 {
845 return -EINVAL;
846 }
847
848 /*removing empty spaces*/
849 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
850
851 /*no argument followed by spaces*/
852 if ('\0' == *inPtr)
853 {
854 return 0;
855 }
856
857 /* getting the first argument which enables or disables RMC
858 * for input IP v4 address*/
Ashish Kumar Dhanotiya54d31a32017-08-04 17:12:44 +0530859 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530860 v = kstrtos32(buf, 10, &tempInt);
861 if ( v < 0)
862 {
863 return -EINVAL;
864 }
865
866 /* Range checking for passed paramter */
867 if (tempInt < WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY_STAMIN ||
868 tempInt > WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY_STAMAX)
869 {
870 return -EINVAL;
871 }
872
873 *pActionPeriod = tempInt;
874
875 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
876 "uActionPeriod: %d", *pActionPeriod);
877
878 return 0;
879}
Dundi Ravitejae110a042018-04-18 13:11:37 +0530880
881/**
882 * hdd_set_vowifi_mode() - Process VOWIFI command.
883 * @hdd_ctx: context handler
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530884 * @enable: Value to be sent as a part of the VOWIFI command
885 *
Dundi Ravitejae110a042018-04-18 13:11:37 +0530886 * Invoke the SME api if station is connected in 2.4 GHz band.
887 * Also start split scan if VOWIFIMODE and dynamic split scan
888 * both are enabled.
889
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530890 * Return: void
891 */
892void hdd_set_vowifi_mode(hdd_context_t *hdd_ctx, bool enable)
893{
894 tANI_U8 sta_chan;
895
Dundi Ravitejaab9d3092018-04-05 18:24:40 +0530896 if (!hdd_ctx->cfg_ini) {
897 hddLog(LOGE, "cfg_ini got NULL");
898 return;
899 }
900
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530901 sta_chan = hdd_get_operating_channel(hdd_ctx, WLAN_HDD_INFRA_STATION);
902
Dundi Ravitejae110a042018-04-18 13:11:37 +0530903 if (CSR_IS_CHANNEL_24GHZ(sta_chan))
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530904 sme_set_vowifi_mode(hdd_ctx->hHal, enable);
Dundi Ravitejae110a042018-04-18 13:11:37 +0530905 else
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530906 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
907 "VoWiFi command rejected as not connected in 2.4GHz");
Dundi Ravitejae110a042018-04-18 13:11:37 +0530908
909 if (enable && hdd_ctx->cfg_ini->dynSplitscan) {
910 hdd_ctx->is_vowifi_enabled = true;
911 hdd_ctx->issplitscan_enabled = TRUE;
912 sme_enable_disable_split_scan(hdd_ctx->hHal,
913 hdd_ctx->cfg_ini->nNumStaChanCombinedConc,
914 hdd_ctx->cfg_ini->nNumP2PChanCombinedConc);
915 } else {
916 hdd_ctx->is_vowifi_enabled = false;
Dundi Ravitejaab9d3092018-04-05 18:24:40 +0530917 }
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530918}
Abhishek Singh00b71972016-01-07 10:51:04 +0530919
920/* Function header left blank Intentionally */
921static int hdd_parse_setrmcrate_command(tANI_U8 *pValue,
922 tANI_U32 *pRate, tTxrateinfoflags *pTxFlags)
923{
924 tANI_U8 *inPtr = pValue;
925 int tempInt;
926 int v = 0;
927 char buf[32];
928 *pRate = 0;
929 *pTxFlags = 0;
930
931 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
932 /*no argument after the command*/
933 if (NULL == inPtr)
934 {
935 return -EINVAL;
936 }
937
938 /*no space after the command*/
939 else if (SPACE_ASCII_VALUE != *inPtr)
940 {
941 return -EINVAL;
942 }
943
944 /*removing empty spaces*/
945 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
946
947 /*no argument followed by spaces*/
948 if ('\0' == *inPtr)
949 {
950 return 0;
951 }
952
953 /*
954 * getting the first argument which sets multicast rate.
955 */
Ashish Kumar Dhanotiya06f9f202017-08-04 15:26:27 +0530956 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530957 v = kstrtos32(buf, 10, &tempInt);
958 if ( v < 0)
959 {
960 return -EINVAL;
961 }
962
963 /*
964 * Validate the multicast rate.
965 */
966 switch (tempInt)
967 {
968 default:
969 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
970 "Unsupported rate: %d", tempInt);
971 return -EINVAL;
972 case 0:
973 case 6:
974 case 9:
975 case 12:
976 case 18:
977 case 24:
978 case 36:
979 case 48:
980 case 54:
981 *pTxFlags = eHAL_TX_RATE_LEGACY;
982 *pRate = tempInt * 10;
983 break;
984 case 65:
985 *pTxFlags = eHAL_TX_RATE_HT20;
986 *pRate = tempInt * 10;
987 break;
988 case 72:
989 *pTxFlags = eHAL_TX_RATE_HT20 | eHAL_TX_RATE_SGI;
990 *pRate = 722; /* fractional rate 72.2 Mbps */
991 break;
992 }
993
994 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
995 "Rate: %d", *pRate);
996
997 return 0;
998}
999
1000/**---------------------------------------------------------------------------
1001
1002 \brief hdd_cfg80211_get_ibss_peer_info_cb() - Callback function for IBSS
1003 Peer Info request
1004
1005 This is an asynchronous callback function from SME when the peer info
1006 is received
1007
1008 \pUserData -> Adapter private data
1009 \pPeerInfoRsp -> Peer info response
1010
1011 \return - 0 for success non-zero for failure
1012 --------------------------------------------------------------------------*/
1013static void
1014hdd_cfg80211_get_ibss_peer_info_cb(v_VOID_t *pUserData, v_VOID_t *pPeerInfoRsp)
1015{
1016 hdd_adapter_t *pAdapter = (hdd_adapter_t *)pUserData;
1017 tSirPeerInfoRspParams *pPeerInfo = (tSirPeerInfoRspParams *)pPeerInfoRsp;
1018 hdd_station_ctx_t *pStaCtx;
1019 v_U8_t i;
1020
1021 /*Sanity check*/
1022 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
1023 {
1024 hddLog(LOGE,
1025 FL("invalid adapter or adapter has invalid magic"));
1026 return;
1027 }
1028
1029 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1030 if (NULL != pStaCtx && NULL != pPeerInfo &&
1031 eHAL_STATUS_SUCCESS == pPeerInfo->status)
1032 {
1033 pStaCtx->ibss_peer_info.status = pPeerInfo->status;
1034 pStaCtx->ibss_peer_info.numIBSSPeers = pPeerInfo->numPeers;
1035
1036 /* Paranoia check */
1037 if (pPeerInfo->numPeers < HDD_MAX_NUM_IBSS_STA)
1038 {
1039 for (i = 0; i < pPeerInfo->numPeers; i++)
1040 {
1041 memcpy(&pStaCtx->ibss_peer_info.ibssPeerList[i],
1042 &pPeerInfo->peerInfoParams[i],
1043 sizeof(hdd_ibss_peer_info_params_t));
1044 }
1045 hddLog(LOG1,
1046 FL("Peer Info copied in HDD"));
1047 }
1048 else
1049 {
1050 hddLog(LOGE,
1051 FL(" Number of peers %d returned is more than limit %d"),
1052 pPeerInfo->numPeers, HDD_MAX_NUM_IBSS_STA);
1053 }
1054 }
1055 else
1056 {
1057 hddLog(LOG1,
1058 FL("peerInfo returned is NULL"));
1059 }
1060
1061 complete(&pAdapter->ibss_peer_info_comp);
1062}
1063
1064/**---------------------------------------------------------------------------
1065
1066 \brief hdd_cfg80211_get_ibss_peer_info_all() -
1067
1068 Request function to get IBSS peer info from lower layers
1069
1070 \pAdapter -> Adapter context
1071
1072 \return - 0 for success non-zero for failure
1073 --------------------------------------------------------------------------*/
1074static
1075VOS_STATUS hdd_cfg80211_get_ibss_peer_info_all(hdd_adapter_t *pAdapter)
1076{
1077 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1078 long status;
1079 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1080
1081 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1082
1083 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1084 hdd_cfg80211_get_ibss_peer_info_cb,
1085 VOS_TRUE, 0xFF);
1086
1087 if (VOS_STATUS_SUCCESS == retStatus)
1088 {
1089 status = wait_for_completion_interruptible_timeout
1090 (&pAdapter->ibss_peer_info_comp,
1091 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1092
1093 /* status will be 0 if timed out */
1094 if (status <= 0)
1095 {
1096 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1097 __func__, status);
1098 retStatus = VOS_STATUS_E_FAILURE;
1099 return retStatus;
1100 }
1101 }
1102 else
1103 {
1104 hddLog(VOS_TRACE_LEVEL_WARN,
1105 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1106 }
1107
1108 return retStatus;
1109}
1110
1111/**---------------------------------------------------------------------------
1112
1113 \brief hdd_cfg80211_get_ibss_peer_info() -
1114
1115 Request function to get IBSS peer info from lower layers
1116
1117 \pAdapter -> Adapter context
1118 \staIdx -> Sta index for which the peer info is requested
1119
1120 \return - 0 for success non-zero for failure
1121 --------------------------------------------------------------------------*/
1122static VOS_STATUS
1123hdd_cfg80211_get_ibss_peer_info(hdd_adapter_t *pAdapter, v_U8_t staIdx)
1124{
1125 long status;
1126 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1127 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1128
1129 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1130
1131 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1132 hdd_cfg80211_get_ibss_peer_info_cb,
1133 VOS_FALSE, staIdx);
1134
1135 if (VOS_STATUS_SUCCESS == retStatus)
1136 {
1137 status = wait_for_completion_interruptible_timeout
1138 (&pAdapter->ibss_peer_info_comp,
1139 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1140
1141 /* status = 0 on timeout */
1142 if (status <= 0)
1143 {
1144 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1145 __func__, status);
1146 retStatus = VOS_STATUS_E_FAILURE;
1147 return retStatus;
1148 }
1149 }
1150 else
1151 {
1152 hddLog(VOS_TRACE_LEVEL_WARN,
1153 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1154 }
1155
1156 return retStatus;
1157}
1158
1159/* Function header left blank Intentionally */
1160VOS_STATUS
1161hdd_parse_get_ibss_peer_info(tANI_U8 *pValue, v_MACADDR_t *pPeerMacAddr)
1162{
1163 tANI_U8 *inPtr = pValue;
1164 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1165
1166 /*no argument after the command*/
1167 if (NULL == inPtr)
1168 {
1169 return VOS_STATUS_E_FAILURE;;
1170 }
1171
1172 /*no space after the command*/
1173 else if (SPACE_ASCII_VALUE != *inPtr)
1174 {
1175 return VOS_STATUS_E_FAILURE;;
1176 }
1177
1178 /*removing empty spaces*/
1179 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
1180
1181 /*no argument followed by spaces*/
1182 if ('\0' == *inPtr)
1183 {
1184 return VOS_STATUS_E_FAILURE;;
1185 }
1186
1187 /*getting the first argument ie the peer mac address */
1188 if (inPtr[2] != ':' || inPtr[5] != ':' || inPtr[8] != ':' ||
1189 inPtr[11] != ':' || inPtr[14] != ':')
1190 {
1191 return VOS_STATUS_E_FAILURE;;
1192 }
1193 sscanf(inPtr, "%2x:%2x:%2x:%2x:%2x:%2x",
1194 (unsigned int *)&pPeerMacAddr->bytes[0],
1195 (unsigned int *)&pPeerMacAddr->bytes[1],
1196 (unsigned int *)&pPeerMacAddr->bytes[2],
1197 (unsigned int *)&pPeerMacAddr->bytes[3],
1198 (unsigned int *)&pPeerMacAddr->bytes[4],
1199 (unsigned int *)&pPeerMacAddr->bytes[5]);
1200
1201 /* The command buffer seems to be fine */
1202 return VOS_STATUS_SUCCESS;
1203}
1204
1205/* Function header left blank Intentionally */
1206static int hdd_parse_set_ibss_oui_data_command(tANI_U8 *command, tANI_U8 *ie,
1207 tANI_U32 limit)
1208{
1209 tANI_U8 len;
1210 tANI_U8 data;
1211
1212 /* skip white space */
1213 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1214 {
1215 command++;
1216 limit--;
1217 }
1218
1219 /* skip element id and element length */
1220 len = 2;
1221
1222 /* extract oui */
1223 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1224 (limit > 1))
1225 {
1226 /* Convert ASCII to decimal */
1227 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1228 ie[len++] = data;
1229 command += 2;
1230 limit -= 2;
1231 }
1232
1233 /* skip white space */
1234 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1235 {
1236 command++;
1237 limit--;
1238 }
1239
1240 /* extract data */
1241 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1242 (limit > 1))
1243 {
1244 /* Convert ASCII to decimal */
1245 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1246 ie[len++] = data;
1247 command += 2;
1248 limit -= 2;
1249 }
1250
1251 /* fill element id and element length */
1252 ie[0] = IE_EID_VENDOR;
1253 ie[1] = len - 2;
1254
1255 return len;
1256}
1257
1258static tANI_U32 hdd_find_ibss_wpa_ie_pos(tANI_U8 *addIePtr, tANI_U32 addIeLen)
1259{
1260 tANI_U32 ieLenPresent = 0;
1261 int left = addIeLen;
1262 v_U8_t *ptr = addIePtr;
1263 v_U8_t elem_id,elem_len;
1264
1265 while(left >= 2)
1266 {
1267 elem_id = ptr[0];
1268 elem_len = ptr[1];
1269 left -= 2;
1270 if(elem_len > left)
1271 {
1272 hddLog(LOGE,
1273 FL("****Invalid elem_len=%d left=%d*****"),
1274 elem_len,left);
1275 return 0;
1276 }
1277 if ((elem_id == IE_EID_VENDOR) &&
1278 (left >= WPA_OUI_TYPE_SIZE))
1279 {
1280 if (!memcmp(&ptr[2], WPA_OUI_TYPE,
1281 WPA_OUI_TYPE_SIZE))
1282 {
1283 ieLenPresent += elem_len + 2;
1284 return ieLenPresent;
1285 }
1286 }
1287 ieLenPresent += (elem_len + 2);
1288 left -= elem_len;
1289 ptr += (elem_len + 2);
1290 }
1291 return 0;
1292}
1293
1294#endif /* WLAN_FEATURE_RMC */
1295
Rajeev79dbe4c2013-10-05 11:03:42 +05301296#ifdef FEATURE_WLAN_BATCH_SCAN
1297
1298/**---------------------------------------------------------------------------
1299
1300 \brief hdd_extract_assigned_int_from_str() - Extracts assigned integer from
1301 input string
1302
1303 This function extracts assigned integer from string in below format:
1304 "STRING=10" : extracts integer 10 from this string
1305
1306 \param - pInPtr Pointer to input string
1307 \param - base Base for string to int conversion(10 for decimal 16 for hex)
1308 \param - pOutPtr Pointer to variable in which extracted integer needs to be
1309 assigned
1310 \param - pLastArg to tell whether it is last arguement in input string or
1311 not
1312
1313 \return - NULL for failure cases
1314 pointer to next arguement in input string for success cases
1315 --------------------------------------------------------------------------*/
1316static tANI_U8 *
1317hdd_extract_assigned_int_from_str
1318(
1319 tANI_U8 *pInPtr,
1320 tANI_U8 base,
1321 tANI_U32 *pOutPtr,
1322 tANI_U8 *pLastArg
1323)
1324{
1325 int tempInt;
1326 int v = 0;
1327 char buf[32];
1328 int val = 0;
1329 *pLastArg = FALSE;
1330
1331 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1332 if (NULL == pInPtr)
1333 {
1334 return NULL;
1335 }
1336
1337 pInPtr++;
1338
1339 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1340
1341 val = sscanf(pInPtr, "%32s ", buf);
1342 if (val < 0 && val > strlen(pInPtr))
1343 {
1344 return NULL;
1345 }
1346 pInPtr += val;
1347 v = kstrtos32(buf, base, &tempInt);
1348 if (v < 0)
1349 {
1350 return NULL;
1351 }
Rajeev Kumar4d93d842014-01-02 18:31:21 -08001352 if (tempInt < 0)
1353 {
1354 tempInt = 0;
1355 }
Rajeev79dbe4c2013-10-05 11:03:42 +05301356 *pOutPtr = tempInt;
1357
1358 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1359 if (NULL == pInPtr)
1360 {
1361 *pLastArg = TRUE;
1362 return NULL;
1363 }
1364 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1365
1366 return pInPtr;
1367}
1368
1369/**---------------------------------------------------------------------------
1370
1371 \brief hdd_extract_assigned_char_from_str() - Extracts assigned char from
1372 input string
1373
1374 This function extracts assigned character from string in below format:
1375 "STRING=A" : extracts char 'A' from this string
1376
1377 \param - pInPtr Pointer to input string
1378 \param - pOutPtr Pointer to variable in which extracted char needs to be
1379 assigned
1380 \param - pLastArg to tell whether it is last arguement in input string or
1381 not
1382
1383 \return - NULL for failure cases
1384 pointer to next arguement in input string for success cases
1385 --------------------------------------------------------------------------*/
1386static tANI_U8 *
1387hdd_extract_assigned_char_from_str
1388(
1389 tANI_U8 *pInPtr,
1390 tANI_U8 *pOutPtr,
1391 tANI_U8 *pLastArg
1392)
1393{
1394 *pLastArg = FALSE;
1395
1396 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1397 if (NULL == pInPtr)
1398 {
1399 return NULL;
1400 }
1401
1402 pInPtr++;
1403
1404 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1405
1406 *pOutPtr = *pInPtr;
1407
1408 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1409 if (NULL == pInPtr)
1410 {
1411 *pLastArg = TRUE;
1412 return NULL;
1413 }
1414 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1415
1416 return pInPtr;
1417}
1418
1419
1420/**---------------------------------------------------------------------------
1421
1422 \brief hdd_parse_set_batchscan_command () - HDD parse set batch scan command
1423
1424 This function parses set batch scan command in below format:
1425 WLS_BATCHING_SET <space> followed by below arguements
1426 "SCANFREQ=XX" : Optional defaults to 30 sec
1427 "MSCAN=XX" : Required number of scans to attempt to batch
1428 "BESTN=XX" : Best Network (RSSI) defaults to 16
1429 "CHANNEL=<X,Y>" : optional defaults to all channels, can list 'A'or` B.
1430 A. implies only 5 GHz , B. implies only 2.4GHz
1431 "RTT=X" : optional defaults to 0
1432 returns the MIN of MSCAN or the max # of scans firmware can cache or -1 on
1433 error
1434
1435 For example input commands:
1436 1) WLS_BATCHING_SET SCANFREQ=60 MSCAN=10 BESTN=20 CHANNEL=A RTT=0 -> This is
1437 translated into set batch scan with following parameters:
1438 a) Frequence 60 seconds
1439 b) Batch 10 scans together
1440 c) Best RSSI to be 20
1441 d) 5GHz band only
1442 e) RTT is equal to 0
1443
1444 \param - pValue Pointer to input channel list
1445 \param - pHddSetBatchScanReq Pointer to HDD batch scan request structure
1446
1447 \return - 0 for success non-zero for failure
1448
1449 --------------------------------------------------------------------------*/
1450static int
1451hdd_parse_set_batchscan_command
1452(
1453 tANI_U8 *pValue,
1454 tSirSetBatchScanReq *pHddSetBatchScanReq
1455)
1456{
1457 tANI_U8 *inPtr = pValue;
1458 tANI_U8 val = 0;
1459 tANI_U8 lastArg = 0;
Abhishek Singh00b71972016-01-07 10:51:04 +05301460 tANI_U32 nScanFreq = HDD_SET_BATCH_SCAN_DEFAULT_FREQ;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001461 tANI_U32 nMscan;
Abhishek Singh00b71972016-01-07 10:51:04 +05301462 tANI_U32 nBestN = HDD_SET_BATCH_SCAN_BEST_NETWORK;
1463 tANI_U8 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1464 tANI_U32 nRtt = 0;
Rajeev Kumarc933d982013-11-18 20:04:20 -08001465 tANI_U32 temp;
Rajeev79dbe4c2013-10-05 11:03:42 +05301466
Rajeev79dbe4c2013-10-05 11:03:42 +05301467 /*go to space after WLS_BATCHING_SET command*/
1468 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1469 /*no argument after the command*/
1470 if (NULL == inPtr)
1471 {
1472 return -EINVAL;
1473 }
1474
1475 /*no space after the command*/
1476 else if (SPACE_ASCII_VALUE != *inPtr)
1477 {
1478 return -EINVAL;
1479 }
1480
1481 /*removing empty spaces*/
1482 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
1483
1484 /*no argument followed by spaces*/
1485 if ('\0' == *inPtr)
1486 {
1487 return -EINVAL;
1488 }
1489
1490 /*check and parse SCANFREQ*/
1491 if ((strncmp(inPtr, "SCANFREQ", 8) == 0))
1492 {
1493 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001494 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001495
Rajeev Kumarc933d982013-11-18 20:04:20 -08001496 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001497 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001498 nScanFreq = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001499 }
1500
Rajeev79dbe4c2013-10-05 11:03:42 +05301501 if ( (NULL == inPtr) || (TRUE == lastArg))
1502 {
1503 return -EINVAL;
1504 }
1505 }
1506
1507 /*check and parse MSCAN*/
1508 if ((strncmp(inPtr, "MSCAN", 5) == 0))
1509 {
1510 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001511 &nMscan, &lastArg);
1512
1513 if (0 == nMscan)
1514 {
1515 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1516 "invalid MSCAN=%d", nMscan);
1517 return -EINVAL;
1518 }
1519
Rajeev79dbe4c2013-10-05 11:03:42 +05301520 if (TRUE == lastArg)
1521 {
1522 goto done;
1523 }
1524 else if (NULL == inPtr)
1525 {
1526 return -EINVAL;
1527 }
1528 }
1529 else
1530 {
1531 return -EINVAL;
1532 }
1533
1534 /*check and parse BESTN*/
1535 if ((strncmp(inPtr, "BESTN", 5) == 0))
1536 {
1537 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001538 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001539
Rajeev Kumarc933d982013-11-18 20:04:20 -08001540 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001541 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001542 nBestN = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001543 }
1544
Rajeev79dbe4c2013-10-05 11:03:42 +05301545 if (TRUE == lastArg)
1546 {
1547 goto done;
1548 }
1549 else if (NULL == inPtr)
1550 {
1551 return -EINVAL;
1552 }
1553 }
1554
1555 /*check and parse CHANNEL*/
1556 if ((strncmp(inPtr, "CHANNEL", 7) == 0))
1557 {
1558 inPtr = hdd_extract_assigned_char_from_str(inPtr, &val, &lastArg);
Rajeev Kumarc933d982013-11-18 20:04:20 -08001559
Rajeev79dbe4c2013-10-05 11:03:42 +05301560 if (('A' == val) || ('a' == val))
1561 {
c_hpothuebf89732014-02-25 13:00:24 +05301562 ucRfBand = HDD_SET_BATCH_SCAN_5GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301563 }
1564 else if (('B' == val) || ('b' == val))
1565 {
c_hpothuebf89732014-02-25 13:00:24 +05301566 ucRfBand = HDD_SET_BATCH_SCAN_24GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301567 }
1568 else
1569 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001570 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1571 }
1572
1573 if (TRUE == lastArg)
1574 {
1575 goto done;
1576 }
1577 else if (NULL == inPtr)
1578 {
Rajeev79dbe4c2013-10-05 11:03:42 +05301579 return -EINVAL;
1580 }
1581 }
1582
1583 /*check and parse RTT*/
1584 if ((strncmp(inPtr, "RTT", 3) == 0))
1585 {
1586 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001587 &nRtt, &lastArg);
Rajeev79dbe4c2013-10-05 11:03:42 +05301588 if (TRUE == lastArg)
1589 {
1590 goto done;
1591 }
1592 if (NULL == inPtr)
1593 {
1594 return -EINVAL;
1595 }
1596 }
1597
1598
1599done:
1600
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001601 pHddSetBatchScanReq->scanFrequency = nScanFreq;
1602 pHddSetBatchScanReq->numberOfScansToBatch = nMscan;
1603 pHddSetBatchScanReq->bestNetwork = nBestN;
1604 pHddSetBatchScanReq->rfBand = ucRfBand;
1605 pHddSetBatchScanReq->rtt = nRtt;
1606
Rajeev79dbe4c2013-10-05 11:03:42 +05301607 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1608 "Received WLS_BATCHING_SET with SCANFREQ=%d "
1609 "MSCAN=%d BESTN=%d CHANNEL=%d RTT=%d",
1610 pHddSetBatchScanReq->scanFrequency,
1611 pHddSetBatchScanReq->numberOfScansToBatch,
1612 pHddSetBatchScanReq->bestNetwork,
1613 pHddSetBatchScanReq->rfBand,
1614 pHddSetBatchScanReq->rtt);
1615
1616 return 0;
1617}/*End of hdd_parse_set_batchscan_command*/
1618
1619/**---------------------------------------------------------------------------
1620
1621 \brief hdd_set_batch_scan_req_callback () - This function is called after
1622 receiving set batch scan response from FW and it saves set batch scan
1623 response data FW to HDD context and sets the completion event on
1624 which hdd_ioctl is waiting
1625
1626 \param - callbackContext Pointer to HDD adapter
1627 \param - pRsp Pointer to set batch scan response data received from FW
1628
1629 \return - nothing
1630
1631 --------------------------------------------------------------------------*/
1632static void hdd_set_batch_scan_req_callback
1633(
1634 void *callbackContext,
1635 tSirSetBatchScanRsp *pRsp
1636)
1637{
1638 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
1639 tSirSetBatchScanRsp *pHddSetBatchScanRsp;
1640
1641 /*sanity check*/
1642 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
1643 {
1644 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1645 "%s: Invalid pAdapter magic", __func__);
1646 VOS_ASSERT(0);
1647 return;
1648 }
1649 pHddSetBatchScanRsp = &pAdapter->hddSetBatchScanRsp;
1650
1651 /*save set batch scan response*/
1652 pHddSetBatchScanRsp->nScansToBatch = pRsp->nScansToBatch;
1653
1654 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
1655 "Received set batch scan rsp from FW with nScansToBatch=%d",
1656 pHddSetBatchScanRsp->nScansToBatch);
1657
1658 pAdapter->hdd_wait_for_set_batch_scan_rsp = FALSE;
1659 complete(&pAdapter->hdd_set_batch_scan_req_var);
1660
1661 return;
1662}/*End of hdd_set_batch_scan_req_callback*/
1663
1664
1665/**---------------------------------------------------------------------------
1666
1667 \brief hdd_populate_batch_scan_rsp_queue () - This function stores AP meta
1668 info in hdd batch scan response queue
1669
1670 \param - pAdapter Pointer to hdd adapter
1671 \param - pAPMetaInfo Pointer to access point meta info
1672 \param - scanId scan ID of batch scan response
1673 \param - isLastAp tells whether AP is last AP in batch scan response or not
1674
1675 \return - nothing
1676
1677 --------------------------------------------------------------------------*/
1678static void hdd_populate_batch_scan_rsp_queue( hdd_adapter_t* pAdapter,
1679 tpSirBatchScanNetworkInfo pApMetaInfo, tANI_U32 scanId, v_BOOL_t isLastAp)
1680{
1681 tHddBatchScanRsp *pHead;
1682 tHddBatchScanRsp *pNode;
1683 tHddBatchScanRsp *pPrev;
1684 tHddBatchScanRsp *pTemp;
1685 tANI_U8 ssidLen;
1686
1687 /*head of hdd batch scan response queue*/
1688 pHead = pAdapter->pBatchScanRsp;
1689
1690 pNode = (tHddBatchScanRsp *)vos_mem_malloc(sizeof(tHddBatchScanRsp));
1691 if (NULL == pNode)
1692 {
1693 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1694 "%s: Could not allocate memory", __func__);
1695 VOS_ASSERT(0);
1696 return;
1697 }
1698
1699 vos_mem_copy(pNode->ApInfo.bssid, pApMetaInfo->bssid,
1700 sizeof(pNode->ApInfo.bssid));
1701 ssidLen = strlen(pApMetaInfo->ssid);
1702 if (SIR_MAX_SSID_SIZE < ssidLen)
1703 {
1704 /*invalid scan result*/
1705 vos_mem_free(pNode);
1706 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1707 "%s: Invalid AP meta info ssidlen %d", __func__, ssidLen);
1708 return;
1709 }
1710 vos_mem_copy(pNode->ApInfo.ssid, pApMetaInfo->ssid, ssidLen);
1711 /*null terminate ssid*/
1712 pNode->ApInfo.ssid[ssidLen] = '\0';
1713 pNode->ApInfo.ch = pApMetaInfo->ch;
1714 pNode->ApInfo.rssi = pApMetaInfo->rssi;
1715 pNode->ApInfo.age = pApMetaInfo->timestamp;
1716 pNode->ApInfo.batchId = scanId;
1717 pNode->ApInfo.isLastAp = isLastAp;
1718
1719 pNode->pNext = NULL;
1720 if (NULL == pHead)
1721 {
1722 pAdapter->pBatchScanRsp = pNode;
1723 }
1724 else
1725 {
1726 pTemp = pHead;
1727 while (NULL != pTemp)
1728 {
1729 pPrev = pTemp;
1730 pTemp = pTemp->pNext;
1731 }
1732 pPrev->pNext = pNode;
1733 }
1734
1735 return;
1736}/*End of hdd_populate_batch_scan_rsp_queue*/
1737
1738/**---------------------------------------------------------------------------
1739
1740 \brief hdd_batch_scan_result_ind_callback () - This function is called after
1741 receiving batch scan response indication from FW. It saves get batch scan
1742 response data in HDD batch scan response queue. This callback sets the
1743 completion event on which hdd_ioctl is waiting only after getting complete
1744 batch scan response data from FW
1745
1746 \param - callbackContext Pointer to HDD adapter
1747 \param - pRsp Pointer to get batch scan response data received from FW
1748
1749 \return - nothing
1750
1751 --------------------------------------------------------------------------*/
1752static void hdd_batch_scan_result_ind_callback
1753(
1754 void *callbackContext,
1755 void *pRsp
1756)
1757{
1758 v_BOOL_t isLastAp;
1759 tANI_U32 numApMetaInfo;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001760 tANI_U32 numNetworkInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301761 tANI_U32 numberScanList;
1762 tANI_U32 nextScanListOffset;
1763 tANI_U32 nextApMetaInfoOffset;
1764 hdd_adapter_t* pAdapter;
1765 tpSirBatchScanList pScanList;
1766 tpSirBatchScanNetworkInfo pApMetaInfo;
1767 tpSirBatchScanResultIndParam pBatchScanRsp;/*batch scan rsp data from FW*/
1768 tSirSetBatchScanReq *pReq;
1769
1770 pAdapter = (hdd_adapter_t *)callbackContext;
1771 /*sanity check*/
Rajeev Kumar5286bb92013-12-05 11:52:10 -08001772 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
Rajeev79dbe4c2013-10-05 11:03:42 +05301773 {
1774 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1775 "%s: Invalid pAdapter magic", __func__);
1776 VOS_ASSERT(0);
1777 return;
1778 }
1779
1780 /*initialize locals*/
1781 pReq = &pAdapter->hddSetBatchScanReq;
1782 pBatchScanRsp = (tpSirBatchScanResultIndParam)pRsp;
1783 isLastAp = FALSE;
1784 numApMetaInfo = 0;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001785 numNetworkInScanList = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05301786 numberScanList = 0;
1787 nextScanListOffset = 0;
1788 nextApMetaInfoOffset = 0;
1789 pScanList = NULL;
1790 pApMetaInfo = NULL;
1791
1792 if ((NULL == pBatchScanRsp) || (NULL == pReq))
1793 {
1794 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001795 "%s: pBatchScanRsp is %pK pReq %pK", __func__, pBatchScanRsp, pReq);
Rajeev79dbe4c2013-10-05 11:03:42 +05301796 isLastAp = TRUE;
1797 goto done;
1798 }
1799
1800 pAdapter->numScanList = numberScanList = pBatchScanRsp->numScanLists;
1801 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1802 "Batch scan rsp: numberScalList %d", numberScanList);
1803
1804 if ((!numberScanList) || (numberScanList > pReq->numberOfScansToBatch))
1805 {
1806 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1807 "%s: numberScanList %d", __func__, numberScanList);
1808 isLastAp = TRUE;
1809 goto done;
1810 }
1811
1812 while (numberScanList)
1813 {
Rajeev Kumarce651e42013-10-21 18:57:15 -07001814 pScanList = (tpSirBatchScanList)((tANI_U8 *)pBatchScanRsp->scanResults +
Rajeev79dbe4c2013-10-05 11:03:42 +05301815 nextScanListOffset);
1816 if (NULL == pScanList)
1817 {
1818 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001819 "%s: pScanList is %pK", __func__, pScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05301820 isLastAp = TRUE;
1821 goto done;
1822 }
Rajeev Kumarce651e42013-10-21 18:57:15 -07001823 numNetworkInScanList = numApMetaInfo = pScanList->numNetworksInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301824 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumarce651e42013-10-21 18:57:15 -07001825 "Batch scan rsp: numApMetaInfo %d scanId %d",
1826 numApMetaInfo, pScanList->scanId);
Rajeev79dbe4c2013-10-05 11:03:42 +05301827
1828 if ((!numApMetaInfo) || (numApMetaInfo > pReq->bestNetwork))
1829 {
1830 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1831 "%s: numApMetaInfo %d", __func__, numApMetaInfo);
1832 isLastAp = TRUE;
1833 goto done;
1834 }
1835
Rajeev Kumarce651e42013-10-21 18:57:15 -07001836 /*Initialize next AP meta info offset for next scan list*/
1837 nextApMetaInfoOffset = 0;
1838
Rajeev79dbe4c2013-10-05 11:03:42 +05301839 while (numApMetaInfo)
1840 {
1841 pApMetaInfo = (tpSirBatchScanNetworkInfo)(pScanList->scanList +
1842 nextApMetaInfoOffset);
1843 if (NULL == pApMetaInfo)
1844 {
1845 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001846 "%s: pApMetaInfo is %pK", __func__, pApMetaInfo);
Rajeev79dbe4c2013-10-05 11:03:42 +05301847 isLastAp = TRUE;
1848 goto done;
1849 }
1850 /*calculate AP age*/
1851 pApMetaInfo->timestamp =
1852 pBatchScanRsp->timestamp - pApMetaInfo->timestamp;
1853
1854 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussaina7c8e412013-11-20 11:06:42 -08001855 "%s: bssId "MAC_ADDRESS_STR
1856 " ch %d rssi %d timestamp %d", __func__,
1857 MAC_ADDR_ARRAY(pApMetaInfo->bssid),
1858 pApMetaInfo->ch, pApMetaInfo->rssi,
1859 pApMetaInfo->timestamp);
Rajeev79dbe4c2013-10-05 11:03:42 +05301860
1861 /*mark last AP in batch scan response*/
1862 if ((TRUE == pBatchScanRsp->isLastResult) &&
1863 (1 == numberScanList) && (1 == numApMetaInfo))
1864 {
1865 isLastAp = TRUE;
1866 }
1867
1868 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1869 /*store batch scan repsonse in hdd queue*/
1870 hdd_populate_batch_scan_rsp_queue(pAdapter, pApMetaInfo,
1871 pScanList->scanId, isLastAp);
1872 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1873
1874 nextApMetaInfoOffset += sizeof(tSirBatchScanNetworkInfo);
1875 numApMetaInfo--;
1876 }
1877
Rajeev Kumarce651e42013-10-21 18:57:15 -07001878 nextScanListOffset += ((sizeof(tSirBatchScanList) - sizeof(tANI_U8))
1879 + (sizeof(tSirBatchScanNetworkInfo)
1880 * numNetworkInScanList));
Rajeev79dbe4c2013-10-05 11:03:42 +05301881 numberScanList--;
1882 }
1883
1884done:
1885
1886 /*notify hdd_ioctl only if complete batch scan rsp is received and it was
1887 requested from hdd_ioctl*/
1888 if ((TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp) &&
1889 (TRUE == isLastAp))
1890 {
1891 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
1892 complete(&pAdapter->hdd_get_batch_scan_req_var);
1893 }
1894
1895 return;
1896}/*End of hdd_batch_scan_result_ind_callback*/
1897
1898/**---------------------------------------------------------------------------
1899
1900 \brief hdd_format_batch_scan_rsp () - This function formats batch scan
1901 response as per batch scan FR request format by putting proper markers
1902
1903 \param - pDest pointer to destination buffer
1904 \param - cur_len current length
1905 \param - tot_len total remaining size which can be written to user space
1906 \param - pApMetaInfo Pointer to get batch scan response AP meta info
1907 \param - pAdapter Pointer to HDD adapter
1908
1909 \return - ret no of characters written
1910
1911 --------------------------------------------------------------------------*/
1912static tANI_U32
1913hdd_format_batch_scan_rsp
1914(
1915 tANI_U8 *pDest,
1916 tANI_U32 cur_len,
1917 tANI_U32 tot_len,
1918 tHddBatchScanRsp *pApMetaInfo,
1919 hdd_adapter_t* pAdapter
1920)
1921{
1922 tANI_U32 ret = 0;
1923 tANI_U32 rem_len = 0;
1924 tANI_U8 temp_len = 0;
1925 tANI_U8 temp_total_len = 0;
1926 tANI_U8 temp[HDD_BATCH_SCAN_AP_META_INFO_SIZE];
1927 tANI_U8 *pTemp = temp;
1928
1929 /*Batch scan reponse needs to be returned to user space in
1930 following format:
1931 "scancount=X\n" where X is the number of scans in current batch
1932 batch
1933 "trunc\n" optional present if current scan truncated
1934 "bssid=XX:XX:XX:XX:XX:XX\n"
1935 "ssid=XXXX\n"
1936 "freq=X\n" frequency in Mhz
1937 "level=XX\n"
1938 "age=X\n" ms
1939 "dist=X\n" cm (-1 if not available)
1940 "errror=X\n" (-1if not available)
1941 "====\n" (end of ap marker)
1942 "####\n" (end of scan marker)
1943 "----\n" (end of results)*/
1944 /*send scan result in above format to user space based on
1945 available length*/
1946 /*The GET response may have more data than the driver can return in its
1947 buffer. In that case the buffer should be filled to the nearest complete
1948 scan, ending with "%%%%".Subsequent callsshould return the remaining data
1949 starting with the next scan (optional .trunc\n., .apcount=X\n., etc).
1950 The final buffer should end with "----\n"*/
1951
1952 /*sanity*/
1953 if (cur_len > tot_len)
1954 {
1955 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1956 "%s: invaid cur_len %d tot_len %d", __func__, cur_len, tot_len);
1957 return 0;
1958 }
1959 else
1960 {
1961 rem_len = (tot_len - cur_len);
1962 }
1963
1964 /*end scan marker*/
1965 if (pApMetaInfo->ApInfo.batchId != pAdapter->prev_batch_id)
1966 {
1967 temp_len = snprintf(pTemp, sizeof(temp), "####\n");
1968 pTemp += temp_len;
1969 temp_total_len += temp_len;
1970 }
1971
1972 /*bssid*/
1973 temp_len = snprintf(pTemp, sizeof(temp),
1974 "bssid=0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n",
1975 pApMetaInfo->ApInfo.bssid[0], pApMetaInfo->ApInfo.bssid[1],
1976 pApMetaInfo->ApInfo.bssid[2], pApMetaInfo->ApInfo.bssid[3],
1977 pApMetaInfo->ApInfo.bssid[4], pApMetaInfo->ApInfo.bssid[5]);
1978 pTemp += temp_len;
1979 temp_total_len += temp_len;
1980
1981 /*ssid*/
1982 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "ssid=%s\n",
1983 pApMetaInfo->ApInfo.ssid);
1984 pTemp += temp_len;
1985 temp_total_len += temp_len;
1986
1987 /*freq*/
1988 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "freq=%d\n",
Rajeev Kumarc40f7512013-11-04 14:13:23 -08001989 sme_ChnToFreq(pApMetaInfo->ApInfo.ch));
Rajeev79dbe4c2013-10-05 11:03:42 +05301990 pTemp += temp_len;
1991 temp_total_len += temp_len;
1992
1993 /*level*/
1994 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "level=%d\n",
1995 pApMetaInfo->ApInfo.rssi);
1996 pTemp += temp_len;
1997 temp_total_len += temp_len;
1998
1999 /*age*/
Jeff Johnson02797792013-10-26 19:17:13 -07002000 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "age=%d\n",
Rajeev79dbe4c2013-10-05 11:03:42 +05302001 pApMetaInfo->ApInfo.age);
2002 pTemp += temp_len;
2003 temp_total_len += temp_len;
2004
2005 /*dist*/
2006 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "dist=-1\n");
2007 pTemp += temp_len;
2008 temp_total_len += temp_len;
2009
2010 /*error*/
2011 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "error=-1\n");
2012 pTemp += temp_len;
2013 temp_total_len += temp_len;
2014
2015 /*end AP marker*/
2016 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "====\n");
2017 pTemp += temp_len;
2018 temp_total_len += temp_len;
2019
2020 /*last AP in batch scan response*/
2021 if(TRUE == pApMetaInfo->ApInfo.isLastAp)
2022 {
2023 /*end scan marker*/
2024 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "####\n");
2025 pTemp += temp_len;
2026 temp_total_len += temp_len;
2027
2028 /*end batch scan result marker*/
2029 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "----\n");
2030 pTemp += temp_len;
2031 temp_total_len += temp_len;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002032
Rajeev79dbe4c2013-10-05 11:03:42 +05302033 }
2034
2035 if (temp_total_len < rem_len)
2036 {
2037 ret = temp_total_len + 1;
2038 strlcpy(pDest, temp, ret);
2039 pAdapter->isTruncated = FALSE;
2040 }
2041 else
2042 {
2043 pAdapter->isTruncated = TRUE;
2044 if (rem_len >= strlen("%%%%"))
2045 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08002046 ret = snprintf(pDest, sizeof(temp), "%%%%");
Rajeev79dbe4c2013-10-05 11:03:42 +05302047 }
Rajeev Kumarc933d982013-11-18 20:04:20 -08002048 else
Rajeev79dbe4c2013-10-05 11:03:42 +05302049 {
2050 ret = 0;
2051 }
2052 }
2053
2054 return ret;
2055
2056}/*End of hdd_format_batch_scan_rsp*/
2057
2058/**---------------------------------------------------------------------------
2059
2060 \brief hdd_populate_user_batch_scan_rsp() - This function populates user data
2061 buffer starting with head of hdd batch scan response queue
2062
2063 \param - pAdapter Pointer to HDD adapter
2064 \param - pDest Pointer to user data buffer
2065 \param - cur_len current offset in user buffer
2066 \param - rem_len remaining no of bytes in user buffer
2067
2068 \return - number of bytes written in user buffer
2069
2070 --------------------------------------------------------------------------*/
2071
2072tANI_U32 hdd_populate_user_batch_scan_rsp
2073(
2074 hdd_adapter_t* pAdapter,
2075 tANI_U8 *pDest,
2076 tANI_U32 cur_len,
2077 tANI_U32 rem_len
2078)
2079{
2080 tHddBatchScanRsp *pHead;
2081 tHddBatchScanRsp *pPrev;
2082 tANI_U32 len;
2083
Rajeev79dbe4c2013-10-05 11:03:42 +05302084 pAdapter->isTruncated = FALSE;
2085
2086 /*head of hdd batch scan response queue*/
2087 pHead = pAdapter->pBatchScanRsp;
2088 while (pHead)
2089 {
2090 len = hdd_format_batch_scan_rsp(pDest, cur_len, rem_len, pHead,
2091 pAdapter);
2092 pDest += len;
Rajeev Kumar292d2bb2013-10-23 15:01:44 -07002093 pDest--;
Rajeev79dbe4c2013-10-05 11:03:42 +05302094 cur_len += len;
2095 if(TRUE == pAdapter->isTruncated)
2096 {
2097 /*result is truncated return rest of scan rsp in next req*/
2098 cur_len = rem_len;
2099 break;
2100 }
2101 pPrev = pHead;
2102 pHead = pHead->pNext;
2103 pAdapter->pBatchScanRsp = pHead;
Rajeev Kumarbe17d8b2014-01-10 15:39:45 -08002104 if (TRUE == pPrev->ApInfo.isLastAp)
2105 {
2106 pAdapter->prev_batch_id = 0;
2107 }
2108 else
2109 {
2110 pAdapter->prev_batch_id = pPrev->ApInfo.batchId;
2111 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302112 vos_mem_free(pPrev);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002113 pPrev = NULL;
Rajeev79dbe4c2013-10-05 11:03:42 +05302114 }
2115
2116 return cur_len;
2117}/*End of hdd_populate_user_batch_scan_rsp*/
2118
2119/**---------------------------------------------------------------------------
2120
2121 \brief hdd_return_batch_scan_rsp_to_user () - This function returns batch
2122 scan response data from HDD queue to user space
2123 It does following in detail:
2124 a) if HDD has enough data in its queue then it 1st copies data to user
2125 space and then send get batch scan indication message to FW. In this
2126 case it does not wait on any event and batch scan response data will
2127 be populated in HDD response queue in MC thread context after receiving
2128 indication from FW
2129 b) else send get batch scan indication message to FW and wait on an event
2130 which will be set once HDD receives complete batch scan response from
2131 FW and then this function returns batch scan response to user space
2132
2133 \param - pAdapter Pointer to HDD adapter
2134 \param - pPrivData Pointer to priv_data
2135
2136 \return - 0 for success -EFAULT for failure
2137
2138 --------------------------------------------------------------------------*/
2139
2140int hdd_return_batch_scan_rsp_to_user
2141(
2142 hdd_adapter_t* pAdapter,
2143 hdd_priv_data_t *pPrivData,
2144 tANI_U8 *command
2145)
2146{
2147 tANI_U8 *pDest;
2148 tANI_U32 count = 0;
2149 tANI_U32 len = 0;
2150 tANI_U32 cur_len = 0;
2151 tANI_U32 rem_len = 0;
2152 eHalStatus halStatus;
2153 unsigned long rc;
2154 tSirTriggerBatchScanResultInd *pReq;
2155
2156 pReq = &pAdapter->hddTriggerBatchScanResultInd;
2157 pReq->param = 0;/*batch scan client*/
2158 pDest = (tANI_U8 *)(command + pPrivData->used_len);
2159 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
2160
2161 cur_len = pPrivData->used_len;
2162 if (pPrivData->total_len > pPrivData->used_len)
2163 {
2164 rem_len = pPrivData->total_len - pPrivData->used_len;
2165 }
2166 else
2167 {
2168 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2169 "%s: Invalid user data buffer total_len %d used_len %d",
2170 __func__, pPrivData->total_len, pPrivData->used_len);
2171 return -EFAULT;
2172 }
2173
2174 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2175 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2176 cur_len, rem_len);
2177 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2178
2179 /*enough scan result available in cache to return to user space or
2180 scan result needs to be fetched 1st from fw and then return*/
Rajeev Kumar99db6262013-11-11 15:23:36 -08002181 if (len == cur_len)
Rajeev79dbe4c2013-10-05 11:03:42 +05302182 {
2183 pAdapter->hdd_wait_for_get_batch_scan_rsp = TRUE;
2184 halStatus = sme_TriggerBatchScanResultInd(
2185 WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2186 pAdapter->sessionId, hdd_batch_scan_result_ind_callback,
2187 pAdapter);
2188 if ( eHAL_STATUS_SUCCESS == halStatus )
2189 {
2190 if (TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp)
2191 {
2192 INIT_COMPLETION(pAdapter->hdd_get_batch_scan_req_var);
2193 rc = wait_for_completion_timeout(
2194 &pAdapter->hdd_get_batch_scan_req_var,
2195 msecs_to_jiffies(HDD_GET_BATCH_SCAN_RSP_TIME_OUT));
Abhishek Singh00b71972016-01-07 10:51:04 +05302196 if (0 >= rc)
Rajeev79dbe4c2013-10-05 11:03:42 +05302197 {
2198 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Abhishek Singh00b71972016-01-07 10:51:04 +05302199 "%s: wait on hdd_get_batch_scan_req_var failed %ld",
2200 __func__, rc);
Rajeev79dbe4c2013-10-05 11:03:42 +05302201 return -EFAULT;
2202 }
2203 }
2204
2205 len = snprintf(pDest, HDD_BATCH_SCAN_AP_META_INFO_SIZE,
Jeff Johnson02797792013-10-26 19:17:13 -07002206 "scancount=%u\n", pAdapter->numScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05302207 pDest += len;
2208 cur_len += len;
2209
2210 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2211 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2212 cur_len, rem_len);
2213 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2214
2215 count = 0;
2216 len = (len - pPrivData->used_len);
2217 pDest = (command + pPrivData->used_len);
2218 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002219 "NEW BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302220 while(count < len)
2221 {
2222 printk("%c", *(pDest + count));
2223 count++;
2224 }
2225 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2226 "%s: copy %d data to user buffer", __func__, len);
2227 if (copy_to_user(pPrivData->buf, pDest, len))
2228 {
2229 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2230 "%s: failed to copy data to user buffer", __func__);
2231 return -EFAULT;
2232 }
2233 }
2234 else
2235 {
2236 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2237 "sme_GetBatchScanScan returned failure halStatus %d",
2238 halStatus);
2239 return -EINVAL;
2240 }
2241 }
2242 else
2243 {
Rajeev79dbe4c2013-10-05 11:03:42 +05302244 count = 0;
2245 len = (len - pPrivData->used_len);
2246 pDest = (command + pPrivData->used_len);
2247 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002248 "REMAINING TRUNCATED BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302249 while(count < len)
2250 {
2251 printk("%c", *(pDest + count));
2252 count++;
2253 }
Rajeev Kumar99db6262013-11-11 15:23:36 -08002254 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2255 "%s: copy %d data to user buffer", __func__, len);
Rajeev79dbe4c2013-10-05 11:03:42 +05302256 if (copy_to_user(pPrivData->buf, pDest, len))
2257 {
2258 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2259 "%s: failed to copy data to user buffer", __func__);
2260 return -EFAULT;
2261 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302262 }
2263
2264 return 0;
2265} /*End of hdd_return_batch_scan_rsp_to_user*/
2266
Rajeev Kumar8b373292014-01-08 20:36:55 -08002267/**---------------------------------------------------------------------------
2268
2269 \brief hdd_handle_batch_scan_ioctl () - This function handles WLS_BATCHING
2270 IOCTLs from user space. Following BATCH SCAN DEV IOCTs are handled:
2271 WLS_BATCHING VERSION
2272 WLS_BATCHING SET
2273 WLS_BATCHING GET
2274 WLS_BATCHING STOP
2275
2276 \param - pAdapter Pointer to HDD adapter
2277 \param - pPrivdata Pointer to priv_data
2278 \param - command Pointer to command
2279
2280 \return - 0 for success -EFAULT for failure
2281
2282 --------------------------------------------------------------------------*/
2283
2284int hdd_handle_batch_scan_ioctl
2285(
2286 hdd_adapter_t *pAdapter,
2287 hdd_priv_data_t *pPrivdata,
2288 tANI_U8 *command
2289)
2290{
2291 int ret = 0;
Yue Mae36e3552014-03-05 17:06:20 -08002292 hdd_context_t *pHddCtx;
2293
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302294 ENTER();
2295
Yue Mae36e3552014-03-05 17:06:20 -08002296 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2297 ret = wlan_hdd_validate_context(pHddCtx);
2298 if (ret)
2299 {
Yue Mae36e3552014-03-05 17:06:20 -08002300 goto exit;
2301 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002302
2303 if (strncmp(command, "WLS_BATCHING VERSION", 20) == 0)
2304 {
2305 char extra[32];
2306 tANI_U8 len = 0;
2307 tANI_U8 version = HDD_BATCH_SCAN_VERSION;
2308
2309 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2310 {
2311 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2312 "%s: Batch scan feature is not supported by FW", __func__);
2313 ret = -EINVAL;
2314 goto exit;
2315 }
2316
2317 len = scnprintf(extra, sizeof(extra), "WLS_BATCHING_VERSION %d",
2318 version);
2319 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2320 {
2321 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2322 "%s: failed to copy data to user buffer", __func__);
2323 ret = -EFAULT;
2324 goto exit;
2325 }
2326 ret = HDD_BATCH_SCAN_VERSION;
2327 }
2328 else if (strncmp(command, "WLS_BATCHING SET", 16) == 0)
2329 {
2330 int status;
2331 tANI_U8 *value = (command + 16);
2332 eHalStatus halStatus;
2333 unsigned long rc;
2334 tSirSetBatchScanReq *pReq = &pAdapter->hddSetBatchScanReq;
2335 tSirSetBatchScanRsp *pRsp = &pAdapter->hddSetBatchScanRsp;
2336
2337 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2338 {
2339 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2340 "%s: Batch scan feature is not supported by FW", __func__);
2341 ret = -EINVAL;
2342 goto exit;
2343 }
2344
2345 if ((WLAN_HDD_INFRA_STATION != pAdapter->device_mode) &&
2346 (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) &&
2347 (WLAN_HDD_P2P_GO != pAdapter->device_mode) &&
2348 (WLAN_HDD_P2P_DEVICE != pAdapter->device_mode))
2349 {
2350 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302351 "Received WLS_BATCHING SET command in invalid mode %s (%d) "
Rajeev Kumar8b373292014-01-08 20:36:55 -08002352 "WLS_BATCHING_SET is only allowed in infra STA/P2P client mode",
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302353 hdd_device_modetoString(pAdapter->device_mode),
2354 pAdapter->device_mode);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002355 ret = -EINVAL;
2356 goto exit;
2357 }
2358
2359 status = hdd_parse_set_batchscan_command(value, pReq);
2360 if (status)
2361 {
2362 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2363 "Invalid WLS_BATCHING SET command");
2364 ret = -EINVAL;
2365 goto exit;
2366 }
2367
2368
2369 pAdapter->hdd_wait_for_set_batch_scan_rsp = TRUE;
2370 halStatus = sme_SetBatchScanReq(WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2371 pAdapter->sessionId, hdd_set_batch_scan_req_callback,
2372 pAdapter);
2373
2374 if ( eHAL_STATUS_SUCCESS == halStatus )
2375 {
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302376 char extra[32];
2377 tANI_U8 len = 0;
2378 tANI_U8 mScan = 0;
2379
Rajeev Kumar8b373292014-01-08 20:36:55 -08002380 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2381 "sme_SetBatchScanReq returned success halStatus %d",
2382 halStatus);
2383 if (TRUE == pAdapter->hdd_wait_for_set_batch_scan_rsp)
2384 {
2385 INIT_COMPLETION(pAdapter->hdd_set_batch_scan_req_var);
2386 rc = wait_for_completion_timeout(
2387 &pAdapter->hdd_set_batch_scan_req_var,
2388 msecs_to_jiffies(HDD_SET_BATCH_SCAN_REQ_TIME_OUT));
2389 if (0 == rc)
2390 {
2391 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2392 "%s: Timeout waiting for set batch scan to complete",
2393 __func__);
2394 ret = -EINVAL;
2395 goto exit;
2396 }
2397 }
2398 if ( !pRsp->nScansToBatch )
2399 {
2400 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2401 "%s: Received set batch scan failure response from FW",
2402 __func__);
2403 ret = -EINVAL;
2404 goto exit;
2405 }
2406 /*As per the Batch Scan Framework API we should return the MIN of
2407 either MSCAN or the max # of scans firmware can cache*/
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302408 mScan = MIN(pReq->numberOfScansToBatch , pRsp->nScansToBatch);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002409
2410 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STARTED;
2411
2412 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2413 "%s: request MSCAN %d response MSCAN %d ret %d",
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302414 __func__, pReq->numberOfScansToBatch, pRsp->nScansToBatch, mScan);
2415 len = scnprintf(extra, sizeof(extra), "%d", mScan);
2416 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2417 {
2418 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2419 "%s: failed to copy MSCAN value to user buffer", __func__);
2420 ret = -EFAULT;
2421 goto exit;
2422 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002423 }
2424 else
2425 {
2426 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2427 "sme_SetBatchScanReq returned failure halStatus %d",
2428 halStatus);
2429 ret = -EINVAL;
2430 goto exit;
2431 }
2432 }
2433 else if (strncmp(command, "WLS_BATCHING STOP", 17) == 0)
2434 {
2435 eHalStatus halStatus;
2436 tSirStopBatchScanInd *pInd = &pAdapter->hddStopBatchScanInd;
2437 pInd->param = 0;
2438
2439 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2440 {
2441 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2442 "%s: Batch scan feature is not supported by FW", __func__);
2443 ret = -EINVAL;
2444 goto exit;
2445 }
2446
2447 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2448 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302449 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002450 "Batch scan is not yet enabled batch scan state %d",
2451 pAdapter->batchScanState);
2452 ret = -EINVAL;
2453 goto exit;
2454 }
2455
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002456 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2457 hdd_deinit_batch_scan(pAdapter);
2458 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2459
Rajeev Kumar8b373292014-01-08 20:36:55 -08002460 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
2461
2462 halStatus = sme_StopBatchScanInd(WLAN_HDD_GET_HAL_CTX(pAdapter), pInd,
2463 pAdapter->sessionId);
2464 if ( eHAL_STATUS_SUCCESS == halStatus )
2465 {
2466 ret = 0;
2467 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2468 "sme_StopBatchScanInd returned success halStatus %d",
2469 halStatus);
2470 }
2471 else
2472 {
2473 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2474 "sme_StopBatchScanInd returned failure halStatus %d",
2475 halStatus);
2476 ret = -EINVAL;
2477 goto exit;
2478 }
2479 }
2480 else if (strncmp(command, "WLS_BATCHING GET", 16) == 0)
2481 {
2482 tANI_U32 remain_len;
2483
2484 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2485 {
2486 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2487 "%s: Batch scan feature is not supported by FW", __func__);
2488 ret = -EINVAL;
2489 goto exit;
2490 }
2491
2492 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2493 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302494 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002495 "Batch scan is not yet enabled could not return results"
2496 "Batch Scan state %d",
2497 pAdapter->batchScanState);
2498 ret = -EINVAL;
2499 goto exit;
2500 }
2501
2502 pPrivdata->used_len = 16;
2503 remain_len = pPrivdata->total_len - pPrivdata->used_len;
2504 if (remain_len < pPrivdata->total_len)
2505 {
2506 /*Clear previous batch scan response data if any*/
2507 vos_mem_zero((tANI_U8 *)(command + pPrivdata->used_len), remain_len);
2508 }
2509 else
2510 {
2511 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2512 "Invalid total length from user space can't fetch batch"
2513 " scan response total_len %d used_len %d remain len %d",
2514 pPrivdata->total_len, pPrivdata->used_len, remain_len);
2515 ret = -EINVAL;
2516 goto exit;
2517 }
2518 ret = hdd_return_batch_scan_rsp_to_user(pAdapter, pPrivdata, command);
2519 }
2520
2521exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302522 EXIT();
Rajeev Kumar8b373292014-01-08 20:36:55 -08002523 return ret;
2524}
2525
2526
Rajeev79dbe4c2013-10-05 11:03:42 +05302527#endif/*End of FEATURE_WLAN_BATCH_SCAN*/
2528
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302529#if defined(WLAN_FEATURE_VOWIFI_11R) || defined(FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
2530/**
2531 * hdd_assign_handoff_src_reassoc - Set handoff source as REASSOC
2532 * to Handoff request
2533 * @handoffInfo: Pointer to Handoff request
2534 * @src: enum of handoff_src
2535 * Return: None
2536 */
2537#ifndef QCA_WIFI_ISOC
2538static inline void hdd_assign_handoff_src_reassoc(tCsrHandoffRequest
2539 *handoffInfo, handoff_src src)
2540{
2541 handoffInfo->src = src;
2542}
2543#else
2544static inline void hdd_assign_handoff_src_reassoc(tCsrHandoffRequest
2545 *handoffInfo, handoff_src src)
2546{
2547}
2548#endif
2549
2550/**
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302551 * hdd_reassoc() - perform a user space-directed reassoc
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302552 *
2553 * @pAdapter: Adapter upon which the command was received
2554 * @bssid: BSSID with which to reassociate
2555 * @channel: channel upon which to reassociate
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302556 * @src: The source for the trigger of this action
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302557 *
2558 * Return: 0 for success non-zero for failure
2559 */
2560#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Selvaraj, Sridhar8ecb4192016-06-23 17:50:49 +05302561int hdd_reassoc(hdd_adapter_t *pAdapter, const tANI_U8 *bssid,
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302562 const tANI_U8 channel, const handoff_src src)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302563{
2564 hdd_station_ctx_t *pHddStaCtx;
2565 tCsrHandoffRequest handoffInfo;
2566 hdd_context_t *pHddCtx = NULL;
2567 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2568
2569 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2570
2571 /* if not associated, no need to proceed with reassoc */
2572 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
2573 hddLog(LOG1, FL("Not associated"));
2574 return -EINVAL;
2575 }
2576
2577 /* if the target bssid is same as currently associated AP,
2578 then no need to proceed with reassoc */
2579 if (!memcmp(bssid, pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr))) {
2580 hddLog(LOG1, FL("Reassoc BSSID is same as currently associated AP bssid"));
2581 return -EINVAL;
2582 }
2583
2584 /* Check channel number is a valid channel number */
2585 if (VOS_STATUS_SUCCESS !=
2586 wlan_hdd_validate_operation_channel(pAdapter, channel)) {
2587 hddLog(LOGE, FL("Invalid Channel %d"), channel);
2588 return -EINVAL;
2589 }
2590
2591 /* Proceed with reassoc */
2592 handoffInfo.channel = channel;
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302593 hdd_assign_handoff_src_reassoc(&handoffInfo, src);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302594 memcpy(handoffInfo.bssid, bssid, sizeof(tSirMacAddr));
2595 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
2596 return 0;
2597}
2598#else
Selvaraj, Sridhar8ecb4192016-06-23 17:50:49 +05302599int hdd_reassoc(hdd_adapter_t *pAdapter, const tANI_U8 *bssid,
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302600 const tANI_U8 channel, const handoff_src src)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302601{
2602 return -EPERM;
2603}
2604#endif
2605
2606/**
2607 * hdd_parse_reassoc_v1() - parse version 1 of the REASSOC command
2608 * This function parses the v1 REASSOC command with the format
2609 * REASSOC xx:xx:xx:xx:xx:xx CH where "xx:xx:xx:xx:xx:xx" is the
2610 * Hex-ASCII representation of the BSSID and CH is the ASCII
2611 * representation of the channel. For example
2612 * REASSOC 00:0a:0b:11:22:33 48
2613 *
2614 * @pAdapter: Adapter upon which the command was received
2615 * @command: ASCII text command that was received
2616 *
2617 * Return: 0 for success non-zero for failure
2618 */
2619static int
2620hdd_parse_reassoc_v1(hdd_adapter_t *pAdapter, const char *command)
2621{
2622 tANI_U8 channel = 0;
2623 tSirMacAddr bssid;
2624 int ret;
2625
2626 ret = hdd_parse_reassoc_command_v1_data(command, bssid, &channel);
2627 if (ret)
2628 hddLog(LOGE, FL("Failed to parse reassoc command data"));
2629 else
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302630 ret = hdd_reassoc(pAdapter, bssid, channel, REASSOC);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302631
2632 return ret;
2633}
2634
2635/**
2636 * hdd_parse_reassoc_v2() - parse version 2 of the REASSOC command
2637 * This function parses the v2 REASSOC command with the format
2638 * REASSOC <android_wifi_reassoc_params>
2639 *
2640 * @pAdapter: Adapter upon which the command was received
2641 * @command: command that was received, ASCII command followed
2642 * by binary data
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302643 * @total_len: Total length of the command received
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302644 *
2645 * Return: 0 for success non-zero for failure
2646 */
2647static int
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302648hdd_parse_reassoc_v2(hdd_adapter_t *pAdapter, const char *command,
2649 int total_len)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302650{
2651 struct android_wifi_reassoc_params params;
2652 tSirMacAddr bssid;
2653 int ret;
2654
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302655 if (total_len < sizeof(params) + 8) {
2656 hddLog(LOGE, FL("Invalid command length"));
2657 return -EINVAL;
2658 }
2659
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302660 /* The params are located after "REASSOC " */
2661 memcpy(&params, command + 8, sizeof(params));
2662
2663 if (!mac_pton(params.bssid, (u8 *)&bssid)) {
2664 hddLog(LOGE, FL("MAC address parsing failed"));
2665 ret = -EINVAL;
2666 } else {
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302667 ret = hdd_reassoc(pAdapter, bssid, params.channel, REASSOC);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302668 }
2669 return ret;
2670}
2671
2672/**
2673 * hdd_parse_reassoc() - parse the REASSOC command
2674 * There are two different versions of the REASSOC command.Version 1
2675 * of the command contains a parameter list that is ASCII characters
2676 * whereas version 2 contains a combination of ASCII and binary
2677 * payload. Determine if a version 1 or a version 2 command is being
2678 * parsed by examining the parameters, and then dispatch the parser
2679 * that is appropriate for the command.
2680 *
2681 * @pAdapter: Adapter upon which the command was received
2682 * @command: command that was received
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302683 * @total_len: Total length of the command received
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302684 *
2685 * Return: 0 for success non-zero for failure
2686 */
2687static int
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302688hdd_parse_reassoc(hdd_adapter_t *pAdapter, const char *command, int total_len)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302689{
2690 int ret;
2691
2692 /*
2693 * both versions start with "REASSOC"
2694 * v1 has a bssid and channel # as an ASCII string
2695 * REASSOC xx:xx:xx:xx:xx:xx CH
2696 * v2 has a C struct
2697 * REASSOC <binary c struct>
2698 *
2699 * The first field in the v2 struct is also the bssid in ASCII.
2700 * But in the case of a v2 message the BSSID is NUL-terminated.
2701 * Hence we can peek at that offset to see if this is V1 or V2
2702 * REASSOC xx:xx:xx:xx:xx:xx*
2703 * 1111111111222222
2704 * 01234567890123456789012345
2705 */
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302706
2707 if (total_len < 26) {
2708 hddLog(LOGE, FL("Invalid command (total_len=%d)"), total_len);
2709 return -EINVAL;
2710 }
2711
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302712 if (command[25])
2713 ret = hdd_parse_reassoc_v1(pAdapter, command);
2714 else
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302715 ret = hdd_parse_reassoc_v2(pAdapter, command, total_len);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302716
2717 return ret;
2718}
2719#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE FEATURE_WLAN_LFR */
2720
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302721struct bcn_miss_rate_priv {
2722 int bcn_miss_rate;
2723};
2724
2725/**
2726 * get_bcn_miss_rate_cb() callback invoked on receiving beacon miss
2727 * rate from firmware
2728 * @status: Status of get beacon miss rate operation
2729 * @bcnMissRate: Beacon miss rate
2730 * @context: Context passed while registering callback
2731 *
2732 * This function is invoked by WDA layer on receiving
2733 * WDI_GET_BCN_MISS_RATE_RSP
2734 *
2735 * Return: None
2736 */
2737static void get_bcn_miss_rate_cb(VOS_STATUS status, int bcnMissRate,
2738 void *context)
c_hpothu92367912014-05-01 15:18:17 +05302739{
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302740 struct hdd_request *request;
2741 struct bcn_miss_rate_priv *priv;
c_hpothu39eb1e32014-06-26 16:31:50 +05302742
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302743 request = hdd_request_get(context);
2744 if (!request) {
2745 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
2746 return;
2747 }
c_hpothu92367912014-05-01 15:18:17 +05302748
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302749 priv = hdd_request_priv(request);
c_hpothu92367912014-05-01 15:18:17 +05302750
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302751 if (VOS_STATUS_SUCCESS == status)
2752 priv->bcn_miss_rate = bcnMissRate;
2753 else
2754 hddLog(VOS_TRACE_LEVEL_ERROR, FL("failed to get bcnMissRate"));
c_hpothu92367912014-05-01 15:18:17 +05302755
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302756 hdd_request_complete(request);
2757 hdd_request_put(request);
Hanumanth Reddy Pothulad0d3c172018-05-02 18:53:05 +05302758
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302759 return;
c_hpothu92367912014-05-01 15:18:17 +05302760}
2761
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302762struct fw_stats_priv {
2763 tSirFwStatsResult *fw_stats;
2764};
2765
2766/**
2767 * hdd_fw_stats_cb() callback invoked on receiving firmware stats
2768 * from firmware
2769 * @status: Status of get firmware stats operation
2770 * @fwStatsResult: firmware stats
2771 * @context: Context passed while registering callback
2772 *
2773 * This function is invoked by WDA layer on receiving
2774 * WDI_GET_FW_STATS_RSP
2775 *
2776 * Return: None
2777 */
2778static void hdd_fw_stats_cb(VOS_STATUS status,
2779 tSirFwStatsResult *fwStatsResult, void *context)
Satyanarayana Dash72806012014-12-02 14:30:08 +05302780{
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302781 struct hdd_request *request;
2782 struct fw_stats_priv *priv;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302783
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302784 hddLog(VOS_TRACE_LEVEL_INFO, FL("with status = %d"),status);
Satyanarayana Dash72806012014-12-02 14:30:08 +05302785
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302786 request = hdd_request_get(context);
2787 if (!request) {
2788 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
2789 return;
2790 }
2791 priv = hdd_request_priv(request);
2792
2793 if (VOS_STATUS_SUCCESS == status)
2794 *priv->fw_stats = *fwStatsResult;
2795 else
2796 priv->fw_stats = NULL;
2797
2798 hdd_request_complete(request);
2799 hdd_request_put(request);
2800 return;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302801}
2802
jge35567202017-06-21 16:39:38 +08002803/*
2804 *hdd_parse_setmaxtxpower_command() - HDD Parse MAXTXPOWER command
2805 *@pValue Pointer to MAXTXPOWER command
2806 *@pTxPower Pointer to tx power
2807 *
2808 *This function parses the MAXTXPOWER command passed in the format
2809 * MAXTXPOWER<space>X(Tx power in dbm)
2810 * For example input commands:
2811 * 1) MAXTXPOWER -8 -> This is translated into set max TX power to -8 dbm
2812 * 2) MAXTXPOWER -23 -> This is translated into set max TX power to -23 dbm
2813 *
2814 *return - 0 for success non-zero for failure
2815 */
2816static int hdd_parse_setmaxtxpower_command(unsigned char *pValue, int *pTxPower)
2817{
2818 unsigned char *inPtr = pValue;
2819 int tempInt;
2820 int v = 0;
2821 *pTxPower = 0;
2822
2823 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
2824 /* no argument after the command */
2825 if (NULL == inPtr)
2826 return -EINVAL;
2827 /* no space after the command */
2828 else if (SPACE_ASCII_VALUE != *inPtr)
2829 return -EINVAL;
2830
2831 /* removing empty spaces */
2832 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
2833
2834 /* no argument followed by spaces */
2835 if ('\0' == *inPtr)
2836 return 0;
2837
2838 v = kstrtos32(inPtr, 10, &tempInt);
2839
2840 /* Range checking for passed parameter */
2841 if ((tempInt < HDD_MIN_TX_POWER) || (tempInt > HDD_MAX_TX_POWER))
2842 return -EINVAL;
2843
2844 *pTxPower = tempInt;
2845
2846 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2847 "SETMAXTXPOWER: %d", *pTxPower);
2848
2849 return 0;
2850}
2851
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302852static int hdd_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command, char *extra, tANI_U8 n, tANI_U8 *len)
2853{
2854 int ret = 0;
2855
2856 if (!pCfg || !command || !extra || !len)
2857 {
2858 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2859 "%s: argument passsed for GETDWELLTIME is incorrect", __func__);
2860 ret = -EINVAL;
2861 return ret;
2862 }
2863
2864 if (strncmp(command, "GETDWELLTIME ACTIVE MAX", 23) == 0)
2865 {
2866 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MAX %u\n",
2867 (int)pCfg->nActiveMaxChnTime);
2868 return ret;
2869 }
2870 else if (strncmp(command, "GETDWELLTIME ACTIVE MIN", 23) == 0)
2871 {
2872 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MIN %u\n",
2873 (int)pCfg->nActiveMinChnTime);
2874 return ret;
2875 }
2876 else if (strncmp(command, "GETDWELLTIME PASSIVE MAX", 24) == 0)
2877 {
2878 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MAX %u\n",
2879 (int)pCfg->nPassiveMaxChnTime);
2880 return ret;
2881 }
2882 else if (strncmp(command, "GETDWELLTIME PASSIVE MIN", 24) == 0)
2883 {
2884 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MIN %u\n",
2885 (int)pCfg->nPassiveMinChnTime);
2886 return ret;
2887 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302888 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
2889 {
2890 *len = scnprintf(extra, n, "GETDWELLTIME %u \n",
2891 (int)pCfg->nActiveMaxChnTime);
2892 return ret;
2893 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302894 else
2895 {
2896 ret = -EINVAL;
2897 }
2898
2899 return ret;
2900}
2901
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05302902/**
2903 * hdd_btc_get_dwell_time() - Get BTC dwell time parameters
2904 * @pCfg: Pointer to HDD context
2905 * @command: ASCII text command that is received
2906 * @extra: Pointer to copy data sent to user
2907 * @n: size of 'extra' buffer
2908 * @len: length copied to 'extra' buffer
2909 *
2910 * Driver commands:
2911 * wpa_cli DRIVER BTCGETDWELLTIME ESCO MAX
2912 * wpa_cli DRIVER BTCGETDWELLTIME ESCO MIN
2913 * wpa_cli DRIVER BTCGETDWELLTIME SCO MAX
2914 * wpa_cli DRIVER BTCGETDWELLTIME SCO MIN
2915 *
2916 * Return: 0 for success non-zero for failure
2917 */
2918
2919static int hdd_btc_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command,
2920 char *extra, tANI_U8 n, tANI_U8 *len)
2921{
2922 int ret = 0;
2923
2924 if (!pCfg || !command || !extra || !len)
2925 {
2926 hddLog(LOGE, FL("Argument passsed for BTCGETDWELLTIME is incorrect"));
2927 ret = -EINVAL;
2928 return ret;
2929 }
2930
2931 if (strncmp(command, "BTCGETDWELLTIME ESCO MAX", 24) == 0)
2932 {
2933 *len = scnprintf(extra, n, "BTCGETDWELLTIME ESCO MAX %u\n",
2934 (int)pCfg->max_chntime_btc_esco);
2935 return ret;
2936 }
2937 else if (strncmp(command, "BTCGETDWELLTIME ESCO MIN", 24) == 0)
2938 {
2939 *len = scnprintf(extra, n, "BTCGETDWELLTIME ESCO MIN %u\n",
2940 (int)pCfg->min_chntime_btc_esco);
2941 return ret;
2942 }
2943 else if (strncmp(command, "BTCGETDWELLTIME SCO MAX", 23) == 0)
2944 {
2945 *len = scnprintf(extra, n, "BTCGETDWELLTIME SCO MAX %u\n",
2946 (int)pCfg->max_chntime_btc_sco);
2947 return ret;
2948 }
2949 else if (strncmp(command, "BTCGETDWELLTIME SCO MIN", 23) == 0)
2950 {
2951 *len = scnprintf(extra, n, "BTCGETDWELLTIME SCO MIN %u\n",
2952 (int)pCfg->min_chntime_btc_sco);
2953 return ret;
2954 }
2955 else
2956 {
2957 ret = -EINVAL;
2958 }
2959
2960 return ret;
2961}
2962
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302963int hdd_drv_cmd_validate(tANI_U8 *command, int len)
2964{
2965 if (command[len] != ' ')
2966 return -EINVAL;
2967
2968 return 0;
2969}
2970
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05302971#ifdef WLAN_AP_STA_CONCURRENCY
2972
2973/**
2974 * hdd_conc_get_dwell_time() - Get concurrency dwell time parameters
2975 * @pCfg: Pointer to HDD context
2976 * @command: ASCII text command that is received
2977 * @extra: Pointer to copy data sent to user
2978 * @n: size of 'extra' buffer
2979 * @len: length copied to 'extra' buffer
2980 *
2981 * Driver commands:
2982 * wpa_cli DRIVER CONCGETDWELLTIME ACTIVE MAX
2983 * wpa_cli DRIVER CONCGETDWELLTIME ACTIVE MIN
2984 * wpa_cli DRIVER CONCGETDWELLTIME PASSIVE MAX
2985 * wpa_cli DRIVER CONCGETDWELLTIME PASSIVE MIN
2986 *
2987 * Return: 0 for success non-zero for failure
2988 */
2989
2990static int hdd_conc_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command,
2991 char *extra, tANI_U8 n, tANI_U8 *len)
2992{
2993 int ret = 0;
2994
2995 if (!pCfg || !command || !extra || !len)
2996 {
2997 hddLog(LOGE, FL("Argument passsed for CONCGETDWELLTIME is incorrect"));
2998 ret = -EINVAL;
2999 return ret;
3000 }
3001
3002 if (strncmp(command, "CONCGETDWELLTIME ACTIVE MAX", 27) == 0)
3003 {
3004 *len = scnprintf(extra, n, "CONCGETDWELLTIME ACTIVE MAX %u\n",
3005 (int)pCfg->nActiveMaxChnTimeConc);
3006 return ret;
3007 }
3008 else if (strncmp(command, "CONCGETDWELLTIME ACTIVE MIN", 27) == 0)
3009 {
3010 *len = scnprintf(extra, n, "CONCGETDWELLTIME ACTIVE MIN %u\n",
3011 (int)pCfg->nActiveMinChnTimeConc);
3012 return ret;
3013 }
3014 else if (strncmp(command, "CONCGETDWELLTIME PASSIVE MAX", 28) == 0)
3015 {
3016 *len = scnprintf(extra, n, "CONCGETDWELLTIME PASSIVE MAX %u\n",
3017 (int)pCfg->nPassiveMaxChnTimeConc);
3018 return ret;
3019 }
3020 else if (strncmp(command, "CONCGETDWELLTIME PASSIVE MIN", 28) == 0)
3021 {
3022 *len = scnprintf(extra, n, "CONCGETDWELLTIME PASSIVE MIN %u\n",
3023 (int)pCfg->nPassiveMinChnTimeConc);
3024 return ret;
3025 }
3026 else
3027 {
3028 ret = -EINVAL;
3029 }
3030
3031 return ret;
3032}
3033
3034/**
3035 * hdd_conc_set_dwell_time() - Set concurrency dwell time parameters
3036 * @pAdapter: Adapter upon which the command was received
3037 * @command: ASCII text command that is received
3038 *
3039 * Driver commands:
3040 * wpa_cli DRIVER CONCSETDWELLTIME ACTIVE MAX <value>
3041 * wpa_cli DRIVER CONCSETDWELLTIME ACTIVE MIN <value>
3042 * wpa_cli DRIVER CONCSETDWELLTIME PASSIVE MAX <value
3043 * wpa_cli DRIVER CONCSETDWELLTIME PASSIVE MIN <value>
3044 *
3045 * Return: 0 for success non-zero for failure
3046 */
3047
3048static int hdd_conc_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3049{
3050 tHalHandle hHal;
3051 hdd_config_t *pCfg;
3052 tANI_U8 *value = command;
3053 int val = 0, ret = 0, temp = 0;
3054 tSmeConfigParams smeConfig;
3055
3056 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3057 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
3058 {
3059 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME is incorrect"));
3060 ret = -EINVAL;
3061 return ret;
3062 }
3063
3064 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3065 sme_GetConfigParam(hHal, &smeConfig);
3066
3067 if (strncmp(command, "CONCSETDWELLTIME ACTIVE MAX", 27) == 0 )
3068 {
3069 if (hdd_drv_cmd_validate(command, 27)) {
3070 hddLog(LOGE, FL("Invalid driver command"));
3071 return -EINVAL;
3072 }
3073
3074 value = value + 28;
3075 temp = kstrtou32(value, 10, &val);
3076 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_CONC_MIN ||
3077 val > CFG_ACTIVE_MAX_CHANNEL_TIME_CONC_MAX)
3078 {
3079 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME ACTIVE MAX is incorrect"));
3080 ret = -EFAULT;
3081 return ret;
3082 }
3083 pCfg->nActiveMaxChnTimeConc = val;
3084 smeConfig.csrConfig.nActiveMaxChnTimeConc = val;
3085 sme_UpdateConfig(hHal, &smeConfig);
3086 }
3087 else if (strncmp(command, "CONCSETDWELLTIME ACTIVE MIN", 27) == 0)
3088 {
3089 if (hdd_drv_cmd_validate(command, 27)) {
3090 hddLog(LOGE, FL("Invalid driver command"));
3091 return -EINVAL;
3092 }
3093
3094 value = value + 28;
3095 temp = kstrtou32(value, 10, &val);
3096 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_CONC_MIN ||
3097 val > CFG_ACTIVE_MIN_CHANNEL_TIME_CONC_MAX)
3098 {
3099 hddLog(LOGE, FL("Argument passsed for CONCSETDWELLTIME ACTIVE MIN is incorrect"));
3100 ret = -EFAULT;
3101 return ret;
3102 }
3103 pCfg->nActiveMinChnTimeConc = val;
3104 smeConfig.csrConfig.nActiveMinChnTimeConc = val;
3105 sme_UpdateConfig(hHal, &smeConfig);
3106 }
3107 else if (strncmp(command, "CONCSETDWELLTIME PASSIVE MAX", 28) == 0)
3108 {
3109 if (hdd_drv_cmd_validate(command, 28)) {
3110 hddLog(LOGE, FL("Invalid driver command"));
3111 return -EINVAL;
3112 }
3113
3114 value = value + 29;
3115 temp = kstrtou32(value, 10, &val);
3116 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_CONC_MIN ||
3117 val > CFG_PASSIVE_MAX_CHANNEL_TIME_CONC_MAX)
3118 {
3119 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME PASSIVE MAX is incorrect"));
3120 ret = -EFAULT;
3121 return ret;
3122 }
3123 pCfg->nPassiveMaxChnTimeConc = val;
3124 smeConfig.csrConfig.nPassiveMaxChnTimeConc = val;
3125 sme_UpdateConfig(hHal, &smeConfig);
3126 }
3127 else if (strncmp(command, "CONCSETDWELLTIME PASSIVE MIN", 28) == 0)
3128 {
3129 if (hdd_drv_cmd_validate(command, 28)) {
3130 hddLog(LOGE, FL("Invalid driver command"));
3131 return -EINVAL;
3132 }
3133
3134 value = value + 29;
3135 temp = kstrtou32(value, 10, &val);
3136 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_CONC_MIN ||
3137 val > CFG_PASSIVE_MIN_CHANNEL_TIME_CONC_MAX )
3138 {
3139 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME PASSIVE MIN is incorrect"));
3140 ret = -EFAULT;
3141 return ret;
3142 }
3143 pCfg->nPassiveMinChnTimeConc = val;
3144 smeConfig.csrConfig.nPassiveMinChnTimeConc = val;
3145 sme_UpdateConfig(hHal, &smeConfig);
3146 }
3147 else
3148 {
3149 ret = -EINVAL;
3150 }
3151
3152 return ret;
3153}
3154
3155#endif
3156
3157/**
3158 * hdd_btc_set_dwell_time() - Set BTC dwell time parameters
3159 * @pAdapter: Adapter upon which the command was received
3160 * @command: ASCII text command that is received
3161 *
3162 * Driver commands:
3163 * wpa_cli DRIVER BTCSETDWELLTIME ESCO MAX <value>
3164 * wpa_cli DRIVER BTCSETDWELLTIME ESCO MIN <value>
3165 * wpa_cli DRIVER BTCSETDWELLTIME SCO MAX <value>
3166 * wpa_cli DRIVER BTCSETDWELLTIME SCO MIN <value>
3167 *
3168 * Return: 0 for success non-zero for failure
3169 */
3170
3171static int hdd_btc_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3172{
3173 tHalHandle hHal;
3174 hdd_config_t *pCfg;
3175 tANI_U8 *value = command;
3176 int val = 0, ret = 0, temp = 0;
3177 tSmeConfigParams smeConfig;
3178
3179 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3180 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
3181 {
3182 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME is incorrect"));
3183 ret = -EINVAL;
3184 return ret;
3185 }
3186
3187 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3188 sme_GetConfigParam(hHal, &smeConfig);
3189
3190 if (strncmp(command, "BTCSETDWELLTIME ESCO MAX", 24) == 0)
3191 {
3192 if (hdd_drv_cmd_validate(command, 24)) {
3193 hddLog(LOGE, FL("Invalid driver command"));
3194 return -EINVAL;
3195 }
3196
3197 value = value + 25;
3198 temp = kstrtou32(value, 10, &val);
3199 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_MIN ||
3200 val > CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_MAX)
3201 {
3202 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME ESCO MAX is incorrect"));
3203 ret = -EFAULT;
3204 return ret;
3205 }
3206 pCfg->max_chntime_btc_esco = val;
3207 smeConfig.csrConfig.max_chntime_btc_esco = val;
3208 sme_UpdateConfig(hHal, &smeConfig);
3209 }
3210 else if (strncmp(command, "BTCSETDWELLTIME ESCO MIN", 24) == 0)
3211 {
3212 if (hdd_drv_cmd_validate(command, 24)) {
3213 hddLog(LOGE, FL("Invalid driver command"));
3214 return -EINVAL;
3215 }
3216
3217 value = value + 25;
3218 temp = kstrtou32(value, 10, &val);
3219 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_MIN ||
3220 val > CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_MAX)
3221 {
3222 hddLog(LOGE, FL("Argument passsed for BTCSETDWELLTIME ESCO MIN is incorrect"));
3223 ret = -EFAULT;
3224 return ret;
3225 }
3226 pCfg->min_chntime_btc_esco = val;
3227 smeConfig.csrConfig.min_chntime_btc_esco = val;
3228 sme_UpdateConfig(hHal, &smeConfig);
3229 }
3230 else if (strncmp(command, "BTCSETDWELLTIME SCO MAX", 23) == 0)
3231 {
3232 if (hdd_drv_cmd_validate(command, 23)) {
3233 hddLog(LOGE, FL("Invalid driver command"));
3234 return -EINVAL;
3235 }
3236
3237 value = value + 24;
3238 temp = kstrtou32(value, 10, &val);
3239 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_SCO_MIN ||
3240 val > CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_SCO_MAX)
3241 {
3242 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME SCO MAX is incorrect"));
3243 ret = -EFAULT;
3244 return ret;
3245 }
3246 pCfg->max_chntime_btc_sco = val;
3247 smeConfig.csrConfig.max_chntime_btc_sco = val;
3248 sme_UpdateConfig(hHal, &smeConfig);
3249 }
3250 else if (strncmp(command, "BTCSETDWELLTIME SCO MIN", 23) == 0)
3251 {
3252 if (hdd_drv_cmd_validate(command, 23)) {
3253 hddLog(LOGE, FL("Invalid driver command"));
3254 return -EINVAL;
3255 }
3256
3257 value = value + 24;
3258 temp = kstrtou32(value, 10, &val);
3259 if (temp != 0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_SCO_MIN ||
3260 val > CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_SCO_MAX)
3261 {
3262 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME SCO MIN is incorrect"));
3263 ret = -EFAULT;
3264 return ret;
3265 }
3266 pCfg->min_chntime_btc_sco = val;
3267 smeConfig.csrConfig.min_chntime_btc_sco = val;
3268 sme_UpdateConfig(hHal, &smeConfig);
3269 }
3270 else
3271 {
3272 ret = -EINVAL;
3273 }
3274
3275 return ret;
3276}
3277
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303278static int hdd_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3279{
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303280 tHalHandle hHal;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303281 hdd_config_t *pCfg;
3282 tANI_U8 *value = command;
3283 int val = 0, ret = 0, temp = 0;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303284 tSmeConfigParams smeConfig;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303285
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303286 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3287 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303288 {
3289 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3290 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
3291 ret = -EINVAL;
3292 return ret;
3293 }
3294
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303295 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3296 sme_GetConfigParam(hHal, &smeConfig);
3297
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303298 if (strncmp(command, "SETDWELLTIME ACTIVE MAX", 23) == 0 )
3299 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303300 if (hdd_drv_cmd_validate(command, 23))
3301 return -EINVAL;
3302
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303303 value = value + 24;
3304 temp = kstrtou32(value, 10, &val);
3305 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
3306 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
3307 {
3308 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3309 "%s: argument passed for SETDWELLTIME ACTIVE MAX is incorrect", __func__);
3310 ret = -EFAULT;
3311 return ret;
3312 }
3313 pCfg->nActiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303314 smeConfig.csrConfig.nActiveMaxChnTime = val;
3315 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303316 }
3317 else if (strncmp(command, "SETDWELLTIME ACTIVE MIN", 23) == 0)
3318 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303319 if (hdd_drv_cmd_validate(command, 23))
3320 return -EINVAL;
3321
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303322 value = value + 24;
3323 temp = kstrtou32(value, 10, &val);
3324 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_MIN ||
3325 val > CFG_ACTIVE_MIN_CHANNEL_TIME_MAX )
3326 {
3327 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3328 "%s: argument passsed for SETDWELLTIME ACTIVE MIN is incorrect", __func__);
3329 ret = -EFAULT;
3330 return ret;
3331 }
3332 pCfg->nActiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303333 smeConfig.csrConfig.nActiveMinChnTime = val;
3334 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303335 }
3336 else if (strncmp(command, "SETDWELLTIME PASSIVE MAX", 24) == 0)
3337 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303338 if (hdd_drv_cmd_validate(command, 24))
3339 return -EINVAL;
3340
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303341 value = value + 25;
3342 temp = kstrtou32(value, 10, &val);
3343 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_MIN ||
3344 val > CFG_PASSIVE_MAX_CHANNEL_TIME_MAX )
3345 {
3346 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3347 "%s: argument passed for SETDWELLTIME PASSIVE MAX is incorrect", __func__);
3348 ret = -EFAULT;
3349 return ret;
3350 }
3351 pCfg->nPassiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303352 smeConfig.csrConfig.nPassiveMaxChnTime = val;
3353 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303354 }
3355 else if (strncmp(command, "SETDWELLTIME PASSIVE MIN", 24) == 0)
3356 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303357 if (hdd_drv_cmd_validate(command, 24))
3358 return -EINVAL;
3359
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303360 value = value + 25;
3361 temp = kstrtou32(value, 10, &val);
3362 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_MIN ||
3363 val > CFG_PASSIVE_MIN_CHANNEL_TIME_MAX )
3364 {
3365 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3366 "%s: argument passed for SETDWELLTIME PASSIVE MIN is incorrect", __func__);
3367 ret = -EFAULT;
3368 return ret;
3369 }
3370 pCfg->nPassiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303371 smeConfig.csrConfig.nPassiveMinChnTime = val;
3372 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303373 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05303374 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
3375 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303376 if (hdd_drv_cmd_validate(command, 12))
3377 return -EINVAL;
3378
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05303379 value = value + 13;
3380 temp = kstrtou32(value, 10, &val);
3381 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
3382 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
3383 {
3384 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3385 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
3386 ret = -EFAULT;
3387 return ret;
3388 }
3389 pCfg->nActiveMaxChnTime = val;
3390 smeConfig.csrConfig.nActiveMaxChnTime = val;
3391 sme_UpdateConfig(hHal, &smeConfig);
3392 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303393 else
3394 {
3395 ret = -EINVAL;
3396 }
3397
3398 return ret;
3399}
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303400static int hdd_cmd_setFccChannel(hdd_context_t *pHddCtx, tANI_U8 *cmd,
3401 tANI_U8 cmd_len)
3402{
3403 tANI_U8 *value;
3404 tANI_U8 fcc_constraint;
3405
3406 eHalStatus status;
3407 int ret = 0;
3408 value = cmd + cmd_len + 1;
3409
3410 ret = kstrtou8(value, 10, &fcc_constraint);
3411 if ((ret < 0) || (fcc_constraint > 1)) {
3412 /*
3413 * If the input value is greater than max value of datatype,
3414 * then also it is a failure
3415 */
3416 hddLog(VOS_TRACE_LEVEL_ERROR,
3417 "%s: value out of range", __func__);
3418 return -EINVAL;
3419 }
3420
Agrawal Ashish842eea82016-02-04 17:56:16 +05303421 status = sme_handleSetFccChannel(pHddCtx->hHal, fcc_constraint,
3422 pHddCtx->scan_info.mScanPending);
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303423 if (status != eHAL_STATUS_SUCCESS)
3424 ret = -EPERM;
3425
3426 return ret;
3427}
3428
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05303429/**---------------------------------------------------------------------------
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303430
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05303431 \brief hdd_enable_disable_ca_event() - When Host sends IOCTL (enabled),
3432 FW will send *ONE* CA ind to Host(even though it is duplicate).
3433 When Host send IOCTL (disable), FW doesn't perform any action.
3434 Whenever any change in CA *and* WLAN is in SAP/P2P-GO mode, FW
3435 sends CA ind to host. (regard less of IOCTL status)
3436 \param - pHddCtx - HDD context
3437 \param - command - command received from framework
3438 \param - cmd_len - len of the command
3439
3440 \return - 0 on success, appropriate error values on failure.
3441
3442 --------------------------------------------------------------------------*/
3443int hdd_enable_disable_ca_event(hdd_context_t *pHddCtx, tANI_U8* command, tANI_U8 cmd_len)
3444{
3445 tANI_U8 set_value;
3446 int ret = 0;
3447 eHalStatus status;
3448
3449 ret = wlan_hdd_validate_context(pHddCtx);
3450 if (0 != ret)
3451 {
3452 ret = -EINVAL;
3453 goto exit;
3454 }
3455
3456 if (pHddCtx->cfg_ini->gOptimizeCAevent == 0)
3457 {
3458 hddLog(VOS_TRACE_LEVEL_ERROR, "Enable gOptimizeCAevent"
3459 " ini param to control channel avooidance indication");
3460 ret = 0;
3461 goto exit;
3462 }
3463
3464 set_value = command[cmd_len + 1] - '0';
3465 status = sme_enableDisableChanAvoidIndEvent(pHddCtx->hHal, set_value);
3466 if (status != eHAL_STATUS_SUCCESS)
3467 {
3468 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to send"
3469 " enableDisableChanAoidance command to SME\n", __func__);
3470 ret = -EINVAL;
3471 }
3472
3473exit:
3474 return ret;
3475}
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303476
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303477/**
3478 * wlan_hdd_fastreassoc_handoff_request() - Post Handoff request to SME
3479 * @pHddCtx: Pointer to the HDD context
3480 * @channel: channel to reassociate
3481 * @targetApBssid: Target AP/BSSID to reassociate
3482 *
3483 * Return: None
3484 */
3485#if defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD) && !defined(QCA_WIFI_ISOC)
3486static void wlan_hdd_fastreassoc_handoff_request(hdd_context_t *pHddCtx,
3487 uint8_t channel, tSirMacAddr targetApBssid)
3488{
3489 tCsrHandoffRequest handoffInfo;
3490 handoffInfo.channel = channel;
3491 handoffInfo.src = FASTREASSOC;
3492 vos_mem_copy(handoffInfo.bssid, targetApBssid, sizeof(tSirMacAddr));
3493 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
3494}
3495#else
3496static void wlan_hdd_fastreassoc_handoff_request(hdd_context_t *pHddCtx,
3497 uint8_t channel, tSirMacAddr targetApBssid)
3498{
3499}
3500#endif
3501
3502/**
3503 * csr_fastroam_neighbor_ap_event() - Function to trigger scan/roam
3504 * @pAdapter: Pointer to HDD adapter
3505 * @channel: Channel to scan/roam
3506 * @targetApBssid: BSSID to roam
3507 *
3508 * Return: None
3509 */
3510#ifdef QCA_WIFI_ISOC
3511static void csr_fastroam_neighbor_ap_event(hdd_adapter_t *pAdapter,
3512 uint8_t channel, tSirMacAddr targetApBssid)
3513{
3514 smeIssueFastRoamNeighborAPEvent(WLAN_HDD_GET_HAL_CTX(pAdapter),
3515 &targetApBssid[0], eSME_ROAM_TRIGGER_SCAN, channel);
3516}
3517#else
3518static void csr_fastroam_neighbor_ap_event(hdd_adapter_t *pAdapter,
3519 uint8_t channel, tSirMacAddr targetApBssid)
3520{
3521}
3522#endif
3523
3524/**
3525 * wlan_hdd_handle_fastreassoc() - Handle fastreassoc command
3526 * @pAdapter: pointer to hdd adapter
3527 * @command: pointer to the command received
3528 *
3529 * Return: VOS_STATUS enum
3530 */
3531static VOS_STATUS wlan_hdd_handle_fastreassoc(hdd_adapter_t *pAdapter,
3532 uint8_t *command)
3533{
3534 tANI_U8 *value = command;
3535 tANI_U8 channel = 0;
3536 tSirMacAddr targetApBssid;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303537 hdd_station_ctx_t *pHddStaCtx = NULL;
3538 hdd_context_t *pHddCtx = NULL;
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05303539 int ret;
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303540 tCsrRoamModifyProfileFields mod_profile_fields;
3541 uint32_t roam_id = 0;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303542 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3543 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3544
3545 /* if not associated, no need to proceed with reassoc */
3546 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
3547 hddLog(LOG1, FL("Not associated!"));
3548 return eHAL_STATUS_FAILURE;
3549 }
3550
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05303551 ret = hdd_parse_reassoc_command_v1_data(value, targetApBssid, &channel);
3552 if (ret) {
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303553 hddLog(LOGE, FL("Failed to parse reassoc command data"));
3554 return eHAL_STATUS_FAILURE;
3555 }
3556
3557 /* if the target bssid is same as currently associated AP,
3558 then no need to proceed with reassoc */
3559 if (vos_mem_compare(targetApBssid,
3560 pHddStaCtx->conn_info.bssId,
3561 sizeof(tSirMacAddr))) {
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303562 sme_GetModifyProfileFields(pHddCtx->hHal, pAdapter->sessionId,
3563 &mod_profile_fields);
3564 sme_RoamReassoc(pHddCtx->hHal, pAdapter->sessionId, NULL,
3565 mod_profile_fields, &roam_id, 1);
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303566 hddLog(LOG1, FL("Reassoc BSSID is same as currently associated AP bssid"));
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303567 return eHAL_STATUS_SUCCESS;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303568 }
3569
3570 /* Check channel number is a valid channel number */
3571 if (VOS_STATUS_SUCCESS !=
3572 wlan_hdd_validate_operation_channel(pAdapter, channel)) {
3573 hddLog(LOGE, FL("Invalid Channel [%d]"), channel);
3574 return eHAL_STATUS_FAILURE;
3575 }
3576
3577 /* Proceed with reassoc */
3578 wlan_hdd_fastreassoc_handoff_request(pHddCtx, channel, targetApBssid);
3579
3580 /* Proceed with scan/roam */
3581 csr_fastroam_neighbor_ap_event(pAdapter, channel, targetApBssid);
3582
3583 return eHAL_STATUS_SUCCESS;
3584}
3585
3586/**
3587 * hdd_assign_reassoc_handoff - Set handoff source as REASSOC
3588 * @handoffInfo: Pointer to the csr Handoff Request.
3589 *
3590 * Return: None
3591 */
3592#ifndef QCA_WIFI_ISOC
3593static inline void hdd_assign_reassoc_handoff(tCsrHandoffRequest *handoffInfo)
3594{
3595 handoffInfo->src = REASSOC;
3596}
3597#else
3598static inline void hdd_assign_reassoc_handoff(tCsrHandoffRequest *handoffInfo)
3599{
3600}
3601#endif
3602
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303603/**
3604 * wlan_hdd_free_cache_channels() - Free the cache channels list
3605 * @hdd_ctx: Pointer to HDD context
3606 *
3607 * Return: None
3608 */
3609
3610static void wlan_hdd_free_cache_channels(hdd_context_t *hdd_ctx)
3611{
Ashish Kumar Dhanotiya19803832018-05-24 19:05:48 +05303612 if(!hdd_ctx || !hdd_ctx->original_channels)
3613 return;
3614
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303615 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303616 hdd_ctx->original_channels->num_channels = 0;
3617 vos_mem_free(hdd_ctx->original_channels->channel_info);
3618 hdd_ctx->original_channels->channel_info = NULL;
3619 vos_mem_free(hdd_ctx->original_channels);
3620 hdd_ctx->original_channels = NULL;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303621 mutex_unlock(&hdd_ctx->cache_channel_lock);
3622}
3623
3624/**
3625 * hdd_alloc_chan_cache() - Allocate the memory to cache the channel
3626 * info for the channels received in command SET_DISABLE_CHANNEL_LIST
3627 * @hdd_ctx: Pointer to HDD context
3628 * @num_chan: Number of channels for which memory needs to
3629 * be allocated
3630 *
3631 * Return: 0 on success and error code on failure
3632 */
3633
3634int hdd_alloc_chan_cache(hdd_context_t *hdd_ctx, int num_chan)
3635{
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303636 hdd_ctx->original_channels =
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303637 vos_mem_malloc(sizeof(struct hdd_cache_channels));
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303638 if (!hdd_ctx->original_channels) {
3639 hddLog(VOS_TRACE_LEVEL_ERROR,
3640 "In %s, VOS_MALLOC_ERR", __func__);
3641 return -EINVAL;
3642 }
3643 hdd_ctx->original_channels->num_channels = num_chan;
3644 hdd_ctx->original_channels->channel_info =
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303645 vos_mem_malloc(num_chan *
3646 sizeof(struct hdd_cache_channel_info));
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303647 if (!hdd_ctx->original_channels->channel_info) {
3648 hddLog(VOS_TRACE_LEVEL_ERROR,
3649 "In %s, VOS_MALLOC_ERR", __func__);
3650 hdd_ctx->original_channels->num_channels = 0;
3651 vos_mem_free(hdd_ctx->original_channels);
3652 hdd_ctx->original_channels = NULL;
3653 return -ENOMEM;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303654 }
3655 return 0;
3656
3657}
3658
3659
3660int hdd_parse_disable_chan_cmd(hdd_adapter_t *adapter, tANI_U8 *ptr)
3661{
3662 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
3663 hdd_context_t *hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, pvosGCtx);
3664 tANI_U8 *param;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303665 int j, tempInt, ret = 0, i, num_channels;
3666 int parsed_channels[MAX_CHANNEL];
3667 bool is_command_repeated = false;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303668
3669 if (NULL == pvosGCtx) {
3670 hddLog(VOS_TRACE_LEVEL_FATAL,
3671 "VOS Global Context is NULL");
3672 return -EINVAL;
3673 }
3674
3675 if (NULL == hdd_ctx) {
3676 hddLog(VOS_TRACE_LEVEL_FATAL, "HDD Context is NULL");
3677 return -EINVAL;
3678 }
3679
3680 param = strchr(ptr, ' ');
3681 /*no argument after the command*/
3682 if (NULL == param)
3683 return -EINVAL;
3684
3685 /*no space after the command*/
3686 else if (SPACE_ASCII_VALUE != *param)
3687 return -EINVAL;
3688
3689 param++;
3690
3691 /*removing empty spaces*/
3692 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3693 param++;
3694
3695 /*no argument followed by spaces*/
3696 if ('\0' == *param)
3697 return -EINVAL;
3698
3699 /*getting the first argument ie the number of channels*/
3700 if (sscanf(param, "%d ", &tempInt) != 1) {
3701 hddLog(VOS_TRACE_LEVEL_ERROR,
3702 "%s: Cannot get number of channels from input",
3703 __func__);
3704 return -EINVAL;
3705 }
3706
3707 if (tempInt < 0 || tempInt > MAX_CHANNEL) {
3708 hddLog(VOS_TRACE_LEVEL_ERROR,
3709 "%s: Invalid Number of channel received", __func__);
3710 return -EINVAL;
3711 }
3712
3713 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
3714 "%s: Number of channel to disable are: %d",
3715 __func__, tempInt);
3716
3717 if (!tempInt) {
3718 if (!wlan_hdd_restore_channels(hdd_ctx)) {
3719 /*
3720 * Free the cache channels only when the command is
3721 * received with num channels as 0
3722 */
3723 wlan_hdd_free_cache_channels(hdd_ctx);
3724 }
3725 return 0;
3726 }
3727
3728 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303729 if (!hdd_ctx->original_channels) {
3730 if (hdd_alloc_chan_cache(hdd_ctx, tempInt)) {
3731 ret = -ENOMEM;
3732 goto mem_alloc_failed;
3733 }
3734 } else if (hdd_ctx->original_channels->num_channels != tempInt) {
3735 hddLog(VOS_TRACE_LEVEL_ERROR,
3736 "%s, Invalid No of channel provided in the list",
3737 __func__);
3738 ret = -EINVAL;
3739 is_command_repeated = true;
3740 goto parse_failed;
3741 } else {
3742 is_command_repeated = true;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303743 }
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303744
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303745 num_channels = tempInt;
3746
3747 for (j = 0; j < num_channels; j++) {
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303748 /*
3749 * param pointing to the beginning of first space
3750 * after number of channels
3751 */
3752 param = strpbrk(param, " ");
3753 /*no channel list after the number of channels argument*/
3754 if (NULL == param) {
3755 hddLog(VOS_TRACE_LEVEL_ERROR,
3756 "%s, Invalid No of channel provided in the list",
3757 __func__);
3758 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303759 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303760 }
3761
3762 param++;
3763
3764 /*removing empty space*/
3765 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3766 param++;
3767
3768 if ('\0' == *param) {
3769 hddLog(VOS_TRACE_LEVEL_ERROR,
3770 "%s, No channel is provided in the list",
3771 __func__);
3772 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303773 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303774
3775 }
3776
3777 if (sscanf(param, "%d ", &tempInt) != 1) {
3778 hddLog(VOS_TRACE_LEVEL_ERROR,
3779 "%s: Cannot read channel number",
3780 __func__);
3781 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303782 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303783
3784 }
3785
3786 if (!IS_CHANNEL_VALID(tempInt)) {
3787 hddLog(VOS_TRACE_LEVEL_ERROR,
3788 "%s: Invalid channel number received",
3789 __func__);
3790 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303791 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303792
3793 }
3794
3795 hddLog(VOS_TRACE_LEVEL_INFO, "%s: channel[%d] = %d", __func__,
3796 j, tempInt);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303797
3798 parsed_channels[j] = tempInt;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303799 }
3800
3801 /*extra arguments check*/
3802 param = strchr(param, ' ');
3803 if (NULL != param) {
3804 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3805 param++;
3806
3807 if ('\0' != *param) {
3808 hddLog(VOS_TRACE_LEVEL_ERROR,
3809 "%s: Invalid argument received", __func__);
3810 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303811 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303812 }
3813 }
3814
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303815 /*
3816 * If command is received first time, cache the channels to
3817 * be disabled else compare the channels received in the
3818 * command with the cached channels, if channel list matches
3819 * return success otherewise return failure.
3820 */
3821 if (!is_command_repeated)
3822 for (j = 0; j < num_channels; j++)
3823 hdd_ctx->original_channels->
3824 channel_info[j].channel_num =
3825 parsed_channels[j];
3826 else {
3827 for (i = 0; i < num_channels; i++) {
3828 for (j = 0; j < num_channels; j++)
3829 if (hdd_ctx->original_channels->
3830 channel_info[i].channel_num ==
3831 parsed_channels[j])
3832 break;
3833 if (j == num_channels) {
3834 ret = -EINVAL;
3835 goto parse_failed;
3836 }
3837 }
3838 ret = 0;
3839 }
3840
3841mem_alloc_failed:
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303842 mutex_unlock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya1cf97dd2019-03-11 16:59:25 +05303843 /* Disable the channels received in command SET_DISABLE_CHANNEL_LIST*/
3844 if (!is_command_repeated) {
3845 wlan_hdd_disable_channels(hdd_ctx);
3846 hdd_check_and_disconnect_sta_on_invalid_channel(hdd_ctx);
3847 }
3848
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303849 EXIT();
3850
3851 return ret;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303852
3853parse_failed:
3854 mutex_unlock(&hdd_ctx->cache_channel_lock);
3855 if (!is_command_repeated)
3856 wlan_hdd_free_cache_channels(hdd_ctx);
3857 EXIT();
3858 return ret;
3859
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303860}
3861
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303862int hdd_get_disable_ch_list(hdd_context_t *hdd_ctx, tANI_U8 *buf,
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303863 uint32_t buf_len)
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303864{
3865 struct hdd_cache_channel_info *ch_list;
3866 unsigned char i, num_ch;
3867 int len = 0;
3868
3869 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303870 if (hdd_ctx->original_channels &&
3871 hdd_ctx->original_channels->num_channels &&
3872 hdd_ctx->original_channels->channel_info) {
3873 num_ch = hdd_ctx->original_channels->num_channels;
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303874
3875 len = scnprintf(buf, buf_len, "%s %hhu",
3876 "GET_DISABLE_CHANNEL_LIST", num_ch);
3877
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303878 ch_list = hdd_ctx->original_channels->channel_info;
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303879
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303880 for (i = 0; (i < num_ch) && (len < buf_len-1); i++) {
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303881 len += scnprintf(buf + len, buf_len - len,
3882 " %d", ch_list[i].channel_num);
3883 }
3884 }
3885 mutex_unlock(&hdd_ctx->cache_channel_lock);
3886
3887 return len;
3888}
3889
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003890static int hdd_driver_command(hdd_adapter_t *pAdapter,
3891 hdd_priv_data_t *ppriv_data)
Jeff Johnson295189b2012-06-20 16:38:30 -07003892{
Jeff Johnson295189b2012-06-20 16:38:30 -07003893 hdd_priv_data_t priv_data;
3894 tANI_U8 *command = NULL;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303895 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3896 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003897 int ret = 0;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303898 int status;
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05303899#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
3900 struct cfg80211_mgmt_tx_params params;
3901#endif
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303902
3903 ENTER();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003904 /*
3905 * Note that valid pointers are provided by caller
3906 */
Jeff Johnson295189b2012-06-20 16:38:30 -07003907
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003908 /* copy to local struct to avoid numerous changes to legacy code */
3909 priv_data = *ppriv_data;
Jeff Johnson295189b2012-06-20 16:38:30 -07003910
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003911 if (priv_data.total_len <= 0 ||
3912 priv_data.total_len > WLAN_PRIV_DATA_MAX_LEN)
Sameer Thalappil8ef3a0e2013-04-05 14:36:04 -07003913 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003914 hddLog(VOS_TRACE_LEVEL_WARN,
3915 "%s:invalid priv_data.total_len(%d)!!!", __func__,
3916 priv_data.total_len);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003917 ret = -EINVAL;
3918 goto exit;
3919 }
Kaushik, Sushant96122442014-10-21 16:40:18 +05303920 status = wlan_hdd_validate_context(pHddCtx);
3921 if (0 != status)
3922 {
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303923 ret = -EINVAL;
3924 goto exit;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303925 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003926 /* Allocate +1 for '\0' */
3927 command = kmalloc(priv_data.total_len + 1, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07003928 if (!command)
3929 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003930 hddLog(VOS_TRACE_LEVEL_ERROR,
3931 "%s: failed to allocate memory", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003932 ret = -ENOMEM;
3933 goto exit;
3934 }
3935
3936 if (copy_from_user(command, priv_data.buf, priv_data.total_len))
3937 {
3938 ret = -EFAULT;
3939 goto exit;
3940 }
3941
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003942 /* Make sure the command is NUL-terminated */
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003943 command[priv_data.total_len] = '\0';
3944
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003945 /* at one time the following block of code was conditional. braces
3946 * have been retained to avoid re-indenting the legacy code
3947 */
Jeff Johnson295189b2012-06-20 16:38:30 -07003948 {
3949 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
3950
3951 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07003952 "%s: Received %s cmd from Wi-Fi GUI***", __func__, command);
Jeff Johnson295189b2012-06-20 16:38:30 -07003953
3954 if (strncmp(command, "P2P_DEV_ADDR", 12) == 0 )
3955 {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303956 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3957 TRACE_CODE_HDD_P2P_DEV_ADDR_IOCTL,
3958 pAdapter->sessionId, (unsigned)
3959 (*(pHddCtx->p2pDeviceAddress.bytes+2)<<24 |
3960 *(pHddCtx->p2pDeviceAddress.bytes+3)<<16 |
3961 *(pHddCtx->p2pDeviceAddress.bytes+4)<<8 |
3962 *(pHddCtx->p2pDeviceAddress.bytes+5))));
Jeff Johnson295189b2012-06-20 16:38:30 -07003963 if (copy_to_user(priv_data.buf, pHddCtx->p2pDeviceAddress.bytes,
3964 sizeof(tSirMacAddr)))
3965 {
3966 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08003967 "%s: failed to copy data to user buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003968 ret = -EFAULT;
3969 }
3970 }
Amar Singhal0974e402013-02-12 14:27:46 -08003971 else if(strncmp(command, "SETBAND", 7) == 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07003972 {
Amar Singhal0974e402013-02-12 14:27:46 -08003973 tANI_U8 *ptr = command ;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003974
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303975 ret = hdd_drv_cmd_validate(command, 7);
3976 if (ret)
3977 goto exit;
3978
Jeff Johnson295189b2012-06-20 16:38:30 -07003979 /* Change band request received */
Srinivas Girigowdade697412013-02-14 16:31:48 -08003980
3981 /* First 8 bytes will have "SETBAND " and
Jeff Johnson295189b2012-06-20 16:38:30 -07003982 * 9 byte will have band setting value */
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07003983 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Amar Singhal0974e402013-02-12 14:27:46 -08003984 "%s: SetBandCommand Info comm %s UL %d, TL %d", __func__, command, priv_data.used_len, priv_data.total_len);
Anand N Sunkad27354cf2015-07-13 14:39:11 +05303985 if(VOS_FTM_MODE != hdd_get_conparam())
3986 {
3987 /* Change band request received */
3988 ret = hdd_setBand_helper(pAdapter->dev, ptr);
3989 if(ret < 0)
3990 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3991 "%s: failed to set band ret=%d", __func__, ret);
3992 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08003993 }
Kiet Lamf040f472013-11-20 21:15:23 +05303994 else if(strncmp(command, "SETWMMPS", 8) == 0)
3995 {
3996 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303997
3998 ret = hdd_drv_cmd_validate(command, 8);
3999 if (ret)
4000 goto exit;
4001
Kiet Lamf040f472013-11-20 21:15:23 +05304002 ret = hdd_wmmps_helper(pAdapter, ptr);
4003 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05304004
4005 else if(strncmp(command, "TDLSSCAN", 8) == 0)
4006 {
4007 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304008
4009 ret = hdd_drv_cmd_validate(command, 8);
4010 if (ret)
4011 goto exit;
4012
Agarwal Ashishef54a182014-12-16 15:07:31 +05304013 ret = hdd_set_tdls_scan_type(pAdapter, ptr);
4014 }
4015
Jeff Johnson32d95a32012-09-10 13:15:23 -07004016 else if ( strncasecmp(command, "COUNTRY", 7) == 0 )
4017 {
4018 char *country_code;
4019
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304020 ret = hdd_drv_cmd_validate(command, 7);
4021 if (ret)
4022 goto exit;
4023
Jeff Johnson32d95a32012-09-10 13:15:23 -07004024 country_code = command + 8;
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07004025
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004026 INIT_COMPLETION(pAdapter->change_country_code);
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07004027 hdd_checkandupdate_dfssetting(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07004028#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +05304029 hdd_checkandupdate_phymode(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07004030#endif
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004031 ret = (int)sme_ChangeCountryCode(pHddCtx->hHal,
4032 (void *)(tSmeChangeCountryCallback)
4033 wlan_hdd_change_country_code_callback,
Abhishek Singha306a442013-11-07 18:39:01 +05304034 country_code, pAdapter, pHddCtx->pvosContext, eSIR_TRUE, eSIR_TRUE);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004035 if (eHAL_STATUS_SUCCESS == ret)
4036 {
4037 ret = wait_for_completion_interruptible_timeout(
4038 &pAdapter->change_country_code,
4039 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
4040 if (0 >= ret)
4041 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004042 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: SME while setting country code timed out %d",
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304043 __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004044 }
4045 }
4046 else
Jeff Johnson32d95a32012-09-10 13:15:23 -07004047 {
4048 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004049 "%s: SME Change Country code fail ret=%d", __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004050 ret = -EINVAL;
Jeff Johnson32d95a32012-09-10 13:15:23 -07004051 }
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004052
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004053 }
4054 /*
4055 command should be a string having format
4056 SET_SAP_CHANNEL_LIST <num of channels> <the channels seperated by spaces>
4057 */
Amar Singhal0974e402013-02-12 14:27:46 -08004058 else if(strncmp(command, "SET_SAP_CHANNEL_LIST", 20) == 0)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004059 {
Amar Singhal0974e402013-02-12 14:27:46 -08004060 tANI_U8 *ptr = command;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004061
4062 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004063 " Received Command to Set Preferred Channels for SAP in %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004064
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -08004065 ret = sapSetPreferredChannel(ptr);
Jeff Johnson32d95a32012-09-10 13:15:23 -07004066 }
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +05304067
4068 else if (strncmp(command, "VOWIFIMODE", 10) == 0)
4069 {
4070 tANI_U8 *ptr;
4071
4072 ret = hdd_drv_cmd_validate(command, 10);
4073 if (ret)
4074 goto exit;
4075
4076 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4077 "Received Command for VOWIFI mode in %s", __func__);
4078
4079 ptr = (tANI_U8*)command + 11;
4080 hdd_set_vowifi_mode(pHddCtx, *ptr - '0');
4081 }
4082
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004083 else if(strncmp(command, "SETSUSPENDMODE", 14) == 0)
4084 {
4085 int suspend = 0;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304086 tANI_U8 *ptr;
4087
4088 ret = hdd_drv_cmd_validate(command, 14);
4089 if (ret)
4090 goto exit;
4091
4092 ptr = (tANI_U8*)command + 15;
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004093
4094 suspend = *ptr - '0';
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304095 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4096 TRACE_CODE_HDD_SETSUSPENDMODE_IOCTL,
4097 pAdapter->sessionId, suspend));
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004098 hdd_set_wlan_suspend_mode(suspend);
4099 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004100#ifdef WLAN_FEATURE_NEIGHBOR_ROAMING
4101 else if (strncmp(command, "SETROAMTRIGGER", 14) == 0)
4102 {
4103 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004104 tANI_S8 rssi = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004105 tANI_U8 lookUpThreshold = CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_DEFAULT;
4106 eHalStatus status = eHAL_STATUS_SUCCESS;
4107
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304108 ret = hdd_drv_cmd_validate(command, 14);
4109 if (ret)
4110 goto exit;
4111
Srinivas Girigowdade697412013-02-14 16:31:48 -08004112 /* Move pointer to ahead of SETROAMTRIGGER<delimiter> */
4113 value = value + 15;
4114
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004115 /* Convert the value from ascii to integer */
4116 ret = kstrtos8(value, 10, &rssi);
4117 if (ret < 0)
4118 {
4119 /* If the input value is greater than max value of datatype, then also
4120 kstrtou8 fails */
4121 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4122 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdafa7157d2013-10-31 10:14:22 -07004123 __func__,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004124 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
4125 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
4126 ret = -EINVAL;
4127 goto exit;
4128 }
4129
Srinivas Girigowdade697412013-02-14 16:31:48 -08004130 lookUpThreshold = abs(rssi);
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004131
Srinivas Girigowdade697412013-02-14 16:31:48 -08004132 if ((lookUpThreshold < CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN) ||
4133 (lookUpThreshold > CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX))
4134 {
4135 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4136 "Neighbor lookup threshold value %d is out of range"
4137 " (Min: %d Max: %d)", lookUpThreshold,
4138 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
4139 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
4140 ret = -EINVAL;
4141 goto exit;
4142 }
4143
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304144 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4145 TRACE_CODE_HDD_SETROAMTRIGGER_IOCTL,
4146 pAdapter->sessionId, lookUpThreshold));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004147 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4148 "%s: Received Command to Set Roam trigger"
4149 " (Neighbor lookup threshold) = %d", __func__, lookUpThreshold);
4150
4151 pHddCtx->cfg_ini->nNeighborLookupRssiThreshold = lookUpThreshold;
4152 status = sme_setNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold);
4153 if (eHAL_STATUS_SUCCESS != status)
4154 {
4155 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4156 "%s: Failed to set roam trigger, try again", __func__);
4157 ret = -EPERM;
4158 goto exit;
4159 }
4160
4161 /* Set Reassoc threshold to (lookup rssi threshold + 5 dBm) */
mukul sharmad6e1fdd2014-06-23 19:19:09 +05304162 pHddCtx->cfg_ini->nNeighborReassocRssiThreshold = lookUpThreshold + 5;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004163 sme_setNeighborReassocRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold + 5);
4164 }
4165 else if (strncmp(command, "GETROAMTRIGGER", 14) == 0)
4166 {
4167 tANI_U8 lookUpThreshold = sme_getNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal));
4168 int rssi = (-1) * lookUpThreshold;
4169 char extra[32];
4170 tANI_U8 len = 0;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304171 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4172 TRACE_CODE_HDD_GETROAMTRIGGER_IOCTL,
4173 pAdapter->sessionId, lookUpThreshold));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004174 len = scnprintf(extra, sizeof(extra), "%s %d", command, rssi);
Srinivas Girigowda91719232015-07-13 15:10:10 +05304175 len = VOS_MIN(priv_data.total_len, len + 1);
4176 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004177 {
4178 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4179 "%s: failed to copy data to user buffer", __func__);
4180 ret = -EFAULT;
4181 goto exit;
4182 }
4183 }
4184 else if (strncmp(command, "SETROAMSCANPERIOD", 17) == 0)
4185 {
4186 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004187 tANI_U8 roamScanPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004188 tANI_U16 neighborEmptyScanRefreshPeriod = CFG_EMPTY_SCAN_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004189
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304190 ret = hdd_drv_cmd_validate(command, 17);
4191 if (ret)
4192 goto exit;
4193
Srinivas Girigowdade697412013-02-14 16:31:48 -08004194 /* input refresh period is in terms of seconds */
4195 /* Move pointer to ahead of SETROAMSCANPERIOD<delimiter> */
4196 value = value + 18;
4197 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004198 ret = kstrtou8(value, 10, &roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004199 if (ret < 0)
4200 {
4201 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004202 kstrtou8 fails */
Srinivas Girigowdade697412013-02-14 16:31:48 -08004203 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004204 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdade697412013-02-14 16:31:48 -08004205 __func__,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07004206 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
4207 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004208 ret = -EINVAL;
4209 goto exit;
4210 }
4211
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004212 if ((roamScanPeriod < (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000)) ||
4213 (roamScanPeriod > (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000)))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004214 {
4215 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004216 "Roam scan period value %d is out of range"
4217 " (Min: %d Max: %d)", roamScanPeriod,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07004218 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
4219 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004220 ret = -EINVAL;
4221 goto exit;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304222 }
4223 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4224 TRACE_CODE_HDD_SETROAMSCANPERIOD_IOCTL,
4225 pAdapter->sessionId, roamScanPeriod));
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004226 neighborEmptyScanRefreshPeriod = roamScanPeriod * 1000;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004227
4228 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4229 "%s: Received Command to Set roam scan period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004230 " (Empty Scan refresh period) = %d", __func__, roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004231
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004232 pHddCtx->cfg_ini->nEmptyScanRefreshPeriod = neighborEmptyScanRefreshPeriod;
4233 sme_UpdateEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborEmptyScanRefreshPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004234 }
4235 else if (strncmp(command, "GETROAMSCANPERIOD", 17) == 0)
4236 {
4237 tANI_U16 nEmptyScanRefreshPeriod = sme_getEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
4238 char extra[32];
4239 tANI_U8 len = 0;
4240
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304241 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4242 TRACE_CODE_HDD_GETROAMSCANPERIOD_IOCTL,
4243 pAdapter->sessionId, nEmptyScanRefreshPeriod));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004244 len = scnprintf(extra, sizeof(extra), "%s %d",
4245 "GETROAMSCANPERIOD", (nEmptyScanRefreshPeriod/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004246 /* Returned value is in units of seconds */
Ratnam Rachuria72ba112015-07-17 13:27:03 +05304247 len = VOS_MIN(priv_data.total_len, len + 1);
4248 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004249 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4250 "%s: failed to copy data to user buffer", __func__);
4251 ret = -EFAULT;
4252 goto exit;
4253 }
4254 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004255 else if (strncmp(command, "SETROAMSCANREFRESHPERIOD", 24) == 0)
4256 {
4257 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004258 tANI_U8 roamScanRefreshPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004259 tANI_U16 neighborScanRefreshPeriod = CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004260
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304261 ret = hdd_drv_cmd_validate(command, 24);
4262 if (ret)
4263 goto exit;
4264
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004265 /* input refresh period is in terms of seconds */
4266 /* Move pointer to ahead of SETROAMSCANREFRESHPERIOD<delimiter> */
4267 value = value + 25;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004268
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004269 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004270 ret = kstrtou8(value, 10, &roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004271 if (ret < 0)
4272 {
4273 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004274 kstrtou8 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004275 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004276 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004277 __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004278 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
4279 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
4280 ret = -EINVAL;
4281 goto exit;
4282 }
4283
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004284 if ((roamScanRefreshPeriod < (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000)) ||
4285 (roamScanRefreshPeriod > (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000)))
4286 {
4287 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4288 "Neighbor scan results refresh period value %d is out of range"
4289 " (Min: %d Max: %d)", roamScanRefreshPeriod,
4290 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
4291 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
4292 ret = -EINVAL;
4293 goto exit;
4294 }
4295 neighborScanRefreshPeriod = roamScanRefreshPeriod * 1000;
4296
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004297 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4298 "%s: Received Command to Set roam scan refresh period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004299 " (Scan refresh period) = %d", __func__, roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004300
4301 pHddCtx->cfg_ini->nNeighborResultsRefreshPeriod = neighborScanRefreshPeriod;
4302 sme_setNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborScanRefreshPeriod);
4303 }
4304 else if (strncmp(command, "GETROAMSCANREFRESHPERIOD", 24) == 0)
4305 {
4306 tANI_U16 value = sme_getNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
4307 char extra[32];
4308 tANI_U8 len = 0;
4309
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004310 len = scnprintf(extra, sizeof(extra), "%s %d",
4311 "GETROAMSCANREFRESHPERIOD", (value/1000));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004312 /* Returned value is in units of seconds */
Ratnam Rachuri2c9d6702015-07-17 13:25:16 +05304313 len = VOS_MIN(priv_data.total_len, len + 1);
4314 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004315 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4316 "%s: failed to copy data to user buffer", __func__);
4317 ret = -EFAULT;
4318 goto exit;
4319 }
4320 }
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004321#ifdef FEATURE_WLAN_LFR
4322 /* SETROAMMODE */
4323 else if (strncmp(command, "SETROAMMODE", SIZE_OF_SETROAMMODE) == 0)
4324 {
4325 tANI_U8 *value = command;
4326 tANI_BOOLEAN roamMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
4327
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05304328 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
4329 hddLog(LOGE,
4330 FL("Roaming is always disabled in STA + MON concurrency"));
4331 ret = -EINVAL;
4332 goto exit;
4333 }
4334
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304335 ret = hdd_drv_cmd_validate(command, SIZE_OF_SETROAMMODE);
4336 if (ret)
4337 goto exit;
4338
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004339 /* Move pointer to ahead of SETROAMMODE<delimiter> */
4340 value = value + SIZE_OF_SETROAMMODE + 1;
4341
4342 /* Convert the value from ascii to integer */
4343 ret = kstrtou8(value, SIZE_OF_SETROAMMODE, &roamMode);
4344 if (ret < 0)
4345 {
4346 /* If the input value is greater than max value of datatype, then also
4347 kstrtou8 fails */
4348 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4349 "%s: kstrtou8 failed range [%d - %d]", __func__,
4350 CFG_LFR_FEATURE_ENABLED_MIN,
4351 CFG_LFR_FEATURE_ENABLED_MAX);
4352 ret = -EINVAL;
4353 goto exit;
4354 }
4355 if ((roamMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
4356 (roamMode > CFG_LFR_FEATURE_ENABLED_MAX))
4357 {
4358 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4359 "Roam Mode value %d is out of range"
4360 " (Min: %d Max: %d)", roamMode,
4361 CFG_LFR_FEATURE_ENABLED_MIN,
4362 CFG_LFR_FEATURE_ENABLED_MAX);
4363 ret = -EINVAL;
4364 goto exit;
4365 }
4366
4367 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4368 "%s: Received Command to Set Roam Mode = %d", __func__, roamMode);
4369 /*
4370 * Note that
4371 * SETROAMMODE 0 is to enable LFR while
4372 * SETROAMMODE 1 is to disable LFR, but
4373 * NotifyIsFastRoamIniFeatureEnabled 0/1 is to enable/disable.
4374 * So, we have to invert the value to call sme_UpdateIsFastRoamIniFeatureEnabled.
4375 */
4376 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
4377 roamMode = CFG_LFR_FEATURE_ENABLED_MAX; /* Roam enable */
4378 else
4379 roamMode = CFG_LFR_FEATURE_ENABLED_MIN; /* Roam disable */
4380
4381 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = roamMode;
4382 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), roamMode);
4383 }
4384 /* GETROAMMODE */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304385 else if (strncmp(command, "GETROAMMODE", SIZE_OF_GETROAMMODE) == 0)
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004386 {
4387 tANI_BOOLEAN roamMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4388 char extra[32];
4389 tANI_U8 len = 0;
4390
4391 /*
4392 * roamMode value shall be inverted because the sementics is different.
4393 */
4394 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
4395 roamMode = CFG_LFR_FEATURE_ENABLED_MAX;
4396 else
4397 roamMode = CFG_LFR_FEATURE_ENABLED_MIN;
4398
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004399 len = scnprintf(extra, sizeof(extra), "%s %d", command, roamMode);
Ratnam Rachuri28693eb2015-07-17 13:23:42 +05304400 len = VOS_MIN(priv_data.total_len, len + 1);
4401 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4403 "%s: failed to copy data to user buffer", __func__);
4404 ret = -EFAULT;
4405 goto exit;
4406 }
4407 }
4408#endif
Srinivas Girigowdade697412013-02-14 16:31:48 -08004409#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004410#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004411 else if (strncmp(command, "SETROAMDELTA", 12) == 0)
4412 {
4413 tANI_U8 *value = command;
4414 tANI_U8 roamRssiDiff = CFG_ROAM_RSSI_DIFF_DEFAULT;
4415
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304416 ret = hdd_drv_cmd_validate(command, 12);
4417 if (ret)
4418 goto exit;
4419
Srinivas Girigowdade697412013-02-14 16:31:48 -08004420 /* Move pointer to ahead of SETROAMDELTA<delimiter> */
4421 value = value + 13;
4422 /* Convert the value from ascii to integer */
4423 ret = kstrtou8(value, 10, &roamRssiDiff);
4424 if (ret < 0)
4425 {
4426 /* If the input value is greater than max value of datatype, then also
4427 kstrtou8 fails */
4428 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4429 "%s: kstrtou8 failed range [%d - %d]", __func__,
4430 CFG_ROAM_RSSI_DIFF_MIN,
4431 CFG_ROAM_RSSI_DIFF_MAX);
4432 ret = -EINVAL;
4433 goto exit;
4434 }
4435
4436 if ((roamRssiDiff < CFG_ROAM_RSSI_DIFF_MIN) ||
4437 (roamRssiDiff > CFG_ROAM_RSSI_DIFF_MAX))
4438 {
4439 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4440 "Roam rssi diff value %d is out of range"
4441 " (Min: %d Max: %d)", roamRssiDiff,
4442 CFG_ROAM_RSSI_DIFF_MIN,
4443 CFG_ROAM_RSSI_DIFF_MAX);
4444 ret = -EINVAL;
4445 goto exit;
4446 }
4447
4448 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4449 "%s: Received Command to Set roam rssi diff = %d", __func__, roamRssiDiff);
4450
4451 pHddCtx->cfg_ini->RoamRssiDiff = roamRssiDiff;
4452 sme_UpdateRoamRssiDiff((tHalHandle)(pHddCtx->hHal), roamRssiDiff);
4453 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304454 else if (strncmp(command, "GETROAMDELTA", 12) == 0)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004455 {
4456 tANI_U8 roamRssiDiff = sme_getRoamRssiDiff((tHalHandle)(pHddCtx->hHal));
4457 char extra[32];
4458 tANI_U8 len = 0;
4459
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304460 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4461 TRACE_CODE_HDD_GETROAMDELTA_IOCTL,
4462 pAdapter->sessionId, roamRssiDiff));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004463 len = scnprintf(extra, sizeof(extra), "%s %d",
4464 command, roamRssiDiff);
Ratnam Rachuri22a3b402015-07-17 13:21:49 +05304465 len = VOS_MIN(priv_data.total_len, len + 1);
4466 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004467 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4468 "%s: failed to copy data to user buffer", __func__);
4469 ret = -EFAULT;
4470 goto exit;
4471 }
4472 }
4473#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004474#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004475 else if (strncmp(command, "GETBAND", 7) == 0)
4476 {
4477 int band = -1;
4478 char extra[32];
4479 tANI_U8 len = 0;
4480 hdd_getBand_helper(pHddCtx, &band);
4481
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304482 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4483 TRACE_CODE_HDD_GETBAND_IOCTL,
4484 pAdapter->sessionId, band));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004485 len = scnprintf(extra, sizeof(extra), "%s %d", command, band);
Ratnam Rachuri52139592015-07-17 13:17:29 +05304486 len = VOS_MIN(priv_data.total_len, len + 1);
4487 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004488 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4489 "%s: failed to copy data to user buffer", __func__);
4490 ret = -EFAULT;
4491 goto exit;
4492 }
4493 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004494 else if (strncmp(command, "SETROAMSCANCHANNELS", 19) == 0)
4495 {
4496 tANI_U8 *value = command;
4497 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
4498 tANI_U8 numChannels = 0;
4499 eHalStatus status = eHAL_STATUS_SUCCESS;
4500
4501 status = hdd_parse_channellist(value, ChannelList, &numChannels);
4502 if (eHAL_STATUS_SUCCESS != status)
4503 {
4504 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4505 "%s: Failed to parse channel list information", __func__);
4506 ret = -EINVAL;
4507 goto exit;
4508 }
4509
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304510 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4511 TRACE_CODE_HDD_SETROAMSCANCHANNELS_IOCTL,
4512 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004513 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
4514 {
4515 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4516 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
4517 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
4518 ret = -EINVAL;
4519 goto exit;
4520 }
4521 status = sme_ChangeRoamScanChannelList((tHalHandle)(pHddCtx->hHal), ChannelList,
4522 numChannels);
4523 if (eHAL_STATUS_SUCCESS != status)
4524 {
4525 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4526 "%s: Failed to update channel list information", __func__);
4527 ret = -EINVAL;
4528 goto exit;
4529 }
4530 }
4531 else if (strncmp(command, "GETROAMSCANCHANNELS", 19) == 0)
4532 {
4533 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
4534 tANI_U8 numChannels = 0;
Jeff Johnson51b67782013-04-05 12:35:41 -07004535 tANI_U8 j = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004536 char extra[128] = {0};
Jeff Johnson51b67782013-04-05 12:35:41 -07004537 int len;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004538
4539 if (eHAL_STATUS_SUCCESS != sme_getRoamScanChannelList( (tHalHandle)(pHddCtx->hHal),
4540 ChannelList, &numChannels ))
4541 {
4542 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4543 "%s: failed to get roam scan channel list", __func__);
4544 ret = -EFAULT;
4545 goto exit;
4546 }
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304547 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4548 TRACE_CODE_HDD_GETROAMSCANCHANNELS_IOCTL,
4549 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004550 /* output channel list is of the format
4551 [Number of roam scan channels][Channel1][Channel2]... */
4552 /* copy the number of channels in the 0th index */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004553 len = scnprintf(extra, sizeof(extra), "%s %d", command, numChannels);
Sushant Kaushika08ca192015-09-16 15:52:04 +05304554 for (j = 0; (j < numChannels) && len <= sizeof(extra); j++)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004555 {
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004556 len += scnprintf(extra + len, sizeof(extra) - len, " %d",
4557 ChannelList[j]);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004558 }
4559
Sushant Kaushikc9b8be52015-07-15 16:41:27 +05304560 len = VOS_MIN(priv_data.total_len, len + 1);
4561 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004562 {
4563 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4564 "%s: failed to copy data to user buffer", __func__);
4565 ret = -EFAULT;
4566 goto exit;
4567 }
4568 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004569 else if (strncmp(command, "GETCCXMODE", 10) == 0)
4570 {
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004571 tANI_BOOLEAN eseMode = sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004572 char extra[32];
4573 tANI_U8 len = 0;
4574
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004575 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004576 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004577 if (eseMode &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004578 hdd_is_okc_mode_enabled(pHddCtx) &&
4579 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4580 {
4581 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004582 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004583 " hence this operation is not permitted!", __func__);
4584 ret = -EPERM;
4585 goto exit;
4586 }
4587
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004588 len = scnprintf(extra, sizeof(extra), "%s %d",
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004589 "GETCCXMODE", eseMode);
Sushant Kaushikf8abd352015-07-15 16:37:49 +05304590 len = VOS_MIN(priv_data.total_len, len + 1);
4591 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004592 {
4593 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4594 "%s: failed to copy data to user buffer", __func__);
4595 ret = -EFAULT;
4596 goto exit;
4597 }
4598 }
4599 else if (strncmp(command, "GETOKCMODE", 10) == 0)
4600 {
4601 tANI_BOOLEAN okcMode = hdd_is_okc_mode_enabled(pHddCtx);
4602 char extra[32];
4603 tANI_U8 len = 0;
4604
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004605 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004606 then this operation is not permitted (return FAILURE) */
4607 if (okcMode &&
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004608 sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004609 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4610 {
4611 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004612 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004613 " hence this operation is not permitted!", __func__);
4614 ret = -EPERM;
4615 goto exit;
4616 }
4617
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004618 len = scnprintf(extra, sizeof(extra), "%s %d",
4619 "GETOKCMODE", okcMode);
Sushant Kaushikbc2fb5c2015-07-15 16:43:16 +05304620 len = VOS_MIN(priv_data.total_len, len + 1);
4621 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004622 {
4623 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4624 "%s: failed to copy data to user buffer", __func__);
4625 ret = -EFAULT;
4626 goto exit;
4627 }
4628 }
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004629 else if (strncmp(command, "GETFASTROAM", 11) == 0)
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004630 {
4631 tANI_BOOLEAN lfrMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4632 char extra[32];
4633 tANI_U8 len = 0;
4634
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004635 len = scnprintf(extra, sizeof(extra), "%s %d",
4636 "GETFASTROAM", lfrMode);
Sushant Kaushik4da7ec92015-07-15 16:39:32 +05304637 len = VOS_MIN(priv_data.total_len, len + 1);
4638 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004639 {
4640 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4641 "%s: failed to copy data to user buffer", __func__);
4642 ret = -EFAULT;
4643 goto exit;
4644 }
4645 }
4646 else if (strncmp(command, "GETFASTTRANSITION", 17) == 0)
4647 {
4648 tANI_BOOLEAN ft = sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4649 char extra[32];
4650 tANI_U8 len = 0;
4651
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004652 len = scnprintf(extra, sizeof(extra), "%s %d",
4653 "GETFASTTRANSITION", ft);
Sushant Kaushik231a4452015-07-15 16:23:56 +05304654 len = VOS_MIN(priv_data.total_len, len + 1);
4655 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004656 {
4657 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4658 "%s: failed to copy data to user buffer", __func__);
4659 ret = -EFAULT;
4660 goto exit;
4661 }
4662 }
4663 else if (strncmp(command, "SETROAMSCANCHANNELMINTIME", 25) == 0)
4664 {
4665 tANI_U8 *value = command;
4666 tANI_U8 minTime = CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_DEFAULT;
4667
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304668 ret = hdd_drv_cmd_validate(command, 25);
4669 if (ret)
4670 goto exit;
4671
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004672 /* Move pointer to ahead of SETROAMSCANCHANNELMINTIME<delimiter> */
4673 value = value + 26;
4674 /* Convert the value from ascii to integer */
4675 ret = kstrtou8(value, 10, &minTime);
4676 if (ret < 0)
4677 {
4678 /* If the input value is greater than max value of datatype, then also
4679 kstrtou8 fails */
4680 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4681 "%s: kstrtou8 failed range [%d - %d]", __func__,
4682 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
4683 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
4684 ret = -EINVAL;
4685 goto exit;
4686 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004687 if ((minTime < CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN) ||
4688 (minTime > CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX))
4689 {
4690 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4691 "scan min channel time value %d is out of range"
4692 " (Min: %d Max: %d)", minTime,
4693 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
4694 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
4695 ret = -EINVAL;
4696 goto exit;
4697 }
4698
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304699 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4700 TRACE_CODE_HDD_SETROAMSCANCHANNELMINTIME_IOCTL,
4701 pAdapter->sessionId, minTime));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004702 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4703 "%s: Received Command to change channel min time = %d", __func__, minTime);
4704
4705 pHddCtx->cfg_ini->nNeighborScanMinChanTime = minTime;
4706 sme_setNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal), minTime);
4707 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004708 else if (strncmp(command, "SENDACTIONFRAME", 15) == 0)
4709 {
4710 tANI_U8 *value = command;
4711 tANI_U8 channel = 0;
4712 tANI_U8 dwellTime = 0;
4713 tANI_U8 bufLen = 0;
4714 tANI_U8 *buf = NULL;
4715 tSirMacAddr targetApBssid;
4716 eHalStatus status = eHAL_STATUS_SUCCESS;
4717 struct ieee80211_channel chan;
4718 tANI_U8 finalLen = 0;
4719 tANI_U8 *finalBuf = NULL;
4720 tANI_U8 temp = 0;
4721 u64 cookie;
4722 hdd_station_ctx_t *pHddStaCtx = NULL;
4723 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4724
4725 /* if not associated, no need to send action frame */
4726 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
4727 {
4728 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
4729 ret = -EINVAL;
4730 goto exit;
4731 }
4732
4733 status = hdd_parse_send_action_frame_data(value, targetApBssid, &channel,
4734 &dwellTime, &buf, &bufLen);
4735 if (eHAL_STATUS_SUCCESS != status)
4736 {
4737 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4738 "%s: Failed to parse send action frame data", __func__);
4739 ret = -EINVAL;
4740 goto exit;
4741 }
4742
4743 /* if the target bssid is different from currently associated AP,
4744 then no need to send action frame */
4745 if (VOS_TRUE != vos_mem_compare(targetApBssid,
4746 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
4747 {
4748 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:STA is not associated to this AP!",__func__);
4749 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004750 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004751 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004752 goto exit;
4753 }
4754
4755 /* if the channel number is different from operating channel then
4756 no need to send action frame */
4757 if (channel != pHddStaCtx->conn_info.operationChannel)
4758 {
4759 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4760 "%s: channel(%d) is different from operating channel(%d)",
4761 __func__, channel, pHddStaCtx->conn_info.operationChannel);
4762 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004763 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004764 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004765 goto exit;
4766 }
4767 chan.center_freq = sme_ChnToFreq(channel);
4768
4769 finalLen = bufLen + 24;
4770 finalBuf = vos_mem_malloc(finalLen);
4771 if (NULL == finalBuf)
4772 {
4773 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:memory allocation failed",__func__);
4774 ret = -ENOMEM;
Jeff Johnson11c33152013-04-16 17:52:40 -07004775 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004776 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004777 goto exit;
4778 }
4779 vos_mem_zero(finalBuf, finalLen);
4780
4781 /* Fill subtype */
4782 temp = SIR_MAC_MGMT_ACTION << 4;
4783 vos_mem_copy(finalBuf + 0, &temp, sizeof(temp));
4784
4785 /* Fill type */
4786 temp = SIR_MAC_MGMT_FRAME;
4787 vos_mem_copy(finalBuf + 2, &temp, sizeof(temp));
4788
4789 /* Fill destination address (bssid of the AP) */
4790 vos_mem_copy(finalBuf + 4, targetApBssid, sizeof(targetApBssid));
4791
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07004792 /* Fill source address (STA mac address) */
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004793 vos_mem_copy(finalBuf + 10, pAdapter->macAddressCurrent.bytes, sizeof(pAdapter->macAddressCurrent.bytes));
4794
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07004795 /* Fill BSSID (AP mac address) */
4796 vos_mem_copy(finalBuf + 16, targetApBssid, sizeof(targetApBssid));
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004797
4798 /* Fill received buffer from 24th address */
4799 vos_mem_copy(finalBuf + 24, buf, bufLen);
4800
Jeff Johnson11c33152013-04-16 17:52:40 -07004801 /* done with the parsed buffer */
4802 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004803 buf = NULL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004804
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05304805#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
4806 params.chan = &chan;
4807 params.offchan = 0;
4808 params.wait = dwellTime;
4809 params.buf = finalBuf;
4810 params.len = finalLen;
4811 params.no_cck = 1;
4812 params.dont_wait_for_ack = 1;
4813 ret = wlan_hdd_mgmt_tx(NULL, &pAdapter->wdev, &params, &cookie);
4814#else
DARAM SUDHA39eede62014-02-12 11:16:40 +05304815 wlan_hdd_mgmt_tx( NULL,
Yue Maf49ba872013-08-19 12:04:25 -07004816#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4817 &(pAdapter->wdev),
4818#else
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004819 pAdapter->dev,
Yue Maf49ba872013-08-19 12:04:25 -07004820#endif
4821 &chan, 0,
4822#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
4823 NL80211_CHAN_HT20, 1,
4824#endif
4825 dwellTime, finalBuf, finalLen, 1,
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004826 1, &cookie );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05304827#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)*/
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004828 vos_mem_free(finalBuf);
4829 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004830 else if (strncmp(command, "GETROAMSCANCHANNELMINTIME", 25) == 0)
4831 {
4832 tANI_U16 val = sme_getNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal));
4833 char extra[32];
4834 tANI_U8 len = 0;
4835
4836 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004837 len = scnprintf(extra, sizeof(extra), "%s %d",
4838 "GETROAMSCANCHANNELMINTIME", val);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304839 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4840 TRACE_CODE_HDD_GETROAMSCANCHANNELMINTIME_IOCTL,
4841 pAdapter->sessionId, val));
Sushant Kaushikbb8c52c2015-07-15 16:36:23 +05304842 len = VOS_MIN(priv_data.total_len, len + 1);
4843 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004844 {
4845 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4846 "%s: failed to copy data to user buffer", __func__);
4847 ret = -EFAULT;
4848 goto exit;
4849 }
4850 }
4851 else if (strncmp(command, "SETSCANCHANNELTIME", 18) == 0)
4852 {
4853 tANI_U8 *value = command;
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004854 tANI_U16 maxTime = CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004855
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304856 ret = hdd_drv_cmd_validate(command, 18);
4857 if (ret)
4858 goto exit;
4859
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004860 /* Move pointer to ahead of SETSCANCHANNELTIME<delimiter> */
4861 value = value + 19;
4862 /* Convert the value from ascii to integer */
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004863 ret = kstrtou16(value, 10, &maxTime);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004864 if (ret < 0)
4865 {
4866 /* If the input value is greater than max value of datatype, then also
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004867 kstrtou16 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004868 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004869 "%s: kstrtou16 failed range [%d - %d]", __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004870 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
4871 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
4872 ret = -EINVAL;
4873 goto exit;
4874 }
4875
4876 if ((maxTime < CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN) ||
4877 (maxTime > CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX))
4878 {
4879 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4880 "lfr mode value %d is out of range"
4881 " (Min: %d Max: %d)", maxTime,
4882 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
4883 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
4884 ret = -EINVAL;
4885 goto exit;
4886 }
4887
4888 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4889 "%s: Received Command to change channel max time = %d", __func__, maxTime);
4890
4891 pHddCtx->cfg_ini->nNeighborScanMaxChanTime = maxTime;
4892 sme_setNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal), maxTime);
4893 }
4894 else if (strncmp(command, "GETSCANCHANNELTIME", 18) == 0)
4895 {
4896 tANI_U16 val = sme_getNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal));
4897 char extra[32];
4898 tANI_U8 len = 0;
4899
4900 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004901 len = scnprintf(extra, sizeof(extra), "%s %d",
4902 "GETSCANCHANNELTIME", val);
Ratheesh S Pacbfa932015-07-16 15:27:18 +05304903 len = VOS_MIN(priv_data.total_len, len + 1);
4904 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004905 {
4906 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4907 "%s: failed to copy data to user buffer", __func__);
4908 ret = -EFAULT;
4909 goto exit;
4910 }
4911 }
4912 else if (strncmp(command, "SETSCANHOMETIME", 15) == 0)
4913 {
4914 tANI_U8 *value = command;
4915 tANI_U16 val = CFG_NEIGHBOR_SCAN_TIMER_PERIOD_DEFAULT;
4916
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304917 ret = hdd_drv_cmd_validate(command, 15);
4918 if (ret)
4919 goto exit;
4920
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004921 /* Move pointer to ahead of SETSCANHOMETIME<delimiter> */
4922 value = value + 16;
4923 /* Convert the value from ascii to integer */
4924 ret = kstrtou16(value, 10, &val);
4925 if (ret < 0)
4926 {
4927 /* If the input value is greater than max value of datatype, then also
4928 kstrtou16 fails */
4929 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4930 "%s: kstrtou16 failed range [%d - %d]", __func__,
4931 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
4932 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
4933 ret = -EINVAL;
4934 goto exit;
4935 }
4936
4937 if ((val < CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN) ||
4938 (val > CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX))
4939 {
4940 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4941 "scan home time value %d is out of range"
4942 " (Min: %d Max: %d)", val,
4943 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
4944 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
4945 ret = -EINVAL;
4946 goto exit;
4947 }
4948
4949 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4950 "%s: Received Command to change scan home time = %d", __func__, val);
4951
4952 pHddCtx->cfg_ini->nNeighborScanPeriod = val;
4953 sme_setNeighborScanPeriod((tHalHandle)(pHddCtx->hHal), val);
4954 }
4955 else if (strncmp(command, "GETSCANHOMETIME", 15) == 0)
4956 {
4957 tANI_U16 val = sme_getNeighborScanPeriod((tHalHandle)(pHddCtx->hHal));
4958 char extra[32];
4959 tANI_U8 len = 0;
4960
4961 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004962 len = scnprintf(extra, sizeof(extra), "%s %d",
4963 "GETSCANHOMETIME", val);
Ratheesh S P728d7c62015-07-16 15:38:58 +05304964 len = VOS_MIN(priv_data.total_len, len + 1);
4965 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004966 {
4967 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4968 "%s: failed to copy data to user buffer", __func__);
4969 ret = -EFAULT;
4970 goto exit;
4971 }
4972 }
4973 else if (strncmp(command, "SETROAMINTRABAND", 16) == 0)
4974 {
4975 tANI_U8 *value = command;
4976 tANI_U8 val = CFG_ROAM_INTRA_BAND_DEFAULT;
4977
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304978 ret = hdd_drv_cmd_validate(command, 16);
4979 if (ret)
4980 goto exit;
4981
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004982 /* Move pointer to ahead of SETROAMINTRABAND<delimiter> */
4983 value = value + 17;
4984 /* Convert the value from ascii to integer */
4985 ret = kstrtou8(value, 10, &val);
4986 if (ret < 0)
4987 {
4988 /* If the input value is greater than max value of datatype, then also
4989 kstrtou8 fails */
4990 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4991 "%s: kstrtou8 failed range [%d - %d]", __func__,
4992 CFG_ROAM_INTRA_BAND_MIN,
4993 CFG_ROAM_INTRA_BAND_MAX);
4994 ret = -EINVAL;
4995 goto exit;
4996 }
4997
4998 if ((val < CFG_ROAM_INTRA_BAND_MIN) ||
4999 (val > CFG_ROAM_INTRA_BAND_MAX))
5000 {
5001 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5002 "intra band mode value %d is out of range"
5003 " (Min: %d Max: %d)", val,
5004 CFG_ROAM_INTRA_BAND_MIN,
5005 CFG_ROAM_INTRA_BAND_MAX);
5006 ret = -EINVAL;
5007 goto exit;
5008 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005009 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5010 "%s: Received Command to change intra band = %d", __func__, val);
5011
5012 pHddCtx->cfg_ini->nRoamIntraBand = val;
5013 sme_setRoamIntraBand((tHalHandle)(pHddCtx->hHal), val);
5014 }
5015 else if (strncmp(command, "GETROAMINTRABAND", 16) == 0)
5016 {
5017 tANI_U16 val = sme_getRoamIntraBand((tHalHandle)(pHddCtx->hHal));
5018 char extra[32];
5019 tANI_U8 len = 0;
5020
5021 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005022 len = scnprintf(extra, sizeof(extra), "%s %d",
5023 "GETROAMINTRABAND", val);
Ratheesh S P2dd2a3e2015-07-16 15:34:23 +05305024 len = VOS_MIN(priv_data.total_len, len + 1);
5025 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005026 {
5027 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5028 "%s: failed to copy data to user buffer", __func__);
5029 ret = -EFAULT;
5030 goto exit;
5031 }
5032 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005033 else if (strncmp(command, "SETSCANNPROBES", 14) == 0)
5034 {
5035 tANI_U8 *value = command;
5036 tANI_U8 nProbes = CFG_ROAM_SCAN_N_PROBES_DEFAULT;
5037
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305038 ret = hdd_drv_cmd_validate(command, 14);
5039 if (ret)
5040 goto exit;
5041
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005042 /* Move pointer to ahead of SETSCANNPROBES<delimiter> */
5043 value = value + 15;
5044 /* Convert the value from ascii to integer */
5045 ret = kstrtou8(value, 10, &nProbes);
5046 if (ret < 0)
5047 {
5048 /* If the input value is greater than max value of datatype, then also
5049 kstrtou8 fails */
5050 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5051 "%s: kstrtou8 failed range [%d - %d]", __func__,
5052 CFG_ROAM_SCAN_N_PROBES_MIN,
5053 CFG_ROAM_SCAN_N_PROBES_MAX);
5054 ret = -EINVAL;
5055 goto exit;
5056 }
5057
5058 if ((nProbes < CFG_ROAM_SCAN_N_PROBES_MIN) ||
5059 (nProbes > CFG_ROAM_SCAN_N_PROBES_MAX))
5060 {
5061 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5062 "NProbes value %d is out of range"
5063 " (Min: %d Max: %d)", nProbes,
5064 CFG_ROAM_SCAN_N_PROBES_MIN,
5065 CFG_ROAM_SCAN_N_PROBES_MAX);
5066 ret = -EINVAL;
5067 goto exit;
5068 }
5069
5070 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5071 "%s: Received Command to Set nProbes = %d", __func__, nProbes);
5072
5073 pHddCtx->cfg_ini->nProbes = nProbes;
5074 sme_UpdateRoamScanNProbes((tHalHandle)(pHddCtx->hHal), nProbes);
5075 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305076 else if (strncmp(command, "GETSCANNPROBES", 14) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005077 {
5078 tANI_U8 val = sme_getRoamScanNProbes((tHalHandle)(pHddCtx->hHal));
5079 char extra[32];
5080 tANI_U8 len = 0;
5081
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005082 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri6da525d2015-08-07 13:55:54 +05305083 len = VOS_MIN(priv_data.total_len, len + 1);
5084 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005085 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5086 "%s: failed to copy data to user buffer", __func__);
5087 ret = -EFAULT;
5088 goto exit;
5089 }
5090 }
5091 else if (strncmp(command, "SETSCANHOMEAWAYTIME", 19) == 0)
5092 {
5093 tANI_U8 *value = command;
5094 tANI_U16 homeAwayTime = CFG_ROAM_SCAN_HOME_AWAY_TIME_DEFAULT;
5095
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305096 ret = hdd_drv_cmd_validate(command, 19);
5097 if (ret)
5098 goto exit;
5099
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005100 /* Move pointer to ahead of SETSCANHOMEAWAYTIME<delimiter> */
5101 /* input value is in units of msec */
5102 value = value + 20;
5103 /* Convert the value from ascii to integer */
5104 ret = kstrtou16(value, 10, &homeAwayTime);
5105 if (ret < 0)
5106 {
5107 /* If the input value is greater than max value of datatype, then also
5108 kstrtou8 fails */
5109 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5110 "%s: kstrtou8 failed range [%d - %d]", __func__,
5111 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
5112 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
5113 ret = -EINVAL;
5114 goto exit;
5115 }
5116
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005117 if ((homeAwayTime < CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN) ||
5118 (homeAwayTime > CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX))
5119 {
5120 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5121 "homeAwayTime value %d is out of range"
5122 " (Min: %d Max: %d)", homeAwayTime,
5123 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
5124 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
5125 ret = -EINVAL;
5126 goto exit;
5127 }
5128
5129 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5130 "%s: Received Command to Set scan away time = %d", __func__, homeAwayTime);
Srinivas Girigowda6cf0b822013-06-27 14:00:20 -07005131 if (pHddCtx->cfg_ini->nRoamScanHomeAwayTime != homeAwayTime)
5132 {
5133 pHddCtx->cfg_ini->nRoamScanHomeAwayTime = homeAwayTime;
5134 sme_UpdateRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal), homeAwayTime, eANI_BOOLEAN_TRUE);
5135 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005136 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305137 else if (strncmp(command, "GETSCANHOMEAWAYTIME", 19) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005138 {
5139 tANI_U16 val = sme_getRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal));
5140 char extra[32];
5141 tANI_U8 len = 0;
5142
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005143 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri51a5ad12015-08-07 14:06:37 +05305144 len = VOS_MIN(priv_data.total_len, len + 1);
5145 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005146 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5147 "%s: failed to copy data to user buffer", __func__);
5148 ret = -EFAULT;
5149 goto exit;
5150 }
5151 }
5152 else if (strncmp(command, "REASSOC", 7) == 0)
5153 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305154 ret = hdd_drv_cmd_validate(command, 7);
5155 if (ret)
5156 goto exit;
5157
5158 ret = hdd_parse_reassoc(pAdapter, command, priv_data.total_len);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05305159 if (!ret)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005160 goto exit;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005161 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005162 else if (strncmp(command, "SETWESMODE", 10) == 0)
5163 {
5164 tANI_U8 *value = command;
5165 tANI_BOOLEAN wesMode = CFG_ENABLE_WES_MODE_NAME_DEFAULT;
5166
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305167 ret = hdd_drv_cmd_validate(command, 10);
5168 if (ret)
5169 goto exit;
5170
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005171 /* Move pointer to ahead of SETWESMODE<delimiter> */
5172 value = value + 11;
5173 /* Convert the value from ascii to integer */
5174 ret = kstrtou8(value, 10, &wesMode);
5175 if (ret < 0)
5176 {
5177 /* If the input value is greater than max value of datatype, then also
5178 kstrtou8 fails */
5179 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5180 "%s: kstrtou8 failed range [%d - %d]", __func__,
5181 CFG_ENABLE_WES_MODE_NAME_MIN,
5182 CFG_ENABLE_WES_MODE_NAME_MAX);
5183 ret = -EINVAL;
5184 goto exit;
5185 }
5186
5187 if ((wesMode < CFG_ENABLE_WES_MODE_NAME_MIN) ||
5188 (wesMode > CFG_ENABLE_WES_MODE_NAME_MAX))
5189 {
5190 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5191 "WES Mode value %d is out of range"
5192 " (Min: %d Max: %d)", wesMode,
5193 CFG_ENABLE_WES_MODE_NAME_MIN,
5194 CFG_ENABLE_WES_MODE_NAME_MAX);
5195 ret = -EINVAL;
5196 goto exit;
5197 }
5198 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5199 "%s: Received Command to Set WES Mode rssi diff = %d", __func__, wesMode);
5200
5201 pHddCtx->cfg_ini->isWESModeEnabled = wesMode;
5202 sme_UpdateWESMode((tHalHandle)(pHddCtx->hHal), wesMode);
5203 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305204 else if (strncmp(command, "GETWESMODE", 10) == 0)
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005205 {
5206 tANI_BOOLEAN wesMode = sme_GetWESMode((tHalHandle)(pHddCtx->hHal));
5207 char extra[32];
5208 tANI_U8 len = 0;
5209
Arif Hussain826d9412013-11-12 16:44:54 -08005210 len = scnprintf(extra, sizeof(extra), "%s %d", command, wesMode);
Ratnam Rachuri8fe90c62015-08-07 14:03:26 +05305211 len = VOS_MIN(priv_data.total_len, len + 1);
5212 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005213 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5214 "%s: failed to copy data to user buffer", __func__);
5215 ret = -EFAULT;
5216 goto exit;
5217 }
5218 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005219#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE || FEATURE_WLAN_LFR */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005220#ifdef FEATURE_WLAN_LFR
5221 else if (strncmp(command, "SETFASTROAM", 11) == 0)
5222 {
5223 tANI_U8 *value = command;
5224 tANI_U8 lfrMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
5225
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05305226 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
5227 hddLog(LOGE,
5228 FL("Roaming is always disabled in STA + MON concurrency"));
5229 ret = -EINVAL;
5230 goto exit;
5231 }
5232
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305233 ret = hdd_drv_cmd_validate(command, 11);
5234 if (ret)
5235 goto exit;
5236
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005237 /* Move pointer to ahead of SETFASTROAM<delimiter> */
5238 value = value + 12;
5239 /* Convert the value from ascii to integer */
5240 ret = kstrtou8(value, 10, &lfrMode);
5241 if (ret < 0)
5242 {
5243 /* If the input value is greater than max value of datatype, then also
5244 kstrtou8 fails */
5245 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5246 "%s: kstrtou8 failed range [%d - %d]", __func__,
5247 CFG_LFR_FEATURE_ENABLED_MIN,
5248 CFG_LFR_FEATURE_ENABLED_MAX);
5249 ret = -EINVAL;
5250 goto exit;
5251 }
5252
5253 if ((lfrMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
5254 (lfrMode > CFG_LFR_FEATURE_ENABLED_MAX))
5255 {
5256 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5257 "lfr mode value %d is out of range"
5258 " (Min: %d Max: %d)", lfrMode,
5259 CFG_LFR_FEATURE_ENABLED_MIN,
5260 CFG_LFR_FEATURE_ENABLED_MAX);
5261 ret = -EINVAL;
5262 goto exit;
5263 }
5264
5265 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5266 "%s: Received Command to change lfr mode = %d", __func__, lfrMode);
5267
5268 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = lfrMode;
5269 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), lfrMode);
5270 }
5271#endif
5272#ifdef WLAN_FEATURE_VOWIFI_11R
5273 else if (strncmp(command, "SETFASTTRANSITION", 17) == 0)
5274 {
5275 tANI_U8 *value = command;
5276 tANI_U8 ft = CFG_FAST_TRANSITION_ENABLED_NAME_DEFAULT;
5277
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305278 ret = hdd_drv_cmd_validate(command, 17);
5279 if (ret)
5280 goto exit;
5281
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005282 /* Move pointer to ahead of SETFASTROAM<delimiter> */
5283 value = value + 18;
5284 /* Convert the value from ascii to integer */
5285 ret = kstrtou8(value, 10, &ft);
5286 if (ret < 0)
5287 {
5288 /* If the input value is greater than max value of datatype, then also
5289 kstrtou8 fails */
5290 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5291 "%s: kstrtou8 failed range [%d - %d]", __func__,
5292 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
5293 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
5294 ret = -EINVAL;
5295 goto exit;
5296 }
5297
5298 if ((ft < CFG_FAST_TRANSITION_ENABLED_NAME_MIN) ||
5299 (ft > CFG_FAST_TRANSITION_ENABLED_NAME_MAX))
5300 {
5301 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5302 "ft mode value %d is out of range"
5303 " (Min: %d Max: %d)", ft,
5304 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
5305 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
5306 ret = -EINVAL;
5307 goto exit;
5308 }
5309
5310 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5311 "%s: Received Command to change ft mode = %d", __func__, ft);
5312
5313 pHddCtx->cfg_ini->isFastTransitionEnabled = ft;
5314 sme_UpdateFastTransitionEnabled((tHalHandle)(pHddCtx->hHal), ft);
5315 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305316 else if (strncmp(command, "SETDFSSCANMODE", 14) == 0)
5317 {
5318 tANI_U8 *value = command;
5319 tANI_U8 dfsScanMode = DFS_CHNL_SCAN_ENABLED_NORMAL;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305320
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305321 ret = hdd_drv_cmd_validate(command, 14);
5322 if (ret)
5323 goto exit;
5324
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305325 /* Move pointer to ahead of SETDFSSCANMODE<delimiter> */
5326 value = value + 15;
5327 /* Convert the value from ascii to integer */
5328 ret = kstrtou8(value, 10, &dfsScanMode);
5329 if (ret < 0)
5330 {
5331 /* If the input value is greater than max value of
5332 datatype, then also kstrtou8 fails
5333 */
5334 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5335 "%s: kstrtou8 failed range [%d - %d]", __func__,
5336 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
5337 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
5338 ret = -EINVAL;
5339 goto exit;
5340 }
5341
5342 if ((dfsScanMode < CFG_ENABLE_DFS_CHNL_SCAN_MIN) ||
5343 (dfsScanMode > CFG_ENABLE_DFS_CHNL_SCAN_MAX))
5344 {
5345 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5346 "dfsScanMode value %d is out of range"
5347 " (Min: %d Max: %d)", dfsScanMode,
5348 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
5349 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
5350 ret = -EINVAL;
5351 goto exit;
5352 }
5353 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5354 "%s: Received Command to Set DFS Scan Mode = %d",
5355 __func__, dfsScanMode);
5356
5357 ret = wlan_hdd_handle_dfs_chan_scan(pHddCtx, dfsScanMode);
5358 }
5359 else if (strncmp(command, "GETDFSSCANMODE", 14) == 0)
5360 {
5361 tANI_U8 dfsScanMode = sme_GetDFSScanMode(pHddCtx->hHal);
5362 char extra[32];
5363 tANI_U8 len = 0;
5364
5365 len = scnprintf(extra, sizeof(extra), "%s %d", command, dfsScanMode);
Ratheesh S P767224e2015-07-16 15:35:51 +05305366 len = VOS_MIN(priv_data.total_len, len + 1);
5367 if (copy_to_user(priv_data.buf, &extra, len))
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305368 {
5369 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5370 "%s: failed to copy data to user buffer", __func__);
5371 ret = -EFAULT;
5372 goto exit;
5373 }
5374 }
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305375 else if (strncmp(command, "FASTREASSOC", 11) == 0)
5376 {
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05305377 ret = wlan_hdd_handle_fastreassoc(pAdapter, command);
5378 if (!ret)
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305379 goto exit;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305380 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005381#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005382#ifdef FEATURE_WLAN_ESE
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005383 else if (strncmp(command, "SETCCXMODE", 10) == 0)
5384 {
5385 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005386 tANI_U8 eseMode = CFG_ESE_FEATURE_ENABLED_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005387
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305388 ret = hdd_drv_cmd_validate(command, 10);
5389 if (ret)
5390 goto exit;
5391
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005392 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005393 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005394 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005395 hdd_is_okc_mode_enabled(pHddCtx) &&
5396 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
5397 {
5398 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005399 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005400 " hence this operation is not permitted!", __func__);
5401 ret = -EPERM;
5402 goto exit;
5403 }
5404
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005405 /* Move pointer to ahead of SETCCXMODE<delimiter> */
5406 value = value + 11;
5407 /* Convert the value from ascii to integer */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005408 ret = kstrtou8(value, 10, &eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005409 if (ret < 0)
5410 {
5411 /* If the input value is greater than max value of datatype, then also
5412 kstrtou8 fails */
5413 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5414 "%s: kstrtou8 failed range [%d - %d]", __func__,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005415 CFG_ESE_FEATURE_ENABLED_MIN,
5416 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005417 ret = -EINVAL;
5418 goto exit;
5419 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005420 if ((eseMode < CFG_ESE_FEATURE_ENABLED_MIN) ||
5421 (eseMode > CFG_ESE_FEATURE_ENABLED_MAX))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005422 {
5423 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005424 "Ese mode value %d is out of range"
5425 " (Min: %d Max: %d)", eseMode,
5426 CFG_ESE_FEATURE_ENABLED_MIN,
5427 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005428 ret = -EINVAL;
5429 goto exit;
5430 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005431 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005432 "%s: Received Command to change ese mode = %d", __func__, eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005433
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005434 pHddCtx->cfg_ini->isEseIniFeatureEnabled = eseMode;
5435 sme_UpdateIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal), eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005436 }
5437#endif
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005438 else if (strncmp(command, "SETROAMSCANCONTROL", 18) == 0)
5439 {
5440 tANI_U8 *value = command;
5441 tANI_BOOLEAN roamScanControl = 0;
5442
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305443 ret = hdd_drv_cmd_validate(command, 18);
5444 if (ret)
5445 goto exit;
5446
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005447 /* Move pointer to ahead of SETROAMSCANCONTROL<delimiter> */
5448 value = value + 19;
5449 /* Convert the value from ascii to integer */
5450 ret = kstrtou8(value, 10, &roamScanControl);
5451 if (ret < 0)
5452 {
5453 /* If the input value is greater than max value of datatype, then also
5454 kstrtou8 fails */
5455 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5456 "%s: kstrtou8 failed ", __func__);
5457 ret = -EINVAL;
5458 goto exit;
5459 }
5460
5461 if (0 != roamScanControl)
5462 {
5463 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5464 "roam scan control invalid value = %d",
5465 roamScanControl);
5466 ret = -EINVAL;
5467 goto exit;
5468 }
5469 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5470 "%s: Received Command to Set roam scan control = %d", __func__, roamScanControl);
5471
5472 sme_SetRoamScanControl((tHalHandle)(pHddCtx->hHal), roamScanControl);
5473 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005474#ifdef FEATURE_WLAN_OKC
5475 else if (strncmp(command, "SETOKCMODE", 10) == 0)
5476 {
5477 tANI_U8 *value = command;
5478 tANI_U8 okcMode = CFG_OKC_FEATURE_ENABLED_DEFAULT;
5479
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305480 ret = hdd_drv_cmd_validate(command, 10);
5481 if (ret)
5482 goto exit;
5483
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005484 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005485 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005486 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005487 hdd_is_okc_mode_enabled(pHddCtx) &&
5488 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
5489 {
5490 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005491 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005492 " hence this operation is not permitted!", __func__);
5493 ret = -EPERM;
5494 goto exit;
5495 }
5496
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005497 /* Move pointer to ahead of SETOKCMODE<delimiter> */
5498 value = value + 11;
5499 /* Convert the value from ascii to integer */
5500 ret = kstrtou8(value, 10, &okcMode);
5501 if (ret < 0)
5502 {
5503 /* If the input value is greater than max value of datatype, then also
5504 kstrtou8 fails */
5505 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5506 "%s: kstrtou8 failed range [%d - %d]", __func__,
5507 CFG_OKC_FEATURE_ENABLED_MIN,
5508 CFG_OKC_FEATURE_ENABLED_MAX);
5509 ret = -EINVAL;
5510 goto exit;
5511 }
5512
5513 if ((okcMode < CFG_OKC_FEATURE_ENABLED_MIN) ||
5514 (okcMode > CFG_OKC_FEATURE_ENABLED_MAX))
5515 {
5516 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5517 "Okc mode value %d is out of range"
5518 " (Min: %d Max: %d)", okcMode,
5519 CFG_OKC_FEATURE_ENABLED_MIN,
5520 CFG_OKC_FEATURE_ENABLED_MAX);
5521 ret = -EINVAL;
5522 goto exit;
5523 }
5524
5525 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5526 "%s: Received Command to change okc mode = %d", __func__, okcMode);
5527
5528 pHddCtx->cfg_ini->isOkcIniFeatureEnabled = okcMode;
5529 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005530#endif /* FEATURE_WLAN_OKC */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305531 else if (strncmp(command, "GETROAMSCANCONTROL", 18) == 0)
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005532 {
5533 tANI_BOOLEAN roamScanControl = sme_GetRoamScanControl((tHalHandle)(pHddCtx->hHal));
5534 char extra[32];
5535 tANI_U8 len = 0;
5536
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005537 len = scnprintf(extra, sizeof(extra), "%s %d",
5538 command, roamScanControl);
Ratnam Rachuri083ada82015-08-07 14:01:05 +05305539 len = VOS_MIN(priv_data.total_len, len + 1);
5540 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005541 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5542 "%s: failed to copy data to user buffer", __func__);
5543 ret = -EFAULT;
5544 goto exit;
5545 }
5546 }
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05305547#ifdef WLAN_FEATURE_PACKET_FILTERING
5548 else if (strncmp(command, "ENABLE_PKTFILTER_IPV6", 21) == 0)
5549 {
5550 tANI_U8 filterType = 0;
5551 tANI_U8 *value = command;
5552
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305553 ret = hdd_drv_cmd_validate(command, 21);
5554 if (ret)
5555 goto exit;
5556
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05305557 /* Move pointer to ahead of ENABLE_PKTFILTER_IPV6<delimiter> */
5558 value = value + 22;
5559
5560 /* Convert the value from ascii to integer */
5561 ret = kstrtou8(value, 10, &filterType);
5562 if (ret < 0)
5563 {
5564 /* If the input value is greater than max value of datatype,
5565 * then also kstrtou8 fails
5566 */
5567 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5568 "%s: kstrtou8 failed range ", __func__);
5569 ret = -EINVAL;
5570 goto exit;
5571 }
5572
5573 if (filterType != 0 && filterType != 1)
5574 {
5575 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5576 "%s: Accepted Values are 0 and 1 ", __func__);
5577 ret = -EINVAL;
5578 goto exit;
5579 }
5580 wlan_hdd_setIPv6Filter(WLAN_HDD_GET_CTX(pAdapter), filterType,
5581 pAdapter->sessionId);
5582 }
5583#endif
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305584 else if (strncmp(command, "BTCOEXMODE", 10) == 0 )
5585 {
Kiet Lamad161252014-07-22 11:23:32 -07005586 char *dhcpPhase;
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05305587 int ret;
5588
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305589 ret = hdd_drv_cmd_validate(command, 10);
5590 if (ret)
5591 goto exit;
5592
Kiet Lamad161252014-07-22 11:23:32 -07005593 dhcpPhase = command + 11;
5594 if ('1' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305595 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05305596 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07005597 FL("send DHCP START indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05305598
5599 pHddCtx->btCoexModeSet = TRUE;
Kiet Lamad161252014-07-22 11:23:32 -07005600
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05305601 ret = wlan_hdd_scan_abort(pAdapter);
5602 if (ret < 0)
5603 {
5604 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5605 FL("failed to abort existing scan %d"), ret);
5606 }
5607
Kiet Lamad161252014-07-22 11:23:32 -07005608 sme_DHCPStartInd(pHddCtx->hHal, pAdapter->device_mode,
5609 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305610 }
Kiet Lamad161252014-07-22 11:23:32 -07005611 else if ('2' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305612 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05305613 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07005614 FL("send DHCP STOP indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05305615
5616 pHddCtx->btCoexModeSet = FALSE;
Kiet Lamad161252014-07-22 11:23:32 -07005617
5618 sme_DHCPStopInd(pHddCtx->hHal, pAdapter->device_mode,
5619 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305620 }
5621 }
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005622 else if (strncmp(command, "SCAN-ACTIVE", 11) == 0)
5623 {
Abhishek Singh58749d62016-02-03 15:27:20 +05305624 hddLog(LOG1,
5625 FL("making default scan to ACTIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05305626 pHddCtx->scan_info.scan_mode = eSIR_ACTIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005627 }
5628 else if (strncmp(command, "SCAN-PASSIVE", 12) == 0)
5629 {
Abhishek Singh58749d62016-02-03 15:27:20 +05305630 hddLog(LOG1,
5631 FL("making default scan to PASSIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05305632 pHddCtx->scan_info.scan_mode = eSIR_PASSIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005633 }
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305634 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
5635 {
5636 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5637 char extra[32];
5638 tANI_U8 len = 0;
5639
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05305640 memset(extra, 0, sizeof(extra));
5641 ret = hdd_get_dwell_time(pCfg, command, extra, sizeof(extra), &len);
Ratnam Rachuri12d5d462015-08-07 14:10:23 +05305642 len = VOS_MIN(priv_data.total_len, len + 1);
5643 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305644 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5645 "%s: failed to copy data to user buffer", __func__);
5646 ret = -EFAULT;
5647 goto exit;
5648 }
5649 ret = len;
5650 }
5651 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
5652 {
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05305653 ret = hdd_set_dwell_time(pAdapter, command);
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305654 }
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05305655 else if (strncmp(command, "BTCGETDWELLTIME", 15) == 0)
5656 {
5657 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5658 char extra[32];
5659 tANI_U8 len = 0;
5660
5661 if (hdd_drv_cmd_validate(command, 15)) {
5662 hddLog(LOGE, FL("Invalid driver command"));
5663 return -EINVAL;
5664 }
5665
5666 memset(extra, 0, sizeof(extra));
5667 ret = hdd_btc_get_dwell_time(pCfg, command, extra,
5668 sizeof(extra), &len);
5669 len = VOS_MIN(priv_data.total_len, len + 1);
5670 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
5671 hddLog(LOGE, FL("Failed to copy data to user buffer"));
5672 ret = -EFAULT;
5673 goto exit;
5674 }
5675 ret = len;
5676 }
5677 else if (strncmp(command, "BTCSETDWELLTIME", 15) == 0)
5678 {
5679 if (hdd_drv_cmd_validate(command, 15)) {
5680 hddLog(LOGE, FL("Invalid driver command"));
5681 return -EINVAL;
5682 }
5683 ret = hdd_btc_set_dwell_time(pAdapter, command);
5684 }
5685#ifdef WLAN_AP_STA_CONCURRENCY
5686 else if (strncmp(command, "CONCGETDWELLTIME", 16) == 0)
5687 {
5688 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5689 char extra[32];
5690 tANI_U8 len = 0;
5691
5692 if (hdd_drv_cmd_validate(command, 16)) {
5693 hddLog(LOGE, FL("Invalid driver command"));
5694 return -EINVAL;
5695 }
5696
5697 memset(extra, 0, sizeof(extra));
5698 ret = hdd_conc_get_dwell_time(pCfg, command, extra,
5699 sizeof(extra), &len);
5700 len = VOS_MIN(priv_data.total_len, len + 1);
5701 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
5702 hddLog(LOGE, FL("Failed to copy data to user buffer"));
5703 ret = -EFAULT;
5704 goto exit;
5705 }
5706 ret = len;
5707 }
5708 else if (strncmp(command, "CONCSETDWELLTIME", 16) == 0)
5709 {
5710 if (hdd_drv_cmd_validate(command, 16)) {
5711 hddLog(LOGE, FL("Invalid driver command"));
5712 return -EINVAL;
5713 }
5714 ret = hdd_conc_set_dwell_time(pAdapter, command);
5715 }
5716#endif
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005717 else if ( strncasecmp(command, "MIRACAST", 8) == 0 )
5718 {
5719 tANI_U8 filterType = 0;
5720 tANI_U8 *value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305721
5722 ret = hdd_drv_cmd_validate(command, 8);
5723 if (ret)
5724 goto exit;
5725
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005726 value = command + 9;
5727
5728 /* Convert the value from ascii to integer */
5729 ret = kstrtou8(value, 10, &filterType);
5730 if (ret < 0)
5731 {
5732 /* If the input value is greater than max value of datatype,
5733 * then also kstrtou8 fails
5734 */
5735 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5736 "%s: kstrtou8 failed range ", __func__);
5737 ret = -EINVAL;
5738 goto exit;
5739 }
5740 if ((filterType < WLAN_HDD_DRIVER_MIRACAST_CFG_MIN_VAL ) ||
5741 (filterType > WLAN_HDD_DRIVER_MIRACAST_CFG_MAX_VAL))
5742 {
5743 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5744 "%s: Accepted Values are 0 to 2. 0-Disabled, 1-Source,"
5745 " 2-Sink ", __func__);
5746 ret = -EINVAL;
5747 goto exit;
5748 }
5749 //Filtertype value should be either 0-Disabled, 1-Source, 2-sink
5750 pHddCtx->drvr_miracast = filterType;
Kaushik, Sushant96122442014-10-21 16:40:18 +05305751 pScanInfo = &pHddCtx->scan_info;
5752 if (filterType && pScanInfo != NULL &&
5753 pHddCtx->scan_info.mScanPending)
5754 {
5755 /*Miracast Session started. Abort Scan */
5756 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5757 "%s, Aborting Scan For Miracast",__func__);
5758 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
5759 eCSR_SCAN_ABORT_DEFAULT);
5760 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005761 hdd_tx_rx_pkt_cnt_stat_timer_handler(pHddCtx);
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05305762 sme_SetMiracastMode(pHddCtx->hHal, pHddCtx->drvr_miracast);
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005763 }
Leo Chang614d2072013-08-22 14:59:44 -07005764 else if (strncmp(command, "SETMCRATE", 9) == 0)
5765 {
Leo Chang614d2072013-08-22 14:59:44 -07005766 tANI_U8 *value = command;
5767 int targetRate;
Leo Chang1f98cbd2013-10-17 15:03:52 -07005768 tSirRateUpdateInd *rateUpdate;
5769 eHalStatus status;
Leo Chang614d2072013-08-22 14:59:44 -07005770
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305771 ret = hdd_drv_cmd_validate(command, 9);
5772 if (ret)
5773 goto exit;
5774
Leo Chang614d2072013-08-22 14:59:44 -07005775 /* Only valid for SAP mode */
5776 if (WLAN_HDD_SOFTAP != pAdapter->device_mode)
5777 {
5778 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5779 "%s: SAP mode is not running", __func__);
5780 ret = -EFAULT;
5781 goto exit;
5782 }
5783
5784 /* Move pointer to ahead of SETMCRATE<delimiter> */
5785 /* input value is in units of hundred kbps */
5786 value = value + 10;
5787 /* Convert the value from ascii to integer, decimal base */
5788 ret = kstrtouint(value, 10, &targetRate);
5789
Leo Chang1f98cbd2013-10-17 15:03:52 -07005790 rateUpdate = (tSirRateUpdateInd *)vos_mem_malloc(sizeof(tSirRateUpdateInd));
5791 if (NULL == rateUpdate)
Leo Chang614d2072013-08-22 14:59:44 -07005792 {
Leo Chang1f98cbd2013-10-17 15:03:52 -07005793 hddLog(VOS_TRACE_LEVEL_ERROR,
5794 "%s: SETMCRATE indication alloc fail", __func__);
5795 ret = -EFAULT;
5796 goto exit;
5797 }
5798 vos_mem_zero(rateUpdate, sizeof(tSirRateUpdateInd ));
5799
5800 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5801 "MC Target rate %d", targetRate);
5802 /* Ignore unicast */
5803 rateUpdate->ucastDataRate = -1;
5804 rateUpdate->mcastDataRate24GHz = targetRate;
5805 rateUpdate->mcastDataRate5GHz = targetRate;
5806 rateUpdate->mcastDataRate24GHzTxFlag = 0;
5807 rateUpdate->mcastDataRate5GHzTxFlag = 0;
5808 status = sme_SendRateUpdateInd(pHddCtx->hHal, rateUpdate);
5809 if (eHAL_STATUS_SUCCESS != status)
5810 {
5811 hddLog(VOS_TRACE_LEVEL_ERROR,
5812 "%s: SET_MC_RATE failed", __func__);
5813 vos_mem_free(rateUpdate);
5814 ret = -EFAULT;
5815 goto exit;
Leo Chang614d2072013-08-22 14:59:44 -07005816 }
5817 }
jge35567202017-06-21 16:39:38 +08005818 else if (strncmp(command, "MAXTXPOWER", 10) == 0)
5819 {
5820 int status;
5821 int txPower;
5822 eHalStatus smeStatus;
5823 tANI_U8 *value = command;
5824 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
5825 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
5826
5827 status = hdd_parse_setmaxtxpower_command(value, &txPower);
5828 if (status)
5829 {
5830 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5831 "Invalid MAXTXPOWER command ");
5832 ret = -EINVAL;
5833 goto exit;
5834 }
5835
5836 hddLog(VOS_TRACE_LEVEL_INFO, "max tx power %d selfMac: "
5837 MAC_ADDRESS_STR " bssId: " MAC_ADDRESS_STR " ",
5838 txPower, MAC_ADDR_ARRAY(selfMac),
5839 MAC_ADDR_ARRAY(bssid));
5840 smeStatus = sme_SetMaxTxPower((tHalHandle)(pHddCtx->hHal),
5841 bssid, selfMac, txPower) ;
5842 if( smeStatus != eHAL_STATUS_SUCCESS )
5843 {
5844 hddLog(VOS_TRACE_LEVEL_ERROR, "%s:Set max tx power failed",
5845 __func__);
5846 ret = -EINVAL;
5847 goto exit;
5848 }
5849
5850 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Set max tx power success",
5851 __func__);
5852 }
Rajeev79dbe4c2013-10-05 11:03:42 +05305853#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev Kumar8b373292014-01-08 20:36:55 -08005854 else if (strncmp(command, "WLS_BATCHING", 12) == 0)
Rajeev79dbe4c2013-10-05 11:03:42 +05305855 {
Rajeev Kumar8b373292014-01-08 20:36:55 -08005856 ret = hdd_handle_batch_scan_ioctl(pAdapter, &priv_data, command);
Rajeev79dbe4c2013-10-05 11:03:42 +05305857 }
5858#endif
Abhishek Singh00b71972016-01-07 10:51:04 +05305859#ifdef WLAN_FEATURE_RMC
5860 else if ((strncasecmp(command, "SETIBSSBEACONOUIDATA", 20) == 0) &&
5861 (WLAN_HDD_IBSS == pAdapter->device_mode))
5862 {
5863 int i = 0;
5864 tANI_U8 *ibss_ie;
5865 tANI_U32 command_len;
5866 tANI_U8 *value = command;
5867 tHalHandle hHal = pHddCtx->hHal;
5868 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
5869 tANI_U32 ibss_ie_length;
5870 tANI_U32 len, present;
5871 tANI_U8 *addIE;
5872 tANI_U8 *addIEData;
5873
5874 hddLog(LOG1,
5875 FL(" received command %s"),((char *) value));
5876 /* validate argument of command */
5877 if (strlen(value) <= 21)
5878 {
5879 hddLog(LOGE,
5880 FL("No arguements in command length %zu"), strlen(value));
5881 ret = -EFAULT;
5882 goto exit;
5883 }
5884
5885 /* moving to arguments of commands */
5886 value = value + 21;
5887 command_len = strlen(value);
5888
5889 /* oui_data can't be less than 3 bytes */
5890 if (command_len <= (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH))
5891 {
5892 hddLog(LOGE,
5893 FL("Invalid SETIBSSBEACONOUIDATA command length %d"),
5894 command_len);
5895 ret = -EFAULT;
5896 goto exit;
5897 }
5898 ibss_ie = vos_mem_malloc(command_len);
5899 if (!ibss_ie) {
5900 hddLog(LOGE,
5901 FL("Could not allocate memory for command length %d"),
5902 command_len);
5903 ret = -ENOMEM;
5904 goto exit;
5905 }
5906 vos_mem_zero(ibss_ie, command_len);
5907
5908 ibss_ie_length = hdd_parse_set_ibss_oui_data_command(value, ibss_ie,
5909 command_len);
5910 if (ibss_ie_length < (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH)) {
5911 hddLog(LOGE, FL("Could not parse command %s return length %d"),
5912 value, ibss_ie_length);
5913 ret = -EFAULT;
5914 vos_mem_free(ibss_ie);
5915 goto exit;
5916 }
5917
5918 hddLog(LOG1, FL("ibss_ie length %d ibss_ie:"), ibss_ie_length);
5919 while (i < ibss_ie_length)
5920 hddLog(LOG1, FL("0x%x"), ibss_ie[i++]);
5921
5922 /* Populate Vendor IE in Beacon */
5923 if ((ccmCfgGetInt(hHal,
5924 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
5925 &present)) != eHAL_STATUS_SUCCESS)
5926 {
5927 hddLog(LOGE,
5928 FL("unable to ftch WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
5929 ret = -EFAULT;
5930 vos_mem_free(ibss_ie);
5931 goto exit;
5932 }
5933
5934 addIE = vos_mem_malloc(WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
5935 if (!addIE) {
5936 hddLog(LOGE,
5937 FL("Could not allocate memory for command length %d"),
5938 command_len);
5939 vos_mem_free(ibss_ie);
5940 ret = -ENOMEM;
5941 goto exit;
5942 }
5943 vos_mem_zero(addIE, WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
5944
5945 if (present)
5946 {
5947 if ((wlan_cfgGetStrLen(pMac,
5948 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, &len)) != eSIR_SUCCESS)
5949 {
5950 hddLog(LOGE,
5951 FL("unable to fetch WNI_CFG_PROBE_RSP_BCN_ADDNIE_LEN"));
5952 ret = -EFAULT;
5953 vos_mem_free(ibss_ie);
5954 vos_mem_free(addIE);
5955 goto exit;
5956 }
5957
5958 if (len <= WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN && len &&
5959 ((len + ibss_ie_length) <=
5960 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN))
5961 {
5962 if ((ccmCfgGetStr(hHal,
5963 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, &len))
5964 != eHAL_STATUS_SUCCESS)
5965 {
5966 hddLog(LOGE,
5967 FL("unable to fetch WNI_PROBE_RSP_BCN_ADDNIE_DATA"));
5968 ret = -EFAULT;
5969 vos_mem_free(ibss_ie);
5970 vos_mem_free(addIE);
5971 goto exit;
5972 }
5973 else
5974 {
5975 /* Curruntly only WPA IE is added before Vendor IE
5976 * so we can blindly place the Vendor IE after WPA
5977 * IE. If no WPA IE found replace all with Vendor IE.
5978 */
5979 len = hdd_find_ibss_wpa_ie_pos(addIE, len);
5980 }
5981 }
5982 else
5983 {
5984 hddLog(LOGE,
5985 FL("IE len exceed limit len %d,ibss_ie_length %d "),
5986 len, ibss_ie_length);
5987 ret = -EFAULT;
5988 vos_mem_free(addIE);
5989 vos_mem_free(ibss_ie);
5990 goto exit;
5991 }
5992 }
5993 else {
5994 len = 0;
5995 }
5996
5997 vos_mem_copy (addIE + len , ibss_ie, ibss_ie_length);
5998 len += ibss_ie_length;
5999
6000 if (ccmCfgSetStr(hHal,
6001 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, len, NULL,
6002 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
6003 {
6004 hddLog(LOGE,
6005 FL("unable to set WNI_CFG_PRBE_RSP_BCN_ADDNIE_DATA"));
6006 ret = -EFAULT;
6007 vos_mem_free(ibss_ie);
6008 vos_mem_free(addIE);
6009 goto exit;
6010 }
6011 vos_mem_free(addIE);
6012 if (ccmCfgSetInt(hHal,
6013 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
6014 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
6015 {
6016 hddLog(LOGE,
6017 FL("unble to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
6018 ret = -EFAULT;
6019 vos_mem_free(ibss_ie);
6020 goto exit;
6021 }
6022
6023 /* Populate Vendor IE in probe resp */
6024 if ((ccmCfgGetInt(hHal,
6025 WNI_CFG_PROBE_RSP_ADDNIE_FLAG,
6026 &present)) != eHAL_STATUS_SUCCESS)
6027 {
6028 hddLog(LOGE,
6029 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
6030 ret = -EFAULT;
6031 vos_mem_free(ibss_ie);
6032 goto exit;
6033 }
6034
6035 addIEData = vos_mem_malloc(WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
6036 if (!addIEData) {
6037 hddLog(LOGE,
6038 FL("Could not allocate memory for command length %d"),
6039 command_len);
6040 vos_mem_free(ibss_ie);
6041 ret = -ENOMEM;
6042 goto exit;
6043 }
6044 vos_mem_zero(addIEData, WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
6045
6046 if (present) {
6047 if (eSIR_SUCCESS != wlan_cfgGetStrLen(pMac,
6048 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, &len)) {
6049 hddLog(LOGE,
6050 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6051 ret = -EFAULT;
6052 vos_mem_free(ibss_ie);
6053 vos_mem_free(addIEData);
6054 goto exit;
6055 }
6056 if (len < WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN && len &&
6057 (ibss_ie_length + len) <=
6058 WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN) {
6059
6060 if ((ccmCfgGetStr(hHal,
6061 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, addIEData, &len))
6062 != eHAL_STATUS_SUCCESS) {
6063 hddLog(LOGE,
6064 FL("unable fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6065 ret = -EFAULT;
6066 vos_mem_free(ibss_ie);
6067 vos_mem_free(addIEData);
6068 goto exit;
6069 }
6070 else {
6071 /* Curruntly only WPA IE is added before Vendor IE
6072 * so we can blindly place the Vendor IE after WPA
6073 * IE. If no WPA IE found replace all with Vendor IE.
6074 */
6075 len = hdd_find_ibss_wpa_ie_pos(addIEData, len);
6076 }
6077 }
6078 else
6079 {
6080 hddLog(LOGE,
6081 FL("IE len exceed limit len %d,ibss_ie_length %d "),
6082 len, ibss_ie_length);
6083 ret = -EFAULT;
6084 vos_mem_free(addIEData);
6085 vos_mem_free(ibss_ie);
6086 goto exit;
6087 }
6088 } /* probe rsp ADD IE present */
6089 else {
6090 /* probe rsp add IE is not present */
6091 len = 0;
6092 }
6093
6094 vos_mem_copy(addIEData +len , ibss_ie, ibss_ie_length);
6095 len += ibss_ie_length;
6096
6097 vos_mem_free(ibss_ie);
6098
6099 if (ccmCfgSetStr(hHal,
6100 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
6101 (tANI_U8*)(addIEData),
6102 len, NULL,
6103 eANI_BOOLEAN_FALSE)
6104 == eHAL_STATUS_FAILURE) {
6105 hddLog(LOGE,
6106 FL("unable to copy to WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6107 ret = -EFAULT;
6108 vos_mem_free(addIEData);
6109 goto exit;
6110 }
6111 vos_mem_free(addIEData);
6112 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6113 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
6114 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6115 {
6116 hddLog(LOGE,
6117 FL("unable to copy WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
6118 ret = -EFAULT;
6119 goto exit;
6120 }
6121 }
6122 else if (strncasecmp(command, "SETRMCENABLE", 12) == 0)
6123 {
6124 tANI_U8 *value = command;
6125 tANI_U8 ucRmcEnable = 0;
6126 int status;
6127
6128 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6129 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6130 {
6131 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6132 "Received SETRMCENABLE command in invalid mode %d "
6133 "SETRMCENABLE command is only allowed in IBSS or SOFTAP mode",
6134 pAdapter->device_mode);
6135 ret = -EINVAL;
6136 goto exit;
6137 }
6138
6139 status = hdd_parse_setrmcenable_command(value, &ucRmcEnable);
6140 if (status)
6141 {
6142 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6143 "Invalid SETRMCENABLE command ");
6144 ret = -EINVAL;
6145 goto exit;
6146 }
6147
6148 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6149 "%s: ucRmcEnable %d ", __func__, ucRmcEnable);
6150
6151 if (TRUE == ucRmcEnable)
6152 {
6153 status = sme_EnableRMC( (tHalHandle)(pHddCtx->hHal),
6154 pAdapter->sessionId );
6155 }
6156 else if(FALSE == ucRmcEnable)
6157 {
6158 status = sme_DisableRMC( (tHalHandle)(pHddCtx->hHal),
6159 pAdapter->sessionId );
6160 }
6161 else
6162 {
6163 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6164 "Invalid SETRMCENABLE command %d", ucRmcEnable);
6165 ret = -EINVAL;
6166 goto exit;
6167 }
6168
6169 if (VOS_STATUS_SUCCESS != status)
6170 {
6171 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6172 "%s: SETRMC %d failed status %d", __func__, ucRmcEnable,
6173 status);
6174 ret = -EINVAL;
6175 goto exit;
6176 }
6177 }
6178 else if (strncasecmp(command, "SETRMCACTIONPERIOD", 18) == 0)
6179 {
6180 tANI_U8 *value = command;
6181 tANI_U32 uActionPeriod = 0;
6182 int status;
6183
6184 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6185 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6186 {
6187 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6188 "Received SETRMC command in invalid mode %d "
6189 "SETRMC command is only allowed in IBSS or SOFTAP mode",
6190 pAdapter->device_mode);
6191 ret = -EINVAL;
6192 goto exit;
6193 }
6194
6195 status = hdd_parse_setrmcactionperiod_command(value, &uActionPeriod);
6196 if (status)
6197 {
6198 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6199 "Invalid SETRMCACTIONPERIOD command ");
6200 ret = -EINVAL;
6201 goto exit;
6202 }
6203
6204 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6205 "%s: uActionPeriod %d ", __func__, uActionPeriod);
6206
6207 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY,
6208 uActionPeriod, NULL, eANI_BOOLEAN_FALSE))
6209 {
6210 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6211 "%s: Could not set SETRMCACTIONPERIOD %d", __func__, uActionPeriod);
6212 ret = -EINVAL;
6213 goto exit;
6214 }
6215
6216 }
6217 else if (strncasecmp(command, "GETIBSSPEERINFOALL", 18) == 0)
6218 {
6219 /* Peer Info All Command */
6220 int status = eHAL_STATUS_SUCCESS;
6221 hdd_station_ctx_t *pHddStaCtx = NULL;
6222 char *extra = NULL;
6223 int idx = 0, length = 0;
6224 v_MACADDR_t *macAddr;
6225 v_U32_t txRateMbps = 0, numOfBytestoPrint = 0;
6226
6227 if (WLAN_HDD_IBSS == pAdapter->device_mode)
6228 {
6229 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6230 }
6231 else
6232 {
6233 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6234 "%s: pAdapter is not valid for this device mode",
6235 __func__);
6236 ret = -EINVAL;
6237 goto exit;
6238 }
6239
6240 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6241 "%s: Received GETIBSSPEERINFOALL Command", __func__);
6242
6243
6244 /* Handle the command */
6245 status = hdd_cfg80211_get_ibss_peer_info_all(pAdapter);
6246 if (VOS_STATUS_SUCCESS == status)
6247 {
6248 /* The variable extra needed to be allocated on the heap since
6249 * amount of memory required to copy the data for 32 devices
6250 * exceeds the size of 1024 bytes of default stack size. On
6251 * 64 bit devices, the default max stack size of 2048 bytes
6252 */
6253 extra = kmalloc(WLAN_MAX_BUF_SIZE, GFP_KERNEL);
6254
6255 if (NULL == extra)
6256 {
6257 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6258 "%s:kmalloc failed", __func__);
6259 ret = -EINVAL;
6260 goto exit;
6261 }
6262
6263 /* Copy number of stations */
6264 length = scnprintf( extra, WLAN_MAX_BUF_SIZE, "%d ",
6265 pHddStaCtx->ibss_peer_info.numIBSSPeers);
6266 numOfBytestoPrint = length;
6267 for (idx = 0; idx < pHddStaCtx->ibss_peer_info.numIBSSPeers; idx++)
6268 {
6269 macAddr =
6270 hdd_wlan_get_ibss_mac_addr_from_staid(pAdapter,
6271 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
6272 if (NULL != macAddr)
6273 {
6274 txRateMbps =
6275 ((pHddStaCtx->ibss_peer_info.ibssPeerList[idx].txRate)*500*1000)/1000000;
6276
6277 length += scnprintf( (extra + length), WLAN_MAX_BUF_SIZE - length,
6278 "%02x:%02x:%02x:%02x:%02x:%02x %d %d ",
6279 macAddr->bytes[0], macAddr->bytes[1], macAddr->bytes[2],
6280 macAddr->bytes[3], macAddr->bytes[4], macAddr->bytes[5],
6281 (int)txRateMbps,
6282 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[idx].rssi);
6283 }
6284 else
6285 {
6286 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6287 "%s: MAC ADDR is NULL for staIdx: %d", __func__,
6288 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
6289 }
6290
6291 /*
6292 * VOS_TRACE() macro has limitation of 512 bytes for the print
6293 * buffer. Hence printing the data in two chunks. The first chunk
6294 * will have the data for 16 devices and the second chunk will
6295 * have the rest.
6296 */
6297 if (idx < NUM_OF_STA_DATA_TO_PRINT)
6298 {
6299 numOfBytestoPrint = length;
6300 }
6301 }
6302
6303 /*
6304 * Copy the data back into buffer, if the data to copy is
6305 * morethan 512 bytes than we will split the data and do
6306 * it in two shots
6307 */
6308 if (copy_to_user(priv_data.buf, extra, numOfBytestoPrint))
6309 {
6310 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6311 "%s: Copy into user data buffer failed ", __func__);
6312 ret = -EFAULT;
6313 kfree(extra);
6314 goto exit;
6315 }
6316 priv_data.buf[numOfBytestoPrint] = '\0';
6317 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6318 "%s", priv_data.buf);
6319
6320 if (length > numOfBytestoPrint)
6321 {
6322 if (copy_to_user(priv_data.buf + numOfBytestoPrint,
6323 extra + numOfBytestoPrint,
6324 length - numOfBytestoPrint + 1))
6325 {
6326 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6327 "%s: Copy into user data buffer failed ", __func__);
6328 ret = -EFAULT;
6329 kfree(extra);
6330 goto exit;
6331 }
6332 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6333 "%s", &priv_data.buf[numOfBytestoPrint]);
6334 }
6335
6336 /* Free temporary buffer */
6337 kfree(extra);
6338 }
6339
6340 else
6341 {
6342 /* Command failed, log error */
6343 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6344 "%s: GETIBSSPEERINFOALL command failed with status code %d",
6345 __func__, status);
6346 ret = -EINVAL;
6347 goto exit;
6348 }
6349 ret = 0;
6350 }
6351 else if(strncasecmp(command, "GETIBSSPEERINFO", 15) == 0)
6352 {
6353 /* Peer Info <Peer Addr> command */
6354 tANI_U8 *value = command;
6355 VOS_STATUS status;
6356 hdd_station_ctx_t *pHddStaCtx = NULL;
6357 char extra[128] = { 0 };
6358 v_U32_t length = 0;
6359 v_U8_t staIdx = 0;
6360 v_U32_t txRateMbps = 0;
6361 v_MACADDR_t peerMacAddr;
6362
6363 if (WLAN_HDD_IBSS == pAdapter->device_mode)
6364 {
6365 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6366 }
6367 else
6368 {
6369 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6370 "%s: pAdapter is not valid for this device mode",
6371 __func__);
6372 ret = -EINVAL;
6373 goto exit;
6374 }
6375
6376 /* if there are no peers, no need to continue with the command */
6377 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6378 "%s: Received GETIBSSPEERINFO Command", __func__);
6379
6380 if (eConnectionState_IbssConnected != pHddStaCtx->conn_info.connState)
6381 {
6382 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6383 "%s:No IBSS Peers coalesced", __func__);
6384 ret = -EINVAL;
6385 goto exit;
6386 }
6387
6388 /* Parse the incoming command buffer */
6389 status = hdd_parse_get_ibss_peer_info(value, &peerMacAddr);
6390 if (VOS_STATUS_SUCCESS != status)
6391 {
6392 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6393 "%s: Invalid GETIBSSPEERINFO command", __func__);
6394 ret = -EINVAL;
6395 goto exit;
6396 }
6397
6398 /* Get station index for the peer mac address */
6399 hdd_Ibss_GetStaId(pHddStaCtx, &peerMacAddr, &staIdx);
6400
6401 if (staIdx > HDD_MAX_NUM_IBSS_STA)
6402 {
6403 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6404 "%s: Invalid StaIdx %d returned", __func__, staIdx);
6405 ret = -EINVAL;
6406 goto exit;
6407 }
6408
6409 /* Handle the command */
6410 status = hdd_cfg80211_get_ibss_peer_info(pAdapter, staIdx);
6411 if (VOS_STATUS_SUCCESS == status)
6412 {
6413 v_U32_t txRate = pHddStaCtx->ibss_peer_info.ibssPeerList[0].txRate;
6414 txRateMbps = (txRate * 500 * 1000)/1000000;
6415
6416 length = scnprintf( extra, sizeof(extra), "%d %d", (int)txRateMbps,
6417 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[0].rssi);
6418
6419 /* Copy the data back into buffer */
6420 if (copy_to_user(priv_data.buf, &extra, length+ 1))
6421 {
6422 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6423 "%s: copy data to user buffer failed GETIBSSPEERINFO command",
6424 __func__);
6425 ret = -EFAULT;
6426 goto exit;
6427 }
6428 }
6429 else
6430 {
6431 /* Command failed, log error */
6432 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6433 "%s: GETIBSSPEERINFO command failed with status code %d",
6434 __func__, status);
6435 ret = -EINVAL;
6436 goto exit;
6437 }
6438
6439 /* Success ! */
6440 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6441 "%s", priv_data.buf);
6442 ret = 0;
6443 }
6444 else if (strncasecmp(command, "SETRMCTXRATE", 12) == 0)
6445 {
6446 tANI_U8 *value = command;
6447 tANI_U32 uRate = 0;
6448 tTxrateinfoflags txFlags = 0;
6449 tSirRateUpdateInd *rateUpdateParams;
6450 int status;
6451
6452 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6453 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6454 {
6455 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6456 "Received SETRMCTXRATE command in invalid mode %d "
6457 "SETRMC command is only allowed in IBSS or SOFTAP mode",
6458 pAdapter->device_mode);
6459 ret = -EINVAL;
6460 goto exit;
6461 }
6462
6463 status = hdd_parse_setrmcrate_command(value, &uRate, &txFlags);
6464 if (status)
6465 {
6466 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6467 "Invalid SETRMCTXRATE command ");
6468 ret = -EINVAL;
6469 goto exit;
6470 }
6471
6472 rateUpdateParams = vos_mem_malloc(sizeof(tSirRateUpdateInd));
6473 if (NULL == rateUpdateParams)
6474 {
6475 ret = -EINVAL;
6476 goto exit;
6477 }
6478
6479 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6480 "%s: uRate %d ", __func__, uRate);
6481
6482 vos_mem_zero(rateUpdateParams, sizeof(tSirRateUpdateInd ));
6483
6484 /* -1 implies ignore this param */
6485 rateUpdateParams->ucastDataRate = -1;
6486
6487 /*
6488 * Fill the user specifieed RMC rate param
6489 * and the derived tx flags.
6490 */
6491 rateUpdateParams->rmcDataRate = uRate;
6492 rateUpdateParams->rmcDataRateTxFlag = txFlags;
6493
6494 status = sme_SendRateUpdateInd((tHalHandle)(pHddCtx->hHal), rateUpdateParams);
6495 }
6496 else if (strncasecmp(command, "SETIBSSTXFAILEVENT", 18) == 0 )
6497 {
6498 char *value;
6499 tANI_U8 tx_fail_count = 0;
6500 tANI_U16 pid = 0;
6501
6502 value = command;
6503
6504 ret = hdd_ParseIBSSTXFailEventParams(value, &tx_fail_count, &pid);
6505
6506 if (0 != ret)
6507 {
6508 hddLog(VOS_TRACE_LEVEL_INFO,
6509 "%s: Failed to parse SETIBSSTXFAILEVENT arguments",
6510 __func__);
6511 goto exit;
6512 }
6513
6514 hddLog(VOS_TRACE_LEVEL_INFO, "%s: tx_fail_cnt=%hhu, pid=%hu",
6515 __func__, tx_fail_count, pid);
6516
6517 if (0 == tx_fail_count)
6518 {
6519 // Disable TX Fail Indication
6520 if (eHAL_STATUS_SUCCESS ==
6521 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
6522 tx_fail_count,
6523 NULL))
6524 {
6525 cesium_pid = 0;
6526 }
6527 else
6528 {
6529 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6530 "%s: failed to disable TX Fail Event ", __func__);
6531 ret = -EINVAL;
6532 }
6533 }
6534 else
6535 {
6536 if (eHAL_STATUS_SUCCESS ==
6537 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
6538 tx_fail_count,
6539 (void*)hdd_tx_fail_ind_callback))
6540 {
6541 cesium_pid = pid;
6542 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6543 "%s: Registered Cesium pid %u", __func__,
6544 cesium_pid);
6545 }
6546 else
6547 {
6548 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6549 "%s: Failed to enable TX Fail Monitoring", __func__);
6550 ret = -EINVAL;
6551 }
6552 }
6553 }
6554
6555#endif /* WLAN_FEATURE_RMC */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006556#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006557 else if (strncmp(command, "SETCCXROAMSCANCHANNELS", 22) == 0)
6558 {
6559 tANI_U8 *value = command;
6560 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
6561 tANI_U8 numChannels = 0;
6562 eHalStatus status = eHAL_STATUS_SUCCESS;
6563
6564 status = hdd_parse_channellist(value, ChannelList, &numChannels);
6565 if (eHAL_STATUS_SUCCESS != status)
6566 {
6567 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6568 "%s: Failed to parse channel list information", __func__);
6569 ret = -EINVAL;
6570 goto exit;
6571 }
6572
6573 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
6574 {
6575 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6576 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
6577 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
6578 ret = -EINVAL;
6579 goto exit;
6580 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006581 status = sme_SetEseRoamScanChannelList((tHalHandle)(pHddCtx->hHal),
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006582 ChannelList,
6583 numChannels);
6584 if (eHAL_STATUS_SUCCESS != status)
6585 {
6586 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6587 "%s: Failed to update channel list information", __func__);
6588 ret = -EINVAL;
6589 goto exit;
6590 }
6591 }
6592 else if (strncmp(command, "GETTSMSTATS", 11) == 0)
6593 {
6594 tANI_U8 *value = command;
6595 char extra[128] = {0};
6596 int len = 0;
6597 tANI_U8 tid = 0;
6598 hdd_station_ctx_t *pHddStaCtx = NULL;
6599 tAniTrafStrmMetrics tsmMetrics;
6600 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6601
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306602 ret = hdd_drv_cmd_validate(command, 11);
6603 if (ret)
6604 goto exit;
6605
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006606 /* if not associated, return error */
6607 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6608 {
6609 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:Not associated!",__func__);
6610 ret = -EINVAL;
6611 goto exit;
6612 }
6613
6614 /* Move pointer to ahead of GETTSMSTATS<delimiter> */
6615 value = value + 12;
6616 /* Convert the value from ascii to integer */
6617 ret = kstrtou8(value, 10, &tid);
6618 if (ret < 0)
6619 {
6620 /* If the input value is greater than max value of datatype, then also
6621 kstrtou8 fails */
6622 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6623 "%s: kstrtou8 failed range [%d - %d]", __func__,
6624 TID_MIN_VALUE,
6625 TID_MAX_VALUE);
6626 ret = -EINVAL;
6627 goto exit;
6628 }
6629
6630 if ((tid < TID_MIN_VALUE) || (tid > TID_MAX_VALUE))
6631 {
6632 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6633 "tid value %d is out of range"
6634 " (Min: %d Max: %d)", tid,
6635 TID_MIN_VALUE,
6636 TID_MAX_VALUE);
6637 ret = -EINVAL;
6638 goto exit;
6639 }
6640
6641 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6642 "%s: Received Command to get tsm stats tid = %d", __func__, tid);
6643
6644 if (VOS_STATUS_SUCCESS != hdd_get_tsm_stats(pAdapter, tid, &tsmMetrics))
6645 {
6646 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6647 "%s: failed to get tsm stats", __func__);
6648 ret = -EFAULT;
6649 goto exit;
6650 }
6651
6652 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6653 "UplinkPktQueueDly(%d)\n"
6654 "UplinkPktQueueDlyHist[0](%d)\n"
6655 "UplinkPktQueueDlyHist[1](%d)\n"
6656 "UplinkPktQueueDlyHist[2](%d)\n"
6657 "UplinkPktQueueDlyHist[3](%d)\n"
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05306658 "UplinkPktTxDly(%u)\n"
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006659 "UplinkPktLoss(%d)\n"
6660 "UplinkPktCount(%d)\n"
6661 "RoamingCount(%d)\n"
6662 "RoamingDly(%d)", tsmMetrics.UplinkPktQueueDly,
6663 tsmMetrics.UplinkPktQueueDlyHist[0],
6664 tsmMetrics.UplinkPktQueueDlyHist[1],
6665 tsmMetrics.UplinkPktQueueDlyHist[2],
6666 tsmMetrics.UplinkPktQueueDlyHist[3],
6667 tsmMetrics.UplinkPktTxDly, tsmMetrics.UplinkPktLoss,
6668 tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount, tsmMetrics.RoamingDly);
6669
6670 /* Output TSM stats is of the format
6671 GETTSMSTATS [PktQueueDly] [PktQueueDlyHist[0]]:[PktQueueDlyHist[1]] ...[RoamingDly]
6672 eg., GETTSMSTATS 10 1:0:0:161 20 1 17 8 39800 */
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006673 len = scnprintf(extra, sizeof(extra), "%s %d %d:%d:%d:%d %u %d %d %d %d", command,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006674 tsmMetrics.UplinkPktQueueDly, tsmMetrics.UplinkPktQueueDlyHist[0],
6675 tsmMetrics.UplinkPktQueueDlyHist[1], tsmMetrics.UplinkPktQueueDlyHist[2],
6676 tsmMetrics.UplinkPktQueueDlyHist[3], tsmMetrics.UplinkPktTxDly,
6677 tsmMetrics.UplinkPktLoss, tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount,
6678 tsmMetrics.RoamingDly);
6679
Ratnam Rachurid53009c2015-08-07 13:59:00 +05306680 len = VOS_MIN(priv_data.total_len, len + 1);
6681 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006682 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6683 "%s: failed to copy data to user buffer", __func__);
6684 ret = -EFAULT;
6685 goto exit;
6686 }
6687 }
6688 else if (strncmp(command, "SETCCKMIE", 9) == 0)
6689 {
6690 tANI_U8 *value = command;
6691 tANI_U8 *cckmIe = NULL;
6692 tANI_U8 cckmIeLen = 0;
6693 eHalStatus status = eHAL_STATUS_SUCCESS;
6694
6695 status = hdd_parse_get_cckm_ie(value, &cckmIe, &cckmIeLen);
6696 if (eHAL_STATUS_SUCCESS != status)
6697 {
6698 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6699 "%s: Failed to parse cckm ie data", __func__);
6700 ret = -EINVAL;
6701 goto exit;
6702 }
6703
6704 if (cckmIeLen > DOT11F_IE_RSN_MAX_LEN)
6705 {
6706 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6707 "%s: CCKM Ie input length is more than max[%d]", __func__,
6708 DOT11F_IE_RSN_MAX_LEN);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006709 vos_mem_free(cckmIe);
6710 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006711 ret = -EINVAL;
6712 goto exit;
6713 }
6714 sme_SetCCKMIe((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, cckmIe, cckmIeLen);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006715 vos_mem_free(cckmIe);
6716 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006717 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006718 else if (strncmp(command, "CCXBEACONREQ", 12) == 0)
6719 {
6720 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006721 tCsrEseBeaconReq eseBcnReq;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006722 eHalStatus status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07006723
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006724 status = hdd_parse_ese_beacon_req(value, &eseBcnReq);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006725 if (eHAL_STATUS_SUCCESS != status)
6726 {
6727 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006728 "%s: Failed to parse ese beacon req", __func__);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006729 ret = -EINVAL;
6730 goto exit;
6731 }
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07006732 if (!hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))) {
6733 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not associated"));
6734 hdd_indicateEseBcnReportNoResults (pAdapter,
6735 eseBcnReq.bcnReq[0].measurementToken,
6736 0x02, //BIT(1) set for measurement done
6737 0); // no BSS
6738 goto exit;
6739 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006740
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006741 status = sme_SetEseBeaconRequest((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, &eseBcnReq);
6742 if (eHAL_STATUS_SUCCESS != status)
6743 {
6744 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6745 "%s: sme_SetEseBeaconRequest failed (%d)", __func__, status);
6746 ret = -EINVAL;
6747 goto exit;
6748 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006749 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006750#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
c_hpothu92367912014-05-01 15:18:17 +05306751 else if (strncmp(command, "GETBCNMISSRATE", 14) == 0)
6752 {
6753 eHalStatus status;
6754 char buf[32], len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306755 void *cookie;
6756 struct hdd_request *request;
6757 struct bcn_miss_rate_priv *priv;
6758 static const struct hdd_request_params params = {
6759 .priv_size = sizeof(*priv),
6760 .timeout_ms = WLAN_WAIT_TIME_STATS,
6761 };
c_hpothu92367912014-05-01 15:18:17 +05306762
6763 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6764
6765 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6766 {
6767 hddLog(VOS_TRACE_LEVEL_WARN,
6768 FL("GETBCNMISSRATE: STA is not in connected state"));
6769 ret = -1;
6770 goto exit;
6771 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306772 request = hdd_request_alloc(&params);
6773 if (!request) {
6774 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
6775 ret = -ENOMEM;
6776 goto exit;
6777 }
6778 cookie = hdd_request_cookie(request);
6779 priv = hdd_request_priv(request);
6780 priv->bcn_miss_rate = -1;
c_hpothu92367912014-05-01 15:18:17 +05306781
6782 status = sme_getBcnMissRate((tHalHandle)(pHddCtx->hHal),
6783 pAdapter->sessionId,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306784 (void *)get_bcn_miss_rate_cb,
6785 cookie);
c_hpothu92367912014-05-01 15:18:17 +05306786 if( eHAL_STATUS_SUCCESS != status)
6787 {
6788 hddLog(VOS_TRACE_LEVEL_INFO,
6789 FL("GETBCNMISSRATE: fail to post WDA cmd"));
6790 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306791 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306792 }
6793
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306794 ret = hdd_request_wait_for_response(request);
6795 if(ret)
c_hpothu92367912014-05-01 15:18:17 +05306796 {
6797 hddLog(VOS_TRACE_LEVEL_ERROR,
6798 FL("failed to wait on bcnMissRateComp %d"), ret);
6799
c_hpothu92367912014-05-01 15:18:17 +05306800 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306801 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306802 }
6803
6804 hddLog(VOS_TRACE_LEVEL_INFO,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306805 FL("GETBCNMISSRATE: bcnMissRate: %d"), priv->bcn_miss_rate);
c_hpothu92367912014-05-01 15:18:17 +05306806
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306807 if (priv->bcn_miss_rate == -1) {
6808 ret = -EFAULT;
6809 goto free_bcn_miss_rate_req;
6810 }
6811
6812 len = snprintf(buf, sizeof(buf), "GETBCNMISSRATE %d",
6813 priv->bcn_miss_rate);
c_hpothu92367912014-05-01 15:18:17 +05306814 if (copy_to_user(priv_data.buf, &buf, len + 1))
6815 {
6816 hddLog(VOS_TRACE_LEVEL_ERROR,
6817 "%s: failed to copy data to user buffer", __func__);
6818 ret = -EFAULT;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306819 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306820 }
6821 ret = len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306822
6823free_bcn_miss_rate_req:
6824 hdd_request_put(request);
c_hpothu92367912014-05-01 15:18:17 +05306825 }
Atul Mittal87ec2422014-09-24 13:12:50 +05306826#ifdef FEATURE_WLAN_TDLS
6827 else if (strncmp(command, "TDLSSECONDARYCHANNELOFFSET", 26) == 0) {
6828 tANI_U8 *value = command;
6829 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306830
6831 ret = hdd_drv_cmd_validate(command, 26);
6832 if (ret)
6833 goto exit;
6834
Atul Mittal87ec2422014-09-24 13:12:50 +05306835 /* Move pointer to ahead of TDLSOFFCH*/
6836 value += 26;
c_manjeebbc40212015-12-08 13:52:59 +05306837 if (!(sscanf(value, "%d", &set_value))) {
6838 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6839 FL("No input identified"));
6840 ret = -EINVAL;
6841 goto exit;
6842 }
6843
Atul Mittal87ec2422014-09-24 13:12:50 +05306844 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6845 "%s: Tdls offchannel offset:%d",
6846 __func__, set_value);
6847 ret = iw_set_tdlssecoffchanneloffset(pHddCtx, set_value);
6848 if (ret < 0)
6849 {
6850 ret = -EINVAL;
6851 goto exit;
6852 }
6853
6854 } else if (strncmp(command, "TDLSOFFCHANNELMODE", 18) == 0) {
6855 tANI_U8 *value = command;
6856 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306857
6858 ret = hdd_drv_cmd_validate(command, 18);
6859 if (ret)
6860 goto exit;
6861
Atul Mittal87ec2422014-09-24 13:12:50 +05306862 /* Move pointer to ahead of tdlsoffchnmode*/
6863 value += 18;
c_manjee82323892015-12-08 12:40:34 +05306864 ret = sscanf(value, "%d", &set_value);
6865 if (ret != 1) {
6866 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6867 FL("No input identified"));
6868 ret = -EINVAL;
6869 goto exit;
6870 }
Atul Mittal87ec2422014-09-24 13:12:50 +05306871 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6872 "%s: Tdls offchannel mode:%d",
6873 __func__, set_value);
6874 ret = iw_set_tdlsoffchannelmode(pAdapter, set_value);
6875 if (ret < 0)
6876 {
6877 ret = -EINVAL;
6878 goto exit;
6879 }
6880 } else if (strncmp(command, "TDLSOFFCHANNEL", 14) == 0) {
6881 tANI_U8 *value = command;
6882 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306883
6884 ret = hdd_drv_cmd_validate(command, 14);
6885 if (ret)
6886 goto exit;
6887
Atul Mittal87ec2422014-09-24 13:12:50 +05306888 /* Move pointer to ahead of TDLSOFFCH*/
6889 value += 14;
c_manjeef6ccaf52015-12-08 11:52:11 +05306890 ret = sscanf(value, "%d", &set_value);
6891 if (ret != 1) {
6892 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6893 "Wrong value is given for hdd_set_tdls_offchannel");
6894 ret = -EINVAL;
6895 goto exit;
6896 }
6897
Atul Mittal87ec2422014-09-24 13:12:50 +05306898 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6899 "%s: Tdls offchannel num: %d",
6900 __func__, set_value);
6901 ret = iw_set_tdlsoffchannel(pHddCtx, set_value);
6902 if (ret < 0)
6903 {
6904 ret = -EINVAL;
6905 goto exit;
6906 }
6907 }
6908#endif
Satyanarayana Dash72806012014-12-02 14:30:08 +05306909 else if (strncmp(command, "GETFWSTATS", 10) == 0)
6910 {
6911 eHalStatus status;
6912 char *buf = NULL;
6913 char len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306914 tSirFwStatsResult *fwStatsRsp = &(pAdapter->fwStatsRsp),
6915 *fw_stats_result;
Satyanarayana Dash72806012014-12-02 14:30:08 +05306916 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306917 int stats;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306918 void *cookie;
6919 struct hdd_request *request;
6920 struct fw_stats_priv *priv;
6921 static const struct hdd_request_params params = {
6922 .priv_size = sizeof(*priv),
6923 .timeout_ms = WLAN_WAIT_TIME_STATS,
6924 };
Satyanarayana Dash72806012014-12-02 14:30:08 +05306925
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306926 ret = hdd_drv_cmd_validate(command, 10);
6927 if (ret)
6928 goto exit;
6929
6930 stats = *(ptr + 11) - '0';
Satyanarayana Dash72806012014-12-02 14:30:08 +05306931 hddLog(VOS_TRACE_LEVEL_INFO, FL("stats = %d "),stats);
6932 if (!IS_FEATURE_FW_STATS_ENABLE)
6933 {
6934 hddLog(VOS_TRACE_LEVEL_INFO,
6935 FL("Get Firmware stats feature not supported"));
6936 ret = -EINVAL;
6937 goto exit;
6938 }
6939
6940 if (FW_STATS_MAX <= stats || 0 >= stats)
6941 {
6942 hddLog(VOS_TRACE_LEVEL_INFO,
6943 FL(" stats %d not supported"),stats);
6944 ret = -EINVAL;
6945 goto exit;
6946 }
6947
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306948 request = hdd_request_alloc(&params);
6949 if (!request) {
6950 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
6951 ret = -ENOMEM;
6952 goto exit;
6953 }
6954 cookie = hdd_request_cookie(request);
6955
Satyanarayana Dash72806012014-12-02 14:30:08 +05306956 status = sme_GetFwStats( (tHalHandle)pHddCtx->hHal, stats,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306957 cookie, hdd_fw_stats_cb);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306958 if (eHAL_STATUS_SUCCESS != status)
6959 {
6960 hddLog(VOS_TRACE_LEVEL_ERROR,
6961 FL(" fail to post WDA cmd status = %d"), status);
6962 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306963 hdd_request_put(request);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306964 goto exit;
6965 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306966 ret = hdd_request_wait_for_response(request);
6967 if (ret)
Satyanarayana Dash72806012014-12-02 14:30:08 +05306968 {
6969 hddLog(VOS_TRACE_LEVEL_ERROR,
6970 FL("failed to wait on GwtFwstats"));
Satyanarayana Dash72806012014-12-02 14:30:08 +05306971 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306972 hdd_request_put(request);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306973 goto exit;
6974 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306975
6976 priv = hdd_request_priv(request);
6977 fw_stats_result = priv->fw_stats;
6978 fwStatsRsp->type = 0;
6979 if (NULL != fw_stats_result)
6980 {
6981 switch (fw_stats_result->type )
6982 {
6983 case FW_UBSP_STATS:
6984 {
6985 tSirUbspFwStats *stats =
6986 &fwStatsRsp->fwStatsData.ubspStats;
6987 memcpy(fwStatsRsp, fw_stats_result,
6988 sizeof(tSirFwStatsResult));
6989 hddLog(VOS_TRACE_LEVEL_INFO,
6990 FL("ubsp_enter_cnt = %d ubsp_jump_ddr_cnt = %d"),
6991 stats->ubsp_enter_cnt,
6992 stats->ubsp_jump_ddr_cnt);
6993 }
6994 break;
6995
6996 default:
6997 {
6998 hddLog(VOS_TRACE_LEVEL_ERROR,
6999 FL("No handling for stats type %d"),
7000 fw_stats_result->type);
7001 }
7002 }
7003 }
7004 hdd_request_put(request);
7005
Satyanarayana Dash72806012014-12-02 14:30:08 +05307006 if (fwStatsRsp->type)
7007 {
7008 buf = kmalloc(FW_STATE_RSP_LEN, GFP_KERNEL);
7009 if (!buf)
7010 {
7011 hddLog(VOS_TRACE_LEVEL_ERROR,
7012 FL(" failed to allocate memory"));
7013 ret = -ENOMEM;
7014 goto exit;
7015 }
7016 switch( fwStatsRsp->type )
7017 {
7018 case FW_UBSP_STATS:
7019 {
7020 len = snprintf(buf, FW_STATE_RSP_LEN,
7021 "GETFWSTATS: ubsp_enter_cnt %d ubsp_jump_ddr_cnt %d",
Abhishek Singh08aa7762014-12-16 13:59:03 +05307022 fwStatsRsp->fwStatsData.ubspStats.ubsp_enter_cnt,
7023 fwStatsRsp->fwStatsData.ubspStats.ubsp_jump_ddr_cnt);
Satyanarayana Dash72806012014-12-02 14:30:08 +05307024 }
7025 break;
7026 default:
7027 {
7028 hddLog(VOS_TRACE_LEVEL_ERROR, FL( "No handling for stats type %d"),fwStatsRsp->type);
7029 ret = -EFAULT;
7030 kfree(buf);
7031 goto exit;
7032 }
7033 }
7034 if (copy_to_user(priv_data.buf, buf, len + 1))
7035 {
7036 hddLog(VOS_TRACE_LEVEL_ERROR,
7037 FL(" failed to copy data to user buffer"));
7038 ret = -EFAULT;
7039 kfree(buf);
7040 goto exit;
7041 }
7042 ret = len;
7043 kfree(buf);
7044 }
7045 else
7046 {
7047 hddLog(VOS_TRACE_LEVEL_ERROR,
7048 FL("failed to fetch the stats"));
7049 ret = -EFAULT;
7050 goto exit;
7051 }
Satyanarayana Dash72806012014-12-02 14:30:08 +05307052 }
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05307053 else if (strncasecmp(command, "SET_FCC_CHANNEL", 15) == 0)
7054 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05307055 ret = hdd_drv_cmd_validate(command, 15);
7056 if (ret)
7057 goto exit;
7058
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05307059 /*
7060 * this command wld be called by user-space when it detects WLAN
7061 * ON after airplane mode is set. When APM is set, WLAN turns off.
7062 * But it can be turned back on. Otherwise; when APM is turned back
7063 * off, WLAN wld turn back on. So at that point the command is
7064 * expected to come down. 0 means disable, 1 means enable. The
7065 * constraint is removed when parameter 1 is set or different
7066 * country code is set
7067 */
7068 ret = hdd_cmd_setFccChannel(pHddCtx, command, 15);
7069 }
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05307070 else if (strncasecmp(command, "DISABLE_CA_EVENT", 16) == 0)
7071 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05307072 ret = hdd_drv_cmd_validate(command, 16);
7073 if (ret)
7074 goto exit;
7075
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05307076 ret = hdd_enable_disable_ca_event(pHddCtx, command, 16);
7077 }
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05307078 /*
7079 * command should be a string having format
7080 * SET_DISABLE_CHANNEL_LIST <num of channels>
7081 * <channels separated by spaces>
7082 */
7083 else if (strncmp(command, "SET_DISABLE_CHANNEL_LIST", 24) == 0) {
7084 tANI_U8 *ptr = command;
7085 ret = hdd_drv_cmd_validate(command, 24);
7086 if (ret)
7087 goto exit;
7088
7089 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7090 " Received Command to disable Channels %s",
7091 __func__);
7092 ret = hdd_parse_disable_chan_cmd(pAdapter, ptr);
7093 if (ret)
7094 goto exit;
7095 }
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307096 else if (strncmp(command, "GET_DISABLE_CHANNEL_LIST", 24) == 0) {
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307097 char extra[512] = {0};
7098 int max_len, copied_length;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05307099
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307100 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307101 " Received Command to get disable Channels list %s",
7102 __func__);
7103
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307104 max_len = VOS_MIN(priv_data.total_len, sizeof(extra));
7105 copied_length = hdd_get_disable_ch_list(pHddCtx, extra, max_len);
7106 if (copied_length == 0) {
7107 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307108 FL("disable channel list are not yet programed"));
7109 ret = -EINVAL;
7110 goto exit;
7111 }
7112
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307113 if (copy_to_user(priv_data.buf, &extra, copied_length + 1)) {
7114 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7115 "%s: failed to copy data to user buffer", __func__);
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307116 ret = -EFAULT;
7117 goto exit;
7118 }
7119
7120 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7121 FL("data:%s"), extra);
7122 }
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07007123 else {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307124 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7125 TRACE_CODE_HDD_UNSUPPORTED_IOCTL,
7126 pAdapter->sessionId, 0));
Satyanarayana Dash72806012014-12-02 14:30:08 +05307127 hddLog( VOS_TRACE_LEVEL_WARN, FL("Unsupported GUI command %s"),
7128 command);
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07007129 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007130 }
7131exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307132 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007133 if (command)
7134 {
7135 kfree(command);
7136 }
7137 return ret;
7138}
7139
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007140#ifdef CONFIG_COMPAT
7141static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7142{
7143 struct {
7144 compat_uptr_t buf;
7145 int used_len;
7146 int total_len;
7147 } compat_priv_data;
7148 hdd_priv_data_t priv_data;
7149 int ret = 0;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007150
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007151 /*
7152 * Note that pAdapter and ifr have already been verified by caller,
7153 * and HDD context has also been validated
7154 */
7155 if (copy_from_user(&compat_priv_data, ifr->ifr_data,
7156 sizeof(compat_priv_data))) {
7157 ret = -EFAULT;
7158 goto exit;
7159 }
7160 priv_data.buf = compat_ptr(compat_priv_data.buf);
7161 priv_data.used_len = compat_priv_data.used_len;
7162 priv_data.total_len = compat_priv_data.total_len;
7163 ret = hdd_driver_command(pAdapter, &priv_data);
7164 exit:
7165 return ret;
7166}
7167#else /* CONFIG_COMPAT */
7168static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7169{
7170 /* will never be invoked */
7171 return 0;
7172}
7173#endif /* CONFIG_COMPAT */
7174
7175static int hdd_driver_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7176{
7177 hdd_priv_data_t priv_data;
7178 int ret = 0;
7179
7180 /*
7181 * Note that pAdapter and ifr have already been verified by caller,
7182 * and HDD context has also been validated
7183 */
7184 if (copy_from_user(&priv_data, ifr->ifr_data, sizeof(priv_data))) {
7185 ret = -EFAULT;
7186 } else {
7187 ret = hdd_driver_command(pAdapter, &priv_data);
7188 }
7189 return ret;
7190}
7191
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307192int __hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007193{
7194 hdd_adapter_t *pAdapter;
7195 hdd_context_t *pHddCtx;
7196 int ret;
7197
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307198 ENTER();
7199
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007200 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7201 if (NULL == pAdapter) {
7202 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7203 "%s: HDD adapter context is Null", __func__);
7204 ret = -ENODEV;
7205 goto exit;
7206 }
7207 if (dev != pAdapter->dev) {
7208 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7209 "%s: HDD adapter/dev inconsistency", __func__);
7210 ret = -ENODEV;
7211 goto exit;
7212 }
7213
7214 if ((!ifr) || (!ifr->ifr_data)) {
7215 ret = -EINVAL;
7216 goto exit;
7217 }
7218
7219 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7220 ret = wlan_hdd_validate_context(pHddCtx);
7221 if (ret) {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007222 ret = -EBUSY;
7223 goto exit;
7224 }
7225
7226 switch (cmd) {
7227 case (SIOCDEVPRIVATE + 1):
7228 if (is_compat_task())
7229 ret = hdd_driver_compat_ioctl(pAdapter, ifr);
7230 else
7231 ret = hdd_driver_ioctl(pAdapter, ifr);
7232 break;
7233 default:
7234 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unknown ioctl %d",
7235 __func__, cmd);
7236 ret = -EINVAL;
7237 break;
7238 }
7239 exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307240 EXIT();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007241 return ret;
7242}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007243
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307244int hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7245{
7246 int ret;
7247
7248 vos_ssr_protect(__func__);
7249 ret = __hdd_ioctl(dev, ifr, cmd);
7250 vos_ssr_unprotect(__func__);
7251
7252 return ret;
7253}
7254
Katya Nigame7b69a82015-04-28 15:24:06 +05307255int hdd_mon_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7256{
7257 return 0;
7258}
7259
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007260#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007261/**---------------------------------------------------------------------------
7262
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007263 \brief hdd_parse_ese_beacon_req() - Parse ese beacon request
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007264
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007265 This function parses the ese beacon request passed in the format
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007266 CCXBEACONREQ<space><Number of fields><space><Measurement token>
7267 <space>Channel 1<space>Scan Mode <space>Meas Duration<space>Channel N
7268 <space>Scan Mode N<space>Meas Duration N
7269 if the Number of bcn req fields (N) does not match with the actual number of fields passed
7270 then take N.
7271 <Meas Token><Channel><Scan Mode> and <Meas Duration> are treated as one pair
7272 For example, CCXBEACONREQ 2 1 1 1 30 2 44 0 40.
7273 This function does not take care of removing duplicate channels from the list
7274
7275 \param - pValue Pointer to data
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007276 \param - pEseBcnReq output pointer to store parsed ie information
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007277
7278 \return - 0 for success non-zero for failure
7279
7280 --------------------------------------------------------------------------*/
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007281static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
7282 tCsrEseBeaconReq *pEseBcnReq)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007283{
7284 tANI_U8 *inPtr = pValue;
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307285 uint8_t input = 0;
7286 uint32_t tempInt = 0;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007287 int j = 0, i = 0, v = 0;
7288 char buf[32];
7289
7290 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7291 /*no argument after the command*/
7292 if (NULL == inPtr)
7293 {
7294 return -EINVAL;
7295 }
7296 /*no space after the command*/
7297 else if (SPACE_ASCII_VALUE != *inPtr)
7298 {
7299 return -EINVAL;
7300 }
7301
7302 /*removing empty spaces*/
7303 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
7304
7305 /*no argument followed by spaces*/
7306 if ('\0' == *inPtr) return -EINVAL;
7307
7308 /*getting the first argument ie measurement token*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007309 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007310 if (1 != v) return -EINVAL;
7311
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307312 v = kstrtos8(buf, 10, &input);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007313 if ( v < 0) return -EINVAL;
7314
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307315 input = VOS_MIN(input, SIR_ESE_MAX_MEAS_IE_REQS);
7316 pEseBcnReq->numBcnReqIe = input;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007317
Srinivas Girigowda725a88e2016-03-31 19:24:25 +05307318 hddLog(LOG1, "Number of Bcn Req Ie fields: %d", pEseBcnReq->numBcnReqIe);
7319
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007320
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007321 for (j = 0; j < (pEseBcnReq->numBcnReqIe); j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007322 {
7323 for (i = 0; i < 4; i++)
7324 {
7325 /*inPtr pointing to the beginning of first space after number of ie fields*/
7326 inPtr = strpbrk( inPtr, " " );
7327 /*no ie data after the number of ie fields argument*/
7328 if (NULL == inPtr) return -EINVAL;
7329
7330 /*removing empty space*/
7331 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
7332
7333 /*no ie data after the number of ie fields argument and spaces*/
7334 if ( '\0' == *inPtr ) return -EINVAL;
7335
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007336 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007337 if (1 != v) return -EINVAL;
7338
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307339 v = kstrtou32(buf, 10, &tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007340 if (v < 0) return -EINVAL;
7341
7342 switch (i)
7343 {
7344 case 0: /* Measurement token */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307345 if (!tempInt)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007346 {
7347 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307348 "Invalid Measurement Token: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007349 return -EINVAL;
7350 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007351 pEseBcnReq->bcnReq[j].measurementToken = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007352 break;
7353
7354 case 1: /* Channel number */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307355 if ((!tempInt) ||
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007356 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7357 {
7358 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307359 "Invalid Channel Number: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007360 return -EINVAL;
7361 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007362 pEseBcnReq->bcnReq[j].channel = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007363 break;
7364
7365 case 2: /* Scan mode */
Varun Reddy Yeturu0b18d5a2013-12-04 11:42:23 -08007366 if ((tempInt < eSIR_PASSIVE_SCAN) || (tempInt > eSIR_BEACON_TABLE))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007367 {
7368 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307369 "Invalid Scan Mode(%u) Expected{0|1|2}", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007370 return -EINVAL;
7371 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007372 pEseBcnReq->bcnReq[j].scanMode= tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007373 break;
7374
7375 case 3: /* Measurement duration */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307376 if (((!tempInt) && (pEseBcnReq->bcnReq[j].scanMode != eSIR_BEACON_TABLE)) ||
7377 ((pEseBcnReq->bcnReq[j].scanMode == eSIR_BEACON_TABLE)))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007378 {
7379 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307380 "Invalid Measurement Duration: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007381 return -EINVAL;
7382 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007383 pEseBcnReq->bcnReq[j].measurementDuration = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007384 break;
7385 }
7386 }
7387 }
7388
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007389 for (j = 0; j < pEseBcnReq->numBcnReqIe; j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007390 {
7391 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05307392 "Index(%d) Measurement Token(%u)Channel(%u) Scan Mode(%u) Measurement Duration(%u)\n",
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007393 j,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007394 pEseBcnReq->bcnReq[j].measurementToken,
7395 pEseBcnReq->bcnReq[j].channel,
7396 pEseBcnReq->bcnReq[j].scanMode,
7397 pEseBcnReq->bcnReq[j].measurementDuration);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007398 }
7399
7400 return VOS_STATUS_SUCCESS;
7401}
7402
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307403struct tsm_priv {
7404 tAniTrafStrmMetrics tsm_metrics;
7405};
7406
7407static void hdd_get_tsm_stats_cb(tAniTrafStrmMetrics tsm_metrics,
7408 const tANI_U32 sta_id, void *context )
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007409{
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307410 struct hdd_request *request;
7411 struct tsm_priv *priv;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007412
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307413 ENTER();
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007414
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307415 request = hdd_request_get(context);
7416 if (!request) {
7417 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
7418 return;
7419 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007420
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307421 priv = hdd_request_priv(request);
7422 priv->tsm_metrics = tsm_metrics;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007423
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307424 hdd_request_complete(request);
7425 hdd_request_put(request);
Jeff Johnson72a40512013-12-19 10:14:15 -08007426
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307427 EXIT();
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007428}
7429
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007430static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
7431 tAniTrafStrmMetrics* pTsmMetrics)
7432{
7433 hdd_station_ctx_t *pHddStaCtx = NULL;
7434 eHalStatus hstatus;
Jeff Johnson72a40512013-12-19 10:14:15 -08007435 VOS_STATUS vstatus = VOS_STATUS_SUCCESS;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007436 hdd_context_t *pHddCtx = NULL;
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307437 int ret;
7438 void *cookie;
7439 struct hdd_request *request;
7440 struct tsm_priv *priv;
7441 static const struct hdd_request_params params = {
7442 .priv_size = sizeof(*priv),
7443 .timeout_ms = WLAN_WAIT_TIME_STATS,
7444 };
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007445
7446 if (NULL == pAdapter)
7447 {
7448 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL", __func__);
7449 return VOS_STATUS_E_FAULT;
7450 }
7451
7452 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7453 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7454
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307455 request = hdd_request_alloc(&params);
7456 if (!request) {
7457 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
7458 return VOS_STATUS_E_NOMEM;
7459 }
7460 cookie = hdd_request_cookie(request);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007461
7462 /* query tsm stats */
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307463 hstatus = sme_GetTsmStats(pHddCtx->hHal, hdd_get_tsm_stats_cb,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007464 pHddStaCtx->conn_info.staId[ 0 ],
7465 pHddStaCtx->conn_info.bssId,
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307466 cookie, pHddCtx->pvosContext, tid);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007467
7468 if (eHAL_STATUS_SUCCESS != hstatus)
7469 {
Jeff Johnson72a40512013-12-19 10:14:15 -08007470 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unable to retrieve statistics",
7471 __func__);
7472 vstatus = VOS_STATUS_E_FAULT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007473 }
7474 else
7475 {
7476 /* request was sent -- wait for the response */
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307477 ret = hdd_request_wait_for_response(request);
7478 if (ret) {
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007479 hddLog(VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307480 "SME timeout while retrieving statistics");
Jeff Johnson72a40512013-12-19 10:14:15 -08007481 vstatus = VOS_STATUS_E_TIMEOUT;
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307482 } else {
7483 priv = hdd_request_priv(request);
7484 *pTsmMetrics = priv->tsm_metrics;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007485 }
7486 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007487
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307488 hdd_request_put(request);
Jeff Johnson72a40512013-12-19 10:14:15 -08007489
Jeff Johnson72a40512013-12-19 10:14:15 -08007490 return vstatus;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007491}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007492#endif /*FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007493
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007494#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08007495void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand)
7496{
7497 eCsrBand band = -1;
7498 sme_GetFreqBand((tHalHandle)(pHddCtx->hHal), &band);
7499 switch (band)
7500 {
7501 case eCSR_BAND_ALL:
7502 *pBand = WLAN_HDD_UI_BAND_AUTO;
7503 break;
7504
7505 case eCSR_BAND_24:
7506 *pBand = WLAN_HDD_UI_BAND_2_4_GHZ;
7507 break;
7508
7509 case eCSR_BAND_5G:
7510 *pBand = WLAN_HDD_UI_BAND_5_GHZ;
7511 break;
7512
7513 default:
7514 hddLog( VOS_TRACE_LEVEL_WARN, "%s: Invalid Band %d", __func__, band);
7515 *pBand = -1;
7516 break;
7517 }
7518}
7519
7520/**---------------------------------------------------------------------------
7521
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007522 \brief hdd_parse_send_action_frame_data() - HDD Parse send action frame data
7523
7524 This function parses the send action frame data passed in the format
7525 SENDACTIONFRAME<space><bssid><space><channel><space><dwelltime><space><data>
7526
Srinivas Girigowda56076852013-08-20 14:00:50 -07007527 \param - pValue Pointer to input data
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007528 \param - pTargetApBssid Pointer to target Ap bssid
7529 \param - pChannel Pointer to the Target AP channel
7530 \param - pDwellTime Pointer to the time to stay off-channel after transmitting action frame
7531 \param - pBuf Pointer to data
7532 \param - pBufLen Pointer to data length
7533
7534 \return - 0 for success non-zero for failure
7535
7536 --------------------------------------------------------------------------*/
7537VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid, tANI_U8 *pChannel,
7538 tANI_U8 *pDwellTime, tANI_U8 **pBuf, tANI_U8 *pBufLen)
7539{
7540 tANI_U8 *inPtr = pValue;
7541 tANI_U8 *dataEnd;
7542 int tempInt;
7543 int j = 0;
7544 int i = 0;
7545 int v = 0;
7546 tANI_U8 tempBuf[32];
7547 tANI_U8 tempByte = 0;
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007548 /* 12 hexa decimal digits, 5 ':' and '\0' */
7549 tANI_U8 macAddress[18];
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007550
7551 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7552 /*no argument after the command*/
7553 if (NULL == inPtr)
7554 {
7555 return -EINVAL;
7556 }
7557
7558 /*no space after the command*/
7559 else if (SPACE_ASCII_VALUE != *inPtr)
7560 {
7561 return -EINVAL;
7562 }
7563
7564 /*removing empty spaces*/
7565 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7566
7567 /*no argument followed by spaces*/
7568 if ('\0' == *inPtr)
7569 {
7570 return -EINVAL;
7571 }
7572
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007573 v = sscanf(inPtr, "%17s", macAddress);
7574 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007575 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007576 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7577 "Invalid MAC address or All hex inputs are not read (%d)", v);
7578 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007579 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007580
7581 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
7582 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
7583 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
7584 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
7585 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
7586 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007587
7588 /* point to the next argument */
7589 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7590 /*no argument after the command*/
7591 if (NULL == inPtr) return -EINVAL;
7592
7593 /*removing empty spaces*/
7594 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7595
7596 /*no argument followed by spaces*/
7597 if ('\0' == *inPtr)
7598 {
7599 return -EINVAL;
7600 }
7601
7602 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007603 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007604 if (1 != v) return -EINVAL;
7605
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007606 v = kstrtos32(tempBuf, 10, &tempInt);
Agarwal Ashish353b3a82014-04-08 14:55:11 +05307607 if ( v < 0 || tempInt <= 0 || tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX )
Kiet Lambe150c22013-11-21 16:30:32 +05307608 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007609
7610 *pChannel = tempInt;
7611
7612 /* point to the next argument */
7613 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7614 /*no argument after the command*/
7615 if (NULL == inPtr) return -EINVAL;
7616 /*removing empty spaces*/
7617 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7618
7619 /*no argument followed by spaces*/
7620 if ('\0' == *inPtr)
7621 {
7622 return -EINVAL;
7623 }
7624
7625 /*getting the next argument ie the dwell time */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007626 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007627 if (1 != v) return -EINVAL;
7628
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007629 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda5a6e0672014-01-09 14:42:57 -08007630 if ( v < 0 || tempInt < 0) return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007631
7632 *pDwellTime = tempInt;
7633
7634 /* point to the next argument */
7635 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7636 /*no argument after the command*/
7637 if (NULL == inPtr) return -EINVAL;
7638 /*removing empty spaces*/
7639 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7640
7641 /*no argument followed by spaces*/
7642 if ('\0' == *inPtr)
7643 {
7644 return -EINVAL;
7645 }
7646
7647 /* find the length of data */
7648 dataEnd = inPtr;
7649 while(('\0' != *dataEnd) )
7650 {
7651 dataEnd++;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007652 }
Kiet Lambe150c22013-11-21 16:30:32 +05307653 *pBufLen = dataEnd - inPtr ;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007654 if ( *pBufLen <= 0) return -EINVAL;
7655
Srinivas Girigowdab5ae85d2013-06-03 10:51:45 -07007656 /* Allocate the number of bytes based on the number of input characters
7657 whether it is even or odd.
7658 if the number of input characters are even, then we need N/2 byte.
7659 if the number of input characters are odd, then we need do (N+1)/2 to
7660 compensate rounding off.
7661 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
7662 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
7663 *pBuf = vos_mem_malloc((*pBufLen + 1)/2);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007664 if (NULL == *pBuf)
7665 {
7666 hddLog(VOS_TRACE_LEVEL_FATAL,
7667 "%s: vos_mem_alloc failed ", __func__);
7668 return -EINVAL;
7669 }
7670
7671 /* the buffer received from the upper layer is character buffer,
7672 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
7673 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
7674 and f0 in 3rd location */
7675 for (i = 0, j = 0; j < *pBufLen; j += 2)
7676 {
Kiet Lambe150c22013-11-21 16:30:32 +05307677 if( j+1 == *pBufLen)
7678 {
7679 tempByte = hdd_parse_hex(inPtr[j]);
7680 }
7681 else
7682 {
7683 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
7684 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007685 (*pBuf)[i++] = tempByte;
7686 }
7687 *pBufLen = i;
7688 return VOS_STATUS_SUCCESS;
7689}
7690
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007691/**---------------------------------------------------------------------------
7692
Srinivas Girigowdade697412013-02-14 16:31:48 -08007693 \brief hdd_parse_channellist() - HDD Parse channel list
7694
7695 This function parses the channel list passed in the format
7696 SETROAMSCANCHANNELS<space><Number of channels><space>Channel 1<space>Channel 2<space>Channel N
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007697 if the Number of channels (N) does not match with the actual number of channels passed
7698 then take the minimum of N and count of (Ch1, Ch2, ...Ch M)
7699 For example, if SETROAMSCANCHANNELS 3 36 40 44 48, only 36, 40 and 44 shall be taken.
7700 If SETROAMSCANCHANNELS 5 36 40 44 48, ignore 5 and take 36, 40, 44 and 48.
7701 This function does not take care of removing duplicate channels from the list
Srinivas Girigowdade697412013-02-14 16:31:48 -08007702
7703 \param - pValue Pointer to input channel list
7704 \param - ChannelList Pointer to local output array to record channel list
7705 \param - pNumChannels Pointer to number of roam scan channels
7706
7707 \return - 0 for success non-zero for failure
7708
7709 --------------------------------------------------------------------------*/
7710VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels)
7711{
7712 tANI_U8 *inPtr = pValue;
7713 int tempInt;
7714 int j = 0;
7715 int v = 0;
7716 char buf[32];
7717
7718 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7719 /*no argument after the command*/
7720 if (NULL == inPtr)
7721 {
7722 return -EINVAL;
7723 }
7724
7725 /*no space after the command*/
7726 else if (SPACE_ASCII_VALUE != *inPtr)
7727 {
7728 return -EINVAL;
7729 }
7730
7731 /*removing empty spaces*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007732 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08007733
7734 /*no argument followed by spaces*/
7735 if ('\0' == *inPtr)
7736 {
7737 return -EINVAL;
7738 }
7739
7740 /*getting the first argument ie the number of channels*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007741 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007742 if (1 != v) return -EINVAL;
7743
Srinivas Girigowdade697412013-02-14 16:31:48 -08007744 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007745 if ((v < 0) ||
7746 (tempInt <= 0) ||
7747 (tempInt > WNI_CFG_VALID_CHANNEL_LIST_LEN))
7748 {
7749 return -EINVAL;
7750 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007751
7752 *pNumChannels = tempInt;
7753
7754 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
7755 "Number of channels are: %d", *pNumChannels);
7756
7757 for (j = 0; j < (*pNumChannels); j++)
7758 {
7759 /*inPtr pointing to the beginning of first space after number of channels*/
7760 inPtr = strpbrk( inPtr, " " );
7761 /*no channel list after the number of channels argument*/
7762 if (NULL == inPtr)
7763 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007764 if (0 != j)
7765 {
7766 *pNumChannels = j;
7767 return VOS_STATUS_SUCCESS;
7768 }
7769 else
7770 {
7771 return -EINVAL;
7772 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007773 }
7774
7775 /*removing empty space*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007776 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08007777
7778 /*no channel list after the number of channels argument and spaces*/
7779 if ( '\0' == *inPtr )
7780 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007781 if (0 != j)
7782 {
7783 *pNumChannels = j;
7784 return VOS_STATUS_SUCCESS;
7785 }
7786 else
7787 {
7788 return -EINVAL;
7789 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007790 }
7791
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007792 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007793 if (1 != v) return -EINVAL;
7794
Srinivas Girigowdade697412013-02-14 16:31:48 -08007795 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007796 if ((v < 0) ||
7797 (tempInt <= 0) ||
7798 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7799 {
7800 return -EINVAL;
7801 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007802 pChannelList[j] = tempInt;
7803
7804 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
7805 "Channel %d added to preferred channel list",
7806 pChannelList[j] );
7807 }
7808
Srinivas Girigowdade697412013-02-14 16:31:48 -08007809 return VOS_STATUS_SUCCESS;
7810}
7811
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007812
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05307813/**
7814 * hdd_parse_reassoc_command_v1_data() - HDD Parse reassoc command data
7815 * This function parses the reasoc command data passed in the format
7816 * REASSOC<space><bssid><space><channel>
7817 *
7818 * @pValue: Pointer to input data (its a NUL terminated string)
7819 * @pTargetApBssid: Pointer to target Ap bssid
7820 * @pChannel: Pointer to the Target AP channel
7821 *
7822 * Return: 0 for success non-zero for failure
7823 */
7824static int hdd_parse_reassoc_command_v1_data(const tANI_U8 *pValue,
7825 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007826{
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05307827 const tANI_U8 *inPtr = pValue;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007828 int tempInt;
7829 int v = 0;
7830 tANI_U8 tempBuf[32];
Kiet Lamaa8e15a2014-02-11 23:30:06 -08007831 /* 12 hexa decimal digits, 5 ':' and '\0' */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007832 tANI_U8 macAddress[18];
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007833
7834 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7835 /*no argument after the command*/
7836 if (NULL == inPtr)
7837 {
7838 return -EINVAL;
7839 }
7840
7841 /*no space after the command*/
7842 else if (SPACE_ASCII_VALUE != *inPtr)
7843 {
7844 return -EINVAL;
7845 }
7846
7847 /*removing empty spaces*/
7848 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7849
7850 /*no argument followed by spaces*/
7851 if ('\0' == *inPtr)
7852 {
7853 return -EINVAL;
7854 }
7855
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007856 v = sscanf(inPtr, "%17s", macAddress);
7857 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007858 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007859 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7860 "Invalid MAC address or All hex inputs are not read (%d)", v);
7861 return -EINVAL;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007862 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007863
7864 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
7865 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
7866 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
7867 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
7868 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
7869 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007870
7871 /* point to the next argument */
7872 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7873 /*no argument after the command*/
7874 if (NULL == inPtr) return -EINVAL;
7875
7876 /*removing empty spaces*/
7877 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7878
7879 /*no argument followed by spaces*/
7880 if ('\0' == *inPtr)
7881 {
7882 return -EINVAL;
7883 }
7884
7885 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007886 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007887 if (1 != v) return -EINVAL;
7888
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007889 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007890 if ((v < 0) ||
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05307891 (tempInt < 0) ||
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007892 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7893 {
7894 return -EINVAL;
7895 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007896
7897 *pChannel = tempInt;
7898 return VOS_STATUS_SUCCESS;
7899}
7900
7901#endif
7902
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007903#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007904/**---------------------------------------------------------------------------
7905
7906 \brief hdd_parse_get_cckm_ie() - HDD Parse and fetch the CCKM IE
7907
7908 This function parses the SETCCKM IE command
7909 SETCCKMIE<space><ie data>
7910
7911 \param - pValue Pointer to input data
7912 \param - pCckmIe Pointer to output cckm Ie
7913 \param - pCckmIeLen Pointer to output cckm ie length
7914
7915 \return - 0 for success non-zero for failure
7916
7917 --------------------------------------------------------------------------*/
7918VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe,
7919 tANI_U8 *pCckmIeLen)
7920{
7921 tANI_U8 *inPtr = pValue;
7922 tANI_U8 *dataEnd;
7923 int j = 0;
7924 int i = 0;
7925 tANI_U8 tempByte = 0;
7926
7927 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7928 /*no argument after the command*/
7929 if (NULL == inPtr)
7930 {
7931 return -EINVAL;
7932 }
7933
7934 /*no space after the command*/
7935 else if (SPACE_ASCII_VALUE != *inPtr)
7936 {
7937 return -EINVAL;
7938 }
7939
7940 /*removing empty spaces*/
7941 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7942
7943 /*no argument followed by spaces*/
7944 if ('\0' == *inPtr)
7945 {
7946 return -EINVAL;
7947 }
7948
7949 /* find the length of data */
7950 dataEnd = inPtr;
7951 while(('\0' != *dataEnd) )
7952 {
7953 dataEnd++;
7954 ++(*pCckmIeLen);
7955 }
7956 if ( *pCckmIeLen <= 0) return -EINVAL;
7957
7958 /* Allocate the number of bytes based on the number of input characters
7959 whether it is even or odd.
7960 if the number of input characters are even, then we need N/2 byte.
7961 if the number of input characters are odd, then we need do (N+1)/2 to
7962 compensate rounding off.
7963 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
7964 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
7965 *pCckmIe = vos_mem_malloc((*pCckmIeLen + 1)/2);
7966 if (NULL == *pCckmIe)
7967 {
7968 hddLog(VOS_TRACE_LEVEL_FATAL,
7969 "%s: vos_mem_alloc failed ", __func__);
7970 return -EINVAL;
7971 }
7972 vos_mem_zero(*pCckmIe, (*pCckmIeLen + 1)/2);
7973 /* the buffer received from the upper layer is character buffer,
7974 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
7975 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
7976 and f0 in 3rd location */
7977 for (i = 0, j = 0; j < *pCckmIeLen; j += 2)
7978 {
7979 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
7980 (*pCckmIe)[i++] = tempByte;
7981 }
7982 *pCckmIeLen = i;
7983
7984 return VOS_STATUS_SUCCESS;
7985}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007986#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007987
Jeff Johnson295189b2012-06-20 16:38:30 -07007988/**---------------------------------------------------------------------------
7989
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007990 \brief hdd_is_valid_mac_address() - Validate MAC address
7991
7992 This function validates whether the given MAC address is valid or not
7993 Expected MAC address is of the format XX:XX:XX:XX:XX:XX
7994 where X is the hexa decimal digit character and separated by ':'
7995 This algorithm works even if MAC address is not separated by ':'
7996
7997 This code checks given input string mac contains exactly 12 hexadecimal digits.
7998 and a separator colon : appears in the input string only after
7999 an even number of hex digits.
8000
8001 \param - pMacAddr pointer to the input MAC address
8002 \return - 1 for valid and 0 for invalid
8003
8004 --------------------------------------------------------------------------*/
8005
8006v_BOOL_t hdd_is_valid_mac_address(const tANI_U8 *pMacAddr)
8007{
8008 int xdigit = 0;
8009 int separator = 0;
8010 while (*pMacAddr)
8011 {
8012 if (isxdigit(*pMacAddr))
8013 {
8014 xdigit++;
8015 }
8016 else if (':' == *pMacAddr)
8017 {
8018 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
8019 break;
8020
8021 ++separator;
8022 }
8023 else
8024 {
8025 separator = -1;
8026 /* Invalid MAC found */
8027 return 0;
8028 }
8029 ++pMacAddr;
8030 }
8031 return (xdigit == 12 && (separator == 5 || separator == 0));
8032}
8033
8034/**---------------------------------------------------------------------------
8035
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308036 \brief __hdd_open() - HDD Open function
Jeff Johnson295189b2012-06-20 16:38:30 -07008037
8038 \param - dev Pointer to net_device structure
8039
8040 \return - 0 for success non-zero for failure
8041
8042 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308043int __hdd_open(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008044{
8045 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8046 hdd_context_t *pHddCtx;
8047 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8048 VOS_STATUS status;
8049 v_BOOL_t in_standby = TRUE;
8050
8051 if (NULL == pAdapter)
8052 {
8053 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05308054 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008055 return -ENODEV;
8056 }
8057
8058 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308059 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
8060 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson295189b2012-06-20 16:38:30 -07008061 if (NULL == pHddCtx)
8062 {
8063 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008064 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008065 return -ENODEV;
8066 }
8067
Arun Kumar Khandavalli9113aee2020-02-26 10:54:02 +05308068 if (test_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags)) {
8069 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: session already opened for the adapter",
8070 __func__);
8071 return 0;
8072 }
8073
Jeff Johnson295189b2012-06-20 16:38:30 -07008074 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8075 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
8076 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008077 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
8078 {
8079 hddLog(VOS_TRACE_LEVEL_INFO, "%s: chip already out of standby",
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05308080 __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008081 in_standby = FALSE;
8082 break;
8083 }
8084 else
8085 {
8086 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8087 pAdapterNode = pNext;
8088 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008089 }
8090
8091 if (TRUE == in_standby)
8092 {
8093 if (VOS_STATUS_SUCCESS != wlan_hdd_exit_lowpower(pHddCtx, pAdapter))
8094 {
8095 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to bring "
8096 "wlan out of power save", __func__);
8097 return -EINVAL;
8098 }
8099 }
Arun Kumar Khandavalli9113aee2020-02-26 10:54:02 +05308100
8101 status = hdd_init_station_mode( pAdapter );
8102 if( VOS_STATUS_SUCCESS != status ) {
8103 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to create session for station mode",
8104 __func__);
8105 return -EINVAL;
8106 }
8107
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008108 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07008109 if (hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
8110 {
8111 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008112 "%s: Enabling Tx Queues", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008113 /* Enable TX queues only when we are connected */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308114 hddLog(VOS_TRACE_LEVEL_INFO, FL("Enabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008115 netif_tx_start_all_queues(dev);
8116 }
8117
8118 return 0;
8119}
8120
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308121/**---------------------------------------------------------------------------
8122
8123 \brief hdd_open() - Wrapper function for __hdd_open to protect it from SSR
8124
8125 This is called in response to ifconfig up
8126
8127 \param - dev Pointer to net_device structure
8128
8129 \return - 0 for success non-zero for failure
8130
8131 --------------------------------------------------------------------------*/
8132int hdd_open(struct net_device *dev)
8133{
8134 int ret;
8135
8136 vos_ssr_protect(__func__);
8137 ret = __hdd_open(dev);
8138 vos_ssr_unprotect(__func__);
8139
8140 return ret;
8141}
8142
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05308143int __hdd_mon_open (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008144{
8145 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308146 hdd_adapter_t *sta_adapter;
8147 hdd_context_t *hdd_ctx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008148
8149 if(pAdapter == NULL) {
8150 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008151 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08008152 return -EINVAL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008153 }
8154
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308155 if (vos_get_concurrency_mode() != VOS_STA_MON)
8156 return 0;
8157
8158 hdd_ctx = WLAN_HDD_GET_CTX(pAdapter);
8159 if (wlan_hdd_validate_context(hdd_ctx))
8160 return -EINVAL;
8161
8162 sta_adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_INFRA_STATION);
8163 if (!sta_adapter) {
8164 hddLog(LOGE, FL("No valid STA interface"));
8165 return -EINVAL;
8166 }
8167
8168 if (!test_bit(DEVICE_IFACE_OPENED, &sta_adapter->event_flags)) {
8169 hddLog(LOGE, FL("STA Interface is not OPENED"));
8170 return -EINVAL;
8171 }
8172
8173 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
8174
Jeff Johnson295189b2012-06-20 16:38:30 -07008175 return 0;
8176}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05308177
8178int hdd_mon_open (struct net_device *dev)
8179{
8180 int ret;
8181
8182 vos_ssr_protect(__func__);
8183 ret = __hdd_mon_open(dev);
8184 vos_ssr_unprotect(__func__);
8185
8186 return ret;
8187}
8188
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308189int __hdd_mon_stop (struct net_device *dev)
8190{
8191 hdd_adapter_t *mon_adapter = WLAN_HDD_GET_PRIV_PTR(dev);
8192 hdd_context_t *hdd_ctx;
8193
8194 if (vos_get_concurrency_mode() != VOS_STA_MON)
8195 return 0;
8196
8197 if(!mon_adapter) {
8198 hddLog(LOGE, FL("HDD adapter is Null"));
8199 return -EINVAL;
8200 }
8201
8202 hdd_ctx = WLAN_HDD_GET_CTX(mon_adapter);
8203 if (wlan_hdd_validate_context(hdd_ctx))
8204 return -EINVAL;
8205
8206 if (!test_bit(DEVICE_IFACE_OPENED, &mon_adapter->event_flags)) {
8207 hddLog(LOGE, FL("NETDEV Interface is not OPENED"));
8208 return -ENODEV;
8209 }
8210
8211 clear_bit(DEVICE_IFACE_OPENED, &mon_adapter->event_flags);
8212 hdd_stop_adapter(hdd_ctx, mon_adapter, VOS_FALSE);
8213
8214 return 0;
8215}
8216
Katya Nigame7b69a82015-04-28 15:24:06 +05308217int hdd_mon_stop(struct net_device *dev)
8218{
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308219 int ret;
8220
8221 vos_ssr_protect(__func__);
8222 ret = __hdd_mon_stop(dev);
8223 vos_ssr_unprotect(__func__);
8224
8225 return ret;
Katya Nigame7b69a82015-04-28 15:24:06 +05308226}
8227
Jeff Johnson295189b2012-06-20 16:38:30 -07008228/**---------------------------------------------------------------------------
8229
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308230 \brief __hdd_stop() - HDD stop function
Jeff Johnson295189b2012-06-20 16:38:30 -07008231
8232 \param - dev Pointer to net_device structure
8233
8234 \return - 0 for success non-zero for failure
8235
8236 --------------------------------------------------------------------------*/
8237
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308238int __hdd_stop (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008239{
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308240 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07008241 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8242 hdd_context_t *pHddCtx;
8243 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8244 VOS_STATUS status;
8245 v_BOOL_t enter_standby = TRUE;
8246
8247 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07008248 if (NULL == pAdapter)
8249 {
8250 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05308251 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008252 return -ENODEV;
8253 }
Sachin Ahuja9b4958f2015-01-15 21:37:00 +05308254 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308255 pAdapter->sessionId, pAdapter->device_mode));
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308256
8257 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8258 ret = wlan_hdd_validate_context(pHddCtx);
8259 if (ret)
Jeff Johnson295189b2012-06-20 16:38:30 -07008260 {
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308261 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07008262 }
8263
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308264 /* Nothing to be done if the interface is not opened */
8265 if (VOS_FALSE == test_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags))
8266 {
8267 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8268 "%s: NETDEV Interface is not OPENED", __func__);
8269 return -ENODEV;
8270 }
8271
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308272 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308273 /*
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05308274 * In STA + Monitor mode concurrency, no point in running
8275 * capture on monitor interface, when STA interface is stopped
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308276 */
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05308277 wlan_hdd_stop_mon(pHddCtx, true);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308278 }
8279
Jeff Johnson295189b2012-06-20 16:38:30 -07008280 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disabling OS Tx queues", __func__);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308281
8282 /* Disable TX on the interface, after this hard_start_xmit() will not
8283 * be called on that interface
8284 */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308285 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008286 netif_tx_disable(pAdapter->dev);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308287
8288 /* Mark the interface status as "down" for outside world */
Jeff Johnson295189b2012-06-20 16:38:30 -07008289 netif_carrier_off(pAdapter->dev);
8290
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308291 /* The interface is marked as down for outside world (aka kernel)
8292 * But the driver is pretty much alive inside. The driver needs to
8293 * tear down the existing connection on the netdev (session)
8294 * cleanup the data pipes and wait until the control plane is stabilized
8295 * for this interface. The call also needs to wait until the above
8296 * mentioned actions are completed before returning to the caller.
8297 * Notice that the hdd_stop_adapter is requested not to close the session
8298 * That is intentional to be able to scan if it is a STA/P2P interface
8299 */
Arun Kumar Khandavalli9113aee2020-02-26 10:54:02 +05308300 hdd_stop_adapter(pHddCtx, pAdapter, VOS_TRUE);
8301 clear_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308302#ifdef FEATURE_WLAN_TDLS
8303 mutex_lock(&pHddCtx->tdls_lock);
8304#endif
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308305 /* DeInit the adapter. This ensures datapath cleanup as well */
c_hpothu002231a2015-02-05 14:58:51 +05308306 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308307#ifdef FEATURE_WLAN_TDLS
8308 mutex_unlock(&pHddCtx->tdls_lock);
8309#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008310 /* SoftAP ifaces should never go in power save mode
8311 making sure same here. */
8312 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07008313 || (WLAN_HDD_P2P_GO == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07008314 )
8315 {
8316 /* SoftAP mode, so return from here */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308317 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8318 "%s: In SAP MODE", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008319 EXIT();
8320 return 0;
8321 }
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308322 /* Find if any iface is up. If any iface is up then can't put device to
8323 * sleep/power save mode
8324 */
Jeff Johnson295189b2012-06-20 16:38:30 -07008325 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8326 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
8327 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008328 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
8329 {
8330 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Still other ifaces are up cannot "
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05308331 "put device to sleep", __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008332 enter_standby = FALSE;
8333 break;
8334 }
8335 else
8336 {
8337 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8338 pAdapterNode = pNext;
8339 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008340 }
8341
8342 if (TRUE == enter_standby)
8343 {
8344 hddLog(VOS_TRACE_LEVEL_INFO, "%s: All Interfaces are Down "
8345 "entering standby", __func__);
8346 if (VOS_STATUS_SUCCESS != wlan_hdd_enter_lowpower(pHddCtx))
8347 {
8348 /*log and return success*/
8349 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to put "
8350 "wlan in power save", __func__);
8351 }
8352 }
Hanumanth Reddy Pothula972e1df2018-06-14 13:33:47 +05308353
Arun Kumar Khandavalli9113aee2020-02-26 10:54:02 +05308354 pAdapter->dev->wireless_handlers = NULL;
8355
Hanumanth Reddy Pothula972e1df2018-06-14 13:33:47 +05308356 /*
8357 * Upon wifi turn off, DUT has to flush the scan results so if
8358 * this is the last cli iface, flush the scan database.
8359 */
8360 if (!hdd_is_cli_iface_up(pHddCtx))
8361 sme_ScanFlushResult(pHddCtx->hHal, 0);
Arun Kumar Khandavalli9113aee2020-02-26 10:54:02 +05308362
Jeff Johnson295189b2012-06-20 16:38:30 -07008363 EXIT();
8364 return 0;
8365}
8366
8367/**---------------------------------------------------------------------------
8368
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308369 \brief hdd_stop() - wrapper_function for __hdd_stop to protect it from SSR
Jeff Johnson295189b2012-06-20 16:38:30 -07008370
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308371 This is called in response to ifconfig down
8372
8373 \param - dev Pointer to net_device structure
8374
8375 \return - 0 for success non-zero for failure
8376-----------------------------------------------------------------------------*/
8377int hdd_stop (struct net_device *dev)
8378{
8379 int ret;
8380
8381 vos_ssr_protect(__func__);
8382 ret = __hdd_stop(dev);
8383 vos_ssr_unprotect(__func__);
8384
8385 return ret;
8386}
8387
8388/**---------------------------------------------------------------------------
8389
8390 \brief __hdd_uninit() - HDD uninit function
Jeff Johnson295189b2012-06-20 16:38:30 -07008391
8392 \param - dev Pointer to net_device structure
8393
8394 \return - void
8395
8396 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308397static void __hdd_uninit (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008398{
8399 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308400 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008401 ENTER();
8402
8403 do
8404 {
8405 if (NULL == pAdapter)
8406 {
8407 hddLog(VOS_TRACE_LEVEL_FATAL,
8408 "%s: NULL pAdapter", __func__);
8409 break;
8410 }
8411
8412 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
8413 {
8414 hddLog(VOS_TRACE_LEVEL_FATAL,
8415 "%s: Invalid magic", __func__);
8416 break;
8417 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308418 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8419 if (NULL == pHddCtx)
Jeff Johnson295189b2012-06-20 16:38:30 -07008420 {
8421 hddLog(VOS_TRACE_LEVEL_FATAL,
8422 "%s: NULL pHddCtx", __func__);
8423 break;
8424 }
8425
8426 if (dev != pAdapter->dev)
8427 {
8428 hddLog(VOS_TRACE_LEVEL_FATAL,
8429 "%s: Invalid device reference", __func__);
8430 /* we haven't validated all cases so let this go for now */
8431 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308432#ifdef FEATURE_WLAN_TDLS
8433 mutex_lock(&pHddCtx->tdls_lock);
8434#endif
c_hpothu002231a2015-02-05 14:58:51 +05308435 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308436#ifdef FEATURE_WLAN_TDLS
8437 mutex_unlock(&pHddCtx->tdls_lock);
8438#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008439
8440 /* after uninit our adapter structure will no longer be valid */
8441 pAdapter->dev = NULL;
8442 pAdapter->magic = 0;
Manjeet Singh47ee8472016-04-11 11:57:18 +05308443 pAdapter->pHddCtx = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008444 } while (0);
8445
8446 EXIT();
8447}
8448
8449/**---------------------------------------------------------------------------
8450
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308451 \brief hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
8452
8453 This is called during the netdev unregister to uninitialize all data
8454associated with the device
8455
8456 \param - dev Pointer to net_device structure
8457
8458 \return - void
8459
8460 --------------------------------------------------------------------------*/
8461static void hdd_uninit (struct net_device *dev)
8462{
8463 vos_ssr_protect(__func__);
8464 __hdd_uninit(dev);
8465 vos_ssr_unprotect(__func__);
8466}
8467
8468/**---------------------------------------------------------------------------
8469
Jeff Johnson295189b2012-06-20 16:38:30 -07008470 \brief hdd_release_firmware() -
8471
8472 This function calls the release firmware API to free the firmware buffer.
8473
8474 \param - pFileName Pointer to the File Name.
8475 pCtx - Pointer to the adapter .
8476
8477
8478 \return - 0 for success, non zero for failure
8479
8480 --------------------------------------------------------------------------*/
8481
8482VOS_STATUS hdd_release_firmware(char *pFileName,v_VOID_t *pCtx)
8483{
8484 VOS_STATUS status = VOS_STATUS_SUCCESS;
8485 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8486 ENTER();
8487
8488
8489 if (!strcmp(WLAN_FW_FILE, pFileName)) {
8490
8491 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"%s: Loaded firmware file is %s",__func__,pFileName);
8492
8493 if(pHddCtx->fw) {
8494 release_firmware(pHddCtx->fw);
8495 pHddCtx->fw = NULL;
8496 }
8497 else
8498 status = VOS_STATUS_E_FAILURE;
8499 }
8500 else if (!strcmp(WLAN_NV_FILE,pFileName)) {
8501 if(pHddCtx->nv) {
8502 release_firmware(pHddCtx->nv);
8503 pHddCtx->nv = NULL;
8504 }
8505 else
8506 status = VOS_STATUS_E_FAILURE;
8507
8508 }
8509
8510 EXIT();
8511 return status;
8512}
8513
8514/**---------------------------------------------------------------------------
8515
8516 \brief hdd_request_firmware() -
8517
8518 This function reads the firmware file using the request firmware
8519 API and returns the the firmware data and the firmware file size.
8520
8521 \param - pfileName - Pointer to the file name.
8522 - pCtx - Pointer to the adapter .
8523 - ppfw_data - Pointer to the pointer of the firmware data.
8524 - pSize - Pointer to the file size.
8525
8526 \return - VOS_STATUS_SUCCESS for success, VOS_STATUS_E_FAILURE for failure
8527
8528 --------------------------------------------------------------------------*/
8529
8530
8531VOS_STATUS hdd_request_firmware(char *pfileName,v_VOID_t *pCtx,v_VOID_t **ppfw_data, v_SIZE_t *pSize)
8532{
8533 int status;
8534 VOS_STATUS retval = VOS_STATUS_SUCCESS;
8535 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8536 ENTER();
8537
8538 if( (!strcmp(WLAN_FW_FILE, pfileName)) ) {
8539
8540 status = request_firmware(&pHddCtx->fw, pfileName, pHddCtx->parent_dev);
8541
8542 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8543 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Firmware %s download failed",
8544 __func__, pfileName);
8545 retval = VOS_STATUS_E_FAILURE;
8546 }
8547
8548 else {
8549 *ppfw_data = (v_VOID_t *)pHddCtx->fw->data;
8550 *pSize = pHddCtx->fw->size;
8551 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Firmware size = %d",
8552 __func__, *pSize);
8553 }
8554 }
8555 else if(!strcmp(WLAN_NV_FILE, pfileName)) {
8556
8557 status = request_firmware(&pHddCtx->nv, pfileName, pHddCtx->parent_dev);
8558
8559 if(status || !pHddCtx->nv || !pHddCtx->nv->data) {
8560 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: nv %s download failed",
8561 __func__, pfileName);
8562 retval = VOS_STATUS_E_FAILURE;
8563 }
8564
8565 else {
8566 *ppfw_data = (v_VOID_t *)pHddCtx->nv->data;
8567 *pSize = pHddCtx->nv->size;
8568 hddLog(VOS_TRACE_LEVEL_INFO, "%s: nv file size = %d",
8569 __func__, *pSize);
8570 }
8571 }
8572
8573 EXIT();
8574 return retval;
8575}
8576/**---------------------------------------------------------------------------
8577 \brief hdd_full_pwr_cbk() - HDD full power callbackfunction
8578
8579 This is the function invoked by SME to inform the result of a full power
8580 request issued by HDD
8581
8582 \param - callbackcontext - Pointer to cookie
8583 status - result of request
8584
8585 \return - None
8586
8587--------------------------------------------------------------------------*/
8588void hdd_full_pwr_cbk(void *callbackContext, eHalStatus status)
8589{
8590 hdd_context_t *pHddCtx = (hdd_context_t*)callbackContext;
8591
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07008592 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"HDD full Power callback status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008593 if(&pHddCtx->full_pwr_comp_var)
8594 {
8595 complete(&pHddCtx->full_pwr_comp_var);
8596 }
8597}
8598
Abhishek Singh00b71972016-01-07 10:51:04 +05308599#ifdef WLAN_FEATURE_RMC
8600static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo)
8601{
8602 int payload_len;
8603 struct sk_buff *skb;
8604 struct nlmsghdr *nlh;
8605 v_U8_t *data;
8606
8607 payload_len = ETH_ALEN;
8608
8609 if (0 == cesium_pid)
8610 {
8611 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: cesium process not registered",
8612 __func__);
8613 return;
8614 }
8615
8616 if ((skb = nlmsg_new(payload_len,GFP_ATOMIC)) == NULL)
8617 {
8618 hddLog(VOS_TRACE_LEVEL_ERROR,
8619 "%s: nlmsg_new() failed for msg size[%d]",
8620 __func__, NLMSG_SPACE(payload_len));
8621 return;
8622 }
8623
8624 nlh = nlmsg_put(skb, cesium_pid, seqNo, 0, payload_len, NLM_F_REQUEST);
8625
8626 if (NULL == nlh)
8627 {
8628 hddLog(VOS_TRACE_LEVEL_ERROR,
8629 "%s: nlmsg_put() failed for msg size[%d]",
8630 __func__, NLMSG_SPACE(payload_len));
8631
8632 kfree_skb(skb);
8633 return;
8634 }
8635
8636 data = nlmsg_data(nlh);
8637 memcpy(data, MacAddr, ETH_ALEN);
8638
8639 if (nlmsg_unicast(cesium_nl_srv_sock, skb, cesium_pid) < 0)
8640 {
8641 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: nlmsg_unicast() failed for msg size[%d]",
8642 __func__, NLMSG_SPACE(payload_len));
8643 }
8644
8645 return;
8646}
8647
8648/**---------------------------------------------------------------------------
8649 \brief hdd_ParseuserParams - return a pointer to the next argument
8650
8651 \return - status
8652
8653--------------------------------------------------------------------------*/
8654static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg)
8655{
8656 tANI_U8 *pVal;
8657
8658 pVal = strchr(pValue, ' ');
8659
8660 if (NULL == pVal)
8661 {
8662 /* no argument remains */
8663 return -EINVAL;
8664 }
8665 else if (SPACE_ASCII_VALUE != *pVal)
8666 {
8667 /* no space after the current argument */
8668 return -EINVAL;
8669 }
8670
8671 pVal++;
8672
8673 /* remove empty spaces */
8674 while ((SPACE_ASCII_VALUE == *pVal) && ('\0' != *pVal))
8675 {
8676 pVal++;
8677 }
8678
8679 /* no argument followed by spaces */
8680 if ('\0' == *pVal)
8681 {
8682 return -EINVAL;
8683 }
8684
8685 *ppArg = pVal;
8686
8687 return 0;
8688}
8689
8690/**----------------------------------------------------------------------------
8691 \brief hdd_ParseIBSSTXFailEventParams - Parse params for SETIBSSTXFAILEVENT
8692
8693 \return - status
8694
8695------------------------------------------------------------------------------*/
8696static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
8697 tANI_U8 *tx_fail_count,
8698 tANI_U16 *pid)
8699{
8700 tANI_U8 *param = NULL;
8701 int ret;
8702
8703 ret = hdd_ParseUserParams(pValue, &param);
8704
8705 if (0 == ret && NULL != param)
8706 {
8707 if (1 != sscanf(param, "%hhu", tx_fail_count))
8708 {
8709 ret = -EINVAL;
8710 goto done;
8711 }
8712 }
8713 else
8714 {
8715 goto done;
8716 }
8717
8718 if (0 == *tx_fail_count)
8719 {
8720 *pid = 0;
8721 goto done;
8722 }
8723
8724 pValue = param;
8725 pValue++;
8726
8727 ret = hdd_ParseUserParams(pValue, &param);
8728
8729 if (0 == ret)
8730 {
8731 if (1 != sscanf(param, "%hu", pid))
8732 {
8733 ret = -EINVAL;
8734 goto done;
8735 }
8736 }
8737 else
8738 {
8739 goto done;
8740 }
8741
8742done:
8743 return ret;
8744}
8745
8746static int hdd_open_cesium_nl_sock()
8747{
8748#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
8749 struct netlink_kernel_cfg cfg = {
8750 .groups = WLAN_NLINK_MCAST_GRP_ID,
8751 .input = NULL
8752 };
8753#endif
8754 int ret = 0;
8755
8756#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
8757 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
8758#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
8759 THIS_MODULE,
8760#endif
8761 &cfg);
8762#else
8763 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
8764 WLAN_NLINK_MCAST_GRP_ID, NULL, NULL, THIS_MODULE);
8765#endif
8766
8767 if (cesium_nl_srv_sock == NULL)
8768 {
8769 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8770 "NLINK: cesium netlink_kernel_create failed");
8771 ret = -ECONNREFUSED;
8772 }
8773
8774 return ret;
8775}
8776
8777static void hdd_close_cesium_nl_sock()
8778{
8779 if (NULL != cesium_nl_srv_sock)
8780 {
8781 netlink_kernel_release(cesium_nl_srv_sock);
8782 cesium_nl_srv_sock = NULL;
8783 }
8784}
8785#endif /* WLAN_FEATURE_RMC */
Jeff Johnson295189b2012-06-20 16:38:30 -07008786/**---------------------------------------------------------------------------
8787
8788 \brief hdd_req_bmps_cbk() - HDD Request BMPS callback function
8789
8790 This is the function invoked by SME to inform the result of BMPS
8791 request issued by HDD
8792
8793 \param - callbackcontext - Pointer to cookie
8794 status - result of request
8795
8796 \return - None
8797
8798--------------------------------------------------------------------------*/
8799void hdd_req_bmps_cbk(void *callbackContext, eHalStatus status)
8800{
8801
8802 struct completion *completion_var = (struct completion*) callbackContext;
8803
Arif Hussain6d2a3322013-11-17 19:50:10 -08008804 hddLog(VOS_TRACE_LEVEL_ERROR, "HDD BMPS request Callback, status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008805 if(completion_var != NULL)
8806 {
8807 complete(completion_var);
8808 }
8809}
8810
8811/**---------------------------------------------------------------------------
8812
8813 \brief hdd_get_cfg_file_size() -
8814
8815 This function reads the configuration file using the request firmware
8816 API and returns the configuration file size.
8817
8818 \param - pCtx - Pointer to the adapter .
8819 - pFileName - Pointer to the file name.
8820 - pBufSize - Pointer to the buffer size.
8821
8822 \return - 0 for success, non zero for failure
8823
8824 --------------------------------------------------------------------------*/
8825
8826VOS_STATUS hdd_get_cfg_file_size(v_VOID_t *pCtx, char *pFileName, v_SIZE_t *pBufSize)
8827{
8828 int status;
8829 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8830
8831 ENTER();
8832
8833 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
8834
8835 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8836 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
8837 status = VOS_STATUS_E_FAILURE;
8838 }
8839 else {
8840 *pBufSize = pHddCtx->fw->size;
8841 hddLog(VOS_TRACE_LEVEL_INFO, "%s: CFG size = %d", __func__, *pBufSize);
8842 release_firmware(pHddCtx->fw);
8843 pHddCtx->fw = NULL;
8844 }
8845
8846 EXIT();
8847 return VOS_STATUS_SUCCESS;
8848}
8849
8850/**---------------------------------------------------------------------------
8851
8852 \brief hdd_read_cfg_file() -
8853
8854 This function reads the configuration file using the request firmware
8855 API and returns the cfg data and the buffer size of the configuration file.
8856
8857 \param - pCtx - Pointer to the adapter .
8858 - pFileName - Pointer to the file name.
8859 - pBuffer - Pointer to the data buffer.
8860 - pBufSize - Pointer to the buffer size.
8861
8862 \return - 0 for success, non zero for failure
8863
8864 --------------------------------------------------------------------------*/
8865
8866VOS_STATUS hdd_read_cfg_file(v_VOID_t *pCtx, char *pFileName,
8867 v_VOID_t *pBuffer, v_SIZE_t *pBufSize)
8868{
8869 int status;
8870 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8871
8872 ENTER();
8873
8874 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
8875
8876 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8877 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
8878 return VOS_STATUS_E_FAILURE;
8879 }
8880 else {
8881 if(*pBufSize != pHddCtx->fw->size) {
8882 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Caller sets invalid CFG "
8883 "file size", __func__);
8884 release_firmware(pHddCtx->fw);
8885 pHddCtx->fw = NULL;
8886 return VOS_STATUS_E_FAILURE;
8887 }
8888 else {
8889 if(pBuffer) {
8890 vos_mem_copy(pBuffer,pHddCtx->fw->data,*pBufSize);
8891 }
8892 release_firmware(pHddCtx->fw);
8893 pHddCtx->fw = NULL;
8894 }
8895 }
8896
8897 EXIT();
8898
8899 return VOS_STATUS_SUCCESS;
8900}
8901
8902/**---------------------------------------------------------------------------
8903
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308904 \brief __hdd_set_mac_address() -
Jeff Johnson295189b2012-06-20 16:38:30 -07008905
8906 This function sets the user specified mac address using
8907 the command ifconfig wlanX hw ether <mac adress>.
8908
8909 \param - dev - Pointer to the net device.
8910 - addr - Pointer to the sockaddr.
8911 \return - 0 for success, non zero for failure
8912
8913 --------------------------------------------------------------------------*/
8914
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308915static int __hdd_set_mac_address(struct net_device *dev, void *addr)
Jeff Johnson295189b2012-06-20 16:38:30 -07008916{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308917 hdd_adapter_t *pAdapter;
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308918 hdd_adapter_t *adapter_temp;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308919 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008920 struct sockaddr *psta_mac_addr = addr;
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308921 int ret = 0, i;
8922 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -07008923
8924 ENTER();
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308925 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8926 if (NULL == pAdapter)
8927 {
8928 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8929 "%s: Adapter is NULL",__func__);
8930 return -EINVAL;
8931 }
8932 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8933 ret = wlan_hdd_validate_context(pHddCtx);
8934 if (0 != ret)
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308935 return ret;
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308936
8937 memcpy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
8938 if(vos_is_macaddr_zero(&mac_addr)) {
8939 hddLog(VOS_TRACE_LEVEL_ERROR, "Zero Mac address");
8940 return -EINVAL;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308941 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008942
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308943 if (vos_is_macaddr_broadcast(&mac_addr)) {
8944 hddLog(VOS_TRACE_LEVEL_ERROR,"MAC is Broadcast");
8945 return -EINVAL;
8946 }
8947
8948 if (vos_is_macaddr_multicast(&mac_addr)) {
8949 hddLog(VOS_TRACE_LEVEL_ERROR, "Multicast Mac address");
8950 return -EINVAL;
8951 }
8952 adapter_temp = hdd_get_adapter_by_macaddr(pHddCtx, mac_addr.bytes);
8953 if (adapter_temp) {
8954 if (!strcmp(adapter_temp->dev->name, dev->name))
8955 return 0;
8956 hddLog(VOS_TRACE_LEVEL_ERROR,
8957 "%s: WLAN Mac Addr: "
8958 MAC_ADDRESS_STR, __func__,
8959 MAC_ADDR_ARRAY(mac_addr.bytes));
8960 return -EINVAL;
8961 }
8962
8963 for (i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++) {
8964 if (!vos_mem_compare(&pAdapter->macAddressCurrent.bytes,
8965 &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], VOS_MAC_ADDR_SIZE)) {
8966 memcpy(&pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], mac_addr.bytes,
8967 VOS_MAC_ADDR_SIZE);
8968 break;
8969 }
8970 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008971 memcpy(&pAdapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008972 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
8973
8974 EXIT();
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308975 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07008976}
8977
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308978/**---------------------------------------------------------------------------
8979
8980 \brief hdd_set_mac_address() -
8981
8982 Wrapper function to protect __hdd_set_mac_address() function from ssr
8983
8984 \param - dev - Pointer to the net device.
8985 - addr - Pointer to the sockaddr.
8986 \return - 0 for success, non zero for failure
8987
8988 --------------------------------------------------------------------------*/
8989static int hdd_set_mac_address(struct net_device *dev, void *addr)
8990{
8991 int ret;
8992
8993 vos_ssr_protect(__func__);
8994 ret = __hdd_set_mac_address(dev, addr);
8995 vos_ssr_unprotect(__func__);
8996
8997 return ret;
8998}
8999
Jeff Johnson295189b2012-06-20 16:38:30 -07009000tANI_U8* wlan_hdd_get_intf_addr(hdd_context_t* pHddCtx)
9001{
9002 int i;
9003 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
9004 {
Abhishek Singheb183782014-02-06 13:37:21 +05309005 if( 0 == ((pHddCtx->cfg_ini->intfAddrMask) & (1 << i)) )
Jeff Johnson295189b2012-06-20 16:38:30 -07009006 break;
9007 }
9008
9009 if( VOS_MAX_CONCURRENCY_PERSONA == i)
9010 return NULL;
9011
9012 pHddCtx->cfg_ini->intfAddrMask |= (1 << i);
9013 return &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0];
9014}
9015
9016void wlan_hdd_release_intf_addr(hdd_context_t* pHddCtx, tANI_U8* releaseAddr)
9017{
9018 int i;
9019 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
9020 {
9021 if ( !memcmp(releaseAddr, &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], 6) )
9022 {
9023 pHddCtx->cfg_ini->intfAddrMask &= ~(1 << i);
9024 break;
9025 }
9026 }
9027 return;
9028}
9029
9030#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
9031 static struct net_device_ops wlan_drv_ops = {
9032 .ndo_open = hdd_open,
9033 .ndo_stop = hdd_stop,
9034 .ndo_uninit = hdd_uninit,
9035 .ndo_start_xmit = hdd_hard_start_xmit,
9036 .ndo_tx_timeout = hdd_tx_timeout,
9037 .ndo_get_stats = hdd_stats,
9038 .ndo_do_ioctl = hdd_ioctl,
9039 .ndo_set_mac_address = hdd_set_mac_address,
9040 .ndo_select_queue = hdd_select_queue,
9041#ifdef WLAN_FEATURE_PACKET_FILTERING
9042#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0))
9043 .ndo_set_rx_mode = hdd_set_multicast_list,
9044#else
9045 .ndo_set_multicast_list = hdd_set_multicast_list,
9046#endif //LINUX_VERSION_CODE
9047#endif
9048 };
Jeff Johnson295189b2012-06-20 16:38:30 -07009049 static struct net_device_ops wlan_mon_drv_ops = {
9050 .ndo_open = hdd_mon_open,
Katya Nigame7b69a82015-04-28 15:24:06 +05309051 .ndo_stop = hdd_mon_stop,
Jeff Johnson295189b2012-06-20 16:38:30 -07009052 .ndo_uninit = hdd_uninit,
9053 .ndo_start_xmit = hdd_mon_hard_start_xmit,
9054 .ndo_tx_timeout = hdd_tx_timeout,
9055 .ndo_get_stats = hdd_stats,
Katya Nigame7b69a82015-04-28 15:24:06 +05309056 .ndo_do_ioctl = hdd_mon_ioctl,
Jeff Johnson295189b2012-06-20 16:38:30 -07009057 .ndo_set_mac_address = hdd_set_mac_address,
9058 };
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +05309059
Jeff Johnson295189b2012-06-20 16:38:30 -07009060#endif
9061
9062void hdd_set_station_ops( struct net_device *pWlanDev )
9063{
9064#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
Jeff Johnson295189b2012-06-20 16:38:30 -07009065 pWlanDev->netdev_ops = &wlan_drv_ops;
9066#else
9067 pWlanDev->open = hdd_open;
9068 pWlanDev->stop = hdd_stop;
9069 pWlanDev->uninit = hdd_uninit;
9070 pWlanDev->hard_start_xmit = NULL;
9071 pWlanDev->tx_timeout = hdd_tx_timeout;
9072 pWlanDev->get_stats = hdd_stats;
9073 pWlanDev->do_ioctl = hdd_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07009074 pWlanDev->set_mac_address = hdd_set_mac_address;
9075#endif
9076}
9077
Katya Nigam1fd24402015-02-16 14:52:19 +05309078void hdd_set_ibss_ops( hdd_adapter_t *pAdapter )
9079{
9080 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
9081 wlan_drv_ops.ndo_start_xmit = hdd_ibss_hard_start_xmit;
9082 #else
9083 pAdapter->dev->hard_start_xmit = hdd_ibss_hard_start_xmit;
9084 #endif
9085}
9086
Jeff Johnsoneed415b2013-01-18 16:11:20 -08009087static hdd_adapter_t* hdd_alloc_station_adapter( hdd_context_t *pHddCtx, tSirMacAddr macAddr, const char* name )
Jeff Johnson295189b2012-06-20 16:38:30 -07009088{
9089 struct net_device *pWlanDev = NULL;
9090 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009091 /*
9092 * cfg80211 initialization and registration....
9093 */
Anand N Sunkadc34abbd2015-07-29 09:52:59 +05309094 pWlanDev = alloc_netdev_mq(sizeof( hdd_adapter_t ), name,
9095#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0))
9096 NET_NAME_UNKNOWN,
9097#endif
9098 ether_setup, NUM_TX_QUEUES);
Jeff Johnson295189b2012-06-20 16:38:30 -07009099 if(pWlanDev != NULL)
9100 {
9101
9102 //Save the pointer to the net_device in the HDD adapter
9103 pAdapter = (hdd_adapter_t*) netdev_priv( pWlanDev );
9104
Jeff Johnson295189b2012-06-20 16:38:30 -07009105 vos_mem_zero( pAdapter, sizeof( hdd_adapter_t ) );
9106
9107 pAdapter->dev = pWlanDev;
9108 pAdapter->pHddCtx = pHddCtx;
9109 pAdapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Agarwal Ashish47d18112014-08-04 19:55:07 +05309110 spin_lock_init(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -07009111
Rajeev79dbe4c2013-10-05 11:03:42 +05309112#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev79dbe4c2013-10-05 11:03:42 +05309113 pAdapter->pBatchScanRsp = NULL;
9114 pAdapter->numScanList = 0;
Rajeev Kumar20140c12013-10-21 19:39:02 -07009115 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08009116 pAdapter->prev_batch_id = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05309117 mutex_init(&pAdapter->hdd_batch_scan_lock);
9118#endif
9119
Jeff Johnson295189b2012-06-20 16:38:30 -07009120 pAdapter->isLinkUpSvcNeeded = FALSE;
9121 pAdapter->higherDtimTransition = eANI_BOOLEAN_TRUE;
9122 //Init the net_device structure
9123 strlcpy(pWlanDev->name, name, IFNAMSIZ);
9124
9125 vos_mem_copy(pWlanDev->dev_addr, (void *)macAddr, sizeof(tSirMacAddr));
9126 vos_mem_copy( pAdapter->macAddressCurrent.bytes, macAddr, sizeof(tSirMacAddr));
9127 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Alok Kumar84458542018-05-14 15:03:08 +05309128
9129 pWlanDev->needed_headroom = LIBRA_HW_NEEDED_HEADROOM;
Jeff Johnson295189b2012-06-20 16:38:30 -07009130
9131 hdd_set_station_ops( pAdapter->dev );
9132
9133 pWlanDev->destructor = free_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009134 pWlanDev->ieee80211_ptr = &pAdapter->wdev ;
9135 pAdapter->wdev.wiphy = pHddCtx->wiphy;
9136 pAdapter->wdev.netdev = pWlanDev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009137 /* set pWlanDev's parent to underlying device */
9138 SET_NETDEV_DEV(pWlanDev, pHddCtx->parent_dev);
Kumar Anand82c009f2014-05-29 00:29:42 -07009139
9140 hdd_wmm_init( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07009141 }
9142
9143 return pAdapter;
9144}
9145
9146VOS_STATUS hdd_register_interface( hdd_adapter_t *pAdapter, tANI_U8 rtnl_lock_held )
9147{
9148 struct net_device *pWlanDev = pAdapter->dev;
9149 //hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
9150 //hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
9151 //eHalStatus halStatus = eHAL_STATUS_SUCCESS;
9152
9153 if( rtnl_lock_held )
9154 {
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -08009155 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
Jeff Johnson295189b2012-06-20 16:38:30 -07009156 if( dev_alloc_name(pWlanDev, pWlanDev->name) < 0 )
9157 {
9158 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:dev_alloc_name",__func__);
9159 return VOS_STATUS_E_FAILURE;
9160 }
9161 }
9162 if (register_netdevice(pWlanDev))
9163 {
9164 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:register_netdev",__func__);
9165 return VOS_STATUS_E_FAILURE;
9166 }
9167 }
9168 else
9169 {
9170 if(register_netdev(pWlanDev))
9171 {
9172 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed:register_netdev",__func__);
9173 return VOS_STATUS_E_FAILURE;
9174 }
9175 }
9176 set_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags);
9177
9178 return VOS_STATUS_SUCCESS;
9179}
9180
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009181static eHalStatus hdd_smeCloseSessionCallback(void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07009182{
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009183 hdd_adapter_t *pAdapter = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07009184
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009185 if (NULL == pAdapter)
9186 {
9187 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: NULL pAdapter", __func__);
9188 return eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07009189 }
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009190
9191 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
9192 {
9193 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Invalid magic", __func__);
9194 return eHAL_STATUS_NOT_INITIALIZED;
9195 }
9196
9197 clear_bit(SME_SESSION_OPENED, &pAdapter->event_flags);
9198
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009199#ifndef WLAN_OPEN_SOURCE
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009200 /* need to make sure all of our scheduled work has completed.
9201 * This callback is called from MC thread context, so it is safe to
9202 * to call below flush workqueue API from here.
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009203 *
9204 * Even though this is called from MC thread context, if there is a faulty
9205 * work item in the system, that can hang this call forever. So flushing
9206 * this global work queue is not safe; and now we make sure that
9207 * individual work queues are stopped correctly. But the cancel work queue
9208 * is a GPL only API, so the proprietary version of the driver would still
9209 * rely on the global work queue flush.
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009210 */
9211 flush_scheduled_work();
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009212#endif
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009213
9214 /* We can be blocked while waiting for scheduled work to be
9215 * flushed, and the adapter structure can potentially be freed, in
9216 * which case the magic will have been reset. So make sure the
9217 * magic is still good, and hence the adapter structure is still
9218 * valid, before signaling completion */
9219 if (WLAN_HDD_ADAPTER_MAGIC == pAdapter->magic)
9220 {
9221 complete(&pAdapter->session_close_comp_var);
9222 }
9223
Jeff Johnson295189b2012-06-20 16:38:30 -07009224 return eHAL_STATUS_SUCCESS;
9225}
Manjeet Singh47ee8472016-04-11 11:57:18 +05309226/**
9227 * hdd_close_tx_queues() - close tx queues
9228 * @hdd_ctx: hdd global context
9229 *
9230 * Return: None
9231 */
9232static void hdd_close_tx_queues(hdd_context_t *hdd_ctx)
9233{
9234 VOS_STATUS status;
9235 hdd_adapter_t *adapter;
9236 hdd_adapter_list_node_t *adapter_node = NULL, *next_adapter = NULL;
9237 /* Not validating hdd_ctx as it's already done by the caller */
9238 ENTER();
9239 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9240 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status) {
9241 adapter = adapter_node->pAdapter;
9242 if (adapter && adapter->dev) {
9243 netif_tx_disable (adapter->dev);
9244 netif_carrier_off(adapter->dev);
9245 }
9246 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
9247 &next_adapter);
9248 adapter_node = next_adapter;
9249 }
9250 EXIT();
9251}
Jeff Johnson295189b2012-06-20 16:38:30 -07009252
9253VOS_STATUS hdd_init_station_mode( hdd_adapter_t *pAdapter )
9254{
9255 struct net_device *pWlanDev = pAdapter->dev;
9256 hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
9257 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
9258 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
9259 VOS_STATUS status = VOS_STATUS_E_FAILURE;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309260 long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07009261
Nirav Shah7e3c8132015-06-22 23:51:42 +05309262 spin_lock_init( &pAdapter->sta_hash_lock);
9263 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
9264
Jeff Johnson295189b2012-06-20 16:38:30 -07009265 INIT_COMPLETION(pAdapter->session_open_comp_var);
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07009266 sme_SetCurrDeviceMode(pHddCtx->hHal, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07009267 //Open a SME session for future operation
9268 halStatus = sme_OpenSession( pHddCtx->hHal, hdd_smeRoamCallback, pAdapter,
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07009269 (tANI_U8 *)&pAdapter->macAddressCurrent, &pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07009270 if ( !HAL_STATUS_SUCCESS( halStatus ) )
9271 {
9272 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009273 "sme_OpenSession() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009274 halStatus, halStatus );
9275 status = VOS_STATUS_E_FAILURE;
9276 goto error_sme_open;
9277 }
9278
9279 //Block on a completion variable. Can't wait forever though.
Vinay Krishna Eranna0fe2e7c2014-04-09 21:32:08 +05309280 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07009281 &pAdapter->session_open_comp_var,
9282 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309283 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07009284 {
9285 hddLog(VOS_TRACE_LEVEL_FATAL,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309286 "Session is not opened within timeout period code %ld", rc );
Jeff Johnson295189b2012-06-20 16:38:30 -07009287 status = VOS_STATUS_E_FAILURE;
9288 goto error_sme_open;
9289 }
9290
9291 // Register wireless extensions
9292 if( eHAL_STATUS_SUCCESS != (halStatus = hdd_register_wext(pWlanDev)))
9293 {
9294 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009295 "hdd_register_wext() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009296 halStatus, halStatus );
9297 status = VOS_STATUS_E_FAILURE;
9298 goto error_register_wext;
9299 }
Katya Nigam1fd24402015-02-16 14:52:19 +05309300
Jeff Johnson295189b2012-06-20 16:38:30 -07009301 //Safe to register the hard_start_xmit function again
Katya Nigam1fd24402015-02-16 14:52:19 +05309302 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
9303 wlan_drv_ops.ndo_start_xmit = hdd_hard_start_xmit;
9304 #else
9305 pWlanDev->hard_start_xmit = hdd_hard_start_xmit;
9306 #endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009307
9308 //Set the Connection State to Not Connected
Abhishek Singhf4669da2014-05-26 15:07:49 +05309309 hddLog(VOS_TRACE_LEVEL_INFO,
9310 "%s: Set HDD connState to eConnectionState_NotConnected",
9311 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009312 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
9313
9314 //Set the default operation channel
9315 pHddStaCtx->conn_info.operationChannel = pHddCtx->cfg_ini->OperatingChannel;
9316
9317 /* Make the default Auth Type as OPEN*/
9318 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
9319
9320 if( VOS_STATUS_SUCCESS != ( status = hdd_init_tx_rx( pAdapter ) ) )
9321 {
9322 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009323 "hdd_init_tx_rx() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009324 status, status );
9325 goto error_init_txrx;
9326 }
9327
9328 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9329
9330 if( VOS_STATUS_SUCCESS != ( status = hdd_wmm_adapter_init( pAdapter ) ) )
9331 {
9332 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009333 "hdd_wmm_adapter_init() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009334 status, status );
9335 goto error_wmm_init;
9336 }
9337
9338 set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9339
9340 return VOS_STATUS_SUCCESS;
9341
9342error_wmm_init:
9343 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9344 hdd_deinit_tx_rx(pAdapter);
9345error_init_txrx:
9346 hdd_UnregisterWext(pWlanDev);
9347error_register_wext:
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009348 if (test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07009349 {
9350 INIT_COMPLETION(pAdapter->session_close_comp_var);
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009351 if (eHAL_STATUS_SUCCESS == sme_CloseSession(pHddCtx->hHal,
Agrawal Ashish5a3522c2016-03-02 15:08:28 +05309352 pAdapter->sessionId, FALSE, VOS_TRUE,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009353 hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07009354 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309355 unsigned long rc;
9356
Jeff Johnson295189b2012-06-20 16:38:30 -07009357 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309358 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07009359 &pAdapter->session_close_comp_var,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009360 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309361 if (rc <= 0)
9362 hddLog(VOS_TRACE_LEVEL_ERROR,
9363 FL("Session is not opened within timeout period code %ld"), rc);
Jeff Johnson295189b2012-06-20 16:38:30 -07009364 }
9365}
9366error_sme_open:
9367 return status;
9368}
9369
Jeff Johnson295189b2012-06-20 16:38:30 -07009370void hdd_cleanup_actionframe( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
9371{
9372 hdd_cfg80211_state_t *cfgState;
9373
9374 cfgState = WLAN_HDD_GET_CFG_STATE_PTR( pAdapter );
9375
9376 if( NULL != cfgState->buf )
9377 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309378 long rc;
Jeff Johnson295189b2012-06-20 16:38:30 -07009379 INIT_COMPLETION(pAdapter->tx_action_cnf_event);
9380 rc = wait_for_completion_interruptible_timeout(
9381 &pAdapter->tx_action_cnf_event,
9382 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309383 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07009384 {
Deepthi Gowri91b3e9c2015-08-25 13:14:58 +05309385 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9386 "%s ERROR: HDD Wait for Action Confirmation Failed!! %ld"
9387 , __func__, rc);
9388
9389 // Inform tx status as FAILURE to upper layer and free cfgState->buf
9390 hdd_sendActionCnf( pAdapter, FALSE );
Jeff Johnson295189b2012-06-20 16:38:30 -07009391 }
9392 }
9393 return;
9394}
Jeff Johnson295189b2012-06-20 16:38:30 -07009395
c_hpothu002231a2015-02-05 14:58:51 +05309396void hdd_deinit_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
Jeff Johnson295189b2012-06-20 16:38:30 -07009397{
9398 ENTER();
9399 switch ( pAdapter->device_mode )
9400 {
Katya Nigam1fd24402015-02-16 14:52:19 +05309401 case WLAN_HDD_IBSS:
9402 {
9403 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9404 {
9405 hdd_ibss_deinit_tx_rx( pAdapter );
9406 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9407 }
9408 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009409 case WLAN_HDD_INFRA_STATION:
9410 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009411 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07009412 {
9413 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9414 {
9415 hdd_deinit_tx_rx( pAdapter );
9416 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9417 }
9418
9419 if(test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
9420 {
9421 hdd_wmm_adapter_close( pAdapter );
9422 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9423 }
9424
Jeff Johnson295189b2012-06-20 16:38:30 -07009425 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009426 break;
9427 }
9428
9429 case WLAN_HDD_SOFTAP:
9430 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009431 {
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05309432
9433 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
9434 {
9435 hdd_wmm_adapter_close( pAdapter );
9436 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9437 }
9438
Jeff Johnson295189b2012-06-20 16:38:30 -07009439 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009440
c_hpothu002231a2015-02-05 14:58:51 +05309441 hdd_unregister_hostapd(pAdapter, rtnl_held);
Agrawal Ashisha0584d42016-09-29 13:03:45 +05309442 /* set con_mode to STA only when no SAP concurrency mode */
9443 if (!(hdd_get_concurrency_mode() & (VOS_SAP | VOS_P2P_GO)))
9444 hdd_set_conparam(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07009445 break;
9446 }
9447
9448 case WLAN_HDD_MONITOR:
9449 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009450 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9451 {
9452 hdd_deinit_tx_rx( pAdapter );
9453 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9454 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009455 break;
9456 }
9457
9458
9459 default:
9460 break;
9461 }
9462
9463 EXIT();
9464}
9465
9466void hdd_cleanup_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
9467{
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08009468 struct net_device *pWlanDev = NULL;
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309469
9470 ENTER();
9471 if (NULL == pAdapter)
9472 {
9473 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9474 "%s: HDD adapter is Null", __func__);
9475 return;
9476 }
9477
9478 pWlanDev = pAdapter->dev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009479
Rajeev79dbe4c2013-10-05 11:03:42 +05309480#ifdef FEATURE_WLAN_BATCH_SCAN
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309481 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
9482 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Rajeev Kumarf999e582014-01-09 17:33:29 -08009483 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309484 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
9485 )
9486 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08009487 if (pAdapter)
Rajeev79dbe4c2013-10-05 11:03:42 +05309488 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08009489 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
9490 {
9491 hdd_deinit_batch_scan(pAdapter);
9492 }
Rajeev79dbe4c2013-10-05 11:03:42 +05309493 }
Rajeev Kumarf999e582014-01-09 17:33:29 -08009494 }
Rajeev79dbe4c2013-10-05 11:03:42 +05309495#endif
9496
Jeff Johnson295189b2012-06-20 16:38:30 -07009497 if(test_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags)) {
9498 if( rtnl_held )
9499 {
9500 unregister_netdevice(pWlanDev);
9501 }
9502 else
9503 {
9504 unregister_netdev(pWlanDev);
9505 }
9506 // note that the pAdapter is no longer valid at this point
9507 // since the memory has been reclaimed
9508 }
9509
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309510 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07009511}
9512
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009513void hdd_set_pwrparams(hdd_context_t *pHddCtx)
9514{
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309515 VOS_STATUS status;
9516 hdd_adapter_t *pAdapter = NULL;
9517 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009518
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309519 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009520
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309521 /*loop through all adapters.*/
9522 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009523 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309524 pAdapter = pAdapterNode->pAdapter;
9525 if ( (WLAN_HDD_INFRA_STATION != pAdapter->device_mode)
9526 && (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009527
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309528 { // we skip this registration for modes other than STA and P2P client modes.
9529 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9530 pAdapterNode = pNext;
9531 continue;
9532 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009533
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309534 //Apply Dynamic DTIM For P2P
9535 //Only if ignoreDynamicDtimInP2pMode is not set in ini
9536 if ((pHddCtx->cfg_ini->enableDynamicDTIM ||
9537 pHddCtx->cfg_ini->enableModulatedDTIM) &&
9538 ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
9539 ((WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) &&
9540 !(pHddCtx->cfg_ini->ignoreDynamicDtimInP2pMode))) &&
9541 (eANI_BOOLEAN_TRUE == pAdapter->higherDtimTransition) &&
9542 (eConnectionState_Associated ==
9543 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState) &&
9544 (pHddCtx->cfg_ini->fIsBmpsEnabled))
9545 {
9546 tSirSetPowerParamsReq powerRequest = { 0 };
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009547
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309548 powerRequest.uIgnoreDTIM = 1;
9549 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
9550
9551 if (pHddCtx->cfg_ini->enableModulatedDTIM)
9552 {
9553 powerRequest.uDTIMPeriod = pHddCtx->cfg_ini->enableModulatedDTIM;
9554 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
9555 }
9556 else
9557 {
9558 powerRequest.uListenInterval = pHddCtx->cfg_ini->enableDynamicDTIM;
9559 }
9560
9561 /* Update ignoreDTIM and ListedInterval in CFG to remain at the DTIM
9562 * specified during Enter/Exit BMPS when LCD off*/
9563 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
9564 NULL, eANI_BOOLEAN_FALSE);
9565 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
9566 NULL, eANI_BOOLEAN_FALSE);
9567
9568 /* switch to the DTIM specified in cfg.ini */
9569 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Abhishek Singh1e390cf2015-10-27 13:45:17 +05309570 "Switch to DTIM %d Listen interval %d",
9571 powerRequest.uDTIMPeriod,
9572 powerRequest.uListenInterval);
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309573 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
9574 break;
9575
9576 }
9577
9578 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9579 pAdapterNode = pNext;
9580 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009581}
9582
9583void hdd_reset_pwrparams(hdd_context_t *pHddCtx)
9584{
9585 /*Switch back to DTIM 1*/
9586 tSirSetPowerParamsReq powerRequest = { 0 };
9587
9588 powerRequest.uIgnoreDTIM = pHddCtx->hdd_actual_ignore_DTIM_value;
9589 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
Yue Mac24062f2013-05-13 17:01:29 -07009590 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009591
9592 /* Update ignoreDTIM and ListedInterval in CFG with default values */
9593 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
9594 NULL, eANI_BOOLEAN_FALSE);
9595 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
9596 NULL, eANI_BOOLEAN_FALSE);
9597
9598 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9599 "Switch to DTIM%d",powerRequest.uListenInterval);
9600 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
9601
9602}
9603
Jeff Johnson295189b2012-06-20 16:38:30 -07009604VOS_STATUS hdd_enable_bmps_imps(hdd_context_t *pHddCtx)
9605{
9606 VOS_STATUS status = VOS_STATUS_SUCCESS;
Sushant Kaushik4928e542014-12-29 15:25:54 +05309607 if (WLAN_HDD_IS_UNLOAD_IN_PROGRESS(pHddCtx))
9608 {
9609 hddLog( LOGE, FL("Wlan Unload in progress"));
9610 return VOS_STATUS_E_PERM;
9611 }
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309612
9613 if (wlan_hdd_check_monitor_state(pHddCtx)) {
9614 hddLog(LOG1, FL("Monitor mode is started, cannot enable BMPS"));
9615 return VOS_STATUS_SUCCESS;
9616 }
9617
Jeff Johnson295189b2012-06-20 16:38:30 -07009618 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
9619 {
9620 sme_EnablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
9621 }
9622
9623 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
9624 {
9625 sme_StartAutoBmpsTimer(pHddCtx->hHal);
9626 }
9627
9628 if (pHddCtx->cfg_ini->fIsImpsEnabled)
9629 {
9630 sme_EnablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
9631 }
9632
9633 return status;
9634}
9635
9636VOS_STATUS hdd_disable_bmps_imps(hdd_context_t *pHddCtx, tANI_U8 session_type)
9637{
9638 hdd_adapter_t *pAdapter = NULL;
9639 eHalStatus halStatus;
9640 VOS_STATUS status = VOS_STATUS_E_INVAL;
9641 v_BOOL_t disableBmps = FALSE;
9642 v_BOOL_t disableImps = FALSE;
9643
9644 switch(session_type)
9645 {
9646 case WLAN_HDD_INFRA_STATION:
9647 case WLAN_HDD_SOFTAP:
Jeff Johnson295189b2012-06-20 16:38:30 -07009648 case WLAN_HDD_P2P_CLIENT:
9649 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009650 //Exit BMPS -> Is Sta/P2P Client is already connected
9651 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
9652 if((NULL != pAdapter)&&
9653 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
9654 {
9655 disableBmps = TRUE;
9656 }
9657
9658 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_CLIENT);
9659 if((NULL != pAdapter)&&
9660 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
9661 {
9662 disableBmps = TRUE;
9663 }
9664
9665 //Exit both Bmps and Imps incase of Go/SAP Mode
9666 if((WLAN_HDD_SOFTAP == session_type) ||
9667 (WLAN_HDD_P2P_GO == session_type))
9668 {
9669 disableBmps = TRUE;
9670 disableImps = TRUE;
9671 }
9672
9673 if(TRUE == disableImps)
9674 {
9675 if (pHddCtx->cfg_ini->fIsImpsEnabled)
9676 {
9677 sme_DisablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
9678 }
9679 }
9680
9681 if(TRUE == disableBmps)
9682 {
9683 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
9684 {
9685 halStatus = sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
9686
9687 if(eHAL_STATUS_SUCCESS != halStatus)
9688 {
9689 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009690 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Disable Power Save", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009691 VOS_ASSERT(0);
9692 return status;
9693 }
9694 }
9695
9696 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
9697 {
9698 halStatus = sme_StopAutoBmpsTimer(pHddCtx->hHal);
9699
9700 if(eHAL_STATUS_SUCCESS != halStatus)
9701 {
9702 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009703 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Stop Auto Bmps Timer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009704 VOS_ASSERT(0);
9705 return status;
9706 }
9707 }
9708 }
9709
9710 if((TRUE == disableBmps) ||
9711 (TRUE == disableImps))
9712 {
9713 /* Now, get the chip into Full Power now */
9714 INIT_COMPLETION(pHddCtx->full_pwr_comp_var);
9715 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_pwr_cbk,
9716 pHddCtx, eSME_FULL_PWR_NEEDED_BY_HDD);
9717
9718 if(halStatus != eHAL_STATUS_SUCCESS)
9719 {
9720 if(halStatus == eHAL_STATUS_PMC_PENDING)
9721 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309722 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07009723 //Block on a completion variable. Can't wait forever though
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309724 ret = wait_for_completion_interruptible_timeout(
9725 &pHddCtx->full_pwr_comp_var,
9726 msecs_to_jiffies(1000));
9727 if (ret <= 0)
9728 {
9729 hddLog(VOS_TRACE_LEVEL_ERROR,
9730 "%s: wait on full_pwr_comp_var failed %ld",
9731 __func__, ret);
9732 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009733 }
9734 else
9735 {
9736 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009737 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Request for Full Power failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009738 VOS_ASSERT(0);
9739 return status;
9740 }
9741 }
9742
9743 status = VOS_STATUS_SUCCESS;
9744 }
9745
9746 break;
9747 }
9748 return status;
9749}
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309750
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309751void hdd_mon_post_msg_cb(void *context)
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309752{
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309753 struct hdd_request *request;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309754
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309755 request = hdd_request_get(context);
9756 if (!request) {
9757 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
9758 return;
9759 }
9760
9761 hdd_request_complete(request);
9762 hdd_request_put(request);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309763}
9764
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309765
Katya Nigame7b69a82015-04-28 15:24:06 +05309766void hdd_init_mon_mode (hdd_adapter_t *pAdapter)
9767 {
9768 hdd_mon_ctx_t *pMonCtx = NULL;
Katya Nigame7b69a82015-04-28 15:24:06 +05309769
Rajeev Kumar Sirasanagandla54447612018-03-06 15:49:56 +05309770 spin_lock_init(&pAdapter->sta_hash_lock);
9771 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
9772
9773 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
Katya Nigame7b69a82015-04-28 15:24:06 +05309774 pMonCtx->state = 0;
9775 pMonCtx->ChannelNo = 1;
9776 pMonCtx->ChannelBW = 20;
Katya Nigamd7d3a1f2015-06-11 14:04:24 +05309777 pMonCtx->crcCheckEnabled = 1;
9778 pMonCtx->typeSubtypeBitmap = 0xFFFF00000000;
9779 pMonCtx->is80211to803ConReq = 1;
Katya Nigame7b69a82015-04-28 15:24:06 +05309780 pMonCtx->numOfMacFilters = 0;
9781 }
9782
Jeff Johnson295189b2012-06-20 16:38:30 -07009783
9784hdd_adapter_t* hdd_open_adapter( hdd_context_t *pHddCtx, tANI_U8 session_type,
Jeff Johnsoneed415b2013-01-18 16:11:20 -08009785 const char *iface_name, tSirMacAddr macAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -07009786 tANI_U8 rtnl_held )
9787{
9788 hdd_adapter_t *pAdapter = NULL;
9789 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
9790 VOS_STATUS status = VOS_STATUS_E_FAILURE;
9791 VOS_STATUS exitbmpsStatus;
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309792 v_CONTEXT_t pVosContext = NULL;
9793
9794 /* No need to check for NULL, reaching this step
9795 * means vos context is initialized
9796 */
9797 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
Jeff Johnson295189b2012-06-20 16:38:30 -07009798
Arif Hussain6d2a3322013-11-17 19:50:10 -08009799 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s iface =%s type = %d",__func__,iface_name,session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009800
Nirav Shah436658f2014-02-28 17:05:45 +05309801 if(macAddr == NULL)
9802 {
9803 /* Not received valid macAddr */
9804 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9805 "%s:Unable to add virtual intf: Not able to get"
9806 "valid mac address",__func__);
9807 return NULL;
9808 }
9809
Jeff Johnson295189b2012-06-20 16:38:30 -07009810 //Disable BMPS incase of Concurrency
9811 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, session_type);
9812
9813 if(VOS_STATUS_E_FAILURE == exitbmpsStatus)
9814 {
9815 //Fail to Exit BMPS
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309816 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Exit BMPS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009817 VOS_ASSERT(0);
9818 return NULL;
9819 }
9820
9821 switch(session_type)
9822 {
9823 case WLAN_HDD_INFRA_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07009824 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009825 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07009826 {
9827 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9828
9829 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309830 {
9831 hddLog(VOS_TRACE_LEVEL_FATAL,
9832 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009833 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309834 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009835
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309836#ifdef FEATURE_WLAN_TDLS
9837 /* A Mutex Lock is introduced while changing/initializing the mode to
9838 * protect the concurrent access for the Adapters by TDLS module.
9839 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05309840 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309841#endif
9842
Jeff Johnsone7245742012-09-05 17:12:55 -07009843 pAdapter->wdev.iftype = (session_type == WLAN_HDD_P2P_CLIENT) ?
9844 NL80211_IFTYPE_P2P_CLIENT:
9845 NL80211_IFTYPE_STATION;
Jeff Johnson295189b2012-06-20 16:38:30 -07009846
Jeff Johnson295189b2012-06-20 16:38:30 -07009847 pAdapter->device_mode = session_type;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309848#ifdef FEATURE_WLAN_TDLS
9849 mutex_unlock(&pHddCtx->tdls_lock);
9850#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05309851
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309852 hdd_initialize_adapter_common(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009853
9854 status = hdd_register_interface( pAdapter, rtnl_held );
9855 if( VOS_STATUS_SUCCESS != status )
9856 {
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05309857#ifdef FEATURE_WLAN_TDLS
9858 mutex_lock(&pHddCtx->tdls_lock);
9859#endif
c_hpothu002231a2015-02-05 14:58:51 +05309860 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05309861#ifdef FEATURE_WLAN_TDLS
9862 mutex_unlock(&pHddCtx->tdls_lock);
9863#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009864 goto err_free_netdev;
9865 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309866
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05309867 // Workqueue which gets scheduled in IPv4 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309868 vos_init_work(&pAdapter->ipv4NotifierWorkQueue, hdd_ipv4_notifier_work_queue);
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05309869
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309870#ifdef WLAN_NS_OFFLOAD
9871 // Workqueue which gets scheduled in IPv6 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309872 vos_init_work(&pAdapter->ipv6NotifierWorkQueue, hdd_ipv6_notifier_work_queue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309873#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009874 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309875 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009876 netif_tx_disable(pAdapter->dev);
9877 //netif_tx_disable(pWlanDev);
9878 netif_carrier_off(pAdapter->dev);
9879
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309880 if (WLAN_HDD_P2P_CLIENT == session_type ||
9881 WLAN_HDD_P2P_DEVICE == session_type)
9882 {
9883 /* Initialize the work queue to defer the
9884 * back to back RoC request */
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309885 vos_init_delayed_work(&pAdapter->roc_work,
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309886 hdd_p2p_roc_work_queue);
9887 }
9888
Jeff Johnson295189b2012-06-20 16:38:30 -07009889 break;
9890 }
9891
Jeff Johnson295189b2012-06-20 16:38:30 -07009892 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009893 case WLAN_HDD_SOFTAP:
9894 {
9895 pAdapter = hdd_wlan_create_ap_dev( pHddCtx, macAddr, (tANI_U8 *)iface_name );
9896 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309897 {
9898 hddLog(VOS_TRACE_LEVEL_FATAL,
9899 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009900 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309901 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009902
Jeff Johnson295189b2012-06-20 16:38:30 -07009903 pAdapter->wdev.iftype = (session_type == WLAN_HDD_SOFTAP) ?
9904 NL80211_IFTYPE_AP:
9905 NL80211_IFTYPE_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07009906 pAdapter->device_mode = session_type;
9907
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309908 hdd_initialize_adapter_common(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009909
Nirav Shah7e3c8132015-06-22 23:51:42 +05309910 status = hdd_sta_id_hash_attach(pAdapter);
9911 if (VOS_STATUS_SUCCESS != status)
9912 {
9913 hddLog(VOS_TRACE_LEVEL_FATAL,
9914 FL("failed to attach hash for session %d"), session_type);
Nirav Shah7e3c8132015-06-22 23:51:42 +05309915 goto err_free_netdev;
9916 }
9917
Jeff Johnson295189b2012-06-20 16:38:30 -07009918 status = hdd_register_hostapd( pAdapter, rtnl_held );
9919 if( VOS_STATUS_SUCCESS != status )
9920 {
c_hpothu002231a2015-02-05 14:58:51 +05309921 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Jeff Johnson295189b2012-06-20 16:38:30 -07009922 goto err_free_netdev;
9923 }
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309924 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009925 netif_tx_disable(pAdapter->dev);
9926 netif_carrier_off(pAdapter->dev);
9927
9928 hdd_set_conparam( 1 );
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309929
Hanumanth Reddy Pothulab4537b82018-03-02 12:20:38 +05309930 // Workqueue which gets scheduled in IPv4 notification callback.
9931 vos_init_work(&pAdapter->ipv4NotifierWorkQueue,
9932 hdd_ipv4_notifier_work_queue);
9933
9934#ifdef WLAN_NS_OFFLOAD
9935 // Workqueue which gets scheduled in IPv6 notification callback.
9936 vos_init_work(&pAdapter->ipv6NotifierWorkQueue,
9937 hdd_ipv6_notifier_work_queue);
9938#endif
9939
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309940 if (WLAN_HDD_P2P_GO == session_type)
9941 {
9942 /* Initialize the work queue to
9943 * defer the back to back RoC request */
9944 INIT_DELAYED_WORK(&pAdapter->roc_work,
9945 hdd_p2p_roc_work_queue);
9946 }
Bhargav Shahd0715912015-10-01 18:17:37 +05309947
Jeff Johnson295189b2012-06-20 16:38:30 -07009948 break;
9949 }
9950 case WLAN_HDD_MONITOR:
9951 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009952 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9953 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309954 {
9955 hddLog(VOS_TRACE_LEVEL_FATAL,
9956 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009957 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309958 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009959
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309960 pAdapter->device_mode = session_type;
9961 pAdapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
9962
Katya Nigame7b69a82015-04-28 15:24:06 +05309963 // Register wireless extensions
9964 if( VOS_STATUS_SUCCESS != (status = hdd_register_wext(pAdapter->dev)))
9965 {
9966 hddLog(VOS_TRACE_LEVEL_FATAL,
9967 "hdd_register_wext() failed with status code %08d [x%08x]",
9968 status, status );
9969 status = VOS_STATUS_E_FAILURE;
9970 }
9971
Jeff Johnson295189b2012-06-20 16:38:30 -07009972#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29)
9973 pAdapter->dev->netdev_ops = &wlan_mon_drv_ops;
9974#else
9975 pAdapter->dev->open = hdd_mon_open;
9976 pAdapter->dev->hard_start_xmit = hdd_mon_hard_start_xmit;
Katya Nigame7b69a82015-04-28 15:24:06 +05309977 pAdapter->dev->stop = hdd_mon_stop;
9978 pAdapter->dev->do_ioctl = hdd_mon_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07009979#endif
Katya Nigame7b69a82015-04-28 15:24:06 +05309980 hdd_init_mon_mode( pAdapter );
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309981 hdd_initialize_adapter_common(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009982 hdd_init_tx_rx( pAdapter );
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309983
9984 if (VOS_MONITOR_MODE != hdd_get_conparam())
9985 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
9986
Jeff Johnson295189b2012-06-20 16:38:30 -07009987 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309988 status = hdd_register_interface( pAdapter, rtnl_held );
Katya Nigame7b69a82015-04-28 15:24:06 +05309989 //Stop the Interface TX queue.
9990 netif_tx_disable(pAdapter->dev);
9991 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07009992 }
9993 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07009994 case WLAN_HDD_FTM:
9995 {
9996 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9997
9998 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309999 {
10000 hddLog(VOS_TRACE_LEVEL_FATAL,
10001 FL("failed to allocate adapter for session %d"), session_type);
10002 return NULL;
10003 }
10004
Jeff Johnson295189b2012-06-20 16:38:30 -070010005 /* Assign NL80211_IFTYPE_STATION as interface type to resolve Kernel Warning
10006 * message while loading driver in FTM mode. */
10007 pAdapter->wdev.iftype = NL80211_IFTYPE_STATION;
10008 pAdapter->device_mode = session_type;
10009 status = hdd_register_interface( pAdapter, rtnl_held );
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +053010010
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053010011 hdd_initialize_adapter_common(pAdapter);
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +053010012 hdd_init_tx_rx( pAdapter );
10013
10014 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +053010015 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +053010016 netif_tx_disable(pAdapter->dev);
10017 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070010018 }
10019 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070010020 default:
10021 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010022 hddLog(VOS_TRACE_LEVEL_FATAL,"%s Invalid session type %d",
10023 __func__, session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -070010024 VOS_ASSERT(0);
10025 return NULL;
10026 }
10027 }
10028
Jeff Johnson295189b2012-06-20 16:38:30 -070010029 if( VOS_STATUS_SUCCESS == status )
10030 {
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053010031 //Add it to the hdd's session list.
Jeff Johnson295189b2012-06-20 16:38:30 -070010032 pHddAdapterNode = vos_mem_malloc( sizeof( hdd_adapter_list_node_t ) );
10033 if( NULL == pHddAdapterNode )
10034 {
10035 status = VOS_STATUS_E_NOMEM;
10036 }
10037 else
10038 {
10039 pHddAdapterNode->pAdapter = pAdapter;
10040 status = hdd_add_adapter_back ( pHddCtx,
10041 pHddAdapterNode );
10042 }
10043 }
10044
10045 if( VOS_STATUS_SUCCESS != status )
10046 {
10047 if( NULL != pAdapter )
10048 {
10049 hdd_cleanup_adapter( pHddCtx, pAdapter, rtnl_held );
10050 pAdapter = NULL;
10051 }
10052 if( NULL != pHddAdapterNode )
10053 {
10054 vos_mem_free( pHddAdapterNode );
10055 }
10056
10057 goto resume_bmps;
10058 }
10059
10060 if(VOS_STATUS_SUCCESS == status)
10061 {
10062 wlan_hdd_set_concurrency_mode(pHddCtx, session_type);
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -070010063 //Initialize the WoWL service
10064 if(!hdd_init_wowl(pAdapter))
10065 {
10066 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_init_wowl failed",__func__);
10067 goto err_free_netdev;
10068 }
Manjeet Singh3ed79242017-01-11 19:04:32 +053010069 //Initialize the TSF capture data
10070 wlan_hdd_tsf_init(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010071 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010072 return pAdapter;
10073
10074err_free_netdev:
Jeff Johnson295189b2012-06-20 16:38:30 -070010075 wlan_hdd_release_intf_addr( pHddCtx,
10076 pAdapter->macAddressCurrent.bytes );
Hanumanth Reddy Pothulaab8e1942018-05-24 18:10:39 +053010077 free_netdev(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070010078
10079resume_bmps:
10080 //If bmps disabled enable it
10081 if(VOS_STATUS_SUCCESS == exitbmpsStatus)
10082 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010083 if (pHddCtx->hdd_wlan_suspended)
10084 {
10085 hdd_set_pwrparams(pHddCtx);
10086 }
10087 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070010088 }
10089 return NULL;
10090}
10091
10092VOS_STATUS hdd_close_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
10093 tANI_U8 rtnl_held )
10094{
10095 hdd_adapter_list_node_t *pAdapterNode, *pCurrent, *pNext;
10096 VOS_STATUS status;
10097
10098 status = hdd_get_front_adapter ( pHddCtx, &pCurrent );
10099 if( VOS_STATUS_SUCCESS != status )
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010100 {
10101 hddLog(VOS_TRACE_LEVEL_WARN,"%s: adapter list empty %d",
10102 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070010103 return status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010104 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010105
10106 while ( pCurrent->pAdapter != pAdapter )
10107 {
10108 status = hdd_get_next_adapter ( pHddCtx, pCurrent, &pNext );
10109 if( VOS_STATUS_SUCCESS != status )
10110 break;
10111
10112 pCurrent = pNext;
10113 }
10114 pAdapterNode = pCurrent;
10115 if( VOS_STATUS_SUCCESS == status )
10116 {
10117 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
10118 hdd_cleanup_adapter( pHddCtx, pAdapterNode->pAdapter, rtnl_held );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010119
10120#ifdef FEATURE_WLAN_TDLS
10121
10122 /* A Mutex Lock is introduced while changing/initializing the mode to
10123 * protect the concurrent access for the Adapters by TDLS module.
10124 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +053010125 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010126#endif
10127
Jeff Johnson295189b2012-06-20 16:38:30 -070010128 hdd_remove_adapter( pHddCtx, pAdapterNode );
10129 vos_mem_free( pAdapterNode );
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080010130 pAdapterNode = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010131
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010132#ifdef FEATURE_WLAN_TDLS
10133 mutex_unlock(&pHddCtx->tdls_lock);
10134#endif
10135
Jeff Johnson295189b2012-06-20 16:38:30 -070010136
10137 /* If there is a single session of STA/P2P client, re-enable BMPS */
Agarwal Ashish51325b52014-06-16 16:50:49 +053010138 if ((!vos_concurrent_open_sessions_running()) &&
10139 ((pHddCtx->no_of_open_sessions[VOS_STA_MODE] >= 1) ||
10140 (pHddCtx->no_of_open_sessions[VOS_P2P_CLIENT_MODE] >= 1)))
Jeff Johnson295189b2012-06-20 16:38:30 -070010141 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010142 if (pHddCtx->hdd_wlan_suspended)
10143 {
10144 hdd_set_pwrparams(pHddCtx);
10145 }
10146 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070010147 }
10148
10149 return VOS_STATUS_SUCCESS;
10150 }
10151
10152 return VOS_STATUS_E_FAILURE;
10153}
10154
10155VOS_STATUS hdd_close_all_adapters( hdd_context_t *pHddCtx )
10156{
10157 hdd_adapter_list_node_t *pHddAdapterNode;
10158 VOS_STATUS status;
10159
10160 ENTER();
10161
10162 do
10163 {
10164 status = hdd_remove_front_adapter( pHddCtx, &pHddAdapterNode );
10165 if( pHddAdapterNode && VOS_STATUS_SUCCESS == status )
10166 {
10167 hdd_cleanup_adapter( pHddCtx, pHddAdapterNode->pAdapter, FALSE );
10168 vos_mem_free( pHddAdapterNode );
10169 }
10170 }while( NULL != pHddAdapterNode && VOS_STATUS_E_EMPTY != status );
10171
10172 EXIT();
10173
10174 return VOS_STATUS_SUCCESS;
10175}
10176
10177void wlan_hdd_reset_prob_rspies(hdd_adapter_t* pHostapdAdapter)
10178{
10179 v_U8_t addIE[1] = {0};
10180
10181 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10182 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,(tANI_U8*)addIE, 0, NULL,
10183 eANI_BOOLEAN_FALSE) )
10184 {
10185 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010186 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010187 }
10188
10189 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10190 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
10191 eANI_BOOLEAN_FALSE) )
10192 {
10193 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010194 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010195 }
10196
10197 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10198 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
10199 eANI_BOOLEAN_FALSE) )
10200 {
10201 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010202 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010203 }
10204}
10205
Anurag Chouhan83026002016-12-13 22:46:21 +053010206VOS_STATUS hdd_cleanup_ap_events(hdd_adapter_t *adapter)
10207{
10208#ifdef DHCP_SERVER_OFFLOAD
10209 vos_event_destroy(&adapter->dhcp_status.vos_event);
10210#endif
Anurag Chouhan0b29de02016-12-16 13:18:40 +053010211#ifdef MDNS_OFFLOAD
10212 vos_event_destroy(&adapter->mdns_status.vos_event);
10213#endif
Anurag Chouhan83026002016-12-13 22:46:21 +053010214 return VOS_STATUS_SUCCESS;
10215}
10216
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010217int wlan_hdd_stop_mon(hdd_context_t *hdd_ctx, bool wait)
10218{
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010219 hdd_adapter_t *adapter;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010220 hdd_mon_ctx_t *mon_ctx;
10221 void (*func_ptr)(void *context) = NULL;
10222 int ret = 0;
10223 void *cookie = NULL;
10224 struct hdd_request *request;
10225 static const struct hdd_request_params params = {
10226 .priv_size = 0,
10227 .timeout_ms = MON_MODE_MSG_TIMEOUT,
10228 };
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010229
10230 adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_MONITOR);
10231 if (!adapter) {
10232 hddLog(LOGE, FL("Invalid STA + MON mode"));
10233 return -EINVAL;
10234 }
10235
10236 mon_ctx = WLAN_HDD_GET_MONITOR_CTX_PTR(adapter);
10237 if (!mon_ctx)
10238 return 0;
10239
10240 if (mon_ctx->state != MON_MODE_START)
10241 return 0;
10242
10243 mon_ctx->state = MON_MODE_STOP;
10244 if (wait) {
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010245 func_ptr = hdd_mon_post_msg_cb;
10246 request = hdd_request_alloc(&params);
10247 if (!request) {
10248 hddLog(VOS_TRACE_LEVEL_ERROR,
10249 FL("Request allocation failure"));
10250 return -ENOMEM;
10251 }
10252 cookie = hdd_request_cookie(request);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010253 }
10254
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010255 /*
10256 * If func_ptr is NULL, on receiving WDI_MON_START_RSP or
10257 * WDI_MON_STOP_RSP hdd_mon_post_msg_cb() won't be invoked
10258 * and so uninitialized cookie won't be accessed.
10259 */
10260 if (VOS_STATUS_SUCCESS != wlan_hdd_mon_postMsg(cookie,
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010261 mon_ctx,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010262 func_ptr)) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010263 hddLog(LOGE, FL("failed to stop MON MODE"));
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010264 ret = -EINVAL;
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010265 }
10266
10267 if (!wait)
10268 goto bmps_roaming;
10269
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010270 if (!ret)
10271 ret = hdd_request_wait_for_response(request);
10272 hdd_request_put(request);
10273 if (ret) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010274 hddLog(LOGE,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010275 FL("timeout on stop monitor mode completion %d"), ret);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010276 return -EINVAL;
10277 }
10278
10279bmps_roaming:
10280 hddLog(LOG1, FL("Enable BMPS"));
10281 hdd_enable_bmps_imps(hdd_ctx);
10282 hdd_restore_roaming(hdd_ctx);
10283
10284 return 0;
10285}
10286
10287bool wlan_hdd_check_monitor_state(hdd_context_t *hdd_ctx)
10288{
10289 hdd_adapter_t *mon_adapter;
10290 hdd_mon_ctx_t *mon_ctx;
10291
10292 if (hdd_ctx->concurrency_mode != VOS_STA_MON)
10293 return false;
10294
10295 mon_adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_MONITOR);
10296 if (!mon_adapter) {
10297 hddLog(LOGE, FL("Invalid concurrency mode"));
10298 return false;
10299 }
10300
10301 mon_ctx = WLAN_HDD_GET_MONITOR_CTX_PTR(mon_adapter);
10302 if (mon_ctx->state == MON_MODE_START)
10303 return true;
10304
10305 return false;
10306}
10307
10308int wlan_hdd_check_and_stop_mon(hdd_adapter_t *sta_adapter, bool wait)
10309{
10310 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(sta_adapter);
10311
10312 if ((sta_adapter->device_mode != WLAN_HDD_INFRA_STATION) ||
10313 !wlan_hdd_check_monitor_state(hdd_ctx))
10314 return 0;
10315
10316 if (wlan_hdd_stop_mon(hdd_ctx, wait))
10317 return -EINVAL;
10318
10319 return 0;
10320}
10321
10322void hdd_disable_roaming(hdd_context_t *hdd_ctx)
10323{
10324 if (!hdd_ctx)
10325 return;
10326
10327 if (!hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled) {
10328 hdd_ctx->roaming_ini_original = CFG_LFR_FEATURE_ENABLED_MIN;
10329 return;
10330 }
10331
10332 hddLog(LOG1, FL("Disable driver and firmware roaming"));
10333
10334 hdd_ctx->roaming_ini_original =
10335 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled;
10336
10337 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled =
10338 CFG_LFR_FEATURE_ENABLED_MIN;
10339
10340 sme_UpdateIsFastRoamIniFeatureEnabled(hdd_ctx->hHal,
10341 CFG_LFR_FEATURE_ENABLED_MIN);
10342}
10343
10344void hdd_restore_roaming(hdd_context_t *hdd_ctx)
10345{
10346 if (!hdd_ctx->roaming_ini_original)
10347 return;
10348
10349 hddLog(LOG1, FL("Enable driver and firmware roaming"));
10350
10351 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled =
10352 CFG_LFR_FEATURE_ENABLED_MAX;
10353
10354 hdd_ctx->roaming_ini_original = CFG_LFR_FEATURE_ENABLED_MIN;
10355
10356 sme_UpdateIsFastRoamIniFeatureEnabled(hdd_ctx->hHal,
10357 CFG_LFR_FEATURE_ENABLED_MAX);
10358}
Anurag Chouhan83026002016-12-13 22:46:21 +053010359
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010360VOS_STATUS hdd_stop_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
10361 const v_BOOL_t bCloseSession )
Jeff Johnson295189b2012-06-20 16:38:30 -070010362{
10363 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
10364 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010365 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010366 union iwreq_data wrqu;
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010367 v_U8_t retry = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010368 long ret;
Nirav Shah7e3c8132015-06-22 23:51:42 +053010369 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -070010370
Anand N Sunkad26d71b92014-12-24 18:08:22 +053010371 if (pHddCtx->isLogpInProgress) {
10372 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
10373 "%s:LOGP in Progress. Ignore!!!",__func__);
10374 return VOS_STATUS_E_FAILURE;
10375 }
10376
Jeff Johnson295189b2012-06-20 16:38:30 -070010377 ENTER();
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010378
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010379 pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -070010380 switch(pAdapter->device_mode)
10381 {
Nirav Shah0cf4d892015-11-05 16:27:27 +053010382 case WLAN_HDD_IBSS:
10383 if ( VOS_TRUE == bCloseSession )
10384 {
10385 status = hdd_sta_id_hash_detach(pAdapter);
10386 if (status != VOS_STATUS_SUCCESS)
10387 hddLog(VOS_TRACE_LEVEL_ERROR,
10388 FL("sta id hash detach failed"));
10389 }
10390
Jeff Johnson295189b2012-06-20 16:38:30 -070010391 case WLAN_HDD_INFRA_STATION:
10392 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -070010393 case WLAN_HDD_P2P_DEVICE:
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010394 {
10395 hdd_station_ctx_t *pstation = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Mahesh A Saptasagare4d05d42015-07-02 16:17:20 +053010396#ifdef FEATURE_WLAN_TDLS
10397 mutex_lock(&pHddCtx->tdls_lock);
10398 wlan_hdd_tdls_exit(pAdapter, TRUE);
10399 mutex_unlock(&pHddCtx->tdls_lock);
10400#endif
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010401 if(hdd_connIsConnected(pstation) ||
10402 (pstation->conn_info.connState == eConnectionState_Connecting))
Jeff Johnson295189b2012-06-20 16:38:30 -070010403 {
10404 if (pWextState->roamProfile.BSSType == eCSR_BSS_TYPE_START_IBSS)
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010405 {
10406 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Jeff Johnson295189b2012-06-20 16:38:30 -070010407 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
10408 pAdapter->sessionId,
10409 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010410 /* Success implies disconnect command got queued up successfully
10411 * Or cmd not queued as scan for SSID is in progress
10412 */
10413 if((eHAL_STATUS_SUCCESS == halStatus) ||
10414 (eHAL_STATUS_CMD_NOT_QUEUED == halStatus))
10415 {
10416 ret = wait_for_completion_timeout(
10417 &pAdapter->disconnect_comp_var,
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010418 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010419 if (ret <= 0 &&
10420 (eHAL_STATUS_CMD_NOT_QUEUED != halStatus))
10421 {
10422 hddLog(VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010423 "%s: wait on disconnect_comp_var failed %ld",
10424 __func__, ret);
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010425 }
10426 }
10427 else
10428 {
10429 hddLog(LOGE, "%s: failed to post disconnect event to SME",
10430 __func__);
10431 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010432 }
10433 else
10434 {
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010435 wlan_hdd_disconnect(pAdapter, eCSR_DISCONNECT_REASON_DEAUTH);
Jeff Johnson295189b2012-06-20 16:38:30 -070010436 }
10437 memset(&wrqu, '\0', sizeof(wrqu));
10438 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
10439 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
10440 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
10441 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010442 else if(pstation->conn_info.connState ==
10443 eConnectionState_Disconnecting)
10444 {
10445 ret = wait_for_completion_interruptible_timeout(
10446 &pAdapter->disconnect_comp_var,
10447 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
10448 if (ret <= 0)
10449 {
10450 hddLog(VOS_TRACE_LEVEL_ERROR,
10451 FL("wait on disconnect_comp_var failed %ld"), ret);
10452 }
10453 }
Sachin Ahuja27dd2402016-08-01 20:30:31 +053010454 if(pScanInfo != NULL && pHddCtx->scan_info.mScanPending)
Jeff Johnson295189b2012-06-20 16:38:30 -070010455 {
Mahesh A Saptasagar0b61dcc2016-02-15 14:23:38 +053010456 wlan_hdd_scan_abort(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010457 }
Abhishek Singh3ac179b2015-09-21 10:01:34 +053010458 if ((pAdapter->device_mode != WLAN_HDD_INFRA_STATION) &&
10459 (pAdapter->device_mode != WLAN_HDD_IBSS))
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010460 {
10461 while (pAdapter->is_roc_inprogress)
10462 {
10463 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10464 "%s: ROC in progress for session %d!!!",
10465 __func__, pAdapter->sessionId);
10466 // waiting for ROC to expire
10467 msleep(500);
10468 /* In GO present case , if retry exceeds 3,
10469 it means something went wrong. */
10470 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION )
10471 {
10472 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10473 "%s: ROC completion is not received.!!!", __func__);
Deepthi Gowri70498252015-01-20 15:56:45 +053010474 if (eHAL_STATUS_SUCCESS !=
10475 sme_CancelRemainOnChannel( WLAN_HDD_GET_HAL_CTX( pAdapter),
10476 pAdapter->sessionId ))
10477 {
10478 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10479 FL("Failed to Cancel Remain on Channel"));
10480 }
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010481 wait_for_completion_interruptible_timeout(
10482 &pAdapter->cancel_rem_on_chan_var,
10483 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
10484 break;
10485 }
10486 }
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010487 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010488 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +053010489#ifdef WLAN_NS_OFFLOAD
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010490 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +053010491#endif
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010492
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010493 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010494
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010495 /* It is possible that the caller of this function does not
10496 * wish to close the session
10497 */
10498 if (VOS_TRUE == bCloseSession &&
10499 test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -070010500 {
10501 INIT_COMPLETION(pAdapter->session_close_comp_var);
10502 if (eHAL_STATUS_SUCCESS ==
Agrawal Ashish5a3522c2016-03-02 15:08:28 +053010503 sme_CloseSession(pHddCtx->hHal, pAdapter->sessionId, FALSE,
10504 VOS_FALSE, hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -070010505 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010506 unsigned long ret;
10507
Jeff Johnson295189b2012-06-20 16:38:30 -070010508 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010509 ret = wait_for_completion_timeout(
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010510 &pAdapter->session_close_comp_var,
10511 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010512 if ( 0 >= ret)
10513 {
10514 hddLog(LOGE, "%s: failure waiting for session_close_comp_var %ld",
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010515 __func__, ret);
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010516 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010517 }
10518 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010519 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010520 break;
10521
10522 case WLAN_HDD_SOFTAP:
Abhishek Singh3dc4c972019-05-09 11:04:24 +053010523 /* Delete all associated STAs before stopping AP */
10524 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10525 hdd_del_all_sta(pAdapter);
10526 /* Fall through */
Jeff Johnson295189b2012-06-20 16:38:30 -070010527 case WLAN_HDD_P2P_GO:
Abhishek Singh3dc4c972019-05-09 11:04:24 +053010528
Nirav Shah0cf4d892015-11-05 16:27:27 +053010529 if ( VOS_TRUE == bCloseSession )
10530 {
10531 status = hdd_sta_id_hash_detach(pAdapter);
10532 if (status != VOS_STATUS_SUCCESS)
10533 hddLog(VOS_TRACE_LEVEL_ERROR,
10534 FL("sta id hash detach failed"));
10535 }
10536
Jeff Johnson295189b2012-06-20 16:38:30 -070010537 //Any softap specific cleanup here...
Anurag Chouhan83026002016-12-13 22:46:21 +053010538 hdd_cleanup_ap_events(pAdapter);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010539 if (pAdapter->device_mode == WLAN_HDD_P2P_GO) {
10540 while (pAdapter->is_roc_inprogress) {
10541 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10542 "%s: ROC in progress for session %d!!!",
10543 __func__, pAdapter->sessionId);
10544 msleep(500);
10545 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION ) {
10546 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10547 "%s: ROC completion is not received.!!!", __func__);
10548 WLANSAP_CancelRemainOnChannel(
10549 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
10550 wait_for_completion_interruptible_timeout(
10551 &pAdapter->cancel_rem_on_chan_var,
10552 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
10553 break;
10554 }
10555 }
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +053010556
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010557 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010558 }
Agrawal Ashish17ef5082016-10-17 18:33:21 +053010559#ifdef SAP_AUTH_OFFLOAD
10560 if (pHddCtx->cfg_ini->enable_sap_auth_offload)
10561 hdd_set_sap_auth_offload(pAdapter, FALSE);
10562#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070010563 mutex_lock(&pHddCtx->sap_lock);
10564 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10565 {
10566 VOS_STATUS status;
10567 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hanumanth Reddy Pothula74ba68c2018-06-22 17:52:09 +053010568 hdd_hostapd_state_t *pHostapdState =
10569 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010570
Hanumanth Reddy Pothula74ba68c2018-06-22 17:52:09 +053010571 vos_event_reset(&pHostapdState->vosEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -070010572 //Stop Bss.
10573 status = WLANSAP_StopBss(pHddCtx->pvosContext);
10574 if (VOS_IS_STATUS_SUCCESS(status))
10575 {
Jeff Johnson295189b2012-06-20 16:38:30 -070010576 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
10577
10578 if (!VOS_IS_STATUS_SUCCESS(status))
10579 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010580 hddLog(LOGE, "%s: failure waiting for WLANSAP_StopBss %d",
10581 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070010582 }
10583 }
10584 else
10585 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010586 hddLog(LOGE, "%s: failure in WLANSAP_StopBss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010587 }
10588 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
Agarwal Ashish51325b52014-06-16 16:50:49 +053010589 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -070010590
10591 if (eHAL_STATUS_FAILURE ==
10592 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
10593 0, NULL, eANI_BOOLEAN_FALSE))
10594 {
10595 hddLog(LOGE,
10596 "%s: Failed to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010597 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010598 }
10599
10600 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pAdapter))->hHal,
10601 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
10602 eANI_BOOLEAN_FALSE) )
10603 {
10604 hddLog(LOGE,
10605 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
10606 }
10607
10608 // Reset WNI_CFG_PROBE_RSP Flags
10609 wlan_hdd_reset_prob_rspies(pAdapter);
10610 kfree(pAdapter->sessionCtx.ap.beacon);
10611 pAdapter->sessionCtx.ap.beacon = NULL;
10612 }
10613 mutex_unlock(&pHddCtx->sap_lock);
Hanumanth Reddy Pothulab4537b82018-03-02 12:20:38 +053010614
10615#ifdef WLAN_NS_OFFLOAD
10616 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
10617#endif
10618 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
10619
Jeff Johnson295189b2012-06-20 16:38:30 -070010620 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -070010621
Jeff Johnson295189b2012-06-20 16:38:30 -070010622 case WLAN_HDD_MONITOR:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010623 if (VOS_MONITOR_MODE != hdd_get_conparam())
10624 wlan_hdd_stop_mon(pHddCtx, true);
10625 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -070010626
Jeff Johnson295189b2012-06-20 16:38:30 -070010627 default:
10628 break;
10629 }
10630
10631 EXIT();
10632 return VOS_STATUS_SUCCESS;
10633}
10634
Kapil Gupta137ef892016-12-13 19:38:00 +053010635/**
10636 * wlan_hdd_restart_sap() - to restart SAP in driver internally
10637 * @ap_adapter: - Pointer to SAP hdd_adapter_t structure
10638 *
10639 * wlan_hdd_restart_sap first delete SAP and do cleanup.
10640 * After that WLANSAP_StartBss start re-start process of SAP.
10641 *
10642 * Return: None
10643 */
10644static void wlan_hdd_restart_sap(hdd_adapter_t *ap_adapter)
10645{
10646 hdd_ap_ctx_t *pHddApCtx;
10647 hdd_hostapd_state_t *pHostapdState;
10648 VOS_STATUS vos_status;
10649 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(ap_adapter);
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010650#ifdef USE_CFG80211_DEL_STA_V2
Kapil Gupta137ef892016-12-13 19:38:00 +053010651 struct station_del_parameters delStaParams;
10652#endif
10653 tsap_Config_t *pConfig;
10654
10655 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10656 pConfig = &pHddApCtx->sapConfig;
10657
10658 mutex_lock(&pHddCtx->sap_lock);
10659 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010660#ifdef USE_CFG80211_DEL_STA_V2
Kapil Gupta137ef892016-12-13 19:38:00 +053010661 delStaParams.mac = NULL;
10662 delStaParams.subtype = SIR_MAC_MGMT_DEAUTH >> 4;
10663 delStaParams.reason_code = eCsrForcedDeauthSta;
10664 wlan_hdd_cfg80211_del_station(ap_adapter->wdev.wiphy, ap_adapter->dev,
10665 &delStaParams);
10666#else
10667 wlan_hdd_cfg80211_del_station(ap_adapter->wdev.wiphy, ap_adapter->dev,
10668 NULL);
10669#endif
10670 hdd_cleanup_actionframe(pHddCtx, ap_adapter);
10671
10672 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10673 vos_event_reset(&pHostapdState->vosEvent);
10674
10675 if (VOS_STATUS_SUCCESS == WLANSAP_StopBss(pHddCtx->pvosContext)) {
10676 vos_status = vos_wait_single_event(&pHostapdState->vosEvent,
10677 10000);
10678 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10679 hddLog(LOGE, FL("SAP Stop Failed"));
10680 goto end;
10681 }
10682 }
10683 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
10684 wlan_hdd_decr_active_session(pHddCtx, ap_adapter->device_mode);
10685 hddLog(LOG1, FL("SAP Stop Success"));
10686
10687 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
10688 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
10689 goto end;
10690 }
10691
Hanumanth Reddy Pothula74ba68c2018-06-22 17:52:09 +053010692 vos_event_reset(&pHostapdState->vosEvent);
Kapil Gupta137ef892016-12-13 19:38:00 +053010693 if (WLANSAP_StartBss(pHddCtx->pvosContext, hdd_hostapd_SAPEventCB,
10694 pConfig, (v_PVOID_t)ap_adapter->dev) != VOS_STATUS_SUCCESS) {
10695 hddLog(LOGE, FL("SAP Start Bss fail"));
10696 goto end;
10697 }
10698
10699 hddLog(LOG1, FL("Waiting for SAP to start"));
10700 vos_status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
10701 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10702 hddLog(LOGE, FL("SAP Start failed"));
10703 goto end;
10704 }
10705 hddLog(LOG1, FL("SAP Start Success"));
10706 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
10707 wlan_hdd_incr_active_session(pHddCtx, ap_adapter->device_mode);
10708 pHostapdState->bCommit = TRUE;
Anurag Chouhanb2951ae2017-03-12 13:41:35 +053010709 if (!VOS_IS_STATUS_SUCCESS(hdd_dhcp_mdns_offload(ap_adapter))) {
10710 hddLog(VOS_TRACE_LEVEL_ERROR, FL("DHCP/MDNS offload Failed!!"));
10711 vos_event_reset(&pHostapdState->vosEvent);
10712 if (VOS_STATUS_SUCCESS == WLANSAP_StopBss(pHddCtx->pvosContext)) {
10713 vos_status = vos_wait_single_event(&pHostapdState->vosEvent,
10714 10000);
10715 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10716 hddLog(LOGE, FL("SAP Stop Failed"));
10717 goto end;
10718 }
10719 }
10720 }
Kapil Gupta137ef892016-12-13 19:38:00 +053010721 }
10722end:
10723 mutex_unlock(&pHddCtx->sap_lock);
10724 return;
10725}
10726
10727/**
10728 * __hdd_sap_restart_handle() - to handle restarting of SAP
10729 * @work: name of the work
10730 *
10731 * Purpose of this function is to trigger sap start. this function
10732 * will be called from workqueue.
10733 *
10734 * Return: void.
10735 */
10736static void __hdd_sap_restart_handle(struct work_struct *work)
10737{
10738 hdd_adapter_t *sap_adapter;
10739 hdd_context_t *hdd_ctx = container_of(work,
10740 hdd_context_t,
10741 sap_start_work);
10742 if (0 != wlan_hdd_validate_context(hdd_ctx)) {
10743 vos_ssr_unprotect(__func__);
10744 return;
10745 }
10746 sap_adapter = hdd_get_adapter(hdd_ctx,
10747 WLAN_HDD_SOFTAP);
10748 if (sap_adapter == NULL) {
10749 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10750 FL("sap_adapter is NULL"));
10751 vos_ssr_unprotect(__func__);
10752 return;
10753 }
10754
10755 if (hdd_ctx->is_ch_avoid_in_progress) {
10756 sap_adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
10757 wlan_hdd_restart_sap(sap_adapter);
10758 hdd_change_ch_avoidance_status(hdd_ctx, false);
10759 }
Agrawal Ashish574b3e62017-02-09 18:58:34 +053010760 if (hdd_ctx->cfg_ini->enable_sap_auth_offload)
10761 wlan_hdd_restart_sap(sap_adapter);
Kapil Gupta137ef892016-12-13 19:38:00 +053010762}
10763
10764/**
10765 * hdd_sap_restart_handle() - to handle restarting of SAP
10766 * @work: name of the work
10767 *
10768 * Purpose of this function is to trigger sap start. this function
10769 * will be called from workqueue.
10770 *
10771 * Return: void.
10772 */
10773static void hdd_sap_restart_handle(struct work_struct *work)
10774{
10775 vos_ssr_protect(__func__);
10776 __hdd_sap_restart_handle(work);
10777 vos_ssr_unprotect(__func__);
10778}
10779
10780
Abhishek Singh78c691f2017-11-30 13:48:44 +053010781/**
10782 * __hdd_force_scc_with_ecsa_handle() - to handle force scc using ecsa
10783 * @work: name of the work
10784 *
10785 * Purpose of this function is to force SCC using ECSA. This function
10786 * will be called from workqueue.
10787 *
10788 * Return: void.
10789 */
10790static void
10791__hdd_force_scc_with_ecsa_handle(struct work_struct *work)
10792{
10793 hdd_adapter_t *sap_adapter;
10794 hdd_station_ctx_t *sta_ctx;
10795 hdd_adapter_t *sta_adapter;
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010796 ptSapContext sap_ctx = NULL;
10797 v_CONTEXT_t vos_ctx;
10798 tANI_U8 target_channel;
10799 tsap_Config_t *sap_config;
10800 bool sta_sap_scc_on_dfs_chan;
10801 eNVChannelEnabledType chan_state;
Abhishek Singh78c691f2017-11-30 13:48:44 +053010802 hdd_context_t *hdd_ctx = container_of(to_delayed_work(work),
10803 hdd_context_t,
10804 ecsa_chan_change_work);
10805
10806 if (wlan_hdd_validate_context(hdd_ctx))
10807 return;
10808
10809 sap_adapter = hdd_get_adapter(hdd_ctx,
10810 WLAN_HDD_SOFTAP);
10811 if (!sap_adapter) {
10812 hddLog(LOGE, FL("sap_adapter is NULL"));
10813 return;
10814 }
10815
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010816 vos_ctx = hdd_ctx->pvosContext;
10817 if (!vos_ctx) {
10818 hddLog(LOGE, FL("vos_ctx is NULL"));
10819 return;
10820 }
10821
10822 sap_ctx = VOS_GET_SAP_CB(vos_ctx);
10823 if (!sap_ctx) {
10824 hddLog(LOGE, FL("sap_ctx is NULL"));
10825 return;
10826 }
10827
10828 sap_config = &sap_adapter->sessionCtx.ap.sapConfig;
10829
10830 sta_sap_scc_on_dfs_chan = hdd_is_sta_sap_scc_allowed_on_dfs_chan(hdd_ctx);
10831
Abhishek Singh78c691f2017-11-30 13:48:44 +053010832 sta_adapter = hdd_get_adapter(hdd_ctx,
10833 WLAN_HDD_INFRA_STATION);
10834 if (!sta_adapter) {
10835 hddLog(LOGE, FL("sta_adapter is NULL"));
10836 return;
10837 }
Abhishek Singh78c691f2017-11-30 13:48:44 +053010838
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010839 if (wlansap_chk_n_set_chan_change_in_progress(sap_ctx))
Abhishek Singh78c691f2017-11-30 13:48:44 +053010840 return;
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010841 INIT_COMPLETION(sap_ctx->ecsa_info.chan_switch_comp);
10842
10843 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(sta_adapter);
10844 if (sta_ctx->conn_info.connState != eConnectionState_Associated) {
10845 if (sta_ctx->conn_info.connState == eConnectionState_NotConnected) {
10846 chan_state = vos_nv_getChannelEnabledState(sap_ctx->channel);
10847 hddLog(LOG1, FL("sta not in connected state %d, sta_sap_scc_on_dfs_chan %d, chan_state %d"),
10848 sta_ctx->conn_info.connState, sta_sap_scc_on_dfs_chan,
10849 chan_state);
10850 if (sta_sap_scc_on_dfs_chan &&
10851 (chan_state == NV_CHANNEL_DFS)) {
10852 hddLog(LOGE, FL("Switch SAP to user configured channel"));
10853 target_channel = sap_config->user_config_channel;
10854 goto switch_channel;
10855 }
10856 }
10857 goto abort;
Abhishek Singh78c691f2017-11-30 13:48:44 +053010858 }
10859
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010860 target_channel = sta_ctx->conn_info.operationChannel;
10861switch_channel:
10862 hddLog(LOGE, FL("Switch SAP to %d channel"),
10863 target_channel);
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010864 if (!wlansap_set_channel_change(vos_ctx, target_channel, true))
10865 return;
10866
10867abort:
10868 wlansap_reset_chan_change_in_progress(sap_ctx);
10869 complete(&sap_ctx->ecsa_info.chan_switch_comp);
Abhishek Singh78c691f2017-11-30 13:48:44 +053010870}
10871
10872/**
10873 * hdd_force_scc_with_ecsa_handle() - to handle force scc using ecsa
10874 * @work: name of the work
10875 *
10876 * Purpose of this function is to force SCC using ECSA. This function
10877 * will be called from workqueue.
10878 *
10879 * Return: void.
10880 */
10881static void
10882hdd_force_scc_with_ecsa_handle(struct work_struct *work)
10883{
10884 vos_ssr_protect(__func__);
10885 __hdd_force_scc_with_ecsa_handle(work);
10886 vos_ssr_unprotect(__func__);
10887}
10888
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010889int hdd_wait_for_ecsa_complete(hdd_context_t *hdd_ctx)
10890{
10891 int ret;
10892 ptSapContext sap_ctx = NULL;
10893 v_CONTEXT_t vos_ctx;
10894
10895 vos_ctx = hdd_ctx->pvosContext;
10896 if (!vos_ctx) {
10897 hddLog(LOGE, FL("vos_ctx is NULL"));
10898 return 0;
10899 }
10900
10901 sap_ctx = VOS_GET_SAP_CB(vos_ctx);
10902 if (!sap_ctx) {
10903 hddLog(LOG1, FL("sap_ctx is NULL"));
10904 return 0;
10905 }
10906 if(!sap_ctx->isSapSessionOpen) {
10907 hddLog(LOG1, FL("sap session not opened, SAP in state %d"),
10908 sap_ctx->sapsMachine);
10909 return 0;
10910 }
10911
10912 if (!wlansap_get_change_in_progress(sap_ctx)) {
10913 hddLog(LOG1, FL("channel switch not in progress"));
10914 return 0;
10915 }
10916 ret = wait_for_completion_timeout(&sap_ctx->ecsa_info.chan_switch_comp,
10917 msecs_to_jiffies(HDD_SAP_CHAN_CNG_WAIT_TIME));
10918 if (!ret)
10919 {
10920 hddLog(LOGE, FL("Timeout waiting for SAP channel switch"));
10921 return ret;
10922 }
10923
10924 return 0;
10925}
10926
10927
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010928/**
10929 * hdd_is_sta_sap_scc_allowed_on_dfs_chan() - check if sta+sap scc allowed on
10930 * dfs chan
10931 * @hdd_ctx: pointer to hdd context
10932 *
10933 * This function used to check if sta+sap scc allowed on DFS channel.
10934 *
10935 * Return: None
10936 */
10937bool hdd_is_sta_sap_scc_allowed_on_dfs_chan(hdd_context_t *hdd_ctx)
10938{
10939 if (hdd_ctx->cfg_ini->force_scc_with_ecsa &&
10940 hdd_ctx->cfg_ini->sta_sap_scc_on_dfs_chan)
10941 return true;
10942 else
10943 return false;
10944}
10945
Jeff Johnson295189b2012-06-20 16:38:30 -070010946VOS_STATUS hdd_stop_all_adapters( hdd_context_t *pHddCtx )
10947{
10948 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10949 VOS_STATUS status;
10950 hdd_adapter_t *pAdapter;
10951
10952 ENTER();
10953
10954 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10955
10956 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10957 {
10958 pAdapter = pAdapterNode->pAdapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070010959
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010960 hdd_stop_adapter( pHddCtx, pAdapter, VOS_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -070010961
10962 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10963 pAdapterNode = pNext;
10964 }
10965
10966 EXIT();
10967
10968 return VOS_STATUS_SUCCESS;
10969}
10970
Rajeev Kumarf999e582014-01-09 17:33:29 -080010971
10972#ifdef FEATURE_WLAN_BATCH_SCAN
10973/**---------------------------------------------------------------------------
10974
10975 \brief hdd_deinit_batch_scan () - This function cleans up batch scan data
10976 structures
10977
10978 \param - pAdapter Pointer to HDD adapter
10979
10980 \return - None
10981
10982 --------------------------------------------------------------------------*/
10983void hdd_deinit_batch_scan(hdd_adapter_t *pAdapter)
10984{
10985 tHddBatchScanRsp *pNode;
10986 tHddBatchScanRsp *pPrev;
10987
Siddharth Bhalb3e9b792014-02-24 15:14:16 +053010988 if (NULL == pAdapter)
Rajeev Kumarf999e582014-01-09 17:33:29 -080010989 {
Siddharth Bhalb3e9b792014-02-24 15:14:16 +053010990 hddLog(VOS_TRACE_LEVEL_ERROR,
10991 "%s: Adapter context is Null", __func__);
10992 return;
10993 }
10994
10995 pNode = pAdapter->pBatchScanRsp;
10996 while (pNode)
10997 {
10998 pPrev = pNode;
10999 pNode = pNode->pNext;
11000 vos_mem_free((v_VOID_t * )pPrev);
Rajeev Kumarf999e582014-01-09 17:33:29 -080011001 }
11002
11003 pAdapter->pBatchScanRsp = NULL;
11004 pAdapter->numScanList = 0;
11005 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
11006 pAdapter->prev_batch_id = 0;
11007
11008 return;
11009}
11010#endif
11011
11012
Jeff Johnson295189b2012-06-20 16:38:30 -070011013VOS_STATUS hdd_reset_all_adapters( hdd_context_t *pHddCtx )
11014{
11015 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11016 VOS_STATUS status;
11017 hdd_adapter_t *pAdapter;
11018
11019 ENTER();
11020
11021 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11022
11023 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11024 {
11025 pAdapter = pAdapterNode->pAdapter;
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +053011026 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -070011027 netif_tx_disable(pAdapter->dev);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011028
11029 if (pHddCtx->cfg_ini->sap_internal_restart &&
11030 pAdapter->device_mode == WLAN_HDD_SOFTAP) {
11031 hddLog(LOG1, FL("driver supports sap restart"));
11032 vos_flush_work(&pHddCtx->sap_start_work);
11033 hdd_sap_indicate_disconnect_for_sta(pAdapter);
11034 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +053011035 hdd_softap_deinit_tx_rx(pAdapter, true);
11036 hdd_sap_destroy_timers(pAdapter);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011037 } else {
11038 netif_carrier_off(pAdapter->dev);
11039 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011040
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070011041 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011042
11043 if (pAdapter->device_mode == WLAN_HDD_MONITOR)
11044 pAdapter->sessionCtx.monitor.state = MON_MODE_STOP;
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070011045
Jeff Johnson295189b2012-06-20 16:38:30 -070011046 hdd_deinit_tx_rx(pAdapter);
Agarwal Ashish6267caa2014-08-06 19:16:21 +053011047
Katya Nigam1fd24402015-02-16 14:52:19 +053011048 if(pAdapter->device_mode == WLAN_HDD_IBSS )
11049 hdd_ibss_deinit_tx_rx(pAdapter);
11050
Nirav Shah7e3c8132015-06-22 23:51:42 +053011051 status = hdd_sta_id_hash_detach(pAdapter);
11052 if (status != VOS_STATUS_SUCCESS)
11053 hddLog(VOS_TRACE_LEVEL_ERROR,
11054 FL("sta id hash detach failed for session id %d"),
11055 pAdapter->sessionId);
11056
Agarwal Ashish6267caa2014-08-06 19:16:21 +053011057 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
11058
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +053011059 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
11060 {
11061 hdd_wmm_adapter_close( pAdapter );
11062 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
11063 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011064
Siddharth Bhal2db319d2014-12-03 12:37:18 +053011065 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
11066 {
11067 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
11068 }
11069
Rajeev Kumarf999e582014-01-09 17:33:29 -080011070#ifdef FEATURE_WLAN_BATCH_SCAN
11071 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
11072 {
11073 hdd_deinit_batch_scan(pAdapter);
11074 }
11075#endif
11076
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +053011077#ifdef FEATURE_WLAN_TDLS
11078 mutex_lock(&pHddCtx->tdls_lock);
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +053011079 wlan_hdd_tdls_exit(pAdapter, TRUE);
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +053011080 mutex_unlock(&pHddCtx->tdls_lock);
11081#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070011082 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11083 pAdapterNode = pNext;
11084 }
11085
11086 EXIT();
11087
11088 return VOS_STATUS_SUCCESS;
11089}
11090
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011091/**
Abhishek Singh5a597e62016-12-05 15:16:30 +053011092 * hdd_get_bss_entry() - Get the bss entry matching the chan, bssid and ssid
11093 * @wiphy: wiphy
11094 * @channel: channel of the BSS to find
11095 * @bssid: bssid of the BSS to find
11096 * @ssid: ssid of the BSS to find
11097 * @ssid_len: ssid len of of the BSS to find
11098 *
11099 * The API is a wrapper to get bss from kernel matching the chan,
11100 * bssid and ssid
11101 *
11102 * Return: Void
11103 */
11104#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
11105 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
11106
11107struct cfg80211_bss* hdd_get_bss_entry(struct wiphy *wiphy,
11108 struct ieee80211_channel *channel,
11109 const u8 *bssid,
11110 const u8 *ssid, size_t ssid_len)
11111{
11112 return cfg80211_get_bss(wiphy, channel, bssid,
11113 ssid, ssid_len,
11114 WLAN_CAPABILITY_ESS,
11115 WLAN_CAPABILITY_ESS);
11116}
11117#else
11118struct cfg80211_bss* hdd_get_bss_entry(struct wiphy *wiphy,
11119 struct ieee80211_channel *channel,
11120 const u8 *bssid,
11121 const u8 *ssid, size_t ssid_len)
11122{
11123 return cfg80211_get_bss(wiphy, channel, bssid,
11124 ssid, ssid_len,
11125 IEEE80211_BSS_TYPE_ESS,
11126 IEEE80211_PRIVACY_ANY);
11127}
11128#endif
11129
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011130#if defined(CFG80211_CONNECT_BSS) || \
11131 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
11132
11133#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) || \
11134 defined (CFG80211_CONNECT_TIMEOUT_REASON_CODE)
11135/**
11136 * hdd_connect_bss() - helper function to send connection status to supplicant
11137 * @dev: network device
11138 * @bssid: bssid to which we want to associate
11139 * @bss: information about connected bss
11140 * @req_ie: Request Information Element
11141 * @req_ie_len: len of the req IE
11142 * @resp_ie: Response IE
11143 * @resp_ie_len: len of ht response IE
11144 * @status: status
11145 * @gfp: Kernel Flag
11146 *
11147 * This is a helper function to send connection status to supplicant
11148 * and gets invoked from wrapper API
11149 *
11150 * Return: Void
11151 */
11152static void hdd_connect_bss(struct net_device *dev,
11153 const u8 *bssid,
11154 struct cfg80211_bss *bss,
11155 const u8 *req_ie,
11156 size_t req_ie_len,
11157 const u8 *resp_ie,
11158 size_t resp_ie_len,
11159 u16 status,
11160 gfp_t gfp)
11161{
11162 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
11163 resp_ie, resp_ie_len, status, gfp, NL80211_TIMEOUT_UNSPECIFIED);
11164}
11165#else
11166/**
11167 * hdd_connect_bss() - helper function to send connection status to supplicant
11168 * @dev: network device
11169 * @bssid: bssid to which we want to associate
11170 * @bss: information about connected bss
11171 * @req_ie: Request Information Element
11172 * @req_ie_len: len of the req IE
11173 * @resp_ie: Response IE
11174 * @resp_ie_len: len of ht response IE
11175 * @status: status
11176 * @gfp: Kernel Flag
11177 *
11178 * This is a helper function to send connection status to supplicant
11179 * and gets invoked from wrapper API
11180 *
11181 * Return: Void
11182 */
11183static void hdd_connect_bss(struct net_device *dev,
11184 const u8 *bssid,
11185 struct cfg80211_bss *bss,
11186 const u8 *req_ie,
11187 size_t req_ie_len,
11188 const u8 *resp_ie,
11189 size_t resp_ie_len,
11190 u16 status,
11191 gfp_t gfp)
11192{
11193 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
11194 resp_ie, resp_ie_len, status, gfp);
11195}
11196#endif
11197
Abhishek Singh5a597e62016-12-05 15:16:30 +053011198/**
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011199 * hdd_connect_result() - API to send connection status to supplicant
11200 * @dev: network device
11201 * @bssid: bssid to which we want to associate
11202 * @roam_info: information about connected bss
11203 * @req_ie: Request Information Element
11204 * @req_ie_len: len of the req IE
11205 * @resp_ie: Response IE
11206 * @resp_ie_len: len of ht response IE
11207 * @status: status
11208 * @gfp: Kernel Flag
11209 *
11210 * The API is a wrapper to send connection status to supplicant
11211 *
11212 * Return: Void
11213 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011214void hdd_connect_result(struct net_device *dev,
11215 const u8 *bssid,
11216 tCsrRoamInfo *roam_info,
11217 const u8 *req_ie,
11218 size_t req_ie_len,
11219 const u8 *resp_ie,
11220 size_t resp_ie_len,
11221 u16 status,
11222 gfp_t gfp)
11223{
11224 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
11225 struct cfg80211_bss *bss = NULL;
11226
11227 if (WLAN_STATUS_SUCCESS == status) {
11228 struct ieee80211_channel *chan;
11229 int freq;
11230 int chan_no = roam_info->pBssDesc->channelId;;
11231
11232 if (chan_no <= 14)
11233 freq = ieee80211_channel_to_frequency(chan_no,
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011234 HDD_NL80211_BAND_2GHZ);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011235 else
11236 freq = ieee80211_channel_to_frequency(chan_no,
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011237 HDD_NL80211_BAND_5GHZ);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011238
11239 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
Abhishek Singh5a597e62016-12-05 15:16:30 +053011240 bss = hdd_get_bss_entry(padapter->wdev.wiphy,
11241 chan, bssid,
11242 roam_info->u.pConnectedProfile->SSID.ssId,
11243 roam_info->u.pConnectedProfile->SSID.length);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011244 }
11245
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011246 hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie, resp_ie_len,
11247 status, gfp);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011248}
11249#else
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011250/**
11251 * hdd_connect_result() - API to send connection status to supplicant
11252 * @dev: network device
11253 * @bssid: bssid to which we want to associate
11254 * @roam_info: information about connected bss
11255 * @req_ie: Request Information Element
11256 * @req_ie_len: len of the req IE
11257 * @resp_ie: Response IE
11258 * @resp_ie_len: len of ht response IE
11259 * @status: status
11260 * @gfp: Kernel Flag
11261 *
11262 * The API is a wrapper to send connection status to supplicant
11263 *
11264 * Return: Void
11265 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011266void hdd_connect_result(struct net_device *dev,
11267 const u8 *bssid,
11268 tCsrRoamInfo *roam_info,
11269 const u8 *req_ie,
11270 size_t req_ie_len,
11271 const u8 * resp_ie,
11272 size_t resp_ie_len,
11273 u16 status,
11274 gfp_t gfp)
11275{
11276 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
11277 resp_ie, resp_ie_len, status, gfp);
11278}
11279#endif
11280
Jeff Johnson295189b2012-06-20 16:38:30 -070011281VOS_STATUS hdd_start_all_adapters( hdd_context_t *pHddCtx )
11282{
11283 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11284 VOS_STATUS status;
11285 hdd_adapter_t *pAdapter;
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011286 eConnectionState connState;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011287 v_CONTEXT_t pVosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011288
11289 ENTER();
11290
11291 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11292
11293 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11294 {
11295 pAdapter = pAdapterNode->pAdapter;
11296
Kumar Anand82c009f2014-05-29 00:29:42 -070011297 hdd_wmm_init( pAdapter );
11298
Jeff Johnson295189b2012-06-20 16:38:30 -070011299 switch(pAdapter->device_mode)
11300 {
11301 case WLAN_HDD_INFRA_STATION:
11302 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -070011303 case WLAN_HDD_P2P_DEVICE:
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011304
11305 connState = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState;
11306
Jeff Johnson295189b2012-06-20 16:38:30 -070011307 hdd_init_station_mode(pAdapter);
11308 /* Open the gates for HDD to receive Wext commands */
11309 pAdapter->isLinkUpSvcNeeded = FALSE;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070011310 pHddCtx->scan_info.mScanPending = FALSE;
11311 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070011312
11313 //Trigger the initial scan
Mukul Sharmae74e42c2015-08-06 23:55:49 +053011314 if (!pHddCtx->isLogpInProgress)
11315 hdd_wlan_initial_scan(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070011316
11317 //Indicate disconnect event to supplicant if associated previously
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011318 if (eConnectionState_Associated == connState ||
11319 eConnectionState_IbssConnected == connState )
Jeff Johnson295189b2012-06-20 16:38:30 -070011320 {
11321 union iwreq_data wrqu;
11322 memset(&wrqu, '\0', sizeof(wrqu));
11323 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
11324 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
11325 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070011326 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070011327
Jeff Johnson295189b2012-06-20 16:38:30 -070011328 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagar9ff4bcc2016-06-01 17:17:50 +053011329 wlan_hdd_cfg80211_indicate_disconnect(pAdapter->dev, false,
Mahesh A Saptasagarb5a15142016-05-25 11:27:43 +053011330 WLAN_REASON_UNSPECIFIED);
Jeff Johnson295189b2012-06-20 16:38:30 -070011331 }
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011332 else if (eConnectionState_Connecting == connState)
11333 {
11334 /*
11335 * Indicate connect failure to supplicant if we were in the
11336 * process of connecting
11337 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011338 hdd_connect_result(pAdapter->dev, NULL, NULL,
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011339 NULL, 0, NULL, 0,
11340 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
11341 GFP_KERNEL);
11342 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011343 break;
11344
11345 case WLAN_HDD_SOFTAP:
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011346 if (pHddCtx->cfg_ini->sap_internal_restart) {
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +053011347 hdd_init_ap_mode(pAdapter, true);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011348 status = hdd_sta_id_hash_attach(pAdapter);
11349 if (VOS_STATUS_SUCCESS != status)
11350 {
11351 hddLog(VOS_TRACE_LEVEL_FATAL,
11352 FL("failed to attach hash for"));
11353 }
11354 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011355 break;
11356
11357 case WLAN_HDD_P2P_GO:
Sameer Thalappiledf0d792013-08-09 14:31:03 -070011358 hddLog(VOS_TRACE_LEVEL_ERROR, "%s [SSR] send stop ap to supplicant",
Jeff Johnson295189b2012-06-20 16:38:30 -070011359 __func__);
Sameer Thalappiledf0d792013-08-09 14:31:03 -070011360 cfg80211_ap_stopped(pAdapter->dev, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -070011361 break;
11362
11363 case WLAN_HDD_MONITOR:
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011364 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
11365
11366 hddLog(VOS_TRACE_LEVEL_INFO, FL("[SSR] monitor mode"));
11367 if (!pVosContext) {
11368 hddLog(VOS_TRACE_LEVEL_ERROR, FL("vos context is NULL"));
11369 break;
11370 }
11371
11372 hdd_init_tx_rx(pAdapter);
11373 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk);
Jeff Johnson295189b2012-06-20 16:38:30 -070011374 break;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011375
Jeff Johnson295189b2012-06-20 16:38:30 -070011376 default:
11377 break;
11378 }
11379
11380 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11381 pAdapterNode = pNext;
11382 }
11383
11384 EXIT();
11385
11386 return VOS_STATUS_SUCCESS;
11387}
11388
11389VOS_STATUS hdd_reconnect_all_adapters( hdd_context_t *pHddCtx )
11390{
11391 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11392 hdd_adapter_t *pAdapter;
11393 VOS_STATUS status;
11394 v_U32_t roamId;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011395 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070011396
11397 ENTER();
11398
11399 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11400
11401 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11402 {
11403 pAdapter = pAdapterNode->pAdapter;
11404
11405 if( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
11406 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
11407 {
11408 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11409 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11410
Abhishek Singhf4669da2014-05-26 15:07:49 +053011411 hddLog(VOS_TRACE_LEVEL_INFO,
11412 "%s: Set HDD connState to eConnectionState_NotConnected",
11413 __func__);
Ganesh Kondabattini04338412015-09-14 15:39:09 +053011414 spin_lock_bh(&pAdapter->lock_for_active_session);
11415 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState)
11416 {
11417 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
11418 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011419 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Ganesh Kondabattini04338412015-09-14 15:39:09 +053011420 spin_unlock_bh(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -070011421 init_completion(&pAdapter->disconnect_comp_var);
11422 sme_RoamDisconnect(pHddCtx->hHal, pAdapter->sessionId,
11423 eCSR_DISCONNECT_REASON_UNSPECIFIED);
11424
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011425 ret = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -070011426 &pAdapter->disconnect_comp_var,
11427 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011428 if (0 >= ret)
11429 hddLog(LOGE, "%s: failure waiting for disconnect_comp_var %ld",
11430 __func__, ret);
Jeff Johnson295189b2012-06-20 16:38:30 -070011431
11432 pWextState->roamProfile.csrPersona = pAdapter->device_mode;
11433 pHddCtx->isAmpAllowed = VOS_FALSE;
11434 sme_RoamConnect(pHddCtx->hHal,
11435 pAdapter->sessionId, &(pWextState->roamProfile),
11436 &roamId);
11437 }
11438
11439 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11440 pAdapterNode = pNext;
11441 }
11442
11443 EXIT();
11444
11445 return VOS_STATUS_SUCCESS;
11446}
11447
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011448void hdd_dump_concurrency_info(hdd_context_t *pHddCtx)
11449{
11450 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11451 VOS_STATUS status;
11452 hdd_adapter_t *pAdapter;
11453 hdd_station_ctx_t *pHddStaCtx;
11454 hdd_ap_ctx_t *pHddApCtx;
11455 hdd_hostapd_state_t * pHostapdState;
11456 tCsrBssid staBssid = { 0 }, p2pBssid = { 0 }, apBssid = { 0 };
11457 v_U8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
11458 const char *p2pMode = "DEV";
11459 const char *ccMode = "Standalone";
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011460
11461 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11462 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11463 {
11464 pAdapter = pAdapterNode->pAdapter;
11465 switch (pAdapter->device_mode) {
11466 case WLAN_HDD_INFRA_STATION:
11467 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11468 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
11469 staChannel = pHddStaCtx->conn_info.operationChannel;
11470 memcpy(staBssid, pHddStaCtx->conn_info.bssId, sizeof(staBssid));
11471 }
11472 break;
11473 case WLAN_HDD_P2P_CLIENT:
11474 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11475 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
11476 p2pChannel = pHddStaCtx->conn_info.operationChannel;
11477 memcpy(p2pBssid, pHddStaCtx->conn_info.bssId, sizeof(p2pBssid));
11478 p2pMode = "CLI";
11479 }
11480 break;
11481 case WLAN_HDD_P2P_GO:
11482 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
11483 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
11484 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
11485 p2pChannel = pHddApCtx->operatingChannel;
11486 memcpy(p2pBssid, pAdapter->macAddressCurrent.bytes, sizeof(p2pBssid));
11487 }
11488 p2pMode = "GO";
11489 break;
11490 case WLAN_HDD_SOFTAP:
11491 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
11492 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
11493 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
11494 apChannel = pHddApCtx->operatingChannel;
11495 memcpy(apBssid, pAdapter->macAddressCurrent.bytes, sizeof(apBssid));
11496 }
11497 break;
11498 default:
11499 break;
11500 }
11501 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11502 pAdapterNode = pNext;
11503 }
11504 if (staChannel > 0 && (apChannel > 0 || p2pChannel > 0)) {
11505 ccMode = (p2pChannel==staChannel||apChannel==staChannel) ? "SCC" : "MCC";
11506 }
Yeshwanth Sriram Guntuka0004c0b2017-12-06 14:43:49 +053011507 hddLog(VOS_TRACE_LEVEL_ERROR, "wlan(%d) " MAC_ADDRESS_STR " %s",
11508 staChannel, MAC_ADDR_ARRAY(staBssid), ccMode);
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011509 if (p2pChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +053011510 hddLog(VOS_TRACE_LEVEL_ERROR, "p2p-%s(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011511 p2pMode, p2pChannel, MAC_ADDR_ARRAY(p2pBssid));
11512 }
11513 if (apChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +053011514 hddLog(VOS_TRACE_LEVEL_ERROR, "AP(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011515 apChannel, MAC_ADDR_ARRAY(apBssid));
11516 }
11517
11518 if (p2pChannel > 0 && apChannel > 0) {
11519 hddLog(VOS_TRACE_LEVEL_ERROR, "Error concurrent SAP %d and P2P %d which is not support", apChannel, p2pChannel);
11520 }
11521}
11522
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011523bool hdd_is_ssr_required( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070011524{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011525 return (isSsrRequired == HDD_SSR_REQUIRED);
Jeff Johnson295189b2012-06-20 16:38:30 -070011526}
11527
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011528/* Once SSR is disabled then it cannot be set. */
11529void hdd_set_ssr_required( e_hdd_ssr_required value)
Jeff Johnson295189b2012-06-20 16:38:30 -070011530{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011531 if (HDD_SSR_DISABLED == isSsrRequired)
11532 return;
11533
Jeff Johnson295189b2012-06-20 16:38:30 -070011534 isSsrRequired = value;
11535}
11536
Hema Aparna Medicharla6b4d4f32015-06-23 04:09:12 +053011537void hdd_set_pre_close( hdd_context_t *pHddCtx)
11538{
11539 sme_PreClose(pHddCtx->hHal);
11540}
11541
Jeff Johnson295189b2012-06-20 16:38:30 -070011542VOS_STATUS hdd_get_front_adapter( hdd_context_t *pHddCtx,
11543 hdd_adapter_list_node_t** ppAdapterNode)
11544{
11545 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011546 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011547 status = hdd_list_peek_front ( &pHddCtx->hddAdapters,
11548 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011549 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011550 return status;
11551}
11552
11553VOS_STATUS hdd_get_next_adapter( hdd_context_t *pHddCtx,
11554 hdd_adapter_list_node_t* pAdapterNode,
11555 hdd_adapter_list_node_t** pNextAdapterNode)
11556{
11557 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011558 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011559 status = hdd_list_peek_next ( &pHddCtx->hddAdapters,
11560 (hdd_list_node_t*) pAdapterNode,
11561 (hdd_list_node_t**)pNextAdapterNode );
11562
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011563 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011564 return status;
11565}
11566
11567VOS_STATUS hdd_remove_adapter( hdd_context_t *pHddCtx,
11568 hdd_adapter_list_node_t* pAdapterNode)
11569{
11570 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011571 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011572 status = hdd_list_remove_node ( &pHddCtx->hddAdapters,
11573 &pAdapterNode->node );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011574 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011575 return status;
11576}
11577
11578VOS_STATUS hdd_remove_front_adapter( hdd_context_t *pHddCtx,
11579 hdd_adapter_list_node_t** ppAdapterNode)
11580{
11581 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011582 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011583 status = hdd_list_remove_front( &pHddCtx->hddAdapters,
11584 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011585 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011586 return status;
11587}
11588
11589VOS_STATUS hdd_add_adapter_back( hdd_context_t *pHddCtx,
11590 hdd_adapter_list_node_t* pAdapterNode)
11591{
11592 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011593 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011594 status = hdd_list_insert_back ( &pHddCtx->hddAdapters,
11595 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011596 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011597 return status;
11598}
11599
11600VOS_STATUS hdd_add_adapter_front( hdd_context_t *pHddCtx,
11601 hdd_adapter_list_node_t* pAdapterNode)
11602{
11603 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011604 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011605 status = hdd_list_insert_front ( &pHddCtx->hddAdapters,
11606 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011607 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011608 return status;
11609}
11610
11611hdd_adapter_t * hdd_get_adapter_by_macaddr( hdd_context_t *pHddCtx,
11612 tSirMacAddr macAddr )
11613{
11614 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11615 hdd_adapter_t *pAdapter;
11616 VOS_STATUS status;
11617
11618 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11619
11620 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11621 {
11622 pAdapter = pAdapterNode->pAdapter;
11623
11624 if( pAdapter && vos_mem_compare( pAdapter->macAddressCurrent.bytes,
11625 macAddr, sizeof(tSirMacAddr) ) )
11626 {
11627 return pAdapter;
11628 }
11629 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11630 pAdapterNode = pNext;
11631 }
11632
11633 return NULL;
11634
11635}
11636
11637hdd_adapter_t * hdd_get_adapter_by_name( hdd_context_t *pHddCtx, tANI_U8 *name )
11638{
11639 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11640 hdd_adapter_t *pAdapter;
11641 VOS_STATUS status;
11642
11643 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11644
11645 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11646 {
11647 pAdapter = pAdapterNode->pAdapter;
11648
11649 if( pAdapter && !strncmp( pAdapter->dev->name, (const char *)name,
11650 IFNAMSIZ ) )
11651 {
11652 return pAdapter;
11653 }
11654 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11655 pAdapterNode = pNext;
11656 }
11657
11658 return NULL;
11659
11660}
11661
Ganesh Kondabattinicbfdc392015-09-11 19:12:59 +053011662hdd_adapter_t *hdd_get_adapter_by_sme_session_id( hdd_context_t *pHddCtx,
11663 tANI_U32 sme_session_id )
11664{
11665 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11666 hdd_adapter_t *pAdapter;
11667 VOS_STATUS vos_status;
11668
11669
11670 vos_status = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
11671
11672 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == vos_status))
11673 {
11674 pAdapter = pAdapterNode->pAdapter;
11675
11676 if (pAdapter->sessionId == sme_session_id)
11677 return pAdapter;
11678
11679 vos_status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
11680 pAdapterNode = pNext;
11681 }
11682
11683 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
11684 "%s: sme_session_id %d does not exist with host",
11685 __func__, sme_session_id);
11686
11687 return NULL;
11688}
11689
Jeff Johnson295189b2012-06-20 16:38:30 -070011690hdd_adapter_t * hdd_get_adapter( hdd_context_t *pHddCtx, device_mode_t mode )
11691{
11692 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11693 hdd_adapter_t *pAdapter;
11694 VOS_STATUS status;
11695
11696 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11697
11698 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11699 {
11700 pAdapter = pAdapterNode->pAdapter;
11701
11702 if( pAdapter && (mode == pAdapter->device_mode) )
11703 {
11704 return pAdapter;
11705 }
11706 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11707 pAdapterNode = pNext;
11708 }
11709
11710 return NULL;
11711
11712}
11713
11714//Remove this function later
11715hdd_adapter_t * hdd_get_mon_adapter( hdd_context_t *pHddCtx )
11716{
11717 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11718 hdd_adapter_t *pAdapter;
11719 VOS_STATUS status;
11720
11721 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11722
11723 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11724 {
11725 pAdapter = pAdapterNode->pAdapter;
11726
11727 if( pAdapter && WLAN_HDD_MONITOR == pAdapter->device_mode )
11728 {
11729 return pAdapter;
11730 }
11731
11732 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11733 pAdapterNode = pNext;
11734 }
11735
11736 return NULL;
11737
11738}
11739
Jeff Johnson295189b2012-06-20 16:38:30 -070011740/**---------------------------------------------------------------------------
11741
Mahesh A Saptasgar64534612014-09-23 13:13:33 +053011742 \brief hdd_get_operating_channel() -
Jeff Johnson295189b2012-06-20 16:38:30 -070011743
11744 This API returns the operating channel of the requested device mode
11745
11746 \param - pHddCtx - Pointer to the HDD context.
11747 - mode - Device mode for which operating channel is required
11748 suported modes - WLAN_HDD_INFRA_STATION, WLAN_HDD_P2P_CLIENT
11749 WLAN_HDD_SOFTAP, WLAN_HDD_P2P_GO.
11750 \return - channel number. "0" id the requested device is not found OR it is not connected.
11751 --------------------------------------------------------------------------*/
11752v_U8_t hdd_get_operating_channel( hdd_context_t *pHddCtx, device_mode_t mode )
11753{
11754 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11755 VOS_STATUS status;
11756 hdd_adapter_t *pAdapter;
11757 v_U8_t operatingChannel = 0;
11758
11759 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11760
11761 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11762 {
11763 pAdapter = pAdapterNode->pAdapter;
11764
11765 if( mode == pAdapter->device_mode )
11766 {
11767 switch(pAdapter->device_mode)
11768 {
11769 case WLAN_HDD_INFRA_STATION:
11770 case WLAN_HDD_P2P_CLIENT:
11771 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
11772 operatingChannel = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.operationChannel;
11773 break;
11774 case WLAN_HDD_SOFTAP:
11775 case WLAN_HDD_P2P_GO:
11776 /*softap connection info */
11777 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
11778 operatingChannel = (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->operatingChannel;
11779 break;
11780 default:
11781 break;
11782 }
11783
11784 break; //Found the device of interest. break the loop
11785 }
11786
11787 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11788 pAdapterNode = pNext;
11789 }
11790 return operatingChannel;
11791}
11792
11793#ifdef WLAN_FEATURE_PACKET_FILTERING
11794/**---------------------------------------------------------------------------
11795
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011796 \brief __hdd_set_multicast_list() -
Jeff Johnson295189b2012-06-20 16:38:30 -070011797
11798 This used to set the multicast address list.
11799
11800 \param - dev - Pointer to the WLAN device.
11801 - skb - Pointer to OS packet (sk_buff).
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011802 \return - success/fail
Jeff Johnson295189b2012-06-20 16:38:30 -070011803
11804 --------------------------------------------------------------------------*/
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011805static void __hdd_set_multicast_list(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -070011806{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011807 hdd_adapter_t *pAdapter;
11808 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -070011809 int mc_count;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011810 int i = 0, ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011811 struct netdev_hw_addr *ha;
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011812
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011813 ENTER();
11814
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011815 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011816 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070011817 {
11818 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011819 "%s: Adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070011820 return;
11821 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011822 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11823 ret = wlan_hdd_validate_context(pHddCtx);
11824 if (0 != ret)
11825 {
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011826 return;
11827 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011828 if (dev->flags & IFF_ALLMULTI)
11829 {
11830 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011831 "%s: allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011832 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011833 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011834 else
Jeff Johnson295189b2012-06-20 16:38:30 -070011835 {
11836 mc_count = netdev_mc_count(dev);
11837 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011838 "%s: mc_count = %u", __func__, mc_count);
Jeff Johnson295189b2012-06-20 16:38:30 -070011839 if (mc_count > WLAN_HDD_MAX_MC_ADDR_LIST)
11840 {
11841 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011842 "%s: No free filter available; allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011843 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011844 return;
11845 }
11846
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011847 pAdapter->mc_addr_list.mc_cnt = mc_count;
Jeff Johnson295189b2012-06-20 16:38:30 -070011848
11849 netdev_for_each_mc_addr(ha, dev) {
11850 if (i == mc_count)
11851 break;
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011852 memset(&(pAdapter->mc_addr_list.addr[i][0]), 0, ETH_ALEN);
11853 memcpy(&(pAdapter->mc_addr_list.addr[i][0]), ha->addr, ETH_ALEN);
Arif Hussain6d2a3322013-11-17 19:50:10 -080011854 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mlist[%d] = "MAC_ADDRESS_STR,
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011855 __func__, i,
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011856 MAC_ADDR_ARRAY(pAdapter->mc_addr_list.addr[i]));
Jeff Johnson295189b2012-06-20 16:38:30 -070011857 i++;
11858 }
11859 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011860
Ganesh Kondabattinifb37e652015-10-09 15:46:47 +053011861 if (pHddCtx->hdd_wlan_suspended)
11862 {
11863 /*
11864 * Configure the Mcast address list to FW
11865 * If wlan is already in suspend mode
11866 */
11867 wlan_hdd_set_mc_addr_list(pAdapter, TRUE);
11868 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011869 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -070011870 return;
11871}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011872
11873static void hdd_set_multicast_list(struct net_device *dev)
11874{
11875 vos_ssr_protect(__func__);
11876 __hdd_set_multicast_list(dev);
11877 vos_ssr_unprotect(__func__);
11878}
Jeff Johnson295189b2012-06-20 16:38:30 -070011879#endif
11880
11881/**---------------------------------------------------------------------------
11882
11883 \brief hdd_select_queue() -
11884
11885 This function is registered with the Linux OS for network
11886 core to decide which queue to use first.
11887
11888 \param - dev - Pointer to the WLAN device.
11889 - skb - Pointer to OS packet (sk_buff).
11890 \return - ac, Queue Index/access category corresponding to UP in IP header
11891
11892 --------------------------------------------------------------------------*/
11893v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053011894 struct sk_buff *skb
11895#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
11896 , void *accel_priv
11897#endif
11898#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
11899 , select_queue_fallback_t fallback
11900#endif
11901)
Jeff Johnson295189b2012-06-20 16:38:30 -070011902{
11903 return hdd_wmm_select_queue(dev, skb);
11904}
11905
11906
11907/**---------------------------------------------------------------------------
11908
11909 \brief hdd_wlan_initial_scan() -
11910
11911 This function triggers the initial scan
11912
11913 \param - pAdapter - Pointer to the HDD adapter.
11914
11915 --------------------------------------------------------------------------*/
11916void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter)
11917{
11918 tCsrScanRequest scanReq;
11919 tCsrChannelInfo channelInfo;
11920 eHalStatus halStatus;
Jeff Johnson02797792013-10-26 19:17:13 -070011921 tANI_U32 scanId;
Jeff Johnson295189b2012-06-20 16:38:30 -070011922 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11923
11924 vos_mem_zero(&scanReq, sizeof(tCsrScanRequest));
11925 vos_mem_set(&scanReq.bssid, sizeof(tCsrBssid), 0xff);
11926 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
11927
11928 if(sme_Is11dSupported(pHddCtx->hHal))
11929 {
11930 halStatus = sme_ScanGetBaseChannels( pHddCtx->hHal, &channelInfo );
11931 if ( HAL_STATUS_SUCCESS( halStatus ) )
11932 {
11933 scanReq.ChannelInfo.ChannelList = vos_mem_malloc(channelInfo.numOfChannels);
11934 if( !scanReq.ChannelInfo.ChannelList )
11935 {
11936 hddLog(VOS_TRACE_LEVEL_ERROR, "%s kmalloc failed", __func__);
11937 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080011938 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011939 return;
11940 }
11941 vos_mem_copy(scanReq.ChannelInfo.ChannelList, channelInfo.ChannelList,
11942 channelInfo.numOfChannels);
11943 scanReq.ChannelInfo.numOfChannels = channelInfo.numOfChannels;
11944 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080011945 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011946 }
11947
11948 scanReq.scanType = eSIR_PASSIVE_SCAN;
11949 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
11950 scanReq.maxChnTime = pHddCtx->cfg_ini->nPassiveMaxChnTime;
11951 scanReq.minChnTime = pHddCtx->cfg_ini->nPassiveMinChnTime;
11952 }
11953 else
11954 {
11955 scanReq.scanType = eSIR_ACTIVE_SCAN;
11956 scanReq.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
11957 scanReq.maxChnTime = pHddCtx->cfg_ini->nActiveMaxChnTime;
11958 scanReq.minChnTime = pHddCtx->cfg_ini->nActiveMinChnTime;
11959 }
11960
11961 halStatus = sme_ScanRequest(pHddCtx->hHal, pAdapter->sessionId, &scanReq, &scanId, NULL, NULL);
11962 if ( !HAL_STATUS_SUCCESS( halStatus ) )
11963 {
11964 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_ScanRequest failed status code %d",
11965 __func__, halStatus );
11966 }
11967
11968 if(sme_Is11dSupported(pHddCtx->hHal))
11969 vos_mem_free(scanReq.ChannelInfo.ChannelList);
11970}
11971
Jeff Johnson295189b2012-06-20 16:38:30 -070011972/**---------------------------------------------------------------------------
11973
11974 \brief hdd_full_power_callback() - HDD full power callback function
11975
11976 This is the function invoked by SME to inform the result of a full power
11977 request issued by HDD
11978
11979 \param - callbackcontext - Pointer to cookie
11980 \param - status - result of request
11981
11982 \return - None
11983
11984 --------------------------------------------------------------------------*/
11985static void hdd_full_power_callback(void *callbackContext, eHalStatus status)
11986{
Jeff Johnson72a40512013-12-19 10:14:15 -080011987 struct statsContext *pContext = callbackContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011988
11989 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070011990 "%s: context = %pK, status = %d", __func__, pContext, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070011991
11992 if (NULL == callbackContext)
11993 {
11994 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070011995 "%s: Bad param, context [%pK]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011996 __func__, callbackContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070011997 return;
11998 }
11999
Jeff Johnson72a40512013-12-19 10:14:15 -080012000 /* there is a race condition that exists between this callback
12001 function and the caller since the caller could time out either
12002 before or while this code is executing. we use a spinlock to
12003 serialize these actions */
12004 spin_lock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012005
12006 if (POWER_CONTEXT_MAGIC != pContext->magic)
12007 {
12008 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -080012009 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012010 hddLog(VOS_TRACE_LEVEL_WARN,
12011 "%s: Invalid context, magic [%08x]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012012 __func__, pContext->magic);
Jeff Johnson295189b2012-06-20 16:38:30 -070012013 return;
12014 }
12015
Jeff Johnson72a40512013-12-19 10:14:15 -080012016 /* context is valid so caller is still waiting */
12017
12018 /* paranoia: invalidate the magic */
12019 pContext->magic = 0;
12020
12021 /* notify the caller */
Jeff Johnson295189b2012-06-20 16:38:30 -070012022 complete(&pContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -080012023
12024 /* serialization is complete */
12025 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012026}
12027
Katya Nigamf0511f62015-05-05 16:40:57 +053012028void wlan_hdd_mon_set_typesubtype( hdd_mon_ctx_t *pMonCtx,int type)
12029{
12030 pMonCtx->typeSubtypeBitmap = 0;
12031 if( type%10 ) /* Management Packets */
12032 pMonCtx->typeSubtypeBitmap |= 0xFFFF;
12033 type/=10;
12034 if( type%10 ) /* Control Packets */
12035 pMonCtx->typeSubtypeBitmap |= 0xFFFF0000;
12036 type/=10;
12037 if( type%10 ) /* Data Packets */
12038 pMonCtx->typeSubtypeBitmap |= 0xFFFF00000000;
12039}
12040
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012041VOS_STATUS wlan_hdd_mon_postMsg(void *context, hdd_mon_ctx_t *pMonCtx,
12042 void* callback)
Katya Nigamf0511f62015-05-05 16:40:57 +053012043{
12044 vos_msg_t monMsg;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012045 tSirMonModeReq *pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +053012046
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012047 if (MON_MODE_START == pMonCtx->state)
12048 monMsg.type = WDA_MON_START_REQ;
12049 else if (MON_MODE_STOP == pMonCtx->state)
12050 monMsg.type = WDA_MON_STOP_REQ;
12051 else {
12052 hddLog(VOS_TRACE_LEVEL_ERROR,
12053 FL("invalid monitor state %d"), pMonCtx->state);
Katya Nigamf0511f62015-05-05 16:40:57 +053012054 return VOS_STATUS_E_FAILURE;
12055 }
12056
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012057 pMonModeReq = vos_mem_malloc(sizeof(tSirMonModeReq));
12058 if (pMonModeReq == NULL) {
12059 hddLog(VOS_TRACE_LEVEL_ERROR,
12060 FL("fail to allocate memory for monitor mode req"));
12061 return VOS_STATUS_E_FAILURE;
12062 }
Katya Nigamf0511f62015-05-05 16:40:57 +053012063
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012064 pMonModeReq->context = context;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012065 pMonModeReq->data = pMonCtx;
12066 pMonModeReq->callback = callback;
Katya Nigamf0511f62015-05-05 16:40:57 +053012067
Katya Nigamf0511f62015-05-05 16:40:57 +053012068 monMsg.reserved = 0;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012069 monMsg.bodyptr = pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +053012070 monMsg.bodyval = 0;
12071
12072 if (VOS_STATUS_SUCCESS != vos_mq_post_message(
12073 VOS_MODULE_ID_WDA,(vos_msg_t *)&monMsg)) {
12074 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: : Failed to post Msg to HAL",__func__);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012075 vos_mem_free(pMonModeReq);
Katya Nigamf0511f62015-05-05 16:40:57 +053012076 }
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012077 return VOS_STATUS_SUCCESS;
Katya Nigamf0511f62015-05-05 16:40:57 +053012078}
12079
Katya Nigame7b69a82015-04-28 15:24:06 +053012080void wlan_hdd_mon_close(hdd_context_t *pHddCtx)
12081{
12082 VOS_STATUS vosStatus;
12083 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012084 hdd_mon_ctx_t *pMonCtx = NULL;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012085 int ret;
12086 void *cookie;
12087 struct hdd_request *request;
12088 static const struct hdd_request_params params = {
12089 .priv_size = 0,
12090 .timeout_ms = MON_MODE_MSG_TIMEOUT,
12091 };
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053012092
Katya Nigame7b69a82015-04-28 15:24:06 +053012093 hdd_adapter_t *pAdapter = hdd_get_adapter(pHddCtx,WLAN_HDD_MONITOR);
12094 if(pAdapter == NULL || pVosContext == NULL)
12095 {
12096 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:pAdapter is NULL",__func__);
12097 return ;
12098 }
Katya Nigamf0511f62015-05-05 16:40:57 +053012099
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012100 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
12101 if (pMonCtx!= NULL && pMonCtx->state == MON_MODE_START) {
12102 pMonCtx->state = MON_MODE_STOP;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012103 request = hdd_request_alloc(&params);
12104 if (!request) {
12105 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
12106 return;
12107 }
12108 cookie = hdd_request_cookie(request);
12109
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012110 if (VOS_STATUS_SUCCESS !=
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012111 wlan_hdd_mon_postMsg(cookie, pMonCtx,
12112 hdd_mon_post_msg_cb)) {
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012113 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12114 FL("failed to post MON MODE REQ"));
12115 pMonCtx->state = MON_MODE_START;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012116 goto req_put;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012117 }
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012118
12119 ret = hdd_request_wait_for_response(request);
12120 if (ret)
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012121 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012122 FL("timeout on monitor mode completion %d"), ret);
12123
12124req_put:
12125 hdd_request_put(request);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012126 }
12127
Katya Nigame7b69a82015-04-28 15:24:06 +053012128 hdd_UnregisterWext(pAdapter->dev);
12129
12130 vos_mon_stop( pVosContext );
12131
12132 vosStatus = vos_sched_close( pVosContext );
12133 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
12134 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
12135 "%s: Failed to close VOSS Scheduler",__func__);
12136 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12137 }
12138
12139 vosStatus = vos_nv_close();
12140 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12141 {
12142 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12143 "%s: Failed to close NV", __func__);
12144 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12145 }
12146
12147 vos_close(pVosContext);
12148
12149 #ifdef WLAN_KD_READY_NOTIFIER
12150 nl_srv_exit(pHddCtx->ptt_pid);
12151 #else
12152 nl_srv_exit();
12153 #endif
12154
Katya Nigame7b69a82015-04-28 15:24:06 +053012155 hdd_close_all_adapters( pHddCtx );
Katya Nigame7b69a82015-04-28 15:24:06 +053012156}
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012157/**
12158 * hdd_wlan_free_wiphy_channels - free Channel pointer for wiphy
12159 * @ wiphy: the wiphy to validate against
12160 *
12161 * Return: void
12162 */
12163void hdd_wlan_free_wiphy_channels(struct wiphy *wiphy)
12164{
12165 int i =0;
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053012166 for (i = 0; i < HDD_NUM_NL80211_BANDS; i++)
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012167 {
12168 if (NULL != wiphy->bands[i] &&
12169 (NULL != wiphy->bands[i]->channels))
12170 {
12171 vos_mem_free(wiphy->bands[i]->channels);
12172 wiphy->bands[i]->channels = NULL;
12173 }
12174 }
12175}
Jeff Johnson295189b2012-06-20 16:38:30 -070012176/**---------------------------------------------------------------------------
12177
12178 \brief hdd_wlan_exit() - HDD WLAN exit function
12179
12180 This is the driver exit point (invoked during rmmod)
12181
12182 \param - pHddCtx - Pointer to the HDD Context
12183
12184 \return - None
12185
12186 --------------------------------------------------------------------------*/
12187void hdd_wlan_exit(hdd_context_t *pHddCtx)
12188{
12189 eHalStatus halStatus;
12190 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
12191 VOS_STATUS vosStatus;
Gopichand Nakkala66923aa2013-03-06 23:17:24 +053012192 struct wiphy *wiphy = pHddCtx->wiphy;
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080012193 hdd_adapter_t* pAdapter = NULL;
Jeff Johnson72a40512013-12-19 10:14:15 -080012194 struct statsContext powerContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070012195 long lrc;
c_hpothu5ab05e92014-06-13 17:34:05 +053012196 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070012197
12198 ENTER();
12199
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012200
Katya Nigame7b69a82015-04-28 15:24:06 +053012201 if (VOS_MONITOR_MODE == hdd_get_conparam())
12202 {
12203 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: MONITOR MODE",__func__);
12204 wlan_hdd_mon_close(pHddCtx);
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053012205 goto free_hdd_ctx;
Katya Nigame7b69a82015-04-28 15:24:06 +053012206 }
12207 else if (VOS_FTM_MODE != hdd_get_conparam())
Jeff Johnson88ba7742013-02-27 14:36:02 -080012208 {
12209 // Unloading, restart logic is no more required.
12210 wlan_hdd_restart_deinit(pHddCtx);
Jeff Johnsone7245742012-09-05 17:12:55 -070012211
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053012212#ifdef FEATURE_WLAN_TDLS
12213 /* At the time of driver unloading; if tdls connection is present;
12214 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer.
12215 * wlan_hdd_tdls_find_peer always checks for valid context;
12216 * as load/unload in progress there can be a race condition.
12217 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer only
12218 * when tdls state is enabled.
12219 * As soon as driver set load/unload flag; tdls flag also needs
12220 * to be disabled so that hdd_rx_packet_cbk won't call
12221 * wlan_hdd_tdls_find_peer.
12222 */
Masti, Narayanraddi20494af2015-12-17 20:56:42 +053012223 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE,
12224 HDD_SET_TDLS_MODE_SOURCE_USER);
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053012225#endif
12226
c_hpothu5ab05e92014-06-13 17:34:05 +053012227 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
12228 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
Jeff Johnson295189b2012-06-20 16:38:30 -070012229 {
c_hpothu5ab05e92014-06-13 17:34:05 +053012230 pAdapter = pAdapterNode->pAdapter;
12231 if (NULL != pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070012232 {
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +053012233 /* Disable TX on the interface, after this hard_start_xmit() will
12234 * not be called on that interface
12235 */
12236 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
12237 netif_tx_disable(pAdapter->dev);
12238
12239 /* Mark the interface status as "down" for outside world */
12240 netif_carrier_off(pAdapter->dev);
12241
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053012242 /* DeInit the adapter. This ensures that all data packets
12243 * are freed.
12244 */
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053012245#ifdef FEATURE_WLAN_TDLS
12246 mutex_lock(&pHddCtx->tdls_lock);
12247#endif
c_hpothu002231a2015-02-05 14:58:51 +053012248 hdd_deinit_adapter(pHddCtx, pAdapter, FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053012249#ifdef FEATURE_WLAN_TDLS
12250 mutex_unlock(&pHddCtx->tdls_lock);
12251#endif
Masti, Narayanraddi26378462016-01-05 18:20:28 +053012252 vos_flush_delayed_work(&pHddCtx->scan_ctxt.scan_work);
12253
12254 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053012255
c_hpothu5ab05e92014-06-13 17:34:05 +053012256 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053012257 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
12258 WLAN_HDD_MONITOR == pAdapter->device_mode)
c_hpothu5ab05e92014-06-13 17:34:05 +053012259 {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053012260 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
12261 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
12262 wlan_hdd_cfg80211_deregister_frames(pAdapter);
12263
c_hpothu5ab05e92014-06-13 17:34:05 +053012264 hdd_UnregisterWext(pAdapter->dev);
12265 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012266
Jeff Johnson295189b2012-06-20 16:38:30 -070012267 }
c_hpothu5ab05e92014-06-13 17:34:05 +053012268 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
12269 pAdapterNode = pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -070012270 }
mukul sharmabab477d2015-06-11 17:14:55 +053012271
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012272 // Cancel any outstanding scan requests. We are about to close all
12273 // of our adapters, but an adapter structure is what SME passes back
12274 // to our callback function. Hence if there are any outstanding scan
12275 // requests then there is a race condition between when the adapter
12276 // is closed and when the callback is invoked.We try to resolve that
12277 // race condition here by canceling any outstanding scans before we
12278 // close the adapters.
12279 // Note that the scans may be cancelled in an asynchronous manner,
12280 // so ideally there needs to be some kind of synchronization. Rather
12281 // than introduce a new synchronization here, we will utilize the
12282 // fact that we are about to Request Full Power, and since that is
12283 // synchronized, the expectation is that by the time Request Full
12284 // Power has completed all scans will be cancelled.
12285 if (pHddCtx->scan_info.mScanPending)
12286 {
Hema Aparna Medicharlaf05f6cd2015-01-21 14:44:19 +053012287 if(NULL != pAdapter)
12288 {
12289 hddLog(VOS_TRACE_LEVEL_INFO,
12290 FL("abort scan mode: %d sessionId: %d"),
12291 pAdapter->device_mode,
12292 pAdapter->sessionId);
12293 }
12294 hdd_abort_mac_scan(pHddCtx,
12295 pHddCtx->scan_info.sessionId,
12296 eCSR_SCAN_ABORT_DEFAULT);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012297 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012298 }
c_hpothu5ab05e92014-06-13 17:34:05 +053012299 else
Jeff Johnson88ba7742013-02-27 14:36:02 -080012300 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012301 hddLog(VOS_TRACE_LEVEL_INFO,"%s: FTM MODE",__func__);
Hanumantha Reddy Pothula45af96b2015-02-12 16:07:58 +053012302 if (pHddCtx->ftm.ftm_state == WLAN_FTM_STARTING)
12303 {
12304 INIT_COMPLETION(pHddCtx->ftm.startCmpVar);
12305 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
12306 "%s: in middle of FTM START", __func__);
12307 lrc = wait_for_completion_timeout(&pHddCtx->ftm.startCmpVar,
12308 msecs_to_jiffies(20000));
12309 if(!lrc)
12310 {
12311 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
12312 "%s: timedout on ftmStartCmpVar fatal error", __func__);
12313 }
12314 }
Jeff Johnson88ba7742013-02-27 14:36:02 -080012315 wlan_hdd_ftm_close(pHddCtx);
12316 goto free_hdd_ctx;
12317 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012318
Jeff Johnson295189b2012-06-20 16:38:30 -070012319 /* DeRegister with platform driver as client for Suspend/Resume */
12320 vosStatus = hddDeregisterPmOps(pHddCtx);
12321 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
12322 {
12323 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDeregisterPmOps failed",__func__);
12324 VOS_ASSERT(0);
12325 }
12326
12327 vosStatus = hddDevTmUnregisterNotifyCallback(pHddCtx);
12328 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
12329 {
12330 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
12331 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012332
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012333 //Stop the traffic monitor timer
Mahesh A Saptasagard461e432016-07-20 15:01:40 +053012334 if ((pHddCtx->cfg_ini->dynSplitscan) && (VOS_TIMER_STATE_RUNNING ==
12335 vos_timer_getCurrentState(&pHddCtx->tx_rx_trafficTmr)))
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012336 {
12337 vos_timer_stop(&pHddCtx->tx_rx_trafficTmr);
12338 }
12339
12340 // Destroy the traffic monitor timer
Mahesh A Saptasagard461e432016-07-20 15:01:40 +053012341 if ((pHddCtx->cfg_ini->dynSplitscan) &&
12342 (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
12343 &pHddCtx->tx_rx_trafficTmr))))
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012344 {
12345 hddLog(VOS_TRACE_LEVEL_ERROR,
12346 "%s: Cannot deallocate Traffic monitor timer", __func__);
12347 }
12348
Bhargav Shahd0715912015-10-01 18:17:37 +053012349 if (VOS_TIMER_STATE_RUNNING ==
12350 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
12351 vos_timer_stop(&pHddCtx->delack_timer);
12352 }
12353
12354 if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
12355 &pHddCtx->delack_timer))) {
12356 hddLog(VOS_TRACE_LEVEL_ERROR,
12357 "%s: Cannot deallocate Bus bandwidth timer", __func__);
12358 }
12359
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053012360 if (VOS_TIMER_STATE_RUNNING ==
12361 vos_timer_getCurrentState(&pHddCtx->tdls_source_timer)) {
12362 vos_timer_stop(&pHddCtx->tdls_source_timer);
12363 }
12364
Abhishek Singh8a3e4dc2017-01-02 10:39:18 +053012365 vos_set_snoc_high_freq_voting(false);
12366
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053012367 vos_timer_destroy(&pHddCtx->tdls_source_timer);
12368
Jeff Johnson295189b2012-06-20 16:38:30 -070012369 //Disable IMPS/BMPS as we do not want the device to enter any power
12370 //save mode during shutdown
12371 sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
12372 sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
12373 sme_DisablePowerSave(pHddCtx->hHal, ePMC_UAPSD_MODE_POWER_SAVE);
12374
12375 //Ensure that device is in full power as we will touch H/W during vos_Stop
12376 init_completion(&powerContext.completion);
12377 powerContext.magic = POWER_CONTEXT_MAGIC;
12378
12379 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_power_callback,
12380 &powerContext, eSME_FULL_PWR_NEEDED_BY_HDD);
12381
12382 if (eHAL_STATUS_SUCCESS != halStatus)
12383 {
12384 if (eHAL_STATUS_PMC_PENDING == halStatus)
12385 {
12386 /* request was sent -- wait for the response */
12387 lrc = wait_for_completion_interruptible_timeout(
12388 &powerContext.completion,
12389 msecs_to_jiffies(WLAN_WAIT_TIME_POWER));
Jeff Johnson295189b2012-06-20 16:38:30 -070012390 if (lrc <= 0)
12391 {
12392 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: %s while requesting full power",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012393 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson295189b2012-06-20 16:38:30 -070012394 }
12395 }
12396 else
12397 {
12398 hddLog(VOS_TRACE_LEVEL_ERROR,
12399 "%s: Request for Full Power failed, status %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012400 __func__, halStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -070012401 /* continue -- need to clean up as much as possible */
12402 }
12403 }
Hanumantha Reddy Pothula81b42b22015-05-12 13:52:00 +053012404 if ((eHAL_STATUS_SUCCESS == halStatus) ||
12405 (eHAL_STATUS_PMC_PENDING == halStatus && lrc > 0))
12406 {
12407 /* This will issue a dump command which will clean up
12408 BTQM queues and unblock MC thread */
12409 vos_fwDumpReq(274, 0, 0, 0, 0, 1);
12410 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012411
Jeff Johnson72a40512013-12-19 10:14:15 -080012412 /* either we never sent a request, we sent a request and received a
12413 response or we sent a request and timed out. if we never sent a
12414 request or if we sent a request and got a response, we want to
12415 clear the magic out of paranoia. if we timed out there is a
12416 race condition such that the callback function could be
12417 executing at the same time we are. of primary concern is if the
12418 callback function had already verified the "magic" but had not
12419 yet set the completion variable when a timeout occurred. we
12420 serialize these activities by invalidating the magic while
12421 holding a shared spinlock which will cause us to block if the
12422 callback is currently executing */
12423 spin_lock(&hdd_context_lock);
12424 powerContext.magic = 0;
12425 spin_unlock(&hdd_context_lock);
12426
Hema Aparna Medicharlaa6cf65e2015-06-01 16:23:28 +053012427 /* If Device is shutdown, no point for SME to wait for responses
12428 from device. Pre Close SME */
12429 if(wcnss_device_is_shutdown())
12430 {
12431 sme_PreClose(pHddCtx->hHal);
12432 }
Yue Ma0d4891e2013-08-06 17:01:45 -070012433 hdd_debugfs_exit(pHddCtx);
12434
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012435#ifdef WLAN_NS_OFFLOAD
Ratheesh S P36dbc932015-08-07 14:28:57 +053012436 hddLog(LOG1, FL("Unregister IPv6 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012437 unregister_inet6addr_notifier(&pHddCtx->ipv6_notifier);
12438#endif
Ratheesh S P36dbc932015-08-07 14:28:57 +053012439 hddLog(LOG1, FL("Unregister IPv4 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012440 unregister_inetaddr_notifier(&pHddCtx->ipv4_notifier);
12441
Jeff Johnson295189b2012-06-20 16:38:30 -070012442 // Unregister the Net Device Notifier
12443 unregister_netdevice_notifier(&hdd_netdev_notifier);
12444
Jeff Johnson295189b2012-06-20 16:38:30 -070012445 hdd_stop_all_adapters( pHddCtx );
12446
Jeff Johnson295189b2012-06-20 16:38:30 -070012447#ifdef WLAN_BTAMP_FEATURE
12448 vosStatus = WLANBAP_Stop(pVosContext);
12449 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12450 {
12451 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12452 "%s: Failed to stop BAP",__func__);
12453 }
12454#endif //WLAN_BTAMP_FEATURE
12455
12456 //Stop all the modules
12457 vosStatus = vos_stop( pVosContext );
12458 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12459 {
12460 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
12461 "%s: Failed to stop VOSS",__func__);
12462 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053012463 if (isSsrPanicOnFailure())
12464 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -070012465 }
12466
Jeff Johnson295189b2012-06-20 16:38:30 -070012467 //This requires pMac access, Call this before vos_close().
Jeff Johnson295189b2012-06-20 16:38:30 -070012468 hdd_unregister_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070012469
12470 //Close the scheduler before calling vos_close to make sure no thread is
12471 // scheduled after the each module close is called i.e after all the data
12472 // structures are freed.
12473 vosStatus = vos_sched_close( pVosContext );
12474 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
12475 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
12476 "%s: Failed to close VOSS Scheduler",__func__);
12477 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12478 }
Jeff Johnsone7245742012-09-05 17:12:55 -070012479#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
12480 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012481 vos_wake_lock_destroy(&pHddCtx->rx_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -070012482#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080012483 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012484 vos_wake_lock_destroy(&pHddCtx->sap_wake_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012485
Mihir Shete7a24b5f2013-12-21 12:18:31 +053012486#ifdef CONFIG_ENABLE_LINUX_REG
12487 vosStatus = vos_nv_close();
12488 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12489 {
12490 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12491 "%s: Failed to close NV", __func__);
12492 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12493 }
12494#endif
12495
Jeff Johnson295189b2012-06-20 16:38:30 -070012496 //Close VOSS
12497 //This frees pMac(HAL) context. There should not be any call that requires pMac access after this.
12498 vos_close(pVosContext);
12499
Jeff Johnson295189b2012-06-20 16:38:30 -070012500 //Close Watchdog
12501 if(pHddCtx->cfg_ini->fIsLogpEnabled)
12502 vos_watchdog_close(pVosContext);
12503
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053012504 //Clean up HDD Nlink Service
12505 send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0);
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053012506
Manjeet Singh47ee8472016-04-11 11:57:18 +053012507 hdd_close_tx_queues(pHddCtx);
c_manjeecfd1efb2015-09-25 19:32:34 +053012508 wlan_free_fwr_mem_dump_buffer();
c_manjeecfd1efb2015-09-25 19:32:34 +053012509
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012510#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053012511 if (pHddCtx->cfg_ini->wlanLoggingEnable)
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012512 {
12513 wlan_logging_sock_deactivate_svc();
12514 }
12515#endif
12516
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053012517#ifdef WLAN_KD_READY_NOTIFIER
12518 nl_srv_exit(pHddCtx->ptt_pid);
12519#else
12520 nl_srv_exit();
12521#endif /* WLAN_KD_READY_NOTIFIER */
12522
Abhishek Singh00b71972016-01-07 10:51:04 +053012523#ifdef WLAN_FEATURE_RMC
12524 hdd_close_cesium_nl_sock();
12525#endif /* WLAN_FEATURE_RMC */
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053012526
Jeff Johnson295189b2012-06-20 16:38:30 -070012527 hdd_close_all_adapters( pHddCtx );
12528
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053012529 vos_flush_delayed_work(&pHddCtx->spoof_mac_addr_work);
Abhishek Singh78c691f2017-11-30 13:48:44 +053012530 vos_flush_delayed_work(&pHddCtx->ecsa_chan_change_work);
Kapil Gupta137ef892016-12-13 19:38:00 +053012531 vos_flush_work(&pHddCtx->sap_start_work);
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053012532
Hanumantha Reddy Pothula97f9bc92015-08-10 17:21:20 +053012533free_hdd_ctx:
Jeff Johnson295189b2012-06-20 16:38:30 -070012534 /* free the power on lock from platform driver */
12535 if (free_riva_power_on_lock("wlan"))
12536 {
12537 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to free power on lock",
12538 __func__);
12539 }
12540
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +053012541 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
12542 wlan_hdd_free_cache_channels(pHddCtx);
12543
c_hpothu78c7b602014-05-17 17:35:49 +053012544 //Free up dynamically allocated members inside HDD Adapter
12545 if (pHddCtx->cfg_ini)
12546 {
12547 kfree(pHddCtx->cfg_ini);
12548 pHddCtx->cfg_ini= NULL;
12549 }
12550
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053012551 hdd_request_manager_deinit();
12552
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053012553 /* FTM/MONITOR mode, WIPHY did not registered
Leo Changf04ddad2013-09-18 13:46:38 -070012554 If un-register here, system crash will happen */
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053012555 if (!(VOS_FTM_MODE == hdd_get_conparam() ||
12556 VOS_MONITOR_MODE == hdd_get_conparam()))
Leo Changf04ddad2013-09-18 13:46:38 -070012557 {
12558 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012559 hdd_wlan_free_wiphy_channels(wiphy);
Leo Changf04ddad2013-09-18 13:46:38 -070012560 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012561 wiphy_free(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070012562 if (hdd_is_ssr_required())
12563 {
12564 /* WDI timeout had happened during unload, so SSR is needed here */
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -070012565 subsystem_restart("wcnss");
Jeff Johnson295189b2012-06-20 16:38:30 -070012566 msleep(5000);
12567 }
12568 hdd_set_ssr_required (VOS_FALSE);
12569}
12570
12571
12572/**---------------------------------------------------------------------------
12573
12574 \brief hdd_update_config_from_nv() - Function to update the contents of
12575 the running configuration with parameters taken from NV storage
12576
12577 \param - pHddCtx - Pointer to the HDD global context
12578
12579 \return - VOS_STATUS_SUCCESS if successful
12580
12581 --------------------------------------------------------------------------*/
12582static VOS_STATUS hdd_update_config_from_nv(hdd_context_t* pHddCtx)
12583{
Jeff Johnson295189b2012-06-20 16:38:30 -070012584 v_BOOL_t itemIsValid = VOS_FALSE;
12585 VOS_STATUS status;
12586 v_MACADDR_t macFromNV[VOS_MAX_CONCURRENCY_PERSONA];
12587 v_U8_t macLoop;
12588
12589 /*If the NV is valid then get the macaddress from nv else get it from qcom_cfg.ini*/
12590 status = vos_nv_getValidity(VNV_FIELD_IMAGE, &itemIsValid);
12591 if(status != VOS_STATUS_SUCCESS)
12592 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080012593 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_getValidity() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070012594 return VOS_STATUS_E_FAILURE;
12595 }
12596
12597 if (itemIsValid == VOS_TRUE)
12598 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080012599 hddLog(VOS_TRACE_LEVEL_INFO_HIGH," Reading the Macaddress from NV");
Jeff Johnson295189b2012-06-20 16:38:30 -070012600 status = vos_nv_readMultiMacAddress((v_U8_t *)&macFromNV[0].bytes[0],
12601 VOS_MAX_CONCURRENCY_PERSONA);
12602 if(status != VOS_STATUS_SUCCESS)
12603 {
12604 /* Get MAC from NV fail, not update CFG info
12605 * INI MAC value will be used for MAC setting */
Arif Hussain6d2a3322013-11-17 19:50:10 -080012606 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_readMacAddress() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070012607 return VOS_STATUS_E_FAILURE;
12608 }
12609
12610 /* If first MAC is not valid, treat all others are not valid
12611 * Then all MACs will be got from ini file */
12612 if(vos_is_macaddr_zero(&macFromNV[0]))
12613 {
12614 /* MAC address in NV file is not configured yet */
12615 hddLog(VOS_TRACE_LEVEL_WARN, "Invalid MAC in NV file");
12616 return VOS_STATUS_E_INVAL;
12617 }
12618
12619 /* Get MAC address from NV, update CFG info */
12620 for(macLoop = 0; macLoop < VOS_MAX_CONCURRENCY_PERSONA; macLoop++)
12621 {
12622 if(vos_is_macaddr_zero(&macFromNV[macLoop]))
12623 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012624 hddLog(VOS_TRACE_LEVEL_ERROR,"not valid MAC from NV for %d", macLoop);
Jeff Johnson295189b2012-06-20 16:38:30 -070012625 /* This MAC is not valid, skip it
12626 * This MAC will be got from ini file */
12627 }
12628 else
12629 {
12630 vos_mem_copy((v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[macLoop].bytes[0],
12631 (v_U8_t *)&macFromNV[macLoop].bytes[0],
12632 VOS_MAC_ADDR_SIZE);
12633 }
12634 }
12635 }
12636 else
12637 {
12638 hddLog(VOS_TRACE_LEVEL_ERROR, "NV ITEM, MAC Not valid");
12639 return VOS_STATUS_E_FAILURE;
12640 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012641
Jeff Johnson295189b2012-06-20 16:38:30 -070012642
12643 return VOS_STATUS_SUCCESS;
12644}
12645
12646/**---------------------------------------------------------------------------
12647
12648 \brief hdd_post_voss_start_config() - HDD post voss start config helper
12649
12650 \param - pAdapter - Pointer to the HDD
12651
12652 \return - None
12653
12654 --------------------------------------------------------------------------*/
12655VOS_STATUS hdd_post_voss_start_config(hdd_context_t* pHddCtx)
12656{
12657 eHalStatus halStatus;
12658 v_U32_t listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012659 tANI_U32 ignoreDtim;
Jeff Johnson295189b2012-06-20 16:38:30 -070012660
Jeff Johnson295189b2012-06-20 16:38:30 -070012661
12662 // Send ready indication to the HDD. This will kick off the MAC
12663 // into a 'running' state and should kick off an initial scan.
12664 halStatus = sme_HDDReadyInd( pHddCtx->hHal );
12665 if ( !HAL_STATUS_SUCCESS( halStatus ) )
12666 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +053012667 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: sme_HDDReadyInd() failed with status "
Jeff Johnson295189b2012-06-20 16:38:30 -070012668 "code %08d [x%08x]",__func__, halStatus, halStatus );
12669 return VOS_STATUS_E_FAILURE;
12670 }
12671
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012672 // Set default LI and ignoreDtim into HDD context,
Jeff Johnson295189b2012-06-20 16:38:30 -070012673 // otherwise under some race condition, HDD will set 0 LI value into RIVA,
12674 // And RIVA will crash
12675 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, &listenInterval);
12676 pHddCtx->hdd_actual_LI_value = listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012677 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, &ignoreDtim);
12678 pHddCtx->hdd_actual_ignore_DTIM_value = ignoreDtim;
12679
12680
Jeff Johnson295189b2012-06-20 16:38:30 -070012681 return VOS_STATUS_SUCCESS;
12682}
12683
Jeff Johnson295189b2012-06-20 16:38:30 -070012684/* wake lock APIs for HDD */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012685void hdd_prevent_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070012686{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012687
12688 vos_wake_lock_acquire(&wlan_wake_lock, reason);
12689
Jeff Johnson295189b2012-06-20 16:38:30 -070012690}
12691
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012692void hdd_allow_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070012693{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012694
12695 vos_wake_lock_release(&wlan_wake_lock, reason);
12696
Jeff Johnson295189b2012-06-20 16:38:30 -070012697}
12698
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012699void hdd_prevent_suspend_timeout(v_U32_t timeout, uint32_t reason)
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070012700{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012701
12702 vos_wake_lock_timeout_release(&wlan_wake_lock, timeout,
12703 reason);
12704
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070012705}
12706
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053012707/**
12708 * hdd_get_feature_caps_cb() - Callback invoked from WDA
12709 * @cookie: to identify HDD request to firmware
12710 *
12711 * This function is invoked from WDA when feature capabilities response
12712 * is received from firmware.
12713 *
12714 * Return: None
12715 */
12716static void hdd_get_feature_caps_cb(void *cookie)
12717{
12718 struct hdd_request *request;
12719
12720 request = hdd_request_get(cookie);
12721 if (!request) {
12722 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
12723 return;
12724 }
12725
12726 pr_info("%s: Firmware feature capabilities received\n", __func__);
12727
12728 hdd_request_complete(request);
12729 hdd_request_put(request);
12730}
12731
12732/**
12733 * hdd_get_feature_caps() - Get features supported by firmware
12734 * @hdd_ctx: Pointer to HDD context
12735 *
12736 * This function uses request manager framework to get the feature
12737 * capabilities from firmware.
12738 *
12739 * Return: None
12740 */
12741static void hdd_get_feature_caps(hdd_context_t *hdd_ctx)
12742{
12743 VOS_STATUS status;
12744 void *cookie;
12745 int ret;
12746 struct hdd_request *request;
12747 static const struct hdd_request_params params = {
12748 .priv_size = 0,
12749 .timeout_ms = WLAN_WAIT_TIME_FEATURE_CAPS,
12750 };
12751 struct sir_feature_caps_params caps_params = {0};
12752
12753 request = hdd_request_alloc(&params);
12754 if (!request) {
12755 pr_err("%s: Request allocation failure\n", __func__);
12756 return;
12757 }
12758
12759 cookie = hdd_request_cookie(request);
12760 caps_params.user_data = cookie;
12761 caps_params.feature_caps_cb = hdd_get_feature_caps_cb;
12762
12763 status = sme_featureCapsExchange(&caps_params);
12764 if (status != VOS_STATUS_SUCCESS) {
12765 pr_err("%s: Unable to get feature caps\n", __func__);
12766 goto end;
12767 }
12768
12769 /* request was sent -- wait for the response */
12770 ret = hdd_request_wait_for_response(request);
12771 if (ret) {
12772 pr_err("%s: SME timeout while retrieving feature caps\n",
12773 __func__);
12774 goto end;
12775 }
12776
12777end:
12778 hdd_request_put(request);
12779}
12780
Jeff Johnson295189b2012-06-20 16:38:30 -070012781/**---------------------------------------------------------------------------
12782
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012783 \brief hdd_exchange_version_and_caps() - HDD function to exchange version and capability
12784 information between Host and Riva
12785
12786 This function gets reported version of FW
12787 It also finds the version of Riva headers used to compile the host
12788 It compares the above two and prints a warning if they are different
12789 It gets the SW and HW version string
12790 Finally, it exchanges capabilities between host and Riva i.e. host and riva exchange a msg
12791 indicating the features they support through a bitmap
12792
12793 \param - pHddCtx - Pointer to HDD context
12794
12795 \return - void
12796
12797 --------------------------------------------------------------------------*/
12798
12799void hdd_exchange_version_and_caps(hdd_context_t *pHddCtx)
12800{
12801
12802 tSirVersionType versionCompiled;
12803 tSirVersionType versionReported;
12804 tSirVersionString versionString;
12805 tANI_U8 fwFeatCapsMsgSupported = 0;
12806 VOS_STATUS vstatus;
12807
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080012808 memset(&versionCompiled, 0, sizeof(versionCompiled));
12809 memset(&versionReported, 0, sizeof(versionReported));
12810
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012811 /* retrieve and display WCNSS version information */
12812 do {
12813
12814 vstatus = sme_GetWcnssWlanCompiledVersion(pHddCtx->hHal,
12815 &versionCompiled);
12816 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12817 {
12818 hddLog(VOS_TRACE_LEVEL_FATAL,
12819 "%s: unable to retrieve WCNSS WLAN compiled version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012820 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012821 break;
12822 }
12823
12824 vstatus = sme_GetWcnssWlanReportedVersion(pHddCtx->hHal,
12825 &versionReported);
12826 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12827 {
12828 hddLog(VOS_TRACE_LEVEL_FATAL,
12829 "%s: unable to retrieve WCNSS WLAN reported version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012830 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012831 break;
12832 }
12833
12834 if ((versionCompiled.major != versionReported.major) ||
12835 (versionCompiled.minor != versionReported.minor) ||
12836 (versionCompiled.version != versionReported.version) ||
12837 (versionCompiled.revision != versionReported.revision))
12838 {
12839 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
12840 "Host expected %u.%u.%u.%u\n",
12841 WLAN_MODULE_NAME,
12842 (int)versionReported.major,
12843 (int)versionReported.minor,
12844 (int)versionReported.version,
12845 (int)versionReported.revision,
12846 (int)versionCompiled.major,
12847 (int)versionCompiled.minor,
12848 (int)versionCompiled.version,
12849 (int)versionCompiled.revision);
12850 }
12851 else
12852 {
12853 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
12854 WLAN_MODULE_NAME,
12855 (int)versionReported.major,
12856 (int)versionReported.minor,
12857 (int)versionReported.version,
12858 (int)versionReported.revision);
12859 }
12860
12861 vstatus = sme_GetWcnssSoftwareVersion(pHddCtx->hHal,
12862 versionString,
12863 sizeof(versionString));
12864 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12865 {
12866 hddLog(VOS_TRACE_LEVEL_FATAL,
12867 "%s: unable to retrieve WCNSS software version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012868 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012869 break;
12870 }
12871
12872 pr_info("%s: WCNSS software version %s\n",
12873 WLAN_MODULE_NAME, versionString);
Sushant Kaushik084f6592015-09-10 13:11:56 +053012874 vos_mem_copy(pHddCtx->fw_Version, versionString, sizeof(versionString));
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012875
12876 vstatus = sme_GetWcnssHardwareVersion(pHddCtx->hHal,
12877 versionString,
12878 sizeof(versionString));
12879 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12880 {
12881 hddLog(VOS_TRACE_LEVEL_FATAL,
12882 "%s: unable to retrieve WCNSS hardware version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012883 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012884 break;
12885 }
12886
12887 pr_info("%s: WCNSS hardware version %s\n",
12888 WLAN_MODULE_NAME, versionString);
12889
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012890 /* 1.Check if FW version is greater than 0.1.1.0. Only then send host-FW capability exchange message
12891 2.Host-FW capability exchange message is only present on riva 1.1 so
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012892 send the message only if it the riva is 1.1
12893 minor numbers for different riva branches:
12894 0 -> (1.0)Mainline Build
12895 1 -> (1.1)Mainline Build
12896 2->(1.04) Stability Build
12897 */
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012898 if (((versionReported.major>0) || (versionReported.minor>1) ||
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012899 ((versionReported.minor>=1) && (versionReported.version>=1)))
12900 && ((versionReported.major == 1) && (versionReported.minor >= 1)))
12901 fwFeatCapsMsgSupported = 1;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012902
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012903 if (fwFeatCapsMsgSupported)
Yathish9f22e662012-12-10 14:21:35 -080012904 {
12905#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
12906 if(!pHddCtx->cfg_ini->fEnableActiveModeOffload)
12907 sme_disableFeatureCapablity(WLANACTIVE_OFFLOAD);
12908#endif
Ravi Joshid2ca7c42013-07-23 08:37:49 -070012909 /* Indicate if IBSS heartbeat monitoring needs to be offloaded */
12910 if (!pHddCtx->cfg_ini->enableIbssHeartBeatOffload)
12911 {
12912 sme_disableFeatureCapablity(IBSS_HEARTBEAT_OFFLOAD);
12913 }
12914
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053012915 hdd_get_feature_caps(pHddCtx);
Yathish9f22e662012-12-10 14:21:35 -080012916 }
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012917
12918 } while (0);
12919
12920}
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053012921
Neelansh Mittaledafed22014-09-04 18:54:39 +053012922void wlan_hdd_send_svc_nlink_msg(int type, void *data, int len)
12923{
12924 struct sk_buff *skb;
12925 struct nlmsghdr *nlh;
12926 tAniMsgHdr *ani_hdr;
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053012927 int flags = GFP_KERNEL;
Bhargav shah23c94942015-10-13 12:48:35 +053012928 void *nl_data = NULL;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012929
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053012930 if (in_interrupt() || irqs_disabled() || in_atomic())
12931 flags = GFP_ATOMIC;
12932
12933 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
Neelansh Mittaledafed22014-09-04 18:54:39 +053012934
12935 if(skb == NULL) {
12936 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12937 "%s: alloc_skb failed", __func__);
12938 return;
12939 }
12940
12941 nlh = (struct nlmsghdr *)skb->data;
12942 nlh->nlmsg_pid = 0; /* from kernel */
12943 nlh->nlmsg_flags = 0;
12944 nlh->nlmsg_seq = 0;
12945 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12946
12947 ani_hdr = NLMSG_DATA(nlh);
12948 ani_hdr->type = type;
12949
12950 switch(type) {
12951 case WLAN_SVC_SAP_RESTART_IND:
12952 ani_hdr->length = 0;
12953 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
12954 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr)));
12955 break;
Bhargav Shahd0715912015-10-01 18:17:37 +053012956 case WLAN_SVC_WLAN_TP_IND:
12957 ani_hdr->length = len;
12958 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)
12959 + len));
12960 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12961 memcpy(nl_data, data, len);
12962 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
12963 break;
Bhargav shah23c94942015-10-13 12:48:35 +053012964 case WLAN_MSG_RPS_ENABLE_IND:
12965 ani_hdr->length = len;
12966 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12967 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12968 memcpy(nl_data, data, len);
12969 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
12970 break;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012971 default:
12972 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12973 "Attempt to send unknown nlink message %d", type);
12974 kfree_skb(skb);
12975 return;
12976 }
12977
12978 nl_srv_bcast(skb);
12979
12980 return;
12981}
12982
Bhargav Shahd0715912015-10-01 18:17:37 +053012983/**
12984 * hdd_request_tcp_delack() - Find the Delack value based on RX packet
12985 * @pHddCtx: Valid Global HDD context pointer
12986 * @rx_packets: Number of RX packet in perticular time
12987 *
12988 * Based on the RX packet this function calculate next value of tcp delack.
12989 * This function compare rx packet value to high and low threshold limit.
12990 *
12991 * Return: void
12992 */
12993void hdd_request_tcp_delack(hdd_context_t *pHddCtx, uint64_t rx_packets)
12994{
12995 /* average of rx_packets and prev_rx is taken so that
12996 bus width doesnot fluctuate much */
12997 uint64_t temp_rx = (rx_packets + pHddCtx->prev_rx)/2;
Alok Kumarf3724462018-04-05 15:18:54 +053012998 enum wlan_tp_level next_rx_level = pHddCtx->cur_rx_level;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012999
Bhargav Shahd0715912015-10-01 18:17:37 +053013000 pHddCtx->prev_rx = rx_packets;
13001 if (temp_rx > pHddCtx->cfg_ini->tcpDelAckThresholdHigh)
Alok Kumarf3724462018-04-05 15:18:54 +053013002 next_rx_level = WLAN_SVC_TP_HIGH;
Bhargav Shahd0715912015-10-01 18:17:37 +053013003 else if (temp_rx <= pHddCtx->cfg_ini->tcpDelAckThresholdLow)
Alok Kumarf3724462018-04-05 15:18:54 +053013004 next_rx_level = WLAN_SVC_TP_LOW;
Bhargav Shahd0715912015-10-01 18:17:37 +053013005
13006 hdd_set_delack_value(pHddCtx, next_rx_level);
13007}
13008
13009#define HDD_BW_GET_DIFF(x, y) ((x) >= (y) ? (x) - (y) : (ULONG_MAX - (y) + (x)))
13010
13011/**
13012 * hdd_tcp_delack_compute_function() - get link status
13013 * @priv: Valid Global HDD context pointer
13014 *
13015 * This function find number of RX packet during timer life span.
13016 * It request tcp delack with number of RX packet and re-configure delack timer
13017 * for tcpDelAckComputeInterval timer interval.
13018 *
13019 * Return: void
13020 */
13021void hdd_tcp_delack_compute_function(void *priv)
13022{
13023 hdd_context_t *pHddCtx = (hdd_context_t *)priv;
13024 hdd_adapter_t *pAdapter = NULL;
13025 v_U32_t rx_packets = 0;
13026 hdd_adapter_list_node_t *pAdapterNode = NULL;
13027 VOS_STATUS status = 0;
13028
13029 for (status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
13030 NULL != pAdapterNode && VOS_STATUS_SUCCESS == status;
13031 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pAdapterNode)) {
13032 if ((pAdapter = pAdapterNode->pAdapter) == NULL)
13033 continue;
13034
13035 rx_packets += HDD_BW_GET_DIFF(pAdapter->stats.rx_packets,
13036 pAdapter->prev_rx_packets);
13037 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
13038 }
13039
13040 hdd_request_tcp_delack(pHddCtx, rx_packets);
13041
13042 vos_timer_start(&pHddCtx->delack_timer,
13043 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
13044}
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070013045
13046/**---------------------------------------------------------------------------
13047
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013048 \brief hdd_is_5g_supported() - HDD function to know if hardware supports 5GHz
13049
13050 \param - pHddCtx - Pointer to the hdd context
13051
13052 \return - true if hardware supports 5GHz
13053
13054 --------------------------------------------------------------------------*/
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +053013055boolean hdd_is_5g_supported(hdd_context_t * pHddCtx)
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013056{
13057 /* If wcnss_wlan_iris_xo_mode() returns WCNSS_XO_48MHZ(1);
13058 * then hardware support 5Ghz.
13059 */
13060 if (WCNSS_XO_48MHZ == wcnss_wlan_iris_xo_mode())
13061 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053013062 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware supports 5Ghz", __func__);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013063 return true;
13064 }
13065 else
13066 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053013067 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware doesn't supports 5Ghz",
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013068 __func__);
13069 return false;
13070 }
13071}
13072
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013073/**---------------------------------------------------------------------------
13074
13075 \brief hdd_generate_iface_mac_addr_auto() - HDD Mac Interface Auto
13076 generate function
13077
13078 This is generate the random mac address for WLAN interface
13079
13080 \param - pHddCtx - Pointer to HDD context
13081 idx - Start interface index to get auto
13082 generated mac addr.
13083 mac_addr - Mac address
13084
13085 \return - 0 for success, < 0 for failure
13086
13087 --------------------------------------------------------------------------*/
13088
13089static int hdd_generate_iface_mac_addr_auto(hdd_context_t *pHddCtx,
13090 int idx, v_MACADDR_t mac_addr)
13091{
13092 int i;
13093 unsigned int serialno;
13094 serialno = wcnss_get_serial_number();
13095
13096 if (0 != serialno)
13097 {
13098 /* MAC address has 3 bytes of OUI so we have a maximum of 3
13099 bytes of the serial number that can be used to generate
13100 the other 3 bytes of the MAC address. Mask off all but
13101 the lower 3 bytes (this will also make sure we don't
13102 overflow in the next step) */
13103 serialno &= 0x00FFFFFF;
13104
13105 /* we need a unique address for each session */
13106 serialno *= VOS_MAX_CONCURRENCY_PERSONA;
13107
13108 /* autogen other Mac addresses */
13109 for (i = idx; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
13110 {
13111 /* start with the entire default address */
13112 pHddCtx->cfg_ini->intfMacAddr[i] = mac_addr;
13113 /* then replace the lower 3 bytes */
13114 pHddCtx->cfg_ini->intfMacAddr[i].bytes[3] = (serialno >> 16) & 0xFF;
13115 pHddCtx->cfg_ini->intfMacAddr[i].bytes[4] = (serialno >> 8) & 0xFF;
13116 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] = serialno & 0xFF;
13117
Nachiket Kukadede2e24f2017-09-25 16:24:27 +053013118 if (0 == memcmp(&pHddCtx->cfg_ini->intfMacAddr[i].bytes[0],
13119 &mac_addr.bytes[0], VOS_MAC_ADDR_SIZE))
13120 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] +=
13121 VOS_MAX_CONCURRENCY_PERSONA;
13122
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013123 serialno++;
13124 hddLog(VOS_TRACE_LEVEL_ERROR,
13125 "%s: Derived Mac Addr: "
13126 MAC_ADDRESS_STR, __func__,
13127 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[i].bytes));
13128 }
13129
13130 }
13131 else
13132 {
13133 hddLog(LOGE, FL("Failed to Get Serial NO"));
13134 return -1;
13135 }
13136 return 0;
13137}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013138
Katya Nigame7b69a82015-04-28 15:24:06 +053013139int wlan_hdd_mon_open(hdd_context_t *pHddCtx)
13140{
13141 VOS_STATUS status;
13142 v_CONTEXT_t pVosContext= NULL;
13143 hdd_adapter_t *pAdapter= NULL;
13144
13145 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
13146
13147 if (NULL == pVosContext)
13148 {
13149 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13150 "%s: Trying to open VOSS without a PreOpen", __func__);
13151 VOS_ASSERT(0);
13152 return VOS_STATUS_E_FAILURE;
13153 }
13154
13155 status = vos_nv_open();
13156 if (!VOS_IS_STATUS_SUCCESS(status))
13157 {
13158 /* NV module cannot be initialized */
13159 hddLog( VOS_TRACE_LEVEL_FATAL,
13160 "%s: vos_nv_open failed", __func__);
13161 return VOS_STATUS_E_FAILURE;
13162 }
13163
13164 status = vos_init_wiphy_from_nv_bin();
13165 if (!VOS_IS_STATUS_SUCCESS(status))
13166 {
13167 /* NV module cannot be initialized */
13168 hddLog( VOS_TRACE_LEVEL_FATAL,
13169 "%s: vos_init_wiphy failed", __func__);
13170 goto err_vos_nv_close;
13171 }
13172
13173 status = vos_open( &pVosContext, pHddCtx->parent_dev);
13174 if ( !VOS_IS_STATUS_SUCCESS( status ))
13175 {
13176 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
13177 goto err_vos_nv_close;
13178 }
13179
13180 status = vos_mon_start( pVosContext );
13181 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13182 {
13183 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
13184 goto err_vosclose;
13185 }
13186
13187 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053013188 sme_featureCapsExchange(NULL);
Katya Nigame7b69a82015-04-28 15:24:06 +053013189 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
13190
13191 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_MONITOR, "wlan%d",
13192 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
13193 if( pAdapter == NULL )
13194 {
13195 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
13196 goto err_close_adapter;
13197 }
13198
13199 //Initialize the nlink service
13200 if(nl_srv_init() != 0)
13201 {
13202 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
13203 goto err_close_adapter;
13204 }
13205 return VOS_STATUS_SUCCESS;
13206
13207err_close_adapter:
13208 hdd_close_all_adapters( pHddCtx );
13209 vos_mon_stop( pVosContext );
13210err_vosclose:
13211 status = vos_sched_close( pVosContext );
13212 if (!VOS_IS_STATUS_SUCCESS(status)) {
13213 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
13214 "%s: Failed to close VOSS Scheduler", __func__);
13215 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
13216 }
13217 vos_close(pVosContext );
13218
13219err_vos_nv_close:
13220 vos_nv_close();
13221
13222return status;
13223}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013224/**---------------------------------------------------------------------------
13225
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013226 \brief hdd_11d_scan_done - callback to be executed when 11d scan is
13227 completed to flush out the scan results
13228
13229 11d scan is done during driver load and is a passive scan on all
13230 channels supported by the device, 11d scans may find some APs on
13231 frequencies which are forbidden to be used in the regulatory domain
13232 the device is operating in. If these APs are notified to the supplicant
13233 it may try to connect to these APs, thus flush out all the scan results
13234 which are present in SME after 11d scan is done.
13235
13236 \return - eHalStatus
13237
13238 --------------------------------------------------------------------------*/
13239static eHalStatus hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
13240 tANI_U32 scanId, eCsrScanStatus status)
13241{
13242 ENTER();
13243
13244 sme_ScanFlushResult(halHandle, 0);
13245
13246 EXIT();
13247
13248 return eHAL_STATUS_SUCCESS;
13249}
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013250/**---------------------------------------------------------------------------
13251
13252 \brief hdd_init_frame_logging_done - callback to be executed when mgmt frame
13253 logging is completed successfully.
13254
13255 \return - None
13256
13257 --------------------------------------------------------------------------*/
c_manjeecfd1efb2015-09-25 19:32:34 +053013258void hdd_init_frame_logging_done(void *fwlogInitCbContext, tAniLoggingInitRsp *pRsp)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013259{
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013260 hdd_context_t* pHddCtx = (hdd_context_t*)fwlogInitCbContext;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013261
13262 if (NULL == pHddCtx)
13263 {
13264 hddLog(VOS_TRACE_LEVEL_ERROR,
13265 "%s: HDD context is NULL",__func__);
13266 return;
13267 }
13268
c_manjeecfd1efb2015-09-25 19:32:34 +053013269 if ((pRsp->status == VOS_STATUS_SUCCESS) &&
Mahesh A Saptasagarfabb1a02015-06-29 12:17:04 +053013270 (TRUE == pHddCtx->cfg_ini->enableMgmtLogging))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013271 {
13272 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init successful"));
13273 pHddCtx->mgmt_frame_logging = TRUE;
13274 }
13275 else
13276 {
13277 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init not success"));
13278 pHddCtx->mgmt_frame_logging = FALSE;
c_manjeecfd1efb2015-09-25 19:32:34 +053013279 return;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013280 }
13281
c_manjeecfd1efb2015-09-25 19:32:34 +053013282 /*Check feature supported by FW*/
13283 if(TRUE == sme_IsFeatureSupportedByFW(MEMORY_DUMP_SUPPORTED))
13284 {
13285 //Store fwr mem dump size given by firmware.
13286 wlan_store_fwr_mem_dump_size(pRsp->fw_mem_dump_max_size);
13287 }
13288 else
13289 {
13290 wlan_store_fwr_mem_dump_size(0);
13291 }
13292
13293
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013294}
13295/**---------------------------------------------------------------------------
13296
13297 \brief hdd_init_frame_logging - function to initialize frame logging.
13298 Currently only Mgmt Frames are logged in both TX
13299 and Rx direction and are sent to userspace
13300 application using logger thread when queried.
13301
13302 \return - None
13303
13304 --------------------------------------------------------------------------*/
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013305void hdd_init_frame_logging(hdd_context_t* pHddCtx)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013306{
13307 eHalStatus halStatus = eHAL_STATUS_FAILURE;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013308 tSirFWLoggingInitParam wlanFWLoggingInitParam = {0};
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013309
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013310 if (TRUE != sme_IsFeatureSupportedByFW(MGMT_FRAME_LOGGING) &&
13311 TRUE != sme_IsFeatureSupportedByFW(LOGGING_ENHANCEMENT))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013312 {
13313 hddLog(VOS_TRACE_LEVEL_INFO, FL("MGMT_FRAME_LOGGING not supp by FW"));
13314 return;
13315 }
13316
sheenam monga1a0202d2020-01-03 15:20:57 +053013317 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Configuring %s %s %s Logging",__func__,
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013318 pHddCtx->cfg_ini->enableFWLogging?"FW Log,":"",
13319 pHddCtx->cfg_ini->enableContFWLogging ? "Cont FW log,":"",
sheenam monga1a0202d2020-01-03 15:20:57 +053013320 pHddCtx->cfg_ini->enableMgmtLogging ? "Mgmt Pkt Log":"");
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013321
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013322 if (pHddCtx->cfg_ini->enableFWLogging ||
13323 pHddCtx->cfg_ini->enableContFWLogging)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013324 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013325 wlanFWLoggingInitParam.enableFlag |= WLAN_QXDM_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013326 }
13327
Sushant Kaushik46804902015-07-08 14:46:03 +053013328 if (pHddCtx->cfg_ini->enableMgmtLogging)
13329 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013330 wlanFWLoggingInitParam.enableFlag |= WLAN_FRAME_LOG_EN;
Sushant Kaushik46804902015-07-08 14:46:03 +053013331 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013332 if (pHddCtx->cfg_ini->enableBMUHWtracing)
13333 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013334 wlanFWLoggingInitParam.enableFlag |= WLAN_BMUHW_TRACE_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013335 }
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013336 if( wlanFWLoggingInitParam.enableFlag == 0 )
c_manjeecfd1efb2015-09-25 19:32:34 +053013337 {
13338 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Logging not enabled", __func__);
13339 return;
13340 }
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013341 wlanFWLoggingInitParam.frameType = WLAN_FRAME_LOGGING_FRAMETYPE_MGMT;
13342 wlanFWLoggingInitParam.frameSize = WLAN_MGMT_LOGGING_FRAMESIZE_128BYTES;
13343 wlanFWLoggingInitParam.bufferMode = WLAN_FRAME_LOGGING_BUFFERMODE_CIRCULAR;
13344 wlanFWLoggingInitParam.continuousFrameLogging =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013345 pHddCtx->cfg_ini->enableContFWLogging;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013346
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013347 wlanFWLoggingInitParam.enableFlag &= ~WLAN_DPU_TXP_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013348
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013349 wlanFWLoggingInitParam.minLogBufferSize =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013350 pHddCtx->cfg_ini->minLoggingBufferSize;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013351 wlanFWLoggingInitParam.maxLogBufferSize =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013352 pHddCtx->cfg_ini->maxLoggingBufferSize;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013353 wlanFWLoggingInitParam.fwlogInitCallback = hdd_init_frame_logging_done;
13354 wlanFWLoggingInitParam.fwlogInitCbContext= pHddCtx;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013355
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013356 halStatus = sme_InitMgmtFrameLogging(pHddCtx->hHal, &wlanFWLoggingInitParam);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013357
13358 if (eHAL_STATUS_SUCCESS != halStatus)
13359 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013360 hddLog(LOGE, FL("sme_InitMgmtFrameLogging failed, returned %d"),
13361 halStatus);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013362 }
13363
13364 return;
13365}
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013366
Bhargav shah23c94942015-10-13 12:48:35 +053013367static void hdd_dp_util_send_rps_ind(hdd_context_t *hdd_ctxt)
13368{
13369 hdd_adapter_t *adapter;
13370 hdd_adapter_list_node_t *adapter_node, *next;
13371 VOS_STATUS status = VOS_STATUS_SUCCESS;
13372 struct wlan_rps_data rps_data;
13373 int count;
13374
13375 if(!hdd_ctxt->cfg_ini->rps_mask)
13376 {
13377 return;
13378 }
13379
13380 for (count=0; count < WLAN_SVC_IFACE_NUM_QUEUES; count++)
13381 {
13382 rps_data.cpu_map[count] = hdd_ctxt->cfg_ini->rps_mask;
13383 }
13384
13385 rps_data.num_queues = WLAN_SVC_IFACE_NUM_QUEUES;
13386
13387 hddLog(LOG1, FL("0x%x 0x%x 0x%x 0x%x 0x%x 0x%x"),
13388 rps_data.cpu_map[0], rps_data.cpu_map[1],rps_data.cpu_map[2],
13389 rps_data.cpu_map[3], rps_data.cpu_map[4], rps_data.cpu_map[5]);
13390
13391 status = hdd_get_front_adapter (hdd_ctxt, &adapter_node);
13392
13393 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status)
13394 {
13395 adapter = adapter_node->pAdapter;
13396 if (NULL != adapter) {
13397 strlcpy(rps_data.ifname, adapter->dev->name,
13398 sizeof(rps_data.ifname));
13399 wlan_hdd_send_svc_nlink_msg(WLAN_MSG_RPS_ENABLE_IND,
13400 (void *)&rps_data,sizeof(rps_data));
13401 }
13402 status = hdd_get_next_adapter (hdd_ctxt, adapter_node, &next);
13403 adapter_node = next;
13404 }
13405}
13406
Masti, Narayanraddi26378462016-01-05 18:20:28 +053013407void wlan_hdd_schedule_defer_scan(struct work_struct *work)
13408{
13409 scan_context_t *scan_ctx =
13410 container_of(work, scan_context_t, scan_work.work);
13411
13412 if (NULL == scan_ctx)
13413 {
13414 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13415 FL("scan_ctx is NULL"));
13416 return;
13417 }
13418
13419 if (unlikely(TDLS_CTX_MAGIC != scan_ctx->magic))
13420 return;
13421
13422 scan_ctx->attempt++;
13423
13424 wlan_hdd_cfg80211_scan(scan_ctx->wiphy,
13425#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13426 scan_ctx->dev,
13427#endif
13428 scan_ctx->scan_request);
13429}
13430
13431int wlan_hdd_copy_defer_scan_context(hdd_context_t *pHddCtx,
13432 struct wiphy *wiphy,
13433#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13434 struct net_device *dev,
13435#endif
13436 struct cfg80211_scan_request *request)
13437{
13438 scan_context_t *scan_ctx;
13439
13440 ENTER();
13441 if (0 != (wlan_hdd_validate_context(pHddCtx)))
13442 {
13443 return -1;
13444 }
13445
13446 scan_ctx = &pHddCtx->scan_ctxt;
13447
13448 scan_ctx->wiphy = wiphy;
13449#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13450 scan_ctx->dev = dev;
13451#endif
13452
13453 scan_ctx->scan_request = request;
13454
13455 EXIT();
13456 return 0;
13457}
13458
13459void wlan_hdd_defer_scan_init_work(hdd_context_t *pHddCtx,
13460 struct wiphy *wiphy,
13461#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13462 struct net_device *dev,
13463#endif
13464 struct cfg80211_scan_request *request,
13465 unsigned long delay)
13466{
13467 if (TDLS_CTX_MAGIC != pHddCtx->scan_ctxt.magic)
13468 {
13469#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13470 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, dev, request);
13471#else
13472 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, request);
13473#endif
13474 pHddCtx->scan_ctxt.attempt = 0;
13475 pHddCtx->scan_ctxt.magic = TDLS_CTX_MAGIC;
13476 }
13477 schedule_delayed_work(&pHddCtx->scan_ctxt.scan_work, delay);
13478}
13479
13480void wlan_hdd_init_deinit_defer_scan_context(scan_context_t *scan_ctx)
13481{
13482 scan_ctx->magic = 0;
13483 scan_ctx->attempt = 0;
13484 scan_ctx->reject = 0;
13485 scan_ctx->scan_request = NULL;
13486
13487 return;
13488}
13489
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013490/**---------------------------------------------------------------------------
13491
Jeff Johnson295189b2012-06-20 16:38:30 -070013492 \brief hdd_wlan_startup() - HDD init function
13493
13494 This is the driver startup code executed once a WLAN device has been detected
13495
13496 \param - dev - Pointer to the underlying device
13497
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080013498 \return - 0 for success, < 0 for failure
Jeff Johnson295189b2012-06-20 16:38:30 -070013499
13500 --------------------------------------------------------------------------*/
13501
13502int hdd_wlan_startup(struct device *dev )
13503{
13504 VOS_STATUS status;
13505 hdd_adapter_t *pAdapter = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -070013506 hdd_adapter_t *pP2pAdapter = NULL;
Arunk Khandavalli95608be2019-01-22 13:12:54 +053013507 hdd_adapter_t *softapAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070013508 hdd_context_t *pHddCtx = NULL;
13509 v_CONTEXT_t pVosContext= NULL;
13510#ifdef WLAN_BTAMP_FEATURE
13511 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
13512 WLANBAP_ConfigType btAmpConfig;
13513 hdd_config_t *pConfig;
13514#endif
13515 int ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070013516 struct wiphy *wiphy;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013517 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -070013518
13519 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -070013520 /*
13521 * cfg80211: wiphy allocation
13522 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013523 wiphy = wlan_hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t)) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070013524
13525 if(wiphy == NULL)
13526 {
13527 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080013528 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070013529 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013530 pHddCtx = wiphy_priv(wiphy);
13531
Jeff Johnson295189b2012-06-20 16:38:30 -070013532 //Initialize the adapter context to zeros.
13533 vos_mem_zero(pHddCtx, sizeof( hdd_context_t ));
13534
Jeff Johnson295189b2012-06-20 16:38:30 -070013535 pHddCtx->wiphy = wiphy;
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013536 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Mihir Shete18156292014-03-11 15:38:30 +053013537 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_LOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070013538
13539 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
13540
Siddharth Bhalcd92b782015-06-29 12:25:40 +053013541 /* register for riva power on lock to platform driver
13542 * Locking power early to ensure FW doesn't reset by kernel while
13543 * host driver is busy initializing itself */
13544 if (req_riva_power_on_lock("wlan"))
13545 {
13546 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: req riva power on lock failed",
13547 __func__);
13548 goto err_free_hdd_context;
13549 }
13550
Jeff Johnson295189b2012-06-20 16:38:30 -070013551 /*Get vos context here bcoz vos_open requires it*/
13552 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
13553
Madan Mohan Koyyalamudi0b78e152012-11-28 15:46:51 -080013554 if(pVosContext == NULL)
13555 {
13556 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed vos_get_global_context",__func__);
13557 goto err_free_hdd_context;
13558 }
13559
Jeff Johnson295189b2012-06-20 16:38:30 -070013560 //Save the Global VOSS context in adapter context for future.
13561 pHddCtx->pvosContext = pVosContext;
13562
13563 //Save the adapter context in global context for future.
13564 ((VosContextType*)(pVosContext))->pHDDContext = (v_VOID_t*)pHddCtx;
13565
Jeff Johnson295189b2012-06-20 16:38:30 -070013566 pHddCtx->parent_dev = dev;
Sreelakshmi Konamkif0646d52016-12-09 12:35:31 +053013567 pHddCtx->last_scan_reject_session_id = 0xFF;
13568 pHddCtx->last_scan_reject_reason = 0;
Sreelakshmi Konamki20ebed92016-10-27 12:13:30 +053013569 pHddCtx->last_scan_reject_timestamp = 0;
Abhishek Singhe4b12562017-06-20 16:53:39 +053013570 pHddCtx->scan_reject_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070013571
13572 init_completion(&pHddCtx->full_pwr_comp_var);
13573 init_completion(&pHddCtx->standby_comp_var);
13574 init_completion(&pHddCtx->req_bmps_comp_var);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070013575 init_completion(&pHddCtx->scan_info.scan_req_completion_event);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -080013576 init_completion(&pHddCtx->scan_info.abortscan_event_var);
Kiet Lam46b8e4e2013-11-06 21:49:53 +053013577 init_completion(&pHddCtx->wiphy_channel_update_event);
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053013578 init_completion(&pHddCtx->ssr_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053013579 init_completion(&pHddCtx->mc_sus_event_var);
13580 init_completion(&pHddCtx->tx_sus_event_var);
13581 init_completion(&pHddCtx->rx_sus_event_var);
13582
Amar Singhala49cbc52013-10-08 18:37:44 -070013583
mukul sharma4bd8d2e2015-08-13 20:33:25 +053013584 hdd_init_ll_stats_ctx(pHddCtx);
Anurag Chouhan6ee81542017-02-09 18:09:27 +053013585 hdd_init_nud_stats_ctx(pHddCtx);
mukul sharma4bd8d2e2015-08-13 20:33:25 +053013586
Amar Singhala49cbc52013-10-08 18:37:44 -070013587#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhalfddc28c2013-09-05 13:03:40 -070013588 init_completion(&pHddCtx->linux_reg_req);
Amar Singhala49cbc52013-10-08 18:37:44 -070013589#else
13590 init_completion(&pHddCtx->driver_crda_req);
13591#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013592
Padma, Santhosh Kumara1aa4a32015-06-19 19:00:46 +053013593#ifdef WLAN_FEATURE_EXTSCAN
13594 init_completion(&pHddCtx->ext_scan_context.response_event);
13595#endif /* WLAN_FEATURE_EXTSCAN */
13596
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053013597 spin_lock_init(&pHddCtx->schedScan_lock);
Kapil Gupta137ef892016-12-13 19:38:00 +053013598 vos_spin_lock_init(&pHddCtx->sap_update_info_lock);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053013599
Jeff Johnson295189b2012-06-20 16:38:30 -070013600 hdd_list_init( &pHddCtx->hddAdapters, MAX_NUMBER_OF_ADAPTERS );
13601
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053013602 vos_init_delayed_work(&pHddCtx->spoof_mac_addr_work,
13603 hdd_processSpoofMacAddrRequest);
Kapil Gupta137ef892016-12-13 19:38:00 +053013604 vos_init_work(&pHddCtx->sap_start_work, hdd_sap_restart_handle);
Abhishek Singh78c691f2017-11-30 13:48:44 +053013605 vos_init_delayed_work(&pHddCtx->ecsa_chan_change_work,
13606 hdd_force_scc_with_ecsa_handle);
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053013607
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053013608#ifdef FEATURE_WLAN_TDLS
13609 /* tdls_lock is initialized before an hdd_open_adapter ( which is
13610 * invoked by other instances also) to protect the concurrent
13611 * access for the Adapters by TDLS module.
13612 */
13613 mutex_init(&pHddCtx->tdls_lock);
13614#endif
Siddharth Bhal76972212014-10-15 16:22:51 +053013615 mutex_init(&pHddCtx->spoofMacAddr.macSpoofingLock);
Mukul Sharma1fd6efd2015-02-14 00:29:14 +053013616 mutex_init(&pHddCtx->wmmLock);
13617
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +053013618 hdd_init_offloaded_packets_ctx(pHddCtx);
Agarwal Ashish1f422872014-07-22 00:11:55 +053013619 /* By default Strict Regulatory For FCC should be false */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053013620
Agarwal Ashish1f422872014-07-22 00:11:55 +053013621 pHddCtx->nEnableStrictRegulatoryForFCC = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070013622 // Load all config first as TL config is needed during vos_open
13623 pHddCtx->cfg_ini = (hdd_config_t*) kmalloc(sizeof(hdd_config_t), GFP_KERNEL);
13624 if(pHddCtx->cfg_ini == NULL)
13625 {
13626 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed kmalloc hdd_config_t",__func__);
13627 goto err_free_hdd_context;
13628 }
13629
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053013630 hdd_request_manager_init();
13631
Jeff Johnson295189b2012-06-20 16:38:30 -070013632 vos_mem_zero(pHddCtx->cfg_ini, sizeof( hdd_config_t ));
13633
13634 // Read and parse the qcom_cfg.ini file
13635 status = hdd_parse_config_ini( pHddCtx );
13636 if ( VOS_STATUS_SUCCESS != status )
13637 {
13638 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: error parsing %s",
13639 __func__, WLAN_INI_FILE);
13640 goto err_config;
13641 }
Arif Hussaind5218912013-12-05 01:10:55 -080013642#ifdef MEMORY_DEBUG
13643 if (pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled)
13644 vos_mem_init();
13645
13646 hddLog(VOS_TRACE_LEVEL_INFO, "%s: gEnableMemoryDebug=%d",
13647 __func__, pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled);
13648#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013649
Gopichand Nakkalab8f0f1a2013-05-23 18:19:48 +053013650 /* INI has been read, initialise the configuredMcastBcastFilter with
13651 * INI value as this will serve as the default value
13652 */
13653 pHddCtx->configuredMcastBcastFilter = pHddCtx->cfg_ini->mcastBcastFilterSetting;
13654 hddLog(VOS_TRACE_LEVEL_INFO, "Setting configuredMcastBcastFilter: %d",
13655 pHddCtx->cfg_ini->mcastBcastFilterSetting);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013656
13657 if (false == hdd_is_5g_supported(pHddCtx))
13658 {
13659 //5Ghz is not supported.
13660 if (1 != pHddCtx->cfg_ini->nBandCapability)
13661 {
13662 hddLog(VOS_TRACE_LEVEL_INFO,
13663 "%s: Setting pHddCtx->cfg_ini->nBandCapability = 1", __func__);
13664 pHddCtx->cfg_ini->nBandCapability = 1;
13665 }
13666 }
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +053013667
13668 /* If SNR Monitoring is enabled, FW has to parse all beacons
13669 * for calcaluting and storing the average SNR, so set Nth beacon
13670 * filter to 1 to enable FW to parse all the beaocons
13671 */
13672 if (1 == pHddCtx->cfg_ini->fEnableSNRMonitoring)
13673 {
13674 /* The log level is deliberately set to WARN as overriding
13675 * nthBeaconFilter to 1 will increase power cosumption and this
13676 * might just prove helpful to detect the power issue.
13677 */
13678 hddLog(VOS_TRACE_LEVEL_WARN,
13679 "%s: Setting pHddCtx->cfg_ini->nthBeaconFilter = 1", __func__);
13680 pHddCtx->cfg_ini->nthBeaconFilter = 1;
13681 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013682 /*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013683 * cfg80211: Initialization ...
Jeff Johnson295189b2012-06-20 16:38:30 -070013684 */
Manjeet Singh61016fa2016-12-02 11:10:19 +053013685 if (0 < wlan_hdd_cfg80211_init(dev, wiphy, pHddCtx->cfg_ini))
Jeff Johnson295189b2012-06-20 16:38:30 -070013686 {
Manjeet Singh61016fa2016-12-02 11:10:19 +053013687 hddLog(VOS_TRACE_LEVEL_FATAL,
13688 "%s: wlan_hdd_cfg80211_init return failure", __func__);
13689 goto err_config;
Jeff Johnson295189b2012-06-20 16:38:30 -070013690 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013691
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013692 // Update VOS trace levels based upon the cfg.ini
13693 hdd_vos_trace_enable(VOS_MODULE_ID_BAP,
13694 pHddCtx->cfg_ini->vosTraceEnableBAP);
13695 hdd_vos_trace_enable(VOS_MODULE_ID_TL,
13696 pHddCtx->cfg_ini->vosTraceEnableTL);
13697 hdd_vos_trace_enable(VOS_MODULE_ID_WDI,
13698 pHddCtx->cfg_ini->vosTraceEnableWDI);
13699 hdd_vos_trace_enable(VOS_MODULE_ID_HDD,
13700 pHddCtx->cfg_ini->vosTraceEnableHDD);
13701 hdd_vos_trace_enable(VOS_MODULE_ID_SME,
13702 pHddCtx->cfg_ini->vosTraceEnableSME);
13703 hdd_vos_trace_enable(VOS_MODULE_ID_PE,
13704 pHddCtx->cfg_ini->vosTraceEnablePE);
Katya Nigam70d68332013-09-16 16:49:45 +053013705 hdd_vos_trace_enable(VOS_MODULE_ID_PMC,
13706 pHddCtx->cfg_ini->vosTraceEnablePMC);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013707 hdd_vos_trace_enable(VOS_MODULE_ID_WDA,
13708 pHddCtx->cfg_ini->vosTraceEnableWDA);
13709 hdd_vos_trace_enable(VOS_MODULE_ID_SYS,
13710 pHddCtx->cfg_ini->vosTraceEnableSYS);
13711 hdd_vos_trace_enable(VOS_MODULE_ID_VOSS,
13712 pHddCtx->cfg_ini->vosTraceEnableVOSS);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013713 hdd_vos_trace_enable(VOS_MODULE_ID_SAP,
13714 pHddCtx->cfg_ini->vosTraceEnableSAP);
13715 hdd_vos_trace_enable(VOS_MODULE_ID_HDD_SOFTAP,
13716 pHddCtx->cfg_ini->vosTraceEnableHDDSAP);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013717
Jeff Johnson295189b2012-06-20 16:38:30 -070013718 // Update WDI trace levels based upon the cfg.ini
13719 hdd_wdi_trace_enable(eWLAN_MODULE_DAL,
13720 pHddCtx->cfg_ini->wdiTraceEnableDAL);
13721 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_CTRL,
13722 pHddCtx->cfg_ini->wdiTraceEnableCTL);
13723 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_DATA,
13724 pHddCtx->cfg_ini->wdiTraceEnableDAT);
13725 hdd_wdi_trace_enable(eWLAN_MODULE_PAL,
13726 pHddCtx->cfg_ini->wdiTraceEnablePAL);
Jeff Johnson295189b2012-06-20 16:38:30 -070013727
Jeff Johnson88ba7742013-02-27 14:36:02 -080013728 if (VOS_FTM_MODE == hdd_get_conparam())
13729 {
Jeff Johnson295189b2012-06-20 16:38:30 -070013730 if ( VOS_STATUS_SUCCESS != wlan_hdd_ftm_open(pHddCtx) )
13731 {
13732 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_ftm_open Failed",__func__);
13733 goto err_free_hdd_context;
13734 }
13735 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: FTM driver loaded success fully",__func__);
Sachin Ahuja38ef5e02015-03-13 17:31:16 +053013736 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
c_hpothu2de0ef62014-04-15 16:16:15 +053013737 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -070013738 return VOS_STATUS_SUCCESS;
Jeff Johnson88ba7742013-02-27 14:36:02 -080013739 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013740
Katya Nigame7b69a82015-04-28 15:24:06 +053013741 if( VOS_MONITOR_MODE == hdd_get_conparam())
13742 {
13743 if ( VOS_STATUS_SUCCESS != wlan_hdd_mon_open(pHddCtx))
13744 {
13745 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_mon_open Failed",__func__);
13746 goto err_free_hdd_context;
13747 }
13748 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Driver loaded in Monitor Mode",__func__);
13749 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
13750 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
13751 return VOS_STATUS_SUCCESS;
13752 }
13753
Jeff Johnson88ba7742013-02-27 14:36:02 -080013754 //Open watchdog module
Jeff Johnson295189b2012-06-20 16:38:30 -070013755 if(pHddCtx->cfg_ini->fIsLogpEnabled)
13756 {
13757 status = vos_watchdog_open(pVosContext,
13758 &((VosContextType*)pVosContext)->vosWatchdog, sizeof(VosWatchdogContext));
13759
13760 if(!VOS_IS_STATUS_SUCCESS( status ))
13761 {
13762 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_watchdog_open failed",__func__);
Ashish Kumar Dhanotiya532bdef2017-05-09 17:31:59 +053013763 goto err_config;
Jeff Johnson295189b2012-06-20 16:38:30 -070013764 }
13765 }
13766
13767 pHddCtx->isLogpInProgress = FALSE;
13768 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
13769
Amar Singhala49cbc52013-10-08 18:37:44 -070013770#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070013771 /* initialize the NV module. This is required so that
13772 we can initialize the channel information in wiphy
13773 from the NV.bin data. The channel information in
13774 wiphy needs to be initialized before wiphy registration */
13775
13776 status = vos_nv_open();
13777 if (!VOS_IS_STATUS_SUCCESS(status))
13778 {
13779 /* NV module cannot be initialized */
13780 hddLog( VOS_TRACE_LEVEL_FATAL,
13781 "%s: vos_nv_open failed", __func__);
Vinay Krishna Eranna2025d892014-09-18 16:51:42 +053013782 goto err_wdclose;
Amar Singhal0a402232013-10-11 20:57:16 -070013783 }
13784
13785 status = vos_init_wiphy_from_nv_bin();
13786 if (!VOS_IS_STATUS_SUCCESS(status))
13787 {
13788 /* NV module cannot be initialized */
13789 hddLog( VOS_TRACE_LEVEL_FATAL,
13790 "%s: vos_init_wiphy failed", __func__);
13791 goto err_vos_nv_close;
13792 }
13793
Amar Singhala49cbc52013-10-08 18:37:44 -070013794#endif
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013795 //Initialize the nlink service
13796 if(nl_srv_init() != 0)
13797 {
13798 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
13799 goto err_vos_nv_close;
13800 }
13801
13802#ifdef WLAN_KD_READY_NOTIFIER
13803 pHddCtx->kd_nl_init = 1;
13804#endif /* WLAN_KD_READY_NOTIFIER */
13805
Girish Gowlibf0e1ab2015-01-19 16:05:16 +053013806 vos_set_roam_delay_stats_enabled(pHddCtx->cfg_ini->gEnableRoamDelayStats);
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053013807 status = vos_open( &pVosContext, pHddCtx->parent_dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070013808 if ( !VOS_IS_STATUS_SUCCESS( status ))
13809 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013810 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013811 goto err_nl_srv;
Jeff Johnson295189b2012-06-20 16:38:30 -070013812 }
13813
Jeff Johnson295189b2012-06-20 16:38:30 -070013814 pHddCtx->hHal = (tHalHandle)vos_get_context( VOS_MODULE_ID_SME, pVosContext );
13815
13816 if ( NULL == pHddCtx->hHal )
13817 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013818 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: HAL context is null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070013819 goto err_vosclose;
13820 }
13821
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013822 status = vos_preStart( pHddCtx->pvosContext );
13823 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13824 {
13825 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_preStart failed", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013826 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013827 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013828
Arif Hussaineaf68602013-12-30 23:10:44 -080013829 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan)
13830 {
13831 pHddCtx->cfg_ini->enableDFSChnlScan = enable_dfs_chan_scan;
13832 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_dfs_chan_scan set to %d",
13833 __func__, enable_dfs_chan_scan);
13834 }
13835 if (0 == enable_11d || 1 == enable_11d)
13836 {
13837 pHddCtx->cfg_ini->Is11dSupportEnabled = enable_11d;
13838 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_11d set to %d",
13839 __func__, enable_11d);
13840 }
13841
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013842 /* Note that the vos_preStart() sequence triggers the cfg download.
13843 The cfg download must occur before we update the SME config
13844 since the SME config operation must access the cfg database */
Jeff Johnson295189b2012-06-20 16:38:30 -070013845 status = hdd_set_sme_config( pHddCtx );
13846
13847 if ( VOS_STATUS_SUCCESS != status )
13848 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013849 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed hdd_set_sme_config", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013850 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013851 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013852
Jeff Johnson295189b2012-06-20 16:38:30 -070013853 /* In the integrated architecture we update the configuration from
13854 the INI file and from NV before vOSS has been started so that
13855 the final contents are available to send down to the cCPU */
13856
13857 // Apply the cfg.ini to cfg.dat
13858 if (FALSE == hdd_update_config_dat(pHddCtx))
13859 {
13860 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013861 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013862 }
13863
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013864 // Get mac addr from platform driver
13865 ret = wcnss_get_wlan_mac_address((char*)&mac_addr.bytes);
13866
13867 if ((0 == ret) && (!vos_is_macaddr_zero(&mac_addr)))
Jeff Johnson295189b2012-06-20 16:38:30 -070013868 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013869 /* Store the mac addr for first interface */
13870 pHddCtx->cfg_ini->intfMacAddr[0] = mac_addr;
13871
13872 hddLog(VOS_TRACE_LEVEL_ERROR,
13873 "%s: WLAN Mac Addr: "
13874 MAC_ADDRESS_STR, __func__,
13875 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
13876
13877 /* Here, passing Arg2 as 1 because we do not want to change the
13878 last 3 bytes (means non OUI bytes) of first interface mac
13879 addr.
13880 */
13881 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 1, mac_addr))
13882 {
13883 hddLog(VOS_TRACE_LEVEL_ERROR,
13884 "%s: Failed to generate wlan interface mac addr "
13885 "using MAC from ini file ", __func__);
13886 }
13887 }
13888 else if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
13889 {
13890 // Apply the NV to cfg.dat
13891 /* Prima Update MAC address only at here */
Jeff Johnson295189b2012-06-20 16:38:30 -070013892#ifdef WLAN_AUTOGEN_MACADDR_FEATURE
13893 /* There was not a valid set of MAC Addresses in NV. See if the
13894 default addresses were modified by the cfg.ini settings. If so,
13895 we'll use them, but if not, we'll autogenerate a set of MAC
13896 addresses based upon the device serial number */
13897
13898 static const v_MACADDR_t default_address =
13899 {{0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}};
Jeff Johnson295189b2012-06-20 16:38:30 -070013900
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013901 if (0 == memcmp(&default_address, &pHddCtx->cfg_ini->intfMacAddr[0],
13902 sizeof(default_address)))
Jeff Johnson295189b2012-06-20 16:38:30 -070013903 {
13904 /* cfg.ini has the default address, invoke autogen logic */
13905
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013906 /* Here, passing Arg2 as 0 because we want to change the
13907 last 3 bytes (means non OUI bytes) of all the interfaces
13908 mac addr.
13909 */
13910 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 0,
13911 default_address))
Jeff Johnson295189b2012-06-20 16:38:30 -070013912 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013913 hddLog(VOS_TRACE_LEVEL_ERROR,
13914 "%s: Failed to generate wlan interface mac addr "
13915 "using MAC from ini file " MAC_ADDRESS_STR, __func__,
13916 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
Jeff Johnson295189b2012-06-20 16:38:30 -070013917 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013918 }
13919 else
13920#endif //WLAN_AUTOGEN_MACADDR_FEATURE
13921 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013922 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -070013923 "%s: Invalid MAC address in NV, using MAC from ini file "
13924 MAC_ADDRESS_STR, __func__,
13925 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
13926 }
13927 }
13928 {
13929 eHalStatus halStatus;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013930
13931 /* Set the MAC Address Currently this is used by HAL to
13932 * add self sta. Remove this once self sta is added as
13933 * part of session open.
13934 */
Jeff Johnson295189b2012-06-20 16:38:30 -070013935 halStatus = cfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
13936 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
13937 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]) );
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013938
Jeff Johnson295189b2012-06-20 16:38:30 -070013939 if (!HAL_STATUS_SUCCESS( halStatus ))
13940 {
13941 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
13942 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013943 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013944 }
13945 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013946
13947 /*Start VOSS which starts up the SME/MAC/HAL modules and everything else
13948 Note: Firmware image will be read and downloaded inside vos_start API */
13949 status = vos_start( pHddCtx->pvosContext );
13950 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13951 {
13952 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053013953 if (isSsrPanicOnFailure())
13954 VOS_BUG(0);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013955 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013956 }
13957
Leo Chang6cec3e22014-01-21 15:33:49 -080013958#ifdef FEATURE_WLAN_CH_AVOID
13959 /* Plug in avoid channel notification callback
13960 * This should happen before ADD_SELF_STA
13961 * FW will send first IND with ADD_SELF_STA REQ from host */
Pradeep Reddy POTTETI5c2e16d2014-06-27 16:47:38 +053013962
13963 /* check the Channel Avoidance is enabled */
13964 if (TRUE == pHddCtx->cfg_ini->fenableCHAvoidance)
13965 {
13966 sme_AddChAvoidCallback(pHddCtx->hHal,
13967 hdd_hostapd_ch_avoid_cb);
13968 }
Leo Chang6cec3e22014-01-21 15:33:49 -080013969#endif /* FEATURE_WLAN_CH_AVOID */
13970
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070013971 /* Exchange capability info between Host and FW and also get versioning info from FW */
13972 hdd_exchange_version_and_caps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070013973
Agarwal Ashishad9281b2014-06-10 14:57:30 +053013974#ifdef CONFIG_ENABLE_LINUX_REG
13975 status = wlan_hdd_init_channels(pHddCtx);
13976 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13977 {
13978 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels failed",
13979 __func__);
13980 goto err_vosstop;
13981 }
13982#endif
13983
Jeff Johnson295189b2012-06-20 16:38:30 -070013984 status = hdd_post_voss_start_config( pHddCtx );
13985 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13986 {
13987 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_post_voss_start_config failed",
13988 __func__);
13989 goto err_vosstop;
13990 }
Amar Singhala49cbc52013-10-08 18:37:44 -070013991
Rajeev Kumar Sirasanagandla2bb30b82019-01-07 22:30:16 +053013992 wlan_hdd_cfg80211_scan_randomization_init(wiphy);
13993
Amar Singhala49cbc52013-10-08 18:37:44 -070013994#ifndef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013995 wlan_hdd_cfg80211_update_reg_info( wiphy );
13996
13997 /* registration of wiphy dev with cfg80211 */
13998 if (0 > wlan_hdd_cfg80211_register(wiphy))
13999 {
14000 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
14001 goto err_vosstop;
14002 }
Amar Singhala49cbc52013-10-08 18:37:44 -070014003#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014004
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053014005#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053014006 /* registration of wiphy dev with cfg80211 */
14007 if (0 > wlan_hdd_cfg80211_register(wiphy))
14008 {
14009 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
14010 goto err_vosstop;
14011 }
14012
Agarwal Ashish6db9d532014-09-30 18:19:10 +053014013 status = wlan_hdd_init_channels_for_cc(pHddCtx, INIT);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053014014 if ( !VOS_IS_STATUS_SUCCESS( status ) )
14015 {
14016 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels_for_cc failed",
14017 __func__);
14018 goto err_unregister_wiphy;
14019 }
14020#endif
14021
c_hpothu4a298be2014-12-22 21:12:51 +053014022 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
14023
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053014024#ifdef SAP_AUTH_OFFLOAD
14025 if (!sme_IsFeatureSupportedByFW(SAP_OFFLOADS))
14026 {
14027 hddLog(VOS_TRACE_LEVEL_INFO, FL(" SAP AUTH OFFLOAD not supp by FW"));
14028 pHddCtx->cfg_ini->enable_sap_auth_offload = 0;
14029 }
14030#endif
14031
Jeff Johnson295189b2012-06-20 16:38:30 -070014032 if (VOS_STA_SAP_MODE == hdd_get_conparam())
14033 {
14034 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP, "softap.%d",
14035 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
14036 }
14037 else
14038 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014039 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_INFRA_STATION, "wlan%d",
14040 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
14041 if (pAdapter != NULL)
14042 {
Katya Nigama7d81d72014-11-12 12:44:34 +053014043 if (pHddCtx->cfg_ini->isP2pDeviceAddrAdministrated && !(pHddCtx->cfg_ini->intfMacAddr[0].bytes[0] & 0x02))
Jeff Johnson295189b2012-06-20 16:38:30 -070014044 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053014045 vos_mem_copy( pHddCtx->p2pDeviceAddress.bytes,
14046 pHddCtx->cfg_ini->intfMacAddr[0].bytes,
14047 sizeof(tSirMacAddr));
Madan Mohan Koyyalamudiedfc1b72012-10-18 20:25:55 -070014048
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053014049 /* Generate the P2P Device Address. This consists of the device's
14050 * primary MAC address with the locally administered bit set.
14051 */
14052 pHddCtx->p2pDeviceAddress.bytes[0] |= 0x02;
Jeff Johnsone7245742012-09-05 17:12:55 -070014053 }
14054 else
14055 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053014056 tANI_U8* p2p_dev_addr = wlan_hdd_get_intf_addr(pHddCtx);
14057 if (p2p_dev_addr != NULL)
14058 {
14059 vos_mem_copy(&pHddCtx->p2pDeviceAddress.bytes[0],
14060 p2p_dev_addr, VOS_MAC_ADDR_SIZE);
14061 }
14062 else
14063 {
14064 hddLog(VOS_TRACE_LEVEL_FATAL,
14065 "%s: Failed to allocate mac_address for p2p_device",
14066 __func__);
14067 goto err_close_adapter;
14068 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014069 }
Jeff Johnsone7245742012-09-05 17:12:55 -070014070
14071 pP2pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_P2P_DEVICE, "p2p%d",
14072 &pHddCtx->p2pDeviceAddress.bytes[0], FALSE );
14073 if ( NULL == pP2pAdapter )
14074 {
14075 hddLog(VOS_TRACE_LEVEL_FATAL,
14076 "%s: Failed to do hdd_open_adapter for P2P Device Interface",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070014077 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070014078 goto err_close_adapter;
14079 }
Jeff Johnsone7245742012-09-05 17:12:55 -070014080 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014081 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014082
14083 if( pAdapter == NULL )
14084 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080014085 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
14086 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070014087 }
Jeff Johnsone7245742012-09-05 17:12:55 -070014088
Ashish Kumar Dhanotiya3ac85a22019-02-12 19:10:14 +053014089 if ((strlen(pHddCtx->cfg_ini->enabledefaultSAP) != 0) &&
14090 (strcmp(pHddCtx->cfg_ini->enabledefaultSAP, "") != 0)) {
Arunk Khandavalli95608be2019-01-22 13:12:54 +053014091 softapAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP,
14092 pHddCtx->cfg_ini->enabledefaultSAP,
14093 wlan_hdd_get_intf_addr(pHddCtx), FALSE);
14094 if (!softapAdapter) {
14095 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
14096 goto err_close_adapter;
14097 }
14098 }
14099
Arif Hussain66559122013-11-21 10:11:40 -080014100 if (country_code)
14101 {
14102 eHalStatus ret;
Arif Hussaincb607082013-12-20 11:57:42 -080014103 INIT_COMPLETION(pAdapter->change_country_code);
Arif Hussain66559122013-11-21 10:11:40 -080014104 hdd_checkandupdate_dfssetting(pAdapter, country_code);
14105#ifndef CONFIG_ENABLE_LINUX_REG
14106 hdd_checkandupdate_phymode(pAdapter, country_code);
14107#endif
Arif Hussaineaf68602013-12-30 23:10:44 -080014108 ret = sme_ChangeCountryCode(pHddCtx->hHal,
14109 (void *)(tSmeChangeCountryCallback)
14110 wlan_hdd_change_country_code_callback,
Arif Hussain66559122013-11-21 10:11:40 -080014111 country_code,
14112 pAdapter, pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +053014113 eSIR_TRUE, eSIR_TRUE);
Arif Hussain66559122013-11-21 10:11:40 -080014114 if (eHAL_STATUS_SUCCESS == ret)
14115 {
Arif Hussaincb607082013-12-20 11:57:42 -080014116 ret = wait_for_completion_interruptible_timeout(
14117 &pAdapter->change_country_code,
14118 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
14119
14120 if (0 >= ret)
14121 {
14122 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14123 "%s: SME while setting country code timed out", __func__);
14124 }
Arif Hussain66559122013-11-21 10:11:40 -080014125 }
14126 else
14127 {
Arif Hussaincb607082013-12-20 11:57:42 -080014128 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14129 "%s: SME Change Country code from module param fail ret=%d",
14130 __func__, ret);
Arif Hussain66559122013-11-21 10:11:40 -080014131 }
14132 }
14133
Jeff Johnson295189b2012-06-20 16:38:30 -070014134#ifdef WLAN_BTAMP_FEATURE
14135 vStatus = WLANBAP_Open(pVosContext);
14136 if(!VOS_IS_STATUS_SUCCESS(vStatus))
14137 {
14138 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14139 "%s: Failed to open BAP",__func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070014140 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070014141 }
14142
14143 vStatus = BSL_Init(pVosContext);
14144 if(!VOS_IS_STATUS_SUCCESS(vStatus))
14145 {
14146 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14147 "%s: Failed to Init BSL",__func__);
14148 goto err_bap_close;
14149 }
14150 vStatus = WLANBAP_Start(pVosContext);
14151 if (!VOS_IS_STATUS_SUCCESS(vStatus))
14152 {
14153 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14154 "%s: Failed to start TL",__func__);
14155 goto err_bap_close;
14156 }
14157
14158 pConfig = pHddCtx->cfg_ini;
14159 btAmpConfig.ucPreferredChannel = pConfig->preferredChannel;
14160 status = WLANBAP_SetConfig(&btAmpConfig);
14161
14162#endif //WLAN_BTAMP_FEATURE
Jeff Johnsone7245742012-09-05 17:12:55 -070014163
Mihir Shete9c238772014-10-15 14:35:16 +053014164 /*
14165 * UapsdMask is 0xf if U-APSD is enbaled for all AC's...
14166 * The value of CFG_QOS_WMM_UAPSD_MASK_DEFAULT is 0xaa(Magic Value)
14167 * which is greater than 0xf. So the below check is safe to make
14168 * sure that there is no entry for UapsdMask in the ini
14169 */
14170 if (CFG_QOS_WMM_UAPSD_MASK_DEFAULT == pHddCtx->cfg_ini->UapsdMask)
14171 {
14172 if(IS_DYNAMIC_WMM_PS_ENABLED)
14173 {
14174 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Enable UAPSD for VI & VO",
14175 __func__);
14176 pHddCtx->cfg_ini->UapsdMask =
14177 CFG_QOS_WMM_UAPSD_MASK_DYMANIC_WMM_PS_DEFAULT;
14178 }
14179 else
14180 {
14181 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Do not enable UAPSD",
14182 __func__);
14183 pHddCtx->cfg_ini->UapsdMask =
14184 CFG_QOS_WMM_UAPSD_MASK_LEGACY_WMM_PS_DEFAULT;
14185 }
14186 }
14187
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -070014188#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
14189 if(!(IS_ROAM_SCAN_OFFLOAD_FEATURE_ENABLE))
14190 {
14191 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: ROAM_SCAN_OFFLOAD Feature not supported",__func__);
14192 pHddCtx->cfg_ini->isRoamOffloadScanEnabled = 0;
14193 sme_UpdateRoamScanOffloadEnabled((tHalHandle)(pHddCtx->hHal),
14194 pHddCtx->cfg_ini->isRoamOffloadScanEnabled);
14195 }
14196#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014197
Agarwal Ashish4b87f922014-06-18 03:03:21 +053014198 wlan_hdd_tdls_init(pHddCtx);
14199
Masti, Narayanraddi26378462016-01-05 18:20:28 +053014200 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
14201
14202 vos_init_delayed_work(&pHddCtx->scan_ctxt.scan_work,
14203 wlan_hdd_schedule_defer_scan);
14204
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053014205 sme_Register11dScanDoneCallback(pHddCtx->hHal, hdd_11d_scan_done);
14206
Jeff Johnson295189b2012-06-20 16:38:30 -070014207 /* Register with platform driver as client for Suspend/Resume */
14208 status = hddRegisterPmOps(pHddCtx);
14209 if ( !VOS_IS_STATUS_SUCCESS( status ) )
14210 {
14211 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddRegisterPmOps failed",__func__);
14212#ifdef WLAN_BTAMP_FEATURE
14213 goto err_bap_stop;
14214#else
Jeff Johnsone7245742012-09-05 17:12:55 -070014215 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070014216#endif //WLAN_BTAMP_FEATURE
14217 }
14218
Yue Ma0d4891e2013-08-06 17:01:45 -070014219 /* Open debugfs interface */
14220 if (VOS_STATUS_SUCCESS != hdd_debugfs_init(pAdapter))
14221 {
14222 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14223 "%s: hdd_debugfs_init failed!", __func__);
Yue Ma0d4891e2013-08-06 17:01:45 -070014224 }
14225
Jeff Johnson295189b2012-06-20 16:38:30 -070014226 /* Register TM level change handler function to the platform */
14227 status = hddDevTmRegisterNotifyCallback(pHddCtx);
14228 if ( !VOS_IS_STATUS_SUCCESS( status ) )
14229 {
14230 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmRegisterNotifyCallback failed",__func__);
14231 goto err_unregister_pmops;
14232 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014233
Jeff Johnson295189b2012-06-20 16:38:30 -070014234 // register net device notifier for device change notification
14235 ret = register_netdevice_notifier(&hdd_netdev_notifier);
14236
14237 if(ret < 0)
14238 {
14239 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: register_netdevice_notifier failed",__func__);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053014240 goto err_unregister_pmops;
Jeff Johnson295189b2012-06-20 16:38:30 -070014241 }
14242
Jeff Johnson295189b2012-06-20 16:38:30 -070014243 //Initialize the BTC service
14244 if(btc_activate_service(pHddCtx) != 0)
14245 {
14246 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: btc_activate_service failed",__func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053014247 goto err_reg_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -070014248 }
14249
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053014250#ifdef FEATURE_OEM_DATA_SUPPORT
14251 //Initialize the OEM service
14252 if (oem_activate_service(pHddCtx) != 0)
14253 {
14254 hddLog(VOS_TRACE_LEVEL_FATAL,
14255 "%s: oem_activate_service failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014256 goto err_btc_activate_service;
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053014257 }
14258#endif
14259
Jeff Johnson295189b2012-06-20 16:38:30 -070014260#ifdef PTT_SOCK_SVC_ENABLE
14261 //Initialize the PTT service
14262 if(ptt_sock_activate_svc(pHddCtx) != 0)
14263 {
14264 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: ptt_sock_activate_svc failed",__func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014265 goto err_oem_activate_service;
Jeff Johnson295189b2012-06-20 16:38:30 -070014266 }
14267#endif
14268
Abhishek Singh00b71972016-01-07 10:51:04 +053014269#ifdef WLAN_FEATURE_RMC
14270 if (hdd_open_cesium_nl_sock() < 0)
14271 {
14272 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_open_cesium_nl_sock failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014273 goto err_ptt_sock_activate_svc;
Abhishek Singh00b71972016-01-07 10:51:04 +053014274 }
14275#endif
14276
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014277#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14278 if(pHddCtx->cfg_ini && pHddCtx->cfg_ini->wlanLoggingEnable)
14279 {
Deepthi Gowri78083a32014-11-04 12:55:51 +053014280 if(wlan_logging_sock_activate_svc(
14281 pHddCtx->cfg_ini->wlanLoggingFEToConsole,
Sushant Kaushik33200572015-08-05 16:46:20 +053014282 pHddCtx->cfg_ini->wlanLoggingNumBuf,
14283 pHddCtx->cfg_ini->wlanPerPktStatsLogEnable,
14284 pHddCtx->cfg_ini->wlanPerPktStatsNumBuf))
Deepthi Gowri78083a32014-11-04 12:55:51 +053014285 {
14286 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wlan_logging_sock_activate_svc"
14287 " failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014288 goto err_open_cesium_nl_sock;
Deepthi Gowri78083a32014-11-04 12:55:51 +053014289 }
14290 //TODO: To Remove enableDhcpDebug and use gEnableDebugLog for
14291 //EAPOL and DHCP
Sachin Ahuja8c65f382014-12-12 15:34:21 +053014292 if (!pHddCtx->cfg_ini->gEnableDebugLog)
14293 pHddCtx->cfg_ini->gEnableDebugLog =
Sushant Kaushik6e4e2bc2015-10-05 17:23:07 +053014294 VOS_PKT_PROTO_TYPE_EAPOL | VOS_PKT_PROTO_TYPE_DHCP |
14295 VOS_PKT_PROTO_TYPE_ARP;
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014296 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014297
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014298 if (pHddCtx->cfg_ini->wlanLoggingEnable &&
14299 (pHddCtx->cfg_ini->enableFWLogging ||
Siddharth Bhaldb963232015-06-25 19:34:35 +053014300 pHddCtx->cfg_ini->enableMgmtLogging ||
sheenam monga1a0202d2020-01-03 15:20:57 +053014301 pHddCtx->cfg_ini->enableContFWLogging))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014302 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014303 hdd_init_frame_logging(pHddCtx);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014304 }
14305 else
14306 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014307 hddLog(VOS_TRACE_LEVEL_INFO, FL("Logging disabled in ini"));
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014308 }
14309
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014310#endif
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014311
Sushant Kaushik215778f2015-05-21 14:05:36 +053014312 if (vos_is_multicast_logging())
14313 wlan_logging_set_log_level();
14314
Jeff Johnson295189b2012-06-20 16:38:30 -070014315 hdd_register_mcast_bcast_filter(pHddCtx);
Bala Venkateshe65810a2019-02-18 20:32:36 +053014316
14317 /* Action frame registered in one adapter which will
14318 * applicable to all interfaces
14319 */
14320 wlan_hdd_cfg80211_register_frames(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070014321
14322 mutex_init(&pHddCtx->sap_lock);
Mahesh A Saptasagar60627942014-10-13 13:55:14 +053014323 mutex_init(&pHddCtx->roc_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070014324
Jeff Johnsone7245742012-09-05 17:12:55 -070014325#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
14326 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014327 vos_wake_lock_init(&pHddCtx->rx_wake_lock,
Jeff Johnsone7245742012-09-05 17:12:55 -070014328 "qcom_rx_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014329
Jeff Johnsone7245742012-09-05 17:12:55 -070014330#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080014331 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014332 vos_wake_lock_init(&pHddCtx->sap_wake_lock,
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080014333 "qcom_sap_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014334
Jeff Johnsone7245742012-09-05 17:12:55 -070014335
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070014336 vos_event_init(&pHddCtx->scan_info.scan_finished_event);
14337 pHddCtx->scan_info.scan_pending_option = WEXT_SCAN_PENDING_GIVEUP;
Jeff Johnson295189b2012-06-20 16:38:30 -070014338
Katya Nigam5c306ea2014-06-19 15:39:54 +053014339 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070014340 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014341 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Katya Nigam5c306ea2014-06-19 15:39:54 +053014342
14343#ifdef FEATURE_WLAN_SCAN_PNO
14344 /*SME must send channel update configuration to RIVA*/
14345 sme_UpdateChannelConfig(pHddCtx->hHal);
14346#endif
Abhishek Singhf644b272014-08-21 02:59:39 +053014347 /* Send the update default channel list to the FW*/
14348 sme_UpdateChannelList(pHddCtx->hHal);
Mukul Sharma45063942015-04-01 20:07:59 +053014349
14350 /* Fwr capabilities received, Set the Dot11 mode */
Abhishek Singh41ebce12016-02-03 10:43:21 +053014351 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
14352 hdd_cfg_xlate_to_csr_phy_mode(pHddCtx->cfg_ini->dot11Mode));
Mukul Sharma45063942015-04-01 20:07:59 +053014353 sme_SetDefDot11Mode(pHddCtx->hHal);
14354
Abhishek Singha306a442013-11-07 18:39:01 +053014355#ifndef CONFIG_ENABLE_LINUX_REG
14356 /*updating wiphy so that regulatory user hints can be processed*/
14357 if (wiphy)
14358 {
14359 regulatory_hint(wiphy, "00");
14360 }
14361#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070014362 // Initialize the restart logic
14363 wlan_hdd_restart_init(pHddCtx);
Chilam NG571c65a2013-01-19 12:27:36 +053014364
Hanumanth Reddy Pothula146bca42016-11-08 12:01:07 +053014365 if (pHddCtx->cfg_ini->fIsLogpEnabled) {
14366 vos_wdthread_init_timer_work(vos_process_wd_timer);
14367 /* Initialize the timer to detect thread stuck issues */
14368 vos_thread_stuck_timer_init(
14369 &((VosContextType*)pVosContext)->vosWatchdog);
14370 }
14371
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070014372 //Register the traffic monitor timer now
14373 if ( pHddCtx->cfg_ini->dynSplitscan)
14374 {
14375 vos_timer_init(&pHddCtx->tx_rx_trafficTmr,
14376 VOS_TIMER_TYPE_SW,
14377 hdd_tx_rx_pkt_cnt_stat_timer_handler,
14378 (void *)pHddCtx);
14379 }
Srinivas Dasari030bad32015-02-18 23:23:54 +053014380 wlan_hdd_cfg80211_nan_init(pHddCtx);
14381
Bhargav Shahd0715912015-10-01 18:17:37 +053014382 mutex_init(&pHddCtx->cur_rx_level_lock);
14383 vos_timer_init(&pHddCtx->delack_timer, VOS_TIMER_TYPE_SW,
14384 hdd_tcp_delack_compute_function,(void *)pHddCtx);
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053014385 vos_timer_init(&pHddCtx->tdls_source_timer, VOS_TIMER_TYPE_SW,
14386 wlan_hdd_change_tdls_mode, (void *)pHddCtx);
Bhargav Shahd0715912015-10-01 18:17:37 +053014387
Dino Mycle6fb96c12014-06-10 11:52:40 +053014388#ifdef WLAN_FEATURE_EXTSCAN
14389 sme_EXTScanRegisterCallback(pHddCtx->hHal,
14390 wlan_hdd_cfg80211_extscan_callback,
14391 pHddCtx);
14392#endif /* WLAN_FEATURE_EXTSCAN */
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014393
Padma, Santhosh Kumar2ccac212015-10-20 17:27:27 +053014394#ifdef FEATURE_OEM_DATA_SUPPORT
14395 sme_OemDataRegisterCallback(pHddCtx->hHal,
14396 wlan_hdd_cfg80211_oemdata_callback,
14397 pHddCtx);
14398#endif /* FEATURE_OEM_DATA_SUPPORT */
14399
Gupta, Kapil7c34b322015-09-30 13:12:35 +053014400 sme_set_rssi_threshold_breached_cb(pHddCtx->hHal, hdd_rssi_threshold_breached_cb);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014401#ifdef WLAN_NS_OFFLOAD
14402 // Register IPv6 notifier to notify if any change in IP
14403 // So that we can reconfigure the offload parameters
14404 pHddCtx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
14405 ret = register_inet6addr_notifier(&pHddCtx->ipv6_notifier);
14406 if (ret)
14407 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014408 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014409 }
14410 else
14411 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014412 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014413 }
14414#endif
14415
Sravan Kumar Kairamb0edc612016-10-26 13:55:24 +053014416 vos_mem_set((uint8_t *)&pHddCtx->bad_sta, HDD_MAX_STA_COUNT, 0);
14417
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014418 // Register IPv4 notifier to notify if any change in IP
14419 // So that we can reconfigure the offload parameters
14420 pHddCtx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
14421 ret = register_inetaddr_notifier(&pHddCtx->ipv4_notifier);
14422 if (ret)
14423 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014424 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014425 }
14426 else
14427 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014428 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014429 }
Bhargav shah23c94942015-10-13 12:48:35 +053014430 hdd_dp_util_send_rps_ind(pHddCtx);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014431
Nishank Aggarwalc11826c2016-12-15 18:54:10 +053014432 pHddCtx->is_ap_mode_wow_supported =
14433 sme_IsFeatureSupportedByFW(SAP_MODE_WOW);
Sravan Kumar Kairam091e5b62017-01-23 14:14:20 +053014434
Hanumanth Reddy Pothulae92bcc12017-05-19 13:56:35 +053014435 pHddCtx->is_fatal_event_log_sup =
14436 sme_IsFeatureSupportedByFW(FATAL_EVENT_LOGGING);
14437 hddLog(VOS_TRACE_LEVEL_INFO, FL("FATAL_EVENT_LOGGING: %d"),
14438 pHddCtx->is_fatal_event_log_sup);
14439
Sravan Kumar Kairam091e5b62017-01-23 14:14:20 +053014440 hdd_assoc_registerFwdEapolCB(pVosContext);
14441
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +053014442 mutex_init(&pHddCtx->cache_channel_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070014443 goto success;
14444
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014445err_open_cesium_nl_sock:
14446#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14447 hdd_close_cesium_nl_sock();
14448#endif
14449
14450err_ptt_sock_activate_svc:
14451#ifdef PTT_SOCK_SVC_ENABLE
14452 ptt_sock_deactivate_svc(pHddCtx);
14453#endif
14454
14455err_oem_activate_service:
14456#ifdef FEATURE_OEM_DATA_SUPPORT
14457 oem_deactivate_service();
14458#endif
14459
14460err_btc_activate_service:
14461 btc_deactivate_service();
14462
Jeff Johnson295189b2012-06-20 16:38:30 -070014463err_reg_netdev:
14464 unregister_netdevice_notifier(&hdd_netdev_notifier);
14465
Jeff Johnson295189b2012-06-20 16:38:30 -070014466err_unregister_pmops:
14467 hddDevTmUnregisterNotifyCallback(pHddCtx);
14468 hddDeregisterPmOps(pHddCtx);
14469
Yue Ma0d4891e2013-08-06 17:01:45 -070014470 hdd_debugfs_exit(pHddCtx);
14471
Jeff Johnson295189b2012-06-20 16:38:30 -070014472#ifdef WLAN_BTAMP_FEATURE
14473err_bap_stop:
14474 WLANBAP_Stop(pVosContext);
14475#endif
14476
14477#ifdef WLAN_BTAMP_FEATURE
14478err_bap_close:
14479 WLANBAP_Close(pVosContext);
14480#endif
14481
Jeff Johnson295189b2012-06-20 16:38:30 -070014482err_close_adapter:
14483 hdd_close_all_adapters( pHddCtx );
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053014484#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053014485err_unregister_wiphy:
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053014486#endif
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053014487 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053014488 hdd_wlan_free_wiphy_channels(wiphy);
14489
Jeff Johnson295189b2012-06-20 16:38:30 -070014490err_vosstop:
14491 vos_stop(pVosContext);
14492
Amar Singhala49cbc52013-10-08 18:37:44 -070014493err_vosclose:
Jeff Johnson295189b2012-06-20 16:38:30 -070014494 status = vos_sched_close( pVosContext );
14495 if (!VOS_IS_STATUS_SUCCESS(status)) {
14496 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
14497 "%s: Failed to close VOSS Scheduler", __func__);
14498 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
14499 }
Amar Singhala49cbc52013-10-08 18:37:44 -070014500 vos_close(pVosContext );
14501
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053014502err_nl_srv:
14503#ifdef WLAN_KD_READY_NOTIFIER
14504 nl_srv_exit(pHddCtx->ptt_pid);
14505#else
14506 nl_srv_exit();
14507#endif /* WLAN_KD_READY_NOTIFIER */
Amar Singhal0a402232013-10-11 20:57:16 -070014508err_vos_nv_close:
14509
c_hpothue6a36282014-03-19 12:27:38 +053014510#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070014511 vos_nv_close();
14512
c_hpothu70f8d812014-03-22 22:59:23 +053014513#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014514
14515err_wdclose:
14516 if(pHddCtx->cfg_ini->fIsLogpEnabled)
14517 vos_watchdog_close(pVosContext);
14518
Jeff Johnson295189b2012-06-20 16:38:30 -070014519err_config:
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053014520 hdd_request_manager_deinit();
Jeff Johnson295189b2012-06-20 16:38:30 -070014521 kfree(pHddCtx->cfg_ini);
14522 pHddCtx->cfg_ini= NULL;
14523
14524err_free_hdd_context:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014525 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053014526 free_riva_power_on_lock("wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070014527 wiphy_free(wiphy) ;
14528 //kfree(wdev) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070014529 VOS_BUG(1);
14530
Madan Mohan Koyyalamudid57ae632012-11-06 18:42:48 -080014531 if (hdd_is_ssr_required())
14532 {
14533 /* WDI timeout had happened during load, so SSR is needed here */
14534 subsystem_restart("wcnss");
14535 msleep(5000);
14536 }
14537 hdd_set_ssr_required (VOS_FALSE);
14538
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080014539 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070014540
14541success:
14542 EXIT();
14543 return 0;
14544}
14545
14546/**---------------------------------------------------------------------------
14547
Jeff Johnson32d95a32012-09-10 13:15:23 -070014548 \brief hdd_driver_init() - Core Driver Init Function
Jeff Johnson295189b2012-06-20 16:38:30 -070014549
Jeff Johnson32d95a32012-09-10 13:15:23 -070014550 This is the driver entry point - called in different timeline depending
14551 on whether the driver is statically or dynamically linked
Jeff Johnson295189b2012-06-20 16:38:30 -070014552
14553 \param - None
14554
14555 \return - 0 for success, non zero for failure
14556
14557 --------------------------------------------------------------------------*/
Jeff Johnson32d95a32012-09-10 13:15:23 -070014558static int hdd_driver_init( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070014559{
14560 VOS_STATUS status;
14561 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070014562 struct device *dev = NULL;
14563 int ret_status = 0;
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014564#ifdef HAVE_WCNSS_CAL_DOWNLOAD
14565 int max_retries = 0;
14566#endif
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014567#ifdef HAVE_CBC_DONE
14568 int max_cbc_retries = 0;
14569#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014570
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014571#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14572 wlan_logging_sock_init_svc();
14573#endif
14574
Jeff Johnson295189b2012-06-20 16:38:30 -070014575 ENTER();
14576
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014577 vos_wake_lock_init(&wlan_wake_lock, "wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070014578
14579 pr_info("%s: loading driver v%s\n", WLAN_MODULE_NAME,
14580 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
14581
Jeff Johnson295189b2012-06-20 16:38:30 -070014582#ifdef ANI_BUS_TYPE_PCI
14583
14584 dev = wcnss_wlan_get_device();
14585
14586#endif // ANI_BUS_TYPE_PCI
14587
14588#ifdef ANI_BUS_TYPE_PLATFORM
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014589
14590#ifdef HAVE_WCNSS_CAL_DOWNLOAD
14591 /* wait until WCNSS driver downloads NV */
Ravi Kumar Bokka7a139e62016-11-17 21:32:55 +053014592 while (!wcnss_device_ready() && 10 >= ++max_retries) {
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014593 msleep(1000);
14594 }
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014595
Ravi Kumar Bokka7a139e62016-11-17 21:32:55 +053014596 if (max_retries >= 10) {
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014597 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WCNSS driver not ready", __func__);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014598 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014599#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14600 wlan_logging_sock_deinit_svc();
14601#endif
14602
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014603 return -ENODEV;
14604 }
14605#endif
14606
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014607#ifdef HAVE_CBC_DONE
14608 while (!wcnss_cbc_complete() && 10 >= ++max_cbc_retries) {
14609 msleep(1000);
14610 }
14611 if (max_cbc_retries >= 10) {
14612 hddLog(VOS_TRACE_LEVEL_FATAL, "%s:CBC not completed", __func__);
14613 }
14614#endif
14615
Jeff Johnson295189b2012-06-20 16:38:30 -070014616 dev = wcnss_wlan_get_device();
14617#endif // ANI_BUS_TYPE_PLATFORM
14618
14619
14620 do {
14621 if (NULL == dev) {
14622 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: WLAN device not found!!",__func__);
14623 ret_status = -1;
14624 break;
14625 }
14626
Jeff Johnson295189b2012-06-20 16:38:30 -070014627#ifdef TIMER_MANAGER
14628 vos_timer_manager_init();
14629#endif
14630
14631 /* Preopen VOSS so that it is ready to start at least SAL */
14632 status = vos_preOpen(&pVosContext);
14633
14634 if (!VOS_IS_STATUS_SUCCESS(status))
14635 {
14636 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to preOpen VOSS", __func__);
14637 ret_status = -1;
14638 break;
14639 }
14640
Sushant Kaushik02beb352015-06-04 15:15:01 +053014641 hddTraceInit();
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +053014642 hdd_register_debug_callback();
14643
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014644#ifndef MODULE
14645 /* For statically linked driver, call hdd_set_conparam to update curr_con_mode
14646 */
14647 hdd_set_conparam((v_UINT_t)con_mode);
14648#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014649
14650 // Call our main init function
Jeff Johnsonbc676b42013-02-14 16:04:08 -080014651 if (hdd_wlan_startup(dev))
14652 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014653 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WLAN Driver Initialization failed",
Jeff Johnsonbc676b42013-02-14 16:04:08 -080014654 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070014655 vos_preClose( &pVosContext );
14656 ret_status = -1;
14657 break;
14658 }
14659
Jeff Johnson295189b2012-06-20 16:38:30 -070014660 } while (0);
14661
14662 if (0 != ret_status)
14663 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014664#ifdef TIMER_MANAGER
14665 vos_timer_exit();
14666#endif
14667#ifdef MEMORY_DEBUG
14668 vos_mem_exit();
14669#endif
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014670 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014671#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14672 wlan_logging_sock_deinit_svc();
14673#endif
14674
Jeff Johnson295189b2012-06-20 16:38:30 -070014675 pr_err("%s: driver load failure\n", WLAN_MODULE_NAME);
14676 }
14677 else
14678 {
14679 //Send WLAN UP indication to Nlink Service
14680 send_btc_nlink_msg(WLAN_MODULE_UP_IND, 0);
14681
14682 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Jeff Johnson295189b2012-06-20 16:38:30 -070014683 }
14684
14685 EXIT();
14686
14687 return ret_status;
14688}
14689
Jeff Johnson32d95a32012-09-10 13:15:23 -070014690/**---------------------------------------------------------------------------
14691
14692 \brief hdd_module_init() - Init Function
14693
14694 This is the driver entry point (invoked when module is loaded using insmod)
14695
14696 \param - None
14697
14698 \return - 0 for success, non zero for failure
14699
14700 --------------------------------------------------------------------------*/
14701#ifdef MODULE
14702static int __init hdd_module_init ( void)
14703{
14704 return hdd_driver_init();
14705}
Jeff Johnson32d95a32012-09-10 13:15:23 -070014706#else /* #ifdef MODULE */
14707static int __init hdd_module_init ( void)
14708{
14709 /* Driver initialization is delayed to fwpath_changed_handler */
14710 return 0;
14711}
Jeff Johnson32d95a32012-09-10 13:15:23 -070014712#endif /* #ifdef MODULE */
14713
Jeff Johnson295189b2012-06-20 16:38:30 -070014714
14715/**---------------------------------------------------------------------------
14716
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014717 \brief hdd_driver_exit() - Exit function
Jeff Johnson295189b2012-06-20 16:38:30 -070014718
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014719 This is the driver exit point (invoked when module is unloaded using rmmod
14720 or con_mode was changed by userspace)
Jeff Johnson295189b2012-06-20 16:38:30 -070014721
14722 \param - None
14723
14724 \return - None
14725
14726 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014727static void hdd_driver_exit(void)
Jeff Johnson295189b2012-06-20 16:38:30 -070014728{
14729 hdd_context_t *pHddCtx = NULL;
14730 v_CONTEXT_t pVosContext = NULL;
Agarwal Ashish5e414792014-06-08 15:25:23 +053014731 v_REGDOMAIN_t regId;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053014732 unsigned long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070014733
14734 pr_info("%s: unloading driver v%s\n", WLAN_MODULE_NAME, QWLAN_VERSIONSTR);
14735
14736 //Get the global vos context
14737 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
14738
14739 if(!pVosContext)
14740 {
14741 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
14742 goto done;
14743 }
14744
14745 //Get the HDD context.
14746 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
14747
14748 if(!pHddCtx)
14749 {
14750 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: module exit called before probe",__func__);
14751 }
Katya Nigame7b69a82015-04-28 15:24:06 +053014752 else if (VOS_MONITOR_MODE == hdd_get_conparam())
14753 {
14754 hddLog(VOS_TRACE_LEVEL_INFO,"%s: MONITOR MODE",__func__);
14755 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
14756 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
14757 hdd_wlan_exit(pHddCtx);
14758 vos_preClose( &pVosContext );
14759 goto done;
14760 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014761 else
14762 {
Siddharth Bhal2e5871b2015-03-24 16:20:51 +053014763 /* We wait for active entry threads to exit from driver
14764 * by waiting until rtnl_lock is available.
14765 */
14766 rtnl_lock();
14767 rtnl_unlock();
14768
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014769 INIT_COMPLETION(pHddCtx->ssr_comp_var);
14770 if ((pHddCtx->isLogpInProgress) && (FALSE ==
14771 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)))
14772 {
Siddharth Bhala204f572015-01-17 02:03:36 +053014773 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014774 "%s:SSR in Progress; block rmmod !!!", __func__);
Siddharth Bhala204f572015-01-17 02:03:36 +053014775 rc = wait_for_completion_timeout(&pHddCtx->ssr_comp_var,
14776 msecs_to_jiffies(30000));
14777 if(!rc)
14778 {
14779 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
14780 "%s:SSR timedout, fatal error", __func__);
14781 VOS_BUG(0);
14782 }
14783 }
14784
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014785 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
14786 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -070014787
c_hpothu8adb97b2014-12-08 19:38:20 +053014788 /* Driver Need to send country code 00 in below condition
14789 * 1) If gCountryCodePriority is set to 1; and last country
14790 * code set is through 11d. This needs to be done in case
14791 * when NV country code is 00.
14792 * This Needs to be done as when kernel store last country
14793 * code and if stored country code is not through 11d,
14794 * in sme_HandleChangeCountryCodeByUser we will disable 11d
14795 * in next load/unload as soon as we get any country through
14796 * 11d. In sme_HandleChangeCountryCodeByUser
14797 * pMsg->countryCode will be last countryCode and
14798 * pMac->scan.countryCode11d will be country through 11d so
14799 * due to mismatch driver will disable 11d.
14800 *
14801 */
Agarwal Ashish8db39882014-07-30 21:56:07 +053014802
c_hpothu8adb97b2014-12-08 19:38:20 +053014803 if ((eANI_BOOLEAN_TRUE == sme_Is11dCountrycode(pHddCtx->hHal) &&
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053014804 pHddCtx->cfg_ini->fSupplicantCountryCodeHasPriority &&
Abhishek Singh2a705962014-10-30 14:47:28 +053014805 sme_Is11dSupported(pHddCtx->hHal)))
c_hpothu8adb97b2014-12-08 19:38:20 +053014806 {
14807 hddLog(VOS_TRACE_LEVEL_INFO,
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053014808 FL("CountryCode 00 is being set while unloading driver"));
c_hpothu8adb97b2014-12-08 19:38:20 +053014809 vos_nv_getRegDomainFromCountryCode(&regId , "00", COUNTRY_USER);
14810 }
Agarwal Ashish5e414792014-06-08 15:25:23 +053014811
c_hpothu8adb97b2014-12-08 19:38:20 +053014812 //Do all the cleanup before deregistering the driver
14813 hdd_wlan_exit(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070014814 }
14815
Jeff Johnson295189b2012-06-20 16:38:30 -070014816 vos_preClose( &pVosContext );
14817
14818#ifdef TIMER_MANAGER
14819 vos_timer_exit();
14820#endif
14821#ifdef MEMORY_DEBUG
14822 vos_mem_exit();
14823#endif
14824
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014825#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14826 wlan_logging_sock_deinit_svc();
14827#endif
14828
Jeff Johnson295189b2012-06-20 16:38:30 -070014829done:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014830 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014831
Jeff Johnson295189b2012-06-20 16:38:30 -070014832 pr_info("%s: driver unloaded\n", WLAN_MODULE_NAME);
14833}
14834
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014835/**---------------------------------------------------------------------------
14836
14837 \brief hdd_module_exit() - Exit function
14838
14839 This is the driver exit point (invoked when module is unloaded using rmmod)
14840
14841 \param - None
14842
14843 \return - None
14844
14845 --------------------------------------------------------------------------*/
14846static void __exit hdd_module_exit(void)
14847{
14848 hdd_driver_exit();
14849}
14850
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014851#ifdef MODULE
14852static int fwpath_changed_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014853 const struct kernel_param *kp)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014854{
Jeff Johnson76052702013-04-16 13:55:05 -070014855 return param_set_copystring(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014856}
14857
14858static int con_mode_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014859 const struct kernel_param *kp)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014860{
Madan Mohan Koyyalamudif2f8d8b2012-10-11 17:06:59 -070014861 return param_set_int(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014862}
14863#else /* #ifdef MODULE */
14864/**---------------------------------------------------------------------------
14865
Jeff Johnson76052702013-04-16 13:55:05 -070014866 \brief kickstart_driver
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014867
Jeff Johnson76052702013-04-16 13:55:05 -070014868 This is the driver entry point
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014869 - delayed driver initialization when driver is statically linked
Jeff Johnson76052702013-04-16 13:55:05 -070014870 - invoked when module parameter fwpath is modified from userspace to signal
14871 initializing the WLAN driver or when con_mode is modified from userspace
14872 to signal a switch in operating mode
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014873
14874 \return - 0 for success, non zero for failure
14875
14876 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -070014877static int kickstart_driver(void)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014878{
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014879 int ret_status;
14880
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014881 if (!wlan_hdd_inited) {
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014882 ret_status = hdd_driver_init();
14883 wlan_hdd_inited = ret_status ? 0 : 1;
14884 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014885 }
14886
14887 hdd_driver_exit();
Jeff Johnson76052702013-04-16 13:55:05 -070014888
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014889 msleep(200);
Jeff Johnson76052702013-04-16 13:55:05 -070014890
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014891 ret_status = hdd_driver_init();
14892 wlan_hdd_inited = ret_status ? 0 : 1;
14893 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014894}
14895
Jeff Johnson295189b2012-06-20 16:38:30 -070014896/**---------------------------------------------------------------------------
14897
Jeff Johnson76052702013-04-16 13:55:05 -070014898 \brief fwpath_changed_handler() - Handler Function
14899
14900 Handle changes to the fwpath parameter
14901
14902 \return - 0 for success, non zero for failure
14903
14904 --------------------------------------------------------------------------*/
14905static int fwpath_changed_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014906 const struct kernel_param *kp)
Jeff Johnson76052702013-04-16 13:55:05 -070014907{
14908 int ret;
14909
14910 ret = param_set_copystring(kmessage, kp);
14911 if (0 == ret)
14912 ret = kickstart_driver();
14913 return ret;
14914}
14915
14916/**---------------------------------------------------------------------------
14917
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014918 \brief con_mode_handler() -
14919
14920 Handler function for module param con_mode when it is changed by userspace
14921 Dynamically linked - do nothing
14922 Statically linked - exit and init driver, as in rmmod and insmod
14923
Jeff Johnson76052702013-04-16 13:55:05 -070014924 \param -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014925
Jeff Johnson76052702013-04-16 13:55:05 -070014926 \return -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014927
14928 --------------------------------------------------------------------------*/
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014929static int con_mode_handler(const char *kmessage,
14930 const struct kernel_param *kp)
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014931{
Jeff Johnson76052702013-04-16 13:55:05 -070014932 int ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014933
Jeff Johnson76052702013-04-16 13:55:05 -070014934 ret = param_set_int(kmessage, kp);
14935 if (0 == ret)
14936 ret = kickstart_driver();
14937 return ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014938}
14939#endif /* #ifdef MODULE */
14940
14941/**---------------------------------------------------------------------------
14942
Jeff Johnson295189b2012-06-20 16:38:30 -070014943 \brief hdd_get_conparam() -
14944
14945 This is the driver exit point (invoked when module is unloaded using rmmod)
14946
14947 \param - None
14948
14949 \return - tVOS_CON_MODE
14950
14951 --------------------------------------------------------------------------*/
14952tVOS_CON_MODE hdd_get_conparam ( void )
14953{
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014954#ifdef MODULE
Jeff Johnson295189b2012-06-20 16:38:30 -070014955 return (tVOS_CON_MODE)con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014956#else
14957 return (tVOS_CON_MODE)curr_con_mode;
14958#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014959}
14960void hdd_set_conparam ( v_UINT_t newParam )
14961{
14962 con_mode = newParam;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014963#ifndef MODULE
14964 curr_con_mode = con_mode;
14965#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014966}
14967/**---------------------------------------------------------------------------
14968
14969 \brief hdd_softap_sta_deauth() - function
14970
14971 This to take counter measure to handle deauth req from HDD
14972
14973 \param - pAdapter - Pointer to the HDD
14974
14975 \param - enable - boolean value
14976
14977 \return - None
14978
14979 --------------------------------------------------------------------------*/
14980
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014981VOS_STATUS hdd_softap_sta_deauth(hdd_adapter_t *pAdapter,
14982 struct tagCsrDelStaParams *pDelStaParams)
Jeff Johnson295189b2012-06-20 16:38:30 -070014983{
Jeff Johnson295189b2012-06-20 16:38:30 -070014984 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080014985 VOS_STATUS vosStatus = VOS_STATUS_E_FAULT;
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014986 struct hdd_cache_sta_info *cache_sta_info;
14987 ptSapContext pSapCtx = VOS_GET_SAP_CB(pVosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014988
14989 ENTER();
14990
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014991 hddLog(LOG1, "hdd_softap_sta_deauth:(%pK, false)",
Rajesh Chauhan18488fc2013-08-22 10:15:03 -070014992 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014993
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014994 if (!pSapCtx) {
14995 hddLog(LOGE, "sap context is NULL");
14996 return vosStatus;
14997 }
14998
14999 cache_sta_info = hdd_get_cache_stainfo(pSapCtx->cache_sta_info,
15000 pDelStaParams->peerMacAddr);
15001 if (cache_sta_info) {
15002 cache_sta_info->reason_code = pDelStaParams->reason_code;
15003 cache_sta_info->rx_rate =
15004 wlan_tl_get_sta_rx_rate(pVosContext, cache_sta_info->ucSTAId);
15005 WLANTL_GetSAPStaRSSi(pVosContext, cache_sta_info->ucSTAId,
15006 &cache_sta_info->rssi);
15007 }
15008
Jeff Johnson295189b2012-06-20 16:38:30 -070015009 //Ignore request to deauth bcmc station
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053015010 if (pDelStaParams->peerMacAddr[0] & 0x1)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080015011 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070015012
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053015013 vosStatus = WLANSAP_DeauthSta(pVosContext, pDelStaParams);
Jeff Johnson295189b2012-06-20 16:38:30 -070015014
15015 EXIT();
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080015016 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070015017}
15018
15019/**---------------------------------------------------------------------------
15020
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015021 \brief hdd_del_all_sta() - function
15022
15023 This function removes all the stations associated on stopping AP/P2P GO.
15024
15025 \param - pAdapter - Pointer to the HDD
15026
15027 \return - None
15028
15029 --------------------------------------------------------------------------*/
15030
15031int hdd_del_all_sta(hdd_adapter_t *pAdapter)
15032{
15033 v_U16_t i;
15034 VOS_STATUS vos_status;
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053015035 v_CONTEXT_t pVosContext = ( WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
15036 ptSapContext pSapCtx = NULL;
15037 pSapCtx = VOS_GET_SAP_CB(pVosContext);
15038 if(pSapCtx == NULL){
15039 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15040 FL("psapCtx is NULL"));
15041 return 1;
15042 }
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015043 ENTER();
15044
15045 hddLog(VOS_TRACE_LEVEL_INFO,
15046 "%s: Delete all STAs associated.",__func__);
15047 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
15048 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
15049 )
15050 {
15051 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
15052 {
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053015053 if ((pSapCtx->aStaInfo[i].isUsed) &&
15054 (!pSapCtx->aStaInfo[i].isDeauthInProgress))
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015055 {
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053015056 struct tagCsrDelStaParams delStaParams;
15057
15058 WLANSAP_PopulateDelStaParams(
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053015059 pSapCtx->aStaInfo[i].macAddrSTA.bytes,
Sushant Kaushik4cd28f62014-12-26 14:23:50 +053015060 eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
15061 SIR_MAC_MGMT_DEAUTH >> 4,
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053015062 &delStaParams);
15063 vos_status = hdd_softap_sta_deauth(pAdapter, &delStaParams);
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015064 if (VOS_IS_STATUS_SUCCESS(vos_status))
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053015065 pSapCtx->aStaInfo[i].isDeauthInProgress = TRUE;
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015066 }
15067 }
15068 }
15069
15070 EXIT();
15071 return 0;
15072}
15073
15074/**---------------------------------------------------------------------------
15075
Jeff Johnson295189b2012-06-20 16:38:30 -070015076 \brief hdd_softap_sta_disassoc() - function
15077
15078 This to take counter measure to handle deauth req from HDD
15079
15080 \param - pAdapter - Pointer to the HDD
15081
15082 \param - enable - boolean value
15083
15084 \return - None
15085
15086 --------------------------------------------------------------------------*/
15087
15088void hdd_softap_sta_disassoc(hdd_adapter_t *pAdapter,v_U8_t *pDestMacAddress)
15089{
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053015090 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
15091 struct hdd_cache_sta_info *cache_sta_info;
15092 ptSapContext pSapCtx = VOS_GET_SAP_CB(pVosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070015093
15094 ENTER();
15095
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070015096 hddLog( LOGE, "hdd_softap_sta_disassoc:(%pK, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070015097
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053015098 if (!pSapCtx) {
15099 hddLog(LOGE, "sap context is NULL");
15100 return ;
15101 }
15102
Jeff Johnson295189b2012-06-20 16:38:30 -070015103 //Ignore request to disassoc bcmc station
15104 if( pDestMacAddress[0] & 0x1 )
15105 return;
15106
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053015107 cache_sta_info = hdd_get_cache_stainfo(pSapCtx->cache_sta_info,
15108 pDestMacAddress);
15109 if (cache_sta_info) {
15110 cache_sta_info->reason_code = eSIR_MAC_DEAUTH_LEAVING_BSS_REASON;
15111 cache_sta_info->rx_rate =
15112 wlan_tl_get_sta_rx_rate(pVosContext, cache_sta_info->ucSTAId);
15113 WLANTL_GetSAPStaRSSi(pVosContext, cache_sta_info->ucSTAId,
15114 &cache_sta_info->rssi);
15115 }
15116
Jeff Johnson295189b2012-06-20 16:38:30 -070015117 WLANSAP_DisassocSta(pVosContext,pDestMacAddress);
15118}
15119
15120void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *pAdapter,v_BOOL_t enable)
15121{
15122 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
15123
15124 ENTER();
15125
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070015126 hddLog( LOGE, "hdd_softap_tkip_mic_fail_counter_measure:(%pK, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070015127
15128 WLANSAP_SetCounterMeasure(pVosContext, (v_BOOL_t)enable);
15129}
15130
Jeff Johnson295189b2012-06-20 16:38:30 -070015131/**---------------------------------------------------------------------------
15132 *
15133 * \brief hdd_get__concurrency_mode() -
15134 *
15135 *
15136 * \param - None
15137 *
15138 * \return - CONCURRENCY MODE
15139 *
15140 * --------------------------------------------------------------------------*/
15141tVOS_CONCURRENCY_MODE hdd_get_concurrency_mode ( void )
15142{
15143 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
15144 hdd_context_t *pHddCtx;
15145
15146 if (NULL != pVosContext)
15147 {
15148 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
15149 if (NULL != pHddCtx)
15150 {
15151 return (tVOS_CONCURRENCY_MODE)pHddCtx->concurrency_mode;
15152 }
15153 }
15154
15155 /* we are in an invalid state :( */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070015156 hddLog(LOGE, "%s: Invalid context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070015157 return VOS_STA;
15158}
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015159v_BOOL_t
15160wlan_hdd_is_GO_power_collapse_allowed (hdd_context_t* pHddCtx)
15161{
15162 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070015163
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015164 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_GO);
15165 if (pAdapter == NULL)
15166 {
15167 hddLog(VOS_TRACE_LEVEL_INFO,
15168 FL("GO doesn't exist"));
15169 return TRUE;
15170 }
15171 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
15172 {
15173 hddLog(VOS_TRACE_LEVEL_INFO,
15174 FL("GO started"));
15175 return TRUE;
15176 }
15177 else
15178 /* wait till GO changes its interface to p2p device */
15179 hddLog(VOS_TRACE_LEVEL_INFO,
15180 FL("Del_bss called, avoid apps suspend"));
15181 return FALSE;
15182
15183}
Jeff Johnson295189b2012-06-20 16:38:30 -070015184/* Decide whether to allow/not the apps power collapse.
15185 * Allow apps power collapse if we are in connected state.
15186 * if not, allow only if we are in IMPS */
15187v_BOOL_t hdd_is_apps_power_collapse_allowed(hdd_context_t* pHddCtx)
15188{
15189 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
Srikant Kuppafef66a72013-01-30 17:32:44 -080015190 tANI_BOOLEAN scanRspPending = csrNeighborRoamScanRspPending(pHddCtx->hHal);
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080015191 tANI_BOOLEAN inMiddleOfRoaming = csrNeighborMiddleOfRoaming(pHddCtx->hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -070015192 hdd_config_t *pConfig = pHddCtx->cfg_ini;
15193 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15194 hdd_adapter_t *pAdapter = NULL;
15195 VOS_STATUS status;
Yathish9f22e662012-12-10 14:21:35 -080015196 tVOS_CONCURRENCY_MODE concurrent_state = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070015197
Jeff Johnson295189b2012-06-20 16:38:30 -070015198 if (VOS_STA_SAP_MODE == hdd_get_conparam())
15199 return TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -070015200
Yathish9f22e662012-12-10 14:21:35 -080015201 concurrent_state = hdd_get_concurrency_mode();
15202
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015203 if ((concurrent_state == (VOS_STA | VOS_P2P_GO)) &&
15204 !(wlan_hdd_is_GO_power_collapse_allowed(pHddCtx)))
15205 return FALSE;
Yathish9f22e662012-12-10 14:21:35 -080015206#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015207
Yathish9f22e662012-12-10 14:21:35 -080015208 if(((concurrent_state == (VOS_STA | VOS_P2P_CLIENT)) ||
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015209 (concurrent_state == (VOS_STA | VOS_P2P_GO)))&&
Yathish9f22e662012-12-10 14:21:35 -080015210 (IS_ACTIVEMODE_OFFLOAD_FEATURE_ENABLE))
15211 return TRUE;
15212#endif
15213
Jeff Johnson295189b2012-06-20 16:38:30 -070015214 /*loop through all adapters. TBD fix for Concurrency */
15215 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15216 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
15217 {
15218 pAdapter = pAdapterNode->pAdapter;
15219 if ( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
15220 || (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
15221 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080015222 if (((pConfig->fIsImpsEnabled || pConfig->fIsBmpsEnabled)
c_hpothu4e8faac2014-05-16 17:38:44 +053015223 && (pmcState != IMPS && pmcState != BMPS && pmcState != UAPSD
c_hpothu1c6957d2015-01-06 18:19:47 +053015224 && pmcState != STOPPED && pmcState != STANDBY &&
15225 pmcState != WOWL)) ||
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080015226 (eANI_BOOLEAN_TRUE == scanRspPending) ||
15227 (eANI_BOOLEAN_TRUE == inMiddleOfRoaming))
Jeff Johnson295189b2012-06-20 16:38:30 -070015228 {
Mukul Sharma4be88422015-03-09 20:29:07 +053015229 if(pmcState == FULL_POWER &&
15230 sme_IsCoexScoIndicationSet(pHddCtx->hHal))
15231 {
15232 /*
15233 * When SCO indication comes from Coex module , host will
15234 * enter in to full power mode, but this should not prevent
15235 * apps processor power collapse.
15236 */
15237 hddLog(LOG1,
15238 FL("Allow apps power collapse"
15239 "even when sco indication is set"));
15240 return TRUE;
15241 }
Srikant Kuppafef66a72013-01-30 17:32:44 -080015242 hddLog( LOGE, "%s: do not allow APPS power collapse-"
Deepthi Gowri03a979f2016-11-03 15:20:19 +053015243 "pmcState = %d scanRspPending = %d "
15244 "inMiddleOfRoaming = %d connected = %d",
15245 __func__, pmcState, scanRspPending,
15246 inMiddleOfRoaming, hdd_connIsConnected(
15247 WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )));
15248 wlan_hdd_get_tdls_stats(pAdapter);
15249 return FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070015250 }
15251 }
15252 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15253 pAdapterNode = pNext;
15254 }
15255 return TRUE;
15256}
15257
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -080015258/* Decides whether to send suspend notification to Riva
15259 * if any adapter is in BMPS; then it is required */
15260v_BOOL_t hdd_is_suspend_notify_allowed(hdd_context_t* pHddCtx)
15261{
15262 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
15263 hdd_config_t *pConfig = pHddCtx->cfg_ini;
15264
15265 if (pConfig->fIsBmpsEnabled && (pmcState == BMPS))
15266 {
15267 return TRUE;
15268 }
15269 return FALSE;
15270}
15271
Jeff Johnson295189b2012-06-20 16:38:30 -070015272void wlan_hdd_set_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15273{
15274 switch(mode)
15275 {
Chilam Ngc4244af2013-04-01 15:37:32 -070015276 case VOS_STA_MODE:
15277 case VOS_P2P_CLIENT_MODE:
15278 case VOS_P2P_GO_MODE:
15279 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053015280 case VOS_MONITOR_MODE:
Jeff Johnsone7245742012-09-05 17:12:55 -070015281 pHddCtx->concurrency_mode |= (1 << mode);
Agarwal Ashish51325b52014-06-16 16:50:49 +053015282 pHddCtx->no_of_open_sessions[mode]++;
Jeff Johnson295189b2012-06-20 16:38:30 -070015283 break;
15284 default:
15285 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070015286 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053015287 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
15288 "Number of open sessions for mode %d = %d"),
15289 pHddCtx->concurrency_mode, mode,
15290 pHddCtx->no_of_open_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070015291}
15292
15293
15294void wlan_hdd_clear_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15295{
15296 switch(mode)
15297 {
Chilam Ngc4244af2013-04-01 15:37:32 -070015298 case VOS_STA_MODE:
15299 case VOS_P2P_CLIENT_MODE:
15300 case VOS_P2P_GO_MODE:
15301 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053015302 case VOS_MONITOR_MODE:
Agarwal Ashish51325b52014-06-16 16:50:49 +053015303 pHddCtx->no_of_open_sessions[mode]--;
15304 if (!(pHddCtx->no_of_open_sessions[mode]))
15305 pHddCtx->concurrency_mode &= (~(1 << mode));
Jeff Johnson295189b2012-06-20 16:38:30 -070015306 break;
15307 default:
15308 break;
15309 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053015310 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
15311 "Number of open sessions for mode %d = %d"),
15312 pHddCtx->concurrency_mode, mode, pHddCtx->no_of_open_sessions[mode]);
15313
15314}
15315/**---------------------------------------------------------------------------
15316 *
15317 * \brief wlan_hdd_incr_active_session()
15318 *
15319 * This function increments the number of active sessions
15320 * maintained per device mode
15321 * Incase of STA/P2P CLI/IBSS upon connection indication it is incremented
15322 * Incase of SAP/P2P GO upon bss start it is incremented
15323 *
15324 * \param pHddCtx - HDD Context
15325 * \param mode - device mode
15326 *
15327 * \return - None
15328 *
15329 * --------------------------------------------------------------------------*/
15330void wlan_hdd_incr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15331{
15332 switch (mode) {
15333 case VOS_STA_MODE:
15334 case VOS_P2P_CLIENT_MODE:
15335 case VOS_P2P_GO_MODE:
15336 case VOS_STA_SAP_MODE:
15337 pHddCtx->no_of_active_sessions[mode]++;
15338 break;
15339 default:
15340 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
15341 break;
15342 }
15343 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
15344 mode,
15345 pHddCtx->no_of_active_sessions[mode]);
15346}
15347
15348/**---------------------------------------------------------------------------
15349 *
15350 * \brief wlan_hdd_decr_active_session()
15351 *
15352 * This function decrements the number of active sessions
15353 * maintained per device mode
15354 * Incase of STA/P2P CLI/IBSS upon disconnection it is decremented
15355 * Incase of SAP/P2P GO upon bss stop it is decremented
15356 *
15357 * \param pHddCtx - HDD Context
15358 * \param mode - device mode
15359 *
15360 * \return - None
15361 *
15362 * --------------------------------------------------------------------------*/
15363void wlan_hdd_decr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15364{
Bhargav Shahd0715912015-10-01 18:17:37 +053015365
Agarwal Ashish51325b52014-06-16 16:50:49 +053015366 switch (mode) {
15367 case VOS_STA_MODE:
15368 case VOS_P2P_CLIENT_MODE:
15369 case VOS_P2P_GO_MODE:
15370 case VOS_STA_SAP_MODE:
Agarwal Ashish5325f522014-08-06 00:58:44 +053015371 if (pHddCtx->no_of_active_sessions[mode] > 0)
15372 pHddCtx->no_of_active_sessions[mode]--;
15373 else
15374 hddLog(VOS_TRACE_LEVEL_INFO, FL(" No.# of Active sessions"
15375 "is already Zero"));
Agarwal Ashish51325b52014-06-16 16:50:49 +053015376 break;
15377 default:
15378 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
15379 break;
15380 }
15381 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
15382 mode,
15383 pHddCtx->no_of_active_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070015384}
15385
Jeff Johnsone7245742012-09-05 17:12:55 -070015386/**---------------------------------------------------------------------------
15387 *
15388 * \brief wlan_hdd_restart_init
15389 *
15390 * This function initalizes restart timer/flag. An internal function.
15391 *
15392 * \param - pHddCtx
15393 *
15394 * \return - None
15395 *
15396 * --------------------------------------------------------------------------*/
15397
15398static void wlan_hdd_restart_init(hdd_context_t *pHddCtx)
15399{
15400 /* Initialize */
15401 pHddCtx->hdd_restart_retries = 0;
15402 atomic_set(&pHddCtx->isRestartInProgress, 0);
15403 vos_timer_init(&pHddCtx->hdd_restart_timer,
15404 VOS_TIMER_TYPE_SW,
15405 wlan_hdd_restart_timer_cb,
15406 pHddCtx);
15407}
15408/**---------------------------------------------------------------------------
15409 *
15410 * \brief wlan_hdd_restart_deinit
15411 *
15412 * This function cleans up the resources used. An internal function.
15413 *
15414 * \param - pHddCtx
15415 *
15416 * \return - None
15417 *
15418 * --------------------------------------------------------------------------*/
15419
15420static void wlan_hdd_restart_deinit(hdd_context_t* pHddCtx)
15421{
15422
15423 VOS_STATUS vos_status;
15424 /* Block any further calls */
15425 atomic_set(&pHddCtx->isRestartInProgress, 1);
15426 /* Cleanup */
15427 vos_status = vos_timer_stop( &pHddCtx->hdd_restart_timer );
15428 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053015429 hddLog(LOGE, FL("Failed to stop HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070015430 vos_status = vos_timer_destroy(&pHddCtx->hdd_restart_timer);
15431 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053015432 hddLog(LOGE, FL("Failed to destroy HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070015433
15434}
15435
15436/**---------------------------------------------------------------------------
15437 *
15438 * \brief wlan_hdd_framework_restart
15439 *
15440 * This function uses a cfg80211 API to start a framework initiated WLAN
15441 * driver module unload/load.
15442 *
15443 * Also this API keep retrying (WLAN_HDD_RESTART_RETRY_MAX_CNT).
15444 *
15445 *
15446 * \param - pHddCtx
15447 *
15448 * \return - VOS_STATUS_SUCCESS: Success
15449 * VOS_STATUS_E_EMPTY: Adapter is Empty
15450 * VOS_STATUS_E_NOMEM: No memory
15451
15452 * --------------------------------------------------------------------------*/
15453
15454static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx)
15455{
15456 VOS_STATUS status = VOS_STATUS_SUCCESS;
15457 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015458 int len = (sizeof (struct ieee80211_mgmt));
15459 struct ieee80211_mgmt *mgmt = NULL;
15460
15461 /* Prepare the DEAUTH managment frame with reason code */
15462 mgmt = kzalloc(len, GFP_KERNEL);
15463 if(mgmt == NULL)
15464 {
15465 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
15466 "%s: memory allocation failed (%d bytes)", __func__, len);
15467 return VOS_STATUS_E_NOMEM;
15468 }
15469 mgmt->u.deauth.reason_code = WLAN_REASON_DISASSOC_LOW_ACK;
Jeff Johnsone7245742012-09-05 17:12:55 -070015470
15471 /* Iterate over all adapters/devices */
15472 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015473 if ((NULL == pAdapterNode) || (VOS_STATUS_SUCCESS != status))
15474 {
15475 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070015476 FL("fail to get adapter: %pK %d"), pAdapterNode, status);
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015477 goto end;
15478 }
15479
Jeff Johnsone7245742012-09-05 17:12:55 -070015480 do
15481 {
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015482 if(pAdapterNode->pAdapter &&
15483 WLAN_HDD_ADAPTER_MAGIC == pAdapterNode->pAdapter->magic)
Jeff Johnsone7245742012-09-05 17:12:55 -070015484 {
15485 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
15486 "restarting the driver(intf:\'%s\' mode:%d :try %d)",
15487 pAdapterNode->pAdapter->dev->name,
15488 pAdapterNode->pAdapter->device_mode,
15489 pHddCtx->hdd_restart_retries + 1);
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015490 /*
15491 * CFG80211 event to restart the driver
15492 *
15493 * 'cfg80211_send_unprot_deauth' sends a
15494 * NL80211_CMD_UNPROT_DEAUTHENTICATE event to supplicant at any state
15495 * of SME(Linux Kernel) state machine.
15496 *
15497 * Reason code WLAN_REASON_DISASSOC_LOW_ACK is currently used to restart
15498 * the driver.
15499 *
15500 */
Abhishek Singh00b71972016-01-07 10:51:04 +053015501
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053015502#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
15503 cfg80211_rx_unprot_mlme_mgmt(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len);
15504#else
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015505 cfg80211_send_unprot_deauth(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053015506#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070015507 }
15508 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15509 pAdapterNode = pNext;
15510 } while((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status));
15511
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015512 end:
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015513 /* Free the allocated management frame */
15514 kfree(mgmt);
15515
Jeff Johnsone7245742012-09-05 17:12:55 -070015516 /* Retry until we unload or reach max count */
15517 if(++pHddCtx->hdd_restart_retries < WLAN_HDD_RESTART_RETRY_MAX_CNT)
15518 vos_timer_start(&pHddCtx->hdd_restart_timer, WLAN_HDD_RESTART_RETRY_DELAY_MS);
15519
15520 return status;
15521
15522}
15523/**---------------------------------------------------------------------------
15524 *
15525 * \brief wlan_hdd_restart_timer_cb
15526 *
15527 * Restart timer callback. An internal function.
15528 *
15529 * \param - User data:
15530 *
15531 * \return - None
15532 *
15533 * --------------------------------------------------------------------------*/
15534
15535void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback)
15536{
15537 hdd_context_t *pHddCtx = usrDataForCallback;
15538 wlan_hdd_framework_restart(pHddCtx);
15539 return;
15540
15541}
15542
15543
15544/**---------------------------------------------------------------------------
15545 *
15546 * \brief wlan_hdd_restart_driver
15547 *
15548 * This function sends an event to supplicant to restart the WLAN driver.
15549 *
15550 * This function is called from vos_wlanRestart.
15551 *
15552 * \param - pHddCtx
15553 *
15554 * \return - VOS_STATUS_SUCCESS: Success
15555 * VOS_STATUS_E_EMPTY: Adapter is Empty
15556 * VOS_STATUS_E_ALREADY: Request already in progress
15557
15558 * --------------------------------------------------------------------------*/
15559VOS_STATUS wlan_hdd_restart_driver(hdd_context_t *pHddCtx)
15560{
15561 VOS_STATUS status = VOS_STATUS_SUCCESS;
15562
15563 /* A tight check to make sure reentrancy */
15564 if(atomic_xchg(&pHddCtx->isRestartInProgress, 1))
15565 {
Mihir Shetefd528652014-06-23 19:07:50 +053015566 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsone7245742012-09-05 17:12:55 -070015567 "%s: WLAN restart is already in progress", __func__);
15568
15569 return VOS_STATUS_E_ALREADY;
15570 }
Sameer Thalappil0c164f52013-03-28 15:27:56 -070015571 /* Send reset FIQ to WCNSS to invoke SSR. */
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -080015572#ifdef HAVE_WCNSS_RESET_INTR
Siddharth Bhal864e7e82015-04-07 20:07:24 +053015573 wcnss_reset_fiq(TRUE);
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -070015574#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070015575
Jeff Johnsone7245742012-09-05 17:12:55 -070015576 return status;
15577}
15578
Bhargav Shahd0715912015-10-01 18:17:37 +053015579/**
15580 * hdd_get_total_sessions() - provide total number of active sessions
15581 * @pHddCtx: Valid Global HDD context pointer
15582 *
15583 * This function iterates through pAdaptors and find the number of all active
15584 * sessions. This active sessions includes connected sta, p2p client and number
15585 * of client connected to sap/p2p go.
15586 *
15587 * Return: Total number of active sessions.
15588 */
15589v_U8_t hdd_get_total_sessions(hdd_context_t *pHddCtx)
15590{
15591 v_U8_t active_session = 0;
15592 hdd_station_ctx_t *pHddStaCtx;
15593 hdd_adapter_list_node_t *pAdapterNode, *pNext;
15594 hdd_adapter_t *pAdapter;
15595 VOS_STATUS status;
15596
15597 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
15598 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
15599 pAdapter = pAdapterNode->pAdapter;
15600 switch (pAdapter->device_mode) {
15601 case VOS_STA_MODE:
15602 case VOS_P2P_CLIENT_MODE:
15603 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
15604 if(eConnectionState_Associated == pHddStaCtx->conn_info.connState)
15605 active_session += 1;
15606 break;
15607 case VOS_STA_SAP_MODE:
15608 case VOS_P2P_GO_MODE:
15609 active_session += hdd_softap_get_connected_sta(pAdapter);
15610 break;
15611 default:
15612 break;
15613 }
15614
15615 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
15616 pAdapterNode = pNext;
15617 }
15618
15619 return active_session;
15620}
15621
15622/**
15623 * hdd_set_delack_value() - Set delack value
15624 * @pHddCtx: Valid Global HDD context pointer
15625 * @next_rx_level: Value to set for delack
15626 *
15627 * This function compare present value and next value of delack. If the both
15628 * are diffrent then it sets next value .
15629 *
15630 * Return: void.
15631 */
15632void hdd_set_delack_value(hdd_context_t *pHddCtx, v_U32_t next_rx_level)
15633{
15634 if (pHddCtx->cur_rx_level != next_rx_level) {
Alok Kumarf3724462018-04-05 15:18:54 +053015635 struct wlan_rx_tp_data rx_tp_data = {0};
15636
Bhargav Shahd0715912015-10-01 18:17:37 +053015637 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15638 "%s: TCP DELACK trigger level %d",
15639 __func__, next_rx_level);
15640 mutex_lock(&pHddCtx->cur_rx_level_lock);
15641 pHddCtx->cur_rx_level = next_rx_level;
15642 mutex_unlock(&pHddCtx->cur_rx_level_lock);
Alok Kumarf3724462018-04-05 15:18:54 +053015643
15644 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
15645 rx_tp_data.level = next_rx_level;
15646
15647 wlan_hdd_send_svc_nlink_msg(WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
15648 sizeof(rx_tp_data));
Bhargav Shahd0715912015-10-01 18:17:37 +053015649 }
15650}
15651
15652/**
15653 * hdd_set_default_stop_delack_timer() - Start delack timer
15654 * @pHddCtx: Valid Global HDD context pointer
15655 *
15656 * This function stop delack timer and set delack value to default..
15657 *
15658 * Return: void.
15659 */
15660
15661void hdd_set_default_stop_delack_timer(hdd_context_t *pHddCtx)
15662{
15663 if (VOS_TIMER_STATE_RUNNING !=
15664 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
15665 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15666 "%s: Can not stop timer", __func__);
15667 return;
15668 }
15669
15670 vos_timer_stop(&pHddCtx->delack_timer);
Alok Kumarf3724462018-04-05 15:18:54 +053015671 hdd_set_delack_value(pHddCtx, WLAN_SVC_TP_LOW);
Bhargav Shahd0715912015-10-01 18:17:37 +053015672}
15673
15674/**
15675 * hdd_start_delack_timer() - Start delack timer
15676 * @pHddCtx: Valid Global HDD context pointer
15677 *
15678 * This function starts the delack timer for tcpDelAckComputeInterval time
15679 * interval.The default timer value is 2 second.
15680 *
15681 * Return: void.
15682 */
15683void hdd_start_delack_timer(hdd_context_t *pHddCtx)
15684{
15685 if (VOS_TIMER_STATE_RUNNING ==
15686 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
15687 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15688 "%s: Timer is already running", __func__);
15689 return;
15690 }
15691
15692 vos_timer_start(&pHddCtx->delack_timer,
15693 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
15694}
15695
15696/**
15697 * hdd_update_prev_rx_packet_count() - Update previous rx packet count
15698 * @pHddCtx: Valid Global HDD context pointer
15699 *
15700 * This function updates the prev_rx_packets count from the corresponding
15701 * pAdapter states. This prev_rx_packets will diffed with the packet count
15702 * at the end of delack timer. That can give number of RX packet is spacific
15703 * time.
15704 *
15705 * Return: void.
15706 */
15707void hdd_update_prev_rx_packet_count(hdd_context_t *pHddCtx)
15708{
15709 hdd_adapter_list_node_t *pAdapterNode, *pNext;
15710 hdd_adapter_t *pAdapter;
15711 VOS_STATUS status;
15712
15713 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15714 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
15715 pAdapter = pAdapterNode->pAdapter;
15716 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
15717 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15718 pAdapterNode = pNext;
15719 }
15720}
15721
15722/**
15723 * hdd_manage_delack_timer() - start\stop delack timer
15724 * @pHddCtx: Valid Global HDD context pointer
15725 *
15726 * This function check the number of concerent session present, it starts the
15727 * delack timer if only one session is present.
15728 * In the case of BT_COEX and TDLS mode it blindly stop delack functionality.
15729 *
15730 * Return: void.
15731 */
15732void hdd_manage_delack_timer(hdd_context_t *pHddCtx)
15733{
15734 uint8_t sessions;
15735
15736 if (!pHddCtx->cfg_ini->enable_delack) {
15737 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15738 "%s: TCP DELACK is not enabled", __func__);
15739 return;
15740 }
15741
15742 /* Blindly stop timer of BTCOEX and TDLS Session is up */
15743 if (pHddCtx->mode != 0) {
15744 hdd_set_default_stop_delack_timer(pHddCtx);
15745 return;
15746 }
15747
15748 sessions = hdd_get_total_sessions(pHddCtx);
15749 if (sessions == 1) {
15750 hdd_update_prev_rx_packet_count(pHddCtx);
15751 hdd_start_delack_timer(pHddCtx);
15752 } else {
15753 hdd_set_default_stop_delack_timer(pHddCtx);
15754 }
15755}
15756
Mihir Shetee1093ba2014-01-21 20:13:32 +053015757/**---------------------------------------------------------------------------
15758 *
15759 * \brief wlan_hdd_init_channels
15760 *
15761 * This function is used to initialize the channel list in CSR
15762 *
15763 * This function is called from hdd_wlan_startup
15764 *
15765 * \param - pHddCtx: HDD context
15766 *
15767 * \return - VOS_STATUS_SUCCESS: Success
15768 * VOS_STATUS_E_FAULT: Failure reported by SME
15769
15770 * --------------------------------------------------------------------------*/
15771static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx)
15772{
15773 eHalStatus status;
15774
15775 status = sme_InitChannels(pHddCtx->hHal);
15776 if (HAL_STATUS_SUCCESS(status))
15777 {
15778 return VOS_STATUS_SUCCESS;
15779 }
15780 else
15781 {
15782 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Channel initialization failed(%d)",
15783 __func__, status);
15784 return VOS_STATUS_E_FAULT;
15785 }
15786}
15787
Mihir Shete04206452014-11-20 17:50:58 +053015788#ifdef CONFIG_ENABLE_LINUX_REG
Agarwal Ashish6db9d532014-09-30 18:19:10 +053015789VOS_STATUS wlan_hdd_init_channels_for_cc(hdd_context_t *pHddCtx, driver_load_type init )
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053015790{
15791 eHalStatus status;
15792
Rajeev Kumar Sirasanagandlaf8fc27c2018-12-06 14:56:43 +053015793 if (init == INIT && init_by_reg_core_user) {
15794 init_by_reg_core_user = false;
15795 pr_info("driver regulatory hint is not required");
15796
15797 return VOS_STATUS_SUCCESS;
15798 }
15799
Agarwal Ashish6db9d532014-09-30 18:19:10 +053015800 status = sme_InitChannelsForCC(pHddCtx->hHal, init);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053015801 if (HAL_STATUS_SUCCESS(status))
15802 {
15803 return VOS_STATUS_SUCCESS;
15804 }
15805 else
15806 {
15807 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Issue reg hint failed(%d)",
15808 __func__, status);
15809 return VOS_STATUS_E_FAULT;
15810 }
15811}
Mihir Shete04206452014-11-20 17:50:58 +053015812#endif
Sudhir Sattayappa Kohallib1d8c3a2013-06-18 14:47:20 -070015813/*
15814 * API to find if there is any STA or P2P-Client is connected
15815 */
15816VOS_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *pHddCtx)
15817{
15818 return sme_isSta_p2p_clientConnected(pHddCtx->hHal);
15819}
Jeff Johnsone7245742012-09-05 17:12:55 -070015820
Mihir Shetee2ae82a2015-03-16 14:08:49 +053015821
15822/*
15823 * API to find if the firmware will send logs using DXE channel
15824 */
15825v_U8_t hdd_is_fw_logging_enabled(void)
15826{
15827 hdd_context_t *pHddCtx;
15828
15829 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
15830 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
15831
Sravan Kumar Kairam1d5bf8e2019-03-21 00:33:56 +053015832 return (pHddCtx && pHddCtx->cfg_ini->wlanLoggingEnable &&
15833 pHddCtx->cfg_ini->enableMgmtLogging);
Mihir Shetee2ae82a2015-03-16 14:08:49 +053015834}
15835
Agarwal Ashish57e84372014-12-05 18:26:53 +053015836/*
Mihir Shetebe94ebb2015-05-26 12:07:14 +053015837 * API to find if the firmware will send trace logs using DXE channel
15838 */
15839v_U8_t hdd_is_fw_ev_logging_enabled(void)
15840{
15841 hdd_context_t *pHddCtx;
15842
15843 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
15844 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
15845
Sravan Kumar Kairam1d5bf8e2019-03-21 00:33:56 +053015846 return (pHddCtx && pHddCtx->cfg_ini->wlanLoggingEnable &&
15847 pHddCtx->cfg_ini->enableFWLogging);
Mihir Shetebe94ebb2015-05-26 12:07:14 +053015848}
Sravan Kumar Kairam1d5bf8e2019-03-21 00:33:56 +053015849
Mihir Shetebe94ebb2015-05-26 12:07:14 +053015850/*
Agarwal Ashish57e84372014-12-05 18:26:53 +053015851 * API to find if there is any session connected
15852 */
15853VOS_STATUS hdd_is_any_session_connected(hdd_context_t *pHddCtx)
15854{
15855 return sme_is_any_session_connected(pHddCtx->hHal);
15856}
15857
15858
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015859int wlan_hdd_scan_abort(hdd_adapter_t *pAdapter)
15860{
15861 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
15862 hdd_scaninfo_t *pScanInfo = NULL;
Girish Gowli4bf7a632014-06-12 13:42:11 +053015863 long status = 0;
c_hpothua3d45d52015-01-05 14:11:17 +053015864 tSirAbortScanStatus abortScanStatus;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015865
15866 pScanInfo = &pHddCtx->scan_info;
Ratnam Rachuric7681132015-06-30 10:35:13 +053015867 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015868 if (pScanInfo->mScanPending)
15869 {
c_hpothua3d45d52015-01-05 14:11:17 +053015870 abortScanStatus = hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
15871 eCSR_SCAN_ABORT_DEFAULT);
15872 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15873 FL("abortScanStatus: %d"), abortScanStatus);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015874
c_hpothua3d45d52015-01-05 14:11:17 +053015875 /* If there is active scan command lets wait for the completion else
15876 * there is no need to wait as scan command might be in the SME pending
15877 * command list.
15878 */
15879 if (abortScanStatus == eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY)
15880 {
Mukul Sharmab392b642017-08-17 17:45:29 +053015881 status = wait_for_completion_timeout(
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015882 &pScanInfo->abortscan_event_var,
15883 msecs_to_jiffies(5000));
c_hpothua3d45d52015-01-05 14:11:17 +053015884 if (0 >= status)
15885 {
15886 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Girish Gowli4bf7a632014-06-12 13:42:11 +053015887 "%s: Timeout or Interrupt occurred while waiting for abort"
15888 "scan, status- %ld", __func__, status);
c_hpothua3d45d52015-01-05 14:11:17 +053015889 return -ETIMEDOUT;
15890 }
15891 }
15892 else if (abortScanStatus == eSIR_ABORT_SCAN_FAILURE)
15893 {
15894 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15895 FL("hdd_abort_mac_scan failed"));
15896 return -VOS_STATUS_E_FAILURE;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015897 }
15898 }
Girish Gowli4bf7a632014-06-12 13:42:11 +053015899 return 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015900}
15901
Abhishek Singh7d624e12015-11-30 14:29:27 +053015902/**
15903 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
15904 * user space
15905 * @frame_ind: Management frame data to be informed.
15906 *
15907 * This function is used to indicate management frame to
15908 * user space
15909 *
15910 * Return: None
15911 *
15912 */
15913void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
15914{
15915 hdd_context_t *hdd_ctx = NULL;
15916 hdd_adapter_t *adapter = NULL;
15917 v_CONTEXT_t vos_context = NULL;
Pragaspathi Thilagaraj4aa58d52019-05-27 18:35:26 +053015918 struct ieee80211_mgmt *mgmt =
15919 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Abhishek Singh7d624e12015-11-30 14:29:27 +053015920
15921 /* Get the global VOSS context.*/
15922 vos_context = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
15923 if (!vos_context) {
15924 hddLog(LOGE, FL("Global VOS context is Null"));
15925 return;
15926 }
15927 /* Get the HDD context.*/
15928 hdd_ctx =
15929 (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, vos_context );
15930
15931 if (0 != wlan_hdd_validate_context(hdd_ctx))
15932 {
15933 return;
15934 }
Pragaspathi Thilagaraj4aa58d52019-05-27 18:35:26 +053015935
15936 if (frame_ind->frameLen < ieee80211_hdrlen(mgmt->frame_control)) {
15937 hddLog(LOGE, FL(" Invalid frame length"));
15938 return;
15939 }
15940
Abhishek Singh7d624e12015-11-30 14:29:27 +053015941 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
15942 frame_ind->sessionId);
15943
15944 if ((NULL != adapter) &&
15945 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
15946 __hdd_indicate_mgmt_frame(adapter,
15947 frame_ind->frameLen,
15948 frame_ind->frameBuf,
15949 frame_ind->frameType,
15950 frame_ind->rxChan,
15951 frame_ind->rxRssi);
15952 return;
15953
15954}
15955
c_hpothu225aa7c2014-10-22 17:45:13 +053015956VOS_STATUS wlan_hdd_cancel_remain_on_channel(hdd_context_t *pHddCtx)
15957{
15958 hdd_adapter_t *pAdapter;
15959 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15960 VOS_STATUS vosStatus;
15961
15962 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15963 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
15964 {
15965 pAdapter = pAdapterNode->pAdapter;
15966 if (NULL != pAdapter)
15967 {
15968 if (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode ||
15969 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
15970 WLAN_HDD_P2P_GO == pAdapter->device_mode)
15971 {
15972 hddLog(LOG1, FL("abort ROC deviceMode: %d"),
15973 pAdapter->device_mode);
15974 if (VOS_STATUS_SUCCESS !=
15975 wlan_hdd_cancel_existing_remain_on_channel(pAdapter))
15976 {
15977 hddLog(LOGE, FL("failed to abort ROC"));
15978 return VOS_STATUS_E_FAILURE;
15979 }
15980 }
15981 }
15982 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15983 pAdapterNode = pNext;
15984 }
15985 return VOS_STATUS_SUCCESS;
15986}
Mahesh A Saptasagard477b092015-02-06 15:12:16 +053015987
Mihir Shete0be28772015-02-17 18:42:14 +053015988hdd_remain_on_chan_ctx_t *hdd_get_remain_on_channel_ctx(hdd_context_t *pHddCtx)
15989{
15990 hdd_adapter_t *pAdapter;
15991 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15992 hdd_cfg80211_state_t *cfgState;
15993 hdd_remain_on_chan_ctx_t *pRemainChanCtx = NULL;
15994 VOS_STATUS vosStatus;
15995
15996 vosStatus = hdd_get_front_adapter (pHddCtx, &pAdapterNode);
15997 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
15998 {
15999 pAdapter = pAdapterNode->pAdapter;
16000 if (NULL != pAdapter)
16001 {
16002 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter);
16003 pRemainChanCtx = cfgState->remain_on_chan_ctx;
16004 if (pRemainChanCtx)
16005 break;
16006 }
16007 vosStatus = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
16008 pAdapterNode = pNext;
16009 }
16010 return pRemainChanCtx;
16011}
16012
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +053016013/**
16014 * wlan_hdd_handle_dfs_chan_scan () - handles disable/enable DFS channels
16015 *
16016 * @pHddCtx: HDD context within host driver
16017 * @dfsScanMode: dfsScanMode passed from ioctl
16018 *
16019 */
16020
16021VOS_STATUS wlan_hdd_handle_dfs_chan_scan(hdd_context_t *pHddCtx,
16022 tANI_U8 dfsScanMode)
16023{
16024 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
16025 hdd_adapter_t *pAdapter;
16026 VOS_STATUS vosStatus;
16027 hdd_station_ctx_t *pHddStaCtx;
16028 eHalStatus status = eHAL_STATUS_SUCCESS;
16029
16030 if(!pHddCtx)
16031 {
16032 hddLog(LOGE, FL("HDD context is Null"));
16033 return eHAL_STATUS_FAILURE;
16034 }
16035
16036 if (pHddCtx->scan_info.mScanPending)
16037 {
16038 hddLog(LOG1, FL("Aborting scan for sessionId: %d"),
16039 pHddCtx->scan_info.sessionId);
16040 hdd_abort_mac_scan(pHddCtx,
16041 pHddCtx->scan_info.sessionId,
16042 eCSR_SCAN_ABORT_DEFAULT);
16043 }
16044
16045 if (!dfsScanMode)
16046 {
16047 vosStatus = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
16048 while ((NULL != pAdapterNode) &&
16049 (VOS_STATUS_SUCCESS == vosStatus))
16050 {
16051 pAdapter = pAdapterNode->pAdapter;
16052
16053 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
16054 {
16055 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
16056
16057 if(!pHddStaCtx)
16058 {
16059 hddLog(LOGE, FL("HDD STA context is Null"));
16060 return eHAL_STATUS_FAILURE;
16061 }
16062
16063 /* if STA is already connected on DFS channel,
16064 disconnect immediately*/
16065 if (hdd_connIsConnected(pHddStaCtx) &&
16066 (NV_CHANNEL_DFS ==
16067 vos_nv_getChannelEnabledState(
16068 pHddStaCtx->conn_info.operationChannel)))
16069 {
16070 status = sme_RoamDisconnect(pHddCtx->hHal,
16071 pAdapter->sessionId,
16072 eCSR_DISCONNECT_REASON_UNSPECIFIED);
16073 hddLog(LOG1, FL("Client connected on DFS channel %d,"
16074 "sme_RoamDisconnect returned with status: %d"
16075 "for sessionid: %d"), pHddStaCtx->conn_info.
16076 operationChannel, status, pAdapter->sessionId);
16077 }
16078 }
16079
16080 vosStatus = hdd_get_next_adapter(pHddCtx, pAdapterNode,
16081 &pNext);
16082 pAdapterNode = pNext;
16083 }
16084 }
16085
16086 sme_UpdateDFSScanMode(pHddCtx->hHal, dfsScanMode);
16087 sme_UpdateDFSRoamMode(pHddCtx->hHal,
16088 (dfsScanMode != DFS_CHNL_SCAN_DISABLED));
16089
16090 status = sme_HandleDFSChanScan(pHddCtx->hHal);
16091 if (!HAL_STATUS_SUCCESS(status))
16092 {
16093 hddLog(LOGE,
16094 FL("Failed in sme_HandleDFSChanScan (err=%d)"), status);
16095 return status;
16096 }
16097
16098 return status;
16099}
16100
Nirav Shah7e3c8132015-06-22 23:51:42 +053016101static int hdd_log2_ceil(unsigned value)
16102{
16103 /* need to switch to unsigned math so that negative values
16104 * will right-shift towards 0 instead of -1
16105 */
16106 unsigned tmp = value;
16107 int log2 = -1;
16108
16109 if (value == 0)
16110 return 0;
16111
16112 while (tmp) {
16113 log2++;
16114 tmp >>= 1;
16115 }
16116 if (1U << log2 != value)
16117 log2++;
16118
16119 return log2;
16120}
16121
16122/**
16123 * hdd_sta_id_hash_attach() - initialize sta id to macaddr hash
16124 * @pAdapter: adapter handle
16125 *
16126 * Return: vos status
16127 */
16128VOS_STATUS hdd_sta_id_hash_attach(hdd_adapter_t *pAdapter)
16129{
16130 int hash_elem, log2, i;
16131
16132 spin_lock_bh( &pAdapter->sta_hash_lock);
16133 if (pAdapter->is_sta_id_hash_initialized == VOS_TRUE) {
16134 spin_unlock_bh( &pAdapter->sta_hash_lock);
16135 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16136 "%s: hash already attached for session id %d",
16137 __func__, pAdapter->sessionId);
16138 return VOS_STATUS_SUCCESS;
16139 }
16140 spin_unlock_bh( &pAdapter->sta_hash_lock);
16141
16142 hash_elem = WLAN_MAX_STA_COUNT;
16143 hash_elem *= HDD_STA_ID_HASH_MULTIPLIER;
16144 log2 = hdd_log2_ceil(hash_elem);
16145 hash_elem = 1 << log2;
16146
16147 pAdapter->sta_id_hash.mask = hash_elem - 1;
16148 pAdapter->sta_id_hash.idx_bits = log2;
16149 pAdapter->sta_id_hash.bins =
16150 vos_mem_malloc(hash_elem *sizeof(hdd_list_t));
16151 if (!pAdapter->sta_id_hash.bins) {
16152 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16153 "%s: malloc failed for session %d",
16154 __func__, pAdapter->sessionId);
16155 return VOS_STATUS_E_NOMEM;
16156 }
16157
16158 for (i = 0; i < hash_elem; i++)
16159 hdd_list_init(&pAdapter->sta_id_hash.bins[i], WLAN_MAX_STA_COUNT);
16160
16161 spin_lock_bh( &pAdapter->sta_hash_lock);
16162 pAdapter->is_sta_id_hash_initialized = VOS_TRUE;
16163 spin_unlock_bh( &pAdapter->sta_hash_lock);
16164 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16165 "%s: Station ID Hash attached for session id %d",
16166 __func__, pAdapter->sessionId);
16167
16168 return VOS_STATUS_SUCCESS;
16169}
16170
16171/**
16172 * hdd_sta_id_hash_detach() - deinit sta_id to macaddr hash
16173 * @pAdapter: adapter handle
16174 *
16175 * Return: vos status
16176 */
16177VOS_STATUS hdd_sta_id_hash_detach(hdd_adapter_t *pAdapter)
16178{
16179 int hash_elem, i;
16180 v_SIZE_t size;
16181
16182 spin_lock_bh( &pAdapter->sta_hash_lock);
16183 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16184 spin_unlock_bh( &pAdapter->sta_hash_lock);
16185 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16186 "%s: hash not initialized for session id %d",
16187 __func__, pAdapter->sessionId);
16188 return VOS_STATUS_SUCCESS;
16189 }
16190
16191 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
16192 spin_unlock_bh( &pAdapter->sta_hash_lock);
16193
16194 hash_elem = 1 << pAdapter->sta_id_hash.idx_bits;
16195
16196 /* free all station info*/
16197 for (i = 0; i < hash_elem; i++) {
16198 hdd_list_size(&pAdapter->sta_id_hash.bins[i], &size);
16199 if (size != 0) {
16200 VOS_STATUS status;
16201 hdd_staid_hash_node_t *sta_info_node = NULL;
16202 hdd_staid_hash_node_t *next_node = NULL;
16203 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[i],
16204 (hdd_list_node_t**) &sta_info_node );
16205
16206 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16207 {
16208 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[i],
16209 &sta_info_node->node);
16210 vos_mem_free(sta_info_node);
16211
16212 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[i],
16213 (hdd_list_node_t*)sta_info_node,
16214 (hdd_list_node_t**)&next_node);
16215 sta_info_node = next_node;
16216 }
16217 }
16218 }
16219
16220 vos_mem_free(pAdapter->sta_id_hash.bins);
16221 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16222 "%s: Station ID Hash detached for session id %d",
16223 __func__, pAdapter->sessionId);
16224 return VOS_STATUS_SUCCESS;
16225}
16226
16227/**
16228 * hdd_sta_id_hash_calculate_index() - derive index from macaddr
16229 * @pAdapter: adapter handle
16230 * @mac_addr_in: input mac address
16231 *
16232 * Return: index derived from mac address
16233 */
16234int hdd_sta_id_hash_calculate_index(hdd_adapter_t *pAdapter,
16235 v_MACADDR_t *mac_addr_in)
16236{
16237 uint16 index;
16238 struct hdd_align_mac_addr_t * mac_addr =
16239 (struct hdd_align_mac_addr_t *)mac_addr_in;
16240
16241 index = mac_addr->bytes_ab ^
16242 mac_addr->bytes_cd ^ mac_addr->bytes_ef;
16243 index ^= index >> pAdapter->sta_id_hash.idx_bits;
16244 index &= pAdapter->sta_id_hash.mask;
16245 return index;
16246}
16247
16248/**
16249 * hdd_sta_id_hash_add_entry() - add entry in hash
16250 * @pAdapter: adapter handle
16251 * @sta_id: station id
16252 * @mac_addr: mac address
16253 *
16254 * Return: vos status
16255 */
16256VOS_STATUS hdd_sta_id_hash_add_entry(hdd_adapter_t *pAdapter,
16257 v_U8_t sta_id, v_MACADDR_t *mac_addr)
16258{
16259 uint16 index;
16260 hdd_staid_hash_node_t *sta_info_node = NULL;
16261
Nirav Shah7e3c8132015-06-22 23:51:42 +053016262 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
16263 sta_info_node = vos_mem_malloc(sizeof(hdd_staid_hash_node_t));
16264 if (!sta_info_node) {
Nirav Shah7e3c8132015-06-22 23:51:42 +053016265 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16266 "%s: malloc failed", __func__);
16267 return VOS_STATUS_E_NOMEM;
16268 }
16269
16270 sta_info_node->sta_id = sta_id;
16271 vos_mem_copy(&sta_info_node->mac_addr, mac_addr, sizeof(v_MACADDR_t));
16272
Nirav Shah303ed5c2015-08-24 10:29:25 +053016273 spin_lock_bh( &pAdapter->sta_hash_lock);
16274 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16275 spin_unlock_bh( &pAdapter->sta_hash_lock);
16276 vos_mem_free(sta_info_node);
16277 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16278 "%s: hash is not initialized for session id %d",
16279 __func__, pAdapter->sessionId);
16280 return VOS_STATUS_E_FAILURE;
16281 }
16282
Nirav Shah7e3c8132015-06-22 23:51:42 +053016283 hdd_list_insert_back ( &pAdapter->sta_id_hash.bins[index],
16284 (hdd_list_node_t*) sta_info_node );
16285 spin_unlock_bh( &pAdapter->sta_hash_lock);
16286 return VOS_STATUS_SUCCESS;
16287}
16288
16289/**
16290 * hdd_sta_id_hash_remove_entry() - remove entry from hash
16291 * @pAdapter: adapter handle
16292 * @sta_id: station id
16293 * @mac_addr: mac address
16294 *
16295 * Return: vos status
16296 */
16297VOS_STATUS hdd_sta_id_hash_remove_entry(hdd_adapter_t *pAdapter,
16298 v_U8_t sta_id, v_MACADDR_t *mac_addr)
16299{
16300 uint16 index;
16301 VOS_STATUS status;
16302 hdd_staid_hash_node_t *sta_info_node = NULL;
16303 hdd_staid_hash_node_t *next_node = NULL;
16304
16305 spin_lock_bh( &pAdapter->sta_hash_lock);
16306 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16307 spin_unlock_bh( &pAdapter->sta_hash_lock);
16308 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16309 "%s: hash is not initialized for session id %d",
16310 __func__, pAdapter->sessionId);
16311 return VOS_STATUS_E_FAILURE;
16312 }
16313
16314 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
16315 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
16316 (hdd_list_node_t**) &sta_info_node );
16317
16318 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16319 {
16320 if (sta_info_node->sta_id == sta_id) {
16321 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[index],
16322 &sta_info_node->node);
16323 vos_mem_free(sta_info_node);
16324 break;
16325 }
16326 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
16327 (hdd_list_node_t*)sta_info_node, (hdd_list_node_t**)&next_node);
16328 sta_info_node = next_node;
16329 }
16330 spin_unlock_bh( &pAdapter->sta_hash_lock);
16331 return status;
16332}
16333
16334/**
16335 * hdd_sta_id_find_from_mac_addr() - find sta id from mac address
16336 * @pAdapter: adapter handle
16337 * @mac_addr_in: mac address
16338 *
16339 * Return: station id
16340 */
16341int hdd_sta_id_find_from_mac_addr(hdd_adapter_t *pAdapter,
16342 v_MACADDR_t *mac_addr_in)
16343{
16344 uint8 is_found = 0;
16345 uint8 sta_id = HDD_WLAN_INVALID_STA_ID;
16346 uint16 index;
16347 VOS_STATUS status;
16348 hdd_staid_hash_node_t *sta_info_node = NULL;
16349 hdd_staid_hash_node_t *next_node = NULL;
16350
16351 spin_lock_bh( &pAdapter->sta_hash_lock);
16352 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16353 spin_unlock_bh( &pAdapter->sta_hash_lock);
Bhargav Shahce3b32c2015-08-10 12:29:24 +053016354 hddLog(VOS_TRACE_LEVEL_INFO,
Nirav Shah7e3c8132015-06-22 23:51:42 +053016355 FL("hash is not initialized for session id %d"),
16356 pAdapter->sessionId);
16357 return HDD_WLAN_INVALID_STA_ID;
16358 }
16359
16360 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr_in);
16361 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
16362 (hdd_list_node_t**) &sta_info_node );
16363
16364 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16365 {
16366 if (vos_mem_compare(&sta_info_node->mac_addr,
16367 mac_addr_in, sizeof(v_MACADDR_t))) {
16368 is_found = 1;
16369 sta_id = sta_info_node->sta_id;
16370 break;
16371 }
16372 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
16373 (hdd_list_node_t*)sta_info_node,
16374 (hdd_list_node_t**)&next_node);
16375 sta_info_node = next_node;
16376 }
16377 spin_unlock_bh( &pAdapter->sta_hash_lock);
16378 return sta_id;
16379}
16380
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053016381void hdd_initialize_adapter_common(hdd_adapter_t *pAdapter)
16382{
16383 if (NULL == pAdapter)
16384 {
16385 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL ", __func__);
16386 return;
16387 }
16388 init_completion(&pAdapter->session_open_comp_var);
16389 init_completion(&pAdapter->session_close_comp_var);
16390 init_completion(&pAdapter->disconnect_comp_var);
16391 init_completion(&pAdapter->linkup_event_var);
16392 init_completion(&pAdapter->cancel_rem_on_chan_var);
16393 init_completion(&pAdapter->rem_on_chan_ready_event);
16394 init_completion(&pAdapter->pno_comp_var);
16395#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
16396 init_completion(&pAdapter->offchannel_tx_event);
16397#endif
16398 init_completion(&pAdapter->tx_action_cnf_event);
16399#ifdef FEATURE_WLAN_TDLS
16400 init_completion(&pAdapter->tdls_add_station_comp);
16401 init_completion(&pAdapter->tdls_del_station_comp);
16402 init_completion(&pAdapter->tdls_mgmt_comp);
16403 init_completion(&pAdapter->tdls_link_establish_req_comp);
16404#endif
16405
16406#ifdef WLAN_FEATURE_RMC
16407 init_completion(&pAdapter->ibss_peer_info_comp);
16408#endif /* WLAN_FEATURE_RMC */
16409 init_completion(&pAdapter->ula_complete);
16410 init_completion(&pAdapter->change_country_code);
16411
16412#ifdef FEATURE_WLAN_BATCH_SCAN
16413 init_completion(&pAdapter->hdd_set_batch_scan_req_var);
16414 init_completion(&pAdapter->hdd_get_batch_scan_req_var);
16415#endif
Kapil Gupta2b44acb2016-12-30 16:49:51 +053016416 init_completion(&pAdapter->wlan_suspend_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053016417
16418 return;
16419}
c_manjeecfd1efb2015-09-25 19:32:34 +053016420
Anurag Chouhan0b29de02016-12-16 13:18:40 +053016421#ifdef MDNS_OFFLOAD
16422
16423/**
16424 * hdd_mdns_enable_offload_done() - mdns enable offload response api
16425 * @padapter: holds adapter
16426 * @status: response status
16427 *
16428 * Return - None
16429 */
16430void hdd_mdns_enable_offload_done(void *padapter, VOS_STATUS status)
16431{
16432 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16433
16434 ENTER();
16435
16436 if (NULL == adapter)
16437 {
16438 hddLog(VOS_TRACE_LEVEL_ERROR,
16439 "%s: adapter is NULL",__func__);
16440 return;
16441 }
16442
16443 adapter->mdns_status.mdns_enable_status = status;
16444 vos_event_set(&adapter->mdns_status.vos_event);
16445 return;
16446}
16447
16448/**
16449 * hdd_mdns_fqdn_offload_done() - mdns fqdn offload response api
16450 * @padapter: holds adapter
16451 * @status: responce status
16452 *
16453 * Return - None
16454 */
16455void hdd_mdns_fqdn_offload_done(void *padapter, VOS_STATUS status)
16456{
16457 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16458
16459 ENTER();
16460
16461 if (NULL == adapter)
16462 {
16463 hddLog(VOS_TRACE_LEVEL_ERROR,
16464 "%s: adapter is NULL",__func__);
16465 return;
16466 }
16467
16468 adapter->mdns_status.mdns_fqdn_status = status;
16469 return;
16470}
16471
16472/**
16473 * hdd_mdns_resp_offload_done() - mdns resp offload response api
16474 * @padapter: holds adapter
16475 * @status: responce status
16476 *
16477 * Return - None
16478 */
16479void hdd_mdns_resp_offload_done(void *padapter, VOS_STATUS status)
16480{
16481 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16482
16483 ENTER();
16484
16485 if (NULL == adapter)
16486 {
16487 hddLog(VOS_TRACE_LEVEL_ERROR,
16488 "%s: adapter is NULL",__func__);
16489 return;
16490 }
16491
16492 adapter->mdns_status.mdns_resp_status = status;
16493 return;
16494}
16495
16496/**
16497 * wlan_hdd_mdns_process_response_dname() - Process mDNS domain name
16498 * @response: Pointer to a struct hdd_mdns_resp_info
16499 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16500 *
16501 * This function will pack the whole domain name without compression. It will
16502 * add the leading len for each field and add zero length octet to terminate
16503 * the domain name.
16504 *
16505 * Return: Return boolean. TRUE for success, FALSE for fail.
16506 */
16507static bool
16508wlan_hdd_mdns_process_response_dname(struct hdd_mdns_resp_info *response,
16509 sir_mdns_resp_info resp_info)
16510{
16511 uint8_t num;
16512 uint16_t idx;
16513 uint8_t len = 0;
16514
16515 if ((response == NULL) || (response->data == NULL) ||
16516 (response->offset == NULL)) {
16517 hddLog(LOGE, FL("Either data or offset in response is NULL!"));
16518 return FALSE;
16519 }
16520
16521 if ((resp_info == NULL) ||
16522 (resp_info->resp_len >= MAX_MDNS_RESP_LEN)) {
16523 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16524 return FALSE;
16525 }
16526
16527 for (num = 0; num < response->num_entries; num++) {
16528 response->offset[num] =
16529 resp_info->resp_len + MDNS_HEADER_LEN;
16530 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16531 len = strlen((char *)&response->data[idx]);
16532 if ((resp_info->resp_len + len + 1) >= MAX_MDNS_RESP_LEN) {
16533 hddLog(LOGE, FL("resp_len exceeds %d!"),
16534 MAX_MDNS_RESP_LEN);
16535 return FALSE;
16536 }
16537 resp_info->resp_data[resp_info->resp_len] = len;
16538 resp_info->resp_len++;
16539 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16540 &response->data[idx], len);
16541 resp_info->resp_len += len;
16542 }
16543
16544 /* The domain name terminates with the zero length octet */
16545 if (num == response->num_entries) {
16546 if (resp_info->resp_len >= MAX_MDNS_RESP_LEN) {
16547 hddLog(LOGE, FL("resp_len exceeds %d!"),
16548 MAX_MDNS_RESP_LEN);
16549 return FALSE;
16550 }
16551 resp_info->resp_data[resp_info->resp_len] = 0;
16552 resp_info->resp_len++;
16553 }
16554
16555 return TRUE;
16556}
16557
16558/**
16559 * wlan_hdd_mdns_format_response_u16() - Form uint16_t response data
16560 * @value: The uint16_t value is formed to the struct tSirMDNSResponseInfo
16561 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16562 *
16563 * Return: None
16564 */
16565static void wlan_hdd_mdns_format_response_u16(uint16_t value,
16566 sir_mdns_resp_info resp_info)
16567{
16568 uint8_t val_u8;
16569
16570 if ((resp_info == NULL) || (resp_info->resp_data == NULL))
16571 return;
16572 val_u8 = (value & 0xff00) >> 8;
16573 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16574 val_u8 = value & 0xff;
16575 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16576}
16577
16578/**
16579 * wlan_hdd_mdns_format_response_u32() - Form uint32_t response data
16580 * @value: The uint32_t value is formed to the struct tSirMDNSResponseInfo
16581 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16582 *
16583 * Return: None
16584 */
16585static void wlan_hdd_mdns_format_response_u32(uint32_t value,
16586 sir_mdns_resp_info resp_info)
16587{
16588 uint8_t val_u8;
16589
16590 if ((resp_info == NULL) || (resp_info->resp_data == NULL))
16591 return;
16592 val_u8 = (value & 0xff000000) >> 24;
16593 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16594 val_u8 = (value & 0xff0000) >> 16;
16595 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16596 val_u8 = (value & 0xff00) >> 8;
16597 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16598 val_u8 = value & 0xff;
16599 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16600}
16601
16602/**
16603 * wlan_hdd_mdns_process_response_misc() - Process misc info in mDNS response
16604 * @resp_type: Response type for mDNS
16605 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16606 *
16607 * This function will pack the response type, class and TTL (Time To Live).
16608 *
16609 * Return: Return boolean. TRUE for success, FALSE for fail.
16610 */
16611static bool wlan_hdd_mdns_process_response_misc(uint16_t resp_type,
16612 sir_mdns_resp_info resp_info)
16613{
16614 uint16_t len;
16615
16616 if (resp_info == NULL) {
16617 hddLog(LOGE, FL("resp_info is NULL!"));
16618 return FALSE;
16619 }
16620
16621 len = resp_info->resp_len + (2 * sizeof(uint16_t) + sizeof(uint32_t));
16622 if (len >= MAX_MDNS_RESP_LEN) {
16623 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16624 return FALSE;
16625 }
16626
16627 /* Fill Type, Class, TTL */
16628 wlan_hdd_mdns_format_response_u16(resp_type, resp_info);
16629 wlan_hdd_mdns_format_response_u16(MDNS_CLASS, resp_info);
16630 wlan_hdd_mdns_format_response_u32(MDNS_TTL, resp_info);
16631
16632 return TRUE;
16633}
16634
16635/**
16636 * wlan_hdd_mdns_compress_data() - Compress the domain name in mDNS response
16637 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16638 * @response_dst: The response which domain name is compressed.
16639 * @response_src: The response which domain name is matched with response_dst.
16640 * Its offset is used for data compression.
16641 * @num_matched: The number of matched entries between response_dst and
16642 * response_src
16643 *
16644 * This function will form the different fields of domain name in response_dst
16645 * if any. Then use the offset of the matched domain name in response_src to
16646 * compress the matched domain name.
16647 *
16648 * Return: Return boolean. TRUE for success, FALSE for fail.
16649 */
16650static bool
16651wlan_hdd_mdns_compress_data(sir_mdns_resp_info resp_info,
16652 struct hdd_mdns_resp_info *response_dst,
16653 struct hdd_mdns_resp_info *response_src,
16654 uint8_t num_matched)
16655{
16656 uint8_t num, num_diff;
16657 uint16_t value, idx;
16658 uint8_t len = 0;
16659
16660 if ((response_src == NULL) || (response_dst == NULL) ||
16661 (resp_info == NULL)) {
16662 hddLog(LOGE, FL("response info is NULL!"));
16663 return FALSE;
16664 }
16665
16666 if (response_dst->num_entries < num_matched) {
16667 hddLog(LOGE, FL("num_entries is less than num_matched!"));
16668 return FALSE;
16669 }
16670
16671 if (resp_info->resp_len >= MAX_MDNS_RESP_LEN) {
16672 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16673 return FALSE;
16674 }
16675
16676 num_diff = response_dst->num_entries - num_matched;
16677 if ((num_diff > 0) && (response_dst->data == NULL)) {
16678 hddLog(LOGE, FL("response_dst->data is NULL!"));
16679 return FALSE;
16680 }
16681
16682 /*
16683 * Handle the unmatched string at the beginning
16684 * Store the length of octets and the octets
16685 */
16686 for (num = 0; num < num_diff; num++) {
16687 response_dst->offset[num] =
16688 resp_info->resp_len + MDNS_HEADER_LEN;
16689 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16690 len = strlen((char *)&response_dst->data[idx]);
16691 if ((resp_info->resp_len + len + 1) >= MAX_MDNS_RESP_LEN) {
16692 hddLog(LOGE, FL("resp_len exceeds %d!"),
16693 MAX_MDNS_RESP_LEN);
16694 return FALSE;
16695 }
16696 resp_info->resp_data[resp_info->resp_len] = len;
16697 resp_info->resp_len++;
16698 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16699 &response_dst->data[idx], len);
16700 resp_info->resp_len += len;
16701 }
16702 /*
16703 * Handle the matched string from the end
16704 * Just keep the offset and mask the leading two bit
16705 */
16706 if (response_src->num_entries >= num_matched) {
16707 num_diff = response_src->num_entries - num_matched;
16708 value = response_src->offset[num_diff];
16709 if (value > 0) {
16710 value |= 0xc000;
16711 if ((resp_info->resp_len + sizeof(uint16_t)) >=
16712 MAX_MDNS_RESP_LEN) {
16713 hddLog(LOGE, FL("resp_len exceeds %d!"),
16714 MAX_MDNS_RESP_LEN);
16715 return FALSE;
16716 }
16717 wlan_hdd_mdns_format_response_u16(value, resp_info);
16718 return TRUE;
16719 }
16720 }
16721 return FALSE;
16722}
16723
16724/**
16725 * wlan_hdd_mdns_reset_response() - Reset the response info
16726 * @response: The response which info is reset.
16727 *
16728 * Return: None
16729 */
16730static void wlan_hdd_mdns_reset_response(struct hdd_mdns_resp_info *response)
16731{
16732 if (response == NULL)
16733 return;
16734 response->num_entries = 0;
16735 response->data = NULL;
16736 response->offset = NULL;
16737}
16738
16739/**
16740 * wlan_hdd_mdns_init_response() - Initialize the response info
16741 * @response: The response which info is initiatized.
16742 * @resp_dname: The domain name string which might be tokenized.
16743 *
16744 * This function will allocate the memory for both response->data and
16745 * response->offset. Besides, it will also tokenize the domain name to some
16746 * entries and fill response->num_entries with the num of entries.
16747 *
16748 * Return: Return boolean. TRUE for success, FALSE for fail.
16749 */
16750static bool wlan_hdd_mdns_init_response(struct hdd_mdns_resp_info *response,
16751 uint8_t *resp_dname, char separator)
16752{
16753 uint16_t size;
16754
16755 if ((resp_dname == NULL) || (response == NULL)) {
16756 hddLog(LOGE, FL("resp_dname or response is NULL!"));
16757 return FALSE;
16758 }
16759
16760 size = MAX_NUM_FIELD_DOMAINNAME * MAX_LEN_DOMAINNAME_FIELD;
16761 response->data = vos_mem_malloc(size);
16762 if (response->data) {
16763 vos_mem_zero(response->data, size);
16764 if (VOS_STATUS_SUCCESS !=
16765 hdd_string_to_string_array((char *)resp_dname,
16766 response->data,
16767 separator,
16768 &response->num_entries,
16769 MAX_NUM_FIELD_DOMAINNAME,
16770 MAX_LEN_DOMAINNAME_FIELD)) {
16771 hddLog(LOGE, FL("hdd_string_to_string_array fail!"));
16772 goto err_init_resp;
16773 }
16774
16775 if ((response->num_entries > 0) &&
16776 (strlen((char *)&response->data[0]) > 0)) {
16777 size = sizeof(uint16_t) * response->num_entries;
16778 response->offset = vos_mem_malloc(size);
16779 if (response->offset) {
16780 vos_mem_zero(response->offset, size);
16781 return TRUE;
16782 }
16783 }
16784 }
16785
16786err_init_resp:
16787 if (response->data)
16788 vos_mem_free(response->data);
16789 wlan_hdd_mdns_reset_response(response);
16790 return FALSE;
16791}
16792
16793/**
16794 * wlan_hdd_mdns_find_entries_from_end() - Find the matched entries
16795 * @response1: The response info is used to be compared.
16796 * @response2: The response info is used to be compared.
16797 *
16798 * This function will find the matched entries from the end.
16799 *
16800 * Return: Return the number of the matched entries.
16801 */
16802static uint8_t
16803wlan_hdd_mdns_find_entries_from_end(struct hdd_mdns_resp_info *response1,
16804 struct hdd_mdns_resp_info *response2)
16805{
16806 uint8_t min, len1, i;
16807 uint16_t num1, num2;
16808 uint8_t num_matched = 0;
16809
16810 min = VOS_MIN(response1->num_entries, response2->num_entries);
16811
16812 for (i = 1; i <= min; i++) {
16813 num1 = (response1->num_entries - i);
16814 num1 *= MAX_LEN_DOMAINNAME_FIELD;
16815 num2 = (response2->num_entries - i);
16816 num2 *= MAX_LEN_DOMAINNAME_FIELD;
16817 len1 = strlen((char *)&response1->data[num1]);
16818
16819 if ((len1 == 0) ||
16820 (len1 != strlen((char *)&response2->data[num2])))
16821 break;
16822 if (memcmp(&response1->data[num1],
16823 &response2->data[num2], len1))
16824 break;
16825 else
16826 num_matched++;
16827 }
16828
16829 return num_matched;
16830}
16831
16832/**
16833 * wlan_hdd_mdns_find_max() - Find the maximum number of the matched entries
16834 * @matchedlist: Pointer to the array of struct hdd_mdns_resp_matched
16835 * @numlist: The number of the elements in the array matchedlist.
16836 *
16837 * Find the max number of the matched entries among the array matchedlist.
16838 *
16839 * Return: None
16840 */
16841static void wlan_hdd_mdns_find_max(struct hdd_mdns_resp_matched *matchedlist,
16842 uint8_t numlist)
16843{
16844 int j;
16845 struct hdd_mdns_resp_matched tmp;
16846
16847 /* At least two values are used for sorting */
16848 if ((numlist < 2) || (matchedlist == NULL)) {
16849 hddLog(LOGE, FL("At least two values are used for sorting!"));
16850 return;
16851 }
16852
16853 for (j = 0; j < numlist-1; j++) {
16854 if (matchedlist[j].num_matched >
16855 matchedlist[j+1].num_matched) {
16856 vos_mem_copy(&tmp, &matchedlist[j],
16857 sizeof(struct hdd_mdns_resp_matched));
16858 vos_mem_copy(&matchedlist[j], &matchedlist[j+1],
16859 sizeof(struct hdd_mdns_resp_matched));
16860 vos_mem_copy(&matchedlist[j+1], &tmp,
16861 sizeof(struct hdd_mdns_resp_matched));
16862 }
16863 }
16864}
16865
16866/**
16867 * wlan_hdd_mdns_pack_response_type_a() - Pack Type A response
16868 * @ini_config: Pointer to the struct hdd_config_t
16869 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16870 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16871 *
16872 * Type A response include QName, response type, class, TTL and Ipv4.
16873 *
16874 * Return: Return boolean. TRUE for success, FALSE for fail.
16875 */
16876static bool
16877wlan_hdd_mdns_pack_response_type_a(hdd_config_t *ini_config,
16878 sir_mdns_resp_info resp_info,
16879 struct hdd_mdns_resp_info *resptype_a)
16880{
16881 uint16_t value;
16882 uint32_t len;
16883
16884 ENTER();
16885 if ((ini_config == NULL) || (resp_info == NULL) ||
16886 (resptype_a == NULL)) {
16887 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16888 return FALSE;
16889 }
16890
16891 /* No Type A response */
16892 if (strlen((char *)ini_config->mdns_resp_type_a) <= 0)
16893 return TRUE;
16894
16895 /* Wrong response is assigned, just ignore this response */
16896 if (!wlan_hdd_mdns_init_response(resptype_a,
16897 ini_config->mdns_resp_type_a, '.'))
16898 return TRUE;
16899
16900 /* Process response domain name */
16901 if (!wlan_hdd_mdns_process_response_dname(resptype_a, resp_info)) {
16902 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
16903 MDNS_TYPE_A);
16904 return FALSE;
16905 }
16906
16907 /* Process response Type, Class, TTL */
16908 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_A, resp_info)) {
16909 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
16910 MDNS_TYPE_A);
16911 return FALSE;
16912 }
16913
16914 /* Process response RDLength, RData */
16915 len = sizeof(uint16_t) + sizeof(uint32_t);
16916 len += resp_info->resp_len;
16917 if (len >= MAX_MDNS_RESP_LEN) {
16918 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16919 return FALSE;
16920 }
16921 value = sizeof(uint32_t);
16922 wlan_hdd_mdns_format_response_u16(value, resp_info);
16923 wlan_hdd_mdns_format_response_u32(ini_config->mdns_resp_type_a_ipv4,
16924 resp_info);
16925
16926 EXIT();
16927 return TRUE;
16928}
16929
16930/**
16931 * wlan_hdd_mdns_pack_response_type_txt() - Pack Type Txt response
16932 * @ini_config: Pointer to the struct hdd_config_t
16933 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16934 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type txt
16935 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16936 *
16937 * Type Txt response include QName, response type, class, TTL and text content.
16938 * Also, it will find the matched QName from resptype_A and compress the data.
16939 *
16940 * Return: Return boolean. TRUE for success, FALSE for fail.
16941 */
16942static bool
16943wlan_hdd_mdns_pack_response_type_txt(hdd_config_t *ini_config,
16944 sir_mdns_resp_info resp_info,
16945 struct hdd_mdns_resp_info *resptype_txt,
16946 struct hdd_mdns_resp_info *resptype_a)
16947{
16948 uint8_t num_matched;
16949 uint8_t num;
16950 uint16_t idx;
16951 uint16_t value = 0;
16952 uint32_t len;
16953 uint32_t total_len;
16954 bool status;
16955 struct hdd_mdns_resp_info resptype_content;
16956
16957 ENTER();
16958
16959 if ((ini_config == NULL) || (resp_info == NULL) ||
16960 (resptype_txt == NULL)) {
16961 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16962 return FALSE;
16963 }
16964
16965 /* No Type Txt response */
16966 if (strlen((char *)ini_config->mdns_resp_type_txt) <= 0)
16967 return TRUE;
16968
16969 /* Wrong response is assigned, just ignore this response */
16970 if (!wlan_hdd_mdns_init_response(resptype_txt,
16971 ini_config->mdns_resp_type_txt, '.'))
16972 return TRUE;
16973
16974 /*
16975 * For data compression
16976 * Check if any strings are matched with Type A response
16977 */
16978 if (resptype_a && (resptype_a->num_entries > 0)) {
16979 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_txt,
16980 resptype_a);
16981 if (num_matched > 0) {
16982 if (!wlan_hdd_mdns_compress_data(resp_info,
16983 resptype_txt, resptype_a, num_matched)) {
16984 hddLog(LOGE, FL("Fail to compress mDNS "
16985 "response (%d)!"), MDNS_TYPE_TXT);
16986 return FALSE;
16987 }
16988 } else {
16989 /*
16990 * num_matched is zero. Error!
16991 * At least ".local" is needed.
16992 */
16993 hddLog(LOGE, FL("No matched string! Fail to pack mDNS "
16994 "response (%d)!"), MDNS_TYPE_TXT);
16995 return FALSE;
16996 }
16997 } else {
16998 /* no TypeA response, so show the whole data */
16999 if (!wlan_hdd_mdns_process_response_dname(resptype_txt,
17000 resp_info)) {
17001 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17002 MDNS_TYPE_TXT);
17003 return FALSE;
17004 }
17005 }
17006
17007 /* Process response Type, Class, TTL */
17008 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_TXT, resp_info)) {
17009 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17010 MDNS_TYPE_TXT);
17011 return FALSE;
17012 }
17013
17014 /*
17015 * Process response RDLength, RData.
17016 * TypeTxt RData include len.
17017 */
17018 status = wlan_hdd_mdns_init_response(&resptype_content,
17019 ini_config->mdns_resp_type_txt_content,
17020 '/');
17021 if (status == FALSE) {
17022 hddLog(LOGE, FL("wlan_hdd_mdns_init_response FAIL"));
17023 return FALSE;
17024 }
17025
17026 for (num = 0; num < resptype_content.num_entries; num++) {
17027 idx = num * MAX_LEN_DOMAINNAME_FIELD;
17028 value += strlen((char *)&resptype_content.data[idx]);
17029 }
17030
17031 /* content len is uint16_t */
17032 total_len = sizeof(uint16_t);
17033 total_len += resp_info->resp_len + value +
17034 resptype_content.num_entries;
17035
17036 if (total_len >= MAX_MDNS_RESP_LEN) {
17037 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
17038 return FALSE;
17039 }
17040 wlan_hdd_mdns_format_response_u16(value + resptype_content.num_entries,
17041 resp_info);
17042
17043 for (num = 0; num < resptype_content.num_entries; num++) {
17044 idx = num * MAX_LEN_DOMAINNAME_FIELD;
17045 len = strlen((char *)&resptype_content.data[idx]);
17046 resp_info->resp_data[resp_info->resp_len] = len;
17047 resp_info->resp_len++;
17048
17049 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
17050 &resptype_content.data[idx], len);
17051
17052 resp_info->resp_len += len;
17053 hddLog(LOG1, FL("index = %d, len = %d, str = %s"),
17054 num, len, &resptype_content.data[idx]);
17055 }
17056
17057 EXIT();
17058 return TRUE;
17059}
17060
17061/**
17062 * wlan_hdd_mdns_pack_response_type_ptr_dname() - Pack Type PTR domain name
17063 * @ini_config: Pointer to the struct hdd_config_t
17064 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17065 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17066 * domain name
17067 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17068 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17069 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17070 *
17071 * The Type Ptr response include Type PTR domain name in its data field.
17072 * Also, it will find the matched QName from the existing resptype_ptr,
17073 * resptype_txt, resptype_a and then compress the data.
17074 *
17075 * Return: Return boolean. TRUE for success, FALSE for fail.
17076 */
17077static bool
17078wlan_hdd_mdns_pack_response_type_ptr_dname(hdd_config_t *ini_config,
17079 sir_mdns_resp_info resp_info,
17080 struct hdd_mdns_resp_info *resptype_ptr_dn,
17081 struct hdd_mdns_resp_info *resptype_ptr,
17082 struct hdd_mdns_resp_info *resptype_txt,
17083 struct hdd_mdns_resp_info *resptype_a)
17084{
17085 uint8_t num_matched, numlist, size;
17086 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17087 struct hdd_mdns_resp_info *resp;
17088
17089 if ((ini_config == NULL) || (resp_info == NULL) ||
17090 (resptype_ptr == NULL) || (resptype_ptr_dn == NULL)) {
17091 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17092 return FALSE;
17093 }
17094
17095 /* No Type Ptr domain name response */
17096 if (strlen((char *)ini_config->mdns_resp_type_ptr_dname) <= 0)
17097 return TRUE;
17098
17099 /* Wrong response is assigned, just ignore this response */
17100 if (!wlan_hdd_mdns_init_response(resptype_ptr_dn,
17101 ini_config->mdns_resp_type_ptr_dname, '.'))
17102 return TRUE;
17103
17104 /*
17105 * For data compression
17106 * Check if any strings are matched with previous
17107 * response.
17108 */
17109 numlist = 0;
17110 size = (MAX_MDNS_RESP_TYPE-1);
17111 size *= sizeof(struct hdd_mdns_resp_matched);
17112 vos_mem_zero(matchedlist, size);
17113 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_ptr_dn,
17114 resptype_ptr);
17115 if (num_matched > 0) {
17116 matchedlist[numlist].num_matched = num_matched;
17117 matchedlist[numlist].type = MDNS_TYPE_PTR;
17118 numlist++;
17119 }
17120 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17121 num_matched = wlan_hdd_mdns_find_entries_from_end(
17122 resptype_ptr_dn, resptype_txt);
17123 if (num_matched > 0) {
17124 matchedlist[numlist].num_matched = num_matched;
17125 matchedlist[numlist].type = MDNS_TYPE_TXT;
17126 numlist++;
17127 }
17128 }
17129 if (resptype_a && (resptype_a->num_entries > 0)) {
17130 num_matched = wlan_hdd_mdns_find_entries_from_end(
17131 resptype_ptr_dn,resptype_a);
17132 if (num_matched > 0) {
17133 matchedlist[numlist].num_matched = num_matched;
17134 matchedlist[numlist].type = MDNS_TYPE_A;
17135 numlist++;
17136 }
17137 }
17138 if (numlist > 0) {
17139 if (numlist > 1)
17140 wlan_hdd_mdns_find_max(matchedlist, numlist);
17141 resp = NULL;
17142 switch (matchedlist[numlist-1].type) {
17143 case MDNS_TYPE_A:
17144 resp = resptype_a;
17145 break;
17146 case MDNS_TYPE_TXT:
17147 resp = resptype_txt;
17148 break;
17149 case MDNS_TYPE_PTR:
17150 resp = resptype_ptr;
17151 break;
17152 default:
17153 hddLog(LOGE, FL("Fail to compress mDNS response "
17154 "(%d)!"), MDNS_TYPE_PTR_DNAME);
17155 return FALSE;
17156 }
17157 num_matched = matchedlist[numlist-1].num_matched;
17158 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_ptr_dn,
17159 resp, num_matched)) {
17160 hddLog(LOGE, FL("Fail to compress mDNS response "
17161 "(%d)!"), MDNS_TYPE_PTR_DNAME);
17162 return FALSE;
17163 }
17164 } else {
17165 /* num = 0 -> no matched string */
17166 if (!wlan_hdd_mdns_process_response_dname(resptype_ptr_dn,
17167 resp_info)) {
17168 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17169 MDNS_TYPE_PTR_DNAME);
17170 return FALSE;
17171 }
17172 }
17173
17174 return TRUE;
17175}
17176
17177/**
17178 * wlan_hdd_mdns_pack_response_type_ptr() - Pack Type PTR response
17179 * @ini_config: Pointer to the struct hdd_config_t
17180 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17181 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17182 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17183 * domain name
17184 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17185 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17186 *
17187 * The Type Ptr response include QName, response type, class, TTL and
17188 * Type PTR domain name. Also, it will find the matched QName from the
17189 * existing resptype_txt, resptype_a and then compress the data.
17190 *
17191 * Return: Return boolean. TRUE for success, FALSE for fail.
17192 */
17193static bool
17194wlan_hdd_mdns_pack_response_type_ptr(hdd_config_t *ini_config,
17195 sir_mdns_resp_info resp_info,
17196 struct hdd_mdns_resp_info *resptype_ptr,
17197 struct hdd_mdns_resp_info *resptype_ptr_dn,
17198 struct hdd_mdns_resp_info *resptype_txt,
17199 struct hdd_mdns_resp_info *resptype_a)
17200{
17201 uint8_t num_matched, num_matched1;
17202 uint16_t value;
17203 uint8_t val_u8;
17204 uint32_t offset_data_len, len;
17205
17206 ENTER();
17207 if ((ini_config == NULL) || (resp_info == NULL) ||
17208 (resptype_ptr == NULL) || (resptype_ptr_dn == NULL)) {
17209 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17210 return FALSE;
17211 }
17212
17213 /* No Type Ptr response */
17214 if (strlen((char *)ini_config->mdns_resp_type_ptr) <= 0)
17215 return TRUE;
17216
17217 /* Wrong response is assigned, just ignore this response */
17218 if (!wlan_hdd_mdns_init_response(resptype_ptr,
17219 ini_config->mdns_resp_type_ptr, '.'))
17220 return TRUE;
17221
17222 /*
17223 * For data compression
17224 * Check if any strings are matched with Type A response
17225 */
17226 num_matched = 0;
17227 num_matched1 = 0;
17228 if (resptype_a && (resptype_a->num_entries > 0)) {
17229 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_ptr,
17230 resptype_a);
17231 }
17232 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17233 num_matched1 = wlan_hdd_mdns_find_entries_from_end(
17234 resptype_ptr, resptype_txt);
17235 }
17236 if ((num_matched != num_matched1) ||
17237 ((num_matched > 0) && (num_matched1 > 0))) {
17238 if (num_matched >= num_matched1) {
17239 if (!wlan_hdd_mdns_compress_data(resp_info,
17240 resptype_ptr, resptype_a, num_matched)) {
17241 hddLog(LOGE, FL("Fail to compress mDNS "
17242 "response (%d)!"), MDNS_TYPE_PTR);
17243 return FALSE;
17244 }
17245 } else {
17246 /* num_matched is less than num_matched1 */
17247 if (!wlan_hdd_mdns_compress_data(resp_info,
17248 resptype_ptr, resptype_txt, num_matched1)) {
17249 hddLog(LOGE, FL("Fail to compress mDNS "
17250 "response (%d)!"), MDNS_TYPE_PTR);
17251 return FALSE;
17252 }
17253 }
17254 } else {
17255 /*
17256 * Both num_matched and num_matched1 are zero.
17257 * no TypeA & TypeTxt
17258 */
17259 if (!wlan_hdd_mdns_process_response_dname(resptype_ptr,
17260 resp_info)) {
17261 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17262 MDNS_TYPE_PTR);
17263 return FALSE;
17264 }
17265 }
17266
17267 /* Process response Type, Class, TTL */
17268 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_PTR, resp_info)) {
17269 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17270 MDNS_TYPE_PTR);
17271 return FALSE;
17272 }
17273
17274 /*
17275 * Process response RDLength, RData (Ptr domain name)
17276 * Save the offset of RData length
17277 */
17278 offset_data_len = resp_info->resp_len;
17279 resp_info->resp_len += sizeof(uint16_t);
17280
17281 if (!wlan_hdd_mdns_pack_response_type_ptr_dname(ini_config, resp_info,
17282 resptype_ptr_dn, resptype_ptr,
17283 resptype_txt, resptype_a)) {
17284 return FALSE;
17285 }
17286 /* Set the RData length */
17287 len = offset_data_len + sizeof(uint16_t);
17288 if ((resptype_ptr_dn->num_entries > 0) &&
17289 (resp_info->resp_len > len)) {
17290 value = resp_info->resp_len - len;
17291 val_u8 = (value & 0xff00) >> 8;
17292 resp_info->resp_data[offset_data_len] = val_u8;
17293 val_u8 = value & 0xff;
17294 resp_info->resp_data[offset_data_len+1] = val_u8;
17295 } else {
17296 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17297 MDNS_TYPE_PTR);
17298 return FALSE;
17299 }
17300
17301 EXIT();
17302 return TRUE;
17303}
17304
17305/**
17306 * wlan_hdd_mdns_pack_response_type_srv_target()- Pack Type Service Target
17307 * @ini_config: Pointer to the struct hdd_config_t
17308 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17309 * @resptype_srv_tgt: Pointer to the struct hdd_mdns_resp_info of Type Srv
17310 * target
17311 * @resptype_srv: Pointer to the struct hdd_mdns_resp_info of Type Srv
17312 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17313 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17314 * domain name
17315 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17316 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17317 *
17318 * The Type service target is one of the data field in the Type SRV response.
17319 * Also, it will find the matched QName from the existing resptype_srv,
17320 * resptype_ptr, resptype_ptr_dn, resptype_txt, resptype_a and then compress
17321 * the data.
17322 *
17323 * Return: Return boolean. TRUE for success, FALSE for fail.
17324 */
17325static bool
17326wlan_hdd_mdns_pack_response_type_srv_target(hdd_config_t *ini_config,
17327 sir_mdns_resp_info resp_info,
17328 struct hdd_mdns_resp_info *resptype_srv_tgt,
17329 struct hdd_mdns_resp_info *resptype_srv,
17330 struct hdd_mdns_resp_info *resptype_ptr,
17331 struct hdd_mdns_resp_info *resptype_ptr_dn,
17332 struct hdd_mdns_resp_info *resptype_txt,
17333 struct hdd_mdns_resp_info *resptype_a)
17334{
17335 uint8_t num_matched, num, size;
17336 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17337 struct hdd_mdns_resp_info *resp;
17338
17339 if ((ini_config == NULL) || (resp_info == NULL) ||
17340 (resptype_srv == NULL) || (resptype_srv_tgt == NULL)) {
17341 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17342 return FALSE;
17343 }
17344
17345 /* No Type Srv Target response */
17346 if (strlen((char *)ini_config->mdns_resp_type_srv_target) <= 0)
17347 return TRUE;
17348
17349 /* Wrong response is assigned, just ignore this response */
17350 if (!wlan_hdd_mdns_init_response(resptype_srv_tgt,
17351 ini_config->mdns_resp_type_srv_target, '.'))
17352 return TRUE;
17353
17354 /*
17355 * For data compression
17356 * Check if any strings are matched with previous response.
17357 */
17358 num = 0;
17359 size = (MAX_MDNS_RESP_TYPE-1);
17360 size *= sizeof(struct hdd_mdns_resp_matched);
17361 vos_mem_zero(matchedlist, size);
17362 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv_tgt,
17363 resptype_srv);
17364 if (num_matched > 0) {
17365 matchedlist[num].num_matched = num_matched;
17366 matchedlist[num].type = MDNS_TYPE_SRV;
17367 num++;
17368 }
17369 if (resptype_ptr && (resptype_ptr->num_entries > 0)) {
17370 if (resptype_ptr_dn && (resptype_ptr_dn->num_entries > 0)) {
17371 num_matched = wlan_hdd_mdns_find_entries_from_end(
17372 resptype_srv_tgt, resptype_ptr_dn);
17373 if (num_matched > 0) {
17374 matchedlist[num].num_matched = num_matched;
17375 matchedlist[num].type = MDNS_TYPE_PTR_DNAME;
17376 num++;
17377 }
17378 }
17379 num_matched = wlan_hdd_mdns_find_entries_from_end(
17380 resptype_srv_tgt, resptype_ptr);
17381 if (num_matched > 0) {
17382 matchedlist[num].num_matched = num_matched;
17383 matchedlist[num].type = MDNS_TYPE_PTR;
17384 num++;
17385 }
17386 }
17387 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17388 num_matched = wlan_hdd_mdns_find_entries_from_end(
17389 resptype_srv_tgt, resptype_txt);
17390 if (num_matched > 0) {
17391 matchedlist[num].num_matched = num_matched;
17392 matchedlist[num].type = MDNS_TYPE_TXT;
17393 num++;
17394 }
17395 }
17396 if (resptype_a && (resptype_a->num_entries > 0)) {
17397 num_matched = wlan_hdd_mdns_find_entries_from_end(
17398 resptype_srv_tgt, resptype_a);
17399 if (num_matched > 0) {
17400 matchedlist[num].num_matched = num_matched;
17401 matchedlist[num].type = MDNS_TYPE_A;
17402 num++;
17403 }
17404 }
17405 if (num > 0) {
17406 if (num > 1)
17407 wlan_hdd_mdns_find_max(matchedlist, num);
17408 resp = NULL;
17409 switch (matchedlist[num-1].type) {
17410 case MDNS_TYPE_A:
17411 resp = resptype_a;
17412 break;
17413 case MDNS_TYPE_TXT:
17414 resp = resptype_txt;
17415 break;
17416 case MDNS_TYPE_PTR:
17417 resp = resptype_ptr;
17418 break;
17419 case MDNS_TYPE_PTR_DNAME:
17420 resp = resptype_ptr_dn;
17421 break;
17422 case MDNS_TYPE_SRV:
17423 resp = resptype_srv;
17424 break;
17425 default:
17426 hddLog(LOGE, FL("Fail to compress mDNS response "
17427 "(%d)!"), MDNS_TYPE_SRV_TARGET);
17428 return FALSE;
17429 }
17430 num_matched = matchedlist[num-1].num_matched;
17431 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_srv_tgt,
17432 resp, num_matched)) {
17433 hddLog(LOGE, FL("Fail to compress mDNS response "
17434 "(%d)!"), MDNS_TYPE_SRV_TARGET);
17435 return FALSE;
17436 }
17437 } else {
17438 /* num = 0 -> no matched string */
17439 if (!wlan_hdd_mdns_process_response_dname(resptype_srv_tgt,
17440 resp_info)) {
17441 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17442 MDNS_TYPE_SRV_TARGET);
17443 return FALSE;
17444 }
17445 }
17446
17447 return TRUE;
17448}
17449
17450/**
17451 * wlan_hdd_mdns_pack_response_type_srv()- Pack Type Service response
17452 * @ini_config: Pointer to the struct hdd_config_t
17453 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17454 * @resptype_srv: Pointer to the struct hdd_mdns_resp_info of Type Srv
17455 * @resptype_srv_tgt: Pointer to the struct hdd_mdns_resp_info of Type Srv
17456 * target
17457 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17458 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17459 * domain name
17460 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17461 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17462 *
17463 * The Type SRV (Service) response include QName, response type, class, TTL
17464 * and four kinds of data fields. Also, it will find the matched QName from
17465 * the existing resptype_ptr, resptype_ptr_dn, resptype_txt, resptype_a and
17466 * then compress the data.
17467 *
17468 * Return: Return boolean. TRUE for success, FALSE for fail.
17469 */
17470static bool
17471wlan_hdd_mdns_pack_response_type_srv(hdd_config_t *ini_config,
17472 sir_mdns_resp_info resp_info,
17473 struct hdd_mdns_resp_info *resptype_srv,
17474 struct hdd_mdns_resp_info *resptype_srv_tgt,
17475 struct hdd_mdns_resp_info *resptype_ptr,
17476 struct hdd_mdns_resp_info *resptype_ptr_dn,
17477 struct hdd_mdns_resp_info *resptype_txt,
17478 struct hdd_mdns_resp_info *resptype_a)
17479{
17480 uint8_t num_matched, num, size;
17481 uint16_t value;
17482 uint8_t val_u8;
17483 uint32_t offset_data_len, len;
17484 struct hdd_mdns_resp_info *resp;
17485 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17486
17487 ENTER();
17488
17489 if ((ini_config == NULL) || (resp_info == NULL) ||
17490 (resptype_srv == NULL) || (resptype_srv_tgt == NULL)) {
17491 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17492 return FALSE;
17493 }
17494
17495 /* No Type Srv response */
17496 if (strlen((char *)ini_config->mdns_resp_type_srv) <= 0)
17497 return TRUE;
17498
17499 /* Wrong response is assigned, just ignore this response */
17500 if (!wlan_hdd_mdns_init_response(resptype_srv,
17501 ini_config->mdns_resp_type_srv, '.'))
17502 return TRUE;
17503
17504 /*
17505 * For data compression
17506 * Check if any strings are matched with Type A response
17507 */
17508 num = 0;
17509 size = (MAX_MDNS_RESP_TYPE-1);
17510 size *= sizeof(struct hdd_mdns_resp_matched);
17511 vos_mem_zero(matchedlist, size);
17512 if (resptype_ptr && (resptype_ptr->num_entries > 0)) {
17513 if (resptype_ptr_dn && (resptype_ptr_dn->num_entries > 0)) {
17514 num_matched = wlan_hdd_mdns_find_entries_from_end(
17515 resptype_srv,
17516 resptype_ptr_dn);
17517 if (num_matched > 0) {
17518 matchedlist[num].num_matched = num_matched;
17519 matchedlist[num].type = MDNS_TYPE_PTR_DNAME;
17520 num++;
17521 }
17522 }
17523 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17524 resptype_ptr);
17525 if (num_matched > 0) {
17526 matchedlist[num].num_matched = num_matched;
17527 matchedlist[num].type = MDNS_TYPE_PTR;
17528 num++;
17529 }
17530 }
17531 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17532 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17533 resptype_txt);
17534 if (num_matched > 0) {
17535 matchedlist[num].num_matched =num_matched;
17536 matchedlist[num].type = MDNS_TYPE_TXT;
17537 num++;
17538 }
17539 }
17540 if (resptype_a && (resptype_a->num_entries > 0)) {
17541 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17542 resptype_a);
17543 if (num_matched > 0) {
17544 matchedlist[num].num_matched = num_matched;
17545 matchedlist[num].type = MDNS_TYPE_A;
17546 num++;
17547 }
17548 }
17549 if (num > 0) {
17550 if (num > 1)
17551 wlan_hdd_mdns_find_max(matchedlist, num);
17552 resp = NULL;
17553 switch (matchedlist[num-1].type) {
17554 case MDNS_TYPE_A:
17555 resp = resptype_a;
17556 break;
17557 case MDNS_TYPE_TXT:
17558 resp = resptype_txt;
17559 break;
17560 case MDNS_TYPE_PTR:
17561 resp = resptype_ptr;
17562 break;
17563 case MDNS_TYPE_PTR_DNAME:
17564 resp = resptype_ptr_dn;
17565 break;
17566 default:
17567 hddLog(LOGE, FL("Fail to compress mDNS response "
17568 "(%d)!"), MDNS_TYPE_SRV);
17569 return FALSE;
17570 }
17571 num_matched = matchedlist[num-1].num_matched;
17572 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_srv,
17573 resp, num_matched)) {
17574 hddLog(LOGE, FL("Fail to compress mDNS response "
17575 "(%d)!"), MDNS_TYPE_SRV);
17576 return FALSE;
17577 }
17578 } else {
17579 /* num = 0 -> no matched string */
17580 if (!wlan_hdd_mdns_process_response_dname(resptype_srv,
17581 resp_info)) {
17582 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17583 MDNS_TYPE_SRV);
17584 return FALSE;
17585 }
17586 }
17587
17588 /* Process response Type, Class, TTL */
17589 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_SRV, resp_info)) {
17590 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17591 MDNS_TYPE_SRV);
17592 return FALSE;
17593 }
17594
17595 /*
17596 * Process response RDLength, RData (Srv target name)
17597 * Save the offset of RData length
17598 */
17599 offset_data_len = resp_info->resp_len;
17600 resp_info->resp_len += sizeof(uint16_t);
17601
17602 len = resp_info->resp_len + (3 * sizeof(uint16_t));
17603 if (len >= MAX_MDNS_RESP_LEN) {
17604 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
17605 return FALSE;
17606 }
17607
17608 /* set Srv Priority */
17609 value = ini_config->mdns_resp_type_srv_priority;
17610 wlan_hdd_mdns_format_response_u16(value, resp_info);
17611 /* set Srv Weight */
17612 value = ini_config->mdns_resp_type_srv_weight;
17613 wlan_hdd_mdns_format_response_u16(value, resp_info);
17614 /* set Srv Port */
17615 value = ini_config->mdns_resp_type_srv_port;
17616 wlan_hdd_mdns_format_response_u16(value, resp_info);
17617
17618 if (!wlan_hdd_mdns_pack_response_type_srv_target(ini_config, resp_info,
17619 resptype_srv_tgt, resptype_srv,
17620 resptype_ptr, resptype_ptr_dn,
17621 resptype_txt, resptype_a)) {
17622 return FALSE;
17623 }
17624 /* Set the RData length */
17625 len = offset_data_len + sizeof(uint16_t);
17626 if ((resptype_srv_tgt->num_entries > 0) &&
17627 (resp_info->resp_len > len)) {
17628 value = resp_info->resp_len - len;
17629 val_u8 = (value & 0xff00) >> 8;
17630 resp_info->resp_data[offset_data_len] = val_u8;
17631 val_u8 = value & 0xff;
17632 resp_info->resp_data[offset_data_len+1] = val_u8;
17633 } else {
17634 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17635 MDNS_TYPE_SRV);
17636 return FALSE;
17637 }
17638
17639 EXIT();
17640 return TRUE;
17641}
17642
17643/**
17644 * wlan_hdd_mdns_free_mem() - Free the allocated memory
17645 * @response: Pointer to the struct hdd_mdns_resp_info
17646 *
17647 * Return: None
17648 */
17649static void wlan_hdd_mdns_free_mem(struct hdd_mdns_resp_info *response)
17650{
17651 if (response && response->data)
17652 vos_mem_free(response->data);
17653 if (response && response->offset)
17654 vos_mem_free(response->offset);
17655}
17656
17657/**
17658 * wlan_hdd_mdns_pack_response() - Pack mDNS response
17659 * @ini_config: Pointer to the struct hdd_config_t
17660 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17661 *
17662 * This function will pack four types of responses (Type A, Type Txt, Type Ptr
17663 * and Type Service). Each response contains QName, response type, class, TTL
17664 * and data fields.
17665 *
17666 * Return: Return boolean. TRUE for success, FALSE for fail.
17667 */
17668static bool wlan_hdd_mdns_pack_response(hdd_config_t *ini_config,
17669 sir_mdns_resp_info resp_info)
17670{
17671 struct hdd_mdns_resp_info resptype_a, resptype_txt;
17672 struct hdd_mdns_resp_info resptype_ptr, resptype_ptr_dn;
17673 struct hdd_mdns_resp_info resptype_srv, resptype_srv_tgt;
17674 uint32_t num_res_records = 0;
17675 bool status = FALSE;
17676
17677 ENTER();
17678
17679 wlan_hdd_mdns_reset_response(&resptype_a);
17680 wlan_hdd_mdns_reset_response(&resptype_txt);
17681 wlan_hdd_mdns_reset_response(&resptype_ptr);
17682 wlan_hdd_mdns_reset_response(&resptype_ptr_dn);
17683 wlan_hdd_mdns_reset_response(&resptype_srv);
17684 wlan_hdd_mdns_reset_response(&resptype_srv_tgt);
17685
17686 resp_info->resp_len = 0;
17687
17688 /* Process Type A response */
17689 if (!wlan_hdd_mdns_pack_response_type_a(ini_config, resp_info,
17690 &resptype_a))
17691 goto err_resptype_a;
17692
17693 if ((resptype_a.num_entries > 0) &&
17694 (strlen((char *)&resptype_a.data[0]) > 0))
17695 num_res_records++;
17696
17697 /* Process Type TXT response */
17698 if (!wlan_hdd_mdns_pack_response_type_txt(ini_config, resp_info,
17699 &resptype_txt, &resptype_a))
17700 goto err_resptype_txt;
17701
17702 if ((resptype_txt.num_entries > 0) &&
17703 (strlen((char *)&resptype_txt.data[0]) > 0))
17704 num_res_records++;
17705
17706 /* Process Type PTR response */
17707 if (!wlan_hdd_mdns_pack_response_type_ptr(ini_config, resp_info,
17708 &resptype_ptr, &resptype_ptr_dn,
17709 &resptype_txt, &resptype_a))
17710 goto err_resptype_ptr;
17711
17712 if ((resptype_ptr.num_entries > 0) &&
17713 (strlen((char *)&resptype_ptr.data[0]) > 0))
17714 num_res_records++;
17715
17716 /* Process Type SRV response */
17717 if (!wlan_hdd_mdns_pack_response_type_srv(ini_config, resp_info,
17718 &resptype_srv, &resptype_srv_tgt,
17719 &resptype_ptr, &resptype_ptr_dn,
17720 &resptype_txt, &resptype_a))
17721 goto err_resptype_srv;
17722
17723 if ((resptype_srv.num_entries > 0) &&
17724 (strlen((char *)&resptype_srv.data[0]) > 0))
17725 num_res_records++;
17726
17727 resp_info->resourceRecord_count = num_res_records;
17728 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
17729 "%s: Pack mDNS response data successfully!", __func__);
17730 status = TRUE;
17731
17732err_resptype_srv:
17733 wlan_hdd_mdns_free_mem(&resptype_srv);
17734 wlan_hdd_mdns_free_mem(&resptype_srv_tgt);
17735
17736err_resptype_ptr:
17737 wlan_hdd_mdns_free_mem(&resptype_ptr);
17738 wlan_hdd_mdns_free_mem(&resptype_ptr_dn);
17739
17740err_resptype_txt:
17741 wlan_hdd_mdns_free_mem(&resptype_txt);
17742
17743err_resptype_a:
17744 wlan_hdd_mdns_free_mem(&resptype_a);
17745
17746 EXIT();
17747 return status;
17748}
17749
17750/**
17751 * wlan_hdd_set_mdns_offload() - Enable mDNS offload
17752 * @hostapd_adapter: Pointer to the struct hdd_adapter_t
17753 *
17754 * This function will set FQDN/unique FQDN (full qualified domain name)
17755 * and the mDNS response. Then send them to SME.
17756 *
17757 * Return: Return boolean. TRUE for success, FALSE for fail.
17758 */
17759bool wlan_hdd_set_mdns_offload(hdd_adapter_t *hostapd_adapter)
17760{
17761 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(hostapd_adapter);
17762 sir_mdns_offload_info mdns_offload_info;
17763 sir_mdns_fqdn_info mdns_fqdn_info;
17764 sir_mdns_resp_info mdns_resp_info;
17765 uint32_t fqdn_len, ufqdn_len;
17766
17767 ENTER();
17768
17769 /* 1. Prepare the MDNS fqdn request to send to SME */
17770 fqdn_len = strlen(hdd_ctx->cfg_ini->mdns_fqdn);
17771 ufqdn_len = strlen(hdd_ctx->cfg_ini->mdns_uniquefqdn);
17772 if ((fqdn_len == 0) && (ufqdn_len == 0)) {
17773 hddLog(LOGE, FL("No mDNS FQDN or UFQDN is assigned fqdn_len %d,"
17774 "ufqdn_len %d!"), fqdn_len, ufqdn_len);
17775 return FALSE;
17776 }
17777
17778 mdns_fqdn_info = vos_mem_malloc(sizeof(*mdns_fqdn_info));
17779 if (NULL == mdns_fqdn_info) {
17780 hddLog(LOGE, FL("could not allocate tSirMDNSFqdnInfo!"));
17781 return FALSE;
17782 }
17783 /* MDNS fqdn request */
17784 if (fqdn_len > 0) {
17785 vos_mem_zero(mdns_fqdn_info, sizeof(*mdns_fqdn_info));
17786 mdns_fqdn_info->bss_idx = hostapd_adapter->sessionId;
17787 mdns_fqdn_info->fqdn_type = MDNS_FQDN_TYPE_GENERAL;
17788 mdns_fqdn_info->fqdn_len = fqdn_len;
17789 mdns_fqdn_info->mdns_fqdn_callback = hdd_mdns_fqdn_offload_done;
17790 mdns_fqdn_info->mdns_fqdn_cb_context = hostapd_adapter;
17791 vos_mem_copy(mdns_fqdn_info->fqdn_data,
17792 hdd_ctx->cfg_ini->mdns_fqdn,
17793 mdns_fqdn_info->fqdn_len);
17794
17795 if (eHAL_STATUS_SUCCESS !=
17796 sme_set_mdns_fqdn(hdd_ctx->hHal, mdns_fqdn_info)) {
17797 hddLog(LOGE, FL("sme_set_mdns_fqdn fail!"));
17798 vos_mem_free(mdns_fqdn_info);
17799 return FALSE;
17800 }
17801 }
17802 /* MDNS unique fqdn request */
17803 if (ufqdn_len > 0) {
17804 vos_mem_zero(mdns_fqdn_info, sizeof(*mdns_fqdn_info));
17805 mdns_fqdn_info->bss_idx = hostapd_adapter->sessionId;
17806 mdns_fqdn_info->fqdn_type = MDNS_FQDN_TYPE_UNIQUE;
17807 mdns_fqdn_info->fqdn_len = ufqdn_len;
17808 mdns_fqdn_info->mdns_fqdn_callback = hdd_mdns_fqdn_offload_done;
17809 mdns_fqdn_info->mdns_fqdn_cb_context = hostapd_adapter;
17810 vos_mem_copy(mdns_fqdn_info->fqdn_data,
17811 hdd_ctx->cfg_ini->mdns_uniquefqdn,
17812 mdns_fqdn_info->fqdn_len);
17813 if (eHAL_STATUS_SUCCESS !=
17814 sme_set_mdns_fqdn(hdd_ctx->hHal, mdns_fqdn_info)) {
17815 hddLog(LOGE, FL("sme_set_mdns_fqdn fail!"));
17816 vos_mem_free(mdns_fqdn_info);
17817 return FALSE;
17818 }
17819 }
17820 vos_mem_free(mdns_fqdn_info);
17821
17822 /* 2. Prepare the MDNS response request to send to SME */
17823 mdns_resp_info = vos_mem_malloc(sizeof(*mdns_resp_info));
17824 if (NULL == mdns_resp_info) {
17825 hddLog(LOGE, FL("could not allocate tSirMDNSResponseInfo!"));
17826 return FALSE;
17827 }
17828
17829 vos_mem_zero(mdns_resp_info, sizeof(*mdns_resp_info));
17830 mdns_resp_info->bss_idx = hostapd_adapter->sessionId;
17831 mdns_resp_info->mdns_resp_callback = hdd_mdns_resp_offload_done;
17832 mdns_resp_info->mdns_resp_cb_context = hostapd_adapter;
17833 if (!wlan_hdd_mdns_pack_response(hdd_ctx->cfg_ini, mdns_resp_info)) {
17834 hddLog(LOGE, FL("wlan_hdd_pack_mdns_response fail!"));
17835 vos_mem_free(mdns_resp_info);
17836 return FALSE;
17837 }
17838 if (eHAL_STATUS_SUCCESS !=
17839 sme_set_mdns_resp(hdd_ctx->hHal, mdns_resp_info)) {
17840 hddLog(LOGE, FL("sme_set_mdns_resp fail!"));
17841 vos_mem_free(mdns_resp_info);
17842 return FALSE;
17843 }
17844 vos_mem_free(mdns_resp_info);
17845
17846 /* 3. Prepare the MDNS Enable request to send to SME */
17847 mdns_offload_info = vos_mem_malloc(sizeof(*mdns_offload_info));
17848 if (NULL == mdns_offload_info) {
17849 hddLog(LOGE, FL("could not allocate tSirMDNSOffloadInfo!"));
17850 return FALSE;
17851 }
17852
17853 vos_mem_zero(mdns_offload_info, sizeof(*mdns_offload_info));
17854
17855 mdns_offload_info->bss_idx = hostapd_adapter->sessionId;
17856 mdns_offload_info->enable = hdd_ctx->cfg_ini->enable_mdns_offload;
17857 mdns_offload_info->mdns_enable_callback = hdd_mdns_enable_offload_done;
17858 mdns_offload_info->mdns_enable_cb_context = hostapd_adapter;
17859 if (eHAL_STATUS_SUCCESS !=
17860 sme_set_mdns_offload(hdd_ctx->hHal, mdns_offload_info)) {
17861 hddLog(LOGE, FL("sme_set_mdns_offload fail!"));
17862 vos_mem_free(mdns_offload_info);
17863 return FALSE;
17864 }
17865
17866 vos_mem_free(mdns_offload_info);
17867 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
17868 "%s: enable mDNS offload successfully!", __func__);
17869 return TRUE;
17870}
Manjeet Singh3ed79242017-01-11 19:04:32 +053017871
17872
Anurag Chouhan0b29de02016-12-16 13:18:40 +053017873#endif /* MDNS_OFFLOAD */
c_manjeecfd1efb2015-09-25 19:32:34 +053017874
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053017875/**
17876 * wlan_hdd_start_sap() - This function starts bss of SAP.
17877 * @ap_adapter: SAP adapter
17878 *
17879 * This function will process the starting of sap adapter.
17880 *
17881 * Return: void.
17882 */
17883void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter)
17884{
17885 hdd_ap_ctx_t *hdd_ap_ctx;
17886 hdd_hostapd_state_t *hostapd_state;
17887 VOS_STATUS vos_status;
17888 hdd_context_t *hdd_ctx;
17889 tsap_Config_t *pConfig;
17890
17891 if (NULL == ap_adapter) {
17892 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
17893 FL("ap_adapter is NULL here"));
17894 return;
17895 }
17896
17897 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
17898 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
17899 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
17900 pConfig = &ap_adapter->sessionCtx.ap.sapConfig;
17901
17902 mutex_lock(&hdd_ctx->sap_lock);
17903 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
17904 goto end;
17905
17906 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
17907 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
17908 goto end;
17909 }
17910
17911 vos_event_reset(&hostapd_state->vosEvent);
17912 if (WLANSAP_StartBss(hdd_ctx->pvosContext, hdd_hostapd_SAPEventCB,
17913 &hdd_ap_ctx->sapConfig, (v_PVOID_t)ap_adapter->dev)
17914 != VOS_STATUS_SUCCESS) {
17915 goto end;
17916 }
17917
17918 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
17919 FL("Waiting for SAP to start"));
17920 vos_status = vos_wait_single_event(&hostapd_state->vosEvent, 10000);
17921 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
17922 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
17923 FL("SAP Start failed"));
17924 goto end;
17925 }
17926 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
17927 FL("SAP Start Success"));
17928 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
17929
17930 wlan_hdd_incr_active_session(hdd_ctx, ap_adapter->device_mode);
17931 hostapd_state->bCommit = TRUE;
17932
17933end:
17934 mutex_unlock(&hdd_ctx->sap_lock);
17935 return;
17936}
17937
Manjeet Singh3ed79242017-01-11 19:04:32 +053017938#ifdef WLAN_FEATURE_TSF
17939
17940/**
17941 * hdd_tsf_cb() - handle tsf request callback
17942 *
17943 * @pcb_cxt: pointer to the hdd_contex
17944 * @ptsf: pointer to struct stsf
17945 *
17946 * Based on the request sent .
17947 *
17948 * Return: Describe the execute result of this routine
17949 */
17950static int hdd_tsf_cb(void *pcb_ctx, struct stsf *ptsf)
17951{
17952 hdd_context_t *hddctx;
17953 int status;
17954 hdd_adapter_t* adapter = (hdd_adapter_t*)pcb_ctx;
17955
17956 if (pcb_ctx == NULL || ptsf == NULL) {
17957 hddLog(VOS_TRACE_LEVEL_ERROR,
17958 FL("HDD context is not valid"));
17959 return -EINVAL;
17960 }
17961
17962 hddctx = (hdd_context_t *)pcb_ctx;
17963 status = wlan_hdd_validate_context(hddctx);
17964 if (0 != status)
17965 return -EINVAL;
17966
17967 if (NULL == adapter) {
17968 hddLog(VOS_TRACE_LEVEL_ERROR,
17969 FL("failed to find adapter"));
17970 return -EINVAL;
17971 }
17972
17973 hddLog(VOS_TRACE_LEVEL_INFO,
17974 FL("tsf cb handle event, device_mode is %d"),
17975 adapter->device_mode);
17976
17977 /* copy the return value to hdd_tsf_ctx in adapter*/
17978 if (ptsf->tsf_req_status) {
17979
17980 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17981 adapter->tsf_cap_ctx.tsf_get_state = TSF_NOT_RETURNED_BY_FW;
17982 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17983 vos_event_set (&adapter->tsf_cap_ctx.tsf_capture_done_event);
17984 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17985
17986 hddLog(VOS_TRACE_LEVEL_ERROR, FL("tsf req failure :%d"),
17987 ptsf->tsf_req_status);
17988 return ptsf->tsf_req_status;
17989 }
17990 /* If this is a get request.Store the tsf values in adapter. */
17991 if (!ptsf->set_tsf_req) {
17992 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17993 adapter->tsf_cap_ctx.tsf_low = ptsf->tsf_low;
17994 adapter->tsf_cap_ctx.tsf_high = ptsf->tsf_high;
17995 adapter->tsf_cap_ctx.tsf_get_state = TSF_RETURN;
17996 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17997 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17998
17999 hddLog(VOS_TRACE_LEVEL_INFO,
18000 FL("hdd_get_tsf_cb sta=%u, tsf_low=%u, tsf_high=%u"),
18001 adapter->sessionId, ptsf->tsf_low, ptsf->tsf_high);
18002 }
18003 else {
18004 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18005 adapter->tsf_cap_ctx.tsf_capture_state = TSF_CAP_STATE;
18006 adapter->tsf_cap_ctx.tsf_get_state = TSF_CURRENT_IN_CAP_STATE;
18007 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18008 }
18009 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18010 vos_event_set (&adapter->tsf_cap_ctx.tsf_capture_done_event);
18011 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18012
18013 /* free allocated mem */
18014 vos_mem_free(ptsf);
18015
18016 return 0;
18017}
18018
18019/**
18020 * hdd_capture_tsf() - capture tsf
18021 *
18022 * @adapter: pointer to adapter
18023 * @buf: pointer to upper layer buf
18024 * @len : the length of buf
18025 *
18026 * This function returns tsf value to uplayer.
18027 *
18028 * Return: Describe the execute result of this routine
18029 */
18030int hdd_capture_tsf(hdd_adapter_t *adapter, uint32_t *buf, int len)
18031{
18032 int ret = 0;
18033 hdd_station_ctx_t *hdd_sta_ctx;
18034 hdd_context_t *hdd_ctx;
18035 tSirCapTsfParams cap_tsf_params;
18036 VOS_STATUS status;
18037
18038 if (adapter == NULL || buf == NULL) {
18039 hddLog(VOS_TRACE_LEVEL_ERROR,
18040 FL("invalid pointer"));
18041 return -EINVAL;
18042 }
18043 if (len != 1)
18044 return -EINVAL;
18045
18046 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
18047
18048 if (wlan_hdd_validate_context(hdd_ctx)) {
18049 hddLog(VOS_TRACE_LEVEL_ERROR,
18050 FL("invalid hdd ctx"));
18051 return -EINVAL;
18052 }
18053 if (adapter->device_mode == WLAN_HDD_INFRA_STATION ||
18054 adapter->device_mode == WLAN_HDD_P2P_CLIENT) {
18055 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
18056 if (hdd_sta_ctx->conn_info.connState !=
18057 eConnectionState_Associated) {
18058
18059 hddLog(VOS_TRACE_LEVEL_INFO,
18060 FL("failed to cap tsf, not connect with ap"));
18061 buf[0] = TSF_STA_NOT_CONNECTED_NO_TSF;
18062 return ret;
18063 }
18064 }
18065 if ((adapter->device_mode == WLAN_HDD_SOFTAP ||
18066 adapter->device_mode == WLAN_HDD_P2P_GO) &&
18067 !(test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))) {
18068 hddLog(VOS_TRACE_LEVEL_INFO,
18069 FL("Soft AP / P2p GO not beaconing"));
18070 buf[0] = TSF_SAP_NOT_STARTED_NO_TSF;
18071 return ret;
18072 }
18073 if (adapter->tsf_cap_ctx.tsf_capture_state == TSF_CAP_STATE) {
18074 hddLog(VOS_TRACE_LEVEL_INFO,
18075 FL("current in capture state, pls reset"));
18076 buf[0] = TSF_CURRENT_IN_CAP_STATE;
18077 } else {
18078 hddLog(VOS_TRACE_LEVEL_INFO, FL("ioctl issue cap tsf cmd"));
18079 buf[0] = TSF_RETURN;
18080 cap_tsf_params.session_id = adapter->sessionId;
18081 cap_tsf_params.tsf_rsp_cb_func = hdd_tsf_cb;
18082 cap_tsf_params.tsf_rsp_cb_ctx = adapter;
18083
18084 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18085 adapter->tsf_cap_ctx.tsf_capture_state = TSF_CAP_STATE;
18086 adapter->tsf_cap_ctx.tsf_get_state = TSF_CURRENT_IN_CAP_STATE;
18087 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18088
18089 ret = sme_capture_tsf_req(hdd_ctx->hHal, cap_tsf_params);
18090
18091 if (ret != VOS_STATUS_SUCCESS) {
18092 hddLog(VOS_TRACE_LEVEL_ERROR, FL("capture fail"));
18093 buf[0] = TSF_CAPTURE_FAIL;
18094 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18095 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18096 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18097 return -EINVAL;
18098 }
18099 /* wait till we get a response from fw */
18100 status = vos_wait_single_event(&adapter->tsf_cap_ctx.
18101 tsf_capture_done_event,
18102 HDD_TSF_CAP_REQ_TIMEOUT);
18103
18104 if (!VOS_IS_STATUS_SUCCESS(status)) {
18105 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
18106 ("capture tsf vos wait for single_event failed!! %d"),
18107 adapter->tsf_cap_ctx.tsf_get_state);
18108
18109 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18110 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18111 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18112
18113 return -EINVAL;
18114 }
18115 }
18116 buf[0] = TSF_RETURN;
18117 hddLog(VOS_TRACE_LEVEL_INFO,
18118 FL("ioctl return cap tsf cmd, ret = %d"), ret);
18119 return ret;
18120}
18121
18122/**
18123 * hdd_indicate_tsf() - return tsf to uplayer
18124 *
18125 * @adapter: pointer to adapter
18126 * @buf: pointer to uplayer buf
18127 * @len : the length of buf
18128 *
18129 * This function returns tsf value to uplayer.
18130 *
18131 * Return: Describe the execute result of this routine
18132 */
18133int hdd_indicate_tsf(hdd_adapter_t *adapter, uint32_t *buf, int len)
18134{
18135 int ret = 0;
18136 hdd_station_ctx_t *hdd_sta_ctx;
18137 hdd_context_t *hdd_ctx;
18138 tSirCapTsfParams cap_tsf_params;
18139 VOS_STATUS status;
18140
18141 if (adapter == NULL || buf == NULL) {
18142 hddLog(VOS_TRACE_LEVEL_ERROR,
18143 FL("invalid pointer"));
18144 return -EINVAL;
18145 }
18146 if (len != 3)
18147 return -EINVAL;
18148
18149 buf [1] = 0;
18150 buf [2] = 0;
18151 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
18152
18153 if (wlan_hdd_validate_context(hdd_ctx)) {
18154 hddLog(VOS_TRACE_LEVEL_ERROR,
18155 FL("invalid hdd ctx"));
18156 return -EINVAL;
18157 }
18158 if (adapter->device_mode == WLAN_HDD_INFRA_STATION ||
18159 adapter->device_mode == WLAN_HDD_P2P_CLIENT) {
18160 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
18161 if (hdd_sta_ctx->conn_info.connState !=
18162 eConnectionState_Associated) {
18163
18164 hddLog(VOS_TRACE_LEVEL_INFO,
18165 FL("failed to cap tsf, not connect with ap"));
18166 buf[0] = TSF_STA_NOT_CONNECTED_NO_TSF;
18167 return ret;
18168 }
18169 }
18170 if ((adapter->device_mode == WLAN_HDD_SOFTAP ||
18171 adapter->device_mode == WLAN_HDD_P2P_GO) &&
18172 !(test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))) {
18173 hddLog(VOS_TRACE_LEVEL_INFO,
18174 FL("Soft AP / P2p GO not beaconing"));
18175 buf[0] = TSF_SAP_NOT_STARTED_NO_TSF;
18176 return ret;
18177 }
18178
18179 if (adapter->tsf_cap_ctx.tsf_capture_state != TSF_CAP_STATE ||
18180 adapter->tsf_cap_ctx.tsf_get_state != TSF_CURRENT_IN_CAP_STATE ) {
18181 hddLog(VOS_TRACE_LEVEL_INFO,
18182 FL("Not in capture state,Enter capture state first"));
18183 buf[0] = TSF_GET_FAIL;
18184 } else {
18185 hddLog(VOS_TRACE_LEVEL_INFO, FL("ioctl issue cap tsf cmd"));
18186 cap_tsf_params.session_id = adapter->sessionId;
18187 cap_tsf_params.tsf_rsp_cb_func = hdd_tsf_cb;
18188 cap_tsf_params.tsf_rsp_cb_ctx = adapter;
18189
18190 ret = sme_get_tsf_req(hdd_ctx->hHal, cap_tsf_params);
18191
18192 if (ret != VOS_STATUS_SUCCESS) {
18193 hddLog(VOS_TRACE_LEVEL_ERROR, FL("capture fail"));
18194 buf[0] = TSF_CAPTURE_FAIL;
18195 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18196 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18197 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18198 return -EINVAL;
18199 }
18200 /* wait till we get a response from fw */
18201 status = vos_wait_single_event(&adapter->tsf_cap_ctx.
18202 tsf_capture_done_event,
18203 HDD_TSF_GET_REQ_TIMEOUT);
18204
18205 if (!VOS_IS_STATUS_SUCCESS(status)) {
18206 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
18207 ("capture tsf vos wait for single_event failed!! %d"),
18208 status);
18209
18210 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18211 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18212 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18213 return status;
18214 }
18215 buf[1] = adapter->tsf_cap_ctx.tsf_low;
18216 buf[2] = adapter->tsf_cap_ctx.tsf_high;
18217
18218 hddLog(VOS_TRACE_LEVEL_INFO,
18219 FL("get tsf cmd,status=%u, tsf_low=%u, tsf_high=%u"),
18220 buf[0], buf[1], buf[2]);
18221 }
18222 hddLog(VOS_TRACE_LEVEL_INFO,
18223 FL("ioctl return cap tsf cmd, ret = %d"), ret);
18224 return ret;
18225}
18226
18227void wlan_hdd_tsf_init(hdd_adapter_t *adapter)
18228{
18229
18230 if (adapter == NULL) {
18231 hddLog(VOS_TRACE_LEVEL_ERROR,
18232 FL("TSF init on a null adapter!"));
18233 return;
18234 }
18235
18236 adapter->tsf_cap_ctx.tsf_get_state = TSF_RETURN;
18237 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18238 vos_event_init(&adapter->tsf_cap_ctx.tsf_capture_done_event);
18239 vos_spin_lock_init(&adapter->tsf_cap_ctx.tsf_lock);
18240 adapter->tsf_cap_ctx.tsf_high = 0;
18241 adapter->tsf_cap_ctx.tsf_low = 0;
18242}
18243
18244#endif
18245
Hanumanth Reddy Pothula972e1df2018-06-14 13:33:47 +053018246bool hdd_is_cli_iface_up(hdd_context_t *hdd_ctx)
18247{
18248 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
18249 hdd_adapter_t *adapter;
18250 VOS_STATUS status;
18251
18252 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
18253 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status) {
18254 adapter = adapter_node->pAdapter;
18255 if ((adapter->device_mode == WLAN_HDD_INFRA_STATION ||
18256 adapter->device_mode == WLAN_HDD_P2P_CLIENT) &&
18257 test_bit(DEVICE_IFACE_OPENED,
18258 &adapter->event_flags)){
18259 return true;
18260 }
18261 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
18262 adapter_node = next;
18263 }
18264
18265 return false;
18266}
18267
Jeff Johnson295189b2012-06-20 16:38:30 -070018268//Register the module init/exit functions
18269module_init(hdd_module_init);
18270module_exit(hdd_module_exit);
18271
18272MODULE_LICENSE("Dual BSD/GPL");
18273MODULE_AUTHOR("Qualcomm Atheros, Inc.");
18274MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
18275
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018276static const struct kernel_param_ops con_mode_ops = {
18277 .set = con_mode_handler,
18278 .get = param_get_int,
18279};
18280
18281static const struct kernel_param_ops fwpath_ops = {
18282 .set = fwpath_changed_handler,
18283 .get = param_get_string,
18284};
18285
Hanumanth Reddy Pothula99219872018-06-08 14:45:18 +053018286#ifdef MODULE
18287module_param(con_mode, int, 0);
18288#else
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018289module_param_cb(con_mode, &con_mode_ops, &con_mode,
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070018290 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Hanumanth Reddy Pothula99219872018-06-08 14:45:18 +053018291#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -070018292
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018293module_param_cb(fwpath, &fwpath_ops, &fwpath,
Jeff Johnson32d95a32012-09-10 13:15:23 -070018294 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Arif Hussain66559122013-11-21 10:11:40 -080018295
18296module_param(enable_dfs_chan_scan, int,
18297 S_IRUSR | S_IRGRP | S_IROTH);
18298
18299module_param(enable_11d, int,
18300 S_IRUSR | S_IRGRP | S_IROTH);
18301
18302module_param(country_code, charp,
18303 S_IRUSR | S_IRGRP | S_IROTH);