blob: 0270d8f2ccbf67e86317ee74246beaf60b6403f6 [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;
c_hpothu92367912014-05-01 15:18:17 +0530154static int gbcnMissRate = -1;
Arif Hussain66559122013-11-21 10:11:40 -0800155
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700156#ifndef MODULE
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700157static int wlan_hdd_inited;
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700158#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700159
Jeff Johnsone7245742012-09-05 17:12:55 -0700160/*
Jeff Johnson72a40512013-12-19 10:14:15 -0800161 * spinlock for synchronizing asynchronous request/response
162 * (full description of use in wlan_hdd_main.h)
163 */
164DEFINE_SPINLOCK(hdd_context_lock);
165
166/*
Jeff Johnsone7245742012-09-05 17:12:55 -0700167 * The rate at which the driver sends RESTART event to supplicant
168 * once the function 'vos_wlanRestart()' is called
169 *
170 */
171#define WLAN_HDD_RESTART_RETRY_DELAY_MS 5000 /* 5 second */
172#define WLAN_HDD_RESTART_RETRY_MAX_CNT 5 /* 5 retries */
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -0700173
174/*
175 * Size of Driver command strings from upper layer
176 */
177#define SIZE_OF_SETROAMMODE 11 /* size of SETROAMMODE */
178#define SIZE_OF_GETROAMMODE 11 /* size of GETROAMMODE */
179
Abhishek Singh00b71972016-01-07 10:51:04 +0530180#ifdef WLAN_FEATURE_RMC
181/*
182 * Ibss prop IE from command will be of size:
183 * size = sizeof(oui) + sizeof(oui_data) + 1(Element ID) + 1(EID Length)
184 * OUI_DATA should be at least 3 bytes long
185 */
186#define WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH (3)
187#endif
188
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800189#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700190#define TID_MIN_VALUE 0
191#define TID_MAX_VALUE 15
192static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
193 tAniTrafStrmMetrics* pTsmMetrics);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800194static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
195 tCsrEseBeaconReq *pEseBcnReq);
196#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700197
Atul Mittal1d722422014-03-19 11:15:07 +0530198/*
199 * Maximum buffer size used for returning the data back to user space
200 */
201#define WLAN_MAX_BUF_SIZE 1024
202#define WLAN_PRIV_DATA_MAX_LEN 8192
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -0700203
Abhishek Singh00b71972016-01-07 10:51:04 +0530204/*
205 * When ever we need to print IBSSPEERINFOALL for morethan 16 STA
206 * we will split the printing.
207 */
208#define NUM_OF_STA_DATA_TO_PRINT 16
209
210#ifdef WLAN_FEATURE_RMC
211#define WLAN_NLINK_CESIUM 30
212#endif
213
c_hpothu92367912014-05-01 15:18:17 +0530214//wait time for beacon miss rate.
215#define BCN_MISS_RATE_TIME 500
216
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +0530217/*
218 * Android DRIVER command structures
219 */
220struct android_wifi_reassoc_params {
221 unsigned char bssid[18];
222 int channel;
223};
224
Sushant Kaushik83392fa2015-05-05 17:44:40 +0530225static vos_wake_lock_t wlan_wake_lock;
226
Jeff Johnson295189b2012-06-20 16:38:30 -0700227/* set when SSR is needed after unload */
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -0700228static e_hdd_ssr_required isSsrRequired = HDD_SSR_NOT_REQUIRED;
Jeff Johnson295189b2012-06-20 16:38:30 -0700229
230//internal function declaration
Jeff Johnsone7245742012-09-05 17:12:55 -0700231static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx);
232static void wlan_hdd_restart_init(hdd_context_t *pHddCtx);
233static void wlan_hdd_restart_deinit(hdd_context_t *pHddCtx);
Abhishek Singh00b71972016-01-07 10:51:04 +0530234
235#ifdef WLAN_FEATURE_RMC
236static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo);
237
238static int hdd_open_cesium_nl_sock(void);
239static void hdd_close_cesium_nl_sock(void);
240static struct sock *cesium_nl_srv_sock;
241static v_U16_t cesium_pid;
242
243static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
244 tANI_U8 *tx_fail_count,
245 tANI_U16 *pid);
246
247static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg);
248
249#endif /* WLAN_FEATURE_RMC */
Jeff Johnsone7245742012-09-05 17:12:55 -0700250void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback);
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800251void hdd_set_wlan_suspend_mode(bool suspend);
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}
868
869/* Function header left blank Intentionally */
870static int hdd_parse_setrmcrate_command(tANI_U8 *pValue,
871 tANI_U32 *pRate, tTxrateinfoflags *pTxFlags)
872{
873 tANI_U8 *inPtr = pValue;
874 int tempInt;
875 int v = 0;
876 char buf[32];
877 *pRate = 0;
878 *pTxFlags = 0;
879
880 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
881 /*no argument after the command*/
882 if (NULL == inPtr)
883 {
884 return -EINVAL;
885 }
886
887 /*no space after the command*/
888 else if (SPACE_ASCII_VALUE != *inPtr)
889 {
890 return -EINVAL;
891 }
892
893 /*removing empty spaces*/
894 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
895
896 /*no argument followed by spaces*/
897 if ('\0' == *inPtr)
898 {
899 return 0;
900 }
901
902 /*
903 * getting the first argument which sets multicast rate.
904 */
Ashish Kumar Dhanotiya06f9f202017-08-04 15:26:27 +0530905 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530906 v = kstrtos32(buf, 10, &tempInt);
907 if ( v < 0)
908 {
909 return -EINVAL;
910 }
911
912 /*
913 * Validate the multicast rate.
914 */
915 switch (tempInt)
916 {
917 default:
918 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
919 "Unsupported rate: %d", tempInt);
920 return -EINVAL;
921 case 0:
922 case 6:
923 case 9:
924 case 12:
925 case 18:
926 case 24:
927 case 36:
928 case 48:
929 case 54:
930 *pTxFlags = eHAL_TX_RATE_LEGACY;
931 *pRate = tempInt * 10;
932 break;
933 case 65:
934 *pTxFlags = eHAL_TX_RATE_HT20;
935 *pRate = tempInt * 10;
936 break;
937 case 72:
938 *pTxFlags = eHAL_TX_RATE_HT20 | eHAL_TX_RATE_SGI;
939 *pRate = 722; /* fractional rate 72.2 Mbps */
940 break;
941 }
942
943 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
944 "Rate: %d", *pRate);
945
946 return 0;
947}
948
949/**---------------------------------------------------------------------------
950
951 \brief hdd_cfg80211_get_ibss_peer_info_cb() - Callback function for IBSS
952 Peer Info request
953
954 This is an asynchronous callback function from SME when the peer info
955 is received
956
957 \pUserData -> Adapter private data
958 \pPeerInfoRsp -> Peer info response
959
960 \return - 0 for success non-zero for failure
961 --------------------------------------------------------------------------*/
962static void
963hdd_cfg80211_get_ibss_peer_info_cb(v_VOID_t *pUserData, v_VOID_t *pPeerInfoRsp)
964{
965 hdd_adapter_t *pAdapter = (hdd_adapter_t *)pUserData;
966 tSirPeerInfoRspParams *pPeerInfo = (tSirPeerInfoRspParams *)pPeerInfoRsp;
967 hdd_station_ctx_t *pStaCtx;
968 v_U8_t i;
969
970 /*Sanity check*/
971 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
972 {
973 hddLog(LOGE,
974 FL("invalid adapter or adapter has invalid magic"));
975 return;
976 }
977
978 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
979 if (NULL != pStaCtx && NULL != pPeerInfo &&
980 eHAL_STATUS_SUCCESS == pPeerInfo->status)
981 {
982 pStaCtx->ibss_peer_info.status = pPeerInfo->status;
983 pStaCtx->ibss_peer_info.numIBSSPeers = pPeerInfo->numPeers;
984
985 /* Paranoia check */
986 if (pPeerInfo->numPeers < HDD_MAX_NUM_IBSS_STA)
987 {
988 for (i = 0; i < pPeerInfo->numPeers; i++)
989 {
990 memcpy(&pStaCtx->ibss_peer_info.ibssPeerList[i],
991 &pPeerInfo->peerInfoParams[i],
992 sizeof(hdd_ibss_peer_info_params_t));
993 }
994 hddLog(LOG1,
995 FL("Peer Info copied in HDD"));
996 }
997 else
998 {
999 hddLog(LOGE,
1000 FL(" Number of peers %d returned is more than limit %d"),
1001 pPeerInfo->numPeers, HDD_MAX_NUM_IBSS_STA);
1002 }
1003 }
1004 else
1005 {
1006 hddLog(LOG1,
1007 FL("peerInfo returned is NULL"));
1008 }
1009
1010 complete(&pAdapter->ibss_peer_info_comp);
1011}
1012
1013/**---------------------------------------------------------------------------
1014
1015 \brief hdd_cfg80211_get_ibss_peer_info_all() -
1016
1017 Request function to get IBSS peer info from lower layers
1018
1019 \pAdapter -> Adapter context
1020
1021 \return - 0 for success non-zero for failure
1022 --------------------------------------------------------------------------*/
1023static
1024VOS_STATUS hdd_cfg80211_get_ibss_peer_info_all(hdd_adapter_t *pAdapter)
1025{
1026 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1027 long status;
1028 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1029
1030 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1031
1032 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1033 hdd_cfg80211_get_ibss_peer_info_cb,
1034 VOS_TRUE, 0xFF);
1035
1036 if (VOS_STATUS_SUCCESS == retStatus)
1037 {
1038 status = wait_for_completion_interruptible_timeout
1039 (&pAdapter->ibss_peer_info_comp,
1040 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1041
1042 /* status will be 0 if timed out */
1043 if (status <= 0)
1044 {
1045 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1046 __func__, status);
1047 retStatus = VOS_STATUS_E_FAILURE;
1048 return retStatus;
1049 }
1050 }
1051 else
1052 {
1053 hddLog(VOS_TRACE_LEVEL_WARN,
1054 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1055 }
1056
1057 return retStatus;
1058}
1059
1060/**---------------------------------------------------------------------------
1061
1062 \brief hdd_cfg80211_get_ibss_peer_info() -
1063
1064 Request function to get IBSS peer info from lower layers
1065
1066 \pAdapter -> Adapter context
1067 \staIdx -> Sta index for which the peer info is requested
1068
1069 \return - 0 for success non-zero for failure
1070 --------------------------------------------------------------------------*/
1071static VOS_STATUS
1072hdd_cfg80211_get_ibss_peer_info(hdd_adapter_t *pAdapter, v_U8_t staIdx)
1073{
1074 long status;
1075 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1076 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1077
1078 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1079
1080 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1081 hdd_cfg80211_get_ibss_peer_info_cb,
1082 VOS_FALSE, staIdx);
1083
1084 if (VOS_STATUS_SUCCESS == retStatus)
1085 {
1086 status = wait_for_completion_interruptible_timeout
1087 (&pAdapter->ibss_peer_info_comp,
1088 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1089
1090 /* status = 0 on timeout */
1091 if (status <= 0)
1092 {
1093 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1094 __func__, status);
1095 retStatus = VOS_STATUS_E_FAILURE;
1096 return retStatus;
1097 }
1098 }
1099 else
1100 {
1101 hddLog(VOS_TRACE_LEVEL_WARN,
1102 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1103 }
1104
1105 return retStatus;
1106}
1107
1108/* Function header left blank Intentionally */
1109VOS_STATUS
1110hdd_parse_get_ibss_peer_info(tANI_U8 *pValue, v_MACADDR_t *pPeerMacAddr)
1111{
1112 tANI_U8 *inPtr = pValue;
1113 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1114
1115 /*no argument after the command*/
1116 if (NULL == inPtr)
1117 {
1118 return VOS_STATUS_E_FAILURE;;
1119 }
1120
1121 /*no space after the command*/
1122 else if (SPACE_ASCII_VALUE != *inPtr)
1123 {
1124 return VOS_STATUS_E_FAILURE;;
1125 }
1126
1127 /*removing empty spaces*/
1128 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
1129
1130 /*no argument followed by spaces*/
1131 if ('\0' == *inPtr)
1132 {
1133 return VOS_STATUS_E_FAILURE;;
1134 }
1135
1136 /*getting the first argument ie the peer mac address */
1137 if (inPtr[2] != ':' || inPtr[5] != ':' || inPtr[8] != ':' ||
1138 inPtr[11] != ':' || inPtr[14] != ':')
1139 {
1140 return VOS_STATUS_E_FAILURE;;
1141 }
1142 sscanf(inPtr, "%2x:%2x:%2x:%2x:%2x:%2x",
1143 (unsigned int *)&pPeerMacAddr->bytes[0],
1144 (unsigned int *)&pPeerMacAddr->bytes[1],
1145 (unsigned int *)&pPeerMacAddr->bytes[2],
1146 (unsigned int *)&pPeerMacAddr->bytes[3],
1147 (unsigned int *)&pPeerMacAddr->bytes[4],
1148 (unsigned int *)&pPeerMacAddr->bytes[5]);
1149
1150 /* The command buffer seems to be fine */
1151 return VOS_STATUS_SUCCESS;
1152}
1153
1154/* Function header left blank Intentionally */
1155static int hdd_parse_set_ibss_oui_data_command(tANI_U8 *command, tANI_U8 *ie,
1156 tANI_U32 limit)
1157{
1158 tANI_U8 len;
1159 tANI_U8 data;
1160
1161 /* skip white space */
1162 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1163 {
1164 command++;
1165 limit--;
1166 }
1167
1168 /* skip element id and element length */
1169 len = 2;
1170
1171 /* extract oui */
1172 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1173 (limit > 1))
1174 {
1175 /* Convert ASCII to decimal */
1176 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1177 ie[len++] = data;
1178 command += 2;
1179 limit -= 2;
1180 }
1181
1182 /* skip white space */
1183 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1184 {
1185 command++;
1186 limit--;
1187 }
1188
1189 /* extract data */
1190 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1191 (limit > 1))
1192 {
1193 /* Convert ASCII to decimal */
1194 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1195 ie[len++] = data;
1196 command += 2;
1197 limit -= 2;
1198 }
1199
1200 /* fill element id and element length */
1201 ie[0] = IE_EID_VENDOR;
1202 ie[1] = len - 2;
1203
1204 return len;
1205}
1206
1207static tANI_U32 hdd_find_ibss_wpa_ie_pos(tANI_U8 *addIePtr, tANI_U32 addIeLen)
1208{
1209 tANI_U32 ieLenPresent = 0;
1210 int left = addIeLen;
1211 v_U8_t *ptr = addIePtr;
1212 v_U8_t elem_id,elem_len;
1213
1214 while(left >= 2)
1215 {
1216 elem_id = ptr[0];
1217 elem_len = ptr[1];
1218 left -= 2;
1219 if(elem_len > left)
1220 {
1221 hddLog(LOGE,
1222 FL("****Invalid elem_len=%d left=%d*****"),
1223 elem_len,left);
1224 return 0;
1225 }
1226 if ((elem_id == IE_EID_VENDOR) &&
1227 (left >= WPA_OUI_TYPE_SIZE))
1228 {
1229 if (!memcmp(&ptr[2], WPA_OUI_TYPE,
1230 WPA_OUI_TYPE_SIZE))
1231 {
1232 ieLenPresent += elem_len + 2;
1233 return ieLenPresent;
1234 }
1235 }
1236 ieLenPresent += (elem_len + 2);
1237 left -= elem_len;
1238 ptr += (elem_len + 2);
1239 }
1240 return 0;
1241}
1242
1243#endif /* WLAN_FEATURE_RMC */
1244
Rajeev79dbe4c2013-10-05 11:03:42 +05301245#ifdef FEATURE_WLAN_BATCH_SCAN
1246
1247/**---------------------------------------------------------------------------
1248
1249 \brief hdd_extract_assigned_int_from_str() - Extracts assigned integer from
1250 input string
1251
1252 This function extracts assigned integer from string in below format:
1253 "STRING=10" : extracts integer 10 from this string
1254
1255 \param - pInPtr Pointer to input string
1256 \param - base Base for string to int conversion(10 for decimal 16 for hex)
1257 \param - pOutPtr Pointer to variable in which extracted integer needs to be
1258 assigned
1259 \param - pLastArg to tell whether it is last arguement in input string or
1260 not
1261
1262 \return - NULL for failure cases
1263 pointer to next arguement in input string for success cases
1264 --------------------------------------------------------------------------*/
1265static tANI_U8 *
1266hdd_extract_assigned_int_from_str
1267(
1268 tANI_U8 *pInPtr,
1269 tANI_U8 base,
1270 tANI_U32 *pOutPtr,
1271 tANI_U8 *pLastArg
1272)
1273{
1274 int tempInt;
1275 int v = 0;
1276 char buf[32];
1277 int val = 0;
1278 *pLastArg = FALSE;
1279
1280 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1281 if (NULL == pInPtr)
1282 {
1283 return NULL;
1284 }
1285
1286 pInPtr++;
1287
1288 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1289
1290 val = sscanf(pInPtr, "%32s ", buf);
1291 if (val < 0 && val > strlen(pInPtr))
1292 {
1293 return NULL;
1294 }
1295 pInPtr += val;
1296 v = kstrtos32(buf, base, &tempInt);
1297 if (v < 0)
1298 {
1299 return NULL;
1300 }
Rajeev Kumar4d93d842014-01-02 18:31:21 -08001301 if (tempInt < 0)
1302 {
1303 tempInt = 0;
1304 }
Rajeev79dbe4c2013-10-05 11:03:42 +05301305 *pOutPtr = tempInt;
1306
1307 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1308 if (NULL == pInPtr)
1309 {
1310 *pLastArg = TRUE;
1311 return NULL;
1312 }
1313 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1314
1315 return pInPtr;
1316}
1317
1318/**---------------------------------------------------------------------------
1319
1320 \brief hdd_extract_assigned_char_from_str() - Extracts assigned char from
1321 input string
1322
1323 This function extracts assigned character from string in below format:
1324 "STRING=A" : extracts char 'A' from this string
1325
1326 \param - pInPtr Pointer to input string
1327 \param - pOutPtr Pointer to variable in which extracted char needs to be
1328 assigned
1329 \param - pLastArg to tell whether it is last arguement in input string or
1330 not
1331
1332 \return - NULL for failure cases
1333 pointer to next arguement in input string for success cases
1334 --------------------------------------------------------------------------*/
1335static tANI_U8 *
1336hdd_extract_assigned_char_from_str
1337(
1338 tANI_U8 *pInPtr,
1339 tANI_U8 *pOutPtr,
1340 tANI_U8 *pLastArg
1341)
1342{
1343 *pLastArg = FALSE;
1344
1345 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1346 if (NULL == pInPtr)
1347 {
1348 return NULL;
1349 }
1350
1351 pInPtr++;
1352
1353 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1354
1355 *pOutPtr = *pInPtr;
1356
1357 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1358 if (NULL == pInPtr)
1359 {
1360 *pLastArg = TRUE;
1361 return NULL;
1362 }
1363 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1364
1365 return pInPtr;
1366}
1367
1368
1369/**---------------------------------------------------------------------------
1370
1371 \brief hdd_parse_set_batchscan_command () - HDD parse set batch scan command
1372
1373 This function parses set batch scan command in below format:
1374 WLS_BATCHING_SET <space> followed by below arguements
1375 "SCANFREQ=XX" : Optional defaults to 30 sec
1376 "MSCAN=XX" : Required number of scans to attempt to batch
1377 "BESTN=XX" : Best Network (RSSI) defaults to 16
1378 "CHANNEL=<X,Y>" : optional defaults to all channels, can list 'A'or` B.
1379 A. implies only 5 GHz , B. implies only 2.4GHz
1380 "RTT=X" : optional defaults to 0
1381 returns the MIN of MSCAN or the max # of scans firmware can cache or -1 on
1382 error
1383
1384 For example input commands:
1385 1) WLS_BATCHING_SET SCANFREQ=60 MSCAN=10 BESTN=20 CHANNEL=A RTT=0 -> This is
1386 translated into set batch scan with following parameters:
1387 a) Frequence 60 seconds
1388 b) Batch 10 scans together
1389 c) Best RSSI to be 20
1390 d) 5GHz band only
1391 e) RTT is equal to 0
1392
1393 \param - pValue Pointer to input channel list
1394 \param - pHddSetBatchScanReq Pointer to HDD batch scan request structure
1395
1396 \return - 0 for success non-zero for failure
1397
1398 --------------------------------------------------------------------------*/
1399static int
1400hdd_parse_set_batchscan_command
1401(
1402 tANI_U8 *pValue,
1403 tSirSetBatchScanReq *pHddSetBatchScanReq
1404)
1405{
1406 tANI_U8 *inPtr = pValue;
1407 tANI_U8 val = 0;
1408 tANI_U8 lastArg = 0;
Abhishek Singh00b71972016-01-07 10:51:04 +05301409 tANI_U32 nScanFreq = HDD_SET_BATCH_SCAN_DEFAULT_FREQ;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001410 tANI_U32 nMscan;
Abhishek Singh00b71972016-01-07 10:51:04 +05301411 tANI_U32 nBestN = HDD_SET_BATCH_SCAN_BEST_NETWORK;
1412 tANI_U8 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1413 tANI_U32 nRtt = 0;
Rajeev Kumarc933d982013-11-18 20:04:20 -08001414 tANI_U32 temp;
Rajeev79dbe4c2013-10-05 11:03:42 +05301415
Rajeev79dbe4c2013-10-05 11:03:42 +05301416 /*go to space after WLS_BATCHING_SET command*/
1417 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1418 /*no argument after the command*/
1419 if (NULL == inPtr)
1420 {
1421 return -EINVAL;
1422 }
1423
1424 /*no space after the command*/
1425 else if (SPACE_ASCII_VALUE != *inPtr)
1426 {
1427 return -EINVAL;
1428 }
1429
1430 /*removing empty spaces*/
1431 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
1432
1433 /*no argument followed by spaces*/
1434 if ('\0' == *inPtr)
1435 {
1436 return -EINVAL;
1437 }
1438
1439 /*check and parse SCANFREQ*/
1440 if ((strncmp(inPtr, "SCANFREQ", 8) == 0))
1441 {
1442 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001443 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001444
Rajeev Kumarc933d982013-11-18 20:04:20 -08001445 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001446 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001447 nScanFreq = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001448 }
1449
Rajeev79dbe4c2013-10-05 11:03:42 +05301450 if ( (NULL == inPtr) || (TRUE == lastArg))
1451 {
1452 return -EINVAL;
1453 }
1454 }
1455
1456 /*check and parse MSCAN*/
1457 if ((strncmp(inPtr, "MSCAN", 5) == 0))
1458 {
1459 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001460 &nMscan, &lastArg);
1461
1462 if (0 == nMscan)
1463 {
1464 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1465 "invalid MSCAN=%d", nMscan);
1466 return -EINVAL;
1467 }
1468
Rajeev79dbe4c2013-10-05 11:03:42 +05301469 if (TRUE == lastArg)
1470 {
1471 goto done;
1472 }
1473 else if (NULL == inPtr)
1474 {
1475 return -EINVAL;
1476 }
1477 }
1478 else
1479 {
1480 return -EINVAL;
1481 }
1482
1483 /*check and parse BESTN*/
1484 if ((strncmp(inPtr, "BESTN", 5) == 0))
1485 {
1486 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001487 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001488
Rajeev Kumarc933d982013-11-18 20:04:20 -08001489 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001490 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001491 nBestN = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001492 }
1493
Rajeev79dbe4c2013-10-05 11:03:42 +05301494 if (TRUE == lastArg)
1495 {
1496 goto done;
1497 }
1498 else if (NULL == inPtr)
1499 {
1500 return -EINVAL;
1501 }
1502 }
1503
1504 /*check and parse CHANNEL*/
1505 if ((strncmp(inPtr, "CHANNEL", 7) == 0))
1506 {
1507 inPtr = hdd_extract_assigned_char_from_str(inPtr, &val, &lastArg);
Rajeev Kumarc933d982013-11-18 20:04:20 -08001508
Rajeev79dbe4c2013-10-05 11:03:42 +05301509 if (('A' == val) || ('a' == val))
1510 {
c_hpothuebf89732014-02-25 13:00:24 +05301511 ucRfBand = HDD_SET_BATCH_SCAN_5GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301512 }
1513 else if (('B' == val) || ('b' == val))
1514 {
c_hpothuebf89732014-02-25 13:00:24 +05301515 ucRfBand = HDD_SET_BATCH_SCAN_24GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301516 }
1517 else
1518 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001519 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1520 }
1521
1522 if (TRUE == lastArg)
1523 {
1524 goto done;
1525 }
1526 else if (NULL == inPtr)
1527 {
Rajeev79dbe4c2013-10-05 11:03:42 +05301528 return -EINVAL;
1529 }
1530 }
1531
1532 /*check and parse RTT*/
1533 if ((strncmp(inPtr, "RTT", 3) == 0))
1534 {
1535 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001536 &nRtt, &lastArg);
Rajeev79dbe4c2013-10-05 11:03:42 +05301537 if (TRUE == lastArg)
1538 {
1539 goto done;
1540 }
1541 if (NULL == inPtr)
1542 {
1543 return -EINVAL;
1544 }
1545 }
1546
1547
1548done:
1549
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001550 pHddSetBatchScanReq->scanFrequency = nScanFreq;
1551 pHddSetBatchScanReq->numberOfScansToBatch = nMscan;
1552 pHddSetBatchScanReq->bestNetwork = nBestN;
1553 pHddSetBatchScanReq->rfBand = ucRfBand;
1554 pHddSetBatchScanReq->rtt = nRtt;
1555
Rajeev79dbe4c2013-10-05 11:03:42 +05301556 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1557 "Received WLS_BATCHING_SET with SCANFREQ=%d "
1558 "MSCAN=%d BESTN=%d CHANNEL=%d RTT=%d",
1559 pHddSetBatchScanReq->scanFrequency,
1560 pHddSetBatchScanReq->numberOfScansToBatch,
1561 pHddSetBatchScanReq->bestNetwork,
1562 pHddSetBatchScanReq->rfBand,
1563 pHddSetBatchScanReq->rtt);
1564
1565 return 0;
1566}/*End of hdd_parse_set_batchscan_command*/
1567
1568/**---------------------------------------------------------------------------
1569
1570 \brief hdd_set_batch_scan_req_callback () - This function is called after
1571 receiving set batch scan response from FW and it saves set batch scan
1572 response data FW to HDD context and sets the completion event on
1573 which hdd_ioctl is waiting
1574
1575 \param - callbackContext Pointer to HDD adapter
1576 \param - pRsp Pointer to set batch scan response data received from FW
1577
1578 \return - nothing
1579
1580 --------------------------------------------------------------------------*/
1581static void hdd_set_batch_scan_req_callback
1582(
1583 void *callbackContext,
1584 tSirSetBatchScanRsp *pRsp
1585)
1586{
1587 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
1588 tSirSetBatchScanRsp *pHddSetBatchScanRsp;
1589
1590 /*sanity check*/
1591 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
1592 {
1593 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1594 "%s: Invalid pAdapter magic", __func__);
1595 VOS_ASSERT(0);
1596 return;
1597 }
1598 pHddSetBatchScanRsp = &pAdapter->hddSetBatchScanRsp;
1599
1600 /*save set batch scan response*/
1601 pHddSetBatchScanRsp->nScansToBatch = pRsp->nScansToBatch;
1602
1603 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
1604 "Received set batch scan rsp from FW with nScansToBatch=%d",
1605 pHddSetBatchScanRsp->nScansToBatch);
1606
1607 pAdapter->hdd_wait_for_set_batch_scan_rsp = FALSE;
1608 complete(&pAdapter->hdd_set_batch_scan_req_var);
1609
1610 return;
1611}/*End of hdd_set_batch_scan_req_callback*/
1612
1613
1614/**---------------------------------------------------------------------------
1615
1616 \brief hdd_populate_batch_scan_rsp_queue () - This function stores AP meta
1617 info in hdd batch scan response queue
1618
1619 \param - pAdapter Pointer to hdd adapter
1620 \param - pAPMetaInfo Pointer to access point meta info
1621 \param - scanId scan ID of batch scan response
1622 \param - isLastAp tells whether AP is last AP in batch scan response or not
1623
1624 \return - nothing
1625
1626 --------------------------------------------------------------------------*/
1627static void hdd_populate_batch_scan_rsp_queue( hdd_adapter_t* pAdapter,
1628 tpSirBatchScanNetworkInfo pApMetaInfo, tANI_U32 scanId, v_BOOL_t isLastAp)
1629{
1630 tHddBatchScanRsp *pHead;
1631 tHddBatchScanRsp *pNode;
1632 tHddBatchScanRsp *pPrev;
1633 tHddBatchScanRsp *pTemp;
1634 tANI_U8 ssidLen;
1635
1636 /*head of hdd batch scan response queue*/
1637 pHead = pAdapter->pBatchScanRsp;
1638
1639 pNode = (tHddBatchScanRsp *)vos_mem_malloc(sizeof(tHddBatchScanRsp));
1640 if (NULL == pNode)
1641 {
1642 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1643 "%s: Could not allocate memory", __func__);
1644 VOS_ASSERT(0);
1645 return;
1646 }
1647
1648 vos_mem_copy(pNode->ApInfo.bssid, pApMetaInfo->bssid,
1649 sizeof(pNode->ApInfo.bssid));
1650 ssidLen = strlen(pApMetaInfo->ssid);
1651 if (SIR_MAX_SSID_SIZE < ssidLen)
1652 {
1653 /*invalid scan result*/
1654 vos_mem_free(pNode);
1655 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1656 "%s: Invalid AP meta info ssidlen %d", __func__, ssidLen);
1657 return;
1658 }
1659 vos_mem_copy(pNode->ApInfo.ssid, pApMetaInfo->ssid, ssidLen);
1660 /*null terminate ssid*/
1661 pNode->ApInfo.ssid[ssidLen] = '\0';
1662 pNode->ApInfo.ch = pApMetaInfo->ch;
1663 pNode->ApInfo.rssi = pApMetaInfo->rssi;
1664 pNode->ApInfo.age = pApMetaInfo->timestamp;
1665 pNode->ApInfo.batchId = scanId;
1666 pNode->ApInfo.isLastAp = isLastAp;
1667
1668 pNode->pNext = NULL;
1669 if (NULL == pHead)
1670 {
1671 pAdapter->pBatchScanRsp = pNode;
1672 }
1673 else
1674 {
1675 pTemp = pHead;
1676 while (NULL != pTemp)
1677 {
1678 pPrev = pTemp;
1679 pTemp = pTemp->pNext;
1680 }
1681 pPrev->pNext = pNode;
1682 }
1683
1684 return;
1685}/*End of hdd_populate_batch_scan_rsp_queue*/
1686
1687/**---------------------------------------------------------------------------
1688
1689 \brief hdd_batch_scan_result_ind_callback () - This function is called after
1690 receiving batch scan response indication from FW. It saves get batch scan
1691 response data in HDD batch scan response queue. This callback sets the
1692 completion event on which hdd_ioctl is waiting only after getting complete
1693 batch scan response data from FW
1694
1695 \param - callbackContext Pointer to HDD adapter
1696 \param - pRsp Pointer to get batch scan response data received from FW
1697
1698 \return - nothing
1699
1700 --------------------------------------------------------------------------*/
1701static void hdd_batch_scan_result_ind_callback
1702(
1703 void *callbackContext,
1704 void *pRsp
1705)
1706{
1707 v_BOOL_t isLastAp;
1708 tANI_U32 numApMetaInfo;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001709 tANI_U32 numNetworkInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301710 tANI_U32 numberScanList;
1711 tANI_U32 nextScanListOffset;
1712 tANI_U32 nextApMetaInfoOffset;
1713 hdd_adapter_t* pAdapter;
1714 tpSirBatchScanList pScanList;
1715 tpSirBatchScanNetworkInfo pApMetaInfo;
1716 tpSirBatchScanResultIndParam pBatchScanRsp;/*batch scan rsp data from FW*/
1717 tSirSetBatchScanReq *pReq;
1718
1719 pAdapter = (hdd_adapter_t *)callbackContext;
1720 /*sanity check*/
Rajeev Kumar5286bb92013-12-05 11:52:10 -08001721 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
Rajeev79dbe4c2013-10-05 11:03:42 +05301722 {
1723 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1724 "%s: Invalid pAdapter magic", __func__);
1725 VOS_ASSERT(0);
1726 return;
1727 }
1728
1729 /*initialize locals*/
1730 pReq = &pAdapter->hddSetBatchScanReq;
1731 pBatchScanRsp = (tpSirBatchScanResultIndParam)pRsp;
1732 isLastAp = FALSE;
1733 numApMetaInfo = 0;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001734 numNetworkInScanList = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05301735 numberScanList = 0;
1736 nextScanListOffset = 0;
1737 nextApMetaInfoOffset = 0;
1738 pScanList = NULL;
1739 pApMetaInfo = NULL;
1740
1741 if ((NULL == pBatchScanRsp) || (NULL == pReq))
1742 {
1743 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001744 "%s: pBatchScanRsp is %pK pReq %pK", __func__, pBatchScanRsp, pReq);
Rajeev79dbe4c2013-10-05 11:03:42 +05301745 isLastAp = TRUE;
1746 goto done;
1747 }
1748
1749 pAdapter->numScanList = numberScanList = pBatchScanRsp->numScanLists;
1750 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1751 "Batch scan rsp: numberScalList %d", numberScanList);
1752
1753 if ((!numberScanList) || (numberScanList > pReq->numberOfScansToBatch))
1754 {
1755 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1756 "%s: numberScanList %d", __func__, numberScanList);
1757 isLastAp = TRUE;
1758 goto done;
1759 }
1760
1761 while (numberScanList)
1762 {
Rajeev Kumarce651e42013-10-21 18:57:15 -07001763 pScanList = (tpSirBatchScanList)((tANI_U8 *)pBatchScanRsp->scanResults +
Rajeev79dbe4c2013-10-05 11:03:42 +05301764 nextScanListOffset);
1765 if (NULL == pScanList)
1766 {
1767 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001768 "%s: pScanList is %pK", __func__, pScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05301769 isLastAp = TRUE;
1770 goto done;
1771 }
Rajeev Kumarce651e42013-10-21 18:57:15 -07001772 numNetworkInScanList = numApMetaInfo = pScanList->numNetworksInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301773 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumarce651e42013-10-21 18:57:15 -07001774 "Batch scan rsp: numApMetaInfo %d scanId %d",
1775 numApMetaInfo, pScanList->scanId);
Rajeev79dbe4c2013-10-05 11:03:42 +05301776
1777 if ((!numApMetaInfo) || (numApMetaInfo > pReq->bestNetwork))
1778 {
1779 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1780 "%s: numApMetaInfo %d", __func__, numApMetaInfo);
1781 isLastAp = TRUE;
1782 goto done;
1783 }
1784
Rajeev Kumarce651e42013-10-21 18:57:15 -07001785 /*Initialize next AP meta info offset for next scan list*/
1786 nextApMetaInfoOffset = 0;
1787
Rajeev79dbe4c2013-10-05 11:03:42 +05301788 while (numApMetaInfo)
1789 {
1790 pApMetaInfo = (tpSirBatchScanNetworkInfo)(pScanList->scanList +
1791 nextApMetaInfoOffset);
1792 if (NULL == pApMetaInfo)
1793 {
1794 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001795 "%s: pApMetaInfo is %pK", __func__, pApMetaInfo);
Rajeev79dbe4c2013-10-05 11:03:42 +05301796 isLastAp = TRUE;
1797 goto done;
1798 }
1799 /*calculate AP age*/
1800 pApMetaInfo->timestamp =
1801 pBatchScanRsp->timestamp - pApMetaInfo->timestamp;
1802
1803 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussaina7c8e412013-11-20 11:06:42 -08001804 "%s: bssId "MAC_ADDRESS_STR
1805 " ch %d rssi %d timestamp %d", __func__,
1806 MAC_ADDR_ARRAY(pApMetaInfo->bssid),
1807 pApMetaInfo->ch, pApMetaInfo->rssi,
1808 pApMetaInfo->timestamp);
Rajeev79dbe4c2013-10-05 11:03:42 +05301809
1810 /*mark last AP in batch scan response*/
1811 if ((TRUE == pBatchScanRsp->isLastResult) &&
1812 (1 == numberScanList) && (1 == numApMetaInfo))
1813 {
1814 isLastAp = TRUE;
1815 }
1816
1817 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1818 /*store batch scan repsonse in hdd queue*/
1819 hdd_populate_batch_scan_rsp_queue(pAdapter, pApMetaInfo,
1820 pScanList->scanId, isLastAp);
1821 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1822
1823 nextApMetaInfoOffset += sizeof(tSirBatchScanNetworkInfo);
1824 numApMetaInfo--;
1825 }
1826
Rajeev Kumarce651e42013-10-21 18:57:15 -07001827 nextScanListOffset += ((sizeof(tSirBatchScanList) - sizeof(tANI_U8))
1828 + (sizeof(tSirBatchScanNetworkInfo)
1829 * numNetworkInScanList));
Rajeev79dbe4c2013-10-05 11:03:42 +05301830 numberScanList--;
1831 }
1832
1833done:
1834
1835 /*notify hdd_ioctl only if complete batch scan rsp is received and it was
1836 requested from hdd_ioctl*/
1837 if ((TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp) &&
1838 (TRUE == isLastAp))
1839 {
1840 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
1841 complete(&pAdapter->hdd_get_batch_scan_req_var);
1842 }
1843
1844 return;
1845}/*End of hdd_batch_scan_result_ind_callback*/
1846
1847/**---------------------------------------------------------------------------
1848
1849 \brief hdd_format_batch_scan_rsp () - This function formats batch scan
1850 response as per batch scan FR request format by putting proper markers
1851
1852 \param - pDest pointer to destination buffer
1853 \param - cur_len current length
1854 \param - tot_len total remaining size which can be written to user space
1855 \param - pApMetaInfo Pointer to get batch scan response AP meta info
1856 \param - pAdapter Pointer to HDD adapter
1857
1858 \return - ret no of characters written
1859
1860 --------------------------------------------------------------------------*/
1861static tANI_U32
1862hdd_format_batch_scan_rsp
1863(
1864 tANI_U8 *pDest,
1865 tANI_U32 cur_len,
1866 tANI_U32 tot_len,
1867 tHddBatchScanRsp *pApMetaInfo,
1868 hdd_adapter_t* pAdapter
1869)
1870{
1871 tANI_U32 ret = 0;
1872 tANI_U32 rem_len = 0;
1873 tANI_U8 temp_len = 0;
1874 tANI_U8 temp_total_len = 0;
1875 tANI_U8 temp[HDD_BATCH_SCAN_AP_META_INFO_SIZE];
1876 tANI_U8 *pTemp = temp;
1877
1878 /*Batch scan reponse needs to be returned to user space in
1879 following format:
1880 "scancount=X\n" where X is the number of scans in current batch
1881 batch
1882 "trunc\n" optional present if current scan truncated
1883 "bssid=XX:XX:XX:XX:XX:XX\n"
1884 "ssid=XXXX\n"
1885 "freq=X\n" frequency in Mhz
1886 "level=XX\n"
1887 "age=X\n" ms
1888 "dist=X\n" cm (-1 if not available)
1889 "errror=X\n" (-1if not available)
1890 "====\n" (end of ap marker)
1891 "####\n" (end of scan marker)
1892 "----\n" (end of results)*/
1893 /*send scan result in above format to user space based on
1894 available length*/
1895 /*The GET response may have more data than the driver can return in its
1896 buffer. In that case the buffer should be filled to the nearest complete
1897 scan, ending with "%%%%".Subsequent callsshould return the remaining data
1898 starting with the next scan (optional .trunc\n., .apcount=X\n., etc).
1899 The final buffer should end with "----\n"*/
1900
1901 /*sanity*/
1902 if (cur_len > tot_len)
1903 {
1904 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1905 "%s: invaid cur_len %d tot_len %d", __func__, cur_len, tot_len);
1906 return 0;
1907 }
1908 else
1909 {
1910 rem_len = (tot_len - cur_len);
1911 }
1912
1913 /*end scan marker*/
1914 if (pApMetaInfo->ApInfo.batchId != pAdapter->prev_batch_id)
1915 {
1916 temp_len = snprintf(pTemp, sizeof(temp), "####\n");
1917 pTemp += temp_len;
1918 temp_total_len += temp_len;
1919 }
1920
1921 /*bssid*/
1922 temp_len = snprintf(pTemp, sizeof(temp),
1923 "bssid=0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n",
1924 pApMetaInfo->ApInfo.bssid[0], pApMetaInfo->ApInfo.bssid[1],
1925 pApMetaInfo->ApInfo.bssid[2], pApMetaInfo->ApInfo.bssid[3],
1926 pApMetaInfo->ApInfo.bssid[4], pApMetaInfo->ApInfo.bssid[5]);
1927 pTemp += temp_len;
1928 temp_total_len += temp_len;
1929
1930 /*ssid*/
1931 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "ssid=%s\n",
1932 pApMetaInfo->ApInfo.ssid);
1933 pTemp += temp_len;
1934 temp_total_len += temp_len;
1935
1936 /*freq*/
1937 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "freq=%d\n",
Rajeev Kumarc40f7512013-11-04 14:13:23 -08001938 sme_ChnToFreq(pApMetaInfo->ApInfo.ch));
Rajeev79dbe4c2013-10-05 11:03:42 +05301939 pTemp += temp_len;
1940 temp_total_len += temp_len;
1941
1942 /*level*/
1943 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "level=%d\n",
1944 pApMetaInfo->ApInfo.rssi);
1945 pTemp += temp_len;
1946 temp_total_len += temp_len;
1947
1948 /*age*/
Jeff Johnson02797792013-10-26 19:17:13 -07001949 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "age=%d\n",
Rajeev79dbe4c2013-10-05 11:03:42 +05301950 pApMetaInfo->ApInfo.age);
1951 pTemp += temp_len;
1952 temp_total_len += temp_len;
1953
1954 /*dist*/
1955 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "dist=-1\n");
1956 pTemp += temp_len;
1957 temp_total_len += temp_len;
1958
1959 /*error*/
1960 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "error=-1\n");
1961 pTemp += temp_len;
1962 temp_total_len += temp_len;
1963
1964 /*end AP marker*/
1965 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "====\n");
1966 pTemp += temp_len;
1967 temp_total_len += temp_len;
1968
1969 /*last AP in batch scan response*/
1970 if(TRUE == pApMetaInfo->ApInfo.isLastAp)
1971 {
1972 /*end scan marker*/
1973 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "####\n");
1974 pTemp += temp_len;
1975 temp_total_len += temp_len;
1976
1977 /*end batch scan result marker*/
1978 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "----\n");
1979 pTemp += temp_len;
1980 temp_total_len += temp_len;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08001981
Rajeev79dbe4c2013-10-05 11:03:42 +05301982 }
1983
1984 if (temp_total_len < rem_len)
1985 {
1986 ret = temp_total_len + 1;
1987 strlcpy(pDest, temp, ret);
1988 pAdapter->isTruncated = FALSE;
1989 }
1990 else
1991 {
1992 pAdapter->isTruncated = TRUE;
1993 if (rem_len >= strlen("%%%%"))
1994 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001995 ret = snprintf(pDest, sizeof(temp), "%%%%");
Rajeev79dbe4c2013-10-05 11:03:42 +05301996 }
Rajeev Kumarc933d982013-11-18 20:04:20 -08001997 else
Rajeev79dbe4c2013-10-05 11:03:42 +05301998 {
1999 ret = 0;
2000 }
2001 }
2002
2003 return ret;
2004
2005}/*End of hdd_format_batch_scan_rsp*/
2006
2007/**---------------------------------------------------------------------------
2008
2009 \brief hdd_populate_user_batch_scan_rsp() - This function populates user data
2010 buffer starting with head of hdd batch scan response queue
2011
2012 \param - pAdapter Pointer to HDD adapter
2013 \param - pDest Pointer to user data buffer
2014 \param - cur_len current offset in user buffer
2015 \param - rem_len remaining no of bytes in user buffer
2016
2017 \return - number of bytes written in user buffer
2018
2019 --------------------------------------------------------------------------*/
2020
2021tANI_U32 hdd_populate_user_batch_scan_rsp
2022(
2023 hdd_adapter_t* pAdapter,
2024 tANI_U8 *pDest,
2025 tANI_U32 cur_len,
2026 tANI_U32 rem_len
2027)
2028{
2029 tHddBatchScanRsp *pHead;
2030 tHddBatchScanRsp *pPrev;
2031 tANI_U32 len;
2032
Rajeev79dbe4c2013-10-05 11:03:42 +05302033 pAdapter->isTruncated = FALSE;
2034
2035 /*head of hdd batch scan response queue*/
2036 pHead = pAdapter->pBatchScanRsp;
2037 while (pHead)
2038 {
2039 len = hdd_format_batch_scan_rsp(pDest, cur_len, rem_len, pHead,
2040 pAdapter);
2041 pDest += len;
Rajeev Kumar292d2bb2013-10-23 15:01:44 -07002042 pDest--;
Rajeev79dbe4c2013-10-05 11:03:42 +05302043 cur_len += len;
2044 if(TRUE == pAdapter->isTruncated)
2045 {
2046 /*result is truncated return rest of scan rsp in next req*/
2047 cur_len = rem_len;
2048 break;
2049 }
2050 pPrev = pHead;
2051 pHead = pHead->pNext;
2052 pAdapter->pBatchScanRsp = pHead;
Rajeev Kumarbe17d8b2014-01-10 15:39:45 -08002053 if (TRUE == pPrev->ApInfo.isLastAp)
2054 {
2055 pAdapter->prev_batch_id = 0;
2056 }
2057 else
2058 {
2059 pAdapter->prev_batch_id = pPrev->ApInfo.batchId;
2060 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302061 vos_mem_free(pPrev);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002062 pPrev = NULL;
Rajeev79dbe4c2013-10-05 11:03:42 +05302063 }
2064
2065 return cur_len;
2066}/*End of hdd_populate_user_batch_scan_rsp*/
2067
2068/**---------------------------------------------------------------------------
2069
2070 \brief hdd_return_batch_scan_rsp_to_user () - This function returns batch
2071 scan response data from HDD queue to user space
2072 It does following in detail:
2073 a) if HDD has enough data in its queue then it 1st copies data to user
2074 space and then send get batch scan indication message to FW. In this
2075 case it does not wait on any event and batch scan response data will
2076 be populated in HDD response queue in MC thread context after receiving
2077 indication from FW
2078 b) else send get batch scan indication message to FW and wait on an event
2079 which will be set once HDD receives complete batch scan response from
2080 FW and then this function returns batch scan response to user space
2081
2082 \param - pAdapter Pointer to HDD adapter
2083 \param - pPrivData Pointer to priv_data
2084
2085 \return - 0 for success -EFAULT for failure
2086
2087 --------------------------------------------------------------------------*/
2088
2089int hdd_return_batch_scan_rsp_to_user
2090(
2091 hdd_adapter_t* pAdapter,
2092 hdd_priv_data_t *pPrivData,
2093 tANI_U8 *command
2094)
2095{
2096 tANI_U8 *pDest;
2097 tANI_U32 count = 0;
2098 tANI_U32 len = 0;
2099 tANI_U32 cur_len = 0;
2100 tANI_U32 rem_len = 0;
2101 eHalStatus halStatus;
2102 unsigned long rc;
2103 tSirTriggerBatchScanResultInd *pReq;
2104
2105 pReq = &pAdapter->hddTriggerBatchScanResultInd;
2106 pReq->param = 0;/*batch scan client*/
2107 pDest = (tANI_U8 *)(command + pPrivData->used_len);
2108 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
2109
2110 cur_len = pPrivData->used_len;
2111 if (pPrivData->total_len > pPrivData->used_len)
2112 {
2113 rem_len = pPrivData->total_len - pPrivData->used_len;
2114 }
2115 else
2116 {
2117 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2118 "%s: Invalid user data buffer total_len %d used_len %d",
2119 __func__, pPrivData->total_len, pPrivData->used_len);
2120 return -EFAULT;
2121 }
2122
2123 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2124 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2125 cur_len, rem_len);
2126 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2127
2128 /*enough scan result available in cache to return to user space or
2129 scan result needs to be fetched 1st from fw and then return*/
Rajeev Kumar99db6262013-11-11 15:23:36 -08002130 if (len == cur_len)
Rajeev79dbe4c2013-10-05 11:03:42 +05302131 {
2132 pAdapter->hdd_wait_for_get_batch_scan_rsp = TRUE;
2133 halStatus = sme_TriggerBatchScanResultInd(
2134 WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2135 pAdapter->sessionId, hdd_batch_scan_result_ind_callback,
2136 pAdapter);
2137 if ( eHAL_STATUS_SUCCESS == halStatus )
2138 {
2139 if (TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp)
2140 {
2141 INIT_COMPLETION(pAdapter->hdd_get_batch_scan_req_var);
2142 rc = wait_for_completion_timeout(
2143 &pAdapter->hdd_get_batch_scan_req_var,
2144 msecs_to_jiffies(HDD_GET_BATCH_SCAN_RSP_TIME_OUT));
Abhishek Singh00b71972016-01-07 10:51:04 +05302145 if (0 >= rc)
Rajeev79dbe4c2013-10-05 11:03:42 +05302146 {
2147 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Abhishek Singh00b71972016-01-07 10:51:04 +05302148 "%s: wait on hdd_get_batch_scan_req_var failed %ld",
2149 __func__, rc);
Rajeev79dbe4c2013-10-05 11:03:42 +05302150 return -EFAULT;
2151 }
2152 }
2153
2154 len = snprintf(pDest, HDD_BATCH_SCAN_AP_META_INFO_SIZE,
Jeff Johnson02797792013-10-26 19:17:13 -07002155 "scancount=%u\n", pAdapter->numScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05302156 pDest += len;
2157 cur_len += len;
2158
2159 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2160 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2161 cur_len, rem_len);
2162 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2163
2164 count = 0;
2165 len = (len - pPrivData->used_len);
2166 pDest = (command + pPrivData->used_len);
2167 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002168 "NEW BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302169 while(count < len)
2170 {
2171 printk("%c", *(pDest + count));
2172 count++;
2173 }
2174 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2175 "%s: copy %d data to user buffer", __func__, len);
2176 if (copy_to_user(pPrivData->buf, pDest, len))
2177 {
2178 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2179 "%s: failed to copy data to user buffer", __func__);
2180 return -EFAULT;
2181 }
2182 }
2183 else
2184 {
2185 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2186 "sme_GetBatchScanScan returned failure halStatus %d",
2187 halStatus);
2188 return -EINVAL;
2189 }
2190 }
2191 else
2192 {
Rajeev79dbe4c2013-10-05 11:03:42 +05302193 count = 0;
2194 len = (len - pPrivData->used_len);
2195 pDest = (command + pPrivData->used_len);
2196 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002197 "REMAINING TRUNCATED BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302198 while(count < len)
2199 {
2200 printk("%c", *(pDest + count));
2201 count++;
2202 }
Rajeev Kumar99db6262013-11-11 15:23:36 -08002203 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2204 "%s: copy %d data to user buffer", __func__, len);
Rajeev79dbe4c2013-10-05 11:03:42 +05302205 if (copy_to_user(pPrivData->buf, pDest, len))
2206 {
2207 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2208 "%s: failed to copy data to user buffer", __func__);
2209 return -EFAULT;
2210 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302211 }
2212
2213 return 0;
2214} /*End of hdd_return_batch_scan_rsp_to_user*/
2215
Rajeev Kumar8b373292014-01-08 20:36:55 -08002216/**---------------------------------------------------------------------------
2217
2218 \brief hdd_handle_batch_scan_ioctl () - This function handles WLS_BATCHING
2219 IOCTLs from user space. Following BATCH SCAN DEV IOCTs are handled:
2220 WLS_BATCHING VERSION
2221 WLS_BATCHING SET
2222 WLS_BATCHING GET
2223 WLS_BATCHING STOP
2224
2225 \param - pAdapter Pointer to HDD adapter
2226 \param - pPrivdata Pointer to priv_data
2227 \param - command Pointer to command
2228
2229 \return - 0 for success -EFAULT for failure
2230
2231 --------------------------------------------------------------------------*/
2232
2233int hdd_handle_batch_scan_ioctl
2234(
2235 hdd_adapter_t *pAdapter,
2236 hdd_priv_data_t *pPrivdata,
2237 tANI_U8 *command
2238)
2239{
2240 int ret = 0;
Yue Mae36e3552014-03-05 17:06:20 -08002241 hdd_context_t *pHddCtx;
2242
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302243 ENTER();
2244
Yue Mae36e3552014-03-05 17:06:20 -08002245 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2246 ret = wlan_hdd_validate_context(pHddCtx);
2247 if (ret)
2248 {
Yue Mae36e3552014-03-05 17:06:20 -08002249 goto exit;
2250 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002251
2252 if (strncmp(command, "WLS_BATCHING VERSION", 20) == 0)
2253 {
2254 char extra[32];
2255 tANI_U8 len = 0;
2256 tANI_U8 version = HDD_BATCH_SCAN_VERSION;
2257
2258 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2259 {
2260 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2261 "%s: Batch scan feature is not supported by FW", __func__);
2262 ret = -EINVAL;
2263 goto exit;
2264 }
2265
2266 len = scnprintf(extra, sizeof(extra), "WLS_BATCHING_VERSION %d",
2267 version);
2268 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2269 {
2270 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2271 "%s: failed to copy data to user buffer", __func__);
2272 ret = -EFAULT;
2273 goto exit;
2274 }
2275 ret = HDD_BATCH_SCAN_VERSION;
2276 }
2277 else if (strncmp(command, "WLS_BATCHING SET", 16) == 0)
2278 {
2279 int status;
2280 tANI_U8 *value = (command + 16);
2281 eHalStatus halStatus;
2282 unsigned long rc;
2283 tSirSetBatchScanReq *pReq = &pAdapter->hddSetBatchScanReq;
2284 tSirSetBatchScanRsp *pRsp = &pAdapter->hddSetBatchScanRsp;
2285
2286 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2287 {
2288 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2289 "%s: Batch scan feature is not supported by FW", __func__);
2290 ret = -EINVAL;
2291 goto exit;
2292 }
2293
2294 if ((WLAN_HDD_INFRA_STATION != pAdapter->device_mode) &&
2295 (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) &&
2296 (WLAN_HDD_P2P_GO != pAdapter->device_mode) &&
2297 (WLAN_HDD_P2P_DEVICE != pAdapter->device_mode))
2298 {
2299 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302300 "Received WLS_BATCHING SET command in invalid mode %s (%d) "
Rajeev Kumar8b373292014-01-08 20:36:55 -08002301 "WLS_BATCHING_SET is only allowed in infra STA/P2P client mode",
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302302 hdd_device_modetoString(pAdapter->device_mode),
2303 pAdapter->device_mode);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002304 ret = -EINVAL;
2305 goto exit;
2306 }
2307
2308 status = hdd_parse_set_batchscan_command(value, pReq);
2309 if (status)
2310 {
2311 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2312 "Invalid WLS_BATCHING SET command");
2313 ret = -EINVAL;
2314 goto exit;
2315 }
2316
2317
2318 pAdapter->hdd_wait_for_set_batch_scan_rsp = TRUE;
2319 halStatus = sme_SetBatchScanReq(WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2320 pAdapter->sessionId, hdd_set_batch_scan_req_callback,
2321 pAdapter);
2322
2323 if ( eHAL_STATUS_SUCCESS == halStatus )
2324 {
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302325 char extra[32];
2326 tANI_U8 len = 0;
2327 tANI_U8 mScan = 0;
2328
Rajeev Kumar8b373292014-01-08 20:36:55 -08002329 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2330 "sme_SetBatchScanReq returned success halStatus %d",
2331 halStatus);
2332 if (TRUE == pAdapter->hdd_wait_for_set_batch_scan_rsp)
2333 {
2334 INIT_COMPLETION(pAdapter->hdd_set_batch_scan_req_var);
2335 rc = wait_for_completion_timeout(
2336 &pAdapter->hdd_set_batch_scan_req_var,
2337 msecs_to_jiffies(HDD_SET_BATCH_SCAN_REQ_TIME_OUT));
2338 if (0 == rc)
2339 {
2340 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2341 "%s: Timeout waiting for set batch scan to complete",
2342 __func__);
2343 ret = -EINVAL;
2344 goto exit;
2345 }
2346 }
2347 if ( !pRsp->nScansToBatch )
2348 {
2349 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2350 "%s: Received set batch scan failure response from FW",
2351 __func__);
2352 ret = -EINVAL;
2353 goto exit;
2354 }
2355 /*As per the Batch Scan Framework API we should return the MIN of
2356 either MSCAN or the max # of scans firmware can cache*/
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302357 mScan = MIN(pReq->numberOfScansToBatch , pRsp->nScansToBatch);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002358
2359 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STARTED;
2360
2361 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2362 "%s: request MSCAN %d response MSCAN %d ret %d",
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302363 __func__, pReq->numberOfScansToBatch, pRsp->nScansToBatch, mScan);
2364 len = scnprintf(extra, sizeof(extra), "%d", mScan);
2365 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2366 {
2367 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2368 "%s: failed to copy MSCAN value to user buffer", __func__);
2369 ret = -EFAULT;
2370 goto exit;
2371 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002372 }
2373 else
2374 {
2375 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2376 "sme_SetBatchScanReq returned failure halStatus %d",
2377 halStatus);
2378 ret = -EINVAL;
2379 goto exit;
2380 }
2381 }
2382 else if (strncmp(command, "WLS_BATCHING STOP", 17) == 0)
2383 {
2384 eHalStatus halStatus;
2385 tSirStopBatchScanInd *pInd = &pAdapter->hddStopBatchScanInd;
2386 pInd->param = 0;
2387
2388 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2389 {
2390 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2391 "%s: Batch scan feature is not supported by FW", __func__);
2392 ret = -EINVAL;
2393 goto exit;
2394 }
2395
2396 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2397 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302398 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002399 "Batch scan is not yet enabled batch scan state %d",
2400 pAdapter->batchScanState);
2401 ret = -EINVAL;
2402 goto exit;
2403 }
2404
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002405 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2406 hdd_deinit_batch_scan(pAdapter);
2407 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2408
Rajeev Kumar8b373292014-01-08 20:36:55 -08002409 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
2410
2411 halStatus = sme_StopBatchScanInd(WLAN_HDD_GET_HAL_CTX(pAdapter), pInd,
2412 pAdapter->sessionId);
2413 if ( eHAL_STATUS_SUCCESS == halStatus )
2414 {
2415 ret = 0;
2416 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2417 "sme_StopBatchScanInd returned success halStatus %d",
2418 halStatus);
2419 }
2420 else
2421 {
2422 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2423 "sme_StopBatchScanInd returned failure halStatus %d",
2424 halStatus);
2425 ret = -EINVAL;
2426 goto exit;
2427 }
2428 }
2429 else if (strncmp(command, "WLS_BATCHING GET", 16) == 0)
2430 {
2431 tANI_U32 remain_len;
2432
2433 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2434 {
2435 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2436 "%s: Batch scan feature is not supported by FW", __func__);
2437 ret = -EINVAL;
2438 goto exit;
2439 }
2440
2441 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2442 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302443 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002444 "Batch scan is not yet enabled could not return results"
2445 "Batch Scan state %d",
2446 pAdapter->batchScanState);
2447 ret = -EINVAL;
2448 goto exit;
2449 }
2450
2451 pPrivdata->used_len = 16;
2452 remain_len = pPrivdata->total_len - pPrivdata->used_len;
2453 if (remain_len < pPrivdata->total_len)
2454 {
2455 /*Clear previous batch scan response data if any*/
2456 vos_mem_zero((tANI_U8 *)(command + pPrivdata->used_len), remain_len);
2457 }
2458 else
2459 {
2460 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2461 "Invalid total length from user space can't fetch batch"
2462 " scan response total_len %d used_len %d remain len %d",
2463 pPrivdata->total_len, pPrivdata->used_len, remain_len);
2464 ret = -EINVAL;
2465 goto exit;
2466 }
2467 ret = hdd_return_batch_scan_rsp_to_user(pAdapter, pPrivdata, command);
2468 }
2469
2470exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302471 EXIT();
Rajeev Kumar8b373292014-01-08 20:36:55 -08002472 return ret;
2473}
2474
2475
Rajeev79dbe4c2013-10-05 11:03:42 +05302476#endif/*End of FEATURE_WLAN_BATCH_SCAN*/
2477
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302478#if defined(WLAN_FEATURE_VOWIFI_11R) || defined(FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
2479/**
2480 * hdd_assign_handoff_src_reassoc - Set handoff source as REASSOC
2481 * to Handoff request
2482 * @handoffInfo: Pointer to Handoff request
2483 * @src: enum of handoff_src
2484 * Return: None
2485 */
2486#ifndef QCA_WIFI_ISOC
2487static inline void hdd_assign_handoff_src_reassoc(tCsrHandoffRequest
2488 *handoffInfo, handoff_src src)
2489{
2490 handoffInfo->src = src;
2491}
2492#else
2493static inline void hdd_assign_handoff_src_reassoc(tCsrHandoffRequest
2494 *handoffInfo, handoff_src src)
2495{
2496}
2497#endif
2498
2499/**
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302500 * hdd_reassoc() - perform a user space-directed reassoc
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302501 *
2502 * @pAdapter: Adapter upon which the command was received
2503 * @bssid: BSSID with which to reassociate
2504 * @channel: channel upon which to reassociate
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302505 * @src: The source for the trigger of this action
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302506 *
2507 * Return: 0 for success non-zero for failure
2508 */
2509#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Selvaraj, Sridhar8ecb4192016-06-23 17:50:49 +05302510int hdd_reassoc(hdd_adapter_t *pAdapter, const tANI_U8 *bssid,
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302511 const tANI_U8 channel, const handoff_src src)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302512{
2513 hdd_station_ctx_t *pHddStaCtx;
2514 tCsrHandoffRequest handoffInfo;
2515 hdd_context_t *pHddCtx = NULL;
2516 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2517
2518 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2519
2520 /* if not associated, no need to proceed with reassoc */
2521 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
2522 hddLog(LOG1, FL("Not associated"));
2523 return -EINVAL;
2524 }
2525
2526 /* if the target bssid is same as currently associated AP,
2527 then no need to proceed with reassoc */
2528 if (!memcmp(bssid, pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr))) {
2529 hddLog(LOG1, FL("Reassoc BSSID is same as currently associated AP bssid"));
2530 return -EINVAL;
2531 }
2532
2533 /* Check channel number is a valid channel number */
2534 if (VOS_STATUS_SUCCESS !=
2535 wlan_hdd_validate_operation_channel(pAdapter, channel)) {
2536 hddLog(LOGE, FL("Invalid Channel %d"), channel);
2537 return -EINVAL;
2538 }
2539
2540 /* Proceed with reassoc */
2541 handoffInfo.channel = channel;
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302542 hdd_assign_handoff_src_reassoc(&handoffInfo, src);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302543 memcpy(handoffInfo.bssid, bssid, sizeof(tSirMacAddr));
2544 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
2545 return 0;
2546}
2547#else
Selvaraj, Sridhar8ecb4192016-06-23 17:50:49 +05302548int hdd_reassoc(hdd_adapter_t *pAdapter, const tANI_U8 *bssid,
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302549 const tANI_U8 channel, const handoff_src src)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302550{
2551 return -EPERM;
2552}
2553#endif
2554
2555/**
2556 * hdd_parse_reassoc_v1() - parse version 1 of the REASSOC command
2557 * This function parses the v1 REASSOC command with the format
2558 * REASSOC xx:xx:xx:xx:xx:xx CH where "xx:xx:xx:xx:xx:xx" is the
2559 * Hex-ASCII representation of the BSSID and CH is the ASCII
2560 * representation of the channel. For example
2561 * REASSOC 00:0a:0b:11:22:33 48
2562 *
2563 * @pAdapter: Adapter upon which the command was received
2564 * @command: ASCII text command that was received
2565 *
2566 * Return: 0 for success non-zero for failure
2567 */
2568static int
2569hdd_parse_reassoc_v1(hdd_adapter_t *pAdapter, const char *command)
2570{
2571 tANI_U8 channel = 0;
2572 tSirMacAddr bssid;
2573 int ret;
2574
2575 ret = hdd_parse_reassoc_command_v1_data(command, bssid, &channel);
2576 if (ret)
2577 hddLog(LOGE, FL("Failed to parse reassoc command data"));
2578 else
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302579 ret = hdd_reassoc(pAdapter, bssid, channel, REASSOC);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302580
2581 return ret;
2582}
2583
2584/**
2585 * hdd_parse_reassoc_v2() - parse version 2 of the REASSOC command
2586 * This function parses the v2 REASSOC command with the format
2587 * REASSOC <android_wifi_reassoc_params>
2588 *
2589 * @pAdapter: Adapter upon which the command was received
2590 * @command: command that was received, ASCII command followed
2591 * by binary data
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302592 * @total_len: Total length of the command received
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302593 *
2594 * Return: 0 for success non-zero for failure
2595 */
2596static int
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302597hdd_parse_reassoc_v2(hdd_adapter_t *pAdapter, const char *command,
2598 int total_len)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302599{
2600 struct android_wifi_reassoc_params params;
2601 tSirMacAddr bssid;
2602 int ret;
2603
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302604 if (total_len < sizeof(params) + 8) {
2605 hddLog(LOGE, FL("Invalid command length"));
2606 return -EINVAL;
2607 }
2608
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302609 /* The params are located after "REASSOC " */
2610 memcpy(&params, command + 8, sizeof(params));
2611
2612 if (!mac_pton(params.bssid, (u8 *)&bssid)) {
2613 hddLog(LOGE, FL("MAC address parsing failed"));
2614 ret = -EINVAL;
2615 } else {
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302616 ret = hdd_reassoc(pAdapter, bssid, params.channel, REASSOC);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302617 }
2618 return ret;
2619}
2620
2621/**
2622 * hdd_parse_reassoc() - parse the REASSOC command
2623 * There are two different versions of the REASSOC command.Version 1
2624 * of the command contains a parameter list that is ASCII characters
2625 * whereas version 2 contains a combination of ASCII and binary
2626 * payload. Determine if a version 1 or a version 2 command is being
2627 * parsed by examining the parameters, and then dispatch the parser
2628 * that is appropriate for the command.
2629 *
2630 * @pAdapter: Adapter upon which the command was received
2631 * @command: command that was received
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302632 * @total_len: Total length of the command received
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302633 *
2634 * Return: 0 for success non-zero for failure
2635 */
2636static int
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302637hdd_parse_reassoc(hdd_adapter_t *pAdapter, const char *command, int total_len)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302638{
2639 int ret;
2640
2641 /*
2642 * both versions start with "REASSOC"
2643 * v1 has a bssid and channel # as an ASCII string
2644 * REASSOC xx:xx:xx:xx:xx:xx CH
2645 * v2 has a C struct
2646 * REASSOC <binary c struct>
2647 *
2648 * The first field in the v2 struct is also the bssid in ASCII.
2649 * But in the case of a v2 message the BSSID is NUL-terminated.
2650 * Hence we can peek at that offset to see if this is V1 or V2
2651 * REASSOC xx:xx:xx:xx:xx:xx*
2652 * 1111111111222222
2653 * 01234567890123456789012345
2654 */
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302655
2656 if (total_len < 26) {
2657 hddLog(LOGE, FL("Invalid command (total_len=%d)"), total_len);
2658 return -EINVAL;
2659 }
2660
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302661 if (command[25])
2662 ret = hdd_parse_reassoc_v1(pAdapter, command);
2663 else
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302664 ret = hdd_parse_reassoc_v2(pAdapter, command, total_len);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302665
2666 return ret;
2667}
2668#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE FEATURE_WLAN_LFR */
2669
c_hpothu92367912014-05-01 15:18:17 +05302670static void getBcnMissRateCB(VOS_STATUS status, int bcnMissRate, void *data)
2671{
c_hpothu39eb1e32014-06-26 16:31:50 +05302672 bcnMissRateContext_t *pCBCtx;
2673
2674 if (NULL == data)
2675 {
2676 hddLog(VOS_TRACE_LEVEL_ERROR, FL("argument data is NULL"));
2677 return;
2678 }
c_hpothu92367912014-05-01 15:18:17 +05302679
2680 /* there is a race condition that exists between this callback
2681 function and the caller since the caller could time out either
2682 before or while this code is executing. we use a spinlock to
2683 serialize these actions */
2684 spin_lock(&hdd_context_lock);
2685
c_hpothu39eb1e32014-06-26 16:31:50 +05302686 pCBCtx = (bcnMissRateContext_t *)data;
c_hpothu92367912014-05-01 15:18:17 +05302687 gbcnMissRate = -1;
2688
c_hpothu39eb1e32014-06-26 16:31:50 +05302689 if (pCBCtx->magic != BCN_MISS_RATE_CONTEXT_MAGIC)
c_hpothu92367912014-05-01 15:18:17 +05302690 {
2691 hddLog(VOS_TRACE_LEVEL_ERROR,
c_hpothu39eb1e32014-06-26 16:31:50 +05302692 FL("invalid context magic: %08x"), pCBCtx->magic);
c_hpothu92367912014-05-01 15:18:17 +05302693 spin_unlock(&hdd_context_lock);
2694 return ;
2695 }
2696
2697 if (VOS_STATUS_SUCCESS == status)
2698 {
c_hpothu39eb1e32014-06-26 16:31:50 +05302699 gbcnMissRate = bcnMissRate;
c_hpothu92367912014-05-01 15:18:17 +05302700 }
c_hpothu39eb1e32014-06-26 16:31:50 +05302701 else
2702 {
2703 hddLog(VOS_TRACE_LEVEL_ERROR, FL("failed to get bcnMissRate"));
2704 }
2705
c_hpothu92367912014-05-01 15:18:17 +05302706 complete(&(pCBCtx->completion));
2707 spin_unlock(&hdd_context_lock);
2708
2709 return;
2710}
2711
Abhishek Singh08aa7762014-12-16 13:59:03 +05302712void hdd_FWStatisCB( VOS_STATUS status,
2713 tSirFwStatsResult *fwStatsResult, void *pContext )
Satyanarayana Dash72806012014-12-02 14:30:08 +05302714{
2715 fwStatsContext_t *fwStatsCtx;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302716 hdd_adapter_t *pAdapter;
2717
2718 hddLog(VOS_TRACE_LEVEL_INFO, FL(" with status = %d"),status);
2719
Abhishek Singh08aa7762014-12-16 13:59:03 +05302720 if (NULL == pContext)
Satyanarayana Dash72806012014-12-02 14:30:08 +05302721 {
2722 hddLog(VOS_TRACE_LEVEL_ERROR, FL("argument data is NULL"));
2723 return;
2724 }
2725 /* there is a race condition that exists between this callback
2726 function and the caller since the caller could time out either
2727 before or while this code is executing. we use a spinlock to
2728 serialize these actions */
2729 spin_lock(&hdd_context_lock);
Abhishek Singh08aa7762014-12-16 13:59:03 +05302730 fwStatsCtx = (fwStatsContext_t *) pContext;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302731 if (fwStatsCtx->magic != FW_STATS_CONTEXT_MAGIC)
2732 {
2733 hddLog(VOS_TRACE_LEVEL_ERROR,
2734 FL("invalid context magic: %08x"), fwStatsCtx->magic);
2735 spin_unlock(&hdd_context_lock);
2736 return;
2737 }
2738 pAdapter = fwStatsCtx->pAdapter;
2739 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2740 {
2741 hddLog(VOS_TRACE_LEVEL_ERROR,
2742 FL("pAdapter returned is NULL or invalid"));
2743 spin_unlock(&hdd_context_lock);
2744 return;
2745 }
2746 pAdapter->fwStatsRsp.type = 0;
Abhishek Singh08aa7762014-12-16 13:59:03 +05302747 if ((VOS_STATUS_SUCCESS == status) && (NULL != fwStatsResult))
Satyanarayana Dash72806012014-12-02 14:30:08 +05302748 {
Satyanarayana Dash72806012014-12-02 14:30:08 +05302749 switch( fwStatsResult->type )
2750 {
2751 case FW_UBSP_STATS:
2752 {
Abhishek Singh08aa7762014-12-16 13:59:03 +05302753 memcpy(&pAdapter->fwStatsRsp,fwStatsResult,sizeof(tSirFwStatsResult));
Satyanarayana Dash72806012014-12-02 14:30:08 +05302754 hddLog(VOS_TRACE_LEVEL_INFO,
2755 FL("ubsp_enter_cnt = %d ubsp_jump_ddr_cnt = %d"),
Abhishek Singh08aa7762014-12-16 13:59:03 +05302756 pAdapter->fwStatsRsp.fwStatsData.ubspStats.ubsp_enter_cnt,
2757 pAdapter->fwStatsRsp.fwStatsData.ubspStats.ubsp_jump_ddr_cnt);
Satyanarayana Dash72806012014-12-02 14:30:08 +05302758 }
2759 break;
2760 default:
2761 {
2762 hddLog(VOS_TRACE_LEVEL_ERROR,
2763 FL(" No handling for stats type %d"),fwStatsResult->type);
2764 }
2765 }
2766 }
2767 complete(&(fwStatsCtx->completion));
2768 spin_unlock(&hdd_context_lock);
2769 return;
2770}
2771
jge35567202017-06-21 16:39:38 +08002772/*
2773 *hdd_parse_setmaxtxpower_command() - HDD Parse MAXTXPOWER command
2774 *@pValue Pointer to MAXTXPOWER command
2775 *@pTxPower Pointer to tx power
2776 *
2777 *This function parses the MAXTXPOWER command passed in the format
2778 * MAXTXPOWER<space>X(Tx power in dbm)
2779 * For example input commands:
2780 * 1) MAXTXPOWER -8 -> This is translated into set max TX power to -8 dbm
2781 * 2) MAXTXPOWER -23 -> This is translated into set max TX power to -23 dbm
2782 *
2783 *return - 0 for success non-zero for failure
2784 */
2785static int hdd_parse_setmaxtxpower_command(unsigned char *pValue, int *pTxPower)
2786{
2787 unsigned char *inPtr = pValue;
2788 int tempInt;
2789 int v = 0;
2790 *pTxPower = 0;
2791
2792 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
2793 /* no argument after the command */
2794 if (NULL == inPtr)
2795 return -EINVAL;
2796 /* no space after the command */
2797 else if (SPACE_ASCII_VALUE != *inPtr)
2798 return -EINVAL;
2799
2800 /* removing empty spaces */
2801 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
2802
2803 /* no argument followed by spaces */
2804 if ('\0' == *inPtr)
2805 return 0;
2806
2807 v = kstrtos32(inPtr, 10, &tempInt);
2808
2809 /* Range checking for passed parameter */
2810 if ((tempInt < HDD_MIN_TX_POWER) || (tempInt > HDD_MAX_TX_POWER))
2811 return -EINVAL;
2812
2813 *pTxPower = tempInt;
2814
2815 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2816 "SETMAXTXPOWER: %d", *pTxPower);
2817
2818 return 0;
2819}
2820
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302821static int hdd_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command, char *extra, tANI_U8 n, tANI_U8 *len)
2822{
2823 int ret = 0;
2824
2825 if (!pCfg || !command || !extra || !len)
2826 {
2827 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2828 "%s: argument passsed for GETDWELLTIME is incorrect", __func__);
2829 ret = -EINVAL;
2830 return ret;
2831 }
2832
2833 if (strncmp(command, "GETDWELLTIME ACTIVE MAX", 23) == 0)
2834 {
2835 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MAX %u\n",
2836 (int)pCfg->nActiveMaxChnTime);
2837 return ret;
2838 }
2839 else if (strncmp(command, "GETDWELLTIME ACTIVE MIN", 23) == 0)
2840 {
2841 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MIN %u\n",
2842 (int)pCfg->nActiveMinChnTime);
2843 return ret;
2844 }
2845 else if (strncmp(command, "GETDWELLTIME PASSIVE MAX", 24) == 0)
2846 {
2847 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MAX %u\n",
2848 (int)pCfg->nPassiveMaxChnTime);
2849 return ret;
2850 }
2851 else if (strncmp(command, "GETDWELLTIME PASSIVE MIN", 24) == 0)
2852 {
2853 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MIN %u\n",
2854 (int)pCfg->nPassiveMinChnTime);
2855 return ret;
2856 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302857 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
2858 {
2859 *len = scnprintf(extra, n, "GETDWELLTIME %u \n",
2860 (int)pCfg->nActiveMaxChnTime);
2861 return ret;
2862 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302863 else
2864 {
2865 ret = -EINVAL;
2866 }
2867
2868 return ret;
2869}
2870
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302871int hdd_drv_cmd_validate(tANI_U8 *command, int len)
2872{
2873 if (command[len] != ' ')
2874 return -EINVAL;
2875
2876 return 0;
2877}
2878
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302879static int hdd_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
2880{
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302881 tHalHandle hHal;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302882 hdd_config_t *pCfg;
2883 tANI_U8 *value = command;
2884 int val = 0, ret = 0, temp = 0;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302885 tSmeConfigParams smeConfig;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302886
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302887 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
2888 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302889 {
2890 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2891 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
2892 ret = -EINVAL;
2893 return ret;
2894 }
2895
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302896 vos_mem_zero(&smeConfig, sizeof(smeConfig));
2897 sme_GetConfigParam(hHal, &smeConfig);
2898
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302899 if (strncmp(command, "SETDWELLTIME ACTIVE MAX", 23) == 0 )
2900 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302901 if (hdd_drv_cmd_validate(command, 23))
2902 return -EINVAL;
2903
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302904 value = value + 24;
2905 temp = kstrtou32(value, 10, &val);
2906 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
2907 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
2908 {
2909 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2910 "%s: argument passed for SETDWELLTIME ACTIVE MAX is incorrect", __func__);
2911 ret = -EFAULT;
2912 return ret;
2913 }
2914 pCfg->nActiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302915 smeConfig.csrConfig.nActiveMaxChnTime = val;
2916 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302917 }
2918 else if (strncmp(command, "SETDWELLTIME ACTIVE MIN", 23) == 0)
2919 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302920 if (hdd_drv_cmd_validate(command, 23))
2921 return -EINVAL;
2922
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302923 value = value + 24;
2924 temp = kstrtou32(value, 10, &val);
2925 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_MIN ||
2926 val > CFG_ACTIVE_MIN_CHANNEL_TIME_MAX )
2927 {
2928 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2929 "%s: argument passsed for SETDWELLTIME ACTIVE MIN is incorrect", __func__);
2930 ret = -EFAULT;
2931 return ret;
2932 }
2933 pCfg->nActiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302934 smeConfig.csrConfig.nActiveMinChnTime = val;
2935 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302936 }
2937 else if (strncmp(command, "SETDWELLTIME PASSIVE MAX", 24) == 0)
2938 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302939 if (hdd_drv_cmd_validate(command, 24))
2940 return -EINVAL;
2941
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302942 value = value + 25;
2943 temp = kstrtou32(value, 10, &val);
2944 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_MIN ||
2945 val > CFG_PASSIVE_MAX_CHANNEL_TIME_MAX )
2946 {
2947 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2948 "%s: argument passed for SETDWELLTIME PASSIVE MAX is incorrect", __func__);
2949 ret = -EFAULT;
2950 return ret;
2951 }
2952 pCfg->nPassiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302953 smeConfig.csrConfig.nPassiveMaxChnTime = val;
2954 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302955 }
2956 else if (strncmp(command, "SETDWELLTIME PASSIVE MIN", 24) == 0)
2957 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302958 if (hdd_drv_cmd_validate(command, 24))
2959 return -EINVAL;
2960
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302961 value = value + 25;
2962 temp = kstrtou32(value, 10, &val);
2963 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_MIN ||
2964 val > CFG_PASSIVE_MIN_CHANNEL_TIME_MAX )
2965 {
2966 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2967 "%s: argument passed for SETDWELLTIME PASSIVE MIN is incorrect", __func__);
2968 ret = -EFAULT;
2969 return ret;
2970 }
2971 pCfg->nPassiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302972 smeConfig.csrConfig.nPassiveMinChnTime = val;
2973 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302974 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302975 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
2976 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302977 if (hdd_drv_cmd_validate(command, 12))
2978 return -EINVAL;
2979
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302980 value = value + 13;
2981 temp = kstrtou32(value, 10, &val);
2982 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
2983 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
2984 {
2985 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2986 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
2987 ret = -EFAULT;
2988 return ret;
2989 }
2990 pCfg->nActiveMaxChnTime = val;
2991 smeConfig.csrConfig.nActiveMaxChnTime = val;
2992 sme_UpdateConfig(hHal, &smeConfig);
2993 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302994 else
2995 {
2996 ret = -EINVAL;
2997 }
2998
2999 return ret;
3000}
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303001static int hdd_cmd_setFccChannel(hdd_context_t *pHddCtx, tANI_U8 *cmd,
3002 tANI_U8 cmd_len)
3003{
3004 tANI_U8 *value;
3005 tANI_U8 fcc_constraint;
3006
3007 eHalStatus status;
3008 int ret = 0;
3009 value = cmd + cmd_len + 1;
3010
3011 ret = kstrtou8(value, 10, &fcc_constraint);
3012 if ((ret < 0) || (fcc_constraint > 1)) {
3013 /*
3014 * If the input value is greater than max value of datatype,
3015 * then also it is a failure
3016 */
3017 hddLog(VOS_TRACE_LEVEL_ERROR,
3018 "%s: value out of range", __func__);
3019 return -EINVAL;
3020 }
3021
Agrawal Ashish842eea82016-02-04 17:56:16 +05303022 status = sme_handleSetFccChannel(pHddCtx->hHal, fcc_constraint,
3023 pHddCtx->scan_info.mScanPending);
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303024 if (status != eHAL_STATUS_SUCCESS)
3025 ret = -EPERM;
3026
3027 return ret;
3028}
3029
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05303030/**---------------------------------------------------------------------------
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303031
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05303032 \brief hdd_enable_disable_ca_event() - When Host sends IOCTL (enabled),
3033 FW will send *ONE* CA ind to Host(even though it is duplicate).
3034 When Host send IOCTL (disable), FW doesn't perform any action.
3035 Whenever any change in CA *and* WLAN is in SAP/P2P-GO mode, FW
3036 sends CA ind to host. (regard less of IOCTL status)
3037 \param - pHddCtx - HDD context
3038 \param - command - command received from framework
3039 \param - cmd_len - len of the command
3040
3041 \return - 0 on success, appropriate error values on failure.
3042
3043 --------------------------------------------------------------------------*/
3044int hdd_enable_disable_ca_event(hdd_context_t *pHddCtx, tANI_U8* command, tANI_U8 cmd_len)
3045{
3046 tANI_U8 set_value;
3047 int ret = 0;
3048 eHalStatus status;
3049
3050 ret = wlan_hdd_validate_context(pHddCtx);
3051 if (0 != ret)
3052 {
3053 ret = -EINVAL;
3054 goto exit;
3055 }
3056
3057 if (pHddCtx->cfg_ini->gOptimizeCAevent == 0)
3058 {
3059 hddLog(VOS_TRACE_LEVEL_ERROR, "Enable gOptimizeCAevent"
3060 " ini param to control channel avooidance indication");
3061 ret = 0;
3062 goto exit;
3063 }
3064
3065 set_value = command[cmd_len + 1] - '0';
3066 status = sme_enableDisableChanAvoidIndEvent(pHddCtx->hHal, set_value);
3067 if (status != eHAL_STATUS_SUCCESS)
3068 {
3069 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to send"
3070 " enableDisableChanAoidance command to SME\n", __func__);
3071 ret = -EINVAL;
3072 }
3073
3074exit:
3075 return ret;
3076}
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303077
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303078/**
3079 * wlan_hdd_fastreassoc_handoff_request() - Post Handoff request to SME
3080 * @pHddCtx: Pointer to the HDD context
3081 * @channel: channel to reassociate
3082 * @targetApBssid: Target AP/BSSID to reassociate
3083 *
3084 * Return: None
3085 */
3086#if defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD) && !defined(QCA_WIFI_ISOC)
3087static void wlan_hdd_fastreassoc_handoff_request(hdd_context_t *pHddCtx,
3088 uint8_t channel, tSirMacAddr targetApBssid)
3089{
3090 tCsrHandoffRequest handoffInfo;
3091 handoffInfo.channel = channel;
3092 handoffInfo.src = FASTREASSOC;
3093 vos_mem_copy(handoffInfo.bssid, targetApBssid, sizeof(tSirMacAddr));
3094 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
3095}
3096#else
3097static void wlan_hdd_fastreassoc_handoff_request(hdd_context_t *pHddCtx,
3098 uint8_t channel, tSirMacAddr targetApBssid)
3099{
3100}
3101#endif
3102
3103/**
3104 * csr_fastroam_neighbor_ap_event() - Function to trigger scan/roam
3105 * @pAdapter: Pointer to HDD adapter
3106 * @channel: Channel to scan/roam
3107 * @targetApBssid: BSSID to roam
3108 *
3109 * Return: None
3110 */
3111#ifdef QCA_WIFI_ISOC
3112static void csr_fastroam_neighbor_ap_event(hdd_adapter_t *pAdapter,
3113 uint8_t channel, tSirMacAddr targetApBssid)
3114{
3115 smeIssueFastRoamNeighborAPEvent(WLAN_HDD_GET_HAL_CTX(pAdapter),
3116 &targetApBssid[0], eSME_ROAM_TRIGGER_SCAN, channel);
3117}
3118#else
3119static void csr_fastroam_neighbor_ap_event(hdd_adapter_t *pAdapter,
3120 uint8_t channel, tSirMacAddr targetApBssid)
3121{
3122}
3123#endif
3124
3125/**
3126 * wlan_hdd_handle_fastreassoc() - Handle fastreassoc command
3127 * @pAdapter: pointer to hdd adapter
3128 * @command: pointer to the command received
3129 *
3130 * Return: VOS_STATUS enum
3131 */
3132static VOS_STATUS wlan_hdd_handle_fastreassoc(hdd_adapter_t *pAdapter,
3133 uint8_t *command)
3134{
3135 tANI_U8 *value = command;
3136 tANI_U8 channel = 0;
3137 tSirMacAddr targetApBssid;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303138 hdd_station_ctx_t *pHddStaCtx = NULL;
3139 hdd_context_t *pHddCtx = NULL;
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05303140 int ret;
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303141 tCsrRoamModifyProfileFields mod_profile_fields;
3142 uint32_t roam_id = 0;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303143 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3144 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3145
3146 /* if not associated, no need to proceed with reassoc */
3147 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
3148 hddLog(LOG1, FL("Not associated!"));
3149 return eHAL_STATUS_FAILURE;
3150 }
3151
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05303152 ret = hdd_parse_reassoc_command_v1_data(value, targetApBssid, &channel);
3153 if (ret) {
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303154 hddLog(LOGE, FL("Failed to parse reassoc command data"));
3155 return eHAL_STATUS_FAILURE;
3156 }
3157
3158 /* if the target bssid is same as currently associated AP,
3159 then no need to proceed with reassoc */
3160 if (vos_mem_compare(targetApBssid,
3161 pHddStaCtx->conn_info.bssId,
3162 sizeof(tSirMacAddr))) {
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303163 sme_GetModifyProfileFields(pHddCtx->hHal, pAdapter->sessionId,
3164 &mod_profile_fields);
3165 sme_RoamReassoc(pHddCtx->hHal, pAdapter->sessionId, NULL,
3166 mod_profile_fields, &roam_id, 1);
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303167 hddLog(LOG1, FL("Reassoc BSSID is same as currently associated AP bssid"));
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303168 return eHAL_STATUS_SUCCESS;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303169 }
3170
3171 /* Check channel number is a valid channel number */
3172 if (VOS_STATUS_SUCCESS !=
3173 wlan_hdd_validate_operation_channel(pAdapter, channel)) {
3174 hddLog(LOGE, FL("Invalid Channel [%d]"), channel);
3175 return eHAL_STATUS_FAILURE;
3176 }
3177
3178 /* Proceed with reassoc */
3179 wlan_hdd_fastreassoc_handoff_request(pHddCtx, channel, targetApBssid);
3180
3181 /* Proceed with scan/roam */
3182 csr_fastroam_neighbor_ap_event(pAdapter, channel, targetApBssid);
3183
3184 return eHAL_STATUS_SUCCESS;
3185}
3186
3187/**
3188 * hdd_assign_reassoc_handoff - Set handoff source as REASSOC
3189 * @handoffInfo: Pointer to the csr Handoff Request.
3190 *
3191 * Return: None
3192 */
3193#ifndef QCA_WIFI_ISOC
3194static inline void hdd_assign_reassoc_handoff(tCsrHandoffRequest *handoffInfo)
3195{
3196 handoffInfo->src = REASSOC;
3197}
3198#else
3199static inline void hdd_assign_reassoc_handoff(tCsrHandoffRequest *handoffInfo)
3200{
3201}
3202#endif
3203
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303204/**
3205 * wlan_hdd_free_cache_channels() - Free the cache channels list
3206 * @hdd_ctx: Pointer to HDD context
3207 *
3208 * Return: None
3209 */
3210
3211static void wlan_hdd_free_cache_channels(hdd_context_t *hdd_ctx)
3212{
3213 mutex_lock(&hdd_ctx->cache_channel_lock);
3214 hdd_ctx->orginal_channels->num_channels = 0;
3215 vos_mem_free(hdd_ctx->orginal_channels->channel_info);
3216 hdd_ctx->orginal_channels->channel_info = NULL;
3217 vos_mem_free(hdd_ctx->orginal_channels);
3218 hdd_ctx->orginal_channels = NULL;
3219 mutex_unlock(&hdd_ctx->cache_channel_lock);
3220}
3221
3222/**
3223 * hdd_alloc_chan_cache() - Allocate the memory to cache the channel
3224 * info for the channels received in command SET_DISABLE_CHANNEL_LIST
3225 * @hdd_ctx: Pointer to HDD context
3226 * @num_chan: Number of channels for which memory needs to
3227 * be allocated
3228 *
3229 * Return: 0 on success and error code on failure
3230 */
3231
3232int hdd_alloc_chan_cache(hdd_context_t *hdd_ctx, int num_chan)
3233{
3234 if (NULL == hdd_ctx->orginal_channels) {
3235 hdd_ctx->orginal_channels =
3236 vos_mem_malloc(sizeof(struct hdd_cache_channels));
3237 if (NULL == hdd_ctx->orginal_channels) {
3238 hddLog(VOS_TRACE_LEVEL_ERROR,
3239 "In %s, VOS_MALLOC_ERR", __func__);
3240 return -EINVAL;
3241 }
3242 hdd_ctx->orginal_channels->num_channels = num_chan;
3243 hdd_ctx->orginal_channels->channel_info =
3244 vos_mem_malloc(num_chan *
3245 sizeof(struct hdd_cache_channel_info));
3246 if (NULL == hdd_ctx->orginal_channels->channel_info) {
3247 hddLog(VOS_TRACE_LEVEL_ERROR,
3248 "In %s, VOS_MALLOC_ERR", __func__);
3249 hdd_ctx->orginal_channels->num_channels = 0;
3250 vos_mem_free(hdd_ctx->orginal_channels);
3251 hdd_ctx->orginal_channels = NULL;
3252 return -EINVAL;
3253 }
3254 } else {
3255 /* Same command comes multiple times */
3256 struct hdd_cache_channel_info *temp_chan_info;
3257
3258 if (hdd_ctx->orginal_channels->num_channels + num_chan >
3259 MAX_CHANNEL) {
3260 hddLog(VOS_TRACE_LEVEL_ERROR,
3261 "%s: Invalid Number of channel received",
3262 __func__);
3263 return -EINVAL;
3264 }
3265
3266 temp_chan_info = vos_mem_malloc((
3267 hdd_ctx->orginal_channels->
3268 num_channels + num_chan) *
3269 sizeof(struct hdd_cache_channel_info));
3270 if (NULL == temp_chan_info) {
3271 hddLog(VOS_TRACE_LEVEL_ERROR,
3272 "In %s, VOS_MALLOC_ERR",
3273 __func__);
3274 return -EINVAL;
3275 }
3276
3277 vos_mem_copy(temp_chan_info, hdd_ctx->orginal_channels->
3278 channel_info, hdd_ctx->orginal_channels->
3279 num_channels *
3280 sizeof(struct hdd_cache_channel_info));
3281
3282 hdd_ctx->orginal_channels->num_channels += num_chan;
3283 vos_mem_free(hdd_ctx->orginal_channels->channel_info);
3284 hdd_ctx->orginal_channels->channel_info = temp_chan_info;
3285 temp_chan_info = NULL;
3286 }
3287 return 0;
3288
3289}
3290
3291
3292int hdd_parse_disable_chan_cmd(hdd_adapter_t *adapter, tANI_U8 *ptr)
3293{
3294 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
3295 hdd_context_t *hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, pvosGCtx);
3296 tANI_U8 *param;
3297 int j, tempInt, index = 0, ret = 0;
3298
3299 if (NULL == pvosGCtx) {
3300 hddLog(VOS_TRACE_LEVEL_FATAL,
3301 "VOS Global Context is NULL");
3302 return -EINVAL;
3303 }
3304
3305 if (NULL == hdd_ctx) {
3306 hddLog(VOS_TRACE_LEVEL_FATAL, "HDD Context is NULL");
3307 return -EINVAL;
3308 }
3309
3310 param = strchr(ptr, ' ');
3311 /*no argument after the command*/
3312 if (NULL == param)
3313 return -EINVAL;
3314
3315 /*no space after the command*/
3316 else if (SPACE_ASCII_VALUE != *param)
3317 return -EINVAL;
3318
3319 param++;
3320
3321 /*removing empty spaces*/
3322 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3323 param++;
3324
3325 /*no argument followed by spaces*/
3326 if ('\0' == *param)
3327 return -EINVAL;
3328
3329 /*getting the first argument ie the number of channels*/
3330 if (sscanf(param, "%d ", &tempInt) != 1) {
3331 hddLog(VOS_TRACE_LEVEL_ERROR,
3332 "%s: Cannot get number of channels from input",
3333 __func__);
3334 return -EINVAL;
3335 }
3336
3337 if (tempInt < 0 || tempInt > MAX_CHANNEL) {
3338 hddLog(VOS_TRACE_LEVEL_ERROR,
3339 "%s: Invalid Number of channel received", __func__);
3340 return -EINVAL;
3341 }
3342
3343 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
3344 "%s: Number of channel to disable are: %d",
3345 __func__, tempInt);
3346
3347 if (!tempInt) {
3348 if (!wlan_hdd_restore_channels(hdd_ctx)) {
3349 /*
3350 * Free the cache channels only when the command is
3351 * received with num channels as 0
3352 */
3353 wlan_hdd_free_cache_channels(hdd_ctx);
3354 }
3355 return 0;
3356 }
3357
3358 mutex_lock(&hdd_ctx->cache_channel_lock);
3359 if (hdd_alloc_chan_cache(hdd_ctx, tempInt)) {
3360 ret = -ENOMEM;
3361 goto parse_done;
3362 }
3363 index = hdd_ctx->orginal_channels->num_channels - tempInt;
3364
3365 for (j = index; j < hdd_ctx->orginal_channels->num_channels; j++) {
3366 /*
3367 * param pointing to the beginning of first space
3368 * after number of channels
3369 */
3370 param = strpbrk(param, " ");
3371 /*no channel list after the number of channels argument*/
3372 if (NULL == param) {
3373 hddLog(VOS_TRACE_LEVEL_ERROR,
3374 "%s, Invalid No of channel provided in the list",
3375 __func__);
3376 ret = -EINVAL;
3377 goto parse_done;
3378 }
3379
3380 param++;
3381
3382 /*removing empty space*/
3383 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3384 param++;
3385
3386 if ('\0' == *param) {
3387 hddLog(VOS_TRACE_LEVEL_ERROR,
3388 "%s, No channel is provided in the list",
3389 __func__);
3390 ret = -EINVAL;
3391 goto parse_done;
3392
3393 }
3394
3395 if (sscanf(param, "%d ", &tempInt) != 1) {
3396 hddLog(VOS_TRACE_LEVEL_ERROR,
3397 "%s: Cannot read channel number",
3398 __func__);
3399 ret = -EINVAL;
3400 goto parse_done;
3401
3402 }
3403
3404 if (!IS_CHANNEL_VALID(tempInt)) {
3405 hddLog(VOS_TRACE_LEVEL_ERROR,
3406 "%s: Invalid channel number received",
3407 __func__);
3408 ret = -EINVAL;
3409 goto parse_done;
3410
3411 }
3412
3413 hddLog(VOS_TRACE_LEVEL_INFO, "%s: channel[%d] = %d", __func__,
3414 j, tempInt);
3415 hdd_ctx->orginal_channels->channel_info[j].channel_num =
3416 tempInt;
3417 }
3418
3419 /*extra arguments check*/
3420 param = strchr(param, ' ');
3421 if (NULL != param) {
3422 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3423 param++;
3424
3425 if ('\0' != *param) {
3426 hddLog(VOS_TRACE_LEVEL_ERROR,
3427 "%s: Invalid argument received", __func__);
3428 ret = -EINVAL;
3429 goto parse_done;
3430 }
3431 }
3432
3433parse_done:
3434 mutex_unlock(&hdd_ctx->cache_channel_lock);
3435 EXIT();
3436
3437 return ret;
3438}
3439
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303440int hdd_get_disable_ch_list(hdd_context_t *hdd_ctx, tANI_U8 *buf,
3441 tANI_U8 buf_len)
3442{
3443 struct hdd_cache_channel_info *ch_list;
3444 unsigned char i, num_ch;
3445 int len = 0;
3446
3447 mutex_lock(&hdd_ctx->cache_channel_lock);
3448 if (hdd_ctx->orginal_channels &&
3449 hdd_ctx->orginal_channels->num_channels) {
3450 num_ch = hdd_ctx->orginal_channels->num_channels;
3451
3452 if (num_ch == 0) {
3453 mutex_unlock(&hdd_ctx->cache_channel_lock);
3454 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3455 FL("no disable channels programed"));
3456 return 0;
3457 }
3458
3459 len = scnprintf(buf, buf_len, "%s %hhu",
3460 "GET_DISABLE_CHANNEL_LIST", num_ch);
3461
3462 ch_list = hdd_ctx->orginal_channels->channel_info;
3463 if (!ch_list) {
3464 mutex_unlock(&hdd_ctx->cache_channel_lock);
3465 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3466 FL("disable channel list is NULL"));
3467 return 0;
3468 }
3469
3470 for (i = 0; (i < num_ch) && len <= buf_len; i++) {
3471 len += scnprintf(buf + len, buf_len - len,
3472 " %d", ch_list[i].channel_num);
3473 }
3474 }
3475 mutex_unlock(&hdd_ctx->cache_channel_lock);
3476
3477 return len;
3478}
3479
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003480static int hdd_driver_command(hdd_adapter_t *pAdapter,
3481 hdd_priv_data_t *ppriv_data)
Jeff Johnson295189b2012-06-20 16:38:30 -07003482{
Jeff Johnson295189b2012-06-20 16:38:30 -07003483 hdd_priv_data_t priv_data;
3484 tANI_U8 *command = NULL;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303485 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3486 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003487 int ret = 0;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303488 int status;
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05303489#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
3490 struct cfg80211_mgmt_tx_params params;
3491#endif
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303492
3493 ENTER();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003494 /*
3495 * Note that valid pointers are provided by caller
3496 */
Jeff Johnson295189b2012-06-20 16:38:30 -07003497
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003498 /* copy to local struct to avoid numerous changes to legacy code */
3499 priv_data = *ppriv_data;
Jeff Johnson295189b2012-06-20 16:38:30 -07003500
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003501 if (priv_data.total_len <= 0 ||
3502 priv_data.total_len > WLAN_PRIV_DATA_MAX_LEN)
Sameer Thalappil8ef3a0e2013-04-05 14:36:04 -07003503 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003504 hddLog(VOS_TRACE_LEVEL_WARN,
3505 "%s:invalid priv_data.total_len(%d)!!!", __func__,
3506 priv_data.total_len);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003507 ret = -EINVAL;
3508 goto exit;
3509 }
Kaushik, Sushant96122442014-10-21 16:40:18 +05303510 status = wlan_hdd_validate_context(pHddCtx);
3511 if (0 != status)
3512 {
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303513 ret = -EINVAL;
3514 goto exit;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303515 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003516 /* Allocate +1 for '\0' */
3517 command = kmalloc(priv_data.total_len + 1, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07003518 if (!command)
3519 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003520 hddLog(VOS_TRACE_LEVEL_ERROR,
3521 "%s: failed to allocate memory", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003522 ret = -ENOMEM;
3523 goto exit;
3524 }
3525
3526 if (copy_from_user(command, priv_data.buf, priv_data.total_len))
3527 {
3528 ret = -EFAULT;
3529 goto exit;
3530 }
3531
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003532 /* Make sure the command is NUL-terminated */
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003533 command[priv_data.total_len] = '\0';
3534
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003535 /* at one time the following block of code was conditional. braces
3536 * have been retained to avoid re-indenting the legacy code
3537 */
Jeff Johnson295189b2012-06-20 16:38:30 -07003538 {
3539 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
3540
3541 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07003542 "%s: Received %s cmd from Wi-Fi GUI***", __func__, command);
Jeff Johnson295189b2012-06-20 16:38:30 -07003543
3544 if (strncmp(command, "P2P_DEV_ADDR", 12) == 0 )
3545 {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303546 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3547 TRACE_CODE_HDD_P2P_DEV_ADDR_IOCTL,
3548 pAdapter->sessionId, (unsigned)
3549 (*(pHddCtx->p2pDeviceAddress.bytes+2)<<24 |
3550 *(pHddCtx->p2pDeviceAddress.bytes+3)<<16 |
3551 *(pHddCtx->p2pDeviceAddress.bytes+4)<<8 |
3552 *(pHddCtx->p2pDeviceAddress.bytes+5))));
Jeff Johnson295189b2012-06-20 16:38:30 -07003553 if (copy_to_user(priv_data.buf, pHddCtx->p2pDeviceAddress.bytes,
3554 sizeof(tSirMacAddr)))
3555 {
3556 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08003557 "%s: failed to copy data to user buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003558 ret = -EFAULT;
3559 }
3560 }
Amar Singhal0974e402013-02-12 14:27:46 -08003561 else if(strncmp(command, "SETBAND", 7) == 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07003562 {
Amar Singhal0974e402013-02-12 14:27:46 -08003563 tANI_U8 *ptr = command ;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003564
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303565 ret = hdd_drv_cmd_validate(command, 7);
3566 if (ret)
3567 goto exit;
3568
Jeff Johnson295189b2012-06-20 16:38:30 -07003569 /* Change band request received */
Srinivas Girigowdade697412013-02-14 16:31:48 -08003570
3571 /* First 8 bytes will have "SETBAND " and
Jeff Johnson295189b2012-06-20 16:38:30 -07003572 * 9 byte will have band setting value */
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07003573 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Amar Singhal0974e402013-02-12 14:27:46 -08003574 "%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 +05303575 if(VOS_FTM_MODE != hdd_get_conparam())
3576 {
3577 /* Change band request received */
3578 ret = hdd_setBand_helper(pAdapter->dev, ptr);
3579 if(ret < 0)
3580 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3581 "%s: failed to set band ret=%d", __func__, ret);
3582 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08003583 }
Kiet Lamf040f472013-11-20 21:15:23 +05303584 else if(strncmp(command, "SETWMMPS", 8) == 0)
3585 {
3586 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303587
3588 ret = hdd_drv_cmd_validate(command, 8);
3589 if (ret)
3590 goto exit;
3591
Kiet Lamf040f472013-11-20 21:15:23 +05303592 ret = hdd_wmmps_helper(pAdapter, ptr);
3593 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05303594
3595 else if(strncmp(command, "TDLSSCAN", 8) == 0)
3596 {
3597 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303598
3599 ret = hdd_drv_cmd_validate(command, 8);
3600 if (ret)
3601 goto exit;
3602
Agarwal Ashishef54a182014-12-16 15:07:31 +05303603 ret = hdd_set_tdls_scan_type(pAdapter, ptr);
3604 }
3605
Jeff Johnson32d95a32012-09-10 13:15:23 -07003606 else if ( strncasecmp(command, "COUNTRY", 7) == 0 )
3607 {
3608 char *country_code;
3609
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303610 ret = hdd_drv_cmd_validate(command, 7);
3611 if (ret)
3612 goto exit;
3613
Jeff Johnson32d95a32012-09-10 13:15:23 -07003614 country_code = command + 8;
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07003615
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07003616 INIT_COMPLETION(pAdapter->change_country_code);
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07003617 hdd_checkandupdate_dfssetting(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07003618#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +05303619 hdd_checkandupdate_phymode(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07003620#endif
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07003621 ret = (int)sme_ChangeCountryCode(pHddCtx->hHal,
3622 (void *)(tSmeChangeCountryCallback)
3623 wlan_hdd_change_country_code_callback,
Abhishek Singha306a442013-11-07 18:39:01 +05303624 country_code, pAdapter, pHddCtx->pvosContext, eSIR_TRUE, eSIR_TRUE);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07003625 if (eHAL_STATUS_SUCCESS == ret)
3626 {
3627 ret = wait_for_completion_interruptible_timeout(
3628 &pAdapter->change_country_code,
3629 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
3630 if (0 >= ret)
3631 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003632 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: SME while setting country code timed out %d",
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303633 __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07003634 }
3635 }
3636 else
Jeff Johnson32d95a32012-09-10 13:15:23 -07003637 {
3638 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003639 "%s: SME Change Country code fail ret=%d", __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07003640 ret = -EINVAL;
Jeff Johnson32d95a32012-09-10 13:15:23 -07003641 }
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07003642
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07003643 }
3644 /*
3645 command should be a string having format
3646 SET_SAP_CHANNEL_LIST <num of channels> <the channels seperated by spaces>
3647 */
Amar Singhal0974e402013-02-12 14:27:46 -08003648 else if(strncmp(command, "SET_SAP_CHANNEL_LIST", 20) == 0)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07003649 {
Amar Singhal0974e402013-02-12 14:27:46 -08003650 tANI_U8 *ptr = command;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07003651
3652 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07003653 " Received Command to Set Preferred Channels for SAP in %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07003654
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -08003655 ret = sapSetPreferredChannel(ptr);
Jeff Johnson32d95a32012-09-10 13:15:23 -07003656 }
Sameer Thalappil45931fb2013-02-01 11:18:05 -08003657 else if(strncmp(command, "SETSUSPENDMODE", 14) == 0)
3658 {
3659 int suspend = 0;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303660 tANI_U8 *ptr;
3661
3662 ret = hdd_drv_cmd_validate(command, 14);
3663 if (ret)
3664 goto exit;
3665
3666 ptr = (tANI_U8*)command + 15;
Sameer Thalappil45931fb2013-02-01 11:18:05 -08003667
3668 suspend = *ptr - '0';
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303669 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3670 TRACE_CODE_HDD_SETSUSPENDMODE_IOCTL,
3671 pAdapter->sessionId, suspend));
Sameer Thalappil45931fb2013-02-01 11:18:05 -08003672 hdd_set_wlan_suspend_mode(suspend);
3673 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08003674#ifdef WLAN_FEATURE_NEIGHBOR_ROAMING
3675 else if (strncmp(command, "SETROAMTRIGGER", 14) == 0)
3676 {
3677 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003678 tANI_S8 rssi = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003679 tANI_U8 lookUpThreshold = CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_DEFAULT;
3680 eHalStatus status = eHAL_STATUS_SUCCESS;
3681
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303682 ret = hdd_drv_cmd_validate(command, 14);
3683 if (ret)
3684 goto exit;
3685
Srinivas Girigowdade697412013-02-14 16:31:48 -08003686 /* Move pointer to ahead of SETROAMTRIGGER<delimiter> */
3687 value = value + 15;
3688
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003689 /* Convert the value from ascii to integer */
3690 ret = kstrtos8(value, 10, &rssi);
3691 if (ret < 0)
3692 {
3693 /* If the input value is greater than max value of datatype, then also
3694 kstrtou8 fails */
3695 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3696 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdafa7157d2013-10-31 10:14:22 -07003697 __func__,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003698 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
3699 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
3700 ret = -EINVAL;
3701 goto exit;
3702 }
3703
Srinivas Girigowdade697412013-02-14 16:31:48 -08003704 lookUpThreshold = abs(rssi);
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003705
Srinivas Girigowdade697412013-02-14 16:31:48 -08003706 if ((lookUpThreshold < CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN) ||
3707 (lookUpThreshold > CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX))
3708 {
3709 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3710 "Neighbor lookup threshold value %d is out of range"
3711 " (Min: %d Max: %d)", lookUpThreshold,
3712 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
3713 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
3714 ret = -EINVAL;
3715 goto exit;
3716 }
3717
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303718 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3719 TRACE_CODE_HDD_SETROAMTRIGGER_IOCTL,
3720 pAdapter->sessionId, lookUpThreshold));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003721 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3722 "%s: Received Command to Set Roam trigger"
3723 " (Neighbor lookup threshold) = %d", __func__, lookUpThreshold);
3724
3725 pHddCtx->cfg_ini->nNeighborLookupRssiThreshold = lookUpThreshold;
3726 status = sme_setNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold);
3727 if (eHAL_STATUS_SUCCESS != status)
3728 {
3729 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3730 "%s: Failed to set roam trigger, try again", __func__);
3731 ret = -EPERM;
3732 goto exit;
3733 }
3734
3735 /* Set Reassoc threshold to (lookup rssi threshold + 5 dBm) */
mukul sharmad6e1fdd2014-06-23 19:19:09 +05303736 pHddCtx->cfg_ini->nNeighborReassocRssiThreshold = lookUpThreshold + 5;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003737 sme_setNeighborReassocRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold + 5);
3738 }
3739 else if (strncmp(command, "GETROAMTRIGGER", 14) == 0)
3740 {
3741 tANI_U8 lookUpThreshold = sme_getNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal));
3742 int rssi = (-1) * lookUpThreshold;
3743 char extra[32];
3744 tANI_U8 len = 0;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303745 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3746 TRACE_CODE_HDD_GETROAMTRIGGER_IOCTL,
3747 pAdapter->sessionId, lookUpThreshold));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003748 len = scnprintf(extra, sizeof(extra), "%s %d", command, rssi);
Srinivas Girigowda91719232015-07-13 15:10:10 +05303749 len = VOS_MIN(priv_data.total_len, len + 1);
3750 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08003751 {
3752 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3753 "%s: failed to copy data to user buffer", __func__);
3754 ret = -EFAULT;
3755 goto exit;
3756 }
3757 }
3758 else if (strncmp(command, "SETROAMSCANPERIOD", 17) == 0)
3759 {
3760 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003761 tANI_U8 roamScanPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003762 tANI_U16 neighborEmptyScanRefreshPeriod = CFG_EMPTY_SCAN_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003763
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303764 ret = hdd_drv_cmd_validate(command, 17);
3765 if (ret)
3766 goto exit;
3767
Srinivas Girigowdade697412013-02-14 16:31:48 -08003768 /* input refresh period is in terms of seconds */
3769 /* Move pointer to ahead of SETROAMSCANPERIOD<delimiter> */
3770 value = value + 18;
3771 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003772 ret = kstrtou8(value, 10, &roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08003773 if (ret < 0)
3774 {
3775 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003776 kstrtou8 fails */
Srinivas Girigowdade697412013-02-14 16:31:48 -08003777 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003778 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdade697412013-02-14 16:31:48 -08003779 __func__,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07003780 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
3781 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003782 ret = -EINVAL;
3783 goto exit;
3784 }
3785
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003786 if ((roamScanPeriod < (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000)) ||
3787 (roamScanPeriod > (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000)))
Srinivas Girigowdade697412013-02-14 16:31:48 -08003788 {
3789 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003790 "Roam scan period value %d is out of range"
3791 " (Min: %d Max: %d)", roamScanPeriod,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07003792 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
3793 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003794 ret = -EINVAL;
3795 goto exit;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303796 }
3797 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3798 TRACE_CODE_HDD_SETROAMSCANPERIOD_IOCTL,
3799 pAdapter->sessionId, roamScanPeriod));
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003800 neighborEmptyScanRefreshPeriod = roamScanPeriod * 1000;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003801
3802 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3803 "%s: Received Command to Set roam scan period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003804 " (Empty Scan refresh period) = %d", __func__, roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08003805
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003806 pHddCtx->cfg_ini->nEmptyScanRefreshPeriod = neighborEmptyScanRefreshPeriod;
3807 sme_UpdateEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborEmptyScanRefreshPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08003808 }
3809 else if (strncmp(command, "GETROAMSCANPERIOD", 17) == 0)
3810 {
3811 tANI_U16 nEmptyScanRefreshPeriod = sme_getEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
3812 char extra[32];
3813 tANI_U8 len = 0;
3814
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303815 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3816 TRACE_CODE_HDD_GETROAMSCANPERIOD_IOCTL,
3817 pAdapter->sessionId, nEmptyScanRefreshPeriod));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003818 len = scnprintf(extra, sizeof(extra), "%s %d",
3819 "GETROAMSCANPERIOD", (nEmptyScanRefreshPeriod/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003820 /* Returned value is in units of seconds */
Ratnam Rachuria72ba112015-07-17 13:27:03 +05303821 len = VOS_MIN(priv_data.total_len, len + 1);
3822 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08003823 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3824 "%s: failed to copy data to user buffer", __func__);
3825 ret = -EFAULT;
3826 goto exit;
3827 }
3828 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003829 else if (strncmp(command, "SETROAMSCANREFRESHPERIOD", 24) == 0)
3830 {
3831 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003832 tANI_U8 roamScanRefreshPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003833 tANI_U16 neighborScanRefreshPeriod = CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003834
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303835 ret = hdd_drv_cmd_validate(command, 24);
3836 if (ret)
3837 goto exit;
3838
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003839 /* input refresh period is in terms of seconds */
3840 /* Move pointer to ahead of SETROAMSCANREFRESHPERIOD<delimiter> */
3841 value = value + 25;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003842
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003843 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003844 ret = kstrtou8(value, 10, &roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003845 if (ret < 0)
3846 {
3847 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003848 kstrtou8 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003849 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003850 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003851 __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003852 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
3853 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
3854 ret = -EINVAL;
3855 goto exit;
3856 }
3857
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003858 if ((roamScanRefreshPeriod < (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000)) ||
3859 (roamScanRefreshPeriod > (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000)))
3860 {
3861 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3862 "Neighbor scan results refresh period value %d is out of range"
3863 " (Min: %d Max: %d)", roamScanRefreshPeriod,
3864 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
3865 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
3866 ret = -EINVAL;
3867 goto exit;
3868 }
3869 neighborScanRefreshPeriod = roamScanRefreshPeriod * 1000;
3870
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003871 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3872 "%s: Received Command to Set roam scan refresh period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003873 " (Scan refresh period) = %d", __func__, roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003874
3875 pHddCtx->cfg_ini->nNeighborResultsRefreshPeriod = neighborScanRefreshPeriod;
3876 sme_setNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborScanRefreshPeriod);
3877 }
3878 else if (strncmp(command, "GETROAMSCANREFRESHPERIOD", 24) == 0)
3879 {
3880 tANI_U16 value = sme_getNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
3881 char extra[32];
3882 tANI_U8 len = 0;
3883
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003884 len = scnprintf(extra, sizeof(extra), "%s %d",
3885 "GETROAMSCANREFRESHPERIOD", (value/1000));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003886 /* Returned value is in units of seconds */
Ratnam Rachuri2c9d6702015-07-17 13:25:16 +05303887 len = VOS_MIN(priv_data.total_len, len + 1);
3888 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003889 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3890 "%s: failed to copy data to user buffer", __func__);
3891 ret = -EFAULT;
3892 goto exit;
3893 }
3894 }
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07003895#ifdef FEATURE_WLAN_LFR
3896 /* SETROAMMODE */
3897 else if (strncmp(command, "SETROAMMODE", SIZE_OF_SETROAMMODE) == 0)
3898 {
3899 tANI_U8 *value = command;
3900 tANI_BOOLEAN roamMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
3901
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05303902 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
3903 hddLog(LOGE,
3904 FL("Roaming is always disabled in STA + MON concurrency"));
3905 ret = -EINVAL;
3906 goto exit;
3907 }
3908
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303909 ret = hdd_drv_cmd_validate(command, SIZE_OF_SETROAMMODE);
3910 if (ret)
3911 goto exit;
3912
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07003913 /* Move pointer to ahead of SETROAMMODE<delimiter> */
3914 value = value + SIZE_OF_SETROAMMODE + 1;
3915
3916 /* Convert the value from ascii to integer */
3917 ret = kstrtou8(value, SIZE_OF_SETROAMMODE, &roamMode);
3918 if (ret < 0)
3919 {
3920 /* If the input value is greater than max value of datatype, then also
3921 kstrtou8 fails */
3922 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3923 "%s: kstrtou8 failed range [%d - %d]", __func__,
3924 CFG_LFR_FEATURE_ENABLED_MIN,
3925 CFG_LFR_FEATURE_ENABLED_MAX);
3926 ret = -EINVAL;
3927 goto exit;
3928 }
3929 if ((roamMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
3930 (roamMode > CFG_LFR_FEATURE_ENABLED_MAX))
3931 {
3932 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3933 "Roam Mode value %d is out of range"
3934 " (Min: %d Max: %d)", roamMode,
3935 CFG_LFR_FEATURE_ENABLED_MIN,
3936 CFG_LFR_FEATURE_ENABLED_MAX);
3937 ret = -EINVAL;
3938 goto exit;
3939 }
3940
3941 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3942 "%s: Received Command to Set Roam Mode = %d", __func__, roamMode);
3943 /*
3944 * Note that
3945 * SETROAMMODE 0 is to enable LFR while
3946 * SETROAMMODE 1 is to disable LFR, but
3947 * NotifyIsFastRoamIniFeatureEnabled 0/1 is to enable/disable.
3948 * So, we have to invert the value to call sme_UpdateIsFastRoamIniFeatureEnabled.
3949 */
3950 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
3951 roamMode = CFG_LFR_FEATURE_ENABLED_MAX; /* Roam enable */
3952 else
3953 roamMode = CFG_LFR_FEATURE_ENABLED_MIN; /* Roam disable */
3954
3955 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = roamMode;
3956 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), roamMode);
3957 }
3958 /* GETROAMMODE */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05303959 else if (strncmp(command, "GETROAMMODE", SIZE_OF_GETROAMMODE) == 0)
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07003960 {
3961 tANI_BOOLEAN roamMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
3962 char extra[32];
3963 tANI_U8 len = 0;
3964
3965 /*
3966 * roamMode value shall be inverted because the sementics is different.
3967 */
3968 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
3969 roamMode = CFG_LFR_FEATURE_ENABLED_MAX;
3970 else
3971 roamMode = CFG_LFR_FEATURE_ENABLED_MIN;
3972
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003973 len = scnprintf(extra, sizeof(extra), "%s %d", command, roamMode);
Ratnam Rachuri28693eb2015-07-17 13:23:42 +05303974 len = VOS_MIN(priv_data.total_len, len + 1);
3975 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07003976 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3977 "%s: failed to copy data to user buffer", __func__);
3978 ret = -EFAULT;
3979 goto exit;
3980 }
3981 }
3982#endif
Srinivas Girigowdade697412013-02-14 16:31:48 -08003983#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003984#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08003985 else if (strncmp(command, "SETROAMDELTA", 12) == 0)
3986 {
3987 tANI_U8 *value = command;
3988 tANI_U8 roamRssiDiff = CFG_ROAM_RSSI_DIFF_DEFAULT;
3989
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303990 ret = hdd_drv_cmd_validate(command, 12);
3991 if (ret)
3992 goto exit;
3993
Srinivas Girigowdade697412013-02-14 16:31:48 -08003994 /* Move pointer to ahead of SETROAMDELTA<delimiter> */
3995 value = value + 13;
3996 /* Convert the value from ascii to integer */
3997 ret = kstrtou8(value, 10, &roamRssiDiff);
3998 if (ret < 0)
3999 {
4000 /* If the input value is greater than max value of datatype, then also
4001 kstrtou8 fails */
4002 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4003 "%s: kstrtou8 failed range [%d - %d]", __func__,
4004 CFG_ROAM_RSSI_DIFF_MIN,
4005 CFG_ROAM_RSSI_DIFF_MAX);
4006 ret = -EINVAL;
4007 goto exit;
4008 }
4009
4010 if ((roamRssiDiff < CFG_ROAM_RSSI_DIFF_MIN) ||
4011 (roamRssiDiff > CFG_ROAM_RSSI_DIFF_MAX))
4012 {
4013 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4014 "Roam rssi diff value %d is out of range"
4015 " (Min: %d Max: %d)", roamRssiDiff,
4016 CFG_ROAM_RSSI_DIFF_MIN,
4017 CFG_ROAM_RSSI_DIFF_MAX);
4018 ret = -EINVAL;
4019 goto exit;
4020 }
4021
4022 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4023 "%s: Received Command to Set roam rssi diff = %d", __func__, roamRssiDiff);
4024
4025 pHddCtx->cfg_ini->RoamRssiDiff = roamRssiDiff;
4026 sme_UpdateRoamRssiDiff((tHalHandle)(pHddCtx->hHal), roamRssiDiff);
4027 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304028 else if (strncmp(command, "GETROAMDELTA", 12) == 0)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004029 {
4030 tANI_U8 roamRssiDiff = sme_getRoamRssiDiff((tHalHandle)(pHddCtx->hHal));
4031 char extra[32];
4032 tANI_U8 len = 0;
4033
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304034 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4035 TRACE_CODE_HDD_GETROAMDELTA_IOCTL,
4036 pAdapter->sessionId, roamRssiDiff));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004037 len = scnprintf(extra, sizeof(extra), "%s %d",
4038 command, roamRssiDiff);
Ratnam Rachuri22a3b402015-07-17 13:21:49 +05304039 len = VOS_MIN(priv_data.total_len, len + 1);
4040 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004041 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4042 "%s: failed to copy data to user buffer", __func__);
4043 ret = -EFAULT;
4044 goto exit;
4045 }
4046 }
4047#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004048#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004049 else if (strncmp(command, "GETBAND", 7) == 0)
4050 {
4051 int band = -1;
4052 char extra[32];
4053 tANI_U8 len = 0;
4054 hdd_getBand_helper(pHddCtx, &band);
4055
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304056 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4057 TRACE_CODE_HDD_GETBAND_IOCTL,
4058 pAdapter->sessionId, band));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004059 len = scnprintf(extra, sizeof(extra), "%s %d", command, band);
Ratnam Rachuri52139592015-07-17 13:17:29 +05304060 len = VOS_MIN(priv_data.total_len, len + 1);
4061 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004062 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4063 "%s: failed to copy data to user buffer", __func__);
4064 ret = -EFAULT;
4065 goto exit;
4066 }
4067 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004068 else if (strncmp(command, "SETROAMSCANCHANNELS", 19) == 0)
4069 {
4070 tANI_U8 *value = command;
4071 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
4072 tANI_U8 numChannels = 0;
4073 eHalStatus status = eHAL_STATUS_SUCCESS;
4074
4075 status = hdd_parse_channellist(value, ChannelList, &numChannels);
4076 if (eHAL_STATUS_SUCCESS != status)
4077 {
4078 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4079 "%s: Failed to parse channel list information", __func__);
4080 ret = -EINVAL;
4081 goto exit;
4082 }
4083
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304084 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4085 TRACE_CODE_HDD_SETROAMSCANCHANNELS_IOCTL,
4086 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004087 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
4088 {
4089 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4090 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
4091 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
4092 ret = -EINVAL;
4093 goto exit;
4094 }
4095 status = sme_ChangeRoamScanChannelList((tHalHandle)(pHddCtx->hHal), ChannelList,
4096 numChannels);
4097 if (eHAL_STATUS_SUCCESS != status)
4098 {
4099 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4100 "%s: Failed to update channel list information", __func__);
4101 ret = -EINVAL;
4102 goto exit;
4103 }
4104 }
4105 else if (strncmp(command, "GETROAMSCANCHANNELS", 19) == 0)
4106 {
4107 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
4108 tANI_U8 numChannels = 0;
Jeff Johnson51b67782013-04-05 12:35:41 -07004109 tANI_U8 j = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004110 char extra[128] = {0};
Jeff Johnson51b67782013-04-05 12:35:41 -07004111 int len;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004112
4113 if (eHAL_STATUS_SUCCESS != sme_getRoamScanChannelList( (tHalHandle)(pHddCtx->hHal),
4114 ChannelList, &numChannels ))
4115 {
4116 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4117 "%s: failed to get roam scan channel list", __func__);
4118 ret = -EFAULT;
4119 goto exit;
4120 }
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304121 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4122 TRACE_CODE_HDD_GETROAMSCANCHANNELS_IOCTL,
4123 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004124 /* output channel list is of the format
4125 [Number of roam scan channels][Channel1][Channel2]... */
4126 /* copy the number of channels in the 0th index */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004127 len = scnprintf(extra, sizeof(extra), "%s %d", command, numChannels);
Sushant Kaushika08ca192015-09-16 15:52:04 +05304128 for (j = 0; (j < numChannels) && len <= sizeof(extra); j++)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004129 {
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004130 len += scnprintf(extra + len, sizeof(extra) - len, " %d",
4131 ChannelList[j]);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004132 }
4133
Sushant Kaushikc9b8be52015-07-15 16:41:27 +05304134 len = VOS_MIN(priv_data.total_len, len + 1);
4135 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004136 {
4137 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4138 "%s: failed to copy data to user buffer", __func__);
4139 ret = -EFAULT;
4140 goto exit;
4141 }
4142 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004143 else if (strncmp(command, "GETCCXMODE", 10) == 0)
4144 {
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004145 tANI_BOOLEAN eseMode = sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004146 char extra[32];
4147 tANI_U8 len = 0;
4148
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004149 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004150 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004151 if (eseMode &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004152 hdd_is_okc_mode_enabled(pHddCtx) &&
4153 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4154 {
4155 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004156 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004157 " hence this operation is not permitted!", __func__);
4158 ret = -EPERM;
4159 goto exit;
4160 }
4161
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004162 len = scnprintf(extra, sizeof(extra), "%s %d",
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004163 "GETCCXMODE", eseMode);
Sushant Kaushikf8abd352015-07-15 16:37:49 +05304164 len = VOS_MIN(priv_data.total_len, len + 1);
4165 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004166 {
4167 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4168 "%s: failed to copy data to user buffer", __func__);
4169 ret = -EFAULT;
4170 goto exit;
4171 }
4172 }
4173 else if (strncmp(command, "GETOKCMODE", 10) == 0)
4174 {
4175 tANI_BOOLEAN okcMode = hdd_is_okc_mode_enabled(pHddCtx);
4176 char extra[32];
4177 tANI_U8 len = 0;
4178
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004179 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004180 then this operation is not permitted (return FAILURE) */
4181 if (okcMode &&
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004182 sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004183 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4184 {
4185 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004186 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004187 " hence this operation is not permitted!", __func__);
4188 ret = -EPERM;
4189 goto exit;
4190 }
4191
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004192 len = scnprintf(extra, sizeof(extra), "%s %d",
4193 "GETOKCMODE", okcMode);
Sushant Kaushikbc2fb5c2015-07-15 16:43:16 +05304194 len = VOS_MIN(priv_data.total_len, len + 1);
4195 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004196 {
4197 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4198 "%s: failed to copy data to user buffer", __func__);
4199 ret = -EFAULT;
4200 goto exit;
4201 }
4202 }
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004203 else if (strncmp(command, "GETFASTROAM", 11) == 0)
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004204 {
4205 tANI_BOOLEAN lfrMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4206 char extra[32];
4207 tANI_U8 len = 0;
4208
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004209 len = scnprintf(extra, sizeof(extra), "%s %d",
4210 "GETFASTROAM", lfrMode);
Sushant Kaushik4da7ec92015-07-15 16:39:32 +05304211 len = VOS_MIN(priv_data.total_len, len + 1);
4212 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004213 {
4214 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4215 "%s: failed to copy data to user buffer", __func__);
4216 ret = -EFAULT;
4217 goto exit;
4218 }
4219 }
4220 else if (strncmp(command, "GETFASTTRANSITION", 17) == 0)
4221 {
4222 tANI_BOOLEAN ft = sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4223 char extra[32];
4224 tANI_U8 len = 0;
4225
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004226 len = scnprintf(extra, sizeof(extra), "%s %d",
4227 "GETFASTTRANSITION", ft);
Sushant Kaushik231a4452015-07-15 16:23:56 +05304228 len = VOS_MIN(priv_data.total_len, len + 1);
4229 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004230 {
4231 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 }
4237 else if (strncmp(command, "SETROAMSCANCHANNELMINTIME", 25) == 0)
4238 {
4239 tANI_U8 *value = command;
4240 tANI_U8 minTime = CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_DEFAULT;
4241
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304242 ret = hdd_drv_cmd_validate(command, 25);
4243 if (ret)
4244 goto exit;
4245
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004246 /* Move pointer to ahead of SETROAMSCANCHANNELMINTIME<delimiter> */
4247 value = value + 26;
4248 /* Convert the value from ascii to integer */
4249 ret = kstrtou8(value, 10, &minTime);
4250 if (ret < 0)
4251 {
4252 /* If the input value is greater than max value of datatype, then also
4253 kstrtou8 fails */
4254 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4255 "%s: kstrtou8 failed range [%d - %d]", __func__,
4256 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
4257 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
4258 ret = -EINVAL;
4259 goto exit;
4260 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004261 if ((minTime < CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN) ||
4262 (minTime > CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX))
4263 {
4264 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4265 "scan min channel time value %d is out of range"
4266 " (Min: %d Max: %d)", minTime,
4267 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
4268 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
4269 ret = -EINVAL;
4270 goto exit;
4271 }
4272
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304273 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4274 TRACE_CODE_HDD_SETROAMSCANCHANNELMINTIME_IOCTL,
4275 pAdapter->sessionId, minTime));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004276 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4277 "%s: Received Command to change channel min time = %d", __func__, minTime);
4278
4279 pHddCtx->cfg_ini->nNeighborScanMinChanTime = minTime;
4280 sme_setNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal), minTime);
4281 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004282 else if (strncmp(command, "SENDACTIONFRAME", 15) == 0)
4283 {
4284 tANI_U8 *value = command;
4285 tANI_U8 channel = 0;
4286 tANI_U8 dwellTime = 0;
4287 tANI_U8 bufLen = 0;
4288 tANI_U8 *buf = NULL;
4289 tSirMacAddr targetApBssid;
4290 eHalStatus status = eHAL_STATUS_SUCCESS;
4291 struct ieee80211_channel chan;
4292 tANI_U8 finalLen = 0;
4293 tANI_U8 *finalBuf = NULL;
4294 tANI_U8 temp = 0;
4295 u64 cookie;
4296 hdd_station_ctx_t *pHddStaCtx = NULL;
4297 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4298
4299 /* if not associated, no need to send action frame */
4300 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
4301 {
4302 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
4303 ret = -EINVAL;
4304 goto exit;
4305 }
4306
4307 status = hdd_parse_send_action_frame_data(value, targetApBssid, &channel,
4308 &dwellTime, &buf, &bufLen);
4309 if (eHAL_STATUS_SUCCESS != status)
4310 {
4311 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4312 "%s: Failed to parse send action frame data", __func__);
4313 ret = -EINVAL;
4314 goto exit;
4315 }
4316
4317 /* if the target bssid is different from currently associated AP,
4318 then no need to send action frame */
4319 if (VOS_TRUE != vos_mem_compare(targetApBssid,
4320 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
4321 {
4322 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:STA is not associated to this AP!",__func__);
4323 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004324 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004325 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004326 goto exit;
4327 }
4328
4329 /* if the channel number is different from operating channel then
4330 no need to send action frame */
4331 if (channel != pHddStaCtx->conn_info.operationChannel)
4332 {
4333 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4334 "%s: channel(%d) is different from operating channel(%d)",
4335 __func__, channel, pHddStaCtx->conn_info.operationChannel);
4336 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004337 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004338 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004339 goto exit;
4340 }
4341 chan.center_freq = sme_ChnToFreq(channel);
4342
4343 finalLen = bufLen + 24;
4344 finalBuf = vos_mem_malloc(finalLen);
4345 if (NULL == finalBuf)
4346 {
4347 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:memory allocation failed",__func__);
4348 ret = -ENOMEM;
Jeff Johnson11c33152013-04-16 17:52:40 -07004349 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004350 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004351 goto exit;
4352 }
4353 vos_mem_zero(finalBuf, finalLen);
4354
4355 /* Fill subtype */
4356 temp = SIR_MAC_MGMT_ACTION << 4;
4357 vos_mem_copy(finalBuf + 0, &temp, sizeof(temp));
4358
4359 /* Fill type */
4360 temp = SIR_MAC_MGMT_FRAME;
4361 vos_mem_copy(finalBuf + 2, &temp, sizeof(temp));
4362
4363 /* Fill destination address (bssid of the AP) */
4364 vos_mem_copy(finalBuf + 4, targetApBssid, sizeof(targetApBssid));
4365
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07004366 /* Fill source address (STA mac address) */
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004367 vos_mem_copy(finalBuf + 10, pAdapter->macAddressCurrent.bytes, sizeof(pAdapter->macAddressCurrent.bytes));
4368
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07004369 /* Fill BSSID (AP mac address) */
4370 vos_mem_copy(finalBuf + 16, targetApBssid, sizeof(targetApBssid));
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004371
4372 /* Fill received buffer from 24th address */
4373 vos_mem_copy(finalBuf + 24, buf, bufLen);
4374
Jeff Johnson11c33152013-04-16 17:52:40 -07004375 /* done with the parsed buffer */
4376 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004377 buf = NULL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004378
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05304379#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
4380 params.chan = &chan;
4381 params.offchan = 0;
4382 params.wait = dwellTime;
4383 params.buf = finalBuf;
4384 params.len = finalLen;
4385 params.no_cck = 1;
4386 params.dont_wait_for_ack = 1;
4387 ret = wlan_hdd_mgmt_tx(NULL, &pAdapter->wdev, &params, &cookie);
4388#else
DARAM SUDHA39eede62014-02-12 11:16:40 +05304389 wlan_hdd_mgmt_tx( NULL,
Yue Maf49ba872013-08-19 12:04:25 -07004390#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4391 &(pAdapter->wdev),
4392#else
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004393 pAdapter->dev,
Yue Maf49ba872013-08-19 12:04:25 -07004394#endif
4395 &chan, 0,
4396#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
4397 NL80211_CHAN_HT20, 1,
4398#endif
4399 dwellTime, finalBuf, finalLen, 1,
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004400 1, &cookie );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05304401#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)*/
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004402 vos_mem_free(finalBuf);
4403 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004404 else if (strncmp(command, "GETROAMSCANCHANNELMINTIME", 25) == 0)
4405 {
4406 tANI_U16 val = sme_getNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal));
4407 char extra[32];
4408 tANI_U8 len = 0;
4409
4410 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004411 len = scnprintf(extra, sizeof(extra), "%s %d",
4412 "GETROAMSCANCHANNELMINTIME", val);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304413 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4414 TRACE_CODE_HDD_GETROAMSCANCHANNELMINTIME_IOCTL,
4415 pAdapter->sessionId, val));
Sushant Kaushikbb8c52c2015-07-15 16:36:23 +05304416 len = VOS_MIN(priv_data.total_len, len + 1);
4417 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004418 {
4419 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4420 "%s: failed to copy data to user buffer", __func__);
4421 ret = -EFAULT;
4422 goto exit;
4423 }
4424 }
4425 else if (strncmp(command, "SETSCANCHANNELTIME", 18) == 0)
4426 {
4427 tANI_U8 *value = command;
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004428 tANI_U16 maxTime = CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004429
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304430 ret = hdd_drv_cmd_validate(command, 18);
4431 if (ret)
4432 goto exit;
4433
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004434 /* Move pointer to ahead of SETSCANCHANNELTIME<delimiter> */
4435 value = value + 19;
4436 /* Convert the value from ascii to integer */
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004437 ret = kstrtou16(value, 10, &maxTime);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004438 if (ret < 0)
4439 {
4440 /* If the input value is greater than max value of datatype, then also
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004441 kstrtou16 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004442 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004443 "%s: kstrtou16 failed range [%d - %d]", __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004444 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
4445 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
4446 ret = -EINVAL;
4447 goto exit;
4448 }
4449
4450 if ((maxTime < CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN) ||
4451 (maxTime > CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX))
4452 {
4453 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4454 "lfr mode value %d is out of range"
4455 " (Min: %d Max: %d)", maxTime,
4456 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
4457 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
4458 ret = -EINVAL;
4459 goto exit;
4460 }
4461
4462 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4463 "%s: Received Command to change channel max time = %d", __func__, maxTime);
4464
4465 pHddCtx->cfg_ini->nNeighborScanMaxChanTime = maxTime;
4466 sme_setNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal), maxTime);
4467 }
4468 else if (strncmp(command, "GETSCANCHANNELTIME", 18) == 0)
4469 {
4470 tANI_U16 val = sme_getNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal));
4471 char extra[32];
4472 tANI_U8 len = 0;
4473
4474 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004475 len = scnprintf(extra, sizeof(extra), "%s %d",
4476 "GETSCANCHANNELTIME", val);
Ratheesh S Pacbfa932015-07-16 15:27:18 +05304477 len = VOS_MIN(priv_data.total_len, len + 1);
4478 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004479 {
4480 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4481 "%s: failed to copy data to user buffer", __func__);
4482 ret = -EFAULT;
4483 goto exit;
4484 }
4485 }
4486 else if (strncmp(command, "SETSCANHOMETIME", 15) == 0)
4487 {
4488 tANI_U8 *value = command;
4489 tANI_U16 val = CFG_NEIGHBOR_SCAN_TIMER_PERIOD_DEFAULT;
4490
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304491 ret = hdd_drv_cmd_validate(command, 15);
4492 if (ret)
4493 goto exit;
4494
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004495 /* Move pointer to ahead of SETSCANHOMETIME<delimiter> */
4496 value = value + 16;
4497 /* Convert the value from ascii to integer */
4498 ret = kstrtou16(value, 10, &val);
4499 if (ret < 0)
4500 {
4501 /* If the input value is greater than max value of datatype, then also
4502 kstrtou16 fails */
4503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4504 "%s: kstrtou16 failed range [%d - %d]", __func__,
4505 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
4506 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
4507 ret = -EINVAL;
4508 goto exit;
4509 }
4510
4511 if ((val < CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN) ||
4512 (val > CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX))
4513 {
4514 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4515 "scan home time value %d is out of range"
4516 " (Min: %d Max: %d)", val,
4517 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
4518 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
4519 ret = -EINVAL;
4520 goto exit;
4521 }
4522
4523 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4524 "%s: Received Command to change scan home time = %d", __func__, val);
4525
4526 pHddCtx->cfg_ini->nNeighborScanPeriod = val;
4527 sme_setNeighborScanPeriod((tHalHandle)(pHddCtx->hHal), val);
4528 }
4529 else if (strncmp(command, "GETSCANHOMETIME", 15) == 0)
4530 {
4531 tANI_U16 val = sme_getNeighborScanPeriod((tHalHandle)(pHddCtx->hHal));
4532 char extra[32];
4533 tANI_U8 len = 0;
4534
4535 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004536 len = scnprintf(extra, sizeof(extra), "%s %d",
4537 "GETSCANHOMETIME", val);
Ratheesh S P728d7c62015-07-16 15:38:58 +05304538 len = VOS_MIN(priv_data.total_len, len + 1);
4539 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004540 {
4541 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4542 "%s: failed to copy data to user buffer", __func__);
4543 ret = -EFAULT;
4544 goto exit;
4545 }
4546 }
4547 else if (strncmp(command, "SETROAMINTRABAND", 16) == 0)
4548 {
4549 tANI_U8 *value = command;
4550 tANI_U8 val = CFG_ROAM_INTRA_BAND_DEFAULT;
4551
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304552 ret = hdd_drv_cmd_validate(command, 16);
4553 if (ret)
4554 goto exit;
4555
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004556 /* Move pointer to ahead of SETROAMINTRABAND<delimiter> */
4557 value = value + 17;
4558 /* Convert the value from ascii to integer */
4559 ret = kstrtou8(value, 10, &val);
4560 if (ret < 0)
4561 {
4562 /* If the input value is greater than max value of datatype, then also
4563 kstrtou8 fails */
4564 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4565 "%s: kstrtou8 failed range [%d - %d]", __func__,
4566 CFG_ROAM_INTRA_BAND_MIN,
4567 CFG_ROAM_INTRA_BAND_MAX);
4568 ret = -EINVAL;
4569 goto exit;
4570 }
4571
4572 if ((val < CFG_ROAM_INTRA_BAND_MIN) ||
4573 (val > CFG_ROAM_INTRA_BAND_MAX))
4574 {
4575 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4576 "intra band mode value %d is out of range"
4577 " (Min: %d Max: %d)", val,
4578 CFG_ROAM_INTRA_BAND_MIN,
4579 CFG_ROAM_INTRA_BAND_MAX);
4580 ret = -EINVAL;
4581 goto exit;
4582 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004583 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4584 "%s: Received Command to change intra band = %d", __func__, val);
4585
4586 pHddCtx->cfg_ini->nRoamIntraBand = val;
4587 sme_setRoamIntraBand((tHalHandle)(pHddCtx->hHal), val);
4588 }
4589 else if (strncmp(command, "GETROAMINTRABAND", 16) == 0)
4590 {
4591 tANI_U16 val = sme_getRoamIntraBand((tHalHandle)(pHddCtx->hHal));
4592 char extra[32];
4593 tANI_U8 len = 0;
4594
4595 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004596 len = scnprintf(extra, sizeof(extra), "%s %d",
4597 "GETROAMINTRABAND", val);
Ratheesh S P2dd2a3e2015-07-16 15:34:23 +05304598 len = VOS_MIN(priv_data.total_len, len + 1);
4599 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004600 {
4601 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4602 "%s: failed to copy data to user buffer", __func__);
4603 ret = -EFAULT;
4604 goto exit;
4605 }
4606 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004607 else if (strncmp(command, "SETSCANNPROBES", 14) == 0)
4608 {
4609 tANI_U8 *value = command;
4610 tANI_U8 nProbes = CFG_ROAM_SCAN_N_PROBES_DEFAULT;
4611
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304612 ret = hdd_drv_cmd_validate(command, 14);
4613 if (ret)
4614 goto exit;
4615
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004616 /* Move pointer to ahead of SETSCANNPROBES<delimiter> */
4617 value = value + 15;
4618 /* Convert the value from ascii to integer */
4619 ret = kstrtou8(value, 10, &nProbes);
4620 if (ret < 0)
4621 {
4622 /* If the input value is greater than max value of datatype, then also
4623 kstrtou8 fails */
4624 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4625 "%s: kstrtou8 failed range [%d - %d]", __func__,
4626 CFG_ROAM_SCAN_N_PROBES_MIN,
4627 CFG_ROAM_SCAN_N_PROBES_MAX);
4628 ret = -EINVAL;
4629 goto exit;
4630 }
4631
4632 if ((nProbes < CFG_ROAM_SCAN_N_PROBES_MIN) ||
4633 (nProbes > CFG_ROAM_SCAN_N_PROBES_MAX))
4634 {
4635 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4636 "NProbes value %d is out of range"
4637 " (Min: %d Max: %d)", nProbes,
4638 CFG_ROAM_SCAN_N_PROBES_MIN,
4639 CFG_ROAM_SCAN_N_PROBES_MAX);
4640 ret = -EINVAL;
4641 goto exit;
4642 }
4643
4644 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4645 "%s: Received Command to Set nProbes = %d", __func__, nProbes);
4646
4647 pHddCtx->cfg_ini->nProbes = nProbes;
4648 sme_UpdateRoamScanNProbes((tHalHandle)(pHddCtx->hHal), nProbes);
4649 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304650 else if (strncmp(command, "GETSCANNPROBES", 14) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004651 {
4652 tANI_U8 val = sme_getRoamScanNProbes((tHalHandle)(pHddCtx->hHal));
4653 char extra[32];
4654 tANI_U8 len = 0;
4655
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004656 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri6da525d2015-08-07 13:55:54 +05304657 len = VOS_MIN(priv_data.total_len, len + 1);
4658 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004659 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4660 "%s: failed to copy data to user buffer", __func__);
4661 ret = -EFAULT;
4662 goto exit;
4663 }
4664 }
4665 else if (strncmp(command, "SETSCANHOMEAWAYTIME", 19) == 0)
4666 {
4667 tANI_U8 *value = command;
4668 tANI_U16 homeAwayTime = CFG_ROAM_SCAN_HOME_AWAY_TIME_DEFAULT;
4669
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304670 ret = hdd_drv_cmd_validate(command, 19);
4671 if (ret)
4672 goto exit;
4673
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004674 /* Move pointer to ahead of SETSCANHOMEAWAYTIME<delimiter> */
4675 /* input value is in units of msec */
4676 value = value + 20;
4677 /* Convert the value from ascii to integer */
4678 ret = kstrtou16(value, 10, &homeAwayTime);
4679 if (ret < 0)
4680 {
4681 /* If the input value is greater than max value of datatype, then also
4682 kstrtou8 fails */
4683 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4684 "%s: kstrtou8 failed range [%d - %d]", __func__,
4685 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
4686 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
4687 ret = -EINVAL;
4688 goto exit;
4689 }
4690
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004691 if ((homeAwayTime < CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN) ||
4692 (homeAwayTime > CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX))
4693 {
4694 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4695 "homeAwayTime value %d is out of range"
4696 " (Min: %d Max: %d)", homeAwayTime,
4697 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
4698 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
4699 ret = -EINVAL;
4700 goto exit;
4701 }
4702
4703 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4704 "%s: Received Command to Set scan away time = %d", __func__, homeAwayTime);
Srinivas Girigowda6cf0b822013-06-27 14:00:20 -07004705 if (pHddCtx->cfg_ini->nRoamScanHomeAwayTime != homeAwayTime)
4706 {
4707 pHddCtx->cfg_ini->nRoamScanHomeAwayTime = homeAwayTime;
4708 sme_UpdateRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal), homeAwayTime, eANI_BOOLEAN_TRUE);
4709 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004710 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304711 else if (strncmp(command, "GETSCANHOMEAWAYTIME", 19) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004712 {
4713 tANI_U16 val = sme_getRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal));
4714 char extra[32];
4715 tANI_U8 len = 0;
4716
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004717 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri51a5ad12015-08-07 14:06:37 +05304718 len = VOS_MIN(priv_data.total_len, len + 1);
4719 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004720 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4721 "%s: failed to copy data to user buffer", __func__);
4722 ret = -EFAULT;
4723 goto exit;
4724 }
4725 }
4726 else if (strncmp(command, "REASSOC", 7) == 0)
4727 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304728 ret = hdd_drv_cmd_validate(command, 7);
4729 if (ret)
4730 goto exit;
4731
4732 ret = hdd_parse_reassoc(pAdapter, command, priv_data.total_len);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05304733 if (!ret)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004734 goto exit;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004735 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07004736 else if (strncmp(command, "SETWESMODE", 10) == 0)
4737 {
4738 tANI_U8 *value = command;
4739 tANI_BOOLEAN wesMode = CFG_ENABLE_WES_MODE_NAME_DEFAULT;
4740
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304741 ret = hdd_drv_cmd_validate(command, 10);
4742 if (ret)
4743 goto exit;
4744
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07004745 /* Move pointer to ahead of SETWESMODE<delimiter> */
4746 value = value + 11;
4747 /* Convert the value from ascii to integer */
4748 ret = kstrtou8(value, 10, &wesMode);
4749 if (ret < 0)
4750 {
4751 /* If the input value is greater than max value of datatype, then also
4752 kstrtou8 fails */
4753 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4754 "%s: kstrtou8 failed range [%d - %d]", __func__,
4755 CFG_ENABLE_WES_MODE_NAME_MIN,
4756 CFG_ENABLE_WES_MODE_NAME_MAX);
4757 ret = -EINVAL;
4758 goto exit;
4759 }
4760
4761 if ((wesMode < CFG_ENABLE_WES_MODE_NAME_MIN) ||
4762 (wesMode > CFG_ENABLE_WES_MODE_NAME_MAX))
4763 {
4764 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4765 "WES Mode value %d is out of range"
4766 " (Min: %d Max: %d)", wesMode,
4767 CFG_ENABLE_WES_MODE_NAME_MIN,
4768 CFG_ENABLE_WES_MODE_NAME_MAX);
4769 ret = -EINVAL;
4770 goto exit;
4771 }
4772 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4773 "%s: Received Command to Set WES Mode rssi diff = %d", __func__, wesMode);
4774
4775 pHddCtx->cfg_ini->isWESModeEnabled = wesMode;
4776 sme_UpdateWESMode((tHalHandle)(pHddCtx->hHal), wesMode);
4777 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304778 else if (strncmp(command, "GETWESMODE", 10) == 0)
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07004779 {
4780 tANI_BOOLEAN wesMode = sme_GetWESMode((tHalHandle)(pHddCtx->hHal));
4781 char extra[32];
4782 tANI_U8 len = 0;
4783
Arif Hussain826d9412013-11-12 16:44:54 -08004784 len = scnprintf(extra, sizeof(extra), "%s %d", command, wesMode);
Ratnam Rachuri8fe90c62015-08-07 14:03:26 +05304785 len = VOS_MIN(priv_data.total_len, len + 1);
4786 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07004787 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4788 "%s: failed to copy data to user buffer", __func__);
4789 ret = -EFAULT;
4790 goto exit;
4791 }
4792 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004793#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE || FEATURE_WLAN_LFR */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004794#ifdef FEATURE_WLAN_LFR
4795 else if (strncmp(command, "SETFASTROAM", 11) == 0)
4796 {
4797 tANI_U8 *value = command;
4798 tANI_U8 lfrMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
4799
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05304800 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
4801 hddLog(LOGE,
4802 FL("Roaming is always disabled in STA + MON concurrency"));
4803 ret = -EINVAL;
4804 goto exit;
4805 }
4806
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304807 ret = hdd_drv_cmd_validate(command, 11);
4808 if (ret)
4809 goto exit;
4810
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004811 /* Move pointer to ahead of SETFASTROAM<delimiter> */
4812 value = value + 12;
4813 /* Convert the value from ascii to integer */
4814 ret = kstrtou8(value, 10, &lfrMode);
4815 if (ret < 0)
4816 {
4817 /* If the input value is greater than max value of datatype, then also
4818 kstrtou8 fails */
4819 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4820 "%s: kstrtou8 failed range [%d - %d]", __func__,
4821 CFG_LFR_FEATURE_ENABLED_MIN,
4822 CFG_LFR_FEATURE_ENABLED_MAX);
4823 ret = -EINVAL;
4824 goto exit;
4825 }
4826
4827 if ((lfrMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
4828 (lfrMode > CFG_LFR_FEATURE_ENABLED_MAX))
4829 {
4830 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4831 "lfr mode value %d is out of range"
4832 " (Min: %d Max: %d)", lfrMode,
4833 CFG_LFR_FEATURE_ENABLED_MIN,
4834 CFG_LFR_FEATURE_ENABLED_MAX);
4835 ret = -EINVAL;
4836 goto exit;
4837 }
4838
4839 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4840 "%s: Received Command to change lfr mode = %d", __func__, lfrMode);
4841
4842 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = lfrMode;
4843 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), lfrMode);
4844 }
4845#endif
4846#ifdef WLAN_FEATURE_VOWIFI_11R
4847 else if (strncmp(command, "SETFASTTRANSITION", 17) == 0)
4848 {
4849 tANI_U8 *value = command;
4850 tANI_U8 ft = CFG_FAST_TRANSITION_ENABLED_NAME_DEFAULT;
4851
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304852 ret = hdd_drv_cmd_validate(command, 17);
4853 if (ret)
4854 goto exit;
4855
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004856 /* Move pointer to ahead of SETFASTROAM<delimiter> */
4857 value = value + 18;
4858 /* Convert the value from ascii to integer */
4859 ret = kstrtou8(value, 10, &ft);
4860 if (ret < 0)
4861 {
4862 /* If the input value is greater than max value of datatype, then also
4863 kstrtou8 fails */
4864 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4865 "%s: kstrtou8 failed range [%d - %d]", __func__,
4866 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
4867 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
4868 ret = -EINVAL;
4869 goto exit;
4870 }
4871
4872 if ((ft < CFG_FAST_TRANSITION_ENABLED_NAME_MIN) ||
4873 (ft > CFG_FAST_TRANSITION_ENABLED_NAME_MAX))
4874 {
4875 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4876 "ft mode value %d is out of range"
4877 " (Min: %d Max: %d)", ft,
4878 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
4879 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
4880 ret = -EINVAL;
4881 goto exit;
4882 }
4883
4884 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4885 "%s: Received Command to change ft mode = %d", __func__, ft);
4886
4887 pHddCtx->cfg_ini->isFastTransitionEnabled = ft;
4888 sme_UpdateFastTransitionEnabled((tHalHandle)(pHddCtx->hHal), ft);
4889 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304890 else if (strncmp(command, "SETDFSSCANMODE", 14) == 0)
4891 {
4892 tANI_U8 *value = command;
4893 tANI_U8 dfsScanMode = DFS_CHNL_SCAN_ENABLED_NORMAL;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304894
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304895 ret = hdd_drv_cmd_validate(command, 14);
4896 if (ret)
4897 goto exit;
4898
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304899 /* Move pointer to ahead of SETDFSSCANMODE<delimiter> */
4900 value = value + 15;
4901 /* Convert the value from ascii to integer */
4902 ret = kstrtou8(value, 10, &dfsScanMode);
4903 if (ret < 0)
4904 {
4905 /* If the input value is greater than max value of
4906 datatype, then also kstrtou8 fails
4907 */
4908 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4909 "%s: kstrtou8 failed range [%d - %d]", __func__,
4910 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
4911 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
4912 ret = -EINVAL;
4913 goto exit;
4914 }
4915
4916 if ((dfsScanMode < CFG_ENABLE_DFS_CHNL_SCAN_MIN) ||
4917 (dfsScanMode > CFG_ENABLE_DFS_CHNL_SCAN_MAX))
4918 {
4919 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4920 "dfsScanMode value %d is out of range"
4921 " (Min: %d Max: %d)", dfsScanMode,
4922 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
4923 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
4924 ret = -EINVAL;
4925 goto exit;
4926 }
4927 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4928 "%s: Received Command to Set DFS Scan Mode = %d",
4929 __func__, dfsScanMode);
4930
4931 ret = wlan_hdd_handle_dfs_chan_scan(pHddCtx, dfsScanMode);
4932 }
4933 else if (strncmp(command, "GETDFSSCANMODE", 14) == 0)
4934 {
4935 tANI_U8 dfsScanMode = sme_GetDFSScanMode(pHddCtx->hHal);
4936 char extra[32];
4937 tANI_U8 len = 0;
4938
4939 len = scnprintf(extra, sizeof(extra), "%s %d", command, dfsScanMode);
Ratheesh S P767224e2015-07-16 15:35:51 +05304940 len = VOS_MIN(priv_data.total_len, len + 1);
4941 if (copy_to_user(priv_data.buf, &extra, len))
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304942 {
4943 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4944 "%s: failed to copy data to user buffer", __func__);
4945 ret = -EFAULT;
4946 goto exit;
4947 }
4948 }
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304949 else if (strncmp(command, "FASTREASSOC", 11) == 0)
4950 {
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05304951 ret = wlan_hdd_handle_fastreassoc(pAdapter, command);
4952 if (!ret)
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304953 goto exit;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304954 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004955#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004956#ifdef FEATURE_WLAN_ESE
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004957 else if (strncmp(command, "SETCCXMODE", 10) == 0)
4958 {
4959 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004960 tANI_U8 eseMode = CFG_ESE_FEATURE_ENABLED_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004961
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304962 ret = hdd_drv_cmd_validate(command, 10);
4963 if (ret)
4964 goto exit;
4965
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004966 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004967 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004968 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004969 hdd_is_okc_mode_enabled(pHddCtx) &&
4970 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4971 {
4972 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004973 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004974 " hence this operation is not permitted!", __func__);
4975 ret = -EPERM;
4976 goto exit;
4977 }
4978
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004979 /* Move pointer to ahead of SETCCXMODE<delimiter> */
4980 value = value + 11;
4981 /* Convert the value from ascii to integer */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004982 ret = kstrtou8(value, 10, &eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004983 if (ret < 0)
4984 {
4985 /* If the input value is greater than max value of datatype, then also
4986 kstrtou8 fails */
4987 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4988 "%s: kstrtou8 failed range [%d - %d]", __func__,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004989 CFG_ESE_FEATURE_ENABLED_MIN,
4990 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004991 ret = -EINVAL;
4992 goto exit;
4993 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004994 if ((eseMode < CFG_ESE_FEATURE_ENABLED_MIN) ||
4995 (eseMode > CFG_ESE_FEATURE_ENABLED_MAX))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004996 {
4997 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004998 "Ese mode value %d is out of range"
4999 " (Min: %d Max: %d)", eseMode,
5000 CFG_ESE_FEATURE_ENABLED_MIN,
5001 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005002 ret = -EINVAL;
5003 goto exit;
5004 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005005 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005006 "%s: Received Command to change ese mode = %d", __func__, eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005007
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005008 pHddCtx->cfg_ini->isEseIniFeatureEnabled = eseMode;
5009 sme_UpdateIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal), eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005010 }
5011#endif
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005012 else if (strncmp(command, "SETROAMSCANCONTROL", 18) == 0)
5013 {
5014 tANI_U8 *value = command;
5015 tANI_BOOLEAN roamScanControl = 0;
5016
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305017 ret = hdd_drv_cmd_validate(command, 18);
5018 if (ret)
5019 goto exit;
5020
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005021 /* Move pointer to ahead of SETROAMSCANCONTROL<delimiter> */
5022 value = value + 19;
5023 /* Convert the value from ascii to integer */
5024 ret = kstrtou8(value, 10, &roamScanControl);
5025 if (ret < 0)
5026 {
5027 /* If the input value is greater than max value of datatype, then also
5028 kstrtou8 fails */
5029 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5030 "%s: kstrtou8 failed ", __func__);
5031 ret = -EINVAL;
5032 goto exit;
5033 }
5034
5035 if (0 != roamScanControl)
5036 {
5037 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5038 "roam scan control invalid value = %d",
5039 roamScanControl);
5040 ret = -EINVAL;
5041 goto exit;
5042 }
5043 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5044 "%s: Received Command to Set roam scan control = %d", __func__, roamScanControl);
5045
5046 sme_SetRoamScanControl((tHalHandle)(pHddCtx->hHal), roamScanControl);
5047 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005048#ifdef FEATURE_WLAN_OKC
5049 else if (strncmp(command, "SETOKCMODE", 10) == 0)
5050 {
5051 tANI_U8 *value = command;
5052 tANI_U8 okcMode = CFG_OKC_FEATURE_ENABLED_DEFAULT;
5053
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305054 ret = hdd_drv_cmd_validate(command, 10);
5055 if (ret)
5056 goto exit;
5057
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005058 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005059 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005060 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005061 hdd_is_okc_mode_enabled(pHddCtx) &&
5062 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
5063 {
5064 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005065 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005066 " hence this operation is not permitted!", __func__);
5067 ret = -EPERM;
5068 goto exit;
5069 }
5070
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005071 /* Move pointer to ahead of SETOKCMODE<delimiter> */
5072 value = value + 11;
5073 /* Convert the value from ascii to integer */
5074 ret = kstrtou8(value, 10, &okcMode);
5075 if (ret < 0)
5076 {
5077 /* If the input value is greater than max value of datatype, then also
5078 kstrtou8 fails */
5079 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5080 "%s: kstrtou8 failed range [%d - %d]", __func__,
5081 CFG_OKC_FEATURE_ENABLED_MIN,
5082 CFG_OKC_FEATURE_ENABLED_MAX);
5083 ret = -EINVAL;
5084 goto exit;
5085 }
5086
5087 if ((okcMode < CFG_OKC_FEATURE_ENABLED_MIN) ||
5088 (okcMode > CFG_OKC_FEATURE_ENABLED_MAX))
5089 {
5090 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5091 "Okc mode value %d is out of range"
5092 " (Min: %d Max: %d)", okcMode,
5093 CFG_OKC_FEATURE_ENABLED_MIN,
5094 CFG_OKC_FEATURE_ENABLED_MAX);
5095 ret = -EINVAL;
5096 goto exit;
5097 }
5098
5099 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5100 "%s: Received Command to change okc mode = %d", __func__, okcMode);
5101
5102 pHddCtx->cfg_ini->isOkcIniFeatureEnabled = okcMode;
5103 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005104#endif /* FEATURE_WLAN_OKC */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305105 else if (strncmp(command, "GETROAMSCANCONTROL", 18) == 0)
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005106 {
5107 tANI_BOOLEAN roamScanControl = sme_GetRoamScanControl((tHalHandle)(pHddCtx->hHal));
5108 char extra[32];
5109 tANI_U8 len = 0;
5110
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005111 len = scnprintf(extra, sizeof(extra), "%s %d",
5112 command, roamScanControl);
Ratnam Rachuri083ada82015-08-07 14:01:05 +05305113 len = VOS_MIN(priv_data.total_len, len + 1);
5114 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005115 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5116 "%s: failed to copy data to user buffer", __func__);
5117 ret = -EFAULT;
5118 goto exit;
5119 }
5120 }
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05305121#ifdef WLAN_FEATURE_PACKET_FILTERING
5122 else if (strncmp(command, "ENABLE_PKTFILTER_IPV6", 21) == 0)
5123 {
5124 tANI_U8 filterType = 0;
5125 tANI_U8 *value = command;
5126
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305127 ret = hdd_drv_cmd_validate(command, 21);
5128 if (ret)
5129 goto exit;
5130
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05305131 /* Move pointer to ahead of ENABLE_PKTFILTER_IPV6<delimiter> */
5132 value = value + 22;
5133
5134 /* Convert the value from ascii to integer */
5135 ret = kstrtou8(value, 10, &filterType);
5136 if (ret < 0)
5137 {
5138 /* If the input value is greater than max value of datatype,
5139 * then also kstrtou8 fails
5140 */
5141 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5142 "%s: kstrtou8 failed range ", __func__);
5143 ret = -EINVAL;
5144 goto exit;
5145 }
5146
5147 if (filterType != 0 && filterType != 1)
5148 {
5149 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5150 "%s: Accepted Values are 0 and 1 ", __func__);
5151 ret = -EINVAL;
5152 goto exit;
5153 }
5154 wlan_hdd_setIPv6Filter(WLAN_HDD_GET_CTX(pAdapter), filterType,
5155 pAdapter->sessionId);
5156 }
5157#endif
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305158 else if (strncmp(command, "BTCOEXMODE", 10) == 0 )
5159 {
Kiet Lamad161252014-07-22 11:23:32 -07005160 char *dhcpPhase;
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05305161 int ret;
5162
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305163 ret = hdd_drv_cmd_validate(command, 10);
5164 if (ret)
5165 goto exit;
5166
Kiet Lamad161252014-07-22 11:23:32 -07005167 dhcpPhase = command + 11;
5168 if ('1' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305169 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05305170 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07005171 FL("send DHCP START indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05305172
5173 pHddCtx->btCoexModeSet = TRUE;
Kiet Lamad161252014-07-22 11:23:32 -07005174
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05305175 ret = wlan_hdd_scan_abort(pAdapter);
5176 if (ret < 0)
5177 {
5178 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5179 FL("failed to abort existing scan %d"), ret);
5180 }
5181
Kiet Lamad161252014-07-22 11:23:32 -07005182 sme_DHCPStartInd(pHddCtx->hHal, pAdapter->device_mode,
5183 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305184 }
Kiet Lamad161252014-07-22 11:23:32 -07005185 else if ('2' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305186 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05305187 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07005188 FL("send DHCP STOP indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05305189
5190 pHddCtx->btCoexModeSet = FALSE;
Kiet Lamad161252014-07-22 11:23:32 -07005191
5192 sme_DHCPStopInd(pHddCtx->hHal, pAdapter->device_mode,
5193 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305194 }
5195 }
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005196 else if (strncmp(command, "SCAN-ACTIVE", 11) == 0)
5197 {
Abhishek Singh58749d62016-02-03 15:27:20 +05305198 hddLog(LOG1,
5199 FL("making default scan to ACTIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05305200 pHddCtx->scan_info.scan_mode = eSIR_ACTIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005201 }
5202 else if (strncmp(command, "SCAN-PASSIVE", 12) == 0)
5203 {
Abhishek Singh58749d62016-02-03 15:27:20 +05305204 hddLog(LOG1,
5205 FL("making default scan to PASSIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05305206 pHddCtx->scan_info.scan_mode = eSIR_PASSIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005207 }
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305208 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
5209 {
5210 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5211 char extra[32];
5212 tANI_U8 len = 0;
5213
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05305214 memset(extra, 0, sizeof(extra));
5215 ret = hdd_get_dwell_time(pCfg, command, extra, sizeof(extra), &len);
Ratnam Rachuri12d5d462015-08-07 14:10:23 +05305216 len = VOS_MIN(priv_data.total_len, len + 1);
5217 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305218 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5219 "%s: failed to copy data to user buffer", __func__);
5220 ret = -EFAULT;
5221 goto exit;
5222 }
5223 ret = len;
5224 }
5225 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
5226 {
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05305227 ret = hdd_set_dwell_time(pAdapter, command);
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305228 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005229 else if ( strncasecmp(command, "MIRACAST", 8) == 0 )
5230 {
5231 tANI_U8 filterType = 0;
5232 tANI_U8 *value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305233
5234 ret = hdd_drv_cmd_validate(command, 8);
5235 if (ret)
5236 goto exit;
5237
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005238 value = command + 9;
5239
5240 /* Convert the value from ascii to integer */
5241 ret = kstrtou8(value, 10, &filterType);
5242 if (ret < 0)
5243 {
5244 /* If the input value is greater than max value of datatype,
5245 * then also kstrtou8 fails
5246 */
5247 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5248 "%s: kstrtou8 failed range ", __func__);
5249 ret = -EINVAL;
5250 goto exit;
5251 }
5252 if ((filterType < WLAN_HDD_DRIVER_MIRACAST_CFG_MIN_VAL ) ||
5253 (filterType > WLAN_HDD_DRIVER_MIRACAST_CFG_MAX_VAL))
5254 {
5255 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5256 "%s: Accepted Values are 0 to 2. 0-Disabled, 1-Source,"
5257 " 2-Sink ", __func__);
5258 ret = -EINVAL;
5259 goto exit;
5260 }
5261 //Filtertype value should be either 0-Disabled, 1-Source, 2-sink
5262 pHddCtx->drvr_miracast = filterType;
Kaushik, Sushant96122442014-10-21 16:40:18 +05305263 pScanInfo = &pHddCtx->scan_info;
5264 if (filterType && pScanInfo != NULL &&
5265 pHddCtx->scan_info.mScanPending)
5266 {
5267 /*Miracast Session started. Abort Scan */
5268 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5269 "%s, Aborting Scan For Miracast",__func__);
5270 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
5271 eCSR_SCAN_ABORT_DEFAULT);
5272 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005273 hdd_tx_rx_pkt_cnt_stat_timer_handler(pHddCtx);
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05305274 sme_SetMiracastMode(pHddCtx->hHal, pHddCtx->drvr_miracast);
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005275 }
Leo Chang614d2072013-08-22 14:59:44 -07005276 else if (strncmp(command, "SETMCRATE", 9) == 0)
5277 {
Leo Chang614d2072013-08-22 14:59:44 -07005278 tANI_U8 *value = command;
5279 int targetRate;
Leo Chang1f98cbd2013-10-17 15:03:52 -07005280 tSirRateUpdateInd *rateUpdate;
5281 eHalStatus status;
Leo Chang614d2072013-08-22 14:59:44 -07005282
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305283 ret = hdd_drv_cmd_validate(command, 9);
5284 if (ret)
5285 goto exit;
5286
Leo Chang614d2072013-08-22 14:59:44 -07005287 /* Only valid for SAP mode */
5288 if (WLAN_HDD_SOFTAP != pAdapter->device_mode)
5289 {
5290 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5291 "%s: SAP mode is not running", __func__);
5292 ret = -EFAULT;
5293 goto exit;
5294 }
5295
5296 /* Move pointer to ahead of SETMCRATE<delimiter> */
5297 /* input value is in units of hundred kbps */
5298 value = value + 10;
5299 /* Convert the value from ascii to integer, decimal base */
5300 ret = kstrtouint(value, 10, &targetRate);
5301
Leo Chang1f98cbd2013-10-17 15:03:52 -07005302 rateUpdate = (tSirRateUpdateInd *)vos_mem_malloc(sizeof(tSirRateUpdateInd));
5303 if (NULL == rateUpdate)
Leo Chang614d2072013-08-22 14:59:44 -07005304 {
Leo Chang1f98cbd2013-10-17 15:03:52 -07005305 hddLog(VOS_TRACE_LEVEL_ERROR,
5306 "%s: SETMCRATE indication alloc fail", __func__);
5307 ret = -EFAULT;
5308 goto exit;
5309 }
5310 vos_mem_zero(rateUpdate, sizeof(tSirRateUpdateInd ));
5311
5312 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5313 "MC Target rate %d", targetRate);
5314 /* Ignore unicast */
5315 rateUpdate->ucastDataRate = -1;
5316 rateUpdate->mcastDataRate24GHz = targetRate;
5317 rateUpdate->mcastDataRate5GHz = targetRate;
5318 rateUpdate->mcastDataRate24GHzTxFlag = 0;
5319 rateUpdate->mcastDataRate5GHzTxFlag = 0;
5320 status = sme_SendRateUpdateInd(pHddCtx->hHal, rateUpdate);
5321 if (eHAL_STATUS_SUCCESS != status)
5322 {
5323 hddLog(VOS_TRACE_LEVEL_ERROR,
5324 "%s: SET_MC_RATE failed", __func__);
5325 vos_mem_free(rateUpdate);
5326 ret = -EFAULT;
5327 goto exit;
Leo Chang614d2072013-08-22 14:59:44 -07005328 }
5329 }
jge35567202017-06-21 16:39:38 +08005330 else if (strncmp(command, "MAXTXPOWER", 10) == 0)
5331 {
5332 int status;
5333 int txPower;
5334 eHalStatus smeStatus;
5335 tANI_U8 *value = command;
5336 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
5337 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
5338
5339 status = hdd_parse_setmaxtxpower_command(value, &txPower);
5340 if (status)
5341 {
5342 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5343 "Invalid MAXTXPOWER command ");
5344 ret = -EINVAL;
5345 goto exit;
5346 }
5347
5348 hddLog(VOS_TRACE_LEVEL_INFO, "max tx power %d selfMac: "
5349 MAC_ADDRESS_STR " bssId: " MAC_ADDRESS_STR " ",
5350 txPower, MAC_ADDR_ARRAY(selfMac),
5351 MAC_ADDR_ARRAY(bssid));
5352 smeStatus = sme_SetMaxTxPower((tHalHandle)(pHddCtx->hHal),
5353 bssid, selfMac, txPower) ;
5354 if( smeStatus != eHAL_STATUS_SUCCESS )
5355 {
5356 hddLog(VOS_TRACE_LEVEL_ERROR, "%s:Set max tx power failed",
5357 __func__);
5358 ret = -EINVAL;
5359 goto exit;
5360 }
5361
5362 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Set max tx power success",
5363 __func__);
5364 }
Rajeev79dbe4c2013-10-05 11:03:42 +05305365#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev Kumar8b373292014-01-08 20:36:55 -08005366 else if (strncmp(command, "WLS_BATCHING", 12) == 0)
Rajeev79dbe4c2013-10-05 11:03:42 +05305367 {
Rajeev Kumar8b373292014-01-08 20:36:55 -08005368 ret = hdd_handle_batch_scan_ioctl(pAdapter, &priv_data, command);
Rajeev79dbe4c2013-10-05 11:03:42 +05305369 }
5370#endif
Abhishek Singh00b71972016-01-07 10:51:04 +05305371#ifdef WLAN_FEATURE_RMC
5372 else if ((strncasecmp(command, "SETIBSSBEACONOUIDATA", 20) == 0) &&
5373 (WLAN_HDD_IBSS == pAdapter->device_mode))
5374 {
5375 int i = 0;
5376 tANI_U8 *ibss_ie;
5377 tANI_U32 command_len;
5378 tANI_U8 *value = command;
5379 tHalHandle hHal = pHddCtx->hHal;
5380 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
5381 tANI_U32 ibss_ie_length;
5382 tANI_U32 len, present;
5383 tANI_U8 *addIE;
5384 tANI_U8 *addIEData;
5385
5386 hddLog(LOG1,
5387 FL(" received command %s"),((char *) value));
5388 /* validate argument of command */
5389 if (strlen(value) <= 21)
5390 {
5391 hddLog(LOGE,
5392 FL("No arguements in command length %zu"), strlen(value));
5393 ret = -EFAULT;
5394 goto exit;
5395 }
5396
5397 /* moving to arguments of commands */
5398 value = value + 21;
5399 command_len = strlen(value);
5400
5401 /* oui_data can't be less than 3 bytes */
5402 if (command_len <= (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH))
5403 {
5404 hddLog(LOGE,
5405 FL("Invalid SETIBSSBEACONOUIDATA command length %d"),
5406 command_len);
5407 ret = -EFAULT;
5408 goto exit;
5409 }
5410 ibss_ie = vos_mem_malloc(command_len);
5411 if (!ibss_ie) {
5412 hddLog(LOGE,
5413 FL("Could not allocate memory for command length %d"),
5414 command_len);
5415 ret = -ENOMEM;
5416 goto exit;
5417 }
5418 vos_mem_zero(ibss_ie, command_len);
5419
5420 ibss_ie_length = hdd_parse_set_ibss_oui_data_command(value, ibss_ie,
5421 command_len);
5422 if (ibss_ie_length < (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH)) {
5423 hddLog(LOGE, FL("Could not parse command %s return length %d"),
5424 value, ibss_ie_length);
5425 ret = -EFAULT;
5426 vos_mem_free(ibss_ie);
5427 goto exit;
5428 }
5429
5430 hddLog(LOG1, FL("ibss_ie length %d ibss_ie:"), ibss_ie_length);
5431 while (i < ibss_ie_length)
5432 hddLog(LOG1, FL("0x%x"), ibss_ie[i++]);
5433
5434 /* Populate Vendor IE in Beacon */
5435 if ((ccmCfgGetInt(hHal,
5436 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
5437 &present)) != eHAL_STATUS_SUCCESS)
5438 {
5439 hddLog(LOGE,
5440 FL("unable to ftch WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
5441 ret = -EFAULT;
5442 vos_mem_free(ibss_ie);
5443 goto exit;
5444 }
5445
5446 addIE = vos_mem_malloc(WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
5447 if (!addIE) {
5448 hddLog(LOGE,
5449 FL("Could not allocate memory for command length %d"),
5450 command_len);
5451 vos_mem_free(ibss_ie);
5452 ret = -ENOMEM;
5453 goto exit;
5454 }
5455 vos_mem_zero(addIE, WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
5456
5457 if (present)
5458 {
5459 if ((wlan_cfgGetStrLen(pMac,
5460 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, &len)) != eSIR_SUCCESS)
5461 {
5462 hddLog(LOGE,
5463 FL("unable to fetch WNI_CFG_PROBE_RSP_BCN_ADDNIE_LEN"));
5464 ret = -EFAULT;
5465 vos_mem_free(ibss_ie);
5466 vos_mem_free(addIE);
5467 goto exit;
5468 }
5469
5470 if (len <= WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN && len &&
5471 ((len + ibss_ie_length) <=
5472 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN))
5473 {
5474 if ((ccmCfgGetStr(hHal,
5475 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, &len))
5476 != eHAL_STATUS_SUCCESS)
5477 {
5478 hddLog(LOGE,
5479 FL("unable to fetch WNI_PROBE_RSP_BCN_ADDNIE_DATA"));
5480 ret = -EFAULT;
5481 vos_mem_free(ibss_ie);
5482 vos_mem_free(addIE);
5483 goto exit;
5484 }
5485 else
5486 {
5487 /* Curruntly only WPA IE is added before Vendor IE
5488 * so we can blindly place the Vendor IE after WPA
5489 * IE. If no WPA IE found replace all with Vendor IE.
5490 */
5491 len = hdd_find_ibss_wpa_ie_pos(addIE, len);
5492 }
5493 }
5494 else
5495 {
5496 hddLog(LOGE,
5497 FL("IE len exceed limit len %d,ibss_ie_length %d "),
5498 len, ibss_ie_length);
5499 ret = -EFAULT;
5500 vos_mem_free(addIE);
5501 vos_mem_free(ibss_ie);
5502 goto exit;
5503 }
5504 }
5505 else {
5506 len = 0;
5507 }
5508
5509 vos_mem_copy (addIE + len , ibss_ie, ibss_ie_length);
5510 len += ibss_ie_length;
5511
5512 if (ccmCfgSetStr(hHal,
5513 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, len, NULL,
5514 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
5515 {
5516 hddLog(LOGE,
5517 FL("unable to set WNI_CFG_PRBE_RSP_BCN_ADDNIE_DATA"));
5518 ret = -EFAULT;
5519 vos_mem_free(ibss_ie);
5520 vos_mem_free(addIE);
5521 goto exit;
5522 }
5523 vos_mem_free(addIE);
5524 if (ccmCfgSetInt(hHal,
5525 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5526 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
5527 {
5528 hddLog(LOGE,
5529 FL("unble to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
5530 ret = -EFAULT;
5531 vos_mem_free(ibss_ie);
5532 goto exit;
5533 }
5534
5535 /* Populate Vendor IE in probe resp */
5536 if ((ccmCfgGetInt(hHal,
5537 WNI_CFG_PROBE_RSP_ADDNIE_FLAG,
5538 &present)) != eHAL_STATUS_SUCCESS)
5539 {
5540 hddLog(LOGE,
5541 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
5542 ret = -EFAULT;
5543 vos_mem_free(ibss_ie);
5544 goto exit;
5545 }
5546
5547 addIEData = vos_mem_malloc(WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
5548 if (!addIEData) {
5549 hddLog(LOGE,
5550 FL("Could not allocate memory for command length %d"),
5551 command_len);
5552 vos_mem_free(ibss_ie);
5553 ret = -ENOMEM;
5554 goto exit;
5555 }
5556 vos_mem_zero(addIEData, WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
5557
5558 if (present) {
5559 if (eSIR_SUCCESS != wlan_cfgGetStrLen(pMac,
5560 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, &len)) {
5561 hddLog(LOGE,
5562 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
5563 ret = -EFAULT;
5564 vos_mem_free(ibss_ie);
5565 vos_mem_free(addIEData);
5566 goto exit;
5567 }
5568 if (len < WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN && len &&
5569 (ibss_ie_length + len) <=
5570 WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN) {
5571
5572 if ((ccmCfgGetStr(hHal,
5573 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, addIEData, &len))
5574 != eHAL_STATUS_SUCCESS) {
5575 hddLog(LOGE,
5576 FL("unable fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
5577 ret = -EFAULT;
5578 vos_mem_free(ibss_ie);
5579 vos_mem_free(addIEData);
5580 goto exit;
5581 }
5582 else {
5583 /* Curruntly only WPA IE is added before Vendor IE
5584 * so we can blindly place the Vendor IE after WPA
5585 * IE. If no WPA IE found replace all with Vendor IE.
5586 */
5587 len = hdd_find_ibss_wpa_ie_pos(addIEData, len);
5588 }
5589 }
5590 else
5591 {
5592 hddLog(LOGE,
5593 FL("IE len exceed limit len %d,ibss_ie_length %d "),
5594 len, ibss_ie_length);
5595 ret = -EFAULT;
5596 vos_mem_free(addIEData);
5597 vos_mem_free(ibss_ie);
5598 goto exit;
5599 }
5600 } /* probe rsp ADD IE present */
5601 else {
5602 /* probe rsp add IE is not present */
5603 len = 0;
5604 }
5605
5606 vos_mem_copy(addIEData +len , ibss_ie, ibss_ie_length);
5607 len += ibss_ie_length;
5608
5609 vos_mem_free(ibss_ie);
5610
5611 if (ccmCfgSetStr(hHal,
5612 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5613 (tANI_U8*)(addIEData),
5614 len, NULL,
5615 eANI_BOOLEAN_FALSE)
5616 == eHAL_STATUS_FAILURE) {
5617 hddLog(LOGE,
5618 FL("unable to copy to WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
5619 ret = -EFAULT;
5620 vos_mem_free(addIEData);
5621 goto exit;
5622 }
5623 vos_mem_free(addIEData);
5624 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5625 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
5626 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5627 {
5628 hddLog(LOGE,
5629 FL("unable to copy WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
5630 ret = -EFAULT;
5631 goto exit;
5632 }
5633 }
5634 else if (strncasecmp(command, "SETRMCENABLE", 12) == 0)
5635 {
5636 tANI_U8 *value = command;
5637 tANI_U8 ucRmcEnable = 0;
5638 int status;
5639
5640 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
5641 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
5642 {
5643 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5644 "Received SETRMCENABLE command in invalid mode %d "
5645 "SETRMCENABLE command is only allowed in IBSS or SOFTAP mode",
5646 pAdapter->device_mode);
5647 ret = -EINVAL;
5648 goto exit;
5649 }
5650
5651 status = hdd_parse_setrmcenable_command(value, &ucRmcEnable);
5652 if (status)
5653 {
5654 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5655 "Invalid SETRMCENABLE command ");
5656 ret = -EINVAL;
5657 goto exit;
5658 }
5659
5660 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5661 "%s: ucRmcEnable %d ", __func__, ucRmcEnable);
5662
5663 if (TRUE == ucRmcEnable)
5664 {
5665 status = sme_EnableRMC( (tHalHandle)(pHddCtx->hHal),
5666 pAdapter->sessionId );
5667 }
5668 else if(FALSE == ucRmcEnable)
5669 {
5670 status = sme_DisableRMC( (tHalHandle)(pHddCtx->hHal),
5671 pAdapter->sessionId );
5672 }
5673 else
5674 {
5675 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5676 "Invalid SETRMCENABLE command %d", ucRmcEnable);
5677 ret = -EINVAL;
5678 goto exit;
5679 }
5680
5681 if (VOS_STATUS_SUCCESS != status)
5682 {
5683 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5684 "%s: SETRMC %d failed status %d", __func__, ucRmcEnable,
5685 status);
5686 ret = -EINVAL;
5687 goto exit;
5688 }
5689 }
5690 else if (strncasecmp(command, "SETRMCACTIONPERIOD", 18) == 0)
5691 {
5692 tANI_U8 *value = command;
5693 tANI_U32 uActionPeriod = 0;
5694 int status;
5695
5696 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
5697 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
5698 {
5699 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5700 "Received SETRMC command in invalid mode %d "
5701 "SETRMC command is only allowed in IBSS or SOFTAP mode",
5702 pAdapter->device_mode);
5703 ret = -EINVAL;
5704 goto exit;
5705 }
5706
5707 status = hdd_parse_setrmcactionperiod_command(value, &uActionPeriod);
5708 if (status)
5709 {
5710 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5711 "Invalid SETRMCACTIONPERIOD command ");
5712 ret = -EINVAL;
5713 goto exit;
5714 }
5715
5716 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5717 "%s: uActionPeriod %d ", __func__, uActionPeriod);
5718
5719 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY,
5720 uActionPeriod, NULL, eANI_BOOLEAN_FALSE))
5721 {
5722 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5723 "%s: Could not set SETRMCACTIONPERIOD %d", __func__, uActionPeriod);
5724 ret = -EINVAL;
5725 goto exit;
5726 }
5727
5728 }
5729 else if (strncasecmp(command, "GETIBSSPEERINFOALL", 18) == 0)
5730 {
5731 /* Peer Info All Command */
5732 int status = eHAL_STATUS_SUCCESS;
5733 hdd_station_ctx_t *pHddStaCtx = NULL;
5734 char *extra = NULL;
5735 int idx = 0, length = 0;
5736 v_MACADDR_t *macAddr;
5737 v_U32_t txRateMbps = 0, numOfBytestoPrint = 0;
5738
5739 if (WLAN_HDD_IBSS == pAdapter->device_mode)
5740 {
5741 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5742 }
5743 else
5744 {
5745 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5746 "%s: pAdapter is not valid for this device mode",
5747 __func__);
5748 ret = -EINVAL;
5749 goto exit;
5750 }
5751
5752 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5753 "%s: Received GETIBSSPEERINFOALL Command", __func__);
5754
5755
5756 /* Handle the command */
5757 status = hdd_cfg80211_get_ibss_peer_info_all(pAdapter);
5758 if (VOS_STATUS_SUCCESS == status)
5759 {
5760 /* The variable extra needed to be allocated on the heap since
5761 * amount of memory required to copy the data for 32 devices
5762 * exceeds the size of 1024 bytes of default stack size. On
5763 * 64 bit devices, the default max stack size of 2048 bytes
5764 */
5765 extra = kmalloc(WLAN_MAX_BUF_SIZE, GFP_KERNEL);
5766
5767 if (NULL == extra)
5768 {
5769 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5770 "%s:kmalloc failed", __func__);
5771 ret = -EINVAL;
5772 goto exit;
5773 }
5774
5775 /* Copy number of stations */
5776 length = scnprintf( extra, WLAN_MAX_BUF_SIZE, "%d ",
5777 pHddStaCtx->ibss_peer_info.numIBSSPeers);
5778 numOfBytestoPrint = length;
5779 for (idx = 0; idx < pHddStaCtx->ibss_peer_info.numIBSSPeers; idx++)
5780 {
5781 macAddr =
5782 hdd_wlan_get_ibss_mac_addr_from_staid(pAdapter,
5783 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
5784 if (NULL != macAddr)
5785 {
5786 txRateMbps =
5787 ((pHddStaCtx->ibss_peer_info.ibssPeerList[idx].txRate)*500*1000)/1000000;
5788
5789 length += scnprintf( (extra + length), WLAN_MAX_BUF_SIZE - length,
5790 "%02x:%02x:%02x:%02x:%02x:%02x %d %d ",
5791 macAddr->bytes[0], macAddr->bytes[1], macAddr->bytes[2],
5792 macAddr->bytes[3], macAddr->bytes[4], macAddr->bytes[5],
5793 (int)txRateMbps,
5794 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[idx].rssi);
5795 }
5796 else
5797 {
5798 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5799 "%s: MAC ADDR is NULL for staIdx: %d", __func__,
5800 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
5801 }
5802
5803 /*
5804 * VOS_TRACE() macro has limitation of 512 bytes for the print
5805 * buffer. Hence printing the data in two chunks. The first chunk
5806 * will have the data for 16 devices and the second chunk will
5807 * have the rest.
5808 */
5809 if (idx < NUM_OF_STA_DATA_TO_PRINT)
5810 {
5811 numOfBytestoPrint = length;
5812 }
5813 }
5814
5815 /*
5816 * Copy the data back into buffer, if the data to copy is
5817 * morethan 512 bytes than we will split the data and do
5818 * it in two shots
5819 */
5820 if (copy_to_user(priv_data.buf, extra, numOfBytestoPrint))
5821 {
5822 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5823 "%s: Copy into user data buffer failed ", __func__);
5824 ret = -EFAULT;
5825 kfree(extra);
5826 goto exit;
5827 }
5828 priv_data.buf[numOfBytestoPrint] = '\0';
5829 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
5830 "%s", priv_data.buf);
5831
5832 if (length > numOfBytestoPrint)
5833 {
5834 if (copy_to_user(priv_data.buf + numOfBytestoPrint,
5835 extra + numOfBytestoPrint,
5836 length - numOfBytestoPrint + 1))
5837 {
5838 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5839 "%s: Copy into user data buffer failed ", __func__);
5840 ret = -EFAULT;
5841 kfree(extra);
5842 goto exit;
5843 }
5844 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
5845 "%s", &priv_data.buf[numOfBytestoPrint]);
5846 }
5847
5848 /* Free temporary buffer */
5849 kfree(extra);
5850 }
5851
5852 else
5853 {
5854 /* Command failed, log error */
5855 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5856 "%s: GETIBSSPEERINFOALL command failed with status code %d",
5857 __func__, status);
5858 ret = -EINVAL;
5859 goto exit;
5860 }
5861 ret = 0;
5862 }
5863 else if(strncasecmp(command, "GETIBSSPEERINFO", 15) == 0)
5864 {
5865 /* Peer Info <Peer Addr> command */
5866 tANI_U8 *value = command;
5867 VOS_STATUS status;
5868 hdd_station_ctx_t *pHddStaCtx = NULL;
5869 char extra[128] = { 0 };
5870 v_U32_t length = 0;
5871 v_U8_t staIdx = 0;
5872 v_U32_t txRateMbps = 0;
5873 v_MACADDR_t peerMacAddr;
5874
5875 if (WLAN_HDD_IBSS == pAdapter->device_mode)
5876 {
5877 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5878 }
5879 else
5880 {
5881 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5882 "%s: pAdapter is not valid for this device mode",
5883 __func__);
5884 ret = -EINVAL;
5885 goto exit;
5886 }
5887
5888 /* if there are no peers, no need to continue with the command */
5889 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5890 "%s: Received GETIBSSPEERINFO Command", __func__);
5891
5892 if (eConnectionState_IbssConnected != pHddStaCtx->conn_info.connState)
5893 {
5894 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5895 "%s:No IBSS Peers coalesced", __func__);
5896 ret = -EINVAL;
5897 goto exit;
5898 }
5899
5900 /* Parse the incoming command buffer */
5901 status = hdd_parse_get_ibss_peer_info(value, &peerMacAddr);
5902 if (VOS_STATUS_SUCCESS != status)
5903 {
5904 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5905 "%s: Invalid GETIBSSPEERINFO command", __func__);
5906 ret = -EINVAL;
5907 goto exit;
5908 }
5909
5910 /* Get station index for the peer mac address */
5911 hdd_Ibss_GetStaId(pHddStaCtx, &peerMacAddr, &staIdx);
5912
5913 if (staIdx > HDD_MAX_NUM_IBSS_STA)
5914 {
5915 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5916 "%s: Invalid StaIdx %d returned", __func__, staIdx);
5917 ret = -EINVAL;
5918 goto exit;
5919 }
5920
5921 /* Handle the command */
5922 status = hdd_cfg80211_get_ibss_peer_info(pAdapter, staIdx);
5923 if (VOS_STATUS_SUCCESS == status)
5924 {
5925 v_U32_t txRate = pHddStaCtx->ibss_peer_info.ibssPeerList[0].txRate;
5926 txRateMbps = (txRate * 500 * 1000)/1000000;
5927
5928 length = scnprintf( extra, sizeof(extra), "%d %d", (int)txRateMbps,
5929 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[0].rssi);
5930
5931 /* Copy the data back into buffer */
5932 if (copy_to_user(priv_data.buf, &extra, length+ 1))
5933 {
5934 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5935 "%s: copy data to user buffer failed GETIBSSPEERINFO command",
5936 __func__);
5937 ret = -EFAULT;
5938 goto exit;
5939 }
5940 }
5941 else
5942 {
5943 /* Command failed, log error */
5944 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5945 "%s: GETIBSSPEERINFO command failed with status code %d",
5946 __func__, status);
5947 ret = -EINVAL;
5948 goto exit;
5949 }
5950
5951 /* Success ! */
5952 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
5953 "%s", priv_data.buf);
5954 ret = 0;
5955 }
5956 else if (strncasecmp(command, "SETRMCTXRATE", 12) == 0)
5957 {
5958 tANI_U8 *value = command;
5959 tANI_U32 uRate = 0;
5960 tTxrateinfoflags txFlags = 0;
5961 tSirRateUpdateInd *rateUpdateParams;
5962 int status;
5963
5964 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
5965 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
5966 {
5967 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5968 "Received SETRMCTXRATE command in invalid mode %d "
5969 "SETRMC command is only allowed in IBSS or SOFTAP mode",
5970 pAdapter->device_mode);
5971 ret = -EINVAL;
5972 goto exit;
5973 }
5974
5975 status = hdd_parse_setrmcrate_command(value, &uRate, &txFlags);
5976 if (status)
5977 {
5978 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5979 "Invalid SETRMCTXRATE command ");
5980 ret = -EINVAL;
5981 goto exit;
5982 }
5983
5984 rateUpdateParams = vos_mem_malloc(sizeof(tSirRateUpdateInd));
5985 if (NULL == rateUpdateParams)
5986 {
5987 ret = -EINVAL;
5988 goto exit;
5989 }
5990
5991 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5992 "%s: uRate %d ", __func__, uRate);
5993
5994 vos_mem_zero(rateUpdateParams, sizeof(tSirRateUpdateInd ));
5995
5996 /* -1 implies ignore this param */
5997 rateUpdateParams->ucastDataRate = -1;
5998
5999 /*
6000 * Fill the user specifieed RMC rate param
6001 * and the derived tx flags.
6002 */
6003 rateUpdateParams->rmcDataRate = uRate;
6004 rateUpdateParams->rmcDataRateTxFlag = txFlags;
6005
6006 status = sme_SendRateUpdateInd((tHalHandle)(pHddCtx->hHal), rateUpdateParams);
6007 }
6008 else if (strncasecmp(command, "SETIBSSTXFAILEVENT", 18) == 0 )
6009 {
6010 char *value;
6011 tANI_U8 tx_fail_count = 0;
6012 tANI_U16 pid = 0;
6013
6014 value = command;
6015
6016 ret = hdd_ParseIBSSTXFailEventParams(value, &tx_fail_count, &pid);
6017
6018 if (0 != ret)
6019 {
6020 hddLog(VOS_TRACE_LEVEL_INFO,
6021 "%s: Failed to parse SETIBSSTXFAILEVENT arguments",
6022 __func__);
6023 goto exit;
6024 }
6025
6026 hddLog(VOS_TRACE_LEVEL_INFO, "%s: tx_fail_cnt=%hhu, pid=%hu",
6027 __func__, tx_fail_count, pid);
6028
6029 if (0 == tx_fail_count)
6030 {
6031 // Disable TX Fail Indication
6032 if (eHAL_STATUS_SUCCESS ==
6033 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
6034 tx_fail_count,
6035 NULL))
6036 {
6037 cesium_pid = 0;
6038 }
6039 else
6040 {
6041 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6042 "%s: failed to disable TX Fail Event ", __func__);
6043 ret = -EINVAL;
6044 }
6045 }
6046 else
6047 {
6048 if (eHAL_STATUS_SUCCESS ==
6049 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
6050 tx_fail_count,
6051 (void*)hdd_tx_fail_ind_callback))
6052 {
6053 cesium_pid = pid;
6054 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6055 "%s: Registered Cesium pid %u", __func__,
6056 cesium_pid);
6057 }
6058 else
6059 {
6060 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6061 "%s: Failed to enable TX Fail Monitoring", __func__);
6062 ret = -EINVAL;
6063 }
6064 }
6065 }
6066
6067#endif /* WLAN_FEATURE_RMC */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006068#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006069 else if (strncmp(command, "SETCCXROAMSCANCHANNELS", 22) == 0)
6070 {
6071 tANI_U8 *value = command;
6072 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
6073 tANI_U8 numChannels = 0;
6074 eHalStatus status = eHAL_STATUS_SUCCESS;
6075
6076 status = hdd_parse_channellist(value, ChannelList, &numChannels);
6077 if (eHAL_STATUS_SUCCESS != status)
6078 {
6079 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6080 "%s: Failed to parse channel list information", __func__);
6081 ret = -EINVAL;
6082 goto exit;
6083 }
6084
6085 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
6086 {
6087 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6088 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
6089 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
6090 ret = -EINVAL;
6091 goto exit;
6092 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006093 status = sme_SetEseRoamScanChannelList((tHalHandle)(pHddCtx->hHal),
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006094 ChannelList,
6095 numChannels);
6096 if (eHAL_STATUS_SUCCESS != status)
6097 {
6098 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6099 "%s: Failed to update channel list information", __func__);
6100 ret = -EINVAL;
6101 goto exit;
6102 }
6103 }
6104 else if (strncmp(command, "GETTSMSTATS", 11) == 0)
6105 {
6106 tANI_U8 *value = command;
6107 char extra[128] = {0};
6108 int len = 0;
6109 tANI_U8 tid = 0;
6110 hdd_station_ctx_t *pHddStaCtx = NULL;
6111 tAniTrafStrmMetrics tsmMetrics;
6112 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6113
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306114 ret = hdd_drv_cmd_validate(command, 11);
6115 if (ret)
6116 goto exit;
6117
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006118 /* if not associated, return error */
6119 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6120 {
6121 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:Not associated!",__func__);
6122 ret = -EINVAL;
6123 goto exit;
6124 }
6125
6126 /* Move pointer to ahead of GETTSMSTATS<delimiter> */
6127 value = value + 12;
6128 /* Convert the value from ascii to integer */
6129 ret = kstrtou8(value, 10, &tid);
6130 if (ret < 0)
6131 {
6132 /* If the input value is greater than max value of datatype, then also
6133 kstrtou8 fails */
6134 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6135 "%s: kstrtou8 failed range [%d - %d]", __func__,
6136 TID_MIN_VALUE,
6137 TID_MAX_VALUE);
6138 ret = -EINVAL;
6139 goto exit;
6140 }
6141
6142 if ((tid < TID_MIN_VALUE) || (tid > TID_MAX_VALUE))
6143 {
6144 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6145 "tid value %d is out of range"
6146 " (Min: %d Max: %d)", tid,
6147 TID_MIN_VALUE,
6148 TID_MAX_VALUE);
6149 ret = -EINVAL;
6150 goto exit;
6151 }
6152
6153 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6154 "%s: Received Command to get tsm stats tid = %d", __func__, tid);
6155
6156 if (VOS_STATUS_SUCCESS != hdd_get_tsm_stats(pAdapter, tid, &tsmMetrics))
6157 {
6158 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6159 "%s: failed to get tsm stats", __func__);
6160 ret = -EFAULT;
6161 goto exit;
6162 }
6163
6164 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6165 "UplinkPktQueueDly(%d)\n"
6166 "UplinkPktQueueDlyHist[0](%d)\n"
6167 "UplinkPktQueueDlyHist[1](%d)\n"
6168 "UplinkPktQueueDlyHist[2](%d)\n"
6169 "UplinkPktQueueDlyHist[3](%d)\n"
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05306170 "UplinkPktTxDly(%u)\n"
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006171 "UplinkPktLoss(%d)\n"
6172 "UplinkPktCount(%d)\n"
6173 "RoamingCount(%d)\n"
6174 "RoamingDly(%d)", tsmMetrics.UplinkPktQueueDly,
6175 tsmMetrics.UplinkPktQueueDlyHist[0],
6176 tsmMetrics.UplinkPktQueueDlyHist[1],
6177 tsmMetrics.UplinkPktQueueDlyHist[2],
6178 tsmMetrics.UplinkPktQueueDlyHist[3],
6179 tsmMetrics.UplinkPktTxDly, tsmMetrics.UplinkPktLoss,
6180 tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount, tsmMetrics.RoamingDly);
6181
6182 /* Output TSM stats is of the format
6183 GETTSMSTATS [PktQueueDly] [PktQueueDlyHist[0]]:[PktQueueDlyHist[1]] ...[RoamingDly]
6184 eg., GETTSMSTATS 10 1:0:0:161 20 1 17 8 39800 */
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006185 len = scnprintf(extra, sizeof(extra), "%s %d %d:%d:%d:%d %u %d %d %d %d", command,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006186 tsmMetrics.UplinkPktQueueDly, tsmMetrics.UplinkPktQueueDlyHist[0],
6187 tsmMetrics.UplinkPktQueueDlyHist[1], tsmMetrics.UplinkPktQueueDlyHist[2],
6188 tsmMetrics.UplinkPktQueueDlyHist[3], tsmMetrics.UplinkPktTxDly,
6189 tsmMetrics.UplinkPktLoss, tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount,
6190 tsmMetrics.RoamingDly);
6191
Ratnam Rachurid53009c2015-08-07 13:59:00 +05306192 len = VOS_MIN(priv_data.total_len, len + 1);
6193 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006194 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6195 "%s: failed to copy data to user buffer", __func__);
6196 ret = -EFAULT;
6197 goto exit;
6198 }
6199 }
6200 else if (strncmp(command, "SETCCKMIE", 9) == 0)
6201 {
6202 tANI_U8 *value = command;
6203 tANI_U8 *cckmIe = NULL;
6204 tANI_U8 cckmIeLen = 0;
6205 eHalStatus status = eHAL_STATUS_SUCCESS;
6206
6207 status = hdd_parse_get_cckm_ie(value, &cckmIe, &cckmIeLen);
6208 if (eHAL_STATUS_SUCCESS != status)
6209 {
6210 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6211 "%s: Failed to parse cckm ie data", __func__);
6212 ret = -EINVAL;
6213 goto exit;
6214 }
6215
6216 if (cckmIeLen > DOT11F_IE_RSN_MAX_LEN)
6217 {
6218 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6219 "%s: CCKM Ie input length is more than max[%d]", __func__,
6220 DOT11F_IE_RSN_MAX_LEN);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006221 vos_mem_free(cckmIe);
6222 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006223 ret = -EINVAL;
6224 goto exit;
6225 }
6226 sme_SetCCKMIe((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, cckmIe, cckmIeLen);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006227 vos_mem_free(cckmIe);
6228 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006229 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006230 else if (strncmp(command, "CCXBEACONREQ", 12) == 0)
6231 {
6232 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006233 tCsrEseBeaconReq eseBcnReq;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006234 eHalStatus status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07006235
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006236 status = hdd_parse_ese_beacon_req(value, &eseBcnReq);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006237 if (eHAL_STATUS_SUCCESS != status)
6238 {
6239 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006240 "%s: Failed to parse ese beacon req", __func__);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006241 ret = -EINVAL;
6242 goto exit;
6243 }
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07006244 if (!hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))) {
6245 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not associated"));
6246 hdd_indicateEseBcnReportNoResults (pAdapter,
6247 eseBcnReq.bcnReq[0].measurementToken,
6248 0x02, //BIT(1) set for measurement done
6249 0); // no BSS
6250 goto exit;
6251 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006252
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006253 status = sme_SetEseBeaconRequest((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, &eseBcnReq);
6254 if (eHAL_STATUS_SUCCESS != status)
6255 {
6256 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6257 "%s: sme_SetEseBeaconRequest failed (%d)", __func__, status);
6258 ret = -EINVAL;
6259 goto exit;
6260 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006261 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006262#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
c_hpothu92367912014-05-01 15:18:17 +05306263 else if (strncmp(command, "GETBCNMISSRATE", 14) == 0)
6264 {
6265 eHalStatus status;
6266 char buf[32], len;
6267 long waitRet;
6268 bcnMissRateContext_t getBcnMissRateCtx;
6269
6270 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6271
6272 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6273 {
6274 hddLog(VOS_TRACE_LEVEL_WARN,
6275 FL("GETBCNMISSRATE: STA is not in connected state"));
6276 ret = -1;
6277 goto exit;
6278 }
6279
6280 init_completion(&(getBcnMissRateCtx.completion));
6281 getBcnMissRateCtx.magic = BCN_MISS_RATE_CONTEXT_MAGIC;
6282
6283 status = sme_getBcnMissRate((tHalHandle)(pHddCtx->hHal),
6284 pAdapter->sessionId,
6285 (void *)getBcnMissRateCB,
6286 (void *)(&getBcnMissRateCtx));
6287 if( eHAL_STATUS_SUCCESS != status)
6288 {
6289 hddLog(VOS_TRACE_LEVEL_INFO,
6290 FL("GETBCNMISSRATE: fail to post WDA cmd"));
6291 ret = -EINVAL;
6292 goto exit;
6293 }
6294
6295 waitRet = wait_for_completion_interruptible_timeout
6296 (&getBcnMissRateCtx.completion, BCN_MISS_RATE_TIME);
6297 if(waitRet <= 0)
6298 {
6299 hddLog(VOS_TRACE_LEVEL_ERROR,
6300 FL("failed to wait on bcnMissRateComp %d"), ret);
6301
6302 //Make magic number to zero so that callback is not called.
6303 spin_lock(&hdd_context_lock);
6304 getBcnMissRateCtx.magic = 0x0;
6305 spin_unlock(&hdd_context_lock);
6306 ret = -EINVAL;
6307 goto exit;
6308 }
6309
6310 hddLog(VOS_TRACE_LEVEL_INFO,
6311 FL("GETBCNMISSRATE: bcnMissRate: %d"), gbcnMissRate);
6312
6313 len = snprintf(buf, sizeof(buf), "GETBCNMISSRATE %d", gbcnMissRate);
6314 if (copy_to_user(priv_data.buf, &buf, len + 1))
6315 {
6316 hddLog(VOS_TRACE_LEVEL_ERROR,
6317 "%s: failed to copy data to user buffer", __func__);
6318 ret = -EFAULT;
6319 goto exit;
6320 }
6321 ret = len;
6322 }
Atul Mittal87ec2422014-09-24 13:12:50 +05306323#ifdef FEATURE_WLAN_TDLS
6324 else if (strncmp(command, "TDLSSECONDARYCHANNELOFFSET", 26) == 0) {
6325 tANI_U8 *value = command;
6326 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306327
6328 ret = hdd_drv_cmd_validate(command, 26);
6329 if (ret)
6330 goto exit;
6331
Atul Mittal87ec2422014-09-24 13:12:50 +05306332 /* Move pointer to ahead of TDLSOFFCH*/
6333 value += 26;
c_manjeebbc40212015-12-08 13:52:59 +05306334 if (!(sscanf(value, "%d", &set_value))) {
6335 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6336 FL("No input identified"));
6337 ret = -EINVAL;
6338 goto exit;
6339 }
6340
Atul Mittal87ec2422014-09-24 13:12:50 +05306341 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6342 "%s: Tdls offchannel offset:%d",
6343 __func__, set_value);
6344 ret = iw_set_tdlssecoffchanneloffset(pHddCtx, set_value);
6345 if (ret < 0)
6346 {
6347 ret = -EINVAL;
6348 goto exit;
6349 }
6350
6351 } else if (strncmp(command, "TDLSOFFCHANNELMODE", 18) == 0) {
6352 tANI_U8 *value = command;
6353 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306354
6355 ret = hdd_drv_cmd_validate(command, 18);
6356 if (ret)
6357 goto exit;
6358
Atul Mittal87ec2422014-09-24 13:12:50 +05306359 /* Move pointer to ahead of tdlsoffchnmode*/
6360 value += 18;
c_manjee82323892015-12-08 12:40:34 +05306361 ret = sscanf(value, "%d", &set_value);
6362 if (ret != 1) {
6363 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6364 FL("No input identified"));
6365 ret = -EINVAL;
6366 goto exit;
6367 }
Atul Mittal87ec2422014-09-24 13:12:50 +05306368 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6369 "%s: Tdls offchannel mode:%d",
6370 __func__, set_value);
6371 ret = iw_set_tdlsoffchannelmode(pAdapter, set_value);
6372 if (ret < 0)
6373 {
6374 ret = -EINVAL;
6375 goto exit;
6376 }
6377 } else if (strncmp(command, "TDLSOFFCHANNEL", 14) == 0) {
6378 tANI_U8 *value = command;
6379 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306380
6381 ret = hdd_drv_cmd_validate(command, 14);
6382 if (ret)
6383 goto exit;
6384
Atul Mittal87ec2422014-09-24 13:12:50 +05306385 /* Move pointer to ahead of TDLSOFFCH*/
6386 value += 14;
c_manjeef6ccaf52015-12-08 11:52:11 +05306387 ret = sscanf(value, "%d", &set_value);
6388 if (ret != 1) {
6389 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6390 "Wrong value is given for hdd_set_tdls_offchannel");
6391 ret = -EINVAL;
6392 goto exit;
6393 }
6394
Atul Mittal87ec2422014-09-24 13:12:50 +05306395 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6396 "%s: Tdls offchannel num: %d",
6397 __func__, set_value);
6398 ret = iw_set_tdlsoffchannel(pHddCtx, set_value);
6399 if (ret < 0)
6400 {
6401 ret = -EINVAL;
6402 goto exit;
6403 }
6404 }
6405#endif
Satyanarayana Dash72806012014-12-02 14:30:08 +05306406 else if (strncmp(command, "GETFWSTATS", 10) == 0)
6407 {
6408 eHalStatus status;
6409 char *buf = NULL;
6410 char len;
6411 long waitRet;
6412 fwStatsContext_t fwStatsCtx;
Abhishek Singh08aa7762014-12-16 13:59:03 +05306413 tSirFwStatsResult *fwStatsRsp = &(pAdapter->fwStatsRsp);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306414 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306415 int stats;
Satyanarayana Dash72806012014-12-02 14:30:08 +05306416
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306417 ret = hdd_drv_cmd_validate(command, 10);
6418 if (ret)
6419 goto exit;
6420
6421 stats = *(ptr + 11) - '0';
Satyanarayana Dash72806012014-12-02 14:30:08 +05306422 hddLog(VOS_TRACE_LEVEL_INFO, FL("stats = %d "),stats);
6423 if (!IS_FEATURE_FW_STATS_ENABLE)
6424 {
6425 hddLog(VOS_TRACE_LEVEL_INFO,
6426 FL("Get Firmware stats feature not supported"));
6427 ret = -EINVAL;
6428 goto exit;
6429 }
6430
6431 if (FW_STATS_MAX <= stats || 0 >= stats)
6432 {
6433 hddLog(VOS_TRACE_LEVEL_INFO,
6434 FL(" stats %d not supported"),stats);
6435 ret = -EINVAL;
6436 goto exit;
6437 }
6438
6439 init_completion(&(fwStatsCtx.completion));
6440 fwStatsCtx.magic = FW_STATS_CONTEXT_MAGIC;
6441 fwStatsCtx.pAdapter = pAdapter;
6442 fwStatsRsp->type = 0;
6443 status = sme_GetFwStats( (tHalHandle)pHddCtx->hHal, stats,
Abhishek Singh08aa7762014-12-16 13:59:03 +05306444 &fwStatsCtx, hdd_FWStatisCB);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306445 if (eHAL_STATUS_SUCCESS != status)
6446 {
6447 hddLog(VOS_TRACE_LEVEL_ERROR,
6448 FL(" fail to post WDA cmd status = %d"), status);
6449 ret = -EINVAL;
6450 goto exit;
6451 }
6452 waitRet = wait_for_completion_timeout
6453 (&(fwStatsCtx.completion), FW_STATE_WAIT_TIME);
6454 if (waitRet <= 0)
6455 {
6456 hddLog(VOS_TRACE_LEVEL_ERROR,
6457 FL("failed to wait on GwtFwstats"));
6458 //Make magic number to zero so that callback is not executed.
6459 spin_lock(&hdd_context_lock);
6460 fwStatsCtx.magic = 0x0;
6461 spin_unlock(&hdd_context_lock);
6462 ret = -EINVAL;
6463 goto exit;
6464 }
6465 if (fwStatsRsp->type)
6466 {
6467 buf = kmalloc(FW_STATE_RSP_LEN, GFP_KERNEL);
6468 if (!buf)
6469 {
6470 hddLog(VOS_TRACE_LEVEL_ERROR,
6471 FL(" failed to allocate memory"));
6472 ret = -ENOMEM;
6473 goto exit;
6474 }
6475 switch( fwStatsRsp->type )
6476 {
6477 case FW_UBSP_STATS:
6478 {
6479 len = snprintf(buf, FW_STATE_RSP_LEN,
6480 "GETFWSTATS: ubsp_enter_cnt %d ubsp_jump_ddr_cnt %d",
Abhishek Singh08aa7762014-12-16 13:59:03 +05306481 fwStatsRsp->fwStatsData.ubspStats.ubsp_enter_cnt,
6482 fwStatsRsp->fwStatsData.ubspStats.ubsp_jump_ddr_cnt);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306483 }
6484 break;
6485 default:
6486 {
6487 hddLog(VOS_TRACE_LEVEL_ERROR, FL( "No handling for stats type %d"),fwStatsRsp->type);
6488 ret = -EFAULT;
6489 kfree(buf);
6490 goto exit;
6491 }
6492 }
6493 if (copy_to_user(priv_data.buf, buf, len + 1))
6494 {
6495 hddLog(VOS_TRACE_LEVEL_ERROR,
6496 FL(" failed to copy data to user buffer"));
6497 ret = -EFAULT;
6498 kfree(buf);
6499 goto exit;
6500 }
6501 ret = len;
6502 kfree(buf);
6503 }
6504 else
6505 {
6506 hddLog(VOS_TRACE_LEVEL_ERROR,
6507 FL("failed to fetch the stats"));
6508 ret = -EFAULT;
6509 goto exit;
6510 }
6511
6512 }
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306513 else if (strncasecmp(command, "SET_FCC_CHANNEL", 15) == 0)
6514 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306515 ret = hdd_drv_cmd_validate(command, 15);
6516 if (ret)
6517 goto exit;
6518
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306519 /*
6520 * this command wld be called by user-space when it detects WLAN
6521 * ON after airplane mode is set. When APM is set, WLAN turns off.
6522 * But it can be turned back on. Otherwise; when APM is turned back
6523 * off, WLAN wld turn back on. So at that point the command is
6524 * expected to come down. 0 means disable, 1 means enable. The
6525 * constraint is removed when parameter 1 is set or different
6526 * country code is set
6527 */
6528 ret = hdd_cmd_setFccChannel(pHddCtx, command, 15);
6529 }
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05306530 else if (strncasecmp(command, "DISABLE_CA_EVENT", 16) == 0)
6531 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306532 ret = hdd_drv_cmd_validate(command, 16);
6533 if (ret)
6534 goto exit;
6535
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05306536 ret = hdd_enable_disable_ca_event(pHddCtx, command, 16);
6537 }
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05306538 /*
6539 * command should be a string having format
6540 * SET_DISABLE_CHANNEL_LIST <num of channels>
6541 * <channels separated by spaces>
6542 */
6543 else if (strncmp(command, "SET_DISABLE_CHANNEL_LIST", 24) == 0) {
6544 tANI_U8 *ptr = command;
6545 ret = hdd_drv_cmd_validate(command, 24);
6546 if (ret)
6547 goto exit;
6548
6549 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6550 " Received Command to disable Channels %s",
6551 __func__);
6552 ret = hdd_parse_disable_chan_cmd(pAdapter, ptr);
6553 if (ret)
6554 goto exit;
6555 }
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05306556 else if (strncmp(command, "GET_DISABLE_CHANNEL_LIST", 24) == 0) {
6557 char extra[128] = {0};
6558 int len;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05306559
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05306560 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6561 " Received Command to get disable Channels list %s",
6562 __func__);
6563
6564 len = hdd_get_disable_ch_list(pHddCtx, extra, sizeof(extra));
6565 if (len == 0) {
6566 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6567 FL("disable channel list are not yet programed"));
6568 ret = -EINVAL;
6569 goto exit;
6570 }
6571
6572 len = VOS_MIN(priv_data.total_len, len + 1);
6573 if (copy_to_user(priv_data.buf, &extra, len)) {
6574 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6575 "%s: failed to copy data to user buffer", __func__);
6576 ret = -EFAULT;
6577 goto exit;
6578 }
6579
6580 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6581 FL("data:%s"), extra);
6582 }
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07006583 else {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05306584 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
6585 TRACE_CODE_HDD_UNSUPPORTED_IOCTL,
6586 pAdapter->sessionId, 0));
Satyanarayana Dash72806012014-12-02 14:30:08 +05306587 hddLog( VOS_TRACE_LEVEL_WARN, FL("Unsupported GUI command %s"),
6588 command);
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07006589 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006590 }
6591exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05306592 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006593 if (command)
6594 {
6595 kfree(command);
6596 }
6597 return ret;
6598}
6599
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07006600#ifdef CONFIG_COMPAT
6601static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
6602{
6603 struct {
6604 compat_uptr_t buf;
6605 int used_len;
6606 int total_len;
6607 } compat_priv_data;
6608 hdd_priv_data_t priv_data;
6609 int ret = 0;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006610
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07006611 /*
6612 * Note that pAdapter and ifr have already been verified by caller,
6613 * and HDD context has also been validated
6614 */
6615 if (copy_from_user(&compat_priv_data, ifr->ifr_data,
6616 sizeof(compat_priv_data))) {
6617 ret = -EFAULT;
6618 goto exit;
6619 }
6620 priv_data.buf = compat_ptr(compat_priv_data.buf);
6621 priv_data.used_len = compat_priv_data.used_len;
6622 priv_data.total_len = compat_priv_data.total_len;
6623 ret = hdd_driver_command(pAdapter, &priv_data);
6624 exit:
6625 return ret;
6626}
6627#else /* CONFIG_COMPAT */
6628static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
6629{
6630 /* will never be invoked */
6631 return 0;
6632}
6633#endif /* CONFIG_COMPAT */
6634
6635static int hdd_driver_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
6636{
6637 hdd_priv_data_t priv_data;
6638 int ret = 0;
6639
6640 /*
6641 * Note that pAdapter and ifr have already been verified by caller,
6642 * and HDD context has also been validated
6643 */
6644 if (copy_from_user(&priv_data, ifr->ifr_data, sizeof(priv_data))) {
6645 ret = -EFAULT;
6646 } else {
6647 ret = hdd_driver_command(pAdapter, &priv_data);
6648 }
6649 return ret;
6650}
6651
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306652int __hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07006653{
6654 hdd_adapter_t *pAdapter;
6655 hdd_context_t *pHddCtx;
6656 int ret;
6657
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05306658 ENTER();
6659
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07006660 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6661 if (NULL == pAdapter) {
6662 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
6663 "%s: HDD adapter context is Null", __func__);
6664 ret = -ENODEV;
6665 goto exit;
6666 }
6667 if (dev != pAdapter->dev) {
6668 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
6669 "%s: HDD adapter/dev inconsistency", __func__);
6670 ret = -ENODEV;
6671 goto exit;
6672 }
6673
6674 if ((!ifr) || (!ifr->ifr_data)) {
6675 ret = -EINVAL;
6676 goto exit;
6677 }
6678
6679 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6680 ret = wlan_hdd_validate_context(pHddCtx);
6681 if (ret) {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07006682 ret = -EBUSY;
6683 goto exit;
6684 }
6685
6686 switch (cmd) {
6687 case (SIOCDEVPRIVATE + 1):
6688 if (is_compat_task())
6689 ret = hdd_driver_compat_ioctl(pAdapter, ifr);
6690 else
6691 ret = hdd_driver_ioctl(pAdapter, ifr);
6692 break;
6693 default:
6694 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unknown ioctl %d",
6695 __func__, cmd);
6696 ret = -EINVAL;
6697 break;
6698 }
6699 exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05306700 EXIT();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07006701 return ret;
6702}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006703
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306704int hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
6705{
6706 int ret;
6707
6708 vos_ssr_protect(__func__);
6709 ret = __hdd_ioctl(dev, ifr, cmd);
6710 vos_ssr_unprotect(__func__);
6711
6712 return ret;
6713}
6714
Katya Nigame7b69a82015-04-28 15:24:06 +05306715int hdd_mon_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
6716{
6717 return 0;
6718}
6719
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006720#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006721/**---------------------------------------------------------------------------
6722
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006723 \brief hdd_parse_ese_beacon_req() - Parse ese beacon request
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006724
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006725 This function parses the ese beacon request passed in the format
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006726 CCXBEACONREQ<space><Number of fields><space><Measurement token>
6727 <space>Channel 1<space>Scan Mode <space>Meas Duration<space>Channel N
6728 <space>Scan Mode N<space>Meas Duration N
6729 if the Number of bcn req fields (N) does not match with the actual number of fields passed
6730 then take N.
6731 <Meas Token><Channel><Scan Mode> and <Meas Duration> are treated as one pair
6732 For example, CCXBEACONREQ 2 1 1 1 30 2 44 0 40.
6733 This function does not take care of removing duplicate channels from the list
6734
6735 \param - pValue Pointer to data
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006736 \param - pEseBcnReq output pointer to store parsed ie information
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006737
6738 \return - 0 for success non-zero for failure
6739
6740 --------------------------------------------------------------------------*/
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006741static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
6742 tCsrEseBeaconReq *pEseBcnReq)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006743{
6744 tANI_U8 *inPtr = pValue;
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306745 uint8_t input = 0;
6746 uint32_t tempInt = 0;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006747 int j = 0, i = 0, v = 0;
6748 char buf[32];
6749
6750 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
6751 /*no argument after the command*/
6752 if (NULL == inPtr)
6753 {
6754 return -EINVAL;
6755 }
6756 /*no space after the command*/
6757 else if (SPACE_ASCII_VALUE != *inPtr)
6758 {
6759 return -EINVAL;
6760 }
6761
6762 /*removing empty spaces*/
6763 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
6764
6765 /*no argument followed by spaces*/
6766 if ('\0' == *inPtr) return -EINVAL;
6767
6768 /*getting the first argument ie measurement token*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006769 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006770 if (1 != v) return -EINVAL;
6771
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306772 v = kstrtos8(buf, 10, &input);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006773 if ( v < 0) return -EINVAL;
6774
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306775 input = VOS_MIN(input, SIR_ESE_MAX_MEAS_IE_REQS);
6776 pEseBcnReq->numBcnReqIe = input;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006777
Srinivas Girigowda725a88e2016-03-31 19:24:25 +05306778 hddLog(LOG1, "Number of Bcn Req Ie fields: %d", pEseBcnReq->numBcnReqIe);
6779
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006780
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006781 for (j = 0; j < (pEseBcnReq->numBcnReqIe); j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006782 {
6783 for (i = 0; i < 4; i++)
6784 {
6785 /*inPtr pointing to the beginning of first space after number of ie fields*/
6786 inPtr = strpbrk( inPtr, " " );
6787 /*no ie data after the number of ie fields argument*/
6788 if (NULL == inPtr) return -EINVAL;
6789
6790 /*removing empty space*/
6791 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
6792
6793 /*no ie data after the number of ie fields argument and spaces*/
6794 if ( '\0' == *inPtr ) return -EINVAL;
6795
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006796 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006797 if (1 != v) return -EINVAL;
6798
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306799 v = kstrtou32(buf, 10, &tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006800 if (v < 0) return -EINVAL;
6801
6802 switch (i)
6803 {
6804 case 0: /* Measurement token */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306805 if (!tempInt)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006806 {
6807 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306808 "Invalid Measurement Token: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006809 return -EINVAL;
6810 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006811 pEseBcnReq->bcnReq[j].measurementToken = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006812 break;
6813
6814 case 1: /* Channel number */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306815 if ((!tempInt) ||
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006816 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
6817 {
6818 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306819 "Invalid Channel Number: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006820 return -EINVAL;
6821 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006822 pEseBcnReq->bcnReq[j].channel = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006823 break;
6824
6825 case 2: /* Scan mode */
Varun Reddy Yeturu0b18d5a2013-12-04 11:42:23 -08006826 if ((tempInt < eSIR_PASSIVE_SCAN) || (tempInt > eSIR_BEACON_TABLE))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006827 {
6828 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306829 "Invalid Scan Mode(%u) Expected{0|1|2}", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006830 return -EINVAL;
6831 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006832 pEseBcnReq->bcnReq[j].scanMode= tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006833 break;
6834
6835 case 3: /* Measurement duration */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306836 if (((!tempInt) && (pEseBcnReq->bcnReq[j].scanMode != eSIR_BEACON_TABLE)) ||
6837 ((pEseBcnReq->bcnReq[j].scanMode == eSIR_BEACON_TABLE)))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006838 {
6839 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05306840 "Invalid Measurement Duration: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006841 return -EINVAL;
6842 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006843 pEseBcnReq->bcnReq[j].measurementDuration = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006844 break;
6845 }
6846 }
6847 }
6848
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006849 for (j = 0; j < pEseBcnReq->numBcnReqIe; j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006850 {
6851 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05306852 "Index(%d) Measurement Token(%u)Channel(%u) Scan Mode(%u) Measurement Duration(%u)\n",
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006853 j,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006854 pEseBcnReq->bcnReq[j].measurementToken,
6855 pEseBcnReq->bcnReq[j].channel,
6856 pEseBcnReq->bcnReq[j].scanMode,
6857 pEseBcnReq->bcnReq[j].measurementDuration);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006858 }
6859
6860 return VOS_STATUS_SUCCESS;
6861}
6862
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006863static void hdd_GetTsmStatsCB( tAniTrafStrmMetrics tsmMetrics, const tANI_U32 staId, void *pContext )
6864{
6865 struct statsContext *pStatsContext = NULL;
6866 hdd_adapter_t *pAdapter = NULL;
6867
6868 if (NULL == pContext)
6869 {
6870 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07006871 "%s: Bad param, pContext [%pK]",
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006872 __func__, pContext);
6873 return;
6874 }
6875
Jeff Johnson72a40512013-12-19 10:14:15 -08006876 /* there is a race condition that exists between this callback
6877 function and the caller since the caller could time out either
6878 before or while this code is executing. we use a spinlock to
6879 serialize these actions */
6880 spin_lock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006881
6882 pStatsContext = pContext;
6883 pAdapter = pStatsContext->pAdapter;
6884 if ((NULL == pAdapter) || (STATS_CONTEXT_MAGIC != pStatsContext->magic))
6885 {
6886 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -08006887 spin_unlock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006888 hddLog(VOS_TRACE_LEVEL_WARN,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07006889 "%s: Invalid context, pAdapter [%pK] magic [%08x]",
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006890 __func__, pAdapter, pStatsContext->magic);
6891 return;
6892 }
6893
Jeff Johnson72a40512013-12-19 10:14:15 -08006894 /* context is valid so caller is still waiting */
6895
6896 /* paranoia: invalidate the magic */
6897 pStatsContext->magic = 0;
6898
6899 /* copy over the tsm stats */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006900 pAdapter->tsmStats.UplinkPktQueueDly = tsmMetrics.UplinkPktQueueDly;
6901 vos_mem_copy(pAdapter->tsmStats.UplinkPktQueueDlyHist,
6902 tsmMetrics.UplinkPktQueueDlyHist,
6903 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist)/
6904 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist[0]));
6905 pAdapter->tsmStats.UplinkPktTxDly = tsmMetrics.UplinkPktTxDly;
6906 pAdapter->tsmStats.UplinkPktLoss = tsmMetrics.UplinkPktLoss;
6907 pAdapter->tsmStats.UplinkPktCount = tsmMetrics.UplinkPktCount;
6908 pAdapter->tsmStats.RoamingCount = tsmMetrics.RoamingCount;
6909 pAdapter->tsmStats.RoamingDly = tsmMetrics.RoamingDly;
6910
Jeff Johnson72a40512013-12-19 10:14:15 -08006911 /* notify the caller */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006912 complete(&pStatsContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -08006913
6914 /* serialization is complete */
6915 spin_unlock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006916}
6917
6918
6919
6920static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
6921 tAniTrafStrmMetrics* pTsmMetrics)
6922{
6923 hdd_station_ctx_t *pHddStaCtx = NULL;
6924 eHalStatus hstatus;
Jeff Johnson72a40512013-12-19 10:14:15 -08006925 VOS_STATUS vstatus = VOS_STATUS_SUCCESS;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006926 long lrc;
6927 struct statsContext context;
6928 hdd_context_t *pHddCtx = NULL;
6929
6930 if (NULL == pAdapter)
6931 {
6932 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL", __func__);
6933 return VOS_STATUS_E_FAULT;
6934 }
6935
6936 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6937 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6938
6939 /* we are connected prepare our callback context */
6940 init_completion(&context.completion);
6941 context.pAdapter = pAdapter;
6942 context.magic = STATS_CONTEXT_MAGIC;
6943
6944 /* query tsm stats */
6945 hstatus = sme_GetTsmStats(pHddCtx->hHal, hdd_GetTsmStatsCB,
6946 pHddStaCtx->conn_info.staId[ 0 ],
6947 pHddStaCtx->conn_info.bssId,
6948 &context, pHddCtx->pvosContext, tid);
6949
6950 if (eHAL_STATUS_SUCCESS != hstatus)
6951 {
Jeff Johnson72a40512013-12-19 10:14:15 -08006952 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unable to retrieve statistics",
6953 __func__);
6954 vstatus = VOS_STATUS_E_FAULT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006955 }
6956 else
6957 {
6958 /* request was sent -- wait for the response */
6959 lrc = wait_for_completion_interruptible_timeout(&context.completion,
6960 msecs_to_jiffies(WLAN_WAIT_TIME_STATS));
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006961 if (lrc <= 0)
6962 {
6963 hddLog(VOS_TRACE_LEVEL_ERROR,
6964 "%s: SME %s while retrieving statistics",
6965 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson72a40512013-12-19 10:14:15 -08006966 vstatus = VOS_STATUS_E_TIMEOUT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006967 }
6968 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006969
Jeff Johnson72a40512013-12-19 10:14:15 -08006970 /* either we never sent a request, we sent a request and received a
6971 response or we sent a request and timed out. if we never sent a
6972 request or if we sent a request and got a response, we want to
6973 clear the magic out of paranoia. if we timed out there is a
6974 race condition such that the callback function could be
6975 executing at the same time we are. of primary concern is if the
6976 callback function had already verified the "magic" but had not
6977 yet set the completion variable when a timeout occurred. we
6978 serialize these activities by invalidating the magic while
6979 holding a shared spinlock which will cause us to block if the
6980 callback is currently executing */
6981 spin_lock(&hdd_context_lock);
6982 context.magic = 0;
6983 spin_unlock(&hdd_context_lock);
6984
6985 if (VOS_STATUS_SUCCESS == vstatus)
6986 {
6987 pTsmMetrics->UplinkPktQueueDly = pAdapter->tsmStats.UplinkPktQueueDly;
6988 vos_mem_copy(pTsmMetrics->UplinkPktQueueDlyHist,
6989 pAdapter->tsmStats.UplinkPktQueueDlyHist,
6990 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist)/
6991 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist[0]));
6992 pTsmMetrics->UplinkPktTxDly = pAdapter->tsmStats.UplinkPktTxDly;
6993 pTsmMetrics->UplinkPktLoss = pAdapter->tsmStats.UplinkPktLoss;
6994 pTsmMetrics->UplinkPktCount = pAdapter->tsmStats.UplinkPktCount;
6995 pTsmMetrics->RoamingCount = pAdapter->tsmStats.RoamingCount;
6996 pTsmMetrics->RoamingDly = pAdapter->tsmStats.RoamingDly;
6997 }
6998 return vstatus;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006999}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007000#endif /*FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007001
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007002#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08007003void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand)
7004{
7005 eCsrBand band = -1;
7006 sme_GetFreqBand((tHalHandle)(pHddCtx->hHal), &band);
7007 switch (band)
7008 {
7009 case eCSR_BAND_ALL:
7010 *pBand = WLAN_HDD_UI_BAND_AUTO;
7011 break;
7012
7013 case eCSR_BAND_24:
7014 *pBand = WLAN_HDD_UI_BAND_2_4_GHZ;
7015 break;
7016
7017 case eCSR_BAND_5G:
7018 *pBand = WLAN_HDD_UI_BAND_5_GHZ;
7019 break;
7020
7021 default:
7022 hddLog( VOS_TRACE_LEVEL_WARN, "%s: Invalid Band %d", __func__, band);
7023 *pBand = -1;
7024 break;
7025 }
7026}
7027
7028/**---------------------------------------------------------------------------
7029
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007030 \brief hdd_parse_send_action_frame_data() - HDD Parse send action frame data
7031
7032 This function parses the send action frame data passed in the format
7033 SENDACTIONFRAME<space><bssid><space><channel><space><dwelltime><space><data>
7034
Srinivas Girigowda56076852013-08-20 14:00:50 -07007035 \param - pValue Pointer to input data
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007036 \param - pTargetApBssid Pointer to target Ap bssid
7037 \param - pChannel Pointer to the Target AP channel
7038 \param - pDwellTime Pointer to the time to stay off-channel after transmitting action frame
7039 \param - pBuf Pointer to data
7040 \param - pBufLen Pointer to data length
7041
7042 \return - 0 for success non-zero for failure
7043
7044 --------------------------------------------------------------------------*/
7045VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid, tANI_U8 *pChannel,
7046 tANI_U8 *pDwellTime, tANI_U8 **pBuf, tANI_U8 *pBufLen)
7047{
7048 tANI_U8 *inPtr = pValue;
7049 tANI_U8 *dataEnd;
7050 int tempInt;
7051 int j = 0;
7052 int i = 0;
7053 int v = 0;
7054 tANI_U8 tempBuf[32];
7055 tANI_U8 tempByte = 0;
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007056 /* 12 hexa decimal digits, 5 ':' and '\0' */
7057 tANI_U8 macAddress[18];
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007058
7059 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7060 /*no argument after the command*/
7061 if (NULL == inPtr)
7062 {
7063 return -EINVAL;
7064 }
7065
7066 /*no space after the command*/
7067 else if (SPACE_ASCII_VALUE != *inPtr)
7068 {
7069 return -EINVAL;
7070 }
7071
7072 /*removing empty spaces*/
7073 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7074
7075 /*no argument followed by spaces*/
7076 if ('\0' == *inPtr)
7077 {
7078 return -EINVAL;
7079 }
7080
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007081 v = sscanf(inPtr, "%17s", macAddress);
7082 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007083 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007084 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7085 "Invalid MAC address or All hex inputs are not read (%d)", v);
7086 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007087 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007088
7089 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
7090 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
7091 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
7092 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
7093 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
7094 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007095
7096 /* point to the next argument */
7097 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7098 /*no argument after the command*/
7099 if (NULL == inPtr) return -EINVAL;
7100
7101 /*removing empty spaces*/
7102 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7103
7104 /*no argument followed by spaces*/
7105 if ('\0' == *inPtr)
7106 {
7107 return -EINVAL;
7108 }
7109
7110 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007111 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007112 if (1 != v) return -EINVAL;
7113
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007114 v = kstrtos32(tempBuf, 10, &tempInt);
Agarwal Ashish353b3a82014-04-08 14:55:11 +05307115 if ( v < 0 || tempInt <= 0 || tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX )
Kiet Lambe150c22013-11-21 16:30:32 +05307116 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007117
7118 *pChannel = tempInt;
7119
7120 /* point to the next argument */
7121 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7122 /*no argument after the command*/
7123 if (NULL == inPtr) return -EINVAL;
7124 /*removing empty spaces*/
7125 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7126
7127 /*no argument followed by spaces*/
7128 if ('\0' == *inPtr)
7129 {
7130 return -EINVAL;
7131 }
7132
7133 /*getting the next argument ie the dwell time */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007134 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007135 if (1 != v) return -EINVAL;
7136
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007137 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda5a6e0672014-01-09 14:42:57 -08007138 if ( v < 0 || tempInt < 0) return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007139
7140 *pDwellTime = tempInt;
7141
7142 /* point to the next argument */
7143 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7144 /*no argument after the command*/
7145 if (NULL == inPtr) return -EINVAL;
7146 /*removing empty spaces*/
7147 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7148
7149 /*no argument followed by spaces*/
7150 if ('\0' == *inPtr)
7151 {
7152 return -EINVAL;
7153 }
7154
7155 /* find the length of data */
7156 dataEnd = inPtr;
7157 while(('\0' != *dataEnd) )
7158 {
7159 dataEnd++;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007160 }
Kiet Lambe150c22013-11-21 16:30:32 +05307161 *pBufLen = dataEnd - inPtr ;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007162 if ( *pBufLen <= 0) return -EINVAL;
7163
Srinivas Girigowdab5ae85d2013-06-03 10:51:45 -07007164 /* Allocate the number of bytes based on the number of input characters
7165 whether it is even or odd.
7166 if the number of input characters are even, then we need N/2 byte.
7167 if the number of input characters are odd, then we need do (N+1)/2 to
7168 compensate rounding off.
7169 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
7170 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
7171 *pBuf = vos_mem_malloc((*pBufLen + 1)/2);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007172 if (NULL == *pBuf)
7173 {
7174 hddLog(VOS_TRACE_LEVEL_FATAL,
7175 "%s: vos_mem_alloc failed ", __func__);
7176 return -EINVAL;
7177 }
7178
7179 /* the buffer received from the upper layer is character buffer,
7180 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
7181 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
7182 and f0 in 3rd location */
7183 for (i = 0, j = 0; j < *pBufLen; j += 2)
7184 {
Kiet Lambe150c22013-11-21 16:30:32 +05307185 if( j+1 == *pBufLen)
7186 {
7187 tempByte = hdd_parse_hex(inPtr[j]);
7188 }
7189 else
7190 {
7191 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
7192 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007193 (*pBuf)[i++] = tempByte;
7194 }
7195 *pBufLen = i;
7196 return VOS_STATUS_SUCCESS;
7197}
7198
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007199/**---------------------------------------------------------------------------
7200
Srinivas Girigowdade697412013-02-14 16:31:48 -08007201 \brief hdd_parse_channellist() - HDD Parse channel list
7202
7203 This function parses the channel list passed in the format
7204 SETROAMSCANCHANNELS<space><Number of channels><space>Channel 1<space>Channel 2<space>Channel N
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007205 if the Number of channels (N) does not match with the actual number of channels passed
7206 then take the minimum of N and count of (Ch1, Ch2, ...Ch M)
7207 For example, if SETROAMSCANCHANNELS 3 36 40 44 48, only 36, 40 and 44 shall be taken.
7208 If SETROAMSCANCHANNELS 5 36 40 44 48, ignore 5 and take 36, 40, 44 and 48.
7209 This function does not take care of removing duplicate channels from the list
Srinivas Girigowdade697412013-02-14 16:31:48 -08007210
7211 \param - pValue Pointer to input channel list
7212 \param - ChannelList Pointer to local output array to record channel list
7213 \param - pNumChannels Pointer to number of roam scan channels
7214
7215 \return - 0 for success non-zero for failure
7216
7217 --------------------------------------------------------------------------*/
7218VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels)
7219{
7220 tANI_U8 *inPtr = pValue;
7221 int tempInt;
7222 int j = 0;
7223 int v = 0;
7224 char buf[32];
7225
7226 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7227 /*no argument after the command*/
7228 if (NULL == inPtr)
7229 {
7230 return -EINVAL;
7231 }
7232
7233 /*no space after the command*/
7234 else if (SPACE_ASCII_VALUE != *inPtr)
7235 {
7236 return -EINVAL;
7237 }
7238
7239 /*removing empty spaces*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007240 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08007241
7242 /*no argument followed by spaces*/
7243 if ('\0' == *inPtr)
7244 {
7245 return -EINVAL;
7246 }
7247
7248 /*getting the first argument ie the number of channels*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007249 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007250 if (1 != v) return -EINVAL;
7251
Srinivas Girigowdade697412013-02-14 16:31:48 -08007252 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007253 if ((v < 0) ||
7254 (tempInt <= 0) ||
7255 (tempInt > WNI_CFG_VALID_CHANNEL_LIST_LEN))
7256 {
7257 return -EINVAL;
7258 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007259
7260 *pNumChannels = tempInt;
7261
7262 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
7263 "Number of channels are: %d", *pNumChannels);
7264
7265 for (j = 0; j < (*pNumChannels); j++)
7266 {
7267 /*inPtr pointing to the beginning of first space after number of channels*/
7268 inPtr = strpbrk( inPtr, " " );
7269 /*no channel list after the number of channels argument*/
7270 if (NULL == inPtr)
7271 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007272 if (0 != j)
7273 {
7274 *pNumChannels = j;
7275 return VOS_STATUS_SUCCESS;
7276 }
7277 else
7278 {
7279 return -EINVAL;
7280 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007281 }
7282
7283 /*removing empty space*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007284 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08007285
7286 /*no channel list after the number of channels argument and spaces*/
7287 if ( '\0' == *inPtr )
7288 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007289 if (0 != j)
7290 {
7291 *pNumChannels = j;
7292 return VOS_STATUS_SUCCESS;
7293 }
7294 else
7295 {
7296 return -EINVAL;
7297 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007298 }
7299
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007300 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007301 if (1 != v) return -EINVAL;
7302
Srinivas Girigowdade697412013-02-14 16:31:48 -08007303 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007304 if ((v < 0) ||
7305 (tempInt <= 0) ||
7306 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7307 {
7308 return -EINVAL;
7309 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007310 pChannelList[j] = tempInt;
7311
7312 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
7313 "Channel %d added to preferred channel list",
7314 pChannelList[j] );
7315 }
7316
Srinivas Girigowdade697412013-02-14 16:31:48 -08007317 return VOS_STATUS_SUCCESS;
7318}
7319
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007320
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05307321/**
7322 * hdd_parse_reassoc_command_v1_data() - HDD Parse reassoc command data
7323 * This function parses the reasoc command data passed in the format
7324 * REASSOC<space><bssid><space><channel>
7325 *
7326 * @pValue: Pointer to input data (its a NUL terminated string)
7327 * @pTargetApBssid: Pointer to target Ap bssid
7328 * @pChannel: Pointer to the Target AP channel
7329 *
7330 * Return: 0 for success non-zero for failure
7331 */
7332static int hdd_parse_reassoc_command_v1_data(const tANI_U8 *pValue,
7333 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007334{
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05307335 const tANI_U8 *inPtr = pValue;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007336 int tempInt;
7337 int v = 0;
7338 tANI_U8 tempBuf[32];
Kiet Lamaa8e15a2014-02-11 23:30:06 -08007339 /* 12 hexa decimal digits, 5 ':' and '\0' */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007340 tANI_U8 macAddress[18];
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007341
7342 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7343 /*no argument after the command*/
7344 if (NULL == inPtr)
7345 {
7346 return -EINVAL;
7347 }
7348
7349 /*no space after the command*/
7350 else if (SPACE_ASCII_VALUE != *inPtr)
7351 {
7352 return -EINVAL;
7353 }
7354
7355 /*removing empty spaces*/
7356 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7357
7358 /*no argument followed by spaces*/
7359 if ('\0' == *inPtr)
7360 {
7361 return -EINVAL;
7362 }
7363
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007364 v = sscanf(inPtr, "%17s", macAddress);
7365 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007366 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007367 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7368 "Invalid MAC address or All hex inputs are not read (%d)", v);
7369 return -EINVAL;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007370 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007371
7372 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
7373 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
7374 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
7375 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
7376 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
7377 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007378
7379 /* point to the next argument */
7380 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7381 /*no argument after the command*/
7382 if (NULL == inPtr) return -EINVAL;
7383
7384 /*removing empty spaces*/
7385 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7386
7387 /*no argument followed by spaces*/
7388 if ('\0' == *inPtr)
7389 {
7390 return -EINVAL;
7391 }
7392
7393 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007394 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007395 if (1 != v) return -EINVAL;
7396
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007397 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007398 if ((v < 0) ||
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05307399 (tempInt < 0) ||
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007400 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7401 {
7402 return -EINVAL;
7403 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007404
7405 *pChannel = tempInt;
7406 return VOS_STATUS_SUCCESS;
7407}
7408
7409#endif
7410
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007411#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007412/**---------------------------------------------------------------------------
7413
7414 \brief hdd_parse_get_cckm_ie() - HDD Parse and fetch the CCKM IE
7415
7416 This function parses the SETCCKM IE command
7417 SETCCKMIE<space><ie data>
7418
7419 \param - pValue Pointer to input data
7420 \param - pCckmIe Pointer to output cckm Ie
7421 \param - pCckmIeLen Pointer to output cckm ie length
7422
7423 \return - 0 for success non-zero for failure
7424
7425 --------------------------------------------------------------------------*/
7426VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe,
7427 tANI_U8 *pCckmIeLen)
7428{
7429 tANI_U8 *inPtr = pValue;
7430 tANI_U8 *dataEnd;
7431 int j = 0;
7432 int i = 0;
7433 tANI_U8 tempByte = 0;
7434
7435 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7436 /*no argument after the command*/
7437 if (NULL == inPtr)
7438 {
7439 return -EINVAL;
7440 }
7441
7442 /*no space after the command*/
7443 else if (SPACE_ASCII_VALUE != *inPtr)
7444 {
7445 return -EINVAL;
7446 }
7447
7448 /*removing empty spaces*/
7449 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7450
7451 /*no argument followed by spaces*/
7452 if ('\0' == *inPtr)
7453 {
7454 return -EINVAL;
7455 }
7456
7457 /* find the length of data */
7458 dataEnd = inPtr;
7459 while(('\0' != *dataEnd) )
7460 {
7461 dataEnd++;
7462 ++(*pCckmIeLen);
7463 }
7464 if ( *pCckmIeLen <= 0) return -EINVAL;
7465
7466 /* Allocate the number of bytes based on the number of input characters
7467 whether it is even or odd.
7468 if the number of input characters are even, then we need N/2 byte.
7469 if the number of input characters are odd, then we need do (N+1)/2 to
7470 compensate rounding off.
7471 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
7472 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
7473 *pCckmIe = vos_mem_malloc((*pCckmIeLen + 1)/2);
7474 if (NULL == *pCckmIe)
7475 {
7476 hddLog(VOS_TRACE_LEVEL_FATAL,
7477 "%s: vos_mem_alloc failed ", __func__);
7478 return -EINVAL;
7479 }
7480 vos_mem_zero(*pCckmIe, (*pCckmIeLen + 1)/2);
7481 /* the buffer received from the upper layer is character buffer,
7482 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
7483 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
7484 and f0 in 3rd location */
7485 for (i = 0, j = 0; j < *pCckmIeLen; j += 2)
7486 {
7487 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
7488 (*pCckmIe)[i++] = tempByte;
7489 }
7490 *pCckmIeLen = i;
7491
7492 return VOS_STATUS_SUCCESS;
7493}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007494#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007495
Jeff Johnson295189b2012-06-20 16:38:30 -07007496/**---------------------------------------------------------------------------
7497
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007498 \brief hdd_is_valid_mac_address() - Validate MAC address
7499
7500 This function validates whether the given MAC address is valid or not
7501 Expected MAC address is of the format XX:XX:XX:XX:XX:XX
7502 where X is the hexa decimal digit character and separated by ':'
7503 This algorithm works even if MAC address is not separated by ':'
7504
7505 This code checks given input string mac contains exactly 12 hexadecimal digits.
7506 and a separator colon : appears in the input string only after
7507 an even number of hex digits.
7508
7509 \param - pMacAddr pointer to the input MAC address
7510 \return - 1 for valid and 0 for invalid
7511
7512 --------------------------------------------------------------------------*/
7513
7514v_BOOL_t hdd_is_valid_mac_address(const tANI_U8 *pMacAddr)
7515{
7516 int xdigit = 0;
7517 int separator = 0;
7518 while (*pMacAddr)
7519 {
7520 if (isxdigit(*pMacAddr))
7521 {
7522 xdigit++;
7523 }
7524 else if (':' == *pMacAddr)
7525 {
7526 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
7527 break;
7528
7529 ++separator;
7530 }
7531 else
7532 {
7533 separator = -1;
7534 /* Invalid MAC found */
7535 return 0;
7536 }
7537 ++pMacAddr;
7538 }
7539 return (xdigit == 12 && (separator == 5 || separator == 0));
7540}
7541
7542/**---------------------------------------------------------------------------
7543
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307544 \brief __hdd_open() - HDD Open function
Jeff Johnson295189b2012-06-20 16:38:30 -07007545
7546 \param - dev Pointer to net_device structure
7547
7548 \return - 0 for success non-zero for failure
7549
7550 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307551int __hdd_open(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07007552{
7553 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7554 hdd_context_t *pHddCtx;
7555 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7556 VOS_STATUS status;
7557 v_BOOL_t in_standby = TRUE;
7558
7559 if (NULL == pAdapter)
7560 {
7561 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05307562 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007563 return -ENODEV;
7564 }
7565
7566 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307567 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
7568 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson295189b2012-06-20 16:38:30 -07007569 if (NULL == pHddCtx)
7570 {
7571 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007572 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007573 return -ENODEV;
7574 }
7575
7576 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7577 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
7578 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07007579 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
7580 {
7581 hddLog(VOS_TRACE_LEVEL_INFO, "%s: chip already out of standby",
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05307582 __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07007583 in_standby = FALSE;
7584 break;
7585 }
7586 else
7587 {
7588 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7589 pAdapterNode = pNext;
7590 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007591 }
7592
7593 if (TRUE == in_standby)
7594 {
7595 if (VOS_STATUS_SUCCESS != wlan_hdd_exit_lowpower(pHddCtx, pAdapter))
7596 {
7597 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to bring "
7598 "wlan out of power save", __func__);
7599 return -EINVAL;
7600 }
7601 }
7602
Jeff Johnson6a81ca42013-04-05 10:37:08 -07007603 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07007604 if (hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
7605 {
7606 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007607 "%s: Enabling Tx Queues", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007608 /* Enable TX queues only when we are connected */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05307609 hddLog(VOS_TRACE_LEVEL_INFO, FL("Enabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007610 netif_tx_start_all_queues(dev);
7611 }
7612
7613 return 0;
7614}
7615
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307616/**---------------------------------------------------------------------------
7617
7618 \brief hdd_open() - Wrapper function for __hdd_open to protect it from SSR
7619
7620 This is called in response to ifconfig up
7621
7622 \param - dev Pointer to net_device structure
7623
7624 \return - 0 for success non-zero for failure
7625
7626 --------------------------------------------------------------------------*/
7627int hdd_open(struct net_device *dev)
7628{
7629 int ret;
7630
7631 vos_ssr_protect(__func__);
7632 ret = __hdd_open(dev);
7633 vos_ssr_unprotect(__func__);
7634
7635 return ret;
7636}
7637
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05307638int __hdd_mon_open (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07007639{
7640 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05307641 hdd_adapter_t *sta_adapter;
7642 hdd_context_t *hdd_ctx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007643
7644 if(pAdapter == NULL) {
7645 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007646 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08007647 return -EINVAL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007648 }
7649
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05307650 if (vos_get_concurrency_mode() != VOS_STA_MON)
7651 return 0;
7652
7653 hdd_ctx = WLAN_HDD_GET_CTX(pAdapter);
7654 if (wlan_hdd_validate_context(hdd_ctx))
7655 return -EINVAL;
7656
7657 sta_adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_INFRA_STATION);
7658 if (!sta_adapter) {
7659 hddLog(LOGE, FL("No valid STA interface"));
7660 return -EINVAL;
7661 }
7662
7663 if (!test_bit(DEVICE_IFACE_OPENED, &sta_adapter->event_flags)) {
7664 hddLog(LOGE, FL("STA Interface is not OPENED"));
7665 return -EINVAL;
7666 }
7667
7668 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
7669
Jeff Johnson295189b2012-06-20 16:38:30 -07007670 return 0;
7671}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05307672
7673int hdd_mon_open (struct net_device *dev)
7674{
7675 int ret;
7676
7677 vos_ssr_protect(__func__);
7678 ret = __hdd_mon_open(dev);
7679 vos_ssr_unprotect(__func__);
7680
7681 return ret;
7682}
7683
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05307684int __hdd_mon_stop (struct net_device *dev)
7685{
7686 hdd_adapter_t *mon_adapter = WLAN_HDD_GET_PRIV_PTR(dev);
7687 hdd_context_t *hdd_ctx;
7688
7689 if (vos_get_concurrency_mode() != VOS_STA_MON)
7690 return 0;
7691
7692 if(!mon_adapter) {
7693 hddLog(LOGE, FL("HDD adapter is Null"));
7694 return -EINVAL;
7695 }
7696
7697 hdd_ctx = WLAN_HDD_GET_CTX(mon_adapter);
7698 if (wlan_hdd_validate_context(hdd_ctx))
7699 return -EINVAL;
7700
7701 if (!test_bit(DEVICE_IFACE_OPENED, &mon_adapter->event_flags)) {
7702 hddLog(LOGE, FL("NETDEV Interface is not OPENED"));
7703 return -ENODEV;
7704 }
7705
7706 clear_bit(DEVICE_IFACE_OPENED, &mon_adapter->event_flags);
7707 hdd_stop_adapter(hdd_ctx, mon_adapter, VOS_FALSE);
7708
7709 return 0;
7710}
7711
Katya Nigame7b69a82015-04-28 15:24:06 +05307712int hdd_mon_stop(struct net_device *dev)
7713{
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05307714 int ret;
7715
7716 vos_ssr_protect(__func__);
7717 ret = __hdd_mon_stop(dev);
7718 vos_ssr_unprotect(__func__);
7719
7720 return ret;
Katya Nigame7b69a82015-04-28 15:24:06 +05307721}
7722
Jeff Johnson295189b2012-06-20 16:38:30 -07007723/**---------------------------------------------------------------------------
7724
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307725 \brief __hdd_stop() - HDD stop function
Jeff Johnson295189b2012-06-20 16:38:30 -07007726
7727 \param - dev Pointer to net_device structure
7728
7729 \return - 0 for success non-zero for failure
7730
7731 --------------------------------------------------------------------------*/
7732
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307733int __hdd_stop (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07007734{
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05307735 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007736 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7737 hdd_context_t *pHddCtx;
7738 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7739 VOS_STATUS status;
7740 v_BOOL_t enter_standby = TRUE;
7741
7742 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007743 if (NULL == pAdapter)
7744 {
7745 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05307746 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007747 return -ENODEV;
7748 }
Sachin Ahuja9b4958f2015-01-15 21:37:00 +05307749 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307750 pAdapter->sessionId, pAdapter->device_mode));
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05307751
7752 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7753 ret = wlan_hdd_validate_context(pHddCtx);
7754 if (ret)
Jeff Johnson295189b2012-06-20 16:38:30 -07007755 {
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05307756 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07007757 }
7758
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307759 /* Nothing to be done if the interface is not opened */
7760 if (VOS_FALSE == test_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags))
7761 {
7762 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7763 "%s: NETDEV Interface is not OPENED", __func__);
7764 return -ENODEV;
7765 }
7766
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05307767 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05307768 /*
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05307769 * In STA + Monitor mode concurrency, no point in running
7770 * capture on monitor interface, when STA interface is stopped
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05307771 */
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05307772 wlan_hdd_stop_mon(pHddCtx, true);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05307773 }
7774
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307775 /* Make sure the interface is marked as closed */
Jeff Johnson6a81ca42013-04-05 10:37:08 -07007776 clear_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07007777 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disabling OS Tx queues", __func__);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307778
7779 /* Disable TX on the interface, after this hard_start_xmit() will not
7780 * be called on that interface
7781 */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05307782 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007783 netif_tx_disable(pAdapter->dev);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307784
7785 /* Mark the interface status as "down" for outside world */
Jeff Johnson295189b2012-06-20 16:38:30 -07007786 netif_carrier_off(pAdapter->dev);
7787
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307788 /* The interface is marked as down for outside world (aka kernel)
7789 * But the driver is pretty much alive inside. The driver needs to
7790 * tear down the existing connection on the netdev (session)
7791 * cleanup the data pipes and wait until the control plane is stabilized
7792 * for this interface. The call also needs to wait until the above
7793 * mentioned actions are completed before returning to the caller.
7794 * Notice that the hdd_stop_adapter is requested not to close the session
7795 * That is intentional to be able to scan if it is a STA/P2P interface
7796 */
7797 hdd_stop_adapter(pHddCtx, pAdapter, VOS_FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307798#ifdef FEATURE_WLAN_TDLS
7799 mutex_lock(&pHddCtx->tdls_lock);
7800#endif
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307801 /* DeInit the adapter. This ensures datapath cleanup as well */
c_hpothu002231a2015-02-05 14:58:51 +05307802 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307803#ifdef FEATURE_WLAN_TDLS
7804 mutex_unlock(&pHddCtx->tdls_lock);
7805#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007806 /* SoftAP ifaces should never go in power save mode
7807 making sure same here. */
7808 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07007809 || (WLAN_HDD_P2P_GO == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07007810 )
7811 {
7812 /* SoftAP mode, so return from here */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307813 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7814 "%s: In SAP MODE", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007815 EXIT();
7816 return 0;
7817 }
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307818 /* Find if any iface is up. If any iface is up then can't put device to
7819 * sleep/power save mode
7820 */
Jeff Johnson295189b2012-06-20 16:38:30 -07007821 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7822 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
7823 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07007824 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
7825 {
7826 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Still other ifaces are up cannot "
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05307827 "put device to sleep", __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07007828 enter_standby = FALSE;
7829 break;
7830 }
7831 else
7832 {
7833 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7834 pAdapterNode = pNext;
7835 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007836 }
7837
7838 if (TRUE == enter_standby)
7839 {
7840 hddLog(VOS_TRACE_LEVEL_INFO, "%s: All Interfaces are Down "
7841 "entering standby", __func__);
7842 if (VOS_STATUS_SUCCESS != wlan_hdd_enter_lowpower(pHddCtx))
7843 {
7844 /*log and return success*/
7845 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to put "
7846 "wlan in power save", __func__);
7847 }
7848 }
7849
7850 EXIT();
7851 return 0;
7852}
7853
7854/**---------------------------------------------------------------------------
7855
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307856 \brief hdd_stop() - wrapper_function for __hdd_stop to protect it from SSR
Jeff Johnson295189b2012-06-20 16:38:30 -07007857
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307858 This is called in response to ifconfig down
7859
7860 \param - dev Pointer to net_device structure
7861
7862 \return - 0 for success non-zero for failure
7863-----------------------------------------------------------------------------*/
7864int hdd_stop (struct net_device *dev)
7865{
7866 int ret;
7867
7868 vos_ssr_protect(__func__);
7869 ret = __hdd_stop(dev);
7870 vos_ssr_unprotect(__func__);
7871
7872 return ret;
7873}
7874
7875/**---------------------------------------------------------------------------
7876
7877 \brief __hdd_uninit() - HDD uninit function
Jeff Johnson295189b2012-06-20 16:38:30 -07007878
7879 \param - dev Pointer to net_device structure
7880
7881 \return - void
7882
7883 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307884static void __hdd_uninit (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07007885{
7886 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307887 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007888 ENTER();
7889
7890 do
7891 {
7892 if (NULL == pAdapter)
7893 {
7894 hddLog(VOS_TRACE_LEVEL_FATAL,
7895 "%s: NULL pAdapter", __func__);
7896 break;
7897 }
7898
7899 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
7900 {
7901 hddLog(VOS_TRACE_LEVEL_FATAL,
7902 "%s: Invalid magic", __func__);
7903 break;
7904 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307905 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7906 if (NULL == pHddCtx)
Jeff Johnson295189b2012-06-20 16:38:30 -07007907 {
7908 hddLog(VOS_TRACE_LEVEL_FATAL,
7909 "%s: NULL pHddCtx", __func__);
7910 break;
7911 }
7912
7913 if (dev != pAdapter->dev)
7914 {
7915 hddLog(VOS_TRACE_LEVEL_FATAL,
7916 "%s: Invalid device reference", __func__);
7917 /* we haven't validated all cases so let this go for now */
7918 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307919#ifdef FEATURE_WLAN_TDLS
7920 mutex_lock(&pHddCtx->tdls_lock);
7921#endif
c_hpothu002231a2015-02-05 14:58:51 +05307922 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307923#ifdef FEATURE_WLAN_TDLS
7924 mutex_unlock(&pHddCtx->tdls_lock);
7925#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007926
7927 /* after uninit our adapter structure will no longer be valid */
7928 pAdapter->dev = NULL;
7929 pAdapter->magic = 0;
Manjeet Singh47ee8472016-04-11 11:57:18 +05307930 pAdapter->pHddCtx = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007931 } while (0);
7932
7933 EXIT();
7934}
7935
7936/**---------------------------------------------------------------------------
7937
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307938 \brief hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
7939
7940 This is called during the netdev unregister to uninitialize all data
7941associated with the device
7942
7943 \param - dev Pointer to net_device structure
7944
7945 \return - void
7946
7947 --------------------------------------------------------------------------*/
7948static void hdd_uninit (struct net_device *dev)
7949{
7950 vos_ssr_protect(__func__);
7951 __hdd_uninit(dev);
7952 vos_ssr_unprotect(__func__);
7953}
7954
7955/**---------------------------------------------------------------------------
7956
Jeff Johnson295189b2012-06-20 16:38:30 -07007957 \brief hdd_release_firmware() -
7958
7959 This function calls the release firmware API to free the firmware buffer.
7960
7961 \param - pFileName Pointer to the File Name.
7962 pCtx - Pointer to the adapter .
7963
7964
7965 \return - 0 for success, non zero for failure
7966
7967 --------------------------------------------------------------------------*/
7968
7969VOS_STATUS hdd_release_firmware(char *pFileName,v_VOID_t *pCtx)
7970{
7971 VOS_STATUS status = VOS_STATUS_SUCCESS;
7972 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
7973 ENTER();
7974
7975
7976 if (!strcmp(WLAN_FW_FILE, pFileName)) {
7977
7978 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"%s: Loaded firmware file is %s",__func__,pFileName);
7979
7980 if(pHddCtx->fw) {
7981 release_firmware(pHddCtx->fw);
7982 pHddCtx->fw = NULL;
7983 }
7984 else
7985 status = VOS_STATUS_E_FAILURE;
7986 }
7987 else if (!strcmp(WLAN_NV_FILE,pFileName)) {
7988 if(pHddCtx->nv) {
7989 release_firmware(pHddCtx->nv);
7990 pHddCtx->nv = NULL;
7991 }
7992 else
7993 status = VOS_STATUS_E_FAILURE;
7994
7995 }
7996
7997 EXIT();
7998 return status;
7999}
8000
8001/**---------------------------------------------------------------------------
8002
8003 \brief hdd_request_firmware() -
8004
8005 This function reads the firmware file using the request firmware
8006 API and returns the the firmware data and the firmware file size.
8007
8008 \param - pfileName - Pointer to the file name.
8009 - pCtx - Pointer to the adapter .
8010 - ppfw_data - Pointer to the pointer of the firmware data.
8011 - pSize - Pointer to the file size.
8012
8013 \return - VOS_STATUS_SUCCESS for success, VOS_STATUS_E_FAILURE for failure
8014
8015 --------------------------------------------------------------------------*/
8016
8017
8018VOS_STATUS hdd_request_firmware(char *pfileName,v_VOID_t *pCtx,v_VOID_t **ppfw_data, v_SIZE_t *pSize)
8019{
8020 int status;
8021 VOS_STATUS retval = VOS_STATUS_SUCCESS;
8022 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8023 ENTER();
8024
8025 if( (!strcmp(WLAN_FW_FILE, pfileName)) ) {
8026
8027 status = request_firmware(&pHddCtx->fw, pfileName, pHddCtx->parent_dev);
8028
8029 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8030 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Firmware %s download failed",
8031 __func__, pfileName);
8032 retval = VOS_STATUS_E_FAILURE;
8033 }
8034
8035 else {
8036 *ppfw_data = (v_VOID_t *)pHddCtx->fw->data;
8037 *pSize = pHddCtx->fw->size;
8038 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Firmware size = %d",
8039 __func__, *pSize);
8040 }
8041 }
8042 else if(!strcmp(WLAN_NV_FILE, pfileName)) {
8043
8044 status = request_firmware(&pHddCtx->nv, pfileName, pHddCtx->parent_dev);
8045
8046 if(status || !pHddCtx->nv || !pHddCtx->nv->data) {
8047 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: nv %s download failed",
8048 __func__, pfileName);
8049 retval = VOS_STATUS_E_FAILURE;
8050 }
8051
8052 else {
8053 *ppfw_data = (v_VOID_t *)pHddCtx->nv->data;
8054 *pSize = pHddCtx->nv->size;
8055 hddLog(VOS_TRACE_LEVEL_INFO, "%s: nv file size = %d",
8056 __func__, *pSize);
8057 }
8058 }
8059
8060 EXIT();
8061 return retval;
8062}
8063/**---------------------------------------------------------------------------
8064 \brief hdd_full_pwr_cbk() - HDD full power callbackfunction
8065
8066 This is the function invoked by SME to inform the result of a full power
8067 request issued by HDD
8068
8069 \param - callbackcontext - Pointer to cookie
8070 status - result of request
8071
8072 \return - None
8073
8074--------------------------------------------------------------------------*/
8075void hdd_full_pwr_cbk(void *callbackContext, eHalStatus status)
8076{
8077 hdd_context_t *pHddCtx = (hdd_context_t*)callbackContext;
8078
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07008079 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"HDD full Power callback status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008080 if(&pHddCtx->full_pwr_comp_var)
8081 {
8082 complete(&pHddCtx->full_pwr_comp_var);
8083 }
8084}
8085
Abhishek Singh00b71972016-01-07 10:51:04 +05308086#ifdef WLAN_FEATURE_RMC
8087static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo)
8088{
8089 int payload_len;
8090 struct sk_buff *skb;
8091 struct nlmsghdr *nlh;
8092 v_U8_t *data;
8093
8094 payload_len = ETH_ALEN;
8095
8096 if (0 == cesium_pid)
8097 {
8098 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: cesium process not registered",
8099 __func__);
8100 return;
8101 }
8102
8103 if ((skb = nlmsg_new(payload_len,GFP_ATOMIC)) == NULL)
8104 {
8105 hddLog(VOS_TRACE_LEVEL_ERROR,
8106 "%s: nlmsg_new() failed for msg size[%d]",
8107 __func__, NLMSG_SPACE(payload_len));
8108 return;
8109 }
8110
8111 nlh = nlmsg_put(skb, cesium_pid, seqNo, 0, payload_len, NLM_F_REQUEST);
8112
8113 if (NULL == nlh)
8114 {
8115 hddLog(VOS_TRACE_LEVEL_ERROR,
8116 "%s: nlmsg_put() failed for msg size[%d]",
8117 __func__, NLMSG_SPACE(payload_len));
8118
8119 kfree_skb(skb);
8120 return;
8121 }
8122
8123 data = nlmsg_data(nlh);
8124 memcpy(data, MacAddr, ETH_ALEN);
8125
8126 if (nlmsg_unicast(cesium_nl_srv_sock, skb, cesium_pid) < 0)
8127 {
8128 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: nlmsg_unicast() failed for msg size[%d]",
8129 __func__, NLMSG_SPACE(payload_len));
8130 }
8131
8132 return;
8133}
8134
8135/**---------------------------------------------------------------------------
8136 \brief hdd_ParseuserParams - return a pointer to the next argument
8137
8138 \return - status
8139
8140--------------------------------------------------------------------------*/
8141static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg)
8142{
8143 tANI_U8 *pVal;
8144
8145 pVal = strchr(pValue, ' ');
8146
8147 if (NULL == pVal)
8148 {
8149 /* no argument remains */
8150 return -EINVAL;
8151 }
8152 else if (SPACE_ASCII_VALUE != *pVal)
8153 {
8154 /* no space after the current argument */
8155 return -EINVAL;
8156 }
8157
8158 pVal++;
8159
8160 /* remove empty spaces */
8161 while ((SPACE_ASCII_VALUE == *pVal) && ('\0' != *pVal))
8162 {
8163 pVal++;
8164 }
8165
8166 /* no argument followed by spaces */
8167 if ('\0' == *pVal)
8168 {
8169 return -EINVAL;
8170 }
8171
8172 *ppArg = pVal;
8173
8174 return 0;
8175}
8176
8177/**----------------------------------------------------------------------------
8178 \brief hdd_ParseIBSSTXFailEventParams - Parse params for SETIBSSTXFAILEVENT
8179
8180 \return - status
8181
8182------------------------------------------------------------------------------*/
8183static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
8184 tANI_U8 *tx_fail_count,
8185 tANI_U16 *pid)
8186{
8187 tANI_U8 *param = NULL;
8188 int ret;
8189
8190 ret = hdd_ParseUserParams(pValue, &param);
8191
8192 if (0 == ret && NULL != param)
8193 {
8194 if (1 != sscanf(param, "%hhu", tx_fail_count))
8195 {
8196 ret = -EINVAL;
8197 goto done;
8198 }
8199 }
8200 else
8201 {
8202 goto done;
8203 }
8204
8205 if (0 == *tx_fail_count)
8206 {
8207 *pid = 0;
8208 goto done;
8209 }
8210
8211 pValue = param;
8212 pValue++;
8213
8214 ret = hdd_ParseUserParams(pValue, &param);
8215
8216 if (0 == ret)
8217 {
8218 if (1 != sscanf(param, "%hu", pid))
8219 {
8220 ret = -EINVAL;
8221 goto done;
8222 }
8223 }
8224 else
8225 {
8226 goto done;
8227 }
8228
8229done:
8230 return ret;
8231}
8232
8233static int hdd_open_cesium_nl_sock()
8234{
8235#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
8236 struct netlink_kernel_cfg cfg = {
8237 .groups = WLAN_NLINK_MCAST_GRP_ID,
8238 .input = NULL
8239 };
8240#endif
8241 int ret = 0;
8242
8243#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
8244 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
8245#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
8246 THIS_MODULE,
8247#endif
8248 &cfg);
8249#else
8250 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
8251 WLAN_NLINK_MCAST_GRP_ID, NULL, NULL, THIS_MODULE);
8252#endif
8253
8254 if (cesium_nl_srv_sock == NULL)
8255 {
8256 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8257 "NLINK: cesium netlink_kernel_create failed");
8258 ret = -ECONNREFUSED;
8259 }
8260
8261 return ret;
8262}
8263
8264static void hdd_close_cesium_nl_sock()
8265{
8266 if (NULL != cesium_nl_srv_sock)
8267 {
8268 netlink_kernel_release(cesium_nl_srv_sock);
8269 cesium_nl_srv_sock = NULL;
8270 }
8271}
8272#endif /* WLAN_FEATURE_RMC */
Jeff Johnson295189b2012-06-20 16:38:30 -07008273/**---------------------------------------------------------------------------
8274
8275 \brief hdd_req_bmps_cbk() - HDD Request BMPS callback function
8276
8277 This is the function invoked by SME to inform the result of BMPS
8278 request issued by HDD
8279
8280 \param - callbackcontext - Pointer to cookie
8281 status - result of request
8282
8283 \return - None
8284
8285--------------------------------------------------------------------------*/
8286void hdd_req_bmps_cbk(void *callbackContext, eHalStatus status)
8287{
8288
8289 struct completion *completion_var = (struct completion*) callbackContext;
8290
Arif Hussain6d2a3322013-11-17 19:50:10 -08008291 hddLog(VOS_TRACE_LEVEL_ERROR, "HDD BMPS request Callback, status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008292 if(completion_var != NULL)
8293 {
8294 complete(completion_var);
8295 }
8296}
8297
8298/**---------------------------------------------------------------------------
8299
8300 \brief hdd_get_cfg_file_size() -
8301
8302 This function reads the configuration file using the request firmware
8303 API and returns the configuration file size.
8304
8305 \param - pCtx - Pointer to the adapter .
8306 - pFileName - Pointer to the file name.
8307 - pBufSize - Pointer to the buffer size.
8308
8309 \return - 0 for success, non zero for failure
8310
8311 --------------------------------------------------------------------------*/
8312
8313VOS_STATUS hdd_get_cfg_file_size(v_VOID_t *pCtx, char *pFileName, v_SIZE_t *pBufSize)
8314{
8315 int status;
8316 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8317
8318 ENTER();
8319
8320 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
8321
8322 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8323 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
8324 status = VOS_STATUS_E_FAILURE;
8325 }
8326 else {
8327 *pBufSize = pHddCtx->fw->size;
8328 hddLog(VOS_TRACE_LEVEL_INFO, "%s: CFG size = %d", __func__, *pBufSize);
8329 release_firmware(pHddCtx->fw);
8330 pHddCtx->fw = NULL;
8331 }
8332
8333 EXIT();
8334 return VOS_STATUS_SUCCESS;
8335}
8336
8337/**---------------------------------------------------------------------------
8338
8339 \brief hdd_read_cfg_file() -
8340
8341 This function reads the configuration file using the request firmware
8342 API and returns the cfg data and the buffer size of the configuration file.
8343
8344 \param - pCtx - Pointer to the adapter .
8345 - pFileName - Pointer to the file name.
8346 - pBuffer - Pointer to the data buffer.
8347 - pBufSize - Pointer to the buffer size.
8348
8349 \return - 0 for success, non zero for failure
8350
8351 --------------------------------------------------------------------------*/
8352
8353VOS_STATUS hdd_read_cfg_file(v_VOID_t *pCtx, char *pFileName,
8354 v_VOID_t *pBuffer, v_SIZE_t *pBufSize)
8355{
8356 int status;
8357 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8358
8359 ENTER();
8360
8361 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
8362
8363 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8364 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
8365 return VOS_STATUS_E_FAILURE;
8366 }
8367 else {
8368 if(*pBufSize != pHddCtx->fw->size) {
8369 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Caller sets invalid CFG "
8370 "file size", __func__);
8371 release_firmware(pHddCtx->fw);
8372 pHddCtx->fw = NULL;
8373 return VOS_STATUS_E_FAILURE;
8374 }
8375 else {
8376 if(pBuffer) {
8377 vos_mem_copy(pBuffer,pHddCtx->fw->data,*pBufSize);
8378 }
8379 release_firmware(pHddCtx->fw);
8380 pHddCtx->fw = NULL;
8381 }
8382 }
8383
8384 EXIT();
8385
8386 return VOS_STATUS_SUCCESS;
8387}
8388
8389/**---------------------------------------------------------------------------
8390
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308391 \brief __hdd_set_mac_address() -
Jeff Johnson295189b2012-06-20 16:38:30 -07008392
8393 This function sets the user specified mac address using
8394 the command ifconfig wlanX hw ether <mac adress>.
8395
8396 \param - dev - Pointer to the net device.
8397 - addr - Pointer to the sockaddr.
8398 \return - 0 for success, non zero for failure
8399
8400 --------------------------------------------------------------------------*/
8401
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308402static int __hdd_set_mac_address(struct net_device *dev, void *addr)
Jeff Johnson295189b2012-06-20 16:38:30 -07008403{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308404 hdd_adapter_t *pAdapter;
8405 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008406 struct sockaddr *psta_mac_addr = addr;
8407 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308408 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07008409
8410 ENTER();
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308411 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8412 if (NULL == pAdapter)
8413 {
8414 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8415 "%s: Adapter is NULL",__func__);
8416 return -EINVAL;
8417 }
8418 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8419 ret = wlan_hdd_validate_context(pHddCtx);
8420 if (0 != ret)
8421 {
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308422 return ret;
8423 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008424
8425 memcpy(&pAdapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008426 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
8427
8428 EXIT();
8429 return halStatus;
8430}
8431
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308432/**---------------------------------------------------------------------------
8433
8434 \brief hdd_set_mac_address() -
8435
8436 Wrapper function to protect __hdd_set_mac_address() function from ssr
8437
8438 \param - dev - Pointer to the net device.
8439 - addr - Pointer to the sockaddr.
8440 \return - 0 for success, non zero for failure
8441
8442 --------------------------------------------------------------------------*/
8443static int hdd_set_mac_address(struct net_device *dev, void *addr)
8444{
8445 int ret;
8446
8447 vos_ssr_protect(__func__);
8448 ret = __hdd_set_mac_address(dev, addr);
8449 vos_ssr_unprotect(__func__);
8450
8451 return ret;
8452}
8453
Jeff Johnson295189b2012-06-20 16:38:30 -07008454tANI_U8* wlan_hdd_get_intf_addr(hdd_context_t* pHddCtx)
8455{
8456 int i;
8457 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
8458 {
Abhishek Singheb183782014-02-06 13:37:21 +05308459 if( 0 == ((pHddCtx->cfg_ini->intfAddrMask) & (1 << i)) )
Jeff Johnson295189b2012-06-20 16:38:30 -07008460 break;
8461 }
8462
8463 if( VOS_MAX_CONCURRENCY_PERSONA == i)
8464 return NULL;
8465
8466 pHddCtx->cfg_ini->intfAddrMask |= (1 << i);
8467 return &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0];
8468}
8469
8470void wlan_hdd_release_intf_addr(hdd_context_t* pHddCtx, tANI_U8* releaseAddr)
8471{
8472 int i;
8473 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
8474 {
8475 if ( !memcmp(releaseAddr, &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], 6) )
8476 {
8477 pHddCtx->cfg_ini->intfAddrMask &= ~(1 << i);
8478 break;
8479 }
8480 }
8481 return;
8482}
8483
8484#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
8485 static struct net_device_ops wlan_drv_ops = {
8486 .ndo_open = hdd_open,
8487 .ndo_stop = hdd_stop,
8488 .ndo_uninit = hdd_uninit,
8489 .ndo_start_xmit = hdd_hard_start_xmit,
8490 .ndo_tx_timeout = hdd_tx_timeout,
8491 .ndo_get_stats = hdd_stats,
8492 .ndo_do_ioctl = hdd_ioctl,
8493 .ndo_set_mac_address = hdd_set_mac_address,
8494 .ndo_select_queue = hdd_select_queue,
8495#ifdef WLAN_FEATURE_PACKET_FILTERING
8496#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0))
8497 .ndo_set_rx_mode = hdd_set_multicast_list,
8498#else
8499 .ndo_set_multicast_list = hdd_set_multicast_list,
8500#endif //LINUX_VERSION_CODE
8501#endif
8502 };
Jeff Johnson295189b2012-06-20 16:38:30 -07008503 static struct net_device_ops wlan_mon_drv_ops = {
8504 .ndo_open = hdd_mon_open,
Katya Nigame7b69a82015-04-28 15:24:06 +05308505 .ndo_stop = hdd_mon_stop,
Jeff Johnson295189b2012-06-20 16:38:30 -07008506 .ndo_uninit = hdd_uninit,
8507 .ndo_start_xmit = hdd_mon_hard_start_xmit,
8508 .ndo_tx_timeout = hdd_tx_timeout,
8509 .ndo_get_stats = hdd_stats,
Katya Nigame7b69a82015-04-28 15:24:06 +05308510 .ndo_do_ioctl = hdd_mon_ioctl,
Jeff Johnson295189b2012-06-20 16:38:30 -07008511 .ndo_set_mac_address = hdd_set_mac_address,
8512 };
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +05308513
Jeff Johnson295189b2012-06-20 16:38:30 -07008514#endif
8515
8516void hdd_set_station_ops( struct net_device *pWlanDev )
8517{
8518#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
Jeff Johnson295189b2012-06-20 16:38:30 -07008519 pWlanDev->netdev_ops = &wlan_drv_ops;
8520#else
8521 pWlanDev->open = hdd_open;
8522 pWlanDev->stop = hdd_stop;
8523 pWlanDev->uninit = hdd_uninit;
8524 pWlanDev->hard_start_xmit = NULL;
8525 pWlanDev->tx_timeout = hdd_tx_timeout;
8526 pWlanDev->get_stats = hdd_stats;
8527 pWlanDev->do_ioctl = hdd_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07008528 pWlanDev->set_mac_address = hdd_set_mac_address;
8529#endif
8530}
8531
Katya Nigam1fd24402015-02-16 14:52:19 +05308532void hdd_set_ibss_ops( hdd_adapter_t *pAdapter )
8533{
8534 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
8535 wlan_drv_ops.ndo_start_xmit = hdd_ibss_hard_start_xmit;
8536 #else
8537 pAdapter->dev->hard_start_xmit = hdd_ibss_hard_start_xmit;
8538 #endif
8539}
8540
Jeff Johnsoneed415b2013-01-18 16:11:20 -08008541static hdd_adapter_t* hdd_alloc_station_adapter( hdd_context_t *pHddCtx, tSirMacAddr macAddr, const char* name )
Jeff Johnson295189b2012-06-20 16:38:30 -07008542{
8543 struct net_device *pWlanDev = NULL;
8544 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008545 /*
8546 * cfg80211 initialization and registration....
8547 */
Anand N Sunkadc34abbd2015-07-29 09:52:59 +05308548 pWlanDev = alloc_netdev_mq(sizeof( hdd_adapter_t ), name,
8549#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0))
8550 NET_NAME_UNKNOWN,
8551#endif
8552 ether_setup, NUM_TX_QUEUES);
Jeff Johnson295189b2012-06-20 16:38:30 -07008553 if(pWlanDev != NULL)
8554 {
8555
8556 //Save the pointer to the net_device in the HDD adapter
8557 pAdapter = (hdd_adapter_t*) netdev_priv( pWlanDev );
8558
Jeff Johnson295189b2012-06-20 16:38:30 -07008559 vos_mem_zero( pAdapter, sizeof( hdd_adapter_t ) );
8560
8561 pAdapter->dev = pWlanDev;
8562 pAdapter->pHddCtx = pHddCtx;
8563 pAdapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Agarwal Ashish47d18112014-08-04 19:55:07 +05308564 spin_lock_init(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -07008565
Rajeev79dbe4c2013-10-05 11:03:42 +05308566#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev79dbe4c2013-10-05 11:03:42 +05308567 pAdapter->pBatchScanRsp = NULL;
8568 pAdapter->numScanList = 0;
Rajeev Kumar20140c12013-10-21 19:39:02 -07008569 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08008570 pAdapter->prev_batch_id = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05308571 mutex_init(&pAdapter->hdd_batch_scan_lock);
8572#endif
8573
Jeff Johnson295189b2012-06-20 16:38:30 -07008574 pAdapter->isLinkUpSvcNeeded = FALSE;
8575 pAdapter->higherDtimTransition = eANI_BOOLEAN_TRUE;
8576 //Init the net_device structure
8577 strlcpy(pWlanDev->name, name, IFNAMSIZ);
8578
8579 vos_mem_copy(pWlanDev->dev_addr, (void *)macAddr, sizeof(tSirMacAddr));
8580 vos_mem_copy( pAdapter->macAddressCurrent.bytes, macAddr, sizeof(tSirMacAddr));
8581 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
8582 pWlanDev->hard_header_len += LIBRA_HW_NEEDED_HEADROOM;
8583
8584 hdd_set_station_ops( pAdapter->dev );
8585
8586 pWlanDev->destructor = free_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -07008587 pWlanDev->ieee80211_ptr = &pAdapter->wdev ;
8588 pAdapter->wdev.wiphy = pHddCtx->wiphy;
8589 pAdapter->wdev.netdev = pWlanDev;
Jeff Johnson295189b2012-06-20 16:38:30 -07008590 /* set pWlanDev's parent to underlying device */
8591 SET_NETDEV_DEV(pWlanDev, pHddCtx->parent_dev);
Kumar Anand82c009f2014-05-29 00:29:42 -07008592
8593 hdd_wmm_init( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07008594 }
8595
8596 return pAdapter;
8597}
8598
8599VOS_STATUS hdd_register_interface( hdd_adapter_t *pAdapter, tANI_U8 rtnl_lock_held )
8600{
8601 struct net_device *pWlanDev = pAdapter->dev;
8602 //hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
8603 //hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
8604 //eHalStatus halStatus = eHAL_STATUS_SUCCESS;
8605
8606 if( rtnl_lock_held )
8607 {
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -08008608 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
Jeff Johnson295189b2012-06-20 16:38:30 -07008609 if( dev_alloc_name(pWlanDev, pWlanDev->name) < 0 )
8610 {
8611 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:dev_alloc_name",__func__);
8612 return VOS_STATUS_E_FAILURE;
8613 }
8614 }
8615 if (register_netdevice(pWlanDev))
8616 {
8617 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:register_netdev",__func__);
8618 return VOS_STATUS_E_FAILURE;
8619 }
8620 }
8621 else
8622 {
8623 if(register_netdev(pWlanDev))
8624 {
8625 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed:register_netdev",__func__);
8626 return VOS_STATUS_E_FAILURE;
8627 }
8628 }
8629 set_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags);
8630
8631 return VOS_STATUS_SUCCESS;
8632}
8633
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008634static eHalStatus hdd_smeCloseSessionCallback(void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07008635{
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008636 hdd_adapter_t *pAdapter = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07008637
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008638 if (NULL == pAdapter)
8639 {
8640 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: NULL pAdapter", __func__);
8641 return eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07008642 }
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008643
8644 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
8645 {
8646 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Invalid magic", __func__);
8647 return eHAL_STATUS_NOT_INITIALIZED;
8648 }
8649
8650 clear_bit(SME_SESSION_OPENED, &pAdapter->event_flags);
8651
Sameer Thalappilbee426e2013-10-30 10:30:30 -07008652#ifndef WLAN_OPEN_SOURCE
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008653 /* need to make sure all of our scheduled work has completed.
8654 * This callback is called from MC thread context, so it is safe to
8655 * to call below flush workqueue API from here.
Sameer Thalappilbee426e2013-10-30 10:30:30 -07008656 *
8657 * Even though this is called from MC thread context, if there is a faulty
8658 * work item in the system, that can hang this call forever. So flushing
8659 * this global work queue is not safe; and now we make sure that
8660 * individual work queues are stopped correctly. But the cancel work queue
8661 * is a GPL only API, so the proprietary version of the driver would still
8662 * rely on the global work queue flush.
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008663 */
8664 flush_scheduled_work();
Sameer Thalappilbee426e2013-10-30 10:30:30 -07008665#endif
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008666
8667 /* We can be blocked while waiting for scheduled work to be
8668 * flushed, and the adapter structure can potentially be freed, in
8669 * which case the magic will have been reset. So make sure the
8670 * magic is still good, and hence the adapter structure is still
8671 * valid, before signaling completion */
8672 if (WLAN_HDD_ADAPTER_MAGIC == pAdapter->magic)
8673 {
8674 complete(&pAdapter->session_close_comp_var);
8675 }
8676
Jeff Johnson295189b2012-06-20 16:38:30 -07008677 return eHAL_STATUS_SUCCESS;
8678}
Manjeet Singh47ee8472016-04-11 11:57:18 +05308679/**
8680 * hdd_close_tx_queues() - close tx queues
8681 * @hdd_ctx: hdd global context
8682 *
8683 * Return: None
8684 */
8685static void hdd_close_tx_queues(hdd_context_t *hdd_ctx)
8686{
8687 VOS_STATUS status;
8688 hdd_adapter_t *adapter;
8689 hdd_adapter_list_node_t *adapter_node = NULL, *next_adapter = NULL;
8690 /* Not validating hdd_ctx as it's already done by the caller */
8691 ENTER();
8692 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
8693 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status) {
8694 adapter = adapter_node->pAdapter;
8695 if (adapter && adapter->dev) {
8696 netif_tx_disable (adapter->dev);
8697 netif_carrier_off(adapter->dev);
8698 }
8699 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
8700 &next_adapter);
8701 adapter_node = next_adapter;
8702 }
8703 EXIT();
8704}
Jeff Johnson295189b2012-06-20 16:38:30 -07008705
8706VOS_STATUS hdd_init_station_mode( hdd_adapter_t *pAdapter )
8707{
8708 struct net_device *pWlanDev = pAdapter->dev;
8709 hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
8710 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
8711 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
8712 VOS_STATUS status = VOS_STATUS_E_FAILURE;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308713 long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07008714
Nirav Shah7e3c8132015-06-22 23:51:42 +05308715 spin_lock_init( &pAdapter->sta_hash_lock);
8716 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
8717
Jeff Johnson295189b2012-06-20 16:38:30 -07008718 INIT_COMPLETION(pAdapter->session_open_comp_var);
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07008719 sme_SetCurrDeviceMode(pHddCtx->hHal, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07008720 //Open a SME session for future operation
8721 halStatus = sme_OpenSession( pHddCtx->hHal, hdd_smeRoamCallback, pAdapter,
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07008722 (tANI_U8 *)&pAdapter->macAddressCurrent, &pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07008723 if ( !HAL_STATUS_SUCCESS( halStatus ) )
8724 {
8725 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008726 "sme_OpenSession() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07008727 halStatus, halStatus );
8728 status = VOS_STATUS_E_FAILURE;
8729 goto error_sme_open;
8730 }
8731
8732 //Block on a completion variable. Can't wait forever though.
Vinay Krishna Eranna0fe2e7c2014-04-09 21:32:08 +05308733 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07008734 &pAdapter->session_open_comp_var,
8735 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308736 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07008737 {
8738 hddLog(VOS_TRACE_LEVEL_FATAL,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308739 "Session is not opened within timeout period code %ld", rc );
Jeff Johnson295189b2012-06-20 16:38:30 -07008740 status = VOS_STATUS_E_FAILURE;
8741 goto error_sme_open;
8742 }
8743
8744 // Register wireless extensions
8745 if( eHAL_STATUS_SUCCESS != (halStatus = hdd_register_wext(pWlanDev)))
8746 {
8747 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008748 "hdd_register_wext() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07008749 halStatus, halStatus );
8750 status = VOS_STATUS_E_FAILURE;
8751 goto error_register_wext;
8752 }
Katya Nigam1fd24402015-02-16 14:52:19 +05308753
Jeff Johnson295189b2012-06-20 16:38:30 -07008754 //Safe to register the hard_start_xmit function again
Katya Nigam1fd24402015-02-16 14:52:19 +05308755 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
8756 wlan_drv_ops.ndo_start_xmit = hdd_hard_start_xmit;
8757 #else
8758 pWlanDev->hard_start_xmit = hdd_hard_start_xmit;
8759 #endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008760
8761 //Set the Connection State to Not Connected
Abhishek Singhf4669da2014-05-26 15:07:49 +05308762 hddLog(VOS_TRACE_LEVEL_INFO,
8763 "%s: Set HDD connState to eConnectionState_NotConnected",
8764 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008765 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
8766
8767 //Set the default operation channel
8768 pHddStaCtx->conn_info.operationChannel = pHddCtx->cfg_ini->OperatingChannel;
8769
8770 /* Make the default Auth Type as OPEN*/
8771 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
8772
8773 if( VOS_STATUS_SUCCESS != ( status = hdd_init_tx_rx( pAdapter ) ) )
8774 {
8775 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008776 "hdd_init_tx_rx() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07008777 status, status );
8778 goto error_init_txrx;
8779 }
8780
8781 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
8782
8783 if( VOS_STATUS_SUCCESS != ( status = hdd_wmm_adapter_init( pAdapter ) ) )
8784 {
8785 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008786 "hdd_wmm_adapter_init() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07008787 status, status );
8788 goto error_wmm_init;
8789 }
8790
8791 set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
8792
8793 return VOS_STATUS_SUCCESS;
8794
8795error_wmm_init:
8796 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
8797 hdd_deinit_tx_rx(pAdapter);
8798error_init_txrx:
8799 hdd_UnregisterWext(pWlanDev);
8800error_register_wext:
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008801 if (test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07008802 {
8803 INIT_COMPLETION(pAdapter->session_close_comp_var);
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008804 if (eHAL_STATUS_SUCCESS == sme_CloseSession(pHddCtx->hHal,
Agrawal Ashish5a3522c2016-03-02 15:08:28 +05308805 pAdapter->sessionId, FALSE, VOS_TRUE,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008806 hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07008807 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308808 unsigned long rc;
8809
Jeff Johnson295189b2012-06-20 16:38:30 -07008810 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308811 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07008812 &pAdapter->session_close_comp_var,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07008813 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308814 if (rc <= 0)
8815 hddLog(VOS_TRACE_LEVEL_ERROR,
8816 FL("Session is not opened within timeout period code %ld"), rc);
Jeff Johnson295189b2012-06-20 16:38:30 -07008817 }
8818}
8819error_sme_open:
8820 return status;
8821}
8822
Jeff Johnson295189b2012-06-20 16:38:30 -07008823void hdd_cleanup_actionframe( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
8824{
8825 hdd_cfg80211_state_t *cfgState;
8826
8827 cfgState = WLAN_HDD_GET_CFG_STATE_PTR( pAdapter );
8828
8829 if( NULL != cfgState->buf )
8830 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308831 long rc;
Jeff Johnson295189b2012-06-20 16:38:30 -07008832 INIT_COMPLETION(pAdapter->tx_action_cnf_event);
8833 rc = wait_for_completion_interruptible_timeout(
8834 &pAdapter->tx_action_cnf_event,
8835 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308836 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07008837 {
Deepthi Gowri91b3e9c2015-08-25 13:14:58 +05308838 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8839 "%s ERROR: HDD Wait for Action Confirmation Failed!! %ld"
8840 , __func__, rc);
8841
8842 // Inform tx status as FAILURE to upper layer and free cfgState->buf
8843 hdd_sendActionCnf( pAdapter, FALSE );
Jeff Johnson295189b2012-06-20 16:38:30 -07008844 }
8845 }
8846 return;
8847}
Jeff Johnson295189b2012-06-20 16:38:30 -07008848
c_hpothu002231a2015-02-05 14:58:51 +05308849void hdd_deinit_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
Jeff Johnson295189b2012-06-20 16:38:30 -07008850{
8851 ENTER();
8852 switch ( pAdapter->device_mode )
8853 {
Katya Nigam1fd24402015-02-16 14:52:19 +05308854 case WLAN_HDD_IBSS:
8855 {
8856 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
8857 {
8858 hdd_ibss_deinit_tx_rx( pAdapter );
8859 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
8860 }
8861 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008862 case WLAN_HDD_INFRA_STATION:
8863 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07008864 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07008865 {
8866 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
8867 {
8868 hdd_deinit_tx_rx( pAdapter );
8869 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
8870 }
8871
8872 if(test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
8873 {
8874 hdd_wmm_adapter_close( pAdapter );
8875 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
8876 }
8877
Jeff Johnson295189b2012-06-20 16:38:30 -07008878 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07008879 break;
8880 }
8881
8882 case WLAN_HDD_SOFTAP:
8883 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07008884 {
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05308885
8886 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
8887 {
8888 hdd_wmm_adapter_close( pAdapter );
8889 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
8890 }
8891
Jeff Johnson295189b2012-06-20 16:38:30 -07008892 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07008893
c_hpothu002231a2015-02-05 14:58:51 +05308894 hdd_unregister_hostapd(pAdapter, rtnl_held);
Agrawal Ashisha0584d42016-09-29 13:03:45 +05308895 /* set con_mode to STA only when no SAP concurrency mode */
8896 if (!(hdd_get_concurrency_mode() & (VOS_SAP | VOS_P2P_GO)))
8897 hdd_set_conparam(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008898 break;
8899 }
8900
8901 case WLAN_HDD_MONITOR:
8902 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008903 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
8904 {
8905 hdd_deinit_tx_rx( pAdapter );
8906 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
8907 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008908 break;
8909 }
8910
8911
8912 default:
8913 break;
8914 }
8915
8916 EXIT();
8917}
8918
8919void hdd_cleanup_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
8920{
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08008921 struct net_device *pWlanDev = NULL;
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05308922
8923 ENTER();
8924 if (NULL == pAdapter)
8925 {
8926 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8927 "%s: HDD adapter is Null", __func__);
8928 return;
8929 }
8930
8931 pWlanDev = pAdapter->dev;
Jeff Johnson295189b2012-06-20 16:38:30 -07008932
Rajeev79dbe4c2013-10-05 11:03:42 +05308933#ifdef FEATURE_WLAN_BATCH_SCAN
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05308934 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
8935 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Rajeev Kumarf999e582014-01-09 17:33:29 -08008936 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05308937 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
8938 )
8939 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08008940 if (pAdapter)
Rajeev79dbe4c2013-10-05 11:03:42 +05308941 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08008942 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
8943 {
8944 hdd_deinit_batch_scan(pAdapter);
8945 }
Rajeev79dbe4c2013-10-05 11:03:42 +05308946 }
Rajeev Kumarf999e582014-01-09 17:33:29 -08008947 }
Rajeev79dbe4c2013-10-05 11:03:42 +05308948#endif
8949
Jeff Johnson295189b2012-06-20 16:38:30 -07008950 if(test_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags)) {
8951 if( rtnl_held )
8952 {
8953 unregister_netdevice(pWlanDev);
8954 }
8955 else
8956 {
8957 unregister_netdev(pWlanDev);
8958 }
8959 // note that the pAdapter is no longer valid at this point
8960 // since the memory has been reclaimed
8961 }
8962
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05308963 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07008964}
8965
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008966void hdd_set_pwrparams(hdd_context_t *pHddCtx)
8967{
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308968 VOS_STATUS status;
8969 hdd_adapter_t *pAdapter = NULL;
8970 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008971
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308972 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008973
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308974 /*loop through all adapters.*/
8975 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008976 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308977 pAdapter = pAdapterNode->pAdapter;
8978 if ( (WLAN_HDD_INFRA_STATION != pAdapter->device_mode)
8979 && (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008980
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308981 { // we skip this registration for modes other than STA and P2P client modes.
8982 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8983 pAdapterNode = pNext;
8984 continue;
8985 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008986
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308987 //Apply Dynamic DTIM For P2P
8988 //Only if ignoreDynamicDtimInP2pMode is not set in ini
8989 if ((pHddCtx->cfg_ini->enableDynamicDTIM ||
8990 pHddCtx->cfg_ini->enableModulatedDTIM) &&
8991 ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
8992 ((WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) &&
8993 !(pHddCtx->cfg_ini->ignoreDynamicDtimInP2pMode))) &&
8994 (eANI_BOOLEAN_TRUE == pAdapter->higherDtimTransition) &&
8995 (eConnectionState_Associated ==
8996 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState) &&
8997 (pHddCtx->cfg_ini->fIsBmpsEnabled))
8998 {
8999 tSirSetPowerParamsReq powerRequest = { 0 };
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009000
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309001 powerRequest.uIgnoreDTIM = 1;
9002 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
9003
9004 if (pHddCtx->cfg_ini->enableModulatedDTIM)
9005 {
9006 powerRequest.uDTIMPeriod = pHddCtx->cfg_ini->enableModulatedDTIM;
9007 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
9008 }
9009 else
9010 {
9011 powerRequest.uListenInterval = pHddCtx->cfg_ini->enableDynamicDTIM;
9012 }
9013
9014 /* Update ignoreDTIM and ListedInterval in CFG to remain at the DTIM
9015 * specified during Enter/Exit BMPS when LCD off*/
9016 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
9017 NULL, eANI_BOOLEAN_FALSE);
9018 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
9019 NULL, eANI_BOOLEAN_FALSE);
9020
9021 /* switch to the DTIM specified in cfg.ini */
9022 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Abhishek Singh1e390cf2015-10-27 13:45:17 +05309023 "Switch to DTIM %d Listen interval %d",
9024 powerRequest.uDTIMPeriod,
9025 powerRequest.uListenInterval);
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309026 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
9027 break;
9028
9029 }
9030
9031 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9032 pAdapterNode = pNext;
9033 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009034}
9035
9036void hdd_reset_pwrparams(hdd_context_t *pHddCtx)
9037{
9038 /*Switch back to DTIM 1*/
9039 tSirSetPowerParamsReq powerRequest = { 0 };
9040
9041 powerRequest.uIgnoreDTIM = pHddCtx->hdd_actual_ignore_DTIM_value;
9042 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
Yue Mac24062f2013-05-13 17:01:29 -07009043 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009044
9045 /* Update ignoreDTIM and ListedInterval in CFG with default values */
9046 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
9047 NULL, eANI_BOOLEAN_FALSE);
9048 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
9049 NULL, eANI_BOOLEAN_FALSE);
9050
9051 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9052 "Switch to DTIM%d",powerRequest.uListenInterval);
9053 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
9054
9055}
9056
Jeff Johnson295189b2012-06-20 16:38:30 -07009057VOS_STATUS hdd_enable_bmps_imps(hdd_context_t *pHddCtx)
9058{
9059 VOS_STATUS status = VOS_STATUS_SUCCESS;
Sushant Kaushik4928e542014-12-29 15:25:54 +05309060 if (WLAN_HDD_IS_UNLOAD_IN_PROGRESS(pHddCtx))
9061 {
9062 hddLog( LOGE, FL("Wlan Unload in progress"));
9063 return VOS_STATUS_E_PERM;
9064 }
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309065
9066 if (wlan_hdd_check_monitor_state(pHddCtx)) {
9067 hddLog(LOG1, FL("Monitor mode is started, cannot enable BMPS"));
9068 return VOS_STATUS_SUCCESS;
9069 }
9070
Jeff Johnson295189b2012-06-20 16:38:30 -07009071 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
9072 {
9073 sme_EnablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
9074 }
9075
9076 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
9077 {
9078 sme_StartAutoBmpsTimer(pHddCtx->hHal);
9079 }
9080
9081 if (pHddCtx->cfg_ini->fIsImpsEnabled)
9082 {
9083 sme_EnablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
9084 }
9085
9086 return status;
9087}
9088
9089VOS_STATUS hdd_disable_bmps_imps(hdd_context_t *pHddCtx, tANI_U8 session_type)
9090{
9091 hdd_adapter_t *pAdapter = NULL;
9092 eHalStatus halStatus;
9093 VOS_STATUS status = VOS_STATUS_E_INVAL;
9094 v_BOOL_t disableBmps = FALSE;
9095 v_BOOL_t disableImps = FALSE;
9096
9097 switch(session_type)
9098 {
9099 case WLAN_HDD_INFRA_STATION:
9100 case WLAN_HDD_SOFTAP:
Jeff Johnson295189b2012-06-20 16:38:30 -07009101 case WLAN_HDD_P2P_CLIENT:
9102 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009103 //Exit BMPS -> Is Sta/P2P Client is already connected
9104 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
9105 if((NULL != pAdapter)&&
9106 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
9107 {
9108 disableBmps = TRUE;
9109 }
9110
9111 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_CLIENT);
9112 if((NULL != pAdapter)&&
9113 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
9114 {
9115 disableBmps = TRUE;
9116 }
9117
9118 //Exit both Bmps and Imps incase of Go/SAP Mode
9119 if((WLAN_HDD_SOFTAP == session_type) ||
9120 (WLAN_HDD_P2P_GO == session_type))
9121 {
9122 disableBmps = TRUE;
9123 disableImps = TRUE;
9124 }
9125
9126 if(TRUE == disableImps)
9127 {
9128 if (pHddCtx->cfg_ini->fIsImpsEnabled)
9129 {
9130 sme_DisablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
9131 }
9132 }
9133
9134 if(TRUE == disableBmps)
9135 {
9136 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
9137 {
9138 halStatus = sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
9139
9140 if(eHAL_STATUS_SUCCESS != halStatus)
9141 {
9142 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009143 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Disable Power Save", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009144 VOS_ASSERT(0);
9145 return status;
9146 }
9147 }
9148
9149 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
9150 {
9151 halStatus = sme_StopAutoBmpsTimer(pHddCtx->hHal);
9152
9153 if(eHAL_STATUS_SUCCESS != halStatus)
9154 {
9155 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009156 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Stop Auto Bmps Timer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009157 VOS_ASSERT(0);
9158 return status;
9159 }
9160 }
9161 }
9162
9163 if((TRUE == disableBmps) ||
9164 (TRUE == disableImps))
9165 {
9166 /* Now, get the chip into Full Power now */
9167 INIT_COMPLETION(pHddCtx->full_pwr_comp_var);
9168 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_pwr_cbk,
9169 pHddCtx, eSME_FULL_PWR_NEEDED_BY_HDD);
9170
9171 if(halStatus != eHAL_STATUS_SUCCESS)
9172 {
9173 if(halStatus == eHAL_STATUS_PMC_PENDING)
9174 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309175 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07009176 //Block on a completion variable. Can't wait forever though
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309177 ret = wait_for_completion_interruptible_timeout(
9178 &pHddCtx->full_pwr_comp_var,
9179 msecs_to_jiffies(1000));
9180 if (ret <= 0)
9181 {
9182 hddLog(VOS_TRACE_LEVEL_ERROR,
9183 "%s: wait on full_pwr_comp_var failed %ld",
9184 __func__, ret);
9185 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009186 }
9187 else
9188 {
9189 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009190 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Request for Full Power failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009191 VOS_ASSERT(0);
9192 return status;
9193 }
9194 }
9195
9196 status = VOS_STATUS_SUCCESS;
9197 }
9198
9199 break;
9200 }
9201 return status;
9202}
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309203
9204void hdd_monPostMsgCb(tANI_U32 *magic, struct completion *cmpVar)
9205{
9206 if (magic == NULL || cmpVar == NULL) {
9207 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07009208 FL("invalid arguments %pK %pK"), magic, cmpVar);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309209 return;
9210 }
9211 if (*magic != MON_MODE_MSG_MAGIC) {
9212 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9213 FL("maic: %x"), *magic);
9214 return;
9215 }
9216
9217 complete(cmpVar);
9218 return;
9219}
9220
Katya Nigame7b69a82015-04-28 15:24:06 +05309221void hdd_init_mon_mode (hdd_adapter_t *pAdapter)
9222 {
9223 hdd_mon_ctx_t *pMonCtx = NULL;
9224 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
9225
9226 pMonCtx->state = 0;
9227 pMonCtx->ChannelNo = 1;
9228 pMonCtx->ChannelBW = 20;
Katya Nigamd7d3a1f2015-06-11 14:04:24 +05309229 pMonCtx->crcCheckEnabled = 1;
9230 pMonCtx->typeSubtypeBitmap = 0xFFFF00000000;
9231 pMonCtx->is80211to803ConReq = 1;
Katya Nigame7b69a82015-04-28 15:24:06 +05309232 pMonCtx->numOfMacFilters = 0;
9233 }
9234
Jeff Johnson295189b2012-06-20 16:38:30 -07009235
9236hdd_adapter_t* hdd_open_adapter( hdd_context_t *pHddCtx, tANI_U8 session_type,
Jeff Johnsoneed415b2013-01-18 16:11:20 -08009237 const char *iface_name, tSirMacAddr macAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -07009238 tANI_U8 rtnl_held )
9239{
9240 hdd_adapter_t *pAdapter = NULL;
9241 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
9242 VOS_STATUS status = VOS_STATUS_E_FAILURE;
9243 VOS_STATUS exitbmpsStatus;
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309244 v_CONTEXT_t pVosContext = NULL;
9245
9246 /* No need to check for NULL, reaching this step
9247 * means vos context is initialized
9248 */
9249 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
Jeff Johnson295189b2012-06-20 16:38:30 -07009250
Arif Hussain6d2a3322013-11-17 19:50:10 -08009251 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s iface =%s type = %d",__func__,iface_name,session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009252
Nirav Shah436658f2014-02-28 17:05:45 +05309253 if(macAddr == NULL)
9254 {
9255 /* Not received valid macAddr */
9256 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9257 "%s:Unable to add virtual intf: Not able to get"
9258 "valid mac address",__func__);
9259 return NULL;
9260 }
9261
Jeff Johnson295189b2012-06-20 16:38:30 -07009262 //Disable BMPS incase of Concurrency
9263 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, session_type);
9264
9265 if(VOS_STATUS_E_FAILURE == exitbmpsStatus)
9266 {
9267 //Fail to Exit BMPS
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309268 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Exit BMPS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009269 VOS_ASSERT(0);
9270 return NULL;
9271 }
9272
9273 switch(session_type)
9274 {
9275 case WLAN_HDD_INFRA_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07009276 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009277 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07009278 {
9279 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9280
9281 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309282 {
9283 hddLog(VOS_TRACE_LEVEL_FATAL,
9284 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009285 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309286 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009287
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309288#ifdef FEATURE_WLAN_TDLS
9289 /* A Mutex Lock is introduced while changing/initializing the mode to
9290 * protect the concurrent access for the Adapters by TDLS module.
9291 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05309292 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309293#endif
9294
Jeff Johnsone7245742012-09-05 17:12:55 -07009295 pAdapter->wdev.iftype = (session_type == WLAN_HDD_P2P_CLIENT) ?
9296 NL80211_IFTYPE_P2P_CLIENT:
9297 NL80211_IFTYPE_STATION;
Jeff Johnson295189b2012-06-20 16:38:30 -07009298
Jeff Johnson295189b2012-06-20 16:38:30 -07009299 pAdapter->device_mode = session_type;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309300#ifdef FEATURE_WLAN_TDLS
9301 mutex_unlock(&pHddCtx->tdls_lock);
9302#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05309303
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309304 hdd_initialize_adapter_common(pAdapter);
Sunil Dutt66485cb2013-12-19 19:05:03 +05309305 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07009306 if( VOS_STATUS_SUCCESS != status )
9307 goto err_free_netdev;
9308
9309 status = hdd_register_interface( pAdapter, rtnl_held );
9310 if( VOS_STATUS_SUCCESS != status )
9311 {
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05309312#ifdef FEATURE_WLAN_TDLS
9313 mutex_lock(&pHddCtx->tdls_lock);
9314#endif
c_hpothu002231a2015-02-05 14:58:51 +05309315 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05309316#ifdef FEATURE_WLAN_TDLS
9317 mutex_unlock(&pHddCtx->tdls_lock);
9318#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009319 goto err_free_netdev;
9320 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309321
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05309322 // Workqueue which gets scheduled in IPv4 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309323 vos_init_work(&pAdapter->ipv4NotifierWorkQueue, hdd_ipv4_notifier_work_queue);
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05309324
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309325#ifdef WLAN_NS_OFFLOAD
9326 // Workqueue which gets scheduled in IPv6 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309327 vos_init_work(&pAdapter->ipv6NotifierWorkQueue, hdd_ipv6_notifier_work_queue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309328#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009329 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309330 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009331 netif_tx_disable(pAdapter->dev);
9332 //netif_tx_disable(pWlanDev);
9333 netif_carrier_off(pAdapter->dev);
9334
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309335 if (WLAN_HDD_P2P_CLIENT == session_type ||
9336 WLAN_HDD_P2P_DEVICE == session_type)
9337 {
9338 /* Initialize the work queue to defer the
9339 * back to back RoC request */
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309340 vos_init_delayed_work(&pAdapter->roc_work,
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309341 hdd_p2p_roc_work_queue);
9342 }
9343
Jeff Johnson295189b2012-06-20 16:38:30 -07009344 break;
9345 }
9346
Jeff Johnson295189b2012-06-20 16:38:30 -07009347 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009348 case WLAN_HDD_SOFTAP:
9349 {
9350 pAdapter = hdd_wlan_create_ap_dev( pHddCtx, macAddr, (tANI_U8 *)iface_name );
9351 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309352 {
9353 hddLog(VOS_TRACE_LEVEL_FATAL,
9354 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009355 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309356 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009357
Jeff Johnson295189b2012-06-20 16:38:30 -07009358 pAdapter->wdev.iftype = (session_type == WLAN_HDD_SOFTAP) ?
9359 NL80211_IFTYPE_AP:
9360 NL80211_IFTYPE_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07009361 pAdapter->device_mode = session_type;
9362
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309363 hdd_initialize_adapter_common(pAdapter);
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +05309364 status = hdd_init_ap_mode(pAdapter, false);
Jeff Johnson295189b2012-06-20 16:38:30 -07009365 if( VOS_STATUS_SUCCESS != status )
9366 goto err_free_netdev;
9367
Nirav Shah7e3c8132015-06-22 23:51:42 +05309368 status = hdd_sta_id_hash_attach(pAdapter);
9369 if (VOS_STATUS_SUCCESS != status)
9370 {
9371 hddLog(VOS_TRACE_LEVEL_FATAL,
9372 FL("failed to attach hash for session %d"), session_type);
9373 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
9374 goto err_free_netdev;
9375 }
9376
Jeff Johnson295189b2012-06-20 16:38:30 -07009377 status = hdd_register_hostapd( pAdapter, rtnl_held );
9378 if( VOS_STATUS_SUCCESS != status )
9379 {
c_hpothu002231a2015-02-05 14:58:51 +05309380 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Jeff Johnson295189b2012-06-20 16:38:30 -07009381 goto err_free_netdev;
9382 }
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309383 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009384 netif_tx_disable(pAdapter->dev);
9385 netif_carrier_off(pAdapter->dev);
9386
9387 hdd_set_conparam( 1 );
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309388
Hanumanth Reddy Pothulab4537b82018-03-02 12:20:38 +05309389 // Workqueue which gets scheduled in IPv4 notification callback.
9390 vos_init_work(&pAdapter->ipv4NotifierWorkQueue,
9391 hdd_ipv4_notifier_work_queue);
9392
9393#ifdef WLAN_NS_OFFLOAD
9394 // Workqueue which gets scheduled in IPv6 notification callback.
9395 vos_init_work(&pAdapter->ipv6NotifierWorkQueue,
9396 hdd_ipv6_notifier_work_queue);
9397#endif
9398
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309399 if (WLAN_HDD_P2P_GO == session_type)
9400 {
9401 /* Initialize the work queue to
9402 * defer the back to back RoC request */
9403 INIT_DELAYED_WORK(&pAdapter->roc_work,
9404 hdd_p2p_roc_work_queue);
9405 }
Bhargav Shahd0715912015-10-01 18:17:37 +05309406
Jeff Johnson295189b2012-06-20 16:38:30 -07009407 break;
9408 }
9409 case WLAN_HDD_MONITOR:
9410 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009411 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9412 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309413 {
9414 hddLog(VOS_TRACE_LEVEL_FATAL,
9415 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009416 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309417 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009418
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309419 pAdapter->device_mode = session_type;
9420 pAdapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
9421
Katya Nigame7b69a82015-04-28 15:24:06 +05309422 // Register wireless extensions
9423 if( VOS_STATUS_SUCCESS != (status = hdd_register_wext(pAdapter->dev)))
9424 {
9425 hddLog(VOS_TRACE_LEVEL_FATAL,
9426 "hdd_register_wext() failed with status code %08d [x%08x]",
9427 status, status );
9428 status = VOS_STATUS_E_FAILURE;
9429 }
9430
Jeff Johnson295189b2012-06-20 16:38:30 -07009431#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29)
9432 pAdapter->dev->netdev_ops = &wlan_mon_drv_ops;
9433#else
9434 pAdapter->dev->open = hdd_mon_open;
9435 pAdapter->dev->hard_start_xmit = hdd_mon_hard_start_xmit;
Katya Nigame7b69a82015-04-28 15:24:06 +05309436 pAdapter->dev->stop = hdd_mon_stop;
9437 pAdapter->dev->do_ioctl = hdd_mon_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07009438#endif
Katya Nigame7b69a82015-04-28 15:24:06 +05309439 hdd_init_mon_mode( pAdapter );
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309440 hdd_initialize_adapter_common(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009441 hdd_init_tx_rx( pAdapter );
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309442
9443 if (VOS_MONITOR_MODE != hdd_get_conparam())
9444 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
9445
Jeff Johnson295189b2012-06-20 16:38:30 -07009446 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309447 status = hdd_register_interface( pAdapter, rtnl_held );
Katya Nigame7b69a82015-04-28 15:24:06 +05309448 //Stop the Interface TX queue.
9449 netif_tx_disable(pAdapter->dev);
9450 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07009451 }
9452 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07009453 case WLAN_HDD_FTM:
9454 {
9455 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9456
9457 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309458 {
9459 hddLog(VOS_TRACE_LEVEL_FATAL,
9460 FL("failed to allocate adapter for session %d"), session_type);
9461 return NULL;
9462 }
9463
Jeff Johnson295189b2012-06-20 16:38:30 -07009464 /* Assign NL80211_IFTYPE_STATION as interface type to resolve Kernel Warning
9465 * message while loading driver in FTM mode. */
9466 pAdapter->wdev.iftype = NL80211_IFTYPE_STATION;
9467 pAdapter->device_mode = session_type;
9468 status = hdd_register_interface( pAdapter, rtnl_held );
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05309469
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309470 hdd_initialize_adapter_common(pAdapter);
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05309471 hdd_init_tx_rx( pAdapter );
9472
9473 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309474 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05309475 netif_tx_disable(pAdapter->dev);
9476 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07009477 }
9478 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07009479 default:
9480 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309481 hddLog(VOS_TRACE_LEVEL_FATAL,"%s Invalid session type %d",
9482 __func__, session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009483 VOS_ASSERT(0);
9484 return NULL;
9485 }
9486 }
9487
Jeff Johnson295189b2012-06-20 16:38:30 -07009488 if( VOS_STATUS_SUCCESS == status )
9489 {
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309490 //Add it to the hdd's session list.
Jeff Johnson295189b2012-06-20 16:38:30 -07009491 pHddAdapterNode = vos_mem_malloc( sizeof( hdd_adapter_list_node_t ) );
9492 if( NULL == pHddAdapterNode )
9493 {
9494 status = VOS_STATUS_E_NOMEM;
9495 }
9496 else
9497 {
9498 pHddAdapterNode->pAdapter = pAdapter;
9499 status = hdd_add_adapter_back ( pHddCtx,
9500 pHddAdapterNode );
9501 }
9502 }
9503
9504 if( VOS_STATUS_SUCCESS != status )
9505 {
9506 if( NULL != pAdapter )
9507 {
9508 hdd_cleanup_adapter( pHddCtx, pAdapter, rtnl_held );
9509 pAdapter = NULL;
9510 }
9511 if( NULL != pHddAdapterNode )
9512 {
9513 vos_mem_free( pHddAdapterNode );
9514 }
9515
9516 goto resume_bmps;
9517 }
9518
9519 if(VOS_STATUS_SUCCESS == status)
9520 {
9521 wlan_hdd_set_concurrency_mode(pHddCtx, session_type);
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -07009522 //Initialize the WoWL service
9523 if(!hdd_init_wowl(pAdapter))
9524 {
9525 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_init_wowl failed",__func__);
9526 goto err_free_netdev;
9527 }
Manjeet Singh3ed79242017-01-11 19:04:32 +05309528 //Initialize the TSF capture data
9529 wlan_hdd_tsf_init(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009530 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009531 return pAdapter;
9532
9533err_free_netdev:
9534 free_netdev(pAdapter->dev);
9535 wlan_hdd_release_intf_addr( pHddCtx,
9536 pAdapter->macAddressCurrent.bytes );
9537
9538resume_bmps:
9539 //If bmps disabled enable it
9540 if(VOS_STATUS_SUCCESS == exitbmpsStatus)
9541 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309542 if (pHddCtx->hdd_wlan_suspended)
9543 {
9544 hdd_set_pwrparams(pHddCtx);
9545 }
9546 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07009547 }
9548 return NULL;
9549}
9550
9551VOS_STATUS hdd_close_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
9552 tANI_U8 rtnl_held )
9553{
9554 hdd_adapter_list_node_t *pAdapterNode, *pCurrent, *pNext;
9555 VOS_STATUS status;
9556
9557 status = hdd_get_front_adapter ( pHddCtx, &pCurrent );
9558 if( VOS_STATUS_SUCCESS != status )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309559 {
9560 hddLog(VOS_TRACE_LEVEL_WARN,"%s: adapter list empty %d",
9561 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07009562 return status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309563 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009564
9565 while ( pCurrent->pAdapter != pAdapter )
9566 {
9567 status = hdd_get_next_adapter ( pHddCtx, pCurrent, &pNext );
9568 if( VOS_STATUS_SUCCESS != status )
9569 break;
9570
9571 pCurrent = pNext;
9572 }
9573 pAdapterNode = pCurrent;
9574 if( VOS_STATUS_SUCCESS == status )
9575 {
9576 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
9577 hdd_cleanup_adapter( pHddCtx, pAdapterNode->pAdapter, rtnl_held );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309578
9579#ifdef FEATURE_WLAN_TDLS
9580
9581 /* A Mutex Lock is introduced while changing/initializing the mode to
9582 * protect the concurrent access for the Adapters by TDLS module.
9583 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05309584 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309585#endif
9586
Jeff Johnson295189b2012-06-20 16:38:30 -07009587 hdd_remove_adapter( pHddCtx, pAdapterNode );
9588 vos_mem_free( pAdapterNode );
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08009589 pAdapterNode = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009590
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309591#ifdef FEATURE_WLAN_TDLS
9592 mutex_unlock(&pHddCtx->tdls_lock);
9593#endif
9594
Jeff Johnson295189b2012-06-20 16:38:30 -07009595
9596 /* If there is a single session of STA/P2P client, re-enable BMPS */
Agarwal Ashish51325b52014-06-16 16:50:49 +05309597 if ((!vos_concurrent_open_sessions_running()) &&
9598 ((pHddCtx->no_of_open_sessions[VOS_STA_MODE] >= 1) ||
9599 (pHddCtx->no_of_open_sessions[VOS_P2P_CLIENT_MODE] >= 1)))
Jeff Johnson295189b2012-06-20 16:38:30 -07009600 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309601 if (pHddCtx->hdd_wlan_suspended)
9602 {
9603 hdd_set_pwrparams(pHddCtx);
9604 }
9605 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07009606 }
9607
9608 return VOS_STATUS_SUCCESS;
9609 }
9610
9611 return VOS_STATUS_E_FAILURE;
9612}
9613
9614VOS_STATUS hdd_close_all_adapters( hdd_context_t *pHddCtx )
9615{
9616 hdd_adapter_list_node_t *pHddAdapterNode;
9617 VOS_STATUS status;
9618
9619 ENTER();
9620
9621 do
9622 {
9623 status = hdd_remove_front_adapter( pHddCtx, &pHddAdapterNode );
9624 if( pHddAdapterNode && VOS_STATUS_SUCCESS == status )
9625 {
9626 hdd_cleanup_adapter( pHddCtx, pHddAdapterNode->pAdapter, FALSE );
9627 vos_mem_free( pHddAdapterNode );
9628 }
9629 }while( NULL != pHddAdapterNode && VOS_STATUS_E_EMPTY != status );
9630
9631 EXIT();
9632
9633 return VOS_STATUS_SUCCESS;
9634}
9635
9636void wlan_hdd_reset_prob_rspies(hdd_adapter_t* pHostapdAdapter)
9637{
9638 v_U8_t addIE[1] = {0};
9639
9640 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
9641 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,(tANI_U8*)addIE, 0, NULL,
9642 eANI_BOOLEAN_FALSE) )
9643 {
9644 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08009645 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07009646 }
9647
9648 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
9649 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
9650 eANI_BOOLEAN_FALSE) )
9651 {
9652 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08009653 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07009654 }
9655
9656 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
9657 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
9658 eANI_BOOLEAN_FALSE) )
9659 {
9660 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08009661 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07009662 }
9663}
9664
Anurag Chouhan83026002016-12-13 22:46:21 +05309665VOS_STATUS hdd_cleanup_ap_events(hdd_adapter_t *adapter)
9666{
9667#ifdef DHCP_SERVER_OFFLOAD
9668 vos_event_destroy(&adapter->dhcp_status.vos_event);
9669#endif
Anurag Chouhan0b29de02016-12-16 13:18:40 +05309670#ifdef MDNS_OFFLOAD
9671 vos_event_destroy(&adapter->mdns_status.vos_event);
9672#endif
Anurag Chouhan83026002016-12-13 22:46:21 +05309673 return VOS_STATUS_SUCCESS;
9674}
9675
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309676int wlan_hdd_stop_mon(hdd_context_t *hdd_ctx, bool wait)
9677{
9678 hdd_mon_ctx_t *mon_ctx;
9679 long ret;
9680 v_U32_t magic;
9681 struct completion cmp_var;
9682 void (*func_ptr)(tANI_U32 *magic, struct completion *cmpVar) = NULL;
9683 hdd_adapter_t *adapter;
9684
9685 adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_MONITOR);
9686 if (!adapter) {
9687 hddLog(LOGE, FL("Invalid STA + MON mode"));
9688 return -EINVAL;
9689 }
9690
9691 mon_ctx = WLAN_HDD_GET_MONITOR_CTX_PTR(adapter);
9692 if (!mon_ctx)
9693 return 0;
9694
9695 if (mon_ctx->state != MON_MODE_START)
9696 return 0;
9697
9698 mon_ctx->state = MON_MODE_STOP;
9699 if (wait) {
9700 func_ptr = hdd_monPostMsgCb;
9701 magic = MON_MODE_MSG_MAGIC;
9702 init_completion(&cmp_var);
9703 }
9704
9705 if (VOS_STATUS_SUCCESS != wlan_hdd_mon_postMsg(&magic, &cmp_var,
9706 mon_ctx,
9707 hdd_monPostMsgCb)) {
9708 hddLog(LOGE, FL("failed to stop MON MODE"));
9709 mon_ctx->state = MON_MODE_START;
9710 magic = 0;
9711 return -EINVAL;
9712 }
9713
9714 if (!wait)
9715 goto bmps_roaming;
9716
9717 ret = wait_for_completion_timeout(&cmp_var, MON_MODE_MSG_TIMEOUT);
9718 magic = 0;
9719 if (ret <= 0 ) {
9720 hddLog(LOGE,
9721 FL("timeout on stop monitor mode completion %ld"), ret);
9722 return -EINVAL;
9723 }
9724
9725bmps_roaming:
9726 hddLog(LOG1, FL("Enable BMPS"));
9727 hdd_enable_bmps_imps(hdd_ctx);
9728 hdd_restore_roaming(hdd_ctx);
9729
9730 return 0;
9731}
9732
9733bool wlan_hdd_check_monitor_state(hdd_context_t *hdd_ctx)
9734{
9735 hdd_adapter_t *mon_adapter;
9736 hdd_mon_ctx_t *mon_ctx;
9737
9738 if (hdd_ctx->concurrency_mode != VOS_STA_MON)
9739 return false;
9740
9741 mon_adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_MONITOR);
9742 if (!mon_adapter) {
9743 hddLog(LOGE, FL("Invalid concurrency mode"));
9744 return false;
9745 }
9746
9747 mon_ctx = WLAN_HDD_GET_MONITOR_CTX_PTR(mon_adapter);
9748 if (mon_ctx->state == MON_MODE_START)
9749 return true;
9750
9751 return false;
9752}
9753
9754int wlan_hdd_check_and_stop_mon(hdd_adapter_t *sta_adapter, bool wait)
9755{
9756 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(sta_adapter);
9757
9758 if ((sta_adapter->device_mode != WLAN_HDD_INFRA_STATION) ||
9759 !wlan_hdd_check_monitor_state(hdd_ctx))
9760 return 0;
9761
9762 if (wlan_hdd_stop_mon(hdd_ctx, wait))
9763 return -EINVAL;
9764
9765 return 0;
9766}
9767
9768void hdd_disable_roaming(hdd_context_t *hdd_ctx)
9769{
9770 if (!hdd_ctx)
9771 return;
9772
9773 if (!hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled) {
9774 hdd_ctx->roaming_ini_original = CFG_LFR_FEATURE_ENABLED_MIN;
9775 return;
9776 }
9777
9778 hddLog(LOG1, FL("Disable driver and firmware roaming"));
9779
9780 hdd_ctx->roaming_ini_original =
9781 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled;
9782
9783 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled =
9784 CFG_LFR_FEATURE_ENABLED_MIN;
9785
9786 sme_UpdateIsFastRoamIniFeatureEnabled(hdd_ctx->hHal,
9787 CFG_LFR_FEATURE_ENABLED_MIN);
9788}
9789
9790void hdd_restore_roaming(hdd_context_t *hdd_ctx)
9791{
9792 if (!hdd_ctx->roaming_ini_original)
9793 return;
9794
9795 hddLog(LOG1, FL("Enable driver and firmware roaming"));
9796
9797 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled =
9798 CFG_LFR_FEATURE_ENABLED_MAX;
9799
9800 hdd_ctx->roaming_ini_original = CFG_LFR_FEATURE_ENABLED_MIN;
9801
9802 sme_UpdateIsFastRoamIniFeatureEnabled(hdd_ctx->hHal,
9803 CFG_LFR_FEATURE_ENABLED_MAX);
9804}
Anurag Chouhan83026002016-12-13 22:46:21 +05309805
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05309806VOS_STATUS hdd_stop_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
9807 const v_BOOL_t bCloseSession )
Jeff Johnson295189b2012-06-20 16:38:30 -07009808{
9809 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
9810 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Kaushik, Sushant4975a572014-10-21 16:07:48 +05309811 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009812 union iwreq_data wrqu;
Kaushik, Sushant7005e372014-04-08 11:36:54 +05309813 v_U8_t retry = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309814 long ret;
Nirav Shah7e3c8132015-06-22 23:51:42 +05309815 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07009816
Anand N Sunkad26d71b92014-12-24 18:08:22 +05309817 if (pHddCtx->isLogpInProgress) {
9818 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9819 "%s:LOGP in Progress. Ignore!!!",__func__);
9820 return VOS_STATUS_E_FAILURE;
9821 }
9822
Jeff Johnson295189b2012-06-20 16:38:30 -07009823 ENTER();
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +05309824
Kaushik, Sushant4975a572014-10-21 16:07:48 +05309825 pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07009826 switch(pAdapter->device_mode)
9827 {
Nirav Shah0cf4d892015-11-05 16:27:27 +05309828 case WLAN_HDD_IBSS:
9829 if ( VOS_TRUE == bCloseSession )
9830 {
9831 status = hdd_sta_id_hash_detach(pAdapter);
9832 if (status != VOS_STATUS_SUCCESS)
9833 hddLog(VOS_TRACE_LEVEL_ERROR,
9834 FL("sta id hash detach failed"));
9835 }
9836
Jeff Johnson295189b2012-06-20 16:38:30 -07009837 case WLAN_HDD_INFRA_STATION:
9838 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009839 case WLAN_HDD_P2P_DEVICE:
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05309840 {
9841 hdd_station_ctx_t *pstation = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Mahesh A Saptasagare4d05d42015-07-02 16:17:20 +05309842#ifdef FEATURE_WLAN_TDLS
9843 mutex_lock(&pHddCtx->tdls_lock);
9844 wlan_hdd_tdls_exit(pAdapter, TRUE);
9845 mutex_unlock(&pHddCtx->tdls_lock);
9846#endif
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05309847 if( hdd_connIsConnected(pstation) ||
9848 (pstation->conn_info.connState == eConnectionState_Connecting) )
Jeff Johnson295189b2012-06-20 16:38:30 -07009849 {
Abhishek Singhe21a5212017-06-09 09:42:58 +05309850 /*
9851 * Indicate sme of disconnect so that in progress connection
9852 * or preauth can be aborted.
9853 */
9854 sme_abortConnection(WLAN_HDD_GET_HAL_CTX(pAdapter),
9855 pAdapter->sessionId);
Abhishek Singh99f17b82017-02-06 16:57:56 +05309856 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07009857 if (pWextState->roamProfile.BSSType == eCSR_BSS_TYPE_START_IBSS)
9858 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
9859 pAdapter->sessionId,
9860 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
9861 else
9862 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
9863 pAdapter->sessionId,
9864 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Abhishek Singh7b52ed52016-02-11 17:45:54 +05309865 /* Success implies disconnect command got queued up successfully
9866 * Or cmd not queued as scan for SSID is in progress
9867 */
9868 if((eHAL_STATUS_SUCCESS == halStatus) ||
9869 (eHAL_STATUS_CMD_NOT_QUEUED == halStatus))
Jeff Johnson295189b2012-06-20 16:38:30 -07009870 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309871 ret = wait_for_completion_interruptible_timeout(
9872 &pAdapter->disconnect_comp_var,
9873 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Abhishek Singh7b52ed52016-02-11 17:45:54 +05309874 if (ret <= 0 &&
9875 (eHAL_STATUS_CMD_NOT_QUEUED != halStatus))
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309876 {
9877 hddLog(VOS_TRACE_LEVEL_ERROR,
9878 "%s: wait on disconnect_comp_var failed %ld",
9879 __func__, ret);
9880 }
9881 }
9882 else
9883 {
9884 hddLog(LOGE, "%s: failed to post disconnect event to SME",
9885 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009886 }
9887 memset(&wrqu, '\0', sizeof(wrqu));
9888 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
9889 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
9890 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
9891 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05309892 else if(pstation->conn_info.connState ==
9893 eConnectionState_Disconnecting)
9894 {
9895 ret = wait_for_completion_interruptible_timeout(
9896 &pAdapter->disconnect_comp_var,
9897 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
9898 if (ret <= 0)
9899 {
9900 hddLog(VOS_TRACE_LEVEL_ERROR,
9901 FL("wait on disconnect_comp_var failed %ld"), ret);
9902 }
9903 }
Sachin Ahuja27dd2402016-08-01 20:30:31 +05309904 if(pScanInfo != NULL && pHddCtx->scan_info.mScanPending)
Jeff Johnson295189b2012-06-20 16:38:30 -07009905 {
Mahesh A Saptasagar0b61dcc2016-02-15 14:23:38 +05309906 wlan_hdd_scan_abort(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009907 }
Abhishek Singh3ac179b2015-09-21 10:01:34 +05309908 if ((pAdapter->device_mode != WLAN_HDD_INFRA_STATION) &&
9909 (pAdapter->device_mode != WLAN_HDD_IBSS))
Kaushik, Sushant7005e372014-04-08 11:36:54 +05309910 {
9911 while (pAdapter->is_roc_inprogress)
9912 {
9913 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9914 "%s: ROC in progress for session %d!!!",
9915 __func__, pAdapter->sessionId);
9916 // waiting for ROC to expire
9917 msleep(500);
9918 /* In GO present case , if retry exceeds 3,
9919 it means something went wrong. */
9920 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION )
9921 {
9922 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9923 "%s: ROC completion is not received.!!!", __func__);
Deepthi Gowri70498252015-01-20 15:56:45 +05309924 if (eHAL_STATUS_SUCCESS !=
9925 sme_CancelRemainOnChannel( WLAN_HDD_GET_HAL_CTX( pAdapter),
9926 pAdapter->sessionId ))
9927 {
9928 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9929 FL("Failed to Cancel Remain on Channel"));
9930 }
Kaushik, Sushant7005e372014-04-08 11:36:54 +05309931 wait_for_completion_interruptible_timeout(
9932 &pAdapter->cancel_rem_on_chan_var,
9933 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
9934 break;
9935 }
9936 }
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309937 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +05309938 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309939#ifdef WLAN_NS_OFFLOAD
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309940 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309941#endif
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +05309942
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309943 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +05309944
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05309945 /* It is possible that the caller of this function does not
9946 * wish to close the session
9947 */
9948 if (VOS_TRUE == bCloseSession &&
9949 test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07009950 {
9951 INIT_COMPLETION(pAdapter->session_close_comp_var);
9952 if (eHAL_STATUS_SUCCESS ==
Agrawal Ashish5a3522c2016-03-02 15:08:28 +05309953 sme_CloseSession(pHddCtx->hHal, pAdapter->sessionId, FALSE,
9954 VOS_FALSE, hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07009955 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309956 unsigned long ret;
9957
Jeff Johnson295189b2012-06-20 16:38:30 -07009958 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309959 ret = wait_for_completion_timeout(
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05309960 &pAdapter->session_close_comp_var,
9961 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309962 if ( 0 >= ret)
9963 {
9964 hddLog(LOGE, "%s: failure waiting for session_close_comp_var %ld",
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05309965 __func__, ret);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309966 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009967 }
9968 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05309969 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009970 break;
9971
9972 case WLAN_HDD_SOFTAP:
9973 case WLAN_HDD_P2P_GO:
Nirav Shah0cf4d892015-11-05 16:27:27 +05309974 if ( VOS_TRUE == bCloseSession )
9975 {
9976 status = hdd_sta_id_hash_detach(pAdapter);
9977 if (status != VOS_STATUS_SUCCESS)
9978 hddLog(VOS_TRACE_LEVEL_ERROR,
9979 FL("sta id hash detach failed"));
9980 }
9981
Jeff Johnson295189b2012-06-20 16:38:30 -07009982 //Any softap specific cleanup here...
Anurag Chouhan83026002016-12-13 22:46:21 +05309983 hdd_cleanup_ap_events(pAdapter);
Kaushik, Sushant7005e372014-04-08 11:36:54 +05309984 if (pAdapter->device_mode == WLAN_HDD_P2P_GO) {
9985 while (pAdapter->is_roc_inprogress) {
9986 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9987 "%s: ROC in progress for session %d!!!",
9988 __func__, pAdapter->sessionId);
9989 msleep(500);
9990 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION ) {
9991 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9992 "%s: ROC completion is not received.!!!", __func__);
9993 WLANSAP_CancelRemainOnChannel(
9994 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
9995 wait_for_completion_interruptible_timeout(
9996 &pAdapter->cancel_rem_on_chan_var,
9997 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
9998 break;
9999 }
10000 }
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +053010001
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010002 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010003 }
Agrawal Ashish17ef5082016-10-17 18:33:21 +053010004#ifdef SAP_AUTH_OFFLOAD
10005 if (pHddCtx->cfg_ini->enable_sap_auth_offload)
10006 hdd_set_sap_auth_offload(pAdapter, FALSE);
10007#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070010008 mutex_lock(&pHddCtx->sap_lock);
10009 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10010 {
10011 VOS_STATUS status;
10012 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10013
10014 //Stop Bss.
10015 status = WLANSAP_StopBss(pHddCtx->pvosContext);
10016 if (VOS_IS_STATUS_SUCCESS(status))
10017 {
10018 hdd_hostapd_state_t *pHostapdState =
10019 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
10020
10021 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
10022
10023 if (!VOS_IS_STATUS_SUCCESS(status))
10024 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010025 hddLog(LOGE, "%s: failure waiting for WLANSAP_StopBss %d",
10026 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070010027 }
10028 }
10029 else
10030 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010031 hddLog(LOGE, "%s: failure in WLANSAP_StopBss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010032 }
10033 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
Agarwal Ashish51325b52014-06-16 16:50:49 +053010034 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -070010035
10036 if (eHAL_STATUS_FAILURE ==
10037 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
10038 0, NULL, eANI_BOOLEAN_FALSE))
10039 {
10040 hddLog(LOGE,
10041 "%s: Failed to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010042 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010043 }
10044
10045 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pAdapter))->hHal,
10046 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
10047 eANI_BOOLEAN_FALSE) )
10048 {
10049 hddLog(LOGE,
10050 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
10051 }
10052
10053 // Reset WNI_CFG_PROBE_RSP Flags
10054 wlan_hdd_reset_prob_rspies(pAdapter);
10055 kfree(pAdapter->sessionCtx.ap.beacon);
10056 pAdapter->sessionCtx.ap.beacon = NULL;
10057 }
10058 mutex_unlock(&pHddCtx->sap_lock);
Hanumanth Reddy Pothulab4537b82018-03-02 12:20:38 +053010059
10060#ifdef WLAN_NS_OFFLOAD
10061 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
10062#endif
10063 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
10064
Jeff Johnson295189b2012-06-20 16:38:30 -070010065 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -070010066
Jeff Johnson295189b2012-06-20 16:38:30 -070010067 case WLAN_HDD_MONITOR:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010068 if (VOS_MONITOR_MODE != hdd_get_conparam())
10069 wlan_hdd_stop_mon(pHddCtx, true);
10070 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -070010071
Jeff Johnson295189b2012-06-20 16:38:30 -070010072 default:
10073 break;
10074 }
10075
10076 EXIT();
10077 return VOS_STATUS_SUCCESS;
10078}
10079
Kapil Gupta137ef892016-12-13 19:38:00 +053010080/**
10081 * wlan_hdd_restart_sap() - to restart SAP in driver internally
10082 * @ap_adapter: - Pointer to SAP hdd_adapter_t structure
10083 *
10084 * wlan_hdd_restart_sap first delete SAP and do cleanup.
10085 * After that WLANSAP_StartBss start re-start process of SAP.
10086 *
10087 * Return: None
10088 */
10089static void wlan_hdd_restart_sap(hdd_adapter_t *ap_adapter)
10090{
10091 hdd_ap_ctx_t *pHddApCtx;
10092 hdd_hostapd_state_t *pHostapdState;
10093 VOS_STATUS vos_status;
10094 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(ap_adapter);
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010095#ifdef USE_CFG80211_DEL_STA_V2
Kapil Gupta137ef892016-12-13 19:38:00 +053010096 struct station_del_parameters delStaParams;
10097#endif
10098 tsap_Config_t *pConfig;
10099
10100 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10101 pConfig = &pHddApCtx->sapConfig;
10102
10103 mutex_lock(&pHddCtx->sap_lock);
10104 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010105#ifdef USE_CFG80211_DEL_STA_V2
Kapil Gupta137ef892016-12-13 19:38:00 +053010106 delStaParams.mac = NULL;
10107 delStaParams.subtype = SIR_MAC_MGMT_DEAUTH >> 4;
10108 delStaParams.reason_code = eCsrForcedDeauthSta;
10109 wlan_hdd_cfg80211_del_station(ap_adapter->wdev.wiphy, ap_adapter->dev,
10110 &delStaParams);
10111#else
10112 wlan_hdd_cfg80211_del_station(ap_adapter->wdev.wiphy, ap_adapter->dev,
10113 NULL);
10114#endif
10115 hdd_cleanup_actionframe(pHddCtx, ap_adapter);
10116
10117 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10118 vos_event_reset(&pHostapdState->vosEvent);
10119
10120 if (VOS_STATUS_SUCCESS == WLANSAP_StopBss(pHddCtx->pvosContext)) {
10121 vos_status = vos_wait_single_event(&pHostapdState->vosEvent,
10122 10000);
10123 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10124 hddLog(LOGE, FL("SAP Stop Failed"));
10125 goto end;
10126 }
10127 }
10128 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
10129 wlan_hdd_decr_active_session(pHddCtx, ap_adapter->device_mode);
10130 hddLog(LOG1, FL("SAP Stop Success"));
10131
10132 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
10133 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
10134 goto end;
10135 }
10136
10137 if (WLANSAP_StartBss(pHddCtx->pvosContext, hdd_hostapd_SAPEventCB,
10138 pConfig, (v_PVOID_t)ap_adapter->dev) != VOS_STATUS_SUCCESS) {
10139 hddLog(LOGE, FL("SAP Start Bss fail"));
10140 goto end;
10141 }
10142
10143 hddLog(LOG1, FL("Waiting for SAP to start"));
10144 vos_status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
10145 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10146 hddLog(LOGE, FL("SAP Start failed"));
10147 goto end;
10148 }
10149 hddLog(LOG1, FL("SAP Start Success"));
10150 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
10151 wlan_hdd_incr_active_session(pHddCtx, ap_adapter->device_mode);
10152 pHostapdState->bCommit = TRUE;
Anurag Chouhanb2951ae2017-03-12 13:41:35 +053010153 if (!VOS_IS_STATUS_SUCCESS(hdd_dhcp_mdns_offload(ap_adapter))) {
10154 hddLog(VOS_TRACE_LEVEL_ERROR, FL("DHCP/MDNS offload Failed!!"));
10155 vos_event_reset(&pHostapdState->vosEvent);
10156 if (VOS_STATUS_SUCCESS == WLANSAP_StopBss(pHddCtx->pvosContext)) {
10157 vos_status = vos_wait_single_event(&pHostapdState->vosEvent,
10158 10000);
10159 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10160 hddLog(LOGE, FL("SAP Stop Failed"));
10161 goto end;
10162 }
10163 }
10164 }
Kapil Gupta137ef892016-12-13 19:38:00 +053010165 }
10166end:
10167 mutex_unlock(&pHddCtx->sap_lock);
10168 return;
10169}
10170
10171/**
10172 * __hdd_sap_restart_handle() - to handle restarting of SAP
10173 * @work: name of the work
10174 *
10175 * Purpose of this function is to trigger sap start. this function
10176 * will be called from workqueue.
10177 *
10178 * Return: void.
10179 */
10180static void __hdd_sap_restart_handle(struct work_struct *work)
10181{
10182 hdd_adapter_t *sap_adapter;
10183 hdd_context_t *hdd_ctx = container_of(work,
10184 hdd_context_t,
10185 sap_start_work);
10186 if (0 != wlan_hdd_validate_context(hdd_ctx)) {
10187 vos_ssr_unprotect(__func__);
10188 return;
10189 }
10190 sap_adapter = hdd_get_adapter(hdd_ctx,
10191 WLAN_HDD_SOFTAP);
10192 if (sap_adapter == NULL) {
10193 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10194 FL("sap_adapter is NULL"));
10195 vos_ssr_unprotect(__func__);
10196 return;
10197 }
10198
10199 if (hdd_ctx->is_ch_avoid_in_progress) {
10200 sap_adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
10201 wlan_hdd_restart_sap(sap_adapter);
10202 hdd_change_ch_avoidance_status(hdd_ctx, false);
10203 }
Agrawal Ashish574b3e62017-02-09 18:58:34 +053010204 if (hdd_ctx->cfg_ini->enable_sap_auth_offload)
10205 wlan_hdd_restart_sap(sap_adapter);
Kapil Gupta137ef892016-12-13 19:38:00 +053010206}
10207
10208/**
10209 * hdd_sap_restart_handle() - to handle restarting of SAP
10210 * @work: name of the work
10211 *
10212 * Purpose of this function is to trigger sap start. this function
10213 * will be called from workqueue.
10214 *
10215 * Return: void.
10216 */
10217static void hdd_sap_restart_handle(struct work_struct *work)
10218{
10219 vos_ssr_protect(__func__);
10220 __hdd_sap_restart_handle(work);
10221 vos_ssr_unprotect(__func__);
10222}
10223
10224
Abhishek Singh78c691f2017-11-30 13:48:44 +053010225/**
10226 * __hdd_force_scc_with_ecsa_handle() - to handle force scc using ecsa
10227 * @work: name of the work
10228 *
10229 * Purpose of this function is to force SCC using ECSA. This function
10230 * will be called from workqueue.
10231 *
10232 * Return: void.
10233 */
10234static void
10235__hdd_force_scc_with_ecsa_handle(struct work_struct *work)
10236{
10237 hdd_adapter_t *sap_adapter;
10238 hdd_station_ctx_t *sta_ctx;
10239 hdd_adapter_t *sta_adapter;
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010240 ptSapContext sap_ctx = NULL;
10241 v_CONTEXT_t vos_ctx;
10242 tANI_U8 target_channel;
10243 tsap_Config_t *sap_config;
10244 bool sta_sap_scc_on_dfs_chan;
10245 eNVChannelEnabledType chan_state;
Abhishek Singh78c691f2017-11-30 13:48:44 +053010246 hdd_context_t *hdd_ctx = container_of(to_delayed_work(work),
10247 hdd_context_t,
10248 ecsa_chan_change_work);
10249
10250 if (wlan_hdd_validate_context(hdd_ctx))
10251 return;
10252
10253 sap_adapter = hdd_get_adapter(hdd_ctx,
10254 WLAN_HDD_SOFTAP);
10255 if (!sap_adapter) {
10256 hddLog(LOGE, FL("sap_adapter is NULL"));
10257 return;
10258 }
10259
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010260 vos_ctx = hdd_ctx->pvosContext;
10261 if (!vos_ctx) {
10262 hddLog(LOGE, FL("vos_ctx is NULL"));
10263 return;
10264 }
10265
10266 sap_ctx = VOS_GET_SAP_CB(vos_ctx);
10267 if (!sap_ctx) {
10268 hddLog(LOGE, FL("sap_ctx is NULL"));
10269 return;
10270 }
10271
10272 sap_config = &sap_adapter->sessionCtx.ap.sapConfig;
10273
10274 sta_sap_scc_on_dfs_chan = hdd_is_sta_sap_scc_allowed_on_dfs_chan(hdd_ctx);
10275
Abhishek Singh78c691f2017-11-30 13:48:44 +053010276 sta_adapter = hdd_get_adapter(hdd_ctx,
10277 WLAN_HDD_INFRA_STATION);
10278 if (!sta_adapter) {
10279 hddLog(LOGE, FL("sta_adapter is NULL"));
10280 return;
10281 }
Abhishek Singh78c691f2017-11-30 13:48:44 +053010282
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010283 if (wlansap_chk_n_set_chan_change_in_progress(sap_ctx))
Abhishek Singh78c691f2017-11-30 13:48:44 +053010284 return;
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010285 INIT_COMPLETION(sap_ctx->ecsa_info.chan_switch_comp);
10286
10287 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(sta_adapter);
10288 if (sta_ctx->conn_info.connState != eConnectionState_Associated) {
10289 if (sta_ctx->conn_info.connState == eConnectionState_NotConnected) {
10290 chan_state = vos_nv_getChannelEnabledState(sap_ctx->channel);
10291 hddLog(LOG1, FL("sta not in connected state %d, sta_sap_scc_on_dfs_chan %d, chan_state %d"),
10292 sta_ctx->conn_info.connState, sta_sap_scc_on_dfs_chan,
10293 chan_state);
10294 if (sta_sap_scc_on_dfs_chan &&
10295 (chan_state == NV_CHANNEL_DFS)) {
10296 hddLog(LOGE, FL("Switch SAP to user configured channel"));
10297 target_channel = sap_config->user_config_channel;
10298 goto switch_channel;
10299 }
10300 }
10301 goto abort;
Abhishek Singh78c691f2017-11-30 13:48:44 +053010302 }
10303
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010304 target_channel = sta_ctx->conn_info.operationChannel;
10305switch_channel:
10306 hddLog(LOGE, FL("Switch SAP to %d channel"),
10307 target_channel);
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010308 if (!wlansap_set_channel_change(vos_ctx, target_channel, true))
10309 return;
10310
10311abort:
10312 wlansap_reset_chan_change_in_progress(sap_ctx);
10313 complete(&sap_ctx->ecsa_info.chan_switch_comp);
Abhishek Singh78c691f2017-11-30 13:48:44 +053010314}
10315
10316/**
10317 * hdd_force_scc_with_ecsa_handle() - to handle force scc using ecsa
10318 * @work: name of the work
10319 *
10320 * Purpose of this function is to force SCC using ECSA. This function
10321 * will be called from workqueue.
10322 *
10323 * Return: void.
10324 */
10325static void
10326hdd_force_scc_with_ecsa_handle(struct work_struct *work)
10327{
10328 vos_ssr_protect(__func__);
10329 __hdd_force_scc_with_ecsa_handle(work);
10330 vos_ssr_unprotect(__func__);
10331}
10332
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010333int hdd_wait_for_ecsa_complete(hdd_context_t *hdd_ctx)
10334{
10335 int ret;
10336 ptSapContext sap_ctx = NULL;
10337 v_CONTEXT_t vos_ctx;
10338
10339 vos_ctx = hdd_ctx->pvosContext;
10340 if (!vos_ctx) {
10341 hddLog(LOGE, FL("vos_ctx is NULL"));
10342 return 0;
10343 }
10344
10345 sap_ctx = VOS_GET_SAP_CB(vos_ctx);
10346 if (!sap_ctx) {
10347 hddLog(LOG1, FL("sap_ctx is NULL"));
10348 return 0;
10349 }
10350 if(!sap_ctx->isSapSessionOpen) {
10351 hddLog(LOG1, FL("sap session not opened, SAP in state %d"),
10352 sap_ctx->sapsMachine);
10353 return 0;
10354 }
10355
10356 if (!wlansap_get_change_in_progress(sap_ctx)) {
10357 hddLog(LOG1, FL("channel switch not in progress"));
10358 return 0;
10359 }
10360 ret = wait_for_completion_timeout(&sap_ctx->ecsa_info.chan_switch_comp,
10361 msecs_to_jiffies(HDD_SAP_CHAN_CNG_WAIT_TIME));
10362 if (!ret)
10363 {
10364 hddLog(LOGE, FL("Timeout waiting for SAP channel switch"));
10365 return ret;
10366 }
10367
10368 return 0;
10369}
10370
10371
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010372/**
10373 * hdd_is_sta_sap_scc_allowed_on_dfs_chan() - check if sta+sap scc allowed on
10374 * dfs chan
10375 * @hdd_ctx: pointer to hdd context
10376 *
10377 * This function used to check if sta+sap scc allowed on DFS channel.
10378 *
10379 * Return: None
10380 */
10381bool hdd_is_sta_sap_scc_allowed_on_dfs_chan(hdd_context_t *hdd_ctx)
10382{
10383 if (hdd_ctx->cfg_ini->force_scc_with_ecsa &&
10384 hdd_ctx->cfg_ini->sta_sap_scc_on_dfs_chan)
10385 return true;
10386 else
10387 return false;
10388}
10389
Jeff Johnson295189b2012-06-20 16:38:30 -070010390VOS_STATUS hdd_stop_all_adapters( hdd_context_t *pHddCtx )
10391{
10392 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10393 VOS_STATUS status;
10394 hdd_adapter_t *pAdapter;
10395
10396 ENTER();
10397
10398 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10399
10400 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10401 {
10402 pAdapter = pAdapterNode->pAdapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070010403
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010404 hdd_stop_adapter( pHddCtx, pAdapter, VOS_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -070010405
10406 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10407 pAdapterNode = pNext;
10408 }
10409
10410 EXIT();
10411
10412 return VOS_STATUS_SUCCESS;
10413}
10414
Rajeev Kumarf999e582014-01-09 17:33:29 -080010415
10416#ifdef FEATURE_WLAN_BATCH_SCAN
10417/**---------------------------------------------------------------------------
10418
10419 \brief hdd_deinit_batch_scan () - This function cleans up batch scan data
10420 structures
10421
10422 \param - pAdapter Pointer to HDD adapter
10423
10424 \return - None
10425
10426 --------------------------------------------------------------------------*/
10427void hdd_deinit_batch_scan(hdd_adapter_t *pAdapter)
10428{
10429 tHddBatchScanRsp *pNode;
10430 tHddBatchScanRsp *pPrev;
10431
Siddharth Bhalb3e9b792014-02-24 15:14:16 +053010432 if (NULL == pAdapter)
Rajeev Kumarf999e582014-01-09 17:33:29 -080010433 {
Siddharth Bhalb3e9b792014-02-24 15:14:16 +053010434 hddLog(VOS_TRACE_LEVEL_ERROR,
10435 "%s: Adapter context is Null", __func__);
10436 return;
10437 }
10438
10439 pNode = pAdapter->pBatchScanRsp;
10440 while (pNode)
10441 {
10442 pPrev = pNode;
10443 pNode = pNode->pNext;
10444 vos_mem_free((v_VOID_t * )pPrev);
Rajeev Kumarf999e582014-01-09 17:33:29 -080010445 }
10446
10447 pAdapter->pBatchScanRsp = NULL;
10448 pAdapter->numScanList = 0;
10449 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
10450 pAdapter->prev_batch_id = 0;
10451
10452 return;
10453}
10454#endif
10455
10456
Jeff Johnson295189b2012-06-20 16:38:30 -070010457VOS_STATUS hdd_reset_all_adapters( hdd_context_t *pHddCtx )
10458{
10459 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10460 VOS_STATUS status;
10461 hdd_adapter_t *pAdapter;
10462
10463 ENTER();
10464
10465 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10466
10467 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10468 {
10469 pAdapter = pAdapterNode->pAdapter;
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +053010470 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -070010471 netif_tx_disable(pAdapter->dev);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053010472
10473 if (pHddCtx->cfg_ini->sap_internal_restart &&
10474 pAdapter->device_mode == WLAN_HDD_SOFTAP) {
10475 hddLog(LOG1, FL("driver supports sap restart"));
10476 vos_flush_work(&pHddCtx->sap_start_work);
10477 hdd_sap_indicate_disconnect_for_sta(pAdapter);
10478 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +053010479 hdd_softap_deinit_tx_rx(pAdapter, true);
10480 hdd_sap_destroy_timers(pAdapter);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053010481 } else {
10482 netif_carrier_off(pAdapter->dev);
10483 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010484
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070010485 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010486 pAdapter->sessionCtx.monitor.state = MON_MODE_STOP;
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070010487
Jeff Johnson295189b2012-06-20 16:38:30 -070010488 hdd_deinit_tx_rx(pAdapter);
Agarwal Ashish6267caa2014-08-06 19:16:21 +053010489
Katya Nigam1fd24402015-02-16 14:52:19 +053010490 if(pAdapter->device_mode == WLAN_HDD_IBSS )
10491 hdd_ibss_deinit_tx_rx(pAdapter);
10492
Nirav Shah7e3c8132015-06-22 23:51:42 +053010493 status = hdd_sta_id_hash_detach(pAdapter);
10494 if (status != VOS_STATUS_SUCCESS)
10495 hddLog(VOS_TRACE_LEVEL_ERROR,
10496 FL("sta id hash detach failed for session id %d"),
10497 pAdapter->sessionId);
10498
Agarwal Ashish6267caa2014-08-06 19:16:21 +053010499 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
10500
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +053010501 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
10502 {
10503 hdd_wmm_adapter_close( pAdapter );
10504 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
10505 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010506
Siddharth Bhal2db319d2014-12-03 12:37:18 +053010507 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10508 {
10509 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
10510 }
10511
Rajeev Kumarf999e582014-01-09 17:33:29 -080010512#ifdef FEATURE_WLAN_BATCH_SCAN
10513 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
10514 {
10515 hdd_deinit_batch_scan(pAdapter);
10516 }
10517#endif
10518
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +053010519#ifdef FEATURE_WLAN_TDLS
10520 mutex_lock(&pHddCtx->tdls_lock);
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +053010521 wlan_hdd_tdls_exit(pAdapter, TRUE);
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +053010522 mutex_unlock(&pHddCtx->tdls_lock);
10523#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070010524 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10525 pAdapterNode = pNext;
10526 }
10527
10528 EXIT();
10529
10530 return VOS_STATUS_SUCCESS;
10531}
10532
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010533/**
Abhishek Singh5a597e62016-12-05 15:16:30 +053010534 * hdd_get_bss_entry() - Get the bss entry matching the chan, bssid and ssid
10535 * @wiphy: wiphy
10536 * @channel: channel of the BSS to find
10537 * @bssid: bssid of the BSS to find
10538 * @ssid: ssid of the BSS to find
10539 * @ssid_len: ssid len of of the BSS to find
10540 *
10541 * The API is a wrapper to get bss from kernel matching the chan,
10542 * bssid and ssid
10543 *
10544 * Return: Void
10545 */
10546#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
10547 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
10548
10549struct cfg80211_bss* hdd_get_bss_entry(struct wiphy *wiphy,
10550 struct ieee80211_channel *channel,
10551 const u8 *bssid,
10552 const u8 *ssid, size_t ssid_len)
10553{
10554 return cfg80211_get_bss(wiphy, channel, bssid,
10555 ssid, ssid_len,
10556 WLAN_CAPABILITY_ESS,
10557 WLAN_CAPABILITY_ESS);
10558}
10559#else
10560struct cfg80211_bss* hdd_get_bss_entry(struct wiphy *wiphy,
10561 struct ieee80211_channel *channel,
10562 const u8 *bssid,
10563 const u8 *ssid, size_t ssid_len)
10564{
10565 return cfg80211_get_bss(wiphy, channel, bssid,
10566 ssid, ssid_len,
10567 IEEE80211_BSS_TYPE_ESS,
10568 IEEE80211_PRIVACY_ANY);
10569}
10570#endif
10571
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010572#if defined(CFG80211_CONNECT_BSS) || \
10573 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
10574
10575#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) || \
10576 defined (CFG80211_CONNECT_TIMEOUT_REASON_CODE)
10577/**
10578 * hdd_connect_bss() - helper function to send connection status to supplicant
10579 * @dev: network device
10580 * @bssid: bssid to which we want to associate
10581 * @bss: information about connected bss
10582 * @req_ie: Request Information Element
10583 * @req_ie_len: len of the req IE
10584 * @resp_ie: Response IE
10585 * @resp_ie_len: len of ht response IE
10586 * @status: status
10587 * @gfp: Kernel Flag
10588 *
10589 * This is a helper function to send connection status to supplicant
10590 * and gets invoked from wrapper API
10591 *
10592 * Return: Void
10593 */
10594static void hdd_connect_bss(struct net_device *dev,
10595 const u8 *bssid,
10596 struct cfg80211_bss *bss,
10597 const u8 *req_ie,
10598 size_t req_ie_len,
10599 const u8 *resp_ie,
10600 size_t resp_ie_len,
10601 u16 status,
10602 gfp_t gfp)
10603{
10604 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
10605 resp_ie, resp_ie_len, status, gfp, NL80211_TIMEOUT_UNSPECIFIED);
10606}
10607#else
10608/**
10609 * hdd_connect_bss() - helper function to send connection status to supplicant
10610 * @dev: network device
10611 * @bssid: bssid to which we want to associate
10612 * @bss: information about connected bss
10613 * @req_ie: Request Information Element
10614 * @req_ie_len: len of the req IE
10615 * @resp_ie: Response IE
10616 * @resp_ie_len: len of ht response IE
10617 * @status: status
10618 * @gfp: Kernel Flag
10619 *
10620 * This is a helper function to send connection status to supplicant
10621 * and gets invoked from wrapper API
10622 *
10623 * Return: Void
10624 */
10625static void hdd_connect_bss(struct net_device *dev,
10626 const u8 *bssid,
10627 struct cfg80211_bss *bss,
10628 const u8 *req_ie,
10629 size_t req_ie_len,
10630 const u8 *resp_ie,
10631 size_t resp_ie_len,
10632 u16 status,
10633 gfp_t gfp)
10634{
10635 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
10636 resp_ie, resp_ie_len, status, gfp);
10637}
10638#endif
10639
Abhishek Singh5a597e62016-12-05 15:16:30 +053010640/**
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010641 * hdd_connect_result() - API to send connection status to supplicant
10642 * @dev: network device
10643 * @bssid: bssid to which we want to associate
10644 * @roam_info: information about connected bss
10645 * @req_ie: Request Information Element
10646 * @req_ie_len: len of the req IE
10647 * @resp_ie: Response IE
10648 * @resp_ie_len: len of ht response IE
10649 * @status: status
10650 * @gfp: Kernel Flag
10651 *
10652 * The API is a wrapper to send connection status to supplicant
10653 *
10654 * Return: Void
10655 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010656void hdd_connect_result(struct net_device *dev,
10657 const u8 *bssid,
10658 tCsrRoamInfo *roam_info,
10659 const u8 *req_ie,
10660 size_t req_ie_len,
10661 const u8 *resp_ie,
10662 size_t resp_ie_len,
10663 u16 status,
10664 gfp_t gfp)
10665{
10666 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
10667 struct cfg80211_bss *bss = NULL;
10668
10669 if (WLAN_STATUS_SUCCESS == status) {
10670 struct ieee80211_channel *chan;
10671 int freq;
10672 int chan_no = roam_info->pBssDesc->channelId;;
10673
10674 if (chan_no <= 14)
10675 freq = ieee80211_channel_to_frequency(chan_no,
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010676 HDD_NL80211_BAND_2GHZ);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010677 else
10678 freq = ieee80211_channel_to_frequency(chan_no,
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010679 HDD_NL80211_BAND_5GHZ);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010680
10681 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
Abhishek Singh5a597e62016-12-05 15:16:30 +053010682 bss = hdd_get_bss_entry(padapter->wdev.wiphy,
10683 chan, bssid,
10684 roam_info->u.pConnectedProfile->SSID.ssId,
10685 roam_info->u.pConnectedProfile->SSID.length);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010686 }
10687
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010688 hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie, resp_ie_len,
10689 status, gfp);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010690}
10691#else
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010692/**
10693 * hdd_connect_result() - API to send connection status to supplicant
10694 * @dev: network device
10695 * @bssid: bssid to which we want to associate
10696 * @roam_info: information about connected bss
10697 * @req_ie: Request Information Element
10698 * @req_ie_len: len of the req IE
10699 * @resp_ie: Response IE
10700 * @resp_ie_len: len of ht response IE
10701 * @status: status
10702 * @gfp: Kernel Flag
10703 *
10704 * The API is a wrapper to send connection status to supplicant
10705 *
10706 * Return: Void
10707 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010708void hdd_connect_result(struct net_device *dev,
10709 const u8 *bssid,
10710 tCsrRoamInfo *roam_info,
10711 const u8 *req_ie,
10712 size_t req_ie_len,
10713 const u8 * resp_ie,
10714 size_t resp_ie_len,
10715 u16 status,
10716 gfp_t gfp)
10717{
10718 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
10719 resp_ie, resp_ie_len, status, gfp);
10720}
10721#endif
10722
Jeff Johnson295189b2012-06-20 16:38:30 -070010723VOS_STATUS hdd_start_all_adapters( hdd_context_t *pHddCtx )
10724{
10725 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10726 VOS_STATUS status;
10727 hdd_adapter_t *pAdapter;
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053010728 eConnectionState connState;
Jeff Johnson295189b2012-06-20 16:38:30 -070010729
10730 ENTER();
10731
10732 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10733
10734 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10735 {
10736 pAdapter = pAdapterNode->pAdapter;
10737
Kumar Anand82c009f2014-05-29 00:29:42 -070010738 hdd_wmm_init( pAdapter );
10739
Jeff Johnson295189b2012-06-20 16:38:30 -070010740 switch(pAdapter->device_mode)
10741 {
10742 case WLAN_HDD_INFRA_STATION:
10743 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -070010744 case WLAN_HDD_P2P_DEVICE:
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053010745
10746 connState = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState;
10747
Jeff Johnson295189b2012-06-20 16:38:30 -070010748 hdd_init_station_mode(pAdapter);
10749 /* Open the gates for HDD to receive Wext commands */
10750 pAdapter->isLinkUpSvcNeeded = FALSE;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070010751 pHddCtx->scan_info.mScanPending = FALSE;
10752 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070010753
10754 //Trigger the initial scan
Mukul Sharmae74e42c2015-08-06 23:55:49 +053010755 if (!pHddCtx->isLogpInProgress)
10756 hdd_wlan_initial_scan(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010757
10758 //Indicate disconnect event to supplicant if associated previously
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053010759 if (eConnectionState_Associated == connState ||
10760 eConnectionState_IbssConnected == connState )
Jeff Johnson295189b2012-06-20 16:38:30 -070010761 {
10762 union iwreq_data wrqu;
10763 memset(&wrqu, '\0', sizeof(wrqu));
10764 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
10765 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
10766 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070010767 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070010768
Jeff Johnson295189b2012-06-20 16:38:30 -070010769 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagar9ff4bcc2016-06-01 17:17:50 +053010770 wlan_hdd_cfg80211_indicate_disconnect(pAdapter->dev, false,
Mahesh A Saptasagarb5a15142016-05-25 11:27:43 +053010771 WLAN_REASON_UNSPECIFIED);
Jeff Johnson295189b2012-06-20 16:38:30 -070010772 }
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053010773 else if (eConnectionState_Connecting == connState)
10774 {
10775 /*
10776 * Indicate connect failure to supplicant if we were in the
10777 * process of connecting
10778 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053010779 hdd_connect_result(pAdapter->dev, NULL, NULL,
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053010780 NULL, 0, NULL, 0,
10781 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
10782 GFP_KERNEL);
10783 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010784 break;
10785
10786 case WLAN_HDD_SOFTAP:
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053010787 if (pHddCtx->cfg_ini->sap_internal_restart) {
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +053010788 hdd_init_ap_mode(pAdapter, true);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053010789 status = hdd_sta_id_hash_attach(pAdapter);
10790 if (VOS_STATUS_SUCCESS != status)
10791 {
10792 hddLog(VOS_TRACE_LEVEL_FATAL,
10793 FL("failed to attach hash for"));
10794 }
10795 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010796 break;
10797
10798 case WLAN_HDD_P2P_GO:
Sameer Thalappiledf0d792013-08-09 14:31:03 -070010799 hddLog(VOS_TRACE_LEVEL_ERROR, "%s [SSR] send stop ap to supplicant",
Jeff Johnson295189b2012-06-20 16:38:30 -070010800 __func__);
Sameer Thalappiledf0d792013-08-09 14:31:03 -070010801 cfg80211_ap_stopped(pAdapter->dev, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -070010802 break;
10803
10804 case WLAN_HDD_MONITOR:
10805 /* monitor interface start */
10806 break;
10807 default:
10808 break;
10809 }
10810
10811 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10812 pAdapterNode = pNext;
10813 }
10814
10815 EXIT();
10816
10817 return VOS_STATUS_SUCCESS;
10818}
10819
10820VOS_STATUS hdd_reconnect_all_adapters( hdd_context_t *pHddCtx )
10821{
10822 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10823 hdd_adapter_t *pAdapter;
10824 VOS_STATUS status;
10825 v_U32_t roamId;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010826 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070010827
10828 ENTER();
10829
10830 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10831
10832 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10833 {
10834 pAdapter = pAdapterNode->pAdapter;
10835
10836 if( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
10837 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
10838 {
10839 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
10840 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
10841
Abhishek Singhf4669da2014-05-26 15:07:49 +053010842 hddLog(VOS_TRACE_LEVEL_INFO,
10843 "%s: Set HDD connState to eConnectionState_NotConnected",
10844 __func__);
Ganesh Kondabattini04338412015-09-14 15:39:09 +053010845 spin_lock_bh(&pAdapter->lock_for_active_session);
10846 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState)
10847 {
10848 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
10849 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010850 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Ganesh Kondabattini04338412015-09-14 15:39:09 +053010851 spin_unlock_bh(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -070010852 init_completion(&pAdapter->disconnect_comp_var);
10853 sme_RoamDisconnect(pHddCtx->hHal, pAdapter->sessionId,
10854 eCSR_DISCONNECT_REASON_UNSPECIFIED);
10855
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010856 ret = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -070010857 &pAdapter->disconnect_comp_var,
10858 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010859 if (0 >= ret)
10860 hddLog(LOGE, "%s: failure waiting for disconnect_comp_var %ld",
10861 __func__, ret);
Jeff Johnson295189b2012-06-20 16:38:30 -070010862
10863 pWextState->roamProfile.csrPersona = pAdapter->device_mode;
10864 pHddCtx->isAmpAllowed = VOS_FALSE;
10865 sme_RoamConnect(pHddCtx->hHal,
10866 pAdapter->sessionId, &(pWextState->roamProfile),
10867 &roamId);
10868 }
10869
10870 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10871 pAdapterNode = pNext;
10872 }
10873
10874 EXIT();
10875
10876 return VOS_STATUS_SUCCESS;
10877}
10878
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070010879void hdd_dump_concurrency_info(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 hdd_station_ctx_t *pHddStaCtx;
10885 hdd_ap_ctx_t *pHddApCtx;
10886 hdd_hostapd_state_t * pHostapdState;
10887 tCsrBssid staBssid = { 0 }, p2pBssid = { 0 }, apBssid = { 0 };
10888 v_U8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
10889 const char *p2pMode = "DEV";
10890 const char *ccMode = "Standalone";
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070010891
10892 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10893 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10894 {
10895 pAdapter = pAdapterNode->pAdapter;
10896 switch (pAdapter->device_mode) {
10897 case WLAN_HDD_INFRA_STATION:
10898 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
10899 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
10900 staChannel = pHddStaCtx->conn_info.operationChannel;
10901 memcpy(staBssid, pHddStaCtx->conn_info.bssId, sizeof(staBssid));
10902 }
10903 break;
10904 case WLAN_HDD_P2P_CLIENT:
10905 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
10906 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
10907 p2pChannel = pHddStaCtx->conn_info.operationChannel;
10908 memcpy(p2pBssid, pHddStaCtx->conn_info.bssId, sizeof(p2pBssid));
10909 p2pMode = "CLI";
10910 }
10911 break;
10912 case WLAN_HDD_P2P_GO:
10913 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
10914 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
10915 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
10916 p2pChannel = pHddApCtx->operatingChannel;
10917 memcpy(p2pBssid, pAdapter->macAddressCurrent.bytes, sizeof(p2pBssid));
10918 }
10919 p2pMode = "GO";
10920 break;
10921 case WLAN_HDD_SOFTAP:
10922 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
10923 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
10924 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
10925 apChannel = pHddApCtx->operatingChannel;
10926 memcpy(apBssid, pAdapter->macAddressCurrent.bytes, sizeof(apBssid));
10927 }
10928 break;
10929 default:
10930 break;
10931 }
10932 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10933 pAdapterNode = pNext;
10934 }
10935 if (staChannel > 0 && (apChannel > 0 || p2pChannel > 0)) {
10936 ccMode = (p2pChannel==staChannel||apChannel==staChannel) ? "SCC" : "MCC";
10937 }
Yeshwanth Sriram Guntuka0004c0b2017-12-06 14:43:49 +053010938 hddLog(VOS_TRACE_LEVEL_ERROR, "wlan(%d) " MAC_ADDRESS_STR " %s",
10939 staChannel, MAC_ADDR_ARRAY(staBssid), ccMode);
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070010940 if (p2pChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +053010941 hddLog(VOS_TRACE_LEVEL_ERROR, "p2p-%s(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070010942 p2pMode, p2pChannel, MAC_ADDR_ARRAY(p2pBssid));
10943 }
10944 if (apChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +053010945 hddLog(VOS_TRACE_LEVEL_ERROR, "AP(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070010946 apChannel, MAC_ADDR_ARRAY(apBssid));
10947 }
10948
10949 if (p2pChannel > 0 && apChannel > 0) {
10950 hddLog(VOS_TRACE_LEVEL_ERROR, "Error concurrent SAP %d and P2P %d which is not support", apChannel, p2pChannel);
10951 }
10952}
10953
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070010954bool hdd_is_ssr_required( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070010955{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070010956 return (isSsrRequired == HDD_SSR_REQUIRED);
Jeff Johnson295189b2012-06-20 16:38:30 -070010957}
10958
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070010959/* Once SSR is disabled then it cannot be set. */
10960void hdd_set_ssr_required( e_hdd_ssr_required value)
Jeff Johnson295189b2012-06-20 16:38:30 -070010961{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070010962 if (HDD_SSR_DISABLED == isSsrRequired)
10963 return;
10964
Jeff Johnson295189b2012-06-20 16:38:30 -070010965 isSsrRequired = value;
10966}
10967
Hema Aparna Medicharla6b4d4f32015-06-23 04:09:12 +053010968void hdd_set_pre_close( hdd_context_t *pHddCtx)
10969{
10970 sme_PreClose(pHddCtx->hHal);
10971}
10972
Jeff Johnson295189b2012-06-20 16:38:30 -070010973VOS_STATUS hdd_get_front_adapter( hdd_context_t *pHddCtx,
10974 hdd_adapter_list_node_t** ppAdapterNode)
10975{
10976 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053010977 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070010978 status = hdd_list_peek_front ( &pHddCtx->hddAdapters,
10979 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053010980 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070010981 return status;
10982}
10983
10984VOS_STATUS hdd_get_next_adapter( hdd_context_t *pHddCtx,
10985 hdd_adapter_list_node_t* pAdapterNode,
10986 hdd_adapter_list_node_t** pNextAdapterNode)
10987{
10988 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053010989 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070010990 status = hdd_list_peek_next ( &pHddCtx->hddAdapters,
10991 (hdd_list_node_t*) pAdapterNode,
10992 (hdd_list_node_t**)pNextAdapterNode );
10993
Mukul Sharmaae1266d2015-06-26 15:29:53 +053010994 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070010995 return status;
10996}
10997
10998VOS_STATUS hdd_remove_adapter( hdd_context_t *pHddCtx,
10999 hdd_adapter_list_node_t* pAdapterNode)
11000{
11001 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011002 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011003 status = hdd_list_remove_node ( &pHddCtx->hddAdapters,
11004 &pAdapterNode->node );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011005 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011006 return status;
11007}
11008
11009VOS_STATUS hdd_remove_front_adapter( hdd_context_t *pHddCtx,
11010 hdd_adapter_list_node_t** ppAdapterNode)
11011{
11012 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011013 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011014 status = hdd_list_remove_front( &pHddCtx->hddAdapters,
11015 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011016 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011017 return status;
11018}
11019
11020VOS_STATUS hdd_add_adapter_back( hdd_context_t *pHddCtx,
11021 hdd_adapter_list_node_t* pAdapterNode)
11022{
11023 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011024 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011025 status = hdd_list_insert_back ( &pHddCtx->hddAdapters,
11026 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011027 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011028 return status;
11029}
11030
11031VOS_STATUS hdd_add_adapter_front( hdd_context_t *pHddCtx,
11032 hdd_adapter_list_node_t* pAdapterNode)
11033{
11034 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011035 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011036 status = hdd_list_insert_front ( &pHddCtx->hddAdapters,
11037 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011038 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011039 return status;
11040}
11041
11042hdd_adapter_t * hdd_get_adapter_by_macaddr( hdd_context_t *pHddCtx,
11043 tSirMacAddr macAddr )
11044{
11045 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11046 hdd_adapter_t *pAdapter;
11047 VOS_STATUS status;
11048
11049 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11050
11051 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11052 {
11053 pAdapter = pAdapterNode->pAdapter;
11054
11055 if( pAdapter && vos_mem_compare( pAdapter->macAddressCurrent.bytes,
11056 macAddr, sizeof(tSirMacAddr) ) )
11057 {
11058 return pAdapter;
11059 }
11060 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11061 pAdapterNode = pNext;
11062 }
11063
11064 return NULL;
11065
11066}
11067
11068hdd_adapter_t * hdd_get_adapter_by_name( hdd_context_t *pHddCtx, tANI_U8 *name )
11069{
11070 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11071 hdd_adapter_t *pAdapter;
11072 VOS_STATUS status;
11073
11074 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11075
11076 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11077 {
11078 pAdapter = pAdapterNode->pAdapter;
11079
11080 if( pAdapter && !strncmp( pAdapter->dev->name, (const char *)name,
11081 IFNAMSIZ ) )
11082 {
11083 return pAdapter;
11084 }
11085 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11086 pAdapterNode = pNext;
11087 }
11088
11089 return NULL;
11090
11091}
11092
Ganesh Kondabattinicbfdc392015-09-11 19:12:59 +053011093hdd_adapter_t *hdd_get_adapter_by_sme_session_id( hdd_context_t *pHddCtx,
11094 tANI_U32 sme_session_id )
11095{
11096 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11097 hdd_adapter_t *pAdapter;
11098 VOS_STATUS vos_status;
11099
11100
11101 vos_status = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
11102
11103 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == vos_status))
11104 {
11105 pAdapter = pAdapterNode->pAdapter;
11106
11107 if (pAdapter->sessionId == sme_session_id)
11108 return pAdapter;
11109
11110 vos_status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
11111 pAdapterNode = pNext;
11112 }
11113
11114 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
11115 "%s: sme_session_id %d does not exist with host",
11116 __func__, sme_session_id);
11117
11118 return NULL;
11119}
11120
Jeff Johnson295189b2012-06-20 16:38:30 -070011121hdd_adapter_t * hdd_get_adapter( hdd_context_t *pHddCtx, device_mode_t mode )
11122{
11123 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11124 hdd_adapter_t *pAdapter;
11125 VOS_STATUS status;
11126
11127 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11128
11129 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11130 {
11131 pAdapter = pAdapterNode->pAdapter;
11132
11133 if( pAdapter && (mode == pAdapter->device_mode) )
11134 {
11135 return pAdapter;
11136 }
11137 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11138 pAdapterNode = pNext;
11139 }
11140
11141 return NULL;
11142
11143}
11144
11145//Remove this function later
11146hdd_adapter_t * hdd_get_mon_adapter( hdd_context_t *pHddCtx )
11147{
11148 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11149 hdd_adapter_t *pAdapter;
11150 VOS_STATUS status;
11151
11152 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11153
11154 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11155 {
11156 pAdapter = pAdapterNode->pAdapter;
11157
11158 if( pAdapter && WLAN_HDD_MONITOR == pAdapter->device_mode )
11159 {
11160 return pAdapter;
11161 }
11162
11163 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11164 pAdapterNode = pNext;
11165 }
11166
11167 return NULL;
11168
11169}
11170
Jeff Johnson295189b2012-06-20 16:38:30 -070011171/**---------------------------------------------------------------------------
11172
Mahesh A Saptasgar64534612014-09-23 13:13:33 +053011173 \brief hdd_get_operating_channel() -
Jeff Johnson295189b2012-06-20 16:38:30 -070011174
11175 This API returns the operating channel of the requested device mode
11176
11177 \param - pHddCtx - Pointer to the HDD context.
11178 - mode - Device mode for which operating channel is required
11179 suported modes - WLAN_HDD_INFRA_STATION, WLAN_HDD_P2P_CLIENT
11180 WLAN_HDD_SOFTAP, WLAN_HDD_P2P_GO.
11181 \return - channel number. "0" id the requested device is not found OR it is not connected.
11182 --------------------------------------------------------------------------*/
11183v_U8_t hdd_get_operating_channel( hdd_context_t *pHddCtx, device_mode_t mode )
11184{
11185 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11186 VOS_STATUS status;
11187 hdd_adapter_t *pAdapter;
11188 v_U8_t operatingChannel = 0;
11189
11190 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11191
11192 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11193 {
11194 pAdapter = pAdapterNode->pAdapter;
11195
11196 if( mode == pAdapter->device_mode )
11197 {
11198 switch(pAdapter->device_mode)
11199 {
11200 case WLAN_HDD_INFRA_STATION:
11201 case WLAN_HDD_P2P_CLIENT:
11202 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
11203 operatingChannel = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.operationChannel;
11204 break;
11205 case WLAN_HDD_SOFTAP:
11206 case WLAN_HDD_P2P_GO:
11207 /*softap connection info */
11208 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
11209 operatingChannel = (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->operatingChannel;
11210 break;
11211 default:
11212 break;
11213 }
11214
11215 break; //Found the device of interest. break the loop
11216 }
11217
11218 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11219 pAdapterNode = pNext;
11220 }
11221 return operatingChannel;
11222}
11223
11224#ifdef WLAN_FEATURE_PACKET_FILTERING
11225/**---------------------------------------------------------------------------
11226
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011227 \brief __hdd_set_multicast_list() -
Jeff Johnson295189b2012-06-20 16:38:30 -070011228
11229 This used to set the multicast address list.
11230
11231 \param - dev - Pointer to the WLAN device.
11232 - skb - Pointer to OS packet (sk_buff).
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011233 \return - success/fail
Jeff Johnson295189b2012-06-20 16:38:30 -070011234
11235 --------------------------------------------------------------------------*/
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011236static void __hdd_set_multicast_list(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -070011237{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011238 hdd_adapter_t *pAdapter;
11239 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -070011240 int mc_count;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011241 int i = 0, ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011242 struct netdev_hw_addr *ha;
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011243
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011244 ENTER();
11245
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011246 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011247 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070011248 {
11249 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011250 "%s: Adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070011251 return;
11252 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011253 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11254 ret = wlan_hdd_validate_context(pHddCtx);
11255 if (0 != ret)
11256 {
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011257 return;
11258 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011259 if (dev->flags & IFF_ALLMULTI)
11260 {
11261 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011262 "%s: allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011263 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011264 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011265 else
Jeff Johnson295189b2012-06-20 16:38:30 -070011266 {
11267 mc_count = netdev_mc_count(dev);
11268 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011269 "%s: mc_count = %u", __func__, mc_count);
Jeff Johnson295189b2012-06-20 16:38:30 -070011270 if (mc_count > WLAN_HDD_MAX_MC_ADDR_LIST)
11271 {
11272 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011273 "%s: No free filter available; allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011274 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011275 return;
11276 }
11277
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011278 pAdapter->mc_addr_list.mc_cnt = mc_count;
Jeff Johnson295189b2012-06-20 16:38:30 -070011279
11280 netdev_for_each_mc_addr(ha, dev) {
11281 if (i == mc_count)
11282 break;
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011283 memset(&(pAdapter->mc_addr_list.addr[i][0]), 0, ETH_ALEN);
11284 memcpy(&(pAdapter->mc_addr_list.addr[i][0]), ha->addr, ETH_ALEN);
Arif Hussain6d2a3322013-11-17 19:50:10 -080011285 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mlist[%d] = "MAC_ADDRESS_STR,
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011286 __func__, i,
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011287 MAC_ADDR_ARRAY(pAdapter->mc_addr_list.addr[i]));
Jeff Johnson295189b2012-06-20 16:38:30 -070011288 i++;
11289 }
11290 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011291
Ganesh Kondabattinifb37e652015-10-09 15:46:47 +053011292 if (pHddCtx->hdd_wlan_suspended)
11293 {
11294 /*
11295 * Configure the Mcast address list to FW
11296 * If wlan is already in suspend mode
11297 */
11298 wlan_hdd_set_mc_addr_list(pAdapter, TRUE);
11299 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011300 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -070011301 return;
11302}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011303
11304static void hdd_set_multicast_list(struct net_device *dev)
11305{
11306 vos_ssr_protect(__func__);
11307 __hdd_set_multicast_list(dev);
11308 vos_ssr_unprotect(__func__);
11309}
Jeff Johnson295189b2012-06-20 16:38:30 -070011310#endif
11311
11312/**---------------------------------------------------------------------------
11313
11314 \brief hdd_select_queue() -
11315
11316 This function is registered with the Linux OS for network
11317 core to decide which queue to use first.
11318
11319 \param - dev - Pointer to the WLAN device.
11320 - skb - Pointer to OS packet (sk_buff).
11321 \return - ac, Queue Index/access category corresponding to UP in IP header
11322
11323 --------------------------------------------------------------------------*/
11324v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053011325 struct sk_buff *skb
11326#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
11327 , void *accel_priv
11328#endif
11329#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
11330 , select_queue_fallback_t fallback
11331#endif
11332)
Jeff Johnson295189b2012-06-20 16:38:30 -070011333{
11334 return hdd_wmm_select_queue(dev, skb);
11335}
11336
11337
11338/**---------------------------------------------------------------------------
11339
11340 \brief hdd_wlan_initial_scan() -
11341
11342 This function triggers the initial scan
11343
11344 \param - pAdapter - Pointer to the HDD adapter.
11345
11346 --------------------------------------------------------------------------*/
11347void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter)
11348{
11349 tCsrScanRequest scanReq;
11350 tCsrChannelInfo channelInfo;
11351 eHalStatus halStatus;
Jeff Johnson02797792013-10-26 19:17:13 -070011352 tANI_U32 scanId;
Jeff Johnson295189b2012-06-20 16:38:30 -070011353 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11354
11355 vos_mem_zero(&scanReq, sizeof(tCsrScanRequest));
11356 vos_mem_set(&scanReq.bssid, sizeof(tCsrBssid), 0xff);
11357 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
11358
11359 if(sme_Is11dSupported(pHddCtx->hHal))
11360 {
11361 halStatus = sme_ScanGetBaseChannels( pHddCtx->hHal, &channelInfo );
11362 if ( HAL_STATUS_SUCCESS( halStatus ) )
11363 {
11364 scanReq.ChannelInfo.ChannelList = vos_mem_malloc(channelInfo.numOfChannels);
11365 if( !scanReq.ChannelInfo.ChannelList )
11366 {
11367 hddLog(VOS_TRACE_LEVEL_ERROR, "%s kmalloc failed", __func__);
11368 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080011369 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011370 return;
11371 }
11372 vos_mem_copy(scanReq.ChannelInfo.ChannelList, channelInfo.ChannelList,
11373 channelInfo.numOfChannels);
11374 scanReq.ChannelInfo.numOfChannels = channelInfo.numOfChannels;
11375 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080011376 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011377 }
11378
11379 scanReq.scanType = eSIR_PASSIVE_SCAN;
11380 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
11381 scanReq.maxChnTime = pHddCtx->cfg_ini->nPassiveMaxChnTime;
11382 scanReq.minChnTime = pHddCtx->cfg_ini->nPassiveMinChnTime;
11383 }
11384 else
11385 {
11386 scanReq.scanType = eSIR_ACTIVE_SCAN;
11387 scanReq.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
11388 scanReq.maxChnTime = pHddCtx->cfg_ini->nActiveMaxChnTime;
11389 scanReq.minChnTime = pHddCtx->cfg_ini->nActiveMinChnTime;
11390 }
11391
11392 halStatus = sme_ScanRequest(pHddCtx->hHal, pAdapter->sessionId, &scanReq, &scanId, NULL, NULL);
11393 if ( !HAL_STATUS_SUCCESS( halStatus ) )
11394 {
11395 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_ScanRequest failed status code %d",
11396 __func__, halStatus );
11397 }
11398
11399 if(sme_Is11dSupported(pHddCtx->hHal))
11400 vos_mem_free(scanReq.ChannelInfo.ChannelList);
11401}
11402
Jeff Johnson295189b2012-06-20 16:38:30 -070011403/**---------------------------------------------------------------------------
11404
11405 \brief hdd_full_power_callback() - HDD full power callback function
11406
11407 This is the function invoked by SME to inform the result of a full power
11408 request issued by HDD
11409
11410 \param - callbackcontext - Pointer to cookie
11411 \param - status - result of request
11412
11413 \return - None
11414
11415 --------------------------------------------------------------------------*/
11416static void hdd_full_power_callback(void *callbackContext, eHalStatus status)
11417{
Jeff Johnson72a40512013-12-19 10:14:15 -080011418 struct statsContext *pContext = callbackContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011419
11420 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070011421 "%s: context = %pK, status = %d", __func__, pContext, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070011422
11423 if (NULL == callbackContext)
11424 {
11425 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070011426 "%s: Bad param, context [%pK]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011427 __func__, callbackContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070011428 return;
11429 }
11430
Jeff Johnson72a40512013-12-19 10:14:15 -080011431 /* there is a race condition that exists between this callback
11432 function and the caller since the caller could time out either
11433 before or while this code is executing. we use a spinlock to
11434 serialize these actions */
11435 spin_lock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011436
11437 if (POWER_CONTEXT_MAGIC != pContext->magic)
11438 {
11439 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -080011440 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011441 hddLog(VOS_TRACE_LEVEL_WARN,
11442 "%s: Invalid context, magic [%08x]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011443 __func__, pContext->magic);
Jeff Johnson295189b2012-06-20 16:38:30 -070011444 return;
11445 }
11446
Jeff Johnson72a40512013-12-19 10:14:15 -080011447 /* context is valid so caller is still waiting */
11448
11449 /* paranoia: invalidate the magic */
11450 pContext->magic = 0;
11451
11452 /* notify the caller */
Jeff Johnson295189b2012-06-20 16:38:30 -070011453 complete(&pContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -080011454
11455 /* serialization is complete */
11456 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011457}
11458
Katya Nigamf0511f62015-05-05 16:40:57 +053011459void wlan_hdd_mon_set_typesubtype( hdd_mon_ctx_t *pMonCtx,int type)
11460{
11461 pMonCtx->typeSubtypeBitmap = 0;
11462 if( type%10 ) /* Management Packets */
11463 pMonCtx->typeSubtypeBitmap |= 0xFFFF;
11464 type/=10;
11465 if( type%10 ) /* Control Packets */
11466 pMonCtx->typeSubtypeBitmap |= 0xFFFF0000;
11467 type/=10;
11468 if( type%10 ) /* Data Packets */
11469 pMonCtx->typeSubtypeBitmap |= 0xFFFF00000000;
11470}
11471
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011472VOS_STATUS wlan_hdd_mon_postMsg(tANI_U32 *magic, struct completion *cmpVar,
11473 hdd_mon_ctx_t *pMonCtx , void* callback)
Katya Nigamf0511f62015-05-05 16:40:57 +053011474{
11475 vos_msg_t monMsg;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011476 tSirMonModeReq *pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +053011477
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011478 if (MON_MODE_START == pMonCtx->state)
11479 monMsg.type = WDA_MON_START_REQ;
11480 else if (MON_MODE_STOP == pMonCtx->state)
11481 monMsg.type = WDA_MON_STOP_REQ;
11482 else {
11483 hddLog(VOS_TRACE_LEVEL_ERROR,
11484 FL("invalid monitor state %d"), pMonCtx->state);
Katya Nigamf0511f62015-05-05 16:40:57 +053011485 return VOS_STATUS_E_FAILURE;
11486 }
11487
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011488 pMonModeReq = vos_mem_malloc(sizeof(tSirMonModeReq));
11489 if (pMonModeReq == NULL) {
11490 hddLog(VOS_TRACE_LEVEL_ERROR,
11491 FL("fail to allocate memory for monitor mode req"));
11492 return VOS_STATUS_E_FAILURE;
11493 }
Katya Nigamf0511f62015-05-05 16:40:57 +053011494
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011495 pMonModeReq->magic = magic;
11496 pMonModeReq->cmpVar = cmpVar;
11497 pMonModeReq->data = pMonCtx;
11498 pMonModeReq->callback = callback;
Katya Nigamf0511f62015-05-05 16:40:57 +053011499
Katya Nigamf0511f62015-05-05 16:40:57 +053011500 monMsg.reserved = 0;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011501 monMsg.bodyptr = pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +053011502 monMsg.bodyval = 0;
11503
11504 if (VOS_STATUS_SUCCESS != vos_mq_post_message(
11505 VOS_MODULE_ID_WDA,(vos_msg_t *)&monMsg)) {
11506 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: : Failed to post Msg to HAL",__func__);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011507 vos_mem_free(pMonModeReq);
Katya Nigamf0511f62015-05-05 16:40:57 +053011508 }
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011509 return VOS_STATUS_SUCCESS;
Katya Nigamf0511f62015-05-05 16:40:57 +053011510}
11511
Katya Nigame7b69a82015-04-28 15:24:06 +053011512void wlan_hdd_mon_close(hdd_context_t *pHddCtx)
11513{
11514 VOS_STATUS vosStatus;
11515 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011516 long ret;
11517 hdd_mon_ctx_t *pMonCtx = NULL;
11518 v_U32_t magic;
11519 struct completion cmpVar;
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053011520
Katya Nigame7b69a82015-04-28 15:24:06 +053011521 hdd_adapter_t *pAdapter = hdd_get_adapter(pHddCtx,WLAN_HDD_MONITOR);
11522 if(pAdapter == NULL || pVosContext == NULL)
11523 {
11524 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:pAdapter is NULL",__func__);
11525 return ;
11526 }
Katya Nigamf0511f62015-05-05 16:40:57 +053011527
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053011528 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
11529 if (pMonCtx!= NULL && pMonCtx->state == MON_MODE_START) {
11530 pMonCtx->state = MON_MODE_STOP;
11531 magic = MON_MODE_MSG_MAGIC;
11532 init_completion(&cmpVar);
11533 if (VOS_STATUS_SUCCESS !=
11534 wlan_hdd_mon_postMsg(&magic, &cmpVar,
11535 pMonCtx, hdd_monPostMsgCb)) {
11536 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
11537 FL("failed to post MON MODE REQ"));
11538 pMonCtx->state = MON_MODE_START;
11539 magic = 0;
11540 return;
11541 }
11542 ret = wait_for_completion_timeout(&cmpVar, MON_MODE_MSG_TIMEOUT);
11543 magic = 0;
11544 if (ret <= 0 ) {
11545 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
11546 FL("timeout on monitor mode completion %ld"), ret);
11547 }
11548 }
11549
Katya Nigame7b69a82015-04-28 15:24:06 +053011550 hdd_UnregisterWext(pAdapter->dev);
11551
11552 vos_mon_stop( pVosContext );
11553
11554 vosStatus = vos_sched_close( pVosContext );
11555 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
11556 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
11557 "%s: Failed to close VOSS Scheduler",__func__);
11558 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
11559 }
11560
11561 vosStatus = vos_nv_close();
11562 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
11563 {
11564 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11565 "%s: Failed to close NV", __func__);
11566 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
11567 }
11568
11569 vos_close(pVosContext);
11570
11571 #ifdef WLAN_KD_READY_NOTIFIER
11572 nl_srv_exit(pHddCtx->ptt_pid);
11573 #else
11574 nl_srv_exit();
11575 #endif
11576
Katya Nigame7b69a82015-04-28 15:24:06 +053011577 hdd_close_all_adapters( pHddCtx );
Katya Nigame7b69a82015-04-28 15:24:06 +053011578}
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053011579/**
11580 * hdd_wlan_free_wiphy_channels - free Channel pointer for wiphy
11581 * @ wiphy: the wiphy to validate against
11582 *
11583 * Return: void
11584 */
11585void hdd_wlan_free_wiphy_channels(struct wiphy *wiphy)
11586{
11587 int i =0;
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011588 for (i = 0; i < HDD_NUM_NL80211_BANDS; i++)
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053011589 {
11590 if (NULL != wiphy->bands[i] &&
11591 (NULL != wiphy->bands[i]->channels))
11592 {
11593 vos_mem_free(wiphy->bands[i]->channels);
11594 wiphy->bands[i]->channels = NULL;
11595 }
11596 }
11597}
Jeff Johnson295189b2012-06-20 16:38:30 -070011598/**---------------------------------------------------------------------------
11599
11600 \brief hdd_wlan_exit() - HDD WLAN exit function
11601
11602 This is the driver exit point (invoked during rmmod)
11603
11604 \param - pHddCtx - Pointer to the HDD Context
11605
11606 \return - None
11607
11608 --------------------------------------------------------------------------*/
11609void hdd_wlan_exit(hdd_context_t *pHddCtx)
11610{
11611 eHalStatus halStatus;
11612 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
11613 VOS_STATUS vosStatus;
Gopichand Nakkala66923aa2013-03-06 23:17:24 +053011614 struct wiphy *wiphy = pHddCtx->wiphy;
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080011615 hdd_adapter_t* pAdapter = NULL;
Jeff Johnson72a40512013-12-19 10:14:15 -080011616 struct statsContext powerContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011617 long lrc;
c_hpothu5ab05e92014-06-13 17:34:05 +053011618 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011619
11620 ENTER();
11621
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053011622
Katya Nigame7b69a82015-04-28 15:24:06 +053011623 if (VOS_MONITOR_MODE == hdd_get_conparam())
11624 {
11625 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: MONITOR MODE",__func__);
11626 wlan_hdd_mon_close(pHddCtx);
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053011627 goto free_hdd_ctx;
Katya Nigame7b69a82015-04-28 15:24:06 +053011628 }
11629 else if (VOS_FTM_MODE != hdd_get_conparam())
Jeff Johnson88ba7742013-02-27 14:36:02 -080011630 {
11631 // Unloading, restart logic is no more required.
11632 wlan_hdd_restart_deinit(pHddCtx);
Jeff Johnsone7245742012-09-05 17:12:55 -070011633
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053011634#ifdef FEATURE_WLAN_TDLS
11635 /* At the time of driver unloading; if tdls connection is present;
11636 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer.
11637 * wlan_hdd_tdls_find_peer always checks for valid context;
11638 * as load/unload in progress there can be a race condition.
11639 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer only
11640 * when tdls state is enabled.
11641 * As soon as driver set load/unload flag; tdls flag also needs
11642 * to be disabled so that hdd_rx_packet_cbk won't call
11643 * wlan_hdd_tdls_find_peer.
11644 */
Masti, Narayanraddi20494af2015-12-17 20:56:42 +053011645 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE,
11646 HDD_SET_TDLS_MODE_SOURCE_USER);
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053011647#endif
11648
c_hpothu5ab05e92014-06-13 17:34:05 +053011649 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11650 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
Jeff Johnson295189b2012-06-20 16:38:30 -070011651 {
c_hpothu5ab05e92014-06-13 17:34:05 +053011652 pAdapter = pAdapterNode->pAdapter;
11653 if (NULL != pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070011654 {
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +053011655 /* Disable TX on the interface, after this hard_start_xmit() will
11656 * not be called on that interface
11657 */
11658 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
11659 netif_tx_disable(pAdapter->dev);
11660
11661 /* Mark the interface status as "down" for outside world */
11662 netif_carrier_off(pAdapter->dev);
11663
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053011664 /* DeInit the adapter. This ensures that all data packets
11665 * are freed.
11666 */
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053011667#ifdef FEATURE_WLAN_TDLS
11668 mutex_lock(&pHddCtx->tdls_lock);
11669#endif
c_hpothu002231a2015-02-05 14:58:51 +053011670 hdd_deinit_adapter(pHddCtx, pAdapter, FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053011671#ifdef FEATURE_WLAN_TDLS
11672 mutex_unlock(&pHddCtx->tdls_lock);
11673#endif
Masti, Narayanraddi26378462016-01-05 18:20:28 +053011674 vos_flush_delayed_work(&pHddCtx->scan_ctxt.scan_work);
11675
11676 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053011677
c_hpothu5ab05e92014-06-13 17:34:05 +053011678 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053011679 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
11680 WLAN_HDD_MONITOR == pAdapter->device_mode)
c_hpothu5ab05e92014-06-13 17:34:05 +053011681 {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053011682 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
11683 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
11684 wlan_hdd_cfg80211_deregister_frames(pAdapter);
11685
c_hpothu5ab05e92014-06-13 17:34:05 +053011686 hdd_UnregisterWext(pAdapter->dev);
11687 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +053011688
Jeff Johnson295189b2012-06-20 16:38:30 -070011689 }
c_hpothu5ab05e92014-06-13 17:34:05 +053011690 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11691 pAdapterNode = pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011692 }
mukul sharmabab477d2015-06-11 17:14:55 +053011693
Kaushik, Sushant4975a572014-10-21 16:07:48 +053011694 // Cancel any outstanding scan requests. We are about to close all
11695 // of our adapters, but an adapter structure is what SME passes back
11696 // to our callback function. Hence if there are any outstanding scan
11697 // requests then there is a race condition between when the adapter
11698 // is closed and when the callback is invoked.We try to resolve that
11699 // race condition here by canceling any outstanding scans before we
11700 // close the adapters.
11701 // Note that the scans may be cancelled in an asynchronous manner,
11702 // so ideally there needs to be some kind of synchronization. Rather
11703 // than introduce a new synchronization here, we will utilize the
11704 // fact that we are about to Request Full Power, and since that is
11705 // synchronized, the expectation is that by the time Request Full
11706 // Power has completed all scans will be cancelled.
11707 if (pHddCtx->scan_info.mScanPending)
11708 {
Hema Aparna Medicharlaf05f6cd2015-01-21 14:44:19 +053011709 if(NULL != pAdapter)
11710 {
11711 hddLog(VOS_TRACE_LEVEL_INFO,
11712 FL("abort scan mode: %d sessionId: %d"),
11713 pAdapter->device_mode,
11714 pAdapter->sessionId);
11715 }
11716 hdd_abort_mac_scan(pHddCtx,
11717 pHddCtx->scan_info.sessionId,
11718 eCSR_SCAN_ABORT_DEFAULT);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053011719 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011720 }
c_hpothu5ab05e92014-06-13 17:34:05 +053011721 else
Jeff Johnson88ba7742013-02-27 14:36:02 -080011722 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011723 hddLog(VOS_TRACE_LEVEL_INFO,"%s: FTM MODE",__func__);
Hanumantha Reddy Pothula45af96b2015-02-12 16:07:58 +053011724 if (pHddCtx->ftm.ftm_state == WLAN_FTM_STARTING)
11725 {
11726 INIT_COMPLETION(pHddCtx->ftm.startCmpVar);
11727 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
11728 "%s: in middle of FTM START", __func__);
11729 lrc = wait_for_completion_timeout(&pHddCtx->ftm.startCmpVar,
11730 msecs_to_jiffies(20000));
11731 if(!lrc)
11732 {
11733 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
11734 "%s: timedout on ftmStartCmpVar fatal error", __func__);
11735 }
11736 }
Jeff Johnson88ba7742013-02-27 14:36:02 -080011737 wlan_hdd_ftm_close(pHddCtx);
11738 goto free_hdd_ctx;
11739 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011740
Jeff Johnson295189b2012-06-20 16:38:30 -070011741 /* DeRegister with platform driver as client for Suspend/Resume */
11742 vosStatus = hddDeregisterPmOps(pHddCtx);
11743 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
11744 {
11745 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDeregisterPmOps failed",__func__);
11746 VOS_ASSERT(0);
11747 }
11748
11749 vosStatus = hddDevTmUnregisterNotifyCallback(pHddCtx);
11750 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
11751 {
11752 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
11753 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011754
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070011755 //Stop the traffic monitor timer
Mahesh A Saptasagard461e432016-07-20 15:01:40 +053011756 if ((pHddCtx->cfg_ini->dynSplitscan) && (VOS_TIMER_STATE_RUNNING ==
11757 vos_timer_getCurrentState(&pHddCtx->tx_rx_trafficTmr)))
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070011758 {
11759 vos_timer_stop(&pHddCtx->tx_rx_trafficTmr);
11760 }
11761
11762 // Destroy the traffic monitor timer
Mahesh A Saptasagard461e432016-07-20 15:01:40 +053011763 if ((pHddCtx->cfg_ini->dynSplitscan) &&
11764 (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
11765 &pHddCtx->tx_rx_trafficTmr))))
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070011766 {
11767 hddLog(VOS_TRACE_LEVEL_ERROR,
11768 "%s: Cannot deallocate Traffic monitor timer", __func__);
11769 }
11770
Bhargav Shahd0715912015-10-01 18:17:37 +053011771 if (VOS_TIMER_STATE_RUNNING ==
11772 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
11773 vos_timer_stop(&pHddCtx->delack_timer);
11774 }
11775
11776 if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
11777 &pHddCtx->delack_timer))) {
11778 hddLog(VOS_TRACE_LEVEL_ERROR,
11779 "%s: Cannot deallocate Bus bandwidth timer", __func__);
11780 }
11781
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053011782 if (VOS_TIMER_STATE_RUNNING ==
11783 vos_timer_getCurrentState(&pHddCtx->tdls_source_timer)) {
11784 vos_timer_stop(&pHddCtx->tdls_source_timer);
11785 }
11786
Abhishek Singh8a3e4dc2017-01-02 10:39:18 +053011787 vos_set_snoc_high_freq_voting(false);
11788
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053011789 vos_timer_destroy(&pHddCtx->tdls_source_timer);
11790
Jeff Johnson295189b2012-06-20 16:38:30 -070011791 //Disable IMPS/BMPS as we do not want the device to enter any power
11792 //save mode during shutdown
11793 sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
11794 sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
11795 sme_DisablePowerSave(pHddCtx->hHal, ePMC_UAPSD_MODE_POWER_SAVE);
11796
11797 //Ensure that device is in full power as we will touch H/W during vos_Stop
11798 init_completion(&powerContext.completion);
11799 powerContext.magic = POWER_CONTEXT_MAGIC;
11800
11801 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_power_callback,
11802 &powerContext, eSME_FULL_PWR_NEEDED_BY_HDD);
11803
11804 if (eHAL_STATUS_SUCCESS != halStatus)
11805 {
11806 if (eHAL_STATUS_PMC_PENDING == halStatus)
11807 {
11808 /* request was sent -- wait for the response */
11809 lrc = wait_for_completion_interruptible_timeout(
11810 &powerContext.completion,
11811 msecs_to_jiffies(WLAN_WAIT_TIME_POWER));
Jeff Johnson295189b2012-06-20 16:38:30 -070011812 if (lrc <= 0)
11813 {
11814 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: %s while requesting full power",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011815 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson295189b2012-06-20 16:38:30 -070011816 }
11817 }
11818 else
11819 {
11820 hddLog(VOS_TRACE_LEVEL_ERROR,
11821 "%s: Request for Full Power failed, status %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011822 __func__, halStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -070011823 /* continue -- need to clean up as much as possible */
11824 }
11825 }
Hanumantha Reddy Pothula81b42b22015-05-12 13:52:00 +053011826 if ((eHAL_STATUS_SUCCESS == halStatus) ||
11827 (eHAL_STATUS_PMC_PENDING == halStatus && lrc > 0))
11828 {
11829 /* This will issue a dump command which will clean up
11830 BTQM queues and unblock MC thread */
11831 vos_fwDumpReq(274, 0, 0, 0, 0, 1);
11832 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011833
Jeff Johnson72a40512013-12-19 10:14:15 -080011834 /* either we never sent a request, we sent a request and received a
11835 response or we sent a request and timed out. if we never sent a
11836 request or if we sent a request and got a response, we want to
11837 clear the magic out of paranoia. if we timed out there is a
11838 race condition such that the callback function could be
11839 executing at the same time we are. of primary concern is if the
11840 callback function had already verified the "magic" but had not
11841 yet set the completion variable when a timeout occurred. we
11842 serialize these activities by invalidating the magic while
11843 holding a shared spinlock which will cause us to block if the
11844 callback is currently executing */
11845 spin_lock(&hdd_context_lock);
11846 powerContext.magic = 0;
11847 spin_unlock(&hdd_context_lock);
11848
Hema Aparna Medicharlaa6cf65e2015-06-01 16:23:28 +053011849 /* If Device is shutdown, no point for SME to wait for responses
11850 from device. Pre Close SME */
11851 if(wcnss_device_is_shutdown())
11852 {
11853 sme_PreClose(pHddCtx->hHal);
11854 }
Yue Ma0d4891e2013-08-06 17:01:45 -070011855 hdd_debugfs_exit(pHddCtx);
11856
Ratheesh S P35ed8b12015-04-27 14:01:07 +053011857#ifdef WLAN_NS_OFFLOAD
Ratheesh S P36dbc932015-08-07 14:28:57 +053011858 hddLog(LOG1, FL("Unregister IPv6 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053011859 unregister_inet6addr_notifier(&pHddCtx->ipv6_notifier);
11860#endif
Ratheesh S P36dbc932015-08-07 14:28:57 +053011861 hddLog(LOG1, FL("Unregister IPv4 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053011862 unregister_inetaddr_notifier(&pHddCtx->ipv4_notifier);
11863
Jeff Johnson295189b2012-06-20 16:38:30 -070011864 // Unregister the Net Device Notifier
11865 unregister_netdevice_notifier(&hdd_netdev_notifier);
11866
Jeff Johnson295189b2012-06-20 16:38:30 -070011867 hdd_stop_all_adapters( pHddCtx );
11868
Jeff Johnson295189b2012-06-20 16:38:30 -070011869#ifdef WLAN_BTAMP_FEATURE
11870 vosStatus = WLANBAP_Stop(pVosContext);
11871 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
11872 {
11873 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11874 "%s: Failed to stop BAP",__func__);
11875 }
11876#endif //WLAN_BTAMP_FEATURE
11877
11878 //Stop all the modules
11879 vosStatus = vos_stop( pVosContext );
11880 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
11881 {
11882 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
11883 "%s: Failed to stop VOSS",__func__);
11884 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053011885 if (isSsrPanicOnFailure())
11886 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -070011887 }
11888
Jeff Johnson295189b2012-06-20 16:38:30 -070011889 //This requires pMac access, Call this before vos_close().
Jeff Johnson295189b2012-06-20 16:38:30 -070011890 hdd_unregister_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070011891
11892 //Close the scheduler before calling vos_close to make sure no thread is
11893 // scheduled after the each module close is called i.e after all the data
11894 // structures are freed.
11895 vosStatus = vos_sched_close( pVosContext );
11896 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
11897 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
11898 "%s: Failed to close VOSS Scheduler",__func__);
11899 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
11900 }
Jeff Johnsone7245742012-09-05 17:12:55 -070011901#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
11902 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053011903 vos_wake_lock_destroy(&pHddCtx->rx_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -070011904#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080011905 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053011906 vos_wake_lock_destroy(&pHddCtx->sap_wake_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011907
Mihir Shete7a24b5f2013-12-21 12:18:31 +053011908#ifdef CONFIG_ENABLE_LINUX_REG
11909 vosStatus = vos_nv_close();
11910 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
11911 {
11912 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11913 "%s: Failed to close NV", __func__);
11914 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
11915 }
11916#endif
11917
Jeff Johnson295189b2012-06-20 16:38:30 -070011918 //Close VOSS
11919 //This frees pMac(HAL) context. There should not be any call that requires pMac access after this.
11920 vos_close(pVosContext);
11921
Jeff Johnson295189b2012-06-20 16:38:30 -070011922 //Close Watchdog
11923 if(pHddCtx->cfg_ini->fIsLogpEnabled)
11924 vos_watchdog_close(pVosContext);
11925
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053011926 //Clean up HDD Nlink Service
11927 send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0);
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053011928
Manjeet Singh47ee8472016-04-11 11:57:18 +053011929 hdd_close_tx_queues(pHddCtx);
c_manjeecfd1efb2015-09-25 19:32:34 +053011930 wlan_free_fwr_mem_dump_buffer();
11931 memdump_deinit();
11932
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053011933#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053011934 if (pHddCtx->cfg_ini->wlanLoggingEnable)
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053011935 {
11936 wlan_logging_sock_deactivate_svc();
11937 }
11938#endif
11939
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053011940#ifdef WLAN_KD_READY_NOTIFIER
11941 nl_srv_exit(pHddCtx->ptt_pid);
11942#else
11943 nl_srv_exit();
11944#endif /* WLAN_KD_READY_NOTIFIER */
11945
Abhishek Singh00b71972016-01-07 10:51:04 +053011946#ifdef WLAN_FEATURE_RMC
11947 hdd_close_cesium_nl_sock();
11948#endif /* WLAN_FEATURE_RMC */
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053011949
Jeff Johnson295189b2012-06-20 16:38:30 -070011950 hdd_close_all_adapters( pHddCtx );
11951
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053011952 vos_flush_delayed_work(&pHddCtx->spoof_mac_addr_work);
Abhishek Singh78c691f2017-11-30 13:48:44 +053011953 vos_flush_delayed_work(&pHddCtx->ecsa_chan_change_work);
Kapil Gupta137ef892016-12-13 19:38:00 +053011954 vos_flush_work(&pHddCtx->sap_start_work);
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053011955
Hanumantha Reddy Pothula97f9bc92015-08-10 17:21:20 +053011956free_hdd_ctx:
Jeff Johnson295189b2012-06-20 16:38:30 -070011957 /* free the power on lock from platform driver */
11958 if (free_riva_power_on_lock("wlan"))
11959 {
11960 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to free power on lock",
11961 __func__);
11962 }
11963
c_hpothu78c7b602014-05-17 17:35:49 +053011964 //Free up dynamically allocated members inside HDD Adapter
11965 if (pHddCtx->cfg_ini)
11966 {
11967 kfree(pHddCtx->cfg_ini);
11968 pHddCtx->cfg_ini= NULL;
11969 }
11970
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053011971 hdd_request_manager_deinit();
11972
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053011973 /* FTM/MONITOR mode, WIPHY did not registered
Leo Changf04ddad2013-09-18 13:46:38 -070011974 If un-register here, system crash will happen */
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053011975 if (!(VOS_FTM_MODE == hdd_get_conparam() ||
11976 VOS_MONITOR_MODE == hdd_get_conparam()))
Leo Changf04ddad2013-09-18 13:46:38 -070011977 {
11978 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053011979 hdd_wlan_free_wiphy_channels(wiphy);
Leo Changf04ddad2013-09-18 13:46:38 -070011980 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011981 wiphy_free(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070011982 if (hdd_is_ssr_required())
11983 {
11984 /* WDI timeout had happened during unload, so SSR is needed here */
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -070011985 subsystem_restart("wcnss");
Jeff Johnson295189b2012-06-20 16:38:30 -070011986 msleep(5000);
11987 }
11988 hdd_set_ssr_required (VOS_FALSE);
11989}
11990
11991
11992/**---------------------------------------------------------------------------
11993
11994 \brief hdd_update_config_from_nv() - Function to update the contents of
11995 the running configuration with parameters taken from NV storage
11996
11997 \param - pHddCtx - Pointer to the HDD global context
11998
11999 \return - VOS_STATUS_SUCCESS if successful
12000
12001 --------------------------------------------------------------------------*/
12002static VOS_STATUS hdd_update_config_from_nv(hdd_context_t* pHddCtx)
12003{
Jeff Johnson295189b2012-06-20 16:38:30 -070012004 v_BOOL_t itemIsValid = VOS_FALSE;
12005 VOS_STATUS status;
12006 v_MACADDR_t macFromNV[VOS_MAX_CONCURRENCY_PERSONA];
12007 v_U8_t macLoop;
12008
12009 /*If the NV is valid then get the macaddress from nv else get it from qcom_cfg.ini*/
12010 status = vos_nv_getValidity(VNV_FIELD_IMAGE, &itemIsValid);
12011 if(status != VOS_STATUS_SUCCESS)
12012 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080012013 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_getValidity() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070012014 return VOS_STATUS_E_FAILURE;
12015 }
12016
12017 if (itemIsValid == VOS_TRUE)
12018 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080012019 hddLog(VOS_TRACE_LEVEL_INFO_HIGH," Reading the Macaddress from NV");
Jeff Johnson295189b2012-06-20 16:38:30 -070012020 status = vos_nv_readMultiMacAddress((v_U8_t *)&macFromNV[0].bytes[0],
12021 VOS_MAX_CONCURRENCY_PERSONA);
12022 if(status != VOS_STATUS_SUCCESS)
12023 {
12024 /* Get MAC from NV fail, not update CFG info
12025 * INI MAC value will be used for MAC setting */
Arif Hussain6d2a3322013-11-17 19:50:10 -080012026 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_readMacAddress() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070012027 return VOS_STATUS_E_FAILURE;
12028 }
12029
12030 /* If first MAC is not valid, treat all others are not valid
12031 * Then all MACs will be got from ini file */
12032 if(vos_is_macaddr_zero(&macFromNV[0]))
12033 {
12034 /* MAC address in NV file is not configured yet */
12035 hddLog(VOS_TRACE_LEVEL_WARN, "Invalid MAC in NV file");
12036 return VOS_STATUS_E_INVAL;
12037 }
12038
12039 /* Get MAC address from NV, update CFG info */
12040 for(macLoop = 0; macLoop < VOS_MAX_CONCURRENCY_PERSONA; macLoop++)
12041 {
12042 if(vos_is_macaddr_zero(&macFromNV[macLoop]))
12043 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012044 hddLog(VOS_TRACE_LEVEL_ERROR,"not valid MAC from NV for %d", macLoop);
Jeff Johnson295189b2012-06-20 16:38:30 -070012045 /* This MAC is not valid, skip it
12046 * This MAC will be got from ini file */
12047 }
12048 else
12049 {
12050 vos_mem_copy((v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[macLoop].bytes[0],
12051 (v_U8_t *)&macFromNV[macLoop].bytes[0],
12052 VOS_MAC_ADDR_SIZE);
12053 }
12054 }
12055 }
12056 else
12057 {
12058 hddLog(VOS_TRACE_LEVEL_ERROR, "NV ITEM, MAC Not valid");
12059 return VOS_STATUS_E_FAILURE;
12060 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012061
Jeff Johnson295189b2012-06-20 16:38:30 -070012062
12063 return VOS_STATUS_SUCCESS;
12064}
12065
12066/**---------------------------------------------------------------------------
12067
12068 \brief hdd_post_voss_start_config() - HDD post voss start config helper
12069
12070 \param - pAdapter - Pointer to the HDD
12071
12072 \return - None
12073
12074 --------------------------------------------------------------------------*/
12075VOS_STATUS hdd_post_voss_start_config(hdd_context_t* pHddCtx)
12076{
12077 eHalStatus halStatus;
12078 v_U32_t listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012079 tANI_U32 ignoreDtim;
Jeff Johnson295189b2012-06-20 16:38:30 -070012080
Jeff Johnson295189b2012-06-20 16:38:30 -070012081
12082 // Send ready indication to the HDD. This will kick off the MAC
12083 // into a 'running' state and should kick off an initial scan.
12084 halStatus = sme_HDDReadyInd( pHddCtx->hHal );
12085 if ( !HAL_STATUS_SUCCESS( halStatus ) )
12086 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +053012087 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: sme_HDDReadyInd() failed with status "
Jeff Johnson295189b2012-06-20 16:38:30 -070012088 "code %08d [x%08x]",__func__, halStatus, halStatus );
12089 return VOS_STATUS_E_FAILURE;
12090 }
12091
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012092 // Set default LI and ignoreDtim into HDD context,
Jeff Johnson295189b2012-06-20 16:38:30 -070012093 // otherwise under some race condition, HDD will set 0 LI value into RIVA,
12094 // And RIVA will crash
12095 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, &listenInterval);
12096 pHddCtx->hdd_actual_LI_value = listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012097 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, &ignoreDtim);
12098 pHddCtx->hdd_actual_ignore_DTIM_value = ignoreDtim;
12099
12100
Jeff Johnson295189b2012-06-20 16:38:30 -070012101 return VOS_STATUS_SUCCESS;
12102}
12103
Jeff Johnson295189b2012-06-20 16:38:30 -070012104/* wake lock APIs for HDD */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012105void hdd_prevent_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070012106{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012107
12108 vos_wake_lock_acquire(&wlan_wake_lock, reason);
12109
Jeff Johnson295189b2012-06-20 16:38:30 -070012110}
12111
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012112void hdd_allow_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070012113{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012114
12115 vos_wake_lock_release(&wlan_wake_lock, reason);
12116
Jeff Johnson295189b2012-06-20 16:38:30 -070012117}
12118
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012119void hdd_prevent_suspend_timeout(v_U32_t timeout, uint32_t reason)
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070012120{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012121
12122 vos_wake_lock_timeout_release(&wlan_wake_lock, timeout,
12123 reason);
12124
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070012125}
12126
Jeff Johnson295189b2012-06-20 16:38:30 -070012127/**---------------------------------------------------------------------------
12128
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012129 \brief hdd_exchange_version_and_caps() - HDD function to exchange version and capability
12130 information between Host and Riva
12131
12132 This function gets reported version of FW
12133 It also finds the version of Riva headers used to compile the host
12134 It compares the above two and prints a warning if they are different
12135 It gets the SW and HW version string
12136 Finally, it exchanges capabilities between host and Riva i.e. host and riva exchange a msg
12137 indicating the features they support through a bitmap
12138
12139 \param - pHddCtx - Pointer to HDD context
12140
12141 \return - void
12142
12143 --------------------------------------------------------------------------*/
12144
12145void hdd_exchange_version_and_caps(hdd_context_t *pHddCtx)
12146{
12147
12148 tSirVersionType versionCompiled;
12149 tSirVersionType versionReported;
12150 tSirVersionString versionString;
12151 tANI_U8 fwFeatCapsMsgSupported = 0;
12152 VOS_STATUS vstatus;
12153
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080012154 memset(&versionCompiled, 0, sizeof(versionCompiled));
12155 memset(&versionReported, 0, sizeof(versionReported));
12156
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012157 /* retrieve and display WCNSS version information */
12158 do {
12159
12160 vstatus = sme_GetWcnssWlanCompiledVersion(pHddCtx->hHal,
12161 &versionCompiled);
12162 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12163 {
12164 hddLog(VOS_TRACE_LEVEL_FATAL,
12165 "%s: unable to retrieve WCNSS WLAN compiled version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012166 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012167 break;
12168 }
12169
12170 vstatus = sme_GetWcnssWlanReportedVersion(pHddCtx->hHal,
12171 &versionReported);
12172 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12173 {
12174 hddLog(VOS_TRACE_LEVEL_FATAL,
12175 "%s: unable to retrieve WCNSS WLAN reported version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012176 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012177 break;
12178 }
12179
12180 if ((versionCompiled.major != versionReported.major) ||
12181 (versionCompiled.minor != versionReported.minor) ||
12182 (versionCompiled.version != versionReported.version) ||
12183 (versionCompiled.revision != versionReported.revision))
12184 {
12185 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
12186 "Host expected %u.%u.%u.%u\n",
12187 WLAN_MODULE_NAME,
12188 (int)versionReported.major,
12189 (int)versionReported.minor,
12190 (int)versionReported.version,
12191 (int)versionReported.revision,
12192 (int)versionCompiled.major,
12193 (int)versionCompiled.minor,
12194 (int)versionCompiled.version,
12195 (int)versionCompiled.revision);
12196 }
12197 else
12198 {
12199 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
12200 WLAN_MODULE_NAME,
12201 (int)versionReported.major,
12202 (int)versionReported.minor,
12203 (int)versionReported.version,
12204 (int)versionReported.revision);
12205 }
12206
12207 vstatus = sme_GetWcnssSoftwareVersion(pHddCtx->hHal,
12208 versionString,
12209 sizeof(versionString));
12210 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12211 {
12212 hddLog(VOS_TRACE_LEVEL_FATAL,
12213 "%s: unable to retrieve WCNSS software version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012214 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012215 break;
12216 }
12217
12218 pr_info("%s: WCNSS software version %s\n",
12219 WLAN_MODULE_NAME, versionString);
Sushant Kaushik084f6592015-09-10 13:11:56 +053012220 vos_mem_copy(pHddCtx->fw_Version, versionString, sizeof(versionString));
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012221
12222 vstatus = sme_GetWcnssHardwareVersion(pHddCtx->hHal,
12223 versionString,
12224 sizeof(versionString));
12225 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12226 {
12227 hddLog(VOS_TRACE_LEVEL_FATAL,
12228 "%s: unable to retrieve WCNSS hardware version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012229 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012230 break;
12231 }
12232
12233 pr_info("%s: WCNSS hardware version %s\n",
12234 WLAN_MODULE_NAME, versionString);
12235
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012236 /* 1.Check if FW version is greater than 0.1.1.0. Only then send host-FW capability exchange message
12237 2.Host-FW capability exchange message is only present on riva 1.1 so
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012238 send the message only if it the riva is 1.1
12239 minor numbers for different riva branches:
12240 0 -> (1.0)Mainline Build
12241 1 -> (1.1)Mainline Build
12242 2->(1.04) Stability Build
12243 */
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012244 if (((versionReported.major>0) || (versionReported.minor>1) ||
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012245 ((versionReported.minor>=1) && (versionReported.version>=1)))
12246 && ((versionReported.major == 1) && (versionReported.minor >= 1)))
12247 fwFeatCapsMsgSupported = 1;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012248
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012249 if (fwFeatCapsMsgSupported)
Yathish9f22e662012-12-10 14:21:35 -080012250 {
12251#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
12252 if(!pHddCtx->cfg_ini->fEnableActiveModeOffload)
12253 sme_disableFeatureCapablity(WLANACTIVE_OFFLOAD);
12254#endif
Ravi Joshid2ca7c42013-07-23 08:37:49 -070012255 /* Indicate if IBSS heartbeat monitoring needs to be offloaded */
12256 if (!pHddCtx->cfg_ini->enableIbssHeartBeatOffload)
12257 {
12258 sme_disableFeatureCapablity(IBSS_HEARTBEAT_OFFLOAD);
12259 }
12260
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012261 sme_featureCapsExchange(pHddCtx->hHal);
Yathish9f22e662012-12-10 14:21:35 -080012262 }
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012263
12264 } while (0);
12265
12266}
Neelansh Mittaledafed22014-09-04 18:54:39 +053012267void wlan_hdd_send_svc_nlink_msg(int type, void *data, int len)
12268{
12269 struct sk_buff *skb;
12270 struct nlmsghdr *nlh;
12271 tAniMsgHdr *ani_hdr;
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053012272 int flags = GFP_KERNEL;
Bhargav shah23c94942015-10-13 12:48:35 +053012273 void *nl_data = NULL;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012274
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053012275 if (in_interrupt() || irqs_disabled() || in_atomic())
12276 flags = GFP_ATOMIC;
12277
12278 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
Neelansh Mittaledafed22014-09-04 18:54:39 +053012279
12280 if(skb == NULL) {
12281 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12282 "%s: alloc_skb failed", __func__);
12283 return;
12284 }
12285
12286 nlh = (struct nlmsghdr *)skb->data;
12287 nlh->nlmsg_pid = 0; /* from kernel */
12288 nlh->nlmsg_flags = 0;
12289 nlh->nlmsg_seq = 0;
12290 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12291
12292 ani_hdr = NLMSG_DATA(nlh);
12293 ani_hdr->type = type;
12294
12295 switch(type) {
12296 case WLAN_SVC_SAP_RESTART_IND:
12297 ani_hdr->length = 0;
12298 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
12299 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr)));
12300 break;
Bhargav Shahd0715912015-10-01 18:17:37 +053012301 case WLAN_SVC_WLAN_TP_IND:
12302 ani_hdr->length = len;
12303 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)
12304 + len));
12305 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12306 memcpy(nl_data, data, len);
12307 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
12308 break;
Bhargav shah23c94942015-10-13 12:48:35 +053012309 case WLAN_MSG_RPS_ENABLE_IND:
12310 ani_hdr->length = len;
12311 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12312 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12313 memcpy(nl_data, data, len);
12314 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
12315 break;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012316 default:
12317 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12318 "Attempt to send unknown nlink message %d", type);
12319 kfree_skb(skb);
12320 return;
12321 }
12322
12323 nl_srv_bcast(skb);
12324
12325 return;
12326}
12327
Bhargav Shahd0715912015-10-01 18:17:37 +053012328/**
12329 * hdd_request_tcp_delack() - Find the Delack value based on RX packet
12330 * @pHddCtx: Valid Global HDD context pointer
12331 * @rx_packets: Number of RX packet in perticular time
12332 *
12333 * Based on the RX packet this function calculate next value of tcp delack.
12334 * This function compare rx packet value to high and low threshold limit.
12335 *
12336 * Return: void
12337 */
12338void hdd_request_tcp_delack(hdd_context_t *pHddCtx, uint64_t rx_packets)
12339{
12340 /* average of rx_packets and prev_rx is taken so that
12341 bus width doesnot fluctuate much */
12342 uint64_t temp_rx = (rx_packets + pHddCtx->prev_rx)/2;
12343 TP_IND_TYPE next_rx_level = pHddCtx->cur_rx_level;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012344
Bhargav Shahd0715912015-10-01 18:17:37 +053012345 pHddCtx->prev_rx = rx_packets;
12346 if (temp_rx > pHddCtx->cfg_ini->tcpDelAckThresholdHigh)
12347 next_rx_level = TP_IND_HIGH;
12348 else if (temp_rx <= pHddCtx->cfg_ini->tcpDelAckThresholdLow)
12349 next_rx_level = TP_IND_LOW;
12350
12351 hdd_set_delack_value(pHddCtx, next_rx_level);
12352}
12353
12354#define HDD_BW_GET_DIFF(x, y) ((x) >= (y) ? (x) - (y) : (ULONG_MAX - (y) + (x)))
12355
12356/**
12357 * hdd_tcp_delack_compute_function() - get link status
12358 * @priv: Valid Global HDD context pointer
12359 *
12360 * This function find number of RX packet during timer life span.
12361 * It request tcp delack with number of RX packet and re-configure delack timer
12362 * for tcpDelAckComputeInterval timer interval.
12363 *
12364 * Return: void
12365 */
12366void hdd_tcp_delack_compute_function(void *priv)
12367{
12368 hdd_context_t *pHddCtx = (hdd_context_t *)priv;
12369 hdd_adapter_t *pAdapter = NULL;
12370 v_U32_t rx_packets = 0;
12371 hdd_adapter_list_node_t *pAdapterNode = NULL;
12372 VOS_STATUS status = 0;
12373
12374 for (status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
12375 NULL != pAdapterNode && VOS_STATUS_SUCCESS == status;
12376 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pAdapterNode)) {
12377 if ((pAdapter = pAdapterNode->pAdapter) == NULL)
12378 continue;
12379
12380 rx_packets += HDD_BW_GET_DIFF(pAdapter->stats.rx_packets,
12381 pAdapter->prev_rx_packets);
12382 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
12383 }
12384
12385 hdd_request_tcp_delack(pHddCtx, rx_packets);
12386
12387 vos_timer_start(&pHddCtx->delack_timer,
12388 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
12389}
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012390
12391/**---------------------------------------------------------------------------
12392
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012393 \brief hdd_is_5g_supported() - HDD function to know if hardware supports 5GHz
12394
12395 \param - pHddCtx - Pointer to the hdd context
12396
12397 \return - true if hardware supports 5GHz
12398
12399 --------------------------------------------------------------------------*/
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +053012400boolean hdd_is_5g_supported(hdd_context_t * pHddCtx)
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012401{
12402 /* If wcnss_wlan_iris_xo_mode() returns WCNSS_XO_48MHZ(1);
12403 * then hardware support 5Ghz.
12404 */
12405 if (WCNSS_XO_48MHZ == wcnss_wlan_iris_xo_mode())
12406 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053012407 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware supports 5Ghz", __func__);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012408 return true;
12409 }
12410 else
12411 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053012412 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware doesn't supports 5Ghz",
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012413 __func__);
12414 return false;
12415 }
12416}
12417
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053012418/**---------------------------------------------------------------------------
12419
12420 \brief hdd_generate_iface_mac_addr_auto() - HDD Mac Interface Auto
12421 generate function
12422
12423 This is generate the random mac address for WLAN interface
12424
12425 \param - pHddCtx - Pointer to HDD context
12426 idx - Start interface index to get auto
12427 generated mac addr.
12428 mac_addr - Mac address
12429
12430 \return - 0 for success, < 0 for failure
12431
12432 --------------------------------------------------------------------------*/
12433
12434static int hdd_generate_iface_mac_addr_auto(hdd_context_t *pHddCtx,
12435 int idx, v_MACADDR_t mac_addr)
12436{
12437 int i;
12438 unsigned int serialno;
12439 serialno = wcnss_get_serial_number();
12440
12441 if (0 != serialno)
12442 {
12443 /* MAC address has 3 bytes of OUI so we have a maximum of 3
12444 bytes of the serial number that can be used to generate
12445 the other 3 bytes of the MAC address. Mask off all but
12446 the lower 3 bytes (this will also make sure we don't
12447 overflow in the next step) */
12448 serialno &= 0x00FFFFFF;
12449
12450 /* we need a unique address for each session */
12451 serialno *= VOS_MAX_CONCURRENCY_PERSONA;
12452
12453 /* autogen other Mac addresses */
12454 for (i = idx; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
12455 {
12456 /* start with the entire default address */
12457 pHddCtx->cfg_ini->intfMacAddr[i] = mac_addr;
12458 /* then replace the lower 3 bytes */
12459 pHddCtx->cfg_ini->intfMacAddr[i].bytes[3] = (serialno >> 16) & 0xFF;
12460 pHddCtx->cfg_ini->intfMacAddr[i].bytes[4] = (serialno >> 8) & 0xFF;
12461 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] = serialno & 0xFF;
12462
Nachiket Kukadede2e24f2017-09-25 16:24:27 +053012463 if (0 == memcmp(&pHddCtx->cfg_ini->intfMacAddr[i].bytes[0],
12464 &mac_addr.bytes[0], VOS_MAC_ADDR_SIZE))
12465 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] +=
12466 VOS_MAX_CONCURRENCY_PERSONA;
12467
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053012468 serialno++;
12469 hddLog(VOS_TRACE_LEVEL_ERROR,
12470 "%s: Derived Mac Addr: "
12471 MAC_ADDRESS_STR, __func__,
12472 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[i].bytes));
12473 }
12474
12475 }
12476 else
12477 {
12478 hddLog(LOGE, FL("Failed to Get Serial NO"));
12479 return -1;
12480 }
12481 return 0;
12482}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012483
Katya Nigame7b69a82015-04-28 15:24:06 +053012484int wlan_hdd_mon_open(hdd_context_t *pHddCtx)
12485{
12486 VOS_STATUS status;
12487 v_CONTEXT_t pVosContext= NULL;
12488 hdd_adapter_t *pAdapter= NULL;
12489
12490 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
12491
12492 if (NULL == pVosContext)
12493 {
12494 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12495 "%s: Trying to open VOSS without a PreOpen", __func__);
12496 VOS_ASSERT(0);
12497 return VOS_STATUS_E_FAILURE;
12498 }
12499
12500 status = vos_nv_open();
12501 if (!VOS_IS_STATUS_SUCCESS(status))
12502 {
12503 /* NV module cannot be initialized */
12504 hddLog( VOS_TRACE_LEVEL_FATAL,
12505 "%s: vos_nv_open failed", __func__);
12506 return VOS_STATUS_E_FAILURE;
12507 }
12508
12509 status = vos_init_wiphy_from_nv_bin();
12510 if (!VOS_IS_STATUS_SUCCESS(status))
12511 {
12512 /* NV module cannot be initialized */
12513 hddLog( VOS_TRACE_LEVEL_FATAL,
12514 "%s: vos_init_wiphy failed", __func__);
12515 goto err_vos_nv_close;
12516 }
12517
12518 status = vos_open( &pVosContext, pHddCtx->parent_dev);
12519 if ( !VOS_IS_STATUS_SUCCESS( status ))
12520 {
12521 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
12522 goto err_vos_nv_close;
12523 }
12524
12525 status = vos_mon_start( pVosContext );
12526 if ( !VOS_IS_STATUS_SUCCESS( status ) )
12527 {
12528 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
12529 goto err_vosclose;
12530 }
12531
12532 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
12533 WDA_featureCapsExchange(pVosContext);
12534 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
12535
12536 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_MONITOR, "wlan%d",
12537 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
12538 if( pAdapter == NULL )
12539 {
12540 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
12541 goto err_close_adapter;
12542 }
12543
12544 //Initialize the nlink service
12545 if(nl_srv_init() != 0)
12546 {
12547 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
12548 goto err_close_adapter;
12549 }
12550 return VOS_STATUS_SUCCESS;
12551
12552err_close_adapter:
12553 hdd_close_all_adapters( pHddCtx );
12554 vos_mon_stop( pVosContext );
12555err_vosclose:
12556 status = vos_sched_close( pVosContext );
12557 if (!VOS_IS_STATUS_SUCCESS(status)) {
12558 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
12559 "%s: Failed to close VOSS Scheduler", __func__);
12560 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
12561 }
12562 vos_close(pVosContext );
12563
12564err_vos_nv_close:
12565 vos_nv_close();
12566
12567return status;
12568}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053012569/**---------------------------------------------------------------------------
12570
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053012571 \brief hdd_11d_scan_done - callback to be executed when 11d scan is
12572 completed to flush out the scan results
12573
12574 11d scan is done during driver load and is a passive scan on all
12575 channels supported by the device, 11d scans may find some APs on
12576 frequencies which are forbidden to be used in the regulatory domain
12577 the device is operating in. If these APs are notified to the supplicant
12578 it may try to connect to these APs, thus flush out all the scan results
12579 which are present in SME after 11d scan is done.
12580
12581 \return - eHalStatus
12582
12583 --------------------------------------------------------------------------*/
12584static eHalStatus hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
12585 tANI_U32 scanId, eCsrScanStatus status)
12586{
12587 ENTER();
12588
12589 sme_ScanFlushResult(halHandle, 0);
12590
12591 EXIT();
12592
12593 return eHAL_STATUS_SUCCESS;
12594}
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012595/**---------------------------------------------------------------------------
12596
12597 \brief hdd_init_frame_logging_done - callback to be executed when mgmt frame
12598 logging is completed successfully.
12599
12600 \return - None
12601
12602 --------------------------------------------------------------------------*/
c_manjeecfd1efb2015-09-25 19:32:34 +053012603void hdd_init_frame_logging_done(void *fwlogInitCbContext, tAniLoggingInitRsp *pRsp)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012604{
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012605 hdd_context_t* pHddCtx = (hdd_context_t*)fwlogInitCbContext;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012606
12607 if (NULL == pHddCtx)
12608 {
12609 hddLog(VOS_TRACE_LEVEL_ERROR,
12610 "%s: HDD context is NULL",__func__);
12611 return;
12612 }
12613
c_manjeecfd1efb2015-09-25 19:32:34 +053012614 if ((pRsp->status == VOS_STATUS_SUCCESS) &&
Mahesh A Saptasagarfabb1a02015-06-29 12:17:04 +053012615 (TRUE == pHddCtx->cfg_ini->enableMgmtLogging))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012616 {
12617 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init successful"));
12618 pHddCtx->mgmt_frame_logging = TRUE;
12619 }
12620 else
12621 {
12622 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init not success"));
12623 pHddCtx->mgmt_frame_logging = FALSE;
c_manjeecfd1efb2015-09-25 19:32:34 +053012624 return;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012625 }
12626
c_manjeecfd1efb2015-09-25 19:32:34 +053012627 /*Check feature supported by FW*/
12628 if(TRUE == sme_IsFeatureSupportedByFW(MEMORY_DUMP_SUPPORTED))
12629 {
12630 //Store fwr mem dump size given by firmware.
12631 wlan_store_fwr_mem_dump_size(pRsp->fw_mem_dump_max_size);
12632 }
12633 else
12634 {
12635 wlan_store_fwr_mem_dump_size(0);
12636 }
12637
12638
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012639}
12640/**---------------------------------------------------------------------------
12641
12642 \brief hdd_init_frame_logging - function to initialize frame logging.
12643 Currently only Mgmt Frames are logged in both TX
12644 and Rx direction and are sent to userspace
12645 application using logger thread when queried.
12646
12647 \return - None
12648
12649 --------------------------------------------------------------------------*/
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012650void hdd_init_frame_logging(hdd_context_t* pHddCtx)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012651{
12652 eHalStatus halStatus = eHAL_STATUS_FAILURE;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012653 tSirFWLoggingInitParam wlanFWLoggingInitParam = {0};
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012654
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012655 if (TRUE != sme_IsFeatureSupportedByFW(MGMT_FRAME_LOGGING) &&
12656 TRUE != sme_IsFeatureSupportedByFW(LOGGING_ENHANCEMENT))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012657 {
12658 hddLog(VOS_TRACE_LEVEL_INFO, FL("MGMT_FRAME_LOGGING not supp by FW"));
12659 return;
12660 }
12661
c_manjeecfd1efb2015-09-25 19:32:34 +053012662 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Configuring %s %s %s %s Logging",__func__,
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012663 pHddCtx->cfg_ini->enableFWLogging?"FW Log,":"",
12664 pHddCtx->cfg_ini->enableContFWLogging ? "Cont FW log,":"",
c_manjeecfd1efb2015-09-25 19:32:34 +053012665 pHddCtx->cfg_ini->enableMgmtLogging ? "Mgmt Pkt Log":"",
12666 pHddCtx->cfg_ini->enableFwrMemDump ? "Fw Mem dump":"");
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012667
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012668 if (pHddCtx->cfg_ini->enableFWLogging ||
12669 pHddCtx->cfg_ini->enableContFWLogging)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012670 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012671 wlanFWLoggingInitParam.enableFlag |= WLAN_QXDM_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012672 }
12673
Sushant Kaushik46804902015-07-08 14:46:03 +053012674 if (pHddCtx->cfg_ini->enableMgmtLogging)
12675 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012676 wlanFWLoggingInitParam.enableFlag |= WLAN_FRAME_LOG_EN;
Sushant Kaushik46804902015-07-08 14:46:03 +053012677 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012678 if (pHddCtx->cfg_ini->enableBMUHWtracing)
12679 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012680 wlanFWLoggingInitParam.enableFlag |= WLAN_BMUHW_TRACE_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012681 }
c_manjeecfd1efb2015-09-25 19:32:34 +053012682 if(pHddCtx->cfg_ini->enableFwrMemDump &&
12683 (TRUE == sme_IsFeatureSupportedByFW(MEMORY_DUMP_SUPPORTED)))
12684 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012685 wlanFWLoggingInitParam.enableFlag |= WLAN_FW_MEM_DUMP_EN;
c_manjeecfd1efb2015-09-25 19:32:34 +053012686 }
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012687 if( wlanFWLoggingInitParam.enableFlag == 0 )
c_manjeecfd1efb2015-09-25 19:32:34 +053012688 {
12689 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Logging not enabled", __func__);
12690 return;
12691 }
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012692 wlanFWLoggingInitParam.frameType = WLAN_FRAME_LOGGING_FRAMETYPE_MGMT;
12693 wlanFWLoggingInitParam.frameSize = WLAN_MGMT_LOGGING_FRAMESIZE_128BYTES;
12694 wlanFWLoggingInitParam.bufferMode = WLAN_FRAME_LOGGING_BUFFERMODE_CIRCULAR;
12695 wlanFWLoggingInitParam.continuousFrameLogging =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012696 pHddCtx->cfg_ini->enableContFWLogging;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012697
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012698 wlanFWLoggingInitParam.enableFlag &= ~WLAN_DPU_TXP_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012699
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012700 wlanFWLoggingInitParam.minLogBufferSize =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012701 pHddCtx->cfg_ini->minLoggingBufferSize;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012702 wlanFWLoggingInitParam.maxLogBufferSize =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012703 pHddCtx->cfg_ini->maxLoggingBufferSize;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012704 wlanFWLoggingInitParam.fwlogInitCallback = hdd_init_frame_logging_done;
12705 wlanFWLoggingInitParam.fwlogInitCbContext= pHddCtx;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012706
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012707 halStatus = sme_InitMgmtFrameLogging(pHddCtx->hHal, &wlanFWLoggingInitParam);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012708
12709 if (eHAL_STATUS_SUCCESS != halStatus)
12710 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053012711 hddLog(LOGE, FL("sme_InitMgmtFrameLogging failed, returned %d"),
12712 halStatus);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012713 }
12714
12715 return;
12716}
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053012717
Bhargav shah23c94942015-10-13 12:48:35 +053012718static void hdd_dp_util_send_rps_ind(hdd_context_t *hdd_ctxt)
12719{
12720 hdd_adapter_t *adapter;
12721 hdd_adapter_list_node_t *adapter_node, *next;
12722 VOS_STATUS status = VOS_STATUS_SUCCESS;
12723 struct wlan_rps_data rps_data;
12724 int count;
12725
12726 if(!hdd_ctxt->cfg_ini->rps_mask)
12727 {
12728 return;
12729 }
12730
12731 for (count=0; count < WLAN_SVC_IFACE_NUM_QUEUES; count++)
12732 {
12733 rps_data.cpu_map[count] = hdd_ctxt->cfg_ini->rps_mask;
12734 }
12735
12736 rps_data.num_queues = WLAN_SVC_IFACE_NUM_QUEUES;
12737
12738 hddLog(LOG1, FL("0x%x 0x%x 0x%x 0x%x 0x%x 0x%x"),
12739 rps_data.cpu_map[0], rps_data.cpu_map[1],rps_data.cpu_map[2],
12740 rps_data.cpu_map[3], rps_data.cpu_map[4], rps_data.cpu_map[5]);
12741
12742 status = hdd_get_front_adapter (hdd_ctxt, &adapter_node);
12743
12744 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status)
12745 {
12746 adapter = adapter_node->pAdapter;
12747 if (NULL != adapter) {
12748 strlcpy(rps_data.ifname, adapter->dev->name,
12749 sizeof(rps_data.ifname));
12750 wlan_hdd_send_svc_nlink_msg(WLAN_MSG_RPS_ENABLE_IND,
12751 (void *)&rps_data,sizeof(rps_data));
12752 }
12753 status = hdd_get_next_adapter (hdd_ctxt, adapter_node, &next);
12754 adapter_node = next;
12755 }
12756}
12757
Masti, Narayanraddi26378462016-01-05 18:20:28 +053012758void wlan_hdd_schedule_defer_scan(struct work_struct *work)
12759{
12760 scan_context_t *scan_ctx =
12761 container_of(work, scan_context_t, scan_work.work);
12762
12763 if (NULL == scan_ctx)
12764 {
12765 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12766 FL("scan_ctx is NULL"));
12767 return;
12768 }
12769
12770 if (unlikely(TDLS_CTX_MAGIC != scan_ctx->magic))
12771 return;
12772
12773 scan_ctx->attempt++;
12774
12775 wlan_hdd_cfg80211_scan(scan_ctx->wiphy,
12776#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
12777 scan_ctx->dev,
12778#endif
12779 scan_ctx->scan_request);
12780}
12781
12782int wlan_hdd_copy_defer_scan_context(hdd_context_t *pHddCtx,
12783 struct wiphy *wiphy,
12784#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
12785 struct net_device *dev,
12786#endif
12787 struct cfg80211_scan_request *request)
12788{
12789 scan_context_t *scan_ctx;
12790
12791 ENTER();
12792 if (0 != (wlan_hdd_validate_context(pHddCtx)))
12793 {
12794 return -1;
12795 }
12796
12797 scan_ctx = &pHddCtx->scan_ctxt;
12798
12799 scan_ctx->wiphy = wiphy;
12800#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
12801 scan_ctx->dev = dev;
12802#endif
12803
12804 scan_ctx->scan_request = request;
12805
12806 EXIT();
12807 return 0;
12808}
12809
12810void wlan_hdd_defer_scan_init_work(hdd_context_t *pHddCtx,
12811 struct wiphy *wiphy,
12812#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
12813 struct net_device *dev,
12814#endif
12815 struct cfg80211_scan_request *request,
12816 unsigned long delay)
12817{
12818 if (TDLS_CTX_MAGIC != pHddCtx->scan_ctxt.magic)
12819 {
12820#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
12821 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, dev, request);
12822#else
12823 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, request);
12824#endif
12825 pHddCtx->scan_ctxt.attempt = 0;
12826 pHddCtx->scan_ctxt.magic = TDLS_CTX_MAGIC;
12827 }
12828 schedule_delayed_work(&pHddCtx->scan_ctxt.scan_work, delay);
12829}
12830
12831void wlan_hdd_init_deinit_defer_scan_context(scan_context_t *scan_ctx)
12832{
12833 scan_ctx->magic = 0;
12834 scan_ctx->attempt = 0;
12835 scan_ctx->reject = 0;
12836 scan_ctx->scan_request = NULL;
12837
12838 return;
12839}
12840
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053012841/**---------------------------------------------------------------------------
12842
Jeff Johnson295189b2012-06-20 16:38:30 -070012843 \brief hdd_wlan_startup() - HDD init function
12844
12845 This is the driver startup code executed once a WLAN device has been detected
12846
12847 \param - dev - Pointer to the underlying device
12848
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080012849 \return - 0 for success, < 0 for failure
Jeff Johnson295189b2012-06-20 16:38:30 -070012850
12851 --------------------------------------------------------------------------*/
12852
12853int hdd_wlan_startup(struct device *dev )
12854{
12855 VOS_STATUS status;
12856 hdd_adapter_t *pAdapter = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -070012857 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070012858 hdd_context_t *pHddCtx = NULL;
12859 v_CONTEXT_t pVosContext= NULL;
12860#ifdef WLAN_BTAMP_FEATURE
12861 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
12862 WLANBAP_ConfigType btAmpConfig;
12863 hdd_config_t *pConfig;
12864#endif
12865 int ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070012866 struct wiphy *wiphy;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053012867 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -070012868
12869 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -070012870 /*
12871 * cfg80211: wiphy allocation
12872 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053012873 wiphy = wlan_hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t)) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070012874
12875 if(wiphy == NULL)
12876 {
12877 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080012878 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070012879 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012880 pHddCtx = wiphy_priv(wiphy);
12881
Jeff Johnson295189b2012-06-20 16:38:30 -070012882 //Initialize the adapter context to zeros.
12883 vos_mem_zero(pHddCtx, sizeof( hdd_context_t ));
12884
Jeff Johnson295189b2012-06-20 16:38:30 -070012885 pHddCtx->wiphy = wiphy;
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012886 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Mihir Shete18156292014-03-11 15:38:30 +053012887 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_LOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070012888
12889 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
12890
Siddharth Bhalcd92b782015-06-29 12:25:40 +053012891 /* register for riva power on lock to platform driver
12892 * Locking power early to ensure FW doesn't reset by kernel while
12893 * host driver is busy initializing itself */
12894 if (req_riva_power_on_lock("wlan"))
12895 {
12896 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: req riva power on lock failed",
12897 __func__);
12898 goto err_free_hdd_context;
12899 }
12900
Jeff Johnson295189b2012-06-20 16:38:30 -070012901 /*Get vos context here bcoz vos_open requires it*/
12902 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
12903
Madan Mohan Koyyalamudi0b78e152012-11-28 15:46:51 -080012904 if(pVosContext == NULL)
12905 {
12906 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed vos_get_global_context",__func__);
12907 goto err_free_hdd_context;
12908 }
12909
Jeff Johnson295189b2012-06-20 16:38:30 -070012910 //Save the Global VOSS context in adapter context for future.
12911 pHddCtx->pvosContext = pVosContext;
12912
12913 //Save the adapter context in global context for future.
12914 ((VosContextType*)(pVosContext))->pHDDContext = (v_VOID_t*)pHddCtx;
12915
Jeff Johnson295189b2012-06-20 16:38:30 -070012916 pHddCtx->parent_dev = dev;
Sreelakshmi Konamkif0646d52016-12-09 12:35:31 +053012917 pHddCtx->last_scan_reject_session_id = 0xFF;
12918 pHddCtx->last_scan_reject_reason = 0;
Sreelakshmi Konamki20ebed92016-10-27 12:13:30 +053012919 pHddCtx->last_scan_reject_timestamp = 0;
Abhishek Singhe4b12562017-06-20 16:53:39 +053012920 pHddCtx->scan_reject_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070012921
12922 init_completion(&pHddCtx->full_pwr_comp_var);
12923 init_completion(&pHddCtx->standby_comp_var);
12924 init_completion(&pHddCtx->req_bmps_comp_var);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070012925 init_completion(&pHddCtx->scan_info.scan_req_completion_event);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -080012926 init_completion(&pHddCtx->scan_info.abortscan_event_var);
Kiet Lam46b8e4e2013-11-06 21:49:53 +053012927 init_completion(&pHddCtx->wiphy_channel_update_event);
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053012928 init_completion(&pHddCtx->ssr_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053012929 init_completion(&pHddCtx->mc_sus_event_var);
12930 init_completion(&pHddCtx->tx_sus_event_var);
12931 init_completion(&pHddCtx->rx_sus_event_var);
12932
Amar Singhala49cbc52013-10-08 18:37:44 -070012933
mukul sharma4bd8d2e2015-08-13 20:33:25 +053012934 hdd_init_ll_stats_ctx(pHddCtx);
Anurag Chouhan6ee81542017-02-09 18:09:27 +053012935 hdd_init_nud_stats_ctx(pHddCtx);
mukul sharma4bd8d2e2015-08-13 20:33:25 +053012936
Amar Singhala49cbc52013-10-08 18:37:44 -070012937#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhalfddc28c2013-09-05 13:03:40 -070012938 init_completion(&pHddCtx->linux_reg_req);
Amar Singhala49cbc52013-10-08 18:37:44 -070012939#else
12940 init_completion(&pHddCtx->driver_crda_req);
12941#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070012942
Padma, Santhosh Kumara1aa4a32015-06-19 19:00:46 +053012943#ifdef WLAN_FEATURE_EXTSCAN
12944 init_completion(&pHddCtx->ext_scan_context.response_event);
12945#endif /* WLAN_FEATURE_EXTSCAN */
12946
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053012947 spin_lock_init(&pHddCtx->schedScan_lock);
Kapil Gupta137ef892016-12-13 19:38:00 +053012948 vos_spin_lock_init(&pHddCtx->sap_update_info_lock);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053012949
Jeff Johnson295189b2012-06-20 16:38:30 -070012950 hdd_list_init( &pHddCtx->hddAdapters, MAX_NUMBER_OF_ADAPTERS );
12951
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053012952 vos_init_delayed_work(&pHddCtx->spoof_mac_addr_work,
12953 hdd_processSpoofMacAddrRequest);
Kapil Gupta137ef892016-12-13 19:38:00 +053012954 vos_init_work(&pHddCtx->sap_start_work, hdd_sap_restart_handle);
Abhishek Singh78c691f2017-11-30 13:48:44 +053012955 vos_init_delayed_work(&pHddCtx->ecsa_chan_change_work,
12956 hdd_force_scc_with_ecsa_handle);
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053012957
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053012958#ifdef FEATURE_WLAN_TDLS
12959 /* tdls_lock is initialized before an hdd_open_adapter ( which is
12960 * invoked by other instances also) to protect the concurrent
12961 * access for the Adapters by TDLS module.
12962 */
12963 mutex_init(&pHddCtx->tdls_lock);
12964#endif
Siddharth Bhal76972212014-10-15 16:22:51 +053012965 mutex_init(&pHddCtx->spoofMacAddr.macSpoofingLock);
Mukul Sharma1fd6efd2015-02-14 00:29:14 +053012966 mutex_init(&pHddCtx->wmmLock);
12967
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +053012968 hdd_init_offloaded_packets_ctx(pHddCtx);
Agarwal Ashish1f422872014-07-22 00:11:55 +053012969 /* By default Strict Regulatory For FCC should be false */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053012970
Agarwal Ashish1f422872014-07-22 00:11:55 +053012971 pHddCtx->nEnableStrictRegulatoryForFCC = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070012972 // Load all config first as TL config is needed during vos_open
12973 pHddCtx->cfg_ini = (hdd_config_t*) kmalloc(sizeof(hdd_config_t), GFP_KERNEL);
12974 if(pHddCtx->cfg_ini == NULL)
12975 {
12976 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed kmalloc hdd_config_t",__func__);
12977 goto err_free_hdd_context;
12978 }
12979
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053012980 hdd_request_manager_init();
12981
Jeff Johnson295189b2012-06-20 16:38:30 -070012982 vos_mem_zero(pHddCtx->cfg_ini, sizeof( hdd_config_t ));
12983
12984 // Read and parse the qcom_cfg.ini file
12985 status = hdd_parse_config_ini( pHddCtx );
12986 if ( VOS_STATUS_SUCCESS != status )
12987 {
12988 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: error parsing %s",
12989 __func__, WLAN_INI_FILE);
12990 goto err_config;
12991 }
Arif Hussaind5218912013-12-05 01:10:55 -080012992#ifdef MEMORY_DEBUG
12993 if (pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled)
12994 vos_mem_init();
12995
12996 hddLog(VOS_TRACE_LEVEL_INFO, "%s: gEnableMemoryDebug=%d",
12997 __func__, pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled);
12998#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070012999
Gopichand Nakkalab8f0f1a2013-05-23 18:19:48 +053013000 /* INI has been read, initialise the configuredMcastBcastFilter with
13001 * INI value as this will serve as the default value
13002 */
13003 pHddCtx->configuredMcastBcastFilter = pHddCtx->cfg_ini->mcastBcastFilterSetting;
13004 hddLog(VOS_TRACE_LEVEL_INFO, "Setting configuredMcastBcastFilter: %d",
13005 pHddCtx->cfg_ini->mcastBcastFilterSetting);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013006
13007 if (false == hdd_is_5g_supported(pHddCtx))
13008 {
13009 //5Ghz is not supported.
13010 if (1 != pHddCtx->cfg_ini->nBandCapability)
13011 {
13012 hddLog(VOS_TRACE_LEVEL_INFO,
13013 "%s: Setting pHddCtx->cfg_ini->nBandCapability = 1", __func__);
13014 pHddCtx->cfg_ini->nBandCapability = 1;
13015 }
13016 }
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +053013017
13018 /* If SNR Monitoring is enabled, FW has to parse all beacons
13019 * for calcaluting and storing the average SNR, so set Nth beacon
13020 * filter to 1 to enable FW to parse all the beaocons
13021 */
13022 if (1 == pHddCtx->cfg_ini->fEnableSNRMonitoring)
13023 {
13024 /* The log level is deliberately set to WARN as overriding
13025 * nthBeaconFilter to 1 will increase power cosumption and this
13026 * might just prove helpful to detect the power issue.
13027 */
13028 hddLog(VOS_TRACE_LEVEL_WARN,
13029 "%s: Setting pHddCtx->cfg_ini->nthBeaconFilter = 1", __func__);
13030 pHddCtx->cfg_ini->nthBeaconFilter = 1;
13031 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013032 /*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013033 * cfg80211: Initialization ...
Jeff Johnson295189b2012-06-20 16:38:30 -070013034 */
Manjeet Singh61016fa2016-12-02 11:10:19 +053013035 if (0 < wlan_hdd_cfg80211_init(dev, wiphy, pHddCtx->cfg_ini))
Jeff Johnson295189b2012-06-20 16:38:30 -070013036 {
Manjeet Singh61016fa2016-12-02 11:10:19 +053013037 hddLog(VOS_TRACE_LEVEL_FATAL,
13038 "%s: wlan_hdd_cfg80211_init return failure", __func__);
13039 goto err_config;
Jeff Johnson295189b2012-06-20 16:38:30 -070013040 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013041
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013042 // Update VOS trace levels based upon the cfg.ini
13043 hdd_vos_trace_enable(VOS_MODULE_ID_BAP,
13044 pHddCtx->cfg_ini->vosTraceEnableBAP);
13045 hdd_vos_trace_enable(VOS_MODULE_ID_TL,
13046 pHddCtx->cfg_ini->vosTraceEnableTL);
13047 hdd_vos_trace_enable(VOS_MODULE_ID_WDI,
13048 pHddCtx->cfg_ini->vosTraceEnableWDI);
13049 hdd_vos_trace_enable(VOS_MODULE_ID_HDD,
13050 pHddCtx->cfg_ini->vosTraceEnableHDD);
13051 hdd_vos_trace_enable(VOS_MODULE_ID_SME,
13052 pHddCtx->cfg_ini->vosTraceEnableSME);
13053 hdd_vos_trace_enable(VOS_MODULE_ID_PE,
13054 pHddCtx->cfg_ini->vosTraceEnablePE);
Katya Nigam70d68332013-09-16 16:49:45 +053013055 hdd_vos_trace_enable(VOS_MODULE_ID_PMC,
13056 pHddCtx->cfg_ini->vosTraceEnablePMC);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013057 hdd_vos_trace_enable(VOS_MODULE_ID_WDA,
13058 pHddCtx->cfg_ini->vosTraceEnableWDA);
13059 hdd_vos_trace_enable(VOS_MODULE_ID_SYS,
13060 pHddCtx->cfg_ini->vosTraceEnableSYS);
13061 hdd_vos_trace_enable(VOS_MODULE_ID_VOSS,
13062 pHddCtx->cfg_ini->vosTraceEnableVOSS);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013063 hdd_vos_trace_enable(VOS_MODULE_ID_SAP,
13064 pHddCtx->cfg_ini->vosTraceEnableSAP);
13065 hdd_vos_trace_enable(VOS_MODULE_ID_HDD_SOFTAP,
13066 pHddCtx->cfg_ini->vosTraceEnableHDDSAP);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013067
Jeff Johnson295189b2012-06-20 16:38:30 -070013068 // Update WDI trace levels based upon the cfg.ini
13069 hdd_wdi_trace_enable(eWLAN_MODULE_DAL,
13070 pHddCtx->cfg_ini->wdiTraceEnableDAL);
13071 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_CTRL,
13072 pHddCtx->cfg_ini->wdiTraceEnableCTL);
13073 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_DATA,
13074 pHddCtx->cfg_ini->wdiTraceEnableDAT);
13075 hdd_wdi_trace_enable(eWLAN_MODULE_PAL,
13076 pHddCtx->cfg_ini->wdiTraceEnablePAL);
Jeff Johnson295189b2012-06-20 16:38:30 -070013077
Jeff Johnson88ba7742013-02-27 14:36:02 -080013078 if (VOS_FTM_MODE == hdd_get_conparam())
13079 {
Jeff Johnson295189b2012-06-20 16:38:30 -070013080 if ( VOS_STATUS_SUCCESS != wlan_hdd_ftm_open(pHddCtx) )
13081 {
13082 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_ftm_open Failed",__func__);
13083 goto err_free_hdd_context;
13084 }
13085 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: FTM driver loaded success fully",__func__);
Sachin Ahuja38ef5e02015-03-13 17:31:16 +053013086 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
c_hpothu2de0ef62014-04-15 16:16:15 +053013087 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -070013088 return VOS_STATUS_SUCCESS;
Jeff Johnson88ba7742013-02-27 14:36:02 -080013089 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013090
Katya Nigame7b69a82015-04-28 15:24:06 +053013091 if( VOS_MONITOR_MODE == hdd_get_conparam())
13092 {
13093 if ( VOS_STATUS_SUCCESS != wlan_hdd_mon_open(pHddCtx))
13094 {
13095 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_mon_open Failed",__func__);
13096 goto err_free_hdd_context;
13097 }
13098 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Driver loaded in Monitor Mode",__func__);
13099 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
13100 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
13101 return VOS_STATUS_SUCCESS;
13102 }
13103
Jeff Johnson88ba7742013-02-27 14:36:02 -080013104 //Open watchdog module
Jeff Johnson295189b2012-06-20 16:38:30 -070013105 if(pHddCtx->cfg_ini->fIsLogpEnabled)
13106 {
13107 status = vos_watchdog_open(pVosContext,
13108 &((VosContextType*)pVosContext)->vosWatchdog, sizeof(VosWatchdogContext));
13109
13110 if(!VOS_IS_STATUS_SUCCESS( status ))
13111 {
13112 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_watchdog_open failed",__func__);
Ashish Kumar Dhanotiya532bdef2017-05-09 17:31:59 +053013113 goto err_config;
Jeff Johnson295189b2012-06-20 16:38:30 -070013114 }
13115 }
13116
13117 pHddCtx->isLogpInProgress = FALSE;
13118 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
13119
Amar Singhala49cbc52013-10-08 18:37:44 -070013120#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070013121 /* initialize the NV module. This is required so that
13122 we can initialize the channel information in wiphy
13123 from the NV.bin data. The channel information in
13124 wiphy needs to be initialized before wiphy registration */
13125
13126 status = vos_nv_open();
13127 if (!VOS_IS_STATUS_SUCCESS(status))
13128 {
13129 /* NV module cannot be initialized */
13130 hddLog( VOS_TRACE_LEVEL_FATAL,
13131 "%s: vos_nv_open failed", __func__);
Vinay Krishna Eranna2025d892014-09-18 16:51:42 +053013132 goto err_wdclose;
Amar Singhal0a402232013-10-11 20:57:16 -070013133 }
13134
13135 status = vos_init_wiphy_from_nv_bin();
13136 if (!VOS_IS_STATUS_SUCCESS(status))
13137 {
13138 /* NV module cannot be initialized */
13139 hddLog( VOS_TRACE_LEVEL_FATAL,
13140 "%s: vos_init_wiphy failed", __func__);
13141 goto err_vos_nv_close;
13142 }
13143
Amar Singhala49cbc52013-10-08 18:37:44 -070013144#endif
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013145 //Initialize the nlink service
13146 if(nl_srv_init() != 0)
13147 {
13148 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
13149 goto err_vos_nv_close;
13150 }
13151
13152#ifdef WLAN_KD_READY_NOTIFIER
13153 pHddCtx->kd_nl_init = 1;
13154#endif /* WLAN_KD_READY_NOTIFIER */
13155
Girish Gowlibf0e1ab2015-01-19 16:05:16 +053013156 vos_set_roam_delay_stats_enabled(pHddCtx->cfg_ini->gEnableRoamDelayStats);
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053013157 status = vos_open( &pVosContext, pHddCtx->parent_dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070013158 if ( !VOS_IS_STATUS_SUCCESS( status ))
13159 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013160 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013161 goto err_nl_srv;
Jeff Johnson295189b2012-06-20 16:38:30 -070013162 }
13163
Jeff Johnson295189b2012-06-20 16:38:30 -070013164 pHddCtx->hHal = (tHalHandle)vos_get_context( VOS_MODULE_ID_SME, pVosContext );
13165
13166 if ( NULL == pHddCtx->hHal )
13167 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013168 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: HAL context is null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070013169 goto err_vosclose;
13170 }
13171
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013172 status = vos_preStart( pHddCtx->pvosContext );
13173 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13174 {
13175 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_preStart failed", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013176 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013177 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013178
Arif Hussaineaf68602013-12-30 23:10:44 -080013179 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan)
13180 {
13181 pHddCtx->cfg_ini->enableDFSChnlScan = enable_dfs_chan_scan;
13182 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_dfs_chan_scan set to %d",
13183 __func__, enable_dfs_chan_scan);
13184 }
13185 if (0 == enable_11d || 1 == enable_11d)
13186 {
13187 pHddCtx->cfg_ini->Is11dSupportEnabled = enable_11d;
13188 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_11d set to %d",
13189 __func__, enable_11d);
13190 }
13191
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013192 /* Note that the vos_preStart() sequence triggers the cfg download.
13193 The cfg download must occur before we update the SME config
13194 since the SME config operation must access the cfg database */
Jeff Johnson295189b2012-06-20 16:38:30 -070013195 status = hdd_set_sme_config( pHddCtx );
13196
13197 if ( VOS_STATUS_SUCCESS != status )
13198 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013199 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed hdd_set_sme_config", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013200 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013201 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013202
Jeff Johnson295189b2012-06-20 16:38:30 -070013203 /* In the integrated architecture we update the configuration from
13204 the INI file and from NV before vOSS has been started so that
13205 the final contents are available to send down to the cCPU */
13206
13207 // Apply the cfg.ini to cfg.dat
13208 if (FALSE == hdd_update_config_dat(pHddCtx))
13209 {
13210 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013211 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013212 }
13213
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013214 // Get mac addr from platform driver
13215 ret = wcnss_get_wlan_mac_address((char*)&mac_addr.bytes);
13216
13217 if ((0 == ret) && (!vos_is_macaddr_zero(&mac_addr)))
Jeff Johnson295189b2012-06-20 16:38:30 -070013218 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013219 /* Store the mac addr for first interface */
13220 pHddCtx->cfg_ini->intfMacAddr[0] = mac_addr;
13221
13222 hddLog(VOS_TRACE_LEVEL_ERROR,
13223 "%s: WLAN Mac Addr: "
13224 MAC_ADDRESS_STR, __func__,
13225 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
13226
13227 /* Here, passing Arg2 as 1 because we do not want to change the
13228 last 3 bytes (means non OUI bytes) of first interface mac
13229 addr.
13230 */
13231 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 1, mac_addr))
13232 {
13233 hddLog(VOS_TRACE_LEVEL_ERROR,
13234 "%s: Failed to generate wlan interface mac addr "
13235 "using MAC from ini file ", __func__);
13236 }
13237 }
13238 else if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
13239 {
13240 // Apply the NV to cfg.dat
13241 /* Prima Update MAC address only at here */
Jeff Johnson295189b2012-06-20 16:38:30 -070013242#ifdef WLAN_AUTOGEN_MACADDR_FEATURE
13243 /* There was not a valid set of MAC Addresses in NV. See if the
13244 default addresses were modified by the cfg.ini settings. If so,
13245 we'll use them, but if not, we'll autogenerate a set of MAC
13246 addresses based upon the device serial number */
13247
13248 static const v_MACADDR_t default_address =
13249 {{0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}};
Jeff Johnson295189b2012-06-20 16:38:30 -070013250
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013251 if (0 == memcmp(&default_address, &pHddCtx->cfg_ini->intfMacAddr[0],
13252 sizeof(default_address)))
Jeff Johnson295189b2012-06-20 16:38:30 -070013253 {
13254 /* cfg.ini has the default address, invoke autogen logic */
13255
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013256 /* Here, passing Arg2 as 0 because we want to change the
13257 last 3 bytes (means non OUI bytes) of all the interfaces
13258 mac addr.
13259 */
13260 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 0,
13261 default_address))
Jeff Johnson295189b2012-06-20 16:38:30 -070013262 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013263 hddLog(VOS_TRACE_LEVEL_ERROR,
13264 "%s: Failed to generate wlan interface mac addr "
13265 "using MAC from ini file " MAC_ADDRESS_STR, __func__,
13266 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
Jeff Johnson295189b2012-06-20 16:38:30 -070013267 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013268 }
13269 else
13270#endif //WLAN_AUTOGEN_MACADDR_FEATURE
13271 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013272 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -070013273 "%s: Invalid MAC address in NV, using MAC from ini file "
13274 MAC_ADDRESS_STR, __func__,
13275 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
13276 }
13277 }
13278 {
13279 eHalStatus halStatus;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013280
13281 /* Set the MAC Address Currently this is used by HAL to
13282 * add self sta. Remove this once self sta is added as
13283 * part of session open.
13284 */
Jeff Johnson295189b2012-06-20 16:38:30 -070013285 halStatus = cfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
13286 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
13287 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]) );
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013288
Jeff Johnson295189b2012-06-20 16:38:30 -070013289 if (!HAL_STATUS_SUCCESS( halStatus ))
13290 {
13291 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
13292 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013293 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013294 }
13295 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013296
13297 /*Start VOSS which starts up the SME/MAC/HAL modules and everything else
13298 Note: Firmware image will be read and downloaded inside vos_start API */
13299 status = vos_start( pHddCtx->pvosContext );
13300 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13301 {
13302 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053013303 if (isSsrPanicOnFailure())
13304 VOS_BUG(0);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013305 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013306 }
13307
Leo Chang6cec3e22014-01-21 15:33:49 -080013308#ifdef FEATURE_WLAN_CH_AVOID
13309 /* Plug in avoid channel notification callback
13310 * This should happen before ADD_SELF_STA
13311 * FW will send first IND with ADD_SELF_STA REQ from host */
Pradeep Reddy POTTETI5c2e16d2014-06-27 16:47:38 +053013312
13313 /* check the Channel Avoidance is enabled */
13314 if (TRUE == pHddCtx->cfg_ini->fenableCHAvoidance)
13315 {
13316 sme_AddChAvoidCallback(pHddCtx->hHal,
13317 hdd_hostapd_ch_avoid_cb);
13318 }
Leo Chang6cec3e22014-01-21 15:33:49 -080013319#endif /* FEATURE_WLAN_CH_AVOID */
13320
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070013321 /* Exchange capability info between Host and FW and also get versioning info from FW */
13322 hdd_exchange_version_and_caps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070013323
Agarwal Ashishad9281b2014-06-10 14:57:30 +053013324#ifdef CONFIG_ENABLE_LINUX_REG
13325 status = wlan_hdd_init_channels(pHddCtx);
13326 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13327 {
13328 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels failed",
13329 __func__);
13330 goto err_vosstop;
13331 }
13332#endif
13333
Jeff Johnson295189b2012-06-20 16:38:30 -070013334 status = hdd_post_voss_start_config( pHddCtx );
13335 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13336 {
13337 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_post_voss_start_config failed",
13338 __func__);
13339 goto err_vosstop;
13340 }
Amar Singhala49cbc52013-10-08 18:37:44 -070013341
13342#ifndef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013343 wlan_hdd_cfg80211_update_reg_info( wiphy );
13344
13345 /* registration of wiphy dev with cfg80211 */
13346 if (0 > wlan_hdd_cfg80211_register(wiphy))
13347 {
13348 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
13349 goto err_vosstop;
13350 }
Amar Singhala49cbc52013-10-08 18:37:44 -070013351#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013352
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013353#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013354 /* registration of wiphy dev with cfg80211 */
13355 if (0 > wlan_hdd_cfg80211_register(wiphy))
13356 {
13357 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
13358 goto err_vosstop;
13359 }
13360
Agarwal Ashish6db9d532014-09-30 18:19:10 +053013361 status = wlan_hdd_init_channels_for_cc(pHddCtx, INIT);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013362 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13363 {
13364 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels_for_cc failed",
13365 __func__);
13366 goto err_unregister_wiphy;
13367 }
13368#endif
13369
c_hpothu4a298be2014-12-22 21:12:51 +053013370 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
13371
Jeff Johnson295189b2012-06-20 16:38:30 -070013372 if (VOS_STA_SAP_MODE == hdd_get_conparam())
13373 {
13374 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP, "softap.%d",
13375 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
13376 }
13377 else
13378 {
Jeff Johnson295189b2012-06-20 16:38:30 -070013379 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_INFRA_STATION, "wlan%d",
13380 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
13381 if (pAdapter != NULL)
13382 {
Katya Nigama7d81d72014-11-12 12:44:34 +053013383 if (pHddCtx->cfg_ini->isP2pDeviceAddrAdministrated && !(pHddCtx->cfg_ini->intfMacAddr[0].bytes[0] & 0x02))
Jeff Johnson295189b2012-06-20 16:38:30 -070013384 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053013385 vos_mem_copy( pHddCtx->p2pDeviceAddress.bytes,
13386 pHddCtx->cfg_ini->intfMacAddr[0].bytes,
13387 sizeof(tSirMacAddr));
Madan Mohan Koyyalamudiedfc1b72012-10-18 20:25:55 -070013388
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053013389 /* Generate the P2P Device Address. This consists of the device's
13390 * primary MAC address with the locally administered bit set.
13391 */
13392 pHddCtx->p2pDeviceAddress.bytes[0] |= 0x02;
Jeff Johnsone7245742012-09-05 17:12:55 -070013393 }
13394 else
13395 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053013396 tANI_U8* p2p_dev_addr = wlan_hdd_get_intf_addr(pHddCtx);
13397 if (p2p_dev_addr != NULL)
13398 {
13399 vos_mem_copy(&pHddCtx->p2pDeviceAddress.bytes[0],
13400 p2p_dev_addr, VOS_MAC_ADDR_SIZE);
13401 }
13402 else
13403 {
13404 hddLog(VOS_TRACE_LEVEL_FATAL,
13405 "%s: Failed to allocate mac_address for p2p_device",
13406 __func__);
13407 goto err_close_adapter;
13408 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013409 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013410
13411 pP2pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_P2P_DEVICE, "p2p%d",
13412 &pHddCtx->p2pDeviceAddress.bytes[0], FALSE );
13413 if ( NULL == pP2pAdapter )
13414 {
13415 hddLog(VOS_TRACE_LEVEL_FATAL,
13416 "%s: Failed to do hdd_open_adapter for P2P Device Interface",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070013417 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070013418 goto err_close_adapter;
13419 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013420 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013421 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013422
13423 if( pAdapter == NULL )
13424 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013425 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
13426 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070013427 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013428
Arif Hussain66559122013-11-21 10:11:40 -080013429 if (country_code)
13430 {
13431 eHalStatus ret;
Arif Hussaincb607082013-12-20 11:57:42 -080013432 INIT_COMPLETION(pAdapter->change_country_code);
Arif Hussain66559122013-11-21 10:11:40 -080013433 hdd_checkandupdate_dfssetting(pAdapter, country_code);
13434#ifndef CONFIG_ENABLE_LINUX_REG
13435 hdd_checkandupdate_phymode(pAdapter, country_code);
13436#endif
Arif Hussaineaf68602013-12-30 23:10:44 -080013437 ret = sme_ChangeCountryCode(pHddCtx->hHal,
13438 (void *)(tSmeChangeCountryCallback)
13439 wlan_hdd_change_country_code_callback,
Arif Hussain66559122013-11-21 10:11:40 -080013440 country_code,
13441 pAdapter, pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +053013442 eSIR_TRUE, eSIR_TRUE);
Arif Hussain66559122013-11-21 10:11:40 -080013443 if (eHAL_STATUS_SUCCESS == ret)
13444 {
Arif Hussaincb607082013-12-20 11:57:42 -080013445 ret = wait_for_completion_interruptible_timeout(
13446 &pAdapter->change_country_code,
13447 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
13448
13449 if (0 >= ret)
13450 {
13451 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13452 "%s: SME while setting country code timed out", __func__);
13453 }
Arif Hussain66559122013-11-21 10:11:40 -080013454 }
13455 else
13456 {
Arif Hussaincb607082013-12-20 11:57:42 -080013457 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13458 "%s: SME Change Country code from module param fail ret=%d",
13459 __func__, ret);
Arif Hussain66559122013-11-21 10:11:40 -080013460 }
13461 }
13462
Jeff Johnson295189b2012-06-20 16:38:30 -070013463#ifdef WLAN_BTAMP_FEATURE
13464 vStatus = WLANBAP_Open(pVosContext);
13465 if(!VOS_IS_STATUS_SUCCESS(vStatus))
13466 {
13467 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13468 "%s: Failed to open BAP",__func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070013469 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070013470 }
13471
13472 vStatus = BSL_Init(pVosContext);
13473 if(!VOS_IS_STATUS_SUCCESS(vStatus))
13474 {
13475 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13476 "%s: Failed to Init BSL",__func__);
13477 goto err_bap_close;
13478 }
13479 vStatus = WLANBAP_Start(pVosContext);
13480 if (!VOS_IS_STATUS_SUCCESS(vStatus))
13481 {
13482 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13483 "%s: Failed to start TL",__func__);
13484 goto err_bap_close;
13485 }
13486
13487 pConfig = pHddCtx->cfg_ini;
13488 btAmpConfig.ucPreferredChannel = pConfig->preferredChannel;
13489 status = WLANBAP_SetConfig(&btAmpConfig);
13490
13491#endif //WLAN_BTAMP_FEATURE
Jeff Johnsone7245742012-09-05 17:12:55 -070013492
Mihir Shete9c238772014-10-15 14:35:16 +053013493 /*
13494 * UapsdMask is 0xf if U-APSD is enbaled for all AC's...
13495 * The value of CFG_QOS_WMM_UAPSD_MASK_DEFAULT is 0xaa(Magic Value)
13496 * which is greater than 0xf. So the below check is safe to make
13497 * sure that there is no entry for UapsdMask in the ini
13498 */
13499 if (CFG_QOS_WMM_UAPSD_MASK_DEFAULT == pHddCtx->cfg_ini->UapsdMask)
13500 {
13501 if(IS_DYNAMIC_WMM_PS_ENABLED)
13502 {
13503 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Enable UAPSD for VI & VO",
13504 __func__);
13505 pHddCtx->cfg_ini->UapsdMask =
13506 CFG_QOS_WMM_UAPSD_MASK_DYMANIC_WMM_PS_DEFAULT;
13507 }
13508 else
13509 {
13510 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Do not enable UAPSD",
13511 __func__);
13512 pHddCtx->cfg_ini->UapsdMask =
13513 CFG_QOS_WMM_UAPSD_MASK_LEGACY_WMM_PS_DEFAULT;
13514 }
13515 }
13516
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -070013517#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
13518 if(!(IS_ROAM_SCAN_OFFLOAD_FEATURE_ENABLE))
13519 {
13520 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: ROAM_SCAN_OFFLOAD Feature not supported",__func__);
13521 pHddCtx->cfg_ini->isRoamOffloadScanEnabled = 0;
13522 sme_UpdateRoamScanOffloadEnabled((tHalHandle)(pHddCtx->hHal),
13523 pHddCtx->cfg_ini->isRoamOffloadScanEnabled);
13524 }
13525#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013526
Agarwal Ashish4b87f922014-06-18 03:03:21 +053013527 wlan_hdd_tdls_init(pHddCtx);
13528
Masti, Narayanraddi26378462016-01-05 18:20:28 +053013529 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
13530
13531 vos_init_delayed_work(&pHddCtx->scan_ctxt.scan_work,
13532 wlan_hdd_schedule_defer_scan);
13533
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013534 sme_Register11dScanDoneCallback(pHddCtx->hHal, hdd_11d_scan_done);
13535
Jeff Johnson295189b2012-06-20 16:38:30 -070013536 /* Register with platform driver as client for Suspend/Resume */
13537 status = hddRegisterPmOps(pHddCtx);
13538 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13539 {
13540 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddRegisterPmOps failed",__func__);
13541#ifdef WLAN_BTAMP_FEATURE
13542 goto err_bap_stop;
13543#else
Jeff Johnsone7245742012-09-05 17:12:55 -070013544 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070013545#endif //WLAN_BTAMP_FEATURE
13546 }
13547
Yue Ma0d4891e2013-08-06 17:01:45 -070013548 /* Open debugfs interface */
13549 if (VOS_STATUS_SUCCESS != hdd_debugfs_init(pAdapter))
13550 {
13551 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
13552 "%s: hdd_debugfs_init failed!", __func__);
Yue Ma0d4891e2013-08-06 17:01:45 -070013553 }
13554
Jeff Johnson295189b2012-06-20 16:38:30 -070013555 /* Register TM level change handler function to the platform */
13556 status = hddDevTmRegisterNotifyCallback(pHddCtx);
13557 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13558 {
13559 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmRegisterNotifyCallback failed",__func__);
13560 goto err_unregister_pmops;
13561 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013562
Jeff Johnson295189b2012-06-20 16:38:30 -070013563 // register net device notifier for device change notification
13564 ret = register_netdevice_notifier(&hdd_netdev_notifier);
13565
13566 if(ret < 0)
13567 {
13568 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: register_netdevice_notifier failed",__func__);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053013569 goto err_unregister_pmops;
Jeff Johnson295189b2012-06-20 16:38:30 -070013570 }
13571
Jeff Johnson295189b2012-06-20 16:38:30 -070013572 //Initialize the BTC service
13573 if(btc_activate_service(pHddCtx) != 0)
13574 {
13575 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: btc_activate_service failed",__func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013576 goto err_reg_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -070013577 }
13578
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053013579#ifdef FEATURE_OEM_DATA_SUPPORT
13580 //Initialize the OEM service
13581 if (oem_activate_service(pHddCtx) != 0)
13582 {
13583 hddLog(VOS_TRACE_LEVEL_FATAL,
13584 "%s: oem_activate_service failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053013585 goto err_btc_activate_service;
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053013586 }
13587#endif
13588
Jeff Johnson295189b2012-06-20 16:38:30 -070013589#ifdef PTT_SOCK_SVC_ENABLE
13590 //Initialize the PTT service
13591 if(ptt_sock_activate_svc(pHddCtx) != 0)
13592 {
13593 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: ptt_sock_activate_svc failed",__func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053013594 goto err_oem_activate_service;
Jeff Johnson295189b2012-06-20 16:38:30 -070013595 }
13596#endif
13597
Abhishek Singh00b71972016-01-07 10:51:04 +053013598#ifdef WLAN_FEATURE_RMC
13599 if (hdd_open_cesium_nl_sock() < 0)
13600 {
13601 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_open_cesium_nl_sock failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053013602 goto err_ptt_sock_activate_svc;
Abhishek Singh00b71972016-01-07 10:51:04 +053013603 }
13604#endif
13605
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053013606#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
13607 if(pHddCtx->cfg_ini && pHddCtx->cfg_ini->wlanLoggingEnable)
13608 {
Deepthi Gowri78083a32014-11-04 12:55:51 +053013609 if(wlan_logging_sock_activate_svc(
13610 pHddCtx->cfg_ini->wlanLoggingFEToConsole,
Sushant Kaushik33200572015-08-05 16:46:20 +053013611 pHddCtx->cfg_ini->wlanLoggingNumBuf,
13612 pHddCtx->cfg_ini->wlanPerPktStatsLogEnable,
13613 pHddCtx->cfg_ini->wlanPerPktStatsNumBuf))
Deepthi Gowri78083a32014-11-04 12:55:51 +053013614 {
13615 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wlan_logging_sock_activate_svc"
13616 " failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053013617 goto err_open_cesium_nl_sock;
Deepthi Gowri78083a32014-11-04 12:55:51 +053013618 }
13619 //TODO: To Remove enableDhcpDebug and use gEnableDebugLog for
13620 //EAPOL and DHCP
Sachin Ahuja8c65f382014-12-12 15:34:21 +053013621 if (!pHddCtx->cfg_ini->gEnableDebugLog)
13622 pHddCtx->cfg_ini->gEnableDebugLog =
Sushant Kaushik6e4e2bc2015-10-05 17:23:07 +053013623 VOS_PKT_PROTO_TYPE_EAPOL | VOS_PKT_PROTO_TYPE_DHCP |
13624 VOS_PKT_PROTO_TYPE_ARP;
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053013625 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013626
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013627 if (pHddCtx->cfg_ini->wlanLoggingEnable &&
13628 (pHddCtx->cfg_ini->enableFWLogging ||
Siddharth Bhaldb963232015-06-25 19:34:35 +053013629 pHddCtx->cfg_ini->enableMgmtLogging ||
c_manjeecfd1efb2015-09-25 19:32:34 +053013630 pHddCtx->cfg_ini->enableContFWLogging ||
13631 pHddCtx->cfg_ini->enableFwrMemDump )
13632 )
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013633 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013634 hdd_init_frame_logging(pHddCtx);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013635 }
13636 else
13637 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013638 hddLog(VOS_TRACE_LEVEL_INFO, FL("Logging disabled in ini"));
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013639 }
13640
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053013641#endif
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013642
Agrawal Ashish17ef5082016-10-17 18:33:21 +053013643#ifdef SAP_AUTH_OFFLOAD
13644 if (!sme_IsFeatureSupportedByFW(SAP_OFFLOADS))
13645 {
13646 hddLog(VOS_TRACE_LEVEL_INFO, FL(" SAP AUTH OFFLOAD not supp by FW"));
13647 pHddCtx->cfg_ini->enable_sap_auth_offload = 0;
13648 }
13649#endif
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013650
Sushant Kaushik215778f2015-05-21 14:05:36 +053013651 if (vos_is_multicast_logging())
13652 wlan_logging_set_log_level();
13653
Jeff Johnson295189b2012-06-20 16:38:30 -070013654 hdd_register_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070013655 if (VOS_STA_SAP_MODE != hdd_get_conparam())
Jeff Johnson295189b2012-06-20 16:38:30 -070013656 {
Madan Mohan Koyyalamudic537df22012-10-22 15:07:08 -070013657 /* Action frame registered in one adapter which will
13658 * applicable to all interfaces
13659 */
Agarwal Ashish8fa0e9a2014-05-23 00:40:12 +053013660 wlan_hdd_cfg80211_register_frames(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070013661 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013662
13663 mutex_init(&pHddCtx->sap_lock);
Mahesh A Saptasagar60627942014-10-13 13:55:14 +053013664 mutex_init(&pHddCtx->roc_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070013665
Jeff Johnsone7245742012-09-05 17:12:55 -070013666#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
13667 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013668 vos_wake_lock_init(&pHddCtx->rx_wake_lock,
Jeff Johnsone7245742012-09-05 17:12:55 -070013669 "qcom_rx_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013670
Jeff Johnsone7245742012-09-05 17:12:55 -070013671#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080013672 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013673 vos_wake_lock_init(&pHddCtx->sap_wake_lock,
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080013674 "qcom_sap_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013675
Jeff Johnsone7245742012-09-05 17:12:55 -070013676
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070013677 vos_event_init(&pHddCtx->scan_info.scan_finished_event);
13678 pHddCtx->scan_info.scan_pending_option = WEXT_SCAN_PENDING_GIVEUP;
Jeff Johnson295189b2012-06-20 16:38:30 -070013679
Katya Nigam5c306ea2014-06-19 15:39:54 +053013680 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070013681 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013682 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Katya Nigam5c306ea2014-06-19 15:39:54 +053013683
13684#ifdef FEATURE_WLAN_SCAN_PNO
13685 /*SME must send channel update configuration to RIVA*/
13686 sme_UpdateChannelConfig(pHddCtx->hHal);
13687#endif
Abhishek Singhf644b272014-08-21 02:59:39 +053013688 /* Send the update default channel list to the FW*/
13689 sme_UpdateChannelList(pHddCtx->hHal);
Mukul Sharma45063942015-04-01 20:07:59 +053013690
13691 /* Fwr capabilities received, Set the Dot11 mode */
Abhishek Singh41ebce12016-02-03 10:43:21 +053013692 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
13693 hdd_cfg_xlate_to_csr_phy_mode(pHddCtx->cfg_ini->dot11Mode));
Mukul Sharma45063942015-04-01 20:07:59 +053013694 sme_SetDefDot11Mode(pHddCtx->hHal);
13695
Abhishek Singha306a442013-11-07 18:39:01 +053013696#ifndef CONFIG_ENABLE_LINUX_REG
13697 /*updating wiphy so that regulatory user hints can be processed*/
13698 if (wiphy)
13699 {
13700 regulatory_hint(wiphy, "00");
13701 }
13702#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070013703 // Initialize the restart logic
13704 wlan_hdd_restart_init(pHddCtx);
Chilam NG571c65a2013-01-19 12:27:36 +053013705
Hanumanth Reddy Pothula146bca42016-11-08 12:01:07 +053013706 if (pHddCtx->cfg_ini->fIsLogpEnabled) {
13707 vos_wdthread_init_timer_work(vos_process_wd_timer);
13708 /* Initialize the timer to detect thread stuck issues */
13709 vos_thread_stuck_timer_init(
13710 &((VosContextType*)pVosContext)->vosWatchdog);
13711 }
13712
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070013713 //Register the traffic monitor timer now
13714 if ( pHddCtx->cfg_ini->dynSplitscan)
13715 {
13716 vos_timer_init(&pHddCtx->tx_rx_trafficTmr,
13717 VOS_TIMER_TYPE_SW,
13718 hdd_tx_rx_pkt_cnt_stat_timer_handler,
13719 (void *)pHddCtx);
13720 }
Srinivas Dasari030bad32015-02-18 23:23:54 +053013721 wlan_hdd_cfg80211_nan_init(pHddCtx);
13722
Bhargav Shahd0715912015-10-01 18:17:37 +053013723 mutex_init(&pHddCtx->cur_rx_level_lock);
13724 vos_timer_init(&pHddCtx->delack_timer, VOS_TIMER_TYPE_SW,
13725 hdd_tcp_delack_compute_function,(void *)pHddCtx);
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053013726 vos_timer_init(&pHddCtx->tdls_source_timer, VOS_TIMER_TYPE_SW,
13727 wlan_hdd_change_tdls_mode, (void *)pHddCtx);
Bhargav Shahd0715912015-10-01 18:17:37 +053013728
Dino Mycle6fb96c12014-06-10 11:52:40 +053013729#ifdef WLAN_FEATURE_EXTSCAN
13730 sme_EXTScanRegisterCallback(pHddCtx->hHal,
13731 wlan_hdd_cfg80211_extscan_callback,
13732 pHddCtx);
13733#endif /* WLAN_FEATURE_EXTSCAN */
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053013734
Padma, Santhosh Kumar2ccac212015-10-20 17:27:27 +053013735#ifdef FEATURE_OEM_DATA_SUPPORT
13736 sme_OemDataRegisterCallback(pHddCtx->hHal,
13737 wlan_hdd_cfg80211_oemdata_callback,
13738 pHddCtx);
13739#endif /* FEATURE_OEM_DATA_SUPPORT */
13740
Gupta, Kapil7c34b322015-09-30 13:12:35 +053013741 sme_set_rssi_threshold_breached_cb(pHddCtx->hHal, hdd_rssi_threshold_breached_cb);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053013742#ifdef WLAN_NS_OFFLOAD
13743 // Register IPv6 notifier to notify if any change in IP
13744 // So that we can reconfigure the offload parameters
13745 pHddCtx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
13746 ret = register_inet6addr_notifier(&pHddCtx->ipv6_notifier);
13747 if (ret)
13748 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053013749 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053013750 }
13751 else
13752 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053013753 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053013754 }
13755#endif
13756
Sravan Kumar Kairamb0edc612016-10-26 13:55:24 +053013757 vos_mem_set((uint8_t *)&pHddCtx->bad_sta, HDD_MAX_STA_COUNT, 0);
13758
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053013759 // Register IPv4 notifier to notify if any change in IP
13760 // So that we can reconfigure the offload parameters
13761 pHddCtx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
13762 ret = register_inetaddr_notifier(&pHddCtx->ipv4_notifier);
13763 if (ret)
13764 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053013765 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053013766 }
13767 else
13768 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053013769 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053013770 }
c_manjeecfd1efb2015-09-25 19:32:34 +053013771 /*Fw mem dump procfs initialization*/
13772 memdump_init();
Bhargav shah23c94942015-10-13 12:48:35 +053013773 hdd_dp_util_send_rps_ind(pHddCtx);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053013774
Nishank Aggarwalc11826c2016-12-15 18:54:10 +053013775 pHddCtx->is_ap_mode_wow_supported =
13776 sme_IsFeatureSupportedByFW(SAP_MODE_WOW);
Sravan Kumar Kairam091e5b62017-01-23 14:14:20 +053013777
Hanumanth Reddy Pothulae92bcc12017-05-19 13:56:35 +053013778 pHddCtx->is_fatal_event_log_sup =
13779 sme_IsFeatureSupportedByFW(FATAL_EVENT_LOGGING);
13780 hddLog(VOS_TRACE_LEVEL_INFO, FL("FATAL_EVENT_LOGGING: %d"),
13781 pHddCtx->is_fatal_event_log_sup);
13782
Sravan Kumar Kairam091e5b62017-01-23 14:14:20 +053013783 hdd_assoc_registerFwdEapolCB(pVosContext);
13784
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +053013785 mutex_init(&pHddCtx->cache_channel_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070013786 goto success;
13787
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053013788err_open_cesium_nl_sock:
13789#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
13790 hdd_close_cesium_nl_sock();
13791#endif
13792
13793err_ptt_sock_activate_svc:
13794#ifdef PTT_SOCK_SVC_ENABLE
13795 ptt_sock_deactivate_svc(pHddCtx);
13796#endif
13797
13798err_oem_activate_service:
13799#ifdef FEATURE_OEM_DATA_SUPPORT
13800 oem_deactivate_service();
13801#endif
13802
13803err_btc_activate_service:
13804 btc_deactivate_service();
13805
Jeff Johnson295189b2012-06-20 16:38:30 -070013806err_reg_netdev:
13807 unregister_netdevice_notifier(&hdd_netdev_notifier);
13808
Jeff Johnson295189b2012-06-20 16:38:30 -070013809err_unregister_pmops:
13810 hddDevTmUnregisterNotifyCallback(pHddCtx);
13811 hddDeregisterPmOps(pHddCtx);
13812
Yue Ma0d4891e2013-08-06 17:01:45 -070013813 hdd_debugfs_exit(pHddCtx);
13814
Jeff Johnson295189b2012-06-20 16:38:30 -070013815#ifdef WLAN_BTAMP_FEATURE
13816err_bap_stop:
13817 WLANBAP_Stop(pVosContext);
13818#endif
13819
13820#ifdef WLAN_BTAMP_FEATURE
13821err_bap_close:
13822 WLANBAP_Close(pVosContext);
13823#endif
13824
Jeff Johnson295189b2012-06-20 16:38:30 -070013825err_close_adapter:
13826 hdd_close_all_adapters( pHddCtx );
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053013827#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013828err_unregister_wiphy:
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053013829#endif
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013830 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053013831 hdd_wlan_free_wiphy_channels(wiphy);
13832
Jeff Johnson295189b2012-06-20 16:38:30 -070013833err_vosstop:
13834 vos_stop(pVosContext);
13835
Amar Singhala49cbc52013-10-08 18:37:44 -070013836err_vosclose:
Jeff Johnson295189b2012-06-20 16:38:30 -070013837 status = vos_sched_close( pVosContext );
13838 if (!VOS_IS_STATUS_SUCCESS(status)) {
13839 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
13840 "%s: Failed to close VOSS Scheduler", __func__);
13841 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
13842 }
Amar Singhala49cbc52013-10-08 18:37:44 -070013843 vos_close(pVosContext );
13844
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013845err_nl_srv:
13846#ifdef WLAN_KD_READY_NOTIFIER
13847 nl_srv_exit(pHddCtx->ptt_pid);
13848#else
13849 nl_srv_exit();
13850#endif /* WLAN_KD_READY_NOTIFIER */
Amar Singhal0a402232013-10-11 20:57:16 -070013851err_vos_nv_close:
13852
c_hpothue6a36282014-03-19 12:27:38 +053013853#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070013854 vos_nv_close();
13855
c_hpothu70f8d812014-03-22 22:59:23 +053013856#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013857
13858err_wdclose:
13859 if(pHddCtx->cfg_ini->fIsLogpEnabled)
13860 vos_watchdog_close(pVosContext);
13861
Jeff Johnson295189b2012-06-20 16:38:30 -070013862err_config:
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053013863 hdd_request_manager_deinit();
Jeff Johnson295189b2012-06-20 16:38:30 -070013864 kfree(pHddCtx->cfg_ini);
13865 pHddCtx->cfg_ini= NULL;
13866
13867err_free_hdd_context:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013868 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053013869 free_riva_power_on_lock("wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070013870 wiphy_free(wiphy) ;
13871 //kfree(wdev) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070013872 VOS_BUG(1);
13873
Madan Mohan Koyyalamudid57ae632012-11-06 18:42:48 -080013874 if (hdd_is_ssr_required())
13875 {
13876 /* WDI timeout had happened during load, so SSR is needed here */
13877 subsystem_restart("wcnss");
13878 msleep(5000);
13879 }
13880 hdd_set_ssr_required (VOS_FALSE);
13881
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080013882 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070013883
13884success:
13885 EXIT();
13886 return 0;
13887}
13888
13889/**---------------------------------------------------------------------------
13890
Jeff Johnson32d95a32012-09-10 13:15:23 -070013891 \brief hdd_driver_init() - Core Driver Init Function
Jeff Johnson295189b2012-06-20 16:38:30 -070013892
Jeff Johnson32d95a32012-09-10 13:15:23 -070013893 This is the driver entry point - called in different timeline depending
13894 on whether the driver is statically or dynamically linked
Jeff Johnson295189b2012-06-20 16:38:30 -070013895
13896 \param - None
13897
13898 \return - 0 for success, non zero for failure
13899
13900 --------------------------------------------------------------------------*/
Jeff Johnson32d95a32012-09-10 13:15:23 -070013901static int hdd_driver_init( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070013902{
13903 VOS_STATUS status;
13904 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070013905 struct device *dev = NULL;
13906 int ret_status = 0;
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070013907#ifdef HAVE_WCNSS_CAL_DOWNLOAD
13908 int max_retries = 0;
13909#endif
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053013910#ifdef HAVE_CBC_DONE
13911 int max_cbc_retries = 0;
13912#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013913
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053013914#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
13915 wlan_logging_sock_init_svc();
13916#endif
13917
Jeff Johnson295189b2012-06-20 16:38:30 -070013918 ENTER();
13919
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013920 vos_wake_lock_init(&wlan_wake_lock, "wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070013921
13922 pr_info("%s: loading driver v%s\n", WLAN_MODULE_NAME,
13923 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
13924
Jeff Johnson295189b2012-06-20 16:38:30 -070013925#ifdef ANI_BUS_TYPE_PCI
13926
13927 dev = wcnss_wlan_get_device();
13928
13929#endif // ANI_BUS_TYPE_PCI
13930
13931#ifdef ANI_BUS_TYPE_PLATFORM
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070013932
13933#ifdef HAVE_WCNSS_CAL_DOWNLOAD
13934 /* wait until WCNSS driver downloads NV */
Ravi Kumar Bokka7a139e62016-11-17 21:32:55 +053013935 while (!wcnss_device_ready() && 10 >= ++max_retries) {
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070013936 msleep(1000);
13937 }
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053013938
Ravi Kumar Bokka7a139e62016-11-17 21:32:55 +053013939 if (max_retries >= 10) {
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070013940 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WCNSS driver not ready", __func__);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013941 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053013942#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
13943 wlan_logging_sock_deinit_svc();
13944#endif
13945
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070013946 return -ENODEV;
13947 }
13948#endif
13949
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053013950#ifdef HAVE_CBC_DONE
13951 while (!wcnss_cbc_complete() && 10 >= ++max_cbc_retries) {
13952 msleep(1000);
13953 }
13954 if (max_cbc_retries >= 10) {
13955 hddLog(VOS_TRACE_LEVEL_FATAL, "%s:CBC not completed", __func__);
13956 }
13957#endif
13958
Jeff Johnson295189b2012-06-20 16:38:30 -070013959 dev = wcnss_wlan_get_device();
13960#endif // ANI_BUS_TYPE_PLATFORM
13961
13962
13963 do {
13964 if (NULL == dev) {
13965 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: WLAN device not found!!",__func__);
13966 ret_status = -1;
13967 break;
13968 }
13969
Jeff Johnson295189b2012-06-20 16:38:30 -070013970#ifdef TIMER_MANAGER
13971 vos_timer_manager_init();
13972#endif
13973
13974 /* Preopen VOSS so that it is ready to start at least SAL */
13975 status = vos_preOpen(&pVosContext);
13976
13977 if (!VOS_IS_STATUS_SUCCESS(status))
13978 {
13979 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to preOpen VOSS", __func__);
13980 ret_status = -1;
13981 break;
13982 }
13983
Sushant Kaushik02beb352015-06-04 15:15:01 +053013984 hddTraceInit();
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +053013985 hdd_register_debug_callback();
13986
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070013987#ifndef MODULE
13988 /* For statically linked driver, call hdd_set_conparam to update curr_con_mode
13989 */
13990 hdd_set_conparam((v_UINT_t)con_mode);
13991#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013992
13993 // Call our main init function
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013994 if (hdd_wlan_startup(dev))
13995 {
Jeff Johnson295189b2012-06-20 16:38:30 -070013996 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WLAN Driver Initialization failed",
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013997 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070013998 vos_preClose( &pVosContext );
13999 ret_status = -1;
14000 break;
14001 }
14002
Jeff Johnson295189b2012-06-20 16:38:30 -070014003 } while (0);
14004
14005 if (0 != ret_status)
14006 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014007#ifdef TIMER_MANAGER
14008 vos_timer_exit();
14009#endif
14010#ifdef MEMORY_DEBUG
14011 vos_mem_exit();
14012#endif
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014013 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014014#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14015 wlan_logging_sock_deinit_svc();
14016#endif
14017
Jeff Johnson295189b2012-06-20 16:38:30 -070014018 pr_err("%s: driver load failure\n", WLAN_MODULE_NAME);
14019 }
14020 else
14021 {
14022 //Send WLAN UP indication to Nlink Service
14023 send_btc_nlink_msg(WLAN_MODULE_UP_IND, 0);
14024
14025 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Jeff Johnson295189b2012-06-20 16:38:30 -070014026 }
14027
14028 EXIT();
14029
14030 return ret_status;
14031}
14032
Jeff Johnson32d95a32012-09-10 13:15:23 -070014033/**---------------------------------------------------------------------------
14034
14035 \brief hdd_module_init() - Init Function
14036
14037 This is the driver entry point (invoked when module is loaded using insmod)
14038
14039 \param - None
14040
14041 \return - 0 for success, non zero for failure
14042
14043 --------------------------------------------------------------------------*/
14044#ifdef MODULE
14045static int __init hdd_module_init ( void)
14046{
14047 return hdd_driver_init();
14048}
Jeff Johnson32d95a32012-09-10 13:15:23 -070014049#else /* #ifdef MODULE */
14050static int __init hdd_module_init ( void)
14051{
14052 /* Driver initialization is delayed to fwpath_changed_handler */
14053 return 0;
14054}
Jeff Johnson32d95a32012-09-10 13:15:23 -070014055#endif /* #ifdef MODULE */
14056
Jeff Johnson295189b2012-06-20 16:38:30 -070014057
14058/**---------------------------------------------------------------------------
14059
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014060 \brief hdd_driver_exit() - Exit function
Jeff Johnson295189b2012-06-20 16:38:30 -070014061
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014062 This is the driver exit point (invoked when module is unloaded using rmmod
14063 or con_mode was changed by userspace)
Jeff Johnson295189b2012-06-20 16:38:30 -070014064
14065 \param - None
14066
14067 \return - None
14068
14069 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014070static void hdd_driver_exit(void)
Jeff Johnson295189b2012-06-20 16:38:30 -070014071{
14072 hdd_context_t *pHddCtx = NULL;
14073 v_CONTEXT_t pVosContext = NULL;
Agarwal Ashish5e414792014-06-08 15:25:23 +053014074 v_REGDOMAIN_t regId;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053014075 unsigned long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070014076
14077 pr_info("%s: unloading driver v%s\n", WLAN_MODULE_NAME, QWLAN_VERSIONSTR);
14078
14079 //Get the global vos context
14080 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
14081
14082 if(!pVosContext)
14083 {
14084 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
14085 goto done;
14086 }
14087
14088 //Get the HDD context.
14089 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
14090
14091 if(!pHddCtx)
14092 {
14093 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: module exit called before probe",__func__);
14094 }
Katya Nigame7b69a82015-04-28 15:24:06 +053014095 else if (VOS_MONITOR_MODE == hdd_get_conparam())
14096 {
14097 hddLog(VOS_TRACE_LEVEL_INFO,"%s: MONITOR MODE",__func__);
14098 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
14099 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
14100 hdd_wlan_exit(pHddCtx);
14101 vos_preClose( &pVosContext );
14102 goto done;
14103 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014104 else
14105 {
Siddharth Bhal2e5871b2015-03-24 16:20:51 +053014106 /* We wait for active entry threads to exit from driver
14107 * by waiting until rtnl_lock is available.
14108 */
14109 rtnl_lock();
14110 rtnl_unlock();
14111
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014112 INIT_COMPLETION(pHddCtx->ssr_comp_var);
14113 if ((pHddCtx->isLogpInProgress) && (FALSE ==
14114 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)))
14115 {
Siddharth Bhala204f572015-01-17 02:03:36 +053014116 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014117 "%s:SSR in Progress; block rmmod !!!", __func__);
Siddharth Bhala204f572015-01-17 02:03:36 +053014118 rc = wait_for_completion_timeout(&pHddCtx->ssr_comp_var,
14119 msecs_to_jiffies(30000));
14120 if(!rc)
14121 {
14122 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
14123 "%s:SSR timedout, fatal error", __func__);
14124 VOS_BUG(0);
14125 }
14126 }
14127
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014128 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
14129 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -070014130
c_hpothu8adb97b2014-12-08 19:38:20 +053014131 /* Driver Need to send country code 00 in below condition
14132 * 1) If gCountryCodePriority is set to 1; and last country
14133 * code set is through 11d. This needs to be done in case
14134 * when NV country code is 00.
14135 * This Needs to be done as when kernel store last country
14136 * code and if stored country code is not through 11d,
14137 * in sme_HandleChangeCountryCodeByUser we will disable 11d
14138 * in next load/unload as soon as we get any country through
14139 * 11d. In sme_HandleChangeCountryCodeByUser
14140 * pMsg->countryCode will be last countryCode and
14141 * pMac->scan.countryCode11d will be country through 11d so
14142 * due to mismatch driver will disable 11d.
14143 *
14144 */
Agarwal Ashish8db39882014-07-30 21:56:07 +053014145
c_hpothu8adb97b2014-12-08 19:38:20 +053014146 if ((eANI_BOOLEAN_TRUE == sme_Is11dCountrycode(pHddCtx->hHal) &&
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053014147 pHddCtx->cfg_ini->fSupplicantCountryCodeHasPriority &&
Abhishek Singh2a705962014-10-30 14:47:28 +053014148 sme_Is11dSupported(pHddCtx->hHal)))
c_hpothu8adb97b2014-12-08 19:38:20 +053014149 {
14150 hddLog(VOS_TRACE_LEVEL_INFO,
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053014151 FL("CountryCode 00 is being set while unloading driver"));
c_hpothu8adb97b2014-12-08 19:38:20 +053014152 vos_nv_getRegDomainFromCountryCode(&regId , "00", COUNTRY_USER);
14153 }
Agarwal Ashish5e414792014-06-08 15:25:23 +053014154
c_hpothu8adb97b2014-12-08 19:38:20 +053014155 //Do all the cleanup before deregistering the driver
14156 hdd_wlan_exit(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070014157 }
14158
Jeff Johnson295189b2012-06-20 16:38:30 -070014159 vos_preClose( &pVosContext );
14160
14161#ifdef TIMER_MANAGER
14162 vos_timer_exit();
14163#endif
14164#ifdef MEMORY_DEBUG
14165 vos_mem_exit();
14166#endif
14167
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014168#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14169 wlan_logging_sock_deinit_svc();
14170#endif
14171
Jeff Johnson295189b2012-06-20 16:38:30 -070014172done:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014173 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014174
Jeff Johnson295189b2012-06-20 16:38:30 -070014175 pr_info("%s: driver unloaded\n", WLAN_MODULE_NAME);
14176}
14177
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014178/**---------------------------------------------------------------------------
14179
14180 \brief hdd_module_exit() - Exit function
14181
14182 This is the driver exit point (invoked when module is unloaded using rmmod)
14183
14184 \param - None
14185
14186 \return - None
14187
14188 --------------------------------------------------------------------------*/
14189static void __exit hdd_module_exit(void)
14190{
14191 hdd_driver_exit();
14192}
14193
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014194#ifdef MODULE
14195static int fwpath_changed_handler(const char *kmessage,
14196 struct kernel_param *kp)
14197{
Jeff Johnson76052702013-04-16 13:55:05 -070014198 return param_set_copystring(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014199}
14200
14201static int con_mode_handler(const char *kmessage,
14202 struct kernel_param *kp)
14203{
Madan Mohan Koyyalamudif2f8d8b2012-10-11 17:06:59 -070014204 return param_set_int(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014205}
14206#else /* #ifdef MODULE */
14207/**---------------------------------------------------------------------------
14208
Jeff Johnson76052702013-04-16 13:55:05 -070014209 \brief kickstart_driver
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014210
Jeff Johnson76052702013-04-16 13:55:05 -070014211 This is the driver entry point
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014212 - delayed driver initialization when driver is statically linked
Jeff Johnson76052702013-04-16 13:55:05 -070014213 - invoked when module parameter fwpath is modified from userspace to signal
14214 initializing the WLAN driver or when con_mode is modified from userspace
14215 to signal a switch in operating mode
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014216
14217 \return - 0 for success, non zero for failure
14218
14219 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -070014220static int kickstart_driver(void)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014221{
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014222 int ret_status;
14223
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014224 if (!wlan_hdd_inited) {
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014225 ret_status = hdd_driver_init();
14226 wlan_hdd_inited = ret_status ? 0 : 1;
14227 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014228 }
14229
14230 hdd_driver_exit();
Jeff Johnson76052702013-04-16 13:55:05 -070014231
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014232 msleep(200);
Jeff Johnson76052702013-04-16 13:55:05 -070014233
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014234 ret_status = hdd_driver_init();
14235 wlan_hdd_inited = ret_status ? 0 : 1;
14236 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014237}
14238
Jeff Johnson295189b2012-06-20 16:38:30 -070014239/**---------------------------------------------------------------------------
14240
Jeff Johnson76052702013-04-16 13:55:05 -070014241 \brief fwpath_changed_handler() - Handler Function
14242
14243 Handle changes to the fwpath parameter
14244
14245 \return - 0 for success, non zero for failure
14246
14247 --------------------------------------------------------------------------*/
14248static int fwpath_changed_handler(const char *kmessage,
14249 struct kernel_param *kp)
14250{
14251 int ret;
14252
14253 ret = param_set_copystring(kmessage, kp);
14254 if (0 == ret)
14255 ret = kickstart_driver();
14256 return ret;
14257}
14258
14259/**---------------------------------------------------------------------------
14260
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014261 \brief con_mode_handler() -
14262
14263 Handler function for module param con_mode when it is changed by userspace
14264 Dynamically linked - do nothing
14265 Statically linked - exit and init driver, as in rmmod and insmod
14266
Jeff Johnson76052702013-04-16 13:55:05 -070014267 \param -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014268
Jeff Johnson76052702013-04-16 13:55:05 -070014269 \return -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014270
14271 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -070014272static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014273{
Jeff Johnson76052702013-04-16 13:55:05 -070014274 int ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014275
Jeff Johnson76052702013-04-16 13:55:05 -070014276 ret = param_set_int(kmessage, kp);
14277 if (0 == ret)
14278 ret = kickstart_driver();
14279 return ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014280}
14281#endif /* #ifdef MODULE */
14282
14283/**---------------------------------------------------------------------------
14284
Jeff Johnson295189b2012-06-20 16:38:30 -070014285 \brief hdd_get_conparam() -
14286
14287 This is the driver exit point (invoked when module is unloaded using rmmod)
14288
14289 \param - None
14290
14291 \return - tVOS_CON_MODE
14292
14293 --------------------------------------------------------------------------*/
14294tVOS_CON_MODE hdd_get_conparam ( void )
14295{
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014296#ifdef MODULE
Jeff Johnson295189b2012-06-20 16:38:30 -070014297 return (tVOS_CON_MODE)con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014298#else
14299 return (tVOS_CON_MODE)curr_con_mode;
14300#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014301}
14302void hdd_set_conparam ( v_UINT_t newParam )
14303{
14304 con_mode = newParam;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014305#ifndef MODULE
14306 curr_con_mode = con_mode;
14307#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014308}
14309/**---------------------------------------------------------------------------
14310
14311 \brief hdd_softap_sta_deauth() - function
14312
14313 This to take counter measure to handle deauth req from HDD
14314
14315 \param - pAdapter - Pointer to the HDD
14316
14317 \param - enable - boolean value
14318
14319 \return - None
14320
14321 --------------------------------------------------------------------------*/
14322
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014323VOS_STATUS hdd_softap_sta_deauth(hdd_adapter_t *pAdapter,
14324 struct tagCsrDelStaParams *pDelStaParams)
Jeff Johnson295189b2012-06-20 16:38:30 -070014325{
Jeff Johnson295189b2012-06-20 16:38:30 -070014326 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080014327 VOS_STATUS vosStatus = VOS_STATUS_E_FAULT;
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014328 struct hdd_cache_sta_info *cache_sta_info;
14329 ptSapContext pSapCtx = VOS_GET_SAP_CB(pVosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014330
14331 ENTER();
14332
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014333 hddLog(LOG1, "hdd_softap_sta_deauth:(%pK, false)",
Rajesh Chauhan18488fc2013-08-22 10:15:03 -070014334 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014335
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014336 if (!pSapCtx) {
14337 hddLog(LOGE, "sap context is NULL");
14338 return vosStatus;
14339 }
14340
14341 cache_sta_info = hdd_get_cache_stainfo(pSapCtx->cache_sta_info,
14342 pDelStaParams->peerMacAddr);
14343 if (cache_sta_info) {
14344 cache_sta_info->reason_code = pDelStaParams->reason_code;
14345 cache_sta_info->rx_rate =
14346 wlan_tl_get_sta_rx_rate(pVosContext, cache_sta_info->ucSTAId);
14347 WLANTL_GetSAPStaRSSi(pVosContext, cache_sta_info->ucSTAId,
14348 &cache_sta_info->rssi);
14349 }
14350
Jeff Johnson295189b2012-06-20 16:38:30 -070014351 //Ignore request to deauth bcmc station
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014352 if (pDelStaParams->peerMacAddr[0] & 0x1)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080014353 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070014354
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014355 vosStatus = WLANSAP_DeauthSta(pVosContext, pDelStaParams);
Jeff Johnson295189b2012-06-20 16:38:30 -070014356
14357 EXIT();
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080014358 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070014359}
14360
14361/**---------------------------------------------------------------------------
14362
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014363 \brief hdd_del_all_sta() - function
14364
14365 This function removes all the stations associated on stopping AP/P2P GO.
14366
14367 \param - pAdapter - Pointer to the HDD
14368
14369 \return - None
14370
14371 --------------------------------------------------------------------------*/
14372
14373int hdd_del_all_sta(hdd_adapter_t *pAdapter)
14374{
14375 v_U16_t i;
14376 VOS_STATUS vos_status;
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053014377 v_CONTEXT_t pVosContext = ( WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
14378 ptSapContext pSapCtx = NULL;
14379 pSapCtx = VOS_GET_SAP_CB(pVosContext);
14380 if(pSapCtx == NULL){
14381 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
14382 FL("psapCtx is NULL"));
14383 return 1;
14384 }
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014385 ENTER();
14386
14387 hddLog(VOS_TRACE_LEVEL_INFO,
14388 "%s: Delete all STAs associated.",__func__);
14389 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
14390 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
14391 )
14392 {
14393 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
14394 {
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053014395 if ((pSapCtx->aStaInfo[i].isUsed) &&
14396 (!pSapCtx->aStaInfo[i].isDeauthInProgress))
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014397 {
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014398 struct tagCsrDelStaParams delStaParams;
14399
14400 WLANSAP_PopulateDelStaParams(
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053014401 pSapCtx->aStaInfo[i].macAddrSTA.bytes,
Sushant Kaushik4cd28f62014-12-26 14:23:50 +053014402 eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
14403 SIR_MAC_MGMT_DEAUTH >> 4,
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014404 &delStaParams);
14405 vos_status = hdd_softap_sta_deauth(pAdapter, &delStaParams);
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014406 if (VOS_IS_STATUS_SUCCESS(vos_status))
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053014407 pSapCtx->aStaInfo[i].isDeauthInProgress = TRUE;
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053014408 }
14409 }
14410 }
14411
14412 EXIT();
14413 return 0;
14414}
14415
14416/**---------------------------------------------------------------------------
14417
Jeff Johnson295189b2012-06-20 16:38:30 -070014418 \brief hdd_softap_sta_disassoc() - function
14419
14420 This to take counter measure to handle deauth req from HDD
14421
14422 \param - pAdapter - Pointer to the HDD
14423
14424 \param - enable - boolean value
14425
14426 \return - None
14427
14428 --------------------------------------------------------------------------*/
14429
14430void hdd_softap_sta_disassoc(hdd_adapter_t *pAdapter,v_U8_t *pDestMacAddress)
14431{
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014432 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
14433 struct hdd_cache_sta_info *cache_sta_info;
14434 ptSapContext pSapCtx = VOS_GET_SAP_CB(pVosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014435
14436 ENTER();
14437
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014438 hddLog( LOGE, "hdd_softap_sta_disassoc:(%pK, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014439
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014440 if (!pSapCtx) {
14441 hddLog(LOGE, "sap context is NULL");
14442 return ;
14443 }
14444
Jeff Johnson295189b2012-06-20 16:38:30 -070014445 //Ignore request to disassoc bcmc station
14446 if( pDestMacAddress[0] & 0x1 )
14447 return;
14448
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014449 cache_sta_info = hdd_get_cache_stainfo(pSapCtx->cache_sta_info,
14450 pDestMacAddress);
14451 if (cache_sta_info) {
14452 cache_sta_info->reason_code = eSIR_MAC_DEAUTH_LEAVING_BSS_REASON;
14453 cache_sta_info->rx_rate =
14454 wlan_tl_get_sta_rx_rate(pVosContext, cache_sta_info->ucSTAId);
14455 WLANTL_GetSAPStaRSSi(pVosContext, cache_sta_info->ucSTAId,
14456 &cache_sta_info->rssi);
14457 }
14458
Jeff Johnson295189b2012-06-20 16:38:30 -070014459 WLANSAP_DisassocSta(pVosContext,pDestMacAddress);
14460}
14461
14462void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *pAdapter,v_BOOL_t enable)
14463{
14464 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
14465
14466 ENTER();
14467
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014468 hddLog( LOGE, "hdd_softap_tkip_mic_fail_counter_measure:(%pK, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014469
14470 WLANSAP_SetCounterMeasure(pVosContext, (v_BOOL_t)enable);
14471}
14472
Jeff Johnson295189b2012-06-20 16:38:30 -070014473/**---------------------------------------------------------------------------
14474 *
14475 * \brief hdd_get__concurrency_mode() -
14476 *
14477 *
14478 * \param - None
14479 *
14480 * \return - CONCURRENCY MODE
14481 *
14482 * --------------------------------------------------------------------------*/
14483tVOS_CONCURRENCY_MODE hdd_get_concurrency_mode ( void )
14484{
14485 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
14486 hdd_context_t *pHddCtx;
14487
14488 if (NULL != pVosContext)
14489 {
14490 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
14491 if (NULL != pHddCtx)
14492 {
14493 return (tVOS_CONCURRENCY_MODE)pHddCtx->concurrency_mode;
14494 }
14495 }
14496
14497 /* we are in an invalid state :( */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070014498 hddLog(LOGE, "%s: Invalid context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070014499 return VOS_STA;
14500}
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053014501v_BOOL_t
14502wlan_hdd_is_GO_power_collapse_allowed (hdd_context_t* pHddCtx)
14503{
14504 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070014505
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053014506 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_GO);
14507 if (pAdapter == NULL)
14508 {
14509 hddLog(VOS_TRACE_LEVEL_INFO,
14510 FL("GO doesn't exist"));
14511 return TRUE;
14512 }
14513 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
14514 {
14515 hddLog(VOS_TRACE_LEVEL_INFO,
14516 FL("GO started"));
14517 return TRUE;
14518 }
14519 else
14520 /* wait till GO changes its interface to p2p device */
14521 hddLog(VOS_TRACE_LEVEL_INFO,
14522 FL("Del_bss called, avoid apps suspend"));
14523 return FALSE;
14524
14525}
Jeff Johnson295189b2012-06-20 16:38:30 -070014526/* Decide whether to allow/not the apps power collapse.
14527 * Allow apps power collapse if we are in connected state.
14528 * if not, allow only if we are in IMPS */
14529v_BOOL_t hdd_is_apps_power_collapse_allowed(hdd_context_t* pHddCtx)
14530{
14531 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
Srikant Kuppafef66a72013-01-30 17:32:44 -080014532 tANI_BOOLEAN scanRspPending = csrNeighborRoamScanRspPending(pHddCtx->hHal);
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080014533 tANI_BOOLEAN inMiddleOfRoaming = csrNeighborMiddleOfRoaming(pHddCtx->hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -070014534 hdd_config_t *pConfig = pHddCtx->cfg_ini;
14535 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
14536 hdd_adapter_t *pAdapter = NULL;
14537 VOS_STATUS status;
Yathish9f22e662012-12-10 14:21:35 -080014538 tVOS_CONCURRENCY_MODE concurrent_state = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070014539
Jeff Johnson295189b2012-06-20 16:38:30 -070014540 if (VOS_STA_SAP_MODE == hdd_get_conparam())
14541 return TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -070014542
Yathish9f22e662012-12-10 14:21:35 -080014543 concurrent_state = hdd_get_concurrency_mode();
14544
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053014545 if ((concurrent_state == (VOS_STA | VOS_P2P_GO)) &&
14546 !(wlan_hdd_is_GO_power_collapse_allowed(pHddCtx)))
14547 return FALSE;
Yathish9f22e662012-12-10 14:21:35 -080014548#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053014549
Yathish9f22e662012-12-10 14:21:35 -080014550 if(((concurrent_state == (VOS_STA | VOS_P2P_CLIENT)) ||
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053014551 (concurrent_state == (VOS_STA | VOS_P2P_GO)))&&
Yathish9f22e662012-12-10 14:21:35 -080014552 (IS_ACTIVEMODE_OFFLOAD_FEATURE_ENABLE))
14553 return TRUE;
14554#endif
14555
Jeff Johnson295189b2012-06-20 16:38:30 -070014556 /*loop through all adapters. TBD fix for Concurrency */
14557 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
14558 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
14559 {
14560 pAdapter = pAdapterNode->pAdapter;
14561 if ( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
14562 || (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
14563 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080014564 if (((pConfig->fIsImpsEnabled || pConfig->fIsBmpsEnabled)
c_hpothu4e8faac2014-05-16 17:38:44 +053014565 && (pmcState != IMPS && pmcState != BMPS && pmcState != UAPSD
c_hpothu1c6957d2015-01-06 18:19:47 +053014566 && pmcState != STOPPED && pmcState != STANDBY &&
14567 pmcState != WOWL)) ||
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080014568 (eANI_BOOLEAN_TRUE == scanRspPending) ||
14569 (eANI_BOOLEAN_TRUE == inMiddleOfRoaming))
Jeff Johnson295189b2012-06-20 16:38:30 -070014570 {
Mukul Sharma4be88422015-03-09 20:29:07 +053014571 if(pmcState == FULL_POWER &&
14572 sme_IsCoexScoIndicationSet(pHddCtx->hHal))
14573 {
14574 /*
14575 * When SCO indication comes from Coex module , host will
14576 * enter in to full power mode, but this should not prevent
14577 * apps processor power collapse.
14578 */
14579 hddLog(LOG1,
14580 FL("Allow apps power collapse"
14581 "even when sco indication is set"));
14582 return TRUE;
14583 }
Srikant Kuppafef66a72013-01-30 17:32:44 -080014584 hddLog( LOGE, "%s: do not allow APPS power collapse-"
Deepthi Gowri03a979f2016-11-03 15:20:19 +053014585 "pmcState = %d scanRspPending = %d "
14586 "inMiddleOfRoaming = %d connected = %d",
14587 __func__, pmcState, scanRspPending,
14588 inMiddleOfRoaming, hdd_connIsConnected(
14589 WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )));
14590 wlan_hdd_get_tdls_stats(pAdapter);
14591 return FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070014592 }
14593 }
14594 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
14595 pAdapterNode = pNext;
14596 }
14597 return TRUE;
14598}
14599
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -080014600/* Decides whether to send suspend notification to Riva
14601 * if any adapter is in BMPS; then it is required */
14602v_BOOL_t hdd_is_suspend_notify_allowed(hdd_context_t* pHddCtx)
14603{
14604 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
14605 hdd_config_t *pConfig = pHddCtx->cfg_ini;
14606
14607 if (pConfig->fIsBmpsEnabled && (pmcState == BMPS))
14608 {
14609 return TRUE;
14610 }
14611 return FALSE;
14612}
14613
Jeff Johnson295189b2012-06-20 16:38:30 -070014614void wlan_hdd_set_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
14615{
14616 switch(mode)
14617 {
Chilam Ngc4244af2013-04-01 15:37:32 -070014618 case VOS_STA_MODE:
14619 case VOS_P2P_CLIENT_MODE:
14620 case VOS_P2P_GO_MODE:
14621 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053014622 case VOS_MONITOR_MODE:
Jeff Johnsone7245742012-09-05 17:12:55 -070014623 pHddCtx->concurrency_mode |= (1 << mode);
Agarwal Ashish51325b52014-06-16 16:50:49 +053014624 pHddCtx->no_of_open_sessions[mode]++;
Jeff Johnson295189b2012-06-20 16:38:30 -070014625 break;
14626 default:
14627 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070014628 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053014629 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
14630 "Number of open sessions for mode %d = %d"),
14631 pHddCtx->concurrency_mode, mode,
14632 pHddCtx->no_of_open_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070014633}
14634
14635
14636void wlan_hdd_clear_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
14637{
14638 switch(mode)
14639 {
Chilam Ngc4244af2013-04-01 15:37:32 -070014640 case VOS_STA_MODE:
14641 case VOS_P2P_CLIENT_MODE:
14642 case VOS_P2P_GO_MODE:
14643 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053014644 case VOS_MONITOR_MODE:
Agarwal Ashish51325b52014-06-16 16:50:49 +053014645 pHddCtx->no_of_open_sessions[mode]--;
14646 if (!(pHddCtx->no_of_open_sessions[mode]))
14647 pHddCtx->concurrency_mode &= (~(1 << mode));
Jeff Johnson295189b2012-06-20 16:38:30 -070014648 break;
14649 default:
14650 break;
14651 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053014652 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
14653 "Number of open sessions for mode %d = %d"),
14654 pHddCtx->concurrency_mode, mode, pHddCtx->no_of_open_sessions[mode]);
14655
14656}
14657/**---------------------------------------------------------------------------
14658 *
14659 * \brief wlan_hdd_incr_active_session()
14660 *
14661 * This function increments the number of active sessions
14662 * maintained per device mode
14663 * Incase of STA/P2P CLI/IBSS upon connection indication it is incremented
14664 * Incase of SAP/P2P GO upon bss start it is incremented
14665 *
14666 * \param pHddCtx - HDD Context
14667 * \param mode - device mode
14668 *
14669 * \return - None
14670 *
14671 * --------------------------------------------------------------------------*/
14672void wlan_hdd_incr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
14673{
14674 switch (mode) {
14675 case VOS_STA_MODE:
14676 case VOS_P2P_CLIENT_MODE:
14677 case VOS_P2P_GO_MODE:
14678 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053014679 case VOS_MONITOR_MODE:
Agarwal Ashish51325b52014-06-16 16:50:49 +053014680 pHddCtx->no_of_active_sessions[mode]++;
14681 break;
14682 default:
14683 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
14684 break;
14685 }
14686 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
14687 mode,
14688 pHddCtx->no_of_active_sessions[mode]);
14689}
14690
14691/**---------------------------------------------------------------------------
14692 *
14693 * \brief wlan_hdd_decr_active_session()
14694 *
14695 * This function decrements the number of active sessions
14696 * maintained per device mode
14697 * Incase of STA/P2P CLI/IBSS upon disconnection it is decremented
14698 * Incase of SAP/P2P GO upon bss stop it is decremented
14699 *
14700 * \param pHddCtx - HDD Context
14701 * \param mode - device mode
14702 *
14703 * \return - None
14704 *
14705 * --------------------------------------------------------------------------*/
14706void wlan_hdd_decr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
14707{
Bhargav Shahd0715912015-10-01 18:17:37 +053014708
Agarwal Ashish51325b52014-06-16 16:50:49 +053014709 switch (mode) {
14710 case VOS_STA_MODE:
14711 case VOS_P2P_CLIENT_MODE:
14712 case VOS_P2P_GO_MODE:
14713 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053014714 case VOS_MONITOR_MODE:
Agarwal Ashish5325f522014-08-06 00:58:44 +053014715 if (pHddCtx->no_of_active_sessions[mode] > 0)
14716 pHddCtx->no_of_active_sessions[mode]--;
14717 else
14718 hddLog(VOS_TRACE_LEVEL_INFO, FL(" No.# of Active sessions"
14719 "is already Zero"));
Agarwal Ashish51325b52014-06-16 16:50:49 +053014720 break;
14721 default:
14722 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
14723 break;
14724 }
14725 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
14726 mode,
14727 pHddCtx->no_of_active_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070014728}
14729
Jeff Johnsone7245742012-09-05 17:12:55 -070014730/**---------------------------------------------------------------------------
14731 *
14732 * \brief wlan_hdd_restart_init
14733 *
14734 * This function initalizes restart timer/flag. An internal function.
14735 *
14736 * \param - pHddCtx
14737 *
14738 * \return - None
14739 *
14740 * --------------------------------------------------------------------------*/
14741
14742static void wlan_hdd_restart_init(hdd_context_t *pHddCtx)
14743{
14744 /* Initialize */
14745 pHddCtx->hdd_restart_retries = 0;
14746 atomic_set(&pHddCtx->isRestartInProgress, 0);
14747 vos_timer_init(&pHddCtx->hdd_restart_timer,
14748 VOS_TIMER_TYPE_SW,
14749 wlan_hdd_restart_timer_cb,
14750 pHddCtx);
14751}
14752/**---------------------------------------------------------------------------
14753 *
14754 * \brief wlan_hdd_restart_deinit
14755 *
14756 * This function cleans up the resources used. An internal function.
14757 *
14758 * \param - pHddCtx
14759 *
14760 * \return - None
14761 *
14762 * --------------------------------------------------------------------------*/
14763
14764static void wlan_hdd_restart_deinit(hdd_context_t* pHddCtx)
14765{
14766
14767 VOS_STATUS vos_status;
14768 /* Block any further calls */
14769 atomic_set(&pHddCtx->isRestartInProgress, 1);
14770 /* Cleanup */
14771 vos_status = vos_timer_stop( &pHddCtx->hdd_restart_timer );
14772 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053014773 hddLog(LOGE, FL("Failed to stop HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070014774 vos_status = vos_timer_destroy(&pHddCtx->hdd_restart_timer);
14775 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053014776 hddLog(LOGE, FL("Failed to destroy HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070014777
14778}
14779
14780/**---------------------------------------------------------------------------
14781 *
14782 * \brief wlan_hdd_framework_restart
14783 *
14784 * This function uses a cfg80211 API to start a framework initiated WLAN
14785 * driver module unload/load.
14786 *
14787 * Also this API keep retrying (WLAN_HDD_RESTART_RETRY_MAX_CNT).
14788 *
14789 *
14790 * \param - pHddCtx
14791 *
14792 * \return - VOS_STATUS_SUCCESS: Success
14793 * VOS_STATUS_E_EMPTY: Adapter is Empty
14794 * VOS_STATUS_E_NOMEM: No memory
14795
14796 * --------------------------------------------------------------------------*/
14797
14798static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx)
14799{
14800 VOS_STATUS status = VOS_STATUS_SUCCESS;
14801 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070014802 int len = (sizeof (struct ieee80211_mgmt));
14803 struct ieee80211_mgmt *mgmt = NULL;
14804
14805 /* Prepare the DEAUTH managment frame with reason code */
14806 mgmt = kzalloc(len, GFP_KERNEL);
14807 if(mgmt == NULL)
14808 {
14809 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
14810 "%s: memory allocation failed (%d bytes)", __func__, len);
14811 return VOS_STATUS_E_NOMEM;
14812 }
14813 mgmt->u.deauth.reason_code = WLAN_REASON_DISASSOC_LOW_ACK;
Jeff Johnsone7245742012-09-05 17:12:55 -070014814
14815 /* Iterate over all adapters/devices */
14816 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053014817 if ((NULL == pAdapterNode) || (VOS_STATUS_SUCCESS != status))
14818 {
14819 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014820 FL("fail to get adapter: %pK %d"), pAdapterNode, status);
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053014821 goto end;
14822 }
14823
Jeff Johnsone7245742012-09-05 17:12:55 -070014824 do
14825 {
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053014826 if(pAdapterNode->pAdapter &&
14827 WLAN_HDD_ADAPTER_MAGIC == pAdapterNode->pAdapter->magic)
Jeff Johnsone7245742012-09-05 17:12:55 -070014828 {
14829 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
14830 "restarting the driver(intf:\'%s\' mode:%d :try %d)",
14831 pAdapterNode->pAdapter->dev->name,
14832 pAdapterNode->pAdapter->device_mode,
14833 pHddCtx->hdd_restart_retries + 1);
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070014834 /*
14835 * CFG80211 event to restart the driver
14836 *
14837 * 'cfg80211_send_unprot_deauth' sends a
14838 * NL80211_CMD_UNPROT_DEAUTHENTICATE event to supplicant at any state
14839 * of SME(Linux Kernel) state machine.
14840 *
14841 * Reason code WLAN_REASON_DISASSOC_LOW_ACK is currently used to restart
14842 * the driver.
14843 *
14844 */
Abhishek Singh00b71972016-01-07 10:51:04 +053014845
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053014846#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
14847 cfg80211_rx_unprot_mlme_mgmt(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len);
14848#else
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070014849 cfg80211_send_unprot_deauth(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053014850#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070014851 }
14852 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
14853 pAdapterNode = pNext;
14854 } while((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status));
14855
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053014856 end:
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070014857 /* Free the allocated management frame */
14858 kfree(mgmt);
14859
Jeff Johnsone7245742012-09-05 17:12:55 -070014860 /* Retry until we unload or reach max count */
14861 if(++pHddCtx->hdd_restart_retries < WLAN_HDD_RESTART_RETRY_MAX_CNT)
14862 vos_timer_start(&pHddCtx->hdd_restart_timer, WLAN_HDD_RESTART_RETRY_DELAY_MS);
14863
14864 return status;
14865
14866}
14867/**---------------------------------------------------------------------------
14868 *
14869 * \brief wlan_hdd_restart_timer_cb
14870 *
14871 * Restart timer callback. An internal function.
14872 *
14873 * \param - User data:
14874 *
14875 * \return - None
14876 *
14877 * --------------------------------------------------------------------------*/
14878
14879void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback)
14880{
14881 hdd_context_t *pHddCtx = usrDataForCallback;
14882 wlan_hdd_framework_restart(pHddCtx);
14883 return;
14884
14885}
14886
14887
14888/**---------------------------------------------------------------------------
14889 *
14890 * \brief wlan_hdd_restart_driver
14891 *
14892 * This function sends an event to supplicant to restart the WLAN driver.
14893 *
14894 * This function is called from vos_wlanRestart.
14895 *
14896 * \param - pHddCtx
14897 *
14898 * \return - VOS_STATUS_SUCCESS: Success
14899 * VOS_STATUS_E_EMPTY: Adapter is Empty
14900 * VOS_STATUS_E_ALREADY: Request already in progress
14901
14902 * --------------------------------------------------------------------------*/
14903VOS_STATUS wlan_hdd_restart_driver(hdd_context_t *pHddCtx)
14904{
14905 VOS_STATUS status = VOS_STATUS_SUCCESS;
14906
14907 /* A tight check to make sure reentrancy */
14908 if(atomic_xchg(&pHddCtx->isRestartInProgress, 1))
14909 {
Mihir Shetefd528652014-06-23 19:07:50 +053014910 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsone7245742012-09-05 17:12:55 -070014911 "%s: WLAN restart is already in progress", __func__);
14912
14913 return VOS_STATUS_E_ALREADY;
14914 }
Sameer Thalappil0c164f52013-03-28 15:27:56 -070014915 /* Send reset FIQ to WCNSS to invoke SSR. */
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -080014916#ifdef HAVE_WCNSS_RESET_INTR
Siddharth Bhal864e7e82015-04-07 20:07:24 +053014917 wcnss_reset_fiq(TRUE);
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -070014918#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070014919
Jeff Johnsone7245742012-09-05 17:12:55 -070014920 return status;
14921}
14922
Bhargav Shahd0715912015-10-01 18:17:37 +053014923/**
14924 * hdd_get_total_sessions() - provide total number of active sessions
14925 * @pHddCtx: Valid Global HDD context pointer
14926 *
14927 * This function iterates through pAdaptors and find the number of all active
14928 * sessions. This active sessions includes connected sta, p2p client and number
14929 * of client connected to sap/p2p go.
14930 *
14931 * Return: Total number of active sessions.
14932 */
14933v_U8_t hdd_get_total_sessions(hdd_context_t *pHddCtx)
14934{
14935 v_U8_t active_session = 0;
14936 hdd_station_ctx_t *pHddStaCtx;
14937 hdd_adapter_list_node_t *pAdapterNode, *pNext;
14938 hdd_adapter_t *pAdapter;
14939 VOS_STATUS status;
14940
14941 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
14942 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
14943 pAdapter = pAdapterNode->pAdapter;
14944 switch (pAdapter->device_mode) {
14945 case VOS_STA_MODE:
14946 case VOS_P2P_CLIENT_MODE:
14947 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
14948 if(eConnectionState_Associated == pHddStaCtx->conn_info.connState)
14949 active_session += 1;
14950 break;
14951 case VOS_STA_SAP_MODE:
14952 case VOS_P2P_GO_MODE:
14953 active_session += hdd_softap_get_connected_sta(pAdapter);
14954 break;
14955 default:
14956 break;
14957 }
14958
14959 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
14960 pAdapterNode = pNext;
14961 }
14962
14963 return active_session;
14964}
14965
14966/**
14967 * hdd_set_delack_value() - Set delack value
14968 * @pHddCtx: Valid Global HDD context pointer
14969 * @next_rx_level: Value to set for delack
14970 *
14971 * This function compare present value and next value of delack. If the both
14972 * are diffrent then it sets next value .
14973 *
14974 * Return: void.
14975 */
14976void hdd_set_delack_value(hdd_context_t *pHddCtx, v_U32_t next_rx_level)
14977{
14978 if (pHddCtx->cur_rx_level != next_rx_level) {
14979 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
14980 "%s: TCP DELACK trigger level %d",
14981 __func__, next_rx_level);
14982 mutex_lock(&pHddCtx->cur_rx_level_lock);
14983 pHddCtx->cur_rx_level = next_rx_level;
14984 mutex_unlock(&pHddCtx->cur_rx_level_lock);
14985 wlan_hdd_send_svc_nlink_msg(WLAN_SVC_WLAN_TP_IND, &next_rx_level,
14986 sizeof(next_rx_level));
14987 }
14988}
14989
14990/**
14991 * hdd_set_default_stop_delack_timer() - Start delack timer
14992 * @pHddCtx: Valid Global HDD context pointer
14993 *
14994 * This function stop delack timer and set delack value to default..
14995 *
14996 * Return: void.
14997 */
14998
14999void hdd_set_default_stop_delack_timer(hdd_context_t *pHddCtx)
15000{
15001 if (VOS_TIMER_STATE_RUNNING !=
15002 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
15003 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15004 "%s: Can not stop timer", __func__);
15005 return;
15006 }
15007
15008 vos_timer_stop(&pHddCtx->delack_timer);
15009 hdd_set_delack_value(pHddCtx, TP_IND_LOW);
15010}
15011
15012/**
15013 * hdd_start_delack_timer() - Start delack timer
15014 * @pHddCtx: Valid Global HDD context pointer
15015 *
15016 * This function starts the delack timer for tcpDelAckComputeInterval time
15017 * interval.The default timer value is 2 second.
15018 *
15019 * Return: void.
15020 */
15021void hdd_start_delack_timer(hdd_context_t *pHddCtx)
15022{
15023 if (VOS_TIMER_STATE_RUNNING ==
15024 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
15025 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15026 "%s: Timer is already running", __func__);
15027 return;
15028 }
15029
15030 vos_timer_start(&pHddCtx->delack_timer,
15031 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
15032}
15033
15034/**
15035 * hdd_update_prev_rx_packet_count() - Update previous rx packet count
15036 * @pHddCtx: Valid Global HDD context pointer
15037 *
15038 * This function updates the prev_rx_packets count from the corresponding
15039 * pAdapter states. This prev_rx_packets will diffed with the packet count
15040 * at the end of delack timer. That can give number of RX packet is spacific
15041 * time.
15042 *
15043 * Return: void.
15044 */
15045void hdd_update_prev_rx_packet_count(hdd_context_t *pHddCtx)
15046{
15047 hdd_adapter_list_node_t *pAdapterNode, *pNext;
15048 hdd_adapter_t *pAdapter;
15049 VOS_STATUS status;
15050
15051 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15052 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
15053 pAdapter = pAdapterNode->pAdapter;
15054 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
15055 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15056 pAdapterNode = pNext;
15057 }
15058}
15059
15060/**
15061 * hdd_manage_delack_timer() - start\stop delack timer
15062 * @pHddCtx: Valid Global HDD context pointer
15063 *
15064 * This function check the number of concerent session present, it starts the
15065 * delack timer if only one session is present.
15066 * In the case of BT_COEX and TDLS mode it blindly stop delack functionality.
15067 *
15068 * Return: void.
15069 */
15070void hdd_manage_delack_timer(hdd_context_t *pHddCtx)
15071{
15072 uint8_t sessions;
15073
15074 if (!pHddCtx->cfg_ini->enable_delack) {
15075 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15076 "%s: TCP DELACK is not enabled", __func__);
15077 return;
15078 }
15079
15080 /* Blindly stop timer of BTCOEX and TDLS Session is up */
15081 if (pHddCtx->mode != 0) {
15082 hdd_set_default_stop_delack_timer(pHddCtx);
15083 return;
15084 }
15085
15086 sessions = hdd_get_total_sessions(pHddCtx);
15087 if (sessions == 1) {
15088 hdd_update_prev_rx_packet_count(pHddCtx);
15089 hdd_start_delack_timer(pHddCtx);
15090 } else {
15091 hdd_set_default_stop_delack_timer(pHddCtx);
15092 }
15093}
15094
Mihir Shetee1093ba2014-01-21 20:13:32 +053015095/**---------------------------------------------------------------------------
15096 *
15097 * \brief wlan_hdd_init_channels
15098 *
15099 * This function is used to initialize the channel list in CSR
15100 *
15101 * This function is called from hdd_wlan_startup
15102 *
15103 * \param - pHddCtx: HDD context
15104 *
15105 * \return - VOS_STATUS_SUCCESS: Success
15106 * VOS_STATUS_E_FAULT: Failure reported by SME
15107
15108 * --------------------------------------------------------------------------*/
15109static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx)
15110{
15111 eHalStatus status;
15112
15113 status = sme_InitChannels(pHddCtx->hHal);
15114 if (HAL_STATUS_SUCCESS(status))
15115 {
15116 return VOS_STATUS_SUCCESS;
15117 }
15118 else
15119 {
15120 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Channel initialization failed(%d)",
15121 __func__, status);
15122 return VOS_STATUS_E_FAULT;
15123 }
15124}
15125
Mihir Shete04206452014-11-20 17:50:58 +053015126#ifdef CONFIG_ENABLE_LINUX_REG
Agarwal Ashish6db9d532014-09-30 18:19:10 +053015127VOS_STATUS wlan_hdd_init_channels_for_cc(hdd_context_t *pHddCtx, driver_load_type init )
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053015128{
15129 eHalStatus status;
15130
Agarwal Ashish6db9d532014-09-30 18:19:10 +053015131 status = sme_InitChannelsForCC(pHddCtx->hHal, init);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053015132 if (HAL_STATUS_SUCCESS(status))
15133 {
15134 return VOS_STATUS_SUCCESS;
15135 }
15136 else
15137 {
15138 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Issue reg hint failed(%d)",
15139 __func__, status);
15140 return VOS_STATUS_E_FAULT;
15141 }
15142}
Mihir Shete04206452014-11-20 17:50:58 +053015143#endif
Sudhir Sattayappa Kohallib1d8c3a2013-06-18 14:47:20 -070015144/*
15145 * API to find if there is any STA or P2P-Client is connected
15146 */
15147VOS_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *pHddCtx)
15148{
15149 return sme_isSta_p2p_clientConnected(pHddCtx->hHal);
15150}
Jeff Johnsone7245742012-09-05 17:12:55 -070015151
Mihir Shetee2ae82a2015-03-16 14:08:49 +053015152
15153/*
15154 * API to find if the firmware will send logs using DXE channel
15155 */
15156v_U8_t hdd_is_fw_logging_enabled(void)
15157{
15158 hdd_context_t *pHddCtx;
15159
15160 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
15161 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
15162
Sachin Ahuja084313e2015-05-21 17:57:10 +053015163 return (pHddCtx && pHddCtx->cfg_ini->enableMgmtLogging);
Mihir Shetee2ae82a2015-03-16 14:08:49 +053015164}
15165
Agarwal Ashish57e84372014-12-05 18:26:53 +053015166/*
Mihir Shetebe94ebb2015-05-26 12:07:14 +053015167 * API to find if the firmware will send trace logs using DXE channel
15168 */
15169v_U8_t hdd_is_fw_ev_logging_enabled(void)
15170{
15171 hdd_context_t *pHddCtx;
15172
15173 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
15174 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
15175
15176 return (pHddCtx && pHddCtx->cfg_ini->enableFWLogging);
15177}
15178/*
Agarwal Ashish57e84372014-12-05 18:26:53 +053015179 * API to find if there is any session connected
15180 */
15181VOS_STATUS hdd_is_any_session_connected(hdd_context_t *pHddCtx)
15182{
15183 return sme_is_any_session_connected(pHddCtx->hHal);
15184}
15185
15186
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015187int wlan_hdd_scan_abort(hdd_adapter_t *pAdapter)
15188{
15189 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
15190 hdd_scaninfo_t *pScanInfo = NULL;
Girish Gowli4bf7a632014-06-12 13:42:11 +053015191 long status = 0;
c_hpothua3d45d52015-01-05 14:11:17 +053015192 tSirAbortScanStatus abortScanStatus;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015193
15194 pScanInfo = &pHddCtx->scan_info;
Ratnam Rachuric7681132015-06-30 10:35:13 +053015195 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015196 if (pScanInfo->mScanPending)
15197 {
c_hpothua3d45d52015-01-05 14:11:17 +053015198 abortScanStatus = hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
15199 eCSR_SCAN_ABORT_DEFAULT);
15200 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15201 FL("abortScanStatus: %d"), abortScanStatus);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015202
c_hpothua3d45d52015-01-05 14:11:17 +053015203 /* If there is active scan command lets wait for the completion else
15204 * there is no need to wait as scan command might be in the SME pending
15205 * command list.
15206 */
15207 if (abortScanStatus == eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY)
15208 {
Mukul Sharmab392b642017-08-17 17:45:29 +053015209 status = wait_for_completion_timeout(
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015210 &pScanInfo->abortscan_event_var,
15211 msecs_to_jiffies(5000));
c_hpothua3d45d52015-01-05 14:11:17 +053015212 if (0 >= status)
15213 {
15214 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Girish Gowli4bf7a632014-06-12 13:42:11 +053015215 "%s: Timeout or Interrupt occurred while waiting for abort"
15216 "scan, status- %ld", __func__, status);
c_hpothua3d45d52015-01-05 14:11:17 +053015217 return -ETIMEDOUT;
15218 }
15219 }
15220 else if (abortScanStatus == eSIR_ABORT_SCAN_FAILURE)
15221 {
15222 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15223 FL("hdd_abort_mac_scan failed"));
15224 return -VOS_STATUS_E_FAILURE;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015225 }
15226 }
Girish Gowli4bf7a632014-06-12 13:42:11 +053015227 return 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015228}
15229
Abhishek Singh7d624e12015-11-30 14:29:27 +053015230/**
15231 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
15232 * user space
15233 * @frame_ind: Management frame data to be informed.
15234 *
15235 * This function is used to indicate management frame to
15236 * user space
15237 *
15238 * Return: None
15239 *
15240 */
15241void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
15242{
15243 hdd_context_t *hdd_ctx = NULL;
15244 hdd_adapter_t *adapter = NULL;
15245 v_CONTEXT_t vos_context = NULL;
15246
15247 /* Get the global VOSS context.*/
15248 vos_context = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
15249 if (!vos_context) {
15250 hddLog(LOGE, FL("Global VOS context is Null"));
15251 return;
15252 }
15253 /* Get the HDD context.*/
15254 hdd_ctx =
15255 (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, vos_context );
15256
15257 if (0 != wlan_hdd_validate_context(hdd_ctx))
15258 {
15259 return;
15260 }
15261 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
15262 frame_ind->sessionId);
15263
15264 if ((NULL != adapter) &&
15265 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
15266 __hdd_indicate_mgmt_frame(adapter,
15267 frame_ind->frameLen,
15268 frame_ind->frameBuf,
15269 frame_ind->frameType,
15270 frame_ind->rxChan,
15271 frame_ind->rxRssi);
15272 return;
15273
15274}
15275
c_hpothu225aa7c2014-10-22 17:45:13 +053015276VOS_STATUS wlan_hdd_cancel_remain_on_channel(hdd_context_t *pHddCtx)
15277{
15278 hdd_adapter_t *pAdapter;
15279 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15280 VOS_STATUS vosStatus;
15281
15282 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15283 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
15284 {
15285 pAdapter = pAdapterNode->pAdapter;
15286 if (NULL != pAdapter)
15287 {
15288 if (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode ||
15289 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
15290 WLAN_HDD_P2P_GO == pAdapter->device_mode)
15291 {
15292 hddLog(LOG1, FL("abort ROC deviceMode: %d"),
15293 pAdapter->device_mode);
15294 if (VOS_STATUS_SUCCESS !=
15295 wlan_hdd_cancel_existing_remain_on_channel(pAdapter))
15296 {
15297 hddLog(LOGE, FL("failed to abort ROC"));
15298 return VOS_STATUS_E_FAILURE;
15299 }
15300 }
15301 }
15302 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15303 pAdapterNode = pNext;
15304 }
15305 return VOS_STATUS_SUCCESS;
15306}
Mahesh A Saptasagard477b092015-02-06 15:12:16 +053015307
Mihir Shete0be28772015-02-17 18:42:14 +053015308hdd_remain_on_chan_ctx_t *hdd_get_remain_on_channel_ctx(hdd_context_t *pHddCtx)
15309{
15310 hdd_adapter_t *pAdapter;
15311 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15312 hdd_cfg80211_state_t *cfgState;
15313 hdd_remain_on_chan_ctx_t *pRemainChanCtx = NULL;
15314 VOS_STATUS vosStatus;
15315
15316 vosStatus = hdd_get_front_adapter (pHddCtx, &pAdapterNode);
15317 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
15318 {
15319 pAdapter = pAdapterNode->pAdapter;
15320 if (NULL != pAdapter)
15321 {
15322 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter);
15323 pRemainChanCtx = cfgState->remain_on_chan_ctx;
15324 if (pRemainChanCtx)
15325 break;
15326 }
15327 vosStatus = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
15328 pAdapterNode = pNext;
15329 }
15330 return pRemainChanCtx;
15331}
15332
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +053015333/**
15334 * wlan_hdd_handle_dfs_chan_scan () - handles disable/enable DFS channels
15335 *
15336 * @pHddCtx: HDD context within host driver
15337 * @dfsScanMode: dfsScanMode passed from ioctl
15338 *
15339 */
15340
15341VOS_STATUS wlan_hdd_handle_dfs_chan_scan(hdd_context_t *pHddCtx,
15342 tANI_U8 dfsScanMode)
15343{
15344 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15345 hdd_adapter_t *pAdapter;
15346 VOS_STATUS vosStatus;
15347 hdd_station_ctx_t *pHddStaCtx;
15348 eHalStatus status = eHAL_STATUS_SUCCESS;
15349
15350 if(!pHddCtx)
15351 {
15352 hddLog(LOGE, FL("HDD context is Null"));
15353 return eHAL_STATUS_FAILURE;
15354 }
15355
15356 if (pHddCtx->scan_info.mScanPending)
15357 {
15358 hddLog(LOG1, FL("Aborting scan for sessionId: %d"),
15359 pHddCtx->scan_info.sessionId);
15360 hdd_abort_mac_scan(pHddCtx,
15361 pHddCtx->scan_info.sessionId,
15362 eCSR_SCAN_ABORT_DEFAULT);
15363 }
15364
15365 if (!dfsScanMode)
15366 {
15367 vosStatus = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
15368 while ((NULL != pAdapterNode) &&
15369 (VOS_STATUS_SUCCESS == vosStatus))
15370 {
15371 pAdapter = pAdapterNode->pAdapter;
15372
15373 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
15374 {
15375 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
15376
15377 if(!pHddStaCtx)
15378 {
15379 hddLog(LOGE, FL("HDD STA context is Null"));
15380 return eHAL_STATUS_FAILURE;
15381 }
15382
15383 /* if STA is already connected on DFS channel,
15384 disconnect immediately*/
15385 if (hdd_connIsConnected(pHddStaCtx) &&
15386 (NV_CHANNEL_DFS ==
15387 vos_nv_getChannelEnabledState(
15388 pHddStaCtx->conn_info.operationChannel)))
15389 {
15390 status = sme_RoamDisconnect(pHddCtx->hHal,
15391 pAdapter->sessionId,
15392 eCSR_DISCONNECT_REASON_UNSPECIFIED);
15393 hddLog(LOG1, FL("Client connected on DFS channel %d,"
15394 "sme_RoamDisconnect returned with status: %d"
15395 "for sessionid: %d"), pHddStaCtx->conn_info.
15396 operationChannel, status, pAdapter->sessionId);
15397 }
15398 }
15399
15400 vosStatus = hdd_get_next_adapter(pHddCtx, pAdapterNode,
15401 &pNext);
15402 pAdapterNode = pNext;
15403 }
15404 }
15405
15406 sme_UpdateDFSScanMode(pHddCtx->hHal, dfsScanMode);
15407 sme_UpdateDFSRoamMode(pHddCtx->hHal,
15408 (dfsScanMode != DFS_CHNL_SCAN_DISABLED));
15409
15410 status = sme_HandleDFSChanScan(pHddCtx->hHal);
15411 if (!HAL_STATUS_SUCCESS(status))
15412 {
15413 hddLog(LOGE,
15414 FL("Failed in sme_HandleDFSChanScan (err=%d)"), status);
15415 return status;
15416 }
15417
15418 return status;
15419}
15420
Nirav Shah7e3c8132015-06-22 23:51:42 +053015421static int hdd_log2_ceil(unsigned value)
15422{
15423 /* need to switch to unsigned math so that negative values
15424 * will right-shift towards 0 instead of -1
15425 */
15426 unsigned tmp = value;
15427 int log2 = -1;
15428
15429 if (value == 0)
15430 return 0;
15431
15432 while (tmp) {
15433 log2++;
15434 tmp >>= 1;
15435 }
15436 if (1U << log2 != value)
15437 log2++;
15438
15439 return log2;
15440}
15441
15442/**
15443 * hdd_sta_id_hash_attach() - initialize sta id to macaddr hash
15444 * @pAdapter: adapter handle
15445 *
15446 * Return: vos status
15447 */
15448VOS_STATUS hdd_sta_id_hash_attach(hdd_adapter_t *pAdapter)
15449{
15450 int hash_elem, log2, i;
15451
15452 spin_lock_bh( &pAdapter->sta_hash_lock);
15453 if (pAdapter->is_sta_id_hash_initialized == VOS_TRUE) {
15454 spin_unlock_bh( &pAdapter->sta_hash_lock);
15455 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15456 "%s: hash already attached for session id %d",
15457 __func__, pAdapter->sessionId);
15458 return VOS_STATUS_SUCCESS;
15459 }
15460 spin_unlock_bh( &pAdapter->sta_hash_lock);
15461
15462 hash_elem = WLAN_MAX_STA_COUNT;
15463 hash_elem *= HDD_STA_ID_HASH_MULTIPLIER;
15464 log2 = hdd_log2_ceil(hash_elem);
15465 hash_elem = 1 << log2;
15466
15467 pAdapter->sta_id_hash.mask = hash_elem - 1;
15468 pAdapter->sta_id_hash.idx_bits = log2;
15469 pAdapter->sta_id_hash.bins =
15470 vos_mem_malloc(hash_elem *sizeof(hdd_list_t));
15471 if (!pAdapter->sta_id_hash.bins) {
15472 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15473 "%s: malloc failed for session %d",
15474 __func__, pAdapter->sessionId);
15475 return VOS_STATUS_E_NOMEM;
15476 }
15477
15478 for (i = 0; i < hash_elem; i++)
15479 hdd_list_init(&pAdapter->sta_id_hash.bins[i], WLAN_MAX_STA_COUNT);
15480
15481 spin_lock_bh( &pAdapter->sta_hash_lock);
15482 pAdapter->is_sta_id_hash_initialized = VOS_TRUE;
15483 spin_unlock_bh( &pAdapter->sta_hash_lock);
15484 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15485 "%s: Station ID Hash attached for session id %d",
15486 __func__, pAdapter->sessionId);
15487
15488 return VOS_STATUS_SUCCESS;
15489}
15490
15491/**
15492 * hdd_sta_id_hash_detach() - deinit sta_id to macaddr hash
15493 * @pAdapter: adapter handle
15494 *
15495 * Return: vos status
15496 */
15497VOS_STATUS hdd_sta_id_hash_detach(hdd_adapter_t *pAdapter)
15498{
15499 int hash_elem, i;
15500 v_SIZE_t size;
15501
15502 spin_lock_bh( &pAdapter->sta_hash_lock);
15503 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
15504 spin_unlock_bh( &pAdapter->sta_hash_lock);
15505 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15506 "%s: hash not initialized for session id %d",
15507 __func__, pAdapter->sessionId);
15508 return VOS_STATUS_SUCCESS;
15509 }
15510
15511 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
15512 spin_unlock_bh( &pAdapter->sta_hash_lock);
15513
15514 hash_elem = 1 << pAdapter->sta_id_hash.idx_bits;
15515
15516 /* free all station info*/
15517 for (i = 0; i < hash_elem; i++) {
15518 hdd_list_size(&pAdapter->sta_id_hash.bins[i], &size);
15519 if (size != 0) {
15520 VOS_STATUS status;
15521 hdd_staid_hash_node_t *sta_info_node = NULL;
15522 hdd_staid_hash_node_t *next_node = NULL;
15523 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[i],
15524 (hdd_list_node_t**) &sta_info_node );
15525
15526 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
15527 {
15528 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[i],
15529 &sta_info_node->node);
15530 vos_mem_free(sta_info_node);
15531
15532 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[i],
15533 (hdd_list_node_t*)sta_info_node,
15534 (hdd_list_node_t**)&next_node);
15535 sta_info_node = next_node;
15536 }
15537 }
15538 }
15539
15540 vos_mem_free(pAdapter->sta_id_hash.bins);
15541 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15542 "%s: Station ID Hash detached for session id %d",
15543 __func__, pAdapter->sessionId);
15544 return VOS_STATUS_SUCCESS;
15545}
15546
15547/**
15548 * hdd_sta_id_hash_calculate_index() - derive index from macaddr
15549 * @pAdapter: adapter handle
15550 * @mac_addr_in: input mac address
15551 *
15552 * Return: index derived from mac address
15553 */
15554int hdd_sta_id_hash_calculate_index(hdd_adapter_t *pAdapter,
15555 v_MACADDR_t *mac_addr_in)
15556{
15557 uint16 index;
15558 struct hdd_align_mac_addr_t * mac_addr =
15559 (struct hdd_align_mac_addr_t *)mac_addr_in;
15560
15561 index = mac_addr->bytes_ab ^
15562 mac_addr->bytes_cd ^ mac_addr->bytes_ef;
15563 index ^= index >> pAdapter->sta_id_hash.idx_bits;
15564 index &= pAdapter->sta_id_hash.mask;
15565 return index;
15566}
15567
15568/**
15569 * hdd_sta_id_hash_add_entry() - add entry in hash
15570 * @pAdapter: adapter handle
15571 * @sta_id: station id
15572 * @mac_addr: mac address
15573 *
15574 * Return: vos status
15575 */
15576VOS_STATUS hdd_sta_id_hash_add_entry(hdd_adapter_t *pAdapter,
15577 v_U8_t sta_id, v_MACADDR_t *mac_addr)
15578{
15579 uint16 index;
15580 hdd_staid_hash_node_t *sta_info_node = NULL;
15581
Nirav Shah7e3c8132015-06-22 23:51:42 +053015582 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
15583 sta_info_node = vos_mem_malloc(sizeof(hdd_staid_hash_node_t));
15584 if (!sta_info_node) {
Nirav Shah7e3c8132015-06-22 23:51:42 +053015585 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15586 "%s: malloc failed", __func__);
15587 return VOS_STATUS_E_NOMEM;
15588 }
15589
15590 sta_info_node->sta_id = sta_id;
15591 vos_mem_copy(&sta_info_node->mac_addr, mac_addr, sizeof(v_MACADDR_t));
15592
Nirav Shah303ed5c2015-08-24 10:29:25 +053015593 spin_lock_bh( &pAdapter->sta_hash_lock);
15594 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
15595 spin_unlock_bh( &pAdapter->sta_hash_lock);
15596 vos_mem_free(sta_info_node);
15597 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15598 "%s: hash is not initialized for session id %d",
15599 __func__, pAdapter->sessionId);
15600 return VOS_STATUS_E_FAILURE;
15601 }
15602
Nirav Shah7e3c8132015-06-22 23:51:42 +053015603 hdd_list_insert_back ( &pAdapter->sta_id_hash.bins[index],
15604 (hdd_list_node_t*) sta_info_node );
15605 spin_unlock_bh( &pAdapter->sta_hash_lock);
15606 return VOS_STATUS_SUCCESS;
15607}
15608
15609/**
15610 * hdd_sta_id_hash_remove_entry() - remove entry from hash
15611 * @pAdapter: adapter handle
15612 * @sta_id: station id
15613 * @mac_addr: mac address
15614 *
15615 * Return: vos status
15616 */
15617VOS_STATUS hdd_sta_id_hash_remove_entry(hdd_adapter_t *pAdapter,
15618 v_U8_t sta_id, v_MACADDR_t *mac_addr)
15619{
15620 uint16 index;
15621 VOS_STATUS status;
15622 hdd_staid_hash_node_t *sta_info_node = NULL;
15623 hdd_staid_hash_node_t *next_node = NULL;
15624
15625 spin_lock_bh( &pAdapter->sta_hash_lock);
15626 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
15627 spin_unlock_bh( &pAdapter->sta_hash_lock);
15628 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15629 "%s: hash is not initialized for session id %d",
15630 __func__, pAdapter->sessionId);
15631 return VOS_STATUS_E_FAILURE;
15632 }
15633
15634 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
15635 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
15636 (hdd_list_node_t**) &sta_info_node );
15637
15638 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
15639 {
15640 if (sta_info_node->sta_id == sta_id) {
15641 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[index],
15642 &sta_info_node->node);
15643 vos_mem_free(sta_info_node);
15644 break;
15645 }
15646 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
15647 (hdd_list_node_t*)sta_info_node, (hdd_list_node_t**)&next_node);
15648 sta_info_node = next_node;
15649 }
15650 spin_unlock_bh( &pAdapter->sta_hash_lock);
15651 return status;
15652}
15653
15654/**
15655 * hdd_sta_id_find_from_mac_addr() - find sta id from mac address
15656 * @pAdapter: adapter handle
15657 * @mac_addr_in: mac address
15658 *
15659 * Return: station id
15660 */
15661int hdd_sta_id_find_from_mac_addr(hdd_adapter_t *pAdapter,
15662 v_MACADDR_t *mac_addr_in)
15663{
15664 uint8 is_found = 0;
15665 uint8 sta_id = HDD_WLAN_INVALID_STA_ID;
15666 uint16 index;
15667 VOS_STATUS status;
15668 hdd_staid_hash_node_t *sta_info_node = NULL;
15669 hdd_staid_hash_node_t *next_node = NULL;
15670
15671 spin_lock_bh( &pAdapter->sta_hash_lock);
15672 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
15673 spin_unlock_bh( &pAdapter->sta_hash_lock);
Bhargav Shahce3b32c2015-08-10 12:29:24 +053015674 hddLog(VOS_TRACE_LEVEL_INFO,
Nirav Shah7e3c8132015-06-22 23:51:42 +053015675 FL("hash is not initialized for session id %d"),
15676 pAdapter->sessionId);
15677 return HDD_WLAN_INVALID_STA_ID;
15678 }
15679
15680 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr_in);
15681 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
15682 (hdd_list_node_t**) &sta_info_node );
15683
15684 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
15685 {
15686 if (vos_mem_compare(&sta_info_node->mac_addr,
15687 mac_addr_in, sizeof(v_MACADDR_t))) {
15688 is_found = 1;
15689 sta_id = sta_info_node->sta_id;
15690 break;
15691 }
15692 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
15693 (hdd_list_node_t*)sta_info_node,
15694 (hdd_list_node_t**)&next_node);
15695 sta_info_node = next_node;
15696 }
15697 spin_unlock_bh( &pAdapter->sta_hash_lock);
15698 return sta_id;
15699}
15700
c_manjeecfd1efb2015-09-25 19:32:34 +053015701/*FW memory dump feature*/
15702/**
15703 * This structure hold information about the /proc file
15704 *
15705 */
15706static struct proc_dir_entry *proc_file, *proc_dir;
15707
15708/**
15709 * memdump_read() - perform read operation in memory dump proc file
15710 *
15711 * @file - handle for the proc file.
15712 * @buf - pointer to user space buffer.
15713 * @count - number of bytes to be read.
15714 * @pos - offset in the from buffer.
15715 *
15716 * This function performs read operation for the memory dump proc file.
15717 *
15718 * Return: number of bytes read on success, error code otherwise.
15719 */
15720static ssize_t memdump_read(struct file *file, char __user *buf,
15721 size_t count, loff_t *pos)
15722{
15723 int status;
15724 hdd_context_t *hdd_ctx = (hdd_context_t *)PDE_DATA(file_inode(file));
15725 size_t ret_count;
c_manjeef1495642015-10-13 18:35:01 +053015726 loff_t bytes_left;
c_manjeecfd1efb2015-09-25 19:32:34 +053015727 ENTER();
15728
15729 hddLog(LOG1, FL("Read req for size:%zu pos:%llu"), count, *pos);
15730 status = wlan_hdd_validate_context(hdd_ctx);
15731 if (0 != status) {
15732 return -EINVAL;
15733 }
15734
15735 if (!wlan_fwr_mem_dump_test_and_set_read_allowed_bit()) {
15736 hddLog(LOGE, FL("Current mem dump request timed out/failed"));
15737 return -EINVAL;
15738 }
15739
15740 /* run fs_read_handler in an atomic context*/
15741 vos_ssr_protect(__func__);
c_manjeef1495642015-10-13 18:35:01 +053015742 ret_count = wlan_fwr_mem_dump_fsread_handler( buf, count, pos, &bytes_left);
15743 if(bytes_left == 0)
c_manjeecfd1efb2015-09-25 19:32:34 +053015744 {
15745 /*Free the fwr mem dump buffer */
15746 wlan_free_fwr_mem_dump_buffer();
15747 wlan_set_fwr_mem_dump_state(FW_MEM_DUMP_IDLE);
c_manjeef1495642015-10-13 18:35:01 +053015748 ret_count=0;
c_manjeecfd1efb2015-09-25 19:32:34 +053015749 }
15750 /*if SSR/unload code is waiting for memdump_read to finish,signal it*/
15751 vos_ssr_unprotect(__func__);
15752 EXIT();
15753 return ret_count;
15754}
15755
15756/**
15757 * struct memdump_fops - file operations for memory dump feature
15758 * @read - read function for memory dump operation.
15759 *
15760 * This structure initialize the file operation handle for memory
15761 * dump feature
15762 */
15763static const struct file_operations memdump_fops = {
15764 read: memdump_read
15765};
15766
15767/*
15768* wlan_hdd_fw_mem_dump_cb : callback for Fw mem dump request
15769* To be passed by HDD to WDA and called upon receiving of response
15770* from firmware
15771* @fwMemDumpReqContext : memory dump request context
15772* @dump_rsp : dump response from HAL
15773* Returns none
15774*/
15775void wlan_hdd_fw_mem_dump_cb(void *fwMemDumpReqContext,
15776 tAniFwrDumpRsp *dump_rsp)
15777{
c_manjeef1495642015-10-13 18:35:01 +053015778 struct hdd_fw_mem_dump_req_ctx *pHddFwMemDumpCtx = (struct hdd_fw_mem_dump_req_ctx *)fwMemDumpReqContext;
c_manjeecfd1efb2015-09-25 19:32:34 +053015779
c_manjeef1495642015-10-13 18:35:01 +053015780 ENTER();
15781 spin_lock(&hdd_context_lock);
15782 if(!pHddFwMemDumpCtx || (FW_MEM_DUMP_MAGIC != pHddFwMemDumpCtx->magic)) {
15783 spin_unlock(&hdd_context_lock);
15784 return;
15785 }
15786 /* report the status to requesting function and free mem.*/
c_manjeecfd1efb2015-09-25 19:32:34 +053015787 if (dump_rsp->dump_status != eHAL_STATUS_SUCCESS) {
c_manjeef1495642015-10-13 18:35:01 +053015788 hddLog(LOGE, FL("fw dump request declined by fwr"));
15789 //set the request completion variable
15790 complete(&(pHddFwMemDumpCtx->req_completion));
c_manjeecfd1efb2015-09-25 19:32:34 +053015791 //Free the allocated fwr dump
15792 wlan_free_fwr_mem_dump_buffer();
15793 wlan_set_fwr_mem_dump_state(FW_MEM_DUMP_IDLE);
c_manjeecfd1efb2015-09-25 19:32:34 +053015794 }
c_manjeef1495642015-10-13 18:35:01 +053015795 else {
15796 hddLog(LOG1, FL("fw dump request accepted by fwr"));
15797 /* register the HDD callback which will be called by SVC */
15798 wlan_set_svc_fw_mem_dump_req_cb((void*)wlan_hdd_fw_mem_dump_req_cb,(void*)pHddFwMemDumpCtx);
15799 }
15800 spin_unlock(&hdd_context_lock);
c_manjeecfd1efb2015-09-25 19:32:34 +053015801 EXIT();
15802
15803}
15804
15805/**
15806 * memdump_procfs_remove() - Remove file/dir under procfs for memory dump
15807 *
15808 * This function removes file/dir under proc file system that was
15809 * processing firmware memory dump
15810 *
15811 * Return: None
15812 */
15813static void memdump_procfs_remove(void)
15814{
15815 remove_proc_entry(PROCFS_MEMDUMP_NAME, proc_dir);
15816 hddLog(LOG1 , FL("/proc/%s/%s removed\n"),
15817 PROCFS_MEMDUMP_DIR, PROCFS_MEMDUMP_NAME);
15818 remove_proc_entry(PROCFS_MEMDUMP_DIR, NULL);
15819 hddLog(LOG1 , FL("/proc/%s removed\n"), PROCFS_MEMDUMP_DIR);
15820}
15821
15822/**
15823 * memdump_procfs_init() - Initialize procfs for memory dump
15824 *
15825 * @vos_ctx - Global vos context.
15826 *
15827 * This function create file under proc file system to be used later for
15828 * processing firmware memory dump
15829 *
15830 * Return: 0 on success, error code otherwise.
15831 */
15832static int memdump_procfs_init(void *vos_ctx)
15833{
15834 hdd_context_t *hdd_ctx;
15835
15836 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
15837 if (!hdd_ctx) {
15838 hddLog(LOGE , FL("Invalid HDD context"));
15839 return -EINVAL;
15840 }
15841
15842 proc_dir = proc_mkdir(PROCFS_MEMDUMP_DIR, NULL);
15843 if (proc_dir == NULL) {
15844 remove_proc_entry(PROCFS_MEMDUMP_DIR, NULL);
15845 hddLog(LOGE , FL("Error: Could not initialize /proc/%s"),
15846 PROCFS_MEMDUMP_DIR);
15847 return -ENOMEM;
15848 }
15849
15850 proc_file = proc_create_data(PROCFS_MEMDUMP_NAME,
15851 S_IRUSR | S_IWUSR, proc_dir,
15852 &memdump_fops, hdd_ctx);
15853 if (proc_file == NULL) {
15854 remove_proc_entry(PROCFS_MEMDUMP_NAME, proc_dir);
15855 hddLog(LOGE , FL("Error: Could not initialize /proc/%s"),
15856 PROCFS_MEMDUMP_NAME);
15857 return -ENOMEM;
15858 }
15859
15860 hddLog(LOG1 , FL("/proc/%s/%s created"),
15861 PROCFS_MEMDUMP_DIR, PROCFS_MEMDUMP_NAME);
15862
15863 return 0;
15864}
15865
15866/**
15867 * memdump_init() - Initialization function for memory dump feature
15868 *
15869 * This function creates proc file for memdump feature and registers
15870 * HDD callback function with SME.
15871 *
15872 * Return - 0 on success, error otherwise
15873 */
15874int memdump_init(void)
15875{
15876 hdd_context_t *hdd_ctx;
15877 void *vos_ctx;
15878 int status = 0;
15879
15880 vos_ctx = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
15881 if (!vos_ctx) {
15882 hddLog(LOGE, FL("Invalid VOS context"));
15883 return -EINVAL;
15884 }
15885
15886 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
15887 if (!hdd_ctx) {
15888 hddLog(LOGE , FL("Invalid HDD context"));
15889 return -EINVAL;
15890 }
15891
15892 status = memdump_procfs_init(vos_ctx);
15893 if (status) {
15894 hddLog(LOGE , FL("Failed to create proc file"));
15895 return status;
15896 }
15897
15898 return 0;
15899}
15900
15901/**
15902 * memdump_deinit() - De initialize memdump feature
15903 *
15904 * This function removes proc file created for memdump feature.
15905 *
15906 * Return: None
15907 */
15908int memdump_deinit(void)
15909{
15910 hdd_context_t *hdd_ctx;
15911 void *vos_ctx;
15912
15913 vos_ctx = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
15914 if (!vos_ctx) {
15915 hddLog(LOGE, FL("Invalid VOS context"));
15916 return -EINVAL;
15917 }
15918
15919 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
15920 if(!hdd_ctx) {
15921 hddLog(LOGE , FL("Invalid HDD context"));
15922 return -EINVAL;
15923 }
15924
15925 memdump_procfs_remove();
15926 return 0;
15927}
15928
15929/**
15930 * wlan_hdd_fw_mem_dump_req(pHddCtx) - common API(cfg80211/ioctl) for requesting fw mem dump to SME
15931 * Return: HAL status
15932 */
15933
15934int wlan_hdd_fw_mem_dump_req(hdd_context_t * pHddCtx)
15935{
15936 tAniFwrDumpReq fw_mem_dump_req={0};
c_manjeef1495642015-10-13 18:35:01 +053015937 struct hdd_fw_mem_dump_req_ctx fw_mem_dump_ctx;
c_manjeecfd1efb2015-09-25 19:32:34 +053015938 eHalStatus status = eHAL_STATUS_FAILURE;
Abhishek Singh4eca9822015-12-09 18:07:34 +053015939 int ret=0, result;
c_manjeecfd1efb2015-09-25 19:32:34 +053015940 ENTER();
c_manjeef1495642015-10-13 18:35:01 +053015941
c_manjeecfd1efb2015-09-25 19:32:34 +053015942 /*Check whether a dump request is already going on
15943 *Caution this function will free previously held memory if new dump request is allowed*/
15944 if (!wlan_fwr_mem_dump_test_and_set_write_allowed_bit()) {
15945 hddLog(LOGE, FL("Fw memdump already in progress"));
15946 return -EBUSY;
15947 }
15948 //Allocate memory for fw mem dump buffer
15949 ret = wlan_fwr_mem_dump_buffer_allocation();
15950 if(ret == -EFAULT)
15951 {
15952 hddLog(LOGE, FL("Fwr mem dump not supported by FW"));
15953 return ret;
15954 }
15955 if (0 != ret) {
15956 hddLog(LOGE, FL("Fwr mem Allocation failed"));
15957 return -ENOMEM;
15958 }
c_manjeef1495642015-10-13 18:35:01 +053015959 init_completion(&fw_mem_dump_ctx.req_completion);
15960 fw_mem_dump_ctx.magic = FW_MEM_DUMP_MAGIC;
15961 fw_mem_dump_ctx.status = false;
15962
c_manjeecfd1efb2015-09-25 19:32:34 +053015963 fw_mem_dump_req.fwMemDumpReqCallback = wlan_hdd_fw_mem_dump_cb;
c_manjeef1495642015-10-13 18:35:01 +053015964 fw_mem_dump_req.fwMemDumpReqContext = &fw_mem_dump_ctx;
c_manjeecfd1efb2015-09-25 19:32:34 +053015965 status = sme_FwMemDumpReq(pHddCtx->hHal, &fw_mem_dump_req);
15966 if(eHAL_STATUS_SUCCESS != status)
15967 {
15968 hddLog(VOS_TRACE_LEVEL_ERROR,
15969 "%s: fw_mem_dump_req failed ", __func__);
15970 wlan_free_fwr_mem_dump_buffer();
c_manjeef1495642015-10-13 18:35:01 +053015971 ret = -EFAULT;
15972 goto cleanup;
c_manjeecfd1efb2015-09-25 19:32:34 +053015973 }
c_manjeef1495642015-10-13 18:35:01 +053015974 /*wait for fw mem dump completion to send event to userspace*/
Abhishek Singh4eca9822015-12-09 18:07:34 +053015975 result =
15976 wait_for_completion_timeout(&fw_mem_dump_ctx.req_completion,
15977 msecs_to_jiffies(FW_MEM_DUMP_TIMEOUT_MS));
15978 if (0 >= result )
c_manjeef1495642015-10-13 18:35:01 +053015979 {
15980 hddLog(VOS_TRACE_LEVEL_ERROR,
Abhishek Singh4eca9822015-12-09 18:07:34 +053015981 "%s: fw_mem_dump_req timeout %d ", __func__,result);
15982 ret = -ETIMEDOUT;
c_manjeef1495642015-10-13 18:35:01 +053015983 }
15984cleanup:
15985 spin_lock(&hdd_context_lock);
15986 fw_mem_dump_ctx.magic = 0;
Abhishek Singh4eca9822015-12-09 18:07:34 +053015987 if(!ret && !fw_mem_dump_ctx.status)
15988 ret = -EFAULT;
c_manjeef1495642015-10-13 18:35:01 +053015989 spin_unlock(&hdd_context_lock);
c_manjeecfd1efb2015-09-25 19:32:34 +053015990
c_manjeef1495642015-10-13 18:35:01 +053015991 EXIT();
Abhishek Singh4eca9822015-12-09 18:07:34 +053015992 return ret;
c_manjeef1495642015-10-13 18:35:01 +053015993}
15994
15995/**
15996 * HDD callback which will be called by SVC to indicate mem dump completion.
15997 */
15998void wlan_hdd_fw_mem_dump_req_cb(struct hdd_fw_mem_dump_req_ctx* pHddFwMemDumpCtx)
15999{
16000 if (!pHddFwMemDumpCtx) {
16001 hddLog(VOS_TRACE_LEVEL_ERROR,
16002 "%s: HDD context not valid ", __func__);
16003 return;
16004 }
16005 spin_lock(&hdd_context_lock);
16006 /* check the req magic and set status */
16007 if (pHddFwMemDumpCtx->magic == FW_MEM_DUMP_MAGIC)
16008 {
16009 pHddFwMemDumpCtx->status = true;
16010 //signal the completion
16011 complete(&(pHddFwMemDumpCtx->req_completion));
16012 }
16013 else
16014 {
16015 hddLog(VOS_TRACE_LEVEL_ERROR,
16016 "%s: fw mem dump request possible timeout ", __func__);
16017 }
16018 spin_unlock(&hdd_context_lock);
c_manjeecfd1efb2015-09-25 19:32:34 +053016019}
16020
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053016021void hdd_initialize_adapter_common(hdd_adapter_t *pAdapter)
16022{
16023 if (NULL == pAdapter)
16024 {
16025 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL ", __func__);
16026 return;
16027 }
16028 init_completion(&pAdapter->session_open_comp_var);
16029 init_completion(&pAdapter->session_close_comp_var);
16030 init_completion(&pAdapter->disconnect_comp_var);
16031 init_completion(&pAdapter->linkup_event_var);
16032 init_completion(&pAdapter->cancel_rem_on_chan_var);
16033 init_completion(&pAdapter->rem_on_chan_ready_event);
16034 init_completion(&pAdapter->pno_comp_var);
16035#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
16036 init_completion(&pAdapter->offchannel_tx_event);
16037#endif
16038 init_completion(&pAdapter->tx_action_cnf_event);
16039#ifdef FEATURE_WLAN_TDLS
16040 init_completion(&pAdapter->tdls_add_station_comp);
16041 init_completion(&pAdapter->tdls_del_station_comp);
16042 init_completion(&pAdapter->tdls_mgmt_comp);
16043 init_completion(&pAdapter->tdls_link_establish_req_comp);
16044#endif
16045
16046#ifdef WLAN_FEATURE_RMC
16047 init_completion(&pAdapter->ibss_peer_info_comp);
16048#endif /* WLAN_FEATURE_RMC */
16049 init_completion(&pAdapter->ula_complete);
16050 init_completion(&pAdapter->change_country_code);
16051
16052#ifdef FEATURE_WLAN_BATCH_SCAN
16053 init_completion(&pAdapter->hdd_set_batch_scan_req_var);
16054 init_completion(&pAdapter->hdd_get_batch_scan_req_var);
16055#endif
Kapil Gupta2b44acb2016-12-30 16:49:51 +053016056 init_completion(&pAdapter->wlan_suspend_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053016057
16058 return;
16059}
c_manjeecfd1efb2015-09-25 19:32:34 +053016060
Anurag Chouhan0b29de02016-12-16 13:18:40 +053016061#ifdef MDNS_OFFLOAD
16062
16063/**
16064 * hdd_mdns_enable_offload_done() - mdns enable offload response api
16065 * @padapter: holds adapter
16066 * @status: response status
16067 *
16068 * Return - None
16069 */
16070void hdd_mdns_enable_offload_done(void *padapter, VOS_STATUS status)
16071{
16072 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16073
16074 ENTER();
16075
16076 if (NULL == adapter)
16077 {
16078 hddLog(VOS_TRACE_LEVEL_ERROR,
16079 "%s: adapter is NULL",__func__);
16080 return;
16081 }
16082
16083 adapter->mdns_status.mdns_enable_status = status;
16084 vos_event_set(&adapter->mdns_status.vos_event);
16085 return;
16086}
16087
16088/**
16089 * hdd_mdns_fqdn_offload_done() - mdns fqdn offload response api
16090 * @padapter: holds adapter
16091 * @status: responce status
16092 *
16093 * Return - None
16094 */
16095void hdd_mdns_fqdn_offload_done(void *padapter, VOS_STATUS status)
16096{
16097 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16098
16099 ENTER();
16100
16101 if (NULL == adapter)
16102 {
16103 hddLog(VOS_TRACE_LEVEL_ERROR,
16104 "%s: adapter is NULL",__func__);
16105 return;
16106 }
16107
16108 adapter->mdns_status.mdns_fqdn_status = status;
16109 return;
16110}
16111
16112/**
16113 * hdd_mdns_resp_offload_done() - mdns resp offload response api
16114 * @padapter: holds adapter
16115 * @status: responce status
16116 *
16117 * Return - None
16118 */
16119void hdd_mdns_resp_offload_done(void *padapter, VOS_STATUS status)
16120{
16121 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16122
16123 ENTER();
16124
16125 if (NULL == adapter)
16126 {
16127 hddLog(VOS_TRACE_LEVEL_ERROR,
16128 "%s: adapter is NULL",__func__);
16129 return;
16130 }
16131
16132 adapter->mdns_status.mdns_resp_status = status;
16133 return;
16134}
16135
16136/**
16137 * wlan_hdd_mdns_process_response_dname() - Process mDNS domain name
16138 * @response: Pointer to a struct hdd_mdns_resp_info
16139 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16140 *
16141 * This function will pack the whole domain name without compression. It will
16142 * add the leading len for each field and add zero length octet to terminate
16143 * the domain name.
16144 *
16145 * Return: Return boolean. TRUE for success, FALSE for fail.
16146 */
16147static bool
16148wlan_hdd_mdns_process_response_dname(struct hdd_mdns_resp_info *response,
16149 sir_mdns_resp_info resp_info)
16150{
16151 uint8_t num;
16152 uint16_t idx;
16153 uint8_t len = 0;
16154
16155 if ((response == NULL) || (response->data == NULL) ||
16156 (response->offset == NULL)) {
16157 hddLog(LOGE, FL("Either data or offset in response is NULL!"));
16158 return FALSE;
16159 }
16160
16161 if ((resp_info == NULL) ||
16162 (resp_info->resp_len >= MAX_MDNS_RESP_LEN)) {
16163 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16164 return FALSE;
16165 }
16166
16167 for (num = 0; num < response->num_entries; num++) {
16168 response->offset[num] =
16169 resp_info->resp_len + MDNS_HEADER_LEN;
16170 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16171 len = strlen((char *)&response->data[idx]);
16172 if ((resp_info->resp_len + len + 1) >= MAX_MDNS_RESP_LEN) {
16173 hddLog(LOGE, FL("resp_len exceeds %d!"),
16174 MAX_MDNS_RESP_LEN);
16175 return FALSE;
16176 }
16177 resp_info->resp_data[resp_info->resp_len] = len;
16178 resp_info->resp_len++;
16179 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16180 &response->data[idx], len);
16181 resp_info->resp_len += len;
16182 }
16183
16184 /* The domain name terminates with the zero length octet */
16185 if (num == response->num_entries) {
16186 if (resp_info->resp_len >= MAX_MDNS_RESP_LEN) {
16187 hddLog(LOGE, FL("resp_len exceeds %d!"),
16188 MAX_MDNS_RESP_LEN);
16189 return FALSE;
16190 }
16191 resp_info->resp_data[resp_info->resp_len] = 0;
16192 resp_info->resp_len++;
16193 }
16194
16195 return TRUE;
16196}
16197
16198/**
16199 * wlan_hdd_mdns_format_response_u16() - Form uint16_t response data
16200 * @value: The uint16_t value is formed to the struct tSirMDNSResponseInfo
16201 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16202 *
16203 * Return: None
16204 */
16205static void wlan_hdd_mdns_format_response_u16(uint16_t value,
16206 sir_mdns_resp_info resp_info)
16207{
16208 uint8_t val_u8;
16209
16210 if ((resp_info == NULL) || (resp_info->resp_data == NULL))
16211 return;
16212 val_u8 = (value & 0xff00) >> 8;
16213 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16214 val_u8 = value & 0xff;
16215 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16216}
16217
16218/**
16219 * wlan_hdd_mdns_format_response_u32() - Form uint32_t response data
16220 * @value: The uint32_t value is formed to the struct tSirMDNSResponseInfo
16221 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16222 *
16223 * Return: None
16224 */
16225static void wlan_hdd_mdns_format_response_u32(uint32_t value,
16226 sir_mdns_resp_info resp_info)
16227{
16228 uint8_t val_u8;
16229
16230 if ((resp_info == NULL) || (resp_info->resp_data == NULL))
16231 return;
16232 val_u8 = (value & 0xff000000) >> 24;
16233 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16234 val_u8 = (value & 0xff0000) >> 16;
16235 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16236 val_u8 = (value & 0xff00) >> 8;
16237 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16238 val_u8 = value & 0xff;
16239 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16240}
16241
16242/**
16243 * wlan_hdd_mdns_process_response_misc() - Process misc info in mDNS response
16244 * @resp_type: Response type for mDNS
16245 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16246 *
16247 * This function will pack the response type, class and TTL (Time To Live).
16248 *
16249 * Return: Return boolean. TRUE for success, FALSE for fail.
16250 */
16251static bool wlan_hdd_mdns_process_response_misc(uint16_t resp_type,
16252 sir_mdns_resp_info resp_info)
16253{
16254 uint16_t len;
16255
16256 if (resp_info == NULL) {
16257 hddLog(LOGE, FL("resp_info is NULL!"));
16258 return FALSE;
16259 }
16260
16261 len = resp_info->resp_len + (2 * sizeof(uint16_t) + sizeof(uint32_t));
16262 if (len >= MAX_MDNS_RESP_LEN) {
16263 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16264 return FALSE;
16265 }
16266
16267 /* Fill Type, Class, TTL */
16268 wlan_hdd_mdns_format_response_u16(resp_type, resp_info);
16269 wlan_hdd_mdns_format_response_u16(MDNS_CLASS, resp_info);
16270 wlan_hdd_mdns_format_response_u32(MDNS_TTL, resp_info);
16271
16272 return TRUE;
16273}
16274
16275/**
16276 * wlan_hdd_mdns_compress_data() - Compress the domain name in mDNS response
16277 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16278 * @response_dst: The response which domain name is compressed.
16279 * @response_src: The response which domain name is matched with response_dst.
16280 * Its offset is used for data compression.
16281 * @num_matched: The number of matched entries between response_dst and
16282 * response_src
16283 *
16284 * This function will form the different fields of domain name in response_dst
16285 * if any. Then use the offset of the matched domain name in response_src to
16286 * compress the matched domain name.
16287 *
16288 * Return: Return boolean. TRUE for success, FALSE for fail.
16289 */
16290static bool
16291wlan_hdd_mdns_compress_data(sir_mdns_resp_info resp_info,
16292 struct hdd_mdns_resp_info *response_dst,
16293 struct hdd_mdns_resp_info *response_src,
16294 uint8_t num_matched)
16295{
16296 uint8_t num, num_diff;
16297 uint16_t value, idx;
16298 uint8_t len = 0;
16299
16300 if ((response_src == NULL) || (response_dst == NULL) ||
16301 (resp_info == NULL)) {
16302 hddLog(LOGE, FL("response info is NULL!"));
16303 return FALSE;
16304 }
16305
16306 if (response_dst->num_entries < num_matched) {
16307 hddLog(LOGE, FL("num_entries is less than num_matched!"));
16308 return FALSE;
16309 }
16310
16311 if (resp_info->resp_len >= MAX_MDNS_RESP_LEN) {
16312 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16313 return FALSE;
16314 }
16315
16316 num_diff = response_dst->num_entries - num_matched;
16317 if ((num_diff > 0) && (response_dst->data == NULL)) {
16318 hddLog(LOGE, FL("response_dst->data is NULL!"));
16319 return FALSE;
16320 }
16321
16322 /*
16323 * Handle the unmatched string at the beginning
16324 * Store the length of octets and the octets
16325 */
16326 for (num = 0; num < num_diff; num++) {
16327 response_dst->offset[num] =
16328 resp_info->resp_len + MDNS_HEADER_LEN;
16329 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16330 len = strlen((char *)&response_dst->data[idx]);
16331 if ((resp_info->resp_len + len + 1) >= MAX_MDNS_RESP_LEN) {
16332 hddLog(LOGE, FL("resp_len exceeds %d!"),
16333 MAX_MDNS_RESP_LEN);
16334 return FALSE;
16335 }
16336 resp_info->resp_data[resp_info->resp_len] = len;
16337 resp_info->resp_len++;
16338 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16339 &response_dst->data[idx], len);
16340 resp_info->resp_len += len;
16341 }
16342 /*
16343 * Handle the matched string from the end
16344 * Just keep the offset and mask the leading two bit
16345 */
16346 if (response_src->num_entries >= num_matched) {
16347 num_diff = response_src->num_entries - num_matched;
16348 value = response_src->offset[num_diff];
16349 if (value > 0) {
16350 value |= 0xc000;
16351 if ((resp_info->resp_len + sizeof(uint16_t)) >=
16352 MAX_MDNS_RESP_LEN) {
16353 hddLog(LOGE, FL("resp_len exceeds %d!"),
16354 MAX_MDNS_RESP_LEN);
16355 return FALSE;
16356 }
16357 wlan_hdd_mdns_format_response_u16(value, resp_info);
16358 return TRUE;
16359 }
16360 }
16361 return FALSE;
16362}
16363
16364/**
16365 * wlan_hdd_mdns_reset_response() - Reset the response info
16366 * @response: The response which info is reset.
16367 *
16368 * Return: None
16369 */
16370static void wlan_hdd_mdns_reset_response(struct hdd_mdns_resp_info *response)
16371{
16372 if (response == NULL)
16373 return;
16374 response->num_entries = 0;
16375 response->data = NULL;
16376 response->offset = NULL;
16377}
16378
16379/**
16380 * wlan_hdd_mdns_init_response() - Initialize the response info
16381 * @response: The response which info is initiatized.
16382 * @resp_dname: The domain name string which might be tokenized.
16383 *
16384 * This function will allocate the memory for both response->data and
16385 * response->offset. Besides, it will also tokenize the domain name to some
16386 * entries and fill response->num_entries with the num of entries.
16387 *
16388 * Return: Return boolean. TRUE for success, FALSE for fail.
16389 */
16390static bool wlan_hdd_mdns_init_response(struct hdd_mdns_resp_info *response,
16391 uint8_t *resp_dname, char separator)
16392{
16393 uint16_t size;
16394
16395 if ((resp_dname == NULL) || (response == NULL)) {
16396 hddLog(LOGE, FL("resp_dname or response is NULL!"));
16397 return FALSE;
16398 }
16399
16400 size = MAX_NUM_FIELD_DOMAINNAME * MAX_LEN_DOMAINNAME_FIELD;
16401 response->data = vos_mem_malloc(size);
16402 if (response->data) {
16403 vos_mem_zero(response->data, size);
16404 if (VOS_STATUS_SUCCESS !=
16405 hdd_string_to_string_array((char *)resp_dname,
16406 response->data,
16407 separator,
16408 &response->num_entries,
16409 MAX_NUM_FIELD_DOMAINNAME,
16410 MAX_LEN_DOMAINNAME_FIELD)) {
16411 hddLog(LOGE, FL("hdd_string_to_string_array fail!"));
16412 goto err_init_resp;
16413 }
16414
16415 if ((response->num_entries > 0) &&
16416 (strlen((char *)&response->data[0]) > 0)) {
16417 size = sizeof(uint16_t) * response->num_entries;
16418 response->offset = vos_mem_malloc(size);
16419 if (response->offset) {
16420 vos_mem_zero(response->offset, size);
16421 return TRUE;
16422 }
16423 }
16424 }
16425
16426err_init_resp:
16427 if (response->data)
16428 vos_mem_free(response->data);
16429 wlan_hdd_mdns_reset_response(response);
16430 return FALSE;
16431}
16432
16433/**
16434 * wlan_hdd_mdns_find_entries_from_end() - Find the matched entries
16435 * @response1: The response info is used to be compared.
16436 * @response2: The response info is used to be compared.
16437 *
16438 * This function will find the matched entries from the end.
16439 *
16440 * Return: Return the number of the matched entries.
16441 */
16442static uint8_t
16443wlan_hdd_mdns_find_entries_from_end(struct hdd_mdns_resp_info *response1,
16444 struct hdd_mdns_resp_info *response2)
16445{
16446 uint8_t min, len1, i;
16447 uint16_t num1, num2;
16448 uint8_t num_matched = 0;
16449
16450 min = VOS_MIN(response1->num_entries, response2->num_entries);
16451
16452 for (i = 1; i <= min; i++) {
16453 num1 = (response1->num_entries - i);
16454 num1 *= MAX_LEN_DOMAINNAME_FIELD;
16455 num2 = (response2->num_entries - i);
16456 num2 *= MAX_LEN_DOMAINNAME_FIELD;
16457 len1 = strlen((char *)&response1->data[num1]);
16458
16459 if ((len1 == 0) ||
16460 (len1 != strlen((char *)&response2->data[num2])))
16461 break;
16462 if (memcmp(&response1->data[num1],
16463 &response2->data[num2], len1))
16464 break;
16465 else
16466 num_matched++;
16467 }
16468
16469 return num_matched;
16470}
16471
16472/**
16473 * wlan_hdd_mdns_find_max() - Find the maximum number of the matched entries
16474 * @matchedlist: Pointer to the array of struct hdd_mdns_resp_matched
16475 * @numlist: The number of the elements in the array matchedlist.
16476 *
16477 * Find the max number of the matched entries among the array matchedlist.
16478 *
16479 * Return: None
16480 */
16481static void wlan_hdd_mdns_find_max(struct hdd_mdns_resp_matched *matchedlist,
16482 uint8_t numlist)
16483{
16484 int j;
16485 struct hdd_mdns_resp_matched tmp;
16486
16487 /* At least two values are used for sorting */
16488 if ((numlist < 2) || (matchedlist == NULL)) {
16489 hddLog(LOGE, FL("At least two values are used for sorting!"));
16490 return;
16491 }
16492
16493 for (j = 0; j < numlist-1; j++) {
16494 if (matchedlist[j].num_matched >
16495 matchedlist[j+1].num_matched) {
16496 vos_mem_copy(&tmp, &matchedlist[j],
16497 sizeof(struct hdd_mdns_resp_matched));
16498 vos_mem_copy(&matchedlist[j], &matchedlist[j+1],
16499 sizeof(struct hdd_mdns_resp_matched));
16500 vos_mem_copy(&matchedlist[j+1], &tmp,
16501 sizeof(struct hdd_mdns_resp_matched));
16502 }
16503 }
16504}
16505
16506/**
16507 * wlan_hdd_mdns_pack_response_type_a() - Pack Type A response
16508 * @ini_config: Pointer to the struct hdd_config_t
16509 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16510 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16511 *
16512 * Type A response include QName, response type, class, TTL and Ipv4.
16513 *
16514 * Return: Return boolean. TRUE for success, FALSE for fail.
16515 */
16516static bool
16517wlan_hdd_mdns_pack_response_type_a(hdd_config_t *ini_config,
16518 sir_mdns_resp_info resp_info,
16519 struct hdd_mdns_resp_info *resptype_a)
16520{
16521 uint16_t value;
16522 uint32_t len;
16523
16524 ENTER();
16525 if ((ini_config == NULL) || (resp_info == NULL) ||
16526 (resptype_a == NULL)) {
16527 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16528 return FALSE;
16529 }
16530
16531 /* No Type A response */
16532 if (strlen((char *)ini_config->mdns_resp_type_a) <= 0)
16533 return TRUE;
16534
16535 /* Wrong response is assigned, just ignore this response */
16536 if (!wlan_hdd_mdns_init_response(resptype_a,
16537 ini_config->mdns_resp_type_a, '.'))
16538 return TRUE;
16539
16540 /* Process response domain name */
16541 if (!wlan_hdd_mdns_process_response_dname(resptype_a, resp_info)) {
16542 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
16543 MDNS_TYPE_A);
16544 return FALSE;
16545 }
16546
16547 /* Process response Type, Class, TTL */
16548 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_A, resp_info)) {
16549 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
16550 MDNS_TYPE_A);
16551 return FALSE;
16552 }
16553
16554 /* Process response RDLength, RData */
16555 len = sizeof(uint16_t) + sizeof(uint32_t);
16556 len += resp_info->resp_len;
16557 if (len >= MAX_MDNS_RESP_LEN) {
16558 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16559 return FALSE;
16560 }
16561 value = sizeof(uint32_t);
16562 wlan_hdd_mdns_format_response_u16(value, resp_info);
16563 wlan_hdd_mdns_format_response_u32(ini_config->mdns_resp_type_a_ipv4,
16564 resp_info);
16565
16566 EXIT();
16567 return TRUE;
16568}
16569
16570/**
16571 * wlan_hdd_mdns_pack_response_type_txt() - Pack Type Txt response
16572 * @ini_config: Pointer to the struct hdd_config_t
16573 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16574 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type txt
16575 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16576 *
16577 * Type Txt response include QName, response type, class, TTL and text content.
16578 * Also, it will find the matched QName from resptype_A and compress the data.
16579 *
16580 * Return: Return boolean. TRUE for success, FALSE for fail.
16581 */
16582static bool
16583wlan_hdd_mdns_pack_response_type_txt(hdd_config_t *ini_config,
16584 sir_mdns_resp_info resp_info,
16585 struct hdd_mdns_resp_info *resptype_txt,
16586 struct hdd_mdns_resp_info *resptype_a)
16587{
16588 uint8_t num_matched;
16589 uint8_t num;
16590 uint16_t idx;
16591 uint16_t value = 0;
16592 uint32_t len;
16593 uint32_t total_len;
16594 bool status;
16595 struct hdd_mdns_resp_info resptype_content;
16596
16597 ENTER();
16598
16599 if ((ini_config == NULL) || (resp_info == NULL) ||
16600 (resptype_txt == NULL)) {
16601 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16602 return FALSE;
16603 }
16604
16605 /* No Type Txt response */
16606 if (strlen((char *)ini_config->mdns_resp_type_txt) <= 0)
16607 return TRUE;
16608
16609 /* Wrong response is assigned, just ignore this response */
16610 if (!wlan_hdd_mdns_init_response(resptype_txt,
16611 ini_config->mdns_resp_type_txt, '.'))
16612 return TRUE;
16613
16614 /*
16615 * For data compression
16616 * Check if any strings are matched with Type A response
16617 */
16618 if (resptype_a && (resptype_a->num_entries > 0)) {
16619 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_txt,
16620 resptype_a);
16621 if (num_matched > 0) {
16622 if (!wlan_hdd_mdns_compress_data(resp_info,
16623 resptype_txt, resptype_a, num_matched)) {
16624 hddLog(LOGE, FL("Fail to compress mDNS "
16625 "response (%d)!"), MDNS_TYPE_TXT);
16626 return FALSE;
16627 }
16628 } else {
16629 /*
16630 * num_matched is zero. Error!
16631 * At least ".local" is needed.
16632 */
16633 hddLog(LOGE, FL("No matched string! Fail to pack mDNS "
16634 "response (%d)!"), MDNS_TYPE_TXT);
16635 return FALSE;
16636 }
16637 } else {
16638 /* no TypeA response, so show the whole data */
16639 if (!wlan_hdd_mdns_process_response_dname(resptype_txt,
16640 resp_info)) {
16641 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
16642 MDNS_TYPE_TXT);
16643 return FALSE;
16644 }
16645 }
16646
16647 /* Process response Type, Class, TTL */
16648 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_TXT, resp_info)) {
16649 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
16650 MDNS_TYPE_TXT);
16651 return FALSE;
16652 }
16653
16654 /*
16655 * Process response RDLength, RData.
16656 * TypeTxt RData include len.
16657 */
16658 status = wlan_hdd_mdns_init_response(&resptype_content,
16659 ini_config->mdns_resp_type_txt_content,
16660 '/');
16661 if (status == FALSE) {
16662 hddLog(LOGE, FL("wlan_hdd_mdns_init_response FAIL"));
16663 return FALSE;
16664 }
16665
16666 for (num = 0; num < resptype_content.num_entries; num++) {
16667 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16668 value += strlen((char *)&resptype_content.data[idx]);
16669 }
16670
16671 /* content len is uint16_t */
16672 total_len = sizeof(uint16_t);
16673 total_len += resp_info->resp_len + value +
16674 resptype_content.num_entries;
16675
16676 if (total_len >= MAX_MDNS_RESP_LEN) {
16677 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16678 return FALSE;
16679 }
16680 wlan_hdd_mdns_format_response_u16(value + resptype_content.num_entries,
16681 resp_info);
16682
16683 for (num = 0; num < resptype_content.num_entries; num++) {
16684 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16685 len = strlen((char *)&resptype_content.data[idx]);
16686 resp_info->resp_data[resp_info->resp_len] = len;
16687 resp_info->resp_len++;
16688
16689 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16690 &resptype_content.data[idx], len);
16691
16692 resp_info->resp_len += len;
16693 hddLog(LOG1, FL("index = %d, len = %d, str = %s"),
16694 num, len, &resptype_content.data[idx]);
16695 }
16696
16697 EXIT();
16698 return TRUE;
16699}
16700
16701/**
16702 * wlan_hdd_mdns_pack_response_type_ptr_dname() - Pack Type PTR domain name
16703 * @ini_config: Pointer to the struct hdd_config_t
16704 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16705 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
16706 * domain name
16707 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
16708 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
16709 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16710 *
16711 * The Type Ptr response include Type PTR domain name in its data field.
16712 * Also, it will find the matched QName from the existing resptype_ptr,
16713 * resptype_txt, resptype_a and then compress the data.
16714 *
16715 * Return: Return boolean. TRUE for success, FALSE for fail.
16716 */
16717static bool
16718wlan_hdd_mdns_pack_response_type_ptr_dname(hdd_config_t *ini_config,
16719 sir_mdns_resp_info resp_info,
16720 struct hdd_mdns_resp_info *resptype_ptr_dn,
16721 struct hdd_mdns_resp_info *resptype_ptr,
16722 struct hdd_mdns_resp_info *resptype_txt,
16723 struct hdd_mdns_resp_info *resptype_a)
16724{
16725 uint8_t num_matched, numlist, size;
16726 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
16727 struct hdd_mdns_resp_info *resp;
16728
16729 if ((ini_config == NULL) || (resp_info == NULL) ||
16730 (resptype_ptr == NULL) || (resptype_ptr_dn == NULL)) {
16731 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16732 return FALSE;
16733 }
16734
16735 /* No Type Ptr domain name response */
16736 if (strlen((char *)ini_config->mdns_resp_type_ptr_dname) <= 0)
16737 return TRUE;
16738
16739 /* Wrong response is assigned, just ignore this response */
16740 if (!wlan_hdd_mdns_init_response(resptype_ptr_dn,
16741 ini_config->mdns_resp_type_ptr_dname, '.'))
16742 return TRUE;
16743
16744 /*
16745 * For data compression
16746 * Check if any strings are matched with previous
16747 * response.
16748 */
16749 numlist = 0;
16750 size = (MAX_MDNS_RESP_TYPE-1);
16751 size *= sizeof(struct hdd_mdns_resp_matched);
16752 vos_mem_zero(matchedlist, size);
16753 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_ptr_dn,
16754 resptype_ptr);
16755 if (num_matched > 0) {
16756 matchedlist[numlist].num_matched = num_matched;
16757 matchedlist[numlist].type = MDNS_TYPE_PTR;
16758 numlist++;
16759 }
16760 if (resptype_txt && (resptype_txt->num_entries > 0)) {
16761 num_matched = wlan_hdd_mdns_find_entries_from_end(
16762 resptype_ptr_dn, resptype_txt);
16763 if (num_matched > 0) {
16764 matchedlist[numlist].num_matched = num_matched;
16765 matchedlist[numlist].type = MDNS_TYPE_TXT;
16766 numlist++;
16767 }
16768 }
16769 if (resptype_a && (resptype_a->num_entries > 0)) {
16770 num_matched = wlan_hdd_mdns_find_entries_from_end(
16771 resptype_ptr_dn,resptype_a);
16772 if (num_matched > 0) {
16773 matchedlist[numlist].num_matched = num_matched;
16774 matchedlist[numlist].type = MDNS_TYPE_A;
16775 numlist++;
16776 }
16777 }
16778 if (numlist > 0) {
16779 if (numlist > 1)
16780 wlan_hdd_mdns_find_max(matchedlist, numlist);
16781 resp = NULL;
16782 switch (matchedlist[numlist-1].type) {
16783 case MDNS_TYPE_A:
16784 resp = resptype_a;
16785 break;
16786 case MDNS_TYPE_TXT:
16787 resp = resptype_txt;
16788 break;
16789 case MDNS_TYPE_PTR:
16790 resp = resptype_ptr;
16791 break;
16792 default:
16793 hddLog(LOGE, FL("Fail to compress mDNS response "
16794 "(%d)!"), MDNS_TYPE_PTR_DNAME);
16795 return FALSE;
16796 }
16797 num_matched = matchedlist[numlist-1].num_matched;
16798 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_ptr_dn,
16799 resp, num_matched)) {
16800 hddLog(LOGE, FL("Fail to compress mDNS response "
16801 "(%d)!"), MDNS_TYPE_PTR_DNAME);
16802 return FALSE;
16803 }
16804 } else {
16805 /* num = 0 -> no matched string */
16806 if (!wlan_hdd_mdns_process_response_dname(resptype_ptr_dn,
16807 resp_info)) {
16808 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
16809 MDNS_TYPE_PTR_DNAME);
16810 return FALSE;
16811 }
16812 }
16813
16814 return TRUE;
16815}
16816
16817/**
16818 * wlan_hdd_mdns_pack_response_type_ptr() - Pack Type PTR response
16819 * @ini_config: Pointer to the struct hdd_config_t
16820 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16821 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
16822 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
16823 * domain name
16824 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
16825 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16826 *
16827 * The Type Ptr response include QName, response type, class, TTL and
16828 * Type PTR domain name. Also, it will find the matched QName from the
16829 * existing resptype_txt, resptype_a and then compress the data.
16830 *
16831 * Return: Return boolean. TRUE for success, FALSE for fail.
16832 */
16833static bool
16834wlan_hdd_mdns_pack_response_type_ptr(hdd_config_t *ini_config,
16835 sir_mdns_resp_info resp_info,
16836 struct hdd_mdns_resp_info *resptype_ptr,
16837 struct hdd_mdns_resp_info *resptype_ptr_dn,
16838 struct hdd_mdns_resp_info *resptype_txt,
16839 struct hdd_mdns_resp_info *resptype_a)
16840{
16841 uint8_t num_matched, num_matched1;
16842 uint16_t value;
16843 uint8_t val_u8;
16844 uint32_t offset_data_len, len;
16845
16846 ENTER();
16847 if ((ini_config == NULL) || (resp_info == NULL) ||
16848 (resptype_ptr == NULL) || (resptype_ptr_dn == NULL)) {
16849 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16850 return FALSE;
16851 }
16852
16853 /* No Type Ptr response */
16854 if (strlen((char *)ini_config->mdns_resp_type_ptr) <= 0)
16855 return TRUE;
16856
16857 /* Wrong response is assigned, just ignore this response */
16858 if (!wlan_hdd_mdns_init_response(resptype_ptr,
16859 ini_config->mdns_resp_type_ptr, '.'))
16860 return TRUE;
16861
16862 /*
16863 * For data compression
16864 * Check if any strings are matched with Type A response
16865 */
16866 num_matched = 0;
16867 num_matched1 = 0;
16868 if (resptype_a && (resptype_a->num_entries > 0)) {
16869 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_ptr,
16870 resptype_a);
16871 }
16872 if (resptype_txt && (resptype_txt->num_entries > 0)) {
16873 num_matched1 = wlan_hdd_mdns_find_entries_from_end(
16874 resptype_ptr, resptype_txt);
16875 }
16876 if ((num_matched != num_matched1) ||
16877 ((num_matched > 0) && (num_matched1 > 0))) {
16878 if (num_matched >= num_matched1) {
16879 if (!wlan_hdd_mdns_compress_data(resp_info,
16880 resptype_ptr, resptype_a, num_matched)) {
16881 hddLog(LOGE, FL("Fail to compress mDNS "
16882 "response (%d)!"), MDNS_TYPE_PTR);
16883 return FALSE;
16884 }
16885 } else {
16886 /* num_matched is less than num_matched1 */
16887 if (!wlan_hdd_mdns_compress_data(resp_info,
16888 resptype_ptr, resptype_txt, num_matched1)) {
16889 hddLog(LOGE, FL("Fail to compress mDNS "
16890 "response (%d)!"), MDNS_TYPE_PTR);
16891 return FALSE;
16892 }
16893 }
16894 } else {
16895 /*
16896 * Both num_matched and num_matched1 are zero.
16897 * no TypeA & TypeTxt
16898 */
16899 if (!wlan_hdd_mdns_process_response_dname(resptype_ptr,
16900 resp_info)) {
16901 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
16902 MDNS_TYPE_PTR);
16903 return FALSE;
16904 }
16905 }
16906
16907 /* Process response Type, Class, TTL */
16908 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_PTR, resp_info)) {
16909 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
16910 MDNS_TYPE_PTR);
16911 return FALSE;
16912 }
16913
16914 /*
16915 * Process response RDLength, RData (Ptr domain name)
16916 * Save the offset of RData length
16917 */
16918 offset_data_len = resp_info->resp_len;
16919 resp_info->resp_len += sizeof(uint16_t);
16920
16921 if (!wlan_hdd_mdns_pack_response_type_ptr_dname(ini_config, resp_info,
16922 resptype_ptr_dn, resptype_ptr,
16923 resptype_txt, resptype_a)) {
16924 return FALSE;
16925 }
16926 /* Set the RData length */
16927 len = offset_data_len + sizeof(uint16_t);
16928 if ((resptype_ptr_dn->num_entries > 0) &&
16929 (resp_info->resp_len > len)) {
16930 value = resp_info->resp_len - len;
16931 val_u8 = (value & 0xff00) >> 8;
16932 resp_info->resp_data[offset_data_len] = val_u8;
16933 val_u8 = value & 0xff;
16934 resp_info->resp_data[offset_data_len+1] = val_u8;
16935 } else {
16936 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
16937 MDNS_TYPE_PTR);
16938 return FALSE;
16939 }
16940
16941 EXIT();
16942 return TRUE;
16943}
16944
16945/**
16946 * wlan_hdd_mdns_pack_response_type_srv_target()- Pack Type Service Target
16947 * @ini_config: Pointer to the struct hdd_config_t
16948 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16949 * @resptype_srv_tgt: Pointer to the struct hdd_mdns_resp_info of Type Srv
16950 * target
16951 * @resptype_srv: Pointer to the struct hdd_mdns_resp_info of Type Srv
16952 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
16953 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
16954 * domain name
16955 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
16956 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16957 *
16958 * The Type service target is one of the data field in the Type SRV response.
16959 * Also, it will find the matched QName from the existing resptype_srv,
16960 * resptype_ptr, resptype_ptr_dn, resptype_txt, resptype_a and then compress
16961 * the data.
16962 *
16963 * Return: Return boolean. TRUE for success, FALSE for fail.
16964 */
16965static bool
16966wlan_hdd_mdns_pack_response_type_srv_target(hdd_config_t *ini_config,
16967 sir_mdns_resp_info resp_info,
16968 struct hdd_mdns_resp_info *resptype_srv_tgt,
16969 struct hdd_mdns_resp_info *resptype_srv,
16970 struct hdd_mdns_resp_info *resptype_ptr,
16971 struct hdd_mdns_resp_info *resptype_ptr_dn,
16972 struct hdd_mdns_resp_info *resptype_txt,
16973 struct hdd_mdns_resp_info *resptype_a)
16974{
16975 uint8_t num_matched, num, size;
16976 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
16977 struct hdd_mdns_resp_info *resp;
16978
16979 if ((ini_config == NULL) || (resp_info == NULL) ||
16980 (resptype_srv == NULL) || (resptype_srv_tgt == NULL)) {
16981 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16982 return FALSE;
16983 }
16984
16985 /* No Type Srv Target response */
16986 if (strlen((char *)ini_config->mdns_resp_type_srv_target) <= 0)
16987 return TRUE;
16988
16989 /* Wrong response is assigned, just ignore this response */
16990 if (!wlan_hdd_mdns_init_response(resptype_srv_tgt,
16991 ini_config->mdns_resp_type_srv_target, '.'))
16992 return TRUE;
16993
16994 /*
16995 * For data compression
16996 * Check if any strings are matched with previous response.
16997 */
16998 num = 0;
16999 size = (MAX_MDNS_RESP_TYPE-1);
17000 size *= sizeof(struct hdd_mdns_resp_matched);
17001 vos_mem_zero(matchedlist, size);
17002 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv_tgt,
17003 resptype_srv);
17004 if (num_matched > 0) {
17005 matchedlist[num].num_matched = num_matched;
17006 matchedlist[num].type = MDNS_TYPE_SRV;
17007 num++;
17008 }
17009 if (resptype_ptr && (resptype_ptr->num_entries > 0)) {
17010 if (resptype_ptr_dn && (resptype_ptr_dn->num_entries > 0)) {
17011 num_matched = wlan_hdd_mdns_find_entries_from_end(
17012 resptype_srv_tgt, resptype_ptr_dn);
17013 if (num_matched > 0) {
17014 matchedlist[num].num_matched = num_matched;
17015 matchedlist[num].type = MDNS_TYPE_PTR_DNAME;
17016 num++;
17017 }
17018 }
17019 num_matched = wlan_hdd_mdns_find_entries_from_end(
17020 resptype_srv_tgt, resptype_ptr);
17021 if (num_matched > 0) {
17022 matchedlist[num].num_matched = num_matched;
17023 matchedlist[num].type = MDNS_TYPE_PTR;
17024 num++;
17025 }
17026 }
17027 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17028 num_matched = wlan_hdd_mdns_find_entries_from_end(
17029 resptype_srv_tgt, resptype_txt);
17030 if (num_matched > 0) {
17031 matchedlist[num].num_matched = num_matched;
17032 matchedlist[num].type = MDNS_TYPE_TXT;
17033 num++;
17034 }
17035 }
17036 if (resptype_a && (resptype_a->num_entries > 0)) {
17037 num_matched = wlan_hdd_mdns_find_entries_from_end(
17038 resptype_srv_tgt, resptype_a);
17039 if (num_matched > 0) {
17040 matchedlist[num].num_matched = num_matched;
17041 matchedlist[num].type = MDNS_TYPE_A;
17042 num++;
17043 }
17044 }
17045 if (num > 0) {
17046 if (num > 1)
17047 wlan_hdd_mdns_find_max(matchedlist, num);
17048 resp = NULL;
17049 switch (matchedlist[num-1].type) {
17050 case MDNS_TYPE_A:
17051 resp = resptype_a;
17052 break;
17053 case MDNS_TYPE_TXT:
17054 resp = resptype_txt;
17055 break;
17056 case MDNS_TYPE_PTR:
17057 resp = resptype_ptr;
17058 break;
17059 case MDNS_TYPE_PTR_DNAME:
17060 resp = resptype_ptr_dn;
17061 break;
17062 case MDNS_TYPE_SRV:
17063 resp = resptype_srv;
17064 break;
17065 default:
17066 hddLog(LOGE, FL("Fail to compress mDNS response "
17067 "(%d)!"), MDNS_TYPE_SRV_TARGET);
17068 return FALSE;
17069 }
17070 num_matched = matchedlist[num-1].num_matched;
17071 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_srv_tgt,
17072 resp, num_matched)) {
17073 hddLog(LOGE, FL("Fail to compress mDNS response "
17074 "(%d)!"), MDNS_TYPE_SRV_TARGET);
17075 return FALSE;
17076 }
17077 } else {
17078 /* num = 0 -> no matched string */
17079 if (!wlan_hdd_mdns_process_response_dname(resptype_srv_tgt,
17080 resp_info)) {
17081 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17082 MDNS_TYPE_SRV_TARGET);
17083 return FALSE;
17084 }
17085 }
17086
17087 return TRUE;
17088}
17089
17090/**
17091 * wlan_hdd_mdns_pack_response_type_srv()- Pack Type Service response
17092 * @ini_config: Pointer to the struct hdd_config_t
17093 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17094 * @resptype_srv: Pointer to the struct hdd_mdns_resp_info of Type Srv
17095 * @resptype_srv_tgt: Pointer to the struct hdd_mdns_resp_info of Type Srv
17096 * target
17097 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17098 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17099 * domain name
17100 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17101 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17102 *
17103 * The Type SRV (Service) response include QName, response type, class, TTL
17104 * and four kinds of data fields. Also, it will find the matched QName from
17105 * the existing resptype_ptr, resptype_ptr_dn, resptype_txt, resptype_a and
17106 * then compress the data.
17107 *
17108 * Return: Return boolean. TRUE for success, FALSE for fail.
17109 */
17110static bool
17111wlan_hdd_mdns_pack_response_type_srv(hdd_config_t *ini_config,
17112 sir_mdns_resp_info resp_info,
17113 struct hdd_mdns_resp_info *resptype_srv,
17114 struct hdd_mdns_resp_info *resptype_srv_tgt,
17115 struct hdd_mdns_resp_info *resptype_ptr,
17116 struct hdd_mdns_resp_info *resptype_ptr_dn,
17117 struct hdd_mdns_resp_info *resptype_txt,
17118 struct hdd_mdns_resp_info *resptype_a)
17119{
17120 uint8_t num_matched, num, size;
17121 uint16_t value;
17122 uint8_t val_u8;
17123 uint32_t offset_data_len, len;
17124 struct hdd_mdns_resp_info *resp;
17125 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17126
17127 ENTER();
17128
17129 if ((ini_config == NULL) || (resp_info == NULL) ||
17130 (resptype_srv == NULL) || (resptype_srv_tgt == NULL)) {
17131 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17132 return FALSE;
17133 }
17134
17135 /* No Type Srv response */
17136 if (strlen((char *)ini_config->mdns_resp_type_srv) <= 0)
17137 return TRUE;
17138
17139 /* Wrong response is assigned, just ignore this response */
17140 if (!wlan_hdd_mdns_init_response(resptype_srv,
17141 ini_config->mdns_resp_type_srv, '.'))
17142 return TRUE;
17143
17144 /*
17145 * For data compression
17146 * Check if any strings are matched with Type A response
17147 */
17148 num = 0;
17149 size = (MAX_MDNS_RESP_TYPE-1);
17150 size *= sizeof(struct hdd_mdns_resp_matched);
17151 vos_mem_zero(matchedlist, size);
17152 if (resptype_ptr && (resptype_ptr->num_entries > 0)) {
17153 if (resptype_ptr_dn && (resptype_ptr_dn->num_entries > 0)) {
17154 num_matched = wlan_hdd_mdns_find_entries_from_end(
17155 resptype_srv,
17156 resptype_ptr_dn);
17157 if (num_matched > 0) {
17158 matchedlist[num].num_matched = num_matched;
17159 matchedlist[num].type = MDNS_TYPE_PTR_DNAME;
17160 num++;
17161 }
17162 }
17163 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17164 resptype_ptr);
17165 if (num_matched > 0) {
17166 matchedlist[num].num_matched = num_matched;
17167 matchedlist[num].type = MDNS_TYPE_PTR;
17168 num++;
17169 }
17170 }
17171 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17172 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17173 resptype_txt);
17174 if (num_matched > 0) {
17175 matchedlist[num].num_matched =num_matched;
17176 matchedlist[num].type = MDNS_TYPE_TXT;
17177 num++;
17178 }
17179 }
17180 if (resptype_a && (resptype_a->num_entries > 0)) {
17181 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17182 resptype_a);
17183 if (num_matched > 0) {
17184 matchedlist[num].num_matched = num_matched;
17185 matchedlist[num].type = MDNS_TYPE_A;
17186 num++;
17187 }
17188 }
17189 if (num > 0) {
17190 if (num > 1)
17191 wlan_hdd_mdns_find_max(matchedlist, num);
17192 resp = NULL;
17193 switch (matchedlist[num-1].type) {
17194 case MDNS_TYPE_A:
17195 resp = resptype_a;
17196 break;
17197 case MDNS_TYPE_TXT:
17198 resp = resptype_txt;
17199 break;
17200 case MDNS_TYPE_PTR:
17201 resp = resptype_ptr;
17202 break;
17203 case MDNS_TYPE_PTR_DNAME:
17204 resp = resptype_ptr_dn;
17205 break;
17206 default:
17207 hddLog(LOGE, FL("Fail to compress mDNS response "
17208 "(%d)!"), MDNS_TYPE_SRV);
17209 return FALSE;
17210 }
17211 num_matched = matchedlist[num-1].num_matched;
17212 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_srv,
17213 resp, num_matched)) {
17214 hddLog(LOGE, FL("Fail to compress mDNS response "
17215 "(%d)!"), MDNS_TYPE_SRV);
17216 return FALSE;
17217 }
17218 } else {
17219 /* num = 0 -> no matched string */
17220 if (!wlan_hdd_mdns_process_response_dname(resptype_srv,
17221 resp_info)) {
17222 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17223 MDNS_TYPE_SRV);
17224 return FALSE;
17225 }
17226 }
17227
17228 /* Process response Type, Class, TTL */
17229 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_SRV, resp_info)) {
17230 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17231 MDNS_TYPE_SRV);
17232 return FALSE;
17233 }
17234
17235 /*
17236 * Process response RDLength, RData (Srv target name)
17237 * Save the offset of RData length
17238 */
17239 offset_data_len = resp_info->resp_len;
17240 resp_info->resp_len += sizeof(uint16_t);
17241
17242 len = resp_info->resp_len + (3 * sizeof(uint16_t));
17243 if (len >= MAX_MDNS_RESP_LEN) {
17244 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
17245 return FALSE;
17246 }
17247
17248 /* set Srv Priority */
17249 value = ini_config->mdns_resp_type_srv_priority;
17250 wlan_hdd_mdns_format_response_u16(value, resp_info);
17251 /* set Srv Weight */
17252 value = ini_config->mdns_resp_type_srv_weight;
17253 wlan_hdd_mdns_format_response_u16(value, resp_info);
17254 /* set Srv Port */
17255 value = ini_config->mdns_resp_type_srv_port;
17256 wlan_hdd_mdns_format_response_u16(value, resp_info);
17257
17258 if (!wlan_hdd_mdns_pack_response_type_srv_target(ini_config, resp_info,
17259 resptype_srv_tgt, resptype_srv,
17260 resptype_ptr, resptype_ptr_dn,
17261 resptype_txt, resptype_a)) {
17262 return FALSE;
17263 }
17264 /* Set the RData length */
17265 len = offset_data_len + sizeof(uint16_t);
17266 if ((resptype_srv_tgt->num_entries > 0) &&
17267 (resp_info->resp_len > len)) {
17268 value = resp_info->resp_len - len;
17269 val_u8 = (value & 0xff00) >> 8;
17270 resp_info->resp_data[offset_data_len] = val_u8;
17271 val_u8 = value & 0xff;
17272 resp_info->resp_data[offset_data_len+1] = val_u8;
17273 } else {
17274 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17275 MDNS_TYPE_SRV);
17276 return FALSE;
17277 }
17278
17279 EXIT();
17280 return TRUE;
17281}
17282
17283/**
17284 * wlan_hdd_mdns_free_mem() - Free the allocated memory
17285 * @response: Pointer to the struct hdd_mdns_resp_info
17286 *
17287 * Return: None
17288 */
17289static void wlan_hdd_mdns_free_mem(struct hdd_mdns_resp_info *response)
17290{
17291 if (response && response->data)
17292 vos_mem_free(response->data);
17293 if (response && response->offset)
17294 vos_mem_free(response->offset);
17295}
17296
17297/**
17298 * wlan_hdd_mdns_pack_response() - Pack mDNS response
17299 * @ini_config: Pointer to the struct hdd_config_t
17300 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17301 *
17302 * This function will pack four types of responses (Type A, Type Txt, Type Ptr
17303 * and Type Service). Each response contains QName, response type, class, TTL
17304 * and data fields.
17305 *
17306 * Return: Return boolean. TRUE for success, FALSE for fail.
17307 */
17308static bool wlan_hdd_mdns_pack_response(hdd_config_t *ini_config,
17309 sir_mdns_resp_info resp_info)
17310{
17311 struct hdd_mdns_resp_info resptype_a, resptype_txt;
17312 struct hdd_mdns_resp_info resptype_ptr, resptype_ptr_dn;
17313 struct hdd_mdns_resp_info resptype_srv, resptype_srv_tgt;
17314 uint32_t num_res_records = 0;
17315 bool status = FALSE;
17316
17317 ENTER();
17318
17319 wlan_hdd_mdns_reset_response(&resptype_a);
17320 wlan_hdd_mdns_reset_response(&resptype_txt);
17321 wlan_hdd_mdns_reset_response(&resptype_ptr);
17322 wlan_hdd_mdns_reset_response(&resptype_ptr_dn);
17323 wlan_hdd_mdns_reset_response(&resptype_srv);
17324 wlan_hdd_mdns_reset_response(&resptype_srv_tgt);
17325
17326 resp_info->resp_len = 0;
17327
17328 /* Process Type A response */
17329 if (!wlan_hdd_mdns_pack_response_type_a(ini_config, resp_info,
17330 &resptype_a))
17331 goto err_resptype_a;
17332
17333 if ((resptype_a.num_entries > 0) &&
17334 (strlen((char *)&resptype_a.data[0]) > 0))
17335 num_res_records++;
17336
17337 /* Process Type TXT response */
17338 if (!wlan_hdd_mdns_pack_response_type_txt(ini_config, resp_info,
17339 &resptype_txt, &resptype_a))
17340 goto err_resptype_txt;
17341
17342 if ((resptype_txt.num_entries > 0) &&
17343 (strlen((char *)&resptype_txt.data[0]) > 0))
17344 num_res_records++;
17345
17346 /* Process Type PTR response */
17347 if (!wlan_hdd_mdns_pack_response_type_ptr(ini_config, resp_info,
17348 &resptype_ptr, &resptype_ptr_dn,
17349 &resptype_txt, &resptype_a))
17350 goto err_resptype_ptr;
17351
17352 if ((resptype_ptr.num_entries > 0) &&
17353 (strlen((char *)&resptype_ptr.data[0]) > 0))
17354 num_res_records++;
17355
17356 /* Process Type SRV response */
17357 if (!wlan_hdd_mdns_pack_response_type_srv(ini_config, resp_info,
17358 &resptype_srv, &resptype_srv_tgt,
17359 &resptype_ptr, &resptype_ptr_dn,
17360 &resptype_txt, &resptype_a))
17361 goto err_resptype_srv;
17362
17363 if ((resptype_srv.num_entries > 0) &&
17364 (strlen((char *)&resptype_srv.data[0]) > 0))
17365 num_res_records++;
17366
17367 resp_info->resourceRecord_count = num_res_records;
17368 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
17369 "%s: Pack mDNS response data successfully!", __func__);
17370 status = TRUE;
17371
17372err_resptype_srv:
17373 wlan_hdd_mdns_free_mem(&resptype_srv);
17374 wlan_hdd_mdns_free_mem(&resptype_srv_tgt);
17375
17376err_resptype_ptr:
17377 wlan_hdd_mdns_free_mem(&resptype_ptr);
17378 wlan_hdd_mdns_free_mem(&resptype_ptr_dn);
17379
17380err_resptype_txt:
17381 wlan_hdd_mdns_free_mem(&resptype_txt);
17382
17383err_resptype_a:
17384 wlan_hdd_mdns_free_mem(&resptype_a);
17385
17386 EXIT();
17387 return status;
17388}
17389
17390/**
17391 * wlan_hdd_set_mdns_offload() - Enable mDNS offload
17392 * @hostapd_adapter: Pointer to the struct hdd_adapter_t
17393 *
17394 * This function will set FQDN/unique FQDN (full qualified domain name)
17395 * and the mDNS response. Then send them to SME.
17396 *
17397 * Return: Return boolean. TRUE for success, FALSE for fail.
17398 */
17399bool wlan_hdd_set_mdns_offload(hdd_adapter_t *hostapd_adapter)
17400{
17401 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(hostapd_adapter);
17402 sir_mdns_offload_info mdns_offload_info;
17403 sir_mdns_fqdn_info mdns_fqdn_info;
17404 sir_mdns_resp_info mdns_resp_info;
17405 uint32_t fqdn_len, ufqdn_len;
17406
17407 ENTER();
17408
17409 /* 1. Prepare the MDNS fqdn request to send to SME */
17410 fqdn_len = strlen(hdd_ctx->cfg_ini->mdns_fqdn);
17411 ufqdn_len = strlen(hdd_ctx->cfg_ini->mdns_uniquefqdn);
17412 if ((fqdn_len == 0) && (ufqdn_len == 0)) {
17413 hddLog(LOGE, FL("No mDNS FQDN or UFQDN is assigned fqdn_len %d,"
17414 "ufqdn_len %d!"), fqdn_len, ufqdn_len);
17415 return FALSE;
17416 }
17417
17418 mdns_fqdn_info = vos_mem_malloc(sizeof(*mdns_fqdn_info));
17419 if (NULL == mdns_fqdn_info) {
17420 hddLog(LOGE, FL("could not allocate tSirMDNSFqdnInfo!"));
17421 return FALSE;
17422 }
17423 /* MDNS fqdn request */
17424 if (fqdn_len > 0) {
17425 vos_mem_zero(mdns_fqdn_info, sizeof(*mdns_fqdn_info));
17426 mdns_fqdn_info->bss_idx = hostapd_adapter->sessionId;
17427 mdns_fqdn_info->fqdn_type = MDNS_FQDN_TYPE_GENERAL;
17428 mdns_fqdn_info->fqdn_len = fqdn_len;
17429 mdns_fqdn_info->mdns_fqdn_callback = hdd_mdns_fqdn_offload_done;
17430 mdns_fqdn_info->mdns_fqdn_cb_context = hostapd_adapter;
17431 vos_mem_copy(mdns_fqdn_info->fqdn_data,
17432 hdd_ctx->cfg_ini->mdns_fqdn,
17433 mdns_fqdn_info->fqdn_len);
17434
17435 if (eHAL_STATUS_SUCCESS !=
17436 sme_set_mdns_fqdn(hdd_ctx->hHal, mdns_fqdn_info)) {
17437 hddLog(LOGE, FL("sme_set_mdns_fqdn fail!"));
17438 vos_mem_free(mdns_fqdn_info);
17439 return FALSE;
17440 }
17441 }
17442 /* MDNS unique fqdn request */
17443 if (ufqdn_len > 0) {
17444 vos_mem_zero(mdns_fqdn_info, sizeof(*mdns_fqdn_info));
17445 mdns_fqdn_info->bss_idx = hostapd_adapter->sessionId;
17446 mdns_fqdn_info->fqdn_type = MDNS_FQDN_TYPE_UNIQUE;
17447 mdns_fqdn_info->fqdn_len = ufqdn_len;
17448 mdns_fqdn_info->mdns_fqdn_callback = hdd_mdns_fqdn_offload_done;
17449 mdns_fqdn_info->mdns_fqdn_cb_context = hostapd_adapter;
17450 vos_mem_copy(mdns_fqdn_info->fqdn_data,
17451 hdd_ctx->cfg_ini->mdns_uniquefqdn,
17452 mdns_fqdn_info->fqdn_len);
17453 if (eHAL_STATUS_SUCCESS !=
17454 sme_set_mdns_fqdn(hdd_ctx->hHal, mdns_fqdn_info)) {
17455 hddLog(LOGE, FL("sme_set_mdns_fqdn fail!"));
17456 vos_mem_free(mdns_fqdn_info);
17457 return FALSE;
17458 }
17459 }
17460 vos_mem_free(mdns_fqdn_info);
17461
17462 /* 2. Prepare the MDNS response request to send to SME */
17463 mdns_resp_info = vos_mem_malloc(sizeof(*mdns_resp_info));
17464 if (NULL == mdns_resp_info) {
17465 hddLog(LOGE, FL("could not allocate tSirMDNSResponseInfo!"));
17466 return FALSE;
17467 }
17468
17469 vos_mem_zero(mdns_resp_info, sizeof(*mdns_resp_info));
17470 mdns_resp_info->bss_idx = hostapd_adapter->sessionId;
17471 mdns_resp_info->mdns_resp_callback = hdd_mdns_resp_offload_done;
17472 mdns_resp_info->mdns_resp_cb_context = hostapd_adapter;
17473 if (!wlan_hdd_mdns_pack_response(hdd_ctx->cfg_ini, mdns_resp_info)) {
17474 hddLog(LOGE, FL("wlan_hdd_pack_mdns_response fail!"));
17475 vos_mem_free(mdns_resp_info);
17476 return FALSE;
17477 }
17478 if (eHAL_STATUS_SUCCESS !=
17479 sme_set_mdns_resp(hdd_ctx->hHal, mdns_resp_info)) {
17480 hddLog(LOGE, FL("sme_set_mdns_resp fail!"));
17481 vos_mem_free(mdns_resp_info);
17482 return FALSE;
17483 }
17484 vos_mem_free(mdns_resp_info);
17485
17486 /* 3. Prepare the MDNS Enable request to send to SME */
17487 mdns_offload_info = vos_mem_malloc(sizeof(*mdns_offload_info));
17488 if (NULL == mdns_offload_info) {
17489 hddLog(LOGE, FL("could not allocate tSirMDNSOffloadInfo!"));
17490 return FALSE;
17491 }
17492
17493 vos_mem_zero(mdns_offload_info, sizeof(*mdns_offload_info));
17494
17495 mdns_offload_info->bss_idx = hostapd_adapter->sessionId;
17496 mdns_offload_info->enable = hdd_ctx->cfg_ini->enable_mdns_offload;
17497 mdns_offload_info->mdns_enable_callback = hdd_mdns_enable_offload_done;
17498 mdns_offload_info->mdns_enable_cb_context = hostapd_adapter;
17499 if (eHAL_STATUS_SUCCESS !=
17500 sme_set_mdns_offload(hdd_ctx->hHal, mdns_offload_info)) {
17501 hddLog(LOGE, FL("sme_set_mdns_offload fail!"));
17502 vos_mem_free(mdns_offload_info);
17503 return FALSE;
17504 }
17505
17506 vos_mem_free(mdns_offload_info);
17507 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
17508 "%s: enable mDNS offload successfully!", __func__);
17509 return TRUE;
17510}
Manjeet Singh3ed79242017-01-11 19:04:32 +053017511
17512
Anurag Chouhan0b29de02016-12-16 13:18:40 +053017513#endif /* MDNS_OFFLOAD */
c_manjeecfd1efb2015-09-25 19:32:34 +053017514
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053017515/**
17516 * wlan_hdd_start_sap() - This function starts bss of SAP.
17517 * @ap_adapter: SAP adapter
17518 *
17519 * This function will process the starting of sap adapter.
17520 *
17521 * Return: void.
17522 */
17523void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter)
17524{
17525 hdd_ap_ctx_t *hdd_ap_ctx;
17526 hdd_hostapd_state_t *hostapd_state;
17527 VOS_STATUS vos_status;
17528 hdd_context_t *hdd_ctx;
17529 tsap_Config_t *pConfig;
17530
17531 if (NULL == ap_adapter) {
17532 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
17533 FL("ap_adapter is NULL here"));
17534 return;
17535 }
17536
17537 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
17538 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
17539 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
17540 pConfig = &ap_adapter->sessionCtx.ap.sapConfig;
17541
17542 mutex_lock(&hdd_ctx->sap_lock);
17543 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
17544 goto end;
17545
17546 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
17547 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
17548 goto end;
17549 }
17550
17551 vos_event_reset(&hostapd_state->vosEvent);
17552 if (WLANSAP_StartBss(hdd_ctx->pvosContext, hdd_hostapd_SAPEventCB,
17553 &hdd_ap_ctx->sapConfig, (v_PVOID_t)ap_adapter->dev)
17554 != VOS_STATUS_SUCCESS) {
17555 goto end;
17556 }
17557
17558 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
17559 FL("Waiting for SAP to start"));
17560 vos_status = vos_wait_single_event(&hostapd_state->vosEvent, 10000);
17561 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
17562 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
17563 FL("SAP Start failed"));
17564 goto end;
17565 }
17566 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
17567 FL("SAP Start Success"));
17568 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
17569
17570 wlan_hdd_incr_active_session(hdd_ctx, ap_adapter->device_mode);
17571 hostapd_state->bCommit = TRUE;
17572
17573end:
17574 mutex_unlock(&hdd_ctx->sap_lock);
17575 return;
17576}
17577
Manjeet Singh3ed79242017-01-11 19:04:32 +053017578#ifdef WLAN_FEATURE_TSF
17579
17580/**
17581 * hdd_tsf_cb() - handle tsf request callback
17582 *
17583 * @pcb_cxt: pointer to the hdd_contex
17584 * @ptsf: pointer to struct stsf
17585 *
17586 * Based on the request sent .
17587 *
17588 * Return: Describe the execute result of this routine
17589 */
17590static int hdd_tsf_cb(void *pcb_ctx, struct stsf *ptsf)
17591{
17592 hdd_context_t *hddctx;
17593 int status;
17594 hdd_adapter_t* adapter = (hdd_adapter_t*)pcb_ctx;
17595
17596 if (pcb_ctx == NULL || ptsf == NULL) {
17597 hddLog(VOS_TRACE_LEVEL_ERROR,
17598 FL("HDD context is not valid"));
17599 return -EINVAL;
17600 }
17601
17602 hddctx = (hdd_context_t *)pcb_ctx;
17603 status = wlan_hdd_validate_context(hddctx);
17604 if (0 != status)
17605 return -EINVAL;
17606
17607 if (NULL == adapter) {
17608 hddLog(VOS_TRACE_LEVEL_ERROR,
17609 FL("failed to find adapter"));
17610 return -EINVAL;
17611 }
17612
17613 hddLog(VOS_TRACE_LEVEL_INFO,
17614 FL("tsf cb handle event, device_mode is %d"),
17615 adapter->device_mode);
17616
17617 /* copy the return value to hdd_tsf_ctx in adapter*/
17618 if (ptsf->tsf_req_status) {
17619
17620 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17621 adapter->tsf_cap_ctx.tsf_get_state = TSF_NOT_RETURNED_BY_FW;
17622 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17623 vos_event_set (&adapter->tsf_cap_ctx.tsf_capture_done_event);
17624 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17625
17626 hddLog(VOS_TRACE_LEVEL_ERROR, FL("tsf req failure :%d"),
17627 ptsf->tsf_req_status);
17628 return ptsf->tsf_req_status;
17629 }
17630 /* If this is a get request.Store the tsf values in adapter. */
17631 if (!ptsf->set_tsf_req) {
17632 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17633 adapter->tsf_cap_ctx.tsf_low = ptsf->tsf_low;
17634 adapter->tsf_cap_ctx.tsf_high = ptsf->tsf_high;
17635 adapter->tsf_cap_ctx.tsf_get_state = TSF_RETURN;
17636 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17637 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17638
17639 hddLog(VOS_TRACE_LEVEL_INFO,
17640 FL("hdd_get_tsf_cb sta=%u, tsf_low=%u, tsf_high=%u"),
17641 adapter->sessionId, ptsf->tsf_low, ptsf->tsf_high);
17642 }
17643 else {
17644 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17645 adapter->tsf_cap_ctx.tsf_capture_state = TSF_CAP_STATE;
17646 adapter->tsf_cap_ctx.tsf_get_state = TSF_CURRENT_IN_CAP_STATE;
17647 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17648 }
17649 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17650 vos_event_set (&adapter->tsf_cap_ctx.tsf_capture_done_event);
17651 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17652
17653 /* free allocated mem */
17654 vos_mem_free(ptsf);
17655
17656 return 0;
17657}
17658
17659/**
17660 * hdd_capture_tsf() - capture tsf
17661 *
17662 * @adapter: pointer to adapter
17663 * @buf: pointer to upper layer buf
17664 * @len : the length of buf
17665 *
17666 * This function returns tsf value to uplayer.
17667 *
17668 * Return: Describe the execute result of this routine
17669 */
17670int hdd_capture_tsf(hdd_adapter_t *adapter, uint32_t *buf, int len)
17671{
17672 int ret = 0;
17673 hdd_station_ctx_t *hdd_sta_ctx;
17674 hdd_context_t *hdd_ctx;
17675 tSirCapTsfParams cap_tsf_params;
17676 VOS_STATUS status;
17677
17678 if (adapter == NULL || buf == NULL) {
17679 hddLog(VOS_TRACE_LEVEL_ERROR,
17680 FL("invalid pointer"));
17681 return -EINVAL;
17682 }
17683 if (len != 1)
17684 return -EINVAL;
17685
17686 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
17687
17688 if (wlan_hdd_validate_context(hdd_ctx)) {
17689 hddLog(VOS_TRACE_LEVEL_ERROR,
17690 FL("invalid hdd ctx"));
17691 return -EINVAL;
17692 }
17693 if (adapter->device_mode == WLAN_HDD_INFRA_STATION ||
17694 adapter->device_mode == WLAN_HDD_P2P_CLIENT) {
17695 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
17696 if (hdd_sta_ctx->conn_info.connState !=
17697 eConnectionState_Associated) {
17698
17699 hddLog(VOS_TRACE_LEVEL_INFO,
17700 FL("failed to cap tsf, not connect with ap"));
17701 buf[0] = TSF_STA_NOT_CONNECTED_NO_TSF;
17702 return ret;
17703 }
17704 }
17705 if ((adapter->device_mode == WLAN_HDD_SOFTAP ||
17706 adapter->device_mode == WLAN_HDD_P2P_GO) &&
17707 !(test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))) {
17708 hddLog(VOS_TRACE_LEVEL_INFO,
17709 FL("Soft AP / P2p GO not beaconing"));
17710 buf[0] = TSF_SAP_NOT_STARTED_NO_TSF;
17711 return ret;
17712 }
17713 if (adapter->tsf_cap_ctx.tsf_capture_state == TSF_CAP_STATE) {
17714 hddLog(VOS_TRACE_LEVEL_INFO,
17715 FL("current in capture state, pls reset"));
17716 buf[0] = TSF_CURRENT_IN_CAP_STATE;
17717 } else {
17718 hddLog(VOS_TRACE_LEVEL_INFO, FL("ioctl issue cap tsf cmd"));
17719 buf[0] = TSF_RETURN;
17720 cap_tsf_params.session_id = adapter->sessionId;
17721 cap_tsf_params.tsf_rsp_cb_func = hdd_tsf_cb;
17722 cap_tsf_params.tsf_rsp_cb_ctx = adapter;
17723
17724 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17725 adapter->tsf_cap_ctx.tsf_capture_state = TSF_CAP_STATE;
17726 adapter->tsf_cap_ctx.tsf_get_state = TSF_CURRENT_IN_CAP_STATE;
17727 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17728
17729 ret = sme_capture_tsf_req(hdd_ctx->hHal, cap_tsf_params);
17730
17731 if (ret != VOS_STATUS_SUCCESS) {
17732 hddLog(VOS_TRACE_LEVEL_ERROR, FL("capture fail"));
17733 buf[0] = TSF_CAPTURE_FAIL;
17734 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17735 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17736 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17737 return -EINVAL;
17738 }
17739 /* wait till we get a response from fw */
17740 status = vos_wait_single_event(&adapter->tsf_cap_ctx.
17741 tsf_capture_done_event,
17742 HDD_TSF_CAP_REQ_TIMEOUT);
17743
17744 if (!VOS_IS_STATUS_SUCCESS(status)) {
17745 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
17746 ("capture tsf vos wait for single_event failed!! %d"),
17747 adapter->tsf_cap_ctx.tsf_get_state);
17748
17749 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17750 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17751 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17752
17753 return -EINVAL;
17754 }
17755 }
17756 buf[0] = TSF_RETURN;
17757 hddLog(VOS_TRACE_LEVEL_INFO,
17758 FL("ioctl return cap tsf cmd, ret = %d"), ret);
17759 return ret;
17760}
17761
17762/**
17763 * hdd_indicate_tsf() - return tsf to uplayer
17764 *
17765 * @adapter: pointer to adapter
17766 * @buf: pointer to uplayer buf
17767 * @len : the length of buf
17768 *
17769 * This function returns tsf value to uplayer.
17770 *
17771 * Return: Describe the execute result of this routine
17772 */
17773int hdd_indicate_tsf(hdd_adapter_t *adapter, uint32_t *buf, int len)
17774{
17775 int ret = 0;
17776 hdd_station_ctx_t *hdd_sta_ctx;
17777 hdd_context_t *hdd_ctx;
17778 tSirCapTsfParams cap_tsf_params;
17779 VOS_STATUS status;
17780
17781 if (adapter == NULL || buf == NULL) {
17782 hddLog(VOS_TRACE_LEVEL_ERROR,
17783 FL("invalid pointer"));
17784 return -EINVAL;
17785 }
17786 if (len != 3)
17787 return -EINVAL;
17788
17789 buf [1] = 0;
17790 buf [2] = 0;
17791 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
17792
17793 if (wlan_hdd_validate_context(hdd_ctx)) {
17794 hddLog(VOS_TRACE_LEVEL_ERROR,
17795 FL("invalid hdd ctx"));
17796 return -EINVAL;
17797 }
17798 if (adapter->device_mode == WLAN_HDD_INFRA_STATION ||
17799 adapter->device_mode == WLAN_HDD_P2P_CLIENT) {
17800 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
17801 if (hdd_sta_ctx->conn_info.connState !=
17802 eConnectionState_Associated) {
17803
17804 hddLog(VOS_TRACE_LEVEL_INFO,
17805 FL("failed to cap tsf, not connect with ap"));
17806 buf[0] = TSF_STA_NOT_CONNECTED_NO_TSF;
17807 return ret;
17808 }
17809 }
17810 if ((adapter->device_mode == WLAN_HDD_SOFTAP ||
17811 adapter->device_mode == WLAN_HDD_P2P_GO) &&
17812 !(test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))) {
17813 hddLog(VOS_TRACE_LEVEL_INFO,
17814 FL("Soft AP / P2p GO not beaconing"));
17815 buf[0] = TSF_SAP_NOT_STARTED_NO_TSF;
17816 return ret;
17817 }
17818
17819 if (adapter->tsf_cap_ctx.tsf_capture_state != TSF_CAP_STATE ||
17820 adapter->tsf_cap_ctx.tsf_get_state != TSF_CURRENT_IN_CAP_STATE ) {
17821 hddLog(VOS_TRACE_LEVEL_INFO,
17822 FL("Not in capture state,Enter capture state first"));
17823 buf[0] = TSF_GET_FAIL;
17824 } else {
17825 hddLog(VOS_TRACE_LEVEL_INFO, FL("ioctl issue cap tsf cmd"));
17826 cap_tsf_params.session_id = adapter->sessionId;
17827 cap_tsf_params.tsf_rsp_cb_func = hdd_tsf_cb;
17828 cap_tsf_params.tsf_rsp_cb_ctx = adapter;
17829
17830 ret = sme_get_tsf_req(hdd_ctx->hHal, cap_tsf_params);
17831
17832 if (ret != VOS_STATUS_SUCCESS) {
17833 hddLog(VOS_TRACE_LEVEL_ERROR, FL("capture fail"));
17834 buf[0] = TSF_CAPTURE_FAIL;
17835 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17836 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17837 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17838 return -EINVAL;
17839 }
17840 /* wait till we get a response from fw */
17841 status = vos_wait_single_event(&adapter->tsf_cap_ctx.
17842 tsf_capture_done_event,
17843 HDD_TSF_GET_REQ_TIMEOUT);
17844
17845 if (!VOS_IS_STATUS_SUCCESS(status)) {
17846 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
17847 ("capture tsf vos wait for single_event failed!! %d"),
17848 status);
17849
17850 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17851 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17852 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17853 return status;
17854 }
17855 buf[1] = adapter->tsf_cap_ctx.tsf_low;
17856 buf[2] = adapter->tsf_cap_ctx.tsf_high;
17857
17858 hddLog(VOS_TRACE_LEVEL_INFO,
17859 FL("get tsf cmd,status=%u, tsf_low=%u, tsf_high=%u"),
17860 buf[0], buf[1], buf[2]);
17861 }
17862 hddLog(VOS_TRACE_LEVEL_INFO,
17863 FL("ioctl return cap tsf cmd, ret = %d"), ret);
17864 return ret;
17865}
17866
17867void wlan_hdd_tsf_init(hdd_adapter_t *adapter)
17868{
17869
17870 if (adapter == NULL) {
17871 hddLog(VOS_TRACE_LEVEL_ERROR,
17872 FL("TSF init on a null adapter!"));
17873 return;
17874 }
17875
17876 adapter->tsf_cap_ctx.tsf_get_state = TSF_RETURN;
17877 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17878 vos_event_init(&adapter->tsf_cap_ctx.tsf_capture_done_event);
17879 vos_spin_lock_init(&adapter->tsf_cap_ctx.tsf_lock);
17880 adapter->tsf_cap_ctx.tsf_high = 0;
17881 adapter->tsf_cap_ctx.tsf_low = 0;
17882}
17883
17884#endif
17885
Jeff Johnson295189b2012-06-20 16:38:30 -070017886//Register the module init/exit functions
17887module_init(hdd_module_init);
17888module_exit(hdd_module_exit);
17889
17890MODULE_LICENSE("Dual BSD/GPL");
17891MODULE_AUTHOR("Qualcomm Atheros, Inc.");
17892MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
17893
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070017894module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
17895 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Jeff Johnson32d95a32012-09-10 13:15:23 -070017896
Jeff Johnson76052702013-04-16 13:55:05 -070017897module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
Jeff Johnson32d95a32012-09-10 13:15:23 -070017898 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Arif Hussain66559122013-11-21 10:11:40 -080017899
17900module_param(enable_dfs_chan_scan, int,
17901 S_IRUSR | S_IRGRP | S_IROTH);
17902
17903module_param(enable_11d, int,
17904 S_IRUSR | S_IRGRP | S_IROTH);
17905
17906module_param(country_code, charp,
17907 S_IRUSR | S_IRGRP | S_IROTH);