blob: 565ff3d9ca392f8cbe0c71a8b43a12953f261c3a [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05302 * Copyright (c) 2012-2018 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>
65#include <vos_sched.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070066#include <linux/etherdevice.h>
67#include <linux/firmware.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070068#ifdef ANI_BUS_TYPE_PLATFORM
69#include <linux/wcnss_wlan.h>
70#endif //ANI_BUS_TYPE_PLATFORM
71#ifdef ANI_BUS_TYPE_PCI
72#include "wcnss_wlan.h"
73#endif /* ANI_BUS_TYPE_PCI */
74#include <wlan_hdd_tx_rx.h>
75#include <palTimer.h>
76#include <wniApi.h>
77#include <wlan_nlink_srv.h>
78#include <wlan_btc_svc.h>
79#include <wlan_hdd_cfg.h>
80#include <wlan_ptt_sock_svc.h>
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053081#include <wlan_logging_sock_svc.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070082#include <wlan_hdd_wowl.h>
83#include <wlan_hdd_misc.h>
84#include <wlan_hdd_wext.h>
85#ifdef WLAN_BTAMP_FEATURE
86#include <bap_hdd_main.h>
87#include <bapInternal.h>
88#endif // WLAN_BTAMP_FEATURE
Sushant Kaushik4b7cb302014-01-06 17:45:01 +053089#include "wlan_hdd_trace.h"
90#include "vos_types.h"
91#include "vos_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070092#include <linux/wireless.h>
93#include <net/cfg80211.h>
Vinay Krishna Erannad9cbdb32014-01-16 12:59:10 +053094#include <linux/inetdevice.h>
95#include <net/addrconf.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070096#include "wlan_hdd_cfg80211.h"
97#include "wlan_hdd_p2p.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070098#include <linux/rtnetlink.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070099int wlan_hdd_ftm_start(hdd_context_t *pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -0700100#include "sapApi.h"
101#include <linux/semaphore.h>
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -0700102#include <linux/ctype.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530103#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
104#include <soc/qcom/subsystem_restart.h>
105#else
Jeff Johnson295189b2012-06-20 16:38:30 -0700106#include <mach/subsystem_restart.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530107#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700108#include <wlan_hdd_hostapd.h>
109#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson295189b2012-06-20 16:38:30 -0700110#include "cfgApi.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700111#include "wlan_hdd_dev_pwr.h"
112#ifdef WLAN_BTAMP_FEATURE
113#include "bap_hdd_misc.h"
114#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700115#include "wlan_qct_pal_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700116#include "qwlan_version.h"
Yathish9f22e662012-12-10 14:21:35 -0800117#include "wlan_qct_wda.h"
Chilam NG571c65a2013-01-19 12:27:36 +0530118#ifdef FEATURE_WLAN_TDLS
119#include "wlan_hdd_tdls.h"
120#endif
Yue Ma0d4891e2013-08-06 17:01:45 -0700121#include "wlan_hdd_debugfs.h"
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +0530122#include "sapInternal.h"
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +0530123#include "wlan_hdd_request_manager.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700124
125#ifdef MODULE
126#define WLAN_MODULE_NAME module_name(THIS_MODULE)
127#else
128#define WLAN_MODULE_NAME "wlan"
129#endif
130
131#ifdef TIMER_MANAGER
132#define TIMER_MANAGER_STR " +TIMER_MANAGER"
133#else
134#define TIMER_MANAGER_STR ""
135#endif
136
137#ifdef MEMORY_DEBUG
138#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
139#else
140#define MEMORY_DEBUG_STR ""
141#endif
Kaushik, Sushant7005e372014-04-08 11:36:54 +0530142#define MAX_WAIT_FOR_ROC_COMPLETION 3
Jeff Johnson295189b2012-06-20 16:38:30 -0700143/* the Android framework expects this param even though we don't use it */
144#define BUF_LEN 20
Jeff Johnson76052702013-04-16 13:55:05 -0700145static char fwpath_buffer[BUF_LEN];
146static struct kparam_string fwpath = {
147 .string = fwpath_buffer,
148 .maxlen = BUF_LEN,
149};
Arif Hussain66559122013-11-21 10:11:40 -0800150
151static char *country_code;
152static int enable_11d = -1;
153static int enable_dfs_chan_scan = -1;
154
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700155#ifndef MODULE
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700156static int wlan_hdd_inited;
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700157#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700158
Jeff Johnsone7245742012-09-05 17:12:55 -0700159/*
Jeff Johnson72a40512013-12-19 10:14:15 -0800160 * spinlock for synchronizing asynchronous request/response
161 * (full description of use in wlan_hdd_main.h)
162 */
163DEFINE_SPINLOCK(hdd_context_lock);
164
165/*
Jeff Johnsone7245742012-09-05 17:12:55 -0700166 * The rate at which the driver sends RESTART event to supplicant
167 * once the function 'vos_wlanRestart()' is called
168 *
169 */
170#define WLAN_HDD_RESTART_RETRY_DELAY_MS 5000 /* 5 second */
171#define WLAN_HDD_RESTART_RETRY_MAX_CNT 5 /* 5 retries */
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -0700172
173/*
174 * Size of Driver command strings from upper layer
175 */
176#define SIZE_OF_SETROAMMODE 11 /* size of SETROAMMODE */
177#define SIZE_OF_GETROAMMODE 11 /* size of GETROAMMODE */
178
Abhishek Singh00b71972016-01-07 10:51:04 +0530179#ifdef WLAN_FEATURE_RMC
180/*
181 * Ibss prop IE from command will be of size:
182 * size = sizeof(oui) + sizeof(oui_data) + 1(Element ID) + 1(EID Length)
183 * OUI_DATA should be at least 3 bytes long
184 */
185#define WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH (3)
186#endif
187
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800188#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700189#define TID_MIN_VALUE 0
190#define TID_MAX_VALUE 15
191static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
192 tAniTrafStrmMetrics* pTsmMetrics);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800193static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
194 tCsrEseBeaconReq *pEseBcnReq);
195#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700196
Atul Mittal1d722422014-03-19 11:15:07 +0530197/*
198 * Maximum buffer size used for returning the data back to user space
199 */
200#define WLAN_MAX_BUF_SIZE 1024
201#define WLAN_PRIV_DATA_MAX_LEN 8192
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -0700202
Abhishek Singh00b71972016-01-07 10:51:04 +0530203/*
204 * When ever we need to print IBSSPEERINFOALL for morethan 16 STA
205 * we will split the printing.
206 */
207#define NUM_OF_STA_DATA_TO_PRINT 16
208
209#ifdef WLAN_FEATURE_RMC
210#define WLAN_NLINK_CESIUM 30
211#endif
212
c_hpothu92367912014-05-01 15:18:17 +0530213//wait time for beacon miss rate.
214#define BCN_MISS_RATE_TIME 500
215
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +0530216/*
217 * Android DRIVER command structures
218 */
219struct android_wifi_reassoc_params {
220 unsigned char bssid[18];
221 int channel;
222};
223
Sushant Kaushik83392fa2015-05-05 17:44:40 +0530224static vos_wake_lock_t wlan_wake_lock;
225
Jeff Johnson295189b2012-06-20 16:38:30 -0700226/* set when SSR is needed after unload */
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -0700227static e_hdd_ssr_required isSsrRequired = HDD_SSR_NOT_REQUIRED;
Jeff Johnson295189b2012-06-20 16:38:30 -0700228
229//internal function declaration
Jeff Johnsone7245742012-09-05 17:12:55 -0700230static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx);
231static void wlan_hdd_restart_init(hdd_context_t *pHddCtx);
232static void wlan_hdd_restart_deinit(hdd_context_t *pHddCtx);
Abhishek Singh00b71972016-01-07 10:51:04 +0530233
234#ifdef WLAN_FEATURE_RMC
235static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo);
236
237static int hdd_open_cesium_nl_sock(void);
238static void hdd_close_cesium_nl_sock(void);
239static struct sock *cesium_nl_srv_sock;
240static v_U16_t cesium_pid;
241
242static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
243 tANI_U8 *tx_fail_count,
244 tANI_U16 *pid);
245
246static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg);
247
248#endif /* WLAN_FEATURE_RMC */
Jeff Johnsone7245742012-09-05 17:12:55 -0700249void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback);
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800250void hdd_set_wlan_suspend_mode(bool suspend);
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530251void hdd_set_vowifi_mode(hdd_context_t *hdd_ctx, bool enable);
Jeff Johnsone7245742012-09-05 17:12:55 -0700252
Jeff Johnson295189b2012-06-20 16:38:30 -0700253v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +0530254 struct sk_buff *skb
255#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
256 , void *accel_priv
257#endif
258#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
259 , select_queue_fallback_t fallback
260#endif
261);
Jeff Johnson295189b2012-06-20 16:38:30 -0700262
263#ifdef WLAN_FEATURE_PACKET_FILTERING
264static void hdd_set_multicast_list(struct net_device *dev);
265#endif
266
267void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter);
268
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800269#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -0800270void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand);
271static VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels);
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700272static VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid,
273 tANI_U8 *pChannel, tANI_U8 *pDwellTime,
274 tANI_U8 **pBuf, tANI_U8 *pBufLen);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +0530275static int hdd_parse_reassoc_command_v1_data(const tANI_U8 *pValue,
276 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel);
Srinivas Girigowdade697412013-02-14 16:31:48 -0800277#endif
Ratheesh S P21280412015-05-19 14:21:52 +0530278
279/* Store WLAN driver info in a global variable such that crash debugger
280 can extract it from driver debug symbol and crashdump for post processing */
281tANI_U8 g_wlan_driver[ ] = "pronto_driver";
282
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800283#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700284VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe, tANI_U8 *pCckmIeLen);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800285#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700286
Mihir Shetee1093ba2014-01-21 20:13:32 +0530287static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx);
Sushant Kaushik8bc7df22014-04-09 17:55:29 +0530288const char * hdd_device_modetoString(v_U8_t device_mode)
289{
290 switch(device_mode)
291 {
292 CASE_RETURN_STRING( WLAN_HDD_INFRA_STATION );
293 CASE_RETURN_STRING( WLAN_HDD_SOFTAP );
294 CASE_RETURN_STRING( WLAN_HDD_P2P_CLIENT );
295 CASE_RETURN_STRING( WLAN_HDD_P2P_GO );
296 CASE_RETURN_STRING( WLAN_HDD_MONITOR);
297 CASE_RETURN_STRING( WLAN_HDD_FTM );
298 CASE_RETURN_STRING( WLAN_HDD_IBSS );
299 CASE_RETURN_STRING( WLAN_HDD_P2P_DEVICE );
300 default:
301 return "device_mode Unknown";
302 }
303}
Mihir Shetee1093ba2014-01-21 20:13:32 +0530304
Mukul Sharmaa78cf6b2015-02-24 16:59:01 +0530305static int __hdd_netdev_notifier_call(struct notifier_block * nb,
Jeff Johnson295189b2012-06-20 16:38:30 -0700306 unsigned long state,
307 void *ndev)
308{
309 struct net_device *dev = ndev;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700310 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson27cee452013-03-27 11:10:24 -0700311 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -0700312#ifdef WLAN_BTAMP_FEATURE
313 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -0700314#endif
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530315 long result;
Jeff Johnson295189b2012-06-20 16:38:30 -0700316
317 //Make sure that this callback corresponds to our device.
Jeff Johnson27cee452013-03-27 11:10:24 -0700318 if ((strncmp(dev->name, "wlan", 4)) &&
Amar Singhal4c723bd2013-03-25 18:14:15 -0700319 (strncmp(dev->name, "p2p", 3)))
320 return NOTIFY_DONE;
321
Jeff Johnson295189b2012-06-20 16:38:30 -0700322 if (!dev->ieee80211_ptr)
Jeff Johnson27cee452013-03-27 11:10:24 -0700323 return NOTIFY_DONE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700324
Jeff Johnson27cee452013-03-27 11:10:24 -0700325 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700326 {
Jeff Johnsona8a1a482012-12-12 16:49:33 -0800327 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Adapter Null Pointer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700328 VOS_ASSERT(0);
329 return NOTIFY_DONE;
330 }
331
Jeff Johnson27cee452013-03-27 11:10:24 -0700332 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
333 if (NULL == pHddCtx)
334 {
335 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Context Null Pointer", __func__);
336 VOS_ASSERT(0);
337 return NOTIFY_DONE;
338 }
Sameer Thalappil14067972014-01-23 14:54:54 -0800339 if (pHddCtx->isLogpInProgress)
340 return NOTIFY_DONE;
341
Jeff Johnson27cee452013-03-27 11:10:24 -0700342
343 hddLog(VOS_TRACE_LEVEL_INFO, "%s: %s New Net Device State = %lu",
344 __func__, dev->name, state);
Jeff Johnson295189b2012-06-20 16:38:30 -0700345
346 switch (state) {
347 case NETDEV_REGISTER:
348 break;
349
350 case NETDEV_UNREGISTER:
351 break;
352
353 case NETDEV_UP:
354 break;
355
356 case NETDEV_DOWN:
357 break;
358
359 case NETDEV_CHANGE:
Jeff Johnsone7245742012-09-05 17:12:55 -0700360 if(TRUE == pAdapter->isLinkUpSvcNeeded)
361 complete(&pAdapter->linkup_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700362 break;
363
364 case NETDEV_GOING_DOWN:
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530365 result = wlan_hdd_scan_abort(pAdapter);
Girish Gowli4bf7a632014-06-12 13:42:11 +0530366 if (result < 0)
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530367 {
368 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
369 "%s: Timeout occurred while waiting for abortscan %ld",
370 __func__, result);
Jeff Johnson295189b2012-06-20 16:38:30 -0700371 }
372 else
373 {
374 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530375 "%s: Scan Abort Successful" , __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700376 }
377#ifdef WLAN_BTAMP_FEATURE
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700378 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s: disabling AMP", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700379 status = WLANBAP_StopAmp();
380 if(VOS_STATUS_SUCCESS != status )
381 {
382 pHddCtx->isAmpAllowed = VOS_TRUE;
383 hddLog(VOS_TRACE_LEVEL_FATAL,
384 "%s: Failed to stop AMP", __func__);
385 }
386 else
387 {
388 //a state m/c implementation in PAL is TBD to avoid this delay
389 msleep(500);
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700390 if ( pHddCtx->isAmpAllowed )
391 {
392 WLANBAP_DeregisterFromHCI();
393 pHddCtx->isAmpAllowed = VOS_FALSE;
394 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700395 }
396#endif //WLAN_BTAMP_FEATURE
397 break;
398
399 default:
400 break;
401 }
402
403 return NOTIFY_DONE;
404}
405
Mukul Sharmaa78cf6b2015-02-24 16:59:01 +0530406static int hdd_netdev_notifier_call(struct notifier_block * nb,
407 unsigned long state,
408 void *ndev)
409{
410 int ret;
411 vos_ssr_protect(__func__);
412 ret = __hdd_netdev_notifier_call( nb, state, ndev);
413 vos_ssr_unprotect(__func__);
414 return ret;
415}
416
Jeff Johnson295189b2012-06-20 16:38:30 -0700417struct notifier_block hdd_netdev_notifier = {
418 .notifier_call = hdd_netdev_notifier_call,
419};
420
421/*---------------------------------------------------------------------------
422 * Function definitions
423 *-------------------------------------------------------------------------*/
Jeff Johnson295189b2012-06-20 16:38:30 -0700424void hdd_unregister_mcast_bcast_filter(hdd_context_t *pHddCtx);
425void hdd_register_mcast_bcast_filter(hdd_context_t *pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -0700426//variable to hold the insmod parameters
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700427static int con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -0700428#ifndef MODULE
429/* current con_mode - used only for statically linked driver
430 * con_mode is changed by userspace to indicate a mode change which will
431 * result in calling the module exit and init functions. The module
432 * exit function will clean up based on the value of con_mode prior to it
433 * being changed by userspace. So curr_con_mode records the current con_mode
434 * for exit when con_mode becomes the next mode for init
435 */
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700436static int curr_con_mode;
Jeff Johnson295189b2012-06-20 16:38:30 -0700437#endif
438
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +0530439#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
440/**
441 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
442 * @hdd_ctx: hdd global context
443 *
444 * Return: none
445 */
446static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
447{
448 uint8_t i;
449
450 mutex_init(&hdd_ctx->op_ctx.op_lock);
451 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++)
452 {
453 hdd_ctx->op_ctx.op_table[i].request_id = 0;
454 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
455 }
456}
457#else
458static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
459{
460}
461#endif
462
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -0800463/**---------------------------------------------------------------------------
464
465 \brief hdd_vos_trace_enable() - Configure initial VOS Trace enable
466
467 Called immediately after the cfg.ini is read in order to configure
468 the desired trace levels.
469
470 \param - moduleId - module whose trace level is being configured
471 \param - bitmask - bitmask of log levels to be enabled
472
473 \return - void
474
475 --------------------------------------------------------------------------*/
476static void hdd_vos_trace_enable(VOS_MODULE_ID moduleId, v_U32_t bitmask)
477{
478 wpt_tracelevel level;
479
480 /* if the bitmask is the default value, then a bitmask was not
481 specified in cfg.ini, so leave the logging level alone (it
482 will remain at the "compiled in" default value) */
483 if (CFG_VOS_TRACE_ENABLE_DEFAULT == bitmask)
484 {
485 return;
486 }
487
488 /* a mask was specified. start by disabling all logging */
489 vos_trace_setValue(moduleId, VOS_TRACE_LEVEL_NONE, 0);
490
491 /* now cycle through the bitmask until all "set" bits are serviced */
492 level = VOS_TRACE_LEVEL_FATAL;
493 while (0 != bitmask)
494 {
495 if (bitmask & 1)
496 {
497 vos_trace_setValue(moduleId, level, 1);
498 }
499 level++;
500 bitmask >>= 1;
501 }
502}
503
504
Jeff Johnson295189b2012-06-20 16:38:30 -0700505/**---------------------------------------------------------------------------
506
507 \brief hdd_wdi_trace_enable() - Configure initial WDI Trace enable
508
509 Called immediately after the cfg.ini is read in order to configure
510 the desired trace levels in the WDI.
511
512 \param - moduleId - module whose trace level is being configured
513 \param - bitmask - bitmask of log levels to be enabled
514
515 \return - void
516
517 --------------------------------------------------------------------------*/
518static void hdd_wdi_trace_enable(wpt_moduleid moduleId, v_U32_t bitmask)
519{
520 wpt_tracelevel level;
521
522 /* if the bitmask is the default value, then a bitmask was not
523 specified in cfg.ini, so leave the logging level alone (it
524 will remain at the "compiled in" default value) */
525 if (CFG_WDI_TRACE_ENABLE_DEFAULT == bitmask)
526 {
527 return;
528 }
529
530 /* a mask was specified. start by disabling all logging */
531 wpalTraceSetLevel(moduleId, eWLAN_PAL_TRACE_LEVEL_NONE, 0);
532
533 /* now cycle through the bitmask until all "set" bits are serviced */
534 level = eWLAN_PAL_TRACE_LEVEL_FATAL;
535 while (0 != bitmask)
536 {
537 if (bitmask & 1)
538 {
539 wpalTraceSetLevel(moduleId, level, 1);
540 }
541 level++;
542 bitmask >>= 1;
543 }
544}
Jeff Johnson295189b2012-06-20 16:38:30 -0700545
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530546/*
547 * FUNCTION: wlan_hdd_validate_context
548 * This function is used to check the HDD context
549 */
550int wlan_hdd_validate_context(hdd_context_t *pHddCtx)
551{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530552
553 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
554 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530555 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530556 "%s: HDD context is Null", __func__);
557 return -ENODEV;
558 }
559
560 if (pHddCtx->isLogpInProgress)
561 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530562 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu8adb97b2014-12-08 19:38:20 +0530563 "%s: LOGP %s. Ignore!!", __func__,
564 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)
565 ?"failed":"in Progress");
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530566 return -EAGAIN;
567 }
568
Mihir Shete18156292014-03-11 15:38:30 +0530569 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530570 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530571 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530572 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
573 return -EAGAIN;
574 }
575 return 0;
576}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700577#ifdef CONFIG_ENABLE_LINUX_REG
578void hdd_checkandupdate_phymode( hdd_context_t *pHddCtx)
579{
580 hdd_adapter_t *pAdapter = NULL;
581 hdd_station_ctx_t *pHddStaCtx = NULL;
582 eCsrPhyMode phyMode;
583 hdd_config_t *cfg_param = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530584
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700585 if (NULL == pHddCtx)
586 {
587 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
588 "HDD Context is null !!");
589 return ;
590 }
591
592 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
593 if (NULL == pAdapter)
594 {
595 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
596 "pAdapter is null !!");
597 return ;
598 }
599
600 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
601 if (NULL == pHddStaCtx)
602 {
603 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
604 "pHddStaCtx is null !!");
605 return ;
606 }
607
608 cfg_param = pHddCtx->cfg_ini;
609 if (NULL == cfg_param)
610 {
611 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
612 "cfg_params not available !!");
613 return ;
614 }
615
616 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
617
618 if (!pHddCtx->isVHT80Allowed)
619 {
620 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
621 (eCSR_DOT11_MODE_11ac == phyMode) ||
622 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
623 {
624 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
625 "Setting phymode to 11n!!");
626 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
627 }
628 }
629 else
630 {
631 /*New country Supports 11ac as well resetting value back from .ini*/
632 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
633 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
634 return ;
635 }
636
637 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
638 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
639 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
640 {
641 VOS_STATUS vosStatus;
642
643 // need to issue a disconnect to CSR.
644 INIT_COMPLETION(pAdapter->disconnect_comp_var);
645 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
646 pAdapter->sessionId,
647 eCSR_DISCONNECT_REASON_UNSPECIFIED );
648
649 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530650 {
651 long ret;
652
653 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700654 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530655 if (0 >= ret)
656 hddLog(LOGE, FL("failure waiting for disconnect_comp_var %ld"),
657 ret);
658 }
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700659
660 }
661}
662#else
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530663void hdd_checkandupdate_phymode( hdd_adapter_t *pAdapter, char *country_code)
664{
665 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
666 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
667 hdd_config_t *cfg_param;
668 eCsrPhyMode phyMode;
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530669 long ret;
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530670
671 if (NULL == pHddCtx)
672 {
673 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
674 "HDD Context is null !!");
675 return ;
676 }
677
678 cfg_param = pHddCtx->cfg_ini;
679
680 if (NULL == cfg_param)
681 {
682 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
683 "cfg_params not available !!");
684 return ;
685 }
686
687 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
688
689 if (NULL != strstr(cfg_param->listOfNon11acCountryCode, country_code))
690 {
691 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
692 (eCSR_DOT11_MODE_11ac == phyMode) ||
693 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
694 {
695 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
696 "Setting phymode to 11n!!");
697 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
698 }
699 }
700 else
701 {
702 /*New country Supports 11ac as well resetting value back from .ini*/
703 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
704 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
705 return ;
706 }
707
708 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
709 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
710 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
711 {
712 VOS_STATUS vosStatus;
713
714 // need to issue a disconnect to CSR.
715 INIT_COMPLETION(pAdapter->disconnect_comp_var);
716 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
717 pAdapter->sessionId,
718 eCSR_DISCONNECT_REASON_UNSPECIFIED );
719
720 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530721 {
722 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530723 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530724 if (ret <= 0)
725 {
726 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
727 "wait on disconnect_comp_var is failed %ld", ret);
728 }
729 }
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530730
731 }
732}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700733#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530734
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700735void hdd_checkandupdate_dfssetting( hdd_adapter_t *pAdapter, char *country_code)
736{
737 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
738 hdd_config_t *cfg_param;
739
740 if (NULL == pHddCtx)
741 {
742 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
743 "HDD Context is null !!");
744 return ;
745 }
746
747 cfg_param = pHddCtx->cfg_ini;
748
749 if (NULL == cfg_param)
750 {
751 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
752 "cfg_params not available !!");
753 return ;
754 }
755
Agarwal Ashish738843c2014-09-25 12:27:56 +0530756 if (NULL != strstr(cfg_param->listOfNonDfsCountryCode, country_code) ||
757 pHddCtx->disable_dfs_flag == TRUE)
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700758 {
759 /*New country doesn't support DFS */
760 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
761 }
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700762
763}
764
Abhishek Singh00b71972016-01-07 10:51:04 +0530765#ifdef WLAN_FEATURE_RMC
766static int hdd_parse_setrmcenable_command(tANI_U8 *pValue, tANI_U8 *pRmcEnable)
767{
768 tANI_U8 *inPtr = pValue;
769 int tempInt;
770 int v = 0;
771 char buf[32];
772 *pRmcEnable = 0;
773
774 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
775 /*no argument after the command*/
776 if (NULL == inPtr)
777 {
778 return 0;
779 }
780
781 /*no space after the command*/
782 else if (SPACE_ASCII_VALUE != *inPtr)
783 {
784 return 0;
785 }
786
787 /*removing empty spaces*/
788 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
789
790 /*no argument followed by spaces*/
791 if ('\0' == *inPtr)
792 {
793 return 0;
794 }
795
796 /* getting the first argument which enables or disables RMC
797 * for input IP v4 address*/
Ashish Kumar Dhanotiya54d31a32017-08-04 17:12:44 +0530798 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530799 v = kstrtos32(buf, 10, &tempInt);
800 if ( v < 0)
801 {
802 return -EINVAL;
803 }
804
805 *pRmcEnable = tempInt;
806
807 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
808 "ucRmcEnable: %d", *pRmcEnable);
809
810 return 0;
811}
812
813/* Function header left blank Intentionally */
814static int hdd_parse_setrmcactionperiod_command(tANI_U8 *pValue,
815 tANI_U32 *pActionPeriod)
816{
817 tANI_U8 *inPtr = pValue;
818 int tempInt;
819 int v = 0;
820 char buf[32];
821 *pActionPeriod = 0;
822
823 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
824 /*no argument after the command*/
825 if (NULL == inPtr)
826 {
827 return -EINVAL;
828 }
829
830 /*no space after the command*/
831 else if (SPACE_ASCII_VALUE != *inPtr)
832 {
833 return -EINVAL;
834 }
835
836 /*removing empty spaces*/
837 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
838
839 /*no argument followed by spaces*/
840 if ('\0' == *inPtr)
841 {
842 return 0;
843 }
844
845 /* getting the first argument which enables or disables RMC
846 * for input IP v4 address*/
Ashish Kumar Dhanotiya54d31a32017-08-04 17:12:44 +0530847 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530848 v = kstrtos32(buf, 10, &tempInt);
849 if ( v < 0)
850 {
851 return -EINVAL;
852 }
853
854 /* Range checking for passed paramter */
855 if (tempInt < WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY_STAMIN ||
856 tempInt > WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY_STAMAX)
857 {
858 return -EINVAL;
859 }
860
861 *pActionPeriod = tempInt;
862
863 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
864 "uActionPeriod: %d", *pActionPeriod);
865
866 return 0;
867}
Dundi Ravitejae110a042018-04-18 13:11:37 +0530868
869/**
870 * hdd_set_vowifi_mode() - Process VOWIFI command.
871 * @hdd_ctx: context handler
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530872 * @enable: Value to be sent as a part of the VOWIFI command
873 *
Dundi Ravitejae110a042018-04-18 13:11:37 +0530874 * Invoke the SME api if station is connected in 2.4 GHz band.
875 * Also start split scan if VOWIFIMODE and dynamic split scan
876 * both are enabled.
877
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530878 * Return: void
879 */
880void hdd_set_vowifi_mode(hdd_context_t *hdd_ctx, bool enable)
881{
882 tANI_U8 sta_chan;
883
Dundi Ravitejaab9d3092018-04-05 18:24:40 +0530884 if (!hdd_ctx->cfg_ini) {
885 hddLog(LOGE, "cfg_ini got NULL");
886 return;
887 }
888
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530889 sta_chan = hdd_get_operating_channel(hdd_ctx, WLAN_HDD_INFRA_STATION);
890
Dundi Ravitejae110a042018-04-18 13:11:37 +0530891 if (CSR_IS_CHANNEL_24GHZ(sta_chan))
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530892 sme_set_vowifi_mode(hdd_ctx->hHal, enable);
Dundi Ravitejae110a042018-04-18 13:11:37 +0530893 else
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530894 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
895 "VoWiFi command rejected as not connected in 2.4GHz");
Dundi Ravitejae110a042018-04-18 13:11:37 +0530896
897 if (enable && hdd_ctx->cfg_ini->dynSplitscan) {
898 hdd_ctx->is_vowifi_enabled = true;
899 hdd_ctx->issplitscan_enabled = TRUE;
900 sme_enable_disable_split_scan(hdd_ctx->hHal,
901 hdd_ctx->cfg_ini->nNumStaChanCombinedConc,
902 hdd_ctx->cfg_ini->nNumP2PChanCombinedConc);
903 } else {
904 hdd_ctx->is_vowifi_enabled = false;
Dundi Ravitejaab9d3092018-04-05 18:24:40 +0530905 }
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530906}
Abhishek Singh00b71972016-01-07 10:51:04 +0530907
908/* Function header left blank Intentionally */
909static int hdd_parse_setrmcrate_command(tANI_U8 *pValue,
910 tANI_U32 *pRate, tTxrateinfoflags *pTxFlags)
911{
912 tANI_U8 *inPtr = pValue;
913 int tempInt;
914 int v = 0;
915 char buf[32];
916 *pRate = 0;
917 *pTxFlags = 0;
918
919 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
920 /*no argument after the command*/
921 if (NULL == inPtr)
922 {
923 return -EINVAL;
924 }
925
926 /*no space after the command*/
927 else if (SPACE_ASCII_VALUE != *inPtr)
928 {
929 return -EINVAL;
930 }
931
932 /*removing empty spaces*/
933 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
934
935 /*no argument followed by spaces*/
936 if ('\0' == *inPtr)
937 {
938 return 0;
939 }
940
941 /*
942 * getting the first argument which sets multicast rate.
943 */
Ashish Kumar Dhanotiya06f9f202017-08-04 15:26:27 +0530944 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530945 v = kstrtos32(buf, 10, &tempInt);
946 if ( v < 0)
947 {
948 return -EINVAL;
949 }
950
951 /*
952 * Validate the multicast rate.
953 */
954 switch (tempInt)
955 {
956 default:
957 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
958 "Unsupported rate: %d", tempInt);
959 return -EINVAL;
960 case 0:
961 case 6:
962 case 9:
963 case 12:
964 case 18:
965 case 24:
966 case 36:
967 case 48:
968 case 54:
969 *pTxFlags = eHAL_TX_RATE_LEGACY;
970 *pRate = tempInt * 10;
971 break;
972 case 65:
973 *pTxFlags = eHAL_TX_RATE_HT20;
974 *pRate = tempInt * 10;
975 break;
976 case 72:
977 *pTxFlags = eHAL_TX_RATE_HT20 | eHAL_TX_RATE_SGI;
978 *pRate = 722; /* fractional rate 72.2 Mbps */
979 break;
980 }
981
982 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
983 "Rate: %d", *pRate);
984
985 return 0;
986}
987
988/**---------------------------------------------------------------------------
989
990 \brief hdd_cfg80211_get_ibss_peer_info_cb() - Callback function for IBSS
991 Peer Info request
992
993 This is an asynchronous callback function from SME when the peer info
994 is received
995
996 \pUserData -> Adapter private data
997 \pPeerInfoRsp -> Peer info response
998
999 \return - 0 for success non-zero for failure
1000 --------------------------------------------------------------------------*/
1001static void
1002hdd_cfg80211_get_ibss_peer_info_cb(v_VOID_t *pUserData, v_VOID_t *pPeerInfoRsp)
1003{
1004 hdd_adapter_t *pAdapter = (hdd_adapter_t *)pUserData;
1005 tSirPeerInfoRspParams *pPeerInfo = (tSirPeerInfoRspParams *)pPeerInfoRsp;
1006 hdd_station_ctx_t *pStaCtx;
1007 v_U8_t i;
1008
1009 /*Sanity check*/
1010 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
1011 {
1012 hddLog(LOGE,
1013 FL("invalid adapter or adapter has invalid magic"));
1014 return;
1015 }
1016
1017 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1018 if (NULL != pStaCtx && NULL != pPeerInfo &&
1019 eHAL_STATUS_SUCCESS == pPeerInfo->status)
1020 {
1021 pStaCtx->ibss_peer_info.status = pPeerInfo->status;
1022 pStaCtx->ibss_peer_info.numIBSSPeers = pPeerInfo->numPeers;
1023
1024 /* Paranoia check */
1025 if (pPeerInfo->numPeers < HDD_MAX_NUM_IBSS_STA)
1026 {
1027 for (i = 0; i < pPeerInfo->numPeers; i++)
1028 {
1029 memcpy(&pStaCtx->ibss_peer_info.ibssPeerList[i],
1030 &pPeerInfo->peerInfoParams[i],
1031 sizeof(hdd_ibss_peer_info_params_t));
1032 }
1033 hddLog(LOG1,
1034 FL("Peer Info copied in HDD"));
1035 }
1036 else
1037 {
1038 hddLog(LOGE,
1039 FL(" Number of peers %d returned is more than limit %d"),
1040 pPeerInfo->numPeers, HDD_MAX_NUM_IBSS_STA);
1041 }
1042 }
1043 else
1044 {
1045 hddLog(LOG1,
1046 FL("peerInfo returned is NULL"));
1047 }
1048
1049 complete(&pAdapter->ibss_peer_info_comp);
1050}
1051
1052/**---------------------------------------------------------------------------
1053
1054 \brief hdd_cfg80211_get_ibss_peer_info_all() -
1055
1056 Request function to get IBSS peer info from lower layers
1057
1058 \pAdapter -> Adapter context
1059
1060 \return - 0 for success non-zero for failure
1061 --------------------------------------------------------------------------*/
1062static
1063VOS_STATUS hdd_cfg80211_get_ibss_peer_info_all(hdd_adapter_t *pAdapter)
1064{
1065 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1066 long status;
1067 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1068
1069 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1070
1071 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1072 hdd_cfg80211_get_ibss_peer_info_cb,
1073 VOS_TRUE, 0xFF);
1074
1075 if (VOS_STATUS_SUCCESS == retStatus)
1076 {
1077 status = wait_for_completion_interruptible_timeout
1078 (&pAdapter->ibss_peer_info_comp,
1079 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1080
1081 /* status will be 0 if timed out */
1082 if (status <= 0)
1083 {
1084 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1085 __func__, status);
1086 retStatus = VOS_STATUS_E_FAILURE;
1087 return retStatus;
1088 }
1089 }
1090 else
1091 {
1092 hddLog(VOS_TRACE_LEVEL_WARN,
1093 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1094 }
1095
1096 return retStatus;
1097}
1098
1099/**---------------------------------------------------------------------------
1100
1101 \brief hdd_cfg80211_get_ibss_peer_info() -
1102
1103 Request function to get IBSS peer info from lower layers
1104
1105 \pAdapter -> Adapter context
1106 \staIdx -> Sta index for which the peer info is requested
1107
1108 \return - 0 for success non-zero for failure
1109 --------------------------------------------------------------------------*/
1110static VOS_STATUS
1111hdd_cfg80211_get_ibss_peer_info(hdd_adapter_t *pAdapter, v_U8_t staIdx)
1112{
1113 long status;
1114 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1115 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1116
1117 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1118
1119 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1120 hdd_cfg80211_get_ibss_peer_info_cb,
1121 VOS_FALSE, staIdx);
1122
1123 if (VOS_STATUS_SUCCESS == retStatus)
1124 {
1125 status = wait_for_completion_interruptible_timeout
1126 (&pAdapter->ibss_peer_info_comp,
1127 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1128
1129 /* status = 0 on timeout */
1130 if (status <= 0)
1131 {
1132 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1133 __func__, status);
1134 retStatus = VOS_STATUS_E_FAILURE;
1135 return retStatus;
1136 }
1137 }
1138 else
1139 {
1140 hddLog(VOS_TRACE_LEVEL_WARN,
1141 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1142 }
1143
1144 return retStatus;
1145}
1146
1147/* Function header left blank Intentionally */
1148VOS_STATUS
1149hdd_parse_get_ibss_peer_info(tANI_U8 *pValue, v_MACADDR_t *pPeerMacAddr)
1150{
1151 tANI_U8 *inPtr = pValue;
1152 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1153
1154 /*no argument after the command*/
1155 if (NULL == inPtr)
1156 {
1157 return VOS_STATUS_E_FAILURE;;
1158 }
1159
1160 /*no space after the command*/
1161 else if (SPACE_ASCII_VALUE != *inPtr)
1162 {
1163 return VOS_STATUS_E_FAILURE;;
1164 }
1165
1166 /*removing empty spaces*/
1167 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
1168
1169 /*no argument followed by spaces*/
1170 if ('\0' == *inPtr)
1171 {
1172 return VOS_STATUS_E_FAILURE;;
1173 }
1174
1175 /*getting the first argument ie the peer mac address */
1176 if (inPtr[2] != ':' || inPtr[5] != ':' || inPtr[8] != ':' ||
1177 inPtr[11] != ':' || inPtr[14] != ':')
1178 {
1179 return VOS_STATUS_E_FAILURE;;
1180 }
1181 sscanf(inPtr, "%2x:%2x:%2x:%2x:%2x:%2x",
1182 (unsigned int *)&pPeerMacAddr->bytes[0],
1183 (unsigned int *)&pPeerMacAddr->bytes[1],
1184 (unsigned int *)&pPeerMacAddr->bytes[2],
1185 (unsigned int *)&pPeerMacAddr->bytes[3],
1186 (unsigned int *)&pPeerMacAddr->bytes[4],
1187 (unsigned int *)&pPeerMacAddr->bytes[5]);
1188
1189 /* The command buffer seems to be fine */
1190 return VOS_STATUS_SUCCESS;
1191}
1192
1193/* Function header left blank Intentionally */
1194static int hdd_parse_set_ibss_oui_data_command(tANI_U8 *command, tANI_U8 *ie,
1195 tANI_U32 limit)
1196{
1197 tANI_U8 len;
1198 tANI_U8 data;
1199
1200 /* skip white space */
1201 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1202 {
1203 command++;
1204 limit--;
1205 }
1206
1207 /* skip element id and element length */
1208 len = 2;
1209
1210 /* extract oui */
1211 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1212 (limit > 1))
1213 {
1214 /* Convert ASCII to decimal */
1215 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1216 ie[len++] = data;
1217 command += 2;
1218 limit -= 2;
1219 }
1220
1221 /* skip white space */
1222 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1223 {
1224 command++;
1225 limit--;
1226 }
1227
1228 /* extract data */
1229 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1230 (limit > 1))
1231 {
1232 /* Convert ASCII to decimal */
1233 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1234 ie[len++] = data;
1235 command += 2;
1236 limit -= 2;
1237 }
1238
1239 /* fill element id and element length */
1240 ie[0] = IE_EID_VENDOR;
1241 ie[1] = len - 2;
1242
1243 return len;
1244}
1245
1246static tANI_U32 hdd_find_ibss_wpa_ie_pos(tANI_U8 *addIePtr, tANI_U32 addIeLen)
1247{
1248 tANI_U32 ieLenPresent = 0;
1249 int left = addIeLen;
1250 v_U8_t *ptr = addIePtr;
1251 v_U8_t elem_id,elem_len;
1252
1253 while(left >= 2)
1254 {
1255 elem_id = ptr[0];
1256 elem_len = ptr[1];
1257 left -= 2;
1258 if(elem_len > left)
1259 {
1260 hddLog(LOGE,
1261 FL("****Invalid elem_len=%d left=%d*****"),
1262 elem_len,left);
1263 return 0;
1264 }
1265 if ((elem_id == IE_EID_VENDOR) &&
1266 (left >= WPA_OUI_TYPE_SIZE))
1267 {
1268 if (!memcmp(&ptr[2], WPA_OUI_TYPE,
1269 WPA_OUI_TYPE_SIZE))
1270 {
1271 ieLenPresent += elem_len + 2;
1272 return ieLenPresent;
1273 }
1274 }
1275 ieLenPresent += (elem_len + 2);
1276 left -= elem_len;
1277 ptr += (elem_len + 2);
1278 }
1279 return 0;
1280}
1281
1282#endif /* WLAN_FEATURE_RMC */
1283
Rajeev79dbe4c2013-10-05 11:03:42 +05301284#ifdef FEATURE_WLAN_BATCH_SCAN
1285
1286/**---------------------------------------------------------------------------
1287
1288 \brief hdd_extract_assigned_int_from_str() - Extracts assigned integer from
1289 input string
1290
1291 This function extracts assigned integer from string in below format:
1292 "STRING=10" : extracts integer 10 from this string
1293
1294 \param - pInPtr Pointer to input string
1295 \param - base Base for string to int conversion(10 for decimal 16 for hex)
1296 \param - pOutPtr Pointer to variable in which extracted integer needs to be
1297 assigned
1298 \param - pLastArg to tell whether it is last arguement in input string or
1299 not
1300
1301 \return - NULL for failure cases
1302 pointer to next arguement in input string for success cases
1303 --------------------------------------------------------------------------*/
1304static tANI_U8 *
1305hdd_extract_assigned_int_from_str
1306(
1307 tANI_U8 *pInPtr,
1308 tANI_U8 base,
1309 tANI_U32 *pOutPtr,
1310 tANI_U8 *pLastArg
1311)
1312{
1313 int tempInt;
1314 int v = 0;
1315 char buf[32];
1316 int val = 0;
1317 *pLastArg = FALSE;
1318
1319 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1320 if (NULL == pInPtr)
1321 {
1322 return NULL;
1323 }
1324
1325 pInPtr++;
1326
1327 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1328
1329 val = sscanf(pInPtr, "%32s ", buf);
1330 if (val < 0 && val > strlen(pInPtr))
1331 {
1332 return NULL;
1333 }
1334 pInPtr += val;
1335 v = kstrtos32(buf, base, &tempInt);
1336 if (v < 0)
1337 {
1338 return NULL;
1339 }
Rajeev Kumar4d93d842014-01-02 18:31:21 -08001340 if (tempInt < 0)
1341 {
1342 tempInt = 0;
1343 }
Rajeev79dbe4c2013-10-05 11:03:42 +05301344 *pOutPtr = tempInt;
1345
1346 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1347 if (NULL == pInPtr)
1348 {
1349 *pLastArg = TRUE;
1350 return NULL;
1351 }
1352 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1353
1354 return pInPtr;
1355}
1356
1357/**---------------------------------------------------------------------------
1358
1359 \brief hdd_extract_assigned_char_from_str() - Extracts assigned char from
1360 input string
1361
1362 This function extracts assigned character from string in below format:
1363 "STRING=A" : extracts char 'A' from this string
1364
1365 \param - pInPtr Pointer to input string
1366 \param - pOutPtr Pointer to variable in which extracted char needs to be
1367 assigned
1368 \param - pLastArg to tell whether it is last arguement in input string or
1369 not
1370
1371 \return - NULL for failure cases
1372 pointer to next arguement in input string for success cases
1373 --------------------------------------------------------------------------*/
1374static tANI_U8 *
1375hdd_extract_assigned_char_from_str
1376(
1377 tANI_U8 *pInPtr,
1378 tANI_U8 *pOutPtr,
1379 tANI_U8 *pLastArg
1380)
1381{
1382 *pLastArg = FALSE;
1383
1384 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1385 if (NULL == pInPtr)
1386 {
1387 return NULL;
1388 }
1389
1390 pInPtr++;
1391
1392 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1393
1394 *pOutPtr = *pInPtr;
1395
1396 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1397 if (NULL == pInPtr)
1398 {
1399 *pLastArg = TRUE;
1400 return NULL;
1401 }
1402 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1403
1404 return pInPtr;
1405}
1406
1407
1408/**---------------------------------------------------------------------------
1409
1410 \brief hdd_parse_set_batchscan_command () - HDD parse set batch scan command
1411
1412 This function parses set batch scan command in below format:
1413 WLS_BATCHING_SET <space> followed by below arguements
1414 "SCANFREQ=XX" : Optional defaults to 30 sec
1415 "MSCAN=XX" : Required number of scans to attempt to batch
1416 "BESTN=XX" : Best Network (RSSI) defaults to 16
1417 "CHANNEL=<X,Y>" : optional defaults to all channels, can list 'A'or` B.
1418 A. implies only 5 GHz , B. implies only 2.4GHz
1419 "RTT=X" : optional defaults to 0
1420 returns the MIN of MSCAN or the max # of scans firmware can cache or -1 on
1421 error
1422
1423 For example input commands:
1424 1) WLS_BATCHING_SET SCANFREQ=60 MSCAN=10 BESTN=20 CHANNEL=A RTT=0 -> This is
1425 translated into set batch scan with following parameters:
1426 a) Frequence 60 seconds
1427 b) Batch 10 scans together
1428 c) Best RSSI to be 20
1429 d) 5GHz band only
1430 e) RTT is equal to 0
1431
1432 \param - pValue Pointer to input channel list
1433 \param - pHddSetBatchScanReq Pointer to HDD batch scan request structure
1434
1435 \return - 0 for success non-zero for failure
1436
1437 --------------------------------------------------------------------------*/
1438static int
1439hdd_parse_set_batchscan_command
1440(
1441 tANI_U8 *pValue,
1442 tSirSetBatchScanReq *pHddSetBatchScanReq
1443)
1444{
1445 tANI_U8 *inPtr = pValue;
1446 tANI_U8 val = 0;
1447 tANI_U8 lastArg = 0;
Abhishek Singh00b71972016-01-07 10:51:04 +05301448 tANI_U32 nScanFreq = HDD_SET_BATCH_SCAN_DEFAULT_FREQ;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001449 tANI_U32 nMscan;
Abhishek Singh00b71972016-01-07 10:51:04 +05301450 tANI_U32 nBestN = HDD_SET_BATCH_SCAN_BEST_NETWORK;
1451 tANI_U8 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1452 tANI_U32 nRtt = 0;
Rajeev Kumarc933d982013-11-18 20:04:20 -08001453 tANI_U32 temp;
Rajeev79dbe4c2013-10-05 11:03:42 +05301454
Rajeev79dbe4c2013-10-05 11:03:42 +05301455 /*go to space after WLS_BATCHING_SET command*/
1456 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1457 /*no argument after the command*/
1458 if (NULL == inPtr)
1459 {
1460 return -EINVAL;
1461 }
1462
1463 /*no space after the command*/
1464 else if (SPACE_ASCII_VALUE != *inPtr)
1465 {
1466 return -EINVAL;
1467 }
1468
1469 /*removing empty spaces*/
1470 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
1471
1472 /*no argument followed by spaces*/
1473 if ('\0' == *inPtr)
1474 {
1475 return -EINVAL;
1476 }
1477
1478 /*check and parse SCANFREQ*/
1479 if ((strncmp(inPtr, "SCANFREQ", 8) == 0))
1480 {
1481 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001482 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001483
Rajeev Kumarc933d982013-11-18 20:04:20 -08001484 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001485 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001486 nScanFreq = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001487 }
1488
Rajeev79dbe4c2013-10-05 11:03:42 +05301489 if ( (NULL == inPtr) || (TRUE == lastArg))
1490 {
1491 return -EINVAL;
1492 }
1493 }
1494
1495 /*check and parse MSCAN*/
1496 if ((strncmp(inPtr, "MSCAN", 5) == 0))
1497 {
1498 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001499 &nMscan, &lastArg);
1500
1501 if (0 == nMscan)
1502 {
1503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1504 "invalid MSCAN=%d", nMscan);
1505 return -EINVAL;
1506 }
1507
Rajeev79dbe4c2013-10-05 11:03:42 +05301508 if (TRUE == lastArg)
1509 {
1510 goto done;
1511 }
1512 else if (NULL == inPtr)
1513 {
1514 return -EINVAL;
1515 }
1516 }
1517 else
1518 {
1519 return -EINVAL;
1520 }
1521
1522 /*check and parse BESTN*/
1523 if ((strncmp(inPtr, "BESTN", 5) == 0))
1524 {
1525 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001526 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001527
Rajeev Kumarc933d982013-11-18 20:04:20 -08001528 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001529 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001530 nBestN = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001531 }
1532
Rajeev79dbe4c2013-10-05 11:03:42 +05301533 if (TRUE == lastArg)
1534 {
1535 goto done;
1536 }
1537 else if (NULL == inPtr)
1538 {
1539 return -EINVAL;
1540 }
1541 }
1542
1543 /*check and parse CHANNEL*/
1544 if ((strncmp(inPtr, "CHANNEL", 7) == 0))
1545 {
1546 inPtr = hdd_extract_assigned_char_from_str(inPtr, &val, &lastArg);
Rajeev Kumarc933d982013-11-18 20:04:20 -08001547
Rajeev79dbe4c2013-10-05 11:03:42 +05301548 if (('A' == val) || ('a' == val))
1549 {
c_hpothuebf89732014-02-25 13:00:24 +05301550 ucRfBand = HDD_SET_BATCH_SCAN_5GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301551 }
1552 else if (('B' == val) || ('b' == val))
1553 {
c_hpothuebf89732014-02-25 13:00:24 +05301554 ucRfBand = HDD_SET_BATCH_SCAN_24GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301555 }
1556 else
1557 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001558 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1559 }
1560
1561 if (TRUE == lastArg)
1562 {
1563 goto done;
1564 }
1565 else if (NULL == inPtr)
1566 {
Rajeev79dbe4c2013-10-05 11:03:42 +05301567 return -EINVAL;
1568 }
1569 }
1570
1571 /*check and parse RTT*/
1572 if ((strncmp(inPtr, "RTT", 3) == 0))
1573 {
1574 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001575 &nRtt, &lastArg);
Rajeev79dbe4c2013-10-05 11:03:42 +05301576 if (TRUE == lastArg)
1577 {
1578 goto done;
1579 }
1580 if (NULL == inPtr)
1581 {
1582 return -EINVAL;
1583 }
1584 }
1585
1586
1587done:
1588
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001589 pHddSetBatchScanReq->scanFrequency = nScanFreq;
1590 pHddSetBatchScanReq->numberOfScansToBatch = nMscan;
1591 pHddSetBatchScanReq->bestNetwork = nBestN;
1592 pHddSetBatchScanReq->rfBand = ucRfBand;
1593 pHddSetBatchScanReq->rtt = nRtt;
1594
Rajeev79dbe4c2013-10-05 11:03:42 +05301595 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1596 "Received WLS_BATCHING_SET with SCANFREQ=%d "
1597 "MSCAN=%d BESTN=%d CHANNEL=%d RTT=%d",
1598 pHddSetBatchScanReq->scanFrequency,
1599 pHddSetBatchScanReq->numberOfScansToBatch,
1600 pHddSetBatchScanReq->bestNetwork,
1601 pHddSetBatchScanReq->rfBand,
1602 pHddSetBatchScanReq->rtt);
1603
1604 return 0;
1605}/*End of hdd_parse_set_batchscan_command*/
1606
1607/**---------------------------------------------------------------------------
1608
1609 \brief hdd_set_batch_scan_req_callback () - This function is called after
1610 receiving set batch scan response from FW and it saves set batch scan
1611 response data FW to HDD context and sets the completion event on
1612 which hdd_ioctl is waiting
1613
1614 \param - callbackContext Pointer to HDD adapter
1615 \param - pRsp Pointer to set batch scan response data received from FW
1616
1617 \return - nothing
1618
1619 --------------------------------------------------------------------------*/
1620static void hdd_set_batch_scan_req_callback
1621(
1622 void *callbackContext,
1623 tSirSetBatchScanRsp *pRsp
1624)
1625{
1626 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
1627 tSirSetBatchScanRsp *pHddSetBatchScanRsp;
1628
1629 /*sanity check*/
1630 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
1631 {
1632 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1633 "%s: Invalid pAdapter magic", __func__);
1634 VOS_ASSERT(0);
1635 return;
1636 }
1637 pHddSetBatchScanRsp = &pAdapter->hddSetBatchScanRsp;
1638
1639 /*save set batch scan response*/
1640 pHddSetBatchScanRsp->nScansToBatch = pRsp->nScansToBatch;
1641
1642 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
1643 "Received set batch scan rsp from FW with nScansToBatch=%d",
1644 pHddSetBatchScanRsp->nScansToBatch);
1645
1646 pAdapter->hdd_wait_for_set_batch_scan_rsp = FALSE;
1647 complete(&pAdapter->hdd_set_batch_scan_req_var);
1648
1649 return;
1650}/*End of hdd_set_batch_scan_req_callback*/
1651
1652
1653/**---------------------------------------------------------------------------
1654
1655 \brief hdd_populate_batch_scan_rsp_queue () - This function stores AP meta
1656 info in hdd batch scan response queue
1657
1658 \param - pAdapter Pointer to hdd adapter
1659 \param - pAPMetaInfo Pointer to access point meta info
1660 \param - scanId scan ID of batch scan response
1661 \param - isLastAp tells whether AP is last AP in batch scan response or not
1662
1663 \return - nothing
1664
1665 --------------------------------------------------------------------------*/
1666static void hdd_populate_batch_scan_rsp_queue( hdd_adapter_t* pAdapter,
1667 tpSirBatchScanNetworkInfo pApMetaInfo, tANI_U32 scanId, v_BOOL_t isLastAp)
1668{
1669 tHddBatchScanRsp *pHead;
1670 tHddBatchScanRsp *pNode;
1671 tHddBatchScanRsp *pPrev;
1672 tHddBatchScanRsp *pTemp;
1673 tANI_U8 ssidLen;
1674
1675 /*head of hdd batch scan response queue*/
1676 pHead = pAdapter->pBatchScanRsp;
1677
1678 pNode = (tHddBatchScanRsp *)vos_mem_malloc(sizeof(tHddBatchScanRsp));
1679 if (NULL == pNode)
1680 {
1681 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1682 "%s: Could not allocate memory", __func__);
1683 VOS_ASSERT(0);
1684 return;
1685 }
1686
1687 vos_mem_copy(pNode->ApInfo.bssid, pApMetaInfo->bssid,
1688 sizeof(pNode->ApInfo.bssid));
1689 ssidLen = strlen(pApMetaInfo->ssid);
1690 if (SIR_MAX_SSID_SIZE < ssidLen)
1691 {
1692 /*invalid scan result*/
1693 vos_mem_free(pNode);
1694 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1695 "%s: Invalid AP meta info ssidlen %d", __func__, ssidLen);
1696 return;
1697 }
1698 vos_mem_copy(pNode->ApInfo.ssid, pApMetaInfo->ssid, ssidLen);
1699 /*null terminate ssid*/
1700 pNode->ApInfo.ssid[ssidLen] = '\0';
1701 pNode->ApInfo.ch = pApMetaInfo->ch;
1702 pNode->ApInfo.rssi = pApMetaInfo->rssi;
1703 pNode->ApInfo.age = pApMetaInfo->timestamp;
1704 pNode->ApInfo.batchId = scanId;
1705 pNode->ApInfo.isLastAp = isLastAp;
1706
1707 pNode->pNext = NULL;
1708 if (NULL == pHead)
1709 {
1710 pAdapter->pBatchScanRsp = pNode;
1711 }
1712 else
1713 {
1714 pTemp = pHead;
1715 while (NULL != pTemp)
1716 {
1717 pPrev = pTemp;
1718 pTemp = pTemp->pNext;
1719 }
1720 pPrev->pNext = pNode;
1721 }
1722
1723 return;
1724}/*End of hdd_populate_batch_scan_rsp_queue*/
1725
1726/**---------------------------------------------------------------------------
1727
1728 \brief hdd_batch_scan_result_ind_callback () - This function is called after
1729 receiving batch scan response indication from FW. It saves get batch scan
1730 response data in HDD batch scan response queue. This callback sets the
1731 completion event on which hdd_ioctl is waiting only after getting complete
1732 batch scan response data from FW
1733
1734 \param - callbackContext Pointer to HDD adapter
1735 \param - pRsp Pointer to get batch scan response data received from FW
1736
1737 \return - nothing
1738
1739 --------------------------------------------------------------------------*/
1740static void hdd_batch_scan_result_ind_callback
1741(
1742 void *callbackContext,
1743 void *pRsp
1744)
1745{
1746 v_BOOL_t isLastAp;
1747 tANI_U32 numApMetaInfo;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001748 tANI_U32 numNetworkInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301749 tANI_U32 numberScanList;
1750 tANI_U32 nextScanListOffset;
1751 tANI_U32 nextApMetaInfoOffset;
1752 hdd_adapter_t* pAdapter;
1753 tpSirBatchScanList pScanList;
1754 tpSirBatchScanNetworkInfo pApMetaInfo;
1755 tpSirBatchScanResultIndParam pBatchScanRsp;/*batch scan rsp data from FW*/
1756 tSirSetBatchScanReq *pReq;
1757
1758 pAdapter = (hdd_adapter_t *)callbackContext;
1759 /*sanity check*/
Rajeev Kumar5286bb92013-12-05 11:52:10 -08001760 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
Rajeev79dbe4c2013-10-05 11:03:42 +05301761 {
1762 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1763 "%s: Invalid pAdapter magic", __func__);
1764 VOS_ASSERT(0);
1765 return;
1766 }
1767
1768 /*initialize locals*/
1769 pReq = &pAdapter->hddSetBatchScanReq;
1770 pBatchScanRsp = (tpSirBatchScanResultIndParam)pRsp;
1771 isLastAp = FALSE;
1772 numApMetaInfo = 0;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001773 numNetworkInScanList = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05301774 numberScanList = 0;
1775 nextScanListOffset = 0;
1776 nextApMetaInfoOffset = 0;
1777 pScanList = NULL;
1778 pApMetaInfo = NULL;
1779
1780 if ((NULL == pBatchScanRsp) || (NULL == pReq))
1781 {
1782 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001783 "%s: pBatchScanRsp is %pK pReq %pK", __func__, pBatchScanRsp, pReq);
Rajeev79dbe4c2013-10-05 11:03:42 +05301784 isLastAp = TRUE;
1785 goto done;
1786 }
1787
1788 pAdapter->numScanList = numberScanList = pBatchScanRsp->numScanLists;
1789 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1790 "Batch scan rsp: numberScalList %d", numberScanList);
1791
1792 if ((!numberScanList) || (numberScanList > pReq->numberOfScansToBatch))
1793 {
1794 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1795 "%s: numberScanList %d", __func__, numberScanList);
1796 isLastAp = TRUE;
1797 goto done;
1798 }
1799
1800 while (numberScanList)
1801 {
Rajeev Kumarce651e42013-10-21 18:57:15 -07001802 pScanList = (tpSirBatchScanList)((tANI_U8 *)pBatchScanRsp->scanResults +
Rajeev79dbe4c2013-10-05 11:03:42 +05301803 nextScanListOffset);
1804 if (NULL == pScanList)
1805 {
1806 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001807 "%s: pScanList is %pK", __func__, pScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05301808 isLastAp = TRUE;
1809 goto done;
1810 }
Rajeev Kumarce651e42013-10-21 18:57:15 -07001811 numNetworkInScanList = numApMetaInfo = pScanList->numNetworksInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301812 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumarce651e42013-10-21 18:57:15 -07001813 "Batch scan rsp: numApMetaInfo %d scanId %d",
1814 numApMetaInfo, pScanList->scanId);
Rajeev79dbe4c2013-10-05 11:03:42 +05301815
1816 if ((!numApMetaInfo) || (numApMetaInfo > pReq->bestNetwork))
1817 {
1818 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1819 "%s: numApMetaInfo %d", __func__, numApMetaInfo);
1820 isLastAp = TRUE;
1821 goto done;
1822 }
1823
Rajeev Kumarce651e42013-10-21 18:57:15 -07001824 /*Initialize next AP meta info offset for next scan list*/
1825 nextApMetaInfoOffset = 0;
1826
Rajeev79dbe4c2013-10-05 11:03:42 +05301827 while (numApMetaInfo)
1828 {
1829 pApMetaInfo = (tpSirBatchScanNetworkInfo)(pScanList->scanList +
1830 nextApMetaInfoOffset);
1831 if (NULL == pApMetaInfo)
1832 {
1833 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001834 "%s: pApMetaInfo is %pK", __func__, pApMetaInfo);
Rajeev79dbe4c2013-10-05 11:03:42 +05301835 isLastAp = TRUE;
1836 goto done;
1837 }
1838 /*calculate AP age*/
1839 pApMetaInfo->timestamp =
1840 pBatchScanRsp->timestamp - pApMetaInfo->timestamp;
1841
1842 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussaina7c8e412013-11-20 11:06:42 -08001843 "%s: bssId "MAC_ADDRESS_STR
1844 " ch %d rssi %d timestamp %d", __func__,
1845 MAC_ADDR_ARRAY(pApMetaInfo->bssid),
1846 pApMetaInfo->ch, pApMetaInfo->rssi,
1847 pApMetaInfo->timestamp);
Rajeev79dbe4c2013-10-05 11:03:42 +05301848
1849 /*mark last AP in batch scan response*/
1850 if ((TRUE == pBatchScanRsp->isLastResult) &&
1851 (1 == numberScanList) && (1 == numApMetaInfo))
1852 {
1853 isLastAp = TRUE;
1854 }
1855
1856 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1857 /*store batch scan repsonse in hdd queue*/
1858 hdd_populate_batch_scan_rsp_queue(pAdapter, pApMetaInfo,
1859 pScanList->scanId, isLastAp);
1860 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1861
1862 nextApMetaInfoOffset += sizeof(tSirBatchScanNetworkInfo);
1863 numApMetaInfo--;
1864 }
1865
Rajeev Kumarce651e42013-10-21 18:57:15 -07001866 nextScanListOffset += ((sizeof(tSirBatchScanList) - sizeof(tANI_U8))
1867 + (sizeof(tSirBatchScanNetworkInfo)
1868 * numNetworkInScanList));
Rajeev79dbe4c2013-10-05 11:03:42 +05301869 numberScanList--;
1870 }
1871
1872done:
1873
1874 /*notify hdd_ioctl only if complete batch scan rsp is received and it was
1875 requested from hdd_ioctl*/
1876 if ((TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp) &&
1877 (TRUE == isLastAp))
1878 {
1879 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
1880 complete(&pAdapter->hdd_get_batch_scan_req_var);
1881 }
1882
1883 return;
1884}/*End of hdd_batch_scan_result_ind_callback*/
1885
1886/**---------------------------------------------------------------------------
1887
1888 \brief hdd_format_batch_scan_rsp () - This function formats batch scan
1889 response as per batch scan FR request format by putting proper markers
1890
1891 \param - pDest pointer to destination buffer
1892 \param - cur_len current length
1893 \param - tot_len total remaining size which can be written to user space
1894 \param - pApMetaInfo Pointer to get batch scan response AP meta info
1895 \param - pAdapter Pointer to HDD adapter
1896
1897 \return - ret no of characters written
1898
1899 --------------------------------------------------------------------------*/
1900static tANI_U32
1901hdd_format_batch_scan_rsp
1902(
1903 tANI_U8 *pDest,
1904 tANI_U32 cur_len,
1905 tANI_U32 tot_len,
1906 tHddBatchScanRsp *pApMetaInfo,
1907 hdd_adapter_t* pAdapter
1908)
1909{
1910 tANI_U32 ret = 0;
1911 tANI_U32 rem_len = 0;
1912 tANI_U8 temp_len = 0;
1913 tANI_U8 temp_total_len = 0;
1914 tANI_U8 temp[HDD_BATCH_SCAN_AP_META_INFO_SIZE];
1915 tANI_U8 *pTemp = temp;
1916
1917 /*Batch scan reponse needs to be returned to user space in
1918 following format:
1919 "scancount=X\n" where X is the number of scans in current batch
1920 batch
1921 "trunc\n" optional present if current scan truncated
1922 "bssid=XX:XX:XX:XX:XX:XX\n"
1923 "ssid=XXXX\n"
1924 "freq=X\n" frequency in Mhz
1925 "level=XX\n"
1926 "age=X\n" ms
1927 "dist=X\n" cm (-1 if not available)
1928 "errror=X\n" (-1if not available)
1929 "====\n" (end of ap marker)
1930 "####\n" (end of scan marker)
1931 "----\n" (end of results)*/
1932 /*send scan result in above format to user space based on
1933 available length*/
1934 /*The GET response may have more data than the driver can return in its
1935 buffer. In that case the buffer should be filled to the nearest complete
1936 scan, ending with "%%%%".Subsequent callsshould return the remaining data
1937 starting with the next scan (optional .trunc\n., .apcount=X\n., etc).
1938 The final buffer should end with "----\n"*/
1939
1940 /*sanity*/
1941 if (cur_len > tot_len)
1942 {
1943 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1944 "%s: invaid cur_len %d tot_len %d", __func__, cur_len, tot_len);
1945 return 0;
1946 }
1947 else
1948 {
1949 rem_len = (tot_len - cur_len);
1950 }
1951
1952 /*end scan marker*/
1953 if (pApMetaInfo->ApInfo.batchId != pAdapter->prev_batch_id)
1954 {
1955 temp_len = snprintf(pTemp, sizeof(temp), "####\n");
1956 pTemp += temp_len;
1957 temp_total_len += temp_len;
1958 }
1959
1960 /*bssid*/
1961 temp_len = snprintf(pTemp, sizeof(temp),
1962 "bssid=0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n",
1963 pApMetaInfo->ApInfo.bssid[0], pApMetaInfo->ApInfo.bssid[1],
1964 pApMetaInfo->ApInfo.bssid[2], pApMetaInfo->ApInfo.bssid[3],
1965 pApMetaInfo->ApInfo.bssid[4], pApMetaInfo->ApInfo.bssid[5]);
1966 pTemp += temp_len;
1967 temp_total_len += temp_len;
1968
1969 /*ssid*/
1970 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "ssid=%s\n",
1971 pApMetaInfo->ApInfo.ssid);
1972 pTemp += temp_len;
1973 temp_total_len += temp_len;
1974
1975 /*freq*/
1976 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "freq=%d\n",
Rajeev Kumarc40f7512013-11-04 14:13:23 -08001977 sme_ChnToFreq(pApMetaInfo->ApInfo.ch));
Rajeev79dbe4c2013-10-05 11:03:42 +05301978 pTemp += temp_len;
1979 temp_total_len += temp_len;
1980
1981 /*level*/
1982 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "level=%d\n",
1983 pApMetaInfo->ApInfo.rssi);
1984 pTemp += temp_len;
1985 temp_total_len += temp_len;
1986
1987 /*age*/
Jeff Johnson02797792013-10-26 19:17:13 -07001988 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "age=%d\n",
Rajeev79dbe4c2013-10-05 11:03:42 +05301989 pApMetaInfo->ApInfo.age);
1990 pTemp += temp_len;
1991 temp_total_len += temp_len;
1992
1993 /*dist*/
1994 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "dist=-1\n");
1995 pTemp += temp_len;
1996 temp_total_len += temp_len;
1997
1998 /*error*/
1999 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "error=-1\n");
2000 pTemp += temp_len;
2001 temp_total_len += temp_len;
2002
2003 /*end AP marker*/
2004 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "====\n");
2005 pTemp += temp_len;
2006 temp_total_len += temp_len;
2007
2008 /*last AP in batch scan response*/
2009 if(TRUE == pApMetaInfo->ApInfo.isLastAp)
2010 {
2011 /*end scan marker*/
2012 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "####\n");
2013 pTemp += temp_len;
2014 temp_total_len += temp_len;
2015
2016 /*end batch scan result marker*/
2017 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "----\n");
2018 pTemp += temp_len;
2019 temp_total_len += temp_len;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002020
Rajeev79dbe4c2013-10-05 11:03:42 +05302021 }
2022
2023 if (temp_total_len < rem_len)
2024 {
2025 ret = temp_total_len + 1;
2026 strlcpy(pDest, temp, ret);
2027 pAdapter->isTruncated = FALSE;
2028 }
2029 else
2030 {
2031 pAdapter->isTruncated = TRUE;
2032 if (rem_len >= strlen("%%%%"))
2033 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08002034 ret = snprintf(pDest, sizeof(temp), "%%%%");
Rajeev79dbe4c2013-10-05 11:03:42 +05302035 }
Rajeev Kumarc933d982013-11-18 20:04:20 -08002036 else
Rajeev79dbe4c2013-10-05 11:03:42 +05302037 {
2038 ret = 0;
2039 }
2040 }
2041
2042 return ret;
2043
2044}/*End of hdd_format_batch_scan_rsp*/
2045
2046/**---------------------------------------------------------------------------
2047
2048 \brief hdd_populate_user_batch_scan_rsp() - This function populates user data
2049 buffer starting with head of hdd batch scan response queue
2050
2051 \param - pAdapter Pointer to HDD adapter
2052 \param - pDest Pointer to user data buffer
2053 \param - cur_len current offset in user buffer
2054 \param - rem_len remaining no of bytes in user buffer
2055
2056 \return - number of bytes written in user buffer
2057
2058 --------------------------------------------------------------------------*/
2059
2060tANI_U32 hdd_populate_user_batch_scan_rsp
2061(
2062 hdd_adapter_t* pAdapter,
2063 tANI_U8 *pDest,
2064 tANI_U32 cur_len,
2065 tANI_U32 rem_len
2066)
2067{
2068 tHddBatchScanRsp *pHead;
2069 tHddBatchScanRsp *pPrev;
2070 tANI_U32 len;
2071
Rajeev79dbe4c2013-10-05 11:03:42 +05302072 pAdapter->isTruncated = FALSE;
2073
2074 /*head of hdd batch scan response queue*/
2075 pHead = pAdapter->pBatchScanRsp;
2076 while (pHead)
2077 {
2078 len = hdd_format_batch_scan_rsp(pDest, cur_len, rem_len, pHead,
2079 pAdapter);
2080 pDest += len;
Rajeev Kumar292d2bb2013-10-23 15:01:44 -07002081 pDest--;
Rajeev79dbe4c2013-10-05 11:03:42 +05302082 cur_len += len;
2083 if(TRUE == pAdapter->isTruncated)
2084 {
2085 /*result is truncated return rest of scan rsp in next req*/
2086 cur_len = rem_len;
2087 break;
2088 }
2089 pPrev = pHead;
2090 pHead = pHead->pNext;
2091 pAdapter->pBatchScanRsp = pHead;
Rajeev Kumarbe17d8b2014-01-10 15:39:45 -08002092 if (TRUE == pPrev->ApInfo.isLastAp)
2093 {
2094 pAdapter->prev_batch_id = 0;
2095 }
2096 else
2097 {
2098 pAdapter->prev_batch_id = pPrev->ApInfo.batchId;
2099 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302100 vos_mem_free(pPrev);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002101 pPrev = NULL;
Rajeev79dbe4c2013-10-05 11:03:42 +05302102 }
2103
2104 return cur_len;
2105}/*End of hdd_populate_user_batch_scan_rsp*/
2106
2107/**---------------------------------------------------------------------------
2108
2109 \brief hdd_return_batch_scan_rsp_to_user () - This function returns batch
2110 scan response data from HDD queue to user space
2111 It does following in detail:
2112 a) if HDD has enough data in its queue then it 1st copies data to user
2113 space and then send get batch scan indication message to FW. In this
2114 case it does not wait on any event and batch scan response data will
2115 be populated in HDD response queue in MC thread context after receiving
2116 indication from FW
2117 b) else send get batch scan indication message to FW and wait on an event
2118 which will be set once HDD receives complete batch scan response from
2119 FW and then this function returns batch scan response to user space
2120
2121 \param - pAdapter Pointer to HDD adapter
2122 \param - pPrivData Pointer to priv_data
2123
2124 \return - 0 for success -EFAULT for failure
2125
2126 --------------------------------------------------------------------------*/
2127
2128int hdd_return_batch_scan_rsp_to_user
2129(
2130 hdd_adapter_t* pAdapter,
2131 hdd_priv_data_t *pPrivData,
2132 tANI_U8 *command
2133)
2134{
2135 tANI_U8 *pDest;
2136 tANI_U32 count = 0;
2137 tANI_U32 len = 0;
2138 tANI_U32 cur_len = 0;
2139 tANI_U32 rem_len = 0;
2140 eHalStatus halStatus;
2141 unsigned long rc;
2142 tSirTriggerBatchScanResultInd *pReq;
2143
2144 pReq = &pAdapter->hddTriggerBatchScanResultInd;
2145 pReq->param = 0;/*batch scan client*/
2146 pDest = (tANI_U8 *)(command + pPrivData->used_len);
2147 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
2148
2149 cur_len = pPrivData->used_len;
2150 if (pPrivData->total_len > pPrivData->used_len)
2151 {
2152 rem_len = pPrivData->total_len - pPrivData->used_len;
2153 }
2154 else
2155 {
2156 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2157 "%s: Invalid user data buffer total_len %d used_len %d",
2158 __func__, pPrivData->total_len, pPrivData->used_len);
2159 return -EFAULT;
2160 }
2161
2162 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2163 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2164 cur_len, rem_len);
2165 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2166
2167 /*enough scan result available in cache to return to user space or
2168 scan result needs to be fetched 1st from fw and then return*/
Rajeev Kumar99db6262013-11-11 15:23:36 -08002169 if (len == cur_len)
Rajeev79dbe4c2013-10-05 11:03:42 +05302170 {
2171 pAdapter->hdd_wait_for_get_batch_scan_rsp = TRUE;
2172 halStatus = sme_TriggerBatchScanResultInd(
2173 WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2174 pAdapter->sessionId, hdd_batch_scan_result_ind_callback,
2175 pAdapter);
2176 if ( eHAL_STATUS_SUCCESS == halStatus )
2177 {
2178 if (TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp)
2179 {
2180 INIT_COMPLETION(pAdapter->hdd_get_batch_scan_req_var);
2181 rc = wait_for_completion_timeout(
2182 &pAdapter->hdd_get_batch_scan_req_var,
2183 msecs_to_jiffies(HDD_GET_BATCH_SCAN_RSP_TIME_OUT));
Abhishek Singh00b71972016-01-07 10:51:04 +05302184 if (0 >= rc)
Rajeev79dbe4c2013-10-05 11:03:42 +05302185 {
2186 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Abhishek Singh00b71972016-01-07 10:51:04 +05302187 "%s: wait on hdd_get_batch_scan_req_var failed %ld",
2188 __func__, rc);
Rajeev79dbe4c2013-10-05 11:03:42 +05302189 return -EFAULT;
2190 }
2191 }
2192
2193 len = snprintf(pDest, HDD_BATCH_SCAN_AP_META_INFO_SIZE,
Jeff Johnson02797792013-10-26 19:17:13 -07002194 "scancount=%u\n", pAdapter->numScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05302195 pDest += len;
2196 cur_len += len;
2197
2198 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2199 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2200 cur_len, rem_len);
2201 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2202
2203 count = 0;
2204 len = (len - pPrivData->used_len);
2205 pDest = (command + pPrivData->used_len);
2206 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002207 "NEW BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302208 while(count < len)
2209 {
2210 printk("%c", *(pDest + count));
2211 count++;
2212 }
2213 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2214 "%s: copy %d data to user buffer", __func__, len);
2215 if (copy_to_user(pPrivData->buf, pDest, len))
2216 {
2217 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2218 "%s: failed to copy data to user buffer", __func__);
2219 return -EFAULT;
2220 }
2221 }
2222 else
2223 {
2224 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2225 "sme_GetBatchScanScan returned failure halStatus %d",
2226 halStatus);
2227 return -EINVAL;
2228 }
2229 }
2230 else
2231 {
Rajeev79dbe4c2013-10-05 11:03:42 +05302232 count = 0;
2233 len = (len - pPrivData->used_len);
2234 pDest = (command + pPrivData->used_len);
2235 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002236 "REMAINING TRUNCATED BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302237 while(count < len)
2238 {
2239 printk("%c", *(pDest + count));
2240 count++;
2241 }
Rajeev Kumar99db6262013-11-11 15:23:36 -08002242 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2243 "%s: copy %d data to user buffer", __func__, len);
Rajeev79dbe4c2013-10-05 11:03:42 +05302244 if (copy_to_user(pPrivData->buf, pDest, len))
2245 {
2246 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2247 "%s: failed to copy data to user buffer", __func__);
2248 return -EFAULT;
2249 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302250 }
2251
2252 return 0;
2253} /*End of hdd_return_batch_scan_rsp_to_user*/
2254
Rajeev Kumar8b373292014-01-08 20:36:55 -08002255/**---------------------------------------------------------------------------
2256
2257 \brief hdd_handle_batch_scan_ioctl () - This function handles WLS_BATCHING
2258 IOCTLs from user space. Following BATCH SCAN DEV IOCTs are handled:
2259 WLS_BATCHING VERSION
2260 WLS_BATCHING SET
2261 WLS_BATCHING GET
2262 WLS_BATCHING STOP
2263
2264 \param - pAdapter Pointer to HDD adapter
2265 \param - pPrivdata Pointer to priv_data
2266 \param - command Pointer to command
2267
2268 \return - 0 for success -EFAULT for failure
2269
2270 --------------------------------------------------------------------------*/
2271
2272int hdd_handle_batch_scan_ioctl
2273(
2274 hdd_adapter_t *pAdapter,
2275 hdd_priv_data_t *pPrivdata,
2276 tANI_U8 *command
2277)
2278{
2279 int ret = 0;
Yue Mae36e3552014-03-05 17:06:20 -08002280 hdd_context_t *pHddCtx;
2281
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302282 ENTER();
2283
Yue Mae36e3552014-03-05 17:06:20 -08002284 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2285 ret = wlan_hdd_validate_context(pHddCtx);
2286 if (ret)
2287 {
Yue Mae36e3552014-03-05 17:06:20 -08002288 goto exit;
2289 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002290
2291 if (strncmp(command, "WLS_BATCHING VERSION", 20) == 0)
2292 {
2293 char extra[32];
2294 tANI_U8 len = 0;
2295 tANI_U8 version = HDD_BATCH_SCAN_VERSION;
2296
2297 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2298 {
2299 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2300 "%s: Batch scan feature is not supported by FW", __func__);
2301 ret = -EINVAL;
2302 goto exit;
2303 }
2304
2305 len = scnprintf(extra, sizeof(extra), "WLS_BATCHING_VERSION %d",
2306 version);
2307 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2308 {
2309 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2310 "%s: failed to copy data to user buffer", __func__);
2311 ret = -EFAULT;
2312 goto exit;
2313 }
2314 ret = HDD_BATCH_SCAN_VERSION;
2315 }
2316 else if (strncmp(command, "WLS_BATCHING SET", 16) == 0)
2317 {
2318 int status;
2319 tANI_U8 *value = (command + 16);
2320 eHalStatus halStatus;
2321 unsigned long rc;
2322 tSirSetBatchScanReq *pReq = &pAdapter->hddSetBatchScanReq;
2323 tSirSetBatchScanRsp *pRsp = &pAdapter->hddSetBatchScanRsp;
2324
2325 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2326 {
2327 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2328 "%s: Batch scan feature is not supported by FW", __func__);
2329 ret = -EINVAL;
2330 goto exit;
2331 }
2332
2333 if ((WLAN_HDD_INFRA_STATION != pAdapter->device_mode) &&
2334 (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) &&
2335 (WLAN_HDD_P2P_GO != pAdapter->device_mode) &&
2336 (WLAN_HDD_P2P_DEVICE != pAdapter->device_mode))
2337 {
2338 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302339 "Received WLS_BATCHING SET command in invalid mode %s (%d) "
Rajeev Kumar8b373292014-01-08 20:36:55 -08002340 "WLS_BATCHING_SET is only allowed in infra STA/P2P client mode",
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302341 hdd_device_modetoString(pAdapter->device_mode),
2342 pAdapter->device_mode);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002343 ret = -EINVAL;
2344 goto exit;
2345 }
2346
2347 status = hdd_parse_set_batchscan_command(value, pReq);
2348 if (status)
2349 {
2350 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2351 "Invalid WLS_BATCHING SET command");
2352 ret = -EINVAL;
2353 goto exit;
2354 }
2355
2356
2357 pAdapter->hdd_wait_for_set_batch_scan_rsp = TRUE;
2358 halStatus = sme_SetBatchScanReq(WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2359 pAdapter->sessionId, hdd_set_batch_scan_req_callback,
2360 pAdapter);
2361
2362 if ( eHAL_STATUS_SUCCESS == halStatus )
2363 {
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302364 char extra[32];
2365 tANI_U8 len = 0;
2366 tANI_U8 mScan = 0;
2367
Rajeev Kumar8b373292014-01-08 20:36:55 -08002368 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2369 "sme_SetBatchScanReq returned success halStatus %d",
2370 halStatus);
2371 if (TRUE == pAdapter->hdd_wait_for_set_batch_scan_rsp)
2372 {
2373 INIT_COMPLETION(pAdapter->hdd_set_batch_scan_req_var);
2374 rc = wait_for_completion_timeout(
2375 &pAdapter->hdd_set_batch_scan_req_var,
2376 msecs_to_jiffies(HDD_SET_BATCH_SCAN_REQ_TIME_OUT));
2377 if (0 == rc)
2378 {
2379 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2380 "%s: Timeout waiting for set batch scan to complete",
2381 __func__);
2382 ret = -EINVAL;
2383 goto exit;
2384 }
2385 }
2386 if ( !pRsp->nScansToBatch )
2387 {
2388 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2389 "%s: Received set batch scan failure response from FW",
2390 __func__);
2391 ret = -EINVAL;
2392 goto exit;
2393 }
2394 /*As per the Batch Scan Framework API we should return the MIN of
2395 either MSCAN or the max # of scans firmware can cache*/
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302396 mScan = MIN(pReq->numberOfScansToBatch , pRsp->nScansToBatch);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002397
2398 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STARTED;
2399
2400 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2401 "%s: request MSCAN %d response MSCAN %d ret %d",
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302402 __func__, pReq->numberOfScansToBatch, pRsp->nScansToBatch, mScan);
2403 len = scnprintf(extra, sizeof(extra), "%d", mScan);
2404 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2405 {
2406 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2407 "%s: failed to copy MSCAN value to user buffer", __func__);
2408 ret = -EFAULT;
2409 goto exit;
2410 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002411 }
2412 else
2413 {
2414 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2415 "sme_SetBatchScanReq returned failure halStatus %d",
2416 halStatus);
2417 ret = -EINVAL;
2418 goto exit;
2419 }
2420 }
2421 else if (strncmp(command, "WLS_BATCHING STOP", 17) == 0)
2422 {
2423 eHalStatus halStatus;
2424 tSirStopBatchScanInd *pInd = &pAdapter->hddStopBatchScanInd;
2425 pInd->param = 0;
2426
2427 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2428 {
2429 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2430 "%s: Batch scan feature is not supported by FW", __func__);
2431 ret = -EINVAL;
2432 goto exit;
2433 }
2434
2435 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2436 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302437 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002438 "Batch scan is not yet enabled batch scan state %d",
2439 pAdapter->batchScanState);
2440 ret = -EINVAL;
2441 goto exit;
2442 }
2443
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002444 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2445 hdd_deinit_batch_scan(pAdapter);
2446 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2447
Rajeev Kumar8b373292014-01-08 20:36:55 -08002448 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
2449
2450 halStatus = sme_StopBatchScanInd(WLAN_HDD_GET_HAL_CTX(pAdapter), pInd,
2451 pAdapter->sessionId);
2452 if ( eHAL_STATUS_SUCCESS == halStatus )
2453 {
2454 ret = 0;
2455 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2456 "sme_StopBatchScanInd returned success halStatus %d",
2457 halStatus);
2458 }
2459 else
2460 {
2461 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2462 "sme_StopBatchScanInd returned failure halStatus %d",
2463 halStatus);
2464 ret = -EINVAL;
2465 goto exit;
2466 }
2467 }
2468 else if (strncmp(command, "WLS_BATCHING GET", 16) == 0)
2469 {
2470 tANI_U32 remain_len;
2471
2472 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2473 {
2474 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2475 "%s: Batch scan feature is not supported by FW", __func__);
2476 ret = -EINVAL;
2477 goto exit;
2478 }
2479
2480 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2481 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302482 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002483 "Batch scan is not yet enabled could not return results"
2484 "Batch Scan state %d",
2485 pAdapter->batchScanState);
2486 ret = -EINVAL;
2487 goto exit;
2488 }
2489
2490 pPrivdata->used_len = 16;
2491 remain_len = pPrivdata->total_len - pPrivdata->used_len;
2492 if (remain_len < pPrivdata->total_len)
2493 {
2494 /*Clear previous batch scan response data if any*/
2495 vos_mem_zero((tANI_U8 *)(command + pPrivdata->used_len), remain_len);
2496 }
2497 else
2498 {
2499 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2500 "Invalid total length from user space can't fetch batch"
2501 " scan response total_len %d used_len %d remain len %d",
2502 pPrivdata->total_len, pPrivdata->used_len, remain_len);
2503 ret = -EINVAL;
2504 goto exit;
2505 }
2506 ret = hdd_return_batch_scan_rsp_to_user(pAdapter, pPrivdata, command);
2507 }
2508
2509exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302510 EXIT();
Rajeev Kumar8b373292014-01-08 20:36:55 -08002511 return ret;
2512}
2513
2514
Rajeev79dbe4c2013-10-05 11:03:42 +05302515#endif/*End of FEATURE_WLAN_BATCH_SCAN*/
2516
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302517#if defined(WLAN_FEATURE_VOWIFI_11R) || defined(FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
2518/**
2519 * hdd_assign_handoff_src_reassoc - Set handoff source as REASSOC
2520 * to Handoff request
2521 * @handoffInfo: Pointer to Handoff request
2522 * @src: enum of handoff_src
2523 * Return: None
2524 */
2525#ifndef QCA_WIFI_ISOC
2526static inline void hdd_assign_handoff_src_reassoc(tCsrHandoffRequest
2527 *handoffInfo, handoff_src src)
2528{
2529 handoffInfo->src = src;
2530}
2531#else
2532static inline void hdd_assign_handoff_src_reassoc(tCsrHandoffRequest
2533 *handoffInfo, handoff_src src)
2534{
2535}
2536#endif
2537
2538/**
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302539 * hdd_reassoc() - perform a user space-directed reassoc
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302540 *
2541 * @pAdapter: Adapter upon which the command was received
2542 * @bssid: BSSID with which to reassociate
2543 * @channel: channel upon which to reassociate
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302544 * @src: The source for the trigger of this action
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302545 *
2546 * Return: 0 for success non-zero for failure
2547 */
2548#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Selvaraj, Sridhar8ecb4192016-06-23 17:50:49 +05302549int hdd_reassoc(hdd_adapter_t *pAdapter, const tANI_U8 *bssid,
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302550 const tANI_U8 channel, const handoff_src src)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302551{
2552 hdd_station_ctx_t *pHddStaCtx;
2553 tCsrHandoffRequest handoffInfo;
2554 hdd_context_t *pHddCtx = NULL;
2555 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2556
2557 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2558
2559 /* if not associated, no need to proceed with reassoc */
2560 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
2561 hddLog(LOG1, FL("Not associated"));
2562 return -EINVAL;
2563 }
2564
2565 /* if the target bssid is same as currently associated AP,
2566 then no need to proceed with reassoc */
2567 if (!memcmp(bssid, pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr))) {
2568 hddLog(LOG1, FL("Reassoc BSSID is same as currently associated AP bssid"));
2569 return -EINVAL;
2570 }
2571
2572 /* Check channel number is a valid channel number */
2573 if (VOS_STATUS_SUCCESS !=
2574 wlan_hdd_validate_operation_channel(pAdapter, channel)) {
2575 hddLog(LOGE, FL("Invalid Channel %d"), channel);
2576 return -EINVAL;
2577 }
2578
2579 /* Proceed with reassoc */
2580 handoffInfo.channel = channel;
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302581 hdd_assign_handoff_src_reassoc(&handoffInfo, src);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302582 memcpy(handoffInfo.bssid, bssid, sizeof(tSirMacAddr));
2583 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
2584 return 0;
2585}
2586#else
Selvaraj, Sridhar8ecb4192016-06-23 17:50:49 +05302587int hdd_reassoc(hdd_adapter_t *pAdapter, const tANI_U8 *bssid,
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302588 const tANI_U8 channel, const handoff_src src)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302589{
2590 return -EPERM;
2591}
2592#endif
2593
2594/**
2595 * hdd_parse_reassoc_v1() - parse version 1 of the REASSOC command
2596 * This function parses the v1 REASSOC command with the format
2597 * REASSOC xx:xx:xx:xx:xx:xx CH where "xx:xx:xx:xx:xx:xx" is the
2598 * Hex-ASCII representation of the BSSID and CH is the ASCII
2599 * representation of the channel. For example
2600 * REASSOC 00:0a:0b:11:22:33 48
2601 *
2602 * @pAdapter: Adapter upon which the command was received
2603 * @command: ASCII text command that was received
2604 *
2605 * Return: 0 for success non-zero for failure
2606 */
2607static int
2608hdd_parse_reassoc_v1(hdd_adapter_t *pAdapter, const char *command)
2609{
2610 tANI_U8 channel = 0;
2611 tSirMacAddr bssid;
2612 int ret;
2613
2614 ret = hdd_parse_reassoc_command_v1_data(command, bssid, &channel);
2615 if (ret)
2616 hddLog(LOGE, FL("Failed to parse reassoc command data"));
2617 else
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302618 ret = hdd_reassoc(pAdapter, bssid, channel, REASSOC);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302619
2620 return ret;
2621}
2622
2623/**
2624 * hdd_parse_reassoc_v2() - parse version 2 of the REASSOC command
2625 * This function parses the v2 REASSOC command with the format
2626 * REASSOC <android_wifi_reassoc_params>
2627 *
2628 * @pAdapter: Adapter upon which the command was received
2629 * @command: command that was received, ASCII command followed
2630 * by binary data
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302631 * @total_len: Total length of the command received
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302632 *
2633 * Return: 0 for success non-zero for failure
2634 */
2635static int
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302636hdd_parse_reassoc_v2(hdd_adapter_t *pAdapter, const char *command,
2637 int total_len)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302638{
2639 struct android_wifi_reassoc_params params;
2640 tSirMacAddr bssid;
2641 int ret;
2642
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302643 if (total_len < sizeof(params) + 8) {
2644 hddLog(LOGE, FL("Invalid command length"));
2645 return -EINVAL;
2646 }
2647
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302648 /* The params are located after "REASSOC " */
2649 memcpy(&params, command + 8, sizeof(params));
2650
2651 if (!mac_pton(params.bssid, (u8 *)&bssid)) {
2652 hddLog(LOGE, FL("MAC address parsing failed"));
2653 ret = -EINVAL;
2654 } else {
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302655 ret = hdd_reassoc(pAdapter, bssid, params.channel, REASSOC);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302656 }
2657 return ret;
2658}
2659
2660/**
2661 * hdd_parse_reassoc() - parse the REASSOC command
2662 * There are two different versions of the REASSOC command.Version 1
2663 * of the command contains a parameter list that is ASCII characters
2664 * whereas version 2 contains a combination of ASCII and binary
2665 * payload. Determine if a version 1 or a version 2 command is being
2666 * parsed by examining the parameters, and then dispatch the parser
2667 * that is appropriate for the command.
2668 *
2669 * @pAdapter: Adapter upon which the command was received
2670 * @command: command that was received
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302671 * @total_len: Total length of the command received
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302672 *
2673 * Return: 0 for success non-zero for failure
2674 */
2675static int
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302676hdd_parse_reassoc(hdd_adapter_t *pAdapter, const char *command, int total_len)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302677{
2678 int ret;
2679
2680 /*
2681 * both versions start with "REASSOC"
2682 * v1 has a bssid and channel # as an ASCII string
2683 * REASSOC xx:xx:xx:xx:xx:xx CH
2684 * v2 has a C struct
2685 * REASSOC <binary c struct>
2686 *
2687 * The first field in the v2 struct is also the bssid in ASCII.
2688 * But in the case of a v2 message the BSSID is NUL-terminated.
2689 * Hence we can peek at that offset to see if this is V1 or V2
2690 * REASSOC xx:xx:xx:xx:xx:xx*
2691 * 1111111111222222
2692 * 01234567890123456789012345
2693 */
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302694
2695 if (total_len < 26) {
2696 hddLog(LOGE, FL("Invalid command (total_len=%d)"), total_len);
2697 return -EINVAL;
2698 }
2699
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302700 if (command[25])
2701 ret = hdd_parse_reassoc_v1(pAdapter, command);
2702 else
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302703 ret = hdd_parse_reassoc_v2(pAdapter, command, total_len);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302704
2705 return ret;
2706}
2707#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE FEATURE_WLAN_LFR */
2708
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302709struct bcn_miss_rate_priv {
2710 int bcn_miss_rate;
2711};
2712
2713/**
2714 * get_bcn_miss_rate_cb() callback invoked on receiving beacon miss
2715 * rate from firmware
2716 * @status: Status of get beacon miss rate operation
2717 * @bcnMissRate: Beacon miss rate
2718 * @context: Context passed while registering callback
2719 *
2720 * This function is invoked by WDA layer on receiving
2721 * WDI_GET_BCN_MISS_RATE_RSP
2722 *
2723 * Return: None
2724 */
2725static void get_bcn_miss_rate_cb(VOS_STATUS status, int bcnMissRate,
2726 void *context)
c_hpothu92367912014-05-01 15:18:17 +05302727{
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302728 struct hdd_request *request;
2729 struct bcn_miss_rate_priv *priv;
c_hpothu39eb1e32014-06-26 16:31:50 +05302730
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302731 request = hdd_request_get(context);
2732 if (!request) {
2733 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
2734 return;
2735 }
c_hpothu92367912014-05-01 15:18:17 +05302736
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302737 priv = hdd_request_priv(request);
c_hpothu92367912014-05-01 15:18:17 +05302738
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302739 if (VOS_STATUS_SUCCESS == status)
2740 priv->bcn_miss_rate = bcnMissRate;
2741 else
2742 hddLog(VOS_TRACE_LEVEL_ERROR, FL("failed to get bcnMissRate"));
c_hpothu92367912014-05-01 15:18:17 +05302743
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302744 hdd_request_complete(request);
2745 hdd_request_put(request);
Hanumanth Reddy Pothulad0d3c172018-05-02 18:53:05 +05302746
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302747 return;
c_hpothu92367912014-05-01 15:18:17 +05302748}
2749
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302750struct fw_stats_priv {
2751 tSirFwStatsResult *fw_stats;
2752};
2753
2754/**
2755 * hdd_fw_stats_cb() callback invoked on receiving firmware stats
2756 * from firmware
2757 * @status: Status of get firmware stats operation
2758 * @fwStatsResult: firmware stats
2759 * @context: Context passed while registering callback
2760 *
2761 * This function is invoked by WDA layer on receiving
2762 * WDI_GET_FW_STATS_RSP
2763 *
2764 * Return: None
2765 */
2766static void hdd_fw_stats_cb(VOS_STATUS status,
2767 tSirFwStatsResult *fwStatsResult, void *context)
Satyanarayana Dash72806012014-12-02 14:30:08 +05302768{
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302769 struct hdd_request *request;
2770 struct fw_stats_priv *priv;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302771
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302772 hddLog(VOS_TRACE_LEVEL_INFO, FL("with status = %d"),status);
Satyanarayana Dash72806012014-12-02 14:30:08 +05302773
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302774 request = hdd_request_get(context);
2775 if (!request) {
2776 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
2777 return;
2778 }
2779 priv = hdd_request_priv(request);
2780
2781 if (VOS_STATUS_SUCCESS == status)
2782 *priv->fw_stats = *fwStatsResult;
2783 else
2784 priv->fw_stats = NULL;
2785
2786 hdd_request_complete(request);
2787 hdd_request_put(request);
2788 return;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302789}
2790
jge35567202017-06-21 16:39:38 +08002791/*
2792 *hdd_parse_setmaxtxpower_command() - HDD Parse MAXTXPOWER command
2793 *@pValue Pointer to MAXTXPOWER command
2794 *@pTxPower Pointer to tx power
2795 *
2796 *This function parses the MAXTXPOWER command passed in the format
2797 * MAXTXPOWER<space>X(Tx power in dbm)
2798 * For example input commands:
2799 * 1) MAXTXPOWER -8 -> This is translated into set max TX power to -8 dbm
2800 * 2) MAXTXPOWER -23 -> This is translated into set max TX power to -23 dbm
2801 *
2802 *return - 0 for success non-zero for failure
2803 */
2804static int hdd_parse_setmaxtxpower_command(unsigned char *pValue, int *pTxPower)
2805{
2806 unsigned char *inPtr = pValue;
2807 int tempInt;
2808 int v = 0;
2809 *pTxPower = 0;
2810
2811 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
2812 /* no argument after the command */
2813 if (NULL == inPtr)
2814 return -EINVAL;
2815 /* no space after the command */
2816 else if (SPACE_ASCII_VALUE != *inPtr)
2817 return -EINVAL;
2818
2819 /* removing empty spaces */
2820 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
2821
2822 /* no argument followed by spaces */
2823 if ('\0' == *inPtr)
2824 return 0;
2825
2826 v = kstrtos32(inPtr, 10, &tempInt);
2827
2828 /* Range checking for passed parameter */
2829 if ((tempInt < HDD_MIN_TX_POWER) || (tempInt > HDD_MAX_TX_POWER))
2830 return -EINVAL;
2831
2832 *pTxPower = tempInt;
2833
2834 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2835 "SETMAXTXPOWER: %d", *pTxPower);
2836
2837 return 0;
2838}
2839
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302840static int hdd_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command, char *extra, tANI_U8 n, tANI_U8 *len)
2841{
2842 int ret = 0;
2843
2844 if (!pCfg || !command || !extra || !len)
2845 {
2846 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2847 "%s: argument passsed for GETDWELLTIME is incorrect", __func__);
2848 ret = -EINVAL;
2849 return ret;
2850 }
2851
2852 if (strncmp(command, "GETDWELLTIME ACTIVE MAX", 23) == 0)
2853 {
2854 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MAX %u\n",
2855 (int)pCfg->nActiveMaxChnTime);
2856 return ret;
2857 }
2858 else if (strncmp(command, "GETDWELLTIME ACTIVE MIN", 23) == 0)
2859 {
2860 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MIN %u\n",
2861 (int)pCfg->nActiveMinChnTime);
2862 return ret;
2863 }
2864 else if (strncmp(command, "GETDWELLTIME PASSIVE MAX", 24) == 0)
2865 {
2866 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MAX %u\n",
2867 (int)pCfg->nPassiveMaxChnTime);
2868 return ret;
2869 }
2870 else if (strncmp(command, "GETDWELLTIME PASSIVE MIN", 24) == 0)
2871 {
2872 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MIN %u\n",
2873 (int)pCfg->nPassiveMinChnTime);
2874 return ret;
2875 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302876 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
2877 {
2878 *len = scnprintf(extra, n, "GETDWELLTIME %u \n",
2879 (int)pCfg->nActiveMaxChnTime);
2880 return ret;
2881 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302882 else
2883 {
2884 ret = -EINVAL;
2885 }
2886
2887 return ret;
2888}
2889
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05302890/**
2891 * hdd_btc_get_dwell_time() - Get BTC dwell time parameters
2892 * @pCfg: Pointer to HDD context
2893 * @command: ASCII text command that is received
2894 * @extra: Pointer to copy data sent to user
2895 * @n: size of 'extra' buffer
2896 * @len: length copied to 'extra' buffer
2897 *
2898 * Driver commands:
2899 * wpa_cli DRIVER BTCGETDWELLTIME ESCO MAX
2900 * wpa_cli DRIVER BTCGETDWELLTIME ESCO MIN
2901 * wpa_cli DRIVER BTCGETDWELLTIME SCO MAX
2902 * wpa_cli DRIVER BTCGETDWELLTIME SCO MIN
2903 *
2904 * Return: 0 for success non-zero for failure
2905 */
2906
2907static int hdd_btc_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command,
2908 char *extra, tANI_U8 n, tANI_U8 *len)
2909{
2910 int ret = 0;
2911
2912 if (!pCfg || !command || !extra || !len)
2913 {
2914 hddLog(LOGE, FL("Argument passsed for BTCGETDWELLTIME is incorrect"));
2915 ret = -EINVAL;
2916 return ret;
2917 }
2918
2919 if (strncmp(command, "BTCGETDWELLTIME ESCO MAX", 24) == 0)
2920 {
2921 *len = scnprintf(extra, n, "BTCGETDWELLTIME ESCO MAX %u\n",
2922 (int)pCfg->max_chntime_btc_esco);
2923 return ret;
2924 }
2925 else if (strncmp(command, "BTCGETDWELLTIME ESCO MIN", 24) == 0)
2926 {
2927 *len = scnprintf(extra, n, "BTCGETDWELLTIME ESCO MIN %u\n",
2928 (int)pCfg->min_chntime_btc_esco);
2929 return ret;
2930 }
2931 else if (strncmp(command, "BTCGETDWELLTIME SCO MAX", 23) == 0)
2932 {
2933 *len = scnprintf(extra, n, "BTCGETDWELLTIME SCO MAX %u\n",
2934 (int)pCfg->max_chntime_btc_sco);
2935 return ret;
2936 }
2937 else if (strncmp(command, "BTCGETDWELLTIME SCO MIN", 23) == 0)
2938 {
2939 *len = scnprintf(extra, n, "BTCGETDWELLTIME SCO MIN %u\n",
2940 (int)pCfg->min_chntime_btc_sco);
2941 return ret;
2942 }
2943 else
2944 {
2945 ret = -EINVAL;
2946 }
2947
2948 return ret;
2949}
2950
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302951int hdd_drv_cmd_validate(tANI_U8 *command, int len)
2952{
2953 if (command[len] != ' ')
2954 return -EINVAL;
2955
2956 return 0;
2957}
2958
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05302959#ifdef WLAN_AP_STA_CONCURRENCY
2960
2961/**
2962 * hdd_conc_get_dwell_time() - Get concurrency dwell time parameters
2963 * @pCfg: Pointer to HDD context
2964 * @command: ASCII text command that is received
2965 * @extra: Pointer to copy data sent to user
2966 * @n: size of 'extra' buffer
2967 * @len: length copied to 'extra' buffer
2968 *
2969 * Driver commands:
2970 * wpa_cli DRIVER CONCGETDWELLTIME ACTIVE MAX
2971 * wpa_cli DRIVER CONCGETDWELLTIME ACTIVE MIN
2972 * wpa_cli DRIVER CONCGETDWELLTIME PASSIVE MAX
2973 * wpa_cli DRIVER CONCGETDWELLTIME PASSIVE MIN
2974 *
2975 * Return: 0 for success non-zero for failure
2976 */
2977
2978static int hdd_conc_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command,
2979 char *extra, tANI_U8 n, tANI_U8 *len)
2980{
2981 int ret = 0;
2982
2983 if (!pCfg || !command || !extra || !len)
2984 {
2985 hddLog(LOGE, FL("Argument passsed for CONCGETDWELLTIME is incorrect"));
2986 ret = -EINVAL;
2987 return ret;
2988 }
2989
2990 if (strncmp(command, "CONCGETDWELLTIME ACTIVE MAX", 27) == 0)
2991 {
2992 *len = scnprintf(extra, n, "CONCGETDWELLTIME ACTIVE MAX %u\n",
2993 (int)pCfg->nActiveMaxChnTimeConc);
2994 return ret;
2995 }
2996 else if (strncmp(command, "CONCGETDWELLTIME ACTIVE MIN", 27) == 0)
2997 {
2998 *len = scnprintf(extra, n, "CONCGETDWELLTIME ACTIVE MIN %u\n",
2999 (int)pCfg->nActiveMinChnTimeConc);
3000 return ret;
3001 }
3002 else if (strncmp(command, "CONCGETDWELLTIME PASSIVE MAX", 28) == 0)
3003 {
3004 *len = scnprintf(extra, n, "CONCGETDWELLTIME PASSIVE MAX %u\n",
3005 (int)pCfg->nPassiveMaxChnTimeConc);
3006 return ret;
3007 }
3008 else if (strncmp(command, "CONCGETDWELLTIME PASSIVE MIN", 28) == 0)
3009 {
3010 *len = scnprintf(extra, n, "CONCGETDWELLTIME PASSIVE MIN %u\n",
3011 (int)pCfg->nPassiveMinChnTimeConc);
3012 return ret;
3013 }
3014 else
3015 {
3016 ret = -EINVAL;
3017 }
3018
3019 return ret;
3020}
3021
3022/**
3023 * hdd_conc_set_dwell_time() - Set concurrency dwell time parameters
3024 * @pAdapter: Adapter upon which the command was received
3025 * @command: ASCII text command that is received
3026 *
3027 * Driver commands:
3028 * wpa_cli DRIVER CONCSETDWELLTIME ACTIVE MAX <value>
3029 * wpa_cli DRIVER CONCSETDWELLTIME ACTIVE MIN <value>
3030 * wpa_cli DRIVER CONCSETDWELLTIME PASSIVE MAX <value
3031 * wpa_cli DRIVER CONCSETDWELLTIME PASSIVE MIN <value>
3032 *
3033 * Return: 0 for success non-zero for failure
3034 */
3035
3036static int hdd_conc_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3037{
3038 tHalHandle hHal;
3039 hdd_config_t *pCfg;
3040 tANI_U8 *value = command;
3041 int val = 0, ret = 0, temp = 0;
3042 tSmeConfigParams smeConfig;
3043
3044 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3045 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
3046 {
3047 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME is incorrect"));
3048 ret = -EINVAL;
3049 return ret;
3050 }
3051
3052 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3053 sme_GetConfigParam(hHal, &smeConfig);
3054
3055 if (strncmp(command, "CONCSETDWELLTIME ACTIVE MAX", 27) == 0 )
3056 {
3057 if (hdd_drv_cmd_validate(command, 27)) {
3058 hddLog(LOGE, FL("Invalid driver command"));
3059 return -EINVAL;
3060 }
3061
3062 value = value + 28;
3063 temp = kstrtou32(value, 10, &val);
3064 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_CONC_MIN ||
3065 val > CFG_ACTIVE_MAX_CHANNEL_TIME_CONC_MAX)
3066 {
3067 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME ACTIVE MAX is incorrect"));
3068 ret = -EFAULT;
3069 return ret;
3070 }
3071 pCfg->nActiveMaxChnTimeConc = val;
3072 smeConfig.csrConfig.nActiveMaxChnTimeConc = val;
3073 sme_UpdateConfig(hHal, &smeConfig);
3074 }
3075 else if (strncmp(command, "CONCSETDWELLTIME ACTIVE MIN", 27) == 0)
3076 {
3077 if (hdd_drv_cmd_validate(command, 27)) {
3078 hddLog(LOGE, FL("Invalid driver command"));
3079 return -EINVAL;
3080 }
3081
3082 value = value + 28;
3083 temp = kstrtou32(value, 10, &val);
3084 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_CONC_MIN ||
3085 val > CFG_ACTIVE_MIN_CHANNEL_TIME_CONC_MAX)
3086 {
3087 hddLog(LOGE, FL("Argument passsed for CONCSETDWELLTIME ACTIVE MIN is incorrect"));
3088 ret = -EFAULT;
3089 return ret;
3090 }
3091 pCfg->nActiveMinChnTimeConc = val;
3092 smeConfig.csrConfig.nActiveMinChnTimeConc = val;
3093 sme_UpdateConfig(hHal, &smeConfig);
3094 }
3095 else if (strncmp(command, "CONCSETDWELLTIME PASSIVE MAX", 28) == 0)
3096 {
3097 if (hdd_drv_cmd_validate(command, 28)) {
3098 hddLog(LOGE, FL("Invalid driver command"));
3099 return -EINVAL;
3100 }
3101
3102 value = value + 29;
3103 temp = kstrtou32(value, 10, &val);
3104 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_CONC_MIN ||
3105 val > CFG_PASSIVE_MAX_CHANNEL_TIME_CONC_MAX)
3106 {
3107 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME PASSIVE MAX is incorrect"));
3108 ret = -EFAULT;
3109 return ret;
3110 }
3111 pCfg->nPassiveMaxChnTimeConc = val;
3112 smeConfig.csrConfig.nPassiveMaxChnTimeConc = val;
3113 sme_UpdateConfig(hHal, &smeConfig);
3114 }
3115 else if (strncmp(command, "CONCSETDWELLTIME PASSIVE MIN", 28) == 0)
3116 {
3117 if (hdd_drv_cmd_validate(command, 28)) {
3118 hddLog(LOGE, FL("Invalid driver command"));
3119 return -EINVAL;
3120 }
3121
3122 value = value + 29;
3123 temp = kstrtou32(value, 10, &val);
3124 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_CONC_MIN ||
3125 val > CFG_PASSIVE_MIN_CHANNEL_TIME_CONC_MAX )
3126 {
3127 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME PASSIVE MIN is incorrect"));
3128 ret = -EFAULT;
3129 return ret;
3130 }
3131 pCfg->nPassiveMinChnTimeConc = val;
3132 smeConfig.csrConfig.nPassiveMinChnTimeConc = val;
3133 sme_UpdateConfig(hHal, &smeConfig);
3134 }
3135 else
3136 {
3137 ret = -EINVAL;
3138 }
3139
3140 return ret;
3141}
3142
3143#endif
3144
3145/**
3146 * hdd_btc_set_dwell_time() - Set BTC dwell time parameters
3147 * @pAdapter: Adapter upon which the command was received
3148 * @command: ASCII text command that is received
3149 *
3150 * Driver commands:
3151 * wpa_cli DRIVER BTCSETDWELLTIME ESCO MAX <value>
3152 * wpa_cli DRIVER BTCSETDWELLTIME ESCO MIN <value>
3153 * wpa_cli DRIVER BTCSETDWELLTIME SCO MAX <value>
3154 * wpa_cli DRIVER BTCSETDWELLTIME SCO MIN <value>
3155 *
3156 * Return: 0 for success non-zero for failure
3157 */
3158
3159static int hdd_btc_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3160{
3161 tHalHandle hHal;
3162 hdd_config_t *pCfg;
3163 tANI_U8 *value = command;
3164 int val = 0, ret = 0, temp = 0;
3165 tSmeConfigParams smeConfig;
3166
3167 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3168 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
3169 {
3170 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME is incorrect"));
3171 ret = -EINVAL;
3172 return ret;
3173 }
3174
3175 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3176 sme_GetConfigParam(hHal, &smeConfig);
3177
3178 if (strncmp(command, "BTCSETDWELLTIME ESCO MAX", 24) == 0)
3179 {
3180 if (hdd_drv_cmd_validate(command, 24)) {
3181 hddLog(LOGE, FL("Invalid driver command"));
3182 return -EINVAL;
3183 }
3184
3185 value = value + 25;
3186 temp = kstrtou32(value, 10, &val);
3187 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_MIN ||
3188 val > CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_MAX)
3189 {
3190 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME ESCO MAX is incorrect"));
3191 ret = -EFAULT;
3192 return ret;
3193 }
3194 pCfg->max_chntime_btc_esco = val;
3195 smeConfig.csrConfig.max_chntime_btc_esco = val;
3196 sme_UpdateConfig(hHal, &smeConfig);
3197 }
3198 else if (strncmp(command, "BTCSETDWELLTIME ESCO MIN", 24) == 0)
3199 {
3200 if (hdd_drv_cmd_validate(command, 24)) {
3201 hddLog(LOGE, FL("Invalid driver command"));
3202 return -EINVAL;
3203 }
3204
3205 value = value + 25;
3206 temp = kstrtou32(value, 10, &val);
3207 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_MIN ||
3208 val > CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_MAX)
3209 {
3210 hddLog(LOGE, FL("Argument passsed for BTCSETDWELLTIME ESCO MIN is incorrect"));
3211 ret = -EFAULT;
3212 return ret;
3213 }
3214 pCfg->min_chntime_btc_esco = val;
3215 smeConfig.csrConfig.min_chntime_btc_esco = val;
3216 sme_UpdateConfig(hHal, &smeConfig);
3217 }
3218 else if (strncmp(command, "BTCSETDWELLTIME SCO MAX", 23) == 0)
3219 {
3220 if (hdd_drv_cmd_validate(command, 23)) {
3221 hddLog(LOGE, FL("Invalid driver command"));
3222 return -EINVAL;
3223 }
3224
3225 value = value + 24;
3226 temp = kstrtou32(value, 10, &val);
3227 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_SCO_MIN ||
3228 val > CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_SCO_MAX)
3229 {
3230 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME SCO MAX is incorrect"));
3231 ret = -EFAULT;
3232 return ret;
3233 }
3234 pCfg->max_chntime_btc_sco = val;
3235 smeConfig.csrConfig.max_chntime_btc_sco = val;
3236 sme_UpdateConfig(hHal, &smeConfig);
3237 }
3238 else if (strncmp(command, "BTCSETDWELLTIME SCO MIN", 23) == 0)
3239 {
3240 if (hdd_drv_cmd_validate(command, 23)) {
3241 hddLog(LOGE, FL("Invalid driver command"));
3242 return -EINVAL;
3243 }
3244
3245 value = value + 24;
3246 temp = kstrtou32(value, 10, &val);
3247 if (temp != 0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_SCO_MIN ||
3248 val > CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_SCO_MAX)
3249 {
3250 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME SCO MIN is incorrect"));
3251 ret = -EFAULT;
3252 return ret;
3253 }
3254 pCfg->min_chntime_btc_sco = val;
3255 smeConfig.csrConfig.min_chntime_btc_sco = val;
3256 sme_UpdateConfig(hHal, &smeConfig);
3257 }
3258 else
3259 {
3260 ret = -EINVAL;
3261 }
3262
3263 return ret;
3264}
3265
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303266static int hdd_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3267{
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303268 tHalHandle hHal;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303269 hdd_config_t *pCfg;
3270 tANI_U8 *value = command;
3271 int val = 0, ret = 0, temp = 0;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303272 tSmeConfigParams smeConfig;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303273
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303274 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3275 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303276 {
3277 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3278 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
3279 ret = -EINVAL;
3280 return ret;
3281 }
3282
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303283 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3284 sme_GetConfigParam(hHal, &smeConfig);
3285
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303286 if (strncmp(command, "SETDWELLTIME ACTIVE MAX", 23) == 0 )
3287 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303288 if (hdd_drv_cmd_validate(command, 23))
3289 return -EINVAL;
3290
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303291 value = value + 24;
3292 temp = kstrtou32(value, 10, &val);
3293 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
3294 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
3295 {
3296 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3297 "%s: argument passed for SETDWELLTIME ACTIVE MAX is incorrect", __func__);
3298 ret = -EFAULT;
3299 return ret;
3300 }
3301 pCfg->nActiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303302 smeConfig.csrConfig.nActiveMaxChnTime = val;
3303 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303304 }
3305 else if (strncmp(command, "SETDWELLTIME ACTIVE MIN", 23) == 0)
3306 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303307 if (hdd_drv_cmd_validate(command, 23))
3308 return -EINVAL;
3309
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303310 value = value + 24;
3311 temp = kstrtou32(value, 10, &val);
3312 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_MIN ||
3313 val > CFG_ACTIVE_MIN_CHANNEL_TIME_MAX )
3314 {
3315 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3316 "%s: argument passsed for SETDWELLTIME ACTIVE MIN is incorrect", __func__);
3317 ret = -EFAULT;
3318 return ret;
3319 }
3320 pCfg->nActiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303321 smeConfig.csrConfig.nActiveMinChnTime = val;
3322 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303323 }
3324 else if (strncmp(command, "SETDWELLTIME PASSIVE MAX", 24) == 0)
3325 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303326 if (hdd_drv_cmd_validate(command, 24))
3327 return -EINVAL;
3328
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303329 value = value + 25;
3330 temp = kstrtou32(value, 10, &val);
3331 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_MIN ||
3332 val > CFG_PASSIVE_MAX_CHANNEL_TIME_MAX )
3333 {
3334 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3335 "%s: argument passed for SETDWELLTIME PASSIVE MAX is incorrect", __func__);
3336 ret = -EFAULT;
3337 return ret;
3338 }
3339 pCfg->nPassiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303340 smeConfig.csrConfig.nPassiveMaxChnTime = val;
3341 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303342 }
3343 else if (strncmp(command, "SETDWELLTIME PASSIVE MIN", 24) == 0)
3344 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303345 if (hdd_drv_cmd_validate(command, 24))
3346 return -EINVAL;
3347
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303348 value = value + 25;
3349 temp = kstrtou32(value, 10, &val);
3350 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_MIN ||
3351 val > CFG_PASSIVE_MIN_CHANNEL_TIME_MAX )
3352 {
3353 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3354 "%s: argument passed for SETDWELLTIME PASSIVE MIN is incorrect", __func__);
3355 ret = -EFAULT;
3356 return ret;
3357 }
3358 pCfg->nPassiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303359 smeConfig.csrConfig.nPassiveMinChnTime = val;
3360 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303361 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05303362 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
3363 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303364 if (hdd_drv_cmd_validate(command, 12))
3365 return -EINVAL;
3366
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05303367 value = value + 13;
3368 temp = kstrtou32(value, 10, &val);
3369 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
3370 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
3371 {
3372 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3373 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
3374 ret = -EFAULT;
3375 return ret;
3376 }
3377 pCfg->nActiveMaxChnTime = val;
3378 smeConfig.csrConfig.nActiveMaxChnTime = val;
3379 sme_UpdateConfig(hHal, &smeConfig);
3380 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303381 else
3382 {
3383 ret = -EINVAL;
3384 }
3385
3386 return ret;
3387}
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303388static int hdd_cmd_setFccChannel(hdd_context_t *pHddCtx, tANI_U8 *cmd,
3389 tANI_U8 cmd_len)
3390{
3391 tANI_U8 *value;
3392 tANI_U8 fcc_constraint;
3393
3394 eHalStatus status;
3395 int ret = 0;
3396 value = cmd + cmd_len + 1;
3397
3398 ret = kstrtou8(value, 10, &fcc_constraint);
3399 if ((ret < 0) || (fcc_constraint > 1)) {
3400 /*
3401 * If the input value is greater than max value of datatype,
3402 * then also it is a failure
3403 */
3404 hddLog(VOS_TRACE_LEVEL_ERROR,
3405 "%s: value out of range", __func__);
3406 return -EINVAL;
3407 }
3408
Agrawal Ashish842eea82016-02-04 17:56:16 +05303409 status = sme_handleSetFccChannel(pHddCtx->hHal, fcc_constraint,
3410 pHddCtx->scan_info.mScanPending);
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303411 if (status != eHAL_STATUS_SUCCESS)
3412 ret = -EPERM;
3413
3414 return ret;
3415}
3416
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05303417/**---------------------------------------------------------------------------
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303418
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05303419 \brief hdd_enable_disable_ca_event() - When Host sends IOCTL (enabled),
3420 FW will send *ONE* CA ind to Host(even though it is duplicate).
3421 When Host send IOCTL (disable), FW doesn't perform any action.
3422 Whenever any change in CA *and* WLAN is in SAP/P2P-GO mode, FW
3423 sends CA ind to host. (regard less of IOCTL status)
3424 \param - pHddCtx - HDD context
3425 \param - command - command received from framework
3426 \param - cmd_len - len of the command
3427
3428 \return - 0 on success, appropriate error values on failure.
3429
3430 --------------------------------------------------------------------------*/
3431int hdd_enable_disable_ca_event(hdd_context_t *pHddCtx, tANI_U8* command, tANI_U8 cmd_len)
3432{
3433 tANI_U8 set_value;
3434 int ret = 0;
3435 eHalStatus status;
3436
3437 ret = wlan_hdd_validate_context(pHddCtx);
3438 if (0 != ret)
3439 {
3440 ret = -EINVAL;
3441 goto exit;
3442 }
3443
3444 if (pHddCtx->cfg_ini->gOptimizeCAevent == 0)
3445 {
3446 hddLog(VOS_TRACE_LEVEL_ERROR, "Enable gOptimizeCAevent"
3447 " ini param to control channel avooidance indication");
3448 ret = 0;
3449 goto exit;
3450 }
3451
3452 set_value = command[cmd_len + 1] - '0';
3453 status = sme_enableDisableChanAvoidIndEvent(pHddCtx->hHal, set_value);
3454 if (status != eHAL_STATUS_SUCCESS)
3455 {
3456 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to send"
3457 " enableDisableChanAoidance command to SME\n", __func__);
3458 ret = -EINVAL;
3459 }
3460
3461exit:
3462 return ret;
3463}
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303464
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303465/**
3466 * wlan_hdd_fastreassoc_handoff_request() - Post Handoff request to SME
3467 * @pHddCtx: Pointer to the HDD context
3468 * @channel: channel to reassociate
3469 * @targetApBssid: Target AP/BSSID to reassociate
3470 *
3471 * Return: None
3472 */
3473#if defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD) && !defined(QCA_WIFI_ISOC)
3474static void wlan_hdd_fastreassoc_handoff_request(hdd_context_t *pHddCtx,
3475 uint8_t channel, tSirMacAddr targetApBssid)
3476{
3477 tCsrHandoffRequest handoffInfo;
3478 handoffInfo.channel = channel;
3479 handoffInfo.src = FASTREASSOC;
3480 vos_mem_copy(handoffInfo.bssid, targetApBssid, sizeof(tSirMacAddr));
3481 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
3482}
3483#else
3484static void wlan_hdd_fastreassoc_handoff_request(hdd_context_t *pHddCtx,
3485 uint8_t channel, tSirMacAddr targetApBssid)
3486{
3487}
3488#endif
3489
3490/**
3491 * csr_fastroam_neighbor_ap_event() - Function to trigger scan/roam
3492 * @pAdapter: Pointer to HDD adapter
3493 * @channel: Channel to scan/roam
3494 * @targetApBssid: BSSID to roam
3495 *
3496 * Return: None
3497 */
3498#ifdef QCA_WIFI_ISOC
3499static void csr_fastroam_neighbor_ap_event(hdd_adapter_t *pAdapter,
3500 uint8_t channel, tSirMacAddr targetApBssid)
3501{
3502 smeIssueFastRoamNeighborAPEvent(WLAN_HDD_GET_HAL_CTX(pAdapter),
3503 &targetApBssid[0], eSME_ROAM_TRIGGER_SCAN, channel);
3504}
3505#else
3506static void csr_fastroam_neighbor_ap_event(hdd_adapter_t *pAdapter,
3507 uint8_t channel, tSirMacAddr targetApBssid)
3508{
3509}
3510#endif
3511
3512/**
3513 * wlan_hdd_handle_fastreassoc() - Handle fastreassoc command
3514 * @pAdapter: pointer to hdd adapter
3515 * @command: pointer to the command received
3516 *
3517 * Return: VOS_STATUS enum
3518 */
3519static VOS_STATUS wlan_hdd_handle_fastreassoc(hdd_adapter_t *pAdapter,
3520 uint8_t *command)
3521{
3522 tANI_U8 *value = command;
3523 tANI_U8 channel = 0;
3524 tSirMacAddr targetApBssid;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303525 hdd_station_ctx_t *pHddStaCtx = NULL;
3526 hdd_context_t *pHddCtx = NULL;
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05303527 int ret;
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303528 tCsrRoamModifyProfileFields mod_profile_fields;
3529 uint32_t roam_id = 0;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303530 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3531 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3532
3533 /* if not associated, no need to proceed with reassoc */
3534 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
3535 hddLog(LOG1, FL("Not associated!"));
3536 return eHAL_STATUS_FAILURE;
3537 }
3538
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05303539 ret = hdd_parse_reassoc_command_v1_data(value, targetApBssid, &channel);
3540 if (ret) {
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303541 hddLog(LOGE, FL("Failed to parse reassoc command data"));
3542 return eHAL_STATUS_FAILURE;
3543 }
3544
3545 /* if the target bssid is same as currently associated AP,
3546 then no need to proceed with reassoc */
3547 if (vos_mem_compare(targetApBssid,
3548 pHddStaCtx->conn_info.bssId,
3549 sizeof(tSirMacAddr))) {
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303550 sme_GetModifyProfileFields(pHddCtx->hHal, pAdapter->sessionId,
3551 &mod_profile_fields);
3552 sme_RoamReassoc(pHddCtx->hHal, pAdapter->sessionId, NULL,
3553 mod_profile_fields, &roam_id, 1);
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303554 hddLog(LOG1, FL("Reassoc BSSID is same as currently associated AP bssid"));
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303555 return eHAL_STATUS_SUCCESS;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303556 }
3557
3558 /* Check channel number is a valid channel number */
3559 if (VOS_STATUS_SUCCESS !=
3560 wlan_hdd_validate_operation_channel(pAdapter, channel)) {
3561 hddLog(LOGE, FL("Invalid Channel [%d]"), channel);
3562 return eHAL_STATUS_FAILURE;
3563 }
3564
3565 /* Proceed with reassoc */
3566 wlan_hdd_fastreassoc_handoff_request(pHddCtx, channel, targetApBssid);
3567
3568 /* Proceed with scan/roam */
3569 csr_fastroam_neighbor_ap_event(pAdapter, channel, targetApBssid);
3570
3571 return eHAL_STATUS_SUCCESS;
3572}
3573
3574/**
3575 * hdd_assign_reassoc_handoff - Set handoff source as REASSOC
3576 * @handoffInfo: Pointer to the csr Handoff Request.
3577 *
3578 * Return: None
3579 */
3580#ifndef QCA_WIFI_ISOC
3581static inline void hdd_assign_reassoc_handoff(tCsrHandoffRequest *handoffInfo)
3582{
3583 handoffInfo->src = REASSOC;
3584}
3585#else
3586static inline void hdd_assign_reassoc_handoff(tCsrHandoffRequest *handoffInfo)
3587{
3588}
3589#endif
3590
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303591/**
3592 * wlan_hdd_free_cache_channels() - Free the cache channels list
3593 * @hdd_ctx: Pointer to HDD context
3594 *
3595 * Return: None
3596 */
3597
3598static void wlan_hdd_free_cache_channels(hdd_context_t *hdd_ctx)
3599{
Ashish Kumar Dhanotiya19803832018-05-24 19:05:48 +05303600 if(!hdd_ctx || !hdd_ctx->original_channels)
3601 return;
3602
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303603 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303604 hdd_ctx->original_channels->num_channels = 0;
3605 vos_mem_free(hdd_ctx->original_channels->channel_info);
3606 hdd_ctx->original_channels->channel_info = NULL;
3607 vos_mem_free(hdd_ctx->original_channels);
3608 hdd_ctx->original_channels = NULL;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303609 mutex_unlock(&hdd_ctx->cache_channel_lock);
3610}
3611
3612/**
3613 * hdd_alloc_chan_cache() - Allocate the memory to cache the channel
3614 * info for the channels received in command SET_DISABLE_CHANNEL_LIST
3615 * @hdd_ctx: Pointer to HDD context
3616 * @num_chan: Number of channels for which memory needs to
3617 * be allocated
3618 *
3619 * Return: 0 on success and error code on failure
3620 */
3621
3622int hdd_alloc_chan_cache(hdd_context_t *hdd_ctx, int num_chan)
3623{
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303624 hdd_ctx->original_channels =
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303625 vos_mem_malloc(sizeof(struct hdd_cache_channels));
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303626 if (!hdd_ctx->original_channels) {
3627 hddLog(VOS_TRACE_LEVEL_ERROR,
3628 "In %s, VOS_MALLOC_ERR", __func__);
3629 return -EINVAL;
3630 }
3631 hdd_ctx->original_channels->num_channels = num_chan;
3632 hdd_ctx->original_channels->channel_info =
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303633 vos_mem_malloc(num_chan *
3634 sizeof(struct hdd_cache_channel_info));
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303635 if (!hdd_ctx->original_channels->channel_info) {
3636 hddLog(VOS_TRACE_LEVEL_ERROR,
3637 "In %s, VOS_MALLOC_ERR", __func__);
3638 hdd_ctx->original_channels->num_channels = 0;
3639 vos_mem_free(hdd_ctx->original_channels);
3640 hdd_ctx->original_channels = NULL;
3641 return -ENOMEM;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303642 }
3643 return 0;
3644
3645}
3646
3647
3648int hdd_parse_disable_chan_cmd(hdd_adapter_t *adapter, tANI_U8 *ptr)
3649{
3650 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
3651 hdd_context_t *hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, pvosGCtx);
3652 tANI_U8 *param;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303653 int j, tempInt, ret = 0, i, num_channels;
3654 int parsed_channels[MAX_CHANNEL];
3655 bool is_command_repeated = false;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303656
3657 if (NULL == pvosGCtx) {
3658 hddLog(VOS_TRACE_LEVEL_FATAL,
3659 "VOS Global Context is NULL");
3660 return -EINVAL;
3661 }
3662
3663 if (NULL == hdd_ctx) {
3664 hddLog(VOS_TRACE_LEVEL_FATAL, "HDD Context is NULL");
3665 return -EINVAL;
3666 }
3667
3668 param = strchr(ptr, ' ');
3669 /*no argument after the command*/
3670 if (NULL == param)
3671 return -EINVAL;
3672
3673 /*no space after the command*/
3674 else if (SPACE_ASCII_VALUE != *param)
3675 return -EINVAL;
3676
3677 param++;
3678
3679 /*removing empty spaces*/
3680 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3681 param++;
3682
3683 /*no argument followed by spaces*/
3684 if ('\0' == *param)
3685 return -EINVAL;
3686
3687 /*getting the first argument ie the number of channels*/
3688 if (sscanf(param, "%d ", &tempInt) != 1) {
3689 hddLog(VOS_TRACE_LEVEL_ERROR,
3690 "%s: Cannot get number of channels from input",
3691 __func__);
3692 return -EINVAL;
3693 }
3694
3695 if (tempInt < 0 || tempInt > MAX_CHANNEL) {
3696 hddLog(VOS_TRACE_LEVEL_ERROR,
3697 "%s: Invalid Number of channel received", __func__);
3698 return -EINVAL;
3699 }
3700
3701 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
3702 "%s: Number of channel to disable are: %d",
3703 __func__, tempInt);
3704
3705 if (!tempInt) {
3706 if (!wlan_hdd_restore_channels(hdd_ctx)) {
3707 /*
3708 * Free the cache channels only when the command is
3709 * received with num channels as 0
3710 */
3711 wlan_hdd_free_cache_channels(hdd_ctx);
3712 }
3713 return 0;
3714 }
3715
3716 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303717 if (!hdd_ctx->original_channels) {
3718 if (hdd_alloc_chan_cache(hdd_ctx, tempInt)) {
3719 ret = -ENOMEM;
3720 goto mem_alloc_failed;
3721 }
3722 } else if (hdd_ctx->original_channels->num_channels != tempInt) {
3723 hddLog(VOS_TRACE_LEVEL_ERROR,
3724 "%s, Invalid No of channel provided in the list",
3725 __func__);
3726 ret = -EINVAL;
3727 is_command_repeated = true;
3728 goto parse_failed;
3729 } else {
3730 is_command_repeated = true;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303731 }
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303732
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303733 num_channels = tempInt;
3734
3735 for (j = 0; j < num_channels; j++) {
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303736 /*
3737 * param pointing to the beginning of first space
3738 * after number of channels
3739 */
3740 param = strpbrk(param, " ");
3741 /*no channel list after the number of channels argument*/
3742 if (NULL == param) {
3743 hddLog(VOS_TRACE_LEVEL_ERROR,
3744 "%s, Invalid No of channel provided in the list",
3745 __func__);
3746 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303747 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303748 }
3749
3750 param++;
3751
3752 /*removing empty space*/
3753 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3754 param++;
3755
3756 if ('\0' == *param) {
3757 hddLog(VOS_TRACE_LEVEL_ERROR,
3758 "%s, No channel is provided in the list",
3759 __func__);
3760 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303761 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303762
3763 }
3764
3765 if (sscanf(param, "%d ", &tempInt) != 1) {
3766 hddLog(VOS_TRACE_LEVEL_ERROR,
3767 "%s: Cannot read channel number",
3768 __func__);
3769 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303770 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303771
3772 }
3773
3774 if (!IS_CHANNEL_VALID(tempInt)) {
3775 hddLog(VOS_TRACE_LEVEL_ERROR,
3776 "%s: Invalid channel number received",
3777 __func__);
3778 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303779 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303780
3781 }
3782
3783 hddLog(VOS_TRACE_LEVEL_INFO, "%s: channel[%d] = %d", __func__,
3784 j, tempInt);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303785
3786 parsed_channels[j] = tempInt;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303787 }
3788
3789 /*extra arguments check*/
3790 param = strchr(param, ' ');
3791 if (NULL != param) {
3792 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3793 param++;
3794
3795 if ('\0' != *param) {
3796 hddLog(VOS_TRACE_LEVEL_ERROR,
3797 "%s: Invalid argument received", __func__);
3798 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303799 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303800 }
3801 }
3802
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303803 /*
3804 * If command is received first time, cache the channels to
3805 * be disabled else compare the channels received in the
3806 * command with the cached channels, if channel list matches
3807 * return success otherewise return failure.
3808 */
3809 if (!is_command_repeated)
3810 for (j = 0; j < num_channels; j++)
3811 hdd_ctx->original_channels->
3812 channel_info[j].channel_num =
3813 parsed_channels[j];
3814 else {
3815 for (i = 0; i < num_channels; i++) {
3816 for (j = 0; j < num_channels; j++)
3817 if (hdd_ctx->original_channels->
3818 channel_info[i].channel_num ==
3819 parsed_channels[j])
3820 break;
3821 if (j == num_channels) {
3822 ret = -EINVAL;
3823 goto parse_failed;
3824 }
3825 }
3826 ret = 0;
3827 }
3828
3829mem_alloc_failed:
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303830 mutex_unlock(&hdd_ctx->cache_channel_lock);
3831 EXIT();
3832
3833 return ret;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303834
3835parse_failed:
3836 mutex_unlock(&hdd_ctx->cache_channel_lock);
3837 if (!is_command_repeated)
3838 wlan_hdd_free_cache_channels(hdd_ctx);
3839 EXIT();
3840 return ret;
3841
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303842}
3843
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303844int hdd_get_disable_ch_list(hdd_context_t *hdd_ctx, tANI_U8 *buf,
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303845 uint32_t buf_len)
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303846{
3847 struct hdd_cache_channel_info *ch_list;
3848 unsigned char i, num_ch;
3849 int len = 0;
3850
3851 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303852 if (hdd_ctx->original_channels &&
3853 hdd_ctx->original_channels->num_channels &&
3854 hdd_ctx->original_channels->channel_info) {
3855 num_ch = hdd_ctx->original_channels->num_channels;
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303856
3857 len = scnprintf(buf, buf_len, "%s %hhu",
3858 "GET_DISABLE_CHANNEL_LIST", num_ch);
3859
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303860 ch_list = hdd_ctx->original_channels->channel_info;
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303861
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303862 for (i = 0; (i < num_ch) && (len < buf_len-1); i++) {
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303863 len += scnprintf(buf + len, buf_len - len,
3864 " %d", ch_list[i].channel_num);
3865 }
3866 }
3867 mutex_unlock(&hdd_ctx->cache_channel_lock);
3868
3869 return len;
3870}
3871
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003872static int hdd_driver_command(hdd_adapter_t *pAdapter,
3873 hdd_priv_data_t *ppriv_data)
Jeff Johnson295189b2012-06-20 16:38:30 -07003874{
Jeff Johnson295189b2012-06-20 16:38:30 -07003875 hdd_priv_data_t priv_data;
3876 tANI_U8 *command = NULL;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303877 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3878 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003879 int ret = 0;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303880 int status;
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05303881#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
3882 struct cfg80211_mgmt_tx_params params;
3883#endif
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303884
3885 ENTER();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003886 /*
3887 * Note that valid pointers are provided by caller
3888 */
Jeff Johnson295189b2012-06-20 16:38:30 -07003889
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003890 /* copy to local struct to avoid numerous changes to legacy code */
3891 priv_data = *ppriv_data;
Jeff Johnson295189b2012-06-20 16:38:30 -07003892
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003893 if (priv_data.total_len <= 0 ||
3894 priv_data.total_len > WLAN_PRIV_DATA_MAX_LEN)
Sameer Thalappil8ef3a0e2013-04-05 14:36:04 -07003895 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003896 hddLog(VOS_TRACE_LEVEL_WARN,
3897 "%s:invalid priv_data.total_len(%d)!!!", __func__,
3898 priv_data.total_len);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003899 ret = -EINVAL;
3900 goto exit;
3901 }
Kaushik, Sushant96122442014-10-21 16:40:18 +05303902 status = wlan_hdd_validate_context(pHddCtx);
3903 if (0 != status)
3904 {
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303905 ret = -EINVAL;
3906 goto exit;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303907 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003908 /* Allocate +1 for '\0' */
3909 command = kmalloc(priv_data.total_len + 1, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07003910 if (!command)
3911 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003912 hddLog(VOS_TRACE_LEVEL_ERROR,
3913 "%s: failed to allocate memory", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003914 ret = -ENOMEM;
3915 goto exit;
3916 }
3917
3918 if (copy_from_user(command, priv_data.buf, priv_data.total_len))
3919 {
3920 ret = -EFAULT;
3921 goto exit;
3922 }
3923
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003924 /* Make sure the command is NUL-terminated */
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003925 command[priv_data.total_len] = '\0';
3926
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003927 /* at one time the following block of code was conditional. braces
3928 * have been retained to avoid re-indenting the legacy code
3929 */
Jeff Johnson295189b2012-06-20 16:38:30 -07003930 {
3931 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
3932
3933 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07003934 "%s: Received %s cmd from Wi-Fi GUI***", __func__, command);
Jeff Johnson295189b2012-06-20 16:38:30 -07003935
3936 if (strncmp(command, "P2P_DEV_ADDR", 12) == 0 )
3937 {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303938 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3939 TRACE_CODE_HDD_P2P_DEV_ADDR_IOCTL,
3940 pAdapter->sessionId, (unsigned)
3941 (*(pHddCtx->p2pDeviceAddress.bytes+2)<<24 |
3942 *(pHddCtx->p2pDeviceAddress.bytes+3)<<16 |
3943 *(pHddCtx->p2pDeviceAddress.bytes+4)<<8 |
3944 *(pHddCtx->p2pDeviceAddress.bytes+5))));
Jeff Johnson295189b2012-06-20 16:38:30 -07003945 if (copy_to_user(priv_data.buf, pHddCtx->p2pDeviceAddress.bytes,
3946 sizeof(tSirMacAddr)))
3947 {
3948 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08003949 "%s: failed to copy data to user buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003950 ret = -EFAULT;
3951 }
3952 }
Amar Singhal0974e402013-02-12 14:27:46 -08003953 else if(strncmp(command, "SETBAND", 7) == 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07003954 {
Amar Singhal0974e402013-02-12 14:27:46 -08003955 tANI_U8 *ptr = command ;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003956
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303957 ret = hdd_drv_cmd_validate(command, 7);
3958 if (ret)
3959 goto exit;
3960
Jeff Johnson295189b2012-06-20 16:38:30 -07003961 /* Change band request received */
Srinivas Girigowdade697412013-02-14 16:31:48 -08003962
3963 /* First 8 bytes will have "SETBAND " and
Jeff Johnson295189b2012-06-20 16:38:30 -07003964 * 9 byte will have band setting value */
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07003965 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Amar Singhal0974e402013-02-12 14:27:46 -08003966 "%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 +05303967 if(VOS_FTM_MODE != hdd_get_conparam())
3968 {
3969 /* Change band request received */
3970 ret = hdd_setBand_helper(pAdapter->dev, ptr);
3971 if(ret < 0)
3972 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3973 "%s: failed to set band ret=%d", __func__, ret);
3974 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08003975 }
Kiet Lamf040f472013-11-20 21:15:23 +05303976 else if(strncmp(command, "SETWMMPS", 8) == 0)
3977 {
3978 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303979
3980 ret = hdd_drv_cmd_validate(command, 8);
3981 if (ret)
3982 goto exit;
3983
Kiet Lamf040f472013-11-20 21:15:23 +05303984 ret = hdd_wmmps_helper(pAdapter, ptr);
3985 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05303986
3987 else if(strncmp(command, "TDLSSCAN", 8) == 0)
3988 {
3989 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303990
3991 ret = hdd_drv_cmd_validate(command, 8);
3992 if (ret)
3993 goto exit;
3994
Agarwal Ashishef54a182014-12-16 15:07:31 +05303995 ret = hdd_set_tdls_scan_type(pAdapter, ptr);
3996 }
3997
Jeff Johnson32d95a32012-09-10 13:15:23 -07003998 else if ( strncasecmp(command, "COUNTRY", 7) == 0 )
3999 {
4000 char *country_code;
4001
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304002 ret = hdd_drv_cmd_validate(command, 7);
4003 if (ret)
4004 goto exit;
4005
Jeff Johnson32d95a32012-09-10 13:15:23 -07004006 country_code = command + 8;
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07004007
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004008 INIT_COMPLETION(pAdapter->change_country_code);
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07004009 hdd_checkandupdate_dfssetting(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07004010#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +05304011 hdd_checkandupdate_phymode(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07004012#endif
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004013 ret = (int)sme_ChangeCountryCode(pHddCtx->hHal,
4014 (void *)(tSmeChangeCountryCallback)
4015 wlan_hdd_change_country_code_callback,
Abhishek Singha306a442013-11-07 18:39:01 +05304016 country_code, pAdapter, pHddCtx->pvosContext, eSIR_TRUE, eSIR_TRUE);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004017 if (eHAL_STATUS_SUCCESS == ret)
4018 {
4019 ret = wait_for_completion_interruptible_timeout(
4020 &pAdapter->change_country_code,
4021 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
4022 if (0 >= ret)
4023 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004024 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: SME while setting country code timed out %d",
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304025 __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004026 }
4027 }
4028 else
Jeff Johnson32d95a32012-09-10 13:15:23 -07004029 {
4030 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004031 "%s: SME Change Country code fail ret=%d", __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004032 ret = -EINVAL;
Jeff Johnson32d95a32012-09-10 13:15:23 -07004033 }
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004034
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004035 }
4036 /*
4037 command should be a string having format
4038 SET_SAP_CHANNEL_LIST <num of channels> <the channels seperated by spaces>
4039 */
Amar Singhal0974e402013-02-12 14:27:46 -08004040 else if(strncmp(command, "SET_SAP_CHANNEL_LIST", 20) == 0)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004041 {
Amar Singhal0974e402013-02-12 14:27:46 -08004042 tANI_U8 *ptr = command;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004043
4044 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004045 " Received Command to Set Preferred Channels for SAP in %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004046
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -08004047 ret = sapSetPreferredChannel(ptr);
Jeff Johnson32d95a32012-09-10 13:15:23 -07004048 }
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +05304049
4050 else if (strncmp(command, "VOWIFIMODE", 10) == 0)
4051 {
4052 tANI_U8 *ptr;
4053
4054 ret = hdd_drv_cmd_validate(command, 10);
4055 if (ret)
4056 goto exit;
4057
4058 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4059 "Received Command for VOWIFI mode in %s", __func__);
4060
4061 ptr = (tANI_U8*)command + 11;
4062 hdd_set_vowifi_mode(pHddCtx, *ptr - '0');
4063 }
4064
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004065 else if(strncmp(command, "SETSUSPENDMODE", 14) == 0)
4066 {
4067 int suspend = 0;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304068 tANI_U8 *ptr;
4069
4070 ret = hdd_drv_cmd_validate(command, 14);
4071 if (ret)
4072 goto exit;
4073
4074 ptr = (tANI_U8*)command + 15;
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004075
4076 suspend = *ptr - '0';
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304077 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4078 TRACE_CODE_HDD_SETSUSPENDMODE_IOCTL,
4079 pAdapter->sessionId, suspend));
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004080 hdd_set_wlan_suspend_mode(suspend);
4081 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004082#ifdef WLAN_FEATURE_NEIGHBOR_ROAMING
4083 else if (strncmp(command, "SETROAMTRIGGER", 14) == 0)
4084 {
4085 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004086 tANI_S8 rssi = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004087 tANI_U8 lookUpThreshold = CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_DEFAULT;
4088 eHalStatus status = eHAL_STATUS_SUCCESS;
4089
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304090 ret = hdd_drv_cmd_validate(command, 14);
4091 if (ret)
4092 goto exit;
4093
Srinivas Girigowdade697412013-02-14 16:31:48 -08004094 /* Move pointer to ahead of SETROAMTRIGGER<delimiter> */
4095 value = value + 15;
4096
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004097 /* Convert the value from ascii to integer */
4098 ret = kstrtos8(value, 10, &rssi);
4099 if (ret < 0)
4100 {
4101 /* If the input value is greater than max value of datatype, then also
4102 kstrtou8 fails */
4103 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4104 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdafa7157d2013-10-31 10:14:22 -07004105 __func__,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004106 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
4107 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
4108 ret = -EINVAL;
4109 goto exit;
4110 }
4111
Srinivas Girigowdade697412013-02-14 16:31:48 -08004112 lookUpThreshold = abs(rssi);
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004113
Srinivas Girigowdade697412013-02-14 16:31:48 -08004114 if ((lookUpThreshold < CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN) ||
4115 (lookUpThreshold > CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX))
4116 {
4117 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4118 "Neighbor lookup threshold value %d is out of range"
4119 " (Min: %d Max: %d)", lookUpThreshold,
4120 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
4121 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
4122 ret = -EINVAL;
4123 goto exit;
4124 }
4125
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304126 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4127 TRACE_CODE_HDD_SETROAMTRIGGER_IOCTL,
4128 pAdapter->sessionId, lookUpThreshold));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004129 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4130 "%s: Received Command to Set Roam trigger"
4131 " (Neighbor lookup threshold) = %d", __func__, lookUpThreshold);
4132
4133 pHddCtx->cfg_ini->nNeighborLookupRssiThreshold = lookUpThreshold;
4134 status = sme_setNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold);
4135 if (eHAL_STATUS_SUCCESS != status)
4136 {
4137 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4138 "%s: Failed to set roam trigger, try again", __func__);
4139 ret = -EPERM;
4140 goto exit;
4141 }
4142
4143 /* Set Reassoc threshold to (lookup rssi threshold + 5 dBm) */
mukul sharmad6e1fdd2014-06-23 19:19:09 +05304144 pHddCtx->cfg_ini->nNeighborReassocRssiThreshold = lookUpThreshold + 5;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004145 sme_setNeighborReassocRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold + 5);
4146 }
4147 else if (strncmp(command, "GETROAMTRIGGER", 14) == 0)
4148 {
4149 tANI_U8 lookUpThreshold = sme_getNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal));
4150 int rssi = (-1) * lookUpThreshold;
4151 char extra[32];
4152 tANI_U8 len = 0;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304153 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4154 TRACE_CODE_HDD_GETROAMTRIGGER_IOCTL,
4155 pAdapter->sessionId, lookUpThreshold));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004156 len = scnprintf(extra, sizeof(extra), "%s %d", command, rssi);
Srinivas Girigowda91719232015-07-13 15:10:10 +05304157 len = VOS_MIN(priv_data.total_len, len + 1);
4158 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004159 {
4160 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4161 "%s: failed to copy data to user buffer", __func__);
4162 ret = -EFAULT;
4163 goto exit;
4164 }
4165 }
4166 else if (strncmp(command, "SETROAMSCANPERIOD", 17) == 0)
4167 {
4168 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004169 tANI_U8 roamScanPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004170 tANI_U16 neighborEmptyScanRefreshPeriod = CFG_EMPTY_SCAN_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004171
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304172 ret = hdd_drv_cmd_validate(command, 17);
4173 if (ret)
4174 goto exit;
4175
Srinivas Girigowdade697412013-02-14 16:31:48 -08004176 /* input refresh period is in terms of seconds */
4177 /* Move pointer to ahead of SETROAMSCANPERIOD<delimiter> */
4178 value = value + 18;
4179 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004180 ret = kstrtou8(value, 10, &roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004181 if (ret < 0)
4182 {
4183 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004184 kstrtou8 fails */
Srinivas Girigowdade697412013-02-14 16:31:48 -08004185 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004186 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdade697412013-02-14 16:31:48 -08004187 __func__,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07004188 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
4189 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004190 ret = -EINVAL;
4191 goto exit;
4192 }
4193
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004194 if ((roamScanPeriod < (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000)) ||
4195 (roamScanPeriod > (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000)))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004196 {
4197 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004198 "Roam scan period value %d is out of range"
4199 " (Min: %d Max: %d)", roamScanPeriod,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07004200 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
4201 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004202 ret = -EINVAL;
4203 goto exit;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304204 }
4205 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4206 TRACE_CODE_HDD_SETROAMSCANPERIOD_IOCTL,
4207 pAdapter->sessionId, roamScanPeriod));
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004208 neighborEmptyScanRefreshPeriod = roamScanPeriod * 1000;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004209
4210 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4211 "%s: Received Command to Set roam scan period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004212 " (Empty Scan refresh period) = %d", __func__, roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004213
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004214 pHddCtx->cfg_ini->nEmptyScanRefreshPeriod = neighborEmptyScanRefreshPeriod;
4215 sme_UpdateEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborEmptyScanRefreshPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004216 }
4217 else if (strncmp(command, "GETROAMSCANPERIOD", 17) == 0)
4218 {
4219 tANI_U16 nEmptyScanRefreshPeriod = sme_getEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
4220 char extra[32];
4221 tANI_U8 len = 0;
4222
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304223 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4224 TRACE_CODE_HDD_GETROAMSCANPERIOD_IOCTL,
4225 pAdapter->sessionId, nEmptyScanRefreshPeriod));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004226 len = scnprintf(extra, sizeof(extra), "%s %d",
4227 "GETROAMSCANPERIOD", (nEmptyScanRefreshPeriod/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004228 /* Returned value is in units of seconds */
Ratnam Rachuria72ba112015-07-17 13:27:03 +05304229 len = VOS_MIN(priv_data.total_len, len + 1);
4230 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004231 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4232 "%s: failed to copy data to user buffer", __func__);
4233 ret = -EFAULT;
4234 goto exit;
4235 }
4236 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004237 else if (strncmp(command, "SETROAMSCANREFRESHPERIOD", 24) == 0)
4238 {
4239 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004240 tANI_U8 roamScanRefreshPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004241 tANI_U16 neighborScanRefreshPeriod = CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004242
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304243 ret = hdd_drv_cmd_validate(command, 24);
4244 if (ret)
4245 goto exit;
4246
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004247 /* input refresh period is in terms of seconds */
4248 /* Move pointer to ahead of SETROAMSCANREFRESHPERIOD<delimiter> */
4249 value = value + 25;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004250
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004251 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004252 ret = kstrtou8(value, 10, &roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004253 if (ret < 0)
4254 {
4255 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004256 kstrtou8 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004257 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004258 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004259 __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004260 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
4261 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
4262 ret = -EINVAL;
4263 goto exit;
4264 }
4265
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004266 if ((roamScanRefreshPeriod < (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000)) ||
4267 (roamScanRefreshPeriod > (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000)))
4268 {
4269 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4270 "Neighbor scan results refresh period value %d is out of range"
4271 " (Min: %d Max: %d)", roamScanRefreshPeriod,
4272 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
4273 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
4274 ret = -EINVAL;
4275 goto exit;
4276 }
4277 neighborScanRefreshPeriod = roamScanRefreshPeriod * 1000;
4278
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004279 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4280 "%s: Received Command to Set roam scan refresh period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004281 " (Scan refresh period) = %d", __func__, roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004282
4283 pHddCtx->cfg_ini->nNeighborResultsRefreshPeriod = neighborScanRefreshPeriod;
4284 sme_setNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborScanRefreshPeriod);
4285 }
4286 else if (strncmp(command, "GETROAMSCANREFRESHPERIOD", 24) == 0)
4287 {
4288 tANI_U16 value = sme_getNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
4289 char extra[32];
4290 tANI_U8 len = 0;
4291
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004292 len = scnprintf(extra, sizeof(extra), "%s %d",
4293 "GETROAMSCANREFRESHPERIOD", (value/1000));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004294 /* Returned value is in units of seconds */
Ratnam Rachuri2c9d6702015-07-17 13:25:16 +05304295 len = VOS_MIN(priv_data.total_len, len + 1);
4296 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004297 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4298 "%s: failed to copy data to user buffer", __func__);
4299 ret = -EFAULT;
4300 goto exit;
4301 }
4302 }
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004303#ifdef FEATURE_WLAN_LFR
4304 /* SETROAMMODE */
4305 else if (strncmp(command, "SETROAMMODE", SIZE_OF_SETROAMMODE) == 0)
4306 {
4307 tANI_U8 *value = command;
4308 tANI_BOOLEAN roamMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
4309
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05304310 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
4311 hddLog(LOGE,
4312 FL("Roaming is always disabled in STA + MON concurrency"));
4313 ret = -EINVAL;
4314 goto exit;
4315 }
4316
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304317 ret = hdd_drv_cmd_validate(command, SIZE_OF_SETROAMMODE);
4318 if (ret)
4319 goto exit;
4320
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004321 /* Move pointer to ahead of SETROAMMODE<delimiter> */
4322 value = value + SIZE_OF_SETROAMMODE + 1;
4323
4324 /* Convert the value from ascii to integer */
4325 ret = kstrtou8(value, SIZE_OF_SETROAMMODE, &roamMode);
4326 if (ret < 0)
4327 {
4328 /* If the input value is greater than max value of datatype, then also
4329 kstrtou8 fails */
4330 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4331 "%s: kstrtou8 failed range [%d - %d]", __func__,
4332 CFG_LFR_FEATURE_ENABLED_MIN,
4333 CFG_LFR_FEATURE_ENABLED_MAX);
4334 ret = -EINVAL;
4335 goto exit;
4336 }
4337 if ((roamMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
4338 (roamMode > CFG_LFR_FEATURE_ENABLED_MAX))
4339 {
4340 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4341 "Roam Mode value %d is out of range"
4342 " (Min: %d Max: %d)", roamMode,
4343 CFG_LFR_FEATURE_ENABLED_MIN,
4344 CFG_LFR_FEATURE_ENABLED_MAX);
4345 ret = -EINVAL;
4346 goto exit;
4347 }
4348
4349 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4350 "%s: Received Command to Set Roam Mode = %d", __func__, roamMode);
4351 /*
4352 * Note that
4353 * SETROAMMODE 0 is to enable LFR while
4354 * SETROAMMODE 1 is to disable LFR, but
4355 * NotifyIsFastRoamIniFeatureEnabled 0/1 is to enable/disable.
4356 * So, we have to invert the value to call sme_UpdateIsFastRoamIniFeatureEnabled.
4357 */
4358 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
4359 roamMode = CFG_LFR_FEATURE_ENABLED_MAX; /* Roam enable */
4360 else
4361 roamMode = CFG_LFR_FEATURE_ENABLED_MIN; /* Roam disable */
4362
4363 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = roamMode;
4364 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), roamMode);
4365 }
4366 /* GETROAMMODE */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304367 else if (strncmp(command, "GETROAMMODE", SIZE_OF_GETROAMMODE) == 0)
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004368 {
4369 tANI_BOOLEAN roamMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4370 char extra[32];
4371 tANI_U8 len = 0;
4372
4373 /*
4374 * roamMode value shall be inverted because the sementics is different.
4375 */
4376 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
4377 roamMode = CFG_LFR_FEATURE_ENABLED_MAX;
4378 else
4379 roamMode = CFG_LFR_FEATURE_ENABLED_MIN;
4380
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004381 len = scnprintf(extra, sizeof(extra), "%s %d", command, roamMode);
Ratnam Rachuri28693eb2015-07-17 13:23:42 +05304382 len = VOS_MIN(priv_data.total_len, len + 1);
4383 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004384 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4385 "%s: failed to copy data to user buffer", __func__);
4386 ret = -EFAULT;
4387 goto exit;
4388 }
4389 }
4390#endif
Srinivas Girigowdade697412013-02-14 16:31:48 -08004391#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004392#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004393 else if (strncmp(command, "SETROAMDELTA", 12) == 0)
4394 {
4395 tANI_U8 *value = command;
4396 tANI_U8 roamRssiDiff = CFG_ROAM_RSSI_DIFF_DEFAULT;
4397
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304398 ret = hdd_drv_cmd_validate(command, 12);
4399 if (ret)
4400 goto exit;
4401
Srinivas Girigowdade697412013-02-14 16:31:48 -08004402 /* Move pointer to ahead of SETROAMDELTA<delimiter> */
4403 value = value + 13;
4404 /* Convert the value from ascii to integer */
4405 ret = kstrtou8(value, 10, &roamRssiDiff);
4406 if (ret < 0)
4407 {
4408 /* If the input value is greater than max value of datatype, then also
4409 kstrtou8 fails */
4410 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4411 "%s: kstrtou8 failed range [%d - %d]", __func__,
4412 CFG_ROAM_RSSI_DIFF_MIN,
4413 CFG_ROAM_RSSI_DIFF_MAX);
4414 ret = -EINVAL;
4415 goto exit;
4416 }
4417
4418 if ((roamRssiDiff < CFG_ROAM_RSSI_DIFF_MIN) ||
4419 (roamRssiDiff > CFG_ROAM_RSSI_DIFF_MAX))
4420 {
4421 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4422 "Roam rssi diff value %d is out of range"
4423 " (Min: %d Max: %d)", roamRssiDiff,
4424 CFG_ROAM_RSSI_DIFF_MIN,
4425 CFG_ROAM_RSSI_DIFF_MAX);
4426 ret = -EINVAL;
4427 goto exit;
4428 }
4429
4430 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4431 "%s: Received Command to Set roam rssi diff = %d", __func__, roamRssiDiff);
4432
4433 pHddCtx->cfg_ini->RoamRssiDiff = roamRssiDiff;
4434 sme_UpdateRoamRssiDiff((tHalHandle)(pHddCtx->hHal), roamRssiDiff);
4435 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304436 else if (strncmp(command, "GETROAMDELTA", 12) == 0)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004437 {
4438 tANI_U8 roamRssiDiff = sme_getRoamRssiDiff((tHalHandle)(pHddCtx->hHal));
4439 char extra[32];
4440 tANI_U8 len = 0;
4441
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304442 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4443 TRACE_CODE_HDD_GETROAMDELTA_IOCTL,
4444 pAdapter->sessionId, roamRssiDiff));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004445 len = scnprintf(extra, sizeof(extra), "%s %d",
4446 command, roamRssiDiff);
Ratnam Rachuri22a3b402015-07-17 13:21:49 +05304447 len = VOS_MIN(priv_data.total_len, len + 1);
4448 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004449 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4450 "%s: failed to copy data to user buffer", __func__);
4451 ret = -EFAULT;
4452 goto exit;
4453 }
4454 }
4455#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004456#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004457 else if (strncmp(command, "GETBAND", 7) == 0)
4458 {
4459 int band = -1;
4460 char extra[32];
4461 tANI_U8 len = 0;
4462 hdd_getBand_helper(pHddCtx, &band);
4463
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304464 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4465 TRACE_CODE_HDD_GETBAND_IOCTL,
4466 pAdapter->sessionId, band));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004467 len = scnprintf(extra, sizeof(extra), "%s %d", command, band);
Ratnam Rachuri52139592015-07-17 13:17:29 +05304468 len = VOS_MIN(priv_data.total_len, len + 1);
4469 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004470 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4471 "%s: failed to copy data to user buffer", __func__);
4472 ret = -EFAULT;
4473 goto exit;
4474 }
4475 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004476 else if (strncmp(command, "SETROAMSCANCHANNELS", 19) == 0)
4477 {
4478 tANI_U8 *value = command;
4479 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
4480 tANI_U8 numChannels = 0;
4481 eHalStatus status = eHAL_STATUS_SUCCESS;
4482
4483 status = hdd_parse_channellist(value, ChannelList, &numChannels);
4484 if (eHAL_STATUS_SUCCESS != status)
4485 {
4486 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4487 "%s: Failed to parse channel list information", __func__);
4488 ret = -EINVAL;
4489 goto exit;
4490 }
4491
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304492 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4493 TRACE_CODE_HDD_SETROAMSCANCHANNELS_IOCTL,
4494 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004495 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
4496 {
4497 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4498 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
4499 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
4500 ret = -EINVAL;
4501 goto exit;
4502 }
4503 status = sme_ChangeRoamScanChannelList((tHalHandle)(pHddCtx->hHal), ChannelList,
4504 numChannels);
4505 if (eHAL_STATUS_SUCCESS != status)
4506 {
4507 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4508 "%s: Failed to update channel list information", __func__);
4509 ret = -EINVAL;
4510 goto exit;
4511 }
4512 }
4513 else if (strncmp(command, "GETROAMSCANCHANNELS", 19) == 0)
4514 {
4515 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
4516 tANI_U8 numChannels = 0;
Jeff Johnson51b67782013-04-05 12:35:41 -07004517 tANI_U8 j = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004518 char extra[128] = {0};
Jeff Johnson51b67782013-04-05 12:35:41 -07004519 int len;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004520
4521 if (eHAL_STATUS_SUCCESS != sme_getRoamScanChannelList( (tHalHandle)(pHddCtx->hHal),
4522 ChannelList, &numChannels ))
4523 {
4524 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4525 "%s: failed to get roam scan channel list", __func__);
4526 ret = -EFAULT;
4527 goto exit;
4528 }
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304529 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4530 TRACE_CODE_HDD_GETROAMSCANCHANNELS_IOCTL,
4531 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004532 /* output channel list is of the format
4533 [Number of roam scan channels][Channel1][Channel2]... */
4534 /* copy the number of channels in the 0th index */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004535 len = scnprintf(extra, sizeof(extra), "%s %d", command, numChannels);
Sushant Kaushika08ca192015-09-16 15:52:04 +05304536 for (j = 0; (j < numChannels) && len <= sizeof(extra); j++)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004537 {
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004538 len += scnprintf(extra + len, sizeof(extra) - len, " %d",
4539 ChannelList[j]);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004540 }
4541
Sushant Kaushikc9b8be52015-07-15 16:41:27 +05304542 len = VOS_MIN(priv_data.total_len, len + 1);
4543 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004544 {
4545 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4546 "%s: failed to copy data to user buffer", __func__);
4547 ret = -EFAULT;
4548 goto exit;
4549 }
4550 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004551 else if (strncmp(command, "GETCCXMODE", 10) == 0)
4552 {
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004553 tANI_BOOLEAN eseMode = sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004554 char extra[32];
4555 tANI_U8 len = 0;
4556
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004557 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004558 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004559 if (eseMode &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004560 hdd_is_okc_mode_enabled(pHddCtx) &&
4561 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4562 {
4563 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004564 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004565 " hence this operation is not permitted!", __func__);
4566 ret = -EPERM;
4567 goto exit;
4568 }
4569
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004570 len = scnprintf(extra, sizeof(extra), "%s %d",
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004571 "GETCCXMODE", eseMode);
Sushant Kaushikf8abd352015-07-15 16:37:49 +05304572 len = VOS_MIN(priv_data.total_len, len + 1);
4573 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004574 {
4575 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4576 "%s: failed to copy data to user buffer", __func__);
4577 ret = -EFAULT;
4578 goto exit;
4579 }
4580 }
4581 else if (strncmp(command, "GETOKCMODE", 10) == 0)
4582 {
4583 tANI_BOOLEAN okcMode = hdd_is_okc_mode_enabled(pHddCtx);
4584 char extra[32];
4585 tANI_U8 len = 0;
4586
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004587 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004588 then this operation is not permitted (return FAILURE) */
4589 if (okcMode &&
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004590 sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004591 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4592 {
4593 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004594 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004595 " hence this operation is not permitted!", __func__);
4596 ret = -EPERM;
4597 goto exit;
4598 }
4599
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004600 len = scnprintf(extra, sizeof(extra), "%s %d",
4601 "GETOKCMODE", okcMode);
Sushant Kaushikbc2fb5c2015-07-15 16:43:16 +05304602 len = VOS_MIN(priv_data.total_len, len + 1);
4603 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004604 {
4605 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4606 "%s: failed to copy data to user buffer", __func__);
4607 ret = -EFAULT;
4608 goto exit;
4609 }
4610 }
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004611 else if (strncmp(command, "GETFASTROAM", 11) == 0)
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004612 {
4613 tANI_BOOLEAN lfrMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4614 char extra[32];
4615 tANI_U8 len = 0;
4616
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004617 len = scnprintf(extra, sizeof(extra), "%s %d",
4618 "GETFASTROAM", lfrMode);
Sushant Kaushik4da7ec92015-07-15 16:39:32 +05304619 len = VOS_MIN(priv_data.total_len, len + 1);
4620 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004621 {
4622 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4623 "%s: failed to copy data to user buffer", __func__);
4624 ret = -EFAULT;
4625 goto exit;
4626 }
4627 }
4628 else if (strncmp(command, "GETFASTTRANSITION", 17) == 0)
4629 {
4630 tANI_BOOLEAN ft = sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4631 char extra[32];
4632 tANI_U8 len = 0;
4633
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004634 len = scnprintf(extra, sizeof(extra), "%s %d",
4635 "GETFASTTRANSITION", ft);
Sushant Kaushik231a4452015-07-15 16:23:56 +05304636 len = VOS_MIN(priv_data.total_len, len + 1);
4637 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004638 {
4639 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4640 "%s: failed to copy data to user buffer", __func__);
4641 ret = -EFAULT;
4642 goto exit;
4643 }
4644 }
4645 else if (strncmp(command, "SETROAMSCANCHANNELMINTIME", 25) == 0)
4646 {
4647 tANI_U8 *value = command;
4648 tANI_U8 minTime = CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_DEFAULT;
4649
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304650 ret = hdd_drv_cmd_validate(command, 25);
4651 if (ret)
4652 goto exit;
4653
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004654 /* Move pointer to ahead of SETROAMSCANCHANNELMINTIME<delimiter> */
4655 value = value + 26;
4656 /* Convert the value from ascii to integer */
4657 ret = kstrtou8(value, 10, &minTime);
4658 if (ret < 0)
4659 {
4660 /* If the input value is greater than max value of datatype, then also
4661 kstrtou8 fails */
4662 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4663 "%s: kstrtou8 failed range [%d - %d]", __func__,
4664 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
4665 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
4666 ret = -EINVAL;
4667 goto exit;
4668 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004669 if ((minTime < CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN) ||
4670 (minTime > CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX))
4671 {
4672 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4673 "scan min channel time value %d is out of range"
4674 " (Min: %d Max: %d)", minTime,
4675 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
4676 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
4677 ret = -EINVAL;
4678 goto exit;
4679 }
4680
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304681 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4682 TRACE_CODE_HDD_SETROAMSCANCHANNELMINTIME_IOCTL,
4683 pAdapter->sessionId, minTime));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004684 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4685 "%s: Received Command to change channel min time = %d", __func__, minTime);
4686
4687 pHddCtx->cfg_ini->nNeighborScanMinChanTime = minTime;
4688 sme_setNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal), minTime);
4689 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004690 else if (strncmp(command, "SENDACTIONFRAME", 15) == 0)
4691 {
4692 tANI_U8 *value = command;
4693 tANI_U8 channel = 0;
4694 tANI_U8 dwellTime = 0;
4695 tANI_U8 bufLen = 0;
4696 tANI_U8 *buf = NULL;
4697 tSirMacAddr targetApBssid;
4698 eHalStatus status = eHAL_STATUS_SUCCESS;
4699 struct ieee80211_channel chan;
4700 tANI_U8 finalLen = 0;
4701 tANI_U8 *finalBuf = NULL;
4702 tANI_U8 temp = 0;
4703 u64 cookie;
4704 hdd_station_ctx_t *pHddStaCtx = NULL;
4705 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4706
4707 /* if not associated, no need to send action frame */
4708 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
4709 {
4710 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
4711 ret = -EINVAL;
4712 goto exit;
4713 }
4714
4715 status = hdd_parse_send_action_frame_data(value, targetApBssid, &channel,
4716 &dwellTime, &buf, &bufLen);
4717 if (eHAL_STATUS_SUCCESS != status)
4718 {
4719 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4720 "%s: Failed to parse send action frame data", __func__);
4721 ret = -EINVAL;
4722 goto exit;
4723 }
4724
4725 /* if the target bssid is different from currently associated AP,
4726 then no need to send action frame */
4727 if (VOS_TRUE != vos_mem_compare(targetApBssid,
4728 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
4729 {
4730 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:STA is not associated to this AP!",__func__);
4731 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004732 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004733 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004734 goto exit;
4735 }
4736
4737 /* if the channel number is different from operating channel then
4738 no need to send action frame */
4739 if (channel != pHddStaCtx->conn_info.operationChannel)
4740 {
4741 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4742 "%s: channel(%d) is different from operating channel(%d)",
4743 __func__, channel, pHddStaCtx->conn_info.operationChannel);
4744 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004745 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004746 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004747 goto exit;
4748 }
4749 chan.center_freq = sme_ChnToFreq(channel);
4750
4751 finalLen = bufLen + 24;
4752 finalBuf = vos_mem_malloc(finalLen);
4753 if (NULL == finalBuf)
4754 {
4755 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:memory allocation failed",__func__);
4756 ret = -ENOMEM;
Jeff Johnson11c33152013-04-16 17:52:40 -07004757 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004758 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004759 goto exit;
4760 }
4761 vos_mem_zero(finalBuf, finalLen);
4762
4763 /* Fill subtype */
4764 temp = SIR_MAC_MGMT_ACTION << 4;
4765 vos_mem_copy(finalBuf + 0, &temp, sizeof(temp));
4766
4767 /* Fill type */
4768 temp = SIR_MAC_MGMT_FRAME;
4769 vos_mem_copy(finalBuf + 2, &temp, sizeof(temp));
4770
4771 /* Fill destination address (bssid of the AP) */
4772 vos_mem_copy(finalBuf + 4, targetApBssid, sizeof(targetApBssid));
4773
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07004774 /* Fill source address (STA mac address) */
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004775 vos_mem_copy(finalBuf + 10, pAdapter->macAddressCurrent.bytes, sizeof(pAdapter->macAddressCurrent.bytes));
4776
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07004777 /* Fill BSSID (AP mac address) */
4778 vos_mem_copy(finalBuf + 16, targetApBssid, sizeof(targetApBssid));
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004779
4780 /* Fill received buffer from 24th address */
4781 vos_mem_copy(finalBuf + 24, buf, bufLen);
4782
Jeff Johnson11c33152013-04-16 17:52:40 -07004783 /* done with the parsed buffer */
4784 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004785 buf = NULL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004786
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05304787#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
4788 params.chan = &chan;
4789 params.offchan = 0;
4790 params.wait = dwellTime;
4791 params.buf = finalBuf;
4792 params.len = finalLen;
4793 params.no_cck = 1;
4794 params.dont_wait_for_ack = 1;
4795 ret = wlan_hdd_mgmt_tx(NULL, &pAdapter->wdev, &params, &cookie);
4796#else
DARAM SUDHA39eede62014-02-12 11:16:40 +05304797 wlan_hdd_mgmt_tx( NULL,
Yue Maf49ba872013-08-19 12:04:25 -07004798#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4799 &(pAdapter->wdev),
4800#else
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004801 pAdapter->dev,
Yue Maf49ba872013-08-19 12:04:25 -07004802#endif
4803 &chan, 0,
4804#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
4805 NL80211_CHAN_HT20, 1,
4806#endif
4807 dwellTime, finalBuf, finalLen, 1,
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004808 1, &cookie );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05304809#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)*/
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004810 vos_mem_free(finalBuf);
4811 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004812 else if (strncmp(command, "GETROAMSCANCHANNELMINTIME", 25) == 0)
4813 {
4814 tANI_U16 val = sme_getNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal));
4815 char extra[32];
4816 tANI_U8 len = 0;
4817
4818 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004819 len = scnprintf(extra, sizeof(extra), "%s %d",
4820 "GETROAMSCANCHANNELMINTIME", val);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304821 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4822 TRACE_CODE_HDD_GETROAMSCANCHANNELMINTIME_IOCTL,
4823 pAdapter->sessionId, val));
Sushant Kaushikbb8c52c2015-07-15 16:36:23 +05304824 len = VOS_MIN(priv_data.total_len, len + 1);
4825 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004826 {
4827 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4828 "%s: failed to copy data to user buffer", __func__);
4829 ret = -EFAULT;
4830 goto exit;
4831 }
4832 }
4833 else if (strncmp(command, "SETSCANCHANNELTIME", 18) == 0)
4834 {
4835 tANI_U8 *value = command;
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004836 tANI_U16 maxTime = CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004837
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304838 ret = hdd_drv_cmd_validate(command, 18);
4839 if (ret)
4840 goto exit;
4841
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004842 /* Move pointer to ahead of SETSCANCHANNELTIME<delimiter> */
4843 value = value + 19;
4844 /* Convert the value from ascii to integer */
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004845 ret = kstrtou16(value, 10, &maxTime);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004846 if (ret < 0)
4847 {
4848 /* If the input value is greater than max value of datatype, then also
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004849 kstrtou16 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004850 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004851 "%s: kstrtou16 failed range [%d - %d]", __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004852 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
4853 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
4854 ret = -EINVAL;
4855 goto exit;
4856 }
4857
4858 if ((maxTime < CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN) ||
4859 (maxTime > CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX))
4860 {
4861 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4862 "lfr mode value %d is out of range"
4863 " (Min: %d Max: %d)", maxTime,
4864 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
4865 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
4866 ret = -EINVAL;
4867 goto exit;
4868 }
4869
4870 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4871 "%s: Received Command to change channel max time = %d", __func__, maxTime);
4872
4873 pHddCtx->cfg_ini->nNeighborScanMaxChanTime = maxTime;
4874 sme_setNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal), maxTime);
4875 }
4876 else if (strncmp(command, "GETSCANCHANNELTIME", 18) == 0)
4877 {
4878 tANI_U16 val = sme_getNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal));
4879 char extra[32];
4880 tANI_U8 len = 0;
4881
4882 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004883 len = scnprintf(extra, sizeof(extra), "%s %d",
4884 "GETSCANCHANNELTIME", val);
Ratheesh S Pacbfa932015-07-16 15:27:18 +05304885 len = VOS_MIN(priv_data.total_len, len + 1);
4886 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004887 {
4888 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4889 "%s: failed to copy data to user buffer", __func__);
4890 ret = -EFAULT;
4891 goto exit;
4892 }
4893 }
4894 else if (strncmp(command, "SETSCANHOMETIME", 15) == 0)
4895 {
4896 tANI_U8 *value = command;
4897 tANI_U16 val = CFG_NEIGHBOR_SCAN_TIMER_PERIOD_DEFAULT;
4898
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304899 ret = hdd_drv_cmd_validate(command, 15);
4900 if (ret)
4901 goto exit;
4902
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004903 /* Move pointer to ahead of SETSCANHOMETIME<delimiter> */
4904 value = value + 16;
4905 /* Convert the value from ascii to integer */
4906 ret = kstrtou16(value, 10, &val);
4907 if (ret < 0)
4908 {
4909 /* If the input value is greater than max value of datatype, then also
4910 kstrtou16 fails */
4911 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4912 "%s: kstrtou16 failed range [%d - %d]", __func__,
4913 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
4914 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
4915 ret = -EINVAL;
4916 goto exit;
4917 }
4918
4919 if ((val < CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN) ||
4920 (val > CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX))
4921 {
4922 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4923 "scan home time value %d is out of range"
4924 " (Min: %d Max: %d)", val,
4925 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
4926 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
4927 ret = -EINVAL;
4928 goto exit;
4929 }
4930
4931 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4932 "%s: Received Command to change scan home time = %d", __func__, val);
4933
4934 pHddCtx->cfg_ini->nNeighborScanPeriod = val;
4935 sme_setNeighborScanPeriod((tHalHandle)(pHddCtx->hHal), val);
4936 }
4937 else if (strncmp(command, "GETSCANHOMETIME", 15) == 0)
4938 {
4939 tANI_U16 val = sme_getNeighborScanPeriod((tHalHandle)(pHddCtx->hHal));
4940 char extra[32];
4941 tANI_U8 len = 0;
4942
4943 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004944 len = scnprintf(extra, sizeof(extra), "%s %d",
4945 "GETSCANHOMETIME", val);
Ratheesh S P728d7c62015-07-16 15:38:58 +05304946 len = VOS_MIN(priv_data.total_len, len + 1);
4947 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004948 {
4949 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4950 "%s: failed to copy data to user buffer", __func__);
4951 ret = -EFAULT;
4952 goto exit;
4953 }
4954 }
4955 else if (strncmp(command, "SETROAMINTRABAND", 16) == 0)
4956 {
4957 tANI_U8 *value = command;
4958 tANI_U8 val = CFG_ROAM_INTRA_BAND_DEFAULT;
4959
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304960 ret = hdd_drv_cmd_validate(command, 16);
4961 if (ret)
4962 goto exit;
4963
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004964 /* Move pointer to ahead of SETROAMINTRABAND<delimiter> */
4965 value = value + 17;
4966 /* Convert the value from ascii to integer */
4967 ret = kstrtou8(value, 10, &val);
4968 if (ret < 0)
4969 {
4970 /* If the input value is greater than max value of datatype, then also
4971 kstrtou8 fails */
4972 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4973 "%s: kstrtou8 failed range [%d - %d]", __func__,
4974 CFG_ROAM_INTRA_BAND_MIN,
4975 CFG_ROAM_INTRA_BAND_MAX);
4976 ret = -EINVAL;
4977 goto exit;
4978 }
4979
4980 if ((val < CFG_ROAM_INTRA_BAND_MIN) ||
4981 (val > CFG_ROAM_INTRA_BAND_MAX))
4982 {
4983 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4984 "intra band mode value %d is out of range"
4985 " (Min: %d Max: %d)", val,
4986 CFG_ROAM_INTRA_BAND_MIN,
4987 CFG_ROAM_INTRA_BAND_MAX);
4988 ret = -EINVAL;
4989 goto exit;
4990 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004991 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4992 "%s: Received Command to change intra band = %d", __func__, val);
4993
4994 pHddCtx->cfg_ini->nRoamIntraBand = val;
4995 sme_setRoamIntraBand((tHalHandle)(pHddCtx->hHal), val);
4996 }
4997 else if (strncmp(command, "GETROAMINTRABAND", 16) == 0)
4998 {
4999 tANI_U16 val = sme_getRoamIntraBand((tHalHandle)(pHddCtx->hHal));
5000 char extra[32];
5001 tANI_U8 len = 0;
5002
5003 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005004 len = scnprintf(extra, sizeof(extra), "%s %d",
5005 "GETROAMINTRABAND", val);
Ratheesh S P2dd2a3e2015-07-16 15:34:23 +05305006 len = VOS_MIN(priv_data.total_len, len + 1);
5007 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005008 {
5009 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5010 "%s: failed to copy data to user buffer", __func__);
5011 ret = -EFAULT;
5012 goto exit;
5013 }
5014 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005015 else if (strncmp(command, "SETSCANNPROBES", 14) == 0)
5016 {
5017 tANI_U8 *value = command;
5018 tANI_U8 nProbes = CFG_ROAM_SCAN_N_PROBES_DEFAULT;
5019
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305020 ret = hdd_drv_cmd_validate(command, 14);
5021 if (ret)
5022 goto exit;
5023
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005024 /* Move pointer to ahead of SETSCANNPROBES<delimiter> */
5025 value = value + 15;
5026 /* Convert the value from ascii to integer */
5027 ret = kstrtou8(value, 10, &nProbes);
5028 if (ret < 0)
5029 {
5030 /* If the input value is greater than max value of datatype, then also
5031 kstrtou8 fails */
5032 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5033 "%s: kstrtou8 failed range [%d - %d]", __func__,
5034 CFG_ROAM_SCAN_N_PROBES_MIN,
5035 CFG_ROAM_SCAN_N_PROBES_MAX);
5036 ret = -EINVAL;
5037 goto exit;
5038 }
5039
5040 if ((nProbes < CFG_ROAM_SCAN_N_PROBES_MIN) ||
5041 (nProbes > CFG_ROAM_SCAN_N_PROBES_MAX))
5042 {
5043 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5044 "NProbes value %d is out of range"
5045 " (Min: %d Max: %d)", nProbes,
5046 CFG_ROAM_SCAN_N_PROBES_MIN,
5047 CFG_ROAM_SCAN_N_PROBES_MAX);
5048 ret = -EINVAL;
5049 goto exit;
5050 }
5051
5052 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5053 "%s: Received Command to Set nProbes = %d", __func__, nProbes);
5054
5055 pHddCtx->cfg_ini->nProbes = nProbes;
5056 sme_UpdateRoamScanNProbes((tHalHandle)(pHddCtx->hHal), nProbes);
5057 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305058 else if (strncmp(command, "GETSCANNPROBES", 14) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005059 {
5060 tANI_U8 val = sme_getRoamScanNProbes((tHalHandle)(pHddCtx->hHal));
5061 char extra[32];
5062 tANI_U8 len = 0;
5063
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005064 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri6da525d2015-08-07 13:55:54 +05305065 len = VOS_MIN(priv_data.total_len, len + 1);
5066 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005067 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5068 "%s: failed to copy data to user buffer", __func__);
5069 ret = -EFAULT;
5070 goto exit;
5071 }
5072 }
5073 else if (strncmp(command, "SETSCANHOMEAWAYTIME", 19) == 0)
5074 {
5075 tANI_U8 *value = command;
5076 tANI_U16 homeAwayTime = CFG_ROAM_SCAN_HOME_AWAY_TIME_DEFAULT;
5077
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305078 ret = hdd_drv_cmd_validate(command, 19);
5079 if (ret)
5080 goto exit;
5081
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005082 /* Move pointer to ahead of SETSCANHOMEAWAYTIME<delimiter> */
5083 /* input value is in units of msec */
5084 value = value + 20;
5085 /* Convert the value from ascii to integer */
5086 ret = kstrtou16(value, 10, &homeAwayTime);
5087 if (ret < 0)
5088 {
5089 /* If the input value is greater than max value of datatype, then also
5090 kstrtou8 fails */
5091 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5092 "%s: kstrtou8 failed range [%d - %d]", __func__,
5093 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
5094 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
5095 ret = -EINVAL;
5096 goto exit;
5097 }
5098
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005099 if ((homeAwayTime < CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN) ||
5100 (homeAwayTime > CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX))
5101 {
5102 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5103 "homeAwayTime value %d is out of range"
5104 " (Min: %d Max: %d)", homeAwayTime,
5105 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
5106 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
5107 ret = -EINVAL;
5108 goto exit;
5109 }
5110
5111 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5112 "%s: Received Command to Set scan away time = %d", __func__, homeAwayTime);
Srinivas Girigowda6cf0b822013-06-27 14:00:20 -07005113 if (pHddCtx->cfg_ini->nRoamScanHomeAwayTime != homeAwayTime)
5114 {
5115 pHddCtx->cfg_ini->nRoamScanHomeAwayTime = homeAwayTime;
5116 sme_UpdateRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal), homeAwayTime, eANI_BOOLEAN_TRUE);
5117 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005118 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305119 else if (strncmp(command, "GETSCANHOMEAWAYTIME", 19) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005120 {
5121 tANI_U16 val = sme_getRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal));
5122 char extra[32];
5123 tANI_U8 len = 0;
5124
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005125 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri51a5ad12015-08-07 14:06:37 +05305126 len = VOS_MIN(priv_data.total_len, len + 1);
5127 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005128 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5129 "%s: failed to copy data to user buffer", __func__);
5130 ret = -EFAULT;
5131 goto exit;
5132 }
5133 }
5134 else if (strncmp(command, "REASSOC", 7) == 0)
5135 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305136 ret = hdd_drv_cmd_validate(command, 7);
5137 if (ret)
5138 goto exit;
5139
5140 ret = hdd_parse_reassoc(pAdapter, command, priv_data.total_len);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05305141 if (!ret)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005142 goto exit;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005143 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005144 else if (strncmp(command, "SETWESMODE", 10) == 0)
5145 {
5146 tANI_U8 *value = command;
5147 tANI_BOOLEAN wesMode = CFG_ENABLE_WES_MODE_NAME_DEFAULT;
5148
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305149 ret = hdd_drv_cmd_validate(command, 10);
5150 if (ret)
5151 goto exit;
5152
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005153 /* Move pointer to ahead of SETWESMODE<delimiter> */
5154 value = value + 11;
5155 /* Convert the value from ascii to integer */
5156 ret = kstrtou8(value, 10, &wesMode);
5157 if (ret < 0)
5158 {
5159 /* If the input value is greater than max value of datatype, then also
5160 kstrtou8 fails */
5161 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5162 "%s: kstrtou8 failed range [%d - %d]", __func__,
5163 CFG_ENABLE_WES_MODE_NAME_MIN,
5164 CFG_ENABLE_WES_MODE_NAME_MAX);
5165 ret = -EINVAL;
5166 goto exit;
5167 }
5168
5169 if ((wesMode < CFG_ENABLE_WES_MODE_NAME_MIN) ||
5170 (wesMode > CFG_ENABLE_WES_MODE_NAME_MAX))
5171 {
5172 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5173 "WES Mode value %d is out of range"
5174 " (Min: %d Max: %d)", wesMode,
5175 CFG_ENABLE_WES_MODE_NAME_MIN,
5176 CFG_ENABLE_WES_MODE_NAME_MAX);
5177 ret = -EINVAL;
5178 goto exit;
5179 }
5180 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5181 "%s: Received Command to Set WES Mode rssi diff = %d", __func__, wesMode);
5182
5183 pHddCtx->cfg_ini->isWESModeEnabled = wesMode;
5184 sme_UpdateWESMode((tHalHandle)(pHddCtx->hHal), wesMode);
5185 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305186 else if (strncmp(command, "GETWESMODE", 10) == 0)
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005187 {
5188 tANI_BOOLEAN wesMode = sme_GetWESMode((tHalHandle)(pHddCtx->hHal));
5189 char extra[32];
5190 tANI_U8 len = 0;
5191
Arif Hussain826d9412013-11-12 16:44:54 -08005192 len = scnprintf(extra, sizeof(extra), "%s %d", command, wesMode);
Ratnam Rachuri8fe90c62015-08-07 14:03:26 +05305193 len = VOS_MIN(priv_data.total_len, len + 1);
5194 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005195 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5196 "%s: failed to copy data to user buffer", __func__);
5197 ret = -EFAULT;
5198 goto exit;
5199 }
5200 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005201#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE || FEATURE_WLAN_LFR */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005202#ifdef FEATURE_WLAN_LFR
5203 else if (strncmp(command, "SETFASTROAM", 11) == 0)
5204 {
5205 tANI_U8 *value = command;
5206 tANI_U8 lfrMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
5207
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05305208 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
5209 hddLog(LOGE,
5210 FL("Roaming is always disabled in STA + MON concurrency"));
5211 ret = -EINVAL;
5212 goto exit;
5213 }
5214
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305215 ret = hdd_drv_cmd_validate(command, 11);
5216 if (ret)
5217 goto exit;
5218
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005219 /* Move pointer to ahead of SETFASTROAM<delimiter> */
5220 value = value + 12;
5221 /* Convert the value from ascii to integer */
5222 ret = kstrtou8(value, 10, &lfrMode);
5223 if (ret < 0)
5224 {
5225 /* If the input value is greater than max value of datatype, then also
5226 kstrtou8 fails */
5227 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5228 "%s: kstrtou8 failed range [%d - %d]", __func__,
5229 CFG_LFR_FEATURE_ENABLED_MIN,
5230 CFG_LFR_FEATURE_ENABLED_MAX);
5231 ret = -EINVAL;
5232 goto exit;
5233 }
5234
5235 if ((lfrMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
5236 (lfrMode > CFG_LFR_FEATURE_ENABLED_MAX))
5237 {
5238 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5239 "lfr mode value %d is out of range"
5240 " (Min: %d Max: %d)", lfrMode,
5241 CFG_LFR_FEATURE_ENABLED_MIN,
5242 CFG_LFR_FEATURE_ENABLED_MAX);
5243 ret = -EINVAL;
5244 goto exit;
5245 }
5246
5247 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5248 "%s: Received Command to change lfr mode = %d", __func__, lfrMode);
5249
5250 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = lfrMode;
5251 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), lfrMode);
5252 }
5253#endif
5254#ifdef WLAN_FEATURE_VOWIFI_11R
5255 else if (strncmp(command, "SETFASTTRANSITION", 17) == 0)
5256 {
5257 tANI_U8 *value = command;
5258 tANI_U8 ft = CFG_FAST_TRANSITION_ENABLED_NAME_DEFAULT;
5259
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305260 ret = hdd_drv_cmd_validate(command, 17);
5261 if (ret)
5262 goto exit;
5263
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005264 /* Move pointer to ahead of SETFASTROAM<delimiter> */
5265 value = value + 18;
5266 /* Convert the value from ascii to integer */
5267 ret = kstrtou8(value, 10, &ft);
5268 if (ret < 0)
5269 {
5270 /* If the input value is greater than max value of datatype, then also
5271 kstrtou8 fails */
5272 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5273 "%s: kstrtou8 failed range [%d - %d]", __func__,
5274 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
5275 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
5276 ret = -EINVAL;
5277 goto exit;
5278 }
5279
5280 if ((ft < CFG_FAST_TRANSITION_ENABLED_NAME_MIN) ||
5281 (ft > CFG_FAST_TRANSITION_ENABLED_NAME_MAX))
5282 {
5283 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5284 "ft mode value %d is out of range"
5285 " (Min: %d Max: %d)", ft,
5286 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
5287 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
5288 ret = -EINVAL;
5289 goto exit;
5290 }
5291
5292 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5293 "%s: Received Command to change ft mode = %d", __func__, ft);
5294
5295 pHddCtx->cfg_ini->isFastTransitionEnabled = ft;
5296 sme_UpdateFastTransitionEnabled((tHalHandle)(pHddCtx->hHal), ft);
5297 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305298 else if (strncmp(command, "SETDFSSCANMODE", 14) == 0)
5299 {
5300 tANI_U8 *value = command;
5301 tANI_U8 dfsScanMode = DFS_CHNL_SCAN_ENABLED_NORMAL;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305302
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305303 ret = hdd_drv_cmd_validate(command, 14);
5304 if (ret)
5305 goto exit;
5306
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305307 /* Move pointer to ahead of SETDFSSCANMODE<delimiter> */
5308 value = value + 15;
5309 /* Convert the value from ascii to integer */
5310 ret = kstrtou8(value, 10, &dfsScanMode);
5311 if (ret < 0)
5312 {
5313 /* If the input value is greater than max value of
5314 datatype, then also kstrtou8 fails
5315 */
5316 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5317 "%s: kstrtou8 failed range [%d - %d]", __func__,
5318 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
5319 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
5320 ret = -EINVAL;
5321 goto exit;
5322 }
5323
5324 if ((dfsScanMode < CFG_ENABLE_DFS_CHNL_SCAN_MIN) ||
5325 (dfsScanMode > CFG_ENABLE_DFS_CHNL_SCAN_MAX))
5326 {
5327 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5328 "dfsScanMode value %d is out of range"
5329 " (Min: %d Max: %d)", dfsScanMode,
5330 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
5331 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
5332 ret = -EINVAL;
5333 goto exit;
5334 }
5335 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5336 "%s: Received Command to Set DFS Scan Mode = %d",
5337 __func__, dfsScanMode);
5338
5339 ret = wlan_hdd_handle_dfs_chan_scan(pHddCtx, dfsScanMode);
5340 }
5341 else if (strncmp(command, "GETDFSSCANMODE", 14) == 0)
5342 {
5343 tANI_U8 dfsScanMode = sme_GetDFSScanMode(pHddCtx->hHal);
5344 char extra[32];
5345 tANI_U8 len = 0;
5346
5347 len = scnprintf(extra, sizeof(extra), "%s %d", command, dfsScanMode);
Ratheesh S P767224e2015-07-16 15:35:51 +05305348 len = VOS_MIN(priv_data.total_len, len + 1);
5349 if (copy_to_user(priv_data.buf, &extra, len))
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305350 {
5351 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5352 "%s: failed to copy data to user buffer", __func__);
5353 ret = -EFAULT;
5354 goto exit;
5355 }
5356 }
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305357 else if (strncmp(command, "FASTREASSOC", 11) == 0)
5358 {
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05305359 ret = wlan_hdd_handle_fastreassoc(pAdapter, command);
5360 if (!ret)
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305361 goto exit;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305362 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005363#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005364#ifdef FEATURE_WLAN_ESE
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005365 else if (strncmp(command, "SETCCXMODE", 10) == 0)
5366 {
5367 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005368 tANI_U8 eseMode = CFG_ESE_FEATURE_ENABLED_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005369
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305370 ret = hdd_drv_cmd_validate(command, 10);
5371 if (ret)
5372 goto exit;
5373
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005374 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005375 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005376 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005377 hdd_is_okc_mode_enabled(pHddCtx) &&
5378 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
5379 {
5380 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005381 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005382 " hence this operation is not permitted!", __func__);
5383 ret = -EPERM;
5384 goto exit;
5385 }
5386
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005387 /* Move pointer to ahead of SETCCXMODE<delimiter> */
5388 value = value + 11;
5389 /* Convert the value from ascii to integer */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005390 ret = kstrtou8(value, 10, &eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005391 if (ret < 0)
5392 {
5393 /* If the input value is greater than max value of datatype, then also
5394 kstrtou8 fails */
5395 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5396 "%s: kstrtou8 failed range [%d - %d]", __func__,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005397 CFG_ESE_FEATURE_ENABLED_MIN,
5398 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005399 ret = -EINVAL;
5400 goto exit;
5401 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005402 if ((eseMode < CFG_ESE_FEATURE_ENABLED_MIN) ||
5403 (eseMode > CFG_ESE_FEATURE_ENABLED_MAX))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005404 {
5405 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005406 "Ese mode value %d is out of range"
5407 " (Min: %d Max: %d)", eseMode,
5408 CFG_ESE_FEATURE_ENABLED_MIN,
5409 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005410 ret = -EINVAL;
5411 goto exit;
5412 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005413 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005414 "%s: Received Command to change ese mode = %d", __func__, eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005415
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005416 pHddCtx->cfg_ini->isEseIniFeatureEnabled = eseMode;
5417 sme_UpdateIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal), eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005418 }
5419#endif
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005420 else if (strncmp(command, "SETROAMSCANCONTROL", 18) == 0)
5421 {
5422 tANI_U8 *value = command;
5423 tANI_BOOLEAN roamScanControl = 0;
5424
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305425 ret = hdd_drv_cmd_validate(command, 18);
5426 if (ret)
5427 goto exit;
5428
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005429 /* Move pointer to ahead of SETROAMSCANCONTROL<delimiter> */
5430 value = value + 19;
5431 /* Convert the value from ascii to integer */
5432 ret = kstrtou8(value, 10, &roamScanControl);
5433 if (ret < 0)
5434 {
5435 /* If the input value is greater than max value of datatype, then also
5436 kstrtou8 fails */
5437 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5438 "%s: kstrtou8 failed ", __func__);
5439 ret = -EINVAL;
5440 goto exit;
5441 }
5442
5443 if (0 != roamScanControl)
5444 {
5445 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5446 "roam scan control invalid value = %d",
5447 roamScanControl);
5448 ret = -EINVAL;
5449 goto exit;
5450 }
5451 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5452 "%s: Received Command to Set roam scan control = %d", __func__, roamScanControl);
5453
5454 sme_SetRoamScanControl((tHalHandle)(pHddCtx->hHal), roamScanControl);
5455 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005456#ifdef FEATURE_WLAN_OKC
5457 else if (strncmp(command, "SETOKCMODE", 10) == 0)
5458 {
5459 tANI_U8 *value = command;
5460 tANI_U8 okcMode = CFG_OKC_FEATURE_ENABLED_DEFAULT;
5461
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305462 ret = hdd_drv_cmd_validate(command, 10);
5463 if (ret)
5464 goto exit;
5465
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005466 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005467 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005468 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005469 hdd_is_okc_mode_enabled(pHddCtx) &&
5470 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
5471 {
5472 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005473 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005474 " hence this operation is not permitted!", __func__);
5475 ret = -EPERM;
5476 goto exit;
5477 }
5478
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005479 /* Move pointer to ahead of SETOKCMODE<delimiter> */
5480 value = value + 11;
5481 /* Convert the value from ascii to integer */
5482 ret = kstrtou8(value, 10, &okcMode);
5483 if (ret < 0)
5484 {
5485 /* If the input value is greater than max value of datatype, then also
5486 kstrtou8 fails */
5487 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5488 "%s: kstrtou8 failed range [%d - %d]", __func__,
5489 CFG_OKC_FEATURE_ENABLED_MIN,
5490 CFG_OKC_FEATURE_ENABLED_MAX);
5491 ret = -EINVAL;
5492 goto exit;
5493 }
5494
5495 if ((okcMode < CFG_OKC_FEATURE_ENABLED_MIN) ||
5496 (okcMode > CFG_OKC_FEATURE_ENABLED_MAX))
5497 {
5498 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5499 "Okc mode value %d is out of range"
5500 " (Min: %d Max: %d)", okcMode,
5501 CFG_OKC_FEATURE_ENABLED_MIN,
5502 CFG_OKC_FEATURE_ENABLED_MAX);
5503 ret = -EINVAL;
5504 goto exit;
5505 }
5506
5507 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5508 "%s: Received Command to change okc mode = %d", __func__, okcMode);
5509
5510 pHddCtx->cfg_ini->isOkcIniFeatureEnabled = okcMode;
5511 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005512#endif /* FEATURE_WLAN_OKC */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305513 else if (strncmp(command, "GETROAMSCANCONTROL", 18) == 0)
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005514 {
5515 tANI_BOOLEAN roamScanControl = sme_GetRoamScanControl((tHalHandle)(pHddCtx->hHal));
5516 char extra[32];
5517 tANI_U8 len = 0;
5518
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005519 len = scnprintf(extra, sizeof(extra), "%s %d",
5520 command, roamScanControl);
Ratnam Rachuri083ada82015-08-07 14:01:05 +05305521 len = VOS_MIN(priv_data.total_len, len + 1);
5522 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005523 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5524 "%s: failed to copy data to user buffer", __func__);
5525 ret = -EFAULT;
5526 goto exit;
5527 }
5528 }
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05305529#ifdef WLAN_FEATURE_PACKET_FILTERING
5530 else if (strncmp(command, "ENABLE_PKTFILTER_IPV6", 21) == 0)
5531 {
5532 tANI_U8 filterType = 0;
5533 tANI_U8 *value = command;
5534
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305535 ret = hdd_drv_cmd_validate(command, 21);
5536 if (ret)
5537 goto exit;
5538
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05305539 /* Move pointer to ahead of ENABLE_PKTFILTER_IPV6<delimiter> */
5540 value = value + 22;
5541
5542 /* Convert the value from ascii to integer */
5543 ret = kstrtou8(value, 10, &filterType);
5544 if (ret < 0)
5545 {
5546 /* If the input value is greater than max value of datatype,
5547 * then also kstrtou8 fails
5548 */
5549 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5550 "%s: kstrtou8 failed range ", __func__);
5551 ret = -EINVAL;
5552 goto exit;
5553 }
5554
5555 if (filterType != 0 && filterType != 1)
5556 {
5557 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5558 "%s: Accepted Values are 0 and 1 ", __func__);
5559 ret = -EINVAL;
5560 goto exit;
5561 }
5562 wlan_hdd_setIPv6Filter(WLAN_HDD_GET_CTX(pAdapter), filterType,
5563 pAdapter->sessionId);
5564 }
5565#endif
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305566 else if (strncmp(command, "BTCOEXMODE", 10) == 0 )
5567 {
Kiet Lamad161252014-07-22 11:23:32 -07005568 char *dhcpPhase;
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05305569 int ret;
5570
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305571 ret = hdd_drv_cmd_validate(command, 10);
5572 if (ret)
5573 goto exit;
5574
Kiet Lamad161252014-07-22 11:23:32 -07005575 dhcpPhase = command + 11;
5576 if ('1' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305577 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05305578 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07005579 FL("send DHCP START indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05305580
5581 pHddCtx->btCoexModeSet = TRUE;
Kiet Lamad161252014-07-22 11:23:32 -07005582
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05305583 ret = wlan_hdd_scan_abort(pAdapter);
5584 if (ret < 0)
5585 {
5586 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5587 FL("failed to abort existing scan %d"), ret);
5588 }
5589
Kiet Lamad161252014-07-22 11:23:32 -07005590 sme_DHCPStartInd(pHddCtx->hHal, pAdapter->device_mode,
5591 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305592 }
Kiet Lamad161252014-07-22 11:23:32 -07005593 else if ('2' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305594 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05305595 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07005596 FL("send DHCP STOP indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05305597
5598 pHddCtx->btCoexModeSet = FALSE;
Kiet Lamad161252014-07-22 11:23:32 -07005599
5600 sme_DHCPStopInd(pHddCtx->hHal, pAdapter->device_mode,
5601 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305602 }
5603 }
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005604 else if (strncmp(command, "SCAN-ACTIVE", 11) == 0)
5605 {
Abhishek Singh58749d62016-02-03 15:27:20 +05305606 hddLog(LOG1,
5607 FL("making default scan to ACTIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05305608 pHddCtx->scan_info.scan_mode = eSIR_ACTIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005609 }
5610 else if (strncmp(command, "SCAN-PASSIVE", 12) == 0)
5611 {
Abhishek Singh58749d62016-02-03 15:27:20 +05305612 hddLog(LOG1,
5613 FL("making default scan to PASSIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05305614 pHddCtx->scan_info.scan_mode = eSIR_PASSIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005615 }
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305616 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
5617 {
5618 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5619 char extra[32];
5620 tANI_U8 len = 0;
5621
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05305622 memset(extra, 0, sizeof(extra));
5623 ret = hdd_get_dwell_time(pCfg, command, extra, sizeof(extra), &len);
Ratnam Rachuri12d5d462015-08-07 14:10:23 +05305624 len = VOS_MIN(priv_data.total_len, len + 1);
5625 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305626 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5627 "%s: failed to copy data to user buffer", __func__);
5628 ret = -EFAULT;
5629 goto exit;
5630 }
5631 ret = len;
5632 }
5633 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
5634 {
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05305635 ret = hdd_set_dwell_time(pAdapter, command);
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305636 }
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05305637 else if (strncmp(command, "BTCGETDWELLTIME", 15) == 0)
5638 {
5639 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5640 char extra[32];
5641 tANI_U8 len = 0;
5642
5643 if (hdd_drv_cmd_validate(command, 15)) {
5644 hddLog(LOGE, FL("Invalid driver command"));
5645 return -EINVAL;
5646 }
5647
5648 memset(extra, 0, sizeof(extra));
5649 ret = hdd_btc_get_dwell_time(pCfg, command, extra,
5650 sizeof(extra), &len);
5651 len = VOS_MIN(priv_data.total_len, len + 1);
5652 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
5653 hddLog(LOGE, FL("Failed to copy data to user buffer"));
5654 ret = -EFAULT;
5655 goto exit;
5656 }
5657 ret = len;
5658 }
5659 else if (strncmp(command, "BTCSETDWELLTIME", 15) == 0)
5660 {
5661 if (hdd_drv_cmd_validate(command, 15)) {
5662 hddLog(LOGE, FL("Invalid driver command"));
5663 return -EINVAL;
5664 }
5665 ret = hdd_btc_set_dwell_time(pAdapter, command);
5666 }
5667#ifdef WLAN_AP_STA_CONCURRENCY
5668 else if (strncmp(command, "CONCGETDWELLTIME", 16) == 0)
5669 {
5670 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5671 char extra[32];
5672 tANI_U8 len = 0;
5673
5674 if (hdd_drv_cmd_validate(command, 16)) {
5675 hddLog(LOGE, FL("Invalid driver command"));
5676 return -EINVAL;
5677 }
5678
5679 memset(extra, 0, sizeof(extra));
5680 ret = hdd_conc_get_dwell_time(pCfg, command, extra,
5681 sizeof(extra), &len);
5682 len = VOS_MIN(priv_data.total_len, len + 1);
5683 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
5684 hddLog(LOGE, FL("Failed to copy data to user buffer"));
5685 ret = -EFAULT;
5686 goto exit;
5687 }
5688 ret = len;
5689 }
5690 else if (strncmp(command, "CONCSETDWELLTIME", 16) == 0)
5691 {
5692 if (hdd_drv_cmd_validate(command, 16)) {
5693 hddLog(LOGE, FL("Invalid driver command"));
5694 return -EINVAL;
5695 }
5696 ret = hdd_conc_set_dwell_time(pAdapter, command);
5697 }
5698#endif
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005699 else if ( strncasecmp(command, "MIRACAST", 8) == 0 )
5700 {
5701 tANI_U8 filterType = 0;
5702 tANI_U8 *value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305703
5704 ret = hdd_drv_cmd_validate(command, 8);
5705 if (ret)
5706 goto exit;
5707
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005708 value = command + 9;
5709
5710 /* Convert the value from ascii to integer */
5711 ret = kstrtou8(value, 10, &filterType);
5712 if (ret < 0)
5713 {
5714 /* If the input value is greater than max value of datatype,
5715 * then also kstrtou8 fails
5716 */
5717 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5718 "%s: kstrtou8 failed range ", __func__);
5719 ret = -EINVAL;
5720 goto exit;
5721 }
5722 if ((filterType < WLAN_HDD_DRIVER_MIRACAST_CFG_MIN_VAL ) ||
5723 (filterType > WLAN_HDD_DRIVER_MIRACAST_CFG_MAX_VAL))
5724 {
5725 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5726 "%s: Accepted Values are 0 to 2. 0-Disabled, 1-Source,"
5727 " 2-Sink ", __func__);
5728 ret = -EINVAL;
5729 goto exit;
5730 }
5731 //Filtertype value should be either 0-Disabled, 1-Source, 2-sink
5732 pHddCtx->drvr_miracast = filterType;
Kaushik, Sushant96122442014-10-21 16:40:18 +05305733 pScanInfo = &pHddCtx->scan_info;
5734 if (filterType && pScanInfo != NULL &&
5735 pHddCtx->scan_info.mScanPending)
5736 {
5737 /*Miracast Session started. Abort Scan */
5738 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5739 "%s, Aborting Scan For Miracast",__func__);
5740 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
5741 eCSR_SCAN_ABORT_DEFAULT);
5742 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005743 hdd_tx_rx_pkt_cnt_stat_timer_handler(pHddCtx);
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05305744 sme_SetMiracastMode(pHddCtx->hHal, pHddCtx->drvr_miracast);
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005745 }
Leo Chang614d2072013-08-22 14:59:44 -07005746 else if (strncmp(command, "SETMCRATE", 9) == 0)
5747 {
Leo Chang614d2072013-08-22 14:59:44 -07005748 tANI_U8 *value = command;
5749 int targetRate;
Leo Chang1f98cbd2013-10-17 15:03:52 -07005750 tSirRateUpdateInd *rateUpdate;
5751 eHalStatus status;
Leo Chang614d2072013-08-22 14:59:44 -07005752
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305753 ret = hdd_drv_cmd_validate(command, 9);
5754 if (ret)
5755 goto exit;
5756
Leo Chang614d2072013-08-22 14:59:44 -07005757 /* Only valid for SAP mode */
5758 if (WLAN_HDD_SOFTAP != pAdapter->device_mode)
5759 {
5760 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5761 "%s: SAP mode is not running", __func__);
5762 ret = -EFAULT;
5763 goto exit;
5764 }
5765
5766 /* Move pointer to ahead of SETMCRATE<delimiter> */
5767 /* input value is in units of hundred kbps */
5768 value = value + 10;
5769 /* Convert the value from ascii to integer, decimal base */
5770 ret = kstrtouint(value, 10, &targetRate);
5771
Leo Chang1f98cbd2013-10-17 15:03:52 -07005772 rateUpdate = (tSirRateUpdateInd *)vos_mem_malloc(sizeof(tSirRateUpdateInd));
5773 if (NULL == rateUpdate)
Leo Chang614d2072013-08-22 14:59:44 -07005774 {
Leo Chang1f98cbd2013-10-17 15:03:52 -07005775 hddLog(VOS_TRACE_LEVEL_ERROR,
5776 "%s: SETMCRATE indication alloc fail", __func__);
5777 ret = -EFAULT;
5778 goto exit;
5779 }
5780 vos_mem_zero(rateUpdate, sizeof(tSirRateUpdateInd ));
5781
5782 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5783 "MC Target rate %d", targetRate);
5784 /* Ignore unicast */
5785 rateUpdate->ucastDataRate = -1;
5786 rateUpdate->mcastDataRate24GHz = targetRate;
5787 rateUpdate->mcastDataRate5GHz = targetRate;
5788 rateUpdate->mcastDataRate24GHzTxFlag = 0;
5789 rateUpdate->mcastDataRate5GHzTxFlag = 0;
5790 status = sme_SendRateUpdateInd(pHddCtx->hHal, rateUpdate);
5791 if (eHAL_STATUS_SUCCESS != status)
5792 {
5793 hddLog(VOS_TRACE_LEVEL_ERROR,
5794 "%s: SET_MC_RATE failed", __func__);
5795 vos_mem_free(rateUpdate);
5796 ret = -EFAULT;
5797 goto exit;
Leo Chang614d2072013-08-22 14:59:44 -07005798 }
5799 }
jge35567202017-06-21 16:39:38 +08005800 else if (strncmp(command, "MAXTXPOWER", 10) == 0)
5801 {
5802 int status;
5803 int txPower;
5804 eHalStatus smeStatus;
5805 tANI_U8 *value = command;
5806 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
5807 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
5808
5809 status = hdd_parse_setmaxtxpower_command(value, &txPower);
5810 if (status)
5811 {
5812 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5813 "Invalid MAXTXPOWER command ");
5814 ret = -EINVAL;
5815 goto exit;
5816 }
5817
5818 hddLog(VOS_TRACE_LEVEL_INFO, "max tx power %d selfMac: "
5819 MAC_ADDRESS_STR " bssId: " MAC_ADDRESS_STR " ",
5820 txPower, MAC_ADDR_ARRAY(selfMac),
5821 MAC_ADDR_ARRAY(bssid));
5822 smeStatus = sme_SetMaxTxPower((tHalHandle)(pHddCtx->hHal),
5823 bssid, selfMac, txPower) ;
5824 if( smeStatus != eHAL_STATUS_SUCCESS )
5825 {
5826 hddLog(VOS_TRACE_LEVEL_ERROR, "%s:Set max tx power failed",
5827 __func__);
5828 ret = -EINVAL;
5829 goto exit;
5830 }
5831
5832 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Set max tx power success",
5833 __func__);
5834 }
Rajeev79dbe4c2013-10-05 11:03:42 +05305835#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev Kumar8b373292014-01-08 20:36:55 -08005836 else if (strncmp(command, "WLS_BATCHING", 12) == 0)
Rajeev79dbe4c2013-10-05 11:03:42 +05305837 {
Rajeev Kumar8b373292014-01-08 20:36:55 -08005838 ret = hdd_handle_batch_scan_ioctl(pAdapter, &priv_data, command);
Rajeev79dbe4c2013-10-05 11:03:42 +05305839 }
5840#endif
Abhishek Singh00b71972016-01-07 10:51:04 +05305841#ifdef WLAN_FEATURE_RMC
5842 else if ((strncasecmp(command, "SETIBSSBEACONOUIDATA", 20) == 0) &&
5843 (WLAN_HDD_IBSS == pAdapter->device_mode))
5844 {
5845 int i = 0;
5846 tANI_U8 *ibss_ie;
5847 tANI_U32 command_len;
5848 tANI_U8 *value = command;
5849 tHalHandle hHal = pHddCtx->hHal;
5850 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
5851 tANI_U32 ibss_ie_length;
5852 tANI_U32 len, present;
5853 tANI_U8 *addIE;
5854 tANI_U8 *addIEData;
5855
5856 hddLog(LOG1,
5857 FL(" received command %s"),((char *) value));
5858 /* validate argument of command */
5859 if (strlen(value) <= 21)
5860 {
5861 hddLog(LOGE,
5862 FL("No arguements in command length %zu"), strlen(value));
5863 ret = -EFAULT;
5864 goto exit;
5865 }
5866
5867 /* moving to arguments of commands */
5868 value = value + 21;
5869 command_len = strlen(value);
5870
5871 /* oui_data can't be less than 3 bytes */
5872 if (command_len <= (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH))
5873 {
5874 hddLog(LOGE,
5875 FL("Invalid SETIBSSBEACONOUIDATA command length %d"),
5876 command_len);
5877 ret = -EFAULT;
5878 goto exit;
5879 }
5880 ibss_ie = vos_mem_malloc(command_len);
5881 if (!ibss_ie) {
5882 hddLog(LOGE,
5883 FL("Could not allocate memory for command length %d"),
5884 command_len);
5885 ret = -ENOMEM;
5886 goto exit;
5887 }
5888 vos_mem_zero(ibss_ie, command_len);
5889
5890 ibss_ie_length = hdd_parse_set_ibss_oui_data_command(value, ibss_ie,
5891 command_len);
5892 if (ibss_ie_length < (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH)) {
5893 hddLog(LOGE, FL("Could not parse command %s return length %d"),
5894 value, ibss_ie_length);
5895 ret = -EFAULT;
5896 vos_mem_free(ibss_ie);
5897 goto exit;
5898 }
5899
5900 hddLog(LOG1, FL("ibss_ie length %d ibss_ie:"), ibss_ie_length);
5901 while (i < ibss_ie_length)
5902 hddLog(LOG1, FL("0x%x"), ibss_ie[i++]);
5903
5904 /* Populate Vendor IE in Beacon */
5905 if ((ccmCfgGetInt(hHal,
5906 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
5907 &present)) != eHAL_STATUS_SUCCESS)
5908 {
5909 hddLog(LOGE,
5910 FL("unable to ftch WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
5911 ret = -EFAULT;
5912 vos_mem_free(ibss_ie);
5913 goto exit;
5914 }
5915
5916 addIE = vos_mem_malloc(WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
5917 if (!addIE) {
5918 hddLog(LOGE,
5919 FL("Could not allocate memory for command length %d"),
5920 command_len);
5921 vos_mem_free(ibss_ie);
5922 ret = -ENOMEM;
5923 goto exit;
5924 }
5925 vos_mem_zero(addIE, WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
5926
5927 if (present)
5928 {
5929 if ((wlan_cfgGetStrLen(pMac,
5930 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, &len)) != eSIR_SUCCESS)
5931 {
5932 hddLog(LOGE,
5933 FL("unable to fetch WNI_CFG_PROBE_RSP_BCN_ADDNIE_LEN"));
5934 ret = -EFAULT;
5935 vos_mem_free(ibss_ie);
5936 vos_mem_free(addIE);
5937 goto exit;
5938 }
5939
5940 if (len <= WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN && len &&
5941 ((len + ibss_ie_length) <=
5942 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN))
5943 {
5944 if ((ccmCfgGetStr(hHal,
5945 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, &len))
5946 != eHAL_STATUS_SUCCESS)
5947 {
5948 hddLog(LOGE,
5949 FL("unable to fetch WNI_PROBE_RSP_BCN_ADDNIE_DATA"));
5950 ret = -EFAULT;
5951 vos_mem_free(ibss_ie);
5952 vos_mem_free(addIE);
5953 goto exit;
5954 }
5955 else
5956 {
5957 /* Curruntly only WPA IE is added before Vendor IE
5958 * so we can blindly place the Vendor IE after WPA
5959 * IE. If no WPA IE found replace all with Vendor IE.
5960 */
5961 len = hdd_find_ibss_wpa_ie_pos(addIE, len);
5962 }
5963 }
5964 else
5965 {
5966 hddLog(LOGE,
5967 FL("IE len exceed limit len %d,ibss_ie_length %d "),
5968 len, ibss_ie_length);
5969 ret = -EFAULT;
5970 vos_mem_free(addIE);
5971 vos_mem_free(ibss_ie);
5972 goto exit;
5973 }
5974 }
5975 else {
5976 len = 0;
5977 }
5978
5979 vos_mem_copy (addIE + len , ibss_ie, ibss_ie_length);
5980 len += ibss_ie_length;
5981
5982 if (ccmCfgSetStr(hHal,
5983 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, len, NULL,
5984 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
5985 {
5986 hddLog(LOGE,
5987 FL("unable to set WNI_CFG_PRBE_RSP_BCN_ADDNIE_DATA"));
5988 ret = -EFAULT;
5989 vos_mem_free(ibss_ie);
5990 vos_mem_free(addIE);
5991 goto exit;
5992 }
5993 vos_mem_free(addIE);
5994 if (ccmCfgSetInt(hHal,
5995 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5996 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
5997 {
5998 hddLog(LOGE,
5999 FL("unble to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
6000 ret = -EFAULT;
6001 vos_mem_free(ibss_ie);
6002 goto exit;
6003 }
6004
6005 /* Populate Vendor IE in probe resp */
6006 if ((ccmCfgGetInt(hHal,
6007 WNI_CFG_PROBE_RSP_ADDNIE_FLAG,
6008 &present)) != eHAL_STATUS_SUCCESS)
6009 {
6010 hddLog(LOGE,
6011 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
6012 ret = -EFAULT;
6013 vos_mem_free(ibss_ie);
6014 goto exit;
6015 }
6016
6017 addIEData = vos_mem_malloc(WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
6018 if (!addIEData) {
6019 hddLog(LOGE,
6020 FL("Could not allocate memory for command length %d"),
6021 command_len);
6022 vos_mem_free(ibss_ie);
6023 ret = -ENOMEM;
6024 goto exit;
6025 }
6026 vos_mem_zero(addIEData, WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
6027
6028 if (present) {
6029 if (eSIR_SUCCESS != wlan_cfgGetStrLen(pMac,
6030 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, &len)) {
6031 hddLog(LOGE,
6032 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6033 ret = -EFAULT;
6034 vos_mem_free(ibss_ie);
6035 vos_mem_free(addIEData);
6036 goto exit;
6037 }
6038 if (len < WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN && len &&
6039 (ibss_ie_length + len) <=
6040 WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN) {
6041
6042 if ((ccmCfgGetStr(hHal,
6043 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, addIEData, &len))
6044 != eHAL_STATUS_SUCCESS) {
6045 hddLog(LOGE,
6046 FL("unable fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6047 ret = -EFAULT;
6048 vos_mem_free(ibss_ie);
6049 vos_mem_free(addIEData);
6050 goto exit;
6051 }
6052 else {
6053 /* Curruntly only WPA IE is added before Vendor IE
6054 * so we can blindly place the Vendor IE after WPA
6055 * IE. If no WPA IE found replace all with Vendor IE.
6056 */
6057 len = hdd_find_ibss_wpa_ie_pos(addIEData, len);
6058 }
6059 }
6060 else
6061 {
6062 hddLog(LOGE,
6063 FL("IE len exceed limit len %d,ibss_ie_length %d "),
6064 len, ibss_ie_length);
6065 ret = -EFAULT;
6066 vos_mem_free(addIEData);
6067 vos_mem_free(ibss_ie);
6068 goto exit;
6069 }
6070 } /* probe rsp ADD IE present */
6071 else {
6072 /* probe rsp add IE is not present */
6073 len = 0;
6074 }
6075
6076 vos_mem_copy(addIEData +len , ibss_ie, ibss_ie_length);
6077 len += ibss_ie_length;
6078
6079 vos_mem_free(ibss_ie);
6080
6081 if (ccmCfgSetStr(hHal,
6082 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
6083 (tANI_U8*)(addIEData),
6084 len, NULL,
6085 eANI_BOOLEAN_FALSE)
6086 == eHAL_STATUS_FAILURE) {
6087 hddLog(LOGE,
6088 FL("unable to copy to WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6089 ret = -EFAULT;
6090 vos_mem_free(addIEData);
6091 goto exit;
6092 }
6093 vos_mem_free(addIEData);
6094 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6095 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
6096 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6097 {
6098 hddLog(LOGE,
6099 FL("unable to copy WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
6100 ret = -EFAULT;
6101 goto exit;
6102 }
6103 }
6104 else if (strncasecmp(command, "SETRMCENABLE", 12) == 0)
6105 {
6106 tANI_U8 *value = command;
6107 tANI_U8 ucRmcEnable = 0;
6108 int status;
6109
6110 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6111 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6112 {
6113 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6114 "Received SETRMCENABLE command in invalid mode %d "
6115 "SETRMCENABLE command is only allowed in IBSS or SOFTAP mode",
6116 pAdapter->device_mode);
6117 ret = -EINVAL;
6118 goto exit;
6119 }
6120
6121 status = hdd_parse_setrmcenable_command(value, &ucRmcEnable);
6122 if (status)
6123 {
6124 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6125 "Invalid SETRMCENABLE command ");
6126 ret = -EINVAL;
6127 goto exit;
6128 }
6129
6130 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6131 "%s: ucRmcEnable %d ", __func__, ucRmcEnable);
6132
6133 if (TRUE == ucRmcEnable)
6134 {
6135 status = sme_EnableRMC( (tHalHandle)(pHddCtx->hHal),
6136 pAdapter->sessionId );
6137 }
6138 else if(FALSE == ucRmcEnable)
6139 {
6140 status = sme_DisableRMC( (tHalHandle)(pHddCtx->hHal),
6141 pAdapter->sessionId );
6142 }
6143 else
6144 {
6145 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6146 "Invalid SETRMCENABLE command %d", ucRmcEnable);
6147 ret = -EINVAL;
6148 goto exit;
6149 }
6150
6151 if (VOS_STATUS_SUCCESS != status)
6152 {
6153 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6154 "%s: SETRMC %d failed status %d", __func__, ucRmcEnable,
6155 status);
6156 ret = -EINVAL;
6157 goto exit;
6158 }
6159 }
6160 else if (strncasecmp(command, "SETRMCACTIONPERIOD", 18) == 0)
6161 {
6162 tANI_U8 *value = command;
6163 tANI_U32 uActionPeriod = 0;
6164 int status;
6165
6166 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6167 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6168 {
6169 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6170 "Received SETRMC command in invalid mode %d "
6171 "SETRMC command is only allowed in IBSS or SOFTAP mode",
6172 pAdapter->device_mode);
6173 ret = -EINVAL;
6174 goto exit;
6175 }
6176
6177 status = hdd_parse_setrmcactionperiod_command(value, &uActionPeriod);
6178 if (status)
6179 {
6180 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6181 "Invalid SETRMCACTIONPERIOD command ");
6182 ret = -EINVAL;
6183 goto exit;
6184 }
6185
6186 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6187 "%s: uActionPeriod %d ", __func__, uActionPeriod);
6188
6189 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY,
6190 uActionPeriod, NULL, eANI_BOOLEAN_FALSE))
6191 {
6192 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6193 "%s: Could not set SETRMCACTIONPERIOD %d", __func__, uActionPeriod);
6194 ret = -EINVAL;
6195 goto exit;
6196 }
6197
6198 }
6199 else if (strncasecmp(command, "GETIBSSPEERINFOALL", 18) == 0)
6200 {
6201 /* Peer Info All Command */
6202 int status = eHAL_STATUS_SUCCESS;
6203 hdd_station_ctx_t *pHddStaCtx = NULL;
6204 char *extra = NULL;
6205 int idx = 0, length = 0;
6206 v_MACADDR_t *macAddr;
6207 v_U32_t txRateMbps = 0, numOfBytestoPrint = 0;
6208
6209 if (WLAN_HDD_IBSS == pAdapter->device_mode)
6210 {
6211 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6212 }
6213 else
6214 {
6215 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6216 "%s: pAdapter is not valid for this device mode",
6217 __func__);
6218 ret = -EINVAL;
6219 goto exit;
6220 }
6221
6222 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6223 "%s: Received GETIBSSPEERINFOALL Command", __func__);
6224
6225
6226 /* Handle the command */
6227 status = hdd_cfg80211_get_ibss_peer_info_all(pAdapter);
6228 if (VOS_STATUS_SUCCESS == status)
6229 {
6230 /* The variable extra needed to be allocated on the heap since
6231 * amount of memory required to copy the data for 32 devices
6232 * exceeds the size of 1024 bytes of default stack size. On
6233 * 64 bit devices, the default max stack size of 2048 bytes
6234 */
6235 extra = kmalloc(WLAN_MAX_BUF_SIZE, GFP_KERNEL);
6236
6237 if (NULL == extra)
6238 {
6239 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6240 "%s:kmalloc failed", __func__);
6241 ret = -EINVAL;
6242 goto exit;
6243 }
6244
6245 /* Copy number of stations */
6246 length = scnprintf( extra, WLAN_MAX_BUF_SIZE, "%d ",
6247 pHddStaCtx->ibss_peer_info.numIBSSPeers);
6248 numOfBytestoPrint = length;
6249 for (idx = 0; idx < pHddStaCtx->ibss_peer_info.numIBSSPeers; idx++)
6250 {
6251 macAddr =
6252 hdd_wlan_get_ibss_mac_addr_from_staid(pAdapter,
6253 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
6254 if (NULL != macAddr)
6255 {
6256 txRateMbps =
6257 ((pHddStaCtx->ibss_peer_info.ibssPeerList[idx].txRate)*500*1000)/1000000;
6258
6259 length += scnprintf( (extra + length), WLAN_MAX_BUF_SIZE - length,
6260 "%02x:%02x:%02x:%02x:%02x:%02x %d %d ",
6261 macAddr->bytes[0], macAddr->bytes[1], macAddr->bytes[2],
6262 macAddr->bytes[3], macAddr->bytes[4], macAddr->bytes[5],
6263 (int)txRateMbps,
6264 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[idx].rssi);
6265 }
6266 else
6267 {
6268 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6269 "%s: MAC ADDR is NULL for staIdx: %d", __func__,
6270 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
6271 }
6272
6273 /*
6274 * VOS_TRACE() macro has limitation of 512 bytes for the print
6275 * buffer. Hence printing the data in two chunks. The first chunk
6276 * will have the data for 16 devices and the second chunk will
6277 * have the rest.
6278 */
6279 if (idx < NUM_OF_STA_DATA_TO_PRINT)
6280 {
6281 numOfBytestoPrint = length;
6282 }
6283 }
6284
6285 /*
6286 * Copy the data back into buffer, if the data to copy is
6287 * morethan 512 bytes than we will split the data and do
6288 * it in two shots
6289 */
6290 if (copy_to_user(priv_data.buf, extra, numOfBytestoPrint))
6291 {
6292 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6293 "%s: Copy into user data buffer failed ", __func__);
6294 ret = -EFAULT;
6295 kfree(extra);
6296 goto exit;
6297 }
6298 priv_data.buf[numOfBytestoPrint] = '\0';
6299 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6300 "%s", priv_data.buf);
6301
6302 if (length > numOfBytestoPrint)
6303 {
6304 if (copy_to_user(priv_data.buf + numOfBytestoPrint,
6305 extra + numOfBytestoPrint,
6306 length - numOfBytestoPrint + 1))
6307 {
6308 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6309 "%s: Copy into user data buffer failed ", __func__);
6310 ret = -EFAULT;
6311 kfree(extra);
6312 goto exit;
6313 }
6314 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6315 "%s", &priv_data.buf[numOfBytestoPrint]);
6316 }
6317
6318 /* Free temporary buffer */
6319 kfree(extra);
6320 }
6321
6322 else
6323 {
6324 /* Command failed, log error */
6325 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6326 "%s: GETIBSSPEERINFOALL command failed with status code %d",
6327 __func__, status);
6328 ret = -EINVAL;
6329 goto exit;
6330 }
6331 ret = 0;
6332 }
6333 else if(strncasecmp(command, "GETIBSSPEERINFO", 15) == 0)
6334 {
6335 /* Peer Info <Peer Addr> command */
6336 tANI_U8 *value = command;
6337 VOS_STATUS status;
6338 hdd_station_ctx_t *pHddStaCtx = NULL;
6339 char extra[128] = { 0 };
6340 v_U32_t length = 0;
6341 v_U8_t staIdx = 0;
6342 v_U32_t txRateMbps = 0;
6343 v_MACADDR_t peerMacAddr;
6344
6345 if (WLAN_HDD_IBSS == pAdapter->device_mode)
6346 {
6347 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6348 }
6349 else
6350 {
6351 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6352 "%s: pAdapter is not valid for this device mode",
6353 __func__);
6354 ret = -EINVAL;
6355 goto exit;
6356 }
6357
6358 /* if there are no peers, no need to continue with the command */
6359 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6360 "%s: Received GETIBSSPEERINFO Command", __func__);
6361
6362 if (eConnectionState_IbssConnected != pHddStaCtx->conn_info.connState)
6363 {
6364 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6365 "%s:No IBSS Peers coalesced", __func__);
6366 ret = -EINVAL;
6367 goto exit;
6368 }
6369
6370 /* Parse the incoming command buffer */
6371 status = hdd_parse_get_ibss_peer_info(value, &peerMacAddr);
6372 if (VOS_STATUS_SUCCESS != status)
6373 {
6374 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6375 "%s: Invalid GETIBSSPEERINFO command", __func__);
6376 ret = -EINVAL;
6377 goto exit;
6378 }
6379
6380 /* Get station index for the peer mac address */
6381 hdd_Ibss_GetStaId(pHddStaCtx, &peerMacAddr, &staIdx);
6382
6383 if (staIdx > HDD_MAX_NUM_IBSS_STA)
6384 {
6385 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6386 "%s: Invalid StaIdx %d returned", __func__, staIdx);
6387 ret = -EINVAL;
6388 goto exit;
6389 }
6390
6391 /* Handle the command */
6392 status = hdd_cfg80211_get_ibss_peer_info(pAdapter, staIdx);
6393 if (VOS_STATUS_SUCCESS == status)
6394 {
6395 v_U32_t txRate = pHddStaCtx->ibss_peer_info.ibssPeerList[0].txRate;
6396 txRateMbps = (txRate * 500 * 1000)/1000000;
6397
6398 length = scnprintf( extra, sizeof(extra), "%d %d", (int)txRateMbps,
6399 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[0].rssi);
6400
6401 /* Copy the data back into buffer */
6402 if (copy_to_user(priv_data.buf, &extra, length+ 1))
6403 {
6404 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6405 "%s: copy data to user buffer failed GETIBSSPEERINFO command",
6406 __func__);
6407 ret = -EFAULT;
6408 goto exit;
6409 }
6410 }
6411 else
6412 {
6413 /* Command failed, log error */
6414 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6415 "%s: GETIBSSPEERINFO command failed with status code %d",
6416 __func__, status);
6417 ret = -EINVAL;
6418 goto exit;
6419 }
6420
6421 /* Success ! */
6422 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6423 "%s", priv_data.buf);
6424 ret = 0;
6425 }
6426 else if (strncasecmp(command, "SETRMCTXRATE", 12) == 0)
6427 {
6428 tANI_U8 *value = command;
6429 tANI_U32 uRate = 0;
6430 tTxrateinfoflags txFlags = 0;
6431 tSirRateUpdateInd *rateUpdateParams;
6432 int status;
6433
6434 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6435 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6436 {
6437 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6438 "Received SETRMCTXRATE command in invalid mode %d "
6439 "SETRMC command is only allowed in IBSS or SOFTAP mode",
6440 pAdapter->device_mode);
6441 ret = -EINVAL;
6442 goto exit;
6443 }
6444
6445 status = hdd_parse_setrmcrate_command(value, &uRate, &txFlags);
6446 if (status)
6447 {
6448 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6449 "Invalid SETRMCTXRATE command ");
6450 ret = -EINVAL;
6451 goto exit;
6452 }
6453
6454 rateUpdateParams = vos_mem_malloc(sizeof(tSirRateUpdateInd));
6455 if (NULL == rateUpdateParams)
6456 {
6457 ret = -EINVAL;
6458 goto exit;
6459 }
6460
6461 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6462 "%s: uRate %d ", __func__, uRate);
6463
6464 vos_mem_zero(rateUpdateParams, sizeof(tSirRateUpdateInd ));
6465
6466 /* -1 implies ignore this param */
6467 rateUpdateParams->ucastDataRate = -1;
6468
6469 /*
6470 * Fill the user specifieed RMC rate param
6471 * and the derived tx flags.
6472 */
6473 rateUpdateParams->rmcDataRate = uRate;
6474 rateUpdateParams->rmcDataRateTxFlag = txFlags;
6475
6476 status = sme_SendRateUpdateInd((tHalHandle)(pHddCtx->hHal), rateUpdateParams);
6477 }
6478 else if (strncasecmp(command, "SETIBSSTXFAILEVENT", 18) == 0 )
6479 {
6480 char *value;
6481 tANI_U8 tx_fail_count = 0;
6482 tANI_U16 pid = 0;
6483
6484 value = command;
6485
6486 ret = hdd_ParseIBSSTXFailEventParams(value, &tx_fail_count, &pid);
6487
6488 if (0 != ret)
6489 {
6490 hddLog(VOS_TRACE_LEVEL_INFO,
6491 "%s: Failed to parse SETIBSSTXFAILEVENT arguments",
6492 __func__);
6493 goto exit;
6494 }
6495
6496 hddLog(VOS_TRACE_LEVEL_INFO, "%s: tx_fail_cnt=%hhu, pid=%hu",
6497 __func__, tx_fail_count, pid);
6498
6499 if (0 == tx_fail_count)
6500 {
6501 // Disable TX Fail Indication
6502 if (eHAL_STATUS_SUCCESS ==
6503 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
6504 tx_fail_count,
6505 NULL))
6506 {
6507 cesium_pid = 0;
6508 }
6509 else
6510 {
6511 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6512 "%s: failed to disable TX Fail Event ", __func__);
6513 ret = -EINVAL;
6514 }
6515 }
6516 else
6517 {
6518 if (eHAL_STATUS_SUCCESS ==
6519 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
6520 tx_fail_count,
6521 (void*)hdd_tx_fail_ind_callback))
6522 {
6523 cesium_pid = pid;
6524 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6525 "%s: Registered Cesium pid %u", __func__,
6526 cesium_pid);
6527 }
6528 else
6529 {
6530 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6531 "%s: Failed to enable TX Fail Monitoring", __func__);
6532 ret = -EINVAL;
6533 }
6534 }
6535 }
6536
6537#endif /* WLAN_FEATURE_RMC */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006538#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006539 else if (strncmp(command, "SETCCXROAMSCANCHANNELS", 22) == 0)
6540 {
6541 tANI_U8 *value = command;
6542 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
6543 tANI_U8 numChannels = 0;
6544 eHalStatus status = eHAL_STATUS_SUCCESS;
6545
6546 status = hdd_parse_channellist(value, ChannelList, &numChannels);
6547 if (eHAL_STATUS_SUCCESS != status)
6548 {
6549 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6550 "%s: Failed to parse channel list information", __func__);
6551 ret = -EINVAL;
6552 goto exit;
6553 }
6554
6555 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
6556 {
6557 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6558 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
6559 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
6560 ret = -EINVAL;
6561 goto exit;
6562 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006563 status = sme_SetEseRoamScanChannelList((tHalHandle)(pHddCtx->hHal),
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006564 ChannelList,
6565 numChannels);
6566 if (eHAL_STATUS_SUCCESS != status)
6567 {
6568 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6569 "%s: Failed to update channel list information", __func__);
6570 ret = -EINVAL;
6571 goto exit;
6572 }
6573 }
6574 else if (strncmp(command, "GETTSMSTATS", 11) == 0)
6575 {
6576 tANI_U8 *value = command;
6577 char extra[128] = {0};
6578 int len = 0;
6579 tANI_U8 tid = 0;
6580 hdd_station_ctx_t *pHddStaCtx = NULL;
6581 tAniTrafStrmMetrics tsmMetrics;
6582 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6583
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306584 ret = hdd_drv_cmd_validate(command, 11);
6585 if (ret)
6586 goto exit;
6587
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006588 /* if not associated, return error */
6589 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6590 {
6591 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:Not associated!",__func__);
6592 ret = -EINVAL;
6593 goto exit;
6594 }
6595
6596 /* Move pointer to ahead of GETTSMSTATS<delimiter> */
6597 value = value + 12;
6598 /* Convert the value from ascii to integer */
6599 ret = kstrtou8(value, 10, &tid);
6600 if (ret < 0)
6601 {
6602 /* If the input value is greater than max value of datatype, then also
6603 kstrtou8 fails */
6604 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6605 "%s: kstrtou8 failed range [%d - %d]", __func__,
6606 TID_MIN_VALUE,
6607 TID_MAX_VALUE);
6608 ret = -EINVAL;
6609 goto exit;
6610 }
6611
6612 if ((tid < TID_MIN_VALUE) || (tid > TID_MAX_VALUE))
6613 {
6614 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6615 "tid value %d is out of range"
6616 " (Min: %d Max: %d)", tid,
6617 TID_MIN_VALUE,
6618 TID_MAX_VALUE);
6619 ret = -EINVAL;
6620 goto exit;
6621 }
6622
6623 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6624 "%s: Received Command to get tsm stats tid = %d", __func__, tid);
6625
6626 if (VOS_STATUS_SUCCESS != hdd_get_tsm_stats(pAdapter, tid, &tsmMetrics))
6627 {
6628 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6629 "%s: failed to get tsm stats", __func__);
6630 ret = -EFAULT;
6631 goto exit;
6632 }
6633
6634 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6635 "UplinkPktQueueDly(%d)\n"
6636 "UplinkPktQueueDlyHist[0](%d)\n"
6637 "UplinkPktQueueDlyHist[1](%d)\n"
6638 "UplinkPktQueueDlyHist[2](%d)\n"
6639 "UplinkPktQueueDlyHist[3](%d)\n"
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05306640 "UplinkPktTxDly(%u)\n"
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006641 "UplinkPktLoss(%d)\n"
6642 "UplinkPktCount(%d)\n"
6643 "RoamingCount(%d)\n"
6644 "RoamingDly(%d)", tsmMetrics.UplinkPktQueueDly,
6645 tsmMetrics.UplinkPktQueueDlyHist[0],
6646 tsmMetrics.UplinkPktQueueDlyHist[1],
6647 tsmMetrics.UplinkPktQueueDlyHist[2],
6648 tsmMetrics.UplinkPktQueueDlyHist[3],
6649 tsmMetrics.UplinkPktTxDly, tsmMetrics.UplinkPktLoss,
6650 tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount, tsmMetrics.RoamingDly);
6651
6652 /* Output TSM stats is of the format
6653 GETTSMSTATS [PktQueueDly] [PktQueueDlyHist[0]]:[PktQueueDlyHist[1]] ...[RoamingDly]
6654 eg., GETTSMSTATS 10 1:0:0:161 20 1 17 8 39800 */
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006655 len = scnprintf(extra, sizeof(extra), "%s %d %d:%d:%d:%d %u %d %d %d %d", command,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006656 tsmMetrics.UplinkPktQueueDly, tsmMetrics.UplinkPktQueueDlyHist[0],
6657 tsmMetrics.UplinkPktQueueDlyHist[1], tsmMetrics.UplinkPktQueueDlyHist[2],
6658 tsmMetrics.UplinkPktQueueDlyHist[3], tsmMetrics.UplinkPktTxDly,
6659 tsmMetrics.UplinkPktLoss, tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount,
6660 tsmMetrics.RoamingDly);
6661
Ratnam Rachurid53009c2015-08-07 13:59:00 +05306662 len = VOS_MIN(priv_data.total_len, len + 1);
6663 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006664 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6665 "%s: failed to copy data to user buffer", __func__);
6666 ret = -EFAULT;
6667 goto exit;
6668 }
6669 }
6670 else if (strncmp(command, "SETCCKMIE", 9) == 0)
6671 {
6672 tANI_U8 *value = command;
6673 tANI_U8 *cckmIe = NULL;
6674 tANI_U8 cckmIeLen = 0;
6675 eHalStatus status = eHAL_STATUS_SUCCESS;
6676
6677 status = hdd_parse_get_cckm_ie(value, &cckmIe, &cckmIeLen);
6678 if (eHAL_STATUS_SUCCESS != status)
6679 {
6680 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6681 "%s: Failed to parse cckm ie data", __func__);
6682 ret = -EINVAL;
6683 goto exit;
6684 }
6685
6686 if (cckmIeLen > DOT11F_IE_RSN_MAX_LEN)
6687 {
6688 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6689 "%s: CCKM Ie input length is more than max[%d]", __func__,
6690 DOT11F_IE_RSN_MAX_LEN);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006691 vos_mem_free(cckmIe);
6692 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006693 ret = -EINVAL;
6694 goto exit;
6695 }
6696 sme_SetCCKMIe((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, cckmIe, cckmIeLen);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006697 vos_mem_free(cckmIe);
6698 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006699 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006700 else if (strncmp(command, "CCXBEACONREQ", 12) == 0)
6701 {
6702 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006703 tCsrEseBeaconReq eseBcnReq;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006704 eHalStatus status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07006705
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006706 status = hdd_parse_ese_beacon_req(value, &eseBcnReq);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006707 if (eHAL_STATUS_SUCCESS != status)
6708 {
6709 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006710 "%s: Failed to parse ese beacon req", __func__);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006711 ret = -EINVAL;
6712 goto exit;
6713 }
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07006714 if (!hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))) {
6715 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not associated"));
6716 hdd_indicateEseBcnReportNoResults (pAdapter,
6717 eseBcnReq.bcnReq[0].measurementToken,
6718 0x02, //BIT(1) set for measurement done
6719 0); // no BSS
6720 goto exit;
6721 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006722
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006723 status = sme_SetEseBeaconRequest((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, &eseBcnReq);
6724 if (eHAL_STATUS_SUCCESS != status)
6725 {
6726 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6727 "%s: sme_SetEseBeaconRequest failed (%d)", __func__, status);
6728 ret = -EINVAL;
6729 goto exit;
6730 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006731 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006732#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
c_hpothu92367912014-05-01 15:18:17 +05306733 else if (strncmp(command, "GETBCNMISSRATE", 14) == 0)
6734 {
6735 eHalStatus status;
6736 char buf[32], len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306737 void *cookie;
6738 struct hdd_request *request;
6739 struct bcn_miss_rate_priv *priv;
6740 static const struct hdd_request_params params = {
6741 .priv_size = sizeof(*priv),
6742 .timeout_ms = WLAN_WAIT_TIME_STATS,
6743 };
c_hpothu92367912014-05-01 15:18:17 +05306744
6745 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6746
6747 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6748 {
6749 hddLog(VOS_TRACE_LEVEL_WARN,
6750 FL("GETBCNMISSRATE: STA is not in connected state"));
6751 ret = -1;
6752 goto exit;
6753 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306754 request = hdd_request_alloc(&params);
6755 if (!request) {
6756 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
6757 ret = -ENOMEM;
6758 goto exit;
6759 }
6760 cookie = hdd_request_cookie(request);
6761 priv = hdd_request_priv(request);
6762 priv->bcn_miss_rate = -1;
c_hpothu92367912014-05-01 15:18:17 +05306763
6764 status = sme_getBcnMissRate((tHalHandle)(pHddCtx->hHal),
6765 pAdapter->sessionId,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306766 (void *)get_bcn_miss_rate_cb,
6767 cookie);
c_hpothu92367912014-05-01 15:18:17 +05306768 if( eHAL_STATUS_SUCCESS != status)
6769 {
6770 hddLog(VOS_TRACE_LEVEL_INFO,
6771 FL("GETBCNMISSRATE: fail to post WDA cmd"));
6772 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306773 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306774 }
6775
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306776 ret = hdd_request_wait_for_response(request);
6777 if(ret)
c_hpothu92367912014-05-01 15:18:17 +05306778 {
6779 hddLog(VOS_TRACE_LEVEL_ERROR,
6780 FL("failed to wait on bcnMissRateComp %d"), ret);
6781
c_hpothu92367912014-05-01 15:18:17 +05306782 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306783 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306784 }
6785
6786 hddLog(VOS_TRACE_LEVEL_INFO,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306787 FL("GETBCNMISSRATE: bcnMissRate: %d"), priv->bcn_miss_rate);
c_hpothu92367912014-05-01 15:18:17 +05306788
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306789 if (priv->bcn_miss_rate == -1) {
6790 ret = -EFAULT;
6791 goto free_bcn_miss_rate_req;
6792 }
6793
6794 len = snprintf(buf, sizeof(buf), "GETBCNMISSRATE %d",
6795 priv->bcn_miss_rate);
c_hpothu92367912014-05-01 15:18:17 +05306796 if (copy_to_user(priv_data.buf, &buf, len + 1))
6797 {
6798 hddLog(VOS_TRACE_LEVEL_ERROR,
6799 "%s: failed to copy data to user buffer", __func__);
6800 ret = -EFAULT;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306801 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306802 }
6803 ret = len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306804
6805free_bcn_miss_rate_req:
6806 hdd_request_put(request);
c_hpothu92367912014-05-01 15:18:17 +05306807 }
Atul Mittal87ec2422014-09-24 13:12:50 +05306808#ifdef FEATURE_WLAN_TDLS
6809 else if (strncmp(command, "TDLSSECONDARYCHANNELOFFSET", 26) == 0) {
6810 tANI_U8 *value = command;
6811 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306812
6813 ret = hdd_drv_cmd_validate(command, 26);
6814 if (ret)
6815 goto exit;
6816
Atul Mittal87ec2422014-09-24 13:12:50 +05306817 /* Move pointer to ahead of TDLSOFFCH*/
6818 value += 26;
c_manjeebbc40212015-12-08 13:52:59 +05306819 if (!(sscanf(value, "%d", &set_value))) {
6820 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6821 FL("No input identified"));
6822 ret = -EINVAL;
6823 goto exit;
6824 }
6825
Atul Mittal87ec2422014-09-24 13:12:50 +05306826 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6827 "%s: Tdls offchannel offset:%d",
6828 __func__, set_value);
6829 ret = iw_set_tdlssecoffchanneloffset(pHddCtx, set_value);
6830 if (ret < 0)
6831 {
6832 ret = -EINVAL;
6833 goto exit;
6834 }
6835
6836 } else if (strncmp(command, "TDLSOFFCHANNELMODE", 18) == 0) {
6837 tANI_U8 *value = command;
6838 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306839
6840 ret = hdd_drv_cmd_validate(command, 18);
6841 if (ret)
6842 goto exit;
6843
Atul Mittal87ec2422014-09-24 13:12:50 +05306844 /* Move pointer to ahead of tdlsoffchnmode*/
6845 value += 18;
c_manjee82323892015-12-08 12:40:34 +05306846 ret = sscanf(value, "%d", &set_value);
6847 if (ret != 1) {
6848 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6849 FL("No input identified"));
6850 ret = -EINVAL;
6851 goto exit;
6852 }
Atul Mittal87ec2422014-09-24 13:12:50 +05306853 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6854 "%s: Tdls offchannel mode:%d",
6855 __func__, set_value);
6856 ret = iw_set_tdlsoffchannelmode(pAdapter, set_value);
6857 if (ret < 0)
6858 {
6859 ret = -EINVAL;
6860 goto exit;
6861 }
6862 } else if (strncmp(command, "TDLSOFFCHANNEL", 14) == 0) {
6863 tANI_U8 *value = command;
6864 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306865
6866 ret = hdd_drv_cmd_validate(command, 14);
6867 if (ret)
6868 goto exit;
6869
Atul Mittal87ec2422014-09-24 13:12:50 +05306870 /* Move pointer to ahead of TDLSOFFCH*/
6871 value += 14;
c_manjeef6ccaf52015-12-08 11:52:11 +05306872 ret = sscanf(value, "%d", &set_value);
6873 if (ret != 1) {
6874 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6875 "Wrong value is given for hdd_set_tdls_offchannel");
6876 ret = -EINVAL;
6877 goto exit;
6878 }
6879
Atul Mittal87ec2422014-09-24 13:12:50 +05306880 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6881 "%s: Tdls offchannel num: %d",
6882 __func__, set_value);
6883 ret = iw_set_tdlsoffchannel(pHddCtx, set_value);
6884 if (ret < 0)
6885 {
6886 ret = -EINVAL;
6887 goto exit;
6888 }
6889 }
6890#endif
Satyanarayana Dash72806012014-12-02 14:30:08 +05306891 else if (strncmp(command, "GETFWSTATS", 10) == 0)
6892 {
6893 eHalStatus status;
6894 char *buf = NULL;
6895 char len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306896 tSirFwStatsResult *fwStatsRsp = &(pAdapter->fwStatsRsp),
6897 *fw_stats_result;
Satyanarayana Dash72806012014-12-02 14:30:08 +05306898 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306899 int stats;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306900 void *cookie;
6901 struct hdd_request *request;
6902 struct fw_stats_priv *priv;
6903 static const struct hdd_request_params params = {
6904 .priv_size = sizeof(*priv),
6905 .timeout_ms = WLAN_WAIT_TIME_STATS,
6906 };
Satyanarayana Dash72806012014-12-02 14:30:08 +05306907
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306908 ret = hdd_drv_cmd_validate(command, 10);
6909 if (ret)
6910 goto exit;
6911
6912 stats = *(ptr + 11) - '0';
Satyanarayana Dash72806012014-12-02 14:30:08 +05306913 hddLog(VOS_TRACE_LEVEL_INFO, FL("stats = %d "),stats);
6914 if (!IS_FEATURE_FW_STATS_ENABLE)
6915 {
6916 hddLog(VOS_TRACE_LEVEL_INFO,
6917 FL("Get Firmware stats feature not supported"));
6918 ret = -EINVAL;
6919 goto exit;
6920 }
6921
6922 if (FW_STATS_MAX <= stats || 0 >= stats)
6923 {
6924 hddLog(VOS_TRACE_LEVEL_INFO,
6925 FL(" stats %d not supported"),stats);
6926 ret = -EINVAL;
6927 goto exit;
6928 }
6929
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306930 request = hdd_request_alloc(&params);
6931 if (!request) {
6932 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
6933 ret = -ENOMEM;
6934 goto exit;
6935 }
6936 cookie = hdd_request_cookie(request);
6937
Satyanarayana Dash72806012014-12-02 14:30:08 +05306938 status = sme_GetFwStats( (tHalHandle)pHddCtx->hHal, stats,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306939 cookie, hdd_fw_stats_cb);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306940 if (eHAL_STATUS_SUCCESS != status)
6941 {
6942 hddLog(VOS_TRACE_LEVEL_ERROR,
6943 FL(" fail to post WDA cmd status = %d"), status);
6944 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306945 hdd_request_put(request);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306946 goto exit;
6947 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306948 ret = hdd_request_wait_for_response(request);
6949 if (ret)
Satyanarayana Dash72806012014-12-02 14:30:08 +05306950 {
6951 hddLog(VOS_TRACE_LEVEL_ERROR,
6952 FL("failed to wait on GwtFwstats"));
Satyanarayana Dash72806012014-12-02 14:30:08 +05306953 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306954 hdd_request_put(request);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306955 goto exit;
6956 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306957
6958 priv = hdd_request_priv(request);
6959 fw_stats_result = priv->fw_stats;
6960 fwStatsRsp->type = 0;
6961 if (NULL != fw_stats_result)
6962 {
6963 switch (fw_stats_result->type )
6964 {
6965 case FW_UBSP_STATS:
6966 {
6967 tSirUbspFwStats *stats =
6968 &fwStatsRsp->fwStatsData.ubspStats;
6969 memcpy(fwStatsRsp, fw_stats_result,
6970 sizeof(tSirFwStatsResult));
6971 hddLog(VOS_TRACE_LEVEL_INFO,
6972 FL("ubsp_enter_cnt = %d ubsp_jump_ddr_cnt = %d"),
6973 stats->ubsp_enter_cnt,
6974 stats->ubsp_jump_ddr_cnt);
6975 }
6976 break;
6977
6978 default:
6979 {
6980 hddLog(VOS_TRACE_LEVEL_ERROR,
6981 FL("No handling for stats type %d"),
6982 fw_stats_result->type);
6983 }
6984 }
6985 }
6986 hdd_request_put(request);
6987
Satyanarayana Dash72806012014-12-02 14:30:08 +05306988 if (fwStatsRsp->type)
6989 {
6990 buf = kmalloc(FW_STATE_RSP_LEN, GFP_KERNEL);
6991 if (!buf)
6992 {
6993 hddLog(VOS_TRACE_LEVEL_ERROR,
6994 FL(" failed to allocate memory"));
6995 ret = -ENOMEM;
6996 goto exit;
6997 }
6998 switch( fwStatsRsp->type )
6999 {
7000 case FW_UBSP_STATS:
7001 {
7002 len = snprintf(buf, FW_STATE_RSP_LEN,
7003 "GETFWSTATS: ubsp_enter_cnt %d ubsp_jump_ddr_cnt %d",
Abhishek Singh08aa7762014-12-16 13:59:03 +05307004 fwStatsRsp->fwStatsData.ubspStats.ubsp_enter_cnt,
7005 fwStatsRsp->fwStatsData.ubspStats.ubsp_jump_ddr_cnt);
Satyanarayana Dash72806012014-12-02 14:30:08 +05307006 }
7007 break;
7008 default:
7009 {
7010 hddLog(VOS_TRACE_LEVEL_ERROR, FL( "No handling for stats type %d"),fwStatsRsp->type);
7011 ret = -EFAULT;
7012 kfree(buf);
7013 goto exit;
7014 }
7015 }
7016 if (copy_to_user(priv_data.buf, buf, len + 1))
7017 {
7018 hddLog(VOS_TRACE_LEVEL_ERROR,
7019 FL(" failed to copy data to user buffer"));
7020 ret = -EFAULT;
7021 kfree(buf);
7022 goto exit;
7023 }
7024 ret = len;
7025 kfree(buf);
7026 }
7027 else
7028 {
7029 hddLog(VOS_TRACE_LEVEL_ERROR,
7030 FL("failed to fetch the stats"));
7031 ret = -EFAULT;
7032 goto exit;
7033 }
Satyanarayana Dash72806012014-12-02 14:30:08 +05307034 }
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05307035 else if (strncasecmp(command, "SET_FCC_CHANNEL", 15) == 0)
7036 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05307037 ret = hdd_drv_cmd_validate(command, 15);
7038 if (ret)
7039 goto exit;
7040
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05307041 /*
7042 * this command wld be called by user-space when it detects WLAN
7043 * ON after airplane mode is set. When APM is set, WLAN turns off.
7044 * But it can be turned back on. Otherwise; when APM is turned back
7045 * off, WLAN wld turn back on. So at that point the command is
7046 * expected to come down. 0 means disable, 1 means enable. The
7047 * constraint is removed when parameter 1 is set or different
7048 * country code is set
7049 */
7050 ret = hdd_cmd_setFccChannel(pHddCtx, command, 15);
7051 }
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05307052 else if (strncasecmp(command, "DISABLE_CA_EVENT", 16) == 0)
7053 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05307054 ret = hdd_drv_cmd_validate(command, 16);
7055 if (ret)
7056 goto exit;
7057
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05307058 ret = hdd_enable_disable_ca_event(pHddCtx, command, 16);
7059 }
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05307060 /*
7061 * command should be a string having format
7062 * SET_DISABLE_CHANNEL_LIST <num of channels>
7063 * <channels separated by spaces>
7064 */
7065 else if (strncmp(command, "SET_DISABLE_CHANNEL_LIST", 24) == 0) {
7066 tANI_U8 *ptr = command;
7067 ret = hdd_drv_cmd_validate(command, 24);
7068 if (ret)
7069 goto exit;
7070
7071 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7072 " Received Command to disable Channels %s",
7073 __func__);
7074 ret = hdd_parse_disable_chan_cmd(pAdapter, ptr);
7075 if (ret)
7076 goto exit;
7077 }
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307078 else if (strncmp(command, "GET_DISABLE_CHANNEL_LIST", 24) == 0) {
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307079 char extra[512] = {0};
7080 int max_len, copied_length;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05307081
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307082 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307083 " Received Command to get disable Channels list %s",
7084 __func__);
7085
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307086 max_len = VOS_MIN(priv_data.total_len, sizeof(extra));
7087 copied_length = hdd_get_disable_ch_list(pHddCtx, extra, max_len);
7088 if (copied_length == 0) {
7089 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307090 FL("disable channel list are not yet programed"));
7091 ret = -EINVAL;
7092 goto exit;
7093 }
7094
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307095 if (copy_to_user(priv_data.buf, &extra, copied_length + 1)) {
7096 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7097 "%s: failed to copy data to user buffer", __func__);
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307098 ret = -EFAULT;
7099 goto exit;
7100 }
7101
7102 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7103 FL("data:%s"), extra);
7104 }
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07007105 else {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307106 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7107 TRACE_CODE_HDD_UNSUPPORTED_IOCTL,
7108 pAdapter->sessionId, 0));
Satyanarayana Dash72806012014-12-02 14:30:08 +05307109 hddLog( VOS_TRACE_LEVEL_WARN, FL("Unsupported GUI command %s"),
7110 command);
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07007111 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007112 }
7113exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307114 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007115 if (command)
7116 {
7117 kfree(command);
7118 }
7119 return ret;
7120}
7121
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007122#ifdef CONFIG_COMPAT
7123static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7124{
7125 struct {
7126 compat_uptr_t buf;
7127 int used_len;
7128 int total_len;
7129 } compat_priv_data;
7130 hdd_priv_data_t priv_data;
7131 int ret = 0;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007132
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007133 /*
7134 * Note that pAdapter and ifr have already been verified by caller,
7135 * and HDD context has also been validated
7136 */
7137 if (copy_from_user(&compat_priv_data, ifr->ifr_data,
7138 sizeof(compat_priv_data))) {
7139 ret = -EFAULT;
7140 goto exit;
7141 }
7142 priv_data.buf = compat_ptr(compat_priv_data.buf);
7143 priv_data.used_len = compat_priv_data.used_len;
7144 priv_data.total_len = compat_priv_data.total_len;
7145 ret = hdd_driver_command(pAdapter, &priv_data);
7146 exit:
7147 return ret;
7148}
7149#else /* CONFIG_COMPAT */
7150static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7151{
7152 /* will never be invoked */
7153 return 0;
7154}
7155#endif /* CONFIG_COMPAT */
7156
7157static int hdd_driver_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7158{
7159 hdd_priv_data_t priv_data;
7160 int ret = 0;
7161
7162 /*
7163 * Note that pAdapter and ifr have already been verified by caller,
7164 * and HDD context has also been validated
7165 */
7166 if (copy_from_user(&priv_data, ifr->ifr_data, sizeof(priv_data))) {
7167 ret = -EFAULT;
7168 } else {
7169 ret = hdd_driver_command(pAdapter, &priv_data);
7170 }
7171 return ret;
7172}
7173
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307174int __hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007175{
7176 hdd_adapter_t *pAdapter;
7177 hdd_context_t *pHddCtx;
7178 int ret;
7179
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307180 ENTER();
7181
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007182 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7183 if (NULL == pAdapter) {
7184 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7185 "%s: HDD adapter context is Null", __func__);
7186 ret = -ENODEV;
7187 goto exit;
7188 }
7189 if (dev != pAdapter->dev) {
7190 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7191 "%s: HDD adapter/dev inconsistency", __func__);
7192 ret = -ENODEV;
7193 goto exit;
7194 }
7195
7196 if ((!ifr) || (!ifr->ifr_data)) {
7197 ret = -EINVAL;
7198 goto exit;
7199 }
7200
7201 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7202 ret = wlan_hdd_validate_context(pHddCtx);
7203 if (ret) {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007204 ret = -EBUSY;
7205 goto exit;
7206 }
7207
7208 switch (cmd) {
7209 case (SIOCDEVPRIVATE + 1):
7210 if (is_compat_task())
7211 ret = hdd_driver_compat_ioctl(pAdapter, ifr);
7212 else
7213 ret = hdd_driver_ioctl(pAdapter, ifr);
7214 break;
7215 default:
7216 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unknown ioctl %d",
7217 __func__, cmd);
7218 ret = -EINVAL;
7219 break;
7220 }
7221 exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307222 EXIT();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007223 return ret;
7224}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007225
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307226int hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7227{
7228 int ret;
7229
7230 vos_ssr_protect(__func__);
7231 ret = __hdd_ioctl(dev, ifr, cmd);
7232 vos_ssr_unprotect(__func__);
7233
7234 return ret;
7235}
7236
Katya Nigame7b69a82015-04-28 15:24:06 +05307237int hdd_mon_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7238{
7239 return 0;
7240}
7241
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007242#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007243/**---------------------------------------------------------------------------
7244
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007245 \brief hdd_parse_ese_beacon_req() - Parse ese beacon request
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007246
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007247 This function parses the ese beacon request passed in the format
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007248 CCXBEACONREQ<space><Number of fields><space><Measurement token>
7249 <space>Channel 1<space>Scan Mode <space>Meas Duration<space>Channel N
7250 <space>Scan Mode N<space>Meas Duration N
7251 if the Number of bcn req fields (N) does not match with the actual number of fields passed
7252 then take N.
7253 <Meas Token><Channel><Scan Mode> and <Meas Duration> are treated as one pair
7254 For example, CCXBEACONREQ 2 1 1 1 30 2 44 0 40.
7255 This function does not take care of removing duplicate channels from the list
7256
7257 \param - pValue Pointer to data
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007258 \param - pEseBcnReq output pointer to store parsed ie information
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007259
7260 \return - 0 for success non-zero for failure
7261
7262 --------------------------------------------------------------------------*/
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007263static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
7264 tCsrEseBeaconReq *pEseBcnReq)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007265{
7266 tANI_U8 *inPtr = pValue;
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307267 uint8_t input = 0;
7268 uint32_t tempInt = 0;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007269 int j = 0, i = 0, v = 0;
7270 char buf[32];
7271
7272 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7273 /*no argument after the command*/
7274 if (NULL == inPtr)
7275 {
7276 return -EINVAL;
7277 }
7278 /*no space after the command*/
7279 else if (SPACE_ASCII_VALUE != *inPtr)
7280 {
7281 return -EINVAL;
7282 }
7283
7284 /*removing empty spaces*/
7285 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
7286
7287 /*no argument followed by spaces*/
7288 if ('\0' == *inPtr) return -EINVAL;
7289
7290 /*getting the first argument ie measurement token*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007291 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007292 if (1 != v) return -EINVAL;
7293
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307294 v = kstrtos8(buf, 10, &input);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007295 if ( v < 0) return -EINVAL;
7296
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307297 input = VOS_MIN(input, SIR_ESE_MAX_MEAS_IE_REQS);
7298 pEseBcnReq->numBcnReqIe = input;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007299
Srinivas Girigowda725a88e2016-03-31 19:24:25 +05307300 hddLog(LOG1, "Number of Bcn Req Ie fields: %d", pEseBcnReq->numBcnReqIe);
7301
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007302
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007303 for (j = 0; j < (pEseBcnReq->numBcnReqIe); j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007304 {
7305 for (i = 0; i < 4; i++)
7306 {
7307 /*inPtr pointing to the beginning of first space after number of ie fields*/
7308 inPtr = strpbrk( inPtr, " " );
7309 /*no ie data after the number of ie fields argument*/
7310 if (NULL == inPtr) return -EINVAL;
7311
7312 /*removing empty space*/
7313 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
7314
7315 /*no ie data after the number of ie fields argument and spaces*/
7316 if ( '\0' == *inPtr ) return -EINVAL;
7317
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007318 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007319 if (1 != v) return -EINVAL;
7320
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307321 v = kstrtou32(buf, 10, &tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007322 if (v < 0) return -EINVAL;
7323
7324 switch (i)
7325 {
7326 case 0: /* Measurement token */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307327 if (!tempInt)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007328 {
7329 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307330 "Invalid Measurement Token: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007331 return -EINVAL;
7332 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007333 pEseBcnReq->bcnReq[j].measurementToken = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007334 break;
7335
7336 case 1: /* Channel number */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307337 if ((!tempInt) ||
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007338 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7339 {
7340 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307341 "Invalid Channel Number: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007342 return -EINVAL;
7343 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007344 pEseBcnReq->bcnReq[j].channel = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007345 break;
7346
7347 case 2: /* Scan mode */
Varun Reddy Yeturu0b18d5a2013-12-04 11:42:23 -08007348 if ((tempInt < eSIR_PASSIVE_SCAN) || (tempInt > eSIR_BEACON_TABLE))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007349 {
7350 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307351 "Invalid Scan Mode(%u) Expected{0|1|2}", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007352 return -EINVAL;
7353 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007354 pEseBcnReq->bcnReq[j].scanMode= tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007355 break;
7356
7357 case 3: /* Measurement duration */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307358 if (((!tempInt) && (pEseBcnReq->bcnReq[j].scanMode != eSIR_BEACON_TABLE)) ||
7359 ((pEseBcnReq->bcnReq[j].scanMode == eSIR_BEACON_TABLE)))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007360 {
7361 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307362 "Invalid Measurement Duration: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007363 return -EINVAL;
7364 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007365 pEseBcnReq->bcnReq[j].measurementDuration = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007366 break;
7367 }
7368 }
7369 }
7370
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007371 for (j = 0; j < pEseBcnReq->numBcnReqIe; j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007372 {
7373 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05307374 "Index(%d) Measurement Token(%u)Channel(%u) Scan Mode(%u) Measurement Duration(%u)\n",
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007375 j,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007376 pEseBcnReq->bcnReq[j].measurementToken,
7377 pEseBcnReq->bcnReq[j].channel,
7378 pEseBcnReq->bcnReq[j].scanMode,
7379 pEseBcnReq->bcnReq[j].measurementDuration);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007380 }
7381
7382 return VOS_STATUS_SUCCESS;
7383}
7384
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307385struct tsm_priv {
7386 tAniTrafStrmMetrics tsm_metrics;
7387};
7388
7389static void hdd_get_tsm_stats_cb(tAniTrafStrmMetrics tsm_metrics,
7390 const tANI_U32 sta_id, void *context )
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007391{
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307392 struct hdd_request *request;
7393 struct tsm_priv *priv;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007394
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307395 ENTER();
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007396
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307397 request = hdd_request_get(context);
7398 if (!request) {
7399 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
7400 return;
7401 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007402
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307403 priv = hdd_request_priv(request);
7404 priv->tsm_metrics = tsm_metrics;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007405
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307406 hdd_request_complete(request);
7407 hdd_request_put(request);
Jeff Johnson72a40512013-12-19 10:14:15 -08007408
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307409 EXIT();
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007410}
7411
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007412static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
7413 tAniTrafStrmMetrics* pTsmMetrics)
7414{
7415 hdd_station_ctx_t *pHddStaCtx = NULL;
7416 eHalStatus hstatus;
Jeff Johnson72a40512013-12-19 10:14:15 -08007417 VOS_STATUS vstatus = VOS_STATUS_SUCCESS;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007418 hdd_context_t *pHddCtx = NULL;
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307419 int ret;
7420 void *cookie;
7421 struct hdd_request *request;
7422 struct tsm_priv *priv;
7423 static const struct hdd_request_params params = {
7424 .priv_size = sizeof(*priv),
7425 .timeout_ms = WLAN_WAIT_TIME_STATS,
7426 };
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007427
7428 if (NULL == pAdapter)
7429 {
7430 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL", __func__);
7431 return VOS_STATUS_E_FAULT;
7432 }
7433
7434 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7435 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7436
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307437 request = hdd_request_alloc(&params);
7438 if (!request) {
7439 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
7440 return VOS_STATUS_E_NOMEM;
7441 }
7442 cookie = hdd_request_cookie(request);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007443
7444 /* query tsm stats */
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307445 hstatus = sme_GetTsmStats(pHddCtx->hHal, hdd_get_tsm_stats_cb,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007446 pHddStaCtx->conn_info.staId[ 0 ],
7447 pHddStaCtx->conn_info.bssId,
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307448 cookie, pHddCtx->pvosContext, tid);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007449
7450 if (eHAL_STATUS_SUCCESS != hstatus)
7451 {
Jeff Johnson72a40512013-12-19 10:14:15 -08007452 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unable to retrieve statistics",
7453 __func__);
7454 vstatus = VOS_STATUS_E_FAULT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007455 }
7456 else
7457 {
7458 /* request was sent -- wait for the response */
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307459 ret = hdd_request_wait_for_response(request);
7460 if (ret) {
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007461 hddLog(VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307462 "SME timeout while retrieving statistics");
Jeff Johnson72a40512013-12-19 10:14:15 -08007463 vstatus = VOS_STATUS_E_TIMEOUT;
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307464 } else {
7465 priv = hdd_request_priv(request);
7466 *pTsmMetrics = priv->tsm_metrics;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007467 }
7468 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007469
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307470 hdd_request_put(request);
Jeff Johnson72a40512013-12-19 10:14:15 -08007471
Jeff Johnson72a40512013-12-19 10:14:15 -08007472 return vstatus;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007473}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007474#endif /*FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007475
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007476#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08007477void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand)
7478{
7479 eCsrBand band = -1;
7480 sme_GetFreqBand((tHalHandle)(pHddCtx->hHal), &band);
7481 switch (band)
7482 {
7483 case eCSR_BAND_ALL:
7484 *pBand = WLAN_HDD_UI_BAND_AUTO;
7485 break;
7486
7487 case eCSR_BAND_24:
7488 *pBand = WLAN_HDD_UI_BAND_2_4_GHZ;
7489 break;
7490
7491 case eCSR_BAND_5G:
7492 *pBand = WLAN_HDD_UI_BAND_5_GHZ;
7493 break;
7494
7495 default:
7496 hddLog( VOS_TRACE_LEVEL_WARN, "%s: Invalid Band %d", __func__, band);
7497 *pBand = -1;
7498 break;
7499 }
7500}
7501
7502/**---------------------------------------------------------------------------
7503
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007504 \brief hdd_parse_send_action_frame_data() - HDD Parse send action frame data
7505
7506 This function parses the send action frame data passed in the format
7507 SENDACTIONFRAME<space><bssid><space><channel><space><dwelltime><space><data>
7508
Srinivas Girigowda56076852013-08-20 14:00:50 -07007509 \param - pValue Pointer to input data
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007510 \param - pTargetApBssid Pointer to target Ap bssid
7511 \param - pChannel Pointer to the Target AP channel
7512 \param - pDwellTime Pointer to the time to stay off-channel after transmitting action frame
7513 \param - pBuf Pointer to data
7514 \param - pBufLen Pointer to data length
7515
7516 \return - 0 for success non-zero for failure
7517
7518 --------------------------------------------------------------------------*/
7519VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid, tANI_U8 *pChannel,
7520 tANI_U8 *pDwellTime, tANI_U8 **pBuf, tANI_U8 *pBufLen)
7521{
7522 tANI_U8 *inPtr = pValue;
7523 tANI_U8 *dataEnd;
7524 int tempInt;
7525 int j = 0;
7526 int i = 0;
7527 int v = 0;
7528 tANI_U8 tempBuf[32];
7529 tANI_U8 tempByte = 0;
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007530 /* 12 hexa decimal digits, 5 ':' and '\0' */
7531 tANI_U8 macAddress[18];
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007532
7533 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7534 /*no argument after the command*/
7535 if (NULL == inPtr)
7536 {
7537 return -EINVAL;
7538 }
7539
7540 /*no space after the command*/
7541 else if (SPACE_ASCII_VALUE != *inPtr)
7542 {
7543 return -EINVAL;
7544 }
7545
7546 /*removing empty spaces*/
7547 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7548
7549 /*no argument followed by spaces*/
7550 if ('\0' == *inPtr)
7551 {
7552 return -EINVAL;
7553 }
7554
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007555 v = sscanf(inPtr, "%17s", macAddress);
7556 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007557 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007558 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7559 "Invalid MAC address or All hex inputs are not read (%d)", v);
7560 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007561 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007562
7563 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
7564 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
7565 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
7566 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
7567 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
7568 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007569
7570 /* point to the next argument */
7571 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7572 /*no argument after the command*/
7573 if (NULL == inPtr) return -EINVAL;
7574
7575 /*removing empty spaces*/
7576 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7577
7578 /*no argument followed by spaces*/
7579 if ('\0' == *inPtr)
7580 {
7581 return -EINVAL;
7582 }
7583
7584 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007585 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007586 if (1 != v) return -EINVAL;
7587
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007588 v = kstrtos32(tempBuf, 10, &tempInt);
Agarwal Ashish353b3a82014-04-08 14:55:11 +05307589 if ( v < 0 || tempInt <= 0 || tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX )
Kiet Lambe150c22013-11-21 16:30:32 +05307590 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007591
7592 *pChannel = tempInt;
7593
7594 /* point to the next argument */
7595 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7596 /*no argument after the command*/
7597 if (NULL == inPtr) return -EINVAL;
7598 /*removing empty spaces*/
7599 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7600
7601 /*no argument followed by spaces*/
7602 if ('\0' == *inPtr)
7603 {
7604 return -EINVAL;
7605 }
7606
7607 /*getting the next argument ie the dwell time */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007608 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007609 if (1 != v) return -EINVAL;
7610
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007611 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda5a6e0672014-01-09 14:42:57 -08007612 if ( v < 0 || tempInt < 0) return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007613
7614 *pDwellTime = tempInt;
7615
7616 /* point to the next argument */
7617 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7618 /*no argument after the command*/
7619 if (NULL == inPtr) return -EINVAL;
7620 /*removing empty spaces*/
7621 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7622
7623 /*no argument followed by spaces*/
7624 if ('\0' == *inPtr)
7625 {
7626 return -EINVAL;
7627 }
7628
7629 /* find the length of data */
7630 dataEnd = inPtr;
7631 while(('\0' != *dataEnd) )
7632 {
7633 dataEnd++;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007634 }
Kiet Lambe150c22013-11-21 16:30:32 +05307635 *pBufLen = dataEnd - inPtr ;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007636 if ( *pBufLen <= 0) return -EINVAL;
7637
Srinivas Girigowdab5ae85d2013-06-03 10:51:45 -07007638 /* Allocate the number of bytes based on the number of input characters
7639 whether it is even or odd.
7640 if the number of input characters are even, then we need N/2 byte.
7641 if the number of input characters are odd, then we need do (N+1)/2 to
7642 compensate rounding off.
7643 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
7644 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
7645 *pBuf = vos_mem_malloc((*pBufLen + 1)/2);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007646 if (NULL == *pBuf)
7647 {
7648 hddLog(VOS_TRACE_LEVEL_FATAL,
7649 "%s: vos_mem_alloc failed ", __func__);
7650 return -EINVAL;
7651 }
7652
7653 /* the buffer received from the upper layer is character buffer,
7654 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
7655 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
7656 and f0 in 3rd location */
7657 for (i = 0, j = 0; j < *pBufLen; j += 2)
7658 {
Kiet Lambe150c22013-11-21 16:30:32 +05307659 if( j+1 == *pBufLen)
7660 {
7661 tempByte = hdd_parse_hex(inPtr[j]);
7662 }
7663 else
7664 {
7665 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
7666 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007667 (*pBuf)[i++] = tempByte;
7668 }
7669 *pBufLen = i;
7670 return VOS_STATUS_SUCCESS;
7671}
7672
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007673/**---------------------------------------------------------------------------
7674
Srinivas Girigowdade697412013-02-14 16:31:48 -08007675 \brief hdd_parse_channellist() - HDD Parse channel list
7676
7677 This function parses the channel list passed in the format
7678 SETROAMSCANCHANNELS<space><Number of channels><space>Channel 1<space>Channel 2<space>Channel N
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007679 if the Number of channels (N) does not match with the actual number of channels passed
7680 then take the minimum of N and count of (Ch1, Ch2, ...Ch M)
7681 For example, if SETROAMSCANCHANNELS 3 36 40 44 48, only 36, 40 and 44 shall be taken.
7682 If SETROAMSCANCHANNELS 5 36 40 44 48, ignore 5 and take 36, 40, 44 and 48.
7683 This function does not take care of removing duplicate channels from the list
Srinivas Girigowdade697412013-02-14 16:31:48 -08007684
7685 \param - pValue Pointer to input channel list
7686 \param - ChannelList Pointer to local output array to record channel list
7687 \param - pNumChannels Pointer to number of roam scan channels
7688
7689 \return - 0 for success non-zero for failure
7690
7691 --------------------------------------------------------------------------*/
7692VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels)
7693{
7694 tANI_U8 *inPtr = pValue;
7695 int tempInt;
7696 int j = 0;
7697 int v = 0;
7698 char buf[32];
7699
7700 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7701 /*no argument after the command*/
7702 if (NULL == inPtr)
7703 {
7704 return -EINVAL;
7705 }
7706
7707 /*no space after the command*/
7708 else if (SPACE_ASCII_VALUE != *inPtr)
7709 {
7710 return -EINVAL;
7711 }
7712
7713 /*removing empty spaces*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007714 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08007715
7716 /*no argument followed by spaces*/
7717 if ('\0' == *inPtr)
7718 {
7719 return -EINVAL;
7720 }
7721
7722 /*getting the first argument ie the number of channels*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007723 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007724 if (1 != v) return -EINVAL;
7725
Srinivas Girigowdade697412013-02-14 16:31:48 -08007726 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007727 if ((v < 0) ||
7728 (tempInt <= 0) ||
7729 (tempInt > WNI_CFG_VALID_CHANNEL_LIST_LEN))
7730 {
7731 return -EINVAL;
7732 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007733
7734 *pNumChannels = tempInt;
7735
7736 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
7737 "Number of channels are: %d", *pNumChannels);
7738
7739 for (j = 0; j < (*pNumChannels); j++)
7740 {
7741 /*inPtr pointing to the beginning of first space after number of channels*/
7742 inPtr = strpbrk( inPtr, " " );
7743 /*no channel list after the number of channels argument*/
7744 if (NULL == inPtr)
7745 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007746 if (0 != j)
7747 {
7748 *pNumChannels = j;
7749 return VOS_STATUS_SUCCESS;
7750 }
7751 else
7752 {
7753 return -EINVAL;
7754 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007755 }
7756
7757 /*removing empty space*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007758 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08007759
7760 /*no channel list after the number of channels argument and spaces*/
7761 if ( '\0' == *inPtr )
7762 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007763 if (0 != j)
7764 {
7765 *pNumChannels = j;
7766 return VOS_STATUS_SUCCESS;
7767 }
7768 else
7769 {
7770 return -EINVAL;
7771 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007772 }
7773
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007774 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007775 if (1 != v) return -EINVAL;
7776
Srinivas Girigowdade697412013-02-14 16:31:48 -08007777 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007778 if ((v < 0) ||
7779 (tempInt <= 0) ||
7780 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7781 {
7782 return -EINVAL;
7783 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007784 pChannelList[j] = tempInt;
7785
7786 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
7787 "Channel %d added to preferred channel list",
7788 pChannelList[j] );
7789 }
7790
Srinivas Girigowdade697412013-02-14 16:31:48 -08007791 return VOS_STATUS_SUCCESS;
7792}
7793
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007794
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05307795/**
7796 * hdd_parse_reassoc_command_v1_data() - HDD Parse reassoc command data
7797 * This function parses the reasoc command data passed in the format
7798 * REASSOC<space><bssid><space><channel>
7799 *
7800 * @pValue: Pointer to input data (its a NUL terminated string)
7801 * @pTargetApBssid: Pointer to target Ap bssid
7802 * @pChannel: Pointer to the Target AP channel
7803 *
7804 * Return: 0 for success non-zero for failure
7805 */
7806static int hdd_parse_reassoc_command_v1_data(const tANI_U8 *pValue,
7807 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007808{
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05307809 const tANI_U8 *inPtr = pValue;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007810 int tempInt;
7811 int v = 0;
7812 tANI_U8 tempBuf[32];
Kiet Lamaa8e15a2014-02-11 23:30:06 -08007813 /* 12 hexa decimal digits, 5 ':' and '\0' */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007814 tANI_U8 macAddress[18];
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007815
7816 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7817 /*no argument after the command*/
7818 if (NULL == inPtr)
7819 {
7820 return -EINVAL;
7821 }
7822
7823 /*no space after the command*/
7824 else if (SPACE_ASCII_VALUE != *inPtr)
7825 {
7826 return -EINVAL;
7827 }
7828
7829 /*removing empty spaces*/
7830 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7831
7832 /*no argument followed by spaces*/
7833 if ('\0' == *inPtr)
7834 {
7835 return -EINVAL;
7836 }
7837
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007838 v = sscanf(inPtr, "%17s", macAddress);
7839 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007840 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007841 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7842 "Invalid MAC address or All hex inputs are not read (%d)", v);
7843 return -EINVAL;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007844 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007845
7846 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
7847 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
7848 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
7849 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
7850 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
7851 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007852
7853 /* point to the next argument */
7854 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7855 /*no argument after the command*/
7856 if (NULL == inPtr) return -EINVAL;
7857
7858 /*removing empty spaces*/
7859 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7860
7861 /*no argument followed by spaces*/
7862 if ('\0' == *inPtr)
7863 {
7864 return -EINVAL;
7865 }
7866
7867 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007868 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007869 if (1 != v) return -EINVAL;
7870
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007871 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007872 if ((v < 0) ||
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05307873 (tempInt < 0) ||
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007874 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7875 {
7876 return -EINVAL;
7877 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007878
7879 *pChannel = tempInt;
7880 return VOS_STATUS_SUCCESS;
7881}
7882
7883#endif
7884
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007885#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007886/**---------------------------------------------------------------------------
7887
7888 \brief hdd_parse_get_cckm_ie() - HDD Parse and fetch the CCKM IE
7889
7890 This function parses the SETCCKM IE command
7891 SETCCKMIE<space><ie data>
7892
7893 \param - pValue Pointer to input data
7894 \param - pCckmIe Pointer to output cckm Ie
7895 \param - pCckmIeLen Pointer to output cckm ie length
7896
7897 \return - 0 for success non-zero for failure
7898
7899 --------------------------------------------------------------------------*/
7900VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe,
7901 tANI_U8 *pCckmIeLen)
7902{
7903 tANI_U8 *inPtr = pValue;
7904 tANI_U8 *dataEnd;
7905 int j = 0;
7906 int i = 0;
7907 tANI_U8 tempByte = 0;
7908
7909 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7910 /*no argument after the command*/
7911 if (NULL == inPtr)
7912 {
7913 return -EINVAL;
7914 }
7915
7916 /*no space after the command*/
7917 else if (SPACE_ASCII_VALUE != *inPtr)
7918 {
7919 return -EINVAL;
7920 }
7921
7922 /*removing empty spaces*/
7923 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7924
7925 /*no argument followed by spaces*/
7926 if ('\0' == *inPtr)
7927 {
7928 return -EINVAL;
7929 }
7930
7931 /* find the length of data */
7932 dataEnd = inPtr;
7933 while(('\0' != *dataEnd) )
7934 {
7935 dataEnd++;
7936 ++(*pCckmIeLen);
7937 }
7938 if ( *pCckmIeLen <= 0) return -EINVAL;
7939
7940 /* Allocate the number of bytes based on the number of input characters
7941 whether it is even or odd.
7942 if the number of input characters are even, then we need N/2 byte.
7943 if the number of input characters are odd, then we need do (N+1)/2 to
7944 compensate rounding off.
7945 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
7946 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
7947 *pCckmIe = vos_mem_malloc((*pCckmIeLen + 1)/2);
7948 if (NULL == *pCckmIe)
7949 {
7950 hddLog(VOS_TRACE_LEVEL_FATAL,
7951 "%s: vos_mem_alloc failed ", __func__);
7952 return -EINVAL;
7953 }
7954 vos_mem_zero(*pCckmIe, (*pCckmIeLen + 1)/2);
7955 /* the buffer received from the upper layer is character buffer,
7956 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
7957 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
7958 and f0 in 3rd location */
7959 for (i = 0, j = 0; j < *pCckmIeLen; j += 2)
7960 {
7961 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
7962 (*pCckmIe)[i++] = tempByte;
7963 }
7964 *pCckmIeLen = i;
7965
7966 return VOS_STATUS_SUCCESS;
7967}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007968#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007969
Jeff Johnson295189b2012-06-20 16:38:30 -07007970/**---------------------------------------------------------------------------
7971
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007972 \brief hdd_is_valid_mac_address() - Validate MAC address
7973
7974 This function validates whether the given MAC address is valid or not
7975 Expected MAC address is of the format XX:XX:XX:XX:XX:XX
7976 where X is the hexa decimal digit character and separated by ':'
7977 This algorithm works even if MAC address is not separated by ':'
7978
7979 This code checks given input string mac contains exactly 12 hexadecimal digits.
7980 and a separator colon : appears in the input string only after
7981 an even number of hex digits.
7982
7983 \param - pMacAddr pointer to the input MAC address
7984 \return - 1 for valid and 0 for invalid
7985
7986 --------------------------------------------------------------------------*/
7987
7988v_BOOL_t hdd_is_valid_mac_address(const tANI_U8 *pMacAddr)
7989{
7990 int xdigit = 0;
7991 int separator = 0;
7992 while (*pMacAddr)
7993 {
7994 if (isxdigit(*pMacAddr))
7995 {
7996 xdigit++;
7997 }
7998 else if (':' == *pMacAddr)
7999 {
8000 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
8001 break;
8002
8003 ++separator;
8004 }
8005 else
8006 {
8007 separator = -1;
8008 /* Invalid MAC found */
8009 return 0;
8010 }
8011 ++pMacAddr;
8012 }
8013 return (xdigit == 12 && (separator == 5 || separator == 0));
8014}
8015
8016/**---------------------------------------------------------------------------
8017
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308018 \brief __hdd_open() - HDD Open function
Jeff Johnson295189b2012-06-20 16:38:30 -07008019
8020 \param - dev Pointer to net_device structure
8021
8022 \return - 0 for success non-zero for failure
8023
8024 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308025int __hdd_open(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008026{
8027 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8028 hdd_context_t *pHddCtx;
8029 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8030 VOS_STATUS status;
8031 v_BOOL_t in_standby = TRUE;
8032
8033 if (NULL == pAdapter)
8034 {
8035 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05308036 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008037 return -ENODEV;
8038 }
8039
8040 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308041 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
8042 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson295189b2012-06-20 16:38:30 -07008043 if (NULL == pHddCtx)
8044 {
8045 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008046 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008047 return -ENODEV;
8048 }
8049
8050 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8051 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
8052 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008053 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
8054 {
8055 hddLog(VOS_TRACE_LEVEL_INFO, "%s: chip already out of standby",
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05308056 __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008057 in_standby = FALSE;
8058 break;
8059 }
8060 else
8061 {
8062 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8063 pAdapterNode = pNext;
8064 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008065 }
8066
8067 if (TRUE == in_standby)
8068 {
8069 if (VOS_STATUS_SUCCESS != wlan_hdd_exit_lowpower(pHddCtx, pAdapter))
8070 {
8071 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to bring "
8072 "wlan out of power save", __func__);
8073 return -EINVAL;
8074 }
8075 }
8076
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008077 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07008078 if (hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
8079 {
8080 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008081 "%s: Enabling Tx Queues", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008082 /* Enable TX queues only when we are connected */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308083 hddLog(VOS_TRACE_LEVEL_INFO, FL("Enabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008084 netif_tx_start_all_queues(dev);
8085 }
8086
8087 return 0;
8088}
8089
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308090/**---------------------------------------------------------------------------
8091
8092 \brief hdd_open() - Wrapper function for __hdd_open to protect it from SSR
8093
8094 This is called in response to ifconfig up
8095
8096 \param - dev Pointer to net_device structure
8097
8098 \return - 0 for success non-zero for failure
8099
8100 --------------------------------------------------------------------------*/
8101int hdd_open(struct net_device *dev)
8102{
8103 int ret;
8104
8105 vos_ssr_protect(__func__);
8106 ret = __hdd_open(dev);
8107 vos_ssr_unprotect(__func__);
8108
8109 return ret;
8110}
8111
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05308112int __hdd_mon_open (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008113{
8114 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308115 hdd_adapter_t *sta_adapter;
8116 hdd_context_t *hdd_ctx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008117
8118 if(pAdapter == NULL) {
8119 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008120 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08008121 return -EINVAL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008122 }
8123
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308124 if (vos_get_concurrency_mode() != VOS_STA_MON)
8125 return 0;
8126
8127 hdd_ctx = WLAN_HDD_GET_CTX(pAdapter);
8128 if (wlan_hdd_validate_context(hdd_ctx))
8129 return -EINVAL;
8130
8131 sta_adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_INFRA_STATION);
8132 if (!sta_adapter) {
8133 hddLog(LOGE, FL("No valid STA interface"));
8134 return -EINVAL;
8135 }
8136
8137 if (!test_bit(DEVICE_IFACE_OPENED, &sta_adapter->event_flags)) {
8138 hddLog(LOGE, FL("STA Interface is not OPENED"));
8139 return -EINVAL;
8140 }
8141
8142 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
8143
Jeff Johnson295189b2012-06-20 16:38:30 -07008144 return 0;
8145}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05308146
8147int hdd_mon_open (struct net_device *dev)
8148{
8149 int ret;
8150
8151 vos_ssr_protect(__func__);
8152 ret = __hdd_mon_open(dev);
8153 vos_ssr_unprotect(__func__);
8154
8155 return ret;
8156}
8157
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308158int __hdd_mon_stop (struct net_device *dev)
8159{
8160 hdd_adapter_t *mon_adapter = WLAN_HDD_GET_PRIV_PTR(dev);
8161 hdd_context_t *hdd_ctx;
8162
8163 if (vos_get_concurrency_mode() != VOS_STA_MON)
8164 return 0;
8165
8166 if(!mon_adapter) {
8167 hddLog(LOGE, FL("HDD adapter is Null"));
8168 return -EINVAL;
8169 }
8170
8171 hdd_ctx = WLAN_HDD_GET_CTX(mon_adapter);
8172 if (wlan_hdd_validate_context(hdd_ctx))
8173 return -EINVAL;
8174
8175 if (!test_bit(DEVICE_IFACE_OPENED, &mon_adapter->event_flags)) {
8176 hddLog(LOGE, FL("NETDEV Interface is not OPENED"));
8177 return -ENODEV;
8178 }
8179
8180 clear_bit(DEVICE_IFACE_OPENED, &mon_adapter->event_flags);
8181 hdd_stop_adapter(hdd_ctx, mon_adapter, VOS_FALSE);
8182
8183 return 0;
8184}
8185
Katya Nigame7b69a82015-04-28 15:24:06 +05308186int hdd_mon_stop(struct net_device *dev)
8187{
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308188 int ret;
8189
8190 vos_ssr_protect(__func__);
8191 ret = __hdd_mon_stop(dev);
8192 vos_ssr_unprotect(__func__);
8193
8194 return ret;
Katya Nigame7b69a82015-04-28 15:24:06 +05308195}
8196
Jeff Johnson295189b2012-06-20 16:38:30 -07008197/**---------------------------------------------------------------------------
8198
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308199 \brief __hdd_stop() - HDD stop function
Jeff Johnson295189b2012-06-20 16:38:30 -07008200
8201 \param - dev Pointer to net_device structure
8202
8203 \return - 0 for success non-zero for failure
8204
8205 --------------------------------------------------------------------------*/
8206
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308207int __hdd_stop (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008208{
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308209 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07008210 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8211 hdd_context_t *pHddCtx;
8212 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8213 VOS_STATUS status;
8214 v_BOOL_t enter_standby = TRUE;
8215
8216 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07008217 if (NULL == pAdapter)
8218 {
8219 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05308220 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008221 return -ENODEV;
8222 }
Sachin Ahuja9b4958f2015-01-15 21:37:00 +05308223 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308224 pAdapter->sessionId, pAdapter->device_mode));
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308225
8226 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8227 ret = wlan_hdd_validate_context(pHddCtx);
8228 if (ret)
Jeff Johnson295189b2012-06-20 16:38:30 -07008229 {
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308230 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07008231 }
8232
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308233 /* Nothing to be done if the interface is not opened */
8234 if (VOS_FALSE == test_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags))
8235 {
8236 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8237 "%s: NETDEV Interface is not OPENED", __func__);
8238 return -ENODEV;
8239 }
8240
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308241 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308242 /*
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05308243 * In STA + Monitor mode concurrency, no point in running
8244 * capture on monitor interface, when STA interface is stopped
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308245 */
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05308246 wlan_hdd_stop_mon(pHddCtx, true);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308247 }
8248
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308249 /* Make sure the interface is marked as closed */
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008250 clear_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07008251 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disabling OS Tx queues", __func__);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308252
8253 /* Disable TX on the interface, after this hard_start_xmit() will not
8254 * be called on that interface
8255 */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308256 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008257 netif_tx_disable(pAdapter->dev);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308258
8259 /* Mark the interface status as "down" for outside world */
Jeff Johnson295189b2012-06-20 16:38:30 -07008260 netif_carrier_off(pAdapter->dev);
8261
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308262 /* The interface is marked as down for outside world (aka kernel)
8263 * But the driver is pretty much alive inside. The driver needs to
8264 * tear down the existing connection on the netdev (session)
8265 * cleanup the data pipes and wait until the control plane is stabilized
8266 * for this interface. The call also needs to wait until the above
8267 * mentioned actions are completed before returning to the caller.
8268 * Notice that the hdd_stop_adapter is requested not to close the session
8269 * That is intentional to be able to scan if it is a STA/P2P interface
8270 */
8271 hdd_stop_adapter(pHddCtx, pAdapter, VOS_FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308272#ifdef FEATURE_WLAN_TDLS
8273 mutex_lock(&pHddCtx->tdls_lock);
8274#endif
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308275 /* DeInit the adapter. This ensures datapath cleanup as well */
c_hpothu002231a2015-02-05 14:58:51 +05308276 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308277#ifdef FEATURE_WLAN_TDLS
8278 mutex_unlock(&pHddCtx->tdls_lock);
8279#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008280 /* SoftAP ifaces should never go in power save mode
8281 making sure same here. */
8282 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07008283 || (WLAN_HDD_P2P_GO == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07008284 )
8285 {
8286 /* SoftAP mode, so return from here */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308287 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8288 "%s: In SAP MODE", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008289 EXIT();
8290 return 0;
8291 }
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308292 /* Find if any iface is up. If any iface is up then can't put device to
8293 * sleep/power save mode
8294 */
Jeff Johnson295189b2012-06-20 16:38:30 -07008295 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8296 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
8297 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008298 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
8299 {
8300 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Still other ifaces are up cannot "
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05308301 "put device to sleep", __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008302 enter_standby = FALSE;
8303 break;
8304 }
8305 else
8306 {
8307 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8308 pAdapterNode = pNext;
8309 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008310 }
8311
8312 if (TRUE == enter_standby)
8313 {
8314 hddLog(VOS_TRACE_LEVEL_INFO, "%s: All Interfaces are Down "
8315 "entering standby", __func__);
8316 if (VOS_STATUS_SUCCESS != wlan_hdd_enter_lowpower(pHddCtx))
8317 {
8318 /*log and return success*/
8319 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to put "
8320 "wlan in power save", __func__);
8321 }
8322 }
8323
8324 EXIT();
8325 return 0;
8326}
8327
8328/**---------------------------------------------------------------------------
8329
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308330 \brief hdd_stop() - wrapper_function for __hdd_stop to protect it from SSR
Jeff Johnson295189b2012-06-20 16:38:30 -07008331
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308332 This is called in response to ifconfig down
8333
8334 \param - dev Pointer to net_device structure
8335
8336 \return - 0 for success non-zero for failure
8337-----------------------------------------------------------------------------*/
8338int hdd_stop (struct net_device *dev)
8339{
8340 int ret;
8341
8342 vos_ssr_protect(__func__);
8343 ret = __hdd_stop(dev);
8344 vos_ssr_unprotect(__func__);
8345
8346 return ret;
8347}
8348
8349/**---------------------------------------------------------------------------
8350
8351 \brief __hdd_uninit() - HDD uninit function
Jeff Johnson295189b2012-06-20 16:38:30 -07008352
8353 \param - dev Pointer to net_device structure
8354
8355 \return - void
8356
8357 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308358static void __hdd_uninit (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008359{
8360 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308361 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008362 ENTER();
8363
8364 do
8365 {
8366 if (NULL == pAdapter)
8367 {
8368 hddLog(VOS_TRACE_LEVEL_FATAL,
8369 "%s: NULL pAdapter", __func__);
8370 break;
8371 }
8372
8373 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
8374 {
8375 hddLog(VOS_TRACE_LEVEL_FATAL,
8376 "%s: Invalid magic", __func__);
8377 break;
8378 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308379 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8380 if (NULL == pHddCtx)
Jeff Johnson295189b2012-06-20 16:38:30 -07008381 {
8382 hddLog(VOS_TRACE_LEVEL_FATAL,
8383 "%s: NULL pHddCtx", __func__);
8384 break;
8385 }
8386
8387 if (dev != pAdapter->dev)
8388 {
8389 hddLog(VOS_TRACE_LEVEL_FATAL,
8390 "%s: Invalid device reference", __func__);
8391 /* we haven't validated all cases so let this go for now */
8392 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308393#ifdef FEATURE_WLAN_TDLS
8394 mutex_lock(&pHddCtx->tdls_lock);
8395#endif
c_hpothu002231a2015-02-05 14:58:51 +05308396 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308397#ifdef FEATURE_WLAN_TDLS
8398 mutex_unlock(&pHddCtx->tdls_lock);
8399#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008400
8401 /* after uninit our adapter structure will no longer be valid */
8402 pAdapter->dev = NULL;
8403 pAdapter->magic = 0;
Manjeet Singh47ee8472016-04-11 11:57:18 +05308404 pAdapter->pHddCtx = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008405 } while (0);
8406
8407 EXIT();
8408}
8409
8410/**---------------------------------------------------------------------------
8411
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308412 \brief hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
8413
8414 This is called during the netdev unregister to uninitialize all data
8415associated with the device
8416
8417 \param - dev Pointer to net_device structure
8418
8419 \return - void
8420
8421 --------------------------------------------------------------------------*/
8422static void hdd_uninit (struct net_device *dev)
8423{
8424 vos_ssr_protect(__func__);
8425 __hdd_uninit(dev);
8426 vos_ssr_unprotect(__func__);
8427}
8428
8429/**---------------------------------------------------------------------------
8430
Jeff Johnson295189b2012-06-20 16:38:30 -07008431 \brief hdd_release_firmware() -
8432
8433 This function calls the release firmware API to free the firmware buffer.
8434
8435 \param - pFileName Pointer to the File Name.
8436 pCtx - Pointer to the adapter .
8437
8438
8439 \return - 0 for success, non zero for failure
8440
8441 --------------------------------------------------------------------------*/
8442
8443VOS_STATUS hdd_release_firmware(char *pFileName,v_VOID_t *pCtx)
8444{
8445 VOS_STATUS status = VOS_STATUS_SUCCESS;
8446 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8447 ENTER();
8448
8449
8450 if (!strcmp(WLAN_FW_FILE, pFileName)) {
8451
8452 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"%s: Loaded firmware file is %s",__func__,pFileName);
8453
8454 if(pHddCtx->fw) {
8455 release_firmware(pHddCtx->fw);
8456 pHddCtx->fw = NULL;
8457 }
8458 else
8459 status = VOS_STATUS_E_FAILURE;
8460 }
8461 else if (!strcmp(WLAN_NV_FILE,pFileName)) {
8462 if(pHddCtx->nv) {
8463 release_firmware(pHddCtx->nv);
8464 pHddCtx->nv = NULL;
8465 }
8466 else
8467 status = VOS_STATUS_E_FAILURE;
8468
8469 }
8470
8471 EXIT();
8472 return status;
8473}
8474
8475/**---------------------------------------------------------------------------
8476
8477 \brief hdd_request_firmware() -
8478
8479 This function reads the firmware file using the request firmware
8480 API and returns the the firmware data and the firmware file size.
8481
8482 \param - pfileName - Pointer to the file name.
8483 - pCtx - Pointer to the adapter .
8484 - ppfw_data - Pointer to the pointer of the firmware data.
8485 - pSize - Pointer to the file size.
8486
8487 \return - VOS_STATUS_SUCCESS for success, VOS_STATUS_E_FAILURE for failure
8488
8489 --------------------------------------------------------------------------*/
8490
8491
8492VOS_STATUS hdd_request_firmware(char *pfileName,v_VOID_t *pCtx,v_VOID_t **ppfw_data, v_SIZE_t *pSize)
8493{
8494 int status;
8495 VOS_STATUS retval = VOS_STATUS_SUCCESS;
8496 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8497 ENTER();
8498
8499 if( (!strcmp(WLAN_FW_FILE, pfileName)) ) {
8500
8501 status = request_firmware(&pHddCtx->fw, pfileName, pHddCtx->parent_dev);
8502
8503 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8504 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Firmware %s download failed",
8505 __func__, pfileName);
8506 retval = VOS_STATUS_E_FAILURE;
8507 }
8508
8509 else {
8510 *ppfw_data = (v_VOID_t *)pHddCtx->fw->data;
8511 *pSize = pHddCtx->fw->size;
8512 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Firmware size = %d",
8513 __func__, *pSize);
8514 }
8515 }
8516 else if(!strcmp(WLAN_NV_FILE, pfileName)) {
8517
8518 status = request_firmware(&pHddCtx->nv, pfileName, pHddCtx->parent_dev);
8519
8520 if(status || !pHddCtx->nv || !pHddCtx->nv->data) {
8521 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: nv %s download failed",
8522 __func__, pfileName);
8523 retval = VOS_STATUS_E_FAILURE;
8524 }
8525
8526 else {
8527 *ppfw_data = (v_VOID_t *)pHddCtx->nv->data;
8528 *pSize = pHddCtx->nv->size;
8529 hddLog(VOS_TRACE_LEVEL_INFO, "%s: nv file size = %d",
8530 __func__, *pSize);
8531 }
8532 }
8533
8534 EXIT();
8535 return retval;
8536}
8537/**---------------------------------------------------------------------------
8538 \brief hdd_full_pwr_cbk() - HDD full power callbackfunction
8539
8540 This is the function invoked by SME to inform the result of a full power
8541 request issued by HDD
8542
8543 \param - callbackcontext - Pointer to cookie
8544 status - result of request
8545
8546 \return - None
8547
8548--------------------------------------------------------------------------*/
8549void hdd_full_pwr_cbk(void *callbackContext, eHalStatus status)
8550{
8551 hdd_context_t *pHddCtx = (hdd_context_t*)callbackContext;
8552
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07008553 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"HDD full Power callback status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008554 if(&pHddCtx->full_pwr_comp_var)
8555 {
8556 complete(&pHddCtx->full_pwr_comp_var);
8557 }
8558}
8559
Abhishek Singh00b71972016-01-07 10:51:04 +05308560#ifdef WLAN_FEATURE_RMC
8561static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo)
8562{
8563 int payload_len;
8564 struct sk_buff *skb;
8565 struct nlmsghdr *nlh;
8566 v_U8_t *data;
8567
8568 payload_len = ETH_ALEN;
8569
8570 if (0 == cesium_pid)
8571 {
8572 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: cesium process not registered",
8573 __func__);
8574 return;
8575 }
8576
8577 if ((skb = nlmsg_new(payload_len,GFP_ATOMIC)) == NULL)
8578 {
8579 hddLog(VOS_TRACE_LEVEL_ERROR,
8580 "%s: nlmsg_new() failed for msg size[%d]",
8581 __func__, NLMSG_SPACE(payload_len));
8582 return;
8583 }
8584
8585 nlh = nlmsg_put(skb, cesium_pid, seqNo, 0, payload_len, NLM_F_REQUEST);
8586
8587 if (NULL == nlh)
8588 {
8589 hddLog(VOS_TRACE_LEVEL_ERROR,
8590 "%s: nlmsg_put() failed for msg size[%d]",
8591 __func__, NLMSG_SPACE(payload_len));
8592
8593 kfree_skb(skb);
8594 return;
8595 }
8596
8597 data = nlmsg_data(nlh);
8598 memcpy(data, MacAddr, ETH_ALEN);
8599
8600 if (nlmsg_unicast(cesium_nl_srv_sock, skb, cesium_pid) < 0)
8601 {
8602 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: nlmsg_unicast() failed for msg size[%d]",
8603 __func__, NLMSG_SPACE(payload_len));
8604 }
8605
8606 return;
8607}
8608
8609/**---------------------------------------------------------------------------
8610 \brief hdd_ParseuserParams - return a pointer to the next argument
8611
8612 \return - status
8613
8614--------------------------------------------------------------------------*/
8615static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg)
8616{
8617 tANI_U8 *pVal;
8618
8619 pVal = strchr(pValue, ' ');
8620
8621 if (NULL == pVal)
8622 {
8623 /* no argument remains */
8624 return -EINVAL;
8625 }
8626 else if (SPACE_ASCII_VALUE != *pVal)
8627 {
8628 /* no space after the current argument */
8629 return -EINVAL;
8630 }
8631
8632 pVal++;
8633
8634 /* remove empty spaces */
8635 while ((SPACE_ASCII_VALUE == *pVal) && ('\0' != *pVal))
8636 {
8637 pVal++;
8638 }
8639
8640 /* no argument followed by spaces */
8641 if ('\0' == *pVal)
8642 {
8643 return -EINVAL;
8644 }
8645
8646 *ppArg = pVal;
8647
8648 return 0;
8649}
8650
8651/**----------------------------------------------------------------------------
8652 \brief hdd_ParseIBSSTXFailEventParams - Parse params for SETIBSSTXFAILEVENT
8653
8654 \return - status
8655
8656------------------------------------------------------------------------------*/
8657static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
8658 tANI_U8 *tx_fail_count,
8659 tANI_U16 *pid)
8660{
8661 tANI_U8 *param = NULL;
8662 int ret;
8663
8664 ret = hdd_ParseUserParams(pValue, &param);
8665
8666 if (0 == ret && NULL != param)
8667 {
8668 if (1 != sscanf(param, "%hhu", tx_fail_count))
8669 {
8670 ret = -EINVAL;
8671 goto done;
8672 }
8673 }
8674 else
8675 {
8676 goto done;
8677 }
8678
8679 if (0 == *tx_fail_count)
8680 {
8681 *pid = 0;
8682 goto done;
8683 }
8684
8685 pValue = param;
8686 pValue++;
8687
8688 ret = hdd_ParseUserParams(pValue, &param);
8689
8690 if (0 == ret)
8691 {
8692 if (1 != sscanf(param, "%hu", pid))
8693 {
8694 ret = -EINVAL;
8695 goto done;
8696 }
8697 }
8698 else
8699 {
8700 goto done;
8701 }
8702
8703done:
8704 return ret;
8705}
8706
8707static int hdd_open_cesium_nl_sock()
8708{
8709#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
8710 struct netlink_kernel_cfg cfg = {
8711 .groups = WLAN_NLINK_MCAST_GRP_ID,
8712 .input = NULL
8713 };
8714#endif
8715 int ret = 0;
8716
8717#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
8718 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
8719#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
8720 THIS_MODULE,
8721#endif
8722 &cfg);
8723#else
8724 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
8725 WLAN_NLINK_MCAST_GRP_ID, NULL, NULL, THIS_MODULE);
8726#endif
8727
8728 if (cesium_nl_srv_sock == NULL)
8729 {
8730 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8731 "NLINK: cesium netlink_kernel_create failed");
8732 ret = -ECONNREFUSED;
8733 }
8734
8735 return ret;
8736}
8737
8738static void hdd_close_cesium_nl_sock()
8739{
8740 if (NULL != cesium_nl_srv_sock)
8741 {
8742 netlink_kernel_release(cesium_nl_srv_sock);
8743 cesium_nl_srv_sock = NULL;
8744 }
8745}
8746#endif /* WLAN_FEATURE_RMC */
Jeff Johnson295189b2012-06-20 16:38:30 -07008747/**---------------------------------------------------------------------------
8748
8749 \brief hdd_req_bmps_cbk() - HDD Request BMPS callback function
8750
8751 This is the function invoked by SME to inform the result of BMPS
8752 request issued by HDD
8753
8754 \param - callbackcontext - Pointer to cookie
8755 status - result of request
8756
8757 \return - None
8758
8759--------------------------------------------------------------------------*/
8760void hdd_req_bmps_cbk(void *callbackContext, eHalStatus status)
8761{
8762
8763 struct completion *completion_var = (struct completion*) callbackContext;
8764
Arif Hussain6d2a3322013-11-17 19:50:10 -08008765 hddLog(VOS_TRACE_LEVEL_ERROR, "HDD BMPS request Callback, status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008766 if(completion_var != NULL)
8767 {
8768 complete(completion_var);
8769 }
8770}
8771
8772/**---------------------------------------------------------------------------
8773
8774 \brief hdd_get_cfg_file_size() -
8775
8776 This function reads the configuration file using the request firmware
8777 API and returns the configuration file size.
8778
8779 \param - pCtx - Pointer to the adapter .
8780 - pFileName - Pointer to the file name.
8781 - pBufSize - Pointer to the buffer size.
8782
8783 \return - 0 for success, non zero for failure
8784
8785 --------------------------------------------------------------------------*/
8786
8787VOS_STATUS hdd_get_cfg_file_size(v_VOID_t *pCtx, char *pFileName, v_SIZE_t *pBufSize)
8788{
8789 int status;
8790 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8791
8792 ENTER();
8793
8794 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
8795
8796 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8797 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
8798 status = VOS_STATUS_E_FAILURE;
8799 }
8800 else {
8801 *pBufSize = pHddCtx->fw->size;
8802 hddLog(VOS_TRACE_LEVEL_INFO, "%s: CFG size = %d", __func__, *pBufSize);
8803 release_firmware(pHddCtx->fw);
8804 pHddCtx->fw = NULL;
8805 }
8806
8807 EXIT();
8808 return VOS_STATUS_SUCCESS;
8809}
8810
8811/**---------------------------------------------------------------------------
8812
8813 \brief hdd_read_cfg_file() -
8814
8815 This function reads the configuration file using the request firmware
8816 API and returns the cfg data and the buffer size of the configuration file.
8817
8818 \param - pCtx - Pointer to the adapter .
8819 - pFileName - Pointer to the file name.
8820 - pBuffer - Pointer to the data buffer.
8821 - pBufSize - Pointer to the buffer size.
8822
8823 \return - 0 for success, non zero for failure
8824
8825 --------------------------------------------------------------------------*/
8826
8827VOS_STATUS hdd_read_cfg_file(v_VOID_t *pCtx, char *pFileName,
8828 v_VOID_t *pBuffer, v_SIZE_t *pBufSize)
8829{
8830 int status;
8831 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8832
8833 ENTER();
8834
8835 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
8836
8837 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8838 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
8839 return VOS_STATUS_E_FAILURE;
8840 }
8841 else {
8842 if(*pBufSize != pHddCtx->fw->size) {
8843 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Caller sets invalid CFG "
8844 "file size", __func__);
8845 release_firmware(pHddCtx->fw);
8846 pHddCtx->fw = NULL;
8847 return VOS_STATUS_E_FAILURE;
8848 }
8849 else {
8850 if(pBuffer) {
8851 vos_mem_copy(pBuffer,pHddCtx->fw->data,*pBufSize);
8852 }
8853 release_firmware(pHddCtx->fw);
8854 pHddCtx->fw = NULL;
8855 }
8856 }
8857
8858 EXIT();
8859
8860 return VOS_STATUS_SUCCESS;
8861}
8862
8863/**---------------------------------------------------------------------------
8864
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308865 \brief __hdd_set_mac_address() -
Jeff Johnson295189b2012-06-20 16:38:30 -07008866
8867 This function sets the user specified mac address using
8868 the command ifconfig wlanX hw ether <mac adress>.
8869
8870 \param - dev - Pointer to the net device.
8871 - addr - Pointer to the sockaddr.
8872 \return - 0 for success, non zero for failure
8873
8874 --------------------------------------------------------------------------*/
8875
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308876static int __hdd_set_mac_address(struct net_device *dev, void *addr)
Jeff Johnson295189b2012-06-20 16:38:30 -07008877{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308878 hdd_adapter_t *pAdapter;
8879 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008880 struct sockaddr *psta_mac_addr = addr;
8881 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308882 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07008883
8884 ENTER();
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308885 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8886 if (NULL == pAdapter)
8887 {
8888 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8889 "%s: Adapter is NULL",__func__);
8890 return -EINVAL;
8891 }
8892 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8893 ret = wlan_hdd_validate_context(pHddCtx);
8894 if (0 != ret)
8895 {
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308896 return ret;
8897 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008898
8899 memcpy(&pAdapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008900 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
8901
8902 EXIT();
8903 return halStatus;
8904}
8905
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308906/**---------------------------------------------------------------------------
8907
8908 \brief hdd_set_mac_address() -
8909
8910 Wrapper function to protect __hdd_set_mac_address() function from ssr
8911
8912 \param - dev - Pointer to the net device.
8913 - addr - Pointer to the sockaddr.
8914 \return - 0 for success, non zero for failure
8915
8916 --------------------------------------------------------------------------*/
8917static int hdd_set_mac_address(struct net_device *dev, void *addr)
8918{
8919 int ret;
8920
8921 vos_ssr_protect(__func__);
8922 ret = __hdd_set_mac_address(dev, addr);
8923 vos_ssr_unprotect(__func__);
8924
8925 return ret;
8926}
8927
Jeff Johnson295189b2012-06-20 16:38:30 -07008928tANI_U8* wlan_hdd_get_intf_addr(hdd_context_t* pHddCtx)
8929{
8930 int i;
8931 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
8932 {
Abhishek Singheb183782014-02-06 13:37:21 +05308933 if( 0 == ((pHddCtx->cfg_ini->intfAddrMask) & (1 << i)) )
Jeff Johnson295189b2012-06-20 16:38:30 -07008934 break;
8935 }
8936
8937 if( VOS_MAX_CONCURRENCY_PERSONA == i)
8938 return NULL;
8939
8940 pHddCtx->cfg_ini->intfAddrMask |= (1 << i);
8941 return &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0];
8942}
8943
8944void wlan_hdd_release_intf_addr(hdd_context_t* pHddCtx, tANI_U8* releaseAddr)
8945{
8946 int i;
8947 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
8948 {
8949 if ( !memcmp(releaseAddr, &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], 6) )
8950 {
8951 pHddCtx->cfg_ini->intfAddrMask &= ~(1 << i);
8952 break;
8953 }
8954 }
8955 return;
8956}
8957
8958#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
8959 static struct net_device_ops wlan_drv_ops = {
8960 .ndo_open = hdd_open,
8961 .ndo_stop = hdd_stop,
8962 .ndo_uninit = hdd_uninit,
8963 .ndo_start_xmit = hdd_hard_start_xmit,
8964 .ndo_tx_timeout = hdd_tx_timeout,
8965 .ndo_get_stats = hdd_stats,
8966 .ndo_do_ioctl = hdd_ioctl,
8967 .ndo_set_mac_address = hdd_set_mac_address,
8968 .ndo_select_queue = hdd_select_queue,
8969#ifdef WLAN_FEATURE_PACKET_FILTERING
8970#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0))
8971 .ndo_set_rx_mode = hdd_set_multicast_list,
8972#else
8973 .ndo_set_multicast_list = hdd_set_multicast_list,
8974#endif //LINUX_VERSION_CODE
8975#endif
8976 };
Jeff Johnson295189b2012-06-20 16:38:30 -07008977 static struct net_device_ops wlan_mon_drv_ops = {
8978 .ndo_open = hdd_mon_open,
Katya Nigame7b69a82015-04-28 15:24:06 +05308979 .ndo_stop = hdd_mon_stop,
Jeff Johnson295189b2012-06-20 16:38:30 -07008980 .ndo_uninit = hdd_uninit,
8981 .ndo_start_xmit = hdd_mon_hard_start_xmit,
8982 .ndo_tx_timeout = hdd_tx_timeout,
8983 .ndo_get_stats = hdd_stats,
Katya Nigame7b69a82015-04-28 15:24:06 +05308984 .ndo_do_ioctl = hdd_mon_ioctl,
Jeff Johnson295189b2012-06-20 16:38:30 -07008985 .ndo_set_mac_address = hdd_set_mac_address,
8986 };
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +05308987
Jeff Johnson295189b2012-06-20 16:38:30 -07008988#endif
8989
8990void hdd_set_station_ops( struct net_device *pWlanDev )
8991{
8992#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
Jeff Johnson295189b2012-06-20 16:38:30 -07008993 pWlanDev->netdev_ops = &wlan_drv_ops;
8994#else
8995 pWlanDev->open = hdd_open;
8996 pWlanDev->stop = hdd_stop;
8997 pWlanDev->uninit = hdd_uninit;
8998 pWlanDev->hard_start_xmit = NULL;
8999 pWlanDev->tx_timeout = hdd_tx_timeout;
9000 pWlanDev->get_stats = hdd_stats;
9001 pWlanDev->do_ioctl = hdd_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07009002 pWlanDev->set_mac_address = hdd_set_mac_address;
9003#endif
9004}
9005
Katya Nigam1fd24402015-02-16 14:52:19 +05309006void hdd_set_ibss_ops( hdd_adapter_t *pAdapter )
9007{
9008 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
9009 wlan_drv_ops.ndo_start_xmit = hdd_ibss_hard_start_xmit;
9010 #else
9011 pAdapter->dev->hard_start_xmit = hdd_ibss_hard_start_xmit;
9012 #endif
9013}
9014
Jeff Johnsoneed415b2013-01-18 16:11:20 -08009015static hdd_adapter_t* hdd_alloc_station_adapter( hdd_context_t *pHddCtx, tSirMacAddr macAddr, const char* name )
Jeff Johnson295189b2012-06-20 16:38:30 -07009016{
9017 struct net_device *pWlanDev = NULL;
9018 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009019 /*
9020 * cfg80211 initialization and registration....
9021 */
Anand N Sunkadc34abbd2015-07-29 09:52:59 +05309022 pWlanDev = alloc_netdev_mq(sizeof( hdd_adapter_t ), name,
9023#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0))
9024 NET_NAME_UNKNOWN,
9025#endif
9026 ether_setup, NUM_TX_QUEUES);
Jeff Johnson295189b2012-06-20 16:38:30 -07009027 if(pWlanDev != NULL)
9028 {
9029
9030 //Save the pointer to the net_device in the HDD adapter
9031 pAdapter = (hdd_adapter_t*) netdev_priv( pWlanDev );
9032
Jeff Johnson295189b2012-06-20 16:38:30 -07009033 vos_mem_zero( pAdapter, sizeof( hdd_adapter_t ) );
9034
9035 pAdapter->dev = pWlanDev;
9036 pAdapter->pHddCtx = pHddCtx;
9037 pAdapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Agarwal Ashish47d18112014-08-04 19:55:07 +05309038 spin_lock_init(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -07009039
Rajeev79dbe4c2013-10-05 11:03:42 +05309040#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev79dbe4c2013-10-05 11:03:42 +05309041 pAdapter->pBatchScanRsp = NULL;
9042 pAdapter->numScanList = 0;
Rajeev Kumar20140c12013-10-21 19:39:02 -07009043 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08009044 pAdapter->prev_batch_id = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05309045 mutex_init(&pAdapter->hdd_batch_scan_lock);
9046#endif
9047
Jeff Johnson295189b2012-06-20 16:38:30 -07009048 pAdapter->isLinkUpSvcNeeded = FALSE;
9049 pAdapter->higherDtimTransition = eANI_BOOLEAN_TRUE;
9050 //Init the net_device structure
9051 strlcpy(pWlanDev->name, name, IFNAMSIZ);
9052
9053 vos_mem_copy(pWlanDev->dev_addr, (void *)macAddr, sizeof(tSirMacAddr));
9054 vos_mem_copy( pAdapter->macAddressCurrent.bytes, macAddr, sizeof(tSirMacAddr));
9055 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Alok Kumar84458542018-05-14 15:03:08 +05309056
9057 pWlanDev->needed_headroom = LIBRA_HW_NEEDED_HEADROOM;
Jeff Johnson295189b2012-06-20 16:38:30 -07009058
9059 hdd_set_station_ops( pAdapter->dev );
9060
9061 pWlanDev->destructor = free_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009062 pWlanDev->ieee80211_ptr = &pAdapter->wdev ;
9063 pAdapter->wdev.wiphy = pHddCtx->wiphy;
9064 pAdapter->wdev.netdev = pWlanDev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009065 /* set pWlanDev's parent to underlying device */
9066 SET_NETDEV_DEV(pWlanDev, pHddCtx->parent_dev);
Kumar Anand82c009f2014-05-29 00:29:42 -07009067
9068 hdd_wmm_init( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07009069 }
9070
9071 return pAdapter;
9072}
9073
9074VOS_STATUS hdd_register_interface( hdd_adapter_t *pAdapter, tANI_U8 rtnl_lock_held )
9075{
9076 struct net_device *pWlanDev = pAdapter->dev;
9077 //hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
9078 //hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
9079 //eHalStatus halStatus = eHAL_STATUS_SUCCESS;
9080
9081 if( rtnl_lock_held )
9082 {
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -08009083 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
Jeff Johnson295189b2012-06-20 16:38:30 -07009084 if( dev_alloc_name(pWlanDev, pWlanDev->name) < 0 )
9085 {
9086 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:dev_alloc_name",__func__);
9087 return VOS_STATUS_E_FAILURE;
9088 }
9089 }
9090 if (register_netdevice(pWlanDev))
9091 {
9092 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:register_netdev",__func__);
9093 return VOS_STATUS_E_FAILURE;
9094 }
9095 }
9096 else
9097 {
9098 if(register_netdev(pWlanDev))
9099 {
9100 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed:register_netdev",__func__);
9101 return VOS_STATUS_E_FAILURE;
9102 }
9103 }
9104 set_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags);
9105
9106 return VOS_STATUS_SUCCESS;
9107}
9108
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009109static eHalStatus hdd_smeCloseSessionCallback(void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07009110{
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009111 hdd_adapter_t *pAdapter = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07009112
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009113 if (NULL == pAdapter)
9114 {
9115 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: NULL pAdapter", __func__);
9116 return eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07009117 }
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009118
9119 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
9120 {
9121 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Invalid magic", __func__);
9122 return eHAL_STATUS_NOT_INITIALIZED;
9123 }
9124
9125 clear_bit(SME_SESSION_OPENED, &pAdapter->event_flags);
9126
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009127#ifndef WLAN_OPEN_SOURCE
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009128 /* need to make sure all of our scheduled work has completed.
9129 * This callback is called from MC thread context, so it is safe to
9130 * to call below flush workqueue API from here.
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009131 *
9132 * Even though this is called from MC thread context, if there is a faulty
9133 * work item in the system, that can hang this call forever. So flushing
9134 * this global work queue is not safe; and now we make sure that
9135 * individual work queues are stopped correctly. But the cancel work queue
9136 * is a GPL only API, so the proprietary version of the driver would still
9137 * rely on the global work queue flush.
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009138 */
9139 flush_scheduled_work();
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009140#endif
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009141
9142 /* We can be blocked while waiting for scheduled work to be
9143 * flushed, and the adapter structure can potentially be freed, in
9144 * which case the magic will have been reset. So make sure the
9145 * magic is still good, and hence the adapter structure is still
9146 * valid, before signaling completion */
9147 if (WLAN_HDD_ADAPTER_MAGIC == pAdapter->magic)
9148 {
9149 complete(&pAdapter->session_close_comp_var);
9150 }
9151
Jeff Johnson295189b2012-06-20 16:38:30 -07009152 return eHAL_STATUS_SUCCESS;
9153}
Manjeet Singh47ee8472016-04-11 11:57:18 +05309154/**
9155 * hdd_close_tx_queues() - close tx queues
9156 * @hdd_ctx: hdd global context
9157 *
9158 * Return: None
9159 */
9160static void hdd_close_tx_queues(hdd_context_t *hdd_ctx)
9161{
9162 VOS_STATUS status;
9163 hdd_adapter_t *adapter;
9164 hdd_adapter_list_node_t *adapter_node = NULL, *next_adapter = NULL;
9165 /* Not validating hdd_ctx as it's already done by the caller */
9166 ENTER();
9167 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9168 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status) {
9169 adapter = adapter_node->pAdapter;
9170 if (adapter && adapter->dev) {
9171 netif_tx_disable (adapter->dev);
9172 netif_carrier_off(adapter->dev);
9173 }
9174 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
9175 &next_adapter);
9176 adapter_node = next_adapter;
9177 }
9178 EXIT();
9179}
Jeff Johnson295189b2012-06-20 16:38:30 -07009180
9181VOS_STATUS hdd_init_station_mode( hdd_adapter_t *pAdapter )
9182{
9183 struct net_device *pWlanDev = pAdapter->dev;
9184 hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
9185 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
9186 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
9187 VOS_STATUS status = VOS_STATUS_E_FAILURE;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309188 long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07009189
Nirav Shah7e3c8132015-06-22 23:51:42 +05309190 spin_lock_init( &pAdapter->sta_hash_lock);
9191 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
9192
Jeff Johnson295189b2012-06-20 16:38:30 -07009193 INIT_COMPLETION(pAdapter->session_open_comp_var);
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07009194 sme_SetCurrDeviceMode(pHddCtx->hHal, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07009195 //Open a SME session for future operation
9196 halStatus = sme_OpenSession( pHddCtx->hHal, hdd_smeRoamCallback, pAdapter,
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07009197 (tANI_U8 *)&pAdapter->macAddressCurrent, &pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07009198 if ( !HAL_STATUS_SUCCESS( halStatus ) )
9199 {
9200 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009201 "sme_OpenSession() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009202 halStatus, halStatus );
9203 status = VOS_STATUS_E_FAILURE;
9204 goto error_sme_open;
9205 }
9206
9207 //Block on a completion variable. Can't wait forever though.
Vinay Krishna Eranna0fe2e7c2014-04-09 21:32:08 +05309208 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07009209 &pAdapter->session_open_comp_var,
9210 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309211 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07009212 {
9213 hddLog(VOS_TRACE_LEVEL_FATAL,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309214 "Session is not opened within timeout period code %ld", rc );
Jeff Johnson295189b2012-06-20 16:38:30 -07009215 status = VOS_STATUS_E_FAILURE;
9216 goto error_sme_open;
9217 }
9218
9219 // Register wireless extensions
9220 if( eHAL_STATUS_SUCCESS != (halStatus = hdd_register_wext(pWlanDev)))
9221 {
9222 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009223 "hdd_register_wext() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009224 halStatus, halStatus );
9225 status = VOS_STATUS_E_FAILURE;
9226 goto error_register_wext;
9227 }
Katya Nigam1fd24402015-02-16 14:52:19 +05309228
Jeff Johnson295189b2012-06-20 16:38:30 -07009229 //Safe to register the hard_start_xmit function again
Katya Nigam1fd24402015-02-16 14:52:19 +05309230 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
9231 wlan_drv_ops.ndo_start_xmit = hdd_hard_start_xmit;
9232 #else
9233 pWlanDev->hard_start_xmit = hdd_hard_start_xmit;
9234 #endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009235
9236 //Set the Connection State to Not Connected
Abhishek Singhf4669da2014-05-26 15:07:49 +05309237 hddLog(VOS_TRACE_LEVEL_INFO,
9238 "%s: Set HDD connState to eConnectionState_NotConnected",
9239 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009240 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
9241
9242 //Set the default operation channel
9243 pHddStaCtx->conn_info.operationChannel = pHddCtx->cfg_ini->OperatingChannel;
9244
9245 /* Make the default Auth Type as OPEN*/
9246 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
9247
9248 if( VOS_STATUS_SUCCESS != ( status = hdd_init_tx_rx( pAdapter ) ) )
9249 {
9250 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009251 "hdd_init_tx_rx() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009252 status, status );
9253 goto error_init_txrx;
9254 }
9255
9256 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9257
9258 if( VOS_STATUS_SUCCESS != ( status = hdd_wmm_adapter_init( pAdapter ) ) )
9259 {
9260 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009261 "hdd_wmm_adapter_init() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009262 status, status );
9263 goto error_wmm_init;
9264 }
9265
9266 set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9267
9268 return VOS_STATUS_SUCCESS;
9269
9270error_wmm_init:
9271 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9272 hdd_deinit_tx_rx(pAdapter);
9273error_init_txrx:
9274 hdd_UnregisterWext(pWlanDev);
9275error_register_wext:
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009276 if (test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07009277 {
9278 INIT_COMPLETION(pAdapter->session_close_comp_var);
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009279 if (eHAL_STATUS_SUCCESS == sme_CloseSession(pHddCtx->hHal,
Agrawal Ashish5a3522c2016-03-02 15:08:28 +05309280 pAdapter->sessionId, FALSE, VOS_TRUE,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009281 hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07009282 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309283 unsigned long rc;
9284
Jeff Johnson295189b2012-06-20 16:38:30 -07009285 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309286 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07009287 &pAdapter->session_close_comp_var,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009288 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309289 if (rc <= 0)
9290 hddLog(VOS_TRACE_LEVEL_ERROR,
9291 FL("Session is not opened within timeout period code %ld"), rc);
Jeff Johnson295189b2012-06-20 16:38:30 -07009292 }
9293}
9294error_sme_open:
9295 return status;
9296}
9297
Jeff Johnson295189b2012-06-20 16:38:30 -07009298void hdd_cleanup_actionframe( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
9299{
9300 hdd_cfg80211_state_t *cfgState;
9301
9302 cfgState = WLAN_HDD_GET_CFG_STATE_PTR( pAdapter );
9303
9304 if( NULL != cfgState->buf )
9305 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309306 long rc;
Jeff Johnson295189b2012-06-20 16:38:30 -07009307 INIT_COMPLETION(pAdapter->tx_action_cnf_event);
9308 rc = wait_for_completion_interruptible_timeout(
9309 &pAdapter->tx_action_cnf_event,
9310 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309311 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07009312 {
Deepthi Gowri91b3e9c2015-08-25 13:14:58 +05309313 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9314 "%s ERROR: HDD Wait for Action Confirmation Failed!! %ld"
9315 , __func__, rc);
9316
9317 // Inform tx status as FAILURE to upper layer and free cfgState->buf
9318 hdd_sendActionCnf( pAdapter, FALSE );
Jeff Johnson295189b2012-06-20 16:38:30 -07009319 }
9320 }
9321 return;
9322}
Jeff Johnson295189b2012-06-20 16:38:30 -07009323
c_hpothu002231a2015-02-05 14:58:51 +05309324void hdd_deinit_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
Jeff Johnson295189b2012-06-20 16:38:30 -07009325{
9326 ENTER();
9327 switch ( pAdapter->device_mode )
9328 {
Katya Nigam1fd24402015-02-16 14:52:19 +05309329 case WLAN_HDD_IBSS:
9330 {
9331 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9332 {
9333 hdd_ibss_deinit_tx_rx( pAdapter );
9334 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9335 }
9336 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009337 case WLAN_HDD_INFRA_STATION:
9338 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009339 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07009340 {
9341 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9342 {
9343 hdd_deinit_tx_rx( pAdapter );
9344 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9345 }
9346
9347 if(test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
9348 {
9349 hdd_wmm_adapter_close( pAdapter );
9350 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9351 }
9352
Jeff Johnson295189b2012-06-20 16:38:30 -07009353 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009354 break;
9355 }
9356
9357 case WLAN_HDD_SOFTAP:
9358 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009359 {
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05309360
9361 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
9362 {
9363 hdd_wmm_adapter_close( pAdapter );
9364 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9365 }
9366
Jeff Johnson295189b2012-06-20 16:38:30 -07009367 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009368
c_hpothu002231a2015-02-05 14:58:51 +05309369 hdd_unregister_hostapd(pAdapter, rtnl_held);
Agrawal Ashisha0584d42016-09-29 13:03:45 +05309370 /* set con_mode to STA only when no SAP concurrency mode */
9371 if (!(hdd_get_concurrency_mode() & (VOS_SAP | VOS_P2P_GO)))
9372 hdd_set_conparam(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07009373 break;
9374 }
9375
9376 case WLAN_HDD_MONITOR:
9377 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009378 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9379 {
9380 hdd_deinit_tx_rx( pAdapter );
9381 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9382 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009383 break;
9384 }
9385
9386
9387 default:
9388 break;
9389 }
9390
9391 EXIT();
9392}
9393
9394void hdd_cleanup_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
9395{
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08009396 struct net_device *pWlanDev = NULL;
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309397
9398 ENTER();
9399 if (NULL == pAdapter)
9400 {
9401 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9402 "%s: HDD adapter is Null", __func__);
9403 return;
9404 }
9405
9406 pWlanDev = pAdapter->dev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009407
Rajeev79dbe4c2013-10-05 11:03:42 +05309408#ifdef FEATURE_WLAN_BATCH_SCAN
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309409 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
9410 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Rajeev Kumarf999e582014-01-09 17:33:29 -08009411 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309412 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
9413 )
9414 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08009415 if (pAdapter)
Rajeev79dbe4c2013-10-05 11:03:42 +05309416 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08009417 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
9418 {
9419 hdd_deinit_batch_scan(pAdapter);
9420 }
Rajeev79dbe4c2013-10-05 11:03:42 +05309421 }
Rajeev Kumarf999e582014-01-09 17:33:29 -08009422 }
Rajeev79dbe4c2013-10-05 11:03:42 +05309423#endif
9424
Jeff Johnson295189b2012-06-20 16:38:30 -07009425 if(test_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags)) {
9426 if( rtnl_held )
9427 {
9428 unregister_netdevice(pWlanDev);
9429 }
9430 else
9431 {
9432 unregister_netdev(pWlanDev);
9433 }
9434 // note that the pAdapter is no longer valid at this point
9435 // since the memory has been reclaimed
9436 }
9437
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309438 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07009439}
9440
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009441void hdd_set_pwrparams(hdd_context_t *pHddCtx)
9442{
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309443 VOS_STATUS status;
9444 hdd_adapter_t *pAdapter = NULL;
9445 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009446
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309447 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009448
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309449 /*loop through all adapters.*/
9450 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009451 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309452 pAdapter = pAdapterNode->pAdapter;
9453 if ( (WLAN_HDD_INFRA_STATION != pAdapter->device_mode)
9454 && (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009455
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309456 { // we skip this registration for modes other than STA and P2P client modes.
9457 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9458 pAdapterNode = pNext;
9459 continue;
9460 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009461
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309462 //Apply Dynamic DTIM For P2P
9463 //Only if ignoreDynamicDtimInP2pMode is not set in ini
9464 if ((pHddCtx->cfg_ini->enableDynamicDTIM ||
9465 pHddCtx->cfg_ini->enableModulatedDTIM) &&
9466 ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
9467 ((WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) &&
9468 !(pHddCtx->cfg_ini->ignoreDynamicDtimInP2pMode))) &&
9469 (eANI_BOOLEAN_TRUE == pAdapter->higherDtimTransition) &&
9470 (eConnectionState_Associated ==
9471 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState) &&
9472 (pHddCtx->cfg_ini->fIsBmpsEnabled))
9473 {
9474 tSirSetPowerParamsReq powerRequest = { 0 };
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009475
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309476 powerRequest.uIgnoreDTIM = 1;
9477 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
9478
9479 if (pHddCtx->cfg_ini->enableModulatedDTIM)
9480 {
9481 powerRequest.uDTIMPeriod = pHddCtx->cfg_ini->enableModulatedDTIM;
9482 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
9483 }
9484 else
9485 {
9486 powerRequest.uListenInterval = pHddCtx->cfg_ini->enableDynamicDTIM;
9487 }
9488
9489 /* Update ignoreDTIM and ListedInterval in CFG to remain at the DTIM
9490 * specified during Enter/Exit BMPS when LCD off*/
9491 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
9492 NULL, eANI_BOOLEAN_FALSE);
9493 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
9494 NULL, eANI_BOOLEAN_FALSE);
9495
9496 /* switch to the DTIM specified in cfg.ini */
9497 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Abhishek Singh1e390cf2015-10-27 13:45:17 +05309498 "Switch to DTIM %d Listen interval %d",
9499 powerRequest.uDTIMPeriod,
9500 powerRequest.uListenInterval);
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309501 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
9502 break;
9503
9504 }
9505
9506 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9507 pAdapterNode = pNext;
9508 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009509}
9510
9511void hdd_reset_pwrparams(hdd_context_t *pHddCtx)
9512{
9513 /*Switch back to DTIM 1*/
9514 tSirSetPowerParamsReq powerRequest = { 0 };
9515
9516 powerRequest.uIgnoreDTIM = pHddCtx->hdd_actual_ignore_DTIM_value;
9517 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
Yue Mac24062f2013-05-13 17:01:29 -07009518 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009519
9520 /* Update ignoreDTIM and ListedInterval in CFG with default values */
9521 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
9522 NULL, eANI_BOOLEAN_FALSE);
9523 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
9524 NULL, eANI_BOOLEAN_FALSE);
9525
9526 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9527 "Switch to DTIM%d",powerRequest.uListenInterval);
9528 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
9529
9530}
9531
Jeff Johnson295189b2012-06-20 16:38:30 -07009532VOS_STATUS hdd_enable_bmps_imps(hdd_context_t *pHddCtx)
9533{
9534 VOS_STATUS status = VOS_STATUS_SUCCESS;
Sushant Kaushik4928e542014-12-29 15:25:54 +05309535 if (WLAN_HDD_IS_UNLOAD_IN_PROGRESS(pHddCtx))
9536 {
9537 hddLog( LOGE, FL("Wlan Unload in progress"));
9538 return VOS_STATUS_E_PERM;
9539 }
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309540
9541 if (wlan_hdd_check_monitor_state(pHddCtx)) {
9542 hddLog(LOG1, FL("Monitor mode is started, cannot enable BMPS"));
9543 return VOS_STATUS_SUCCESS;
9544 }
9545
Jeff Johnson295189b2012-06-20 16:38:30 -07009546 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
9547 {
9548 sme_EnablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
9549 }
9550
9551 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
9552 {
9553 sme_StartAutoBmpsTimer(pHddCtx->hHal);
9554 }
9555
9556 if (pHddCtx->cfg_ini->fIsImpsEnabled)
9557 {
9558 sme_EnablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
9559 }
9560
9561 return status;
9562}
9563
9564VOS_STATUS hdd_disable_bmps_imps(hdd_context_t *pHddCtx, tANI_U8 session_type)
9565{
9566 hdd_adapter_t *pAdapter = NULL;
9567 eHalStatus halStatus;
9568 VOS_STATUS status = VOS_STATUS_E_INVAL;
9569 v_BOOL_t disableBmps = FALSE;
9570 v_BOOL_t disableImps = FALSE;
9571
9572 switch(session_type)
9573 {
9574 case WLAN_HDD_INFRA_STATION:
9575 case WLAN_HDD_SOFTAP:
Jeff Johnson295189b2012-06-20 16:38:30 -07009576 case WLAN_HDD_P2P_CLIENT:
9577 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009578 //Exit BMPS -> Is Sta/P2P Client is already connected
9579 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
9580 if((NULL != pAdapter)&&
9581 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
9582 {
9583 disableBmps = TRUE;
9584 }
9585
9586 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_CLIENT);
9587 if((NULL != pAdapter)&&
9588 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
9589 {
9590 disableBmps = TRUE;
9591 }
9592
9593 //Exit both Bmps and Imps incase of Go/SAP Mode
9594 if((WLAN_HDD_SOFTAP == session_type) ||
9595 (WLAN_HDD_P2P_GO == session_type))
9596 {
9597 disableBmps = TRUE;
9598 disableImps = TRUE;
9599 }
9600
9601 if(TRUE == disableImps)
9602 {
9603 if (pHddCtx->cfg_ini->fIsImpsEnabled)
9604 {
9605 sme_DisablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
9606 }
9607 }
9608
9609 if(TRUE == disableBmps)
9610 {
9611 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
9612 {
9613 halStatus = sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
9614
9615 if(eHAL_STATUS_SUCCESS != halStatus)
9616 {
9617 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009618 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Disable Power Save", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009619 VOS_ASSERT(0);
9620 return status;
9621 }
9622 }
9623
9624 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
9625 {
9626 halStatus = sme_StopAutoBmpsTimer(pHddCtx->hHal);
9627
9628 if(eHAL_STATUS_SUCCESS != halStatus)
9629 {
9630 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009631 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Stop Auto Bmps Timer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009632 VOS_ASSERT(0);
9633 return status;
9634 }
9635 }
9636 }
9637
9638 if((TRUE == disableBmps) ||
9639 (TRUE == disableImps))
9640 {
9641 /* Now, get the chip into Full Power now */
9642 INIT_COMPLETION(pHddCtx->full_pwr_comp_var);
9643 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_pwr_cbk,
9644 pHddCtx, eSME_FULL_PWR_NEEDED_BY_HDD);
9645
9646 if(halStatus != eHAL_STATUS_SUCCESS)
9647 {
9648 if(halStatus == eHAL_STATUS_PMC_PENDING)
9649 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309650 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07009651 //Block on a completion variable. Can't wait forever though
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309652 ret = wait_for_completion_interruptible_timeout(
9653 &pHddCtx->full_pwr_comp_var,
9654 msecs_to_jiffies(1000));
9655 if (ret <= 0)
9656 {
9657 hddLog(VOS_TRACE_LEVEL_ERROR,
9658 "%s: wait on full_pwr_comp_var failed %ld",
9659 __func__, ret);
9660 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009661 }
9662 else
9663 {
9664 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009665 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Request for Full Power failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009666 VOS_ASSERT(0);
9667 return status;
9668 }
9669 }
9670
9671 status = VOS_STATUS_SUCCESS;
9672 }
9673
9674 break;
9675 }
9676 return status;
9677}
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309678
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309679void hdd_mon_post_msg_cb(void *context)
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309680{
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309681 struct hdd_request *request;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309682
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309683 request = hdd_request_get(context);
9684 if (!request) {
9685 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
9686 return;
9687 }
9688
9689 hdd_request_complete(request);
9690 hdd_request_put(request);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309691}
9692
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309693
Katya Nigame7b69a82015-04-28 15:24:06 +05309694void hdd_init_mon_mode (hdd_adapter_t *pAdapter)
9695 {
9696 hdd_mon_ctx_t *pMonCtx = NULL;
Katya Nigame7b69a82015-04-28 15:24:06 +05309697
Rajeev Kumar Sirasanagandla54447612018-03-06 15:49:56 +05309698 spin_lock_init(&pAdapter->sta_hash_lock);
9699 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
9700
9701 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
Katya Nigame7b69a82015-04-28 15:24:06 +05309702 pMonCtx->state = 0;
9703 pMonCtx->ChannelNo = 1;
9704 pMonCtx->ChannelBW = 20;
Katya Nigamd7d3a1f2015-06-11 14:04:24 +05309705 pMonCtx->crcCheckEnabled = 1;
9706 pMonCtx->typeSubtypeBitmap = 0xFFFF00000000;
9707 pMonCtx->is80211to803ConReq = 1;
Katya Nigame7b69a82015-04-28 15:24:06 +05309708 pMonCtx->numOfMacFilters = 0;
9709 }
9710
Jeff Johnson295189b2012-06-20 16:38:30 -07009711
9712hdd_adapter_t* hdd_open_adapter( hdd_context_t *pHddCtx, tANI_U8 session_type,
Jeff Johnsoneed415b2013-01-18 16:11:20 -08009713 const char *iface_name, tSirMacAddr macAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -07009714 tANI_U8 rtnl_held )
9715{
9716 hdd_adapter_t *pAdapter = NULL;
9717 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
9718 VOS_STATUS status = VOS_STATUS_E_FAILURE;
9719 VOS_STATUS exitbmpsStatus;
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309720 v_CONTEXT_t pVosContext = NULL;
9721
9722 /* No need to check for NULL, reaching this step
9723 * means vos context is initialized
9724 */
9725 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
Jeff Johnson295189b2012-06-20 16:38:30 -07009726
Arif Hussain6d2a3322013-11-17 19:50:10 -08009727 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s iface =%s type = %d",__func__,iface_name,session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009728
Nirav Shah436658f2014-02-28 17:05:45 +05309729 if(macAddr == NULL)
9730 {
9731 /* Not received valid macAddr */
9732 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9733 "%s:Unable to add virtual intf: Not able to get"
9734 "valid mac address",__func__);
9735 return NULL;
9736 }
9737
Jeff Johnson295189b2012-06-20 16:38:30 -07009738 //Disable BMPS incase of Concurrency
9739 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, session_type);
9740
9741 if(VOS_STATUS_E_FAILURE == exitbmpsStatus)
9742 {
9743 //Fail to Exit BMPS
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309744 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Exit BMPS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009745 VOS_ASSERT(0);
9746 return NULL;
9747 }
9748
9749 switch(session_type)
9750 {
9751 case WLAN_HDD_INFRA_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07009752 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009753 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07009754 {
9755 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9756
9757 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309758 {
9759 hddLog(VOS_TRACE_LEVEL_FATAL,
9760 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009761 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309762 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009763
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309764#ifdef FEATURE_WLAN_TDLS
9765 /* A Mutex Lock is introduced while changing/initializing the mode to
9766 * protect the concurrent access for the Adapters by TDLS module.
9767 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05309768 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309769#endif
9770
Jeff Johnsone7245742012-09-05 17:12:55 -07009771 pAdapter->wdev.iftype = (session_type == WLAN_HDD_P2P_CLIENT) ?
9772 NL80211_IFTYPE_P2P_CLIENT:
9773 NL80211_IFTYPE_STATION;
Jeff Johnson295189b2012-06-20 16:38:30 -07009774
Jeff Johnson295189b2012-06-20 16:38:30 -07009775 pAdapter->device_mode = session_type;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309776#ifdef FEATURE_WLAN_TDLS
9777 mutex_unlock(&pHddCtx->tdls_lock);
9778#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05309779
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309780 hdd_initialize_adapter_common(pAdapter);
Sunil Dutt66485cb2013-12-19 19:05:03 +05309781 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07009782 if( VOS_STATUS_SUCCESS != status )
9783 goto err_free_netdev;
9784
9785 status = hdd_register_interface( pAdapter, rtnl_held );
9786 if( VOS_STATUS_SUCCESS != status )
9787 {
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05309788#ifdef FEATURE_WLAN_TDLS
9789 mutex_lock(&pHddCtx->tdls_lock);
9790#endif
c_hpothu002231a2015-02-05 14:58:51 +05309791 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05309792#ifdef FEATURE_WLAN_TDLS
9793 mutex_unlock(&pHddCtx->tdls_lock);
9794#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009795 goto err_free_netdev;
9796 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309797
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05309798 // Workqueue which gets scheduled in IPv4 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309799 vos_init_work(&pAdapter->ipv4NotifierWorkQueue, hdd_ipv4_notifier_work_queue);
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05309800
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309801#ifdef WLAN_NS_OFFLOAD
9802 // Workqueue which gets scheduled in IPv6 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309803 vos_init_work(&pAdapter->ipv6NotifierWorkQueue, hdd_ipv6_notifier_work_queue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309804#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009805 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309806 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009807 netif_tx_disable(pAdapter->dev);
9808 //netif_tx_disable(pWlanDev);
9809 netif_carrier_off(pAdapter->dev);
9810
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309811 if (WLAN_HDD_P2P_CLIENT == session_type ||
9812 WLAN_HDD_P2P_DEVICE == session_type)
9813 {
9814 /* Initialize the work queue to defer the
9815 * back to back RoC request */
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309816 vos_init_delayed_work(&pAdapter->roc_work,
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309817 hdd_p2p_roc_work_queue);
9818 }
9819
Jeff Johnson295189b2012-06-20 16:38:30 -07009820 break;
9821 }
9822
Jeff Johnson295189b2012-06-20 16:38:30 -07009823 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009824 case WLAN_HDD_SOFTAP:
9825 {
9826 pAdapter = hdd_wlan_create_ap_dev( pHddCtx, macAddr, (tANI_U8 *)iface_name );
9827 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309828 {
9829 hddLog(VOS_TRACE_LEVEL_FATAL,
9830 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009831 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309832 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009833
Jeff Johnson295189b2012-06-20 16:38:30 -07009834 pAdapter->wdev.iftype = (session_type == WLAN_HDD_SOFTAP) ?
9835 NL80211_IFTYPE_AP:
9836 NL80211_IFTYPE_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07009837 pAdapter->device_mode = session_type;
9838
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309839 hdd_initialize_adapter_common(pAdapter);
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +05309840 status = hdd_init_ap_mode(pAdapter, false);
Jeff Johnson295189b2012-06-20 16:38:30 -07009841 if( VOS_STATUS_SUCCESS != status )
9842 goto err_free_netdev;
9843
Nirav Shah7e3c8132015-06-22 23:51:42 +05309844 status = hdd_sta_id_hash_attach(pAdapter);
9845 if (VOS_STATUS_SUCCESS != status)
9846 {
9847 hddLog(VOS_TRACE_LEVEL_FATAL,
9848 FL("failed to attach hash for session %d"), session_type);
9849 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
9850 goto err_free_netdev;
9851 }
9852
Jeff Johnson295189b2012-06-20 16:38:30 -07009853 status = hdd_register_hostapd( pAdapter, rtnl_held );
9854 if( VOS_STATUS_SUCCESS != status )
9855 {
c_hpothu002231a2015-02-05 14:58:51 +05309856 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Jeff Johnson295189b2012-06-20 16:38:30 -07009857 goto err_free_netdev;
9858 }
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309859 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009860 netif_tx_disable(pAdapter->dev);
9861 netif_carrier_off(pAdapter->dev);
9862
9863 hdd_set_conparam( 1 );
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309864
Hanumanth Reddy Pothulab4537b82018-03-02 12:20:38 +05309865 // Workqueue which gets scheduled in IPv4 notification callback.
9866 vos_init_work(&pAdapter->ipv4NotifierWorkQueue,
9867 hdd_ipv4_notifier_work_queue);
9868
9869#ifdef WLAN_NS_OFFLOAD
9870 // Workqueue which gets scheduled in IPv6 notification callback.
9871 vos_init_work(&pAdapter->ipv6NotifierWorkQueue,
9872 hdd_ipv6_notifier_work_queue);
9873#endif
9874
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309875 if (WLAN_HDD_P2P_GO == session_type)
9876 {
9877 /* Initialize the work queue to
9878 * defer the back to back RoC request */
9879 INIT_DELAYED_WORK(&pAdapter->roc_work,
9880 hdd_p2p_roc_work_queue);
9881 }
Bhargav Shahd0715912015-10-01 18:17:37 +05309882
Jeff Johnson295189b2012-06-20 16:38:30 -07009883 break;
9884 }
9885 case WLAN_HDD_MONITOR:
9886 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009887 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9888 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309889 {
9890 hddLog(VOS_TRACE_LEVEL_FATAL,
9891 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009892 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309893 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009894
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309895 pAdapter->device_mode = session_type;
9896 pAdapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
9897
Katya Nigame7b69a82015-04-28 15:24:06 +05309898 // Register wireless extensions
9899 if( VOS_STATUS_SUCCESS != (status = hdd_register_wext(pAdapter->dev)))
9900 {
9901 hddLog(VOS_TRACE_LEVEL_FATAL,
9902 "hdd_register_wext() failed with status code %08d [x%08x]",
9903 status, status );
9904 status = VOS_STATUS_E_FAILURE;
9905 }
9906
Jeff Johnson295189b2012-06-20 16:38:30 -07009907#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29)
9908 pAdapter->dev->netdev_ops = &wlan_mon_drv_ops;
9909#else
9910 pAdapter->dev->open = hdd_mon_open;
9911 pAdapter->dev->hard_start_xmit = hdd_mon_hard_start_xmit;
Katya Nigame7b69a82015-04-28 15:24:06 +05309912 pAdapter->dev->stop = hdd_mon_stop;
9913 pAdapter->dev->do_ioctl = hdd_mon_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07009914#endif
Katya Nigame7b69a82015-04-28 15:24:06 +05309915 hdd_init_mon_mode( pAdapter );
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309916 hdd_initialize_adapter_common(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009917 hdd_init_tx_rx( pAdapter );
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309918
9919 if (VOS_MONITOR_MODE != hdd_get_conparam())
9920 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
9921
Jeff Johnson295189b2012-06-20 16:38:30 -07009922 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309923 status = hdd_register_interface( pAdapter, rtnl_held );
Katya Nigame7b69a82015-04-28 15:24:06 +05309924 //Stop the Interface TX queue.
9925 netif_tx_disable(pAdapter->dev);
9926 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07009927 }
9928 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07009929 case WLAN_HDD_FTM:
9930 {
9931 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9932
9933 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309934 {
9935 hddLog(VOS_TRACE_LEVEL_FATAL,
9936 FL("failed to allocate adapter for session %d"), session_type);
9937 return NULL;
9938 }
9939
Jeff Johnson295189b2012-06-20 16:38:30 -07009940 /* Assign NL80211_IFTYPE_STATION as interface type to resolve Kernel Warning
9941 * message while loading driver in FTM mode. */
9942 pAdapter->wdev.iftype = NL80211_IFTYPE_STATION;
9943 pAdapter->device_mode = session_type;
9944 status = hdd_register_interface( pAdapter, rtnl_held );
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05309945
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309946 hdd_initialize_adapter_common(pAdapter);
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05309947 hdd_init_tx_rx( pAdapter );
9948
9949 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309950 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05309951 netif_tx_disable(pAdapter->dev);
9952 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07009953 }
9954 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07009955 default:
9956 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309957 hddLog(VOS_TRACE_LEVEL_FATAL,"%s Invalid session type %d",
9958 __func__, session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009959 VOS_ASSERT(0);
9960 return NULL;
9961 }
9962 }
9963
Jeff Johnson295189b2012-06-20 16:38:30 -07009964 if( VOS_STATUS_SUCCESS == status )
9965 {
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309966 //Add it to the hdd's session list.
Jeff Johnson295189b2012-06-20 16:38:30 -07009967 pHddAdapterNode = vos_mem_malloc( sizeof( hdd_adapter_list_node_t ) );
9968 if( NULL == pHddAdapterNode )
9969 {
9970 status = VOS_STATUS_E_NOMEM;
9971 }
9972 else
9973 {
9974 pHddAdapterNode->pAdapter = pAdapter;
9975 status = hdd_add_adapter_back ( pHddCtx,
9976 pHddAdapterNode );
9977 }
9978 }
9979
9980 if( VOS_STATUS_SUCCESS != status )
9981 {
9982 if( NULL != pAdapter )
9983 {
9984 hdd_cleanup_adapter( pHddCtx, pAdapter, rtnl_held );
9985 pAdapter = NULL;
9986 }
9987 if( NULL != pHddAdapterNode )
9988 {
9989 vos_mem_free( pHddAdapterNode );
9990 }
9991
9992 goto resume_bmps;
9993 }
9994
9995 if(VOS_STATUS_SUCCESS == status)
9996 {
9997 wlan_hdd_set_concurrency_mode(pHddCtx, session_type);
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -07009998 //Initialize the WoWL service
9999 if(!hdd_init_wowl(pAdapter))
10000 {
10001 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_init_wowl failed",__func__);
10002 goto err_free_netdev;
10003 }
Manjeet Singh3ed79242017-01-11 19:04:32 +053010004 //Initialize the TSF capture data
10005 wlan_hdd_tsf_init(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010006 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010007 return pAdapter;
10008
10009err_free_netdev:
Jeff Johnson295189b2012-06-20 16:38:30 -070010010 wlan_hdd_release_intf_addr( pHddCtx,
10011 pAdapter->macAddressCurrent.bytes );
Hanumanth Reddy Pothulaab8e1942018-05-24 18:10:39 +053010012 free_netdev(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070010013
10014resume_bmps:
10015 //If bmps disabled enable it
10016 if(VOS_STATUS_SUCCESS == exitbmpsStatus)
10017 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010018 if (pHddCtx->hdd_wlan_suspended)
10019 {
10020 hdd_set_pwrparams(pHddCtx);
10021 }
10022 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070010023 }
10024 return NULL;
10025}
10026
10027VOS_STATUS hdd_close_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
10028 tANI_U8 rtnl_held )
10029{
10030 hdd_adapter_list_node_t *pAdapterNode, *pCurrent, *pNext;
10031 VOS_STATUS status;
10032
10033 status = hdd_get_front_adapter ( pHddCtx, &pCurrent );
10034 if( VOS_STATUS_SUCCESS != status )
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010035 {
10036 hddLog(VOS_TRACE_LEVEL_WARN,"%s: adapter list empty %d",
10037 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070010038 return status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010039 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010040
10041 while ( pCurrent->pAdapter != pAdapter )
10042 {
10043 status = hdd_get_next_adapter ( pHddCtx, pCurrent, &pNext );
10044 if( VOS_STATUS_SUCCESS != status )
10045 break;
10046
10047 pCurrent = pNext;
10048 }
10049 pAdapterNode = pCurrent;
10050 if( VOS_STATUS_SUCCESS == status )
10051 {
10052 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
10053 hdd_cleanup_adapter( pHddCtx, pAdapterNode->pAdapter, rtnl_held );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010054
10055#ifdef FEATURE_WLAN_TDLS
10056
10057 /* A Mutex Lock is introduced while changing/initializing the mode to
10058 * protect the concurrent access for the Adapters by TDLS module.
10059 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +053010060 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010061#endif
10062
Jeff Johnson295189b2012-06-20 16:38:30 -070010063 hdd_remove_adapter( pHddCtx, pAdapterNode );
10064 vos_mem_free( pAdapterNode );
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080010065 pAdapterNode = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010066
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010067#ifdef FEATURE_WLAN_TDLS
10068 mutex_unlock(&pHddCtx->tdls_lock);
10069#endif
10070
Jeff Johnson295189b2012-06-20 16:38:30 -070010071
10072 /* If there is a single session of STA/P2P client, re-enable BMPS */
Agarwal Ashish51325b52014-06-16 16:50:49 +053010073 if ((!vos_concurrent_open_sessions_running()) &&
10074 ((pHddCtx->no_of_open_sessions[VOS_STA_MODE] >= 1) ||
10075 (pHddCtx->no_of_open_sessions[VOS_P2P_CLIENT_MODE] >= 1)))
Jeff Johnson295189b2012-06-20 16:38:30 -070010076 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010077 if (pHddCtx->hdd_wlan_suspended)
10078 {
10079 hdd_set_pwrparams(pHddCtx);
10080 }
10081 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070010082 }
10083
10084 return VOS_STATUS_SUCCESS;
10085 }
10086
10087 return VOS_STATUS_E_FAILURE;
10088}
10089
10090VOS_STATUS hdd_close_all_adapters( hdd_context_t *pHddCtx )
10091{
10092 hdd_adapter_list_node_t *pHddAdapterNode;
10093 VOS_STATUS status;
10094
10095 ENTER();
10096
10097 do
10098 {
10099 status = hdd_remove_front_adapter( pHddCtx, &pHddAdapterNode );
10100 if( pHddAdapterNode && VOS_STATUS_SUCCESS == status )
10101 {
10102 hdd_cleanup_adapter( pHddCtx, pHddAdapterNode->pAdapter, FALSE );
10103 vos_mem_free( pHddAdapterNode );
10104 }
10105 }while( NULL != pHddAdapterNode && VOS_STATUS_E_EMPTY != status );
10106
10107 EXIT();
10108
10109 return VOS_STATUS_SUCCESS;
10110}
10111
10112void wlan_hdd_reset_prob_rspies(hdd_adapter_t* pHostapdAdapter)
10113{
10114 v_U8_t addIE[1] = {0};
10115
10116 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10117 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,(tANI_U8*)addIE, 0, NULL,
10118 eANI_BOOLEAN_FALSE) )
10119 {
10120 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010121 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010122 }
10123
10124 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10125 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
10126 eANI_BOOLEAN_FALSE) )
10127 {
10128 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010129 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010130 }
10131
10132 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10133 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
10134 eANI_BOOLEAN_FALSE) )
10135 {
10136 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010137 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010138 }
10139}
10140
Anurag Chouhan83026002016-12-13 22:46:21 +053010141VOS_STATUS hdd_cleanup_ap_events(hdd_adapter_t *adapter)
10142{
10143#ifdef DHCP_SERVER_OFFLOAD
10144 vos_event_destroy(&adapter->dhcp_status.vos_event);
10145#endif
Anurag Chouhan0b29de02016-12-16 13:18:40 +053010146#ifdef MDNS_OFFLOAD
10147 vos_event_destroy(&adapter->mdns_status.vos_event);
10148#endif
Anurag Chouhan83026002016-12-13 22:46:21 +053010149 return VOS_STATUS_SUCCESS;
10150}
10151
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010152int wlan_hdd_stop_mon(hdd_context_t *hdd_ctx, bool wait)
10153{
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010154 hdd_adapter_t *adapter;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010155 hdd_mon_ctx_t *mon_ctx;
10156 void (*func_ptr)(void *context) = NULL;
10157 int ret = 0;
10158 void *cookie = NULL;
10159 struct hdd_request *request;
10160 static const struct hdd_request_params params = {
10161 .priv_size = 0,
10162 .timeout_ms = MON_MODE_MSG_TIMEOUT,
10163 };
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010164
10165 adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_MONITOR);
10166 if (!adapter) {
10167 hddLog(LOGE, FL("Invalid STA + MON mode"));
10168 return -EINVAL;
10169 }
10170
10171 mon_ctx = WLAN_HDD_GET_MONITOR_CTX_PTR(adapter);
10172 if (!mon_ctx)
10173 return 0;
10174
10175 if (mon_ctx->state != MON_MODE_START)
10176 return 0;
10177
10178 mon_ctx->state = MON_MODE_STOP;
10179 if (wait) {
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010180 func_ptr = hdd_mon_post_msg_cb;
10181 request = hdd_request_alloc(&params);
10182 if (!request) {
10183 hddLog(VOS_TRACE_LEVEL_ERROR,
10184 FL("Request allocation failure"));
10185 return -ENOMEM;
10186 }
10187 cookie = hdd_request_cookie(request);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010188 }
10189
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010190 /*
10191 * If func_ptr is NULL, on receiving WDI_MON_START_RSP or
10192 * WDI_MON_STOP_RSP hdd_mon_post_msg_cb() won't be invoked
10193 * and so uninitialized cookie won't be accessed.
10194 */
10195 if (VOS_STATUS_SUCCESS != wlan_hdd_mon_postMsg(cookie,
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010196 mon_ctx,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010197 func_ptr)) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010198 hddLog(LOGE, FL("failed to stop MON MODE"));
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010199 ret = -EINVAL;
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010200 }
10201
10202 if (!wait)
10203 goto bmps_roaming;
10204
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010205 if (!ret)
10206 ret = hdd_request_wait_for_response(request);
10207 hdd_request_put(request);
10208 if (ret) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010209 hddLog(LOGE,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010210 FL("timeout on stop monitor mode completion %d"), ret);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010211 return -EINVAL;
10212 }
10213
10214bmps_roaming:
10215 hddLog(LOG1, FL("Enable BMPS"));
10216 hdd_enable_bmps_imps(hdd_ctx);
10217 hdd_restore_roaming(hdd_ctx);
10218
10219 return 0;
10220}
10221
10222bool wlan_hdd_check_monitor_state(hdd_context_t *hdd_ctx)
10223{
10224 hdd_adapter_t *mon_adapter;
10225 hdd_mon_ctx_t *mon_ctx;
10226
10227 if (hdd_ctx->concurrency_mode != VOS_STA_MON)
10228 return false;
10229
10230 mon_adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_MONITOR);
10231 if (!mon_adapter) {
10232 hddLog(LOGE, FL("Invalid concurrency mode"));
10233 return false;
10234 }
10235
10236 mon_ctx = WLAN_HDD_GET_MONITOR_CTX_PTR(mon_adapter);
10237 if (mon_ctx->state == MON_MODE_START)
10238 return true;
10239
10240 return false;
10241}
10242
10243int wlan_hdd_check_and_stop_mon(hdd_adapter_t *sta_adapter, bool wait)
10244{
10245 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(sta_adapter);
10246
10247 if ((sta_adapter->device_mode != WLAN_HDD_INFRA_STATION) ||
10248 !wlan_hdd_check_monitor_state(hdd_ctx))
10249 return 0;
10250
10251 if (wlan_hdd_stop_mon(hdd_ctx, wait))
10252 return -EINVAL;
10253
10254 return 0;
10255}
10256
10257void hdd_disable_roaming(hdd_context_t *hdd_ctx)
10258{
10259 if (!hdd_ctx)
10260 return;
10261
10262 if (!hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled) {
10263 hdd_ctx->roaming_ini_original = CFG_LFR_FEATURE_ENABLED_MIN;
10264 return;
10265 }
10266
10267 hddLog(LOG1, FL("Disable driver and firmware roaming"));
10268
10269 hdd_ctx->roaming_ini_original =
10270 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled;
10271
10272 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled =
10273 CFG_LFR_FEATURE_ENABLED_MIN;
10274
10275 sme_UpdateIsFastRoamIniFeatureEnabled(hdd_ctx->hHal,
10276 CFG_LFR_FEATURE_ENABLED_MIN);
10277}
10278
10279void hdd_restore_roaming(hdd_context_t *hdd_ctx)
10280{
10281 if (!hdd_ctx->roaming_ini_original)
10282 return;
10283
10284 hddLog(LOG1, FL("Enable driver and firmware roaming"));
10285
10286 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled =
10287 CFG_LFR_FEATURE_ENABLED_MAX;
10288
10289 hdd_ctx->roaming_ini_original = CFG_LFR_FEATURE_ENABLED_MIN;
10290
10291 sme_UpdateIsFastRoamIniFeatureEnabled(hdd_ctx->hHal,
10292 CFG_LFR_FEATURE_ENABLED_MAX);
10293}
Anurag Chouhan83026002016-12-13 22:46:21 +053010294
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010295VOS_STATUS hdd_stop_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
10296 const v_BOOL_t bCloseSession )
Jeff Johnson295189b2012-06-20 16:38:30 -070010297{
10298 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
10299 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010300 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010301 union iwreq_data wrqu;
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010302 v_U8_t retry = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010303 long ret;
Nirav Shah7e3c8132015-06-22 23:51:42 +053010304 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -070010305
Anand N Sunkad26d71b92014-12-24 18:08:22 +053010306 if (pHddCtx->isLogpInProgress) {
10307 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
10308 "%s:LOGP in Progress. Ignore!!!",__func__);
10309 return VOS_STATUS_E_FAILURE;
10310 }
10311
Jeff Johnson295189b2012-06-20 16:38:30 -070010312 ENTER();
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010313
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010314 pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -070010315 switch(pAdapter->device_mode)
10316 {
Nirav Shah0cf4d892015-11-05 16:27:27 +053010317 case WLAN_HDD_IBSS:
10318 if ( VOS_TRUE == bCloseSession )
10319 {
10320 status = hdd_sta_id_hash_detach(pAdapter);
10321 if (status != VOS_STATUS_SUCCESS)
10322 hddLog(VOS_TRACE_LEVEL_ERROR,
10323 FL("sta id hash detach failed"));
10324 }
10325
Jeff Johnson295189b2012-06-20 16:38:30 -070010326 case WLAN_HDD_INFRA_STATION:
10327 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -070010328 case WLAN_HDD_P2P_DEVICE:
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010329 {
10330 hdd_station_ctx_t *pstation = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Mahesh A Saptasagare4d05d42015-07-02 16:17:20 +053010331#ifdef FEATURE_WLAN_TDLS
10332 mutex_lock(&pHddCtx->tdls_lock);
10333 wlan_hdd_tdls_exit(pAdapter, TRUE);
10334 mutex_unlock(&pHddCtx->tdls_lock);
10335#endif
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010336 if( hdd_connIsConnected(pstation) ||
10337 (pstation->conn_info.connState == eConnectionState_Connecting) )
Jeff Johnson295189b2012-06-20 16:38:30 -070010338 {
Abhishek Singhe21a5212017-06-09 09:42:58 +053010339 /*
10340 * Indicate sme of disconnect so that in progress connection
10341 * or preauth can be aborted.
10342 */
10343 sme_abortConnection(WLAN_HDD_GET_HAL_CTX(pAdapter),
10344 pAdapter->sessionId);
Abhishek Singh99f17b82017-02-06 16:57:56 +053010345 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Jeff Johnson295189b2012-06-20 16:38:30 -070010346 if (pWextState->roamProfile.BSSType == eCSR_BSS_TYPE_START_IBSS)
10347 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
10348 pAdapter->sessionId,
10349 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
10350 else
10351 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
10352 pAdapter->sessionId,
10353 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Abhishek Singh7b52ed52016-02-11 17:45:54 +053010354 /* Success implies disconnect command got queued up successfully
10355 * Or cmd not queued as scan for SSID is in progress
10356 */
10357 if((eHAL_STATUS_SUCCESS == halStatus) ||
10358 (eHAL_STATUS_CMD_NOT_QUEUED == halStatus))
Jeff Johnson295189b2012-06-20 16:38:30 -070010359 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010360 ret = wait_for_completion_interruptible_timeout(
10361 &pAdapter->disconnect_comp_var,
10362 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Abhishek Singh7b52ed52016-02-11 17:45:54 +053010363 if (ret <= 0 &&
10364 (eHAL_STATUS_CMD_NOT_QUEUED != halStatus))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010365 {
10366 hddLog(VOS_TRACE_LEVEL_ERROR,
10367 "%s: wait on disconnect_comp_var failed %ld",
10368 __func__, ret);
10369 }
10370 }
10371 else
10372 {
10373 hddLog(LOGE, "%s: failed to post disconnect event to SME",
10374 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010375 }
10376 memset(&wrqu, '\0', sizeof(wrqu));
10377 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
10378 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
10379 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
10380 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010381 else if(pstation->conn_info.connState ==
10382 eConnectionState_Disconnecting)
10383 {
10384 ret = wait_for_completion_interruptible_timeout(
10385 &pAdapter->disconnect_comp_var,
10386 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
10387 if (ret <= 0)
10388 {
10389 hddLog(VOS_TRACE_LEVEL_ERROR,
10390 FL("wait on disconnect_comp_var failed %ld"), ret);
10391 }
10392 }
Sachin Ahuja27dd2402016-08-01 20:30:31 +053010393 if(pScanInfo != NULL && pHddCtx->scan_info.mScanPending)
Jeff Johnson295189b2012-06-20 16:38:30 -070010394 {
Mahesh A Saptasagar0b61dcc2016-02-15 14:23:38 +053010395 wlan_hdd_scan_abort(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010396 }
Abhishek Singh3ac179b2015-09-21 10:01:34 +053010397 if ((pAdapter->device_mode != WLAN_HDD_INFRA_STATION) &&
10398 (pAdapter->device_mode != WLAN_HDD_IBSS))
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010399 {
10400 while (pAdapter->is_roc_inprogress)
10401 {
10402 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10403 "%s: ROC in progress for session %d!!!",
10404 __func__, pAdapter->sessionId);
10405 // waiting for ROC to expire
10406 msleep(500);
10407 /* In GO present case , if retry exceeds 3,
10408 it means something went wrong. */
10409 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION )
10410 {
10411 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10412 "%s: ROC completion is not received.!!!", __func__);
Deepthi Gowri70498252015-01-20 15:56:45 +053010413 if (eHAL_STATUS_SUCCESS !=
10414 sme_CancelRemainOnChannel( WLAN_HDD_GET_HAL_CTX( pAdapter),
10415 pAdapter->sessionId ))
10416 {
10417 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10418 FL("Failed to Cancel Remain on Channel"));
10419 }
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010420 wait_for_completion_interruptible_timeout(
10421 &pAdapter->cancel_rem_on_chan_var,
10422 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
10423 break;
10424 }
10425 }
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010426 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010427 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +053010428#ifdef WLAN_NS_OFFLOAD
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010429 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +053010430#endif
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010431
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010432 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010433
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010434 /* It is possible that the caller of this function does not
10435 * wish to close the session
10436 */
10437 if (VOS_TRUE == bCloseSession &&
10438 test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -070010439 {
10440 INIT_COMPLETION(pAdapter->session_close_comp_var);
10441 if (eHAL_STATUS_SUCCESS ==
Agrawal Ashish5a3522c2016-03-02 15:08:28 +053010442 sme_CloseSession(pHddCtx->hHal, pAdapter->sessionId, FALSE,
10443 VOS_FALSE, hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -070010444 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010445 unsigned long ret;
10446
Jeff Johnson295189b2012-06-20 16:38:30 -070010447 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010448 ret = wait_for_completion_timeout(
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010449 &pAdapter->session_close_comp_var,
10450 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010451 if ( 0 >= ret)
10452 {
10453 hddLog(LOGE, "%s: failure waiting for session_close_comp_var %ld",
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010454 __func__, ret);
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010455 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010456 }
10457 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010458 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010459 break;
10460
10461 case WLAN_HDD_SOFTAP:
10462 case WLAN_HDD_P2P_GO:
Nirav Shah0cf4d892015-11-05 16:27:27 +053010463 if ( VOS_TRUE == bCloseSession )
10464 {
10465 status = hdd_sta_id_hash_detach(pAdapter);
10466 if (status != VOS_STATUS_SUCCESS)
10467 hddLog(VOS_TRACE_LEVEL_ERROR,
10468 FL("sta id hash detach failed"));
10469 }
10470
Jeff Johnson295189b2012-06-20 16:38:30 -070010471 //Any softap specific cleanup here...
Anurag Chouhan83026002016-12-13 22:46:21 +053010472 hdd_cleanup_ap_events(pAdapter);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010473 if (pAdapter->device_mode == WLAN_HDD_P2P_GO) {
10474 while (pAdapter->is_roc_inprogress) {
10475 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10476 "%s: ROC in progress for session %d!!!",
10477 __func__, pAdapter->sessionId);
10478 msleep(500);
10479 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION ) {
10480 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10481 "%s: ROC completion is not received.!!!", __func__);
10482 WLANSAP_CancelRemainOnChannel(
10483 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
10484 wait_for_completion_interruptible_timeout(
10485 &pAdapter->cancel_rem_on_chan_var,
10486 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
10487 break;
10488 }
10489 }
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +053010490
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010491 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010492 }
Agrawal Ashish17ef5082016-10-17 18:33:21 +053010493#ifdef SAP_AUTH_OFFLOAD
10494 if (pHddCtx->cfg_ini->enable_sap_auth_offload)
10495 hdd_set_sap_auth_offload(pAdapter, FALSE);
10496#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070010497 mutex_lock(&pHddCtx->sap_lock);
10498 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10499 {
10500 VOS_STATUS status;
10501 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10502
10503 //Stop Bss.
10504 status = WLANSAP_StopBss(pHddCtx->pvosContext);
10505 if (VOS_IS_STATUS_SUCCESS(status))
10506 {
10507 hdd_hostapd_state_t *pHostapdState =
10508 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
10509
10510 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
10511
10512 if (!VOS_IS_STATUS_SUCCESS(status))
10513 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010514 hddLog(LOGE, "%s: failure waiting for WLANSAP_StopBss %d",
10515 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070010516 }
10517 }
10518 else
10519 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010520 hddLog(LOGE, "%s: failure in WLANSAP_StopBss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010521 }
10522 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
Agarwal Ashish51325b52014-06-16 16:50:49 +053010523 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -070010524
10525 if (eHAL_STATUS_FAILURE ==
10526 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
10527 0, NULL, eANI_BOOLEAN_FALSE))
10528 {
10529 hddLog(LOGE,
10530 "%s: Failed to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010531 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010532 }
10533
10534 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pAdapter))->hHal,
10535 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
10536 eANI_BOOLEAN_FALSE) )
10537 {
10538 hddLog(LOGE,
10539 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
10540 }
10541
10542 // Reset WNI_CFG_PROBE_RSP Flags
10543 wlan_hdd_reset_prob_rspies(pAdapter);
10544 kfree(pAdapter->sessionCtx.ap.beacon);
10545 pAdapter->sessionCtx.ap.beacon = NULL;
10546 }
10547 mutex_unlock(&pHddCtx->sap_lock);
Hanumanth Reddy Pothulab4537b82018-03-02 12:20:38 +053010548
10549#ifdef WLAN_NS_OFFLOAD
10550 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
10551#endif
10552 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
10553
Jeff Johnson295189b2012-06-20 16:38:30 -070010554 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -070010555
Jeff Johnson295189b2012-06-20 16:38:30 -070010556 case WLAN_HDD_MONITOR:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010557 if (VOS_MONITOR_MODE != hdd_get_conparam())
10558 wlan_hdd_stop_mon(pHddCtx, true);
10559 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -070010560
Jeff Johnson295189b2012-06-20 16:38:30 -070010561 default:
10562 break;
10563 }
10564
10565 EXIT();
10566 return VOS_STATUS_SUCCESS;
10567}
10568
Kapil Gupta137ef892016-12-13 19:38:00 +053010569/**
10570 * wlan_hdd_restart_sap() - to restart SAP in driver internally
10571 * @ap_adapter: - Pointer to SAP hdd_adapter_t structure
10572 *
10573 * wlan_hdd_restart_sap first delete SAP and do cleanup.
10574 * After that WLANSAP_StartBss start re-start process of SAP.
10575 *
10576 * Return: None
10577 */
10578static void wlan_hdd_restart_sap(hdd_adapter_t *ap_adapter)
10579{
10580 hdd_ap_ctx_t *pHddApCtx;
10581 hdd_hostapd_state_t *pHostapdState;
10582 VOS_STATUS vos_status;
10583 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(ap_adapter);
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010584#ifdef USE_CFG80211_DEL_STA_V2
Kapil Gupta137ef892016-12-13 19:38:00 +053010585 struct station_del_parameters delStaParams;
10586#endif
10587 tsap_Config_t *pConfig;
10588
10589 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10590 pConfig = &pHddApCtx->sapConfig;
10591
10592 mutex_lock(&pHddCtx->sap_lock);
10593 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010594#ifdef USE_CFG80211_DEL_STA_V2
Kapil Gupta137ef892016-12-13 19:38:00 +053010595 delStaParams.mac = NULL;
10596 delStaParams.subtype = SIR_MAC_MGMT_DEAUTH >> 4;
10597 delStaParams.reason_code = eCsrForcedDeauthSta;
10598 wlan_hdd_cfg80211_del_station(ap_adapter->wdev.wiphy, ap_adapter->dev,
10599 &delStaParams);
10600#else
10601 wlan_hdd_cfg80211_del_station(ap_adapter->wdev.wiphy, ap_adapter->dev,
10602 NULL);
10603#endif
10604 hdd_cleanup_actionframe(pHddCtx, ap_adapter);
10605
10606 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10607 vos_event_reset(&pHostapdState->vosEvent);
10608
10609 if (VOS_STATUS_SUCCESS == WLANSAP_StopBss(pHddCtx->pvosContext)) {
10610 vos_status = vos_wait_single_event(&pHostapdState->vosEvent,
10611 10000);
10612 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10613 hddLog(LOGE, FL("SAP Stop Failed"));
10614 goto end;
10615 }
10616 }
10617 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
10618 wlan_hdd_decr_active_session(pHddCtx, ap_adapter->device_mode);
10619 hddLog(LOG1, FL("SAP Stop Success"));
10620
10621 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
10622 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
10623 goto end;
10624 }
10625
10626 if (WLANSAP_StartBss(pHddCtx->pvosContext, hdd_hostapd_SAPEventCB,
10627 pConfig, (v_PVOID_t)ap_adapter->dev) != VOS_STATUS_SUCCESS) {
10628 hddLog(LOGE, FL("SAP Start Bss fail"));
10629 goto end;
10630 }
10631
10632 hddLog(LOG1, FL("Waiting for SAP to start"));
10633 vos_status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
10634 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10635 hddLog(LOGE, FL("SAP Start failed"));
10636 goto end;
10637 }
10638 hddLog(LOG1, FL("SAP Start Success"));
10639 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
10640 wlan_hdd_incr_active_session(pHddCtx, ap_adapter->device_mode);
10641 pHostapdState->bCommit = TRUE;
Anurag Chouhanb2951ae2017-03-12 13:41:35 +053010642 if (!VOS_IS_STATUS_SUCCESS(hdd_dhcp_mdns_offload(ap_adapter))) {
10643 hddLog(VOS_TRACE_LEVEL_ERROR, FL("DHCP/MDNS offload Failed!!"));
10644 vos_event_reset(&pHostapdState->vosEvent);
10645 if (VOS_STATUS_SUCCESS == WLANSAP_StopBss(pHddCtx->pvosContext)) {
10646 vos_status = vos_wait_single_event(&pHostapdState->vosEvent,
10647 10000);
10648 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10649 hddLog(LOGE, FL("SAP Stop Failed"));
10650 goto end;
10651 }
10652 }
10653 }
Kapil Gupta137ef892016-12-13 19:38:00 +053010654 }
10655end:
10656 mutex_unlock(&pHddCtx->sap_lock);
10657 return;
10658}
10659
10660/**
10661 * __hdd_sap_restart_handle() - to handle restarting of SAP
10662 * @work: name of the work
10663 *
10664 * Purpose of this function is to trigger sap start. this function
10665 * will be called from workqueue.
10666 *
10667 * Return: void.
10668 */
10669static void __hdd_sap_restart_handle(struct work_struct *work)
10670{
10671 hdd_adapter_t *sap_adapter;
10672 hdd_context_t *hdd_ctx = container_of(work,
10673 hdd_context_t,
10674 sap_start_work);
10675 if (0 != wlan_hdd_validate_context(hdd_ctx)) {
10676 vos_ssr_unprotect(__func__);
10677 return;
10678 }
10679 sap_adapter = hdd_get_adapter(hdd_ctx,
10680 WLAN_HDD_SOFTAP);
10681 if (sap_adapter == NULL) {
10682 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10683 FL("sap_adapter is NULL"));
10684 vos_ssr_unprotect(__func__);
10685 return;
10686 }
10687
10688 if (hdd_ctx->is_ch_avoid_in_progress) {
10689 sap_adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
10690 wlan_hdd_restart_sap(sap_adapter);
10691 hdd_change_ch_avoidance_status(hdd_ctx, false);
10692 }
Agrawal Ashish574b3e62017-02-09 18:58:34 +053010693 if (hdd_ctx->cfg_ini->enable_sap_auth_offload)
10694 wlan_hdd_restart_sap(sap_adapter);
Kapil Gupta137ef892016-12-13 19:38:00 +053010695}
10696
10697/**
10698 * hdd_sap_restart_handle() - to handle restarting of SAP
10699 * @work: name of the work
10700 *
10701 * Purpose of this function is to trigger sap start. this function
10702 * will be called from workqueue.
10703 *
10704 * Return: void.
10705 */
10706static void hdd_sap_restart_handle(struct work_struct *work)
10707{
10708 vos_ssr_protect(__func__);
10709 __hdd_sap_restart_handle(work);
10710 vos_ssr_unprotect(__func__);
10711}
10712
10713
Abhishek Singh78c691f2017-11-30 13:48:44 +053010714/**
10715 * __hdd_force_scc_with_ecsa_handle() - to handle force scc using ecsa
10716 * @work: name of the work
10717 *
10718 * Purpose of this function is to force SCC using ECSA. This function
10719 * will be called from workqueue.
10720 *
10721 * Return: void.
10722 */
10723static void
10724__hdd_force_scc_with_ecsa_handle(struct work_struct *work)
10725{
10726 hdd_adapter_t *sap_adapter;
10727 hdd_station_ctx_t *sta_ctx;
10728 hdd_adapter_t *sta_adapter;
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010729 ptSapContext sap_ctx = NULL;
10730 v_CONTEXT_t vos_ctx;
10731 tANI_U8 target_channel;
10732 tsap_Config_t *sap_config;
10733 bool sta_sap_scc_on_dfs_chan;
10734 eNVChannelEnabledType chan_state;
Abhishek Singh78c691f2017-11-30 13:48:44 +053010735 hdd_context_t *hdd_ctx = container_of(to_delayed_work(work),
10736 hdd_context_t,
10737 ecsa_chan_change_work);
10738
10739 if (wlan_hdd_validate_context(hdd_ctx))
10740 return;
10741
10742 sap_adapter = hdd_get_adapter(hdd_ctx,
10743 WLAN_HDD_SOFTAP);
10744 if (!sap_adapter) {
10745 hddLog(LOGE, FL("sap_adapter is NULL"));
10746 return;
10747 }
10748
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010749 vos_ctx = hdd_ctx->pvosContext;
10750 if (!vos_ctx) {
10751 hddLog(LOGE, FL("vos_ctx is NULL"));
10752 return;
10753 }
10754
10755 sap_ctx = VOS_GET_SAP_CB(vos_ctx);
10756 if (!sap_ctx) {
10757 hddLog(LOGE, FL("sap_ctx is NULL"));
10758 return;
10759 }
10760
10761 sap_config = &sap_adapter->sessionCtx.ap.sapConfig;
10762
10763 sta_sap_scc_on_dfs_chan = hdd_is_sta_sap_scc_allowed_on_dfs_chan(hdd_ctx);
10764
Abhishek Singh78c691f2017-11-30 13:48:44 +053010765 sta_adapter = hdd_get_adapter(hdd_ctx,
10766 WLAN_HDD_INFRA_STATION);
10767 if (!sta_adapter) {
10768 hddLog(LOGE, FL("sta_adapter is NULL"));
10769 return;
10770 }
Abhishek Singh78c691f2017-11-30 13:48:44 +053010771
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010772 if (wlansap_chk_n_set_chan_change_in_progress(sap_ctx))
Abhishek Singh78c691f2017-11-30 13:48:44 +053010773 return;
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010774 INIT_COMPLETION(sap_ctx->ecsa_info.chan_switch_comp);
10775
10776 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(sta_adapter);
10777 if (sta_ctx->conn_info.connState != eConnectionState_Associated) {
10778 if (sta_ctx->conn_info.connState == eConnectionState_NotConnected) {
10779 chan_state = vos_nv_getChannelEnabledState(sap_ctx->channel);
10780 hddLog(LOG1, FL("sta not in connected state %d, sta_sap_scc_on_dfs_chan %d, chan_state %d"),
10781 sta_ctx->conn_info.connState, sta_sap_scc_on_dfs_chan,
10782 chan_state);
10783 if (sta_sap_scc_on_dfs_chan &&
10784 (chan_state == NV_CHANNEL_DFS)) {
10785 hddLog(LOGE, FL("Switch SAP to user configured channel"));
10786 target_channel = sap_config->user_config_channel;
10787 goto switch_channel;
10788 }
10789 }
10790 goto abort;
Abhishek Singh78c691f2017-11-30 13:48:44 +053010791 }
10792
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010793 target_channel = sta_ctx->conn_info.operationChannel;
10794switch_channel:
10795 hddLog(LOGE, FL("Switch SAP to %d channel"),
10796 target_channel);
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010797 if (!wlansap_set_channel_change(vos_ctx, target_channel, true))
10798 return;
10799
10800abort:
10801 wlansap_reset_chan_change_in_progress(sap_ctx);
10802 complete(&sap_ctx->ecsa_info.chan_switch_comp);
Abhishek Singh78c691f2017-11-30 13:48:44 +053010803}
10804
10805/**
10806 * hdd_force_scc_with_ecsa_handle() - to handle force scc using ecsa
10807 * @work: name of the work
10808 *
10809 * Purpose of this function is to force SCC using ECSA. This function
10810 * will be called from workqueue.
10811 *
10812 * Return: void.
10813 */
10814static void
10815hdd_force_scc_with_ecsa_handle(struct work_struct *work)
10816{
10817 vos_ssr_protect(__func__);
10818 __hdd_force_scc_with_ecsa_handle(work);
10819 vos_ssr_unprotect(__func__);
10820}
10821
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010822int hdd_wait_for_ecsa_complete(hdd_context_t *hdd_ctx)
10823{
10824 int ret;
10825 ptSapContext sap_ctx = NULL;
10826 v_CONTEXT_t vos_ctx;
10827
10828 vos_ctx = hdd_ctx->pvosContext;
10829 if (!vos_ctx) {
10830 hddLog(LOGE, FL("vos_ctx is NULL"));
10831 return 0;
10832 }
10833
10834 sap_ctx = VOS_GET_SAP_CB(vos_ctx);
10835 if (!sap_ctx) {
10836 hddLog(LOG1, FL("sap_ctx is NULL"));
10837 return 0;
10838 }
10839 if(!sap_ctx->isSapSessionOpen) {
10840 hddLog(LOG1, FL("sap session not opened, SAP in state %d"),
10841 sap_ctx->sapsMachine);
10842 return 0;
10843 }
10844
10845 if (!wlansap_get_change_in_progress(sap_ctx)) {
10846 hddLog(LOG1, FL("channel switch not in progress"));
10847 return 0;
10848 }
10849 ret = wait_for_completion_timeout(&sap_ctx->ecsa_info.chan_switch_comp,
10850 msecs_to_jiffies(HDD_SAP_CHAN_CNG_WAIT_TIME));
10851 if (!ret)
10852 {
10853 hddLog(LOGE, FL("Timeout waiting for SAP channel switch"));
10854 return ret;
10855 }
10856
10857 return 0;
10858}
10859
10860
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010861/**
10862 * hdd_is_sta_sap_scc_allowed_on_dfs_chan() - check if sta+sap scc allowed on
10863 * dfs chan
10864 * @hdd_ctx: pointer to hdd context
10865 *
10866 * This function used to check if sta+sap scc allowed on DFS channel.
10867 *
10868 * Return: None
10869 */
10870bool hdd_is_sta_sap_scc_allowed_on_dfs_chan(hdd_context_t *hdd_ctx)
10871{
10872 if (hdd_ctx->cfg_ini->force_scc_with_ecsa &&
10873 hdd_ctx->cfg_ini->sta_sap_scc_on_dfs_chan)
10874 return true;
10875 else
10876 return false;
10877}
10878
Jeff Johnson295189b2012-06-20 16:38:30 -070010879VOS_STATUS hdd_stop_all_adapters( hdd_context_t *pHddCtx )
10880{
10881 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10882 VOS_STATUS status;
10883 hdd_adapter_t *pAdapter;
10884
10885 ENTER();
10886
10887 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10888
10889 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10890 {
10891 pAdapter = pAdapterNode->pAdapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070010892
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010893 hdd_stop_adapter( pHddCtx, pAdapter, VOS_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -070010894
10895 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10896 pAdapterNode = pNext;
10897 }
10898
10899 EXIT();
10900
10901 return VOS_STATUS_SUCCESS;
10902}
10903
Rajeev Kumarf999e582014-01-09 17:33:29 -080010904
10905#ifdef FEATURE_WLAN_BATCH_SCAN
10906/**---------------------------------------------------------------------------
10907
10908 \brief hdd_deinit_batch_scan () - This function cleans up batch scan data
10909 structures
10910
10911 \param - pAdapter Pointer to HDD adapter
10912
10913 \return - None
10914
10915 --------------------------------------------------------------------------*/
10916void hdd_deinit_batch_scan(hdd_adapter_t *pAdapter)
10917{
10918 tHddBatchScanRsp *pNode;
10919 tHddBatchScanRsp *pPrev;
10920
Siddharth Bhalb3e9b792014-02-24 15:14:16 +053010921 if (NULL == pAdapter)
Rajeev Kumarf999e582014-01-09 17:33:29 -080010922 {
Siddharth Bhalb3e9b792014-02-24 15:14:16 +053010923 hddLog(VOS_TRACE_LEVEL_ERROR,
10924 "%s: Adapter context is Null", __func__);
10925 return;
10926 }
10927
10928 pNode = pAdapter->pBatchScanRsp;
10929 while (pNode)
10930 {
10931 pPrev = pNode;
10932 pNode = pNode->pNext;
10933 vos_mem_free((v_VOID_t * )pPrev);
Rajeev Kumarf999e582014-01-09 17:33:29 -080010934 }
10935
10936 pAdapter->pBatchScanRsp = NULL;
10937 pAdapter->numScanList = 0;
10938 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
10939 pAdapter->prev_batch_id = 0;
10940
10941 return;
10942}
10943#endif
10944
10945
Jeff Johnson295189b2012-06-20 16:38:30 -070010946VOS_STATUS hdd_reset_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;
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +053010959 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -070010960 netif_tx_disable(pAdapter->dev);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053010961
10962 if (pHddCtx->cfg_ini->sap_internal_restart &&
10963 pAdapter->device_mode == WLAN_HDD_SOFTAP) {
10964 hddLog(LOG1, FL("driver supports sap restart"));
10965 vos_flush_work(&pHddCtx->sap_start_work);
10966 hdd_sap_indicate_disconnect_for_sta(pAdapter);
10967 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +053010968 hdd_softap_deinit_tx_rx(pAdapter, true);
10969 hdd_sap_destroy_timers(pAdapter);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053010970 } else {
10971 netif_carrier_off(pAdapter->dev);
10972 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010973
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070010974 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053010975
10976 if (pAdapter->device_mode == WLAN_HDD_MONITOR)
10977 pAdapter->sessionCtx.monitor.state = MON_MODE_STOP;
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070010978
Jeff Johnson295189b2012-06-20 16:38:30 -070010979 hdd_deinit_tx_rx(pAdapter);
Agarwal Ashish6267caa2014-08-06 19:16:21 +053010980
Katya Nigam1fd24402015-02-16 14:52:19 +053010981 if(pAdapter->device_mode == WLAN_HDD_IBSS )
10982 hdd_ibss_deinit_tx_rx(pAdapter);
10983
Nirav Shah7e3c8132015-06-22 23:51:42 +053010984 status = hdd_sta_id_hash_detach(pAdapter);
10985 if (status != VOS_STATUS_SUCCESS)
10986 hddLog(VOS_TRACE_LEVEL_ERROR,
10987 FL("sta id hash detach failed for session id %d"),
10988 pAdapter->sessionId);
10989
Agarwal Ashish6267caa2014-08-06 19:16:21 +053010990 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
10991
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +053010992 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
10993 {
10994 hdd_wmm_adapter_close( pAdapter );
10995 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
10996 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010997
Siddharth Bhal2db319d2014-12-03 12:37:18 +053010998 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10999 {
11000 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
11001 }
11002
Rajeev Kumarf999e582014-01-09 17:33:29 -080011003#ifdef FEATURE_WLAN_BATCH_SCAN
11004 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
11005 {
11006 hdd_deinit_batch_scan(pAdapter);
11007 }
11008#endif
11009
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +053011010#ifdef FEATURE_WLAN_TDLS
11011 mutex_lock(&pHddCtx->tdls_lock);
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +053011012 wlan_hdd_tdls_exit(pAdapter, TRUE);
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +053011013 mutex_unlock(&pHddCtx->tdls_lock);
11014#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070011015 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11016 pAdapterNode = pNext;
11017 }
11018
11019 EXIT();
11020
11021 return VOS_STATUS_SUCCESS;
11022}
11023
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011024/**
Abhishek Singh5a597e62016-12-05 15:16:30 +053011025 * hdd_get_bss_entry() - Get the bss entry matching the chan, bssid and ssid
11026 * @wiphy: wiphy
11027 * @channel: channel of the BSS to find
11028 * @bssid: bssid of the BSS to find
11029 * @ssid: ssid of the BSS to find
11030 * @ssid_len: ssid len of of the BSS to find
11031 *
11032 * The API is a wrapper to get bss from kernel matching the chan,
11033 * bssid and ssid
11034 *
11035 * Return: Void
11036 */
11037#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
11038 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
11039
11040struct cfg80211_bss* hdd_get_bss_entry(struct wiphy *wiphy,
11041 struct ieee80211_channel *channel,
11042 const u8 *bssid,
11043 const u8 *ssid, size_t ssid_len)
11044{
11045 return cfg80211_get_bss(wiphy, channel, bssid,
11046 ssid, ssid_len,
11047 WLAN_CAPABILITY_ESS,
11048 WLAN_CAPABILITY_ESS);
11049}
11050#else
11051struct cfg80211_bss* hdd_get_bss_entry(struct wiphy *wiphy,
11052 struct ieee80211_channel *channel,
11053 const u8 *bssid,
11054 const u8 *ssid, size_t ssid_len)
11055{
11056 return cfg80211_get_bss(wiphy, channel, bssid,
11057 ssid, ssid_len,
11058 IEEE80211_BSS_TYPE_ESS,
11059 IEEE80211_PRIVACY_ANY);
11060}
11061#endif
11062
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011063#if defined(CFG80211_CONNECT_BSS) || \
11064 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
11065
11066#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) || \
11067 defined (CFG80211_CONNECT_TIMEOUT_REASON_CODE)
11068/**
11069 * hdd_connect_bss() - helper function to send connection status to supplicant
11070 * @dev: network device
11071 * @bssid: bssid to which we want to associate
11072 * @bss: information about connected bss
11073 * @req_ie: Request Information Element
11074 * @req_ie_len: len of the req IE
11075 * @resp_ie: Response IE
11076 * @resp_ie_len: len of ht response IE
11077 * @status: status
11078 * @gfp: Kernel Flag
11079 *
11080 * This is a helper function to send connection status to supplicant
11081 * and gets invoked from wrapper API
11082 *
11083 * Return: Void
11084 */
11085static void hdd_connect_bss(struct net_device *dev,
11086 const u8 *bssid,
11087 struct cfg80211_bss *bss,
11088 const u8 *req_ie,
11089 size_t req_ie_len,
11090 const u8 *resp_ie,
11091 size_t resp_ie_len,
11092 u16 status,
11093 gfp_t gfp)
11094{
11095 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
11096 resp_ie, resp_ie_len, status, gfp, NL80211_TIMEOUT_UNSPECIFIED);
11097}
11098#else
11099/**
11100 * hdd_connect_bss() - helper function to send connection status to supplicant
11101 * @dev: network device
11102 * @bssid: bssid to which we want to associate
11103 * @bss: information about connected bss
11104 * @req_ie: Request Information Element
11105 * @req_ie_len: len of the req IE
11106 * @resp_ie: Response IE
11107 * @resp_ie_len: len of ht response IE
11108 * @status: status
11109 * @gfp: Kernel Flag
11110 *
11111 * This is a helper function to send connection status to supplicant
11112 * and gets invoked from wrapper API
11113 *
11114 * Return: Void
11115 */
11116static void hdd_connect_bss(struct net_device *dev,
11117 const u8 *bssid,
11118 struct cfg80211_bss *bss,
11119 const u8 *req_ie,
11120 size_t req_ie_len,
11121 const u8 *resp_ie,
11122 size_t resp_ie_len,
11123 u16 status,
11124 gfp_t gfp)
11125{
11126 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
11127 resp_ie, resp_ie_len, status, gfp);
11128}
11129#endif
11130
Abhishek Singh5a597e62016-12-05 15:16:30 +053011131/**
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011132 * hdd_connect_result() - API to send connection status to supplicant
11133 * @dev: network device
11134 * @bssid: bssid to which we want to associate
11135 * @roam_info: information about connected bss
11136 * @req_ie: Request Information Element
11137 * @req_ie_len: len of the req IE
11138 * @resp_ie: Response IE
11139 * @resp_ie_len: len of ht response IE
11140 * @status: status
11141 * @gfp: Kernel Flag
11142 *
11143 * The API is a wrapper to send connection status to supplicant
11144 *
11145 * Return: Void
11146 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011147void hdd_connect_result(struct net_device *dev,
11148 const u8 *bssid,
11149 tCsrRoamInfo *roam_info,
11150 const u8 *req_ie,
11151 size_t req_ie_len,
11152 const u8 *resp_ie,
11153 size_t resp_ie_len,
11154 u16 status,
11155 gfp_t gfp)
11156{
11157 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
11158 struct cfg80211_bss *bss = NULL;
11159
11160 if (WLAN_STATUS_SUCCESS == status) {
11161 struct ieee80211_channel *chan;
11162 int freq;
11163 int chan_no = roam_info->pBssDesc->channelId;;
11164
11165 if (chan_no <= 14)
11166 freq = ieee80211_channel_to_frequency(chan_no,
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011167 HDD_NL80211_BAND_2GHZ);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011168 else
11169 freq = ieee80211_channel_to_frequency(chan_no,
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011170 HDD_NL80211_BAND_5GHZ);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011171
11172 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
Abhishek Singh5a597e62016-12-05 15:16:30 +053011173 bss = hdd_get_bss_entry(padapter->wdev.wiphy,
11174 chan, bssid,
11175 roam_info->u.pConnectedProfile->SSID.ssId,
11176 roam_info->u.pConnectedProfile->SSID.length);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011177 }
11178
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011179 hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie, resp_ie_len,
11180 status, gfp);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011181}
11182#else
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011183/**
11184 * hdd_connect_result() - API to send connection status to supplicant
11185 * @dev: network device
11186 * @bssid: bssid to which we want to associate
11187 * @roam_info: information about connected bss
11188 * @req_ie: Request Information Element
11189 * @req_ie_len: len of the req IE
11190 * @resp_ie: Response IE
11191 * @resp_ie_len: len of ht response IE
11192 * @status: status
11193 * @gfp: Kernel Flag
11194 *
11195 * The API is a wrapper to send connection status to supplicant
11196 *
11197 * Return: Void
11198 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011199void hdd_connect_result(struct net_device *dev,
11200 const u8 *bssid,
11201 tCsrRoamInfo *roam_info,
11202 const u8 *req_ie,
11203 size_t req_ie_len,
11204 const u8 * resp_ie,
11205 size_t resp_ie_len,
11206 u16 status,
11207 gfp_t gfp)
11208{
11209 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
11210 resp_ie, resp_ie_len, status, gfp);
11211}
11212#endif
11213
Jeff Johnson295189b2012-06-20 16:38:30 -070011214VOS_STATUS hdd_start_all_adapters( hdd_context_t *pHddCtx )
11215{
11216 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11217 VOS_STATUS status;
11218 hdd_adapter_t *pAdapter;
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011219 eConnectionState connState;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011220 v_CONTEXT_t pVosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011221
11222 ENTER();
11223
11224 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11225
11226 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11227 {
11228 pAdapter = pAdapterNode->pAdapter;
11229
Kumar Anand82c009f2014-05-29 00:29:42 -070011230 hdd_wmm_init( pAdapter );
11231
Jeff Johnson295189b2012-06-20 16:38:30 -070011232 switch(pAdapter->device_mode)
11233 {
11234 case WLAN_HDD_INFRA_STATION:
11235 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -070011236 case WLAN_HDD_P2P_DEVICE:
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011237
11238 connState = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState;
11239
Jeff Johnson295189b2012-06-20 16:38:30 -070011240 hdd_init_station_mode(pAdapter);
11241 /* Open the gates for HDD to receive Wext commands */
11242 pAdapter->isLinkUpSvcNeeded = FALSE;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070011243 pHddCtx->scan_info.mScanPending = FALSE;
11244 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070011245
11246 //Trigger the initial scan
Mukul Sharmae74e42c2015-08-06 23:55:49 +053011247 if (!pHddCtx->isLogpInProgress)
11248 hdd_wlan_initial_scan(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070011249
11250 //Indicate disconnect event to supplicant if associated previously
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011251 if (eConnectionState_Associated == connState ||
11252 eConnectionState_IbssConnected == connState )
Jeff Johnson295189b2012-06-20 16:38:30 -070011253 {
11254 union iwreq_data wrqu;
11255 memset(&wrqu, '\0', sizeof(wrqu));
11256 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
11257 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
11258 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070011259 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070011260
Jeff Johnson295189b2012-06-20 16:38:30 -070011261 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagar9ff4bcc2016-06-01 17:17:50 +053011262 wlan_hdd_cfg80211_indicate_disconnect(pAdapter->dev, false,
Mahesh A Saptasagarb5a15142016-05-25 11:27:43 +053011263 WLAN_REASON_UNSPECIFIED);
Jeff Johnson295189b2012-06-20 16:38:30 -070011264 }
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011265 else if (eConnectionState_Connecting == connState)
11266 {
11267 /*
11268 * Indicate connect failure to supplicant if we were in the
11269 * process of connecting
11270 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011271 hdd_connect_result(pAdapter->dev, NULL, NULL,
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011272 NULL, 0, NULL, 0,
11273 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
11274 GFP_KERNEL);
11275 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011276 break;
11277
11278 case WLAN_HDD_SOFTAP:
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011279 if (pHddCtx->cfg_ini->sap_internal_restart) {
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +053011280 hdd_init_ap_mode(pAdapter, true);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011281 status = hdd_sta_id_hash_attach(pAdapter);
11282 if (VOS_STATUS_SUCCESS != status)
11283 {
11284 hddLog(VOS_TRACE_LEVEL_FATAL,
11285 FL("failed to attach hash for"));
11286 }
11287 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011288 break;
11289
11290 case WLAN_HDD_P2P_GO:
Sameer Thalappiledf0d792013-08-09 14:31:03 -070011291 hddLog(VOS_TRACE_LEVEL_ERROR, "%s [SSR] send stop ap to supplicant",
Jeff Johnson295189b2012-06-20 16:38:30 -070011292 __func__);
Sameer Thalappiledf0d792013-08-09 14:31:03 -070011293 cfg80211_ap_stopped(pAdapter->dev, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -070011294 break;
11295
11296 case WLAN_HDD_MONITOR:
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011297 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
11298
11299 hddLog(VOS_TRACE_LEVEL_INFO, FL("[SSR] monitor mode"));
11300 if (!pVosContext) {
11301 hddLog(VOS_TRACE_LEVEL_ERROR, FL("vos context is NULL"));
11302 break;
11303 }
11304
11305 hdd_init_tx_rx(pAdapter);
11306 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk);
Jeff Johnson295189b2012-06-20 16:38:30 -070011307 break;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011308
Jeff Johnson295189b2012-06-20 16:38:30 -070011309 default:
11310 break;
11311 }
11312
11313 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11314 pAdapterNode = pNext;
11315 }
11316
11317 EXIT();
11318
11319 return VOS_STATUS_SUCCESS;
11320}
11321
11322VOS_STATUS hdd_reconnect_all_adapters( hdd_context_t *pHddCtx )
11323{
11324 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11325 hdd_adapter_t *pAdapter;
11326 VOS_STATUS status;
11327 v_U32_t roamId;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011328 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070011329
11330 ENTER();
11331
11332 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11333
11334 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11335 {
11336 pAdapter = pAdapterNode->pAdapter;
11337
11338 if( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
11339 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
11340 {
11341 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11342 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11343
Abhishek Singhf4669da2014-05-26 15:07:49 +053011344 hddLog(VOS_TRACE_LEVEL_INFO,
11345 "%s: Set HDD connState to eConnectionState_NotConnected",
11346 __func__);
Ganesh Kondabattini04338412015-09-14 15:39:09 +053011347 spin_lock_bh(&pAdapter->lock_for_active_session);
11348 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState)
11349 {
11350 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
11351 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011352 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Ganesh Kondabattini04338412015-09-14 15:39:09 +053011353 spin_unlock_bh(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -070011354 init_completion(&pAdapter->disconnect_comp_var);
11355 sme_RoamDisconnect(pHddCtx->hHal, pAdapter->sessionId,
11356 eCSR_DISCONNECT_REASON_UNSPECIFIED);
11357
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011358 ret = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -070011359 &pAdapter->disconnect_comp_var,
11360 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011361 if (0 >= ret)
11362 hddLog(LOGE, "%s: failure waiting for disconnect_comp_var %ld",
11363 __func__, ret);
Jeff Johnson295189b2012-06-20 16:38:30 -070011364
11365 pWextState->roamProfile.csrPersona = pAdapter->device_mode;
11366 pHddCtx->isAmpAllowed = VOS_FALSE;
11367 sme_RoamConnect(pHddCtx->hHal,
11368 pAdapter->sessionId, &(pWextState->roamProfile),
11369 &roamId);
11370 }
11371
11372 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11373 pAdapterNode = pNext;
11374 }
11375
11376 EXIT();
11377
11378 return VOS_STATUS_SUCCESS;
11379}
11380
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011381void hdd_dump_concurrency_info(hdd_context_t *pHddCtx)
11382{
11383 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11384 VOS_STATUS status;
11385 hdd_adapter_t *pAdapter;
11386 hdd_station_ctx_t *pHddStaCtx;
11387 hdd_ap_ctx_t *pHddApCtx;
11388 hdd_hostapd_state_t * pHostapdState;
11389 tCsrBssid staBssid = { 0 }, p2pBssid = { 0 }, apBssid = { 0 };
11390 v_U8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
11391 const char *p2pMode = "DEV";
11392 const char *ccMode = "Standalone";
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011393
11394 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11395 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11396 {
11397 pAdapter = pAdapterNode->pAdapter;
11398 switch (pAdapter->device_mode) {
11399 case WLAN_HDD_INFRA_STATION:
11400 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11401 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
11402 staChannel = pHddStaCtx->conn_info.operationChannel;
11403 memcpy(staBssid, pHddStaCtx->conn_info.bssId, sizeof(staBssid));
11404 }
11405 break;
11406 case WLAN_HDD_P2P_CLIENT:
11407 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11408 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
11409 p2pChannel = pHddStaCtx->conn_info.operationChannel;
11410 memcpy(p2pBssid, pHddStaCtx->conn_info.bssId, sizeof(p2pBssid));
11411 p2pMode = "CLI";
11412 }
11413 break;
11414 case WLAN_HDD_P2P_GO:
11415 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
11416 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
11417 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
11418 p2pChannel = pHddApCtx->operatingChannel;
11419 memcpy(p2pBssid, pAdapter->macAddressCurrent.bytes, sizeof(p2pBssid));
11420 }
11421 p2pMode = "GO";
11422 break;
11423 case WLAN_HDD_SOFTAP:
11424 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
11425 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
11426 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
11427 apChannel = pHddApCtx->operatingChannel;
11428 memcpy(apBssid, pAdapter->macAddressCurrent.bytes, sizeof(apBssid));
11429 }
11430 break;
11431 default:
11432 break;
11433 }
11434 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11435 pAdapterNode = pNext;
11436 }
11437 if (staChannel > 0 && (apChannel > 0 || p2pChannel > 0)) {
11438 ccMode = (p2pChannel==staChannel||apChannel==staChannel) ? "SCC" : "MCC";
11439 }
Yeshwanth Sriram Guntuka0004c0b2017-12-06 14:43:49 +053011440 hddLog(VOS_TRACE_LEVEL_ERROR, "wlan(%d) " MAC_ADDRESS_STR " %s",
11441 staChannel, MAC_ADDR_ARRAY(staBssid), ccMode);
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011442 if (p2pChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +053011443 hddLog(VOS_TRACE_LEVEL_ERROR, "p2p-%s(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011444 p2pMode, p2pChannel, MAC_ADDR_ARRAY(p2pBssid));
11445 }
11446 if (apChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +053011447 hddLog(VOS_TRACE_LEVEL_ERROR, "AP(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011448 apChannel, MAC_ADDR_ARRAY(apBssid));
11449 }
11450
11451 if (p2pChannel > 0 && apChannel > 0) {
11452 hddLog(VOS_TRACE_LEVEL_ERROR, "Error concurrent SAP %d and P2P %d which is not support", apChannel, p2pChannel);
11453 }
11454}
11455
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011456bool hdd_is_ssr_required( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070011457{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011458 return (isSsrRequired == HDD_SSR_REQUIRED);
Jeff Johnson295189b2012-06-20 16:38:30 -070011459}
11460
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011461/* Once SSR is disabled then it cannot be set. */
11462void hdd_set_ssr_required( e_hdd_ssr_required value)
Jeff Johnson295189b2012-06-20 16:38:30 -070011463{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011464 if (HDD_SSR_DISABLED == isSsrRequired)
11465 return;
11466
Jeff Johnson295189b2012-06-20 16:38:30 -070011467 isSsrRequired = value;
11468}
11469
Hema Aparna Medicharla6b4d4f32015-06-23 04:09:12 +053011470void hdd_set_pre_close( hdd_context_t *pHddCtx)
11471{
11472 sme_PreClose(pHddCtx->hHal);
11473}
11474
Jeff Johnson295189b2012-06-20 16:38:30 -070011475VOS_STATUS hdd_get_front_adapter( hdd_context_t *pHddCtx,
11476 hdd_adapter_list_node_t** ppAdapterNode)
11477{
11478 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011479 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011480 status = hdd_list_peek_front ( &pHddCtx->hddAdapters,
11481 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011482 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011483 return status;
11484}
11485
11486VOS_STATUS hdd_get_next_adapter( hdd_context_t *pHddCtx,
11487 hdd_adapter_list_node_t* pAdapterNode,
11488 hdd_adapter_list_node_t** pNextAdapterNode)
11489{
11490 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011491 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011492 status = hdd_list_peek_next ( &pHddCtx->hddAdapters,
11493 (hdd_list_node_t*) pAdapterNode,
11494 (hdd_list_node_t**)pNextAdapterNode );
11495
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011496 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011497 return status;
11498}
11499
11500VOS_STATUS hdd_remove_adapter( hdd_context_t *pHddCtx,
11501 hdd_adapter_list_node_t* pAdapterNode)
11502{
11503 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011504 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011505 status = hdd_list_remove_node ( &pHddCtx->hddAdapters,
11506 &pAdapterNode->node );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011507 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011508 return status;
11509}
11510
11511VOS_STATUS hdd_remove_front_adapter( hdd_context_t *pHddCtx,
11512 hdd_adapter_list_node_t** ppAdapterNode)
11513{
11514 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011515 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011516 status = hdd_list_remove_front( &pHddCtx->hddAdapters,
11517 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011518 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011519 return status;
11520}
11521
11522VOS_STATUS hdd_add_adapter_back( hdd_context_t *pHddCtx,
11523 hdd_adapter_list_node_t* pAdapterNode)
11524{
11525 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011526 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011527 status = hdd_list_insert_back ( &pHddCtx->hddAdapters,
11528 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011529 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011530 return status;
11531}
11532
11533VOS_STATUS hdd_add_adapter_front( hdd_context_t *pHddCtx,
11534 hdd_adapter_list_node_t* pAdapterNode)
11535{
11536 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011537 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011538 status = hdd_list_insert_front ( &pHddCtx->hddAdapters,
11539 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011540 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011541 return status;
11542}
11543
11544hdd_adapter_t * hdd_get_adapter_by_macaddr( hdd_context_t *pHddCtx,
11545 tSirMacAddr macAddr )
11546{
11547 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11548 hdd_adapter_t *pAdapter;
11549 VOS_STATUS status;
11550
11551 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11552
11553 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11554 {
11555 pAdapter = pAdapterNode->pAdapter;
11556
11557 if( pAdapter && vos_mem_compare( pAdapter->macAddressCurrent.bytes,
11558 macAddr, sizeof(tSirMacAddr) ) )
11559 {
11560 return pAdapter;
11561 }
11562 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11563 pAdapterNode = pNext;
11564 }
11565
11566 return NULL;
11567
11568}
11569
11570hdd_adapter_t * hdd_get_adapter_by_name( hdd_context_t *pHddCtx, tANI_U8 *name )
11571{
11572 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11573 hdd_adapter_t *pAdapter;
11574 VOS_STATUS status;
11575
11576 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11577
11578 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11579 {
11580 pAdapter = pAdapterNode->pAdapter;
11581
11582 if( pAdapter && !strncmp( pAdapter->dev->name, (const char *)name,
11583 IFNAMSIZ ) )
11584 {
11585 return pAdapter;
11586 }
11587 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11588 pAdapterNode = pNext;
11589 }
11590
11591 return NULL;
11592
11593}
11594
Ganesh Kondabattinicbfdc392015-09-11 19:12:59 +053011595hdd_adapter_t *hdd_get_adapter_by_sme_session_id( hdd_context_t *pHddCtx,
11596 tANI_U32 sme_session_id )
11597{
11598 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11599 hdd_adapter_t *pAdapter;
11600 VOS_STATUS vos_status;
11601
11602
11603 vos_status = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
11604
11605 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == vos_status))
11606 {
11607 pAdapter = pAdapterNode->pAdapter;
11608
11609 if (pAdapter->sessionId == sme_session_id)
11610 return pAdapter;
11611
11612 vos_status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
11613 pAdapterNode = pNext;
11614 }
11615
11616 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
11617 "%s: sme_session_id %d does not exist with host",
11618 __func__, sme_session_id);
11619
11620 return NULL;
11621}
11622
Jeff Johnson295189b2012-06-20 16:38:30 -070011623hdd_adapter_t * hdd_get_adapter( hdd_context_t *pHddCtx, device_mode_t mode )
11624{
11625 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11626 hdd_adapter_t *pAdapter;
11627 VOS_STATUS status;
11628
11629 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11630
11631 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11632 {
11633 pAdapter = pAdapterNode->pAdapter;
11634
11635 if( pAdapter && (mode == pAdapter->device_mode) )
11636 {
11637 return pAdapter;
11638 }
11639 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11640 pAdapterNode = pNext;
11641 }
11642
11643 return NULL;
11644
11645}
11646
11647//Remove this function later
11648hdd_adapter_t * hdd_get_mon_adapter( hdd_context_t *pHddCtx )
11649{
11650 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11651 hdd_adapter_t *pAdapter;
11652 VOS_STATUS status;
11653
11654 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11655
11656 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11657 {
11658 pAdapter = pAdapterNode->pAdapter;
11659
11660 if( pAdapter && WLAN_HDD_MONITOR == pAdapter->device_mode )
11661 {
11662 return pAdapter;
11663 }
11664
11665 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11666 pAdapterNode = pNext;
11667 }
11668
11669 return NULL;
11670
11671}
11672
Jeff Johnson295189b2012-06-20 16:38:30 -070011673/**---------------------------------------------------------------------------
11674
Mahesh A Saptasgar64534612014-09-23 13:13:33 +053011675 \brief hdd_get_operating_channel() -
Jeff Johnson295189b2012-06-20 16:38:30 -070011676
11677 This API returns the operating channel of the requested device mode
11678
11679 \param - pHddCtx - Pointer to the HDD context.
11680 - mode - Device mode for which operating channel is required
11681 suported modes - WLAN_HDD_INFRA_STATION, WLAN_HDD_P2P_CLIENT
11682 WLAN_HDD_SOFTAP, WLAN_HDD_P2P_GO.
11683 \return - channel number. "0" id the requested device is not found OR it is not connected.
11684 --------------------------------------------------------------------------*/
11685v_U8_t hdd_get_operating_channel( hdd_context_t *pHddCtx, device_mode_t mode )
11686{
11687 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11688 VOS_STATUS status;
11689 hdd_adapter_t *pAdapter;
11690 v_U8_t operatingChannel = 0;
11691
11692 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11693
11694 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11695 {
11696 pAdapter = pAdapterNode->pAdapter;
11697
11698 if( mode == pAdapter->device_mode )
11699 {
11700 switch(pAdapter->device_mode)
11701 {
11702 case WLAN_HDD_INFRA_STATION:
11703 case WLAN_HDD_P2P_CLIENT:
11704 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
11705 operatingChannel = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.operationChannel;
11706 break;
11707 case WLAN_HDD_SOFTAP:
11708 case WLAN_HDD_P2P_GO:
11709 /*softap connection info */
11710 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
11711 operatingChannel = (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->operatingChannel;
11712 break;
11713 default:
11714 break;
11715 }
11716
11717 break; //Found the device of interest. break the loop
11718 }
11719
11720 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11721 pAdapterNode = pNext;
11722 }
11723 return operatingChannel;
11724}
11725
11726#ifdef WLAN_FEATURE_PACKET_FILTERING
11727/**---------------------------------------------------------------------------
11728
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011729 \brief __hdd_set_multicast_list() -
Jeff Johnson295189b2012-06-20 16:38:30 -070011730
11731 This used to set the multicast address list.
11732
11733 \param - dev - Pointer to the WLAN device.
11734 - skb - Pointer to OS packet (sk_buff).
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011735 \return - success/fail
Jeff Johnson295189b2012-06-20 16:38:30 -070011736
11737 --------------------------------------------------------------------------*/
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011738static void __hdd_set_multicast_list(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -070011739{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011740 hdd_adapter_t *pAdapter;
11741 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -070011742 int mc_count;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011743 int i = 0, ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011744 struct netdev_hw_addr *ha;
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011745
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011746 ENTER();
11747
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011748 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011749 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070011750 {
11751 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011752 "%s: Adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070011753 return;
11754 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011755 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11756 ret = wlan_hdd_validate_context(pHddCtx);
11757 if (0 != ret)
11758 {
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011759 return;
11760 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011761 if (dev->flags & IFF_ALLMULTI)
11762 {
11763 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011764 "%s: allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011765 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011766 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011767 else
Jeff Johnson295189b2012-06-20 16:38:30 -070011768 {
11769 mc_count = netdev_mc_count(dev);
11770 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011771 "%s: mc_count = %u", __func__, mc_count);
Jeff Johnson295189b2012-06-20 16:38:30 -070011772 if (mc_count > WLAN_HDD_MAX_MC_ADDR_LIST)
11773 {
11774 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011775 "%s: No free filter available; allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011776 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011777 return;
11778 }
11779
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011780 pAdapter->mc_addr_list.mc_cnt = mc_count;
Jeff Johnson295189b2012-06-20 16:38:30 -070011781
11782 netdev_for_each_mc_addr(ha, dev) {
11783 if (i == mc_count)
11784 break;
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011785 memset(&(pAdapter->mc_addr_list.addr[i][0]), 0, ETH_ALEN);
11786 memcpy(&(pAdapter->mc_addr_list.addr[i][0]), ha->addr, ETH_ALEN);
Arif Hussain6d2a3322013-11-17 19:50:10 -080011787 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mlist[%d] = "MAC_ADDRESS_STR,
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011788 __func__, i,
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011789 MAC_ADDR_ARRAY(pAdapter->mc_addr_list.addr[i]));
Jeff Johnson295189b2012-06-20 16:38:30 -070011790 i++;
11791 }
11792 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011793
Ganesh Kondabattinifb37e652015-10-09 15:46:47 +053011794 if (pHddCtx->hdd_wlan_suspended)
11795 {
11796 /*
11797 * Configure the Mcast address list to FW
11798 * If wlan is already in suspend mode
11799 */
11800 wlan_hdd_set_mc_addr_list(pAdapter, TRUE);
11801 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011802 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -070011803 return;
11804}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011805
11806static void hdd_set_multicast_list(struct net_device *dev)
11807{
11808 vos_ssr_protect(__func__);
11809 __hdd_set_multicast_list(dev);
11810 vos_ssr_unprotect(__func__);
11811}
Jeff Johnson295189b2012-06-20 16:38:30 -070011812#endif
11813
11814/**---------------------------------------------------------------------------
11815
11816 \brief hdd_select_queue() -
11817
11818 This function is registered with the Linux OS for network
11819 core to decide which queue to use first.
11820
11821 \param - dev - Pointer to the WLAN device.
11822 - skb - Pointer to OS packet (sk_buff).
11823 \return - ac, Queue Index/access category corresponding to UP in IP header
11824
11825 --------------------------------------------------------------------------*/
11826v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053011827 struct sk_buff *skb
11828#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
11829 , void *accel_priv
11830#endif
11831#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
11832 , select_queue_fallback_t fallback
11833#endif
11834)
Jeff Johnson295189b2012-06-20 16:38:30 -070011835{
11836 return hdd_wmm_select_queue(dev, skb);
11837}
11838
11839
11840/**---------------------------------------------------------------------------
11841
11842 \brief hdd_wlan_initial_scan() -
11843
11844 This function triggers the initial scan
11845
11846 \param - pAdapter - Pointer to the HDD adapter.
11847
11848 --------------------------------------------------------------------------*/
11849void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter)
11850{
11851 tCsrScanRequest scanReq;
11852 tCsrChannelInfo channelInfo;
11853 eHalStatus halStatus;
Jeff Johnson02797792013-10-26 19:17:13 -070011854 tANI_U32 scanId;
Jeff Johnson295189b2012-06-20 16:38:30 -070011855 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11856
11857 vos_mem_zero(&scanReq, sizeof(tCsrScanRequest));
11858 vos_mem_set(&scanReq.bssid, sizeof(tCsrBssid), 0xff);
11859 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
11860
11861 if(sme_Is11dSupported(pHddCtx->hHal))
11862 {
11863 halStatus = sme_ScanGetBaseChannels( pHddCtx->hHal, &channelInfo );
11864 if ( HAL_STATUS_SUCCESS( halStatus ) )
11865 {
11866 scanReq.ChannelInfo.ChannelList = vos_mem_malloc(channelInfo.numOfChannels);
11867 if( !scanReq.ChannelInfo.ChannelList )
11868 {
11869 hddLog(VOS_TRACE_LEVEL_ERROR, "%s kmalloc failed", __func__);
11870 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080011871 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011872 return;
11873 }
11874 vos_mem_copy(scanReq.ChannelInfo.ChannelList, channelInfo.ChannelList,
11875 channelInfo.numOfChannels);
11876 scanReq.ChannelInfo.numOfChannels = channelInfo.numOfChannels;
11877 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080011878 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011879 }
11880
11881 scanReq.scanType = eSIR_PASSIVE_SCAN;
11882 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
11883 scanReq.maxChnTime = pHddCtx->cfg_ini->nPassiveMaxChnTime;
11884 scanReq.minChnTime = pHddCtx->cfg_ini->nPassiveMinChnTime;
11885 }
11886 else
11887 {
11888 scanReq.scanType = eSIR_ACTIVE_SCAN;
11889 scanReq.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
11890 scanReq.maxChnTime = pHddCtx->cfg_ini->nActiveMaxChnTime;
11891 scanReq.minChnTime = pHddCtx->cfg_ini->nActiveMinChnTime;
11892 }
11893
11894 halStatus = sme_ScanRequest(pHddCtx->hHal, pAdapter->sessionId, &scanReq, &scanId, NULL, NULL);
11895 if ( !HAL_STATUS_SUCCESS( halStatus ) )
11896 {
11897 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_ScanRequest failed status code %d",
11898 __func__, halStatus );
11899 }
11900
11901 if(sme_Is11dSupported(pHddCtx->hHal))
11902 vos_mem_free(scanReq.ChannelInfo.ChannelList);
11903}
11904
Jeff Johnson295189b2012-06-20 16:38:30 -070011905/**---------------------------------------------------------------------------
11906
11907 \brief hdd_full_power_callback() - HDD full power callback function
11908
11909 This is the function invoked by SME to inform the result of a full power
11910 request issued by HDD
11911
11912 \param - callbackcontext - Pointer to cookie
11913 \param - status - result of request
11914
11915 \return - None
11916
11917 --------------------------------------------------------------------------*/
11918static void hdd_full_power_callback(void *callbackContext, eHalStatus status)
11919{
Jeff Johnson72a40512013-12-19 10:14:15 -080011920 struct statsContext *pContext = callbackContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011921
11922 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070011923 "%s: context = %pK, status = %d", __func__, pContext, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070011924
11925 if (NULL == callbackContext)
11926 {
11927 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070011928 "%s: Bad param, context [%pK]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011929 __func__, callbackContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070011930 return;
11931 }
11932
Jeff Johnson72a40512013-12-19 10:14:15 -080011933 /* there is a race condition that exists between this callback
11934 function and the caller since the caller could time out either
11935 before or while this code is executing. we use a spinlock to
11936 serialize these actions */
11937 spin_lock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011938
11939 if (POWER_CONTEXT_MAGIC != pContext->magic)
11940 {
11941 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -080011942 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011943 hddLog(VOS_TRACE_LEVEL_WARN,
11944 "%s: Invalid context, magic [%08x]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011945 __func__, pContext->magic);
Jeff Johnson295189b2012-06-20 16:38:30 -070011946 return;
11947 }
11948
Jeff Johnson72a40512013-12-19 10:14:15 -080011949 /* context is valid so caller is still waiting */
11950
11951 /* paranoia: invalidate the magic */
11952 pContext->magic = 0;
11953
11954 /* notify the caller */
Jeff Johnson295189b2012-06-20 16:38:30 -070011955 complete(&pContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -080011956
11957 /* serialization is complete */
11958 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011959}
11960
Katya Nigamf0511f62015-05-05 16:40:57 +053011961void wlan_hdd_mon_set_typesubtype( hdd_mon_ctx_t *pMonCtx,int type)
11962{
11963 pMonCtx->typeSubtypeBitmap = 0;
11964 if( type%10 ) /* Management Packets */
11965 pMonCtx->typeSubtypeBitmap |= 0xFFFF;
11966 type/=10;
11967 if( type%10 ) /* Control Packets */
11968 pMonCtx->typeSubtypeBitmap |= 0xFFFF0000;
11969 type/=10;
11970 if( type%10 ) /* Data Packets */
11971 pMonCtx->typeSubtypeBitmap |= 0xFFFF00000000;
11972}
11973
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053011974VOS_STATUS wlan_hdd_mon_postMsg(void *context, hdd_mon_ctx_t *pMonCtx,
11975 void* callback)
Katya Nigamf0511f62015-05-05 16:40:57 +053011976{
11977 vos_msg_t monMsg;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011978 tSirMonModeReq *pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +053011979
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011980 if (MON_MODE_START == pMonCtx->state)
11981 monMsg.type = WDA_MON_START_REQ;
11982 else if (MON_MODE_STOP == pMonCtx->state)
11983 monMsg.type = WDA_MON_STOP_REQ;
11984 else {
11985 hddLog(VOS_TRACE_LEVEL_ERROR,
11986 FL("invalid monitor state %d"), pMonCtx->state);
Katya Nigamf0511f62015-05-05 16:40:57 +053011987 return VOS_STATUS_E_FAILURE;
11988 }
11989
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011990 pMonModeReq = vos_mem_malloc(sizeof(tSirMonModeReq));
11991 if (pMonModeReq == NULL) {
11992 hddLog(VOS_TRACE_LEVEL_ERROR,
11993 FL("fail to allocate memory for monitor mode req"));
11994 return VOS_STATUS_E_FAILURE;
11995 }
Katya Nigamf0511f62015-05-05 16:40:57 +053011996
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053011997 pMonModeReq->context = context;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011998 pMonModeReq->data = pMonCtx;
11999 pMonModeReq->callback = callback;
Katya Nigamf0511f62015-05-05 16:40:57 +053012000
Katya Nigamf0511f62015-05-05 16:40:57 +053012001 monMsg.reserved = 0;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012002 monMsg.bodyptr = pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +053012003 monMsg.bodyval = 0;
12004
12005 if (VOS_STATUS_SUCCESS != vos_mq_post_message(
12006 VOS_MODULE_ID_WDA,(vos_msg_t *)&monMsg)) {
12007 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: : Failed to post Msg to HAL",__func__);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012008 vos_mem_free(pMonModeReq);
Katya Nigamf0511f62015-05-05 16:40:57 +053012009 }
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012010 return VOS_STATUS_SUCCESS;
Katya Nigamf0511f62015-05-05 16:40:57 +053012011}
12012
Katya Nigame7b69a82015-04-28 15:24:06 +053012013void wlan_hdd_mon_close(hdd_context_t *pHddCtx)
12014{
12015 VOS_STATUS vosStatus;
12016 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012017 hdd_mon_ctx_t *pMonCtx = NULL;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012018 int ret;
12019 void *cookie;
12020 struct hdd_request *request;
12021 static const struct hdd_request_params params = {
12022 .priv_size = 0,
12023 .timeout_ms = MON_MODE_MSG_TIMEOUT,
12024 };
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053012025
Katya Nigame7b69a82015-04-28 15:24:06 +053012026 hdd_adapter_t *pAdapter = hdd_get_adapter(pHddCtx,WLAN_HDD_MONITOR);
12027 if(pAdapter == NULL || pVosContext == NULL)
12028 {
12029 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:pAdapter is NULL",__func__);
12030 return ;
12031 }
Katya Nigamf0511f62015-05-05 16:40:57 +053012032
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012033 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
12034 if (pMonCtx!= NULL && pMonCtx->state == MON_MODE_START) {
12035 pMonCtx->state = MON_MODE_STOP;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012036 request = hdd_request_alloc(&params);
12037 if (!request) {
12038 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
12039 return;
12040 }
12041 cookie = hdd_request_cookie(request);
12042
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012043 if (VOS_STATUS_SUCCESS !=
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012044 wlan_hdd_mon_postMsg(cookie, pMonCtx,
12045 hdd_mon_post_msg_cb)) {
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012046 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12047 FL("failed to post MON MODE REQ"));
12048 pMonCtx->state = MON_MODE_START;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012049 goto req_put;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012050 }
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012051
12052 ret = hdd_request_wait_for_response(request);
12053 if (ret)
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012054 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012055 FL("timeout on monitor mode completion %d"), ret);
12056
12057req_put:
12058 hdd_request_put(request);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012059 }
12060
Katya Nigame7b69a82015-04-28 15:24:06 +053012061 hdd_UnregisterWext(pAdapter->dev);
12062
12063 vos_mon_stop( pVosContext );
12064
12065 vosStatus = vos_sched_close( pVosContext );
12066 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
12067 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
12068 "%s: Failed to close VOSS Scheduler",__func__);
12069 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12070 }
12071
12072 vosStatus = vos_nv_close();
12073 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12074 {
12075 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12076 "%s: Failed to close NV", __func__);
12077 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12078 }
12079
12080 vos_close(pVosContext);
12081
12082 #ifdef WLAN_KD_READY_NOTIFIER
12083 nl_srv_exit(pHddCtx->ptt_pid);
12084 #else
12085 nl_srv_exit();
12086 #endif
12087
Katya Nigame7b69a82015-04-28 15:24:06 +053012088 hdd_close_all_adapters( pHddCtx );
Katya Nigame7b69a82015-04-28 15:24:06 +053012089}
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012090/**
12091 * hdd_wlan_free_wiphy_channels - free Channel pointer for wiphy
12092 * @ wiphy: the wiphy to validate against
12093 *
12094 * Return: void
12095 */
12096void hdd_wlan_free_wiphy_channels(struct wiphy *wiphy)
12097{
12098 int i =0;
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053012099 for (i = 0; i < HDD_NUM_NL80211_BANDS; i++)
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012100 {
12101 if (NULL != wiphy->bands[i] &&
12102 (NULL != wiphy->bands[i]->channels))
12103 {
12104 vos_mem_free(wiphy->bands[i]->channels);
12105 wiphy->bands[i]->channels = NULL;
12106 }
12107 }
12108}
Jeff Johnson295189b2012-06-20 16:38:30 -070012109/**---------------------------------------------------------------------------
12110
12111 \brief hdd_wlan_exit() - HDD WLAN exit function
12112
12113 This is the driver exit point (invoked during rmmod)
12114
12115 \param - pHddCtx - Pointer to the HDD Context
12116
12117 \return - None
12118
12119 --------------------------------------------------------------------------*/
12120void hdd_wlan_exit(hdd_context_t *pHddCtx)
12121{
12122 eHalStatus halStatus;
12123 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
12124 VOS_STATUS vosStatus;
Gopichand Nakkala66923aa2013-03-06 23:17:24 +053012125 struct wiphy *wiphy = pHddCtx->wiphy;
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080012126 hdd_adapter_t* pAdapter = NULL;
Jeff Johnson72a40512013-12-19 10:14:15 -080012127 struct statsContext powerContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070012128 long lrc;
c_hpothu5ab05e92014-06-13 17:34:05 +053012129 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070012130
12131 ENTER();
12132
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012133
Katya Nigame7b69a82015-04-28 15:24:06 +053012134 if (VOS_MONITOR_MODE == hdd_get_conparam())
12135 {
12136 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: MONITOR MODE",__func__);
12137 wlan_hdd_mon_close(pHddCtx);
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053012138 goto free_hdd_ctx;
Katya Nigame7b69a82015-04-28 15:24:06 +053012139 }
12140 else if (VOS_FTM_MODE != hdd_get_conparam())
Jeff Johnson88ba7742013-02-27 14:36:02 -080012141 {
12142 // Unloading, restart logic is no more required.
12143 wlan_hdd_restart_deinit(pHddCtx);
Jeff Johnsone7245742012-09-05 17:12:55 -070012144
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053012145#ifdef FEATURE_WLAN_TDLS
12146 /* At the time of driver unloading; if tdls connection is present;
12147 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer.
12148 * wlan_hdd_tdls_find_peer always checks for valid context;
12149 * as load/unload in progress there can be a race condition.
12150 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer only
12151 * when tdls state is enabled.
12152 * As soon as driver set load/unload flag; tdls flag also needs
12153 * to be disabled so that hdd_rx_packet_cbk won't call
12154 * wlan_hdd_tdls_find_peer.
12155 */
Masti, Narayanraddi20494af2015-12-17 20:56:42 +053012156 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE,
12157 HDD_SET_TDLS_MODE_SOURCE_USER);
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053012158#endif
12159
c_hpothu5ab05e92014-06-13 17:34:05 +053012160 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
12161 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
Jeff Johnson295189b2012-06-20 16:38:30 -070012162 {
c_hpothu5ab05e92014-06-13 17:34:05 +053012163 pAdapter = pAdapterNode->pAdapter;
12164 if (NULL != pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070012165 {
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +053012166 /* Disable TX on the interface, after this hard_start_xmit() will
12167 * not be called on that interface
12168 */
12169 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
12170 netif_tx_disable(pAdapter->dev);
12171
12172 /* Mark the interface status as "down" for outside world */
12173 netif_carrier_off(pAdapter->dev);
12174
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053012175 /* DeInit the adapter. This ensures that all data packets
12176 * are freed.
12177 */
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053012178#ifdef FEATURE_WLAN_TDLS
12179 mutex_lock(&pHddCtx->tdls_lock);
12180#endif
c_hpothu002231a2015-02-05 14:58:51 +053012181 hdd_deinit_adapter(pHddCtx, pAdapter, FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053012182#ifdef FEATURE_WLAN_TDLS
12183 mutex_unlock(&pHddCtx->tdls_lock);
12184#endif
Masti, Narayanraddi26378462016-01-05 18:20:28 +053012185 vos_flush_delayed_work(&pHddCtx->scan_ctxt.scan_work);
12186
12187 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053012188
c_hpothu5ab05e92014-06-13 17:34:05 +053012189 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053012190 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
12191 WLAN_HDD_MONITOR == pAdapter->device_mode)
c_hpothu5ab05e92014-06-13 17:34:05 +053012192 {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053012193 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
12194 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
12195 wlan_hdd_cfg80211_deregister_frames(pAdapter);
12196
c_hpothu5ab05e92014-06-13 17:34:05 +053012197 hdd_UnregisterWext(pAdapter->dev);
12198 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012199
Jeff Johnson295189b2012-06-20 16:38:30 -070012200 }
c_hpothu5ab05e92014-06-13 17:34:05 +053012201 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
12202 pAdapterNode = pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -070012203 }
mukul sharmabab477d2015-06-11 17:14:55 +053012204
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012205 // Cancel any outstanding scan requests. We are about to close all
12206 // of our adapters, but an adapter structure is what SME passes back
12207 // to our callback function. Hence if there are any outstanding scan
12208 // requests then there is a race condition between when the adapter
12209 // is closed and when the callback is invoked.We try to resolve that
12210 // race condition here by canceling any outstanding scans before we
12211 // close the adapters.
12212 // Note that the scans may be cancelled in an asynchronous manner,
12213 // so ideally there needs to be some kind of synchronization. Rather
12214 // than introduce a new synchronization here, we will utilize the
12215 // fact that we are about to Request Full Power, and since that is
12216 // synchronized, the expectation is that by the time Request Full
12217 // Power has completed all scans will be cancelled.
12218 if (pHddCtx->scan_info.mScanPending)
12219 {
Hema Aparna Medicharlaf05f6cd2015-01-21 14:44:19 +053012220 if(NULL != pAdapter)
12221 {
12222 hddLog(VOS_TRACE_LEVEL_INFO,
12223 FL("abort scan mode: %d sessionId: %d"),
12224 pAdapter->device_mode,
12225 pAdapter->sessionId);
12226 }
12227 hdd_abort_mac_scan(pHddCtx,
12228 pHddCtx->scan_info.sessionId,
12229 eCSR_SCAN_ABORT_DEFAULT);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012230 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012231 }
c_hpothu5ab05e92014-06-13 17:34:05 +053012232 else
Jeff Johnson88ba7742013-02-27 14:36:02 -080012233 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012234 hddLog(VOS_TRACE_LEVEL_INFO,"%s: FTM MODE",__func__);
Hanumantha Reddy Pothula45af96b2015-02-12 16:07:58 +053012235 if (pHddCtx->ftm.ftm_state == WLAN_FTM_STARTING)
12236 {
12237 INIT_COMPLETION(pHddCtx->ftm.startCmpVar);
12238 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
12239 "%s: in middle of FTM START", __func__);
12240 lrc = wait_for_completion_timeout(&pHddCtx->ftm.startCmpVar,
12241 msecs_to_jiffies(20000));
12242 if(!lrc)
12243 {
12244 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
12245 "%s: timedout on ftmStartCmpVar fatal error", __func__);
12246 }
12247 }
Jeff Johnson88ba7742013-02-27 14:36:02 -080012248 wlan_hdd_ftm_close(pHddCtx);
12249 goto free_hdd_ctx;
12250 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012251
Jeff Johnson295189b2012-06-20 16:38:30 -070012252 /* DeRegister with platform driver as client for Suspend/Resume */
12253 vosStatus = hddDeregisterPmOps(pHddCtx);
12254 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
12255 {
12256 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDeregisterPmOps failed",__func__);
12257 VOS_ASSERT(0);
12258 }
12259
12260 vosStatus = hddDevTmUnregisterNotifyCallback(pHddCtx);
12261 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
12262 {
12263 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
12264 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012265
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012266 //Stop the traffic monitor timer
Mahesh A Saptasagard461e432016-07-20 15:01:40 +053012267 if ((pHddCtx->cfg_ini->dynSplitscan) && (VOS_TIMER_STATE_RUNNING ==
12268 vos_timer_getCurrentState(&pHddCtx->tx_rx_trafficTmr)))
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012269 {
12270 vos_timer_stop(&pHddCtx->tx_rx_trafficTmr);
12271 }
12272
12273 // Destroy the traffic monitor timer
Mahesh A Saptasagard461e432016-07-20 15:01:40 +053012274 if ((pHddCtx->cfg_ini->dynSplitscan) &&
12275 (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
12276 &pHddCtx->tx_rx_trafficTmr))))
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012277 {
12278 hddLog(VOS_TRACE_LEVEL_ERROR,
12279 "%s: Cannot deallocate Traffic monitor timer", __func__);
12280 }
12281
Bhargav Shahd0715912015-10-01 18:17:37 +053012282 if (VOS_TIMER_STATE_RUNNING ==
12283 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
12284 vos_timer_stop(&pHddCtx->delack_timer);
12285 }
12286
12287 if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
12288 &pHddCtx->delack_timer))) {
12289 hddLog(VOS_TRACE_LEVEL_ERROR,
12290 "%s: Cannot deallocate Bus bandwidth timer", __func__);
12291 }
12292
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053012293 if (VOS_TIMER_STATE_RUNNING ==
12294 vos_timer_getCurrentState(&pHddCtx->tdls_source_timer)) {
12295 vos_timer_stop(&pHddCtx->tdls_source_timer);
12296 }
12297
Abhishek Singh8a3e4dc2017-01-02 10:39:18 +053012298 vos_set_snoc_high_freq_voting(false);
12299
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053012300 vos_timer_destroy(&pHddCtx->tdls_source_timer);
12301
Jeff Johnson295189b2012-06-20 16:38:30 -070012302 //Disable IMPS/BMPS as we do not want the device to enter any power
12303 //save mode during shutdown
12304 sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
12305 sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
12306 sme_DisablePowerSave(pHddCtx->hHal, ePMC_UAPSD_MODE_POWER_SAVE);
12307
12308 //Ensure that device is in full power as we will touch H/W during vos_Stop
12309 init_completion(&powerContext.completion);
12310 powerContext.magic = POWER_CONTEXT_MAGIC;
12311
12312 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_power_callback,
12313 &powerContext, eSME_FULL_PWR_NEEDED_BY_HDD);
12314
12315 if (eHAL_STATUS_SUCCESS != halStatus)
12316 {
12317 if (eHAL_STATUS_PMC_PENDING == halStatus)
12318 {
12319 /* request was sent -- wait for the response */
12320 lrc = wait_for_completion_interruptible_timeout(
12321 &powerContext.completion,
12322 msecs_to_jiffies(WLAN_WAIT_TIME_POWER));
Jeff Johnson295189b2012-06-20 16:38:30 -070012323 if (lrc <= 0)
12324 {
12325 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: %s while requesting full power",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012326 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson295189b2012-06-20 16:38:30 -070012327 }
12328 }
12329 else
12330 {
12331 hddLog(VOS_TRACE_LEVEL_ERROR,
12332 "%s: Request for Full Power failed, status %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012333 __func__, halStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -070012334 /* continue -- need to clean up as much as possible */
12335 }
12336 }
Hanumantha Reddy Pothula81b42b22015-05-12 13:52:00 +053012337 if ((eHAL_STATUS_SUCCESS == halStatus) ||
12338 (eHAL_STATUS_PMC_PENDING == halStatus && lrc > 0))
12339 {
12340 /* This will issue a dump command which will clean up
12341 BTQM queues and unblock MC thread */
12342 vos_fwDumpReq(274, 0, 0, 0, 0, 1);
12343 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012344
Jeff Johnson72a40512013-12-19 10:14:15 -080012345 /* either we never sent a request, we sent a request and received a
12346 response or we sent a request and timed out. if we never sent a
12347 request or if we sent a request and got a response, we want to
12348 clear the magic out of paranoia. if we timed out there is a
12349 race condition such that the callback function could be
12350 executing at the same time we are. of primary concern is if the
12351 callback function had already verified the "magic" but had not
12352 yet set the completion variable when a timeout occurred. we
12353 serialize these activities by invalidating the magic while
12354 holding a shared spinlock which will cause us to block if the
12355 callback is currently executing */
12356 spin_lock(&hdd_context_lock);
12357 powerContext.magic = 0;
12358 spin_unlock(&hdd_context_lock);
12359
Hema Aparna Medicharlaa6cf65e2015-06-01 16:23:28 +053012360 /* If Device is shutdown, no point for SME to wait for responses
12361 from device. Pre Close SME */
12362 if(wcnss_device_is_shutdown())
12363 {
12364 sme_PreClose(pHddCtx->hHal);
12365 }
Yue Ma0d4891e2013-08-06 17:01:45 -070012366 hdd_debugfs_exit(pHddCtx);
12367
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012368#ifdef WLAN_NS_OFFLOAD
Ratheesh S P36dbc932015-08-07 14:28:57 +053012369 hddLog(LOG1, FL("Unregister IPv6 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012370 unregister_inet6addr_notifier(&pHddCtx->ipv6_notifier);
12371#endif
Ratheesh S P36dbc932015-08-07 14:28:57 +053012372 hddLog(LOG1, FL("Unregister IPv4 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012373 unregister_inetaddr_notifier(&pHddCtx->ipv4_notifier);
12374
Jeff Johnson295189b2012-06-20 16:38:30 -070012375 // Unregister the Net Device Notifier
12376 unregister_netdevice_notifier(&hdd_netdev_notifier);
12377
Jeff Johnson295189b2012-06-20 16:38:30 -070012378 hdd_stop_all_adapters( pHddCtx );
12379
Jeff Johnson295189b2012-06-20 16:38:30 -070012380#ifdef WLAN_BTAMP_FEATURE
12381 vosStatus = WLANBAP_Stop(pVosContext);
12382 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12383 {
12384 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12385 "%s: Failed to stop BAP",__func__);
12386 }
12387#endif //WLAN_BTAMP_FEATURE
12388
12389 //Stop all the modules
12390 vosStatus = vos_stop( pVosContext );
12391 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12392 {
12393 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
12394 "%s: Failed to stop VOSS",__func__);
12395 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053012396 if (isSsrPanicOnFailure())
12397 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -070012398 }
12399
Jeff Johnson295189b2012-06-20 16:38:30 -070012400 //This requires pMac access, Call this before vos_close().
Jeff Johnson295189b2012-06-20 16:38:30 -070012401 hdd_unregister_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070012402
12403 //Close the scheduler before calling vos_close to make sure no thread is
12404 // scheduled after the each module close is called i.e after all the data
12405 // structures are freed.
12406 vosStatus = vos_sched_close( pVosContext );
12407 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
12408 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
12409 "%s: Failed to close VOSS Scheduler",__func__);
12410 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12411 }
Jeff Johnsone7245742012-09-05 17:12:55 -070012412#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
12413 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012414 vos_wake_lock_destroy(&pHddCtx->rx_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -070012415#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080012416 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012417 vos_wake_lock_destroy(&pHddCtx->sap_wake_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012418
Mihir Shete7a24b5f2013-12-21 12:18:31 +053012419#ifdef CONFIG_ENABLE_LINUX_REG
12420 vosStatus = vos_nv_close();
12421 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12422 {
12423 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12424 "%s: Failed to close NV", __func__);
12425 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12426 }
12427#endif
12428
Jeff Johnson295189b2012-06-20 16:38:30 -070012429 //Close VOSS
12430 //This frees pMac(HAL) context. There should not be any call that requires pMac access after this.
12431 vos_close(pVosContext);
12432
Jeff Johnson295189b2012-06-20 16:38:30 -070012433 //Close Watchdog
12434 if(pHddCtx->cfg_ini->fIsLogpEnabled)
12435 vos_watchdog_close(pVosContext);
12436
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053012437 //Clean up HDD Nlink Service
12438 send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0);
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053012439
Manjeet Singh47ee8472016-04-11 11:57:18 +053012440 hdd_close_tx_queues(pHddCtx);
c_manjeecfd1efb2015-09-25 19:32:34 +053012441 wlan_free_fwr_mem_dump_buffer();
12442 memdump_deinit();
12443
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012444#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053012445 if (pHddCtx->cfg_ini->wlanLoggingEnable)
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012446 {
12447 wlan_logging_sock_deactivate_svc();
12448 }
12449#endif
12450
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053012451#ifdef WLAN_KD_READY_NOTIFIER
12452 nl_srv_exit(pHddCtx->ptt_pid);
12453#else
12454 nl_srv_exit();
12455#endif /* WLAN_KD_READY_NOTIFIER */
12456
Abhishek Singh00b71972016-01-07 10:51:04 +053012457#ifdef WLAN_FEATURE_RMC
12458 hdd_close_cesium_nl_sock();
12459#endif /* WLAN_FEATURE_RMC */
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053012460
Jeff Johnson295189b2012-06-20 16:38:30 -070012461 hdd_close_all_adapters( pHddCtx );
12462
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053012463 vos_flush_delayed_work(&pHddCtx->spoof_mac_addr_work);
Abhishek Singh78c691f2017-11-30 13:48:44 +053012464 vos_flush_delayed_work(&pHddCtx->ecsa_chan_change_work);
Kapil Gupta137ef892016-12-13 19:38:00 +053012465 vos_flush_work(&pHddCtx->sap_start_work);
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053012466
Hanumantha Reddy Pothula97f9bc92015-08-10 17:21:20 +053012467free_hdd_ctx:
Jeff Johnson295189b2012-06-20 16:38:30 -070012468 /* free the power on lock from platform driver */
12469 if (free_riva_power_on_lock("wlan"))
12470 {
12471 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to free power on lock",
12472 __func__);
12473 }
12474
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +053012475 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
12476 wlan_hdd_free_cache_channels(pHddCtx);
12477
c_hpothu78c7b602014-05-17 17:35:49 +053012478 //Free up dynamically allocated members inside HDD Adapter
12479 if (pHddCtx->cfg_ini)
12480 {
12481 kfree(pHddCtx->cfg_ini);
12482 pHddCtx->cfg_ini= NULL;
12483 }
12484
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053012485 hdd_request_manager_deinit();
12486
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053012487 /* FTM/MONITOR mode, WIPHY did not registered
Leo Changf04ddad2013-09-18 13:46:38 -070012488 If un-register here, system crash will happen */
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053012489 if (!(VOS_FTM_MODE == hdd_get_conparam() ||
12490 VOS_MONITOR_MODE == hdd_get_conparam()))
Leo Changf04ddad2013-09-18 13:46:38 -070012491 {
12492 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012493 hdd_wlan_free_wiphy_channels(wiphy);
Leo Changf04ddad2013-09-18 13:46:38 -070012494 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012495 wiphy_free(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070012496 if (hdd_is_ssr_required())
12497 {
12498 /* WDI timeout had happened during unload, so SSR is needed here */
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -070012499 subsystem_restart("wcnss");
Jeff Johnson295189b2012-06-20 16:38:30 -070012500 msleep(5000);
12501 }
12502 hdd_set_ssr_required (VOS_FALSE);
12503}
12504
12505
12506/**---------------------------------------------------------------------------
12507
12508 \brief hdd_update_config_from_nv() - Function to update the contents of
12509 the running configuration with parameters taken from NV storage
12510
12511 \param - pHddCtx - Pointer to the HDD global context
12512
12513 \return - VOS_STATUS_SUCCESS if successful
12514
12515 --------------------------------------------------------------------------*/
12516static VOS_STATUS hdd_update_config_from_nv(hdd_context_t* pHddCtx)
12517{
Jeff Johnson295189b2012-06-20 16:38:30 -070012518 v_BOOL_t itemIsValid = VOS_FALSE;
12519 VOS_STATUS status;
12520 v_MACADDR_t macFromNV[VOS_MAX_CONCURRENCY_PERSONA];
12521 v_U8_t macLoop;
12522
12523 /*If the NV is valid then get the macaddress from nv else get it from qcom_cfg.ini*/
12524 status = vos_nv_getValidity(VNV_FIELD_IMAGE, &itemIsValid);
12525 if(status != VOS_STATUS_SUCCESS)
12526 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080012527 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_getValidity() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070012528 return VOS_STATUS_E_FAILURE;
12529 }
12530
12531 if (itemIsValid == VOS_TRUE)
12532 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080012533 hddLog(VOS_TRACE_LEVEL_INFO_HIGH," Reading the Macaddress from NV");
Jeff Johnson295189b2012-06-20 16:38:30 -070012534 status = vos_nv_readMultiMacAddress((v_U8_t *)&macFromNV[0].bytes[0],
12535 VOS_MAX_CONCURRENCY_PERSONA);
12536 if(status != VOS_STATUS_SUCCESS)
12537 {
12538 /* Get MAC from NV fail, not update CFG info
12539 * INI MAC value will be used for MAC setting */
Arif Hussain6d2a3322013-11-17 19:50:10 -080012540 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_readMacAddress() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070012541 return VOS_STATUS_E_FAILURE;
12542 }
12543
12544 /* If first MAC is not valid, treat all others are not valid
12545 * Then all MACs will be got from ini file */
12546 if(vos_is_macaddr_zero(&macFromNV[0]))
12547 {
12548 /* MAC address in NV file is not configured yet */
12549 hddLog(VOS_TRACE_LEVEL_WARN, "Invalid MAC in NV file");
12550 return VOS_STATUS_E_INVAL;
12551 }
12552
12553 /* Get MAC address from NV, update CFG info */
12554 for(macLoop = 0; macLoop < VOS_MAX_CONCURRENCY_PERSONA; macLoop++)
12555 {
12556 if(vos_is_macaddr_zero(&macFromNV[macLoop]))
12557 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012558 hddLog(VOS_TRACE_LEVEL_ERROR,"not valid MAC from NV for %d", macLoop);
Jeff Johnson295189b2012-06-20 16:38:30 -070012559 /* This MAC is not valid, skip it
12560 * This MAC will be got from ini file */
12561 }
12562 else
12563 {
12564 vos_mem_copy((v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[macLoop].bytes[0],
12565 (v_U8_t *)&macFromNV[macLoop].bytes[0],
12566 VOS_MAC_ADDR_SIZE);
12567 }
12568 }
12569 }
12570 else
12571 {
12572 hddLog(VOS_TRACE_LEVEL_ERROR, "NV ITEM, MAC Not valid");
12573 return VOS_STATUS_E_FAILURE;
12574 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012575
Jeff Johnson295189b2012-06-20 16:38:30 -070012576
12577 return VOS_STATUS_SUCCESS;
12578}
12579
12580/**---------------------------------------------------------------------------
12581
12582 \brief hdd_post_voss_start_config() - HDD post voss start config helper
12583
12584 \param - pAdapter - Pointer to the HDD
12585
12586 \return - None
12587
12588 --------------------------------------------------------------------------*/
12589VOS_STATUS hdd_post_voss_start_config(hdd_context_t* pHddCtx)
12590{
12591 eHalStatus halStatus;
12592 v_U32_t listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012593 tANI_U32 ignoreDtim;
Jeff Johnson295189b2012-06-20 16:38:30 -070012594
Jeff Johnson295189b2012-06-20 16:38:30 -070012595
12596 // Send ready indication to the HDD. This will kick off the MAC
12597 // into a 'running' state and should kick off an initial scan.
12598 halStatus = sme_HDDReadyInd( pHddCtx->hHal );
12599 if ( !HAL_STATUS_SUCCESS( halStatus ) )
12600 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +053012601 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: sme_HDDReadyInd() failed with status "
Jeff Johnson295189b2012-06-20 16:38:30 -070012602 "code %08d [x%08x]",__func__, halStatus, halStatus );
12603 return VOS_STATUS_E_FAILURE;
12604 }
12605
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012606 // Set default LI and ignoreDtim into HDD context,
Jeff Johnson295189b2012-06-20 16:38:30 -070012607 // otherwise under some race condition, HDD will set 0 LI value into RIVA,
12608 // And RIVA will crash
12609 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, &listenInterval);
12610 pHddCtx->hdd_actual_LI_value = listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012611 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, &ignoreDtim);
12612 pHddCtx->hdd_actual_ignore_DTIM_value = ignoreDtim;
12613
12614
Jeff Johnson295189b2012-06-20 16:38:30 -070012615 return VOS_STATUS_SUCCESS;
12616}
12617
Jeff Johnson295189b2012-06-20 16:38:30 -070012618/* wake lock APIs for HDD */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012619void hdd_prevent_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070012620{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012621
12622 vos_wake_lock_acquire(&wlan_wake_lock, reason);
12623
Jeff Johnson295189b2012-06-20 16:38:30 -070012624}
12625
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012626void hdd_allow_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070012627{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012628
12629 vos_wake_lock_release(&wlan_wake_lock, reason);
12630
Jeff Johnson295189b2012-06-20 16:38:30 -070012631}
12632
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012633void hdd_prevent_suspend_timeout(v_U32_t timeout, uint32_t reason)
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070012634{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012635
12636 vos_wake_lock_timeout_release(&wlan_wake_lock, timeout,
12637 reason);
12638
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070012639}
12640
Jeff Johnson295189b2012-06-20 16:38:30 -070012641/**---------------------------------------------------------------------------
12642
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012643 \brief hdd_exchange_version_and_caps() - HDD function to exchange version and capability
12644 information between Host and Riva
12645
12646 This function gets reported version of FW
12647 It also finds the version of Riva headers used to compile the host
12648 It compares the above two and prints a warning if they are different
12649 It gets the SW and HW version string
12650 Finally, it exchanges capabilities between host and Riva i.e. host and riva exchange a msg
12651 indicating the features they support through a bitmap
12652
12653 \param - pHddCtx - Pointer to HDD context
12654
12655 \return - void
12656
12657 --------------------------------------------------------------------------*/
12658
12659void hdd_exchange_version_and_caps(hdd_context_t *pHddCtx)
12660{
12661
12662 tSirVersionType versionCompiled;
12663 tSirVersionType versionReported;
12664 tSirVersionString versionString;
12665 tANI_U8 fwFeatCapsMsgSupported = 0;
12666 VOS_STATUS vstatus;
12667
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080012668 memset(&versionCompiled, 0, sizeof(versionCompiled));
12669 memset(&versionReported, 0, sizeof(versionReported));
12670
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012671 /* retrieve and display WCNSS version information */
12672 do {
12673
12674 vstatus = sme_GetWcnssWlanCompiledVersion(pHddCtx->hHal,
12675 &versionCompiled);
12676 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12677 {
12678 hddLog(VOS_TRACE_LEVEL_FATAL,
12679 "%s: unable to retrieve WCNSS WLAN compiled version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012680 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012681 break;
12682 }
12683
12684 vstatus = sme_GetWcnssWlanReportedVersion(pHddCtx->hHal,
12685 &versionReported);
12686 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12687 {
12688 hddLog(VOS_TRACE_LEVEL_FATAL,
12689 "%s: unable to retrieve WCNSS WLAN reported version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012690 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012691 break;
12692 }
12693
12694 if ((versionCompiled.major != versionReported.major) ||
12695 (versionCompiled.minor != versionReported.minor) ||
12696 (versionCompiled.version != versionReported.version) ||
12697 (versionCompiled.revision != versionReported.revision))
12698 {
12699 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
12700 "Host expected %u.%u.%u.%u\n",
12701 WLAN_MODULE_NAME,
12702 (int)versionReported.major,
12703 (int)versionReported.minor,
12704 (int)versionReported.version,
12705 (int)versionReported.revision,
12706 (int)versionCompiled.major,
12707 (int)versionCompiled.minor,
12708 (int)versionCompiled.version,
12709 (int)versionCompiled.revision);
12710 }
12711 else
12712 {
12713 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
12714 WLAN_MODULE_NAME,
12715 (int)versionReported.major,
12716 (int)versionReported.minor,
12717 (int)versionReported.version,
12718 (int)versionReported.revision);
12719 }
12720
12721 vstatus = sme_GetWcnssSoftwareVersion(pHddCtx->hHal,
12722 versionString,
12723 sizeof(versionString));
12724 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12725 {
12726 hddLog(VOS_TRACE_LEVEL_FATAL,
12727 "%s: unable to retrieve WCNSS software version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012728 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012729 break;
12730 }
12731
12732 pr_info("%s: WCNSS software version %s\n",
12733 WLAN_MODULE_NAME, versionString);
Sushant Kaushik084f6592015-09-10 13:11:56 +053012734 vos_mem_copy(pHddCtx->fw_Version, versionString, sizeof(versionString));
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012735
12736 vstatus = sme_GetWcnssHardwareVersion(pHddCtx->hHal,
12737 versionString,
12738 sizeof(versionString));
12739 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12740 {
12741 hddLog(VOS_TRACE_LEVEL_FATAL,
12742 "%s: unable to retrieve WCNSS hardware version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012743 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012744 break;
12745 }
12746
12747 pr_info("%s: WCNSS hardware version %s\n",
12748 WLAN_MODULE_NAME, versionString);
12749
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012750 /* 1.Check if FW version is greater than 0.1.1.0. Only then send host-FW capability exchange message
12751 2.Host-FW capability exchange message is only present on riva 1.1 so
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012752 send the message only if it the riva is 1.1
12753 minor numbers for different riva branches:
12754 0 -> (1.0)Mainline Build
12755 1 -> (1.1)Mainline Build
12756 2->(1.04) Stability Build
12757 */
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012758 if (((versionReported.major>0) || (versionReported.minor>1) ||
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012759 ((versionReported.minor>=1) && (versionReported.version>=1)))
12760 && ((versionReported.major == 1) && (versionReported.minor >= 1)))
12761 fwFeatCapsMsgSupported = 1;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012762
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012763 if (fwFeatCapsMsgSupported)
Yathish9f22e662012-12-10 14:21:35 -080012764 {
12765#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
12766 if(!pHddCtx->cfg_ini->fEnableActiveModeOffload)
12767 sme_disableFeatureCapablity(WLANACTIVE_OFFLOAD);
12768#endif
Ravi Joshid2ca7c42013-07-23 08:37:49 -070012769 /* Indicate if IBSS heartbeat monitoring needs to be offloaded */
12770 if (!pHddCtx->cfg_ini->enableIbssHeartBeatOffload)
12771 {
12772 sme_disableFeatureCapablity(IBSS_HEARTBEAT_OFFLOAD);
12773 }
12774
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012775 sme_featureCapsExchange(pHddCtx->hHal);
Yathish9f22e662012-12-10 14:21:35 -080012776 }
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012777
12778 } while (0);
12779
12780}
Neelansh Mittaledafed22014-09-04 18:54:39 +053012781void wlan_hdd_send_svc_nlink_msg(int type, void *data, int len)
12782{
12783 struct sk_buff *skb;
12784 struct nlmsghdr *nlh;
12785 tAniMsgHdr *ani_hdr;
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053012786 int flags = GFP_KERNEL;
Bhargav shah23c94942015-10-13 12:48:35 +053012787 void *nl_data = NULL;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012788
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053012789 if (in_interrupt() || irqs_disabled() || in_atomic())
12790 flags = GFP_ATOMIC;
12791
12792 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
Neelansh Mittaledafed22014-09-04 18:54:39 +053012793
12794 if(skb == NULL) {
12795 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12796 "%s: alloc_skb failed", __func__);
12797 return;
12798 }
12799
12800 nlh = (struct nlmsghdr *)skb->data;
12801 nlh->nlmsg_pid = 0; /* from kernel */
12802 nlh->nlmsg_flags = 0;
12803 nlh->nlmsg_seq = 0;
12804 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12805
12806 ani_hdr = NLMSG_DATA(nlh);
12807 ani_hdr->type = type;
12808
12809 switch(type) {
12810 case WLAN_SVC_SAP_RESTART_IND:
12811 ani_hdr->length = 0;
12812 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
12813 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr)));
12814 break;
Bhargav Shahd0715912015-10-01 18:17:37 +053012815 case WLAN_SVC_WLAN_TP_IND:
12816 ani_hdr->length = len;
12817 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)
12818 + len));
12819 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12820 memcpy(nl_data, data, len);
12821 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
12822 break;
Bhargav shah23c94942015-10-13 12:48:35 +053012823 case WLAN_MSG_RPS_ENABLE_IND:
12824 ani_hdr->length = len;
12825 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12826 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12827 memcpy(nl_data, data, len);
12828 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
12829 break;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012830 default:
12831 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12832 "Attempt to send unknown nlink message %d", type);
12833 kfree_skb(skb);
12834 return;
12835 }
12836
12837 nl_srv_bcast(skb);
12838
12839 return;
12840}
12841
Bhargav Shahd0715912015-10-01 18:17:37 +053012842/**
12843 * hdd_request_tcp_delack() - Find the Delack value based on RX packet
12844 * @pHddCtx: Valid Global HDD context pointer
12845 * @rx_packets: Number of RX packet in perticular time
12846 *
12847 * Based on the RX packet this function calculate next value of tcp delack.
12848 * This function compare rx packet value to high and low threshold limit.
12849 *
12850 * Return: void
12851 */
12852void hdd_request_tcp_delack(hdd_context_t *pHddCtx, uint64_t rx_packets)
12853{
12854 /* average of rx_packets and prev_rx is taken so that
12855 bus width doesnot fluctuate much */
12856 uint64_t temp_rx = (rx_packets + pHddCtx->prev_rx)/2;
12857 TP_IND_TYPE next_rx_level = pHddCtx->cur_rx_level;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012858
Bhargav Shahd0715912015-10-01 18:17:37 +053012859 pHddCtx->prev_rx = rx_packets;
12860 if (temp_rx > pHddCtx->cfg_ini->tcpDelAckThresholdHigh)
12861 next_rx_level = TP_IND_HIGH;
12862 else if (temp_rx <= pHddCtx->cfg_ini->tcpDelAckThresholdLow)
12863 next_rx_level = TP_IND_LOW;
12864
12865 hdd_set_delack_value(pHddCtx, next_rx_level);
12866}
12867
12868#define HDD_BW_GET_DIFF(x, y) ((x) >= (y) ? (x) - (y) : (ULONG_MAX - (y) + (x)))
12869
12870/**
12871 * hdd_tcp_delack_compute_function() - get link status
12872 * @priv: Valid Global HDD context pointer
12873 *
12874 * This function find number of RX packet during timer life span.
12875 * It request tcp delack with number of RX packet and re-configure delack timer
12876 * for tcpDelAckComputeInterval timer interval.
12877 *
12878 * Return: void
12879 */
12880void hdd_tcp_delack_compute_function(void *priv)
12881{
12882 hdd_context_t *pHddCtx = (hdd_context_t *)priv;
12883 hdd_adapter_t *pAdapter = NULL;
12884 v_U32_t rx_packets = 0;
12885 hdd_adapter_list_node_t *pAdapterNode = NULL;
12886 VOS_STATUS status = 0;
12887
12888 for (status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
12889 NULL != pAdapterNode && VOS_STATUS_SUCCESS == status;
12890 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pAdapterNode)) {
12891 if ((pAdapter = pAdapterNode->pAdapter) == NULL)
12892 continue;
12893
12894 rx_packets += HDD_BW_GET_DIFF(pAdapter->stats.rx_packets,
12895 pAdapter->prev_rx_packets);
12896 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
12897 }
12898
12899 hdd_request_tcp_delack(pHddCtx, rx_packets);
12900
12901 vos_timer_start(&pHddCtx->delack_timer,
12902 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
12903}
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012904
12905/**---------------------------------------------------------------------------
12906
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012907 \brief hdd_is_5g_supported() - HDD function to know if hardware supports 5GHz
12908
12909 \param - pHddCtx - Pointer to the hdd context
12910
12911 \return - true if hardware supports 5GHz
12912
12913 --------------------------------------------------------------------------*/
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +053012914boolean hdd_is_5g_supported(hdd_context_t * pHddCtx)
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012915{
12916 /* If wcnss_wlan_iris_xo_mode() returns WCNSS_XO_48MHZ(1);
12917 * then hardware support 5Ghz.
12918 */
12919 if (WCNSS_XO_48MHZ == wcnss_wlan_iris_xo_mode())
12920 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053012921 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware supports 5Ghz", __func__);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012922 return true;
12923 }
12924 else
12925 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053012926 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware doesn't supports 5Ghz",
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012927 __func__);
12928 return false;
12929 }
12930}
12931
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053012932/**---------------------------------------------------------------------------
12933
12934 \brief hdd_generate_iface_mac_addr_auto() - HDD Mac Interface Auto
12935 generate function
12936
12937 This is generate the random mac address for WLAN interface
12938
12939 \param - pHddCtx - Pointer to HDD context
12940 idx - Start interface index to get auto
12941 generated mac addr.
12942 mac_addr - Mac address
12943
12944 \return - 0 for success, < 0 for failure
12945
12946 --------------------------------------------------------------------------*/
12947
12948static int hdd_generate_iface_mac_addr_auto(hdd_context_t *pHddCtx,
12949 int idx, v_MACADDR_t mac_addr)
12950{
12951 int i;
12952 unsigned int serialno;
12953 serialno = wcnss_get_serial_number();
12954
12955 if (0 != serialno)
12956 {
12957 /* MAC address has 3 bytes of OUI so we have a maximum of 3
12958 bytes of the serial number that can be used to generate
12959 the other 3 bytes of the MAC address. Mask off all but
12960 the lower 3 bytes (this will also make sure we don't
12961 overflow in the next step) */
12962 serialno &= 0x00FFFFFF;
12963
12964 /* we need a unique address for each session */
12965 serialno *= VOS_MAX_CONCURRENCY_PERSONA;
12966
12967 /* autogen other Mac addresses */
12968 for (i = idx; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
12969 {
12970 /* start with the entire default address */
12971 pHddCtx->cfg_ini->intfMacAddr[i] = mac_addr;
12972 /* then replace the lower 3 bytes */
12973 pHddCtx->cfg_ini->intfMacAddr[i].bytes[3] = (serialno >> 16) & 0xFF;
12974 pHddCtx->cfg_ini->intfMacAddr[i].bytes[4] = (serialno >> 8) & 0xFF;
12975 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] = serialno & 0xFF;
12976
Nachiket Kukadede2e24f2017-09-25 16:24:27 +053012977 if (0 == memcmp(&pHddCtx->cfg_ini->intfMacAddr[i].bytes[0],
12978 &mac_addr.bytes[0], VOS_MAC_ADDR_SIZE))
12979 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] +=
12980 VOS_MAX_CONCURRENCY_PERSONA;
12981
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053012982 serialno++;
12983 hddLog(VOS_TRACE_LEVEL_ERROR,
12984 "%s: Derived Mac Addr: "
12985 MAC_ADDRESS_STR, __func__,
12986 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[i].bytes));
12987 }
12988
12989 }
12990 else
12991 {
12992 hddLog(LOGE, FL("Failed to Get Serial NO"));
12993 return -1;
12994 }
12995 return 0;
12996}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012997
Katya Nigame7b69a82015-04-28 15:24:06 +053012998int wlan_hdd_mon_open(hdd_context_t *pHddCtx)
12999{
13000 VOS_STATUS status;
13001 v_CONTEXT_t pVosContext= NULL;
13002 hdd_adapter_t *pAdapter= NULL;
13003
13004 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
13005
13006 if (NULL == pVosContext)
13007 {
13008 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13009 "%s: Trying to open VOSS without a PreOpen", __func__);
13010 VOS_ASSERT(0);
13011 return VOS_STATUS_E_FAILURE;
13012 }
13013
13014 status = vos_nv_open();
13015 if (!VOS_IS_STATUS_SUCCESS(status))
13016 {
13017 /* NV module cannot be initialized */
13018 hddLog( VOS_TRACE_LEVEL_FATAL,
13019 "%s: vos_nv_open failed", __func__);
13020 return VOS_STATUS_E_FAILURE;
13021 }
13022
13023 status = vos_init_wiphy_from_nv_bin();
13024 if (!VOS_IS_STATUS_SUCCESS(status))
13025 {
13026 /* NV module cannot be initialized */
13027 hddLog( VOS_TRACE_LEVEL_FATAL,
13028 "%s: vos_init_wiphy failed", __func__);
13029 goto err_vos_nv_close;
13030 }
13031
13032 status = vos_open( &pVosContext, pHddCtx->parent_dev);
13033 if ( !VOS_IS_STATUS_SUCCESS( status ))
13034 {
13035 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
13036 goto err_vos_nv_close;
13037 }
13038
13039 status = vos_mon_start( pVosContext );
13040 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13041 {
13042 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
13043 goto err_vosclose;
13044 }
13045
13046 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
13047 WDA_featureCapsExchange(pVosContext);
13048 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
13049
13050 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_MONITOR, "wlan%d",
13051 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
13052 if( pAdapter == NULL )
13053 {
13054 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
13055 goto err_close_adapter;
13056 }
13057
13058 //Initialize the nlink service
13059 if(nl_srv_init() != 0)
13060 {
13061 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
13062 goto err_close_adapter;
13063 }
13064 return VOS_STATUS_SUCCESS;
13065
13066err_close_adapter:
13067 hdd_close_all_adapters( pHddCtx );
13068 vos_mon_stop( pVosContext );
13069err_vosclose:
13070 status = vos_sched_close( pVosContext );
13071 if (!VOS_IS_STATUS_SUCCESS(status)) {
13072 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
13073 "%s: Failed to close VOSS Scheduler", __func__);
13074 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
13075 }
13076 vos_close(pVosContext );
13077
13078err_vos_nv_close:
13079 vos_nv_close();
13080
13081return status;
13082}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013083/**---------------------------------------------------------------------------
13084
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013085 \brief hdd_11d_scan_done - callback to be executed when 11d scan is
13086 completed to flush out the scan results
13087
13088 11d scan is done during driver load and is a passive scan on all
13089 channels supported by the device, 11d scans may find some APs on
13090 frequencies which are forbidden to be used in the regulatory domain
13091 the device is operating in. If these APs are notified to the supplicant
13092 it may try to connect to these APs, thus flush out all the scan results
13093 which are present in SME after 11d scan is done.
13094
13095 \return - eHalStatus
13096
13097 --------------------------------------------------------------------------*/
13098static eHalStatus hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
13099 tANI_U32 scanId, eCsrScanStatus status)
13100{
13101 ENTER();
13102
13103 sme_ScanFlushResult(halHandle, 0);
13104
13105 EXIT();
13106
13107 return eHAL_STATUS_SUCCESS;
13108}
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013109/**---------------------------------------------------------------------------
13110
13111 \brief hdd_init_frame_logging_done - callback to be executed when mgmt frame
13112 logging is completed successfully.
13113
13114 \return - None
13115
13116 --------------------------------------------------------------------------*/
c_manjeecfd1efb2015-09-25 19:32:34 +053013117void hdd_init_frame_logging_done(void *fwlogInitCbContext, tAniLoggingInitRsp *pRsp)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013118{
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013119 hdd_context_t* pHddCtx = (hdd_context_t*)fwlogInitCbContext;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013120
13121 if (NULL == pHddCtx)
13122 {
13123 hddLog(VOS_TRACE_LEVEL_ERROR,
13124 "%s: HDD context is NULL",__func__);
13125 return;
13126 }
13127
c_manjeecfd1efb2015-09-25 19:32:34 +053013128 if ((pRsp->status == VOS_STATUS_SUCCESS) &&
Mahesh A Saptasagarfabb1a02015-06-29 12:17:04 +053013129 (TRUE == pHddCtx->cfg_ini->enableMgmtLogging))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013130 {
13131 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init successful"));
13132 pHddCtx->mgmt_frame_logging = TRUE;
13133 }
13134 else
13135 {
13136 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init not success"));
13137 pHddCtx->mgmt_frame_logging = FALSE;
c_manjeecfd1efb2015-09-25 19:32:34 +053013138 return;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013139 }
13140
c_manjeecfd1efb2015-09-25 19:32:34 +053013141 /*Check feature supported by FW*/
13142 if(TRUE == sme_IsFeatureSupportedByFW(MEMORY_DUMP_SUPPORTED))
13143 {
13144 //Store fwr mem dump size given by firmware.
13145 wlan_store_fwr_mem_dump_size(pRsp->fw_mem_dump_max_size);
13146 }
13147 else
13148 {
13149 wlan_store_fwr_mem_dump_size(0);
13150 }
13151
13152
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013153}
13154/**---------------------------------------------------------------------------
13155
13156 \brief hdd_init_frame_logging - function to initialize frame logging.
13157 Currently only Mgmt Frames are logged in both TX
13158 and Rx direction and are sent to userspace
13159 application using logger thread when queried.
13160
13161 \return - None
13162
13163 --------------------------------------------------------------------------*/
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013164void hdd_init_frame_logging(hdd_context_t* pHddCtx)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013165{
13166 eHalStatus halStatus = eHAL_STATUS_FAILURE;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013167 tSirFWLoggingInitParam wlanFWLoggingInitParam = {0};
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013168
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013169 if (TRUE != sme_IsFeatureSupportedByFW(MGMT_FRAME_LOGGING) &&
13170 TRUE != sme_IsFeatureSupportedByFW(LOGGING_ENHANCEMENT))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013171 {
13172 hddLog(VOS_TRACE_LEVEL_INFO, FL("MGMT_FRAME_LOGGING not supp by FW"));
13173 return;
13174 }
13175
c_manjeecfd1efb2015-09-25 19:32:34 +053013176 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Configuring %s %s %s %s Logging",__func__,
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013177 pHddCtx->cfg_ini->enableFWLogging?"FW Log,":"",
13178 pHddCtx->cfg_ini->enableContFWLogging ? "Cont FW log,":"",
c_manjeecfd1efb2015-09-25 19:32:34 +053013179 pHddCtx->cfg_ini->enableMgmtLogging ? "Mgmt Pkt Log":"",
13180 pHddCtx->cfg_ini->enableFwrMemDump ? "Fw Mem dump":"");
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013181
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013182 if (pHddCtx->cfg_ini->enableFWLogging ||
13183 pHddCtx->cfg_ini->enableContFWLogging)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013184 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013185 wlanFWLoggingInitParam.enableFlag |= WLAN_QXDM_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013186 }
13187
Sushant Kaushik46804902015-07-08 14:46:03 +053013188 if (pHddCtx->cfg_ini->enableMgmtLogging)
13189 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013190 wlanFWLoggingInitParam.enableFlag |= WLAN_FRAME_LOG_EN;
Sushant Kaushik46804902015-07-08 14:46:03 +053013191 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013192 if (pHddCtx->cfg_ini->enableBMUHWtracing)
13193 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013194 wlanFWLoggingInitParam.enableFlag |= WLAN_BMUHW_TRACE_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013195 }
c_manjeecfd1efb2015-09-25 19:32:34 +053013196 if(pHddCtx->cfg_ini->enableFwrMemDump &&
13197 (TRUE == sme_IsFeatureSupportedByFW(MEMORY_DUMP_SUPPORTED)))
13198 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013199 wlanFWLoggingInitParam.enableFlag |= WLAN_FW_MEM_DUMP_EN;
c_manjeecfd1efb2015-09-25 19:32:34 +053013200 }
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013201 if( wlanFWLoggingInitParam.enableFlag == 0 )
c_manjeecfd1efb2015-09-25 19:32:34 +053013202 {
13203 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Logging not enabled", __func__);
13204 return;
13205 }
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013206 wlanFWLoggingInitParam.frameType = WLAN_FRAME_LOGGING_FRAMETYPE_MGMT;
13207 wlanFWLoggingInitParam.frameSize = WLAN_MGMT_LOGGING_FRAMESIZE_128BYTES;
13208 wlanFWLoggingInitParam.bufferMode = WLAN_FRAME_LOGGING_BUFFERMODE_CIRCULAR;
13209 wlanFWLoggingInitParam.continuousFrameLogging =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013210 pHddCtx->cfg_ini->enableContFWLogging;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013211
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013212 wlanFWLoggingInitParam.enableFlag &= ~WLAN_DPU_TXP_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013213
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013214 wlanFWLoggingInitParam.minLogBufferSize =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013215 pHddCtx->cfg_ini->minLoggingBufferSize;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013216 wlanFWLoggingInitParam.maxLogBufferSize =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013217 pHddCtx->cfg_ini->maxLoggingBufferSize;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013218 wlanFWLoggingInitParam.fwlogInitCallback = hdd_init_frame_logging_done;
13219 wlanFWLoggingInitParam.fwlogInitCbContext= pHddCtx;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013220
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013221 halStatus = sme_InitMgmtFrameLogging(pHddCtx->hHal, &wlanFWLoggingInitParam);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013222
13223 if (eHAL_STATUS_SUCCESS != halStatus)
13224 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013225 hddLog(LOGE, FL("sme_InitMgmtFrameLogging failed, returned %d"),
13226 halStatus);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013227 }
13228
13229 return;
13230}
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013231
Bhargav shah23c94942015-10-13 12:48:35 +053013232static void hdd_dp_util_send_rps_ind(hdd_context_t *hdd_ctxt)
13233{
13234 hdd_adapter_t *adapter;
13235 hdd_adapter_list_node_t *adapter_node, *next;
13236 VOS_STATUS status = VOS_STATUS_SUCCESS;
13237 struct wlan_rps_data rps_data;
13238 int count;
13239
13240 if(!hdd_ctxt->cfg_ini->rps_mask)
13241 {
13242 return;
13243 }
13244
13245 for (count=0; count < WLAN_SVC_IFACE_NUM_QUEUES; count++)
13246 {
13247 rps_data.cpu_map[count] = hdd_ctxt->cfg_ini->rps_mask;
13248 }
13249
13250 rps_data.num_queues = WLAN_SVC_IFACE_NUM_QUEUES;
13251
13252 hddLog(LOG1, FL("0x%x 0x%x 0x%x 0x%x 0x%x 0x%x"),
13253 rps_data.cpu_map[0], rps_data.cpu_map[1],rps_data.cpu_map[2],
13254 rps_data.cpu_map[3], rps_data.cpu_map[4], rps_data.cpu_map[5]);
13255
13256 status = hdd_get_front_adapter (hdd_ctxt, &adapter_node);
13257
13258 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status)
13259 {
13260 adapter = adapter_node->pAdapter;
13261 if (NULL != adapter) {
13262 strlcpy(rps_data.ifname, adapter->dev->name,
13263 sizeof(rps_data.ifname));
13264 wlan_hdd_send_svc_nlink_msg(WLAN_MSG_RPS_ENABLE_IND,
13265 (void *)&rps_data,sizeof(rps_data));
13266 }
13267 status = hdd_get_next_adapter (hdd_ctxt, adapter_node, &next);
13268 adapter_node = next;
13269 }
13270}
13271
Masti, Narayanraddi26378462016-01-05 18:20:28 +053013272void wlan_hdd_schedule_defer_scan(struct work_struct *work)
13273{
13274 scan_context_t *scan_ctx =
13275 container_of(work, scan_context_t, scan_work.work);
13276
13277 if (NULL == scan_ctx)
13278 {
13279 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13280 FL("scan_ctx is NULL"));
13281 return;
13282 }
13283
13284 if (unlikely(TDLS_CTX_MAGIC != scan_ctx->magic))
13285 return;
13286
13287 scan_ctx->attempt++;
13288
13289 wlan_hdd_cfg80211_scan(scan_ctx->wiphy,
13290#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13291 scan_ctx->dev,
13292#endif
13293 scan_ctx->scan_request);
13294}
13295
13296int wlan_hdd_copy_defer_scan_context(hdd_context_t *pHddCtx,
13297 struct wiphy *wiphy,
13298#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13299 struct net_device *dev,
13300#endif
13301 struct cfg80211_scan_request *request)
13302{
13303 scan_context_t *scan_ctx;
13304
13305 ENTER();
13306 if (0 != (wlan_hdd_validate_context(pHddCtx)))
13307 {
13308 return -1;
13309 }
13310
13311 scan_ctx = &pHddCtx->scan_ctxt;
13312
13313 scan_ctx->wiphy = wiphy;
13314#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13315 scan_ctx->dev = dev;
13316#endif
13317
13318 scan_ctx->scan_request = request;
13319
13320 EXIT();
13321 return 0;
13322}
13323
13324void wlan_hdd_defer_scan_init_work(hdd_context_t *pHddCtx,
13325 struct wiphy *wiphy,
13326#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13327 struct net_device *dev,
13328#endif
13329 struct cfg80211_scan_request *request,
13330 unsigned long delay)
13331{
13332 if (TDLS_CTX_MAGIC != pHddCtx->scan_ctxt.magic)
13333 {
13334#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13335 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, dev, request);
13336#else
13337 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, request);
13338#endif
13339 pHddCtx->scan_ctxt.attempt = 0;
13340 pHddCtx->scan_ctxt.magic = TDLS_CTX_MAGIC;
13341 }
13342 schedule_delayed_work(&pHddCtx->scan_ctxt.scan_work, delay);
13343}
13344
13345void wlan_hdd_init_deinit_defer_scan_context(scan_context_t *scan_ctx)
13346{
13347 scan_ctx->magic = 0;
13348 scan_ctx->attempt = 0;
13349 scan_ctx->reject = 0;
13350 scan_ctx->scan_request = NULL;
13351
13352 return;
13353}
13354
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013355/**---------------------------------------------------------------------------
13356
Jeff Johnson295189b2012-06-20 16:38:30 -070013357 \brief hdd_wlan_startup() - HDD init function
13358
13359 This is the driver startup code executed once a WLAN device has been detected
13360
13361 \param - dev - Pointer to the underlying device
13362
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080013363 \return - 0 for success, < 0 for failure
Jeff Johnson295189b2012-06-20 16:38:30 -070013364
13365 --------------------------------------------------------------------------*/
13366
13367int hdd_wlan_startup(struct device *dev )
13368{
13369 VOS_STATUS status;
13370 hdd_adapter_t *pAdapter = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -070013371 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070013372 hdd_context_t *pHddCtx = NULL;
13373 v_CONTEXT_t pVosContext= NULL;
13374#ifdef WLAN_BTAMP_FEATURE
13375 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
13376 WLANBAP_ConfigType btAmpConfig;
13377 hdd_config_t *pConfig;
13378#endif
13379 int ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070013380 struct wiphy *wiphy;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013381 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -070013382
13383 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -070013384 /*
13385 * cfg80211: wiphy allocation
13386 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013387 wiphy = wlan_hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t)) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070013388
13389 if(wiphy == NULL)
13390 {
13391 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080013392 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070013393 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013394 pHddCtx = wiphy_priv(wiphy);
13395
Jeff Johnson295189b2012-06-20 16:38:30 -070013396 //Initialize the adapter context to zeros.
13397 vos_mem_zero(pHddCtx, sizeof( hdd_context_t ));
13398
Jeff Johnson295189b2012-06-20 16:38:30 -070013399 pHddCtx->wiphy = wiphy;
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013400 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Mihir Shete18156292014-03-11 15:38:30 +053013401 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_LOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070013402
13403 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
13404
Siddharth Bhalcd92b782015-06-29 12:25:40 +053013405 /* register for riva power on lock to platform driver
13406 * Locking power early to ensure FW doesn't reset by kernel while
13407 * host driver is busy initializing itself */
13408 if (req_riva_power_on_lock("wlan"))
13409 {
13410 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: req riva power on lock failed",
13411 __func__);
13412 goto err_free_hdd_context;
13413 }
13414
Jeff Johnson295189b2012-06-20 16:38:30 -070013415 /*Get vos context here bcoz vos_open requires it*/
13416 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
13417
Madan Mohan Koyyalamudi0b78e152012-11-28 15:46:51 -080013418 if(pVosContext == NULL)
13419 {
13420 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed vos_get_global_context",__func__);
13421 goto err_free_hdd_context;
13422 }
13423
Jeff Johnson295189b2012-06-20 16:38:30 -070013424 //Save the Global VOSS context in adapter context for future.
13425 pHddCtx->pvosContext = pVosContext;
13426
13427 //Save the adapter context in global context for future.
13428 ((VosContextType*)(pVosContext))->pHDDContext = (v_VOID_t*)pHddCtx;
13429
Jeff Johnson295189b2012-06-20 16:38:30 -070013430 pHddCtx->parent_dev = dev;
Sreelakshmi Konamkif0646d52016-12-09 12:35:31 +053013431 pHddCtx->last_scan_reject_session_id = 0xFF;
13432 pHddCtx->last_scan_reject_reason = 0;
Sreelakshmi Konamki20ebed92016-10-27 12:13:30 +053013433 pHddCtx->last_scan_reject_timestamp = 0;
Abhishek Singhe4b12562017-06-20 16:53:39 +053013434 pHddCtx->scan_reject_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070013435
13436 init_completion(&pHddCtx->full_pwr_comp_var);
13437 init_completion(&pHddCtx->standby_comp_var);
13438 init_completion(&pHddCtx->req_bmps_comp_var);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070013439 init_completion(&pHddCtx->scan_info.scan_req_completion_event);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -080013440 init_completion(&pHddCtx->scan_info.abortscan_event_var);
Kiet Lam46b8e4e2013-11-06 21:49:53 +053013441 init_completion(&pHddCtx->wiphy_channel_update_event);
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053013442 init_completion(&pHddCtx->ssr_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053013443 init_completion(&pHddCtx->mc_sus_event_var);
13444 init_completion(&pHddCtx->tx_sus_event_var);
13445 init_completion(&pHddCtx->rx_sus_event_var);
13446
Amar Singhala49cbc52013-10-08 18:37:44 -070013447
mukul sharma4bd8d2e2015-08-13 20:33:25 +053013448 hdd_init_ll_stats_ctx(pHddCtx);
Anurag Chouhan6ee81542017-02-09 18:09:27 +053013449 hdd_init_nud_stats_ctx(pHddCtx);
mukul sharma4bd8d2e2015-08-13 20:33:25 +053013450
Amar Singhala49cbc52013-10-08 18:37:44 -070013451#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhalfddc28c2013-09-05 13:03:40 -070013452 init_completion(&pHddCtx->linux_reg_req);
Amar Singhala49cbc52013-10-08 18:37:44 -070013453#else
13454 init_completion(&pHddCtx->driver_crda_req);
13455#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013456
Padma, Santhosh Kumara1aa4a32015-06-19 19:00:46 +053013457#ifdef WLAN_FEATURE_EXTSCAN
13458 init_completion(&pHddCtx->ext_scan_context.response_event);
13459#endif /* WLAN_FEATURE_EXTSCAN */
13460
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053013461 spin_lock_init(&pHddCtx->schedScan_lock);
Kapil Gupta137ef892016-12-13 19:38:00 +053013462 vos_spin_lock_init(&pHddCtx->sap_update_info_lock);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053013463
Jeff Johnson295189b2012-06-20 16:38:30 -070013464 hdd_list_init( &pHddCtx->hddAdapters, MAX_NUMBER_OF_ADAPTERS );
13465
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053013466 vos_init_delayed_work(&pHddCtx->spoof_mac_addr_work,
13467 hdd_processSpoofMacAddrRequest);
Kapil Gupta137ef892016-12-13 19:38:00 +053013468 vos_init_work(&pHddCtx->sap_start_work, hdd_sap_restart_handle);
Abhishek Singh78c691f2017-11-30 13:48:44 +053013469 vos_init_delayed_work(&pHddCtx->ecsa_chan_change_work,
13470 hdd_force_scc_with_ecsa_handle);
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053013471
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053013472#ifdef FEATURE_WLAN_TDLS
13473 /* tdls_lock is initialized before an hdd_open_adapter ( which is
13474 * invoked by other instances also) to protect the concurrent
13475 * access for the Adapters by TDLS module.
13476 */
13477 mutex_init(&pHddCtx->tdls_lock);
13478#endif
Siddharth Bhal76972212014-10-15 16:22:51 +053013479 mutex_init(&pHddCtx->spoofMacAddr.macSpoofingLock);
Mukul Sharma1fd6efd2015-02-14 00:29:14 +053013480 mutex_init(&pHddCtx->wmmLock);
13481
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +053013482 hdd_init_offloaded_packets_ctx(pHddCtx);
Agarwal Ashish1f422872014-07-22 00:11:55 +053013483 /* By default Strict Regulatory For FCC should be false */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053013484
Agarwal Ashish1f422872014-07-22 00:11:55 +053013485 pHddCtx->nEnableStrictRegulatoryForFCC = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070013486 // Load all config first as TL config is needed during vos_open
13487 pHddCtx->cfg_ini = (hdd_config_t*) kmalloc(sizeof(hdd_config_t), GFP_KERNEL);
13488 if(pHddCtx->cfg_ini == NULL)
13489 {
13490 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed kmalloc hdd_config_t",__func__);
13491 goto err_free_hdd_context;
13492 }
13493
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053013494 hdd_request_manager_init();
13495
Jeff Johnson295189b2012-06-20 16:38:30 -070013496 vos_mem_zero(pHddCtx->cfg_ini, sizeof( hdd_config_t ));
13497
13498 // Read and parse the qcom_cfg.ini file
13499 status = hdd_parse_config_ini( pHddCtx );
13500 if ( VOS_STATUS_SUCCESS != status )
13501 {
13502 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: error parsing %s",
13503 __func__, WLAN_INI_FILE);
13504 goto err_config;
13505 }
Arif Hussaind5218912013-12-05 01:10:55 -080013506#ifdef MEMORY_DEBUG
13507 if (pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled)
13508 vos_mem_init();
13509
13510 hddLog(VOS_TRACE_LEVEL_INFO, "%s: gEnableMemoryDebug=%d",
13511 __func__, pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled);
13512#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013513
Gopichand Nakkalab8f0f1a2013-05-23 18:19:48 +053013514 /* INI has been read, initialise the configuredMcastBcastFilter with
13515 * INI value as this will serve as the default value
13516 */
13517 pHddCtx->configuredMcastBcastFilter = pHddCtx->cfg_ini->mcastBcastFilterSetting;
13518 hddLog(VOS_TRACE_LEVEL_INFO, "Setting configuredMcastBcastFilter: %d",
13519 pHddCtx->cfg_ini->mcastBcastFilterSetting);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013520
13521 if (false == hdd_is_5g_supported(pHddCtx))
13522 {
13523 //5Ghz is not supported.
13524 if (1 != pHddCtx->cfg_ini->nBandCapability)
13525 {
13526 hddLog(VOS_TRACE_LEVEL_INFO,
13527 "%s: Setting pHddCtx->cfg_ini->nBandCapability = 1", __func__);
13528 pHddCtx->cfg_ini->nBandCapability = 1;
13529 }
13530 }
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +053013531
13532 /* If SNR Monitoring is enabled, FW has to parse all beacons
13533 * for calcaluting and storing the average SNR, so set Nth beacon
13534 * filter to 1 to enable FW to parse all the beaocons
13535 */
13536 if (1 == pHddCtx->cfg_ini->fEnableSNRMonitoring)
13537 {
13538 /* The log level is deliberately set to WARN as overriding
13539 * nthBeaconFilter to 1 will increase power cosumption and this
13540 * might just prove helpful to detect the power issue.
13541 */
13542 hddLog(VOS_TRACE_LEVEL_WARN,
13543 "%s: Setting pHddCtx->cfg_ini->nthBeaconFilter = 1", __func__);
13544 pHddCtx->cfg_ini->nthBeaconFilter = 1;
13545 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013546 /*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013547 * cfg80211: Initialization ...
Jeff Johnson295189b2012-06-20 16:38:30 -070013548 */
Manjeet Singh61016fa2016-12-02 11:10:19 +053013549 if (0 < wlan_hdd_cfg80211_init(dev, wiphy, pHddCtx->cfg_ini))
Jeff Johnson295189b2012-06-20 16:38:30 -070013550 {
Manjeet Singh61016fa2016-12-02 11:10:19 +053013551 hddLog(VOS_TRACE_LEVEL_FATAL,
13552 "%s: wlan_hdd_cfg80211_init return failure", __func__);
13553 goto err_config;
Jeff Johnson295189b2012-06-20 16:38:30 -070013554 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013555
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013556 // Update VOS trace levels based upon the cfg.ini
13557 hdd_vos_trace_enable(VOS_MODULE_ID_BAP,
13558 pHddCtx->cfg_ini->vosTraceEnableBAP);
13559 hdd_vos_trace_enable(VOS_MODULE_ID_TL,
13560 pHddCtx->cfg_ini->vosTraceEnableTL);
13561 hdd_vos_trace_enable(VOS_MODULE_ID_WDI,
13562 pHddCtx->cfg_ini->vosTraceEnableWDI);
13563 hdd_vos_trace_enable(VOS_MODULE_ID_HDD,
13564 pHddCtx->cfg_ini->vosTraceEnableHDD);
13565 hdd_vos_trace_enable(VOS_MODULE_ID_SME,
13566 pHddCtx->cfg_ini->vosTraceEnableSME);
13567 hdd_vos_trace_enable(VOS_MODULE_ID_PE,
13568 pHddCtx->cfg_ini->vosTraceEnablePE);
Katya Nigam70d68332013-09-16 16:49:45 +053013569 hdd_vos_trace_enable(VOS_MODULE_ID_PMC,
13570 pHddCtx->cfg_ini->vosTraceEnablePMC);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013571 hdd_vos_trace_enable(VOS_MODULE_ID_WDA,
13572 pHddCtx->cfg_ini->vosTraceEnableWDA);
13573 hdd_vos_trace_enable(VOS_MODULE_ID_SYS,
13574 pHddCtx->cfg_ini->vosTraceEnableSYS);
13575 hdd_vos_trace_enable(VOS_MODULE_ID_VOSS,
13576 pHddCtx->cfg_ini->vosTraceEnableVOSS);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013577 hdd_vos_trace_enable(VOS_MODULE_ID_SAP,
13578 pHddCtx->cfg_ini->vosTraceEnableSAP);
13579 hdd_vos_trace_enable(VOS_MODULE_ID_HDD_SOFTAP,
13580 pHddCtx->cfg_ini->vosTraceEnableHDDSAP);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013581
Jeff Johnson295189b2012-06-20 16:38:30 -070013582 // Update WDI trace levels based upon the cfg.ini
13583 hdd_wdi_trace_enable(eWLAN_MODULE_DAL,
13584 pHddCtx->cfg_ini->wdiTraceEnableDAL);
13585 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_CTRL,
13586 pHddCtx->cfg_ini->wdiTraceEnableCTL);
13587 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_DATA,
13588 pHddCtx->cfg_ini->wdiTraceEnableDAT);
13589 hdd_wdi_trace_enable(eWLAN_MODULE_PAL,
13590 pHddCtx->cfg_ini->wdiTraceEnablePAL);
Jeff Johnson295189b2012-06-20 16:38:30 -070013591
Jeff Johnson88ba7742013-02-27 14:36:02 -080013592 if (VOS_FTM_MODE == hdd_get_conparam())
13593 {
Jeff Johnson295189b2012-06-20 16:38:30 -070013594 if ( VOS_STATUS_SUCCESS != wlan_hdd_ftm_open(pHddCtx) )
13595 {
13596 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_ftm_open Failed",__func__);
13597 goto err_free_hdd_context;
13598 }
13599 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: FTM driver loaded success fully",__func__);
Sachin Ahuja38ef5e02015-03-13 17:31:16 +053013600 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
c_hpothu2de0ef62014-04-15 16:16:15 +053013601 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -070013602 return VOS_STATUS_SUCCESS;
Jeff Johnson88ba7742013-02-27 14:36:02 -080013603 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013604
Katya Nigame7b69a82015-04-28 15:24:06 +053013605 if( VOS_MONITOR_MODE == hdd_get_conparam())
13606 {
13607 if ( VOS_STATUS_SUCCESS != wlan_hdd_mon_open(pHddCtx))
13608 {
13609 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_mon_open Failed",__func__);
13610 goto err_free_hdd_context;
13611 }
13612 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Driver loaded in Monitor Mode",__func__);
13613 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
13614 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
13615 return VOS_STATUS_SUCCESS;
13616 }
13617
Jeff Johnson88ba7742013-02-27 14:36:02 -080013618 //Open watchdog module
Jeff Johnson295189b2012-06-20 16:38:30 -070013619 if(pHddCtx->cfg_ini->fIsLogpEnabled)
13620 {
13621 status = vos_watchdog_open(pVosContext,
13622 &((VosContextType*)pVosContext)->vosWatchdog, sizeof(VosWatchdogContext));
13623
13624 if(!VOS_IS_STATUS_SUCCESS( status ))
13625 {
13626 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_watchdog_open failed",__func__);
Ashish Kumar Dhanotiya532bdef2017-05-09 17:31:59 +053013627 goto err_config;
Jeff Johnson295189b2012-06-20 16:38:30 -070013628 }
13629 }
13630
13631 pHddCtx->isLogpInProgress = FALSE;
13632 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
13633
Amar Singhala49cbc52013-10-08 18:37:44 -070013634#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070013635 /* initialize the NV module. This is required so that
13636 we can initialize the channel information in wiphy
13637 from the NV.bin data. The channel information in
13638 wiphy needs to be initialized before wiphy registration */
13639
13640 status = vos_nv_open();
13641 if (!VOS_IS_STATUS_SUCCESS(status))
13642 {
13643 /* NV module cannot be initialized */
13644 hddLog( VOS_TRACE_LEVEL_FATAL,
13645 "%s: vos_nv_open failed", __func__);
Vinay Krishna Eranna2025d892014-09-18 16:51:42 +053013646 goto err_wdclose;
Amar Singhal0a402232013-10-11 20:57:16 -070013647 }
13648
13649 status = vos_init_wiphy_from_nv_bin();
13650 if (!VOS_IS_STATUS_SUCCESS(status))
13651 {
13652 /* NV module cannot be initialized */
13653 hddLog( VOS_TRACE_LEVEL_FATAL,
13654 "%s: vos_init_wiphy failed", __func__);
13655 goto err_vos_nv_close;
13656 }
13657
Amar Singhala49cbc52013-10-08 18:37:44 -070013658#endif
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013659 //Initialize the nlink service
13660 if(nl_srv_init() != 0)
13661 {
13662 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
13663 goto err_vos_nv_close;
13664 }
13665
13666#ifdef WLAN_KD_READY_NOTIFIER
13667 pHddCtx->kd_nl_init = 1;
13668#endif /* WLAN_KD_READY_NOTIFIER */
13669
Girish Gowlibf0e1ab2015-01-19 16:05:16 +053013670 vos_set_roam_delay_stats_enabled(pHddCtx->cfg_ini->gEnableRoamDelayStats);
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053013671 status = vos_open( &pVosContext, pHddCtx->parent_dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070013672 if ( !VOS_IS_STATUS_SUCCESS( status ))
13673 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013674 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013675 goto err_nl_srv;
Jeff Johnson295189b2012-06-20 16:38:30 -070013676 }
13677
Jeff Johnson295189b2012-06-20 16:38:30 -070013678 pHddCtx->hHal = (tHalHandle)vos_get_context( VOS_MODULE_ID_SME, pVosContext );
13679
13680 if ( NULL == pHddCtx->hHal )
13681 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013682 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: HAL context is null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070013683 goto err_vosclose;
13684 }
13685
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013686 status = vos_preStart( pHddCtx->pvosContext );
13687 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13688 {
13689 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_preStart failed", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013690 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013691 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013692
Arif Hussaineaf68602013-12-30 23:10:44 -080013693 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan)
13694 {
13695 pHddCtx->cfg_ini->enableDFSChnlScan = enable_dfs_chan_scan;
13696 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_dfs_chan_scan set to %d",
13697 __func__, enable_dfs_chan_scan);
13698 }
13699 if (0 == enable_11d || 1 == enable_11d)
13700 {
13701 pHddCtx->cfg_ini->Is11dSupportEnabled = enable_11d;
13702 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_11d set to %d",
13703 __func__, enable_11d);
13704 }
13705
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013706 /* Note that the vos_preStart() sequence triggers the cfg download.
13707 The cfg download must occur before we update the SME config
13708 since the SME config operation must access the cfg database */
Jeff Johnson295189b2012-06-20 16:38:30 -070013709 status = hdd_set_sme_config( pHddCtx );
13710
13711 if ( VOS_STATUS_SUCCESS != status )
13712 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013713 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed hdd_set_sme_config", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013714 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013715 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013716
Jeff Johnson295189b2012-06-20 16:38:30 -070013717 /* In the integrated architecture we update the configuration from
13718 the INI file and from NV before vOSS has been started so that
13719 the final contents are available to send down to the cCPU */
13720
13721 // Apply the cfg.ini to cfg.dat
13722 if (FALSE == hdd_update_config_dat(pHddCtx))
13723 {
13724 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013725 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013726 }
13727
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013728 // Get mac addr from platform driver
13729 ret = wcnss_get_wlan_mac_address((char*)&mac_addr.bytes);
13730
13731 if ((0 == ret) && (!vos_is_macaddr_zero(&mac_addr)))
Jeff Johnson295189b2012-06-20 16:38:30 -070013732 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013733 /* Store the mac addr for first interface */
13734 pHddCtx->cfg_ini->intfMacAddr[0] = mac_addr;
13735
13736 hddLog(VOS_TRACE_LEVEL_ERROR,
13737 "%s: WLAN Mac Addr: "
13738 MAC_ADDRESS_STR, __func__,
13739 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
13740
13741 /* Here, passing Arg2 as 1 because we do not want to change the
13742 last 3 bytes (means non OUI bytes) of first interface mac
13743 addr.
13744 */
13745 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 1, mac_addr))
13746 {
13747 hddLog(VOS_TRACE_LEVEL_ERROR,
13748 "%s: Failed to generate wlan interface mac addr "
13749 "using MAC from ini file ", __func__);
13750 }
13751 }
13752 else if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
13753 {
13754 // Apply the NV to cfg.dat
13755 /* Prima Update MAC address only at here */
Jeff Johnson295189b2012-06-20 16:38:30 -070013756#ifdef WLAN_AUTOGEN_MACADDR_FEATURE
13757 /* There was not a valid set of MAC Addresses in NV. See if the
13758 default addresses were modified by the cfg.ini settings. If so,
13759 we'll use them, but if not, we'll autogenerate a set of MAC
13760 addresses based upon the device serial number */
13761
13762 static const v_MACADDR_t default_address =
13763 {{0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}};
Jeff Johnson295189b2012-06-20 16:38:30 -070013764
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013765 if (0 == memcmp(&default_address, &pHddCtx->cfg_ini->intfMacAddr[0],
13766 sizeof(default_address)))
Jeff Johnson295189b2012-06-20 16:38:30 -070013767 {
13768 /* cfg.ini has the default address, invoke autogen logic */
13769
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013770 /* Here, passing Arg2 as 0 because we want to change the
13771 last 3 bytes (means non OUI bytes) of all the interfaces
13772 mac addr.
13773 */
13774 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 0,
13775 default_address))
Jeff Johnson295189b2012-06-20 16:38:30 -070013776 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013777 hddLog(VOS_TRACE_LEVEL_ERROR,
13778 "%s: Failed to generate wlan interface mac addr "
13779 "using MAC from ini file " MAC_ADDRESS_STR, __func__,
13780 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
Jeff Johnson295189b2012-06-20 16:38:30 -070013781 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013782 }
13783 else
13784#endif //WLAN_AUTOGEN_MACADDR_FEATURE
13785 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013786 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -070013787 "%s: Invalid MAC address in NV, using MAC from ini file "
13788 MAC_ADDRESS_STR, __func__,
13789 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
13790 }
13791 }
13792 {
13793 eHalStatus halStatus;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013794
13795 /* Set the MAC Address Currently this is used by HAL to
13796 * add self sta. Remove this once self sta is added as
13797 * part of session open.
13798 */
Jeff Johnson295189b2012-06-20 16:38:30 -070013799 halStatus = cfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
13800 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
13801 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]) );
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013802
Jeff Johnson295189b2012-06-20 16:38:30 -070013803 if (!HAL_STATUS_SUCCESS( halStatus ))
13804 {
13805 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
13806 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013807 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013808 }
13809 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013810
13811 /*Start VOSS which starts up the SME/MAC/HAL modules and everything else
13812 Note: Firmware image will be read and downloaded inside vos_start API */
13813 status = vos_start( pHddCtx->pvosContext );
13814 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13815 {
13816 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053013817 if (isSsrPanicOnFailure())
13818 VOS_BUG(0);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013819 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013820 }
13821
Leo Chang6cec3e22014-01-21 15:33:49 -080013822#ifdef FEATURE_WLAN_CH_AVOID
13823 /* Plug in avoid channel notification callback
13824 * This should happen before ADD_SELF_STA
13825 * FW will send first IND with ADD_SELF_STA REQ from host */
Pradeep Reddy POTTETI5c2e16d2014-06-27 16:47:38 +053013826
13827 /* check the Channel Avoidance is enabled */
13828 if (TRUE == pHddCtx->cfg_ini->fenableCHAvoidance)
13829 {
13830 sme_AddChAvoidCallback(pHddCtx->hHal,
13831 hdd_hostapd_ch_avoid_cb);
13832 }
Leo Chang6cec3e22014-01-21 15:33:49 -080013833#endif /* FEATURE_WLAN_CH_AVOID */
13834
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070013835 /* Exchange capability info between Host and FW and also get versioning info from FW */
13836 hdd_exchange_version_and_caps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070013837
Agarwal Ashishad9281b2014-06-10 14:57:30 +053013838#ifdef CONFIG_ENABLE_LINUX_REG
13839 status = wlan_hdd_init_channels(pHddCtx);
13840 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13841 {
13842 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels failed",
13843 __func__);
13844 goto err_vosstop;
13845 }
13846#endif
13847
Jeff Johnson295189b2012-06-20 16:38:30 -070013848 status = hdd_post_voss_start_config( pHddCtx );
13849 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13850 {
13851 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_post_voss_start_config failed",
13852 __func__);
13853 goto err_vosstop;
13854 }
Amar Singhala49cbc52013-10-08 18:37:44 -070013855
13856#ifndef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013857 wlan_hdd_cfg80211_update_reg_info( wiphy );
13858
13859 /* registration of wiphy dev with cfg80211 */
13860 if (0 > wlan_hdd_cfg80211_register(wiphy))
13861 {
13862 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
13863 goto err_vosstop;
13864 }
Amar Singhala49cbc52013-10-08 18:37:44 -070013865#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013866
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013867#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013868 /* registration of wiphy dev with cfg80211 */
13869 if (0 > wlan_hdd_cfg80211_register(wiphy))
13870 {
13871 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
13872 goto err_vosstop;
13873 }
13874
Agarwal Ashish6db9d532014-09-30 18:19:10 +053013875 status = wlan_hdd_init_channels_for_cc(pHddCtx, INIT);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013876 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13877 {
13878 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels_for_cc failed",
13879 __func__);
13880 goto err_unregister_wiphy;
13881 }
13882#endif
13883
c_hpothu4a298be2014-12-22 21:12:51 +053013884 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
13885
Jeff Johnson295189b2012-06-20 16:38:30 -070013886 if (VOS_STA_SAP_MODE == hdd_get_conparam())
13887 {
13888 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP, "softap.%d",
13889 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
13890 }
13891 else
13892 {
Jeff Johnson295189b2012-06-20 16:38:30 -070013893 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_INFRA_STATION, "wlan%d",
13894 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
13895 if (pAdapter != NULL)
13896 {
Katya Nigama7d81d72014-11-12 12:44:34 +053013897 if (pHddCtx->cfg_ini->isP2pDeviceAddrAdministrated && !(pHddCtx->cfg_ini->intfMacAddr[0].bytes[0] & 0x02))
Jeff Johnson295189b2012-06-20 16:38:30 -070013898 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053013899 vos_mem_copy( pHddCtx->p2pDeviceAddress.bytes,
13900 pHddCtx->cfg_ini->intfMacAddr[0].bytes,
13901 sizeof(tSirMacAddr));
Madan Mohan Koyyalamudiedfc1b72012-10-18 20:25:55 -070013902
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053013903 /* Generate the P2P Device Address. This consists of the device's
13904 * primary MAC address with the locally administered bit set.
13905 */
13906 pHddCtx->p2pDeviceAddress.bytes[0] |= 0x02;
Jeff Johnsone7245742012-09-05 17:12:55 -070013907 }
13908 else
13909 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053013910 tANI_U8* p2p_dev_addr = wlan_hdd_get_intf_addr(pHddCtx);
13911 if (p2p_dev_addr != NULL)
13912 {
13913 vos_mem_copy(&pHddCtx->p2pDeviceAddress.bytes[0],
13914 p2p_dev_addr, VOS_MAC_ADDR_SIZE);
13915 }
13916 else
13917 {
13918 hddLog(VOS_TRACE_LEVEL_FATAL,
13919 "%s: Failed to allocate mac_address for p2p_device",
13920 __func__);
13921 goto err_close_adapter;
13922 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013923 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013924
13925 pP2pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_P2P_DEVICE, "p2p%d",
13926 &pHddCtx->p2pDeviceAddress.bytes[0], FALSE );
13927 if ( NULL == pP2pAdapter )
13928 {
13929 hddLog(VOS_TRACE_LEVEL_FATAL,
13930 "%s: Failed to do hdd_open_adapter for P2P Device Interface",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070013931 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070013932 goto err_close_adapter;
13933 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013934 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013935 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013936
13937 if( pAdapter == NULL )
13938 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013939 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
13940 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070013941 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013942
Arif Hussain66559122013-11-21 10:11:40 -080013943 if (country_code)
13944 {
13945 eHalStatus ret;
Arif Hussaincb607082013-12-20 11:57:42 -080013946 INIT_COMPLETION(pAdapter->change_country_code);
Arif Hussain66559122013-11-21 10:11:40 -080013947 hdd_checkandupdate_dfssetting(pAdapter, country_code);
13948#ifndef CONFIG_ENABLE_LINUX_REG
13949 hdd_checkandupdate_phymode(pAdapter, country_code);
13950#endif
Arif Hussaineaf68602013-12-30 23:10:44 -080013951 ret = sme_ChangeCountryCode(pHddCtx->hHal,
13952 (void *)(tSmeChangeCountryCallback)
13953 wlan_hdd_change_country_code_callback,
Arif Hussain66559122013-11-21 10:11:40 -080013954 country_code,
13955 pAdapter, pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +053013956 eSIR_TRUE, eSIR_TRUE);
Arif Hussain66559122013-11-21 10:11:40 -080013957 if (eHAL_STATUS_SUCCESS == ret)
13958 {
Arif Hussaincb607082013-12-20 11:57:42 -080013959 ret = wait_for_completion_interruptible_timeout(
13960 &pAdapter->change_country_code,
13961 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
13962
13963 if (0 >= ret)
13964 {
13965 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13966 "%s: SME while setting country code timed out", __func__);
13967 }
Arif Hussain66559122013-11-21 10:11:40 -080013968 }
13969 else
13970 {
Arif Hussaincb607082013-12-20 11:57:42 -080013971 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13972 "%s: SME Change Country code from module param fail ret=%d",
13973 __func__, ret);
Arif Hussain66559122013-11-21 10:11:40 -080013974 }
13975 }
13976
Jeff Johnson295189b2012-06-20 16:38:30 -070013977#ifdef WLAN_BTAMP_FEATURE
13978 vStatus = WLANBAP_Open(pVosContext);
13979 if(!VOS_IS_STATUS_SUCCESS(vStatus))
13980 {
13981 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13982 "%s: Failed to open BAP",__func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070013983 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070013984 }
13985
13986 vStatus = BSL_Init(pVosContext);
13987 if(!VOS_IS_STATUS_SUCCESS(vStatus))
13988 {
13989 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13990 "%s: Failed to Init BSL",__func__);
13991 goto err_bap_close;
13992 }
13993 vStatus = WLANBAP_Start(pVosContext);
13994 if (!VOS_IS_STATUS_SUCCESS(vStatus))
13995 {
13996 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13997 "%s: Failed to start TL",__func__);
13998 goto err_bap_close;
13999 }
14000
14001 pConfig = pHddCtx->cfg_ini;
14002 btAmpConfig.ucPreferredChannel = pConfig->preferredChannel;
14003 status = WLANBAP_SetConfig(&btAmpConfig);
14004
14005#endif //WLAN_BTAMP_FEATURE
Jeff Johnsone7245742012-09-05 17:12:55 -070014006
Mihir Shete9c238772014-10-15 14:35:16 +053014007 /*
14008 * UapsdMask is 0xf if U-APSD is enbaled for all AC's...
14009 * The value of CFG_QOS_WMM_UAPSD_MASK_DEFAULT is 0xaa(Magic Value)
14010 * which is greater than 0xf. So the below check is safe to make
14011 * sure that there is no entry for UapsdMask in the ini
14012 */
14013 if (CFG_QOS_WMM_UAPSD_MASK_DEFAULT == pHddCtx->cfg_ini->UapsdMask)
14014 {
14015 if(IS_DYNAMIC_WMM_PS_ENABLED)
14016 {
14017 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Enable UAPSD for VI & VO",
14018 __func__);
14019 pHddCtx->cfg_ini->UapsdMask =
14020 CFG_QOS_WMM_UAPSD_MASK_DYMANIC_WMM_PS_DEFAULT;
14021 }
14022 else
14023 {
14024 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Do not enable UAPSD",
14025 __func__);
14026 pHddCtx->cfg_ini->UapsdMask =
14027 CFG_QOS_WMM_UAPSD_MASK_LEGACY_WMM_PS_DEFAULT;
14028 }
14029 }
14030
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -070014031#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
14032 if(!(IS_ROAM_SCAN_OFFLOAD_FEATURE_ENABLE))
14033 {
14034 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: ROAM_SCAN_OFFLOAD Feature not supported",__func__);
14035 pHddCtx->cfg_ini->isRoamOffloadScanEnabled = 0;
14036 sme_UpdateRoamScanOffloadEnabled((tHalHandle)(pHddCtx->hHal),
14037 pHddCtx->cfg_ini->isRoamOffloadScanEnabled);
14038 }
14039#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014040
Agarwal Ashish4b87f922014-06-18 03:03:21 +053014041 wlan_hdd_tdls_init(pHddCtx);
14042
Masti, Narayanraddi26378462016-01-05 18:20:28 +053014043 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
14044
14045 vos_init_delayed_work(&pHddCtx->scan_ctxt.scan_work,
14046 wlan_hdd_schedule_defer_scan);
14047
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053014048 sme_Register11dScanDoneCallback(pHddCtx->hHal, hdd_11d_scan_done);
14049
Jeff Johnson295189b2012-06-20 16:38:30 -070014050 /* Register with platform driver as client for Suspend/Resume */
14051 status = hddRegisterPmOps(pHddCtx);
14052 if ( !VOS_IS_STATUS_SUCCESS( status ) )
14053 {
14054 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddRegisterPmOps failed",__func__);
14055#ifdef WLAN_BTAMP_FEATURE
14056 goto err_bap_stop;
14057#else
Jeff Johnsone7245742012-09-05 17:12:55 -070014058 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070014059#endif //WLAN_BTAMP_FEATURE
14060 }
14061
Yue Ma0d4891e2013-08-06 17:01:45 -070014062 /* Open debugfs interface */
14063 if (VOS_STATUS_SUCCESS != hdd_debugfs_init(pAdapter))
14064 {
14065 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14066 "%s: hdd_debugfs_init failed!", __func__);
Yue Ma0d4891e2013-08-06 17:01:45 -070014067 }
14068
Jeff Johnson295189b2012-06-20 16:38:30 -070014069 /* Register TM level change handler function to the platform */
14070 status = hddDevTmRegisterNotifyCallback(pHddCtx);
14071 if ( !VOS_IS_STATUS_SUCCESS( status ) )
14072 {
14073 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmRegisterNotifyCallback failed",__func__);
14074 goto err_unregister_pmops;
14075 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014076
Jeff Johnson295189b2012-06-20 16:38:30 -070014077 // register net device notifier for device change notification
14078 ret = register_netdevice_notifier(&hdd_netdev_notifier);
14079
14080 if(ret < 0)
14081 {
14082 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: register_netdevice_notifier failed",__func__);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053014083 goto err_unregister_pmops;
Jeff Johnson295189b2012-06-20 16:38:30 -070014084 }
14085
Jeff Johnson295189b2012-06-20 16:38:30 -070014086 //Initialize the BTC service
14087 if(btc_activate_service(pHddCtx) != 0)
14088 {
14089 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: btc_activate_service failed",__func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053014090 goto err_reg_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -070014091 }
14092
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053014093#ifdef FEATURE_OEM_DATA_SUPPORT
14094 //Initialize the OEM service
14095 if (oem_activate_service(pHddCtx) != 0)
14096 {
14097 hddLog(VOS_TRACE_LEVEL_FATAL,
14098 "%s: oem_activate_service failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014099 goto err_btc_activate_service;
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053014100 }
14101#endif
14102
Jeff Johnson295189b2012-06-20 16:38:30 -070014103#ifdef PTT_SOCK_SVC_ENABLE
14104 //Initialize the PTT service
14105 if(ptt_sock_activate_svc(pHddCtx) != 0)
14106 {
14107 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: ptt_sock_activate_svc failed",__func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014108 goto err_oem_activate_service;
Jeff Johnson295189b2012-06-20 16:38:30 -070014109 }
14110#endif
14111
Abhishek Singh00b71972016-01-07 10:51:04 +053014112#ifdef WLAN_FEATURE_RMC
14113 if (hdd_open_cesium_nl_sock() < 0)
14114 {
14115 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_open_cesium_nl_sock failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014116 goto err_ptt_sock_activate_svc;
Abhishek Singh00b71972016-01-07 10:51:04 +053014117 }
14118#endif
14119
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014120#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14121 if(pHddCtx->cfg_ini && pHddCtx->cfg_ini->wlanLoggingEnable)
14122 {
Deepthi Gowri78083a32014-11-04 12:55:51 +053014123 if(wlan_logging_sock_activate_svc(
14124 pHddCtx->cfg_ini->wlanLoggingFEToConsole,
Sushant Kaushik33200572015-08-05 16:46:20 +053014125 pHddCtx->cfg_ini->wlanLoggingNumBuf,
14126 pHddCtx->cfg_ini->wlanPerPktStatsLogEnable,
14127 pHddCtx->cfg_ini->wlanPerPktStatsNumBuf))
Deepthi Gowri78083a32014-11-04 12:55:51 +053014128 {
14129 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wlan_logging_sock_activate_svc"
14130 " failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014131 goto err_open_cesium_nl_sock;
Deepthi Gowri78083a32014-11-04 12:55:51 +053014132 }
14133 //TODO: To Remove enableDhcpDebug and use gEnableDebugLog for
14134 //EAPOL and DHCP
Sachin Ahuja8c65f382014-12-12 15:34:21 +053014135 if (!pHddCtx->cfg_ini->gEnableDebugLog)
14136 pHddCtx->cfg_ini->gEnableDebugLog =
Sushant Kaushik6e4e2bc2015-10-05 17:23:07 +053014137 VOS_PKT_PROTO_TYPE_EAPOL | VOS_PKT_PROTO_TYPE_DHCP |
14138 VOS_PKT_PROTO_TYPE_ARP;
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014139 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014140
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014141 if (pHddCtx->cfg_ini->wlanLoggingEnable &&
14142 (pHddCtx->cfg_ini->enableFWLogging ||
Siddharth Bhaldb963232015-06-25 19:34:35 +053014143 pHddCtx->cfg_ini->enableMgmtLogging ||
c_manjeecfd1efb2015-09-25 19:32:34 +053014144 pHddCtx->cfg_ini->enableContFWLogging ||
14145 pHddCtx->cfg_ini->enableFwrMemDump )
14146 )
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014147 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014148 hdd_init_frame_logging(pHddCtx);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014149 }
14150 else
14151 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014152 hddLog(VOS_TRACE_LEVEL_INFO, FL("Logging disabled in ini"));
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014153 }
14154
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014155#endif
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014156
Agrawal Ashish17ef5082016-10-17 18:33:21 +053014157#ifdef SAP_AUTH_OFFLOAD
14158 if (!sme_IsFeatureSupportedByFW(SAP_OFFLOADS))
14159 {
14160 hddLog(VOS_TRACE_LEVEL_INFO, FL(" SAP AUTH OFFLOAD not supp by FW"));
14161 pHddCtx->cfg_ini->enable_sap_auth_offload = 0;
14162 }
14163#endif
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014164
Sushant Kaushik215778f2015-05-21 14:05:36 +053014165 if (vos_is_multicast_logging())
14166 wlan_logging_set_log_level();
14167
Jeff Johnson295189b2012-06-20 16:38:30 -070014168 hdd_register_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070014169 if (VOS_STA_SAP_MODE != hdd_get_conparam())
Jeff Johnson295189b2012-06-20 16:38:30 -070014170 {
Madan Mohan Koyyalamudic537df22012-10-22 15:07:08 -070014171 /* Action frame registered in one adapter which will
14172 * applicable to all interfaces
14173 */
Agarwal Ashish8fa0e9a2014-05-23 00:40:12 +053014174 wlan_hdd_cfg80211_register_frames(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070014175 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014176
14177 mutex_init(&pHddCtx->sap_lock);
Mahesh A Saptasagar60627942014-10-13 13:55:14 +053014178 mutex_init(&pHddCtx->roc_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070014179
Jeff Johnsone7245742012-09-05 17:12:55 -070014180#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
14181 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014182 vos_wake_lock_init(&pHddCtx->rx_wake_lock,
Jeff Johnsone7245742012-09-05 17:12:55 -070014183 "qcom_rx_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014184
Jeff Johnsone7245742012-09-05 17:12:55 -070014185#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080014186 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014187 vos_wake_lock_init(&pHddCtx->sap_wake_lock,
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080014188 "qcom_sap_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014189
Jeff Johnsone7245742012-09-05 17:12:55 -070014190
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070014191 vos_event_init(&pHddCtx->scan_info.scan_finished_event);
14192 pHddCtx->scan_info.scan_pending_option = WEXT_SCAN_PENDING_GIVEUP;
Jeff Johnson295189b2012-06-20 16:38:30 -070014193
Katya Nigam5c306ea2014-06-19 15:39:54 +053014194 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070014195 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014196 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Katya Nigam5c306ea2014-06-19 15:39:54 +053014197
14198#ifdef FEATURE_WLAN_SCAN_PNO
14199 /*SME must send channel update configuration to RIVA*/
14200 sme_UpdateChannelConfig(pHddCtx->hHal);
14201#endif
Abhishek Singhf644b272014-08-21 02:59:39 +053014202 /* Send the update default channel list to the FW*/
14203 sme_UpdateChannelList(pHddCtx->hHal);
Mukul Sharma45063942015-04-01 20:07:59 +053014204
14205 /* Fwr capabilities received, Set the Dot11 mode */
Abhishek Singh41ebce12016-02-03 10:43:21 +053014206 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
14207 hdd_cfg_xlate_to_csr_phy_mode(pHddCtx->cfg_ini->dot11Mode));
Mukul Sharma45063942015-04-01 20:07:59 +053014208 sme_SetDefDot11Mode(pHddCtx->hHal);
14209
Abhishek Singha306a442013-11-07 18:39:01 +053014210#ifndef CONFIG_ENABLE_LINUX_REG
14211 /*updating wiphy so that regulatory user hints can be processed*/
14212 if (wiphy)
14213 {
14214 regulatory_hint(wiphy, "00");
14215 }
14216#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070014217 // Initialize the restart logic
14218 wlan_hdd_restart_init(pHddCtx);
Chilam NG571c65a2013-01-19 12:27:36 +053014219
Hanumanth Reddy Pothula146bca42016-11-08 12:01:07 +053014220 if (pHddCtx->cfg_ini->fIsLogpEnabled) {
14221 vos_wdthread_init_timer_work(vos_process_wd_timer);
14222 /* Initialize the timer to detect thread stuck issues */
14223 vos_thread_stuck_timer_init(
14224 &((VosContextType*)pVosContext)->vosWatchdog);
14225 }
14226
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070014227 //Register the traffic monitor timer now
14228 if ( pHddCtx->cfg_ini->dynSplitscan)
14229 {
14230 vos_timer_init(&pHddCtx->tx_rx_trafficTmr,
14231 VOS_TIMER_TYPE_SW,
14232 hdd_tx_rx_pkt_cnt_stat_timer_handler,
14233 (void *)pHddCtx);
14234 }
Srinivas Dasari030bad32015-02-18 23:23:54 +053014235 wlan_hdd_cfg80211_nan_init(pHddCtx);
14236
Bhargav Shahd0715912015-10-01 18:17:37 +053014237 mutex_init(&pHddCtx->cur_rx_level_lock);
14238 vos_timer_init(&pHddCtx->delack_timer, VOS_TIMER_TYPE_SW,
14239 hdd_tcp_delack_compute_function,(void *)pHddCtx);
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053014240 vos_timer_init(&pHddCtx->tdls_source_timer, VOS_TIMER_TYPE_SW,
14241 wlan_hdd_change_tdls_mode, (void *)pHddCtx);
Bhargav Shahd0715912015-10-01 18:17:37 +053014242
Dino Mycle6fb96c12014-06-10 11:52:40 +053014243#ifdef WLAN_FEATURE_EXTSCAN
14244 sme_EXTScanRegisterCallback(pHddCtx->hHal,
14245 wlan_hdd_cfg80211_extscan_callback,
14246 pHddCtx);
14247#endif /* WLAN_FEATURE_EXTSCAN */
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014248
Padma, Santhosh Kumar2ccac212015-10-20 17:27:27 +053014249#ifdef FEATURE_OEM_DATA_SUPPORT
14250 sme_OemDataRegisterCallback(pHddCtx->hHal,
14251 wlan_hdd_cfg80211_oemdata_callback,
14252 pHddCtx);
14253#endif /* FEATURE_OEM_DATA_SUPPORT */
14254
Gupta, Kapil7c34b322015-09-30 13:12:35 +053014255 sme_set_rssi_threshold_breached_cb(pHddCtx->hHal, hdd_rssi_threshold_breached_cb);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014256#ifdef WLAN_NS_OFFLOAD
14257 // Register IPv6 notifier to notify if any change in IP
14258 // So that we can reconfigure the offload parameters
14259 pHddCtx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
14260 ret = register_inet6addr_notifier(&pHddCtx->ipv6_notifier);
14261 if (ret)
14262 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014263 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014264 }
14265 else
14266 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014267 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014268 }
14269#endif
14270
Sravan Kumar Kairamb0edc612016-10-26 13:55:24 +053014271 vos_mem_set((uint8_t *)&pHddCtx->bad_sta, HDD_MAX_STA_COUNT, 0);
14272
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014273 // Register IPv4 notifier to notify if any change in IP
14274 // So that we can reconfigure the offload parameters
14275 pHddCtx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
14276 ret = register_inetaddr_notifier(&pHddCtx->ipv4_notifier);
14277 if (ret)
14278 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014279 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014280 }
14281 else
14282 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014283 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014284 }
c_manjeecfd1efb2015-09-25 19:32:34 +053014285 /*Fw mem dump procfs initialization*/
14286 memdump_init();
Bhargav shah23c94942015-10-13 12:48:35 +053014287 hdd_dp_util_send_rps_ind(pHddCtx);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014288
Nishank Aggarwalc11826c2016-12-15 18:54:10 +053014289 pHddCtx->is_ap_mode_wow_supported =
14290 sme_IsFeatureSupportedByFW(SAP_MODE_WOW);
Sravan Kumar Kairam091e5b62017-01-23 14:14:20 +053014291
Hanumanth Reddy Pothulae92bcc12017-05-19 13:56:35 +053014292 pHddCtx->is_fatal_event_log_sup =
14293 sme_IsFeatureSupportedByFW(FATAL_EVENT_LOGGING);
14294 hddLog(VOS_TRACE_LEVEL_INFO, FL("FATAL_EVENT_LOGGING: %d"),
14295 pHddCtx->is_fatal_event_log_sup);
14296
Sravan Kumar Kairam091e5b62017-01-23 14:14:20 +053014297 hdd_assoc_registerFwdEapolCB(pVosContext);
14298
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +053014299 mutex_init(&pHddCtx->cache_channel_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070014300 goto success;
14301
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014302err_open_cesium_nl_sock:
14303#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14304 hdd_close_cesium_nl_sock();
14305#endif
14306
14307err_ptt_sock_activate_svc:
14308#ifdef PTT_SOCK_SVC_ENABLE
14309 ptt_sock_deactivate_svc(pHddCtx);
14310#endif
14311
14312err_oem_activate_service:
14313#ifdef FEATURE_OEM_DATA_SUPPORT
14314 oem_deactivate_service();
14315#endif
14316
14317err_btc_activate_service:
14318 btc_deactivate_service();
14319
Jeff Johnson295189b2012-06-20 16:38:30 -070014320err_reg_netdev:
14321 unregister_netdevice_notifier(&hdd_netdev_notifier);
14322
Jeff Johnson295189b2012-06-20 16:38:30 -070014323err_unregister_pmops:
14324 hddDevTmUnregisterNotifyCallback(pHddCtx);
14325 hddDeregisterPmOps(pHddCtx);
14326
Yue Ma0d4891e2013-08-06 17:01:45 -070014327 hdd_debugfs_exit(pHddCtx);
14328
Jeff Johnson295189b2012-06-20 16:38:30 -070014329#ifdef WLAN_BTAMP_FEATURE
14330err_bap_stop:
14331 WLANBAP_Stop(pVosContext);
14332#endif
14333
14334#ifdef WLAN_BTAMP_FEATURE
14335err_bap_close:
14336 WLANBAP_Close(pVosContext);
14337#endif
14338
Jeff Johnson295189b2012-06-20 16:38:30 -070014339err_close_adapter:
14340 hdd_close_all_adapters( pHddCtx );
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053014341#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053014342err_unregister_wiphy:
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053014343#endif
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053014344 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053014345 hdd_wlan_free_wiphy_channels(wiphy);
14346
Jeff Johnson295189b2012-06-20 16:38:30 -070014347err_vosstop:
14348 vos_stop(pVosContext);
14349
Amar Singhala49cbc52013-10-08 18:37:44 -070014350err_vosclose:
Jeff Johnson295189b2012-06-20 16:38:30 -070014351 status = vos_sched_close( pVosContext );
14352 if (!VOS_IS_STATUS_SUCCESS(status)) {
14353 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
14354 "%s: Failed to close VOSS Scheduler", __func__);
14355 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
14356 }
Amar Singhala49cbc52013-10-08 18:37:44 -070014357 vos_close(pVosContext );
14358
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053014359err_nl_srv:
14360#ifdef WLAN_KD_READY_NOTIFIER
14361 nl_srv_exit(pHddCtx->ptt_pid);
14362#else
14363 nl_srv_exit();
14364#endif /* WLAN_KD_READY_NOTIFIER */
Amar Singhal0a402232013-10-11 20:57:16 -070014365err_vos_nv_close:
14366
c_hpothue6a36282014-03-19 12:27:38 +053014367#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070014368 vos_nv_close();
14369
c_hpothu70f8d812014-03-22 22:59:23 +053014370#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014371
14372err_wdclose:
14373 if(pHddCtx->cfg_ini->fIsLogpEnabled)
14374 vos_watchdog_close(pVosContext);
14375
Jeff Johnson295189b2012-06-20 16:38:30 -070014376err_config:
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053014377 hdd_request_manager_deinit();
Jeff Johnson295189b2012-06-20 16:38:30 -070014378 kfree(pHddCtx->cfg_ini);
14379 pHddCtx->cfg_ini= NULL;
14380
14381err_free_hdd_context:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014382 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053014383 free_riva_power_on_lock("wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070014384 wiphy_free(wiphy) ;
14385 //kfree(wdev) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070014386 VOS_BUG(1);
14387
Madan Mohan Koyyalamudid57ae632012-11-06 18:42:48 -080014388 if (hdd_is_ssr_required())
14389 {
14390 /* WDI timeout had happened during load, so SSR is needed here */
14391 subsystem_restart("wcnss");
14392 msleep(5000);
14393 }
14394 hdd_set_ssr_required (VOS_FALSE);
14395
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080014396 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070014397
14398success:
14399 EXIT();
14400 return 0;
14401}
14402
14403/**---------------------------------------------------------------------------
14404
Jeff Johnson32d95a32012-09-10 13:15:23 -070014405 \brief hdd_driver_init() - Core Driver Init Function
Jeff Johnson295189b2012-06-20 16:38:30 -070014406
Jeff Johnson32d95a32012-09-10 13:15:23 -070014407 This is the driver entry point - called in different timeline depending
14408 on whether the driver is statically or dynamically linked
Jeff Johnson295189b2012-06-20 16:38:30 -070014409
14410 \param - None
14411
14412 \return - 0 for success, non zero for failure
14413
14414 --------------------------------------------------------------------------*/
Jeff Johnson32d95a32012-09-10 13:15:23 -070014415static int hdd_driver_init( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070014416{
14417 VOS_STATUS status;
14418 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070014419 struct device *dev = NULL;
14420 int ret_status = 0;
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014421#ifdef HAVE_WCNSS_CAL_DOWNLOAD
14422 int max_retries = 0;
14423#endif
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014424#ifdef HAVE_CBC_DONE
14425 int max_cbc_retries = 0;
14426#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014427
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014428#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14429 wlan_logging_sock_init_svc();
14430#endif
14431
Jeff Johnson295189b2012-06-20 16:38:30 -070014432 ENTER();
14433
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014434 vos_wake_lock_init(&wlan_wake_lock, "wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070014435
14436 pr_info("%s: loading driver v%s\n", WLAN_MODULE_NAME,
14437 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
14438
Jeff Johnson295189b2012-06-20 16:38:30 -070014439#ifdef ANI_BUS_TYPE_PCI
14440
14441 dev = wcnss_wlan_get_device();
14442
14443#endif // ANI_BUS_TYPE_PCI
14444
14445#ifdef ANI_BUS_TYPE_PLATFORM
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014446
14447#ifdef HAVE_WCNSS_CAL_DOWNLOAD
14448 /* wait until WCNSS driver downloads NV */
Ravi Kumar Bokka7a139e62016-11-17 21:32:55 +053014449 while (!wcnss_device_ready() && 10 >= ++max_retries) {
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014450 msleep(1000);
14451 }
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014452
Ravi Kumar Bokka7a139e62016-11-17 21:32:55 +053014453 if (max_retries >= 10) {
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014454 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WCNSS driver not ready", __func__);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014455 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014456#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14457 wlan_logging_sock_deinit_svc();
14458#endif
14459
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014460 return -ENODEV;
14461 }
14462#endif
14463
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014464#ifdef HAVE_CBC_DONE
14465 while (!wcnss_cbc_complete() && 10 >= ++max_cbc_retries) {
14466 msleep(1000);
14467 }
14468 if (max_cbc_retries >= 10) {
14469 hddLog(VOS_TRACE_LEVEL_FATAL, "%s:CBC not completed", __func__);
14470 }
14471#endif
14472
Jeff Johnson295189b2012-06-20 16:38:30 -070014473 dev = wcnss_wlan_get_device();
14474#endif // ANI_BUS_TYPE_PLATFORM
14475
14476
14477 do {
14478 if (NULL == dev) {
14479 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: WLAN device not found!!",__func__);
14480 ret_status = -1;
14481 break;
14482 }
14483
Jeff Johnson295189b2012-06-20 16:38:30 -070014484#ifdef TIMER_MANAGER
14485 vos_timer_manager_init();
14486#endif
14487
14488 /* Preopen VOSS so that it is ready to start at least SAL */
14489 status = vos_preOpen(&pVosContext);
14490
14491 if (!VOS_IS_STATUS_SUCCESS(status))
14492 {
14493 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to preOpen VOSS", __func__);
14494 ret_status = -1;
14495 break;
14496 }
14497
Sushant Kaushik02beb352015-06-04 15:15:01 +053014498 hddTraceInit();
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +053014499 hdd_register_debug_callback();
14500
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014501#ifndef MODULE
14502 /* For statically linked driver, call hdd_set_conparam to update curr_con_mode
14503 */
14504 hdd_set_conparam((v_UINT_t)con_mode);
14505#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014506
14507 // Call our main init function
Jeff Johnsonbc676b42013-02-14 16:04:08 -080014508 if (hdd_wlan_startup(dev))
14509 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014510 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WLAN Driver Initialization failed",
Jeff Johnsonbc676b42013-02-14 16:04:08 -080014511 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070014512 vos_preClose( &pVosContext );
14513 ret_status = -1;
14514 break;
14515 }
14516
Jeff Johnson295189b2012-06-20 16:38:30 -070014517 } while (0);
14518
14519 if (0 != ret_status)
14520 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014521#ifdef TIMER_MANAGER
14522 vos_timer_exit();
14523#endif
14524#ifdef MEMORY_DEBUG
14525 vos_mem_exit();
14526#endif
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014527 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014528#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14529 wlan_logging_sock_deinit_svc();
14530#endif
14531
Jeff Johnson295189b2012-06-20 16:38:30 -070014532 pr_err("%s: driver load failure\n", WLAN_MODULE_NAME);
14533 }
14534 else
14535 {
14536 //Send WLAN UP indication to Nlink Service
14537 send_btc_nlink_msg(WLAN_MODULE_UP_IND, 0);
14538
14539 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Jeff Johnson295189b2012-06-20 16:38:30 -070014540 }
14541
14542 EXIT();
14543
14544 return ret_status;
14545}
14546
Jeff Johnson32d95a32012-09-10 13:15:23 -070014547/**---------------------------------------------------------------------------
14548
14549 \brief hdd_module_init() - Init Function
14550
14551 This is the driver entry point (invoked when module is loaded using insmod)
14552
14553 \param - None
14554
14555 \return - 0 for success, non zero for failure
14556
14557 --------------------------------------------------------------------------*/
14558#ifdef MODULE
14559static int __init hdd_module_init ( void)
14560{
14561 return hdd_driver_init();
14562}
Jeff Johnson32d95a32012-09-10 13:15:23 -070014563#else /* #ifdef MODULE */
14564static int __init hdd_module_init ( void)
14565{
14566 /* Driver initialization is delayed to fwpath_changed_handler */
14567 return 0;
14568}
Jeff Johnson32d95a32012-09-10 13:15:23 -070014569#endif /* #ifdef MODULE */
14570
Jeff Johnson295189b2012-06-20 16:38:30 -070014571
14572/**---------------------------------------------------------------------------
14573
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014574 \brief hdd_driver_exit() - Exit function
Jeff Johnson295189b2012-06-20 16:38:30 -070014575
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014576 This is the driver exit point (invoked when module is unloaded using rmmod
14577 or con_mode was changed by userspace)
Jeff Johnson295189b2012-06-20 16:38:30 -070014578
14579 \param - None
14580
14581 \return - None
14582
14583 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014584static void hdd_driver_exit(void)
Jeff Johnson295189b2012-06-20 16:38:30 -070014585{
14586 hdd_context_t *pHddCtx = NULL;
14587 v_CONTEXT_t pVosContext = NULL;
Agarwal Ashish5e414792014-06-08 15:25:23 +053014588 v_REGDOMAIN_t regId;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053014589 unsigned long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070014590
14591 pr_info("%s: unloading driver v%s\n", WLAN_MODULE_NAME, QWLAN_VERSIONSTR);
14592
14593 //Get the global vos context
14594 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
14595
14596 if(!pVosContext)
14597 {
14598 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
14599 goto done;
14600 }
14601
14602 //Get the HDD context.
14603 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
14604
14605 if(!pHddCtx)
14606 {
14607 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: module exit called before probe",__func__);
14608 }
Katya Nigame7b69a82015-04-28 15:24:06 +053014609 else if (VOS_MONITOR_MODE == hdd_get_conparam())
14610 {
14611 hddLog(VOS_TRACE_LEVEL_INFO,"%s: MONITOR MODE",__func__);
14612 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
14613 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
14614 hdd_wlan_exit(pHddCtx);
14615 vos_preClose( &pVosContext );
14616 goto done;
14617 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014618 else
14619 {
Siddharth Bhal2e5871b2015-03-24 16:20:51 +053014620 /* We wait for active entry threads to exit from driver
14621 * by waiting until rtnl_lock is available.
14622 */
14623 rtnl_lock();
14624 rtnl_unlock();
14625
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014626 INIT_COMPLETION(pHddCtx->ssr_comp_var);
14627 if ((pHddCtx->isLogpInProgress) && (FALSE ==
14628 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)))
14629 {
Siddharth Bhala204f572015-01-17 02:03:36 +053014630 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014631 "%s:SSR in Progress; block rmmod !!!", __func__);
Siddharth Bhala204f572015-01-17 02:03:36 +053014632 rc = wait_for_completion_timeout(&pHddCtx->ssr_comp_var,
14633 msecs_to_jiffies(30000));
14634 if(!rc)
14635 {
14636 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
14637 "%s:SSR timedout, fatal error", __func__);
14638 VOS_BUG(0);
14639 }
14640 }
14641
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014642 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
14643 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -070014644
c_hpothu8adb97b2014-12-08 19:38:20 +053014645 /* Driver Need to send country code 00 in below condition
14646 * 1) If gCountryCodePriority is set to 1; and last country
14647 * code set is through 11d. This needs to be done in case
14648 * when NV country code is 00.
14649 * This Needs to be done as when kernel store last country
14650 * code and if stored country code is not through 11d,
14651 * in sme_HandleChangeCountryCodeByUser we will disable 11d
14652 * in next load/unload as soon as we get any country through
14653 * 11d. In sme_HandleChangeCountryCodeByUser
14654 * pMsg->countryCode will be last countryCode and
14655 * pMac->scan.countryCode11d will be country through 11d so
14656 * due to mismatch driver will disable 11d.
14657 *
14658 */
Agarwal Ashish8db39882014-07-30 21:56:07 +053014659
c_hpothu8adb97b2014-12-08 19:38:20 +053014660 if ((eANI_BOOLEAN_TRUE == sme_Is11dCountrycode(pHddCtx->hHal) &&
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053014661 pHddCtx->cfg_ini->fSupplicantCountryCodeHasPriority &&
Abhishek Singh2a705962014-10-30 14:47:28 +053014662 sme_Is11dSupported(pHddCtx->hHal)))
c_hpothu8adb97b2014-12-08 19:38:20 +053014663 {
14664 hddLog(VOS_TRACE_LEVEL_INFO,
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053014665 FL("CountryCode 00 is being set while unloading driver"));
c_hpothu8adb97b2014-12-08 19:38:20 +053014666 vos_nv_getRegDomainFromCountryCode(&regId , "00", COUNTRY_USER);
14667 }
Agarwal Ashish5e414792014-06-08 15:25:23 +053014668
c_hpothu8adb97b2014-12-08 19:38:20 +053014669 //Do all the cleanup before deregistering the driver
14670 hdd_wlan_exit(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070014671 }
14672
Jeff Johnson295189b2012-06-20 16:38:30 -070014673 vos_preClose( &pVosContext );
14674
14675#ifdef TIMER_MANAGER
14676 vos_timer_exit();
14677#endif
14678#ifdef MEMORY_DEBUG
14679 vos_mem_exit();
14680#endif
14681
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014682#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14683 wlan_logging_sock_deinit_svc();
14684#endif
14685
Jeff Johnson295189b2012-06-20 16:38:30 -070014686done:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014687 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014688
Jeff Johnson295189b2012-06-20 16:38:30 -070014689 pr_info("%s: driver unloaded\n", WLAN_MODULE_NAME);
14690}
14691
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014692/**---------------------------------------------------------------------------
14693
14694 \brief hdd_module_exit() - Exit function
14695
14696 This is the driver exit point (invoked when module is unloaded using rmmod)
14697
14698 \param - None
14699
14700 \return - None
14701
14702 --------------------------------------------------------------------------*/
14703static void __exit hdd_module_exit(void)
14704{
14705 hdd_driver_exit();
14706}
14707
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014708#ifdef MODULE
14709static int fwpath_changed_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014710 const struct kernel_param *kp)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014711{
Jeff Johnson76052702013-04-16 13:55:05 -070014712 return param_set_copystring(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014713}
14714
14715static int con_mode_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014716 const struct kernel_param *kp)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014717{
Madan Mohan Koyyalamudif2f8d8b2012-10-11 17:06:59 -070014718 return param_set_int(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014719}
14720#else /* #ifdef MODULE */
14721/**---------------------------------------------------------------------------
14722
Jeff Johnson76052702013-04-16 13:55:05 -070014723 \brief kickstart_driver
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014724
Jeff Johnson76052702013-04-16 13:55:05 -070014725 This is the driver entry point
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014726 - delayed driver initialization when driver is statically linked
Jeff Johnson76052702013-04-16 13:55:05 -070014727 - invoked when module parameter fwpath is modified from userspace to signal
14728 initializing the WLAN driver or when con_mode is modified from userspace
14729 to signal a switch in operating mode
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014730
14731 \return - 0 for success, non zero for failure
14732
14733 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -070014734static int kickstart_driver(void)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014735{
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014736 int ret_status;
14737
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014738 if (!wlan_hdd_inited) {
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014739 ret_status = hdd_driver_init();
14740 wlan_hdd_inited = ret_status ? 0 : 1;
14741 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014742 }
14743
14744 hdd_driver_exit();
Jeff Johnson76052702013-04-16 13:55:05 -070014745
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014746 msleep(200);
Jeff Johnson76052702013-04-16 13:55:05 -070014747
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014748 ret_status = hdd_driver_init();
14749 wlan_hdd_inited = ret_status ? 0 : 1;
14750 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014751}
14752
Jeff Johnson295189b2012-06-20 16:38:30 -070014753/**---------------------------------------------------------------------------
14754
Jeff Johnson76052702013-04-16 13:55:05 -070014755 \brief fwpath_changed_handler() - Handler Function
14756
14757 Handle changes to the fwpath parameter
14758
14759 \return - 0 for success, non zero for failure
14760
14761 --------------------------------------------------------------------------*/
14762static int fwpath_changed_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014763 const struct kernel_param *kp)
Jeff Johnson76052702013-04-16 13:55:05 -070014764{
14765 int ret;
14766
14767 ret = param_set_copystring(kmessage, kp);
14768 if (0 == ret)
14769 ret = kickstart_driver();
14770 return ret;
14771}
14772
14773/**---------------------------------------------------------------------------
14774
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014775 \brief con_mode_handler() -
14776
14777 Handler function for module param con_mode when it is changed by userspace
14778 Dynamically linked - do nothing
14779 Statically linked - exit and init driver, as in rmmod and insmod
14780
Jeff Johnson76052702013-04-16 13:55:05 -070014781 \param -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014782
Jeff Johnson76052702013-04-16 13:55:05 -070014783 \return -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014784
14785 --------------------------------------------------------------------------*/
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014786static int con_mode_handler(const char *kmessage,
14787 const struct kernel_param *kp)
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014788{
Jeff Johnson76052702013-04-16 13:55:05 -070014789 int ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014790
Jeff Johnson76052702013-04-16 13:55:05 -070014791 ret = param_set_int(kmessage, kp);
14792 if (0 == ret)
14793 ret = kickstart_driver();
14794 return ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014795}
14796#endif /* #ifdef MODULE */
14797
14798/**---------------------------------------------------------------------------
14799
Jeff Johnson295189b2012-06-20 16:38:30 -070014800 \brief hdd_get_conparam() -
14801
14802 This is the driver exit point (invoked when module is unloaded using rmmod)
14803
14804 \param - None
14805
14806 \return - tVOS_CON_MODE
14807
14808 --------------------------------------------------------------------------*/
14809tVOS_CON_MODE hdd_get_conparam ( void )
14810{
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014811#ifdef MODULE
Jeff Johnson295189b2012-06-20 16:38:30 -070014812 return (tVOS_CON_MODE)con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014813#else
14814 return (tVOS_CON_MODE)curr_con_mode;
14815#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014816}
14817void hdd_set_conparam ( v_UINT_t newParam )
14818{
14819 con_mode = newParam;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014820#ifndef MODULE
14821 curr_con_mode = con_mode;
14822#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014823}
14824/**---------------------------------------------------------------------------
14825
14826 \brief hdd_softap_sta_deauth() - function
14827
14828 This to take counter measure to handle deauth req from HDD
14829
14830 \param - pAdapter - Pointer to the HDD
14831
14832 \param - enable - boolean value
14833
14834 \return - None
14835
14836 --------------------------------------------------------------------------*/
14837
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014838VOS_STATUS hdd_softap_sta_deauth(hdd_adapter_t *pAdapter,
14839 struct tagCsrDelStaParams *pDelStaParams)
Jeff Johnson295189b2012-06-20 16:38:30 -070014840{
Jeff Johnson295189b2012-06-20 16:38:30 -070014841 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080014842 VOS_STATUS vosStatus = VOS_STATUS_E_FAULT;
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014843 struct hdd_cache_sta_info *cache_sta_info;
14844 ptSapContext pSapCtx = VOS_GET_SAP_CB(pVosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014845
14846 ENTER();
14847
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014848 hddLog(LOG1, "hdd_softap_sta_deauth:(%pK, false)",
Rajesh Chauhan18488fc2013-08-22 10:15:03 -070014849 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014850
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014851 if (!pSapCtx) {
14852 hddLog(LOGE, "sap context is NULL");
14853 return vosStatus;
14854 }
14855
14856 cache_sta_info = hdd_get_cache_stainfo(pSapCtx->cache_sta_info,
14857 pDelStaParams->peerMacAddr);
14858 if (cache_sta_info) {
14859 cache_sta_info->reason_code = pDelStaParams->reason_code;
14860 cache_sta_info->rx_rate =
14861 wlan_tl_get_sta_rx_rate(pVosContext, cache_sta_info->ucSTAId);
14862 WLANTL_GetSAPStaRSSi(pVosContext, cache_sta_info->ucSTAId,
14863 &cache_sta_info->rssi);
14864 }
14865
Jeff Johnson295189b2012-06-20 16:38:30 -070014866 //Ignore request to deauth bcmc station
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014867 if (pDelStaParams->peerMacAddr[0] & 0x1)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080014868 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070014869
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014870 vosStatus = WLANSAP_DeauthSta(pVosContext, pDelStaParams);
Jeff Johnson295189b2012-06-20 16:38:30 -070014871
14872 EXIT();
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080014873 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070014874}
14875
14876/**---------------------------------------------------------------------------
14877
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014878 \brief hdd_del_all_sta() - function
14879
14880 This function removes all the stations associated on stopping AP/P2P GO.
14881
14882 \param - pAdapter - Pointer to the HDD
14883
14884 \return - None
14885
14886 --------------------------------------------------------------------------*/
14887
14888int hdd_del_all_sta(hdd_adapter_t *pAdapter)
14889{
14890 v_U16_t i;
14891 VOS_STATUS vos_status;
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053014892 v_CONTEXT_t pVosContext = ( WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
14893 ptSapContext pSapCtx = NULL;
14894 pSapCtx = VOS_GET_SAP_CB(pVosContext);
14895 if(pSapCtx == NULL){
14896 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
14897 FL("psapCtx is NULL"));
14898 return 1;
14899 }
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014900 ENTER();
14901
14902 hddLog(VOS_TRACE_LEVEL_INFO,
14903 "%s: Delete all STAs associated.",__func__);
14904 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
14905 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
14906 )
14907 {
14908 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
14909 {
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053014910 if ((pSapCtx->aStaInfo[i].isUsed) &&
14911 (!pSapCtx->aStaInfo[i].isDeauthInProgress))
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014912 {
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014913 struct tagCsrDelStaParams delStaParams;
14914
14915 WLANSAP_PopulateDelStaParams(
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053014916 pSapCtx->aStaInfo[i].macAddrSTA.bytes,
Sushant Kaushik4cd28f62014-12-26 14:23:50 +053014917 eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
14918 SIR_MAC_MGMT_DEAUTH >> 4,
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014919 &delStaParams);
14920 vos_status = hdd_softap_sta_deauth(pAdapter, &delStaParams);
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014921 if (VOS_IS_STATUS_SUCCESS(vos_status))
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053014922 pSapCtx->aStaInfo[i].isDeauthInProgress = TRUE;
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014923 }
14924 }
14925 }
14926
14927 EXIT();
14928 return 0;
14929}
14930
14931/**---------------------------------------------------------------------------
14932
Jeff Johnson295189b2012-06-20 16:38:30 -070014933 \brief hdd_softap_sta_disassoc() - function
14934
14935 This to take counter measure to handle deauth req from HDD
14936
14937 \param - pAdapter - Pointer to the HDD
14938
14939 \param - enable - boolean value
14940
14941 \return - None
14942
14943 --------------------------------------------------------------------------*/
14944
14945void hdd_softap_sta_disassoc(hdd_adapter_t *pAdapter,v_U8_t *pDestMacAddress)
14946{
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014947 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
14948 struct hdd_cache_sta_info *cache_sta_info;
14949 ptSapContext pSapCtx = VOS_GET_SAP_CB(pVosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014950
14951 ENTER();
14952
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014953 hddLog( LOGE, "hdd_softap_sta_disassoc:(%pK, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014954
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014955 if (!pSapCtx) {
14956 hddLog(LOGE, "sap context is NULL");
14957 return ;
14958 }
14959
Jeff Johnson295189b2012-06-20 16:38:30 -070014960 //Ignore request to disassoc bcmc station
14961 if( pDestMacAddress[0] & 0x1 )
14962 return;
14963
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014964 cache_sta_info = hdd_get_cache_stainfo(pSapCtx->cache_sta_info,
14965 pDestMacAddress);
14966 if (cache_sta_info) {
14967 cache_sta_info->reason_code = eSIR_MAC_DEAUTH_LEAVING_BSS_REASON;
14968 cache_sta_info->rx_rate =
14969 wlan_tl_get_sta_rx_rate(pVosContext, cache_sta_info->ucSTAId);
14970 WLANTL_GetSAPStaRSSi(pVosContext, cache_sta_info->ucSTAId,
14971 &cache_sta_info->rssi);
14972 }
14973
Jeff Johnson295189b2012-06-20 16:38:30 -070014974 WLANSAP_DisassocSta(pVosContext,pDestMacAddress);
14975}
14976
14977void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *pAdapter,v_BOOL_t enable)
14978{
14979 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
14980
14981 ENTER();
14982
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014983 hddLog( LOGE, "hdd_softap_tkip_mic_fail_counter_measure:(%pK, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014984
14985 WLANSAP_SetCounterMeasure(pVosContext, (v_BOOL_t)enable);
14986}
14987
Jeff Johnson295189b2012-06-20 16:38:30 -070014988/**---------------------------------------------------------------------------
14989 *
14990 * \brief hdd_get__concurrency_mode() -
14991 *
14992 *
14993 * \param - None
14994 *
14995 * \return - CONCURRENCY MODE
14996 *
14997 * --------------------------------------------------------------------------*/
14998tVOS_CONCURRENCY_MODE hdd_get_concurrency_mode ( void )
14999{
15000 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
15001 hdd_context_t *pHddCtx;
15002
15003 if (NULL != pVosContext)
15004 {
15005 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
15006 if (NULL != pHddCtx)
15007 {
15008 return (tVOS_CONCURRENCY_MODE)pHddCtx->concurrency_mode;
15009 }
15010 }
15011
15012 /* we are in an invalid state :( */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070015013 hddLog(LOGE, "%s: Invalid context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070015014 return VOS_STA;
15015}
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015016v_BOOL_t
15017wlan_hdd_is_GO_power_collapse_allowed (hdd_context_t* pHddCtx)
15018{
15019 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070015020
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015021 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_GO);
15022 if (pAdapter == NULL)
15023 {
15024 hddLog(VOS_TRACE_LEVEL_INFO,
15025 FL("GO doesn't exist"));
15026 return TRUE;
15027 }
15028 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
15029 {
15030 hddLog(VOS_TRACE_LEVEL_INFO,
15031 FL("GO started"));
15032 return TRUE;
15033 }
15034 else
15035 /* wait till GO changes its interface to p2p device */
15036 hddLog(VOS_TRACE_LEVEL_INFO,
15037 FL("Del_bss called, avoid apps suspend"));
15038 return FALSE;
15039
15040}
Jeff Johnson295189b2012-06-20 16:38:30 -070015041/* Decide whether to allow/not the apps power collapse.
15042 * Allow apps power collapse if we are in connected state.
15043 * if not, allow only if we are in IMPS */
15044v_BOOL_t hdd_is_apps_power_collapse_allowed(hdd_context_t* pHddCtx)
15045{
15046 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
Srikant Kuppafef66a72013-01-30 17:32:44 -080015047 tANI_BOOLEAN scanRspPending = csrNeighborRoamScanRspPending(pHddCtx->hHal);
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080015048 tANI_BOOLEAN inMiddleOfRoaming = csrNeighborMiddleOfRoaming(pHddCtx->hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -070015049 hdd_config_t *pConfig = pHddCtx->cfg_ini;
15050 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15051 hdd_adapter_t *pAdapter = NULL;
15052 VOS_STATUS status;
Yathish9f22e662012-12-10 14:21:35 -080015053 tVOS_CONCURRENCY_MODE concurrent_state = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070015054
Jeff Johnson295189b2012-06-20 16:38:30 -070015055 if (VOS_STA_SAP_MODE == hdd_get_conparam())
15056 return TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -070015057
Yathish9f22e662012-12-10 14:21:35 -080015058 concurrent_state = hdd_get_concurrency_mode();
15059
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015060 if ((concurrent_state == (VOS_STA | VOS_P2P_GO)) &&
15061 !(wlan_hdd_is_GO_power_collapse_allowed(pHddCtx)))
15062 return FALSE;
Yathish9f22e662012-12-10 14:21:35 -080015063#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015064
Yathish9f22e662012-12-10 14:21:35 -080015065 if(((concurrent_state == (VOS_STA | VOS_P2P_CLIENT)) ||
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015066 (concurrent_state == (VOS_STA | VOS_P2P_GO)))&&
Yathish9f22e662012-12-10 14:21:35 -080015067 (IS_ACTIVEMODE_OFFLOAD_FEATURE_ENABLE))
15068 return TRUE;
15069#endif
15070
Jeff Johnson295189b2012-06-20 16:38:30 -070015071 /*loop through all adapters. TBD fix for Concurrency */
15072 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15073 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
15074 {
15075 pAdapter = pAdapterNode->pAdapter;
15076 if ( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
15077 || (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
15078 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080015079 if (((pConfig->fIsImpsEnabled || pConfig->fIsBmpsEnabled)
c_hpothu4e8faac2014-05-16 17:38:44 +053015080 && (pmcState != IMPS && pmcState != BMPS && pmcState != UAPSD
c_hpothu1c6957d2015-01-06 18:19:47 +053015081 && pmcState != STOPPED && pmcState != STANDBY &&
15082 pmcState != WOWL)) ||
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080015083 (eANI_BOOLEAN_TRUE == scanRspPending) ||
15084 (eANI_BOOLEAN_TRUE == inMiddleOfRoaming))
Jeff Johnson295189b2012-06-20 16:38:30 -070015085 {
Mukul Sharma4be88422015-03-09 20:29:07 +053015086 if(pmcState == FULL_POWER &&
15087 sme_IsCoexScoIndicationSet(pHddCtx->hHal))
15088 {
15089 /*
15090 * When SCO indication comes from Coex module , host will
15091 * enter in to full power mode, but this should not prevent
15092 * apps processor power collapse.
15093 */
15094 hddLog(LOG1,
15095 FL("Allow apps power collapse"
15096 "even when sco indication is set"));
15097 return TRUE;
15098 }
Srikant Kuppafef66a72013-01-30 17:32:44 -080015099 hddLog( LOGE, "%s: do not allow APPS power collapse-"
Deepthi Gowri03a979f2016-11-03 15:20:19 +053015100 "pmcState = %d scanRspPending = %d "
15101 "inMiddleOfRoaming = %d connected = %d",
15102 __func__, pmcState, scanRspPending,
15103 inMiddleOfRoaming, hdd_connIsConnected(
15104 WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )));
15105 wlan_hdd_get_tdls_stats(pAdapter);
15106 return FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070015107 }
15108 }
15109 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15110 pAdapterNode = pNext;
15111 }
15112 return TRUE;
15113}
15114
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -080015115/* Decides whether to send suspend notification to Riva
15116 * if any adapter is in BMPS; then it is required */
15117v_BOOL_t hdd_is_suspend_notify_allowed(hdd_context_t* pHddCtx)
15118{
15119 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
15120 hdd_config_t *pConfig = pHddCtx->cfg_ini;
15121
15122 if (pConfig->fIsBmpsEnabled && (pmcState == BMPS))
15123 {
15124 return TRUE;
15125 }
15126 return FALSE;
15127}
15128
Jeff Johnson295189b2012-06-20 16:38:30 -070015129void wlan_hdd_set_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15130{
15131 switch(mode)
15132 {
Chilam Ngc4244af2013-04-01 15:37:32 -070015133 case VOS_STA_MODE:
15134 case VOS_P2P_CLIENT_MODE:
15135 case VOS_P2P_GO_MODE:
15136 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053015137 case VOS_MONITOR_MODE:
Jeff Johnsone7245742012-09-05 17:12:55 -070015138 pHddCtx->concurrency_mode |= (1 << mode);
Agarwal Ashish51325b52014-06-16 16:50:49 +053015139 pHddCtx->no_of_open_sessions[mode]++;
Jeff Johnson295189b2012-06-20 16:38:30 -070015140 break;
15141 default:
15142 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070015143 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053015144 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
15145 "Number of open sessions for mode %d = %d"),
15146 pHddCtx->concurrency_mode, mode,
15147 pHddCtx->no_of_open_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070015148}
15149
15150
15151void wlan_hdd_clear_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15152{
15153 switch(mode)
15154 {
Chilam Ngc4244af2013-04-01 15:37:32 -070015155 case VOS_STA_MODE:
15156 case VOS_P2P_CLIENT_MODE:
15157 case VOS_P2P_GO_MODE:
15158 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053015159 case VOS_MONITOR_MODE:
Agarwal Ashish51325b52014-06-16 16:50:49 +053015160 pHddCtx->no_of_open_sessions[mode]--;
15161 if (!(pHddCtx->no_of_open_sessions[mode]))
15162 pHddCtx->concurrency_mode &= (~(1 << mode));
Jeff Johnson295189b2012-06-20 16:38:30 -070015163 break;
15164 default:
15165 break;
15166 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053015167 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
15168 "Number of open sessions for mode %d = %d"),
15169 pHddCtx->concurrency_mode, mode, pHddCtx->no_of_open_sessions[mode]);
15170
15171}
15172/**---------------------------------------------------------------------------
15173 *
15174 * \brief wlan_hdd_incr_active_session()
15175 *
15176 * This function increments the number of active sessions
15177 * maintained per device mode
15178 * Incase of STA/P2P CLI/IBSS upon connection indication it is incremented
15179 * Incase of SAP/P2P GO upon bss start it is incremented
15180 *
15181 * \param pHddCtx - HDD Context
15182 * \param mode - device mode
15183 *
15184 * \return - None
15185 *
15186 * --------------------------------------------------------------------------*/
15187void wlan_hdd_incr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15188{
15189 switch (mode) {
15190 case VOS_STA_MODE:
15191 case VOS_P2P_CLIENT_MODE:
15192 case VOS_P2P_GO_MODE:
15193 case VOS_STA_SAP_MODE:
15194 pHddCtx->no_of_active_sessions[mode]++;
15195 break;
15196 default:
15197 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
15198 break;
15199 }
15200 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
15201 mode,
15202 pHddCtx->no_of_active_sessions[mode]);
15203}
15204
15205/**---------------------------------------------------------------------------
15206 *
15207 * \brief wlan_hdd_decr_active_session()
15208 *
15209 * This function decrements the number of active sessions
15210 * maintained per device mode
15211 * Incase of STA/P2P CLI/IBSS upon disconnection it is decremented
15212 * Incase of SAP/P2P GO upon bss stop it is decremented
15213 *
15214 * \param pHddCtx - HDD Context
15215 * \param mode - device mode
15216 *
15217 * \return - None
15218 *
15219 * --------------------------------------------------------------------------*/
15220void wlan_hdd_decr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15221{
Bhargav Shahd0715912015-10-01 18:17:37 +053015222
Agarwal Ashish51325b52014-06-16 16:50:49 +053015223 switch (mode) {
15224 case VOS_STA_MODE:
15225 case VOS_P2P_CLIENT_MODE:
15226 case VOS_P2P_GO_MODE:
15227 case VOS_STA_SAP_MODE:
Agarwal Ashish5325f522014-08-06 00:58:44 +053015228 if (pHddCtx->no_of_active_sessions[mode] > 0)
15229 pHddCtx->no_of_active_sessions[mode]--;
15230 else
15231 hddLog(VOS_TRACE_LEVEL_INFO, FL(" No.# of Active sessions"
15232 "is already Zero"));
Agarwal Ashish51325b52014-06-16 16:50:49 +053015233 break;
15234 default:
15235 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
15236 break;
15237 }
15238 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
15239 mode,
15240 pHddCtx->no_of_active_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070015241}
15242
Jeff Johnsone7245742012-09-05 17:12:55 -070015243/**---------------------------------------------------------------------------
15244 *
15245 * \brief wlan_hdd_restart_init
15246 *
15247 * This function initalizes restart timer/flag. An internal function.
15248 *
15249 * \param - pHddCtx
15250 *
15251 * \return - None
15252 *
15253 * --------------------------------------------------------------------------*/
15254
15255static void wlan_hdd_restart_init(hdd_context_t *pHddCtx)
15256{
15257 /* Initialize */
15258 pHddCtx->hdd_restart_retries = 0;
15259 atomic_set(&pHddCtx->isRestartInProgress, 0);
15260 vos_timer_init(&pHddCtx->hdd_restart_timer,
15261 VOS_TIMER_TYPE_SW,
15262 wlan_hdd_restart_timer_cb,
15263 pHddCtx);
15264}
15265/**---------------------------------------------------------------------------
15266 *
15267 * \brief wlan_hdd_restart_deinit
15268 *
15269 * This function cleans up the resources used. An internal function.
15270 *
15271 * \param - pHddCtx
15272 *
15273 * \return - None
15274 *
15275 * --------------------------------------------------------------------------*/
15276
15277static void wlan_hdd_restart_deinit(hdd_context_t* pHddCtx)
15278{
15279
15280 VOS_STATUS vos_status;
15281 /* Block any further calls */
15282 atomic_set(&pHddCtx->isRestartInProgress, 1);
15283 /* Cleanup */
15284 vos_status = vos_timer_stop( &pHddCtx->hdd_restart_timer );
15285 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053015286 hddLog(LOGE, FL("Failed to stop HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070015287 vos_status = vos_timer_destroy(&pHddCtx->hdd_restart_timer);
15288 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053015289 hddLog(LOGE, FL("Failed to destroy HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070015290
15291}
15292
15293/**---------------------------------------------------------------------------
15294 *
15295 * \brief wlan_hdd_framework_restart
15296 *
15297 * This function uses a cfg80211 API to start a framework initiated WLAN
15298 * driver module unload/load.
15299 *
15300 * Also this API keep retrying (WLAN_HDD_RESTART_RETRY_MAX_CNT).
15301 *
15302 *
15303 * \param - pHddCtx
15304 *
15305 * \return - VOS_STATUS_SUCCESS: Success
15306 * VOS_STATUS_E_EMPTY: Adapter is Empty
15307 * VOS_STATUS_E_NOMEM: No memory
15308
15309 * --------------------------------------------------------------------------*/
15310
15311static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx)
15312{
15313 VOS_STATUS status = VOS_STATUS_SUCCESS;
15314 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015315 int len = (sizeof (struct ieee80211_mgmt));
15316 struct ieee80211_mgmt *mgmt = NULL;
15317
15318 /* Prepare the DEAUTH managment frame with reason code */
15319 mgmt = kzalloc(len, GFP_KERNEL);
15320 if(mgmt == NULL)
15321 {
15322 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
15323 "%s: memory allocation failed (%d bytes)", __func__, len);
15324 return VOS_STATUS_E_NOMEM;
15325 }
15326 mgmt->u.deauth.reason_code = WLAN_REASON_DISASSOC_LOW_ACK;
Jeff Johnsone7245742012-09-05 17:12:55 -070015327
15328 /* Iterate over all adapters/devices */
15329 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015330 if ((NULL == pAdapterNode) || (VOS_STATUS_SUCCESS != status))
15331 {
15332 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070015333 FL("fail to get adapter: %pK %d"), pAdapterNode, status);
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015334 goto end;
15335 }
15336
Jeff Johnsone7245742012-09-05 17:12:55 -070015337 do
15338 {
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015339 if(pAdapterNode->pAdapter &&
15340 WLAN_HDD_ADAPTER_MAGIC == pAdapterNode->pAdapter->magic)
Jeff Johnsone7245742012-09-05 17:12:55 -070015341 {
15342 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
15343 "restarting the driver(intf:\'%s\' mode:%d :try %d)",
15344 pAdapterNode->pAdapter->dev->name,
15345 pAdapterNode->pAdapter->device_mode,
15346 pHddCtx->hdd_restart_retries + 1);
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015347 /*
15348 * CFG80211 event to restart the driver
15349 *
15350 * 'cfg80211_send_unprot_deauth' sends a
15351 * NL80211_CMD_UNPROT_DEAUTHENTICATE event to supplicant at any state
15352 * of SME(Linux Kernel) state machine.
15353 *
15354 * Reason code WLAN_REASON_DISASSOC_LOW_ACK is currently used to restart
15355 * the driver.
15356 *
15357 */
Abhishek Singh00b71972016-01-07 10:51:04 +053015358
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053015359#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
15360 cfg80211_rx_unprot_mlme_mgmt(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len);
15361#else
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015362 cfg80211_send_unprot_deauth(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053015363#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070015364 }
15365 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15366 pAdapterNode = pNext;
15367 } while((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status));
15368
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015369 end:
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015370 /* Free the allocated management frame */
15371 kfree(mgmt);
15372
Jeff Johnsone7245742012-09-05 17:12:55 -070015373 /* Retry until we unload or reach max count */
15374 if(++pHddCtx->hdd_restart_retries < WLAN_HDD_RESTART_RETRY_MAX_CNT)
15375 vos_timer_start(&pHddCtx->hdd_restart_timer, WLAN_HDD_RESTART_RETRY_DELAY_MS);
15376
15377 return status;
15378
15379}
15380/**---------------------------------------------------------------------------
15381 *
15382 * \brief wlan_hdd_restart_timer_cb
15383 *
15384 * Restart timer callback. An internal function.
15385 *
15386 * \param - User data:
15387 *
15388 * \return - None
15389 *
15390 * --------------------------------------------------------------------------*/
15391
15392void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback)
15393{
15394 hdd_context_t *pHddCtx = usrDataForCallback;
15395 wlan_hdd_framework_restart(pHddCtx);
15396 return;
15397
15398}
15399
15400
15401/**---------------------------------------------------------------------------
15402 *
15403 * \brief wlan_hdd_restart_driver
15404 *
15405 * This function sends an event to supplicant to restart the WLAN driver.
15406 *
15407 * This function is called from vos_wlanRestart.
15408 *
15409 * \param - pHddCtx
15410 *
15411 * \return - VOS_STATUS_SUCCESS: Success
15412 * VOS_STATUS_E_EMPTY: Adapter is Empty
15413 * VOS_STATUS_E_ALREADY: Request already in progress
15414
15415 * --------------------------------------------------------------------------*/
15416VOS_STATUS wlan_hdd_restart_driver(hdd_context_t *pHddCtx)
15417{
15418 VOS_STATUS status = VOS_STATUS_SUCCESS;
15419
15420 /* A tight check to make sure reentrancy */
15421 if(atomic_xchg(&pHddCtx->isRestartInProgress, 1))
15422 {
Mihir Shetefd528652014-06-23 19:07:50 +053015423 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsone7245742012-09-05 17:12:55 -070015424 "%s: WLAN restart is already in progress", __func__);
15425
15426 return VOS_STATUS_E_ALREADY;
15427 }
Sameer Thalappil0c164f52013-03-28 15:27:56 -070015428 /* Send reset FIQ to WCNSS to invoke SSR. */
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -080015429#ifdef HAVE_WCNSS_RESET_INTR
Siddharth Bhal864e7e82015-04-07 20:07:24 +053015430 wcnss_reset_fiq(TRUE);
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -070015431#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070015432
Jeff Johnsone7245742012-09-05 17:12:55 -070015433 return status;
15434}
15435
Bhargav Shahd0715912015-10-01 18:17:37 +053015436/**
15437 * hdd_get_total_sessions() - provide total number of active sessions
15438 * @pHddCtx: Valid Global HDD context pointer
15439 *
15440 * This function iterates through pAdaptors and find the number of all active
15441 * sessions. This active sessions includes connected sta, p2p client and number
15442 * of client connected to sap/p2p go.
15443 *
15444 * Return: Total number of active sessions.
15445 */
15446v_U8_t hdd_get_total_sessions(hdd_context_t *pHddCtx)
15447{
15448 v_U8_t active_session = 0;
15449 hdd_station_ctx_t *pHddStaCtx;
15450 hdd_adapter_list_node_t *pAdapterNode, *pNext;
15451 hdd_adapter_t *pAdapter;
15452 VOS_STATUS status;
15453
15454 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
15455 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
15456 pAdapter = pAdapterNode->pAdapter;
15457 switch (pAdapter->device_mode) {
15458 case VOS_STA_MODE:
15459 case VOS_P2P_CLIENT_MODE:
15460 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
15461 if(eConnectionState_Associated == pHddStaCtx->conn_info.connState)
15462 active_session += 1;
15463 break;
15464 case VOS_STA_SAP_MODE:
15465 case VOS_P2P_GO_MODE:
15466 active_session += hdd_softap_get_connected_sta(pAdapter);
15467 break;
15468 default:
15469 break;
15470 }
15471
15472 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
15473 pAdapterNode = pNext;
15474 }
15475
15476 return active_session;
15477}
15478
15479/**
15480 * hdd_set_delack_value() - Set delack value
15481 * @pHddCtx: Valid Global HDD context pointer
15482 * @next_rx_level: Value to set for delack
15483 *
15484 * This function compare present value and next value of delack. If the both
15485 * are diffrent then it sets next value .
15486 *
15487 * Return: void.
15488 */
15489void hdd_set_delack_value(hdd_context_t *pHddCtx, v_U32_t next_rx_level)
15490{
15491 if (pHddCtx->cur_rx_level != next_rx_level) {
15492 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15493 "%s: TCP DELACK trigger level %d",
15494 __func__, next_rx_level);
15495 mutex_lock(&pHddCtx->cur_rx_level_lock);
15496 pHddCtx->cur_rx_level = next_rx_level;
15497 mutex_unlock(&pHddCtx->cur_rx_level_lock);
15498 wlan_hdd_send_svc_nlink_msg(WLAN_SVC_WLAN_TP_IND, &next_rx_level,
15499 sizeof(next_rx_level));
15500 }
15501}
15502
15503/**
15504 * hdd_set_default_stop_delack_timer() - Start delack timer
15505 * @pHddCtx: Valid Global HDD context pointer
15506 *
15507 * This function stop delack timer and set delack value to default..
15508 *
15509 * Return: void.
15510 */
15511
15512void hdd_set_default_stop_delack_timer(hdd_context_t *pHddCtx)
15513{
15514 if (VOS_TIMER_STATE_RUNNING !=
15515 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
15516 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15517 "%s: Can not stop timer", __func__);
15518 return;
15519 }
15520
15521 vos_timer_stop(&pHddCtx->delack_timer);
15522 hdd_set_delack_value(pHddCtx, TP_IND_LOW);
15523}
15524
15525/**
15526 * hdd_start_delack_timer() - Start delack timer
15527 * @pHddCtx: Valid Global HDD context pointer
15528 *
15529 * This function starts the delack timer for tcpDelAckComputeInterval time
15530 * interval.The default timer value is 2 second.
15531 *
15532 * Return: void.
15533 */
15534void hdd_start_delack_timer(hdd_context_t *pHddCtx)
15535{
15536 if (VOS_TIMER_STATE_RUNNING ==
15537 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
15538 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15539 "%s: Timer is already running", __func__);
15540 return;
15541 }
15542
15543 vos_timer_start(&pHddCtx->delack_timer,
15544 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
15545}
15546
15547/**
15548 * hdd_update_prev_rx_packet_count() - Update previous rx packet count
15549 * @pHddCtx: Valid Global HDD context pointer
15550 *
15551 * This function updates the prev_rx_packets count from the corresponding
15552 * pAdapter states. This prev_rx_packets will diffed with the packet count
15553 * at the end of delack timer. That can give number of RX packet is spacific
15554 * time.
15555 *
15556 * Return: void.
15557 */
15558void hdd_update_prev_rx_packet_count(hdd_context_t *pHddCtx)
15559{
15560 hdd_adapter_list_node_t *pAdapterNode, *pNext;
15561 hdd_adapter_t *pAdapter;
15562 VOS_STATUS status;
15563
15564 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15565 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
15566 pAdapter = pAdapterNode->pAdapter;
15567 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
15568 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15569 pAdapterNode = pNext;
15570 }
15571}
15572
15573/**
15574 * hdd_manage_delack_timer() - start\stop delack timer
15575 * @pHddCtx: Valid Global HDD context pointer
15576 *
15577 * This function check the number of concerent session present, it starts the
15578 * delack timer if only one session is present.
15579 * In the case of BT_COEX and TDLS mode it blindly stop delack functionality.
15580 *
15581 * Return: void.
15582 */
15583void hdd_manage_delack_timer(hdd_context_t *pHddCtx)
15584{
15585 uint8_t sessions;
15586
15587 if (!pHddCtx->cfg_ini->enable_delack) {
15588 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15589 "%s: TCP DELACK is not enabled", __func__);
15590 return;
15591 }
15592
15593 /* Blindly stop timer of BTCOEX and TDLS Session is up */
15594 if (pHddCtx->mode != 0) {
15595 hdd_set_default_stop_delack_timer(pHddCtx);
15596 return;
15597 }
15598
15599 sessions = hdd_get_total_sessions(pHddCtx);
15600 if (sessions == 1) {
15601 hdd_update_prev_rx_packet_count(pHddCtx);
15602 hdd_start_delack_timer(pHddCtx);
15603 } else {
15604 hdd_set_default_stop_delack_timer(pHddCtx);
15605 }
15606}
15607
Mihir Shetee1093ba2014-01-21 20:13:32 +053015608/**---------------------------------------------------------------------------
15609 *
15610 * \brief wlan_hdd_init_channels
15611 *
15612 * This function is used to initialize the channel list in CSR
15613 *
15614 * This function is called from hdd_wlan_startup
15615 *
15616 * \param - pHddCtx: HDD context
15617 *
15618 * \return - VOS_STATUS_SUCCESS: Success
15619 * VOS_STATUS_E_FAULT: Failure reported by SME
15620
15621 * --------------------------------------------------------------------------*/
15622static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx)
15623{
15624 eHalStatus status;
15625
15626 status = sme_InitChannels(pHddCtx->hHal);
15627 if (HAL_STATUS_SUCCESS(status))
15628 {
15629 return VOS_STATUS_SUCCESS;
15630 }
15631 else
15632 {
15633 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Channel initialization failed(%d)",
15634 __func__, status);
15635 return VOS_STATUS_E_FAULT;
15636 }
15637}
15638
Mihir Shete04206452014-11-20 17:50:58 +053015639#ifdef CONFIG_ENABLE_LINUX_REG
Agarwal Ashish6db9d532014-09-30 18:19:10 +053015640VOS_STATUS wlan_hdd_init_channels_for_cc(hdd_context_t *pHddCtx, driver_load_type init )
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053015641{
15642 eHalStatus status;
15643
Agarwal Ashish6db9d532014-09-30 18:19:10 +053015644 status = sme_InitChannelsForCC(pHddCtx->hHal, init);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053015645 if (HAL_STATUS_SUCCESS(status))
15646 {
15647 return VOS_STATUS_SUCCESS;
15648 }
15649 else
15650 {
15651 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Issue reg hint failed(%d)",
15652 __func__, status);
15653 return VOS_STATUS_E_FAULT;
15654 }
15655}
Mihir Shete04206452014-11-20 17:50:58 +053015656#endif
Sudhir Sattayappa Kohallib1d8c3a2013-06-18 14:47:20 -070015657/*
15658 * API to find if there is any STA or P2P-Client is connected
15659 */
15660VOS_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *pHddCtx)
15661{
15662 return sme_isSta_p2p_clientConnected(pHddCtx->hHal);
15663}
Jeff Johnsone7245742012-09-05 17:12:55 -070015664
Mihir Shetee2ae82a2015-03-16 14:08:49 +053015665
15666/*
15667 * API to find if the firmware will send logs using DXE channel
15668 */
15669v_U8_t hdd_is_fw_logging_enabled(void)
15670{
15671 hdd_context_t *pHddCtx;
15672
15673 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
15674 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
15675
Sachin Ahuja084313e2015-05-21 17:57:10 +053015676 return (pHddCtx && pHddCtx->cfg_ini->enableMgmtLogging);
Mihir Shetee2ae82a2015-03-16 14:08:49 +053015677}
15678
Agarwal Ashish57e84372014-12-05 18:26:53 +053015679/*
Mihir Shetebe94ebb2015-05-26 12:07:14 +053015680 * API to find if the firmware will send trace logs using DXE channel
15681 */
15682v_U8_t hdd_is_fw_ev_logging_enabled(void)
15683{
15684 hdd_context_t *pHddCtx;
15685
15686 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
15687 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
15688
15689 return (pHddCtx && pHddCtx->cfg_ini->enableFWLogging);
15690}
15691/*
Agarwal Ashish57e84372014-12-05 18:26:53 +053015692 * API to find if there is any session connected
15693 */
15694VOS_STATUS hdd_is_any_session_connected(hdd_context_t *pHddCtx)
15695{
15696 return sme_is_any_session_connected(pHddCtx->hHal);
15697}
15698
15699
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015700int wlan_hdd_scan_abort(hdd_adapter_t *pAdapter)
15701{
15702 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
15703 hdd_scaninfo_t *pScanInfo = NULL;
Girish Gowli4bf7a632014-06-12 13:42:11 +053015704 long status = 0;
c_hpothua3d45d52015-01-05 14:11:17 +053015705 tSirAbortScanStatus abortScanStatus;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015706
15707 pScanInfo = &pHddCtx->scan_info;
Ratnam Rachuric7681132015-06-30 10:35:13 +053015708 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015709 if (pScanInfo->mScanPending)
15710 {
c_hpothua3d45d52015-01-05 14:11:17 +053015711 abortScanStatus = hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
15712 eCSR_SCAN_ABORT_DEFAULT);
15713 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15714 FL("abortScanStatus: %d"), abortScanStatus);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015715
c_hpothua3d45d52015-01-05 14:11:17 +053015716 /* If there is active scan command lets wait for the completion else
15717 * there is no need to wait as scan command might be in the SME pending
15718 * command list.
15719 */
15720 if (abortScanStatus == eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY)
15721 {
Mukul Sharmab392b642017-08-17 17:45:29 +053015722 status = wait_for_completion_timeout(
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015723 &pScanInfo->abortscan_event_var,
15724 msecs_to_jiffies(5000));
c_hpothua3d45d52015-01-05 14:11:17 +053015725 if (0 >= status)
15726 {
15727 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Girish Gowli4bf7a632014-06-12 13:42:11 +053015728 "%s: Timeout or Interrupt occurred while waiting for abort"
15729 "scan, status- %ld", __func__, status);
c_hpothua3d45d52015-01-05 14:11:17 +053015730 return -ETIMEDOUT;
15731 }
15732 }
15733 else if (abortScanStatus == eSIR_ABORT_SCAN_FAILURE)
15734 {
15735 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15736 FL("hdd_abort_mac_scan failed"));
15737 return -VOS_STATUS_E_FAILURE;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015738 }
15739 }
Girish Gowli4bf7a632014-06-12 13:42:11 +053015740 return 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015741}
15742
Abhishek Singh7d624e12015-11-30 14:29:27 +053015743/**
15744 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
15745 * user space
15746 * @frame_ind: Management frame data to be informed.
15747 *
15748 * This function is used to indicate management frame to
15749 * user space
15750 *
15751 * Return: None
15752 *
15753 */
15754void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
15755{
15756 hdd_context_t *hdd_ctx = NULL;
15757 hdd_adapter_t *adapter = NULL;
15758 v_CONTEXT_t vos_context = NULL;
15759
15760 /* Get the global VOSS context.*/
15761 vos_context = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
15762 if (!vos_context) {
15763 hddLog(LOGE, FL("Global VOS context is Null"));
15764 return;
15765 }
15766 /* Get the HDD context.*/
15767 hdd_ctx =
15768 (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, vos_context );
15769
15770 if (0 != wlan_hdd_validate_context(hdd_ctx))
15771 {
15772 return;
15773 }
15774 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
15775 frame_ind->sessionId);
15776
15777 if ((NULL != adapter) &&
15778 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
15779 __hdd_indicate_mgmt_frame(adapter,
15780 frame_ind->frameLen,
15781 frame_ind->frameBuf,
15782 frame_ind->frameType,
15783 frame_ind->rxChan,
15784 frame_ind->rxRssi);
15785 return;
15786
15787}
15788
c_hpothu225aa7c2014-10-22 17:45:13 +053015789VOS_STATUS wlan_hdd_cancel_remain_on_channel(hdd_context_t *pHddCtx)
15790{
15791 hdd_adapter_t *pAdapter;
15792 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15793 VOS_STATUS vosStatus;
15794
15795 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15796 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
15797 {
15798 pAdapter = pAdapterNode->pAdapter;
15799 if (NULL != pAdapter)
15800 {
15801 if (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode ||
15802 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
15803 WLAN_HDD_P2P_GO == pAdapter->device_mode)
15804 {
15805 hddLog(LOG1, FL("abort ROC deviceMode: %d"),
15806 pAdapter->device_mode);
15807 if (VOS_STATUS_SUCCESS !=
15808 wlan_hdd_cancel_existing_remain_on_channel(pAdapter))
15809 {
15810 hddLog(LOGE, FL("failed to abort ROC"));
15811 return VOS_STATUS_E_FAILURE;
15812 }
15813 }
15814 }
15815 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15816 pAdapterNode = pNext;
15817 }
15818 return VOS_STATUS_SUCCESS;
15819}
Mahesh A Saptasagard477b092015-02-06 15:12:16 +053015820
Mihir Shete0be28772015-02-17 18:42:14 +053015821hdd_remain_on_chan_ctx_t *hdd_get_remain_on_channel_ctx(hdd_context_t *pHddCtx)
15822{
15823 hdd_adapter_t *pAdapter;
15824 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15825 hdd_cfg80211_state_t *cfgState;
15826 hdd_remain_on_chan_ctx_t *pRemainChanCtx = NULL;
15827 VOS_STATUS vosStatus;
15828
15829 vosStatus = hdd_get_front_adapter (pHddCtx, &pAdapterNode);
15830 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
15831 {
15832 pAdapter = pAdapterNode->pAdapter;
15833 if (NULL != pAdapter)
15834 {
15835 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter);
15836 pRemainChanCtx = cfgState->remain_on_chan_ctx;
15837 if (pRemainChanCtx)
15838 break;
15839 }
15840 vosStatus = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
15841 pAdapterNode = pNext;
15842 }
15843 return pRemainChanCtx;
15844}
15845
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +053015846/**
15847 * wlan_hdd_handle_dfs_chan_scan () - handles disable/enable DFS channels
15848 *
15849 * @pHddCtx: HDD context within host driver
15850 * @dfsScanMode: dfsScanMode passed from ioctl
15851 *
15852 */
15853
15854VOS_STATUS wlan_hdd_handle_dfs_chan_scan(hdd_context_t *pHddCtx,
15855 tANI_U8 dfsScanMode)
15856{
15857 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15858 hdd_adapter_t *pAdapter;
15859 VOS_STATUS vosStatus;
15860 hdd_station_ctx_t *pHddStaCtx;
15861 eHalStatus status = eHAL_STATUS_SUCCESS;
15862
15863 if(!pHddCtx)
15864 {
15865 hddLog(LOGE, FL("HDD context is Null"));
15866 return eHAL_STATUS_FAILURE;
15867 }
15868
15869 if (pHddCtx->scan_info.mScanPending)
15870 {
15871 hddLog(LOG1, FL("Aborting scan for sessionId: %d"),
15872 pHddCtx->scan_info.sessionId);
15873 hdd_abort_mac_scan(pHddCtx,
15874 pHddCtx->scan_info.sessionId,
15875 eCSR_SCAN_ABORT_DEFAULT);
15876 }
15877
15878 if (!dfsScanMode)
15879 {
15880 vosStatus = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
15881 while ((NULL != pAdapterNode) &&
15882 (VOS_STATUS_SUCCESS == vosStatus))
15883 {
15884 pAdapter = pAdapterNode->pAdapter;
15885
15886 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
15887 {
15888 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
15889
15890 if(!pHddStaCtx)
15891 {
15892 hddLog(LOGE, FL("HDD STA context is Null"));
15893 return eHAL_STATUS_FAILURE;
15894 }
15895
15896 /* if STA is already connected on DFS channel,
15897 disconnect immediately*/
15898 if (hdd_connIsConnected(pHddStaCtx) &&
15899 (NV_CHANNEL_DFS ==
15900 vos_nv_getChannelEnabledState(
15901 pHddStaCtx->conn_info.operationChannel)))
15902 {
15903 status = sme_RoamDisconnect(pHddCtx->hHal,
15904 pAdapter->sessionId,
15905 eCSR_DISCONNECT_REASON_UNSPECIFIED);
15906 hddLog(LOG1, FL("Client connected on DFS channel %d,"
15907 "sme_RoamDisconnect returned with status: %d"
15908 "for sessionid: %d"), pHddStaCtx->conn_info.
15909 operationChannel, status, pAdapter->sessionId);
15910 }
15911 }
15912
15913 vosStatus = hdd_get_next_adapter(pHddCtx, pAdapterNode,
15914 &pNext);
15915 pAdapterNode = pNext;
15916 }
15917 }
15918
15919 sme_UpdateDFSScanMode(pHddCtx->hHal, dfsScanMode);
15920 sme_UpdateDFSRoamMode(pHddCtx->hHal,
15921 (dfsScanMode != DFS_CHNL_SCAN_DISABLED));
15922
15923 status = sme_HandleDFSChanScan(pHddCtx->hHal);
15924 if (!HAL_STATUS_SUCCESS(status))
15925 {
15926 hddLog(LOGE,
15927 FL("Failed in sme_HandleDFSChanScan (err=%d)"), status);
15928 return status;
15929 }
15930
15931 return status;
15932}
15933
Nirav Shah7e3c8132015-06-22 23:51:42 +053015934static int hdd_log2_ceil(unsigned value)
15935{
15936 /* need to switch to unsigned math so that negative values
15937 * will right-shift towards 0 instead of -1
15938 */
15939 unsigned tmp = value;
15940 int log2 = -1;
15941
15942 if (value == 0)
15943 return 0;
15944
15945 while (tmp) {
15946 log2++;
15947 tmp >>= 1;
15948 }
15949 if (1U << log2 != value)
15950 log2++;
15951
15952 return log2;
15953}
15954
15955/**
15956 * hdd_sta_id_hash_attach() - initialize sta id to macaddr hash
15957 * @pAdapter: adapter handle
15958 *
15959 * Return: vos status
15960 */
15961VOS_STATUS hdd_sta_id_hash_attach(hdd_adapter_t *pAdapter)
15962{
15963 int hash_elem, log2, i;
15964
15965 spin_lock_bh( &pAdapter->sta_hash_lock);
15966 if (pAdapter->is_sta_id_hash_initialized == VOS_TRUE) {
15967 spin_unlock_bh( &pAdapter->sta_hash_lock);
15968 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15969 "%s: hash already attached for session id %d",
15970 __func__, pAdapter->sessionId);
15971 return VOS_STATUS_SUCCESS;
15972 }
15973 spin_unlock_bh( &pAdapter->sta_hash_lock);
15974
15975 hash_elem = WLAN_MAX_STA_COUNT;
15976 hash_elem *= HDD_STA_ID_HASH_MULTIPLIER;
15977 log2 = hdd_log2_ceil(hash_elem);
15978 hash_elem = 1 << log2;
15979
15980 pAdapter->sta_id_hash.mask = hash_elem - 1;
15981 pAdapter->sta_id_hash.idx_bits = log2;
15982 pAdapter->sta_id_hash.bins =
15983 vos_mem_malloc(hash_elem *sizeof(hdd_list_t));
15984 if (!pAdapter->sta_id_hash.bins) {
15985 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15986 "%s: malloc failed for session %d",
15987 __func__, pAdapter->sessionId);
15988 return VOS_STATUS_E_NOMEM;
15989 }
15990
15991 for (i = 0; i < hash_elem; i++)
15992 hdd_list_init(&pAdapter->sta_id_hash.bins[i], WLAN_MAX_STA_COUNT);
15993
15994 spin_lock_bh( &pAdapter->sta_hash_lock);
15995 pAdapter->is_sta_id_hash_initialized = VOS_TRUE;
15996 spin_unlock_bh( &pAdapter->sta_hash_lock);
15997 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15998 "%s: Station ID Hash attached for session id %d",
15999 __func__, pAdapter->sessionId);
16000
16001 return VOS_STATUS_SUCCESS;
16002}
16003
16004/**
16005 * hdd_sta_id_hash_detach() - deinit sta_id to macaddr hash
16006 * @pAdapter: adapter handle
16007 *
16008 * Return: vos status
16009 */
16010VOS_STATUS hdd_sta_id_hash_detach(hdd_adapter_t *pAdapter)
16011{
16012 int hash_elem, i;
16013 v_SIZE_t size;
16014
16015 spin_lock_bh( &pAdapter->sta_hash_lock);
16016 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16017 spin_unlock_bh( &pAdapter->sta_hash_lock);
16018 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16019 "%s: hash not initialized for session id %d",
16020 __func__, pAdapter->sessionId);
16021 return VOS_STATUS_SUCCESS;
16022 }
16023
16024 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
16025 spin_unlock_bh( &pAdapter->sta_hash_lock);
16026
16027 hash_elem = 1 << pAdapter->sta_id_hash.idx_bits;
16028
16029 /* free all station info*/
16030 for (i = 0; i < hash_elem; i++) {
16031 hdd_list_size(&pAdapter->sta_id_hash.bins[i], &size);
16032 if (size != 0) {
16033 VOS_STATUS status;
16034 hdd_staid_hash_node_t *sta_info_node = NULL;
16035 hdd_staid_hash_node_t *next_node = NULL;
16036 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[i],
16037 (hdd_list_node_t**) &sta_info_node );
16038
16039 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16040 {
16041 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[i],
16042 &sta_info_node->node);
16043 vos_mem_free(sta_info_node);
16044
16045 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[i],
16046 (hdd_list_node_t*)sta_info_node,
16047 (hdd_list_node_t**)&next_node);
16048 sta_info_node = next_node;
16049 }
16050 }
16051 }
16052
16053 vos_mem_free(pAdapter->sta_id_hash.bins);
16054 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16055 "%s: Station ID Hash detached for session id %d",
16056 __func__, pAdapter->sessionId);
16057 return VOS_STATUS_SUCCESS;
16058}
16059
16060/**
16061 * hdd_sta_id_hash_calculate_index() - derive index from macaddr
16062 * @pAdapter: adapter handle
16063 * @mac_addr_in: input mac address
16064 *
16065 * Return: index derived from mac address
16066 */
16067int hdd_sta_id_hash_calculate_index(hdd_adapter_t *pAdapter,
16068 v_MACADDR_t *mac_addr_in)
16069{
16070 uint16 index;
16071 struct hdd_align_mac_addr_t * mac_addr =
16072 (struct hdd_align_mac_addr_t *)mac_addr_in;
16073
16074 index = mac_addr->bytes_ab ^
16075 mac_addr->bytes_cd ^ mac_addr->bytes_ef;
16076 index ^= index >> pAdapter->sta_id_hash.idx_bits;
16077 index &= pAdapter->sta_id_hash.mask;
16078 return index;
16079}
16080
16081/**
16082 * hdd_sta_id_hash_add_entry() - add entry in hash
16083 * @pAdapter: adapter handle
16084 * @sta_id: station id
16085 * @mac_addr: mac address
16086 *
16087 * Return: vos status
16088 */
16089VOS_STATUS hdd_sta_id_hash_add_entry(hdd_adapter_t *pAdapter,
16090 v_U8_t sta_id, v_MACADDR_t *mac_addr)
16091{
16092 uint16 index;
16093 hdd_staid_hash_node_t *sta_info_node = NULL;
16094
Nirav Shah7e3c8132015-06-22 23:51:42 +053016095 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
16096 sta_info_node = vos_mem_malloc(sizeof(hdd_staid_hash_node_t));
16097 if (!sta_info_node) {
Nirav Shah7e3c8132015-06-22 23:51:42 +053016098 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16099 "%s: malloc failed", __func__);
16100 return VOS_STATUS_E_NOMEM;
16101 }
16102
16103 sta_info_node->sta_id = sta_id;
16104 vos_mem_copy(&sta_info_node->mac_addr, mac_addr, sizeof(v_MACADDR_t));
16105
Nirav Shah303ed5c2015-08-24 10:29:25 +053016106 spin_lock_bh( &pAdapter->sta_hash_lock);
16107 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16108 spin_unlock_bh( &pAdapter->sta_hash_lock);
16109 vos_mem_free(sta_info_node);
16110 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16111 "%s: hash is not initialized for session id %d",
16112 __func__, pAdapter->sessionId);
16113 return VOS_STATUS_E_FAILURE;
16114 }
16115
Nirav Shah7e3c8132015-06-22 23:51:42 +053016116 hdd_list_insert_back ( &pAdapter->sta_id_hash.bins[index],
16117 (hdd_list_node_t*) sta_info_node );
16118 spin_unlock_bh( &pAdapter->sta_hash_lock);
16119 return VOS_STATUS_SUCCESS;
16120}
16121
16122/**
16123 * hdd_sta_id_hash_remove_entry() - remove entry from hash
16124 * @pAdapter: adapter handle
16125 * @sta_id: station id
16126 * @mac_addr: mac address
16127 *
16128 * Return: vos status
16129 */
16130VOS_STATUS hdd_sta_id_hash_remove_entry(hdd_adapter_t *pAdapter,
16131 v_U8_t sta_id, v_MACADDR_t *mac_addr)
16132{
16133 uint16 index;
16134 VOS_STATUS status;
16135 hdd_staid_hash_node_t *sta_info_node = NULL;
16136 hdd_staid_hash_node_t *next_node = NULL;
16137
16138 spin_lock_bh( &pAdapter->sta_hash_lock);
16139 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16140 spin_unlock_bh( &pAdapter->sta_hash_lock);
16141 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16142 "%s: hash is not initialized for session id %d",
16143 __func__, pAdapter->sessionId);
16144 return VOS_STATUS_E_FAILURE;
16145 }
16146
16147 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
16148 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
16149 (hdd_list_node_t**) &sta_info_node );
16150
16151 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16152 {
16153 if (sta_info_node->sta_id == sta_id) {
16154 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[index],
16155 &sta_info_node->node);
16156 vos_mem_free(sta_info_node);
16157 break;
16158 }
16159 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
16160 (hdd_list_node_t*)sta_info_node, (hdd_list_node_t**)&next_node);
16161 sta_info_node = next_node;
16162 }
16163 spin_unlock_bh( &pAdapter->sta_hash_lock);
16164 return status;
16165}
16166
16167/**
16168 * hdd_sta_id_find_from_mac_addr() - find sta id from mac address
16169 * @pAdapter: adapter handle
16170 * @mac_addr_in: mac address
16171 *
16172 * Return: station id
16173 */
16174int hdd_sta_id_find_from_mac_addr(hdd_adapter_t *pAdapter,
16175 v_MACADDR_t *mac_addr_in)
16176{
16177 uint8 is_found = 0;
16178 uint8 sta_id = HDD_WLAN_INVALID_STA_ID;
16179 uint16 index;
16180 VOS_STATUS status;
16181 hdd_staid_hash_node_t *sta_info_node = NULL;
16182 hdd_staid_hash_node_t *next_node = NULL;
16183
16184 spin_lock_bh( &pAdapter->sta_hash_lock);
16185 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16186 spin_unlock_bh( &pAdapter->sta_hash_lock);
Bhargav Shahce3b32c2015-08-10 12:29:24 +053016187 hddLog(VOS_TRACE_LEVEL_INFO,
Nirav Shah7e3c8132015-06-22 23:51:42 +053016188 FL("hash is not initialized for session id %d"),
16189 pAdapter->sessionId);
16190 return HDD_WLAN_INVALID_STA_ID;
16191 }
16192
16193 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr_in);
16194 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
16195 (hdd_list_node_t**) &sta_info_node );
16196
16197 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16198 {
16199 if (vos_mem_compare(&sta_info_node->mac_addr,
16200 mac_addr_in, sizeof(v_MACADDR_t))) {
16201 is_found = 1;
16202 sta_id = sta_info_node->sta_id;
16203 break;
16204 }
16205 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
16206 (hdd_list_node_t*)sta_info_node,
16207 (hdd_list_node_t**)&next_node);
16208 sta_info_node = next_node;
16209 }
16210 spin_unlock_bh( &pAdapter->sta_hash_lock);
16211 return sta_id;
16212}
16213
c_manjeecfd1efb2015-09-25 19:32:34 +053016214/*FW memory dump feature*/
16215/**
16216 * This structure hold information about the /proc file
16217 *
16218 */
16219static struct proc_dir_entry *proc_file, *proc_dir;
16220
16221/**
16222 * memdump_read() - perform read operation in memory dump proc file
16223 *
16224 * @file - handle for the proc file.
16225 * @buf - pointer to user space buffer.
16226 * @count - number of bytes to be read.
16227 * @pos - offset in the from buffer.
16228 *
16229 * This function performs read operation for the memory dump proc file.
16230 *
16231 * Return: number of bytes read on success, error code otherwise.
16232 */
16233static ssize_t memdump_read(struct file *file, char __user *buf,
16234 size_t count, loff_t *pos)
16235{
16236 int status;
16237 hdd_context_t *hdd_ctx = (hdd_context_t *)PDE_DATA(file_inode(file));
16238 size_t ret_count;
c_manjeef1495642015-10-13 18:35:01 +053016239 loff_t bytes_left;
c_manjeecfd1efb2015-09-25 19:32:34 +053016240 ENTER();
16241
16242 hddLog(LOG1, FL("Read req for size:%zu pos:%llu"), count, *pos);
16243 status = wlan_hdd_validate_context(hdd_ctx);
16244 if (0 != status) {
16245 return -EINVAL;
16246 }
16247
16248 if (!wlan_fwr_mem_dump_test_and_set_read_allowed_bit()) {
16249 hddLog(LOGE, FL("Current mem dump request timed out/failed"));
16250 return -EINVAL;
16251 }
16252
16253 /* run fs_read_handler in an atomic context*/
16254 vos_ssr_protect(__func__);
c_manjeef1495642015-10-13 18:35:01 +053016255 ret_count = wlan_fwr_mem_dump_fsread_handler( buf, count, pos, &bytes_left);
16256 if(bytes_left == 0)
c_manjeecfd1efb2015-09-25 19:32:34 +053016257 {
16258 /*Free the fwr mem dump buffer */
16259 wlan_free_fwr_mem_dump_buffer();
16260 wlan_set_fwr_mem_dump_state(FW_MEM_DUMP_IDLE);
c_manjeef1495642015-10-13 18:35:01 +053016261 ret_count=0;
c_manjeecfd1efb2015-09-25 19:32:34 +053016262 }
16263 /*if SSR/unload code is waiting for memdump_read to finish,signal it*/
16264 vos_ssr_unprotect(__func__);
16265 EXIT();
16266 return ret_count;
16267}
16268
16269/**
16270 * struct memdump_fops - file operations for memory dump feature
16271 * @read - read function for memory dump operation.
16272 *
16273 * This structure initialize the file operation handle for memory
16274 * dump feature
16275 */
16276static const struct file_operations memdump_fops = {
16277 read: memdump_read
16278};
16279
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016280struct fw_mem_dump_priv {
16281 uint32_t status;
16282};
16283
c_manjeecfd1efb2015-09-25 19:32:34 +053016284/*
16285* wlan_hdd_fw_mem_dump_cb : callback for Fw mem dump request
16286* To be passed by HDD to WDA and called upon receiving of response
16287* from firmware
16288* @fwMemDumpReqContext : memory dump request context
16289* @dump_rsp : dump response from HAL
16290* Returns none
16291*/
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016292void wlan_hdd_fw_mem_dump_cb(void *context,
c_manjeecfd1efb2015-09-25 19:32:34 +053016293 tAniFwrDumpRsp *dump_rsp)
16294{
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016295 struct hdd_request *request;
16296 struct fw_mem_dump_priv *priv;
c_manjeecfd1efb2015-09-25 19:32:34 +053016297
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016298 request = hdd_request_get(context);
16299 if (!request) {
16300 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
16301 return;
16302 }
c_manjeecfd1efb2015-09-25 19:32:34 +053016303
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016304 ENTER();
16305
16306 priv = hdd_request_priv(request);
16307 priv->status = dump_rsp->dump_status;
16308
16309 /* report the status to requesting function and free mem.*/
16310 if (dump_rsp->dump_status != eHAL_STATUS_SUCCESS) {
16311 hddLog(LOGE, FL("fw dump request declined by fwr"));
16312 //set the request completion variable
16313 hdd_request_complete(request);
16314 //Free the allocated fwr dump
16315 wlan_free_fwr_mem_dump_buffer();
16316 wlan_set_fwr_mem_dump_state(FW_MEM_DUMP_IDLE);
16317 } else {
16318 hddLog(LOG1, FL("fw dump request accepted by fwr"));
16319 /* register the HDD callback which will be called by SVC */
16320 wlan_set_svc_fw_mem_dump_req_cb(
16321 (void*)wlan_hdd_fw_mem_dump_req_cb,
16322 context);
16323 }
16324
16325 hdd_request_put(request);
16326
16327 EXIT();
c_manjeecfd1efb2015-09-25 19:32:34 +053016328}
16329
16330/**
16331 * memdump_procfs_remove() - Remove file/dir under procfs for memory dump
16332 *
16333 * This function removes file/dir under proc file system that was
16334 * processing firmware memory dump
16335 *
16336 * Return: None
16337 */
16338static void memdump_procfs_remove(void)
16339{
16340 remove_proc_entry(PROCFS_MEMDUMP_NAME, proc_dir);
16341 hddLog(LOG1 , FL("/proc/%s/%s removed\n"),
16342 PROCFS_MEMDUMP_DIR, PROCFS_MEMDUMP_NAME);
16343 remove_proc_entry(PROCFS_MEMDUMP_DIR, NULL);
16344 hddLog(LOG1 , FL("/proc/%s removed\n"), PROCFS_MEMDUMP_DIR);
16345}
16346
16347/**
16348 * memdump_procfs_init() - Initialize procfs for memory dump
16349 *
16350 * @vos_ctx - Global vos context.
16351 *
16352 * This function create file under proc file system to be used later for
16353 * processing firmware memory dump
16354 *
16355 * Return: 0 on success, error code otherwise.
16356 */
16357static int memdump_procfs_init(void *vos_ctx)
16358{
16359 hdd_context_t *hdd_ctx;
16360
16361 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
16362 if (!hdd_ctx) {
16363 hddLog(LOGE , FL("Invalid HDD context"));
16364 return -EINVAL;
16365 }
16366
16367 proc_dir = proc_mkdir(PROCFS_MEMDUMP_DIR, NULL);
16368 if (proc_dir == NULL) {
16369 remove_proc_entry(PROCFS_MEMDUMP_DIR, NULL);
16370 hddLog(LOGE , FL("Error: Could not initialize /proc/%s"),
16371 PROCFS_MEMDUMP_DIR);
16372 return -ENOMEM;
16373 }
16374
16375 proc_file = proc_create_data(PROCFS_MEMDUMP_NAME,
16376 S_IRUSR | S_IWUSR, proc_dir,
16377 &memdump_fops, hdd_ctx);
16378 if (proc_file == NULL) {
16379 remove_proc_entry(PROCFS_MEMDUMP_NAME, proc_dir);
16380 hddLog(LOGE , FL("Error: Could not initialize /proc/%s"),
16381 PROCFS_MEMDUMP_NAME);
16382 return -ENOMEM;
16383 }
16384
16385 hddLog(LOG1 , FL("/proc/%s/%s created"),
16386 PROCFS_MEMDUMP_DIR, PROCFS_MEMDUMP_NAME);
16387
16388 return 0;
16389}
16390
16391/**
16392 * memdump_init() - Initialization function for memory dump feature
16393 *
16394 * This function creates proc file for memdump feature and registers
16395 * HDD callback function with SME.
16396 *
16397 * Return - 0 on success, error otherwise
16398 */
16399int memdump_init(void)
16400{
16401 hdd_context_t *hdd_ctx;
16402 void *vos_ctx;
16403 int status = 0;
16404
16405 vos_ctx = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
16406 if (!vos_ctx) {
16407 hddLog(LOGE, FL("Invalid VOS context"));
16408 return -EINVAL;
16409 }
16410
16411 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
16412 if (!hdd_ctx) {
16413 hddLog(LOGE , FL("Invalid HDD context"));
16414 return -EINVAL;
16415 }
16416
16417 status = memdump_procfs_init(vos_ctx);
16418 if (status) {
16419 hddLog(LOGE , FL("Failed to create proc file"));
16420 return status;
16421 }
16422
16423 return 0;
16424}
16425
16426/**
16427 * memdump_deinit() - De initialize memdump feature
16428 *
16429 * This function removes proc file created for memdump feature.
16430 *
16431 * Return: None
16432 */
16433int memdump_deinit(void)
16434{
16435 hdd_context_t *hdd_ctx;
16436 void *vos_ctx;
16437
16438 vos_ctx = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
16439 if (!vos_ctx) {
16440 hddLog(LOGE, FL("Invalid VOS context"));
16441 return -EINVAL;
16442 }
16443
16444 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
16445 if(!hdd_ctx) {
16446 hddLog(LOGE , FL("Invalid HDD context"));
16447 return -EINVAL;
16448 }
16449
16450 memdump_procfs_remove();
16451 return 0;
16452}
16453
16454/**
16455 * wlan_hdd_fw_mem_dump_req(pHddCtx) - common API(cfg80211/ioctl) for requesting fw mem dump to SME
16456 * Return: HAL status
16457 */
16458
16459int wlan_hdd_fw_mem_dump_req(hdd_context_t * pHddCtx)
16460{
16461 tAniFwrDumpReq fw_mem_dump_req={0};
16462 eHalStatus status = eHAL_STATUS_FAILURE;
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016463 int ret=0, dump_status;
16464 void *cookie;
16465 struct hdd_request *request;
16466 struct fw_mem_dump_priv *priv;
16467 static const struct hdd_request_params params = {
16468 .priv_size = sizeof(*priv),
16469 .timeout_ms = FW_MEM_DUMP_TIMEOUT_MS,
16470 };
16471
c_manjeecfd1efb2015-09-25 19:32:34 +053016472 ENTER();
c_manjeef1495642015-10-13 18:35:01 +053016473
c_manjeecfd1efb2015-09-25 19:32:34 +053016474 /*Check whether a dump request is already going on
16475 *Caution this function will free previously held memory if new dump request is allowed*/
16476 if (!wlan_fwr_mem_dump_test_and_set_write_allowed_bit()) {
16477 hddLog(LOGE, FL("Fw memdump already in progress"));
16478 return -EBUSY;
16479 }
16480 //Allocate memory for fw mem dump buffer
16481 ret = wlan_fwr_mem_dump_buffer_allocation();
16482 if(ret == -EFAULT)
16483 {
16484 hddLog(LOGE, FL("Fwr mem dump not supported by FW"));
16485 return ret;
16486 }
16487 if (0 != ret) {
16488 hddLog(LOGE, FL("Fwr mem Allocation failed"));
16489 return -ENOMEM;
16490 }
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016491
16492 request = hdd_request_alloc(&params);
16493 if (!request) {
16494 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
16495 return VOS_STATUS_E_NOMEM;
16496 }
16497 cookie = hdd_request_cookie(request);
c_manjeef1495642015-10-13 18:35:01 +053016498
c_manjeecfd1efb2015-09-25 19:32:34 +053016499 fw_mem_dump_req.fwMemDumpReqCallback = wlan_hdd_fw_mem_dump_cb;
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016500 fw_mem_dump_req.fwMemDumpReqContext = cookie;
c_manjeecfd1efb2015-09-25 19:32:34 +053016501 status = sme_FwMemDumpReq(pHddCtx->hHal, &fw_mem_dump_req);
16502 if(eHAL_STATUS_SUCCESS != status)
16503 {
16504 hddLog(VOS_TRACE_LEVEL_ERROR,
16505 "%s: fw_mem_dump_req failed ", __func__);
16506 wlan_free_fwr_mem_dump_buffer();
c_manjeef1495642015-10-13 18:35:01 +053016507 ret = -EFAULT;
16508 goto cleanup;
c_manjeecfd1efb2015-09-25 19:32:34 +053016509 }
c_manjeef1495642015-10-13 18:35:01 +053016510 /*wait for fw mem dump completion to send event to userspace*/
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016511 ret = hdd_request_wait_for_response(request);
16512 if (ret)
c_manjeef1495642015-10-13 18:35:01 +053016513 {
16514 hddLog(VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016515 "%s: fw_mem_dump_req timeout %d ", __func__,ret);
Abhishek Singh4eca9822015-12-09 18:07:34 +053016516 ret = -ETIMEDOUT;
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016517 }else {
16518 priv = hdd_request_priv(request);
16519 dump_status = priv->status;
c_manjeef1495642015-10-13 18:35:01 +053016520 }
16521cleanup:
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016522 hdd_request_put(request);
16523 if(!ret && !dump_status)
Abhishek Singh4eca9822015-12-09 18:07:34 +053016524 ret = -EFAULT;
c_manjeecfd1efb2015-09-25 19:32:34 +053016525
c_manjeef1495642015-10-13 18:35:01 +053016526 EXIT();
Abhishek Singh4eca9822015-12-09 18:07:34 +053016527 return ret;
c_manjeef1495642015-10-13 18:35:01 +053016528}
16529
16530/**
16531 * HDD callback which will be called by SVC to indicate mem dump completion.
16532 */
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016533void wlan_hdd_fw_mem_dump_req_cb(void *context)
c_manjeef1495642015-10-13 18:35:01 +053016534{
Hanumanth Reddy Pothulae856bc22018-04-11 15:35:36 +053016535 struct hdd_request *request;
16536 struct fw_mem_dump_priv *priv;
16537
16538 request = hdd_request_get(context);
16539 if (!request) {
16540 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
16541 return;
16542 }
16543
16544 priv = hdd_request_priv(request);
16545 priv->status = true;
16546
16547 hdd_request_complete(request);
16548 hdd_request_put(request);
c_manjeecfd1efb2015-09-25 19:32:34 +053016549}
16550
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053016551void hdd_initialize_adapter_common(hdd_adapter_t *pAdapter)
16552{
16553 if (NULL == pAdapter)
16554 {
16555 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL ", __func__);
16556 return;
16557 }
16558 init_completion(&pAdapter->session_open_comp_var);
16559 init_completion(&pAdapter->session_close_comp_var);
16560 init_completion(&pAdapter->disconnect_comp_var);
16561 init_completion(&pAdapter->linkup_event_var);
16562 init_completion(&pAdapter->cancel_rem_on_chan_var);
16563 init_completion(&pAdapter->rem_on_chan_ready_event);
16564 init_completion(&pAdapter->pno_comp_var);
16565#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
16566 init_completion(&pAdapter->offchannel_tx_event);
16567#endif
16568 init_completion(&pAdapter->tx_action_cnf_event);
16569#ifdef FEATURE_WLAN_TDLS
16570 init_completion(&pAdapter->tdls_add_station_comp);
16571 init_completion(&pAdapter->tdls_del_station_comp);
16572 init_completion(&pAdapter->tdls_mgmt_comp);
16573 init_completion(&pAdapter->tdls_link_establish_req_comp);
16574#endif
16575
16576#ifdef WLAN_FEATURE_RMC
16577 init_completion(&pAdapter->ibss_peer_info_comp);
16578#endif /* WLAN_FEATURE_RMC */
16579 init_completion(&pAdapter->ula_complete);
16580 init_completion(&pAdapter->change_country_code);
16581
16582#ifdef FEATURE_WLAN_BATCH_SCAN
16583 init_completion(&pAdapter->hdd_set_batch_scan_req_var);
16584 init_completion(&pAdapter->hdd_get_batch_scan_req_var);
16585#endif
Kapil Gupta2b44acb2016-12-30 16:49:51 +053016586 init_completion(&pAdapter->wlan_suspend_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053016587
16588 return;
16589}
c_manjeecfd1efb2015-09-25 19:32:34 +053016590
Anurag Chouhan0b29de02016-12-16 13:18:40 +053016591#ifdef MDNS_OFFLOAD
16592
16593/**
16594 * hdd_mdns_enable_offload_done() - mdns enable offload response api
16595 * @padapter: holds adapter
16596 * @status: response status
16597 *
16598 * Return - None
16599 */
16600void hdd_mdns_enable_offload_done(void *padapter, VOS_STATUS status)
16601{
16602 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16603
16604 ENTER();
16605
16606 if (NULL == adapter)
16607 {
16608 hddLog(VOS_TRACE_LEVEL_ERROR,
16609 "%s: adapter is NULL",__func__);
16610 return;
16611 }
16612
16613 adapter->mdns_status.mdns_enable_status = status;
16614 vos_event_set(&adapter->mdns_status.vos_event);
16615 return;
16616}
16617
16618/**
16619 * hdd_mdns_fqdn_offload_done() - mdns fqdn offload response api
16620 * @padapter: holds adapter
16621 * @status: responce status
16622 *
16623 * Return - None
16624 */
16625void hdd_mdns_fqdn_offload_done(void *padapter, VOS_STATUS status)
16626{
16627 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16628
16629 ENTER();
16630
16631 if (NULL == adapter)
16632 {
16633 hddLog(VOS_TRACE_LEVEL_ERROR,
16634 "%s: adapter is NULL",__func__);
16635 return;
16636 }
16637
16638 adapter->mdns_status.mdns_fqdn_status = status;
16639 return;
16640}
16641
16642/**
16643 * hdd_mdns_resp_offload_done() - mdns resp offload response api
16644 * @padapter: holds adapter
16645 * @status: responce status
16646 *
16647 * Return - None
16648 */
16649void hdd_mdns_resp_offload_done(void *padapter, VOS_STATUS status)
16650{
16651 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16652
16653 ENTER();
16654
16655 if (NULL == adapter)
16656 {
16657 hddLog(VOS_TRACE_LEVEL_ERROR,
16658 "%s: adapter is NULL",__func__);
16659 return;
16660 }
16661
16662 adapter->mdns_status.mdns_resp_status = status;
16663 return;
16664}
16665
16666/**
16667 * wlan_hdd_mdns_process_response_dname() - Process mDNS domain name
16668 * @response: Pointer to a struct hdd_mdns_resp_info
16669 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16670 *
16671 * This function will pack the whole domain name without compression. It will
16672 * add the leading len for each field and add zero length octet to terminate
16673 * the domain name.
16674 *
16675 * Return: Return boolean. TRUE for success, FALSE for fail.
16676 */
16677static bool
16678wlan_hdd_mdns_process_response_dname(struct hdd_mdns_resp_info *response,
16679 sir_mdns_resp_info resp_info)
16680{
16681 uint8_t num;
16682 uint16_t idx;
16683 uint8_t len = 0;
16684
16685 if ((response == NULL) || (response->data == NULL) ||
16686 (response->offset == NULL)) {
16687 hddLog(LOGE, FL("Either data or offset in response is NULL!"));
16688 return FALSE;
16689 }
16690
16691 if ((resp_info == NULL) ||
16692 (resp_info->resp_len >= MAX_MDNS_RESP_LEN)) {
16693 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16694 return FALSE;
16695 }
16696
16697 for (num = 0; num < response->num_entries; num++) {
16698 response->offset[num] =
16699 resp_info->resp_len + MDNS_HEADER_LEN;
16700 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16701 len = strlen((char *)&response->data[idx]);
16702 if ((resp_info->resp_len + len + 1) >= MAX_MDNS_RESP_LEN) {
16703 hddLog(LOGE, FL("resp_len exceeds %d!"),
16704 MAX_MDNS_RESP_LEN);
16705 return FALSE;
16706 }
16707 resp_info->resp_data[resp_info->resp_len] = len;
16708 resp_info->resp_len++;
16709 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16710 &response->data[idx], len);
16711 resp_info->resp_len += len;
16712 }
16713
16714 /* The domain name terminates with the zero length octet */
16715 if (num == response->num_entries) {
16716 if (resp_info->resp_len >= MAX_MDNS_RESP_LEN) {
16717 hddLog(LOGE, FL("resp_len exceeds %d!"),
16718 MAX_MDNS_RESP_LEN);
16719 return FALSE;
16720 }
16721 resp_info->resp_data[resp_info->resp_len] = 0;
16722 resp_info->resp_len++;
16723 }
16724
16725 return TRUE;
16726}
16727
16728/**
16729 * wlan_hdd_mdns_format_response_u16() - Form uint16_t response data
16730 * @value: The uint16_t value is formed to the struct tSirMDNSResponseInfo
16731 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16732 *
16733 * Return: None
16734 */
16735static void wlan_hdd_mdns_format_response_u16(uint16_t value,
16736 sir_mdns_resp_info resp_info)
16737{
16738 uint8_t val_u8;
16739
16740 if ((resp_info == NULL) || (resp_info->resp_data == NULL))
16741 return;
16742 val_u8 = (value & 0xff00) >> 8;
16743 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16744 val_u8 = value & 0xff;
16745 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16746}
16747
16748/**
16749 * wlan_hdd_mdns_format_response_u32() - Form uint32_t response data
16750 * @value: The uint32_t value is formed to the struct tSirMDNSResponseInfo
16751 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16752 *
16753 * Return: None
16754 */
16755static void wlan_hdd_mdns_format_response_u32(uint32_t value,
16756 sir_mdns_resp_info resp_info)
16757{
16758 uint8_t val_u8;
16759
16760 if ((resp_info == NULL) || (resp_info->resp_data == NULL))
16761 return;
16762 val_u8 = (value & 0xff000000) >> 24;
16763 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16764 val_u8 = (value & 0xff0000) >> 16;
16765 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16766 val_u8 = (value & 0xff00) >> 8;
16767 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16768 val_u8 = value & 0xff;
16769 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16770}
16771
16772/**
16773 * wlan_hdd_mdns_process_response_misc() - Process misc info in mDNS response
16774 * @resp_type: Response type for mDNS
16775 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16776 *
16777 * This function will pack the response type, class and TTL (Time To Live).
16778 *
16779 * Return: Return boolean. TRUE for success, FALSE for fail.
16780 */
16781static bool wlan_hdd_mdns_process_response_misc(uint16_t resp_type,
16782 sir_mdns_resp_info resp_info)
16783{
16784 uint16_t len;
16785
16786 if (resp_info == NULL) {
16787 hddLog(LOGE, FL("resp_info is NULL!"));
16788 return FALSE;
16789 }
16790
16791 len = resp_info->resp_len + (2 * sizeof(uint16_t) + sizeof(uint32_t));
16792 if (len >= MAX_MDNS_RESP_LEN) {
16793 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16794 return FALSE;
16795 }
16796
16797 /* Fill Type, Class, TTL */
16798 wlan_hdd_mdns_format_response_u16(resp_type, resp_info);
16799 wlan_hdd_mdns_format_response_u16(MDNS_CLASS, resp_info);
16800 wlan_hdd_mdns_format_response_u32(MDNS_TTL, resp_info);
16801
16802 return TRUE;
16803}
16804
16805/**
16806 * wlan_hdd_mdns_compress_data() - Compress the domain name in mDNS response
16807 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16808 * @response_dst: The response which domain name is compressed.
16809 * @response_src: The response which domain name is matched with response_dst.
16810 * Its offset is used for data compression.
16811 * @num_matched: The number of matched entries between response_dst and
16812 * response_src
16813 *
16814 * This function will form the different fields of domain name in response_dst
16815 * if any. Then use the offset of the matched domain name in response_src to
16816 * compress the matched domain name.
16817 *
16818 * Return: Return boolean. TRUE for success, FALSE for fail.
16819 */
16820static bool
16821wlan_hdd_mdns_compress_data(sir_mdns_resp_info resp_info,
16822 struct hdd_mdns_resp_info *response_dst,
16823 struct hdd_mdns_resp_info *response_src,
16824 uint8_t num_matched)
16825{
16826 uint8_t num, num_diff;
16827 uint16_t value, idx;
16828 uint8_t len = 0;
16829
16830 if ((response_src == NULL) || (response_dst == NULL) ||
16831 (resp_info == NULL)) {
16832 hddLog(LOGE, FL("response info is NULL!"));
16833 return FALSE;
16834 }
16835
16836 if (response_dst->num_entries < num_matched) {
16837 hddLog(LOGE, FL("num_entries is less than num_matched!"));
16838 return FALSE;
16839 }
16840
16841 if (resp_info->resp_len >= MAX_MDNS_RESP_LEN) {
16842 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16843 return FALSE;
16844 }
16845
16846 num_diff = response_dst->num_entries - num_matched;
16847 if ((num_diff > 0) && (response_dst->data == NULL)) {
16848 hddLog(LOGE, FL("response_dst->data is NULL!"));
16849 return FALSE;
16850 }
16851
16852 /*
16853 * Handle the unmatched string at the beginning
16854 * Store the length of octets and the octets
16855 */
16856 for (num = 0; num < num_diff; num++) {
16857 response_dst->offset[num] =
16858 resp_info->resp_len + MDNS_HEADER_LEN;
16859 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16860 len = strlen((char *)&response_dst->data[idx]);
16861 if ((resp_info->resp_len + len + 1) >= MAX_MDNS_RESP_LEN) {
16862 hddLog(LOGE, FL("resp_len exceeds %d!"),
16863 MAX_MDNS_RESP_LEN);
16864 return FALSE;
16865 }
16866 resp_info->resp_data[resp_info->resp_len] = len;
16867 resp_info->resp_len++;
16868 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16869 &response_dst->data[idx], len);
16870 resp_info->resp_len += len;
16871 }
16872 /*
16873 * Handle the matched string from the end
16874 * Just keep the offset and mask the leading two bit
16875 */
16876 if (response_src->num_entries >= num_matched) {
16877 num_diff = response_src->num_entries - num_matched;
16878 value = response_src->offset[num_diff];
16879 if (value > 0) {
16880 value |= 0xc000;
16881 if ((resp_info->resp_len + sizeof(uint16_t)) >=
16882 MAX_MDNS_RESP_LEN) {
16883 hddLog(LOGE, FL("resp_len exceeds %d!"),
16884 MAX_MDNS_RESP_LEN);
16885 return FALSE;
16886 }
16887 wlan_hdd_mdns_format_response_u16(value, resp_info);
16888 return TRUE;
16889 }
16890 }
16891 return FALSE;
16892}
16893
16894/**
16895 * wlan_hdd_mdns_reset_response() - Reset the response info
16896 * @response: The response which info is reset.
16897 *
16898 * Return: None
16899 */
16900static void wlan_hdd_mdns_reset_response(struct hdd_mdns_resp_info *response)
16901{
16902 if (response == NULL)
16903 return;
16904 response->num_entries = 0;
16905 response->data = NULL;
16906 response->offset = NULL;
16907}
16908
16909/**
16910 * wlan_hdd_mdns_init_response() - Initialize the response info
16911 * @response: The response which info is initiatized.
16912 * @resp_dname: The domain name string which might be tokenized.
16913 *
16914 * This function will allocate the memory for both response->data and
16915 * response->offset. Besides, it will also tokenize the domain name to some
16916 * entries and fill response->num_entries with the num of entries.
16917 *
16918 * Return: Return boolean. TRUE for success, FALSE for fail.
16919 */
16920static bool wlan_hdd_mdns_init_response(struct hdd_mdns_resp_info *response,
16921 uint8_t *resp_dname, char separator)
16922{
16923 uint16_t size;
16924
16925 if ((resp_dname == NULL) || (response == NULL)) {
16926 hddLog(LOGE, FL("resp_dname or response is NULL!"));
16927 return FALSE;
16928 }
16929
16930 size = MAX_NUM_FIELD_DOMAINNAME * MAX_LEN_DOMAINNAME_FIELD;
16931 response->data = vos_mem_malloc(size);
16932 if (response->data) {
16933 vos_mem_zero(response->data, size);
16934 if (VOS_STATUS_SUCCESS !=
16935 hdd_string_to_string_array((char *)resp_dname,
16936 response->data,
16937 separator,
16938 &response->num_entries,
16939 MAX_NUM_FIELD_DOMAINNAME,
16940 MAX_LEN_DOMAINNAME_FIELD)) {
16941 hddLog(LOGE, FL("hdd_string_to_string_array fail!"));
16942 goto err_init_resp;
16943 }
16944
16945 if ((response->num_entries > 0) &&
16946 (strlen((char *)&response->data[0]) > 0)) {
16947 size = sizeof(uint16_t) * response->num_entries;
16948 response->offset = vos_mem_malloc(size);
16949 if (response->offset) {
16950 vos_mem_zero(response->offset, size);
16951 return TRUE;
16952 }
16953 }
16954 }
16955
16956err_init_resp:
16957 if (response->data)
16958 vos_mem_free(response->data);
16959 wlan_hdd_mdns_reset_response(response);
16960 return FALSE;
16961}
16962
16963/**
16964 * wlan_hdd_mdns_find_entries_from_end() - Find the matched entries
16965 * @response1: The response info is used to be compared.
16966 * @response2: The response info is used to be compared.
16967 *
16968 * This function will find the matched entries from the end.
16969 *
16970 * Return: Return the number of the matched entries.
16971 */
16972static uint8_t
16973wlan_hdd_mdns_find_entries_from_end(struct hdd_mdns_resp_info *response1,
16974 struct hdd_mdns_resp_info *response2)
16975{
16976 uint8_t min, len1, i;
16977 uint16_t num1, num2;
16978 uint8_t num_matched = 0;
16979
16980 min = VOS_MIN(response1->num_entries, response2->num_entries);
16981
16982 for (i = 1; i <= min; i++) {
16983 num1 = (response1->num_entries - i);
16984 num1 *= MAX_LEN_DOMAINNAME_FIELD;
16985 num2 = (response2->num_entries - i);
16986 num2 *= MAX_LEN_DOMAINNAME_FIELD;
16987 len1 = strlen((char *)&response1->data[num1]);
16988
16989 if ((len1 == 0) ||
16990 (len1 != strlen((char *)&response2->data[num2])))
16991 break;
16992 if (memcmp(&response1->data[num1],
16993 &response2->data[num2], len1))
16994 break;
16995 else
16996 num_matched++;
16997 }
16998
16999 return num_matched;
17000}
17001
17002/**
17003 * wlan_hdd_mdns_find_max() - Find the maximum number of the matched entries
17004 * @matchedlist: Pointer to the array of struct hdd_mdns_resp_matched
17005 * @numlist: The number of the elements in the array matchedlist.
17006 *
17007 * Find the max number of the matched entries among the array matchedlist.
17008 *
17009 * Return: None
17010 */
17011static void wlan_hdd_mdns_find_max(struct hdd_mdns_resp_matched *matchedlist,
17012 uint8_t numlist)
17013{
17014 int j;
17015 struct hdd_mdns_resp_matched tmp;
17016
17017 /* At least two values are used for sorting */
17018 if ((numlist < 2) || (matchedlist == NULL)) {
17019 hddLog(LOGE, FL("At least two values are used for sorting!"));
17020 return;
17021 }
17022
17023 for (j = 0; j < numlist-1; j++) {
17024 if (matchedlist[j].num_matched >
17025 matchedlist[j+1].num_matched) {
17026 vos_mem_copy(&tmp, &matchedlist[j],
17027 sizeof(struct hdd_mdns_resp_matched));
17028 vos_mem_copy(&matchedlist[j], &matchedlist[j+1],
17029 sizeof(struct hdd_mdns_resp_matched));
17030 vos_mem_copy(&matchedlist[j+1], &tmp,
17031 sizeof(struct hdd_mdns_resp_matched));
17032 }
17033 }
17034}
17035
17036/**
17037 * wlan_hdd_mdns_pack_response_type_a() - Pack Type A response
17038 * @ini_config: Pointer to the struct hdd_config_t
17039 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17040 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17041 *
17042 * Type A response include QName, response type, class, TTL and Ipv4.
17043 *
17044 * Return: Return boolean. TRUE for success, FALSE for fail.
17045 */
17046static bool
17047wlan_hdd_mdns_pack_response_type_a(hdd_config_t *ini_config,
17048 sir_mdns_resp_info resp_info,
17049 struct hdd_mdns_resp_info *resptype_a)
17050{
17051 uint16_t value;
17052 uint32_t len;
17053
17054 ENTER();
17055 if ((ini_config == NULL) || (resp_info == NULL) ||
17056 (resptype_a == NULL)) {
17057 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17058 return FALSE;
17059 }
17060
17061 /* No Type A response */
17062 if (strlen((char *)ini_config->mdns_resp_type_a) <= 0)
17063 return TRUE;
17064
17065 /* Wrong response is assigned, just ignore this response */
17066 if (!wlan_hdd_mdns_init_response(resptype_a,
17067 ini_config->mdns_resp_type_a, '.'))
17068 return TRUE;
17069
17070 /* Process response domain name */
17071 if (!wlan_hdd_mdns_process_response_dname(resptype_a, resp_info)) {
17072 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17073 MDNS_TYPE_A);
17074 return FALSE;
17075 }
17076
17077 /* Process response Type, Class, TTL */
17078 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_A, resp_info)) {
17079 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17080 MDNS_TYPE_A);
17081 return FALSE;
17082 }
17083
17084 /* Process response RDLength, RData */
17085 len = sizeof(uint16_t) + sizeof(uint32_t);
17086 len += resp_info->resp_len;
17087 if (len >= MAX_MDNS_RESP_LEN) {
17088 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
17089 return FALSE;
17090 }
17091 value = sizeof(uint32_t);
17092 wlan_hdd_mdns_format_response_u16(value, resp_info);
17093 wlan_hdd_mdns_format_response_u32(ini_config->mdns_resp_type_a_ipv4,
17094 resp_info);
17095
17096 EXIT();
17097 return TRUE;
17098}
17099
17100/**
17101 * wlan_hdd_mdns_pack_response_type_txt() - Pack Type Txt response
17102 * @ini_config: Pointer to the struct hdd_config_t
17103 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17104 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type txt
17105 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17106 *
17107 * Type Txt response include QName, response type, class, TTL and text content.
17108 * Also, it will find the matched QName from resptype_A and compress the data.
17109 *
17110 * Return: Return boolean. TRUE for success, FALSE for fail.
17111 */
17112static bool
17113wlan_hdd_mdns_pack_response_type_txt(hdd_config_t *ini_config,
17114 sir_mdns_resp_info resp_info,
17115 struct hdd_mdns_resp_info *resptype_txt,
17116 struct hdd_mdns_resp_info *resptype_a)
17117{
17118 uint8_t num_matched;
17119 uint8_t num;
17120 uint16_t idx;
17121 uint16_t value = 0;
17122 uint32_t len;
17123 uint32_t total_len;
17124 bool status;
17125 struct hdd_mdns_resp_info resptype_content;
17126
17127 ENTER();
17128
17129 if ((ini_config == NULL) || (resp_info == NULL) ||
17130 (resptype_txt == NULL)) {
17131 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17132 return FALSE;
17133 }
17134
17135 /* No Type Txt response */
17136 if (strlen((char *)ini_config->mdns_resp_type_txt) <= 0)
17137 return TRUE;
17138
17139 /* Wrong response is assigned, just ignore this response */
17140 if (!wlan_hdd_mdns_init_response(resptype_txt,
17141 ini_config->mdns_resp_type_txt, '.'))
17142 return TRUE;
17143
17144 /*
17145 * For data compression
17146 * Check if any strings are matched with Type A response
17147 */
17148 if (resptype_a && (resptype_a->num_entries > 0)) {
17149 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_txt,
17150 resptype_a);
17151 if (num_matched > 0) {
17152 if (!wlan_hdd_mdns_compress_data(resp_info,
17153 resptype_txt, resptype_a, num_matched)) {
17154 hddLog(LOGE, FL("Fail to compress mDNS "
17155 "response (%d)!"), MDNS_TYPE_TXT);
17156 return FALSE;
17157 }
17158 } else {
17159 /*
17160 * num_matched is zero. Error!
17161 * At least ".local" is needed.
17162 */
17163 hddLog(LOGE, FL("No matched string! Fail to pack mDNS "
17164 "response (%d)!"), MDNS_TYPE_TXT);
17165 return FALSE;
17166 }
17167 } else {
17168 /* no TypeA response, so show the whole data */
17169 if (!wlan_hdd_mdns_process_response_dname(resptype_txt,
17170 resp_info)) {
17171 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17172 MDNS_TYPE_TXT);
17173 return FALSE;
17174 }
17175 }
17176
17177 /* Process response Type, Class, TTL */
17178 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_TXT, resp_info)) {
17179 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17180 MDNS_TYPE_TXT);
17181 return FALSE;
17182 }
17183
17184 /*
17185 * Process response RDLength, RData.
17186 * TypeTxt RData include len.
17187 */
17188 status = wlan_hdd_mdns_init_response(&resptype_content,
17189 ini_config->mdns_resp_type_txt_content,
17190 '/');
17191 if (status == FALSE) {
17192 hddLog(LOGE, FL("wlan_hdd_mdns_init_response FAIL"));
17193 return FALSE;
17194 }
17195
17196 for (num = 0; num < resptype_content.num_entries; num++) {
17197 idx = num * MAX_LEN_DOMAINNAME_FIELD;
17198 value += strlen((char *)&resptype_content.data[idx]);
17199 }
17200
17201 /* content len is uint16_t */
17202 total_len = sizeof(uint16_t);
17203 total_len += resp_info->resp_len + value +
17204 resptype_content.num_entries;
17205
17206 if (total_len >= MAX_MDNS_RESP_LEN) {
17207 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
17208 return FALSE;
17209 }
17210 wlan_hdd_mdns_format_response_u16(value + resptype_content.num_entries,
17211 resp_info);
17212
17213 for (num = 0; num < resptype_content.num_entries; num++) {
17214 idx = num * MAX_LEN_DOMAINNAME_FIELD;
17215 len = strlen((char *)&resptype_content.data[idx]);
17216 resp_info->resp_data[resp_info->resp_len] = len;
17217 resp_info->resp_len++;
17218
17219 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
17220 &resptype_content.data[idx], len);
17221
17222 resp_info->resp_len += len;
17223 hddLog(LOG1, FL("index = %d, len = %d, str = %s"),
17224 num, len, &resptype_content.data[idx]);
17225 }
17226
17227 EXIT();
17228 return TRUE;
17229}
17230
17231/**
17232 * wlan_hdd_mdns_pack_response_type_ptr_dname() - Pack Type PTR domain name
17233 * @ini_config: Pointer to the struct hdd_config_t
17234 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17235 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17236 * domain name
17237 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17238 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17239 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17240 *
17241 * The Type Ptr response include Type PTR domain name in its data field.
17242 * Also, it will find the matched QName from the existing resptype_ptr,
17243 * resptype_txt, resptype_a and then compress the data.
17244 *
17245 * Return: Return boolean. TRUE for success, FALSE for fail.
17246 */
17247static bool
17248wlan_hdd_mdns_pack_response_type_ptr_dname(hdd_config_t *ini_config,
17249 sir_mdns_resp_info resp_info,
17250 struct hdd_mdns_resp_info *resptype_ptr_dn,
17251 struct hdd_mdns_resp_info *resptype_ptr,
17252 struct hdd_mdns_resp_info *resptype_txt,
17253 struct hdd_mdns_resp_info *resptype_a)
17254{
17255 uint8_t num_matched, numlist, size;
17256 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17257 struct hdd_mdns_resp_info *resp;
17258
17259 if ((ini_config == NULL) || (resp_info == NULL) ||
17260 (resptype_ptr == NULL) || (resptype_ptr_dn == NULL)) {
17261 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17262 return FALSE;
17263 }
17264
17265 /* No Type Ptr domain name response */
17266 if (strlen((char *)ini_config->mdns_resp_type_ptr_dname) <= 0)
17267 return TRUE;
17268
17269 /* Wrong response is assigned, just ignore this response */
17270 if (!wlan_hdd_mdns_init_response(resptype_ptr_dn,
17271 ini_config->mdns_resp_type_ptr_dname, '.'))
17272 return TRUE;
17273
17274 /*
17275 * For data compression
17276 * Check if any strings are matched with previous
17277 * response.
17278 */
17279 numlist = 0;
17280 size = (MAX_MDNS_RESP_TYPE-1);
17281 size *= sizeof(struct hdd_mdns_resp_matched);
17282 vos_mem_zero(matchedlist, size);
17283 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_ptr_dn,
17284 resptype_ptr);
17285 if (num_matched > 0) {
17286 matchedlist[numlist].num_matched = num_matched;
17287 matchedlist[numlist].type = MDNS_TYPE_PTR;
17288 numlist++;
17289 }
17290 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17291 num_matched = wlan_hdd_mdns_find_entries_from_end(
17292 resptype_ptr_dn, resptype_txt);
17293 if (num_matched > 0) {
17294 matchedlist[numlist].num_matched = num_matched;
17295 matchedlist[numlist].type = MDNS_TYPE_TXT;
17296 numlist++;
17297 }
17298 }
17299 if (resptype_a && (resptype_a->num_entries > 0)) {
17300 num_matched = wlan_hdd_mdns_find_entries_from_end(
17301 resptype_ptr_dn,resptype_a);
17302 if (num_matched > 0) {
17303 matchedlist[numlist].num_matched = num_matched;
17304 matchedlist[numlist].type = MDNS_TYPE_A;
17305 numlist++;
17306 }
17307 }
17308 if (numlist > 0) {
17309 if (numlist > 1)
17310 wlan_hdd_mdns_find_max(matchedlist, numlist);
17311 resp = NULL;
17312 switch (matchedlist[numlist-1].type) {
17313 case MDNS_TYPE_A:
17314 resp = resptype_a;
17315 break;
17316 case MDNS_TYPE_TXT:
17317 resp = resptype_txt;
17318 break;
17319 case MDNS_TYPE_PTR:
17320 resp = resptype_ptr;
17321 break;
17322 default:
17323 hddLog(LOGE, FL("Fail to compress mDNS response "
17324 "(%d)!"), MDNS_TYPE_PTR_DNAME);
17325 return FALSE;
17326 }
17327 num_matched = matchedlist[numlist-1].num_matched;
17328 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_ptr_dn,
17329 resp, num_matched)) {
17330 hddLog(LOGE, FL("Fail to compress mDNS response "
17331 "(%d)!"), MDNS_TYPE_PTR_DNAME);
17332 return FALSE;
17333 }
17334 } else {
17335 /* num = 0 -> no matched string */
17336 if (!wlan_hdd_mdns_process_response_dname(resptype_ptr_dn,
17337 resp_info)) {
17338 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17339 MDNS_TYPE_PTR_DNAME);
17340 return FALSE;
17341 }
17342 }
17343
17344 return TRUE;
17345}
17346
17347/**
17348 * wlan_hdd_mdns_pack_response_type_ptr() - Pack Type PTR response
17349 * @ini_config: Pointer to the struct hdd_config_t
17350 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17351 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17352 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17353 * domain name
17354 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17355 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17356 *
17357 * The Type Ptr response include QName, response type, class, TTL and
17358 * Type PTR domain name. Also, it will find the matched QName from the
17359 * existing resptype_txt, resptype_a and then compress the data.
17360 *
17361 * Return: Return boolean. TRUE for success, FALSE for fail.
17362 */
17363static bool
17364wlan_hdd_mdns_pack_response_type_ptr(hdd_config_t *ini_config,
17365 sir_mdns_resp_info resp_info,
17366 struct hdd_mdns_resp_info *resptype_ptr,
17367 struct hdd_mdns_resp_info *resptype_ptr_dn,
17368 struct hdd_mdns_resp_info *resptype_txt,
17369 struct hdd_mdns_resp_info *resptype_a)
17370{
17371 uint8_t num_matched, num_matched1;
17372 uint16_t value;
17373 uint8_t val_u8;
17374 uint32_t offset_data_len, len;
17375
17376 ENTER();
17377 if ((ini_config == NULL) || (resp_info == NULL) ||
17378 (resptype_ptr == NULL) || (resptype_ptr_dn == NULL)) {
17379 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17380 return FALSE;
17381 }
17382
17383 /* No Type Ptr response */
17384 if (strlen((char *)ini_config->mdns_resp_type_ptr) <= 0)
17385 return TRUE;
17386
17387 /* Wrong response is assigned, just ignore this response */
17388 if (!wlan_hdd_mdns_init_response(resptype_ptr,
17389 ini_config->mdns_resp_type_ptr, '.'))
17390 return TRUE;
17391
17392 /*
17393 * For data compression
17394 * Check if any strings are matched with Type A response
17395 */
17396 num_matched = 0;
17397 num_matched1 = 0;
17398 if (resptype_a && (resptype_a->num_entries > 0)) {
17399 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_ptr,
17400 resptype_a);
17401 }
17402 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17403 num_matched1 = wlan_hdd_mdns_find_entries_from_end(
17404 resptype_ptr, resptype_txt);
17405 }
17406 if ((num_matched != num_matched1) ||
17407 ((num_matched > 0) && (num_matched1 > 0))) {
17408 if (num_matched >= num_matched1) {
17409 if (!wlan_hdd_mdns_compress_data(resp_info,
17410 resptype_ptr, resptype_a, num_matched)) {
17411 hddLog(LOGE, FL("Fail to compress mDNS "
17412 "response (%d)!"), MDNS_TYPE_PTR);
17413 return FALSE;
17414 }
17415 } else {
17416 /* num_matched is less than num_matched1 */
17417 if (!wlan_hdd_mdns_compress_data(resp_info,
17418 resptype_ptr, resptype_txt, num_matched1)) {
17419 hddLog(LOGE, FL("Fail to compress mDNS "
17420 "response (%d)!"), MDNS_TYPE_PTR);
17421 return FALSE;
17422 }
17423 }
17424 } else {
17425 /*
17426 * Both num_matched and num_matched1 are zero.
17427 * no TypeA & TypeTxt
17428 */
17429 if (!wlan_hdd_mdns_process_response_dname(resptype_ptr,
17430 resp_info)) {
17431 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17432 MDNS_TYPE_PTR);
17433 return FALSE;
17434 }
17435 }
17436
17437 /* Process response Type, Class, TTL */
17438 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_PTR, resp_info)) {
17439 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17440 MDNS_TYPE_PTR);
17441 return FALSE;
17442 }
17443
17444 /*
17445 * Process response RDLength, RData (Ptr domain name)
17446 * Save the offset of RData length
17447 */
17448 offset_data_len = resp_info->resp_len;
17449 resp_info->resp_len += sizeof(uint16_t);
17450
17451 if (!wlan_hdd_mdns_pack_response_type_ptr_dname(ini_config, resp_info,
17452 resptype_ptr_dn, resptype_ptr,
17453 resptype_txt, resptype_a)) {
17454 return FALSE;
17455 }
17456 /* Set the RData length */
17457 len = offset_data_len + sizeof(uint16_t);
17458 if ((resptype_ptr_dn->num_entries > 0) &&
17459 (resp_info->resp_len > len)) {
17460 value = resp_info->resp_len - len;
17461 val_u8 = (value & 0xff00) >> 8;
17462 resp_info->resp_data[offset_data_len] = val_u8;
17463 val_u8 = value & 0xff;
17464 resp_info->resp_data[offset_data_len+1] = val_u8;
17465 } else {
17466 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17467 MDNS_TYPE_PTR);
17468 return FALSE;
17469 }
17470
17471 EXIT();
17472 return TRUE;
17473}
17474
17475/**
17476 * wlan_hdd_mdns_pack_response_type_srv_target()- Pack Type Service Target
17477 * @ini_config: Pointer to the struct hdd_config_t
17478 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17479 * @resptype_srv_tgt: Pointer to the struct hdd_mdns_resp_info of Type Srv
17480 * target
17481 * @resptype_srv: Pointer to the struct hdd_mdns_resp_info of Type Srv
17482 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17483 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17484 * domain name
17485 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17486 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17487 *
17488 * The Type service target is one of the data field in the Type SRV response.
17489 * Also, it will find the matched QName from the existing resptype_srv,
17490 * resptype_ptr, resptype_ptr_dn, resptype_txt, resptype_a and then compress
17491 * the data.
17492 *
17493 * Return: Return boolean. TRUE for success, FALSE for fail.
17494 */
17495static bool
17496wlan_hdd_mdns_pack_response_type_srv_target(hdd_config_t *ini_config,
17497 sir_mdns_resp_info resp_info,
17498 struct hdd_mdns_resp_info *resptype_srv_tgt,
17499 struct hdd_mdns_resp_info *resptype_srv,
17500 struct hdd_mdns_resp_info *resptype_ptr,
17501 struct hdd_mdns_resp_info *resptype_ptr_dn,
17502 struct hdd_mdns_resp_info *resptype_txt,
17503 struct hdd_mdns_resp_info *resptype_a)
17504{
17505 uint8_t num_matched, num, size;
17506 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17507 struct hdd_mdns_resp_info *resp;
17508
17509 if ((ini_config == NULL) || (resp_info == NULL) ||
17510 (resptype_srv == NULL) || (resptype_srv_tgt == NULL)) {
17511 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17512 return FALSE;
17513 }
17514
17515 /* No Type Srv Target response */
17516 if (strlen((char *)ini_config->mdns_resp_type_srv_target) <= 0)
17517 return TRUE;
17518
17519 /* Wrong response is assigned, just ignore this response */
17520 if (!wlan_hdd_mdns_init_response(resptype_srv_tgt,
17521 ini_config->mdns_resp_type_srv_target, '.'))
17522 return TRUE;
17523
17524 /*
17525 * For data compression
17526 * Check if any strings are matched with previous response.
17527 */
17528 num = 0;
17529 size = (MAX_MDNS_RESP_TYPE-1);
17530 size *= sizeof(struct hdd_mdns_resp_matched);
17531 vos_mem_zero(matchedlist, size);
17532 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv_tgt,
17533 resptype_srv);
17534 if (num_matched > 0) {
17535 matchedlist[num].num_matched = num_matched;
17536 matchedlist[num].type = MDNS_TYPE_SRV;
17537 num++;
17538 }
17539 if (resptype_ptr && (resptype_ptr->num_entries > 0)) {
17540 if (resptype_ptr_dn && (resptype_ptr_dn->num_entries > 0)) {
17541 num_matched = wlan_hdd_mdns_find_entries_from_end(
17542 resptype_srv_tgt, resptype_ptr_dn);
17543 if (num_matched > 0) {
17544 matchedlist[num].num_matched = num_matched;
17545 matchedlist[num].type = MDNS_TYPE_PTR_DNAME;
17546 num++;
17547 }
17548 }
17549 num_matched = wlan_hdd_mdns_find_entries_from_end(
17550 resptype_srv_tgt, resptype_ptr);
17551 if (num_matched > 0) {
17552 matchedlist[num].num_matched = num_matched;
17553 matchedlist[num].type = MDNS_TYPE_PTR;
17554 num++;
17555 }
17556 }
17557 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17558 num_matched = wlan_hdd_mdns_find_entries_from_end(
17559 resptype_srv_tgt, resptype_txt);
17560 if (num_matched > 0) {
17561 matchedlist[num].num_matched = num_matched;
17562 matchedlist[num].type = MDNS_TYPE_TXT;
17563 num++;
17564 }
17565 }
17566 if (resptype_a && (resptype_a->num_entries > 0)) {
17567 num_matched = wlan_hdd_mdns_find_entries_from_end(
17568 resptype_srv_tgt, resptype_a);
17569 if (num_matched > 0) {
17570 matchedlist[num].num_matched = num_matched;
17571 matchedlist[num].type = MDNS_TYPE_A;
17572 num++;
17573 }
17574 }
17575 if (num > 0) {
17576 if (num > 1)
17577 wlan_hdd_mdns_find_max(matchedlist, num);
17578 resp = NULL;
17579 switch (matchedlist[num-1].type) {
17580 case MDNS_TYPE_A:
17581 resp = resptype_a;
17582 break;
17583 case MDNS_TYPE_TXT:
17584 resp = resptype_txt;
17585 break;
17586 case MDNS_TYPE_PTR:
17587 resp = resptype_ptr;
17588 break;
17589 case MDNS_TYPE_PTR_DNAME:
17590 resp = resptype_ptr_dn;
17591 break;
17592 case MDNS_TYPE_SRV:
17593 resp = resptype_srv;
17594 break;
17595 default:
17596 hddLog(LOGE, FL("Fail to compress mDNS response "
17597 "(%d)!"), MDNS_TYPE_SRV_TARGET);
17598 return FALSE;
17599 }
17600 num_matched = matchedlist[num-1].num_matched;
17601 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_srv_tgt,
17602 resp, num_matched)) {
17603 hddLog(LOGE, FL("Fail to compress mDNS response "
17604 "(%d)!"), MDNS_TYPE_SRV_TARGET);
17605 return FALSE;
17606 }
17607 } else {
17608 /* num = 0 -> no matched string */
17609 if (!wlan_hdd_mdns_process_response_dname(resptype_srv_tgt,
17610 resp_info)) {
17611 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17612 MDNS_TYPE_SRV_TARGET);
17613 return FALSE;
17614 }
17615 }
17616
17617 return TRUE;
17618}
17619
17620/**
17621 * wlan_hdd_mdns_pack_response_type_srv()- Pack Type Service response
17622 * @ini_config: Pointer to the struct hdd_config_t
17623 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17624 * @resptype_srv: Pointer to the struct hdd_mdns_resp_info of Type Srv
17625 * @resptype_srv_tgt: Pointer to the struct hdd_mdns_resp_info of Type Srv
17626 * target
17627 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17628 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17629 * domain name
17630 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17631 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17632 *
17633 * The Type SRV (Service) response include QName, response type, class, TTL
17634 * and four kinds of data fields. Also, it will find the matched QName from
17635 * the existing resptype_ptr, resptype_ptr_dn, resptype_txt, resptype_a and
17636 * then compress the data.
17637 *
17638 * Return: Return boolean. TRUE for success, FALSE for fail.
17639 */
17640static bool
17641wlan_hdd_mdns_pack_response_type_srv(hdd_config_t *ini_config,
17642 sir_mdns_resp_info resp_info,
17643 struct hdd_mdns_resp_info *resptype_srv,
17644 struct hdd_mdns_resp_info *resptype_srv_tgt,
17645 struct hdd_mdns_resp_info *resptype_ptr,
17646 struct hdd_mdns_resp_info *resptype_ptr_dn,
17647 struct hdd_mdns_resp_info *resptype_txt,
17648 struct hdd_mdns_resp_info *resptype_a)
17649{
17650 uint8_t num_matched, num, size;
17651 uint16_t value;
17652 uint8_t val_u8;
17653 uint32_t offset_data_len, len;
17654 struct hdd_mdns_resp_info *resp;
17655 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17656
17657 ENTER();
17658
17659 if ((ini_config == NULL) || (resp_info == NULL) ||
17660 (resptype_srv == NULL) || (resptype_srv_tgt == NULL)) {
17661 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17662 return FALSE;
17663 }
17664
17665 /* No Type Srv response */
17666 if (strlen((char *)ini_config->mdns_resp_type_srv) <= 0)
17667 return TRUE;
17668
17669 /* Wrong response is assigned, just ignore this response */
17670 if (!wlan_hdd_mdns_init_response(resptype_srv,
17671 ini_config->mdns_resp_type_srv, '.'))
17672 return TRUE;
17673
17674 /*
17675 * For data compression
17676 * Check if any strings are matched with Type A response
17677 */
17678 num = 0;
17679 size = (MAX_MDNS_RESP_TYPE-1);
17680 size *= sizeof(struct hdd_mdns_resp_matched);
17681 vos_mem_zero(matchedlist, size);
17682 if (resptype_ptr && (resptype_ptr->num_entries > 0)) {
17683 if (resptype_ptr_dn && (resptype_ptr_dn->num_entries > 0)) {
17684 num_matched = wlan_hdd_mdns_find_entries_from_end(
17685 resptype_srv,
17686 resptype_ptr_dn);
17687 if (num_matched > 0) {
17688 matchedlist[num].num_matched = num_matched;
17689 matchedlist[num].type = MDNS_TYPE_PTR_DNAME;
17690 num++;
17691 }
17692 }
17693 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17694 resptype_ptr);
17695 if (num_matched > 0) {
17696 matchedlist[num].num_matched = num_matched;
17697 matchedlist[num].type = MDNS_TYPE_PTR;
17698 num++;
17699 }
17700 }
17701 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17702 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17703 resptype_txt);
17704 if (num_matched > 0) {
17705 matchedlist[num].num_matched =num_matched;
17706 matchedlist[num].type = MDNS_TYPE_TXT;
17707 num++;
17708 }
17709 }
17710 if (resptype_a && (resptype_a->num_entries > 0)) {
17711 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17712 resptype_a);
17713 if (num_matched > 0) {
17714 matchedlist[num].num_matched = num_matched;
17715 matchedlist[num].type = MDNS_TYPE_A;
17716 num++;
17717 }
17718 }
17719 if (num > 0) {
17720 if (num > 1)
17721 wlan_hdd_mdns_find_max(matchedlist, num);
17722 resp = NULL;
17723 switch (matchedlist[num-1].type) {
17724 case MDNS_TYPE_A:
17725 resp = resptype_a;
17726 break;
17727 case MDNS_TYPE_TXT:
17728 resp = resptype_txt;
17729 break;
17730 case MDNS_TYPE_PTR:
17731 resp = resptype_ptr;
17732 break;
17733 case MDNS_TYPE_PTR_DNAME:
17734 resp = resptype_ptr_dn;
17735 break;
17736 default:
17737 hddLog(LOGE, FL("Fail to compress mDNS response "
17738 "(%d)!"), MDNS_TYPE_SRV);
17739 return FALSE;
17740 }
17741 num_matched = matchedlist[num-1].num_matched;
17742 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_srv,
17743 resp, num_matched)) {
17744 hddLog(LOGE, FL("Fail to compress mDNS response "
17745 "(%d)!"), MDNS_TYPE_SRV);
17746 return FALSE;
17747 }
17748 } else {
17749 /* num = 0 -> no matched string */
17750 if (!wlan_hdd_mdns_process_response_dname(resptype_srv,
17751 resp_info)) {
17752 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17753 MDNS_TYPE_SRV);
17754 return FALSE;
17755 }
17756 }
17757
17758 /* Process response Type, Class, TTL */
17759 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_SRV, resp_info)) {
17760 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17761 MDNS_TYPE_SRV);
17762 return FALSE;
17763 }
17764
17765 /*
17766 * Process response RDLength, RData (Srv target name)
17767 * Save the offset of RData length
17768 */
17769 offset_data_len = resp_info->resp_len;
17770 resp_info->resp_len += sizeof(uint16_t);
17771
17772 len = resp_info->resp_len + (3 * sizeof(uint16_t));
17773 if (len >= MAX_MDNS_RESP_LEN) {
17774 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
17775 return FALSE;
17776 }
17777
17778 /* set Srv Priority */
17779 value = ini_config->mdns_resp_type_srv_priority;
17780 wlan_hdd_mdns_format_response_u16(value, resp_info);
17781 /* set Srv Weight */
17782 value = ini_config->mdns_resp_type_srv_weight;
17783 wlan_hdd_mdns_format_response_u16(value, resp_info);
17784 /* set Srv Port */
17785 value = ini_config->mdns_resp_type_srv_port;
17786 wlan_hdd_mdns_format_response_u16(value, resp_info);
17787
17788 if (!wlan_hdd_mdns_pack_response_type_srv_target(ini_config, resp_info,
17789 resptype_srv_tgt, resptype_srv,
17790 resptype_ptr, resptype_ptr_dn,
17791 resptype_txt, resptype_a)) {
17792 return FALSE;
17793 }
17794 /* Set the RData length */
17795 len = offset_data_len + sizeof(uint16_t);
17796 if ((resptype_srv_tgt->num_entries > 0) &&
17797 (resp_info->resp_len > len)) {
17798 value = resp_info->resp_len - len;
17799 val_u8 = (value & 0xff00) >> 8;
17800 resp_info->resp_data[offset_data_len] = val_u8;
17801 val_u8 = value & 0xff;
17802 resp_info->resp_data[offset_data_len+1] = val_u8;
17803 } else {
17804 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17805 MDNS_TYPE_SRV);
17806 return FALSE;
17807 }
17808
17809 EXIT();
17810 return TRUE;
17811}
17812
17813/**
17814 * wlan_hdd_mdns_free_mem() - Free the allocated memory
17815 * @response: Pointer to the struct hdd_mdns_resp_info
17816 *
17817 * Return: None
17818 */
17819static void wlan_hdd_mdns_free_mem(struct hdd_mdns_resp_info *response)
17820{
17821 if (response && response->data)
17822 vos_mem_free(response->data);
17823 if (response && response->offset)
17824 vos_mem_free(response->offset);
17825}
17826
17827/**
17828 * wlan_hdd_mdns_pack_response() - Pack mDNS response
17829 * @ini_config: Pointer to the struct hdd_config_t
17830 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17831 *
17832 * This function will pack four types of responses (Type A, Type Txt, Type Ptr
17833 * and Type Service). Each response contains QName, response type, class, TTL
17834 * and data fields.
17835 *
17836 * Return: Return boolean. TRUE for success, FALSE for fail.
17837 */
17838static bool wlan_hdd_mdns_pack_response(hdd_config_t *ini_config,
17839 sir_mdns_resp_info resp_info)
17840{
17841 struct hdd_mdns_resp_info resptype_a, resptype_txt;
17842 struct hdd_mdns_resp_info resptype_ptr, resptype_ptr_dn;
17843 struct hdd_mdns_resp_info resptype_srv, resptype_srv_tgt;
17844 uint32_t num_res_records = 0;
17845 bool status = FALSE;
17846
17847 ENTER();
17848
17849 wlan_hdd_mdns_reset_response(&resptype_a);
17850 wlan_hdd_mdns_reset_response(&resptype_txt);
17851 wlan_hdd_mdns_reset_response(&resptype_ptr);
17852 wlan_hdd_mdns_reset_response(&resptype_ptr_dn);
17853 wlan_hdd_mdns_reset_response(&resptype_srv);
17854 wlan_hdd_mdns_reset_response(&resptype_srv_tgt);
17855
17856 resp_info->resp_len = 0;
17857
17858 /* Process Type A response */
17859 if (!wlan_hdd_mdns_pack_response_type_a(ini_config, resp_info,
17860 &resptype_a))
17861 goto err_resptype_a;
17862
17863 if ((resptype_a.num_entries > 0) &&
17864 (strlen((char *)&resptype_a.data[0]) > 0))
17865 num_res_records++;
17866
17867 /* Process Type TXT response */
17868 if (!wlan_hdd_mdns_pack_response_type_txt(ini_config, resp_info,
17869 &resptype_txt, &resptype_a))
17870 goto err_resptype_txt;
17871
17872 if ((resptype_txt.num_entries > 0) &&
17873 (strlen((char *)&resptype_txt.data[0]) > 0))
17874 num_res_records++;
17875
17876 /* Process Type PTR response */
17877 if (!wlan_hdd_mdns_pack_response_type_ptr(ini_config, resp_info,
17878 &resptype_ptr, &resptype_ptr_dn,
17879 &resptype_txt, &resptype_a))
17880 goto err_resptype_ptr;
17881
17882 if ((resptype_ptr.num_entries > 0) &&
17883 (strlen((char *)&resptype_ptr.data[0]) > 0))
17884 num_res_records++;
17885
17886 /* Process Type SRV response */
17887 if (!wlan_hdd_mdns_pack_response_type_srv(ini_config, resp_info,
17888 &resptype_srv, &resptype_srv_tgt,
17889 &resptype_ptr, &resptype_ptr_dn,
17890 &resptype_txt, &resptype_a))
17891 goto err_resptype_srv;
17892
17893 if ((resptype_srv.num_entries > 0) &&
17894 (strlen((char *)&resptype_srv.data[0]) > 0))
17895 num_res_records++;
17896
17897 resp_info->resourceRecord_count = num_res_records;
17898 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
17899 "%s: Pack mDNS response data successfully!", __func__);
17900 status = TRUE;
17901
17902err_resptype_srv:
17903 wlan_hdd_mdns_free_mem(&resptype_srv);
17904 wlan_hdd_mdns_free_mem(&resptype_srv_tgt);
17905
17906err_resptype_ptr:
17907 wlan_hdd_mdns_free_mem(&resptype_ptr);
17908 wlan_hdd_mdns_free_mem(&resptype_ptr_dn);
17909
17910err_resptype_txt:
17911 wlan_hdd_mdns_free_mem(&resptype_txt);
17912
17913err_resptype_a:
17914 wlan_hdd_mdns_free_mem(&resptype_a);
17915
17916 EXIT();
17917 return status;
17918}
17919
17920/**
17921 * wlan_hdd_set_mdns_offload() - Enable mDNS offload
17922 * @hostapd_adapter: Pointer to the struct hdd_adapter_t
17923 *
17924 * This function will set FQDN/unique FQDN (full qualified domain name)
17925 * and the mDNS response. Then send them to SME.
17926 *
17927 * Return: Return boolean. TRUE for success, FALSE for fail.
17928 */
17929bool wlan_hdd_set_mdns_offload(hdd_adapter_t *hostapd_adapter)
17930{
17931 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(hostapd_adapter);
17932 sir_mdns_offload_info mdns_offload_info;
17933 sir_mdns_fqdn_info mdns_fqdn_info;
17934 sir_mdns_resp_info mdns_resp_info;
17935 uint32_t fqdn_len, ufqdn_len;
17936
17937 ENTER();
17938
17939 /* 1. Prepare the MDNS fqdn request to send to SME */
17940 fqdn_len = strlen(hdd_ctx->cfg_ini->mdns_fqdn);
17941 ufqdn_len = strlen(hdd_ctx->cfg_ini->mdns_uniquefqdn);
17942 if ((fqdn_len == 0) && (ufqdn_len == 0)) {
17943 hddLog(LOGE, FL("No mDNS FQDN or UFQDN is assigned fqdn_len %d,"
17944 "ufqdn_len %d!"), fqdn_len, ufqdn_len);
17945 return FALSE;
17946 }
17947
17948 mdns_fqdn_info = vos_mem_malloc(sizeof(*mdns_fqdn_info));
17949 if (NULL == mdns_fqdn_info) {
17950 hddLog(LOGE, FL("could not allocate tSirMDNSFqdnInfo!"));
17951 return FALSE;
17952 }
17953 /* MDNS fqdn request */
17954 if (fqdn_len > 0) {
17955 vos_mem_zero(mdns_fqdn_info, sizeof(*mdns_fqdn_info));
17956 mdns_fqdn_info->bss_idx = hostapd_adapter->sessionId;
17957 mdns_fqdn_info->fqdn_type = MDNS_FQDN_TYPE_GENERAL;
17958 mdns_fqdn_info->fqdn_len = fqdn_len;
17959 mdns_fqdn_info->mdns_fqdn_callback = hdd_mdns_fqdn_offload_done;
17960 mdns_fqdn_info->mdns_fqdn_cb_context = hostapd_adapter;
17961 vos_mem_copy(mdns_fqdn_info->fqdn_data,
17962 hdd_ctx->cfg_ini->mdns_fqdn,
17963 mdns_fqdn_info->fqdn_len);
17964
17965 if (eHAL_STATUS_SUCCESS !=
17966 sme_set_mdns_fqdn(hdd_ctx->hHal, mdns_fqdn_info)) {
17967 hddLog(LOGE, FL("sme_set_mdns_fqdn fail!"));
17968 vos_mem_free(mdns_fqdn_info);
17969 return FALSE;
17970 }
17971 }
17972 /* MDNS unique fqdn request */
17973 if (ufqdn_len > 0) {
17974 vos_mem_zero(mdns_fqdn_info, sizeof(*mdns_fqdn_info));
17975 mdns_fqdn_info->bss_idx = hostapd_adapter->sessionId;
17976 mdns_fqdn_info->fqdn_type = MDNS_FQDN_TYPE_UNIQUE;
17977 mdns_fqdn_info->fqdn_len = ufqdn_len;
17978 mdns_fqdn_info->mdns_fqdn_callback = hdd_mdns_fqdn_offload_done;
17979 mdns_fqdn_info->mdns_fqdn_cb_context = hostapd_adapter;
17980 vos_mem_copy(mdns_fqdn_info->fqdn_data,
17981 hdd_ctx->cfg_ini->mdns_uniquefqdn,
17982 mdns_fqdn_info->fqdn_len);
17983 if (eHAL_STATUS_SUCCESS !=
17984 sme_set_mdns_fqdn(hdd_ctx->hHal, mdns_fqdn_info)) {
17985 hddLog(LOGE, FL("sme_set_mdns_fqdn fail!"));
17986 vos_mem_free(mdns_fqdn_info);
17987 return FALSE;
17988 }
17989 }
17990 vos_mem_free(mdns_fqdn_info);
17991
17992 /* 2. Prepare the MDNS response request to send to SME */
17993 mdns_resp_info = vos_mem_malloc(sizeof(*mdns_resp_info));
17994 if (NULL == mdns_resp_info) {
17995 hddLog(LOGE, FL("could not allocate tSirMDNSResponseInfo!"));
17996 return FALSE;
17997 }
17998
17999 vos_mem_zero(mdns_resp_info, sizeof(*mdns_resp_info));
18000 mdns_resp_info->bss_idx = hostapd_adapter->sessionId;
18001 mdns_resp_info->mdns_resp_callback = hdd_mdns_resp_offload_done;
18002 mdns_resp_info->mdns_resp_cb_context = hostapd_adapter;
18003 if (!wlan_hdd_mdns_pack_response(hdd_ctx->cfg_ini, mdns_resp_info)) {
18004 hddLog(LOGE, FL("wlan_hdd_pack_mdns_response fail!"));
18005 vos_mem_free(mdns_resp_info);
18006 return FALSE;
18007 }
18008 if (eHAL_STATUS_SUCCESS !=
18009 sme_set_mdns_resp(hdd_ctx->hHal, mdns_resp_info)) {
18010 hddLog(LOGE, FL("sme_set_mdns_resp fail!"));
18011 vos_mem_free(mdns_resp_info);
18012 return FALSE;
18013 }
18014 vos_mem_free(mdns_resp_info);
18015
18016 /* 3. Prepare the MDNS Enable request to send to SME */
18017 mdns_offload_info = vos_mem_malloc(sizeof(*mdns_offload_info));
18018 if (NULL == mdns_offload_info) {
18019 hddLog(LOGE, FL("could not allocate tSirMDNSOffloadInfo!"));
18020 return FALSE;
18021 }
18022
18023 vos_mem_zero(mdns_offload_info, sizeof(*mdns_offload_info));
18024
18025 mdns_offload_info->bss_idx = hostapd_adapter->sessionId;
18026 mdns_offload_info->enable = hdd_ctx->cfg_ini->enable_mdns_offload;
18027 mdns_offload_info->mdns_enable_callback = hdd_mdns_enable_offload_done;
18028 mdns_offload_info->mdns_enable_cb_context = hostapd_adapter;
18029 if (eHAL_STATUS_SUCCESS !=
18030 sme_set_mdns_offload(hdd_ctx->hHal, mdns_offload_info)) {
18031 hddLog(LOGE, FL("sme_set_mdns_offload fail!"));
18032 vos_mem_free(mdns_offload_info);
18033 return FALSE;
18034 }
18035
18036 vos_mem_free(mdns_offload_info);
18037 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
18038 "%s: enable mDNS offload successfully!", __func__);
18039 return TRUE;
18040}
Manjeet Singh3ed79242017-01-11 19:04:32 +053018041
18042
Anurag Chouhan0b29de02016-12-16 13:18:40 +053018043#endif /* MDNS_OFFLOAD */
c_manjeecfd1efb2015-09-25 19:32:34 +053018044
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053018045/**
18046 * wlan_hdd_start_sap() - This function starts bss of SAP.
18047 * @ap_adapter: SAP adapter
18048 *
18049 * This function will process the starting of sap adapter.
18050 *
18051 * Return: void.
18052 */
18053void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter)
18054{
18055 hdd_ap_ctx_t *hdd_ap_ctx;
18056 hdd_hostapd_state_t *hostapd_state;
18057 VOS_STATUS vos_status;
18058 hdd_context_t *hdd_ctx;
18059 tsap_Config_t *pConfig;
18060
18061 if (NULL == ap_adapter) {
18062 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
18063 FL("ap_adapter is NULL here"));
18064 return;
18065 }
18066
18067 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
18068 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
18069 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
18070 pConfig = &ap_adapter->sessionCtx.ap.sapConfig;
18071
18072 mutex_lock(&hdd_ctx->sap_lock);
18073 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
18074 goto end;
18075
18076 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
18077 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
18078 goto end;
18079 }
18080
18081 vos_event_reset(&hostapd_state->vosEvent);
18082 if (WLANSAP_StartBss(hdd_ctx->pvosContext, hdd_hostapd_SAPEventCB,
18083 &hdd_ap_ctx->sapConfig, (v_PVOID_t)ap_adapter->dev)
18084 != VOS_STATUS_SUCCESS) {
18085 goto end;
18086 }
18087
18088 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
18089 FL("Waiting for SAP to start"));
18090 vos_status = vos_wait_single_event(&hostapd_state->vosEvent, 10000);
18091 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
18092 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
18093 FL("SAP Start failed"));
18094 goto end;
18095 }
18096 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
18097 FL("SAP Start Success"));
18098 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
18099
18100 wlan_hdd_incr_active_session(hdd_ctx, ap_adapter->device_mode);
18101 hostapd_state->bCommit = TRUE;
18102
18103end:
18104 mutex_unlock(&hdd_ctx->sap_lock);
18105 return;
18106}
18107
Manjeet Singh3ed79242017-01-11 19:04:32 +053018108#ifdef WLAN_FEATURE_TSF
18109
18110/**
18111 * hdd_tsf_cb() - handle tsf request callback
18112 *
18113 * @pcb_cxt: pointer to the hdd_contex
18114 * @ptsf: pointer to struct stsf
18115 *
18116 * Based on the request sent .
18117 *
18118 * Return: Describe the execute result of this routine
18119 */
18120static int hdd_tsf_cb(void *pcb_ctx, struct stsf *ptsf)
18121{
18122 hdd_context_t *hddctx;
18123 int status;
18124 hdd_adapter_t* adapter = (hdd_adapter_t*)pcb_ctx;
18125
18126 if (pcb_ctx == NULL || ptsf == NULL) {
18127 hddLog(VOS_TRACE_LEVEL_ERROR,
18128 FL("HDD context is not valid"));
18129 return -EINVAL;
18130 }
18131
18132 hddctx = (hdd_context_t *)pcb_ctx;
18133 status = wlan_hdd_validate_context(hddctx);
18134 if (0 != status)
18135 return -EINVAL;
18136
18137 if (NULL == adapter) {
18138 hddLog(VOS_TRACE_LEVEL_ERROR,
18139 FL("failed to find adapter"));
18140 return -EINVAL;
18141 }
18142
18143 hddLog(VOS_TRACE_LEVEL_INFO,
18144 FL("tsf cb handle event, device_mode is %d"),
18145 adapter->device_mode);
18146
18147 /* copy the return value to hdd_tsf_ctx in adapter*/
18148 if (ptsf->tsf_req_status) {
18149
18150 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18151 adapter->tsf_cap_ctx.tsf_get_state = TSF_NOT_RETURNED_BY_FW;
18152 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18153 vos_event_set (&adapter->tsf_cap_ctx.tsf_capture_done_event);
18154 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18155
18156 hddLog(VOS_TRACE_LEVEL_ERROR, FL("tsf req failure :%d"),
18157 ptsf->tsf_req_status);
18158 return ptsf->tsf_req_status;
18159 }
18160 /* If this is a get request.Store the tsf values in adapter. */
18161 if (!ptsf->set_tsf_req) {
18162 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18163 adapter->tsf_cap_ctx.tsf_low = ptsf->tsf_low;
18164 adapter->tsf_cap_ctx.tsf_high = ptsf->tsf_high;
18165 adapter->tsf_cap_ctx.tsf_get_state = TSF_RETURN;
18166 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18167 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18168
18169 hddLog(VOS_TRACE_LEVEL_INFO,
18170 FL("hdd_get_tsf_cb sta=%u, tsf_low=%u, tsf_high=%u"),
18171 adapter->sessionId, ptsf->tsf_low, ptsf->tsf_high);
18172 }
18173 else {
18174 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18175 adapter->tsf_cap_ctx.tsf_capture_state = TSF_CAP_STATE;
18176 adapter->tsf_cap_ctx.tsf_get_state = TSF_CURRENT_IN_CAP_STATE;
18177 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18178 }
18179 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18180 vos_event_set (&adapter->tsf_cap_ctx.tsf_capture_done_event);
18181 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18182
18183 /* free allocated mem */
18184 vos_mem_free(ptsf);
18185
18186 return 0;
18187}
18188
18189/**
18190 * hdd_capture_tsf() - capture tsf
18191 *
18192 * @adapter: pointer to adapter
18193 * @buf: pointer to upper layer buf
18194 * @len : the length of buf
18195 *
18196 * This function returns tsf value to uplayer.
18197 *
18198 * Return: Describe the execute result of this routine
18199 */
18200int hdd_capture_tsf(hdd_adapter_t *adapter, uint32_t *buf, int len)
18201{
18202 int ret = 0;
18203 hdd_station_ctx_t *hdd_sta_ctx;
18204 hdd_context_t *hdd_ctx;
18205 tSirCapTsfParams cap_tsf_params;
18206 VOS_STATUS status;
18207
18208 if (adapter == NULL || buf == NULL) {
18209 hddLog(VOS_TRACE_LEVEL_ERROR,
18210 FL("invalid pointer"));
18211 return -EINVAL;
18212 }
18213 if (len != 1)
18214 return -EINVAL;
18215
18216 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
18217
18218 if (wlan_hdd_validate_context(hdd_ctx)) {
18219 hddLog(VOS_TRACE_LEVEL_ERROR,
18220 FL("invalid hdd ctx"));
18221 return -EINVAL;
18222 }
18223 if (adapter->device_mode == WLAN_HDD_INFRA_STATION ||
18224 adapter->device_mode == WLAN_HDD_P2P_CLIENT) {
18225 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
18226 if (hdd_sta_ctx->conn_info.connState !=
18227 eConnectionState_Associated) {
18228
18229 hddLog(VOS_TRACE_LEVEL_INFO,
18230 FL("failed to cap tsf, not connect with ap"));
18231 buf[0] = TSF_STA_NOT_CONNECTED_NO_TSF;
18232 return ret;
18233 }
18234 }
18235 if ((adapter->device_mode == WLAN_HDD_SOFTAP ||
18236 adapter->device_mode == WLAN_HDD_P2P_GO) &&
18237 !(test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))) {
18238 hddLog(VOS_TRACE_LEVEL_INFO,
18239 FL("Soft AP / P2p GO not beaconing"));
18240 buf[0] = TSF_SAP_NOT_STARTED_NO_TSF;
18241 return ret;
18242 }
18243 if (adapter->tsf_cap_ctx.tsf_capture_state == TSF_CAP_STATE) {
18244 hddLog(VOS_TRACE_LEVEL_INFO,
18245 FL("current in capture state, pls reset"));
18246 buf[0] = TSF_CURRENT_IN_CAP_STATE;
18247 } else {
18248 hddLog(VOS_TRACE_LEVEL_INFO, FL("ioctl issue cap tsf cmd"));
18249 buf[0] = TSF_RETURN;
18250 cap_tsf_params.session_id = adapter->sessionId;
18251 cap_tsf_params.tsf_rsp_cb_func = hdd_tsf_cb;
18252 cap_tsf_params.tsf_rsp_cb_ctx = adapter;
18253
18254 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18255 adapter->tsf_cap_ctx.tsf_capture_state = TSF_CAP_STATE;
18256 adapter->tsf_cap_ctx.tsf_get_state = TSF_CURRENT_IN_CAP_STATE;
18257 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18258
18259 ret = sme_capture_tsf_req(hdd_ctx->hHal, cap_tsf_params);
18260
18261 if (ret != VOS_STATUS_SUCCESS) {
18262 hddLog(VOS_TRACE_LEVEL_ERROR, FL("capture fail"));
18263 buf[0] = TSF_CAPTURE_FAIL;
18264 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18265 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18266 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18267 return -EINVAL;
18268 }
18269 /* wait till we get a response from fw */
18270 status = vos_wait_single_event(&adapter->tsf_cap_ctx.
18271 tsf_capture_done_event,
18272 HDD_TSF_CAP_REQ_TIMEOUT);
18273
18274 if (!VOS_IS_STATUS_SUCCESS(status)) {
18275 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
18276 ("capture tsf vos wait for single_event failed!! %d"),
18277 adapter->tsf_cap_ctx.tsf_get_state);
18278
18279 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18280 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18281 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18282
18283 return -EINVAL;
18284 }
18285 }
18286 buf[0] = TSF_RETURN;
18287 hddLog(VOS_TRACE_LEVEL_INFO,
18288 FL("ioctl return cap tsf cmd, ret = %d"), ret);
18289 return ret;
18290}
18291
18292/**
18293 * hdd_indicate_tsf() - return tsf to uplayer
18294 *
18295 * @adapter: pointer to adapter
18296 * @buf: pointer to uplayer buf
18297 * @len : the length of buf
18298 *
18299 * This function returns tsf value to uplayer.
18300 *
18301 * Return: Describe the execute result of this routine
18302 */
18303int hdd_indicate_tsf(hdd_adapter_t *adapter, uint32_t *buf, int len)
18304{
18305 int ret = 0;
18306 hdd_station_ctx_t *hdd_sta_ctx;
18307 hdd_context_t *hdd_ctx;
18308 tSirCapTsfParams cap_tsf_params;
18309 VOS_STATUS status;
18310
18311 if (adapter == NULL || buf == NULL) {
18312 hddLog(VOS_TRACE_LEVEL_ERROR,
18313 FL("invalid pointer"));
18314 return -EINVAL;
18315 }
18316 if (len != 3)
18317 return -EINVAL;
18318
18319 buf [1] = 0;
18320 buf [2] = 0;
18321 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
18322
18323 if (wlan_hdd_validate_context(hdd_ctx)) {
18324 hddLog(VOS_TRACE_LEVEL_ERROR,
18325 FL("invalid hdd ctx"));
18326 return -EINVAL;
18327 }
18328 if (adapter->device_mode == WLAN_HDD_INFRA_STATION ||
18329 adapter->device_mode == WLAN_HDD_P2P_CLIENT) {
18330 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
18331 if (hdd_sta_ctx->conn_info.connState !=
18332 eConnectionState_Associated) {
18333
18334 hddLog(VOS_TRACE_LEVEL_INFO,
18335 FL("failed to cap tsf, not connect with ap"));
18336 buf[0] = TSF_STA_NOT_CONNECTED_NO_TSF;
18337 return ret;
18338 }
18339 }
18340 if ((adapter->device_mode == WLAN_HDD_SOFTAP ||
18341 adapter->device_mode == WLAN_HDD_P2P_GO) &&
18342 !(test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))) {
18343 hddLog(VOS_TRACE_LEVEL_INFO,
18344 FL("Soft AP / P2p GO not beaconing"));
18345 buf[0] = TSF_SAP_NOT_STARTED_NO_TSF;
18346 return ret;
18347 }
18348
18349 if (adapter->tsf_cap_ctx.tsf_capture_state != TSF_CAP_STATE ||
18350 adapter->tsf_cap_ctx.tsf_get_state != TSF_CURRENT_IN_CAP_STATE ) {
18351 hddLog(VOS_TRACE_LEVEL_INFO,
18352 FL("Not in capture state,Enter capture state first"));
18353 buf[0] = TSF_GET_FAIL;
18354 } else {
18355 hddLog(VOS_TRACE_LEVEL_INFO, FL("ioctl issue cap tsf cmd"));
18356 cap_tsf_params.session_id = adapter->sessionId;
18357 cap_tsf_params.tsf_rsp_cb_func = hdd_tsf_cb;
18358 cap_tsf_params.tsf_rsp_cb_ctx = adapter;
18359
18360 ret = sme_get_tsf_req(hdd_ctx->hHal, cap_tsf_params);
18361
18362 if (ret != VOS_STATUS_SUCCESS) {
18363 hddLog(VOS_TRACE_LEVEL_ERROR, FL("capture fail"));
18364 buf[0] = TSF_CAPTURE_FAIL;
18365 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18366 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18367 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18368 return -EINVAL;
18369 }
18370 /* wait till we get a response from fw */
18371 status = vos_wait_single_event(&adapter->tsf_cap_ctx.
18372 tsf_capture_done_event,
18373 HDD_TSF_GET_REQ_TIMEOUT);
18374
18375 if (!VOS_IS_STATUS_SUCCESS(status)) {
18376 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
18377 ("capture tsf vos wait for single_event failed!! %d"),
18378 status);
18379
18380 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18381 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18382 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18383 return status;
18384 }
18385 buf[1] = adapter->tsf_cap_ctx.tsf_low;
18386 buf[2] = adapter->tsf_cap_ctx.tsf_high;
18387
18388 hddLog(VOS_TRACE_LEVEL_INFO,
18389 FL("get tsf cmd,status=%u, tsf_low=%u, tsf_high=%u"),
18390 buf[0], buf[1], buf[2]);
18391 }
18392 hddLog(VOS_TRACE_LEVEL_INFO,
18393 FL("ioctl return cap tsf cmd, ret = %d"), ret);
18394 return ret;
18395}
18396
18397void wlan_hdd_tsf_init(hdd_adapter_t *adapter)
18398{
18399
18400 if (adapter == NULL) {
18401 hddLog(VOS_TRACE_LEVEL_ERROR,
18402 FL("TSF init on a null adapter!"));
18403 return;
18404 }
18405
18406 adapter->tsf_cap_ctx.tsf_get_state = TSF_RETURN;
18407 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18408 vos_event_init(&adapter->tsf_cap_ctx.tsf_capture_done_event);
18409 vos_spin_lock_init(&adapter->tsf_cap_ctx.tsf_lock);
18410 adapter->tsf_cap_ctx.tsf_high = 0;
18411 adapter->tsf_cap_ctx.tsf_low = 0;
18412}
18413
18414#endif
18415
Hanumanth Reddy Pothula49c3f902018-02-16 16:01:13 +053018416bool hdd_is_memdump_supported(void)
18417{
18418#ifdef WLAN_FEATURE_MEMDUMP
18419 return true;
18420#endif
18421 return false;
18422}
18423
Jeff Johnson295189b2012-06-20 16:38:30 -070018424//Register the module init/exit functions
18425module_init(hdd_module_init);
18426module_exit(hdd_module_exit);
18427
18428MODULE_LICENSE("Dual BSD/GPL");
18429MODULE_AUTHOR("Qualcomm Atheros, Inc.");
18430MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
18431
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018432static const struct kernel_param_ops con_mode_ops = {
18433 .set = con_mode_handler,
18434 .get = param_get_int,
18435};
18436
18437static const struct kernel_param_ops fwpath_ops = {
18438 .set = fwpath_changed_handler,
18439 .get = param_get_string,
18440};
18441
Hanumanth Reddy Pothula99219872018-06-08 14:45:18 +053018442#ifdef MODULE
18443module_param(con_mode, int, 0);
18444#else
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018445module_param_cb(con_mode, &con_mode_ops, &con_mode,
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070018446 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Hanumanth Reddy Pothula99219872018-06-08 14:45:18 +053018447#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -070018448
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018449module_param_cb(fwpath, &fwpath_ops, &fwpath,
Jeff Johnson32d95a32012-09-10 13:15:23 -070018450 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Arif Hussain66559122013-11-21 10:11:40 -080018451
18452module_param(enable_dfs_chan_scan, int,
18453 S_IRUSR | S_IRGRP | S_IROTH);
18454
18455module_param(enable_11d, int,
18456 S_IRUSR | S_IRGRP | S_IROTH);
18457
18458module_param(country_code, charp,
18459 S_IRUSR | S_IRGRP | S_IROTH);