blob: 3a3603d38aaa068f3f8f80750ccf0d23d9afbaa9 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Arunk Khandavalli95608be2019-01-22 13:12:54 +05302 * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved.
Kiet Lam842dad02014-02-18 18:44:02 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
Kiet Lama7f454d2014-07-24 12:04:06 -070023 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080026 */
Kiet Lam842dad02014-02-18 18:44:02 -080027
28
Kiet Lama7f454d2014-07-24 12:04:06 -070029
30
Jeff Johnson295189b2012-06-20 16:38:30 -070031/*========================================================================
32
33 \file wlan_hdd_main.c
34
35 \brief WLAN Host Device Driver implementation
36
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38 ========================================================================*/
39
40/**=========================================================================
41
42 EDIT HISTORY FOR FILE
43
44
45 This section contains comments describing changes made to the module.
46 Notice that changes are listed in reverse chronological order.
47
48
49 $Header:$ $DateTime: $ $Author: $
50
51
52 when who what, where, why
53 -------- --- --------------------------------------------------------
54 04/5/09 Shailender Created module.
55 02/24/10 Sudhir.S.Kohalli Added to support param for SoftAP module
56 06/03/10 js - Added support to hostapd driven deauth/disassoc/mic failure
57 ==========================================================================*/
58
59/*--------------------------------------------------------------------------
60 Include Files
61 ------------------------------------------------------------------------*/
62//#include <wlan_qct_driver.h>
63#include <wlan_hdd_includes.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070064#include <vos_api.h>
Rajeev Kumar Sirasanagandlaf8fc27c2018-12-06 14:56:43 +053065#include <vos_nvitem.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070066#include <vos_sched.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070067#include <linux/etherdevice.h>
68#include <linux/firmware.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070069#ifdef ANI_BUS_TYPE_PLATFORM
70#include <linux/wcnss_wlan.h>
71#endif //ANI_BUS_TYPE_PLATFORM
72#ifdef ANI_BUS_TYPE_PCI
73#include "wcnss_wlan.h"
74#endif /* ANI_BUS_TYPE_PCI */
75#include <wlan_hdd_tx_rx.h>
76#include <palTimer.h>
77#include <wniApi.h>
78#include <wlan_nlink_srv.h>
79#include <wlan_btc_svc.h>
80#include <wlan_hdd_cfg.h>
81#include <wlan_ptt_sock_svc.h>
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053082#include <wlan_logging_sock_svc.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070083#include <wlan_hdd_wowl.h>
84#include <wlan_hdd_misc.h>
85#include <wlan_hdd_wext.h>
86#ifdef WLAN_BTAMP_FEATURE
87#include <bap_hdd_main.h>
88#include <bapInternal.h>
89#endif // WLAN_BTAMP_FEATURE
Sushant Kaushik4b7cb302014-01-06 17:45:01 +053090#include "wlan_hdd_trace.h"
91#include "vos_types.h"
92#include "vos_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070093#include <linux/wireless.h>
94#include <net/cfg80211.h>
Vinay Krishna Erannad9cbdb32014-01-16 12:59:10 +053095#include <linux/inetdevice.h>
96#include <net/addrconf.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070097#include "wlan_hdd_cfg80211.h"
98#include "wlan_hdd_p2p.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070099#include <linux/rtnetlink.h>
Jeff Johnson295189b2012-06-20 16:38:30 -0700100int wlan_hdd_ftm_start(hdd_context_t *pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -0700101#include "sapApi.h"
102#include <linux/semaphore.h>
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -0700103#include <linux/ctype.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530104#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
105#include <soc/qcom/subsystem_restart.h>
106#else
Jeff Johnson295189b2012-06-20 16:38:30 -0700107#include <mach/subsystem_restart.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530108#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700109#include <wlan_hdd_hostapd.h>
110#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson295189b2012-06-20 16:38:30 -0700111#include "cfgApi.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700112#include "wlan_hdd_dev_pwr.h"
113#ifdef WLAN_BTAMP_FEATURE
114#include "bap_hdd_misc.h"
115#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700116#include "wlan_qct_pal_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700117#include "qwlan_version.h"
Yathish9f22e662012-12-10 14:21:35 -0800118#include "wlan_qct_wda.h"
Chilam NG571c65a2013-01-19 12:27:36 +0530119#ifdef FEATURE_WLAN_TDLS
120#include "wlan_hdd_tdls.h"
121#endif
Yue Ma0d4891e2013-08-06 17:01:45 -0700122#include "wlan_hdd_debugfs.h"
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +0530123#include "sapInternal.h"
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +0530124#include "wlan_hdd_request_manager.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700125
126#ifdef MODULE
127#define WLAN_MODULE_NAME module_name(THIS_MODULE)
128#else
129#define WLAN_MODULE_NAME "wlan"
130#endif
131
132#ifdef TIMER_MANAGER
133#define TIMER_MANAGER_STR " +TIMER_MANAGER"
134#else
135#define TIMER_MANAGER_STR ""
136#endif
137
138#ifdef MEMORY_DEBUG
139#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
140#else
141#define MEMORY_DEBUG_STR ""
142#endif
Kaushik, Sushant7005e372014-04-08 11:36:54 +0530143#define MAX_WAIT_FOR_ROC_COMPLETION 3
Jeff Johnson295189b2012-06-20 16:38:30 -0700144/* the Android framework expects this param even though we don't use it */
145#define BUF_LEN 20
Jeff Johnson76052702013-04-16 13:55:05 -0700146static char fwpath_buffer[BUF_LEN];
147static struct kparam_string fwpath = {
148 .string = fwpath_buffer,
149 .maxlen = BUF_LEN,
150};
Arif Hussain66559122013-11-21 10:11:40 -0800151
152static char *country_code;
153static int enable_11d = -1;
154static int enable_dfs_chan_scan = -1;
155
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700156#ifndef MODULE
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700157static int wlan_hdd_inited;
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700158#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700159
Jeff Johnsone7245742012-09-05 17:12:55 -0700160/*
Jeff Johnson72a40512013-12-19 10:14:15 -0800161 * spinlock for synchronizing asynchronous request/response
162 * (full description of use in wlan_hdd_main.h)
163 */
164DEFINE_SPINLOCK(hdd_context_lock);
165
166/*
Jeff Johnsone7245742012-09-05 17:12:55 -0700167 * The rate at which the driver sends RESTART event to supplicant
168 * once the function 'vos_wlanRestart()' is called
169 *
170 */
171#define WLAN_HDD_RESTART_RETRY_DELAY_MS 5000 /* 5 second */
172#define WLAN_HDD_RESTART_RETRY_MAX_CNT 5 /* 5 retries */
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -0700173
174/*
175 * Size of Driver command strings from upper layer
176 */
177#define SIZE_OF_SETROAMMODE 11 /* size of SETROAMMODE */
178#define SIZE_OF_GETROAMMODE 11 /* size of GETROAMMODE */
179
Abhishek Singh00b71972016-01-07 10:51:04 +0530180#ifdef WLAN_FEATURE_RMC
181/*
182 * Ibss prop IE from command will be of size:
183 * size = sizeof(oui) + sizeof(oui_data) + 1(Element ID) + 1(EID Length)
184 * OUI_DATA should be at least 3 bytes long
185 */
186#define WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH (3)
187#endif
188
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800189#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700190#define TID_MIN_VALUE 0
191#define TID_MAX_VALUE 15
192static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
193 tAniTrafStrmMetrics* pTsmMetrics);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800194static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
195 tCsrEseBeaconReq *pEseBcnReq);
196#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700197
Atul Mittal1d722422014-03-19 11:15:07 +0530198/*
199 * Maximum buffer size used for returning the data back to user space
200 */
201#define WLAN_MAX_BUF_SIZE 1024
202#define WLAN_PRIV_DATA_MAX_LEN 8192
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -0700203
Abhishek Singh00b71972016-01-07 10:51:04 +0530204/*
205 * When ever we need to print IBSSPEERINFOALL for morethan 16 STA
206 * we will split the printing.
207 */
208#define NUM_OF_STA_DATA_TO_PRINT 16
209
210#ifdef WLAN_FEATURE_RMC
211#define WLAN_NLINK_CESIUM 30
212#endif
213
c_hpothu92367912014-05-01 15:18:17 +0530214//wait time for beacon miss rate.
215#define BCN_MISS_RATE_TIME 500
216
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +0530217/*
218 * Android DRIVER command structures
219 */
220struct android_wifi_reassoc_params {
221 unsigned char bssid[18];
222 int channel;
223};
224
Sushant Kaushik83392fa2015-05-05 17:44:40 +0530225static vos_wake_lock_t wlan_wake_lock;
226
Jeff Johnson295189b2012-06-20 16:38:30 -0700227/* set when SSR is needed after unload */
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -0700228static e_hdd_ssr_required isSsrRequired = HDD_SSR_NOT_REQUIRED;
Jeff Johnson295189b2012-06-20 16:38:30 -0700229
230//internal function declaration
Jeff Johnsone7245742012-09-05 17:12:55 -0700231static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx);
232static void wlan_hdd_restart_init(hdd_context_t *pHddCtx);
233static void wlan_hdd_restart_deinit(hdd_context_t *pHddCtx);
Abhishek Singh00b71972016-01-07 10:51:04 +0530234
235#ifdef WLAN_FEATURE_RMC
236static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo);
237
238static int hdd_open_cesium_nl_sock(void);
239static void hdd_close_cesium_nl_sock(void);
240static struct sock *cesium_nl_srv_sock;
241static v_U16_t cesium_pid;
242
243static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
244 tANI_U8 *tx_fail_count,
245 tANI_U16 *pid);
246
247static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg);
248
249#endif /* WLAN_FEATURE_RMC */
Jeff Johnsone7245742012-09-05 17:12:55 -0700250void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback);
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800251void hdd_set_wlan_suspend_mode(bool suspend);
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530252void hdd_set_vowifi_mode(hdd_context_t *hdd_ctx, bool enable);
Jeff Johnsone7245742012-09-05 17:12:55 -0700253
Jeff Johnson295189b2012-06-20 16:38:30 -0700254v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +0530255 struct sk_buff *skb
256#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
257 , void *accel_priv
258#endif
259#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
260 , select_queue_fallback_t fallback
261#endif
262);
Jeff Johnson295189b2012-06-20 16:38:30 -0700263
264#ifdef WLAN_FEATURE_PACKET_FILTERING
265static void hdd_set_multicast_list(struct net_device *dev);
266#endif
267
268void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter);
269
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800270#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -0800271void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand);
272static VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels);
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700273static VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid,
274 tANI_U8 *pChannel, tANI_U8 *pDwellTime,
275 tANI_U8 **pBuf, tANI_U8 *pBufLen);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +0530276static int hdd_parse_reassoc_command_v1_data(const tANI_U8 *pValue,
277 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel);
Srinivas Girigowdade697412013-02-14 16:31:48 -0800278#endif
Ratheesh S P21280412015-05-19 14:21:52 +0530279
280/* Store WLAN driver info in a global variable such that crash debugger
281 can extract it from driver debug symbol and crashdump for post processing */
282tANI_U8 g_wlan_driver[ ] = "pronto_driver";
283
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800284#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700285VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe, tANI_U8 *pCckmIeLen);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800286#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700287
Mihir Shetee1093ba2014-01-21 20:13:32 +0530288static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx);
Sushant Kaushik8bc7df22014-04-09 17:55:29 +0530289const char * hdd_device_modetoString(v_U8_t device_mode)
290{
291 switch(device_mode)
292 {
293 CASE_RETURN_STRING( WLAN_HDD_INFRA_STATION );
294 CASE_RETURN_STRING( WLAN_HDD_SOFTAP );
295 CASE_RETURN_STRING( WLAN_HDD_P2P_CLIENT );
296 CASE_RETURN_STRING( WLAN_HDD_P2P_GO );
297 CASE_RETURN_STRING( WLAN_HDD_MONITOR);
298 CASE_RETURN_STRING( WLAN_HDD_FTM );
299 CASE_RETURN_STRING( WLAN_HDD_IBSS );
300 CASE_RETURN_STRING( WLAN_HDD_P2P_DEVICE );
301 default:
302 return "device_mode Unknown";
303 }
304}
Mihir Shetee1093ba2014-01-21 20:13:32 +0530305
Mukul Sharmaa78cf6b2015-02-24 16:59:01 +0530306static int __hdd_netdev_notifier_call(struct notifier_block * nb,
Jeff Johnson295189b2012-06-20 16:38:30 -0700307 unsigned long state,
308 void *ndev)
309{
Yeshwanth Sriram Guntukadb04f472019-08-08 16:58:23 +0530310#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
311 struct netdev_notifier_info *info = ndev;
312 struct net_device *dev = info->dev;
313#else
Jeff Johnson295189b2012-06-20 16:38:30 -0700314 struct net_device *dev = ndev;
Yeshwanth Sriram Guntukadb04f472019-08-08 16:58:23 +0530315#endif
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700316 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson27cee452013-03-27 11:10:24 -0700317 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -0700318#ifdef WLAN_BTAMP_FEATURE
319 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -0700320#endif
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530321 long result;
Jeff Johnson295189b2012-06-20 16:38:30 -0700322
323 //Make sure that this callback corresponds to our device.
Jeff Johnson27cee452013-03-27 11:10:24 -0700324 if ((strncmp(dev->name, "wlan", 4)) &&
Amar Singhal4c723bd2013-03-25 18:14:15 -0700325 (strncmp(dev->name, "p2p", 3)))
326 return NOTIFY_DONE;
327
Jeff Johnson295189b2012-06-20 16:38:30 -0700328 if (!dev->ieee80211_ptr)
Jeff Johnson27cee452013-03-27 11:10:24 -0700329 return NOTIFY_DONE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700330
Jeff Johnson27cee452013-03-27 11:10:24 -0700331 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700332 {
Jeff Johnsona8a1a482012-12-12 16:49:33 -0800333 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Adapter Null Pointer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700334 VOS_ASSERT(0);
335 return NOTIFY_DONE;
336 }
337
Jeff Johnson27cee452013-03-27 11:10:24 -0700338 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
339 if (NULL == pHddCtx)
340 {
341 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Context Null Pointer", __func__);
342 VOS_ASSERT(0);
343 return NOTIFY_DONE;
344 }
Sameer Thalappil14067972014-01-23 14:54:54 -0800345 if (pHddCtx->isLogpInProgress)
346 return NOTIFY_DONE;
347
Jeff Johnson27cee452013-03-27 11:10:24 -0700348
349 hddLog(VOS_TRACE_LEVEL_INFO, "%s: %s New Net Device State = %lu",
350 __func__, dev->name, state);
Jeff Johnson295189b2012-06-20 16:38:30 -0700351
352 switch (state) {
353 case NETDEV_REGISTER:
354 break;
355
356 case NETDEV_UNREGISTER:
357 break;
358
359 case NETDEV_UP:
360 break;
361
362 case NETDEV_DOWN:
363 break;
364
365 case NETDEV_CHANGE:
Jeff Johnsone7245742012-09-05 17:12:55 -0700366 if(TRUE == pAdapter->isLinkUpSvcNeeded)
367 complete(&pAdapter->linkup_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700368 break;
369
370 case NETDEV_GOING_DOWN:
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530371 result = wlan_hdd_scan_abort(pAdapter);
Girish Gowli4bf7a632014-06-12 13:42:11 +0530372 if (result < 0)
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530373 {
374 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
375 "%s: Timeout occurred while waiting for abortscan %ld",
376 __func__, result);
Jeff Johnson295189b2012-06-20 16:38:30 -0700377 }
378 else
379 {
380 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530381 "%s: Scan Abort Successful" , __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700382 }
383#ifdef WLAN_BTAMP_FEATURE
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700384 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s: disabling AMP", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700385 status = WLANBAP_StopAmp();
386 if(VOS_STATUS_SUCCESS != status )
387 {
388 pHddCtx->isAmpAllowed = VOS_TRUE;
389 hddLog(VOS_TRACE_LEVEL_FATAL,
390 "%s: Failed to stop AMP", __func__);
391 }
392 else
393 {
394 //a state m/c implementation in PAL is TBD to avoid this delay
395 msleep(500);
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700396 if ( pHddCtx->isAmpAllowed )
397 {
398 WLANBAP_DeregisterFromHCI();
399 pHddCtx->isAmpAllowed = VOS_FALSE;
400 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700401 }
402#endif //WLAN_BTAMP_FEATURE
403 break;
404
405 default:
406 break;
407 }
408
409 return NOTIFY_DONE;
410}
411
Mukul Sharmaa78cf6b2015-02-24 16:59:01 +0530412static int hdd_netdev_notifier_call(struct notifier_block * nb,
413 unsigned long state,
414 void *ndev)
415{
416 int ret;
417 vos_ssr_protect(__func__);
418 ret = __hdd_netdev_notifier_call( nb, state, ndev);
419 vos_ssr_unprotect(__func__);
420 return ret;
421}
422
Jeff Johnson295189b2012-06-20 16:38:30 -0700423struct notifier_block hdd_netdev_notifier = {
424 .notifier_call = hdd_netdev_notifier_call,
425};
426
427/*---------------------------------------------------------------------------
428 * Function definitions
429 *-------------------------------------------------------------------------*/
Jeff Johnson295189b2012-06-20 16:38:30 -0700430void hdd_unregister_mcast_bcast_filter(hdd_context_t *pHddCtx);
431void hdd_register_mcast_bcast_filter(hdd_context_t *pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -0700432//variable to hold the insmod parameters
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700433static int con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -0700434#ifndef MODULE
435/* current con_mode - used only for statically linked driver
436 * con_mode is changed by userspace to indicate a mode change which will
437 * result in calling the module exit and init functions. The module
438 * exit function will clean up based on the value of con_mode prior to it
439 * being changed by userspace. So curr_con_mode records the current con_mode
440 * for exit when con_mode becomes the next mode for init
441 */
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700442static int curr_con_mode;
Jeff Johnson295189b2012-06-20 16:38:30 -0700443#endif
444
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +0530445#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
446/**
447 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
448 * @hdd_ctx: hdd global context
449 *
450 * Return: none
451 */
452static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
453{
454 uint8_t i;
455
456 mutex_init(&hdd_ctx->op_ctx.op_lock);
457 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++)
458 {
459 hdd_ctx->op_ctx.op_table[i].request_id = 0;
460 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
461 }
462}
463#else
464static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
465{
466}
467#endif
468
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -0800469/**---------------------------------------------------------------------------
470
471 \brief hdd_vos_trace_enable() - Configure initial VOS Trace enable
472
473 Called immediately after the cfg.ini is read in order to configure
474 the desired trace levels.
475
476 \param - moduleId - module whose trace level is being configured
477 \param - bitmask - bitmask of log levels to be enabled
478
479 \return - void
480
481 --------------------------------------------------------------------------*/
482static void hdd_vos_trace_enable(VOS_MODULE_ID moduleId, v_U32_t bitmask)
483{
484 wpt_tracelevel level;
485
486 /* if the bitmask is the default value, then a bitmask was not
487 specified in cfg.ini, so leave the logging level alone (it
488 will remain at the "compiled in" default value) */
489 if (CFG_VOS_TRACE_ENABLE_DEFAULT == bitmask)
490 {
491 return;
492 }
493
494 /* a mask was specified. start by disabling all logging */
495 vos_trace_setValue(moduleId, VOS_TRACE_LEVEL_NONE, 0);
496
497 /* now cycle through the bitmask until all "set" bits are serviced */
498 level = VOS_TRACE_LEVEL_FATAL;
499 while (0 != bitmask)
500 {
501 if (bitmask & 1)
502 {
503 vos_trace_setValue(moduleId, level, 1);
504 }
505 level++;
506 bitmask >>= 1;
507 }
508}
509
510
Jeff Johnson295189b2012-06-20 16:38:30 -0700511/**---------------------------------------------------------------------------
512
513 \brief hdd_wdi_trace_enable() - Configure initial WDI Trace enable
514
515 Called immediately after the cfg.ini is read in order to configure
516 the desired trace levels in the WDI.
517
518 \param - moduleId - module whose trace level is being configured
519 \param - bitmask - bitmask of log levels to be enabled
520
521 \return - void
522
523 --------------------------------------------------------------------------*/
524static void hdd_wdi_trace_enable(wpt_moduleid moduleId, v_U32_t bitmask)
525{
526 wpt_tracelevel level;
527
528 /* if the bitmask is the default value, then a bitmask was not
529 specified in cfg.ini, so leave the logging level alone (it
530 will remain at the "compiled in" default value) */
531 if (CFG_WDI_TRACE_ENABLE_DEFAULT == bitmask)
532 {
533 return;
534 }
535
536 /* a mask was specified. start by disabling all logging */
537 wpalTraceSetLevel(moduleId, eWLAN_PAL_TRACE_LEVEL_NONE, 0);
538
539 /* now cycle through the bitmask until all "set" bits are serviced */
540 level = eWLAN_PAL_TRACE_LEVEL_FATAL;
541 while (0 != bitmask)
542 {
543 if (bitmask & 1)
544 {
545 wpalTraceSetLevel(moduleId, level, 1);
546 }
547 level++;
548 bitmask >>= 1;
549 }
550}
Jeff Johnson295189b2012-06-20 16:38:30 -0700551
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530552/*
553 * FUNCTION: wlan_hdd_validate_context
554 * This function is used to check the HDD context
555 */
556int wlan_hdd_validate_context(hdd_context_t *pHddCtx)
557{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530558
559 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
560 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530561 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530562 "%s: HDD context is Null", __func__);
563 return -ENODEV;
564 }
565
566 if (pHddCtx->isLogpInProgress)
567 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530568 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu8adb97b2014-12-08 19:38:20 +0530569 "%s: LOGP %s. Ignore!!", __func__,
570 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)
571 ?"failed":"in Progress");
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530572 return -EAGAIN;
573 }
574
Mihir Shete18156292014-03-11 15:38:30 +0530575 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530576 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530577 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530578 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
579 return -EAGAIN;
580 }
581 return 0;
582}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700583#ifdef CONFIG_ENABLE_LINUX_REG
584void hdd_checkandupdate_phymode( hdd_context_t *pHddCtx)
585{
586 hdd_adapter_t *pAdapter = NULL;
587 hdd_station_ctx_t *pHddStaCtx = NULL;
588 eCsrPhyMode phyMode;
589 hdd_config_t *cfg_param = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530590
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700591 if (NULL == pHddCtx)
592 {
593 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
594 "HDD Context is null !!");
595 return ;
596 }
597
598 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
599 if (NULL == pAdapter)
600 {
601 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
602 "pAdapter is null !!");
603 return ;
604 }
605
606 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
607 if (NULL == pHddStaCtx)
608 {
609 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
610 "pHddStaCtx is null !!");
611 return ;
612 }
613
614 cfg_param = pHddCtx->cfg_ini;
615 if (NULL == cfg_param)
616 {
617 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
618 "cfg_params not available !!");
619 return ;
620 }
621
622 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
623
624 if (!pHddCtx->isVHT80Allowed)
625 {
626 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
627 (eCSR_DOT11_MODE_11ac == phyMode) ||
628 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
629 {
630 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
631 "Setting phymode to 11n!!");
632 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
633 }
634 }
635 else
636 {
637 /*New country Supports 11ac as well resetting value back from .ini*/
638 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
639 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
640 return ;
641 }
642
643 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
644 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
645 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
646 {
647 VOS_STATUS vosStatus;
648
649 // need to issue a disconnect to CSR.
650 INIT_COMPLETION(pAdapter->disconnect_comp_var);
651 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
652 pAdapter->sessionId,
653 eCSR_DISCONNECT_REASON_UNSPECIFIED );
654
655 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530656 {
657 long ret;
658
659 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700660 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530661 if (0 >= ret)
662 hddLog(LOGE, FL("failure waiting for disconnect_comp_var %ld"),
663 ret);
664 }
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700665
666 }
667}
668#else
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530669void hdd_checkandupdate_phymode( hdd_adapter_t *pAdapter, char *country_code)
670{
671 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
672 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
673 hdd_config_t *cfg_param;
674 eCsrPhyMode phyMode;
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530675 long ret;
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530676
677 if (NULL == pHddCtx)
678 {
679 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
680 "HDD Context is null !!");
681 return ;
682 }
683
684 cfg_param = pHddCtx->cfg_ini;
685
686 if (NULL == cfg_param)
687 {
688 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
689 "cfg_params not available !!");
690 return ;
691 }
692
693 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
694
695 if (NULL != strstr(cfg_param->listOfNon11acCountryCode, country_code))
696 {
697 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
698 (eCSR_DOT11_MODE_11ac == phyMode) ||
699 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
700 {
701 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
702 "Setting phymode to 11n!!");
703 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
704 }
705 }
706 else
707 {
708 /*New country Supports 11ac as well resetting value back from .ini*/
709 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
710 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
711 return ;
712 }
713
714 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
715 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
716 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
717 {
718 VOS_STATUS vosStatus;
719
720 // need to issue a disconnect to CSR.
721 INIT_COMPLETION(pAdapter->disconnect_comp_var);
722 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
723 pAdapter->sessionId,
724 eCSR_DISCONNECT_REASON_UNSPECIFIED );
725
726 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530727 {
728 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530729 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530730 if (ret <= 0)
731 {
732 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
733 "wait on disconnect_comp_var is failed %ld", ret);
734 }
735 }
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530736
737 }
738}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700739#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530740
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700741void hdd_checkandupdate_dfssetting( hdd_adapter_t *pAdapter, char *country_code)
742{
743 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
744 hdd_config_t *cfg_param;
745
746 if (NULL == pHddCtx)
747 {
748 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
749 "HDD Context is null !!");
750 return ;
751 }
752
753 cfg_param = pHddCtx->cfg_ini;
754
755 if (NULL == cfg_param)
756 {
757 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
758 "cfg_params not available !!");
759 return ;
760 }
761
Agarwal Ashish738843c2014-09-25 12:27:56 +0530762 if (NULL != strstr(cfg_param->listOfNonDfsCountryCode, country_code) ||
763 pHddCtx->disable_dfs_flag == TRUE)
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700764 {
765 /*New country doesn't support DFS */
766 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
767 }
Ashish Kumar Dhanotiya445b3b92018-06-07 12:38:12 +0530768 else
769 {
770 /* New country Supports DFS as well resetting value back from .ini */
771 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter),
772 cfg_param->enableDFSChnlScan);
773 }
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700774
775}
776
Abhishek Singh00b71972016-01-07 10:51:04 +0530777#ifdef WLAN_FEATURE_RMC
778static int hdd_parse_setrmcenable_command(tANI_U8 *pValue, tANI_U8 *pRmcEnable)
779{
780 tANI_U8 *inPtr = pValue;
781 int tempInt;
782 int v = 0;
783 char buf[32];
784 *pRmcEnable = 0;
785
786 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
787 /*no argument after the command*/
788 if (NULL == inPtr)
789 {
790 return 0;
791 }
792
793 /*no space after the command*/
794 else if (SPACE_ASCII_VALUE != *inPtr)
795 {
796 return 0;
797 }
798
799 /*removing empty spaces*/
800 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
801
802 /*no argument followed by spaces*/
803 if ('\0' == *inPtr)
804 {
805 return 0;
806 }
807
808 /* getting the first argument which enables or disables RMC
809 * for input IP v4 address*/
Ashish Kumar Dhanotiya54d31a32017-08-04 17:12:44 +0530810 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530811 v = kstrtos32(buf, 10, &tempInt);
812 if ( v < 0)
813 {
814 return -EINVAL;
815 }
816
817 *pRmcEnable = tempInt;
818
819 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
820 "ucRmcEnable: %d", *pRmcEnable);
821
822 return 0;
823}
824
825/* Function header left blank Intentionally */
826static int hdd_parse_setrmcactionperiod_command(tANI_U8 *pValue,
827 tANI_U32 *pActionPeriod)
828{
829 tANI_U8 *inPtr = pValue;
830 int tempInt;
831 int v = 0;
832 char buf[32];
833 *pActionPeriod = 0;
834
835 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
836 /*no argument after the command*/
837 if (NULL == inPtr)
838 {
839 return -EINVAL;
840 }
841
842 /*no space after the command*/
843 else if (SPACE_ASCII_VALUE != *inPtr)
844 {
845 return -EINVAL;
846 }
847
848 /*removing empty spaces*/
849 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
850
851 /*no argument followed by spaces*/
852 if ('\0' == *inPtr)
853 {
854 return 0;
855 }
856
857 /* getting the first argument which enables or disables RMC
858 * for input IP v4 address*/
Ashish Kumar Dhanotiya54d31a32017-08-04 17:12:44 +0530859 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530860 v = kstrtos32(buf, 10, &tempInt);
861 if ( v < 0)
862 {
863 return -EINVAL;
864 }
865
866 /* Range checking for passed paramter */
867 if (tempInt < WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY_STAMIN ||
868 tempInt > WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY_STAMAX)
869 {
870 return -EINVAL;
871 }
872
873 *pActionPeriod = tempInt;
874
875 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
876 "uActionPeriod: %d", *pActionPeriod);
877
878 return 0;
879}
Dundi Ravitejae110a042018-04-18 13:11:37 +0530880
881/**
882 * hdd_set_vowifi_mode() - Process VOWIFI command.
883 * @hdd_ctx: context handler
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530884 * @enable: Value to be sent as a part of the VOWIFI command
885 *
Dundi Ravitejae110a042018-04-18 13:11:37 +0530886 * Invoke the SME api if station is connected in 2.4 GHz band.
887 * Also start split scan if VOWIFIMODE and dynamic split scan
888 * both are enabled.
889
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530890 * Return: void
891 */
892void hdd_set_vowifi_mode(hdd_context_t *hdd_ctx, bool enable)
893{
894 tANI_U8 sta_chan;
895
Dundi Ravitejaab9d3092018-04-05 18:24:40 +0530896 if (!hdd_ctx->cfg_ini) {
897 hddLog(LOGE, "cfg_ini got NULL");
898 return;
899 }
900
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530901 sta_chan = hdd_get_operating_channel(hdd_ctx, WLAN_HDD_INFRA_STATION);
902
Dundi Ravitejae110a042018-04-18 13:11:37 +0530903 if (CSR_IS_CHANNEL_24GHZ(sta_chan))
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530904 sme_set_vowifi_mode(hdd_ctx->hHal, enable);
Dundi Ravitejae110a042018-04-18 13:11:37 +0530905 else
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530906 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
907 "VoWiFi command rejected as not connected in 2.4GHz");
Dundi Ravitejae110a042018-04-18 13:11:37 +0530908
909 if (enable && hdd_ctx->cfg_ini->dynSplitscan) {
910 hdd_ctx->is_vowifi_enabled = true;
911 hdd_ctx->issplitscan_enabled = TRUE;
912 sme_enable_disable_split_scan(hdd_ctx->hHal,
913 hdd_ctx->cfg_ini->nNumStaChanCombinedConc,
914 hdd_ctx->cfg_ini->nNumP2PChanCombinedConc);
915 } else {
916 hdd_ctx->is_vowifi_enabled = false;
Dundi Ravitejaab9d3092018-04-05 18:24:40 +0530917 }
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +0530918}
Abhishek Singh00b71972016-01-07 10:51:04 +0530919
920/* Function header left blank Intentionally */
921static int hdd_parse_setrmcrate_command(tANI_U8 *pValue,
922 tANI_U32 *pRate, tTxrateinfoflags *pTxFlags)
923{
924 tANI_U8 *inPtr = pValue;
925 int tempInt;
926 int v = 0;
927 char buf[32];
928 *pRate = 0;
929 *pTxFlags = 0;
930
931 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
932 /*no argument after the command*/
933 if (NULL == inPtr)
934 {
935 return -EINVAL;
936 }
937
938 /*no space after the command*/
939 else if (SPACE_ASCII_VALUE != *inPtr)
940 {
941 return -EINVAL;
942 }
943
944 /*removing empty spaces*/
945 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
946
947 /*no argument followed by spaces*/
948 if ('\0' == *inPtr)
949 {
950 return 0;
951 }
952
953 /*
954 * getting the first argument which sets multicast rate.
955 */
Ashish Kumar Dhanotiya06f9f202017-08-04 15:26:27 +0530956 sscanf(inPtr, "%31s ", buf);
Abhishek Singh00b71972016-01-07 10:51:04 +0530957 v = kstrtos32(buf, 10, &tempInt);
958 if ( v < 0)
959 {
960 return -EINVAL;
961 }
962
963 /*
964 * Validate the multicast rate.
965 */
966 switch (tempInt)
967 {
968 default:
969 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
970 "Unsupported rate: %d", tempInt);
971 return -EINVAL;
972 case 0:
973 case 6:
974 case 9:
975 case 12:
976 case 18:
977 case 24:
978 case 36:
979 case 48:
980 case 54:
981 *pTxFlags = eHAL_TX_RATE_LEGACY;
982 *pRate = tempInt * 10;
983 break;
984 case 65:
985 *pTxFlags = eHAL_TX_RATE_HT20;
986 *pRate = tempInt * 10;
987 break;
988 case 72:
989 *pTxFlags = eHAL_TX_RATE_HT20 | eHAL_TX_RATE_SGI;
990 *pRate = 722; /* fractional rate 72.2 Mbps */
991 break;
992 }
993
994 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
995 "Rate: %d", *pRate);
996
997 return 0;
998}
999
1000/**---------------------------------------------------------------------------
1001
1002 \brief hdd_cfg80211_get_ibss_peer_info_cb() - Callback function for IBSS
1003 Peer Info request
1004
1005 This is an asynchronous callback function from SME when the peer info
1006 is received
1007
1008 \pUserData -> Adapter private data
1009 \pPeerInfoRsp -> Peer info response
1010
1011 \return - 0 for success non-zero for failure
1012 --------------------------------------------------------------------------*/
1013static void
1014hdd_cfg80211_get_ibss_peer_info_cb(v_VOID_t *pUserData, v_VOID_t *pPeerInfoRsp)
1015{
1016 hdd_adapter_t *pAdapter = (hdd_adapter_t *)pUserData;
1017 tSirPeerInfoRspParams *pPeerInfo = (tSirPeerInfoRspParams *)pPeerInfoRsp;
1018 hdd_station_ctx_t *pStaCtx;
1019 v_U8_t i;
1020
1021 /*Sanity check*/
1022 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
1023 {
1024 hddLog(LOGE,
1025 FL("invalid adapter or adapter has invalid magic"));
1026 return;
1027 }
1028
1029 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1030 if (NULL != pStaCtx && NULL != pPeerInfo &&
1031 eHAL_STATUS_SUCCESS == pPeerInfo->status)
1032 {
1033 pStaCtx->ibss_peer_info.status = pPeerInfo->status;
1034 pStaCtx->ibss_peer_info.numIBSSPeers = pPeerInfo->numPeers;
1035
1036 /* Paranoia check */
1037 if (pPeerInfo->numPeers < HDD_MAX_NUM_IBSS_STA)
1038 {
1039 for (i = 0; i < pPeerInfo->numPeers; i++)
1040 {
1041 memcpy(&pStaCtx->ibss_peer_info.ibssPeerList[i],
1042 &pPeerInfo->peerInfoParams[i],
1043 sizeof(hdd_ibss_peer_info_params_t));
1044 }
1045 hddLog(LOG1,
1046 FL("Peer Info copied in HDD"));
1047 }
1048 else
1049 {
1050 hddLog(LOGE,
1051 FL(" Number of peers %d returned is more than limit %d"),
1052 pPeerInfo->numPeers, HDD_MAX_NUM_IBSS_STA);
1053 }
1054 }
1055 else
1056 {
1057 hddLog(LOG1,
1058 FL("peerInfo returned is NULL"));
1059 }
1060
1061 complete(&pAdapter->ibss_peer_info_comp);
1062}
1063
1064/**---------------------------------------------------------------------------
1065
1066 \brief hdd_cfg80211_get_ibss_peer_info_all() -
1067
1068 Request function to get IBSS peer info from lower layers
1069
1070 \pAdapter -> Adapter context
1071
1072 \return - 0 for success non-zero for failure
1073 --------------------------------------------------------------------------*/
1074static
1075VOS_STATUS hdd_cfg80211_get_ibss_peer_info_all(hdd_adapter_t *pAdapter)
1076{
1077 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1078 long status;
1079 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1080
1081 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1082
1083 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1084 hdd_cfg80211_get_ibss_peer_info_cb,
1085 VOS_TRUE, 0xFF);
1086
1087 if (VOS_STATUS_SUCCESS == retStatus)
1088 {
1089 status = wait_for_completion_interruptible_timeout
1090 (&pAdapter->ibss_peer_info_comp,
1091 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1092
1093 /* status will be 0 if timed out */
1094 if (status <= 0)
1095 {
1096 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1097 __func__, status);
1098 retStatus = VOS_STATUS_E_FAILURE;
1099 return retStatus;
1100 }
1101 }
1102 else
1103 {
1104 hddLog(VOS_TRACE_LEVEL_WARN,
1105 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1106 }
1107
1108 return retStatus;
1109}
1110
1111/**---------------------------------------------------------------------------
1112
1113 \brief hdd_cfg80211_get_ibss_peer_info() -
1114
1115 Request function to get IBSS peer info from lower layers
1116
1117 \pAdapter -> Adapter context
1118 \staIdx -> Sta index for which the peer info is requested
1119
1120 \return - 0 for success non-zero for failure
1121 --------------------------------------------------------------------------*/
1122static VOS_STATUS
1123hdd_cfg80211_get_ibss_peer_info(hdd_adapter_t *pAdapter, v_U8_t staIdx)
1124{
1125 long status;
1126 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1127 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1128
1129 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1130
1131 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1132 hdd_cfg80211_get_ibss_peer_info_cb,
1133 VOS_FALSE, staIdx);
1134
1135 if (VOS_STATUS_SUCCESS == retStatus)
1136 {
1137 status = wait_for_completion_interruptible_timeout
1138 (&pAdapter->ibss_peer_info_comp,
1139 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1140
1141 /* status = 0 on timeout */
1142 if (status <= 0)
1143 {
1144 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1145 __func__, status);
1146 retStatus = VOS_STATUS_E_FAILURE;
1147 return retStatus;
1148 }
1149 }
1150 else
1151 {
1152 hddLog(VOS_TRACE_LEVEL_WARN,
1153 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1154 }
1155
1156 return retStatus;
1157}
1158
1159/* Function header left blank Intentionally */
1160VOS_STATUS
1161hdd_parse_get_ibss_peer_info(tANI_U8 *pValue, v_MACADDR_t *pPeerMacAddr)
1162{
1163 tANI_U8 *inPtr = pValue;
1164 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1165
1166 /*no argument after the command*/
1167 if (NULL == inPtr)
1168 {
1169 return VOS_STATUS_E_FAILURE;;
1170 }
1171
1172 /*no space after the command*/
1173 else if (SPACE_ASCII_VALUE != *inPtr)
1174 {
1175 return VOS_STATUS_E_FAILURE;;
1176 }
1177
1178 /*removing empty spaces*/
1179 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
1180
1181 /*no argument followed by spaces*/
1182 if ('\0' == *inPtr)
1183 {
1184 return VOS_STATUS_E_FAILURE;;
1185 }
1186
1187 /*getting the first argument ie the peer mac address */
1188 if (inPtr[2] != ':' || inPtr[5] != ':' || inPtr[8] != ':' ||
1189 inPtr[11] != ':' || inPtr[14] != ':')
1190 {
1191 return VOS_STATUS_E_FAILURE;;
1192 }
1193 sscanf(inPtr, "%2x:%2x:%2x:%2x:%2x:%2x",
1194 (unsigned int *)&pPeerMacAddr->bytes[0],
1195 (unsigned int *)&pPeerMacAddr->bytes[1],
1196 (unsigned int *)&pPeerMacAddr->bytes[2],
1197 (unsigned int *)&pPeerMacAddr->bytes[3],
1198 (unsigned int *)&pPeerMacAddr->bytes[4],
1199 (unsigned int *)&pPeerMacAddr->bytes[5]);
1200
1201 /* The command buffer seems to be fine */
1202 return VOS_STATUS_SUCCESS;
1203}
1204
1205/* Function header left blank Intentionally */
1206static int hdd_parse_set_ibss_oui_data_command(tANI_U8 *command, tANI_U8 *ie,
1207 tANI_U32 limit)
1208{
1209 tANI_U8 len;
1210 tANI_U8 data;
1211
1212 /* skip white space */
1213 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1214 {
1215 command++;
1216 limit--;
1217 }
1218
1219 /* skip element id and element length */
1220 len = 2;
1221
1222 /* extract oui */
1223 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1224 (limit > 1))
1225 {
1226 /* Convert ASCII to decimal */
1227 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1228 ie[len++] = data;
1229 command += 2;
1230 limit -= 2;
1231 }
1232
1233 /* skip white space */
1234 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1235 {
1236 command++;
1237 limit--;
1238 }
1239
1240 /* extract data */
1241 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1242 (limit > 1))
1243 {
1244 /* Convert ASCII to decimal */
1245 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1246 ie[len++] = data;
1247 command += 2;
1248 limit -= 2;
1249 }
1250
1251 /* fill element id and element length */
1252 ie[0] = IE_EID_VENDOR;
1253 ie[1] = len - 2;
1254
1255 return len;
1256}
1257
1258static tANI_U32 hdd_find_ibss_wpa_ie_pos(tANI_U8 *addIePtr, tANI_U32 addIeLen)
1259{
1260 tANI_U32 ieLenPresent = 0;
1261 int left = addIeLen;
1262 v_U8_t *ptr = addIePtr;
1263 v_U8_t elem_id,elem_len;
1264
1265 while(left >= 2)
1266 {
1267 elem_id = ptr[0];
1268 elem_len = ptr[1];
1269 left -= 2;
1270 if(elem_len > left)
1271 {
1272 hddLog(LOGE,
1273 FL("****Invalid elem_len=%d left=%d*****"),
1274 elem_len,left);
1275 return 0;
1276 }
1277 if ((elem_id == IE_EID_VENDOR) &&
1278 (left >= WPA_OUI_TYPE_SIZE))
1279 {
1280 if (!memcmp(&ptr[2], WPA_OUI_TYPE,
1281 WPA_OUI_TYPE_SIZE))
1282 {
1283 ieLenPresent += elem_len + 2;
1284 return ieLenPresent;
1285 }
1286 }
1287 ieLenPresent += (elem_len + 2);
1288 left -= elem_len;
1289 ptr += (elem_len + 2);
1290 }
1291 return 0;
1292}
1293
1294#endif /* WLAN_FEATURE_RMC */
1295
Rajeev79dbe4c2013-10-05 11:03:42 +05301296#ifdef FEATURE_WLAN_BATCH_SCAN
1297
1298/**---------------------------------------------------------------------------
1299
1300 \brief hdd_extract_assigned_int_from_str() - Extracts assigned integer from
1301 input string
1302
1303 This function extracts assigned integer from string in below format:
1304 "STRING=10" : extracts integer 10 from this string
1305
1306 \param - pInPtr Pointer to input string
1307 \param - base Base for string to int conversion(10 for decimal 16 for hex)
1308 \param - pOutPtr Pointer to variable in which extracted integer needs to be
1309 assigned
1310 \param - pLastArg to tell whether it is last arguement in input string or
1311 not
1312
1313 \return - NULL for failure cases
1314 pointer to next arguement in input string for success cases
1315 --------------------------------------------------------------------------*/
1316static tANI_U8 *
1317hdd_extract_assigned_int_from_str
1318(
1319 tANI_U8 *pInPtr,
1320 tANI_U8 base,
1321 tANI_U32 *pOutPtr,
1322 tANI_U8 *pLastArg
1323)
1324{
1325 int tempInt;
1326 int v = 0;
1327 char buf[32];
1328 int val = 0;
1329 *pLastArg = FALSE;
1330
1331 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1332 if (NULL == pInPtr)
1333 {
1334 return NULL;
1335 }
1336
1337 pInPtr++;
1338
1339 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1340
1341 val = sscanf(pInPtr, "%32s ", buf);
1342 if (val < 0 && val > strlen(pInPtr))
1343 {
1344 return NULL;
1345 }
1346 pInPtr += val;
1347 v = kstrtos32(buf, base, &tempInt);
1348 if (v < 0)
1349 {
1350 return NULL;
1351 }
Rajeev Kumar4d93d842014-01-02 18:31:21 -08001352 if (tempInt < 0)
1353 {
1354 tempInt = 0;
1355 }
Rajeev79dbe4c2013-10-05 11:03:42 +05301356 *pOutPtr = tempInt;
1357
1358 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1359 if (NULL == pInPtr)
1360 {
1361 *pLastArg = TRUE;
1362 return NULL;
1363 }
1364 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1365
1366 return pInPtr;
1367}
1368
1369/**---------------------------------------------------------------------------
1370
1371 \brief hdd_extract_assigned_char_from_str() - Extracts assigned char from
1372 input string
1373
1374 This function extracts assigned character from string in below format:
1375 "STRING=A" : extracts char 'A' from this string
1376
1377 \param - pInPtr Pointer to input string
1378 \param - pOutPtr Pointer to variable in which extracted char needs to be
1379 assigned
1380 \param - pLastArg to tell whether it is last arguement in input string or
1381 not
1382
1383 \return - NULL for failure cases
1384 pointer to next arguement in input string for success cases
1385 --------------------------------------------------------------------------*/
1386static tANI_U8 *
1387hdd_extract_assigned_char_from_str
1388(
1389 tANI_U8 *pInPtr,
1390 tANI_U8 *pOutPtr,
1391 tANI_U8 *pLastArg
1392)
1393{
1394 *pLastArg = FALSE;
1395
1396 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1397 if (NULL == pInPtr)
1398 {
1399 return NULL;
1400 }
1401
1402 pInPtr++;
1403
1404 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1405
1406 *pOutPtr = *pInPtr;
1407
1408 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1409 if (NULL == pInPtr)
1410 {
1411 *pLastArg = TRUE;
1412 return NULL;
1413 }
1414 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1415
1416 return pInPtr;
1417}
1418
1419
1420/**---------------------------------------------------------------------------
1421
1422 \brief hdd_parse_set_batchscan_command () - HDD parse set batch scan command
1423
1424 This function parses set batch scan command in below format:
1425 WLS_BATCHING_SET <space> followed by below arguements
1426 "SCANFREQ=XX" : Optional defaults to 30 sec
1427 "MSCAN=XX" : Required number of scans to attempt to batch
1428 "BESTN=XX" : Best Network (RSSI) defaults to 16
1429 "CHANNEL=<X,Y>" : optional defaults to all channels, can list 'A'or` B.
1430 A. implies only 5 GHz , B. implies only 2.4GHz
1431 "RTT=X" : optional defaults to 0
1432 returns the MIN of MSCAN or the max # of scans firmware can cache or -1 on
1433 error
1434
1435 For example input commands:
1436 1) WLS_BATCHING_SET SCANFREQ=60 MSCAN=10 BESTN=20 CHANNEL=A RTT=0 -> This is
1437 translated into set batch scan with following parameters:
1438 a) Frequence 60 seconds
1439 b) Batch 10 scans together
1440 c) Best RSSI to be 20
1441 d) 5GHz band only
1442 e) RTT is equal to 0
1443
1444 \param - pValue Pointer to input channel list
1445 \param - pHddSetBatchScanReq Pointer to HDD batch scan request structure
1446
1447 \return - 0 for success non-zero for failure
1448
1449 --------------------------------------------------------------------------*/
1450static int
1451hdd_parse_set_batchscan_command
1452(
1453 tANI_U8 *pValue,
1454 tSirSetBatchScanReq *pHddSetBatchScanReq
1455)
1456{
1457 tANI_U8 *inPtr = pValue;
1458 tANI_U8 val = 0;
1459 tANI_U8 lastArg = 0;
Abhishek Singh00b71972016-01-07 10:51:04 +05301460 tANI_U32 nScanFreq = HDD_SET_BATCH_SCAN_DEFAULT_FREQ;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001461 tANI_U32 nMscan;
Abhishek Singh00b71972016-01-07 10:51:04 +05301462 tANI_U32 nBestN = HDD_SET_BATCH_SCAN_BEST_NETWORK;
1463 tANI_U8 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1464 tANI_U32 nRtt = 0;
Rajeev Kumarc933d982013-11-18 20:04:20 -08001465 tANI_U32 temp;
Rajeev79dbe4c2013-10-05 11:03:42 +05301466
Rajeev79dbe4c2013-10-05 11:03:42 +05301467 /*go to space after WLS_BATCHING_SET command*/
1468 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1469 /*no argument after the command*/
1470 if (NULL == inPtr)
1471 {
1472 return -EINVAL;
1473 }
1474
1475 /*no space after the command*/
1476 else if (SPACE_ASCII_VALUE != *inPtr)
1477 {
1478 return -EINVAL;
1479 }
1480
1481 /*removing empty spaces*/
1482 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
1483
1484 /*no argument followed by spaces*/
1485 if ('\0' == *inPtr)
1486 {
1487 return -EINVAL;
1488 }
1489
1490 /*check and parse SCANFREQ*/
1491 if ((strncmp(inPtr, "SCANFREQ", 8) == 0))
1492 {
1493 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001494 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001495
Rajeev Kumarc933d982013-11-18 20:04:20 -08001496 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001497 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001498 nScanFreq = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001499 }
1500
Rajeev79dbe4c2013-10-05 11:03:42 +05301501 if ( (NULL == inPtr) || (TRUE == lastArg))
1502 {
1503 return -EINVAL;
1504 }
1505 }
1506
1507 /*check and parse MSCAN*/
1508 if ((strncmp(inPtr, "MSCAN", 5) == 0))
1509 {
1510 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001511 &nMscan, &lastArg);
1512
1513 if (0 == nMscan)
1514 {
1515 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1516 "invalid MSCAN=%d", nMscan);
1517 return -EINVAL;
1518 }
1519
Rajeev79dbe4c2013-10-05 11:03:42 +05301520 if (TRUE == lastArg)
1521 {
1522 goto done;
1523 }
1524 else if (NULL == inPtr)
1525 {
1526 return -EINVAL;
1527 }
1528 }
1529 else
1530 {
1531 return -EINVAL;
1532 }
1533
1534 /*check and parse BESTN*/
1535 if ((strncmp(inPtr, "BESTN", 5) == 0))
1536 {
1537 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001538 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001539
Rajeev Kumarc933d982013-11-18 20:04:20 -08001540 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001541 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001542 nBestN = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001543 }
1544
Rajeev79dbe4c2013-10-05 11:03:42 +05301545 if (TRUE == lastArg)
1546 {
1547 goto done;
1548 }
1549 else if (NULL == inPtr)
1550 {
1551 return -EINVAL;
1552 }
1553 }
1554
1555 /*check and parse CHANNEL*/
1556 if ((strncmp(inPtr, "CHANNEL", 7) == 0))
1557 {
1558 inPtr = hdd_extract_assigned_char_from_str(inPtr, &val, &lastArg);
Rajeev Kumarc933d982013-11-18 20:04:20 -08001559
Rajeev79dbe4c2013-10-05 11:03:42 +05301560 if (('A' == val) || ('a' == val))
1561 {
c_hpothuebf89732014-02-25 13:00:24 +05301562 ucRfBand = HDD_SET_BATCH_SCAN_5GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301563 }
1564 else if (('B' == val) || ('b' == val))
1565 {
c_hpothuebf89732014-02-25 13:00:24 +05301566 ucRfBand = HDD_SET_BATCH_SCAN_24GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301567 }
1568 else
1569 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001570 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1571 }
1572
1573 if (TRUE == lastArg)
1574 {
1575 goto done;
1576 }
1577 else if (NULL == inPtr)
1578 {
Rajeev79dbe4c2013-10-05 11:03:42 +05301579 return -EINVAL;
1580 }
1581 }
1582
1583 /*check and parse RTT*/
1584 if ((strncmp(inPtr, "RTT", 3) == 0))
1585 {
1586 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001587 &nRtt, &lastArg);
Rajeev79dbe4c2013-10-05 11:03:42 +05301588 if (TRUE == lastArg)
1589 {
1590 goto done;
1591 }
1592 if (NULL == inPtr)
1593 {
1594 return -EINVAL;
1595 }
1596 }
1597
1598
1599done:
1600
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001601 pHddSetBatchScanReq->scanFrequency = nScanFreq;
1602 pHddSetBatchScanReq->numberOfScansToBatch = nMscan;
1603 pHddSetBatchScanReq->bestNetwork = nBestN;
1604 pHddSetBatchScanReq->rfBand = ucRfBand;
1605 pHddSetBatchScanReq->rtt = nRtt;
1606
Rajeev79dbe4c2013-10-05 11:03:42 +05301607 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1608 "Received WLS_BATCHING_SET with SCANFREQ=%d "
1609 "MSCAN=%d BESTN=%d CHANNEL=%d RTT=%d",
1610 pHddSetBatchScanReq->scanFrequency,
1611 pHddSetBatchScanReq->numberOfScansToBatch,
1612 pHddSetBatchScanReq->bestNetwork,
1613 pHddSetBatchScanReq->rfBand,
1614 pHddSetBatchScanReq->rtt);
1615
1616 return 0;
1617}/*End of hdd_parse_set_batchscan_command*/
1618
1619/**---------------------------------------------------------------------------
1620
1621 \brief hdd_set_batch_scan_req_callback () - This function is called after
1622 receiving set batch scan response from FW and it saves set batch scan
1623 response data FW to HDD context and sets the completion event on
1624 which hdd_ioctl is waiting
1625
1626 \param - callbackContext Pointer to HDD adapter
1627 \param - pRsp Pointer to set batch scan response data received from FW
1628
1629 \return - nothing
1630
1631 --------------------------------------------------------------------------*/
1632static void hdd_set_batch_scan_req_callback
1633(
1634 void *callbackContext,
1635 tSirSetBatchScanRsp *pRsp
1636)
1637{
1638 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
1639 tSirSetBatchScanRsp *pHddSetBatchScanRsp;
1640
1641 /*sanity check*/
1642 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
1643 {
1644 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1645 "%s: Invalid pAdapter magic", __func__);
1646 VOS_ASSERT(0);
1647 return;
1648 }
1649 pHddSetBatchScanRsp = &pAdapter->hddSetBatchScanRsp;
1650
1651 /*save set batch scan response*/
1652 pHddSetBatchScanRsp->nScansToBatch = pRsp->nScansToBatch;
1653
1654 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
1655 "Received set batch scan rsp from FW with nScansToBatch=%d",
1656 pHddSetBatchScanRsp->nScansToBatch);
1657
1658 pAdapter->hdd_wait_for_set_batch_scan_rsp = FALSE;
1659 complete(&pAdapter->hdd_set_batch_scan_req_var);
1660
1661 return;
1662}/*End of hdd_set_batch_scan_req_callback*/
1663
1664
1665/**---------------------------------------------------------------------------
1666
1667 \brief hdd_populate_batch_scan_rsp_queue () - This function stores AP meta
1668 info in hdd batch scan response queue
1669
1670 \param - pAdapter Pointer to hdd adapter
1671 \param - pAPMetaInfo Pointer to access point meta info
1672 \param - scanId scan ID of batch scan response
1673 \param - isLastAp tells whether AP is last AP in batch scan response or not
1674
1675 \return - nothing
1676
1677 --------------------------------------------------------------------------*/
1678static void hdd_populate_batch_scan_rsp_queue( hdd_adapter_t* pAdapter,
1679 tpSirBatchScanNetworkInfo pApMetaInfo, tANI_U32 scanId, v_BOOL_t isLastAp)
1680{
1681 tHddBatchScanRsp *pHead;
1682 tHddBatchScanRsp *pNode;
1683 tHddBatchScanRsp *pPrev;
1684 tHddBatchScanRsp *pTemp;
1685 tANI_U8 ssidLen;
1686
1687 /*head of hdd batch scan response queue*/
1688 pHead = pAdapter->pBatchScanRsp;
1689
1690 pNode = (tHddBatchScanRsp *)vos_mem_malloc(sizeof(tHddBatchScanRsp));
1691 if (NULL == pNode)
1692 {
1693 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1694 "%s: Could not allocate memory", __func__);
1695 VOS_ASSERT(0);
1696 return;
1697 }
1698
1699 vos_mem_copy(pNode->ApInfo.bssid, pApMetaInfo->bssid,
1700 sizeof(pNode->ApInfo.bssid));
1701 ssidLen = strlen(pApMetaInfo->ssid);
1702 if (SIR_MAX_SSID_SIZE < ssidLen)
1703 {
1704 /*invalid scan result*/
1705 vos_mem_free(pNode);
1706 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1707 "%s: Invalid AP meta info ssidlen %d", __func__, ssidLen);
1708 return;
1709 }
1710 vos_mem_copy(pNode->ApInfo.ssid, pApMetaInfo->ssid, ssidLen);
1711 /*null terminate ssid*/
1712 pNode->ApInfo.ssid[ssidLen] = '\0';
1713 pNode->ApInfo.ch = pApMetaInfo->ch;
1714 pNode->ApInfo.rssi = pApMetaInfo->rssi;
1715 pNode->ApInfo.age = pApMetaInfo->timestamp;
1716 pNode->ApInfo.batchId = scanId;
1717 pNode->ApInfo.isLastAp = isLastAp;
1718
1719 pNode->pNext = NULL;
1720 if (NULL == pHead)
1721 {
1722 pAdapter->pBatchScanRsp = pNode;
1723 }
1724 else
1725 {
1726 pTemp = pHead;
1727 while (NULL != pTemp)
1728 {
1729 pPrev = pTemp;
1730 pTemp = pTemp->pNext;
1731 }
1732 pPrev->pNext = pNode;
1733 }
1734
1735 return;
1736}/*End of hdd_populate_batch_scan_rsp_queue*/
1737
1738/**---------------------------------------------------------------------------
1739
1740 \brief hdd_batch_scan_result_ind_callback () - This function is called after
1741 receiving batch scan response indication from FW. It saves get batch scan
1742 response data in HDD batch scan response queue. This callback sets the
1743 completion event on which hdd_ioctl is waiting only after getting complete
1744 batch scan response data from FW
1745
1746 \param - callbackContext Pointer to HDD adapter
1747 \param - pRsp Pointer to get batch scan response data received from FW
1748
1749 \return - nothing
1750
1751 --------------------------------------------------------------------------*/
1752static void hdd_batch_scan_result_ind_callback
1753(
1754 void *callbackContext,
1755 void *pRsp
1756)
1757{
1758 v_BOOL_t isLastAp;
1759 tANI_U32 numApMetaInfo;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001760 tANI_U32 numNetworkInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301761 tANI_U32 numberScanList;
1762 tANI_U32 nextScanListOffset;
1763 tANI_U32 nextApMetaInfoOffset;
1764 hdd_adapter_t* pAdapter;
1765 tpSirBatchScanList pScanList;
1766 tpSirBatchScanNetworkInfo pApMetaInfo;
1767 tpSirBatchScanResultIndParam pBatchScanRsp;/*batch scan rsp data from FW*/
1768 tSirSetBatchScanReq *pReq;
1769
1770 pAdapter = (hdd_adapter_t *)callbackContext;
1771 /*sanity check*/
Rajeev Kumar5286bb92013-12-05 11:52:10 -08001772 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
Rajeev79dbe4c2013-10-05 11:03:42 +05301773 {
1774 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1775 "%s: Invalid pAdapter magic", __func__);
1776 VOS_ASSERT(0);
1777 return;
1778 }
1779
1780 /*initialize locals*/
1781 pReq = &pAdapter->hddSetBatchScanReq;
1782 pBatchScanRsp = (tpSirBatchScanResultIndParam)pRsp;
1783 isLastAp = FALSE;
1784 numApMetaInfo = 0;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001785 numNetworkInScanList = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05301786 numberScanList = 0;
1787 nextScanListOffset = 0;
1788 nextApMetaInfoOffset = 0;
1789 pScanList = NULL;
1790 pApMetaInfo = NULL;
1791
1792 if ((NULL == pBatchScanRsp) || (NULL == pReq))
1793 {
1794 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001795 "%s: pBatchScanRsp is %pK pReq %pK", __func__, pBatchScanRsp, pReq);
Rajeev79dbe4c2013-10-05 11:03:42 +05301796 isLastAp = TRUE;
1797 goto done;
1798 }
1799
1800 pAdapter->numScanList = numberScanList = pBatchScanRsp->numScanLists;
1801 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1802 "Batch scan rsp: numberScalList %d", numberScanList);
1803
1804 if ((!numberScanList) || (numberScanList > pReq->numberOfScansToBatch))
1805 {
1806 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1807 "%s: numberScanList %d", __func__, numberScanList);
1808 isLastAp = TRUE;
1809 goto done;
1810 }
1811
1812 while (numberScanList)
1813 {
Rajeev Kumarce651e42013-10-21 18:57:15 -07001814 pScanList = (tpSirBatchScanList)((tANI_U8 *)pBatchScanRsp->scanResults +
Rajeev79dbe4c2013-10-05 11:03:42 +05301815 nextScanListOffset);
1816 if (NULL == pScanList)
1817 {
1818 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001819 "%s: pScanList is %pK", __func__, pScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05301820 isLastAp = TRUE;
1821 goto done;
1822 }
Rajeev Kumarce651e42013-10-21 18:57:15 -07001823 numNetworkInScanList = numApMetaInfo = pScanList->numNetworksInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301824 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumarce651e42013-10-21 18:57:15 -07001825 "Batch scan rsp: numApMetaInfo %d scanId %d",
1826 numApMetaInfo, pScanList->scanId);
Rajeev79dbe4c2013-10-05 11:03:42 +05301827
1828 if ((!numApMetaInfo) || (numApMetaInfo > pReq->bestNetwork))
1829 {
1830 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1831 "%s: numApMetaInfo %d", __func__, numApMetaInfo);
1832 isLastAp = TRUE;
1833 goto done;
1834 }
1835
Rajeev Kumarce651e42013-10-21 18:57:15 -07001836 /*Initialize next AP meta info offset for next scan list*/
1837 nextApMetaInfoOffset = 0;
1838
Rajeev79dbe4c2013-10-05 11:03:42 +05301839 while (numApMetaInfo)
1840 {
1841 pApMetaInfo = (tpSirBatchScanNetworkInfo)(pScanList->scanList +
1842 nextApMetaInfoOffset);
1843 if (NULL == pApMetaInfo)
1844 {
1845 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -07001846 "%s: pApMetaInfo is %pK", __func__, pApMetaInfo);
Rajeev79dbe4c2013-10-05 11:03:42 +05301847 isLastAp = TRUE;
1848 goto done;
1849 }
1850 /*calculate AP age*/
1851 pApMetaInfo->timestamp =
1852 pBatchScanRsp->timestamp - pApMetaInfo->timestamp;
1853
1854 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussaina7c8e412013-11-20 11:06:42 -08001855 "%s: bssId "MAC_ADDRESS_STR
1856 " ch %d rssi %d timestamp %d", __func__,
1857 MAC_ADDR_ARRAY(pApMetaInfo->bssid),
1858 pApMetaInfo->ch, pApMetaInfo->rssi,
1859 pApMetaInfo->timestamp);
Rajeev79dbe4c2013-10-05 11:03:42 +05301860
1861 /*mark last AP in batch scan response*/
1862 if ((TRUE == pBatchScanRsp->isLastResult) &&
1863 (1 == numberScanList) && (1 == numApMetaInfo))
1864 {
1865 isLastAp = TRUE;
1866 }
1867
1868 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1869 /*store batch scan repsonse in hdd queue*/
1870 hdd_populate_batch_scan_rsp_queue(pAdapter, pApMetaInfo,
1871 pScanList->scanId, isLastAp);
1872 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1873
1874 nextApMetaInfoOffset += sizeof(tSirBatchScanNetworkInfo);
1875 numApMetaInfo--;
1876 }
1877
Rajeev Kumarce651e42013-10-21 18:57:15 -07001878 nextScanListOffset += ((sizeof(tSirBatchScanList) - sizeof(tANI_U8))
1879 + (sizeof(tSirBatchScanNetworkInfo)
1880 * numNetworkInScanList));
Rajeev79dbe4c2013-10-05 11:03:42 +05301881 numberScanList--;
1882 }
1883
1884done:
1885
1886 /*notify hdd_ioctl only if complete batch scan rsp is received and it was
1887 requested from hdd_ioctl*/
1888 if ((TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp) &&
1889 (TRUE == isLastAp))
1890 {
1891 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
1892 complete(&pAdapter->hdd_get_batch_scan_req_var);
1893 }
1894
1895 return;
1896}/*End of hdd_batch_scan_result_ind_callback*/
1897
1898/**---------------------------------------------------------------------------
1899
1900 \brief hdd_format_batch_scan_rsp () - This function formats batch scan
1901 response as per batch scan FR request format by putting proper markers
1902
1903 \param - pDest pointer to destination buffer
1904 \param - cur_len current length
1905 \param - tot_len total remaining size which can be written to user space
1906 \param - pApMetaInfo Pointer to get batch scan response AP meta info
1907 \param - pAdapter Pointer to HDD adapter
1908
1909 \return - ret no of characters written
1910
1911 --------------------------------------------------------------------------*/
1912static tANI_U32
1913hdd_format_batch_scan_rsp
1914(
1915 tANI_U8 *pDest,
1916 tANI_U32 cur_len,
1917 tANI_U32 tot_len,
1918 tHddBatchScanRsp *pApMetaInfo,
1919 hdd_adapter_t* pAdapter
1920)
1921{
1922 tANI_U32 ret = 0;
1923 tANI_U32 rem_len = 0;
1924 tANI_U8 temp_len = 0;
1925 tANI_U8 temp_total_len = 0;
1926 tANI_U8 temp[HDD_BATCH_SCAN_AP_META_INFO_SIZE];
1927 tANI_U8 *pTemp = temp;
1928
1929 /*Batch scan reponse needs to be returned to user space in
1930 following format:
1931 "scancount=X\n" where X is the number of scans in current batch
1932 batch
1933 "trunc\n" optional present if current scan truncated
1934 "bssid=XX:XX:XX:XX:XX:XX\n"
1935 "ssid=XXXX\n"
1936 "freq=X\n" frequency in Mhz
1937 "level=XX\n"
1938 "age=X\n" ms
1939 "dist=X\n" cm (-1 if not available)
1940 "errror=X\n" (-1if not available)
1941 "====\n" (end of ap marker)
1942 "####\n" (end of scan marker)
1943 "----\n" (end of results)*/
1944 /*send scan result in above format to user space based on
1945 available length*/
1946 /*The GET response may have more data than the driver can return in its
1947 buffer. In that case the buffer should be filled to the nearest complete
1948 scan, ending with "%%%%".Subsequent callsshould return the remaining data
1949 starting with the next scan (optional .trunc\n., .apcount=X\n., etc).
1950 The final buffer should end with "----\n"*/
1951
1952 /*sanity*/
1953 if (cur_len > tot_len)
1954 {
1955 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1956 "%s: invaid cur_len %d tot_len %d", __func__, cur_len, tot_len);
1957 return 0;
1958 }
1959 else
1960 {
1961 rem_len = (tot_len - cur_len);
1962 }
1963
1964 /*end scan marker*/
1965 if (pApMetaInfo->ApInfo.batchId != pAdapter->prev_batch_id)
1966 {
1967 temp_len = snprintf(pTemp, sizeof(temp), "####\n");
1968 pTemp += temp_len;
1969 temp_total_len += temp_len;
1970 }
1971
1972 /*bssid*/
1973 temp_len = snprintf(pTemp, sizeof(temp),
1974 "bssid=0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n",
1975 pApMetaInfo->ApInfo.bssid[0], pApMetaInfo->ApInfo.bssid[1],
1976 pApMetaInfo->ApInfo.bssid[2], pApMetaInfo->ApInfo.bssid[3],
1977 pApMetaInfo->ApInfo.bssid[4], pApMetaInfo->ApInfo.bssid[5]);
1978 pTemp += temp_len;
1979 temp_total_len += temp_len;
1980
1981 /*ssid*/
1982 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "ssid=%s\n",
1983 pApMetaInfo->ApInfo.ssid);
1984 pTemp += temp_len;
1985 temp_total_len += temp_len;
1986
1987 /*freq*/
1988 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "freq=%d\n",
Rajeev Kumarc40f7512013-11-04 14:13:23 -08001989 sme_ChnToFreq(pApMetaInfo->ApInfo.ch));
Rajeev79dbe4c2013-10-05 11:03:42 +05301990 pTemp += temp_len;
1991 temp_total_len += temp_len;
1992
1993 /*level*/
1994 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "level=%d\n",
1995 pApMetaInfo->ApInfo.rssi);
1996 pTemp += temp_len;
1997 temp_total_len += temp_len;
1998
1999 /*age*/
Jeff Johnson02797792013-10-26 19:17:13 -07002000 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "age=%d\n",
Rajeev79dbe4c2013-10-05 11:03:42 +05302001 pApMetaInfo->ApInfo.age);
2002 pTemp += temp_len;
2003 temp_total_len += temp_len;
2004
2005 /*dist*/
2006 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "dist=-1\n");
2007 pTemp += temp_len;
2008 temp_total_len += temp_len;
2009
2010 /*error*/
2011 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "error=-1\n");
2012 pTemp += temp_len;
2013 temp_total_len += temp_len;
2014
2015 /*end AP marker*/
2016 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "====\n");
2017 pTemp += temp_len;
2018 temp_total_len += temp_len;
2019
2020 /*last AP in batch scan response*/
2021 if(TRUE == pApMetaInfo->ApInfo.isLastAp)
2022 {
2023 /*end scan marker*/
2024 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "####\n");
2025 pTemp += temp_len;
2026 temp_total_len += temp_len;
2027
2028 /*end batch scan result marker*/
2029 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "----\n");
2030 pTemp += temp_len;
2031 temp_total_len += temp_len;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002032
Rajeev79dbe4c2013-10-05 11:03:42 +05302033 }
2034
2035 if (temp_total_len < rem_len)
2036 {
2037 ret = temp_total_len + 1;
2038 strlcpy(pDest, temp, ret);
2039 pAdapter->isTruncated = FALSE;
2040 }
2041 else
2042 {
2043 pAdapter->isTruncated = TRUE;
2044 if (rem_len >= strlen("%%%%"))
2045 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08002046 ret = snprintf(pDest, sizeof(temp), "%%%%");
Rajeev79dbe4c2013-10-05 11:03:42 +05302047 }
Rajeev Kumarc933d982013-11-18 20:04:20 -08002048 else
Rajeev79dbe4c2013-10-05 11:03:42 +05302049 {
2050 ret = 0;
2051 }
2052 }
2053
2054 return ret;
2055
2056}/*End of hdd_format_batch_scan_rsp*/
2057
2058/**---------------------------------------------------------------------------
2059
2060 \brief hdd_populate_user_batch_scan_rsp() - This function populates user data
2061 buffer starting with head of hdd batch scan response queue
2062
2063 \param - pAdapter Pointer to HDD adapter
2064 \param - pDest Pointer to user data buffer
2065 \param - cur_len current offset in user buffer
2066 \param - rem_len remaining no of bytes in user buffer
2067
2068 \return - number of bytes written in user buffer
2069
2070 --------------------------------------------------------------------------*/
2071
2072tANI_U32 hdd_populate_user_batch_scan_rsp
2073(
2074 hdd_adapter_t* pAdapter,
2075 tANI_U8 *pDest,
2076 tANI_U32 cur_len,
2077 tANI_U32 rem_len
2078)
2079{
2080 tHddBatchScanRsp *pHead;
2081 tHddBatchScanRsp *pPrev;
2082 tANI_U32 len;
2083
Rajeev79dbe4c2013-10-05 11:03:42 +05302084 pAdapter->isTruncated = FALSE;
2085
2086 /*head of hdd batch scan response queue*/
2087 pHead = pAdapter->pBatchScanRsp;
2088 while (pHead)
2089 {
2090 len = hdd_format_batch_scan_rsp(pDest, cur_len, rem_len, pHead,
2091 pAdapter);
2092 pDest += len;
Rajeev Kumar292d2bb2013-10-23 15:01:44 -07002093 pDest--;
Rajeev79dbe4c2013-10-05 11:03:42 +05302094 cur_len += len;
2095 if(TRUE == pAdapter->isTruncated)
2096 {
2097 /*result is truncated return rest of scan rsp in next req*/
2098 cur_len = rem_len;
2099 break;
2100 }
2101 pPrev = pHead;
2102 pHead = pHead->pNext;
2103 pAdapter->pBatchScanRsp = pHead;
Rajeev Kumarbe17d8b2014-01-10 15:39:45 -08002104 if (TRUE == pPrev->ApInfo.isLastAp)
2105 {
2106 pAdapter->prev_batch_id = 0;
2107 }
2108 else
2109 {
2110 pAdapter->prev_batch_id = pPrev->ApInfo.batchId;
2111 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302112 vos_mem_free(pPrev);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002113 pPrev = NULL;
Rajeev79dbe4c2013-10-05 11:03:42 +05302114 }
2115
2116 return cur_len;
2117}/*End of hdd_populate_user_batch_scan_rsp*/
2118
2119/**---------------------------------------------------------------------------
2120
2121 \brief hdd_return_batch_scan_rsp_to_user () - This function returns batch
2122 scan response data from HDD queue to user space
2123 It does following in detail:
2124 a) if HDD has enough data in its queue then it 1st copies data to user
2125 space and then send get batch scan indication message to FW. In this
2126 case it does not wait on any event and batch scan response data will
2127 be populated in HDD response queue in MC thread context after receiving
2128 indication from FW
2129 b) else send get batch scan indication message to FW and wait on an event
2130 which will be set once HDD receives complete batch scan response from
2131 FW and then this function returns batch scan response to user space
2132
2133 \param - pAdapter Pointer to HDD adapter
2134 \param - pPrivData Pointer to priv_data
2135
2136 \return - 0 for success -EFAULT for failure
2137
2138 --------------------------------------------------------------------------*/
2139
2140int hdd_return_batch_scan_rsp_to_user
2141(
2142 hdd_adapter_t* pAdapter,
2143 hdd_priv_data_t *pPrivData,
2144 tANI_U8 *command
2145)
2146{
2147 tANI_U8 *pDest;
2148 tANI_U32 count = 0;
2149 tANI_U32 len = 0;
2150 tANI_U32 cur_len = 0;
2151 tANI_U32 rem_len = 0;
2152 eHalStatus halStatus;
2153 unsigned long rc;
2154 tSirTriggerBatchScanResultInd *pReq;
2155
2156 pReq = &pAdapter->hddTriggerBatchScanResultInd;
2157 pReq->param = 0;/*batch scan client*/
2158 pDest = (tANI_U8 *)(command + pPrivData->used_len);
2159 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
2160
2161 cur_len = pPrivData->used_len;
2162 if (pPrivData->total_len > pPrivData->used_len)
2163 {
2164 rem_len = pPrivData->total_len - pPrivData->used_len;
2165 }
2166 else
2167 {
2168 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2169 "%s: Invalid user data buffer total_len %d used_len %d",
2170 __func__, pPrivData->total_len, pPrivData->used_len);
2171 return -EFAULT;
2172 }
2173
2174 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2175 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2176 cur_len, rem_len);
2177 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2178
2179 /*enough scan result available in cache to return to user space or
2180 scan result needs to be fetched 1st from fw and then return*/
Rajeev Kumar99db6262013-11-11 15:23:36 -08002181 if (len == cur_len)
Rajeev79dbe4c2013-10-05 11:03:42 +05302182 {
2183 pAdapter->hdd_wait_for_get_batch_scan_rsp = TRUE;
2184 halStatus = sme_TriggerBatchScanResultInd(
2185 WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2186 pAdapter->sessionId, hdd_batch_scan_result_ind_callback,
2187 pAdapter);
2188 if ( eHAL_STATUS_SUCCESS == halStatus )
2189 {
2190 if (TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp)
2191 {
2192 INIT_COMPLETION(pAdapter->hdd_get_batch_scan_req_var);
2193 rc = wait_for_completion_timeout(
2194 &pAdapter->hdd_get_batch_scan_req_var,
2195 msecs_to_jiffies(HDD_GET_BATCH_SCAN_RSP_TIME_OUT));
Abhishek Singh00b71972016-01-07 10:51:04 +05302196 if (0 >= rc)
Rajeev79dbe4c2013-10-05 11:03:42 +05302197 {
2198 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Abhishek Singh00b71972016-01-07 10:51:04 +05302199 "%s: wait on hdd_get_batch_scan_req_var failed %ld",
2200 __func__, rc);
Rajeev79dbe4c2013-10-05 11:03:42 +05302201 return -EFAULT;
2202 }
2203 }
2204
2205 len = snprintf(pDest, HDD_BATCH_SCAN_AP_META_INFO_SIZE,
Jeff Johnson02797792013-10-26 19:17:13 -07002206 "scancount=%u\n", pAdapter->numScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05302207 pDest += len;
2208 cur_len += len;
2209
2210 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2211 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2212 cur_len, rem_len);
2213 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2214
2215 count = 0;
2216 len = (len - pPrivData->used_len);
2217 pDest = (command + pPrivData->used_len);
2218 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002219 "NEW BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302220 while(count < len)
2221 {
2222 printk("%c", *(pDest + count));
2223 count++;
2224 }
2225 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2226 "%s: copy %d data to user buffer", __func__, len);
2227 if (copy_to_user(pPrivData->buf, pDest, len))
2228 {
2229 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2230 "%s: failed to copy data to user buffer", __func__);
2231 return -EFAULT;
2232 }
2233 }
2234 else
2235 {
2236 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2237 "sme_GetBatchScanScan returned failure halStatus %d",
2238 halStatus);
2239 return -EINVAL;
2240 }
2241 }
2242 else
2243 {
Rajeev79dbe4c2013-10-05 11:03:42 +05302244 count = 0;
2245 len = (len - pPrivData->used_len);
2246 pDest = (command + pPrivData->used_len);
2247 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002248 "REMAINING TRUNCATED BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302249 while(count < len)
2250 {
2251 printk("%c", *(pDest + count));
2252 count++;
2253 }
Rajeev Kumar99db6262013-11-11 15:23:36 -08002254 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2255 "%s: copy %d data to user buffer", __func__, len);
Rajeev79dbe4c2013-10-05 11:03:42 +05302256 if (copy_to_user(pPrivData->buf, pDest, len))
2257 {
2258 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2259 "%s: failed to copy data to user buffer", __func__);
2260 return -EFAULT;
2261 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302262 }
2263
2264 return 0;
2265} /*End of hdd_return_batch_scan_rsp_to_user*/
2266
Rajeev Kumar8b373292014-01-08 20:36:55 -08002267/**---------------------------------------------------------------------------
2268
2269 \brief hdd_handle_batch_scan_ioctl () - This function handles WLS_BATCHING
2270 IOCTLs from user space. Following BATCH SCAN DEV IOCTs are handled:
2271 WLS_BATCHING VERSION
2272 WLS_BATCHING SET
2273 WLS_BATCHING GET
2274 WLS_BATCHING STOP
2275
2276 \param - pAdapter Pointer to HDD adapter
2277 \param - pPrivdata Pointer to priv_data
2278 \param - command Pointer to command
2279
2280 \return - 0 for success -EFAULT for failure
2281
2282 --------------------------------------------------------------------------*/
2283
2284int hdd_handle_batch_scan_ioctl
2285(
2286 hdd_adapter_t *pAdapter,
2287 hdd_priv_data_t *pPrivdata,
2288 tANI_U8 *command
2289)
2290{
2291 int ret = 0;
Yue Mae36e3552014-03-05 17:06:20 -08002292 hdd_context_t *pHddCtx;
2293
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302294 ENTER();
2295
Yue Mae36e3552014-03-05 17:06:20 -08002296 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2297 ret = wlan_hdd_validate_context(pHddCtx);
2298 if (ret)
2299 {
Yue Mae36e3552014-03-05 17:06:20 -08002300 goto exit;
2301 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002302
2303 if (strncmp(command, "WLS_BATCHING VERSION", 20) == 0)
2304 {
2305 char extra[32];
2306 tANI_U8 len = 0;
2307 tANI_U8 version = HDD_BATCH_SCAN_VERSION;
2308
2309 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2310 {
2311 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2312 "%s: Batch scan feature is not supported by FW", __func__);
2313 ret = -EINVAL;
2314 goto exit;
2315 }
2316
2317 len = scnprintf(extra, sizeof(extra), "WLS_BATCHING_VERSION %d",
2318 version);
2319 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2320 {
2321 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2322 "%s: failed to copy data to user buffer", __func__);
2323 ret = -EFAULT;
2324 goto exit;
2325 }
2326 ret = HDD_BATCH_SCAN_VERSION;
2327 }
2328 else if (strncmp(command, "WLS_BATCHING SET", 16) == 0)
2329 {
2330 int status;
2331 tANI_U8 *value = (command + 16);
2332 eHalStatus halStatus;
2333 unsigned long rc;
2334 tSirSetBatchScanReq *pReq = &pAdapter->hddSetBatchScanReq;
2335 tSirSetBatchScanRsp *pRsp = &pAdapter->hddSetBatchScanRsp;
2336
2337 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2338 {
2339 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2340 "%s: Batch scan feature is not supported by FW", __func__);
2341 ret = -EINVAL;
2342 goto exit;
2343 }
2344
2345 if ((WLAN_HDD_INFRA_STATION != pAdapter->device_mode) &&
2346 (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) &&
2347 (WLAN_HDD_P2P_GO != pAdapter->device_mode) &&
2348 (WLAN_HDD_P2P_DEVICE != pAdapter->device_mode))
2349 {
2350 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302351 "Received WLS_BATCHING SET command in invalid mode %s (%d) "
Rajeev Kumar8b373292014-01-08 20:36:55 -08002352 "WLS_BATCHING_SET is only allowed in infra STA/P2P client mode",
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302353 hdd_device_modetoString(pAdapter->device_mode),
2354 pAdapter->device_mode);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002355 ret = -EINVAL;
2356 goto exit;
2357 }
2358
2359 status = hdd_parse_set_batchscan_command(value, pReq);
2360 if (status)
2361 {
2362 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2363 "Invalid WLS_BATCHING SET command");
2364 ret = -EINVAL;
2365 goto exit;
2366 }
2367
2368
2369 pAdapter->hdd_wait_for_set_batch_scan_rsp = TRUE;
2370 halStatus = sme_SetBatchScanReq(WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2371 pAdapter->sessionId, hdd_set_batch_scan_req_callback,
2372 pAdapter);
2373
2374 if ( eHAL_STATUS_SUCCESS == halStatus )
2375 {
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302376 char extra[32];
2377 tANI_U8 len = 0;
2378 tANI_U8 mScan = 0;
2379
Rajeev Kumar8b373292014-01-08 20:36:55 -08002380 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2381 "sme_SetBatchScanReq returned success halStatus %d",
2382 halStatus);
2383 if (TRUE == pAdapter->hdd_wait_for_set_batch_scan_rsp)
2384 {
2385 INIT_COMPLETION(pAdapter->hdd_set_batch_scan_req_var);
2386 rc = wait_for_completion_timeout(
2387 &pAdapter->hdd_set_batch_scan_req_var,
2388 msecs_to_jiffies(HDD_SET_BATCH_SCAN_REQ_TIME_OUT));
2389 if (0 == rc)
2390 {
2391 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2392 "%s: Timeout waiting for set batch scan to complete",
2393 __func__);
2394 ret = -EINVAL;
2395 goto exit;
2396 }
2397 }
2398 if ( !pRsp->nScansToBatch )
2399 {
2400 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2401 "%s: Received set batch scan failure response from FW",
2402 __func__);
2403 ret = -EINVAL;
2404 goto exit;
2405 }
2406 /*As per the Batch Scan Framework API we should return the MIN of
2407 either MSCAN or the max # of scans firmware can cache*/
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302408 mScan = MIN(pReq->numberOfScansToBatch , pRsp->nScansToBatch);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002409
2410 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STARTED;
2411
2412 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2413 "%s: request MSCAN %d response MSCAN %d ret %d",
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302414 __func__, pReq->numberOfScansToBatch, pRsp->nScansToBatch, mScan);
2415 len = scnprintf(extra, sizeof(extra), "%d", mScan);
2416 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2417 {
2418 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2419 "%s: failed to copy MSCAN value to user buffer", __func__);
2420 ret = -EFAULT;
2421 goto exit;
2422 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002423 }
2424 else
2425 {
2426 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2427 "sme_SetBatchScanReq returned failure halStatus %d",
2428 halStatus);
2429 ret = -EINVAL;
2430 goto exit;
2431 }
2432 }
2433 else if (strncmp(command, "WLS_BATCHING STOP", 17) == 0)
2434 {
2435 eHalStatus halStatus;
2436 tSirStopBatchScanInd *pInd = &pAdapter->hddStopBatchScanInd;
2437 pInd->param = 0;
2438
2439 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2440 {
2441 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2442 "%s: Batch scan feature is not supported by FW", __func__);
2443 ret = -EINVAL;
2444 goto exit;
2445 }
2446
2447 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2448 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302449 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002450 "Batch scan is not yet enabled batch scan state %d",
2451 pAdapter->batchScanState);
2452 ret = -EINVAL;
2453 goto exit;
2454 }
2455
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002456 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2457 hdd_deinit_batch_scan(pAdapter);
2458 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2459
Rajeev Kumar8b373292014-01-08 20:36:55 -08002460 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
2461
2462 halStatus = sme_StopBatchScanInd(WLAN_HDD_GET_HAL_CTX(pAdapter), pInd,
2463 pAdapter->sessionId);
2464 if ( eHAL_STATUS_SUCCESS == halStatus )
2465 {
2466 ret = 0;
2467 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2468 "sme_StopBatchScanInd returned success halStatus %d",
2469 halStatus);
2470 }
2471 else
2472 {
2473 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2474 "sme_StopBatchScanInd returned failure halStatus %d",
2475 halStatus);
2476 ret = -EINVAL;
2477 goto exit;
2478 }
2479 }
2480 else if (strncmp(command, "WLS_BATCHING GET", 16) == 0)
2481 {
2482 tANI_U32 remain_len;
2483
2484 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2485 {
2486 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2487 "%s: Batch scan feature is not supported by FW", __func__);
2488 ret = -EINVAL;
2489 goto exit;
2490 }
2491
2492 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2493 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302494 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002495 "Batch scan is not yet enabled could not return results"
2496 "Batch Scan state %d",
2497 pAdapter->batchScanState);
2498 ret = -EINVAL;
2499 goto exit;
2500 }
2501
2502 pPrivdata->used_len = 16;
2503 remain_len = pPrivdata->total_len - pPrivdata->used_len;
2504 if (remain_len < pPrivdata->total_len)
2505 {
2506 /*Clear previous batch scan response data if any*/
2507 vos_mem_zero((tANI_U8 *)(command + pPrivdata->used_len), remain_len);
2508 }
2509 else
2510 {
2511 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2512 "Invalid total length from user space can't fetch batch"
2513 " scan response total_len %d used_len %d remain len %d",
2514 pPrivdata->total_len, pPrivdata->used_len, remain_len);
2515 ret = -EINVAL;
2516 goto exit;
2517 }
2518 ret = hdd_return_batch_scan_rsp_to_user(pAdapter, pPrivdata, command);
2519 }
2520
2521exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302522 EXIT();
Rajeev Kumar8b373292014-01-08 20:36:55 -08002523 return ret;
2524}
2525
2526
Rajeev79dbe4c2013-10-05 11:03:42 +05302527#endif/*End of FEATURE_WLAN_BATCH_SCAN*/
2528
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302529#if defined(WLAN_FEATURE_VOWIFI_11R) || defined(FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
2530/**
2531 * hdd_assign_handoff_src_reassoc - Set handoff source as REASSOC
2532 * to Handoff request
2533 * @handoffInfo: Pointer to Handoff request
2534 * @src: enum of handoff_src
2535 * Return: None
2536 */
2537#ifndef QCA_WIFI_ISOC
2538static inline void hdd_assign_handoff_src_reassoc(tCsrHandoffRequest
2539 *handoffInfo, handoff_src src)
2540{
2541 handoffInfo->src = src;
2542}
2543#else
2544static inline void hdd_assign_handoff_src_reassoc(tCsrHandoffRequest
2545 *handoffInfo, handoff_src src)
2546{
2547}
2548#endif
2549
2550/**
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302551 * hdd_reassoc() - perform a user space-directed reassoc
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302552 *
2553 * @pAdapter: Adapter upon which the command was received
2554 * @bssid: BSSID with which to reassociate
2555 * @channel: channel upon which to reassociate
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302556 * @src: The source for the trigger of this action
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302557 *
2558 * Return: 0 for success non-zero for failure
2559 */
2560#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Selvaraj, Sridhar8ecb4192016-06-23 17:50:49 +05302561int hdd_reassoc(hdd_adapter_t *pAdapter, const tANI_U8 *bssid,
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302562 const tANI_U8 channel, const handoff_src src)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302563{
2564 hdd_station_ctx_t *pHddStaCtx;
2565 tCsrHandoffRequest handoffInfo;
2566 hdd_context_t *pHddCtx = NULL;
2567 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2568
2569 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2570
2571 /* if not associated, no need to proceed with reassoc */
2572 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
2573 hddLog(LOG1, FL("Not associated"));
2574 return -EINVAL;
2575 }
2576
2577 /* if the target bssid is same as currently associated AP,
2578 then no need to proceed with reassoc */
2579 if (!memcmp(bssid, pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr))) {
2580 hddLog(LOG1, FL("Reassoc BSSID is same as currently associated AP bssid"));
2581 return -EINVAL;
2582 }
2583
2584 /* Check channel number is a valid channel number */
2585 if (VOS_STATUS_SUCCESS !=
2586 wlan_hdd_validate_operation_channel(pAdapter, channel)) {
2587 hddLog(LOGE, FL("Invalid Channel %d"), channel);
2588 return -EINVAL;
2589 }
2590
2591 /* Proceed with reassoc */
2592 handoffInfo.channel = channel;
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302593 hdd_assign_handoff_src_reassoc(&handoffInfo, src);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302594 memcpy(handoffInfo.bssid, bssid, sizeof(tSirMacAddr));
2595 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
2596 return 0;
2597}
2598#else
Selvaraj, Sridhar8ecb4192016-06-23 17:50:49 +05302599int hdd_reassoc(hdd_adapter_t *pAdapter, const tANI_U8 *bssid,
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302600 const tANI_U8 channel, const handoff_src src)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302601{
2602 return -EPERM;
2603}
2604#endif
2605
2606/**
2607 * hdd_parse_reassoc_v1() - parse version 1 of the REASSOC command
2608 * This function parses the v1 REASSOC command with the format
2609 * REASSOC xx:xx:xx:xx:xx:xx CH where "xx:xx:xx:xx:xx:xx" is the
2610 * Hex-ASCII representation of the BSSID and CH is the ASCII
2611 * representation of the channel. For example
2612 * REASSOC 00:0a:0b:11:22:33 48
2613 *
2614 * @pAdapter: Adapter upon which the command was received
2615 * @command: ASCII text command that was received
2616 *
2617 * Return: 0 for success non-zero for failure
2618 */
2619static int
2620hdd_parse_reassoc_v1(hdd_adapter_t *pAdapter, const char *command)
2621{
2622 tANI_U8 channel = 0;
2623 tSirMacAddr bssid;
2624 int ret;
2625
2626 ret = hdd_parse_reassoc_command_v1_data(command, bssid, &channel);
2627 if (ret)
2628 hddLog(LOGE, FL("Failed to parse reassoc command data"));
2629 else
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302630 ret = hdd_reassoc(pAdapter, bssid, channel, REASSOC);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302631
2632 return ret;
2633}
2634
2635/**
2636 * hdd_parse_reassoc_v2() - parse version 2 of the REASSOC command
2637 * This function parses the v2 REASSOC command with the format
2638 * REASSOC <android_wifi_reassoc_params>
2639 *
2640 * @pAdapter: Adapter upon which the command was received
2641 * @command: command that was received, ASCII command followed
2642 * by binary data
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302643 * @total_len: Total length of the command received
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302644 *
2645 * Return: 0 for success non-zero for failure
2646 */
2647static int
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302648hdd_parse_reassoc_v2(hdd_adapter_t *pAdapter, const char *command,
2649 int total_len)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302650{
2651 struct android_wifi_reassoc_params params;
2652 tSirMacAddr bssid;
2653 int ret;
2654
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302655 if (total_len < sizeof(params) + 8) {
2656 hddLog(LOGE, FL("Invalid command length"));
2657 return -EINVAL;
2658 }
2659
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302660 /* The params are located after "REASSOC " */
2661 memcpy(&params, command + 8, sizeof(params));
2662
2663 if (!mac_pton(params.bssid, (u8 *)&bssid)) {
2664 hddLog(LOGE, FL("MAC address parsing failed"));
2665 ret = -EINVAL;
2666 } else {
Selvaraj, Sridhar4fa15232016-06-18 12:27:25 +05302667 ret = hdd_reassoc(pAdapter, bssid, params.channel, REASSOC);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302668 }
2669 return ret;
2670}
2671
2672/**
2673 * hdd_parse_reassoc() - parse the REASSOC command
2674 * There are two different versions of the REASSOC command.Version 1
2675 * of the command contains a parameter list that is ASCII characters
2676 * whereas version 2 contains a combination of ASCII and binary
2677 * payload. Determine if a version 1 or a version 2 command is being
2678 * parsed by examining the parameters, and then dispatch the parser
2679 * that is appropriate for the command.
2680 *
2681 * @pAdapter: Adapter upon which the command was received
2682 * @command: command that was received
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302683 * @total_len: Total length of the command received
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302684 *
2685 * Return: 0 for success non-zero for failure
2686 */
2687static int
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302688hdd_parse_reassoc(hdd_adapter_t *pAdapter, const char *command, int total_len)
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302689{
2690 int ret;
2691
2692 /*
2693 * both versions start with "REASSOC"
2694 * v1 has a bssid and channel # as an ASCII string
2695 * REASSOC xx:xx:xx:xx:xx:xx CH
2696 * v2 has a C struct
2697 * REASSOC <binary c struct>
2698 *
2699 * The first field in the v2 struct is also the bssid in ASCII.
2700 * But in the case of a v2 message the BSSID is NUL-terminated.
2701 * Hence we can peek at that offset to see if this is V1 or V2
2702 * REASSOC xx:xx:xx:xx:xx:xx*
2703 * 1111111111222222
2704 * 01234567890123456789012345
2705 */
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302706
2707 if (total_len < 26) {
2708 hddLog(LOGE, FL("Invalid command (total_len=%d)"), total_len);
2709 return -EINVAL;
2710 }
2711
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302712 if (command[25])
2713 ret = hdd_parse_reassoc_v1(pAdapter, command);
2714 else
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302715 ret = hdd_parse_reassoc_v2(pAdapter, command, total_len);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05302716
2717 return ret;
2718}
2719#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE FEATURE_WLAN_LFR */
2720
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302721struct bcn_miss_rate_priv {
2722 int bcn_miss_rate;
2723};
2724
2725/**
2726 * get_bcn_miss_rate_cb() callback invoked on receiving beacon miss
2727 * rate from firmware
2728 * @status: Status of get beacon miss rate operation
2729 * @bcnMissRate: Beacon miss rate
2730 * @context: Context passed while registering callback
2731 *
2732 * This function is invoked by WDA layer on receiving
2733 * WDI_GET_BCN_MISS_RATE_RSP
2734 *
2735 * Return: None
2736 */
2737static void get_bcn_miss_rate_cb(VOS_STATUS status, int bcnMissRate,
2738 void *context)
c_hpothu92367912014-05-01 15:18:17 +05302739{
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302740 struct hdd_request *request;
2741 struct bcn_miss_rate_priv *priv;
c_hpothu39eb1e32014-06-26 16:31:50 +05302742
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302743 request = hdd_request_get(context);
2744 if (!request) {
2745 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
2746 return;
2747 }
c_hpothu92367912014-05-01 15:18:17 +05302748
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302749 priv = hdd_request_priv(request);
c_hpothu92367912014-05-01 15:18:17 +05302750
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302751 if (VOS_STATUS_SUCCESS == status)
2752 priv->bcn_miss_rate = bcnMissRate;
2753 else
2754 hddLog(VOS_TRACE_LEVEL_ERROR, FL("failed to get bcnMissRate"));
c_hpothu92367912014-05-01 15:18:17 +05302755
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302756 hdd_request_complete(request);
2757 hdd_request_put(request);
Hanumanth Reddy Pothulad0d3c172018-05-02 18:53:05 +05302758
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302759 return;
c_hpothu92367912014-05-01 15:18:17 +05302760}
2761
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302762struct fw_stats_priv {
2763 tSirFwStatsResult *fw_stats;
2764};
2765
2766/**
2767 * hdd_fw_stats_cb() callback invoked on receiving firmware stats
2768 * from firmware
2769 * @status: Status of get firmware stats operation
2770 * @fwStatsResult: firmware stats
2771 * @context: Context passed while registering callback
2772 *
2773 * This function is invoked by WDA layer on receiving
2774 * WDI_GET_FW_STATS_RSP
2775 *
2776 * Return: None
2777 */
2778static void hdd_fw_stats_cb(VOS_STATUS status,
2779 tSirFwStatsResult *fwStatsResult, void *context)
Satyanarayana Dash72806012014-12-02 14:30:08 +05302780{
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302781 struct hdd_request *request;
2782 struct fw_stats_priv *priv;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302783
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302784 hddLog(VOS_TRACE_LEVEL_INFO, FL("with status = %d"),status);
Satyanarayana Dash72806012014-12-02 14:30:08 +05302785
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05302786 request = hdd_request_get(context);
2787 if (!request) {
2788 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
2789 return;
2790 }
2791 priv = hdd_request_priv(request);
2792
2793 if (VOS_STATUS_SUCCESS == status)
2794 *priv->fw_stats = *fwStatsResult;
2795 else
2796 priv->fw_stats = NULL;
2797
2798 hdd_request_complete(request);
2799 hdd_request_put(request);
2800 return;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302801}
2802
jge35567202017-06-21 16:39:38 +08002803/*
2804 *hdd_parse_setmaxtxpower_command() - HDD Parse MAXTXPOWER command
2805 *@pValue Pointer to MAXTXPOWER command
2806 *@pTxPower Pointer to tx power
2807 *
2808 *This function parses the MAXTXPOWER command passed in the format
2809 * MAXTXPOWER<space>X(Tx power in dbm)
2810 * For example input commands:
2811 * 1) MAXTXPOWER -8 -> This is translated into set max TX power to -8 dbm
2812 * 2) MAXTXPOWER -23 -> This is translated into set max TX power to -23 dbm
2813 *
2814 *return - 0 for success non-zero for failure
2815 */
2816static int hdd_parse_setmaxtxpower_command(unsigned char *pValue, int *pTxPower)
2817{
2818 unsigned char *inPtr = pValue;
2819 int tempInt;
2820 int v = 0;
2821 *pTxPower = 0;
2822
2823 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
2824 /* no argument after the command */
2825 if (NULL == inPtr)
2826 return -EINVAL;
2827 /* no space after the command */
2828 else if (SPACE_ASCII_VALUE != *inPtr)
2829 return -EINVAL;
2830
2831 /* removing empty spaces */
2832 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
2833
2834 /* no argument followed by spaces */
2835 if ('\0' == *inPtr)
2836 return 0;
2837
2838 v = kstrtos32(inPtr, 10, &tempInt);
2839
2840 /* Range checking for passed parameter */
2841 if ((tempInt < HDD_MIN_TX_POWER) || (tempInt > HDD_MAX_TX_POWER))
2842 return -EINVAL;
2843
2844 *pTxPower = tempInt;
2845
2846 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2847 "SETMAXTXPOWER: %d", *pTxPower);
2848
2849 return 0;
2850}
2851
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302852static int hdd_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command, char *extra, tANI_U8 n, tANI_U8 *len)
2853{
2854 int ret = 0;
2855
2856 if (!pCfg || !command || !extra || !len)
2857 {
2858 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2859 "%s: argument passsed for GETDWELLTIME is incorrect", __func__);
2860 ret = -EINVAL;
2861 return ret;
2862 }
2863
2864 if (strncmp(command, "GETDWELLTIME ACTIVE MAX", 23) == 0)
2865 {
2866 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MAX %u\n",
2867 (int)pCfg->nActiveMaxChnTime);
2868 return ret;
2869 }
2870 else if (strncmp(command, "GETDWELLTIME ACTIVE MIN", 23) == 0)
2871 {
2872 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MIN %u\n",
2873 (int)pCfg->nActiveMinChnTime);
2874 return ret;
2875 }
2876 else if (strncmp(command, "GETDWELLTIME PASSIVE MAX", 24) == 0)
2877 {
2878 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MAX %u\n",
2879 (int)pCfg->nPassiveMaxChnTime);
2880 return ret;
2881 }
2882 else if (strncmp(command, "GETDWELLTIME PASSIVE MIN", 24) == 0)
2883 {
2884 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MIN %u\n",
2885 (int)pCfg->nPassiveMinChnTime);
2886 return ret;
2887 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302888 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
2889 {
2890 *len = scnprintf(extra, n, "GETDWELLTIME %u \n",
2891 (int)pCfg->nActiveMaxChnTime);
2892 return ret;
2893 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302894 else
2895 {
2896 ret = -EINVAL;
2897 }
2898
2899 return ret;
2900}
2901
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05302902/**
2903 * hdd_btc_get_dwell_time() - Get BTC dwell time parameters
2904 * @pCfg: Pointer to HDD context
2905 * @command: ASCII text command that is received
2906 * @extra: Pointer to copy data sent to user
2907 * @n: size of 'extra' buffer
2908 * @len: length copied to 'extra' buffer
2909 *
2910 * Driver commands:
2911 * wpa_cli DRIVER BTCGETDWELLTIME ESCO MAX
2912 * wpa_cli DRIVER BTCGETDWELLTIME ESCO MIN
2913 * wpa_cli DRIVER BTCGETDWELLTIME SCO MAX
2914 * wpa_cli DRIVER BTCGETDWELLTIME SCO MIN
2915 *
2916 * Return: 0 for success non-zero for failure
2917 */
2918
2919static int hdd_btc_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command,
2920 char *extra, tANI_U8 n, tANI_U8 *len)
2921{
2922 int ret = 0;
2923
2924 if (!pCfg || !command || !extra || !len)
2925 {
2926 hddLog(LOGE, FL("Argument passsed for BTCGETDWELLTIME is incorrect"));
2927 ret = -EINVAL;
2928 return ret;
2929 }
2930
2931 if (strncmp(command, "BTCGETDWELLTIME ESCO MAX", 24) == 0)
2932 {
2933 *len = scnprintf(extra, n, "BTCGETDWELLTIME ESCO MAX %u\n",
2934 (int)pCfg->max_chntime_btc_esco);
2935 return ret;
2936 }
2937 else if (strncmp(command, "BTCGETDWELLTIME ESCO MIN", 24) == 0)
2938 {
2939 *len = scnprintf(extra, n, "BTCGETDWELLTIME ESCO MIN %u\n",
2940 (int)pCfg->min_chntime_btc_esco);
2941 return ret;
2942 }
2943 else if (strncmp(command, "BTCGETDWELLTIME SCO MAX", 23) == 0)
2944 {
2945 *len = scnprintf(extra, n, "BTCGETDWELLTIME SCO MAX %u\n",
2946 (int)pCfg->max_chntime_btc_sco);
2947 return ret;
2948 }
2949 else if (strncmp(command, "BTCGETDWELLTIME SCO MIN", 23) == 0)
2950 {
2951 *len = scnprintf(extra, n, "BTCGETDWELLTIME SCO MIN %u\n",
2952 (int)pCfg->min_chntime_btc_sco);
2953 return ret;
2954 }
2955 else
2956 {
2957 ret = -EINVAL;
2958 }
2959
2960 return ret;
2961}
2962
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05302963int hdd_drv_cmd_validate(tANI_U8 *command, int len)
2964{
2965 if (command[len] != ' ')
2966 return -EINVAL;
2967
2968 return 0;
2969}
2970
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05302971#ifdef WLAN_AP_STA_CONCURRENCY
2972
2973/**
2974 * hdd_conc_get_dwell_time() - Get concurrency dwell time parameters
2975 * @pCfg: Pointer to HDD context
2976 * @command: ASCII text command that is received
2977 * @extra: Pointer to copy data sent to user
2978 * @n: size of 'extra' buffer
2979 * @len: length copied to 'extra' buffer
2980 *
2981 * Driver commands:
2982 * wpa_cli DRIVER CONCGETDWELLTIME ACTIVE MAX
2983 * wpa_cli DRIVER CONCGETDWELLTIME ACTIVE MIN
2984 * wpa_cli DRIVER CONCGETDWELLTIME PASSIVE MAX
2985 * wpa_cli DRIVER CONCGETDWELLTIME PASSIVE MIN
2986 *
2987 * Return: 0 for success non-zero for failure
2988 */
2989
2990static int hdd_conc_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command,
2991 char *extra, tANI_U8 n, tANI_U8 *len)
2992{
2993 int ret = 0;
2994
2995 if (!pCfg || !command || !extra || !len)
2996 {
2997 hddLog(LOGE, FL("Argument passsed for CONCGETDWELLTIME is incorrect"));
2998 ret = -EINVAL;
2999 return ret;
3000 }
3001
3002 if (strncmp(command, "CONCGETDWELLTIME ACTIVE MAX", 27) == 0)
3003 {
3004 *len = scnprintf(extra, n, "CONCGETDWELLTIME ACTIVE MAX %u\n",
3005 (int)pCfg->nActiveMaxChnTimeConc);
3006 return ret;
3007 }
3008 else if (strncmp(command, "CONCGETDWELLTIME ACTIVE MIN", 27) == 0)
3009 {
3010 *len = scnprintf(extra, n, "CONCGETDWELLTIME ACTIVE MIN %u\n",
3011 (int)pCfg->nActiveMinChnTimeConc);
3012 return ret;
3013 }
3014 else if (strncmp(command, "CONCGETDWELLTIME PASSIVE MAX", 28) == 0)
3015 {
3016 *len = scnprintf(extra, n, "CONCGETDWELLTIME PASSIVE MAX %u\n",
3017 (int)pCfg->nPassiveMaxChnTimeConc);
3018 return ret;
3019 }
3020 else if (strncmp(command, "CONCGETDWELLTIME PASSIVE MIN", 28) == 0)
3021 {
3022 *len = scnprintf(extra, n, "CONCGETDWELLTIME PASSIVE MIN %u\n",
3023 (int)pCfg->nPassiveMinChnTimeConc);
3024 return ret;
3025 }
3026 else
3027 {
3028 ret = -EINVAL;
3029 }
3030
3031 return ret;
3032}
3033
3034/**
3035 * hdd_conc_set_dwell_time() - Set concurrency dwell time parameters
3036 * @pAdapter: Adapter upon which the command was received
3037 * @command: ASCII text command that is received
3038 *
3039 * Driver commands:
3040 * wpa_cli DRIVER CONCSETDWELLTIME ACTIVE MAX <value>
3041 * wpa_cli DRIVER CONCSETDWELLTIME ACTIVE MIN <value>
3042 * wpa_cli DRIVER CONCSETDWELLTIME PASSIVE MAX <value
3043 * wpa_cli DRIVER CONCSETDWELLTIME PASSIVE MIN <value>
3044 *
3045 * Return: 0 for success non-zero for failure
3046 */
3047
3048static int hdd_conc_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3049{
3050 tHalHandle hHal;
3051 hdd_config_t *pCfg;
3052 tANI_U8 *value = command;
3053 int val = 0, ret = 0, temp = 0;
3054 tSmeConfigParams smeConfig;
3055
3056 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3057 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
3058 {
3059 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME is incorrect"));
3060 ret = -EINVAL;
3061 return ret;
3062 }
3063
3064 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3065 sme_GetConfigParam(hHal, &smeConfig);
3066
3067 if (strncmp(command, "CONCSETDWELLTIME ACTIVE MAX", 27) == 0 )
3068 {
3069 if (hdd_drv_cmd_validate(command, 27)) {
3070 hddLog(LOGE, FL("Invalid driver command"));
3071 return -EINVAL;
3072 }
3073
3074 value = value + 28;
3075 temp = kstrtou32(value, 10, &val);
3076 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_CONC_MIN ||
3077 val > CFG_ACTIVE_MAX_CHANNEL_TIME_CONC_MAX)
3078 {
3079 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME ACTIVE MAX is incorrect"));
3080 ret = -EFAULT;
3081 return ret;
3082 }
3083 pCfg->nActiveMaxChnTimeConc = val;
3084 smeConfig.csrConfig.nActiveMaxChnTimeConc = val;
3085 sme_UpdateConfig(hHal, &smeConfig);
3086 }
3087 else if (strncmp(command, "CONCSETDWELLTIME ACTIVE MIN", 27) == 0)
3088 {
3089 if (hdd_drv_cmd_validate(command, 27)) {
3090 hddLog(LOGE, FL("Invalid driver command"));
3091 return -EINVAL;
3092 }
3093
3094 value = value + 28;
3095 temp = kstrtou32(value, 10, &val);
3096 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_CONC_MIN ||
3097 val > CFG_ACTIVE_MIN_CHANNEL_TIME_CONC_MAX)
3098 {
3099 hddLog(LOGE, FL("Argument passsed for CONCSETDWELLTIME ACTIVE MIN is incorrect"));
3100 ret = -EFAULT;
3101 return ret;
3102 }
3103 pCfg->nActiveMinChnTimeConc = val;
3104 smeConfig.csrConfig.nActiveMinChnTimeConc = val;
3105 sme_UpdateConfig(hHal, &smeConfig);
3106 }
3107 else if (strncmp(command, "CONCSETDWELLTIME PASSIVE MAX", 28) == 0)
3108 {
3109 if (hdd_drv_cmd_validate(command, 28)) {
3110 hddLog(LOGE, FL("Invalid driver command"));
3111 return -EINVAL;
3112 }
3113
3114 value = value + 29;
3115 temp = kstrtou32(value, 10, &val);
3116 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_CONC_MIN ||
3117 val > CFG_PASSIVE_MAX_CHANNEL_TIME_CONC_MAX)
3118 {
3119 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME PASSIVE MAX is incorrect"));
3120 ret = -EFAULT;
3121 return ret;
3122 }
3123 pCfg->nPassiveMaxChnTimeConc = val;
3124 smeConfig.csrConfig.nPassiveMaxChnTimeConc = val;
3125 sme_UpdateConfig(hHal, &smeConfig);
3126 }
3127 else if (strncmp(command, "CONCSETDWELLTIME PASSIVE MIN", 28) == 0)
3128 {
3129 if (hdd_drv_cmd_validate(command, 28)) {
3130 hddLog(LOGE, FL("Invalid driver command"));
3131 return -EINVAL;
3132 }
3133
3134 value = value + 29;
3135 temp = kstrtou32(value, 10, &val);
3136 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_CONC_MIN ||
3137 val > CFG_PASSIVE_MIN_CHANNEL_TIME_CONC_MAX )
3138 {
3139 hddLog(LOGE, FL("Argument passed for CONCSETDWELLTIME PASSIVE MIN is incorrect"));
3140 ret = -EFAULT;
3141 return ret;
3142 }
3143 pCfg->nPassiveMinChnTimeConc = val;
3144 smeConfig.csrConfig.nPassiveMinChnTimeConc = val;
3145 sme_UpdateConfig(hHal, &smeConfig);
3146 }
3147 else
3148 {
3149 ret = -EINVAL;
3150 }
3151
3152 return ret;
3153}
3154
3155#endif
3156
3157/**
3158 * hdd_btc_set_dwell_time() - Set BTC dwell time parameters
3159 * @pAdapter: Adapter upon which the command was received
3160 * @command: ASCII text command that is received
3161 *
3162 * Driver commands:
3163 * wpa_cli DRIVER BTCSETDWELLTIME ESCO MAX <value>
3164 * wpa_cli DRIVER BTCSETDWELLTIME ESCO MIN <value>
3165 * wpa_cli DRIVER BTCSETDWELLTIME SCO MAX <value>
3166 * wpa_cli DRIVER BTCSETDWELLTIME SCO MIN <value>
3167 *
3168 * Return: 0 for success non-zero for failure
3169 */
3170
3171static int hdd_btc_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3172{
3173 tHalHandle hHal;
3174 hdd_config_t *pCfg;
3175 tANI_U8 *value = command;
3176 int val = 0, ret = 0, temp = 0;
3177 tSmeConfigParams smeConfig;
3178
3179 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3180 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
3181 {
3182 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME is incorrect"));
3183 ret = -EINVAL;
3184 return ret;
3185 }
3186
3187 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3188 sme_GetConfigParam(hHal, &smeConfig);
3189
3190 if (strncmp(command, "BTCSETDWELLTIME ESCO MAX", 24) == 0)
3191 {
3192 if (hdd_drv_cmd_validate(command, 24)) {
3193 hddLog(LOGE, FL("Invalid driver command"));
3194 return -EINVAL;
3195 }
3196
3197 value = value + 25;
3198 temp = kstrtou32(value, 10, &val);
3199 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_MIN ||
3200 val > CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_MAX)
3201 {
3202 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME ESCO MAX is incorrect"));
3203 ret = -EFAULT;
3204 return ret;
3205 }
3206 pCfg->max_chntime_btc_esco = val;
3207 smeConfig.csrConfig.max_chntime_btc_esco = val;
3208 sme_UpdateConfig(hHal, &smeConfig);
3209 }
3210 else if (strncmp(command, "BTCSETDWELLTIME ESCO MIN", 24) == 0)
3211 {
3212 if (hdd_drv_cmd_validate(command, 24)) {
3213 hddLog(LOGE, FL("Invalid driver command"));
3214 return -EINVAL;
3215 }
3216
3217 value = value + 25;
3218 temp = kstrtou32(value, 10, &val);
3219 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_MIN ||
3220 val > CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_MAX)
3221 {
3222 hddLog(LOGE, FL("Argument passsed for BTCSETDWELLTIME ESCO MIN is incorrect"));
3223 ret = -EFAULT;
3224 return ret;
3225 }
3226 pCfg->min_chntime_btc_esco = val;
3227 smeConfig.csrConfig.min_chntime_btc_esco = val;
3228 sme_UpdateConfig(hHal, &smeConfig);
3229 }
3230 else if (strncmp(command, "BTCSETDWELLTIME SCO MAX", 23) == 0)
3231 {
3232 if (hdd_drv_cmd_validate(command, 23)) {
3233 hddLog(LOGE, FL("Invalid driver command"));
3234 return -EINVAL;
3235 }
3236
3237 value = value + 24;
3238 temp = kstrtou32(value, 10, &val);
3239 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_SCO_MIN ||
3240 val > CFG_ACTIVE_MAX_CHANNEL_TIME_BTC_SCO_MAX)
3241 {
3242 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME SCO MAX is incorrect"));
3243 ret = -EFAULT;
3244 return ret;
3245 }
3246 pCfg->max_chntime_btc_sco = val;
3247 smeConfig.csrConfig.max_chntime_btc_sco = val;
3248 sme_UpdateConfig(hHal, &smeConfig);
3249 }
3250 else if (strncmp(command, "BTCSETDWELLTIME SCO MIN", 23) == 0)
3251 {
3252 if (hdd_drv_cmd_validate(command, 23)) {
3253 hddLog(LOGE, FL("Invalid driver command"));
3254 return -EINVAL;
3255 }
3256
3257 value = value + 24;
3258 temp = kstrtou32(value, 10, &val);
3259 if (temp != 0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_SCO_MIN ||
3260 val > CFG_ACTIVE_MIN_CHANNEL_TIME_BTC_SCO_MAX)
3261 {
3262 hddLog(LOGE, FL("Argument passed for BTCSETDWELLTIME SCO MIN is incorrect"));
3263 ret = -EFAULT;
3264 return ret;
3265 }
3266 pCfg->min_chntime_btc_sco = val;
3267 smeConfig.csrConfig.min_chntime_btc_sco = val;
3268 sme_UpdateConfig(hHal, &smeConfig);
3269 }
3270 else
3271 {
3272 ret = -EINVAL;
3273 }
3274
3275 return ret;
3276}
3277
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303278static int hdd_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
3279{
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303280 tHalHandle hHal;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303281 hdd_config_t *pCfg;
3282 tANI_U8 *value = command;
3283 int val = 0, ret = 0, temp = 0;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303284 tSmeConfigParams smeConfig;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303285
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303286 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
3287 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303288 {
3289 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3290 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
3291 ret = -EINVAL;
3292 return ret;
3293 }
3294
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303295 vos_mem_zero(&smeConfig, sizeof(smeConfig));
3296 sme_GetConfigParam(hHal, &smeConfig);
3297
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303298 if (strncmp(command, "SETDWELLTIME ACTIVE MAX", 23) == 0 )
3299 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303300 if (hdd_drv_cmd_validate(command, 23))
3301 return -EINVAL;
3302
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303303 value = value + 24;
3304 temp = kstrtou32(value, 10, &val);
3305 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
3306 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
3307 {
3308 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3309 "%s: argument passed for SETDWELLTIME ACTIVE MAX is incorrect", __func__);
3310 ret = -EFAULT;
3311 return ret;
3312 }
3313 pCfg->nActiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303314 smeConfig.csrConfig.nActiveMaxChnTime = val;
3315 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303316 }
3317 else if (strncmp(command, "SETDWELLTIME ACTIVE MIN", 23) == 0)
3318 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303319 if (hdd_drv_cmd_validate(command, 23))
3320 return -EINVAL;
3321
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303322 value = value + 24;
3323 temp = kstrtou32(value, 10, &val);
3324 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_MIN ||
3325 val > CFG_ACTIVE_MIN_CHANNEL_TIME_MAX )
3326 {
3327 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3328 "%s: argument passsed for SETDWELLTIME ACTIVE MIN is incorrect", __func__);
3329 ret = -EFAULT;
3330 return ret;
3331 }
3332 pCfg->nActiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303333 smeConfig.csrConfig.nActiveMinChnTime = val;
3334 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303335 }
3336 else if (strncmp(command, "SETDWELLTIME PASSIVE MAX", 24) == 0)
3337 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303338 if (hdd_drv_cmd_validate(command, 24))
3339 return -EINVAL;
3340
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303341 value = value + 25;
3342 temp = kstrtou32(value, 10, &val);
3343 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_MIN ||
3344 val > CFG_PASSIVE_MAX_CHANNEL_TIME_MAX )
3345 {
3346 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3347 "%s: argument passed for SETDWELLTIME PASSIVE MAX is incorrect", __func__);
3348 ret = -EFAULT;
3349 return ret;
3350 }
3351 pCfg->nPassiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303352 smeConfig.csrConfig.nPassiveMaxChnTime = val;
3353 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303354 }
3355 else if (strncmp(command, "SETDWELLTIME PASSIVE MIN", 24) == 0)
3356 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303357 if (hdd_drv_cmd_validate(command, 24))
3358 return -EINVAL;
3359
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303360 value = value + 25;
3361 temp = kstrtou32(value, 10, &val);
3362 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_MIN ||
3363 val > CFG_PASSIVE_MIN_CHANNEL_TIME_MAX )
3364 {
3365 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3366 "%s: argument passed for SETDWELLTIME PASSIVE MIN is incorrect", __func__);
3367 ret = -EFAULT;
3368 return ret;
3369 }
3370 pCfg->nPassiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05303371 smeConfig.csrConfig.nPassiveMinChnTime = val;
3372 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303373 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05303374 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
3375 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303376 if (hdd_drv_cmd_validate(command, 12))
3377 return -EINVAL;
3378
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05303379 value = value + 13;
3380 temp = kstrtou32(value, 10, &val);
3381 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
3382 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
3383 {
3384 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3385 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
3386 ret = -EFAULT;
3387 return ret;
3388 }
3389 pCfg->nActiveMaxChnTime = val;
3390 smeConfig.csrConfig.nActiveMaxChnTime = val;
3391 sme_UpdateConfig(hHal, &smeConfig);
3392 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303393 else
3394 {
3395 ret = -EINVAL;
3396 }
3397
3398 return ret;
3399}
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303400static int hdd_cmd_setFccChannel(hdd_context_t *pHddCtx, tANI_U8 *cmd,
3401 tANI_U8 cmd_len)
3402{
3403 tANI_U8 *value;
3404 tANI_U8 fcc_constraint;
3405
3406 eHalStatus status;
3407 int ret = 0;
3408 value = cmd + cmd_len + 1;
3409
3410 ret = kstrtou8(value, 10, &fcc_constraint);
3411 if ((ret < 0) || (fcc_constraint > 1)) {
3412 /*
3413 * If the input value is greater than max value of datatype,
3414 * then also it is a failure
3415 */
3416 hddLog(VOS_TRACE_LEVEL_ERROR,
3417 "%s: value out of range", __func__);
3418 return -EINVAL;
3419 }
3420
Agrawal Ashish842eea82016-02-04 17:56:16 +05303421 status = sme_handleSetFccChannel(pHddCtx->hHal, fcc_constraint,
3422 pHddCtx->scan_info.mScanPending);
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303423 if (status != eHAL_STATUS_SUCCESS)
3424 ret = -EPERM;
3425
3426 return ret;
3427}
3428
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05303429/**---------------------------------------------------------------------------
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303430
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05303431 \brief hdd_enable_disable_ca_event() - When Host sends IOCTL (enabled),
3432 FW will send *ONE* CA ind to Host(even though it is duplicate).
3433 When Host send IOCTL (disable), FW doesn't perform any action.
3434 Whenever any change in CA *and* WLAN is in SAP/P2P-GO mode, FW
3435 sends CA ind to host. (regard less of IOCTL status)
3436 \param - pHddCtx - HDD context
3437 \param - command - command received from framework
3438 \param - cmd_len - len of the command
3439
3440 \return - 0 on success, appropriate error values on failure.
3441
3442 --------------------------------------------------------------------------*/
3443int hdd_enable_disable_ca_event(hdd_context_t *pHddCtx, tANI_U8* command, tANI_U8 cmd_len)
3444{
3445 tANI_U8 set_value;
3446 int ret = 0;
3447 eHalStatus status;
3448
3449 ret = wlan_hdd_validate_context(pHddCtx);
3450 if (0 != ret)
3451 {
3452 ret = -EINVAL;
3453 goto exit;
3454 }
3455
3456 if (pHddCtx->cfg_ini->gOptimizeCAevent == 0)
3457 {
3458 hddLog(VOS_TRACE_LEVEL_ERROR, "Enable gOptimizeCAevent"
3459 " ini param to control channel avooidance indication");
3460 ret = 0;
3461 goto exit;
3462 }
3463
3464 set_value = command[cmd_len + 1] - '0';
3465 status = sme_enableDisableChanAvoidIndEvent(pHddCtx->hHal, set_value);
3466 if (status != eHAL_STATUS_SUCCESS)
3467 {
3468 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to send"
3469 " enableDisableChanAoidance command to SME\n", __func__);
3470 ret = -EINVAL;
3471 }
3472
3473exit:
3474 return ret;
3475}
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303476
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303477/**
3478 * wlan_hdd_fastreassoc_handoff_request() - Post Handoff request to SME
3479 * @pHddCtx: Pointer to the HDD context
3480 * @channel: channel to reassociate
3481 * @targetApBssid: Target AP/BSSID to reassociate
3482 *
3483 * Return: None
3484 */
3485#if defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD) && !defined(QCA_WIFI_ISOC)
3486static void wlan_hdd_fastreassoc_handoff_request(hdd_context_t *pHddCtx,
3487 uint8_t channel, tSirMacAddr targetApBssid)
3488{
3489 tCsrHandoffRequest handoffInfo;
3490 handoffInfo.channel = channel;
3491 handoffInfo.src = FASTREASSOC;
3492 vos_mem_copy(handoffInfo.bssid, targetApBssid, sizeof(tSirMacAddr));
3493 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
3494}
3495#else
3496static void wlan_hdd_fastreassoc_handoff_request(hdd_context_t *pHddCtx,
3497 uint8_t channel, tSirMacAddr targetApBssid)
3498{
3499}
3500#endif
3501
3502/**
3503 * csr_fastroam_neighbor_ap_event() - Function to trigger scan/roam
3504 * @pAdapter: Pointer to HDD adapter
3505 * @channel: Channel to scan/roam
3506 * @targetApBssid: BSSID to roam
3507 *
3508 * Return: None
3509 */
3510#ifdef QCA_WIFI_ISOC
3511static void csr_fastroam_neighbor_ap_event(hdd_adapter_t *pAdapter,
3512 uint8_t channel, tSirMacAddr targetApBssid)
3513{
3514 smeIssueFastRoamNeighborAPEvent(WLAN_HDD_GET_HAL_CTX(pAdapter),
3515 &targetApBssid[0], eSME_ROAM_TRIGGER_SCAN, channel);
3516}
3517#else
3518static void csr_fastroam_neighbor_ap_event(hdd_adapter_t *pAdapter,
3519 uint8_t channel, tSirMacAddr targetApBssid)
3520{
3521}
3522#endif
3523
3524/**
3525 * wlan_hdd_handle_fastreassoc() - Handle fastreassoc command
3526 * @pAdapter: pointer to hdd adapter
3527 * @command: pointer to the command received
3528 *
3529 * Return: VOS_STATUS enum
3530 */
3531static VOS_STATUS wlan_hdd_handle_fastreassoc(hdd_adapter_t *pAdapter,
3532 uint8_t *command)
3533{
3534 tANI_U8 *value = command;
3535 tANI_U8 channel = 0;
3536 tSirMacAddr targetApBssid;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303537 hdd_station_ctx_t *pHddStaCtx = NULL;
3538 hdd_context_t *pHddCtx = NULL;
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05303539 int ret;
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303540 tCsrRoamModifyProfileFields mod_profile_fields;
3541 uint32_t roam_id = 0;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303542 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3543 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3544
3545 /* if not associated, no need to proceed with reassoc */
3546 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState) {
3547 hddLog(LOG1, FL("Not associated!"));
3548 return eHAL_STATUS_FAILURE;
3549 }
3550
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05303551 ret = hdd_parse_reassoc_command_v1_data(value, targetApBssid, &channel);
3552 if (ret) {
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303553 hddLog(LOGE, FL("Failed to parse reassoc command data"));
3554 return eHAL_STATUS_FAILURE;
3555 }
3556
3557 /* if the target bssid is same as currently associated AP,
3558 then no need to proceed with reassoc */
3559 if (vos_mem_compare(targetApBssid,
3560 pHddStaCtx->conn_info.bssId,
3561 sizeof(tSirMacAddr))) {
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303562 sme_GetModifyProfileFields(pHddCtx->hHal, pAdapter->sessionId,
3563 &mod_profile_fields);
3564 sme_RoamReassoc(pHddCtx->hHal, pAdapter->sessionId, NULL,
3565 mod_profile_fields, &roam_id, 1);
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303566 hddLog(LOG1, FL("Reassoc BSSID is same as currently associated AP bssid"));
Selvaraj, Sridhar349b8fe2017-01-18 13:11:25 +05303567 return eHAL_STATUS_SUCCESS;
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05303568 }
3569
3570 /* Check channel number is a valid channel number */
3571 if (VOS_STATUS_SUCCESS !=
3572 wlan_hdd_validate_operation_channel(pAdapter, channel)) {
3573 hddLog(LOGE, FL("Invalid Channel [%d]"), channel);
3574 return eHAL_STATUS_FAILURE;
3575 }
3576
3577 /* Proceed with reassoc */
3578 wlan_hdd_fastreassoc_handoff_request(pHddCtx, channel, targetApBssid);
3579
3580 /* Proceed with scan/roam */
3581 csr_fastroam_neighbor_ap_event(pAdapter, channel, targetApBssid);
3582
3583 return eHAL_STATUS_SUCCESS;
3584}
3585
3586/**
3587 * hdd_assign_reassoc_handoff - Set handoff source as REASSOC
3588 * @handoffInfo: Pointer to the csr Handoff Request.
3589 *
3590 * Return: None
3591 */
3592#ifndef QCA_WIFI_ISOC
3593static inline void hdd_assign_reassoc_handoff(tCsrHandoffRequest *handoffInfo)
3594{
3595 handoffInfo->src = REASSOC;
3596}
3597#else
3598static inline void hdd_assign_reassoc_handoff(tCsrHandoffRequest *handoffInfo)
3599{
3600}
3601#endif
3602
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303603/**
3604 * wlan_hdd_free_cache_channels() - Free the cache channels list
3605 * @hdd_ctx: Pointer to HDD context
3606 *
3607 * Return: None
3608 */
3609
3610static void wlan_hdd_free_cache_channels(hdd_context_t *hdd_ctx)
3611{
Ashish Kumar Dhanotiya19803832018-05-24 19:05:48 +05303612 if(!hdd_ctx || !hdd_ctx->original_channels)
3613 return;
3614
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303615 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303616 hdd_ctx->original_channels->num_channels = 0;
3617 vos_mem_free(hdd_ctx->original_channels->channel_info);
3618 hdd_ctx->original_channels->channel_info = NULL;
3619 vos_mem_free(hdd_ctx->original_channels);
3620 hdd_ctx->original_channels = NULL;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303621 mutex_unlock(&hdd_ctx->cache_channel_lock);
3622}
3623
3624/**
3625 * hdd_alloc_chan_cache() - Allocate the memory to cache the channel
3626 * info for the channels received in command SET_DISABLE_CHANNEL_LIST
3627 * @hdd_ctx: Pointer to HDD context
3628 * @num_chan: Number of channels for which memory needs to
3629 * be allocated
3630 *
3631 * Return: 0 on success and error code on failure
3632 */
3633
3634int hdd_alloc_chan_cache(hdd_context_t *hdd_ctx, int num_chan)
3635{
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303636 hdd_ctx->original_channels =
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303637 vos_mem_malloc(sizeof(struct hdd_cache_channels));
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303638 if (!hdd_ctx->original_channels) {
3639 hddLog(VOS_TRACE_LEVEL_ERROR,
3640 "In %s, VOS_MALLOC_ERR", __func__);
3641 return -EINVAL;
3642 }
3643 hdd_ctx->original_channels->num_channels = num_chan;
3644 hdd_ctx->original_channels->channel_info =
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303645 vos_mem_malloc(num_chan *
3646 sizeof(struct hdd_cache_channel_info));
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303647 if (!hdd_ctx->original_channels->channel_info) {
3648 hddLog(VOS_TRACE_LEVEL_ERROR,
3649 "In %s, VOS_MALLOC_ERR", __func__);
3650 hdd_ctx->original_channels->num_channels = 0;
3651 vos_mem_free(hdd_ctx->original_channels);
3652 hdd_ctx->original_channels = NULL;
3653 return -ENOMEM;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303654 }
3655 return 0;
3656
3657}
3658
3659
3660int hdd_parse_disable_chan_cmd(hdd_adapter_t *adapter, tANI_U8 *ptr)
3661{
3662 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
3663 hdd_context_t *hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, pvosGCtx);
3664 tANI_U8 *param;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303665 int j, tempInt, ret = 0, i, num_channels;
3666 int parsed_channels[MAX_CHANNEL];
3667 bool is_command_repeated = false;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303668
3669 if (NULL == pvosGCtx) {
3670 hddLog(VOS_TRACE_LEVEL_FATAL,
3671 "VOS Global Context is NULL");
3672 return -EINVAL;
3673 }
3674
3675 if (NULL == hdd_ctx) {
3676 hddLog(VOS_TRACE_LEVEL_FATAL, "HDD Context is NULL");
3677 return -EINVAL;
3678 }
3679
3680 param = strchr(ptr, ' ');
3681 /*no argument after the command*/
3682 if (NULL == param)
3683 return -EINVAL;
3684
3685 /*no space after the command*/
3686 else if (SPACE_ASCII_VALUE != *param)
3687 return -EINVAL;
3688
3689 param++;
3690
3691 /*removing empty spaces*/
3692 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3693 param++;
3694
3695 /*no argument followed by spaces*/
3696 if ('\0' == *param)
3697 return -EINVAL;
3698
3699 /*getting the first argument ie the number of channels*/
3700 if (sscanf(param, "%d ", &tempInt) != 1) {
3701 hddLog(VOS_TRACE_LEVEL_ERROR,
3702 "%s: Cannot get number of channels from input",
3703 __func__);
3704 return -EINVAL;
3705 }
3706
3707 if (tempInt < 0 || tempInt > MAX_CHANNEL) {
3708 hddLog(VOS_TRACE_LEVEL_ERROR,
3709 "%s: Invalid Number of channel received", __func__);
3710 return -EINVAL;
3711 }
3712
3713 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
3714 "%s: Number of channel to disable are: %d",
3715 __func__, tempInt);
3716
3717 if (!tempInt) {
3718 if (!wlan_hdd_restore_channels(hdd_ctx)) {
3719 /*
3720 * Free the cache channels only when the command is
3721 * received with num channels as 0
3722 */
3723 wlan_hdd_free_cache_channels(hdd_ctx);
3724 }
3725 return 0;
3726 }
3727
3728 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303729 if (!hdd_ctx->original_channels) {
3730 if (hdd_alloc_chan_cache(hdd_ctx, tempInt)) {
3731 ret = -ENOMEM;
3732 goto mem_alloc_failed;
3733 }
3734 } else if (hdd_ctx->original_channels->num_channels != tempInt) {
3735 hddLog(VOS_TRACE_LEVEL_ERROR,
3736 "%s, Invalid No of channel provided in the list",
3737 __func__);
3738 ret = -EINVAL;
3739 is_command_repeated = true;
3740 goto parse_failed;
3741 } else {
3742 is_command_repeated = true;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303743 }
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303744
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303745 num_channels = tempInt;
3746
3747 for (j = 0; j < num_channels; j++) {
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303748 /*
3749 * param pointing to the beginning of first space
3750 * after number of channels
3751 */
3752 param = strpbrk(param, " ");
3753 /*no channel list after the number of channels argument*/
3754 if (NULL == param) {
3755 hddLog(VOS_TRACE_LEVEL_ERROR,
3756 "%s, Invalid No of channel provided in the list",
3757 __func__);
3758 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303759 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303760 }
3761
3762 param++;
3763
3764 /*removing empty space*/
3765 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3766 param++;
3767
3768 if ('\0' == *param) {
3769 hddLog(VOS_TRACE_LEVEL_ERROR,
3770 "%s, No channel is provided in the list",
3771 __func__);
3772 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303773 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303774
3775 }
3776
3777 if (sscanf(param, "%d ", &tempInt) != 1) {
3778 hddLog(VOS_TRACE_LEVEL_ERROR,
3779 "%s: Cannot read channel number",
3780 __func__);
3781 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303782 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303783
3784 }
3785
3786 if (!IS_CHANNEL_VALID(tempInt)) {
3787 hddLog(VOS_TRACE_LEVEL_ERROR,
3788 "%s: Invalid channel number received",
3789 __func__);
3790 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303791 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303792
3793 }
3794
3795 hddLog(VOS_TRACE_LEVEL_INFO, "%s: channel[%d] = %d", __func__,
3796 j, tempInt);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303797
3798 parsed_channels[j] = tempInt;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303799 }
3800
3801 /*extra arguments check*/
3802 param = strchr(param, ' ');
3803 if (NULL != param) {
3804 while ((SPACE_ASCII_VALUE == *param) && ('\0' != *param))
3805 param++;
3806
3807 if ('\0' != *param) {
3808 hddLog(VOS_TRACE_LEVEL_ERROR,
3809 "%s: Invalid argument received", __func__);
3810 ret = -EINVAL;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303811 goto parse_failed;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303812 }
3813 }
3814
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303815 /*
3816 * If command is received first time, cache the channels to
3817 * be disabled else compare the channels received in the
3818 * command with the cached channels, if channel list matches
3819 * return success otherewise return failure.
3820 */
3821 if (!is_command_repeated)
3822 for (j = 0; j < num_channels; j++)
3823 hdd_ctx->original_channels->
3824 channel_info[j].channel_num =
3825 parsed_channels[j];
3826 else {
3827 for (i = 0; i < num_channels; i++) {
3828 for (j = 0; j < num_channels; j++)
3829 if (hdd_ctx->original_channels->
3830 channel_info[i].channel_num ==
3831 parsed_channels[j])
3832 break;
3833 if (j == num_channels) {
3834 ret = -EINVAL;
3835 goto parse_failed;
3836 }
3837 }
3838 ret = 0;
3839 }
3840
3841mem_alloc_failed:
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303842 mutex_unlock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya1cf97dd2019-03-11 16:59:25 +05303843 /* Disable the channels received in command SET_DISABLE_CHANNEL_LIST*/
3844 if (!is_command_repeated) {
3845 wlan_hdd_disable_channels(hdd_ctx);
3846 hdd_check_and_disconnect_sta_on_invalid_channel(hdd_ctx);
3847 }
3848
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303849 EXIT();
3850
3851 return ret;
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303852
3853parse_failed:
3854 mutex_unlock(&hdd_ctx->cache_channel_lock);
3855 if (!is_command_repeated)
3856 wlan_hdd_free_cache_channels(hdd_ctx);
3857 EXIT();
3858 return ret;
3859
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05303860}
3861
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303862int hdd_get_disable_ch_list(hdd_context_t *hdd_ctx, tANI_U8 *buf,
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303863 uint32_t buf_len)
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303864{
3865 struct hdd_cache_channel_info *ch_list;
3866 unsigned char i, num_ch;
3867 int len = 0;
3868
3869 mutex_lock(&hdd_ctx->cache_channel_lock);
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303870 if (hdd_ctx->original_channels &&
3871 hdd_ctx->original_channels->num_channels &&
3872 hdd_ctx->original_channels->channel_info) {
3873 num_ch = hdd_ctx->original_channels->num_channels;
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303874
3875 len = scnprintf(buf, buf_len, "%s %hhu",
3876 "GET_DISABLE_CHANNEL_LIST", num_ch);
3877
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303878 ch_list = hdd_ctx->original_channels->channel_info;
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303879
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05303880 for (i = 0; (i < num_ch) && (len < buf_len-1); i++) {
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05303881 len += scnprintf(buf + len, buf_len - len,
3882 " %d", ch_list[i].channel_num);
3883 }
3884 }
3885 mutex_unlock(&hdd_ctx->cache_channel_lock);
3886
3887 return len;
3888}
3889
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003890static int hdd_driver_command(hdd_adapter_t *pAdapter,
3891 hdd_priv_data_t *ppriv_data)
Jeff Johnson295189b2012-06-20 16:38:30 -07003892{
Jeff Johnson295189b2012-06-20 16:38:30 -07003893 hdd_priv_data_t priv_data;
3894 tANI_U8 *command = NULL;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303895 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3896 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003897 int ret = 0;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303898 int status;
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05303899#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
3900 struct cfg80211_mgmt_tx_params params;
3901#endif
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303902
3903 ENTER();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003904 /*
3905 * Note that valid pointers are provided by caller
3906 */
Jeff Johnson295189b2012-06-20 16:38:30 -07003907
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003908 /* copy to local struct to avoid numerous changes to legacy code */
3909 priv_data = *ppriv_data;
Jeff Johnson295189b2012-06-20 16:38:30 -07003910
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003911 if (priv_data.total_len <= 0 ||
3912 priv_data.total_len > WLAN_PRIV_DATA_MAX_LEN)
Sameer Thalappil8ef3a0e2013-04-05 14:36:04 -07003913 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003914 hddLog(VOS_TRACE_LEVEL_WARN,
3915 "%s:invalid priv_data.total_len(%d)!!!", __func__,
3916 priv_data.total_len);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003917 ret = -EINVAL;
3918 goto exit;
3919 }
Kaushik, Sushant96122442014-10-21 16:40:18 +05303920 status = wlan_hdd_validate_context(pHddCtx);
3921 if (0 != status)
3922 {
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303923 ret = -EINVAL;
3924 goto exit;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303925 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003926 /* Allocate +1 for '\0' */
3927 command = kmalloc(priv_data.total_len + 1, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07003928 if (!command)
3929 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003930 hddLog(VOS_TRACE_LEVEL_ERROR,
3931 "%s: failed to allocate memory", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003932 ret = -ENOMEM;
3933 goto exit;
3934 }
3935
3936 if (copy_from_user(command, priv_data.buf, priv_data.total_len))
3937 {
3938 ret = -EFAULT;
3939 goto exit;
3940 }
3941
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003942 /* Make sure the command is NUL-terminated */
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07003943 command[priv_data.total_len] = '\0';
3944
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003945 /* at one time the following block of code was conditional. braces
3946 * have been retained to avoid re-indenting the legacy code
3947 */
Jeff Johnson295189b2012-06-20 16:38:30 -07003948 {
3949 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
3950
3951 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07003952 "%s: Received %s cmd from Wi-Fi GUI***", __func__, command);
Jeff Johnson295189b2012-06-20 16:38:30 -07003953
3954 if (strncmp(command, "P2P_DEV_ADDR", 12) == 0 )
3955 {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303956 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3957 TRACE_CODE_HDD_P2P_DEV_ADDR_IOCTL,
3958 pAdapter->sessionId, (unsigned)
3959 (*(pHddCtx->p2pDeviceAddress.bytes+2)<<24 |
3960 *(pHddCtx->p2pDeviceAddress.bytes+3)<<16 |
3961 *(pHddCtx->p2pDeviceAddress.bytes+4)<<8 |
3962 *(pHddCtx->p2pDeviceAddress.bytes+5))));
Jeff Johnson295189b2012-06-20 16:38:30 -07003963 if (copy_to_user(priv_data.buf, pHddCtx->p2pDeviceAddress.bytes,
3964 sizeof(tSirMacAddr)))
3965 {
3966 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08003967 "%s: failed to copy data to user buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003968 ret = -EFAULT;
3969 }
3970 }
Amar Singhal0974e402013-02-12 14:27:46 -08003971 else if(strncmp(command, "SETBAND", 7) == 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07003972 {
Amar Singhal0974e402013-02-12 14:27:46 -08003973 tANI_U8 *ptr = command ;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003974
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303975 ret = hdd_drv_cmd_validate(command, 7);
3976 if (ret)
3977 goto exit;
3978
Jeff Johnson295189b2012-06-20 16:38:30 -07003979 /* Change band request received */
Srinivas Girigowdade697412013-02-14 16:31:48 -08003980
3981 /* First 8 bytes will have "SETBAND " and
Jeff Johnson295189b2012-06-20 16:38:30 -07003982 * 9 byte will have band setting value */
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07003983 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Amar Singhal0974e402013-02-12 14:27:46 -08003984 "%s: SetBandCommand Info comm %s UL %d, TL %d", __func__, command, priv_data.used_len, priv_data.total_len);
Anand N Sunkad27354cf2015-07-13 14:39:11 +05303985 if(VOS_FTM_MODE != hdd_get_conparam())
3986 {
3987 /* Change band request received */
3988 ret = hdd_setBand_helper(pAdapter->dev, ptr);
3989 if(ret < 0)
3990 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3991 "%s: failed to set band ret=%d", __func__, ret);
3992 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08003993 }
Kiet Lamf040f472013-11-20 21:15:23 +05303994 else if(strncmp(command, "SETWMMPS", 8) == 0)
3995 {
3996 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05303997
3998 ret = hdd_drv_cmd_validate(command, 8);
3999 if (ret)
4000 goto exit;
4001
Kiet Lamf040f472013-11-20 21:15:23 +05304002 ret = hdd_wmmps_helper(pAdapter, ptr);
4003 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05304004
4005 else if(strncmp(command, "TDLSSCAN", 8) == 0)
4006 {
4007 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304008
4009 ret = hdd_drv_cmd_validate(command, 8);
4010 if (ret)
4011 goto exit;
4012
Agarwal Ashishef54a182014-12-16 15:07:31 +05304013 ret = hdd_set_tdls_scan_type(pAdapter, ptr);
4014 }
4015
Jeff Johnson32d95a32012-09-10 13:15:23 -07004016 else if ( strncasecmp(command, "COUNTRY", 7) == 0 )
4017 {
4018 char *country_code;
4019
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304020 ret = hdd_drv_cmd_validate(command, 7);
4021 if (ret)
4022 goto exit;
4023
Jeff Johnson32d95a32012-09-10 13:15:23 -07004024 country_code = command + 8;
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07004025
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004026 INIT_COMPLETION(pAdapter->change_country_code);
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07004027 hdd_checkandupdate_dfssetting(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07004028#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +05304029 hdd_checkandupdate_phymode(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07004030#endif
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004031 ret = (int)sme_ChangeCountryCode(pHddCtx->hHal,
4032 (void *)(tSmeChangeCountryCallback)
4033 wlan_hdd_change_country_code_callback,
Abhishek Singha306a442013-11-07 18:39:01 +05304034 country_code, pAdapter, pHddCtx->pvosContext, eSIR_TRUE, eSIR_TRUE);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004035 if (eHAL_STATUS_SUCCESS == ret)
4036 {
4037 ret = wait_for_completion_interruptible_timeout(
4038 &pAdapter->change_country_code,
4039 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
4040 if (0 >= ret)
4041 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004042 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: SME while setting country code timed out %d",
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304043 __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004044 }
4045 }
4046 else
Jeff Johnson32d95a32012-09-10 13:15:23 -07004047 {
4048 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004049 "%s: SME Change Country code fail ret=%d", __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004050 ret = -EINVAL;
Jeff Johnson32d95a32012-09-10 13:15:23 -07004051 }
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07004052
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004053 }
4054 /*
4055 command should be a string having format
4056 SET_SAP_CHANNEL_LIST <num of channels> <the channels seperated by spaces>
4057 */
Amar Singhal0974e402013-02-12 14:27:46 -08004058 else if(strncmp(command, "SET_SAP_CHANNEL_LIST", 20) == 0)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004059 {
Amar Singhal0974e402013-02-12 14:27:46 -08004060 tANI_U8 *ptr = command;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004061
4062 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004063 " Received Command to Set Preferred Channels for SAP in %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004064
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -08004065 ret = sapSetPreferredChannel(ptr);
Jeff Johnson32d95a32012-09-10 13:15:23 -07004066 }
Sourav Mohapatra2416e0e2018-03-05 18:44:21 +05304067
4068 else if (strncmp(command, "VOWIFIMODE", 10) == 0)
4069 {
4070 tANI_U8 *ptr;
4071
4072 ret = hdd_drv_cmd_validate(command, 10);
4073 if (ret)
4074 goto exit;
4075
4076 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4077 "Received Command for VOWIFI mode in %s", __func__);
4078
4079 ptr = (tANI_U8*)command + 11;
4080 hdd_set_vowifi_mode(pHddCtx, *ptr - '0');
4081 }
4082
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004083 else if(strncmp(command, "SETSUSPENDMODE", 14) == 0)
4084 {
4085 int suspend = 0;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304086 tANI_U8 *ptr;
4087
4088 ret = hdd_drv_cmd_validate(command, 14);
4089 if (ret)
4090 goto exit;
4091
4092 ptr = (tANI_U8*)command + 15;
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004093
4094 suspend = *ptr - '0';
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304095 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4096 TRACE_CODE_HDD_SETSUSPENDMODE_IOCTL,
4097 pAdapter->sessionId, suspend));
Sameer Thalappil45931fb2013-02-01 11:18:05 -08004098 hdd_set_wlan_suspend_mode(suspend);
4099 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004100#ifdef WLAN_FEATURE_NEIGHBOR_ROAMING
4101 else if (strncmp(command, "SETROAMTRIGGER", 14) == 0)
4102 {
4103 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004104 tANI_S8 rssi = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004105 tANI_U8 lookUpThreshold = CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_DEFAULT;
4106 eHalStatus status = eHAL_STATUS_SUCCESS;
4107
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304108 ret = hdd_drv_cmd_validate(command, 14);
4109 if (ret)
4110 goto exit;
4111
Srinivas Girigowdade697412013-02-14 16:31:48 -08004112 /* Move pointer to ahead of SETROAMTRIGGER<delimiter> */
4113 value = value + 15;
4114
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004115 /* Convert the value from ascii to integer */
4116 ret = kstrtos8(value, 10, &rssi);
4117 if (ret < 0)
4118 {
4119 /* If the input value is greater than max value of datatype, then also
4120 kstrtou8 fails */
4121 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4122 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdafa7157d2013-10-31 10:14:22 -07004123 __func__,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004124 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
4125 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
4126 ret = -EINVAL;
4127 goto exit;
4128 }
4129
Srinivas Girigowdade697412013-02-14 16:31:48 -08004130 lookUpThreshold = abs(rssi);
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004131
Srinivas Girigowdade697412013-02-14 16:31:48 -08004132 if ((lookUpThreshold < CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN) ||
4133 (lookUpThreshold > CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX))
4134 {
4135 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4136 "Neighbor lookup threshold value %d is out of range"
4137 " (Min: %d Max: %d)", lookUpThreshold,
4138 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
4139 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
4140 ret = -EINVAL;
4141 goto exit;
4142 }
4143
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304144 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4145 TRACE_CODE_HDD_SETROAMTRIGGER_IOCTL,
4146 pAdapter->sessionId, lookUpThreshold));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004147 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4148 "%s: Received Command to Set Roam trigger"
4149 " (Neighbor lookup threshold) = %d", __func__, lookUpThreshold);
4150
4151 pHddCtx->cfg_ini->nNeighborLookupRssiThreshold = lookUpThreshold;
4152 status = sme_setNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold);
4153 if (eHAL_STATUS_SUCCESS != status)
4154 {
4155 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4156 "%s: Failed to set roam trigger, try again", __func__);
4157 ret = -EPERM;
4158 goto exit;
4159 }
4160
4161 /* Set Reassoc threshold to (lookup rssi threshold + 5 dBm) */
mukul sharmad6e1fdd2014-06-23 19:19:09 +05304162 pHddCtx->cfg_ini->nNeighborReassocRssiThreshold = lookUpThreshold + 5;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004163 sme_setNeighborReassocRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold + 5);
4164 }
4165 else if (strncmp(command, "GETROAMTRIGGER", 14) == 0)
4166 {
4167 tANI_U8 lookUpThreshold = sme_getNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal));
4168 int rssi = (-1) * lookUpThreshold;
4169 char extra[32];
4170 tANI_U8 len = 0;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304171 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4172 TRACE_CODE_HDD_GETROAMTRIGGER_IOCTL,
4173 pAdapter->sessionId, lookUpThreshold));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004174 len = scnprintf(extra, sizeof(extra), "%s %d", command, rssi);
Srinivas Girigowda91719232015-07-13 15:10:10 +05304175 len = VOS_MIN(priv_data.total_len, len + 1);
4176 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004177 {
4178 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4179 "%s: failed to copy data to user buffer", __func__);
4180 ret = -EFAULT;
4181 goto exit;
4182 }
4183 }
4184 else if (strncmp(command, "SETROAMSCANPERIOD", 17) == 0)
4185 {
4186 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004187 tANI_U8 roamScanPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004188 tANI_U16 neighborEmptyScanRefreshPeriod = CFG_EMPTY_SCAN_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004189
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304190 ret = hdd_drv_cmd_validate(command, 17);
4191 if (ret)
4192 goto exit;
4193
Srinivas Girigowdade697412013-02-14 16:31:48 -08004194 /* input refresh period is in terms of seconds */
4195 /* Move pointer to ahead of SETROAMSCANPERIOD<delimiter> */
4196 value = value + 18;
4197 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004198 ret = kstrtou8(value, 10, &roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004199 if (ret < 0)
4200 {
4201 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004202 kstrtou8 fails */
Srinivas Girigowdade697412013-02-14 16:31:48 -08004203 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004204 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdade697412013-02-14 16:31:48 -08004205 __func__,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07004206 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
4207 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004208 ret = -EINVAL;
4209 goto exit;
4210 }
4211
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004212 if ((roamScanPeriod < (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000)) ||
4213 (roamScanPeriod > (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000)))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004214 {
4215 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004216 "Roam scan period value %d is out of range"
4217 " (Min: %d Max: %d)", roamScanPeriod,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07004218 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
4219 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004220 ret = -EINVAL;
4221 goto exit;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304222 }
4223 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4224 TRACE_CODE_HDD_SETROAMSCANPERIOD_IOCTL,
4225 pAdapter->sessionId, roamScanPeriod));
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004226 neighborEmptyScanRefreshPeriod = roamScanPeriod * 1000;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004227
4228 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4229 "%s: Received Command to Set roam scan period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004230 " (Empty Scan refresh period) = %d", __func__, roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004231
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004232 pHddCtx->cfg_ini->nEmptyScanRefreshPeriod = neighborEmptyScanRefreshPeriod;
4233 sme_UpdateEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborEmptyScanRefreshPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004234 }
4235 else if (strncmp(command, "GETROAMSCANPERIOD", 17) == 0)
4236 {
4237 tANI_U16 nEmptyScanRefreshPeriod = sme_getEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
4238 char extra[32];
4239 tANI_U8 len = 0;
4240
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304241 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4242 TRACE_CODE_HDD_GETROAMSCANPERIOD_IOCTL,
4243 pAdapter->sessionId, nEmptyScanRefreshPeriod));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004244 len = scnprintf(extra, sizeof(extra), "%s %d",
4245 "GETROAMSCANPERIOD", (nEmptyScanRefreshPeriod/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004246 /* Returned value is in units of seconds */
Ratnam Rachuria72ba112015-07-17 13:27:03 +05304247 len = VOS_MIN(priv_data.total_len, len + 1);
4248 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004249 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4250 "%s: failed to copy data to user buffer", __func__);
4251 ret = -EFAULT;
4252 goto exit;
4253 }
4254 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004255 else if (strncmp(command, "SETROAMSCANREFRESHPERIOD", 24) == 0)
4256 {
4257 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004258 tANI_U8 roamScanRefreshPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004259 tANI_U16 neighborScanRefreshPeriod = CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004260
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304261 ret = hdd_drv_cmd_validate(command, 24);
4262 if (ret)
4263 goto exit;
4264
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004265 /* input refresh period is in terms of seconds */
4266 /* Move pointer to ahead of SETROAMSCANREFRESHPERIOD<delimiter> */
4267 value = value + 25;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004268
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004269 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004270 ret = kstrtou8(value, 10, &roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004271 if (ret < 0)
4272 {
4273 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004274 kstrtou8 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004275 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004276 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004277 __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004278 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
4279 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
4280 ret = -EINVAL;
4281 goto exit;
4282 }
4283
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004284 if ((roamScanRefreshPeriod < (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000)) ||
4285 (roamScanRefreshPeriod > (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000)))
4286 {
4287 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4288 "Neighbor scan results refresh period value %d is out of range"
4289 " (Min: %d Max: %d)", roamScanRefreshPeriod,
4290 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
4291 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
4292 ret = -EINVAL;
4293 goto exit;
4294 }
4295 neighborScanRefreshPeriod = roamScanRefreshPeriod * 1000;
4296
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004297 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4298 "%s: Received Command to Set roam scan refresh period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004299 " (Scan refresh period) = %d", __func__, roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004300
4301 pHddCtx->cfg_ini->nNeighborResultsRefreshPeriod = neighborScanRefreshPeriod;
4302 sme_setNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborScanRefreshPeriod);
4303 }
4304 else if (strncmp(command, "GETROAMSCANREFRESHPERIOD", 24) == 0)
4305 {
4306 tANI_U16 value = sme_getNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
4307 char extra[32];
4308 tANI_U8 len = 0;
4309
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004310 len = scnprintf(extra, sizeof(extra), "%s %d",
4311 "GETROAMSCANREFRESHPERIOD", (value/1000));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004312 /* Returned value is in units of seconds */
Ratnam Rachuri2c9d6702015-07-17 13:25:16 +05304313 len = VOS_MIN(priv_data.total_len, len + 1);
4314 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004315 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4316 "%s: failed to copy data to user buffer", __func__);
4317 ret = -EFAULT;
4318 goto exit;
4319 }
4320 }
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004321#ifdef FEATURE_WLAN_LFR
4322 /* SETROAMMODE */
4323 else if (strncmp(command, "SETROAMMODE", SIZE_OF_SETROAMMODE) == 0)
4324 {
4325 tANI_U8 *value = command;
4326 tANI_BOOLEAN roamMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
4327
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05304328 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
4329 hddLog(LOGE,
4330 FL("Roaming is always disabled in STA + MON concurrency"));
4331 ret = -EINVAL;
4332 goto exit;
4333 }
4334
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304335 ret = hdd_drv_cmd_validate(command, SIZE_OF_SETROAMMODE);
4336 if (ret)
4337 goto exit;
4338
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004339 /* Move pointer to ahead of SETROAMMODE<delimiter> */
4340 value = value + SIZE_OF_SETROAMMODE + 1;
4341
4342 /* Convert the value from ascii to integer */
4343 ret = kstrtou8(value, SIZE_OF_SETROAMMODE, &roamMode);
4344 if (ret < 0)
4345 {
4346 /* If the input value is greater than max value of datatype, then also
4347 kstrtou8 fails */
4348 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4349 "%s: kstrtou8 failed range [%d - %d]", __func__,
4350 CFG_LFR_FEATURE_ENABLED_MIN,
4351 CFG_LFR_FEATURE_ENABLED_MAX);
4352 ret = -EINVAL;
4353 goto exit;
4354 }
4355 if ((roamMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
4356 (roamMode > CFG_LFR_FEATURE_ENABLED_MAX))
4357 {
4358 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4359 "Roam Mode value %d is out of range"
4360 " (Min: %d Max: %d)", roamMode,
4361 CFG_LFR_FEATURE_ENABLED_MIN,
4362 CFG_LFR_FEATURE_ENABLED_MAX);
4363 ret = -EINVAL;
4364 goto exit;
4365 }
4366
4367 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4368 "%s: Received Command to Set Roam Mode = %d", __func__, roamMode);
4369 /*
4370 * Note that
4371 * SETROAMMODE 0 is to enable LFR while
4372 * SETROAMMODE 1 is to disable LFR, but
4373 * NotifyIsFastRoamIniFeatureEnabled 0/1 is to enable/disable.
4374 * So, we have to invert the value to call sme_UpdateIsFastRoamIniFeatureEnabled.
4375 */
4376 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
4377 roamMode = CFG_LFR_FEATURE_ENABLED_MAX; /* Roam enable */
4378 else
4379 roamMode = CFG_LFR_FEATURE_ENABLED_MIN; /* Roam disable */
4380
4381 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = roamMode;
4382 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), roamMode);
4383 }
4384 /* GETROAMMODE */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304385 else if (strncmp(command, "GETROAMMODE", SIZE_OF_GETROAMMODE) == 0)
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004386 {
4387 tANI_BOOLEAN roamMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4388 char extra[32];
4389 tANI_U8 len = 0;
4390
4391 /*
4392 * roamMode value shall be inverted because the sementics is different.
4393 */
4394 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
4395 roamMode = CFG_LFR_FEATURE_ENABLED_MAX;
4396 else
4397 roamMode = CFG_LFR_FEATURE_ENABLED_MIN;
4398
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004399 len = scnprintf(extra, sizeof(extra), "%s %d", command, roamMode);
Ratnam Rachuri28693eb2015-07-17 13:23:42 +05304400 len = VOS_MIN(priv_data.total_len, len + 1);
4401 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07004402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4403 "%s: failed to copy data to user buffer", __func__);
4404 ret = -EFAULT;
4405 goto exit;
4406 }
4407 }
4408#endif
Srinivas Girigowdade697412013-02-14 16:31:48 -08004409#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004410#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004411 else if (strncmp(command, "SETROAMDELTA", 12) == 0)
4412 {
4413 tANI_U8 *value = command;
4414 tANI_U8 roamRssiDiff = CFG_ROAM_RSSI_DIFF_DEFAULT;
4415
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304416 ret = hdd_drv_cmd_validate(command, 12);
4417 if (ret)
4418 goto exit;
4419
Srinivas Girigowdade697412013-02-14 16:31:48 -08004420 /* Move pointer to ahead of SETROAMDELTA<delimiter> */
4421 value = value + 13;
4422 /* Convert the value from ascii to integer */
4423 ret = kstrtou8(value, 10, &roamRssiDiff);
4424 if (ret < 0)
4425 {
4426 /* If the input value is greater than max value of datatype, then also
4427 kstrtou8 fails */
4428 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4429 "%s: kstrtou8 failed range [%d - %d]", __func__,
4430 CFG_ROAM_RSSI_DIFF_MIN,
4431 CFG_ROAM_RSSI_DIFF_MAX);
4432 ret = -EINVAL;
4433 goto exit;
4434 }
4435
4436 if ((roamRssiDiff < CFG_ROAM_RSSI_DIFF_MIN) ||
4437 (roamRssiDiff > CFG_ROAM_RSSI_DIFF_MAX))
4438 {
4439 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4440 "Roam rssi diff value %d is out of range"
4441 " (Min: %d Max: %d)", roamRssiDiff,
4442 CFG_ROAM_RSSI_DIFF_MIN,
4443 CFG_ROAM_RSSI_DIFF_MAX);
4444 ret = -EINVAL;
4445 goto exit;
4446 }
4447
4448 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4449 "%s: Received Command to Set roam rssi diff = %d", __func__, roamRssiDiff);
4450
4451 pHddCtx->cfg_ini->RoamRssiDiff = roamRssiDiff;
4452 sme_UpdateRoamRssiDiff((tHalHandle)(pHddCtx->hHal), roamRssiDiff);
4453 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304454 else if (strncmp(command, "GETROAMDELTA", 12) == 0)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004455 {
4456 tANI_U8 roamRssiDiff = sme_getRoamRssiDiff((tHalHandle)(pHddCtx->hHal));
4457 char extra[32];
4458 tANI_U8 len = 0;
4459
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304460 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4461 TRACE_CODE_HDD_GETROAMDELTA_IOCTL,
4462 pAdapter->sessionId, roamRssiDiff));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004463 len = scnprintf(extra, sizeof(extra), "%s %d",
4464 command, roamRssiDiff);
Ratnam Rachuri22a3b402015-07-17 13:21:49 +05304465 len = VOS_MIN(priv_data.total_len, len + 1);
4466 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004467 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4468 "%s: failed to copy data to user buffer", __func__);
4469 ret = -EFAULT;
4470 goto exit;
4471 }
4472 }
4473#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004474#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004475 else if (strncmp(command, "GETBAND", 7) == 0)
4476 {
4477 int band = -1;
4478 char extra[32];
4479 tANI_U8 len = 0;
4480 hdd_getBand_helper(pHddCtx, &band);
4481
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304482 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4483 TRACE_CODE_HDD_GETBAND_IOCTL,
4484 pAdapter->sessionId, band));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004485 len = scnprintf(extra, sizeof(extra), "%s %d", command, band);
Ratnam Rachuri52139592015-07-17 13:17:29 +05304486 len = VOS_MIN(priv_data.total_len, len + 1);
4487 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08004488 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4489 "%s: failed to copy data to user buffer", __func__);
4490 ret = -EFAULT;
4491 goto exit;
4492 }
4493 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004494 else if (strncmp(command, "SETROAMSCANCHANNELS", 19) == 0)
4495 {
4496 tANI_U8 *value = command;
4497 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
4498 tANI_U8 numChannels = 0;
4499 eHalStatus status = eHAL_STATUS_SUCCESS;
4500
4501 status = hdd_parse_channellist(value, ChannelList, &numChannels);
4502 if (eHAL_STATUS_SUCCESS != status)
4503 {
4504 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4505 "%s: Failed to parse channel list information", __func__);
4506 ret = -EINVAL;
4507 goto exit;
4508 }
4509
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304510 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4511 TRACE_CODE_HDD_SETROAMSCANCHANNELS_IOCTL,
4512 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004513 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
4514 {
4515 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4516 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
4517 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
4518 ret = -EINVAL;
4519 goto exit;
4520 }
4521 status = sme_ChangeRoamScanChannelList((tHalHandle)(pHddCtx->hHal), ChannelList,
4522 numChannels);
4523 if (eHAL_STATUS_SUCCESS != status)
4524 {
4525 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4526 "%s: Failed to update channel list information", __func__);
4527 ret = -EINVAL;
4528 goto exit;
4529 }
4530 }
4531 else if (strncmp(command, "GETROAMSCANCHANNELS", 19) == 0)
4532 {
4533 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
4534 tANI_U8 numChannels = 0;
Jeff Johnson51b67782013-04-05 12:35:41 -07004535 tANI_U8 j = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004536 char extra[128] = {0};
Jeff Johnson51b67782013-04-05 12:35:41 -07004537 int len;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004538
4539 if (eHAL_STATUS_SUCCESS != sme_getRoamScanChannelList( (tHalHandle)(pHddCtx->hHal),
4540 ChannelList, &numChannels ))
4541 {
4542 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4543 "%s: failed to get roam scan channel list", __func__);
4544 ret = -EFAULT;
4545 goto exit;
4546 }
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304547 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4548 TRACE_CODE_HDD_GETROAMSCANCHANNELS_IOCTL,
4549 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08004550 /* output channel list is of the format
4551 [Number of roam scan channels][Channel1][Channel2]... */
4552 /* copy the number of channels in the 0th index */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004553 len = scnprintf(extra, sizeof(extra), "%s %d", command, numChannels);
Sushant Kaushika08ca192015-09-16 15:52:04 +05304554 for (j = 0; (j < numChannels) && len <= sizeof(extra); j++)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004555 {
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004556 len += scnprintf(extra + len, sizeof(extra) - len, " %d",
4557 ChannelList[j]);
Srinivas Girigowdade697412013-02-14 16:31:48 -08004558 }
4559
Sushant Kaushikc9b8be52015-07-15 16:41:27 +05304560 len = VOS_MIN(priv_data.total_len, len + 1);
4561 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08004562 {
4563 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4564 "%s: failed to copy data to user buffer", __func__);
4565 ret = -EFAULT;
4566 goto exit;
4567 }
4568 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004569 else if (strncmp(command, "GETCCXMODE", 10) == 0)
4570 {
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004571 tANI_BOOLEAN eseMode = sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004572 char extra[32];
4573 tANI_U8 len = 0;
4574
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004575 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004576 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004577 if (eseMode &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004578 hdd_is_okc_mode_enabled(pHddCtx) &&
4579 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4580 {
4581 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004582 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004583 " hence this operation is not permitted!", __func__);
4584 ret = -EPERM;
4585 goto exit;
4586 }
4587
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004588 len = scnprintf(extra, sizeof(extra), "%s %d",
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004589 "GETCCXMODE", eseMode);
Sushant Kaushikf8abd352015-07-15 16:37:49 +05304590 len = VOS_MIN(priv_data.total_len, len + 1);
4591 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004592 {
4593 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4594 "%s: failed to copy data to user buffer", __func__);
4595 ret = -EFAULT;
4596 goto exit;
4597 }
4598 }
4599 else if (strncmp(command, "GETOKCMODE", 10) == 0)
4600 {
4601 tANI_BOOLEAN okcMode = hdd_is_okc_mode_enabled(pHddCtx);
4602 char extra[32];
4603 tANI_U8 len = 0;
4604
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004605 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004606 then this operation is not permitted (return FAILURE) */
4607 if (okcMode &&
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004608 sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004609 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4610 {
4611 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004612 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004613 " hence this operation is not permitted!", __func__);
4614 ret = -EPERM;
4615 goto exit;
4616 }
4617
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004618 len = scnprintf(extra, sizeof(extra), "%s %d",
4619 "GETOKCMODE", okcMode);
Sushant Kaushikbc2fb5c2015-07-15 16:43:16 +05304620 len = VOS_MIN(priv_data.total_len, len + 1);
4621 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004622 {
4623 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4624 "%s: failed to copy data to user buffer", __func__);
4625 ret = -EFAULT;
4626 goto exit;
4627 }
4628 }
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07004629 else if (strncmp(command, "GETFASTROAM", 11) == 0)
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004630 {
4631 tANI_BOOLEAN lfrMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4632 char extra[32];
4633 tANI_U8 len = 0;
4634
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004635 len = scnprintf(extra, sizeof(extra), "%s %d",
4636 "GETFASTROAM", lfrMode);
Sushant Kaushik4da7ec92015-07-15 16:39:32 +05304637 len = VOS_MIN(priv_data.total_len, len + 1);
4638 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004639 {
4640 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4641 "%s: failed to copy data to user buffer", __func__);
4642 ret = -EFAULT;
4643 goto exit;
4644 }
4645 }
4646 else if (strncmp(command, "GETFASTTRANSITION", 17) == 0)
4647 {
4648 tANI_BOOLEAN ft = sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal));
4649 char extra[32];
4650 tANI_U8 len = 0;
4651
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004652 len = scnprintf(extra, sizeof(extra), "%s %d",
4653 "GETFASTTRANSITION", ft);
Sushant Kaushik231a4452015-07-15 16:23:56 +05304654 len = VOS_MIN(priv_data.total_len, len + 1);
4655 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004656 {
4657 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4658 "%s: failed to copy data to user buffer", __func__);
4659 ret = -EFAULT;
4660 goto exit;
4661 }
4662 }
4663 else if (strncmp(command, "SETROAMSCANCHANNELMINTIME", 25) == 0)
4664 {
4665 tANI_U8 *value = command;
4666 tANI_U8 minTime = CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_DEFAULT;
4667
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304668 ret = hdd_drv_cmd_validate(command, 25);
4669 if (ret)
4670 goto exit;
4671
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004672 /* Move pointer to ahead of SETROAMSCANCHANNELMINTIME<delimiter> */
4673 value = value + 26;
4674 /* Convert the value from ascii to integer */
4675 ret = kstrtou8(value, 10, &minTime);
4676 if (ret < 0)
4677 {
4678 /* If the input value is greater than max value of datatype, then also
4679 kstrtou8 fails */
4680 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4681 "%s: kstrtou8 failed range [%d - %d]", __func__,
4682 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
4683 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
4684 ret = -EINVAL;
4685 goto exit;
4686 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004687 if ((minTime < CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN) ||
4688 (minTime > CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX))
4689 {
4690 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4691 "scan min channel time value %d is out of range"
4692 " (Min: %d Max: %d)", minTime,
4693 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
4694 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
4695 ret = -EINVAL;
4696 goto exit;
4697 }
4698
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304699 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4700 TRACE_CODE_HDD_SETROAMSCANCHANNELMINTIME_IOCTL,
4701 pAdapter->sessionId, minTime));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004702 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4703 "%s: Received Command to change channel min time = %d", __func__, minTime);
4704
4705 pHddCtx->cfg_ini->nNeighborScanMinChanTime = minTime;
4706 sme_setNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal), minTime);
4707 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004708 else if (strncmp(command, "SENDACTIONFRAME", 15) == 0)
4709 {
4710 tANI_U8 *value = command;
4711 tANI_U8 channel = 0;
4712 tANI_U8 dwellTime = 0;
4713 tANI_U8 bufLen = 0;
4714 tANI_U8 *buf = NULL;
4715 tSirMacAddr targetApBssid;
4716 eHalStatus status = eHAL_STATUS_SUCCESS;
4717 struct ieee80211_channel chan;
4718 tANI_U8 finalLen = 0;
4719 tANI_U8 *finalBuf = NULL;
4720 tANI_U8 temp = 0;
4721 u64 cookie;
4722 hdd_station_ctx_t *pHddStaCtx = NULL;
4723 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4724
4725 /* if not associated, no need to send action frame */
4726 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
4727 {
4728 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
4729 ret = -EINVAL;
4730 goto exit;
4731 }
4732
4733 status = hdd_parse_send_action_frame_data(value, targetApBssid, &channel,
4734 &dwellTime, &buf, &bufLen);
4735 if (eHAL_STATUS_SUCCESS != status)
4736 {
4737 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4738 "%s: Failed to parse send action frame data", __func__);
4739 ret = -EINVAL;
4740 goto exit;
4741 }
4742
4743 /* if the target bssid is different from currently associated AP,
4744 then no need to send action frame */
4745 if (VOS_TRUE != vos_mem_compare(targetApBssid,
4746 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
4747 {
4748 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:STA is not associated to this AP!",__func__);
4749 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004750 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004751 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004752 goto exit;
4753 }
4754
4755 /* if the channel number is different from operating channel then
4756 no need to send action frame */
4757 if (channel != pHddStaCtx->conn_info.operationChannel)
4758 {
4759 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4760 "%s: channel(%d) is different from operating channel(%d)",
4761 __func__, channel, pHddStaCtx->conn_info.operationChannel);
4762 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004763 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004764 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004765 goto exit;
4766 }
4767 chan.center_freq = sme_ChnToFreq(channel);
4768
4769 finalLen = bufLen + 24;
4770 finalBuf = vos_mem_malloc(finalLen);
4771 if (NULL == finalBuf)
4772 {
4773 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:memory allocation failed",__func__);
4774 ret = -ENOMEM;
Jeff Johnson11c33152013-04-16 17:52:40 -07004775 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004776 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004777 goto exit;
4778 }
4779 vos_mem_zero(finalBuf, finalLen);
4780
4781 /* Fill subtype */
4782 temp = SIR_MAC_MGMT_ACTION << 4;
4783 vos_mem_copy(finalBuf + 0, &temp, sizeof(temp));
4784
4785 /* Fill type */
4786 temp = SIR_MAC_MGMT_FRAME;
4787 vos_mem_copy(finalBuf + 2, &temp, sizeof(temp));
4788
4789 /* Fill destination address (bssid of the AP) */
4790 vos_mem_copy(finalBuf + 4, targetApBssid, sizeof(targetApBssid));
4791
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07004792 /* Fill source address (STA mac address) */
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004793 vos_mem_copy(finalBuf + 10, pAdapter->macAddressCurrent.bytes, sizeof(pAdapter->macAddressCurrent.bytes));
4794
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07004795 /* Fill BSSID (AP mac address) */
4796 vos_mem_copy(finalBuf + 16, targetApBssid, sizeof(targetApBssid));
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004797
4798 /* Fill received buffer from 24th address */
4799 vos_mem_copy(finalBuf + 24, buf, bufLen);
4800
Jeff Johnson11c33152013-04-16 17:52:40 -07004801 /* done with the parsed buffer */
4802 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004803 buf = NULL;
Jeff Johnson11c33152013-04-16 17:52:40 -07004804
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05304805#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
4806 params.chan = &chan;
4807 params.offchan = 0;
4808 params.wait = dwellTime;
4809 params.buf = finalBuf;
4810 params.len = finalLen;
4811 params.no_cck = 1;
4812 params.dont_wait_for_ack = 1;
4813 ret = wlan_hdd_mgmt_tx(NULL, &pAdapter->wdev, &params, &cookie);
4814#else
DARAM SUDHA39eede62014-02-12 11:16:40 +05304815 wlan_hdd_mgmt_tx( NULL,
Yue Maf49ba872013-08-19 12:04:25 -07004816#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4817 &(pAdapter->wdev),
4818#else
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004819 pAdapter->dev,
Yue Maf49ba872013-08-19 12:04:25 -07004820#endif
4821 &chan, 0,
4822#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
4823 NL80211_CHAN_HT20, 1,
4824#endif
4825 dwellTime, finalBuf, finalLen, 1,
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004826 1, &cookie );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05304827#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)*/
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004828 vos_mem_free(finalBuf);
4829 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004830 else if (strncmp(command, "GETROAMSCANCHANNELMINTIME", 25) == 0)
4831 {
4832 tANI_U16 val = sme_getNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal));
4833 char extra[32];
4834 tANI_U8 len = 0;
4835
4836 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004837 len = scnprintf(extra, sizeof(extra), "%s %d",
4838 "GETROAMSCANCHANNELMINTIME", val);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304839 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4840 TRACE_CODE_HDD_GETROAMSCANCHANNELMINTIME_IOCTL,
4841 pAdapter->sessionId, val));
Sushant Kaushikbb8c52c2015-07-15 16:36:23 +05304842 len = VOS_MIN(priv_data.total_len, len + 1);
4843 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004844 {
4845 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4846 "%s: failed to copy data to user buffer", __func__);
4847 ret = -EFAULT;
4848 goto exit;
4849 }
4850 }
4851 else if (strncmp(command, "SETSCANCHANNELTIME", 18) == 0)
4852 {
4853 tANI_U8 *value = command;
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004854 tANI_U16 maxTime = CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004855
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304856 ret = hdd_drv_cmd_validate(command, 18);
4857 if (ret)
4858 goto exit;
4859
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004860 /* Move pointer to ahead of SETSCANCHANNELTIME<delimiter> */
4861 value = value + 19;
4862 /* Convert the value from ascii to integer */
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004863 ret = kstrtou16(value, 10, &maxTime);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004864 if (ret < 0)
4865 {
4866 /* If the input value is greater than max value of datatype, then also
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004867 kstrtou16 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004868 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07004869 "%s: kstrtou16 failed range [%d - %d]", __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004870 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
4871 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
4872 ret = -EINVAL;
4873 goto exit;
4874 }
4875
4876 if ((maxTime < CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN) ||
4877 (maxTime > CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX))
4878 {
4879 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4880 "lfr mode value %d is out of range"
4881 " (Min: %d Max: %d)", maxTime,
4882 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
4883 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
4884 ret = -EINVAL;
4885 goto exit;
4886 }
4887
4888 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4889 "%s: Received Command to change channel max time = %d", __func__, maxTime);
4890
4891 pHddCtx->cfg_ini->nNeighborScanMaxChanTime = maxTime;
4892 sme_setNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal), maxTime);
4893 }
4894 else if (strncmp(command, "GETSCANCHANNELTIME", 18) == 0)
4895 {
4896 tANI_U16 val = sme_getNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal));
4897 char extra[32];
4898 tANI_U8 len = 0;
4899
4900 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004901 len = scnprintf(extra, sizeof(extra), "%s %d",
4902 "GETSCANCHANNELTIME", val);
Ratheesh S Pacbfa932015-07-16 15:27:18 +05304903 len = VOS_MIN(priv_data.total_len, len + 1);
4904 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004905 {
4906 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4907 "%s: failed to copy data to user buffer", __func__);
4908 ret = -EFAULT;
4909 goto exit;
4910 }
4911 }
4912 else if (strncmp(command, "SETSCANHOMETIME", 15) == 0)
4913 {
4914 tANI_U8 *value = command;
4915 tANI_U16 val = CFG_NEIGHBOR_SCAN_TIMER_PERIOD_DEFAULT;
4916
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304917 ret = hdd_drv_cmd_validate(command, 15);
4918 if (ret)
4919 goto exit;
4920
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004921 /* Move pointer to ahead of SETSCANHOMETIME<delimiter> */
4922 value = value + 16;
4923 /* Convert the value from ascii to integer */
4924 ret = kstrtou16(value, 10, &val);
4925 if (ret < 0)
4926 {
4927 /* If the input value is greater than max value of datatype, then also
4928 kstrtou16 fails */
4929 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4930 "%s: kstrtou16 failed range [%d - %d]", __func__,
4931 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
4932 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
4933 ret = -EINVAL;
4934 goto exit;
4935 }
4936
4937 if ((val < CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN) ||
4938 (val > CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX))
4939 {
4940 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4941 "scan home time value %d is out of range"
4942 " (Min: %d Max: %d)", val,
4943 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
4944 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
4945 ret = -EINVAL;
4946 goto exit;
4947 }
4948
4949 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4950 "%s: Received Command to change scan home time = %d", __func__, val);
4951
4952 pHddCtx->cfg_ini->nNeighborScanPeriod = val;
4953 sme_setNeighborScanPeriod((tHalHandle)(pHddCtx->hHal), val);
4954 }
4955 else if (strncmp(command, "GETSCANHOMETIME", 15) == 0)
4956 {
4957 tANI_U16 val = sme_getNeighborScanPeriod((tHalHandle)(pHddCtx->hHal));
4958 char extra[32];
4959 tANI_U8 len = 0;
4960
4961 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004962 len = scnprintf(extra, sizeof(extra), "%s %d",
4963 "GETSCANHOMETIME", val);
Ratheesh S P728d7c62015-07-16 15:38:58 +05304964 len = VOS_MIN(priv_data.total_len, len + 1);
4965 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004966 {
4967 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4968 "%s: failed to copy data to user buffer", __func__);
4969 ret = -EFAULT;
4970 goto exit;
4971 }
4972 }
4973 else if (strncmp(command, "SETROAMINTRABAND", 16) == 0)
4974 {
4975 tANI_U8 *value = command;
4976 tANI_U8 val = CFG_ROAM_INTRA_BAND_DEFAULT;
4977
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05304978 ret = hdd_drv_cmd_validate(command, 16);
4979 if (ret)
4980 goto exit;
4981
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004982 /* Move pointer to ahead of SETROAMINTRABAND<delimiter> */
4983 value = value + 17;
4984 /* Convert the value from ascii to integer */
4985 ret = kstrtou8(value, 10, &val);
4986 if (ret < 0)
4987 {
4988 /* If the input value is greater than max value of datatype, then also
4989 kstrtou8 fails */
4990 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4991 "%s: kstrtou8 failed range [%d - %d]", __func__,
4992 CFG_ROAM_INTRA_BAND_MIN,
4993 CFG_ROAM_INTRA_BAND_MAX);
4994 ret = -EINVAL;
4995 goto exit;
4996 }
4997
4998 if ((val < CFG_ROAM_INTRA_BAND_MIN) ||
4999 (val > CFG_ROAM_INTRA_BAND_MAX))
5000 {
5001 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5002 "intra band mode value %d is out of range"
5003 " (Min: %d Max: %d)", val,
5004 CFG_ROAM_INTRA_BAND_MIN,
5005 CFG_ROAM_INTRA_BAND_MAX);
5006 ret = -EINVAL;
5007 goto exit;
5008 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005009 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5010 "%s: Received Command to change intra band = %d", __func__, val);
5011
5012 pHddCtx->cfg_ini->nRoamIntraBand = val;
5013 sme_setRoamIntraBand((tHalHandle)(pHddCtx->hHal), val);
5014 }
5015 else if (strncmp(command, "GETROAMINTRABAND", 16) == 0)
5016 {
5017 tANI_U16 val = sme_getRoamIntraBand((tHalHandle)(pHddCtx->hHal));
5018 char extra[32];
5019 tANI_U8 len = 0;
5020
5021 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005022 len = scnprintf(extra, sizeof(extra), "%s %d",
5023 "GETROAMINTRABAND", val);
Ratheesh S P2dd2a3e2015-07-16 15:34:23 +05305024 len = VOS_MIN(priv_data.total_len, len + 1);
5025 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005026 {
5027 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5028 "%s: failed to copy data to user buffer", __func__);
5029 ret = -EFAULT;
5030 goto exit;
5031 }
5032 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005033 else if (strncmp(command, "SETSCANNPROBES", 14) == 0)
5034 {
5035 tANI_U8 *value = command;
5036 tANI_U8 nProbes = CFG_ROAM_SCAN_N_PROBES_DEFAULT;
5037
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305038 ret = hdd_drv_cmd_validate(command, 14);
5039 if (ret)
5040 goto exit;
5041
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005042 /* Move pointer to ahead of SETSCANNPROBES<delimiter> */
5043 value = value + 15;
5044 /* Convert the value from ascii to integer */
5045 ret = kstrtou8(value, 10, &nProbes);
5046 if (ret < 0)
5047 {
5048 /* If the input value is greater than max value of datatype, then also
5049 kstrtou8 fails */
5050 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5051 "%s: kstrtou8 failed range [%d - %d]", __func__,
5052 CFG_ROAM_SCAN_N_PROBES_MIN,
5053 CFG_ROAM_SCAN_N_PROBES_MAX);
5054 ret = -EINVAL;
5055 goto exit;
5056 }
5057
5058 if ((nProbes < CFG_ROAM_SCAN_N_PROBES_MIN) ||
5059 (nProbes > CFG_ROAM_SCAN_N_PROBES_MAX))
5060 {
5061 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5062 "NProbes value %d is out of range"
5063 " (Min: %d Max: %d)", nProbes,
5064 CFG_ROAM_SCAN_N_PROBES_MIN,
5065 CFG_ROAM_SCAN_N_PROBES_MAX);
5066 ret = -EINVAL;
5067 goto exit;
5068 }
5069
5070 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5071 "%s: Received Command to Set nProbes = %d", __func__, nProbes);
5072
5073 pHddCtx->cfg_ini->nProbes = nProbes;
5074 sme_UpdateRoamScanNProbes((tHalHandle)(pHddCtx->hHal), nProbes);
5075 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305076 else if (strncmp(command, "GETSCANNPROBES", 14) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005077 {
5078 tANI_U8 val = sme_getRoamScanNProbes((tHalHandle)(pHddCtx->hHal));
5079 char extra[32];
5080 tANI_U8 len = 0;
5081
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005082 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri6da525d2015-08-07 13:55:54 +05305083 len = VOS_MIN(priv_data.total_len, len + 1);
5084 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005085 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5086 "%s: failed to copy data to user buffer", __func__);
5087 ret = -EFAULT;
5088 goto exit;
5089 }
5090 }
5091 else if (strncmp(command, "SETSCANHOMEAWAYTIME", 19) == 0)
5092 {
5093 tANI_U8 *value = command;
5094 tANI_U16 homeAwayTime = CFG_ROAM_SCAN_HOME_AWAY_TIME_DEFAULT;
5095
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305096 ret = hdd_drv_cmd_validate(command, 19);
5097 if (ret)
5098 goto exit;
5099
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005100 /* Move pointer to ahead of SETSCANHOMEAWAYTIME<delimiter> */
5101 /* input value is in units of msec */
5102 value = value + 20;
5103 /* Convert the value from ascii to integer */
5104 ret = kstrtou16(value, 10, &homeAwayTime);
5105 if (ret < 0)
5106 {
5107 /* If the input value is greater than max value of datatype, then also
5108 kstrtou8 fails */
5109 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5110 "%s: kstrtou8 failed range [%d - %d]", __func__,
5111 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
5112 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
5113 ret = -EINVAL;
5114 goto exit;
5115 }
5116
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005117 if ((homeAwayTime < CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN) ||
5118 (homeAwayTime > CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX))
5119 {
5120 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5121 "homeAwayTime value %d is out of range"
5122 " (Min: %d Max: %d)", homeAwayTime,
5123 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
5124 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
5125 ret = -EINVAL;
5126 goto exit;
5127 }
5128
5129 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5130 "%s: Received Command to Set scan away time = %d", __func__, homeAwayTime);
Srinivas Girigowda6cf0b822013-06-27 14:00:20 -07005131 if (pHddCtx->cfg_ini->nRoamScanHomeAwayTime != homeAwayTime)
5132 {
5133 pHddCtx->cfg_ini->nRoamScanHomeAwayTime = homeAwayTime;
5134 sme_UpdateRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal), homeAwayTime, eANI_BOOLEAN_TRUE);
5135 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005136 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305137 else if (strncmp(command, "GETSCANHOMEAWAYTIME", 19) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005138 {
5139 tANI_U16 val = sme_getRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal));
5140 char extra[32];
5141 tANI_U8 len = 0;
5142
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005143 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri51a5ad12015-08-07 14:06:37 +05305144 len = VOS_MIN(priv_data.total_len, len + 1);
5145 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005146 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5147 "%s: failed to copy data to user buffer", __func__);
5148 ret = -EFAULT;
5149 goto exit;
5150 }
5151 }
5152 else if (strncmp(command, "REASSOC", 7) == 0)
5153 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305154 ret = hdd_drv_cmd_validate(command, 7);
5155 if (ret)
5156 goto exit;
5157
5158 ret = hdd_parse_reassoc(pAdapter, command, priv_data.total_len);
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05305159 if (!ret)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005160 goto exit;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07005161 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005162 else if (strncmp(command, "SETWESMODE", 10) == 0)
5163 {
5164 tANI_U8 *value = command;
5165 tANI_BOOLEAN wesMode = CFG_ENABLE_WES_MODE_NAME_DEFAULT;
5166
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305167 ret = hdd_drv_cmd_validate(command, 10);
5168 if (ret)
5169 goto exit;
5170
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005171 /* Move pointer to ahead of SETWESMODE<delimiter> */
5172 value = value + 11;
5173 /* Convert the value from ascii to integer */
5174 ret = kstrtou8(value, 10, &wesMode);
5175 if (ret < 0)
5176 {
5177 /* If the input value is greater than max value of datatype, then also
5178 kstrtou8 fails */
5179 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5180 "%s: kstrtou8 failed range [%d - %d]", __func__,
5181 CFG_ENABLE_WES_MODE_NAME_MIN,
5182 CFG_ENABLE_WES_MODE_NAME_MAX);
5183 ret = -EINVAL;
5184 goto exit;
5185 }
5186
5187 if ((wesMode < CFG_ENABLE_WES_MODE_NAME_MIN) ||
5188 (wesMode > CFG_ENABLE_WES_MODE_NAME_MAX))
5189 {
5190 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5191 "WES Mode value %d is out of range"
5192 " (Min: %d Max: %d)", wesMode,
5193 CFG_ENABLE_WES_MODE_NAME_MIN,
5194 CFG_ENABLE_WES_MODE_NAME_MAX);
5195 ret = -EINVAL;
5196 goto exit;
5197 }
5198 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5199 "%s: Received Command to Set WES Mode rssi diff = %d", __func__, wesMode);
5200
5201 pHddCtx->cfg_ini->isWESModeEnabled = wesMode;
5202 sme_UpdateWESMode((tHalHandle)(pHddCtx->hHal), wesMode);
5203 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305204 else if (strncmp(command, "GETWESMODE", 10) == 0)
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005205 {
5206 tANI_BOOLEAN wesMode = sme_GetWESMode((tHalHandle)(pHddCtx->hHal));
5207 char extra[32];
5208 tANI_U8 len = 0;
5209
Arif Hussain826d9412013-11-12 16:44:54 -08005210 len = scnprintf(extra, sizeof(extra), "%s %d", command, wesMode);
Ratnam Rachuri8fe90c62015-08-07 14:03:26 +05305211 len = VOS_MIN(priv_data.total_len, len + 1);
5212 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005213 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5214 "%s: failed to copy data to user buffer", __func__);
5215 ret = -EFAULT;
5216 goto exit;
5217 }
5218 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005219#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE || FEATURE_WLAN_LFR */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005220#ifdef FEATURE_WLAN_LFR
5221 else if (strncmp(command, "SETFASTROAM", 11) == 0)
5222 {
5223 tANI_U8 *value = command;
5224 tANI_U8 lfrMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
5225
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05305226 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
5227 hddLog(LOGE,
5228 FL("Roaming is always disabled in STA + MON concurrency"));
5229 ret = -EINVAL;
5230 goto exit;
5231 }
5232
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305233 ret = hdd_drv_cmd_validate(command, 11);
5234 if (ret)
5235 goto exit;
5236
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005237 /* Move pointer to ahead of SETFASTROAM<delimiter> */
5238 value = value + 12;
5239 /* Convert the value from ascii to integer */
5240 ret = kstrtou8(value, 10, &lfrMode);
5241 if (ret < 0)
5242 {
5243 /* If the input value is greater than max value of datatype, then also
5244 kstrtou8 fails */
5245 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5246 "%s: kstrtou8 failed range [%d - %d]", __func__,
5247 CFG_LFR_FEATURE_ENABLED_MIN,
5248 CFG_LFR_FEATURE_ENABLED_MAX);
5249 ret = -EINVAL;
5250 goto exit;
5251 }
5252
5253 if ((lfrMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
5254 (lfrMode > CFG_LFR_FEATURE_ENABLED_MAX))
5255 {
5256 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5257 "lfr mode value %d is out of range"
5258 " (Min: %d Max: %d)", lfrMode,
5259 CFG_LFR_FEATURE_ENABLED_MIN,
5260 CFG_LFR_FEATURE_ENABLED_MAX);
5261 ret = -EINVAL;
5262 goto exit;
5263 }
5264
5265 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5266 "%s: Received Command to change lfr mode = %d", __func__, lfrMode);
5267
5268 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = lfrMode;
5269 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), lfrMode);
5270 }
5271#endif
5272#ifdef WLAN_FEATURE_VOWIFI_11R
5273 else if (strncmp(command, "SETFASTTRANSITION", 17) == 0)
5274 {
5275 tANI_U8 *value = command;
5276 tANI_U8 ft = CFG_FAST_TRANSITION_ENABLED_NAME_DEFAULT;
5277
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305278 ret = hdd_drv_cmd_validate(command, 17);
5279 if (ret)
5280 goto exit;
5281
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005282 /* Move pointer to ahead of SETFASTROAM<delimiter> */
5283 value = value + 18;
5284 /* Convert the value from ascii to integer */
5285 ret = kstrtou8(value, 10, &ft);
5286 if (ret < 0)
5287 {
5288 /* If the input value is greater than max value of datatype, then also
5289 kstrtou8 fails */
5290 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5291 "%s: kstrtou8 failed range [%d - %d]", __func__,
5292 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
5293 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
5294 ret = -EINVAL;
5295 goto exit;
5296 }
5297
5298 if ((ft < CFG_FAST_TRANSITION_ENABLED_NAME_MIN) ||
5299 (ft > CFG_FAST_TRANSITION_ENABLED_NAME_MAX))
5300 {
5301 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5302 "ft mode value %d is out of range"
5303 " (Min: %d Max: %d)", ft,
5304 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
5305 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
5306 ret = -EINVAL;
5307 goto exit;
5308 }
5309
5310 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5311 "%s: Received Command to change ft mode = %d", __func__, ft);
5312
5313 pHddCtx->cfg_ini->isFastTransitionEnabled = ft;
5314 sme_UpdateFastTransitionEnabled((tHalHandle)(pHddCtx->hHal), ft);
5315 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305316 else if (strncmp(command, "SETDFSSCANMODE", 14) == 0)
5317 {
5318 tANI_U8 *value = command;
5319 tANI_U8 dfsScanMode = DFS_CHNL_SCAN_ENABLED_NORMAL;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305320
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305321 ret = hdd_drv_cmd_validate(command, 14);
5322 if (ret)
5323 goto exit;
5324
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305325 /* Move pointer to ahead of SETDFSSCANMODE<delimiter> */
5326 value = value + 15;
5327 /* Convert the value from ascii to integer */
5328 ret = kstrtou8(value, 10, &dfsScanMode);
5329 if (ret < 0)
5330 {
5331 /* If the input value is greater than max value of
5332 datatype, then also kstrtou8 fails
5333 */
5334 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5335 "%s: kstrtou8 failed range [%d - %d]", __func__,
5336 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
5337 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
5338 ret = -EINVAL;
5339 goto exit;
5340 }
5341
5342 if ((dfsScanMode < CFG_ENABLE_DFS_CHNL_SCAN_MIN) ||
5343 (dfsScanMode > CFG_ENABLE_DFS_CHNL_SCAN_MAX))
5344 {
5345 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5346 "dfsScanMode value %d is out of range"
5347 " (Min: %d Max: %d)", dfsScanMode,
5348 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
5349 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
5350 ret = -EINVAL;
5351 goto exit;
5352 }
5353 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5354 "%s: Received Command to Set DFS Scan Mode = %d",
5355 __func__, dfsScanMode);
5356
5357 ret = wlan_hdd_handle_dfs_chan_scan(pHddCtx, dfsScanMode);
5358 }
5359 else if (strncmp(command, "GETDFSSCANMODE", 14) == 0)
5360 {
5361 tANI_U8 dfsScanMode = sme_GetDFSScanMode(pHddCtx->hHal);
5362 char extra[32];
5363 tANI_U8 len = 0;
5364
5365 len = scnprintf(extra, sizeof(extra), "%s %d", command, dfsScanMode);
Ratheesh S P767224e2015-07-16 15:35:51 +05305366 len = VOS_MIN(priv_data.total_len, len + 1);
5367 if (copy_to_user(priv_data.buf, &extra, len))
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05305368 {
5369 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5370 "%s: failed to copy data to user buffer", __func__);
5371 ret = -EFAULT;
5372 goto exit;
5373 }
5374 }
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305375 else if (strncmp(command, "FASTREASSOC", 11) == 0)
5376 {
Selvaraj, Sridhar3714c4d2016-06-22 15:19:12 +05305377 ret = wlan_hdd_handle_fastreassoc(pAdapter, command);
5378 if (!ret)
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305379 goto exit;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05305380 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005381#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005382#ifdef FEATURE_WLAN_ESE
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005383 else if (strncmp(command, "SETCCXMODE", 10) == 0)
5384 {
5385 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005386 tANI_U8 eseMode = CFG_ESE_FEATURE_ENABLED_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005387
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305388 ret = hdd_drv_cmd_validate(command, 10);
5389 if (ret)
5390 goto exit;
5391
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005392 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005393 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005394 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005395 hdd_is_okc_mode_enabled(pHddCtx) &&
5396 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
5397 {
5398 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005399 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005400 " hence this operation is not permitted!", __func__);
5401 ret = -EPERM;
5402 goto exit;
5403 }
5404
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005405 /* Move pointer to ahead of SETCCXMODE<delimiter> */
5406 value = value + 11;
5407 /* Convert the value from ascii to integer */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005408 ret = kstrtou8(value, 10, &eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005409 if (ret < 0)
5410 {
5411 /* If the input value is greater than max value of datatype, then also
5412 kstrtou8 fails */
5413 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5414 "%s: kstrtou8 failed range [%d - %d]", __func__,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005415 CFG_ESE_FEATURE_ENABLED_MIN,
5416 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005417 ret = -EINVAL;
5418 goto exit;
5419 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005420 if ((eseMode < CFG_ESE_FEATURE_ENABLED_MIN) ||
5421 (eseMode > CFG_ESE_FEATURE_ENABLED_MAX))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005422 {
5423 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005424 "Ese mode value %d is out of range"
5425 " (Min: %d Max: %d)", eseMode,
5426 CFG_ESE_FEATURE_ENABLED_MIN,
5427 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005428 ret = -EINVAL;
5429 goto exit;
5430 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005431 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005432 "%s: Received Command to change ese mode = %d", __func__, eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005433
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005434 pHddCtx->cfg_ini->isEseIniFeatureEnabled = eseMode;
5435 sme_UpdateIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal), eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005436 }
5437#endif
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005438 else if (strncmp(command, "SETROAMSCANCONTROL", 18) == 0)
5439 {
5440 tANI_U8 *value = command;
5441 tANI_BOOLEAN roamScanControl = 0;
5442
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305443 ret = hdd_drv_cmd_validate(command, 18);
5444 if (ret)
5445 goto exit;
5446
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005447 /* Move pointer to ahead of SETROAMSCANCONTROL<delimiter> */
5448 value = value + 19;
5449 /* Convert the value from ascii to integer */
5450 ret = kstrtou8(value, 10, &roamScanControl);
5451 if (ret < 0)
5452 {
5453 /* If the input value is greater than max value of datatype, then also
5454 kstrtou8 fails */
5455 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5456 "%s: kstrtou8 failed ", __func__);
5457 ret = -EINVAL;
5458 goto exit;
5459 }
5460
5461 if (0 != roamScanControl)
5462 {
5463 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5464 "roam scan control invalid value = %d",
5465 roamScanControl);
5466 ret = -EINVAL;
5467 goto exit;
5468 }
5469 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5470 "%s: Received Command to Set roam scan control = %d", __func__, roamScanControl);
5471
5472 sme_SetRoamScanControl((tHalHandle)(pHddCtx->hHal), roamScanControl);
5473 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005474#ifdef FEATURE_WLAN_OKC
5475 else if (strncmp(command, "SETOKCMODE", 10) == 0)
5476 {
5477 tANI_U8 *value = command;
5478 tANI_U8 okcMode = CFG_OKC_FEATURE_ENABLED_DEFAULT;
5479
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305480 ret = hdd_drv_cmd_validate(command, 10);
5481 if (ret)
5482 goto exit;
5483
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005484 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005485 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005486 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005487 hdd_is_okc_mode_enabled(pHddCtx) &&
5488 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
5489 {
5490 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005491 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07005492 " hence this operation is not permitted!", __func__);
5493 ret = -EPERM;
5494 goto exit;
5495 }
5496
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07005497 /* Move pointer to ahead of SETOKCMODE<delimiter> */
5498 value = value + 11;
5499 /* Convert the value from ascii to integer */
5500 ret = kstrtou8(value, 10, &okcMode);
5501 if (ret < 0)
5502 {
5503 /* If the input value is greater than max value of datatype, then also
5504 kstrtou8 fails */
5505 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5506 "%s: kstrtou8 failed range [%d - %d]", __func__,
5507 CFG_OKC_FEATURE_ENABLED_MIN,
5508 CFG_OKC_FEATURE_ENABLED_MAX);
5509 ret = -EINVAL;
5510 goto exit;
5511 }
5512
5513 if ((okcMode < CFG_OKC_FEATURE_ENABLED_MIN) ||
5514 (okcMode > CFG_OKC_FEATURE_ENABLED_MAX))
5515 {
5516 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5517 "Okc mode value %d is out of range"
5518 " (Min: %d Max: %d)", okcMode,
5519 CFG_OKC_FEATURE_ENABLED_MIN,
5520 CFG_OKC_FEATURE_ENABLED_MAX);
5521 ret = -EINVAL;
5522 goto exit;
5523 }
5524
5525 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5526 "%s: Received Command to change okc mode = %d", __func__, okcMode);
5527
5528 pHddCtx->cfg_ini->isOkcIniFeatureEnabled = okcMode;
5529 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07005530#endif /* FEATURE_WLAN_OKC */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05305531 else if (strncmp(command, "GETROAMSCANCONTROL", 18) == 0)
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005532 {
5533 tANI_BOOLEAN roamScanControl = sme_GetRoamScanControl((tHalHandle)(pHddCtx->hHal));
5534 char extra[32];
5535 tANI_U8 len = 0;
5536
Sameer Thalappilb0a30232013-09-27 15:37:48 -07005537 len = scnprintf(extra, sizeof(extra), "%s %d",
5538 command, roamScanControl);
Ratnam Rachuri083ada82015-08-07 14:01:05 +05305539 len = VOS_MIN(priv_data.total_len, len + 1);
5540 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda100eb322013-03-15 16:48:20 -07005541 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5542 "%s: failed to copy data to user buffer", __func__);
5543 ret = -EFAULT;
5544 goto exit;
5545 }
5546 }
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05305547#ifdef WLAN_FEATURE_PACKET_FILTERING
5548 else if (strncmp(command, "ENABLE_PKTFILTER_IPV6", 21) == 0)
5549 {
5550 tANI_U8 filterType = 0;
5551 tANI_U8 *value = command;
5552
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305553 ret = hdd_drv_cmd_validate(command, 21);
5554 if (ret)
5555 goto exit;
5556
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05305557 /* Move pointer to ahead of ENABLE_PKTFILTER_IPV6<delimiter> */
5558 value = value + 22;
5559
5560 /* Convert the value from ascii to integer */
5561 ret = kstrtou8(value, 10, &filterType);
5562 if (ret < 0)
5563 {
5564 /* If the input value is greater than max value of datatype,
5565 * then also kstrtou8 fails
5566 */
5567 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5568 "%s: kstrtou8 failed range ", __func__);
5569 ret = -EINVAL;
5570 goto exit;
5571 }
5572
5573 if (filterType != 0 && filterType != 1)
5574 {
5575 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5576 "%s: Accepted Values are 0 and 1 ", __func__);
5577 ret = -EINVAL;
5578 goto exit;
5579 }
5580 wlan_hdd_setIPv6Filter(WLAN_HDD_GET_CTX(pAdapter), filterType,
5581 pAdapter->sessionId);
5582 }
5583#endif
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305584 else if (strncmp(command, "BTCOEXMODE", 10) == 0 )
5585 {
Kiet Lamad161252014-07-22 11:23:32 -07005586 char *dhcpPhase;
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05305587 int ret;
5588
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305589 ret = hdd_drv_cmd_validate(command, 10);
5590 if (ret)
5591 goto exit;
5592
Kiet Lamad161252014-07-22 11:23:32 -07005593 dhcpPhase = command + 11;
5594 if ('1' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305595 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05305596 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07005597 FL("send DHCP START indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05305598
5599 pHddCtx->btCoexModeSet = TRUE;
Kiet Lamad161252014-07-22 11:23:32 -07005600
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05305601 ret = wlan_hdd_scan_abort(pAdapter);
5602 if (ret < 0)
5603 {
5604 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5605 FL("failed to abort existing scan %d"), ret);
5606 }
5607
Kiet Lamad161252014-07-22 11:23:32 -07005608 sme_DHCPStartInd(pHddCtx->hHal, pAdapter->device_mode,
5609 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305610 }
Kiet Lamad161252014-07-22 11:23:32 -07005611 else if ('2' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305612 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05305613 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07005614 FL("send DHCP STOP indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05305615
5616 pHddCtx->btCoexModeSet = FALSE;
Kiet Lamad161252014-07-22 11:23:32 -07005617
5618 sme_DHCPStopInd(pHddCtx->hHal, pAdapter->device_mode,
5619 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05305620 }
5621 }
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005622 else if (strncmp(command, "SCAN-ACTIVE", 11) == 0)
5623 {
Abhishek Singh58749d62016-02-03 15:27:20 +05305624 hddLog(LOG1,
5625 FL("making default scan to ACTIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05305626 pHddCtx->scan_info.scan_mode = eSIR_ACTIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005627 }
5628 else if (strncmp(command, "SCAN-PASSIVE", 12) == 0)
5629 {
Abhishek Singh58749d62016-02-03 15:27:20 +05305630 hddLog(LOG1,
5631 FL("making default scan to PASSIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05305632 pHddCtx->scan_info.scan_mode = eSIR_PASSIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07005633 }
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305634 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
5635 {
5636 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5637 char extra[32];
5638 tANI_U8 len = 0;
5639
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05305640 memset(extra, 0, sizeof(extra));
5641 ret = hdd_get_dwell_time(pCfg, command, extra, sizeof(extra), &len);
Ratnam Rachuri12d5d462015-08-07 14:10:23 +05305642 len = VOS_MIN(priv_data.total_len, len + 1);
5643 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305644 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5645 "%s: failed to copy data to user buffer", __func__);
5646 ret = -EFAULT;
5647 goto exit;
5648 }
5649 ret = len;
5650 }
5651 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
5652 {
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05305653 ret = hdd_set_dwell_time(pAdapter, command);
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05305654 }
Dundi Ravitejaae5adf42018-04-23 20:44:47 +05305655 else if (strncmp(command, "BTCGETDWELLTIME", 15) == 0)
5656 {
5657 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5658 char extra[32];
5659 tANI_U8 len = 0;
5660
5661 if (hdd_drv_cmd_validate(command, 15)) {
5662 hddLog(LOGE, FL("Invalid driver command"));
5663 return -EINVAL;
5664 }
5665
5666 memset(extra, 0, sizeof(extra));
5667 ret = hdd_btc_get_dwell_time(pCfg, command, extra,
5668 sizeof(extra), &len);
5669 len = VOS_MIN(priv_data.total_len, len + 1);
5670 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
5671 hddLog(LOGE, FL("Failed to copy data to user buffer"));
5672 ret = -EFAULT;
5673 goto exit;
5674 }
5675 ret = len;
5676 }
5677 else if (strncmp(command, "BTCSETDWELLTIME", 15) == 0)
5678 {
5679 if (hdd_drv_cmd_validate(command, 15)) {
5680 hddLog(LOGE, FL("Invalid driver command"));
5681 return -EINVAL;
5682 }
5683 ret = hdd_btc_set_dwell_time(pAdapter, command);
5684 }
5685#ifdef WLAN_AP_STA_CONCURRENCY
5686 else if (strncmp(command, "CONCGETDWELLTIME", 16) == 0)
5687 {
5688 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
5689 char extra[32];
5690 tANI_U8 len = 0;
5691
5692 if (hdd_drv_cmd_validate(command, 16)) {
5693 hddLog(LOGE, FL("Invalid driver command"));
5694 return -EINVAL;
5695 }
5696
5697 memset(extra, 0, sizeof(extra));
5698 ret = hdd_conc_get_dwell_time(pCfg, command, extra,
5699 sizeof(extra), &len);
5700 len = VOS_MIN(priv_data.total_len, len + 1);
5701 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
5702 hddLog(LOGE, FL("Failed to copy data to user buffer"));
5703 ret = -EFAULT;
5704 goto exit;
5705 }
5706 ret = len;
5707 }
5708 else if (strncmp(command, "CONCSETDWELLTIME", 16) == 0)
5709 {
5710 if (hdd_drv_cmd_validate(command, 16)) {
5711 hddLog(LOGE, FL("Invalid driver command"));
5712 return -EINVAL;
5713 }
5714 ret = hdd_conc_set_dwell_time(pAdapter, command);
5715 }
5716#endif
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005717 else if ( strncasecmp(command, "MIRACAST", 8) == 0 )
5718 {
5719 tANI_U8 filterType = 0;
5720 tANI_U8 *value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305721
5722 ret = hdd_drv_cmd_validate(command, 8);
5723 if (ret)
5724 goto exit;
5725
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005726 value = command + 9;
5727
5728 /* Convert the value from ascii to integer */
5729 ret = kstrtou8(value, 10, &filterType);
5730 if (ret < 0)
5731 {
5732 /* If the input value is greater than max value of datatype,
5733 * then also kstrtou8 fails
5734 */
5735 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5736 "%s: kstrtou8 failed range ", __func__);
5737 ret = -EINVAL;
5738 goto exit;
5739 }
5740 if ((filterType < WLAN_HDD_DRIVER_MIRACAST_CFG_MIN_VAL ) ||
5741 (filterType > WLAN_HDD_DRIVER_MIRACAST_CFG_MAX_VAL))
5742 {
5743 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5744 "%s: Accepted Values are 0 to 2. 0-Disabled, 1-Source,"
5745 " 2-Sink ", __func__);
5746 ret = -EINVAL;
5747 goto exit;
5748 }
5749 //Filtertype value should be either 0-Disabled, 1-Source, 2-sink
5750 pHddCtx->drvr_miracast = filterType;
Kaushik, Sushant96122442014-10-21 16:40:18 +05305751 pScanInfo = &pHddCtx->scan_info;
5752 if (filterType && pScanInfo != NULL &&
5753 pHddCtx->scan_info.mScanPending)
5754 {
5755 /*Miracast Session started. Abort Scan */
5756 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5757 "%s, Aborting Scan For Miracast",__func__);
5758 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
5759 eCSR_SCAN_ABORT_DEFAULT);
5760 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005761 hdd_tx_rx_pkt_cnt_stat_timer_handler(pHddCtx);
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05305762 sme_SetMiracastMode(pHddCtx->hHal, pHddCtx->drvr_miracast);
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07005763 }
Leo Chang614d2072013-08-22 14:59:44 -07005764 else if (strncmp(command, "SETMCRATE", 9) == 0)
5765 {
Leo Chang614d2072013-08-22 14:59:44 -07005766 tANI_U8 *value = command;
5767 int targetRate;
Leo Chang1f98cbd2013-10-17 15:03:52 -07005768 tSirRateUpdateInd *rateUpdate;
5769 eHalStatus status;
Leo Chang614d2072013-08-22 14:59:44 -07005770
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05305771 ret = hdd_drv_cmd_validate(command, 9);
5772 if (ret)
5773 goto exit;
5774
Leo Chang614d2072013-08-22 14:59:44 -07005775 /* Only valid for SAP mode */
5776 if (WLAN_HDD_SOFTAP != pAdapter->device_mode)
5777 {
5778 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5779 "%s: SAP mode is not running", __func__);
5780 ret = -EFAULT;
5781 goto exit;
5782 }
5783
5784 /* Move pointer to ahead of SETMCRATE<delimiter> */
5785 /* input value is in units of hundred kbps */
5786 value = value + 10;
5787 /* Convert the value from ascii to integer, decimal base */
5788 ret = kstrtouint(value, 10, &targetRate);
5789
Leo Chang1f98cbd2013-10-17 15:03:52 -07005790 rateUpdate = (tSirRateUpdateInd *)vos_mem_malloc(sizeof(tSirRateUpdateInd));
5791 if (NULL == rateUpdate)
Leo Chang614d2072013-08-22 14:59:44 -07005792 {
Leo Chang1f98cbd2013-10-17 15:03:52 -07005793 hddLog(VOS_TRACE_LEVEL_ERROR,
5794 "%s: SETMCRATE indication alloc fail", __func__);
5795 ret = -EFAULT;
5796 goto exit;
5797 }
5798 vos_mem_zero(rateUpdate, sizeof(tSirRateUpdateInd ));
5799
5800 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5801 "MC Target rate %d", targetRate);
5802 /* Ignore unicast */
5803 rateUpdate->ucastDataRate = -1;
5804 rateUpdate->mcastDataRate24GHz = targetRate;
5805 rateUpdate->mcastDataRate5GHz = targetRate;
5806 rateUpdate->mcastDataRate24GHzTxFlag = 0;
5807 rateUpdate->mcastDataRate5GHzTxFlag = 0;
5808 status = sme_SendRateUpdateInd(pHddCtx->hHal, rateUpdate);
5809 if (eHAL_STATUS_SUCCESS != status)
5810 {
5811 hddLog(VOS_TRACE_LEVEL_ERROR,
5812 "%s: SET_MC_RATE failed", __func__);
5813 vos_mem_free(rateUpdate);
5814 ret = -EFAULT;
5815 goto exit;
Leo Chang614d2072013-08-22 14:59:44 -07005816 }
5817 }
jge35567202017-06-21 16:39:38 +08005818 else if (strncmp(command, "MAXTXPOWER", 10) == 0)
5819 {
5820 int status;
5821 int txPower;
5822 eHalStatus smeStatus;
5823 tANI_U8 *value = command;
5824 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
5825 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
5826
5827 status = hdd_parse_setmaxtxpower_command(value, &txPower);
5828 if (status)
5829 {
5830 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5831 "Invalid MAXTXPOWER command ");
5832 ret = -EINVAL;
5833 goto exit;
5834 }
5835
5836 hddLog(VOS_TRACE_LEVEL_INFO, "max tx power %d selfMac: "
5837 MAC_ADDRESS_STR " bssId: " MAC_ADDRESS_STR " ",
5838 txPower, MAC_ADDR_ARRAY(selfMac),
5839 MAC_ADDR_ARRAY(bssid));
5840 smeStatus = sme_SetMaxTxPower((tHalHandle)(pHddCtx->hHal),
5841 bssid, selfMac, txPower) ;
5842 if( smeStatus != eHAL_STATUS_SUCCESS )
5843 {
5844 hddLog(VOS_TRACE_LEVEL_ERROR, "%s:Set max tx power failed",
5845 __func__);
5846 ret = -EINVAL;
5847 goto exit;
5848 }
5849
5850 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Set max tx power success",
5851 __func__);
5852 }
Rajeev79dbe4c2013-10-05 11:03:42 +05305853#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev Kumar8b373292014-01-08 20:36:55 -08005854 else if (strncmp(command, "WLS_BATCHING", 12) == 0)
Rajeev79dbe4c2013-10-05 11:03:42 +05305855 {
Rajeev Kumar8b373292014-01-08 20:36:55 -08005856 ret = hdd_handle_batch_scan_ioctl(pAdapter, &priv_data, command);
Rajeev79dbe4c2013-10-05 11:03:42 +05305857 }
5858#endif
Abhishek Singh00b71972016-01-07 10:51:04 +05305859#ifdef WLAN_FEATURE_RMC
5860 else if ((strncasecmp(command, "SETIBSSBEACONOUIDATA", 20) == 0) &&
5861 (WLAN_HDD_IBSS == pAdapter->device_mode))
5862 {
5863 int i = 0;
5864 tANI_U8 *ibss_ie;
5865 tANI_U32 command_len;
5866 tANI_U8 *value = command;
5867 tHalHandle hHal = pHddCtx->hHal;
5868 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
5869 tANI_U32 ibss_ie_length;
5870 tANI_U32 len, present;
5871 tANI_U8 *addIE;
5872 tANI_U8 *addIEData;
5873
5874 hddLog(LOG1,
5875 FL(" received command %s"),((char *) value));
5876 /* validate argument of command */
5877 if (strlen(value) <= 21)
5878 {
5879 hddLog(LOGE,
5880 FL("No arguements in command length %zu"), strlen(value));
5881 ret = -EFAULT;
5882 goto exit;
5883 }
5884
5885 /* moving to arguments of commands */
5886 value = value + 21;
5887 command_len = strlen(value);
5888
5889 /* oui_data can't be less than 3 bytes */
5890 if (command_len <= (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH))
5891 {
5892 hddLog(LOGE,
5893 FL("Invalid SETIBSSBEACONOUIDATA command length %d"),
5894 command_len);
5895 ret = -EFAULT;
5896 goto exit;
5897 }
5898 ibss_ie = vos_mem_malloc(command_len);
5899 if (!ibss_ie) {
5900 hddLog(LOGE,
5901 FL("Could not allocate memory for command length %d"),
5902 command_len);
5903 ret = -ENOMEM;
5904 goto exit;
5905 }
5906 vos_mem_zero(ibss_ie, command_len);
5907
5908 ibss_ie_length = hdd_parse_set_ibss_oui_data_command(value, ibss_ie,
5909 command_len);
5910 if (ibss_ie_length < (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH)) {
5911 hddLog(LOGE, FL("Could not parse command %s return length %d"),
5912 value, ibss_ie_length);
5913 ret = -EFAULT;
5914 vos_mem_free(ibss_ie);
5915 goto exit;
5916 }
5917
5918 hddLog(LOG1, FL("ibss_ie length %d ibss_ie:"), ibss_ie_length);
5919 while (i < ibss_ie_length)
5920 hddLog(LOG1, FL("0x%x"), ibss_ie[i++]);
5921
5922 /* Populate Vendor IE in Beacon */
5923 if ((ccmCfgGetInt(hHal,
5924 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
5925 &present)) != eHAL_STATUS_SUCCESS)
5926 {
5927 hddLog(LOGE,
5928 FL("unable to ftch WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
5929 ret = -EFAULT;
5930 vos_mem_free(ibss_ie);
5931 goto exit;
5932 }
5933
5934 addIE = vos_mem_malloc(WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
5935 if (!addIE) {
5936 hddLog(LOGE,
5937 FL("Could not allocate memory for command length %d"),
5938 command_len);
5939 vos_mem_free(ibss_ie);
5940 ret = -ENOMEM;
5941 goto exit;
5942 }
5943 vos_mem_zero(addIE, WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
5944
5945 if (present)
5946 {
5947 if ((wlan_cfgGetStrLen(pMac,
5948 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, &len)) != eSIR_SUCCESS)
5949 {
5950 hddLog(LOGE,
5951 FL("unable to fetch WNI_CFG_PROBE_RSP_BCN_ADDNIE_LEN"));
5952 ret = -EFAULT;
5953 vos_mem_free(ibss_ie);
5954 vos_mem_free(addIE);
5955 goto exit;
5956 }
5957
5958 if (len <= WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN && len &&
5959 ((len + ibss_ie_length) <=
5960 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN))
5961 {
5962 if ((ccmCfgGetStr(hHal,
5963 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, &len))
5964 != eHAL_STATUS_SUCCESS)
5965 {
5966 hddLog(LOGE,
5967 FL("unable to fetch WNI_PROBE_RSP_BCN_ADDNIE_DATA"));
5968 ret = -EFAULT;
5969 vos_mem_free(ibss_ie);
5970 vos_mem_free(addIE);
5971 goto exit;
5972 }
5973 else
5974 {
5975 /* Curruntly only WPA IE is added before Vendor IE
5976 * so we can blindly place the Vendor IE after WPA
5977 * IE. If no WPA IE found replace all with Vendor IE.
5978 */
5979 len = hdd_find_ibss_wpa_ie_pos(addIE, len);
5980 }
5981 }
5982 else
5983 {
5984 hddLog(LOGE,
5985 FL("IE len exceed limit len %d,ibss_ie_length %d "),
5986 len, ibss_ie_length);
5987 ret = -EFAULT;
5988 vos_mem_free(addIE);
5989 vos_mem_free(ibss_ie);
5990 goto exit;
5991 }
5992 }
5993 else {
5994 len = 0;
5995 }
5996
5997 vos_mem_copy (addIE + len , ibss_ie, ibss_ie_length);
5998 len += ibss_ie_length;
5999
6000 if (ccmCfgSetStr(hHal,
6001 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, len, NULL,
6002 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
6003 {
6004 hddLog(LOGE,
6005 FL("unable to set WNI_CFG_PRBE_RSP_BCN_ADDNIE_DATA"));
6006 ret = -EFAULT;
6007 vos_mem_free(ibss_ie);
6008 vos_mem_free(addIE);
6009 goto exit;
6010 }
6011 vos_mem_free(addIE);
6012 if (ccmCfgSetInt(hHal,
6013 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
6014 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
6015 {
6016 hddLog(LOGE,
6017 FL("unble to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
6018 ret = -EFAULT;
6019 vos_mem_free(ibss_ie);
6020 goto exit;
6021 }
6022
6023 /* Populate Vendor IE in probe resp */
6024 if ((ccmCfgGetInt(hHal,
6025 WNI_CFG_PROBE_RSP_ADDNIE_FLAG,
6026 &present)) != eHAL_STATUS_SUCCESS)
6027 {
6028 hddLog(LOGE,
6029 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
6030 ret = -EFAULT;
6031 vos_mem_free(ibss_ie);
6032 goto exit;
6033 }
6034
6035 addIEData = vos_mem_malloc(WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
6036 if (!addIEData) {
6037 hddLog(LOGE,
6038 FL("Could not allocate memory for command length %d"),
6039 command_len);
6040 vos_mem_free(ibss_ie);
6041 ret = -ENOMEM;
6042 goto exit;
6043 }
6044 vos_mem_zero(addIEData, WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
6045
6046 if (present) {
6047 if (eSIR_SUCCESS != wlan_cfgGetStrLen(pMac,
6048 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, &len)) {
6049 hddLog(LOGE,
6050 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6051 ret = -EFAULT;
6052 vos_mem_free(ibss_ie);
6053 vos_mem_free(addIEData);
6054 goto exit;
6055 }
6056 if (len < WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN && len &&
6057 (ibss_ie_length + len) <=
6058 WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN) {
6059
6060 if ((ccmCfgGetStr(hHal,
6061 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, addIEData, &len))
6062 != eHAL_STATUS_SUCCESS) {
6063 hddLog(LOGE,
6064 FL("unable fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6065 ret = -EFAULT;
6066 vos_mem_free(ibss_ie);
6067 vos_mem_free(addIEData);
6068 goto exit;
6069 }
6070 else {
6071 /* Curruntly only WPA IE is added before Vendor IE
6072 * so we can blindly place the Vendor IE after WPA
6073 * IE. If no WPA IE found replace all with Vendor IE.
6074 */
6075 len = hdd_find_ibss_wpa_ie_pos(addIEData, len);
6076 }
6077 }
6078 else
6079 {
6080 hddLog(LOGE,
6081 FL("IE len exceed limit len %d,ibss_ie_length %d "),
6082 len, ibss_ie_length);
6083 ret = -EFAULT;
6084 vos_mem_free(addIEData);
6085 vos_mem_free(ibss_ie);
6086 goto exit;
6087 }
6088 } /* probe rsp ADD IE present */
6089 else {
6090 /* probe rsp add IE is not present */
6091 len = 0;
6092 }
6093
6094 vos_mem_copy(addIEData +len , ibss_ie, ibss_ie_length);
6095 len += ibss_ie_length;
6096
6097 vos_mem_free(ibss_ie);
6098
6099 if (ccmCfgSetStr(hHal,
6100 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
6101 (tANI_U8*)(addIEData),
6102 len, NULL,
6103 eANI_BOOLEAN_FALSE)
6104 == eHAL_STATUS_FAILURE) {
6105 hddLog(LOGE,
6106 FL("unable to copy to WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
6107 ret = -EFAULT;
6108 vos_mem_free(addIEData);
6109 goto exit;
6110 }
6111 vos_mem_free(addIEData);
6112 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6113 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
6114 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6115 {
6116 hddLog(LOGE,
6117 FL("unable to copy WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
6118 ret = -EFAULT;
6119 goto exit;
6120 }
6121 }
6122 else if (strncasecmp(command, "SETRMCENABLE", 12) == 0)
6123 {
6124 tANI_U8 *value = command;
6125 tANI_U8 ucRmcEnable = 0;
6126 int status;
6127
6128 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6129 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6130 {
6131 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6132 "Received SETRMCENABLE command in invalid mode %d "
6133 "SETRMCENABLE command is only allowed in IBSS or SOFTAP mode",
6134 pAdapter->device_mode);
6135 ret = -EINVAL;
6136 goto exit;
6137 }
6138
6139 status = hdd_parse_setrmcenable_command(value, &ucRmcEnable);
6140 if (status)
6141 {
6142 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6143 "Invalid SETRMCENABLE command ");
6144 ret = -EINVAL;
6145 goto exit;
6146 }
6147
6148 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6149 "%s: ucRmcEnable %d ", __func__, ucRmcEnable);
6150
6151 if (TRUE == ucRmcEnable)
6152 {
6153 status = sme_EnableRMC( (tHalHandle)(pHddCtx->hHal),
6154 pAdapter->sessionId );
6155 }
6156 else if(FALSE == ucRmcEnable)
6157 {
6158 status = sme_DisableRMC( (tHalHandle)(pHddCtx->hHal),
6159 pAdapter->sessionId );
6160 }
6161 else
6162 {
6163 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6164 "Invalid SETRMCENABLE command %d", ucRmcEnable);
6165 ret = -EINVAL;
6166 goto exit;
6167 }
6168
6169 if (VOS_STATUS_SUCCESS != status)
6170 {
6171 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6172 "%s: SETRMC %d failed status %d", __func__, ucRmcEnable,
6173 status);
6174 ret = -EINVAL;
6175 goto exit;
6176 }
6177 }
6178 else if (strncasecmp(command, "SETRMCACTIONPERIOD", 18) == 0)
6179 {
6180 tANI_U8 *value = command;
6181 tANI_U32 uActionPeriod = 0;
6182 int status;
6183
6184 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6185 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6186 {
6187 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6188 "Received SETRMC command in invalid mode %d "
6189 "SETRMC command is only allowed in IBSS or SOFTAP mode",
6190 pAdapter->device_mode);
6191 ret = -EINVAL;
6192 goto exit;
6193 }
6194
6195 status = hdd_parse_setrmcactionperiod_command(value, &uActionPeriod);
6196 if (status)
6197 {
6198 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6199 "Invalid SETRMCACTIONPERIOD command ");
6200 ret = -EINVAL;
6201 goto exit;
6202 }
6203
6204 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6205 "%s: uActionPeriod %d ", __func__, uActionPeriod);
6206
6207 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY,
6208 uActionPeriod, NULL, eANI_BOOLEAN_FALSE))
6209 {
6210 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6211 "%s: Could not set SETRMCACTIONPERIOD %d", __func__, uActionPeriod);
6212 ret = -EINVAL;
6213 goto exit;
6214 }
6215
6216 }
6217 else if (strncasecmp(command, "GETIBSSPEERINFOALL", 18) == 0)
6218 {
6219 /* Peer Info All Command */
6220 int status = eHAL_STATUS_SUCCESS;
6221 hdd_station_ctx_t *pHddStaCtx = NULL;
6222 char *extra = NULL;
6223 int idx = 0, length = 0;
6224 v_MACADDR_t *macAddr;
6225 v_U32_t txRateMbps = 0, numOfBytestoPrint = 0;
6226
6227 if (WLAN_HDD_IBSS == pAdapter->device_mode)
6228 {
6229 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6230 }
6231 else
6232 {
6233 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6234 "%s: pAdapter is not valid for this device mode",
6235 __func__);
6236 ret = -EINVAL;
6237 goto exit;
6238 }
6239
6240 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6241 "%s: Received GETIBSSPEERINFOALL Command", __func__);
6242
6243
6244 /* Handle the command */
6245 status = hdd_cfg80211_get_ibss_peer_info_all(pAdapter);
6246 if (VOS_STATUS_SUCCESS == status)
6247 {
6248 /* The variable extra needed to be allocated on the heap since
6249 * amount of memory required to copy the data for 32 devices
6250 * exceeds the size of 1024 bytes of default stack size. On
6251 * 64 bit devices, the default max stack size of 2048 bytes
6252 */
6253 extra = kmalloc(WLAN_MAX_BUF_SIZE, GFP_KERNEL);
6254
6255 if (NULL == extra)
6256 {
6257 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6258 "%s:kmalloc failed", __func__);
6259 ret = -EINVAL;
6260 goto exit;
6261 }
6262
6263 /* Copy number of stations */
6264 length = scnprintf( extra, WLAN_MAX_BUF_SIZE, "%d ",
6265 pHddStaCtx->ibss_peer_info.numIBSSPeers);
6266 numOfBytestoPrint = length;
6267 for (idx = 0; idx < pHddStaCtx->ibss_peer_info.numIBSSPeers; idx++)
6268 {
6269 macAddr =
6270 hdd_wlan_get_ibss_mac_addr_from_staid(pAdapter,
6271 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
6272 if (NULL != macAddr)
6273 {
6274 txRateMbps =
6275 ((pHddStaCtx->ibss_peer_info.ibssPeerList[idx].txRate)*500*1000)/1000000;
6276
6277 length += scnprintf( (extra + length), WLAN_MAX_BUF_SIZE - length,
6278 "%02x:%02x:%02x:%02x:%02x:%02x %d %d ",
6279 macAddr->bytes[0], macAddr->bytes[1], macAddr->bytes[2],
6280 macAddr->bytes[3], macAddr->bytes[4], macAddr->bytes[5],
6281 (int)txRateMbps,
6282 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[idx].rssi);
6283 }
6284 else
6285 {
6286 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6287 "%s: MAC ADDR is NULL for staIdx: %d", __func__,
6288 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
6289 }
6290
6291 /*
6292 * VOS_TRACE() macro has limitation of 512 bytes for the print
6293 * buffer. Hence printing the data in two chunks. The first chunk
6294 * will have the data for 16 devices and the second chunk will
6295 * have the rest.
6296 */
6297 if (idx < NUM_OF_STA_DATA_TO_PRINT)
6298 {
6299 numOfBytestoPrint = length;
6300 }
6301 }
6302
6303 /*
6304 * Copy the data back into buffer, if the data to copy is
6305 * morethan 512 bytes than we will split the data and do
6306 * it in two shots
6307 */
6308 if (copy_to_user(priv_data.buf, extra, numOfBytestoPrint))
6309 {
6310 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6311 "%s: Copy into user data buffer failed ", __func__);
6312 ret = -EFAULT;
6313 kfree(extra);
6314 goto exit;
6315 }
6316 priv_data.buf[numOfBytestoPrint] = '\0';
6317 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6318 "%s", priv_data.buf);
6319
6320 if (length > numOfBytestoPrint)
6321 {
6322 if (copy_to_user(priv_data.buf + numOfBytestoPrint,
6323 extra + numOfBytestoPrint,
6324 length - numOfBytestoPrint + 1))
6325 {
6326 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6327 "%s: Copy into user data buffer failed ", __func__);
6328 ret = -EFAULT;
6329 kfree(extra);
6330 goto exit;
6331 }
6332 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6333 "%s", &priv_data.buf[numOfBytestoPrint]);
6334 }
6335
6336 /* Free temporary buffer */
6337 kfree(extra);
6338 }
6339
6340 else
6341 {
6342 /* Command failed, log error */
6343 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6344 "%s: GETIBSSPEERINFOALL command failed with status code %d",
6345 __func__, status);
6346 ret = -EINVAL;
6347 goto exit;
6348 }
6349 ret = 0;
6350 }
6351 else if(strncasecmp(command, "GETIBSSPEERINFO", 15) == 0)
6352 {
6353 /* Peer Info <Peer Addr> command */
6354 tANI_U8 *value = command;
6355 VOS_STATUS status;
6356 hdd_station_ctx_t *pHddStaCtx = NULL;
6357 char extra[128] = { 0 };
6358 v_U32_t length = 0;
6359 v_U8_t staIdx = 0;
6360 v_U32_t txRateMbps = 0;
6361 v_MACADDR_t peerMacAddr;
6362
6363 if (WLAN_HDD_IBSS == pAdapter->device_mode)
6364 {
6365 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6366 }
6367 else
6368 {
6369 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6370 "%s: pAdapter is not valid for this device mode",
6371 __func__);
6372 ret = -EINVAL;
6373 goto exit;
6374 }
6375
6376 /* if there are no peers, no need to continue with the command */
6377 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6378 "%s: Received GETIBSSPEERINFO Command", __func__);
6379
6380 if (eConnectionState_IbssConnected != pHddStaCtx->conn_info.connState)
6381 {
6382 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6383 "%s:No IBSS Peers coalesced", __func__);
6384 ret = -EINVAL;
6385 goto exit;
6386 }
6387
6388 /* Parse the incoming command buffer */
6389 status = hdd_parse_get_ibss_peer_info(value, &peerMacAddr);
6390 if (VOS_STATUS_SUCCESS != status)
6391 {
6392 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6393 "%s: Invalid GETIBSSPEERINFO command", __func__);
6394 ret = -EINVAL;
6395 goto exit;
6396 }
6397
6398 /* Get station index for the peer mac address */
6399 hdd_Ibss_GetStaId(pHddStaCtx, &peerMacAddr, &staIdx);
6400
6401 if (staIdx > HDD_MAX_NUM_IBSS_STA)
6402 {
6403 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6404 "%s: Invalid StaIdx %d returned", __func__, staIdx);
6405 ret = -EINVAL;
6406 goto exit;
6407 }
6408
6409 /* Handle the command */
6410 status = hdd_cfg80211_get_ibss_peer_info(pAdapter, staIdx);
6411 if (VOS_STATUS_SUCCESS == status)
6412 {
6413 v_U32_t txRate = pHddStaCtx->ibss_peer_info.ibssPeerList[0].txRate;
6414 txRateMbps = (txRate * 500 * 1000)/1000000;
6415
6416 length = scnprintf( extra, sizeof(extra), "%d %d", (int)txRateMbps,
6417 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[0].rssi);
6418
6419 /* Copy the data back into buffer */
6420 if (copy_to_user(priv_data.buf, &extra, length+ 1))
6421 {
6422 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6423 "%s: copy data to user buffer failed GETIBSSPEERINFO command",
6424 __func__);
6425 ret = -EFAULT;
6426 goto exit;
6427 }
6428 }
6429 else
6430 {
6431 /* Command failed, log error */
6432 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6433 "%s: GETIBSSPEERINFO command failed with status code %d",
6434 __func__, status);
6435 ret = -EINVAL;
6436 goto exit;
6437 }
6438
6439 /* Success ! */
6440 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
6441 "%s", priv_data.buf);
6442 ret = 0;
6443 }
6444 else if (strncasecmp(command, "SETRMCTXRATE", 12) == 0)
6445 {
6446 tANI_U8 *value = command;
6447 tANI_U32 uRate = 0;
6448 tTxrateinfoflags txFlags = 0;
6449 tSirRateUpdateInd *rateUpdateParams;
6450 int status;
6451
6452 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
6453 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
6454 {
6455 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6456 "Received SETRMCTXRATE command in invalid mode %d "
6457 "SETRMC command is only allowed in IBSS or SOFTAP mode",
6458 pAdapter->device_mode);
6459 ret = -EINVAL;
6460 goto exit;
6461 }
6462
6463 status = hdd_parse_setrmcrate_command(value, &uRate, &txFlags);
6464 if (status)
6465 {
6466 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6467 "Invalid SETRMCTXRATE command ");
6468 ret = -EINVAL;
6469 goto exit;
6470 }
6471
6472 rateUpdateParams = vos_mem_malloc(sizeof(tSirRateUpdateInd));
6473 if (NULL == rateUpdateParams)
6474 {
6475 ret = -EINVAL;
6476 goto exit;
6477 }
6478
6479 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6480 "%s: uRate %d ", __func__, uRate);
6481
6482 vos_mem_zero(rateUpdateParams, sizeof(tSirRateUpdateInd ));
6483
6484 /* -1 implies ignore this param */
6485 rateUpdateParams->ucastDataRate = -1;
6486
6487 /*
6488 * Fill the user specifieed RMC rate param
6489 * and the derived tx flags.
6490 */
6491 rateUpdateParams->rmcDataRate = uRate;
6492 rateUpdateParams->rmcDataRateTxFlag = txFlags;
6493
6494 status = sme_SendRateUpdateInd((tHalHandle)(pHddCtx->hHal), rateUpdateParams);
6495 }
6496 else if (strncasecmp(command, "SETIBSSTXFAILEVENT", 18) == 0 )
6497 {
6498 char *value;
6499 tANI_U8 tx_fail_count = 0;
6500 tANI_U16 pid = 0;
6501
6502 value = command;
6503
6504 ret = hdd_ParseIBSSTXFailEventParams(value, &tx_fail_count, &pid);
6505
6506 if (0 != ret)
6507 {
6508 hddLog(VOS_TRACE_LEVEL_INFO,
6509 "%s: Failed to parse SETIBSSTXFAILEVENT arguments",
6510 __func__);
6511 goto exit;
6512 }
6513
6514 hddLog(VOS_TRACE_LEVEL_INFO, "%s: tx_fail_cnt=%hhu, pid=%hu",
6515 __func__, tx_fail_count, pid);
6516
6517 if (0 == tx_fail_count)
6518 {
6519 // Disable TX Fail Indication
6520 if (eHAL_STATUS_SUCCESS ==
6521 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
6522 tx_fail_count,
6523 NULL))
6524 {
6525 cesium_pid = 0;
6526 }
6527 else
6528 {
6529 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6530 "%s: failed to disable TX Fail Event ", __func__);
6531 ret = -EINVAL;
6532 }
6533 }
6534 else
6535 {
6536 if (eHAL_STATUS_SUCCESS ==
6537 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
6538 tx_fail_count,
6539 (void*)hdd_tx_fail_ind_callback))
6540 {
6541 cesium_pid = pid;
6542 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6543 "%s: Registered Cesium pid %u", __func__,
6544 cesium_pid);
6545 }
6546 else
6547 {
6548 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6549 "%s: Failed to enable TX Fail Monitoring", __func__);
6550 ret = -EINVAL;
6551 }
6552 }
6553 }
6554
6555#endif /* WLAN_FEATURE_RMC */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006556#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006557 else if (strncmp(command, "SETCCXROAMSCANCHANNELS", 22) == 0)
6558 {
6559 tANI_U8 *value = command;
6560 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
6561 tANI_U8 numChannels = 0;
6562 eHalStatus status = eHAL_STATUS_SUCCESS;
6563
6564 status = hdd_parse_channellist(value, ChannelList, &numChannels);
6565 if (eHAL_STATUS_SUCCESS != status)
6566 {
6567 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6568 "%s: Failed to parse channel list information", __func__);
6569 ret = -EINVAL;
6570 goto exit;
6571 }
6572
6573 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
6574 {
6575 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6576 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
6577 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
6578 ret = -EINVAL;
6579 goto exit;
6580 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006581 status = sme_SetEseRoamScanChannelList((tHalHandle)(pHddCtx->hHal),
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006582 ChannelList,
6583 numChannels);
6584 if (eHAL_STATUS_SUCCESS != status)
6585 {
6586 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6587 "%s: Failed to update channel list information", __func__);
6588 ret = -EINVAL;
6589 goto exit;
6590 }
6591 }
6592 else if (strncmp(command, "GETTSMSTATS", 11) == 0)
6593 {
6594 tANI_U8 *value = command;
6595 char extra[128] = {0};
6596 int len = 0;
6597 tANI_U8 tid = 0;
6598 hdd_station_ctx_t *pHddStaCtx = NULL;
6599 tAniTrafStrmMetrics tsmMetrics;
6600 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6601
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306602 ret = hdd_drv_cmd_validate(command, 11);
6603 if (ret)
6604 goto exit;
6605
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006606 /* if not associated, return error */
6607 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6608 {
6609 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:Not associated!",__func__);
6610 ret = -EINVAL;
6611 goto exit;
6612 }
6613
6614 /* Move pointer to ahead of GETTSMSTATS<delimiter> */
6615 value = value + 12;
6616 /* Convert the value from ascii to integer */
6617 ret = kstrtou8(value, 10, &tid);
6618 if (ret < 0)
6619 {
6620 /* If the input value is greater than max value of datatype, then also
6621 kstrtou8 fails */
6622 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6623 "%s: kstrtou8 failed range [%d - %d]", __func__,
6624 TID_MIN_VALUE,
6625 TID_MAX_VALUE);
6626 ret = -EINVAL;
6627 goto exit;
6628 }
6629
6630 if ((tid < TID_MIN_VALUE) || (tid > TID_MAX_VALUE))
6631 {
6632 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6633 "tid value %d is out of range"
6634 " (Min: %d Max: %d)", tid,
6635 TID_MIN_VALUE,
6636 TID_MAX_VALUE);
6637 ret = -EINVAL;
6638 goto exit;
6639 }
6640
6641 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6642 "%s: Received Command to get tsm stats tid = %d", __func__, tid);
6643
6644 if (VOS_STATUS_SUCCESS != hdd_get_tsm_stats(pAdapter, tid, &tsmMetrics))
6645 {
6646 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6647 "%s: failed to get tsm stats", __func__);
6648 ret = -EFAULT;
6649 goto exit;
6650 }
6651
6652 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6653 "UplinkPktQueueDly(%d)\n"
6654 "UplinkPktQueueDlyHist[0](%d)\n"
6655 "UplinkPktQueueDlyHist[1](%d)\n"
6656 "UplinkPktQueueDlyHist[2](%d)\n"
6657 "UplinkPktQueueDlyHist[3](%d)\n"
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05306658 "UplinkPktTxDly(%u)\n"
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006659 "UplinkPktLoss(%d)\n"
6660 "UplinkPktCount(%d)\n"
6661 "RoamingCount(%d)\n"
6662 "RoamingDly(%d)", tsmMetrics.UplinkPktQueueDly,
6663 tsmMetrics.UplinkPktQueueDlyHist[0],
6664 tsmMetrics.UplinkPktQueueDlyHist[1],
6665 tsmMetrics.UplinkPktQueueDlyHist[2],
6666 tsmMetrics.UplinkPktQueueDlyHist[3],
6667 tsmMetrics.UplinkPktTxDly, tsmMetrics.UplinkPktLoss,
6668 tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount, tsmMetrics.RoamingDly);
6669
6670 /* Output TSM stats is of the format
6671 GETTSMSTATS [PktQueueDly] [PktQueueDlyHist[0]]:[PktQueueDlyHist[1]] ...[RoamingDly]
6672 eg., GETTSMSTATS 10 1:0:0:161 20 1 17 8 39800 */
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006673 len = scnprintf(extra, sizeof(extra), "%s %d %d:%d:%d:%d %u %d %d %d %d", command,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006674 tsmMetrics.UplinkPktQueueDly, tsmMetrics.UplinkPktQueueDlyHist[0],
6675 tsmMetrics.UplinkPktQueueDlyHist[1], tsmMetrics.UplinkPktQueueDlyHist[2],
6676 tsmMetrics.UplinkPktQueueDlyHist[3], tsmMetrics.UplinkPktTxDly,
6677 tsmMetrics.UplinkPktLoss, tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount,
6678 tsmMetrics.RoamingDly);
6679
Ratnam Rachurid53009c2015-08-07 13:59:00 +05306680 len = VOS_MIN(priv_data.total_len, len + 1);
6681 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006682 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6683 "%s: failed to copy data to user buffer", __func__);
6684 ret = -EFAULT;
6685 goto exit;
6686 }
6687 }
6688 else if (strncmp(command, "SETCCKMIE", 9) == 0)
6689 {
6690 tANI_U8 *value = command;
6691 tANI_U8 *cckmIe = NULL;
6692 tANI_U8 cckmIeLen = 0;
6693 eHalStatus status = eHAL_STATUS_SUCCESS;
6694
6695 status = hdd_parse_get_cckm_ie(value, &cckmIe, &cckmIeLen);
6696 if (eHAL_STATUS_SUCCESS != status)
6697 {
6698 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6699 "%s: Failed to parse cckm ie data", __func__);
6700 ret = -EINVAL;
6701 goto exit;
6702 }
6703
6704 if (cckmIeLen > DOT11F_IE_RSN_MAX_LEN)
6705 {
6706 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6707 "%s: CCKM Ie input length is more than max[%d]", __func__,
6708 DOT11F_IE_RSN_MAX_LEN);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006709 vos_mem_free(cckmIe);
6710 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006711 ret = -EINVAL;
6712 goto exit;
6713 }
6714 sme_SetCCKMIe((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, cckmIe, cckmIeLen);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006715 vos_mem_free(cckmIe);
6716 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006717 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006718 else if (strncmp(command, "CCXBEACONREQ", 12) == 0)
6719 {
6720 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006721 tCsrEseBeaconReq eseBcnReq;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006722 eHalStatus status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07006723
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006724 status = hdd_parse_ese_beacon_req(value, &eseBcnReq);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006725 if (eHAL_STATUS_SUCCESS != status)
6726 {
6727 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006728 "%s: Failed to parse ese beacon req", __func__);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006729 ret = -EINVAL;
6730 goto exit;
6731 }
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07006732 if (!hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))) {
6733 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not associated"));
6734 hdd_indicateEseBcnReportNoResults (pAdapter,
6735 eseBcnReq.bcnReq[0].measurementToken,
6736 0x02, //BIT(1) set for measurement done
6737 0); // no BSS
6738 goto exit;
6739 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006740
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006741 status = sme_SetEseBeaconRequest((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, &eseBcnReq);
6742 if (eHAL_STATUS_SUCCESS != status)
6743 {
6744 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6745 "%s: sme_SetEseBeaconRequest failed (%d)", __func__, status);
6746 ret = -EINVAL;
6747 goto exit;
6748 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006749 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006750#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
c_hpothu92367912014-05-01 15:18:17 +05306751 else if (strncmp(command, "GETBCNMISSRATE", 14) == 0)
6752 {
6753 eHalStatus status;
6754 char buf[32], len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306755 void *cookie;
6756 struct hdd_request *request;
6757 struct bcn_miss_rate_priv *priv;
6758 static const struct hdd_request_params params = {
6759 .priv_size = sizeof(*priv),
6760 .timeout_ms = WLAN_WAIT_TIME_STATS,
6761 };
c_hpothu92367912014-05-01 15:18:17 +05306762
6763 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6764
6765 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6766 {
6767 hddLog(VOS_TRACE_LEVEL_WARN,
6768 FL("GETBCNMISSRATE: STA is not in connected state"));
6769 ret = -1;
6770 goto exit;
6771 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306772 request = hdd_request_alloc(&params);
6773 if (!request) {
6774 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
6775 ret = -ENOMEM;
6776 goto exit;
6777 }
6778 cookie = hdd_request_cookie(request);
6779 priv = hdd_request_priv(request);
6780 priv->bcn_miss_rate = -1;
c_hpothu92367912014-05-01 15:18:17 +05306781
6782 status = sme_getBcnMissRate((tHalHandle)(pHddCtx->hHal),
6783 pAdapter->sessionId,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306784 (void *)get_bcn_miss_rate_cb,
6785 cookie);
c_hpothu92367912014-05-01 15:18:17 +05306786 if( eHAL_STATUS_SUCCESS != status)
6787 {
6788 hddLog(VOS_TRACE_LEVEL_INFO,
6789 FL("GETBCNMISSRATE: fail to post WDA cmd"));
6790 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306791 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306792 }
6793
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306794 ret = hdd_request_wait_for_response(request);
6795 if(ret)
c_hpothu92367912014-05-01 15:18:17 +05306796 {
6797 hddLog(VOS_TRACE_LEVEL_ERROR,
6798 FL("failed to wait on bcnMissRateComp %d"), ret);
6799
c_hpothu92367912014-05-01 15:18:17 +05306800 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306801 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306802 }
6803
6804 hddLog(VOS_TRACE_LEVEL_INFO,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306805 FL("GETBCNMISSRATE: bcnMissRate: %d"), priv->bcn_miss_rate);
c_hpothu92367912014-05-01 15:18:17 +05306806
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306807 if (priv->bcn_miss_rate == -1) {
6808 ret = -EFAULT;
6809 goto free_bcn_miss_rate_req;
6810 }
6811
6812 len = snprintf(buf, sizeof(buf), "GETBCNMISSRATE %d",
6813 priv->bcn_miss_rate);
c_hpothu92367912014-05-01 15:18:17 +05306814 if (copy_to_user(priv_data.buf, &buf, len + 1))
6815 {
6816 hddLog(VOS_TRACE_LEVEL_ERROR,
6817 "%s: failed to copy data to user buffer", __func__);
6818 ret = -EFAULT;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306819 goto free_bcn_miss_rate_req;
c_hpothu92367912014-05-01 15:18:17 +05306820 }
6821 ret = len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306822
6823free_bcn_miss_rate_req:
6824 hdd_request_put(request);
c_hpothu92367912014-05-01 15:18:17 +05306825 }
Atul Mittal87ec2422014-09-24 13:12:50 +05306826#ifdef FEATURE_WLAN_TDLS
6827 else if (strncmp(command, "TDLSSECONDARYCHANNELOFFSET", 26) == 0) {
6828 tANI_U8 *value = command;
6829 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306830
6831 ret = hdd_drv_cmd_validate(command, 26);
6832 if (ret)
6833 goto exit;
6834
Atul Mittal87ec2422014-09-24 13:12:50 +05306835 /* Move pointer to ahead of TDLSOFFCH*/
6836 value += 26;
c_manjeebbc40212015-12-08 13:52:59 +05306837 if (!(sscanf(value, "%d", &set_value))) {
6838 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6839 FL("No input identified"));
6840 ret = -EINVAL;
6841 goto exit;
6842 }
6843
Atul Mittal87ec2422014-09-24 13:12:50 +05306844 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6845 "%s: Tdls offchannel offset:%d",
6846 __func__, set_value);
6847 ret = iw_set_tdlssecoffchanneloffset(pHddCtx, set_value);
6848 if (ret < 0)
6849 {
6850 ret = -EINVAL;
6851 goto exit;
6852 }
6853
6854 } else if (strncmp(command, "TDLSOFFCHANNELMODE", 18) == 0) {
6855 tANI_U8 *value = command;
6856 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306857
6858 ret = hdd_drv_cmd_validate(command, 18);
6859 if (ret)
6860 goto exit;
6861
Atul Mittal87ec2422014-09-24 13:12:50 +05306862 /* Move pointer to ahead of tdlsoffchnmode*/
6863 value += 18;
c_manjee82323892015-12-08 12:40:34 +05306864 ret = sscanf(value, "%d", &set_value);
6865 if (ret != 1) {
6866 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6867 FL("No input identified"));
6868 ret = -EINVAL;
6869 goto exit;
6870 }
Atul Mittal87ec2422014-09-24 13:12:50 +05306871 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6872 "%s: Tdls offchannel mode:%d",
6873 __func__, set_value);
6874 ret = iw_set_tdlsoffchannelmode(pAdapter, set_value);
6875 if (ret < 0)
6876 {
6877 ret = -EINVAL;
6878 goto exit;
6879 }
6880 } else if (strncmp(command, "TDLSOFFCHANNEL", 14) == 0) {
6881 tANI_U8 *value = command;
6882 int set_value;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306883
6884 ret = hdd_drv_cmd_validate(command, 14);
6885 if (ret)
6886 goto exit;
6887
Atul Mittal87ec2422014-09-24 13:12:50 +05306888 /* Move pointer to ahead of TDLSOFFCH*/
6889 value += 14;
c_manjeef6ccaf52015-12-08 11:52:11 +05306890 ret = sscanf(value, "%d", &set_value);
6891 if (ret != 1) {
6892 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6893 "Wrong value is given for hdd_set_tdls_offchannel");
6894 ret = -EINVAL;
6895 goto exit;
6896 }
6897
Atul Mittal87ec2422014-09-24 13:12:50 +05306898 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6899 "%s: Tdls offchannel num: %d",
6900 __func__, set_value);
6901 ret = iw_set_tdlsoffchannel(pHddCtx, set_value);
6902 if (ret < 0)
6903 {
6904 ret = -EINVAL;
6905 goto exit;
6906 }
6907 }
6908#endif
Satyanarayana Dash72806012014-12-02 14:30:08 +05306909 else if (strncmp(command, "GETFWSTATS", 10) == 0)
6910 {
6911 eHalStatus status;
6912 char *buf = NULL;
6913 char len;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306914 tSirFwStatsResult *fwStatsRsp = &(pAdapter->fwStatsRsp),
6915 *fw_stats_result;
Satyanarayana Dash72806012014-12-02 14:30:08 +05306916 tANI_U8 *ptr = command;
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306917 int stats;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306918 void *cookie;
6919 struct hdd_request *request;
6920 struct fw_stats_priv *priv;
6921 static const struct hdd_request_params params = {
6922 .priv_size = sizeof(*priv),
6923 .timeout_ms = WLAN_WAIT_TIME_STATS,
6924 };
Satyanarayana Dash72806012014-12-02 14:30:08 +05306925
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05306926 ret = hdd_drv_cmd_validate(command, 10);
6927 if (ret)
6928 goto exit;
6929
6930 stats = *(ptr + 11) - '0';
Satyanarayana Dash72806012014-12-02 14:30:08 +05306931 hddLog(VOS_TRACE_LEVEL_INFO, FL("stats = %d "),stats);
6932 if (!IS_FEATURE_FW_STATS_ENABLE)
6933 {
6934 hddLog(VOS_TRACE_LEVEL_INFO,
6935 FL("Get Firmware stats feature not supported"));
6936 ret = -EINVAL;
6937 goto exit;
6938 }
6939
6940 if (FW_STATS_MAX <= stats || 0 >= stats)
6941 {
6942 hddLog(VOS_TRACE_LEVEL_INFO,
6943 FL(" stats %d not supported"),stats);
6944 ret = -EINVAL;
6945 goto exit;
6946 }
6947
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306948 request = hdd_request_alloc(&params);
6949 if (!request) {
6950 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
6951 ret = -ENOMEM;
6952 goto exit;
6953 }
6954 cookie = hdd_request_cookie(request);
6955
Satyanarayana Dash72806012014-12-02 14:30:08 +05306956 status = sme_GetFwStats( (tHalHandle)pHddCtx->hHal, stats,
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306957 cookie, hdd_fw_stats_cb);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306958 if (eHAL_STATUS_SUCCESS != status)
6959 {
6960 hddLog(VOS_TRACE_LEVEL_ERROR,
6961 FL(" fail to post WDA cmd status = %d"), status);
6962 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306963 hdd_request_put(request);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306964 goto exit;
6965 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306966 ret = hdd_request_wait_for_response(request);
6967 if (ret)
Satyanarayana Dash72806012014-12-02 14:30:08 +05306968 {
6969 hddLog(VOS_TRACE_LEVEL_ERROR,
6970 FL("failed to wait on GwtFwstats"));
Satyanarayana Dash72806012014-12-02 14:30:08 +05306971 ret = -EINVAL;
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306972 hdd_request_put(request);
Satyanarayana Dash72806012014-12-02 14:30:08 +05306973 goto exit;
6974 }
Hanumanth Reddy Pothula7aa4bea2018-04-09 17:19:03 +05306975
6976 priv = hdd_request_priv(request);
6977 fw_stats_result = priv->fw_stats;
6978 fwStatsRsp->type = 0;
6979 if (NULL != fw_stats_result)
6980 {
6981 switch (fw_stats_result->type )
6982 {
6983 case FW_UBSP_STATS:
6984 {
6985 tSirUbspFwStats *stats =
6986 &fwStatsRsp->fwStatsData.ubspStats;
6987 memcpy(fwStatsRsp, fw_stats_result,
6988 sizeof(tSirFwStatsResult));
6989 hddLog(VOS_TRACE_LEVEL_INFO,
6990 FL("ubsp_enter_cnt = %d ubsp_jump_ddr_cnt = %d"),
6991 stats->ubsp_enter_cnt,
6992 stats->ubsp_jump_ddr_cnt);
6993 }
6994 break;
6995
6996 default:
6997 {
6998 hddLog(VOS_TRACE_LEVEL_ERROR,
6999 FL("No handling for stats type %d"),
7000 fw_stats_result->type);
7001 }
7002 }
7003 }
7004 hdd_request_put(request);
7005
Satyanarayana Dash72806012014-12-02 14:30:08 +05307006 if (fwStatsRsp->type)
7007 {
7008 buf = kmalloc(FW_STATE_RSP_LEN, GFP_KERNEL);
7009 if (!buf)
7010 {
7011 hddLog(VOS_TRACE_LEVEL_ERROR,
7012 FL(" failed to allocate memory"));
7013 ret = -ENOMEM;
7014 goto exit;
7015 }
7016 switch( fwStatsRsp->type )
7017 {
7018 case FW_UBSP_STATS:
7019 {
7020 len = snprintf(buf, FW_STATE_RSP_LEN,
7021 "GETFWSTATS: ubsp_enter_cnt %d ubsp_jump_ddr_cnt %d",
Abhishek Singh08aa7762014-12-16 13:59:03 +05307022 fwStatsRsp->fwStatsData.ubspStats.ubsp_enter_cnt,
7023 fwStatsRsp->fwStatsData.ubspStats.ubsp_jump_ddr_cnt);
Satyanarayana Dash72806012014-12-02 14:30:08 +05307024 }
7025 break;
7026 default:
7027 {
7028 hddLog(VOS_TRACE_LEVEL_ERROR, FL( "No handling for stats type %d"),fwStatsRsp->type);
7029 ret = -EFAULT;
7030 kfree(buf);
7031 goto exit;
7032 }
7033 }
7034 if (copy_to_user(priv_data.buf, buf, len + 1))
7035 {
7036 hddLog(VOS_TRACE_LEVEL_ERROR,
7037 FL(" failed to copy data to user buffer"));
7038 ret = -EFAULT;
7039 kfree(buf);
7040 goto exit;
7041 }
7042 ret = len;
7043 kfree(buf);
7044 }
7045 else
7046 {
7047 hddLog(VOS_TRACE_LEVEL_ERROR,
7048 FL("failed to fetch the stats"));
7049 ret = -EFAULT;
7050 goto exit;
7051 }
Satyanarayana Dash72806012014-12-02 14:30:08 +05307052 }
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05307053 else if (strncasecmp(command, "SET_FCC_CHANNEL", 15) == 0)
7054 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05307055 ret = hdd_drv_cmd_validate(command, 15);
7056 if (ret)
7057 goto exit;
7058
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05307059 /*
7060 * this command wld be called by user-space when it detects WLAN
7061 * ON after airplane mode is set. When APM is set, WLAN turns off.
7062 * But it can be turned back on. Otherwise; when APM is turned back
7063 * off, WLAN wld turn back on. So at that point the command is
7064 * expected to come down. 0 means disable, 1 means enable. The
7065 * constraint is removed when parameter 1 is set or different
7066 * country code is set
7067 */
7068 ret = hdd_cmd_setFccChannel(pHddCtx, command, 15);
7069 }
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05307070 else if (strncasecmp(command, "DISABLE_CA_EVENT", 16) == 0)
7071 {
Rajeev Kumar Sirasanagandlaf740b1e2017-08-23 18:07:01 +05307072 ret = hdd_drv_cmd_validate(command, 16);
7073 if (ret)
7074 goto exit;
7075
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05307076 ret = hdd_enable_disable_ca_event(pHddCtx, command, 16);
7077 }
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05307078 /*
7079 * command should be a string having format
7080 * SET_DISABLE_CHANNEL_LIST <num of channels>
7081 * <channels separated by spaces>
7082 */
7083 else if (strncmp(command, "SET_DISABLE_CHANNEL_LIST", 24) == 0) {
7084 tANI_U8 *ptr = command;
7085 ret = hdd_drv_cmd_validate(command, 24);
7086 if (ret)
7087 goto exit;
7088
7089 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7090 " Received Command to disable Channels %s",
7091 __func__);
7092 ret = hdd_parse_disable_chan_cmd(pAdapter, ptr);
7093 if (ret)
7094 goto exit;
7095 }
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307096 else if (strncmp(command, "GET_DISABLE_CHANNEL_LIST", 24) == 0) {
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307097 char extra[512] = {0};
7098 int max_len, copied_length;
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +05307099
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307100 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307101 " Received Command to get disable Channels list %s",
7102 __func__);
7103
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307104 max_len = VOS_MIN(priv_data.total_len, sizeof(extra));
7105 copied_length = hdd_get_disable_ch_list(pHddCtx, extra, max_len);
7106 if (copied_length == 0) {
7107 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307108 FL("disable channel list are not yet programed"));
7109 ret = -EINVAL;
7110 goto exit;
7111 }
7112
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +05307113 if (copy_to_user(priv_data.buf, &extra, copied_length + 1)) {
7114 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7115 "%s: failed to copy data to user buffer", __func__);
Hanumanth Reddy Pothula8ae38bb2018-03-07 18:59:30 +05307116 ret = -EFAULT;
7117 goto exit;
7118 }
7119
7120 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7121 FL("data:%s"), extra);
7122 }
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07007123 else {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307124 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7125 TRACE_CODE_HDD_UNSUPPORTED_IOCTL,
7126 pAdapter->sessionId, 0));
Satyanarayana Dash72806012014-12-02 14:30:08 +05307127 hddLog( VOS_TRACE_LEVEL_WARN, FL("Unsupported GUI command %s"),
7128 command);
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07007129 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007130 }
7131exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307132 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007133 if (command)
7134 {
7135 kfree(command);
7136 }
7137 return ret;
7138}
7139
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007140#ifdef CONFIG_COMPAT
7141static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7142{
7143 struct {
7144 compat_uptr_t buf;
7145 int used_len;
7146 int total_len;
7147 } compat_priv_data;
7148 hdd_priv_data_t priv_data;
7149 int ret = 0;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007150
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007151 /*
7152 * Note that pAdapter and ifr have already been verified by caller,
7153 * and HDD context has also been validated
7154 */
7155 if (copy_from_user(&compat_priv_data, ifr->ifr_data,
7156 sizeof(compat_priv_data))) {
7157 ret = -EFAULT;
7158 goto exit;
7159 }
7160 priv_data.buf = compat_ptr(compat_priv_data.buf);
7161 priv_data.used_len = compat_priv_data.used_len;
7162 priv_data.total_len = compat_priv_data.total_len;
7163 ret = hdd_driver_command(pAdapter, &priv_data);
7164 exit:
7165 return ret;
7166}
7167#else /* CONFIG_COMPAT */
7168static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7169{
7170 /* will never be invoked */
7171 return 0;
7172}
7173#endif /* CONFIG_COMPAT */
7174
7175static int hdd_driver_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
7176{
7177 hdd_priv_data_t priv_data;
7178 int ret = 0;
7179
7180 /*
7181 * Note that pAdapter and ifr have already been verified by caller,
7182 * and HDD context has also been validated
7183 */
7184 if (copy_from_user(&priv_data, ifr->ifr_data, sizeof(priv_data))) {
7185 ret = -EFAULT;
7186 } else {
7187 ret = hdd_driver_command(pAdapter, &priv_data);
7188 }
7189 return ret;
7190}
7191
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307192int __hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007193{
7194 hdd_adapter_t *pAdapter;
7195 hdd_context_t *pHddCtx;
7196 int ret;
7197
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307198 ENTER();
7199
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007200 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7201 if (NULL == pAdapter) {
7202 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7203 "%s: HDD adapter context is Null", __func__);
7204 ret = -ENODEV;
7205 goto exit;
7206 }
7207 if (dev != pAdapter->dev) {
7208 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7209 "%s: HDD adapter/dev inconsistency", __func__);
7210 ret = -ENODEV;
7211 goto exit;
7212 }
7213
7214 if ((!ifr) || (!ifr->ifr_data)) {
7215 ret = -EINVAL;
7216 goto exit;
7217 }
7218
7219 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7220 ret = wlan_hdd_validate_context(pHddCtx);
7221 if (ret) {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007222 ret = -EBUSY;
7223 goto exit;
7224 }
7225
7226 switch (cmd) {
7227 case (SIOCDEVPRIVATE + 1):
7228 if (is_compat_task())
7229 ret = hdd_driver_compat_ioctl(pAdapter, ifr);
7230 else
7231 ret = hdd_driver_ioctl(pAdapter, ifr);
7232 break;
7233 default:
7234 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unknown ioctl %d",
7235 __func__, cmd);
7236 ret = -EINVAL;
7237 break;
7238 }
7239 exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05307240 EXIT();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07007241 return ret;
7242}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007243
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307244int hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7245{
7246 int ret;
7247
7248 vos_ssr_protect(__func__);
7249 ret = __hdd_ioctl(dev, ifr, cmd);
7250 vos_ssr_unprotect(__func__);
7251
7252 return ret;
7253}
7254
Katya Nigame7b69a82015-04-28 15:24:06 +05307255int hdd_mon_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7256{
7257 return 0;
7258}
7259
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007260#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007261/**---------------------------------------------------------------------------
7262
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007263 \brief hdd_parse_ese_beacon_req() - Parse ese beacon request
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007264
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007265 This function parses the ese beacon request passed in the format
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007266 CCXBEACONREQ<space><Number of fields><space><Measurement token>
7267 <space>Channel 1<space>Scan Mode <space>Meas Duration<space>Channel N
7268 <space>Scan Mode N<space>Meas Duration N
7269 if the Number of bcn req fields (N) does not match with the actual number of fields passed
7270 then take N.
7271 <Meas Token><Channel><Scan Mode> and <Meas Duration> are treated as one pair
7272 For example, CCXBEACONREQ 2 1 1 1 30 2 44 0 40.
7273 This function does not take care of removing duplicate channels from the list
7274
7275 \param - pValue Pointer to data
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007276 \param - pEseBcnReq output pointer to store parsed ie information
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007277
7278 \return - 0 for success non-zero for failure
7279
7280 --------------------------------------------------------------------------*/
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007281static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
7282 tCsrEseBeaconReq *pEseBcnReq)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007283{
7284 tANI_U8 *inPtr = pValue;
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307285 uint8_t input = 0;
7286 uint32_t tempInt = 0;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007287 int j = 0, i = 0, v = 0;
7288 char buf[32];
7289
7290 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7291 /*no argument after the command*/
7292 if (NULL == inPtr)
7293 {
7294 return -EINVAL;
7295 }
7296 /*no space after the command*/
7297 else if (SPACE_ASCII_VALUE != *inPtr)
7298 {
7299 return -EINVAL;
7300 }
7301
7302 /*removing empty spaces*/
7303 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
7304
7305 /*no argument followed by spaces*/
7306 if ('\0' == *inPtr) return -EINVAL;
7307
7308 /*getting the first argument ie measurement token*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007309 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007310 if (1 != v) return -EINVAL;
7311
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307312 v = kstrtos8(buf, 10, &input);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007313 if ( v < 0) return -EINVAL;
7314
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307315 input = VOS_MIN(input, SIR_ESE_MAX_MEAS_IE_REQS);
7316 pEseBcnReq->numBcnReqIe = input;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007317
Srinivas Girigowda725a88e2016-03-31 19:24:25 +05307318 hddLog(LOG1, "Number of Bcn Req Ie fields: %d", pEseBcnReq->numBcnReqIe);
7319
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007320
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007321 for (j = 0; j < (pEseBcnReq->numBcnReqIe); j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007322 {
7323 for (i = 0; i < 4; i++)
7324 {
7325 /*inPtr pointing to the beginning of first space after number of ie fields*/
7326 inPtr = strpbrk( inPtr, " " );
7327 /*no ie data after the number of ie fields argument*/
7328 if (NULL == inPtr) return -EINVAL;
7329
7330 /*removing empty space*/
7331 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
7332
7333 /*no ie data after the number of ie fields argument and spaces*/
7334 if ( '\0' == *inPtr ) return -EINVAL;
7335
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007336 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007337 if (1 != v) return -EINVAL;
7338
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307339 v = kstrtou32(buf, 10, &tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007340 if (v < 0) return -EINVAL;
7341
7342 switch (i)
7343 {
7344 case 0: /* Measurement token */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307345 if (!tempInt)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007346 {
7347 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307348 "Invalid Measurement Token: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007349 return -EINVAL;
7350 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007351 pEseBcnReq->bcnReq[j].measurementToken = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007352 break;
7353
7354 case 1: /* Channel number */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307355 if ((!tempInt) ||
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007356 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7357 {
7358 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307359 "Invalid Channel Number: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007360 return -EINVAL;
7361 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007362 pEseBcnReq->bcnReq[j].channel = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007363 break;
7364
7365 case 2: /* Scan mode */
Varun Reddy Yeturu0b18d5a2013-12-04 11:42:23 -08007366 if ((tempInt < eSIR_PASSIVE_SCAN) || (tempInt > eSIR_BEACON_TABLE))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007367 {
7368 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307369 "Invalid Scan Mode(%u) Expected{0|1|2}", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007370 return -EINVAL;
7371 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007372 pEseBcnReq->bcnReq[j].scanMode= tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007373 break;
7374
7375 case 3: /* Measurement duration */
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307376 if (((!tempInt) && (pEseBcnReq->bcnReq[j].scanMode != eSIR_BEACON_TABLE)) ||
7377 ((pEseBcnReq->bcnReq[j].scanMode == eSIR_BEACON_TABLE)))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007378 {
7379 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Khandavalli9f3b4832016-06-30 16:58:38 +05307380 "Invalid Measurement Duration: %u", tempInt);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007381 return -EINVAL;
7382 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007383 pEseBcnReq->bcnReq[j].measurementDuration = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007384 break;
7385 }
7386 }
7387 }
7388
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007389 for (j = 0; j < pEseBcnReq->numBcnReqIe; j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007390 {
7391 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05307392 "Index(%d) Measurement Token(%u)Channel(%u) Scan Mode(%u) Measurement Duration(%u)\n",
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007393 j,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007394 pEseBcnReq->bcnReq[j].measurementToken,
7395 pEseBcnReq->bcnReq[j].channel,
7396 pEseBcnReq->bcnReq[j].scanMode,
7397 pEseBcnReq->bcnReq[j].measurementDuration);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08007398 }
7399
7400 return VOS_STATUS_SUCCESS;
7401}
7402
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307403struct tsm_priv {
7404 tAniTrafStrmMetrics tsm_metrics;
7405};
7406
7407static void hdd_get_tsm_stats_cb(tAniTrafStrmMetrics tsm_metrics,
7408 const tANI_U32 sta_id, void *context )
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007409{
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307410 struct hdd_request *request;
7411 struct tsm_priv *priv;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007412
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307413 ENTER();
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007414
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307415 request = hdd_request_get(context);
7416 if (!request) {
7417 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
7418 return;
7419 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007420
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307421 priv = hdd_request_priv(request);
7422 priv->tsm_metrics = tsm_metrics;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007423
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307424 hdd_request_complete(request);
7425 hdd_request_put(request);
Jeff Johnson72a40512013-12-19 10:14:15 -08007426
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307427 EXIT();
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007428}
7429
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007430static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
7431 tAniTrafStrmMetrics* pTsmMetrics)
7432{
7433 hdd_station_ctx_t *pHddStaCtx = NULL;
7434 eHalStatus hstatus;
Jeff Johnson72a40512013-12-19 10:14:15 -08007435 VOS_STATUS vstatus = VOS_STATUS_SUCCESS;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007436 hdd_context_t *pHddCtx = NULL;
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307437 int ret;
7438 void *cookie;
7439 struct hdd_request *request;
7440 struct tsm_priv *priv;
7441 static const struct hdd_request_params params = {
7442 .priv_size = sizeof(*priv),
7443 .timeout_ms = WLAN_WAIT_TIME_STATS,
7444 };
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007445
7446 if (NULL == pAdapter)
7447 {
7448 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL", __func__);
7449 return VOS_STATUS_E_FAULT;
7450 }
7451
7452 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7453 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7454
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307455 request = hdd_request_alloc(&params);
7456 if (!request) {
7457 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
7458 return VOS_STATUS_E_NOMEM;
7459 }
7460 cookie = hdd_request_cookie(request);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007461
7462 /* query tsm stats */
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307463 hstatus = sme_GetTsmStats(pHddCtx->hHal, hdd_get_tsm_stats_cb,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007464 pHddStaCtx->conn_info.staId[ 0 ],
7465 pHddStaCtx->conn_info.bssId,
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307466 cookie, pHddCtx->pvosContext, tid);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007467
7468 if (eHAL_STATUS_SUCCESS != hstatus)
7469 {
Jeff Johnson72a40512013-12-19 10:14:15 -08007470 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unable to retrieve statistics",
7471 __func__);
7472 vstatus = VOS_STATUS_E_FAULT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007473 }
7474 else
7475 {
7476 /* request was sent -- wait for the response */
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307477 ret = hdd_request_wait_for_response(request);
7478 if (ret) {
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007479 hddLog(VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307480 "SME timeout while retrieving statistics");
Jeff Johnson72a40512013-12-19 10:14:15 -08007481 vstatus = VOS_STATUS_E_TIMEOUT;
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307482 } else {
7483 priv = hdd_request_priv(request);
7484 *pTsmMetrics = priv->tsm_metrics;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007485 }
7486 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007487
Hanumanth Reddy Pothula1ceb7032018-04-05 19:35:55 +05307488 hdd_request_put(request);
Jeff Johnson72a40512013-12-19 10:14:15 -08007489
Jeff Johnson72a40512013-12-19 10:14:15 -08007490 return vstatus;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007491}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007492#endif /*FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007493
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007494#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08007495void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand)
7496{
7497 eCsrBand band = -1;
7498 sme_GetFreqBand((tHalHandle)(pHddCtx->hHal), &band);
7499 switch (band)
7500 {
7501 case eCSR_BAND_ALL:
7502 *pBand = WLAN_HDD_UI_BAND_AUTO;
7503 break;
7504
7505 case eCSR_BAND_24:
7506 *pBand = WLAN_HDD_UI_BAND_2_4_GHZ;
7507 break;
7508
7509 case eCSR_BAND_5G:
7510 *pBand = WLAN_HDD_UI_BAND_5_GHZ;
7511 break;
7512
7513 default:
7514 hddLog( VOS_TRACE_LEVEL_WARN, "%s: Invalid Band %d", __func__, band);
7515 *pBand = -1;
7516 break;
7517 }
7518}
7519
7520/**---------------------------------------------------------------------------
7521
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007522 \brief hdd_parse_send_action_frame_data() - HDD Parse send action frame data
7523
7524 This function parses the send action frame data passed in the format
7525 SENDACTIONFRAME<space><bssid><space><channel><space><dwelltime><space><data>
7526
Srinivas Girigowda56076852013-08-20 14:00:50 -07007527 \param - pValue Pointer to input data
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007528 \param - pTargetApBssid Pointer to target Ap bssid
7529 \param - pChannel Pointer to the Target AP channel
7530 \param - pDwellTime Pointer to the time to stay off-channel after transmitting action frame
7531 \param - pBuf Pointer to data
7532 \param - pBufLen Pointer to data length
7533
7534 \return - 0 for success non-zero for failure
7535
7536 --------------------------------------------------------------------------*/
7537VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid, tANI_U8 *pChannel,
7538 tANI_U8 *pDwellTime, tANI_U8 **pBuf, tANI_U8 *pBufLen)
7539{
7540 tANI_U8 *inPtr = pValue;
7541 tANI_U8 *dataEnd;
7542 int tempInt;
7543 int j = 0;
7544 int i = 0;
7545 int v = 0;
7546 tANI_U8 tempBuf[32];
7547 tANI_U8 tempByte = 0;
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007548 /* 12 hexa decimal digits, 5 ':' and '\0' */
7549 tANI_U8 macAddress[18];
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007550
7551 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7552 /*no argument after the command*/
7553 if (NULL == inPtr)
7554 {
7555 return -EINVAL;
7556 }
7557
7558 /*no space after the command*/
7559 else if (SPACE_ASCII_VALUE != *inPtr)
7560 {
7561 return -EINVAL;
7562 }
7563
7564 /*removing empty spaces*/
7565 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7566
7567 /*no argument followed by spaces*/
7568 if ('\0' == *inPtr)
7569 {
7570 return -EINVAL;
7571 }
7572
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007573 v = sscanf(inPtr, "%17s", macAddress);
7574 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007575 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007576 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7577 "Invalid MAC address or All hex inputs are not read (%d)", v);
7578 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007579 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007580
7581 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
7582 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
7583 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
7584 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
7585 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
7586 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007587
7588 /* point to the next argument */
7589 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7590 /*no argument after the command*/
7591 if (NULL == inPtr) return -EINVAL;
7592
7593 /*removing empty spaces*/
7594 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7595
7596 /*no argument followed by spaces*/
7597 if ('\0' == *inPtr)
7598 {
7599 return -EINVAL;
7600 }
7601
7602 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007603 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007604 if (1 != v) return -EINVAL;
7605
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007606 v = kstrtos32(tempBuf, 10, &tempInt);
Agarwal Ashish353b3a82014-04-08 14:55:11 +05307607 if ( v < 0 || tempInt <= 0 || tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX )
Kiet Lambe150c22013-11-21 16:30:32 +05307608 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007609
7610 *pChannel = tempInt;
7611
7612 /* point to the next argument */
7613 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7614 /*no argument after the command*/
7615 if (NULL == inPtr) return -EINVAL;
7616 /*removing empty spaces*/
7617 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7618
7619 /*no argument followed by spaces*/
7620 if ('\0' == *inPtr)
7621 {
7622 return -EINVAL;
7623 }
7624
7625 /*getting the next argument ie the dwell time */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007626 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007627 if (1 != v) return -EINVAL;
7628
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007629 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda5a6e0672014-01-09 14:42:57 -08007630 if ( v < 0 || tempInt < 0) return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007631
7632 *pDwellTime = tempInt;
7633
7634 /* point to the next argument */
7635 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7636 /*no argument after the command*/
7637 if (NULL == inPtr) return -EINVAL;
7638 /*removing empty spaces*/
7639 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7640
7641 /*no argument followed by spaces*/
7642 if ('\0' == *inPtr)
7643 {
7644 return -EINVAL;
7645 }
7646
7647 /* find the length of data */
7648 dataEnd = inPtr;
7649 while(('\0' != *dataEnd) )
7650 {
7651 dataEnd++;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007652 }
Kiet Lambe150c22013-11-21 16:30:32 +05307653 *pBufLen = dataEnd - inPtr ;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007654 if ( *pBufLen <= 0) return -EINVAL;
7655
Srinivas Girigowdab5ae85d2013-06-03 10:51:45 -07007656 /* Allocate the number of bytes based on the number of input characters
7657 whether it is even or odd.
7658 if the number of input characters are even, then we need N/2 byte.
7659 if the number of input characters are odd, then we need do (N+1)/2 to
7660 compensate rounding off.
7661 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
7662 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
7663 *pBuf = vos_mem_malloc((*pBufLen + 1)/2);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007664 if (NULL == *pBuf)
7665 {
7666 hddLog(VOS_TRACE_LEVEL_FATAL,
7667 "%s: vos_mem_alloc failed ", __func__);
7668 return -EINVAL;
7669 }
7670
7671 /* the buffer received from the upper layer is character buffer,
7672 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
7673 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
7674 and f0 in 3rd location */
7675 for (i = 0, j = 0; j < *pBufLen; j += 2)
7676 {
Kiet Lambe150c22013-11-21 16:30:32 +05307677 if( j+1 == *pBufLen)
7678 {
7679 tempByte = hdd_parse_hex(inPtr[j]);
7680 }
7681 else
7682 {
7683 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
7684 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007685 (*pBuf)[i++] = tempByte;
7686 }
7687 *pBufLen = i;
7688 return VOS_STATUS_SUCCESS;
7689}
7690
Srinivas Girigowda100eb322013-03-15 16:48:20 -07007691/**---------------------------------------------------------------------------
7692
Srinivas Girigowdade697412013-02-14 16:31:48 -08007693 \brief hdd_parse_channellist() - HDD Parse channel list
7694
7695 This function parses the channel list passed in the format
7696 SETROAMSCANCHANNELS<space><Number of channels><space>Channel 1<space>Channel 2<space>Channel N
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007697 if the Number of channels (N) does not match with the actual number of channels passed
7698 then take the minimum of N and count of (Ch1, Ch2, ...Ch M)
7699 For example, if SETROAMSCANCHANNELS 3 36 40 44 48, only 36, 40 and 44 shall be taken.
7700 If SETROAMSCANCHANNELS 5 36 40 44 48, ignore 5 and take 36, 40, 44 and 48.
7701 This function does not take care of removing duplicate channels from the list
Srinivas Girigowdade697412013-02-14 16:31:48 -08007702
7703 \param - pValue Pointer to input channel list
7704 \param - ChannelList Pointer to local output array to record channel list
7705 \param - pNumChannels Pointer to number of roam scan channels
7706
7707 \return - 0 for success non-zero for failure
7708
7709 --------------------------------------------------------------------------*/
7710VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels)
7711{
7712 tANI_U8 *inPtr = pValue;
7713 int tempInt;
7714 int j = 0;
7715 int v = 0;
7716 char buf[32];
7717
7718 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7719 /*no argument after the command*/
7720 if (NULL == inPtr)
7721 {
7722 return -EINVAL;
7723 }
7724
7725 /*no space after the command*/
7726 else if (SPACE_ASCII_VALUE != *inPtr)
7727 {
7728 return -EINVAL;
7729 }
7730
7731 /*removing empty spaces*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007732 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08007733
7734 /*no argument followed by spaces*/
7735 if ('\0' == *inPtr)
7736 {
7737 return -EINVAL;
7738 }
7739
7740 /*getting the first argument ie the number of channels*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007741 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007742 if (1 != v) return -EINVAL;
7743
Srinivas Girigowdade697412013-02-14 16:31:48 -08007744 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007745 if ((v < 0) ||
7746 (tempInt <= 0) ||
7747 (tempInt > WNI_CFG_VALID_CHANNEL_LIST_LEN))
7748 {
7749 return -EINVAL;
7750 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007751
7752 *pNumChannels = tempInt;
7753
7754 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
7755 "Number of channels are: %d", *pNumChannels);
7756
7757 for (j = 0; j < (*pNumChannels); j++)
7758 {
7759 /*inPtr pointing to the beginning of first space after number of channels*/
7760 inPtr = strpbrk( inPtr, " " );
7761 /*no channel list after the number of channels argument*/
7762 if (NULL == inPtr)
7763 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007764 if (0 != j)
7765 {
7766 *pNumChannels = j;
7767 return VOS_STATUS_SUCCESS;
7768 }
7769 else
7770 {
7771 return -EINVAL;
7772 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007773 }
7774
7775 /*removing empty space*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007776 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08007777
7778 /*no channel list after the number of channels argument and spaces*/
7779 if ( '\0' == *inPtr )
7780 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07007781 if (0 != j)
7782 {
7783 *pNumChannels = j;
7784 return VOS_STATUS_SUCCESS;
7785 }
7786 else
7787 {
7788 return -EINVAL;
7789 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007790 }
7791
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007792 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007793 if (1 != v) return -EINVAL;
7794
Srinivas Girigowdade697412013-02-14 16:31:48 -08007795 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07007796 if ((v < 0) ||
7797 (tempInt <= 0) ||
7798 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7799 {
7800 return -EINVAL;
7801 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08007802 pChannelList[j] = tempInt;
7803
7804 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
7805 "Channel %d added to preferred channel list",
7806 pChannelList[j] );
7807 }
7808
Srinivas Girigowdade697412013-02-14 16:31:48 -08007809 return VOS_STATUS_SUCCESS;
7810}
7811
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007812
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05307813/**
7814 * hdd_parse_reassoc_command_v1_data() - HDD Parse reassoc command data
7815 * This function parses the reasoc command data passed in the format
7816 * REASSOC<space><bssid><space><channel>
7817 *
7818 * @pValue: Pointer to input data (its a NUL terminated string)
7819 * @pTargetApBssid: Pointer to target Ap bssid
7820 * @pChannel: Pointer to the Target AP channel
7821 *
7822 * Return: 0 for success non-zero for failure
7823 */
7824static int hdd_parse_reassoc_command_v1_data(const tANI_U8 *pValue,
7825 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007826{
Selvaraj, Sridhar5aff1ed2016-06-18 01:26:23 +05307827 const tANI_U8 *inPtr = pValue;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007828 int tempInt;
7829 int v = 0;
7830 tANI_U8 tempBuf[32];
Kiet Lamaa8e15a2014-02-11 23:30:06 -08007831 /* 12 hexa decimal digits, 5 ':' and '\0' */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007832 tANI_U8 macAddress[18];
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007833
7834 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7835 /*no argument after the command*/
7836 if (NULL == inPtr)
7837 {
7838 return -EINVAL;
7839 }
7840
7841 /*no space after the command*/
7842 else if (SPACE_ASCII_VALUE != *inPtr)
7843 {
7844 return -EINVAL;
7845 }
7846
7847 /*removing empty spaces*/
7848 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7849
7850 /*no argument followed by spaces*/
7851 if ('\0' == *inPtr)
7852 {
7853 return -EINVAL;
7854 }
7855
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007856 v = sscanf(inPtr, "%17s", macAddress);
7857 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007858 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007859 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7860 "Invalid MAC address or All hex inputs are not read (%d)", v);
7861 return -EINVAL;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007862 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007863
7864 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
7865 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
7866 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
7867 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
7868 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
7869 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007870
7871 /* point to the next argument */
7872 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
7873 /*no argument after the command*/
7874 if (NULL == inPtr) return -EINVAL;
7875
7876 /*removing empty spaces*/
7877 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7878
7879 /*no argument followed by spaces*/
7880 if ('\0' == *inPtr)
7881 {
7882 return -EINVAL;
7883 }
7884
7885 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08007886 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007887 if (1 != v) return -EINVAL;
7888
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007889 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007890 if ((v < 0) ||
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05307891 (tempInt < 0) ||
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007892 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
7893 {
7894 return -EINVAL;
7895 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07007896
7897 *pChannel = tempInt;
7898 return VOS_STATUS_SUCCESS;
7899}
7900
7901#endif
7902
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007903#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007904/**---------------------------------------------------------------------------
7905
7906 \brief hdd_parse_get_cckm_ie() - HDD Parse and fetch the CCKM IE
7907
7908 This function parses the SETCCKM IE command
7909 SETCCKMIE<space><ie data>
7910
7911 \param - pValue Pointer to input data
7912 \param - pCckmIe Pointer to output cckm Ie
7913 \param - pCckmIeLen Pointer to output cckm ie length
7914
7915 \return - 0 for success non-zero for failure
7916
7917 --------------------------------------------------------------------------*/
7918VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe,
7919 tANI_U8 *pCckmIeLen)
7920{
7921 tANI_U8 *inPtr = pValue;
7922 tANI_U8 *dataEnd;
7923 int j = 0;
7924 int i = 0;
7925 tANI_U8 tempByte = 0;
7926
7927 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
7928 /*no argument after the command*/
7929 if (NULL == inPtr)
7930 {
7931 return -EINVAL;
7932 }
7933
7934 /*no space after the command*/
7935 else if (SPACE_ASCII_VALUE != *inPtr)
7936 {
7937 return -EINVAL;
7938 }
7939
7940 /*removing empty spaces*/
7941 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
7942
7943 /*no argument followed by spaces*/
7944 if ('\0' == *inPtr)
7945 {
7946 return -EINVAL;
7947 }
7948
7949 /* find the length of data */
7950 dataEnd = inPtr;
7951 while(('\0' != *dataEnd) )
7952 {
7953 dataEnd++;
7954 ++(*pCckmIeLen);
7955 }
7956 if ( *pCckmIeLen <= 0) return -EINVAL;
7957
7958 /* Allocate the number of bytes based on the number of input characters
7959 whether it is even or odd.
7960 if the number of input characters are even, then we need N/2 byte.
7961 if the number of input characters are odd, then we need do (N+1)/2 to
7962 compensate rounding off.
7963 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
7964 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
7965 *pCckmIe = vos_mem_malloc((*pCckmIeLen + 1)/2);
7966 if (NULL == *pCckmIe)
7967 {
7968 hddLog(VOS_TRACE_LEVEL_FATAL,
7969 "%s: vos_mem_alloc failed ", __func__);
7970 return -EINVAL;
7971 }
7972 vos_mem_zero(*pCckmIe, (*pCckmIeLen + 1)/2);
7973 /* the buffer received from the upper layer is character buffer,
7974 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
7975 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
7976 and f0 in 3rd location */
7977 for (i = 0, j = 0; j < *pCckmIeLen; j += 2)
7978 {
7979 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
7980 (*pCckmIe)[i++] = tempByte;
7981 }
7982 *pCckmIeLen = i;
7983
7984 return VOS_STATUS_SUCCESS;
7985}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08007986#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07007987
Jeff Johnson295189b2012-06-20 16:38:30 -07007988/**---------------------------------------------------------------------------
7989
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07007990 \brief hdd_is_valid_mac_address() - Validate MAC address
7991
7992 This function validates whether the given MAC address is valid or not
7993 Expected MAC address is of the format XX:XX:XX:XX:XX:XX
7994 where X is the hexa decimal digit character and separated by ':'
7995 This algorithm works even if MAC address is not separated by ':'
7996
7997 This code checks given input string mac contains exactly 12 hexadecimal digits.
7998 and a separator colon : appears in the input string only after
7999 an even number of hex digits.
8000
8001 \param - pMacAddr pointer to the input MAC address
8002 \return - 1 for valid and 0 for invalid
8003
8004 --------------------------------------------------------------------------*/
8005
8006v_BOOL_t hdd_is_valid_mac_address(const tANI_U8 *pMacAddr)
8007{
8008 int xdigit = 0;
8009 int separator = 0;
8010 while (*pMacAddr)
8011 {
8012 if (isxdigit(*pMacAddr))
8013 {
8014 xdigit++;
8015 }
8016 else if (':' == *pMacAddr)
8017 {
8018 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
8019 break;
8020
8021 ++separator;
8022 }
8023 else
8024 {
8025 separator = -1;
8026 /* Invalid MAC found */
8027 return 0;
8028 }
8029 ++pMacAddr;
8030 }
8031 return (xdigit == 12 && (separator == 5 || separator == 0));
8032}
8033
8034/**---------------------------------------------------------------------------
8035
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308036 \brief __hdd_open() - HDD Open function
Jeff Johnson295189b2012-06-20 16:38:30 -07008037
8038 \param - dev Pointer to net_device structure
8039
8040 \return - 0 for success non-zero for failure
8041
8042 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308043int __hdd_open(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008044{
8045 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8046 hdd_context_t *pHddCtx;
8047 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8048 VOS_STATUS status;
8049 v_BOOL_t in_standby = TRUE;
8050
8051 if (NULL == pAdapter)
8052 {
8053 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05308054 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008055 return -ENODEV;
8056 }
8057
8058 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308059 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
8060 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson295189b2012-06-20 16:38:30 -07008061 if (NULL == pHddCtx)
8062 {
8063 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008064 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008065 return -ENODEV;
8066 }
8067
8068 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8069 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
8070 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008071 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
8072 {
8073 hddLog(VOS_TRACE_LEVEL_INFO, "%s: chip already out of standby",
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05308074 __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008075 in_standby = FALSE;
8076 break;
8077 }
8078 else
8079 {
8080 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8081 pAdapterNode = pNext;
8082 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008083 }
8084
8085 if (TRUE == in_standby)
8086 {
8087 if (VOS_STATUS_SUCCESS != wlan_hdd_exit_lowpower(pHddCtx, pAdapter))
8088 {
8089 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to bring "
8090 "wlan out of power save", __func__);
8091 return -EINVAL;
8092 }
8093 }
8094
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008095 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07008096 if (hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
8097 {
8098 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008099 "%s: Enabling Tx Queues", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008100 /* Enable TX queues only when we are connected */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308101 hddLog(VOS_TRACE_LEVEL_INFO, FL("Enabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008102 netif_tx_start_all_queues(dev);
8103 }
8104
8105 return 0;
8106}
8107
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308108/**---------------------------------------------------------------------------
8109
8110 \brief hdd_open() - Wrapper function for __hdd_open to protect it from SSR
8111
8112 This is called in response to ifconfig up
8113
8114 \param - dev Pointer to net_device structure
8115
8116 \return - 0 for success non-zero for failure
8117
8118 --------------------------------------------------------------------------*/
8119int hdd_open(struct net_device *dev)
8120{
8121 int ret;
8122
8123 vos_ssr_protect(__func__);
8124 ret = __hdd_open(dev);
8125 vos_ssr_unprotect(__func__);
8126
8127 return ret;
8128}
8129
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05308130int __hdd_mon_open (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008131{
8132 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308133 hdd_adapter_t *sta_adapter;
8134 hdd_context_t *hdd_ctx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008135
8136 if(pAdapter == NULL) {
8137 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008138 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08008139 return -EINVAL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008140 }
8141
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308142 if (vos_get_concurrency_mode() != VOS_STA_MON)
8143 return 0;
8144
8145 hdd_ctx = WLAN_HDD_GET_CTX(pAdapter);
8146 if (wlan_hdd_validate_context(hdd_ctx))
8147 return -EINVAL;
8148
8149 sta_adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_INFRA_STATION);
8150 if (!sta_adapter) {
8151 hddLog(LOGE, FL("No valid STA interface"));
8152 return -EINVAL;
8153 }
8154
8155 if (!test_bit(DEVICE_IFACE_OPENED, &sta_adapter->event_flags)) {
8156 hddLog(LOGE, FL("STA Interface is not OPENED"));
8157 return -EINVAL;
8158 }
8159
8160 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
8161
Jeff Johnson295189b2012-06-20 16:38:30 -07008162 return 0;
8163}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05308164
8165int hdd_mon_open (struct net_device *dev)
8166{
8167 int ret;
8168
8169 vos_ssr_protect(__func__);
8170 ret = __hdd_mon_open(dev);
8171 vos_ssr_unprotect(__func__);
8172
8173 return ret;
8174}
8175
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308176int __hdd_mon_stop (struct net_device *dev)
8177{
8178 hdd_adapter_t *mon_adapter = WLAN_HDD_GET_PRIV_PTR(dev);
8179 hdd_context_t *hdd_ctx;
8180
8181 if (vos_get_concurrency_mode() != VOS_STA_MON)
8182 return 0;
8183
8184 if(!mon_adapter) {
8185 hddLog(LOGE, FL("HDD adapter is Null"));
8186 return -EINVAL;
8187 }
8188
8189 hdd_ctx = WLAN_HDD_GET_CTX(mon_adapter);
8190 if (wlan_hdd_validate_context(hdd_ctx))
8191 return -EINVAL;
8192
8193 if (!test_bit(DEVICE_IFACE_OPENED, &mon_adapter->event_flags)) {
8194 hddLog(LOGE, FL("NETDEV Interface is not OPENED"));
8195 return -ENODEV;
8196 }
8197
8198 clear_bit(DEVICE_IFACE_OPENED, &mon_adapter->event_flags);
8199 hdd_stop_adapter(hdd_ctx, mon_adapter, VOS_FALSE);
8200
8201 return 0;
8202}
8203
Katya Nigame7b69a82015-04-28 15:24:06 +05308204int hdd_mon_stop(struct net_device *dev)
8205{
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308206 int ret;
8207
8208 vos_ssr_protect(__func__);
8209 ret = __hdd_mon_stop(dev);
8210 vos_ssr_unprotect(__func__);
8211
8212 return ret;
Katya Nigame7b69a82015-04-28 15:24:06 +05308213}
8214
Jeff Johnson295189b2012-06-20 16:38:30 -07008215/**---------------------------------------------------------------------------
8216
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308217 \brief __hdd_stop() - HDD stop function
Jeff Johnson295189b2012-06-20 16:38:30 -07008218
8219 \param - dev Pointer to net_device structure
8220
8221 \return - 0 for success non-zero for failure
8222
8223 --------------------------------------------------------------------------*/
8224
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308225int __hdd_stop (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008226{
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308227 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07008228 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8229 hdd_context_t *pHddCtx;
8230 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8231 VOS_STATUS status;
8232 v_BOOL_t enter_standby = TRUE;
8233
8234 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07008235 if (NULL == pAdapter)
8236 {
8237 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05308238 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008239 return -ENODEV;
8240 }
Sachin Ahuja9b4958f2015-01-15 21:37:00 +05308241 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308242 pAdapter->sessionId, pAdapter->device_mode));
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308243
8244 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8245 ret = wlan_hdd_validate_context(pHddCtx);
8246 if (ret)
Jeff Johnson295189b2012-06-20 16:38:30 -07008247 {
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05308248 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07008249 }
8250
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308251 /* Nothing to be done if the interface is not opened */
8252 if (VOS_FALSE == test_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags))
8253 {
8254 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8255 "%s: NETDEV Interface is not OPENED", __func__);
8256 return -ENODEV;
8257 }
8258
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308259 if (pHddCtx->concurrency_mode == VOS_STA_MON) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308260 /*
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05308261 * In STA + Monitor mode concurrency, no point in running
8262 * capture on monitor interface, when STA interface is stopped
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308263 */
Rajeev Kumar Sirasanagandlaa74e1222018-01-09 17:38:55 +05308264 wlan_hdd_stop_mon(pHddCtx, true);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05308265 }
8266
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308267 /* Make sure the interface is marked as closed */
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008268 clear_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07008269 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disabling OS Tx queues", __func__);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308270
8271 /* Disable TX on the interface, after this hard_start_xmit() will not
8272 * be called on that interface
8273 */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308274 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008275 netif_tx_disable(pAdapter->dev);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308276
8277 /* Mark the interface status as "down" for outside world */
Jeff Johnson295189b2012-06-20 16:38:30 -07008278 netif_carrier_off(pAdapter->dev);
8279
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308280 /* The interface is marked as down for outside world (aka kernel)
8281 * But the driver is pretty much alive inside. The driver needs to
8282 * tear down the existing connection on the netdev (session)
8283 * cleanup the data pipes and wait until the control plane is stabilized
8284 * for this interface. The call also needs to wait until the above
8285 * mentioned actions are completed before returning to the caller.
8286 * Notice that the hdd_stop_adapter is requested not to close the session
8287 * That is intentional to be able to scan if it is a STA/P2P interface
8288 */
8289 hdd_stop_adapter(pHddCtx, pAdapter, VOS_FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308290#ifdef FEATURE_WLAN_TDLS
8291 mutex_lock(&pHddCtx->tdls_lock);
8292#endif
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308293 /* DeInit the adapter. This ensures datapath cleanup as well */
c_hpothu002231a2015-02-05 14:58:51 +05308294 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308295#ifdef FEATURE_WLAN_TDLS
8296 mutex_unlock(&pHddCtx->tdls_lock);
8297#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008298 /* SoftAP ifaces should never go in power save mode
8299 making sure same here. */
8300 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07008301 || (WLAN_HDD_P2P_GO == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07008302 )
8303 {
8304 /* SoftAP mode, so return from here */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308305 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8306 "%s: In SAP MODE", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008307 EXIT();
8308 return 0;
8309 }
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308310 /* Find if any iface is up. If any iface is up then can't put device to
8311 * sleep/power save mode
8312 */
Jeff Johnson295189b2012-06-20 16:38:30 -07008313 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8314 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
8315 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008316 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
8317 {
8318 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Still other ifaces are up cannot "
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05308319 "put device to sleep", __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07008320 enter_standby = FALSE;
8321 break;
8322 }
8323 else
8324 {
8325 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8326 pAdapterNode = pNext;
8327 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008328 }
8329
8330 if (TRUE == enter_standby)
8331 {
8332 hddLog(VOS_TRACE_LEVEL_INFO, "%s: All Interfaces are Down "
8333 "entering standby", __func__);
8334 if (VOS_STATUS_SUCCESS != wlan_hdd_enter_lowpower(pHddCtx))
8335 {
8336 /*log and return success*/
8337 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to put "
8338 "wlan in power save", __func__);
8339 }
8340 }
Hanumanth Reddy Pothula972e1df2018-06-14 13:33:47 +05308341
8342 /*
8343 * Upon wifi turn off, DUT has to flush the scan results so if
8344 * this is the last cli iface, flush the scan database.
8345 */
8346 if (!hdd_is_cli_iface_up(pHddCtx))
8347 sme_ScanFlushResult(pHddCtx->hHal, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008348
8349 EXIT();
8350 return 0;
8351}
8352
8353/**---------------------------------------------------------------------------
8354
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308355 \brief hdd_stop() - wrapper_function for __hdd_stop to protect it from SSR
Jeff Johnson295189b2012-06-20 16:38:30 -07008356
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308357 This is called in response to ifconfig down
8358
8359 \param - dev Pointer to net_device structure
8360
8361 \return - 0 for success non-zero for failure
8362-----------------------------------------------------------------------------*/
8363int hdd_stop (struct net_device *dev)
8364{
8365 int ret;
8366
8367 vos_ssr_protect(__func__);
8368 ret = __hdd_stop(dev);
8369 vos_ssr_unprotect(__func__);
8370
8371 return ret;
8372}
8373
8374/**---------------------------------------------------------------------------
8375
8376 \brief __hdd_uninit() - HDD uninit function
Jeff Johnson295189b2012-06-20 16:38:30 -07008377
8378 \param - dev Pointer to net_device structure
8379
8380 \return - void
8381
8382 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308383static void __hdd_uninit (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07008384{
8385 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308386 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008387 ENTER();
8388
8389 do
8390 {
8391 if (NULL == pAdapter)
8392 {
8393 hddLog(VOS_TRACE_LEVEL_FATAL,
8394 "%s: NULL pAdapter", __func__);
8395 break;
8396 }
8397
8398 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
8399 {
8400 hddLog(VOS_TRACE_LEVEL_FATAL,
8401 "%s: Invalid magic", __func__);
8402 break;
8403 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308404 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8405 if (NULL == pHddCtx)
Jeff Johnson295189b2012-06-20 16:38:30 -07008406 {
8407 hddLog(VOS_TRACE_LEVEL_FATAL,
8408 "%s: NULL pHddCtx", __func__);
8409 break;
8410 }
8411
8412 if (dev != pAdapter->dev)
8413 {
8414 hddLog(VOS_TRACE_LEVEL_FATAL,
8415 "%s: Invalid device reference", __func__);
8416 /* we haven't validated all cases so let this go for now */
8417 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308418#ifdef FEATURE_WLAN_TDLS
8419 mutex_lock(&pHddCtx->tdls_lock);
8420#endif
c_hpothu002231a2015-02-05 14:58:51 +05308421 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308422#ifdef FEATURE_WLAN_TDLS
8423 mutex_unlock(&pHddCtx->tdls_lock);
8424#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008425
8426 /* after uninit our adapter structure will no longer be valid */
8427 pAdapter->dev = NULL;
8428 pAdapter->magic = 0;
Manjeet Singh47ee8472016-04-11 11:57:18 +05308429 pAdapter->pHddCtx = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008430 } while (0);
8431
8432 EXIT();
8433}
8434
8435/**---------------------------------------------------------------------------
8436
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308437 \brief hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
8438
8439 This is called during the netdev unregister to uninitialize all data
8440associated with the device
8441
8442 \param - dev Pointer to net_device structure
8443
8444 \return - void
8445
8446 --------------------------------------------------------------------------*/
8447static void hdd_uninit (struct net_device *dev)
8448{
8449 vos_ssr_protect(__func__);
8450 __hdd_uninit(dev);
8451 vos_ssr_unprotect(__func__);
8452}
8453
8454/**---------------------------------------------------------------------------
8455
Jeff Johnson295189b2012-06-20 16:38:30 -07008456 \brief hdd_release_firmware() -
8457
8458 This function calls the release firmware API to free the firmware buffer.
8459
8460 \param - pFileName Pointer to the File Name.
8461 pCtx - Pointer to the adapter .
8462
8463
8464 \return - 0 for success, non zero for failure
8465
8466 --------------------------------------------------------------------------*/
8467
8468VOS_STATUS hdd_release_firmware(char *pFileName,v_VOID_t *pCtx)
8469{
8470 VOS_STATUS status = VOS_STATUS_SUCCESS;
8471 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8472 ENTER();
8473
8474
8475 if (!strcmp(WLAN_FW_FILE, pFileName)) {
8476
8477 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"%s: Loaded firmware file is %s",__func__,pFileName);
8478
8479 if(pHddCtx->fw) {
8480 release_firmware(pHddCtx->fw);
8481 pHddCtx->fw = NULL;
8482 }
8483 else
8484 status = VOS_STATUS_E_FAILURE;
8485 }
8486 else if (!strcmp(WLAN_NV_FILE,pFileName)) {
8487 if(pHddCtx->nv) {
8488 release_firmware(pHddCtx->nv);
8489 pHddCtx->nv = NULL;
8490 }
8491 else
8492 status = VOS_STATUS_E_FAILURE;
8493
8494 }
8495
8496 EXIT();
8497 return status;
8498}
8499
8500/**---------------------------------------------------------------------------
8501
8502 \brief hdd_request_firmware() -
8503
8504 This function reads the firmware file using the request firmware
8505 API and returns the the firmware data and the firmware file size.
8506
8507 \param - pfileName - Pointer to the file name.
8508 - pCtx - Pointer to the adapter .
8509 - ppfw_data - Pointer to the pointer of the firmware data.
8510 - pSize - Pointer to the file size.
8511
8512 \return - VOS_STATUS_SUCCESS for success, VOS_STATUS_E_FAILURE for failure
8513
8514 --------------------------------------------------------------------------*/
8515
8516
8517VOS_STATUS hdd_request_firmware(char *pfileName,v_VOID_t *pCtx,v_VOID_t **ppfw_data, v_SIZE_t *pSize)
8518{
8519 int status;
8520 VOS_STATUS retval = VOS_STATUS_SUCCESS;
8521 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8522 ENTER();
8523
8524 if( (!strcmp(WLAN_FW_FILE, pfileName)) ) {
8525
8526 status = request_firmware(&pHddCtx->fw, pfileName, pHddCtx->parent_dev);
8527
8528 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8529 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Firmware %s download failed",
8530 __func__, pfileName);
8531 retval = VOS_STATUS_E_FAILURE;
8532 }
8533
8534 else {
8535 *ppfw_data = (v_VOID_t *)pHddCtx->fw->data;
8536 *pSize = pHddCtx->fw->size;
8537 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Firmware size = %d",
8538 __func__, *pSize);
8539 }
8540 }
8541 else if(!strcmp(WLAN_NV_FILE, pfileName)) {
8542
8543 status = request_firmware(&pHddCtx->nv, pfileName, pHddCtx->parent_dev);
8544
8545 if(status || !pHddCtx->nv || !pHddCtx->nv->data) {
8546 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: nv %s download failed",
8547 __func__, pfileName);
8548 retval = VOS_STATUS_E_FAILURE;
8549 }
8550
8551 else {
8552 *ppfw_data = (v_VOID_t *)pHddCtx->nv->data;
8553 *pSize = pHddCtx->nv->size;
8554 hddLog(VOS_TRACE_LEVEL_INFO, "%s: nv file size = %d",
8555 __func__, *pSize);
8556 }
8557 }
8558
8559 EXIT();
8560 return retval;
8561}
8562/**---------------------------------------------------------------------------
8563 \brief hdd_full_pwr_cbk() - HDD full power callbackfunction
8564
8565 This is the function invoked by SME to inform the result of a full power
8566 request issued by HDD
8567
8568 \param - callbackcontext - Pointer to cookie
8569 status - result of request
8570
8571 \return - None
8572
8573--------------------------------------------------------------------------*/
8574void hdd_full_pwr_cbk(void *callbackContext, eHalStatus status)
8575{
8576 hdd_context_t *pHddCtx = (hdd_context_t*)callbackContext;
8577
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07008578 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"HDD full Power callback status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008579 if(&pHddCtx->full_pwr_comp_var)
8580 {
8581 complete(&pHddCtx->full_pwr_comp_var);
8582 }
8583}
8584
Abhishek Singh00b71972016-01-07 10:51:04 +05308585#ifdef WLAN_FEATURE_RMC
8586static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo)
8587{
8588 int payload_len;
8589 struct sk_buff *skb;
8590 struct nlmsghdr *nlh;
8591 v_U8_t *data;
8592
8593 payload_len = ETH_ALEN;
8594
8595 if (0 == cesium_pid)
8596 {
8597 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: cesium process not registered",
8598 __func__);
8599 return;
8600 }
8601
8602 if ((skb = nlmsg_new(payload_len,GFP_ATOMIC)) == NULL)
8603 {
8604 hddLog(VOS_TRACE_LEVEL_ERROR,
8605 "%s: nlmsg_new() failed for msg size[%d]",
8606 __func__, NLMSG_SPACE(payload_len));
8607 return;
8608 }
8609
8610 nlh = nlmsg_put(skb, cesium_pid, seqNo, 0, payload_len, NLM_F_REQUEST);
8611
8612 if (NULL == nlh)
8613 {
8614 hddLog(VOS_TRACE_LEVEL_ERROR,
8615 "%s: nlmsg_put() failed for msg size[%d]",
8616 __func__, NLMSG_SPACE(payload_len));
8617
8618 kfree_skb(skb);
8619 return;
8620 }
8621
8622 data = nlmsg_data(nlh);
8623 memcpy(data, MacAddr, ETH_ALEN);
8624
8625 if (nlmsg_unicast(cesium_nl_srv_sock, skb, cesium_pid) < 0)
8626 {
8627 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: nlmsg_unicast() failed for msg size[%d]",
8628 __func__, NLMSG_SPACE(payload_len));
8629 }
8630
8631 return;
8632}
8633
8634/**---------------------------------------------------------------------------
8635 \brief hdd_ParseuserParams - return a pointer to the next argument
8636
8637 \return - status
8638
8639--------------------------------------------------------------------------*/
8640static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg)
8641{
8642 tANI_U8 *pVal;
8643
8644 pVal = strchr(pValue, ' ');
8645
8646 if (NULL == pVal)
8647 {
8648 /* no argument remains */
8649 return -EINVAL;
8650 }
8651 else if (SPACE_ASCII_VALUE != *pVal)
8652 {
8653 /* no space after the current argument */
8654 return -EINVAL;
8655 }
8656
8657 pVal++;
8658
8659 /* remove empty spaces */
8660 while ((SPACE_ASCII_VALUE == *pVal) && ('\0' != *pVal))
8661 {
8662 pVal++;
8663 }
8664
8665 /* no argument followed by spaces */
8666 if ('\0' == *pVal)
8667 {
8668 return -EINVAL;
8669 }
8670
8671 *ppArg = pVal;
8672
8673 return 0;
8674}
8675
8676/**----------------------------------------------------------------------------
8677 \brief hdd_ParseIBSSTXFailEventParams - Parse params for SETIBSSTXFAILEVENT
8678
8679 \return - status
8680
8681------------------------------------------------------------------------------*/
8682static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
8683 tANI_U8 *tx_fail_count,
8684 tANI_U16 *pid)
8685{
8686 tANI_U8 *param = NULL;
8687 int ret;
8688
8689 ret = hdd_ParseUserParams(pValue, &param);
8690
8691 if (0 == ret && NULL != param)
8692 {
8693 if (1 != sscanf(param, "%hhu", tx_fail_count))
8694 {
8695 ret = -EINVAL;
8696 goto done;
8697 }
8698 }
8699 else
8700 {
8701 goto done;
8702 }
8703
8704 if (0 == *tx_fail_count)
8705 {
8706 *pid = 0;
8707 goto done;
8708 }
8709
8710 pValue = param;
8711 pValue++;
8712
8713 ret = hdd_ParseUserParams(pValue, &param);
8714
8715 if (0 == ret)
8716 {
8717 if (1 != sscanf(param, "%hu", pid))
8718 {
8719 ret = -EINVAL;
8720 goto done;
8721 }
8722 }
8723 else
8724 {
8725 goto done;
8726 }
8727
8728done:
8729 return ret;
8730}
8731
8732static int hdd_open_cesium_nl_sock()
8733{
8734#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
8735 struct netlink_kernel_cfg cfg = {
8736 .groups = WLAN_NLINK_MCAST_GRP_ID,
8737 .input = NULL
8738 };
8739#endif
8740 int ret = 0;
8741
8742#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
8743 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
8744#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
8745 THIS_MODULE,
8746#endif
8747 &cfg);
8748#else
8749 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
8750 WLAN_NLINK_MCAST_GRP_ID, NULL, NULL, THIS_MODULE);
8751#endif
8752
8753 if (cesium_nl_srv_sock == NULL)
8754 {
8755 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8756 "NLINK: cesium netlink_kernel_create failed");
8757 ret = -ECONNREFUSED;
8758 }
8759
8760 return ret;
8761}
8762
8763static void hdd_close_cesium_nl_sock()
8764{
8765 if (NULL != cesium_nl_srv_sock)
8766 {
8767 netlink_kernel_release(cesium_nl_srv_sock);
8768 cesium_nl_srv_sock = NULL;
8769 }
8770}
8771#endif /* WLAN_FEATURE_RMC */
Jeff Johnson295189b2012-06-20 16:38:30 -07008772/**---------------------------------------------------------------------------
8773
8774 \brief hdd_req_bmps_cbk() - HDD Request BMPS callback function
8775
8776 This is the function invoked by SME to inform the result of BMPS
8777 request issued by HDD
8778
8779 \param - callbackcontext - Pointer to cookie
8780 status - result of request
8781
8782 \return - None
8783
8784--------------------------------------------------------------------------*/
8785void hdd_req_bmps_cbk(void *callbackContext, eHalStatus status)
8786{
8787
8788 struct completion *completion_var = (struct completion*) callbackContext;
8789
Arif Hussain6d2a3322013-11-17 19:50:10 -08008790 hddLog(VOS_TRACE_LEVEL_ERROR, "HDD BMPS request Callback, status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008791 if(completion_var != NULL)
8792 {
8793 complete(completion_var);
8794 }
8795}
8796
8797/**---------------------------------------------------------------------------
8798
8799 \brief hdd_get_cfg_file_size() -
8800
8801 This function reads the configuration file using the request firmware
8802 API and returns the configuration file size.
8803
8804 \param - pCtx - Pointer to the adapter .
8805 - pFileName - Pointer to the file name.
8806 - pBufSize - Pointer to the buffer size.
8807
8808 \return - 0 for success, non zero for failure
8809
8810 --------------------------------------------------------------------------*/
8811
8812VOS_STATUS hdd_get_cfg_file_size(v_VOID_t *pCtx, char *pFileName, v_SIZE_t *pBufSize)
8813{
8814 int status;
8815 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8816
8817 ENTER();
8818
8819 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
8820
8821 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8822 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
8823 status = VOS_STATUS_E_FAILURE;
8824 }
8825 else {
8826 *pBufSize = pHddCtx->fw->size;
8827 hddLog(VOS_TRACE_LEVEL_INFO, "%s: CFG size = %d", __func__, *pBufSize);
8828 release_firmware(pHddCtx->fw);
8829 pHddCtx->fw = NULL;
8830 }
8831
8832 EXIT();
8833 return VOS_STATUS_SUCCESS;
8834}
8835
8836/**---------------------------------------------------------------------------
8837
8838 \brief hdd_read_cfg_file() -
8839
8840 This function reads the configuration file using the request firmware
8841 API and returns the cfg data and the buffer size of the configuration file.
8842
8843 \param - pCtx - Pointer to the adapter .
8844 - pFileName - Pointer to the file name.
8845 - pBuffer - Pointer to the data buffer.
8846 - pBufSize - Pointer to the buffer size.
8847
8848 \return - 0 for success, non zero for failure
8849
8850 --------------------------------------------------------------------------*/
8851
8852VOS_STATUS hdd_read_cfg_file(v_VOID_t *pCtx, char *pFileName,
8853 v_VOID_t *pBuffer, v_SIZE_t *pBufSize)
8854{
8855 int status;
8856 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
8857
8858 ENTER();
8859
8860 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
8861
8862 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
8863 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
8864 return VOS_STATUS_E_FAILURE;
8865 }
8866 else {
8867 if(*pBufSize != pHddCtx->fw->size) {
8868 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Caller sets invalid CFG "
8869 "file size", __func__);
8870 release_firmware(pHddCtx->fw);
8871 pHddCtx->fw = NULL;
8872 return VOS_STATUS_E_FAILURE;
8873 }
8874 else {
8875 if(pBuffer) {
8876 vos_mem_copy(pBuffer,pHddCtx->fw->data,*pBufSize);
8877 }
8878 release_firmware(pHddCtx->fw);
8879 pHddCtx->fw = NULL;
8880 }
8881 }
8882
8883 EXIT();
8884
8885 return VOS_STATUS_SUCCESS;
8886}
8887
8888/**---------------------------------------------------------------------------
8889
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308890 \brief __hdd_set_mac_address() -
Jeff Johnson295189b2012-06-20 16:38:30 -07008891
8892 This function sets the user specified mac address using
8893 the command ifconfig wlanX hw ether <mac adress>.
8894
8895 \param - dev - Pointer to the net device.
8896 - addr - Pointer to the sockaddr.
8897 \return - 0 for success, non zero for failure
8898
8899 --------------------------------------------------------------------------*/
8900
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308901static int __hdd_set_mac_address(struct net_device *dev, void *addr)
Jeff Johnson295189b2012-06-20 16:38:30 -07008902{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308903 hdd_adapter_t *pAdapter;
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308904 hdd_adapter_t *adapter_temp;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308905 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07008906 struct sockaddr *psta_mac_addr = addr;
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308907 int ret = 0, i;
8908 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -07008909
8910 ENTER();
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308911 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8912 if (NULL == pAdapter)
8913 {
8914 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8915 "%s: Adapter is NULL",__func__);
8916 return -EINVAL;
8917 }
8918 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8919 ret = wlan_hdd_validate_context(pHddCtx);
8920 if (0 != ret)
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308921 return ret;
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308922
8923 memcpy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
8924 if(vos_is_macaddr_zero(&mac_addr)) {
8925 hddLog(VOS_TRACE_LEVEL_ERROR, "Zero Mac address");
8926 return -EINVAL;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05308927 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008928
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308929 if (vos_is_macaddr_broadcast(&mac_addr)) {
8930 hddLog(VOS_TRACE_LEVEL_ERROR,"MAC is Broadcast");
8931 return -EINVAL;
8932 }
8933
8934 if (vos_is_macaddr_multicast(&mac_addr)) {
8935 hddLog(VOS_TRACE_LEVEL_ERROR, "Multicast Mac address");
8936 return -EINVAL;
8937 }
8938 adapter_temp = hdd_get_adapter_by_macaddr(pHddCtx, mac_addr.bytes);
8939 if (adapter_temp) {
8940 if (!strcmp(adapter_temp->dev->name, dev->name))
8941 return 0;
8942 hddLog(VOS_TRACE_LEVEL_ERROR,
8943 "%s: WLAN Mac Addr: "
8944 MAC_ADDRESS_STR, __func__,
8945 MAC_ADDR_ARRAY(mac_addr.bytes));
8946 return -EINVAL;
8947 }
8948
8949 for (i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++) {
8950 if (!vos_mem_compare(&pAdapter->macAddressCurrent.bytes,
8951 &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], VOS_MAC_ADDR_SIZE)) {
8952 memcpy(&pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], mac_addr.bytes,
8953 VOS_MAC_ADDR_SIZE);
8954 break;
8955 }
8956 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008957 memcpy(&pAdapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008958 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
8959
8960 EXIT();
Arun Kumar Khandavalli18303eb2020-01-22 20:44:09 +05308961 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07008962}
8963
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05308964/**---------------------------------------------------------------------------
8965
8966 \brief hdd_set_mac_address() -
8967
8968 Wrapper function to protect __hdd_set_mac_address() function from ssr
8969
8970 \param - dev - Pointer to the net device.
8971 - addr - Pointer to the sockaddr.
8972 \return - 0 for success, non zero for failure
8973
8974 --------------------------------------------------------------------------*/
8975static int hdd_set_mac_address(struct net_device *dev, void *addr)
8976{
8977 int ret;
8978
8979 vos_ssr_protect(__func__);
8980 ret = __hdd_set_mac_address(dev, addr);
8981 vos_ssr_unprotect(__func__);
8982
8983 return ret;
8984}
8985
Jeff Johnson295189b2012-06-20 16:38:30 -07008986tANI_U8* wlan_hdd_get_intf_addr(hdd_context_t* pHddCtx)
8987{
8988 int i;
8989 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
8990 {
Abhishek Singheb183782014-02-06 13:37:21 +05308991 if( 0 == ((pHddCtx->cfg_ini->intfAddrMask) & (1 << i)) )
Jeff Johnson295189b2012-06-20 16:38:30 -07008992 break;
8993 }
8994
8995 if( VOS_MAX_CONCURRENCY_PERSONA == i)
8996 return NULL;
8997
8998 pHddCtx->cfg_ini->intfAddrMask |= (1 << i);
8999 return &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0];
9000}
9001
9002void wlan_hdd_release_intf_addr(hdd_context_t* pHddCtx, tANI_U8* releaseAddr)
9003{
9004 int i;
9005 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
9006 {
9007 if ( !memcmp(releaseAddr, &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], 6) )
9008 {
9009 pHddCtx->cfg_ini->intfAddrMask &= ~(1 << i);
9010 break;
9011 }
9012 }
9013 return;
9014}
9015
9016#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
9017 static struct net_device_ops wlan_drv_ops = {
9018 .ndo_open = hdd_open,
9019 .ndo_stop = hdd_stop,
9020 .ndo_uninit = hdd_uninit,
9021 .ndo_start_xmit = hdd_hard_start_xmit,
9022 .ndo_tx_timeout = hdd_tx_timeout,
9023 .ndo_get_stats = hdd_stats,
9024 .ndo_do_ioctl = hdd_ioctl,
9025 .ndo_set_mac_address = hdd_set_mac_address,
9026 .ndo_select_queue = hdd_select_queue,
9027#ifdef WLAN_FEATURE_PACKET_FILTERING
9028#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0))
9029 .ndo_set_rx_mode = hdd_set_multicast_list,
9030#else
9031 .ndo_set_multicast_list = hdd_set_multicast_list,
9032#endif //LINUX_VERSION_CODE
9033#endif
9034 };
Jeff Johnson295189b2012-06-20 16:38:30 -07009035 static struct net_device_ops wlan_mon_drv_ops = {
9036 .ndo_open = hdd_mon_open,
Katya Nigame7b69a82015-04-28 15:24:06 +05309037 .ndo_stop = hdd_mon_stop,
Jeff Johnson295189b2012-06-20 16:38:30 -07009038 .ndo_uninit = hdd_uninit,
9039 .ndo_start_xmit = hdd_mon_hard_start_xmit,
9040 .ndo_tx_timeout = hdd_tx_timeout,
9041 .ndo_get_stats = hdd_stats,
Katya Nigame7b69a82015-04-28 15:24:06 +05309042 .ndo_do_ioctl = hdd_mon_ioctl,
Jeff Johnson295189b2012-06-20 16:38:30 -07009043 .ndo_set_mac_address = hdd_set_mac_address,
9044 };
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +05309045
Jeff Johnson295189b2012-06-20 16:38:30 -07009046#endif
9047
9048void hdd_set_station_ops( struct net_device *pWlanDev )
9049{
9050#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
Jeff Johnson295189b2012-06-20 16:38:30 -07009051 pWlanDev->netdev_ops = &wlan_drv_ops;
9052#else
9053 pWlanDev->open = hdd_open;
9054 pWlanDev->stop = hdd_stop;
9055 pWlanDev->uninit = hdd_uninit;
9056 pWlanDev->hard_start_xmit = NULL;
9057 pWlanDev->tx_timeout = hdd_tx_timeout;
9058 pWlanDev->get_stats = hdd_stats;
9059 pWlanDev->do_ioctl = hdd_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07009060 pWlanDev->set_mac_address = hdd_set_mac_address;
9061#endif
9062}
9063
Katya Nigam1fd24402015-02-16 14:52:19 +05309064void hdd_set_ibss_ops( hdd_adapter_t *pAdapter )
9065{
9066 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
9067 wlan_drv_ops.ndo_start_xmit = hdd_ibss_hard_start_xmit;
9068 #else
9069 pAdapter->dev->hard_start_xmit = hdd_ibss_hard_start_xmit;
9070 #endif
9071}
9072
Jeff Johnsoneed415b2013-01-18 16:11:20 -08009073static hdd_adapter_t* hdd_alloc_station_adapter( hdd_context_t *pHddCtx, tSirMacAddr macAddr, const char* name )
Jeff Johnson295189b2012-06-20 16:38:30 -07009074{
9075 struct net_device *pWlanDev = NULL;
9076 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009077 /*
9078 * cfg80211 initialization and registration....
9079 */
Anand N Sunkadc34abbd2015-07-29 09:52:59 +05309080 pWlanDev = alloc_netdev_mq(sizeof( hdd_adapter_t ), name,
9081#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0))
9082 NET_NAME_UNKNOWN,
9083#endif
9084 ether_setup, NUM_TX_QUEUES);
Jeff Johnson295189b2012-06-20 16:38:30 -07009085 if(pWlanDev != NULL)
9086 {
9087
9088 //Save the pointer to the net_device in the HDD adapter
9089 pAdapter = (hdd_adapter_t*) netdev_priv( pWlanDev );
9090
Jeff Johnson295189b2012-06-20 16:38:30 -07009091 vos_mem_zero( pAdapter, sizeof( hdd_adapter_t ) );
9092
9093 pAdapter->dev = pWlanDev;
9094 pAdapter->pHddCtx = pHddCtx;
9095 pAdapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Agarwal Ashish47d18112014-08-04 19:55:07 +05309096 spin_lock_init(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -07009097
Rajeev79dbe4c2013-10-05 11:03:42 +05309098#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev79dbe4c2013-10-05 11:03:42 +05309099 pAdapter->pBatchScanRsp = NULL;
9100 pAdapter->numScanList = 0;
Rajeev Kumar20140c12013-10-21 19:39:02 -07009101 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08009102 pAdapter->prev_batch_id = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05309103 mutex_init(&pAdapter->hdd_batch_scan_lock);
9104#endif
9105
Jeff Johnson295189b2012-06-20 16:38:30 -07009106 pAdapter->isLinkUpSvcNeeded = FALSE;
9107 pAdapter->higherDtimTransition = eANI_BOOLEAN_TRUE;
9108 //Init the net_device structure
9109 strlcpy(pWlanDev->name, name, IFNAMSIZ);
9110
9111 vos_mem_copy(pWlanDev->dev_addr, (void *)macAddr, sizeof(tSirMacAddr));
9112 vos_mem_copy( pAdapter->macAddressCurrent.bytes, macAddr, sizeof(tSirMacAddr));
9113 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Alok Kumar84458542018-05-14 15:03:08 +05309114
9115 pWlanDev->needed_headroom = LIBRA_HW_NEEDED_HEADROOM;
Jeff Johnson295189b2012-06-20 16:38:30 -07009116
9117 hdd_set_station_ops( pAdapter->dev );
9118
9119 pWlanDev->destructor = free_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009120 pWlanDev->ieee80211_ptr = &pAdapter->wdev ;
9121 pAdapter->wdev.wiphy = pHddCtx->wiphy;
9122 pAdapter->wdev.netdev = pWlanDev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009123 /* set pWlanDev's parent to underlying device */
9124 SET_NETDEV_DEV(pWlanDev, pHddCtx->parent_dev);
Kumar Anand82c009f2014-05-29 00:29:42 -07009125
9126 hdd_wmm_init( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07009127 }
9128
9129 return pAdapter;
9130}
9131
9132VOS_STATUS hdd_register_interface( hdd_adapter_t *pAdapter, tANI_U8 rtnl_lock_held )
9133{
9134 struct net_device *pWlanDev = pAdapter->dev;
9135 //hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
9136 //hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
9137 //eHalStatus halStatus = eHAL_STATUS_SUCCESS;
9138
9139 if( rtnl_lock_held )
9140 {
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -08009141 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
Jeff Johnson295189b2012-06-20 16:38:30 -07009142 if( dev_alloc_name(pWlanDev, pWlanDev->name) < 0 )
9143 {
9144 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:dev_alloc_name",__func__);
9145 return VOS_STATUS_E_FAILURE;
9146 }
9147 }
9148 if (register_netdevice(pWlanDev))
9149 {
9150 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:register_netdev",__func__);
9151 return VOS_STATUS_E_FAILURE;
9152 }
9153 }
9154 else
9155 {
9156 if(register_netdev(pWlanDev))
9157 {
9158 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed:register_netdev",__func__);
9159 return VOS_STATUS_E_FAILURE;
9160 }
9161 }
9162 set_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags);
9163
9164 return VOS_STATUS_SUCCESS;
9165}
9166
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009167static eHalStatus hdd_smeCloseSessionCallback(void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07009168{
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009169 hdd_adapter_t *pAdapter = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07009170
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009171 if (NULL == pAdapter)
9172 {
9173 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: NULL pAdapter", __func__);
9174 return eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07009175 }
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009176
9177 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
9178 {
9179 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Invalid magic", __func__);
9180 return eHAL_STATUS_NOT_INITIALIZED;
9181 }
9182
9183 clear_bit(SME_SESSION_OPENED, &pAdapter->event_flags);
9184
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009185#ifndef WLAN_OPEN_SOURCE
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009186 /* need to make sure all of our scheduled work has completed.
9187 * This callback is called from MC thread context, so it is safe to
9188 * to call below flush workqueue API from here.
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009189 *
9190 * Even though this is called from MC thread context, if there is a faulty
9191 * work item in the system, that can hang this call forever. So flushing
9192 * this global work queue is not safe; and now we make sure that
9193 * individual work queues are stopped correctly. But the cancel work queue
9194 * is a GPL only API, so the proprietary version of the driver would still
9195 * rely on the global work queue flush.
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009196 */
9197 flush_scheduled_work();
Sameer Thalappilbee426e2013-10-30 10:30:30 -07009198#endif
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009199
9200 /* We can be blocked while waiting for scheduled work to be
9201 * flushed, and the adapter structure can potentially be freed, in
9202 * which case the magic will have been reset. So make sure the
9203 * magic is still good, and hence the adapter structure is still
9204 * valid, before signaling completion */
9205 if (WLAN_HDD_ADAPTER_MAGIC == pAdapter->magic)
9206 {
9207 complete(&pAdapter->session_close_comp_var);
9208 }
9209
Jeff Johnson295189b2012-06-20 16:38:30 -07009210 return eHAL_STATUS_SUCCESS;
9211}
Manjeet Singh47ee8472016-04-11 11:57:18 +05309212/**
9213 * hdd_close_tx_queues() - close tx queues
9214 * @hdd_ctx: hdd global context
9215 *
9216 * Return: None
9217 */
9218static void hdd_close_tx_queues(hdd_context_t *hdd_ctx)
9219{
9220 VOS_STATUS status;
9221 hdd_adapter_t *adapter;
9222 hdd_adapter_list_node_t *adapter_node = NULL, *next_adapter = NULL;
9223 /* Not validating hdd_ctx as it's already done by the caller */
9224 ENTER();
9225 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9226 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status) {
9227 adapter = adapter_node->pAdapter;
9228 if (adapter && adapter->dev) {
9229 netif_tx_disable (adapter->dev);
9230 netif_carrier_off(adapter->dev);
9231 }
9232 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
9233 &next_adapter);
9234 adapter_node = next_adapter;
9235 }
9236 EXIT();
9237}
Jeff Johnson295189b2012-06-20 16:38:30 -07009238
9239VOS_STATUS hdd_init_station_mode( hdd_adapter_t *pAdapter )
9240{
9241 struct net_device *pWlanDev = pAdapter->dev;
9242 hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
9243 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
9244 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
9245 VOS_STATUS status = VOS_STATUS_E_FAILURE;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309246 long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07009247
Nirav Shah7e3c8132015-06-22 23:51:42 +05309248 spin_lock_init( &pAdapter->sta_hash_lock);
9249 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
9250
Jeff Johnson295189b2012-06-20 16:38:30 -07009251 INIT_COMPLETION(pAdapter->session_open_comp_var);
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07009252 sme_SetCurrDeviceMode(pHddCtx->hHal, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07009253 //Open a SME session for future operation
9254 halStatus = sme_OpenSession( pHddCtx->hHal, hdd_smeRoamCallback, pAdapter,
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07009255 (tANI_U8 *)&pAdapter->macAddressCurrent, &pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07009256 if ( !HAL_STATUS_SUCCESS( halStatus ) )
9257 {
9258 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009259 "sme_OpenSession() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009260 halStatus, halStatus );
9261 status = VOS_STATUS_E_FAILURE;
9262 goto error_sme_open;
9263 }
9264
9265 //Block on a completion variable. Can't wait forever though.
Vinay Krishna Eranna0fe2e7c2014-04-09 21:32:08 +05309266 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07009267 &pAdapter->session_open_comp_var,
9268 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309269 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07009270 {
9271 hddLog(VOS_TRACE_LEVEL_FATAL,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309272 "Session is not opened within timeout period code %ld", rc );
Jeff Johnson295189b2012-06-20 16:38:30 -07009273 status = VOS_STATUS_E_FAILURE;
9274 goto error_sme_open;
9275 }
9276
9277 // Register wireless extensions
9278 if( eHAL_STATUS_SUCCESS != (halStatus = hdd_register_wext(pWlanDev)))
9279 {
9280 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009281 "hdd_register_wext() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009282 halStatus, halStatus );
9283 status = VOS_STATUS_E_FAILURE;
9284 goto error_register_wext;
9285 }
Katya Nigam1fd24402015-02-16 14:52:19 +05309286
Jeff Johnson295189b2012-06-20 16:38:30 -07009287 //Safe to register the hard_start_xmit function again
Katya Nigam1fd24402015-02-16 14:52:19 +05309288 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
9289 wlan_drv_ops.ndo_start_xmit = hdd_hard_start_xmit;
9290 #else
9291 pWlanDev->hard_start_xmit = hdd_hard_start_xmit;
9292 #endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009293
9294 //Set the Connection State to Not Connected
Abhishek Singhf4669da2014-05-26 15:07:49 +05309295 hddLog(VOS_TRACE_LEVEL_INFO,
9296 "%s: Set HDD connState to eConnectionState_NotConnected",
9297 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009298 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
9299
9300 //Set the default operation channel
9301 pHddStaCtx->conn_info.operationChannel = pHddCtx->cfg_ini->OperatingChannel;
9302
9303 /* Make the default Auth Type as OPEN*/
9304 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
9305
9306 if( VOS_STATUS_SUCCESS != ( status = hdd_init_tx_rx( pAdapter ) ) )
9307 {
9308 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009309 "hdd_init_tx_rx() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009310 status, status );
9311 goto error_init_txrx;
9312 }
9313
9314 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9315
9316 if( VOS_STATUS_SUCCESS != ( status = hdd_wmm_adapter_init( pAdapter ) ) )
9317 {
9318 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009319 "hdd_wmm_adapter_init() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07009320 status, status );
9321 goto error_wmm_init;
9322 }
9323
9324 set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9325
9326 return VOS_STATUS_SUCCESS;
9327
9328error_wmm_init:
9329 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9330 hdd_deinit_tx_rx(pAdapter);
9331error_init_txrx:
9332 hdd_UnregisterWext(pWlanDev);
9333error_register_wext:
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009334 if (test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07009335 {
9336 INIT_COMPLETION(pAdapter->session_close_comp_var);
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009337 if (eHAL_STATUS_SUCCESS == sme_CloseSession(pHddCtx->hHal,
Agrawal Ashish5a3522c2016-03-02 15:08:28 +05309338 pAdapter->sessionId, FALSE, VOS_TRUE,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009339 hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07009340 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309341 unsigned long rc;
9342
Jeff Johnson295189b2012-06-20 16:38:30 -07009343 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309344 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07009345 &pAdapter->session_close_comp_var,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07009346 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309347 if (rc <= 0)
9348 hddLog(VOS_TRACE_LEVEL_ERROR,
9349 FL("Session is not opened within timeout period code %ld"), rc);
Jeff Johnson295189b2012-06-20 16:38:30 -07009350 }
9351}
9352error_sme_open:
9353 return status;
9354}
9355
Jeff Johnson295189b2012-06-20 16:38:30 -07009356void hdd_cleanup_actionframe( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
9357{
9358 hdd_cfg80211_state_t *cfgState;
9359
9360 cfgState = WLAN_HDD_GET_CFG_STATE_PTR( pAdapter );
9361
9362 if( NULL != cfgState->buf )
9363 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309364 long rc;
Jeff Johnson295189b2012-06-20 16:38:30 -07009365 INIT_COMPLETION(pAdapter->tx_action_cnf_event);
9366 rc = wait_for_completion_interruptible_timeout(
9367 &pAdapter->tx_action_cnf_event,
9368 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309369 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07009370 {
Deepthi Gowri91b3e9c2015-08-25 13:14:58 +05309371 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9372 "%s ERROR: HDD Wait for Action Confirmation Failed!! %ld"
9373 , __func__, rc);
9374
9375 // Inform tx status as FAILURE to upper layer and free cfgState->buf
9376 hdd_sendActionCnf( pAdapter, FALSE );
Jeff Johnson295189b2012-06-20 16:38:30 -07009377 }
9378 }
9379 return;
9380}
Jeff Johnson295189b2012-06-20 16:38:30 -07009381
c_hpothu002231a2015-02-05 14:58:51 +05309382void hdd_deinit_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
Jeff Johnson295189b2012-06-20 16:38:30 -07009383{
9384 ENTER();
9385 switch ( pAdapter->device_mode )
9386 {
Katya Nigam1fd24402015-02-16 14:52:19 +05309387 case WLAN_HDD_IBSS:
9388 {
9389 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9390 {
9391 hdd_ibss_deinit_tx_rx( pAdapter );
9392 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9393 }
9394 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009395 case WLAN_HDD_INFRA_STATION:
9396 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009397 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07009398 {
9399 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9400 {
9401 hdd_deinit_tx_rx( pAdapter );
9402 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9403 }
9404
9405 if(test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
9406 {
9407 hdd_wmm_adapter_close( pAdapter );
9408 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9409 }
9410
Jeff Johnson295189b2012-06-20 16:38:30 -07009411 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009412 break;
9413 }
9414
9415 case WLAN_HDD_SOFTAP:
9416 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009417 {
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05309418
9419 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
9420 {
9421 hdd_wmm_adapter_close( pAdapter );
9422 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9423 }
9424
Jeff Johnson295189b2012-06-20 16:38:30 -07009425 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009426
c_hpothu002231a2015-02-05 14:58:51 +05309427 hdd_unregister_hostapd(pAdapter, rtnl_held);
Agrawal Ashisha0584d42016-09-29 13:03:45 +05309428 /* set con_mode to STA only when no SAP concurrency mode */
9429 if (!(hdd_get_concurrency_mode() & (VOS_SAP | VOS_P2P_GO)))
9430 hdd_set_conparam(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07009431 break;
9432 }
9433
9434 case WLAN_HDD_MONITOR:
9435 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009436 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
9437 {
9438 hdd_deinit_tx_rx( pAdapter );
9439 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
9440 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009441 break;
9442 }
9443
9444
9445 default:
9446 break;
9447 }
9448
9449 EXIT();
9450}
9451
9452void hdd_cleanup_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
9453{
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08009454 struct net_device *pWlanDev = NULL;
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309455
9456 ENTER();
9457 if (NULL == pAdapter)
9458 {
9459 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9460 "%s: HDD adapter is Null", __func__);
9461 return;
9462 }
9463
9464 pWlanDev = pAdapter->dev;
Jeff Johnson295189b2012-06-20 16:38:30 -07009465
Rajeev79dbe4c2013-10-05 11:03:42 +05309466#ifdef FEATURE_WLAN_BATCH_SCAN
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309467 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
9468 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Rajeev Kumarf999e582014-01-09 17:33:29 -08009469 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309470 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
9471 )
9472 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08009473 if (pAdapter)
Rajeev79dbe4c2013-10-05 11:03:42 +05309474 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08009475 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
9476 {
9477 hdd_deinit_batch_scan(pAdapter);
9478 }
Rajeev79dbe4c2013-10-05 11:03:42 +05309479 }
Rajeev Kumarf999e582014-01-09 17:33:29 -08009480 }
Rajeev79dbe4c2013-10-05 11:03:42 +05309481#endif
9482
Jeff Johnson295189b2012-06-20 16:38:30 -07009483 if(test_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags)) {
9484 if( rtnl_held )
9485 {
9486 unregister_netdevice(pWlanDev);
9487 }
9488 else
9489 {
9490 unregister_netdev(pWlanDev);
9491 }
9492 // note that the pAdapter is no longer valid at this point
9493 // since the memory has been reclaimed
9494 }
9495
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05309496 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07009497}
9498
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009499void hdd_set_pwrparams(hdd_context_t *pHddCtx)
9500{
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309501 VOS_STATUS status;
9502 hdd_adapter_t *pAdapter = NULL;
9503 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009504
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309505 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009506
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309507 /*loop through all adapters.*/
9508 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009509 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309510 pAdapter = pAdapterNode->pAdapter;
9511 if ( (WLAN_HDD_INFRA_STATION != pAdapter->device_mode)
9512 && (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009513
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309514 { // we skip this registration for modes other than STA and P2P client modes.
9515 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9516 pAdapterNode = pNext;
9517 continue;
9518 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009519
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309520 //Apply Dynamic DTIM For P2P
9521 //Only if ignoreDynamicDtimInP2pMode is not set in ini
9522 if ((pHddCtx->cfg_ini->enableDynamicDTIM ||
9523 pHddCtx->cfg_ini->enableModulatedDTIM) &&
9524 ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
9525 ((WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) &&
9526 !(pHddCtx->cfg_ini->ignoreDynamicDtimInP2pMode))) &&
9527 (eANI_BOOLEAN_TRUE == pAdapter->higherDtimTransition) &&
9528 (eConnectionState_Associated ==
9529 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState) &&
9530 (pHddCtx->cfg_ini->fIsBmpsEnabled))
9531 {
9532 tSirSetPowerParamsReq powerRequest = { 0 };
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009533
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309534 powerRequest.uIgnoreDTIM = 1;
9535 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
9536
9537 if (pHddCtx->cfg_ini->enableModulatedDTIM)
9538 {
9539 powerRequest.uDTIMPeriod = pHddCtx->cfg_ini->enableModulatedDTIM;
9540 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
9541 }
9542 else
9543 {
9544 powerRequest.uListenInterval = pHddCtx->cfg_ini->enableDynamicDTIM;
9545 }
9546
9547 /* Update ignoreDTIM and ListedInterval in CFG to remain at the DTIM
9548 * specified during Enter/Exit BMPS when LCD off*/
9549 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
9550 NULL, eANI_BOOLEAN_FALSE);
9551 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
9552 NULL, eANI_BOOLEAN_FALSE);
9553
9554 /* switch to the DTIM specified in cfg.ini */
9555 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Abhishek Singh1e390cf2015-10-27 13:45:17 +05309556 "Switch to DTIM %d Listen interval %d",
9557 powerRequest.uDTIMPeriod,
9558 powerRequest.uListenInterval);
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05309559 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
9560 break;
9561
9562 }
9563
9564 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9565 pAdapterNode = pNext;
9566 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009567}
9568
9569void hdd_reset_pwrparams(hdd_context_t *pHddCtx)
9570{
9571 /*Switch back to DTIM 1*/
9572 tSirSetPowerParamsReq powerRequest = { 0 };
9573
9574 powerRequest.uIgnoreDTIM = pHddCtx->hdd_actual_ignore_DTIM_value;
9575 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
Yue Mac24062f2013-05-13 17:01:29 -07009576 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08009577
9578 /* Update ignoreDTIM and ListedInterval in CFG with default values */
9579 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
9580 NULL, eANI_BOOLEAN_FALSE);
9581 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
9582 NULL, eANI_BOOLEAN_FALSE);
9583
9584 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9585 "Switch to DTIM%d",powerRequest.uListenInterval);
9586 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
9587
9588}
9589
Jeff Johnson295189b2012-06-20 16:38:30 -07009590VOS_STATUS hdd_enable_bmps_imps(hdd_context_t *pHddCtx)
9591{
9592 VOS_STATUS status = VOS_STATUS_SUCCESS;
Sushant Kaushik4928e542014-12-29 15:25:54 +05309593 if (WLAN_HDD_IS_UNLOAD_IN_PROGRESS(pHddCtx))
9594 {
9595 hddLog( LOGE, FL("Wlan Unload in progress"));
9596 return VOS_STATUS_E_PERM;
9597 }
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309598
9599 if (wlan_hdd_check_monitor_state(pHddCtx)) {
9600 hddLog(LOG1, FL("Monitor mode is started, cannot enable BMPS"));
9601 return VOS_STATUS_SUCCESS;
9602 }
9603
Jeff Johnson295189b2012-06-20 16:38:30 -07009604 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
9605 {
9606 sme_EnablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
9607 }
9608
9609 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
9610 {
9611 sme_StartAutoBmpsTimer(pHddCtx->hHal);
9612 }
9613
9614 if (pHddCtx->cfg_ini->fIsImpsEnabled)
9615 {
9616 sme_EnablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
9617 }
9618
9619 return status;
9620}
9621
9622VOS_STATUS hdd_disable_bmps_imps(hdd_context_t *pHddCtx, tANI_U8 session_type)
9623{
9624 hdd_adapter_t *pAdapter = NULL;
9625 eHalStatus halStatus;
9626 VOS_STATUS status = VOS_STATUS_E_INVAL;
9627 v_BOOL_t disableBmps = FALSE;
9628 v_BOOL_t disableImps = FALSE;
9629
9630 switch(session_type)
9631 {
9632 case WLAN_HDD_INFRA_STATION:
9633 case WLAN_HDD_SOFTAP:
Jeff Johnson295189b2012-06-20 16:38:30 -07009634 case WLAN_HDD_P2P_CLIENT:
9635 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009636 //Exit BMPS -> Is Sta/P2P Client is already connected
9637 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
9638 if((NULL != pAdapter)&&
9639 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
9640 {
9641 disableBmps = TRUE;
9642 }
9643
9644 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_CLIENT);
9645 if((NULL != pAdapter)&&
9646 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
9647 {
9648 disableBmps = TRUE;
9649 }
9650
9651 //Exit both Bmps and Imps incase of Go/SAP Mode
9652 if((WLAN_HDD_SOFTAP == session_type) ||
9653 (WLAN_HDD_P2P_GO == session_type))
9654 {
9655 disableBmps = TRUE;
9656 disableImps = TRUE;
9657 }
9658
9659 if(TRUE == disableImps)
9660 {
9661 if (pHddCtx->cfg_ini->fIsImpsEnabled)
9662 {
9663 sme_DisablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
9664 }
9665 }
9666
9667 if(TRUE == disableBmps)
9668 {
9669 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
9670 {
9671 halStatus = sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
9672
9673 if(eHAL_STATUS_SUCCESS != halStatus)
9674 {
9675 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009676 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Disable Power Save", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009677 VOS_ASSERT(0);
9678 return status;
9679 }
9680 }
9681
9682 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
9683 {
9684 halStatus = sme_StopAutoBmpsTimer(pHddCtx->hHal);
9685
9686 if(eHAL_STATUS_SUCCESS != halStatus)
9687 {
9688 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009689 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Stop Auto Bmps Timer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009690 VOS_ASSERT(0);
9691 return status;
9692 }
9693 }
9694 }
9695
9696 if((TRUE == disableBmps) ||
9697 (TRUE == disableImps))
9698 {
9699 /* Now, get the chip into Full Power now */
9700 INIT_COMPLETION(pHddCtx->full_pwr_comp_var);
9701 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_pwr_cbk,
9702 pHddCtx, eSME_FULL_PWR_NEEDED_BY_HDD);
9703
9704 if(halStatus != eHAL_STATUS_SUCCESS)
9705 {
9706 if(halStatus == eHAL_STATUS_PMC_PENDING)
9707 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309708 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07009709 //Block on a completion variable. Can't wait forever though
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309710 ret = wait_for_completion_interruptible_timeout(
9711 &pHddCtx->full_pwr_comp_var,
9712 msecs_to_jiffies(1000));
9713 if (ret <= 0)
9714 {
9715 hddLog(VOS_TRACE_LEVEL_ERROR,
9716 "%s: wait on full_pwr_comp_var failed %ld",
9717 __func__, ret);
9718 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009719 }
9720 else
9721 {
9722 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08009723 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Request for Full Power failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009724 VOS_ASSERT(0);
9725 return status;
9726 }
9727 }
9728
9729 status = VOS_STATUS_SUCCESS;
9730 }
9731
9732 break;
9733 }
9734 return status;
9735}
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309736
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309737void hdd_mon_post_msg_cb(void *context)
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309738{
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309739 struct hdd_request *request;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309740
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309741 request = hdd_request_get(context);
9742 if (!request) {
9743 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
9744 return;
9745 }
9746
9747 hdd_request_complete(request);
9748 hdd_request_put(request);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309749}
9750
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +05309751
Katya Nigame7b69a82015-04-28 15:24:06 +05309752void hdd_init_mon_mode (hdd_adapter_t *pAdapter)
9753 {
9754 hdd_mon_ctx_t *pMonCtx = NULL;
Katya Nigame7b69a82015-04-28 15:24:06 +05309755
Rajeev Kumar Sirasanagandla54447612018-03-06 15:49:56 +05309756 spin_lock_init(&pAdapter->sta_hash_lock);
9757 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
9758
9759 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
Katya Nigame7b69a82015-04-28 15:24:06 +05309760 pMonCtx->state = 0;
9761 pMonCtx->ChannelNo = 1;
9762 pMonCtx->ChannelBW = 20;
Katya Nigamd7d3a1f2015-06-11 14:04:24 +05309763 pMonCtx->crcCheckEnabled = 1;
9764 pMonCtx->typeSubtypeBitmap = 0xFFFF00000000;
9765 pMonCtx->is80211to803ConReq = 1;
Katya Nigame7b69a82015-04-28 15:24:06 +05309766 pMonCtx->numOfMacFilters = 0;
9767 }
9768
Jeff Johnson295189b2012-06-20 16:38:30 -07009769
9770hdd_adapter_t* hdd_open_adapter( hdd_context_t *pHddCtx, tANI_U8 session_type,
Jeff Johnsoneed415b2013-01-18 16:11:20 -08009771 const char *iface_name, tSirMacAddr macAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -07009772 tANI_U8 rtnl_held )
9773{
9774 hdd_adapter_t *pAdapter = NULL;
9775 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
9776 VOS_STATUS status = VOS_STATUS_E_FAILURE;
9777 VOS_STATUS exitbmpsStatus;
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309778 v_CONTEXT_t pVosContext = NULL;
9779
9780 /* No need to check for NULL, reaching this step
9781 * means vos context is initialized
9782 */
9783 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
Jeff Johnson295189b2012-06-20 16:38:30 -07009784
Arif Hussain6d2a3322013-11-17 19:50:10 -08009785 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s iface =%s type = %d",__func__,iface_name,session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009786
Nirav Shah436658f2014-02-28 17:05:45 +05309787 if(macAddr == NULL)
9788 {
9789 /* Not received valid macAddr */
9790 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9791 "%s:Unable to add virtual intf: Not able to get"
9792 "valid mac address",__func__);
9793 return NULL;
9794 }
9795
Jeff Johnson295189b2012-06-20 16:38:30 -07009796 //Disable BMPS incase of Concurrency
9797 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, session_type);
9798
9799 if(VOS_STATUS_E_FAILURE == exitbmpsStatus)
9800 {
9801 //Fail to Exit BMPS
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309802 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Exit BMPS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009803 VOS_ASSERT(0);
9804 return NULL;
9805 }
9806
9807 switch(session_type)
9808 {
9809 case WLAN_HDD_INFRA_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07009810 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009811 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07009812 {
9813 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9814
9815 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309816 {
9817 hddLog(VOS_TRACE_LEVEL_FATAL,
9818 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009819 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309820 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009821
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309822#ifdef FEATURE_WLAN_TDLS
9823 /* A Mutex Lock is introduced while changing/initializing the mode to
9824 * protect the concurrent access for the Adapters by TDLS module.
9825 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05309826 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309827#endif
9828
Jeff Johnsone7245742012-09-05 17:12:55 -07009829 pAdapter->wdev.iftype = (session_type == WLAN_HDD_P2P_CLIENT) ?
9830 NL80211_IFTYPE_P2P_CLIENT:
9831 NL80211_IFTYPE_STATION;
Jeff Johnson295189b2012-06-20 16:38:30 -07009832
Jeff Johnson295189b2012-06-20 16:38:30 -07009833 pAdapter->device_mode = session_type;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309834#ifdef FEATURE_WLAN_TDLS
9835 mutex_unlock(&pHddCtx->tdls_lock);
9836#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05309837
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309838 hdd_initialize_adapter_common(pAdapter);
Sunil Dutt66485cb2013-12-19 19:05:03 +05309839 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07009840 if( VOS_STATUS_SUCCESS != status )
9841 goto err_free_netdev;
9842
9843 status = hdd_register_interface( pAdapter, rtnl_held );
9844 if( VOS_STATUS_SUCCESS != status )
9845 {
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05309846#ifdef FEATURE_WLAN_TDLS
9847 mutex_lock(&pHddCtx->tdls_lock);
9848#endif
c_hpothu002231a2015-02-05 14:58:51 +05309849 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05309850#ifdef FEATURE_WLAN_TDLS
9851 mutex_unlock(&pHddCtx->tdls_lock);
9852#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009853 goto err_free_netdev;
9854 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309855
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05309856 // Workqueue which gets scheduled in IPv4 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309857 vos_init_work(&pAdapter->ipv4NotifierWorkQueue, hdd_ipv4_notifier_work_queue);
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05309858
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309859#ifdef WLAN_NS_OFFLOAD
9860 // Workqueue which gets scheduled in IPv6 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309861 vos_init_work(&pAdapter->ipv6NotifierWorkQueue, hdd_ipv6_notifier_work_queue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05309862#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009863 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309864 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009865 netif_tx_disable(pAdapter->dev);
9866 //netif_tx_disable(pWlanDev);
9867 netif_carrier_off(pAdapter->dev);
9868
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309869 if (WLAN_HDD_P2P_CLIENT == session_type ||
9870 WLAN_HDD_P2P_DEVICE == session_type)
9871 {
9872 /* Initialize the work queue to defer the
9873 * back to back RoC request */
Anand N Sunkaddc63c792015-06-03 14:33:24 +05309874 vos_init_delayed_work(&pAdapter->roc_work,
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309875 hdd_p2p_roc_work_queue);
9876 }
9877
Jeff Johnson295189b2012-06-20 16:38:30 -07009878 break;
9879 }
9880
Jeff Johnson295189b2012-06-20 16:38:30 -07009881 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07009882 case WLAN_HDD_SOFTAP:
9883 {
9884 pAdapter = hdd_wlan_create_ap_dev( pHddCtx, macAddr, (tANI_U8 *)iface_name );
9885 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309886 {
9887 hddLog(VOS_TRACE_LEVEL_FATAL,
9888 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009889 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309890 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009891
Jeff Johnson295189b2012-06-20 16:38:30 -07009892 pAdapter->wdev.iftype = (session_type == WLAN_HDD_SOFTAP) ?
9893 NL80211_IFTYPE_AP:
9894 NL80211_IFTYPE_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07009895 pAdapter->device_mode = session_type;
9896
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309897 hdd_initialize_adapter_common(pAdapter);
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +05309898 status = hdd_init_ap_mode(pAdapter, false);
Jeff Johnson295189b2012-06-20 16:38:30 -07009899 if( VOS_STATUS_SUCCESS != status )
9900 goto err_free_netdev;
9901
Nirav Shah7e3c8132015-06-22 23:51:42 +05309902 status = hdd_sta_id_hash_attach(pAdapter);
9903 if (VOS_STATUS_SUCCESS != status)
9904 {
9905 hddLog(VOS_TRACE_LEVEL_FATAL,
9906 FL("failed to attach hash for session %d"), session_type);
9907 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
9908 goto err_free_netdev;
9909 }
9910
Jeff Johnson295189b2012-06-20 16:38:30 -07009911 status = hdd_register_hostapd( pAdapter, rtnl_held );
9912 if( VOS_STATUS_SUCCESS != status )
9913 {
c_hpothu002231a2015-02-05 14:58:51 +05309914 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Jeff Johnson295189b2012-06-20 16:38:30 -07009915 goto err_free_netdev;
9916 }
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309917 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009918 netif_tx_disable(pAdapter->dev);
9919 netif_carrier_off(pAdapter->dev);
9920
9921 hdd_set_conparam( 1 );
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309922
Hanumanth Reddy Pothulab4537b82018-03-02 12:20:38 +05309923 // Workqueue which gets scheduled in IPv4 notification callback.
9924 vos_init_work(&pAdapter->ipv4NotifierWorkQueue,
9925 hdd_ipv4_notifier_work_queue);
9926
9927#ifdef WLAN_NS_OFFLOAD
9928 // Workqueue which gets scheduled in IPv6 notification callback.
9929 vos_init_work(&pAdapter->ipv6NotifierWorkQueue,
9930 hdd_ipv6_notifier_work_queue);
9931#endif
9932
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05309933 if (WLAN_HDD_P2P_GO == session_type)
9934 {
9935 /* Initialize the work queue to
9936 * defer the back to back RoC request */
9937 INIT_DELAYED_WORK(&pAdapter->roc_work,
9938 hdd_p2p_roc_work_queue);
9939 }
Bhargav Shahd0715912015-10-01 18:17:37 +05309940
Jeff Johnson295189b2012-06-20 16:38:30 -07009941 break;
9942 }
9943 case WLAN_HDD_MONITOR:
9944 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009945 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9946 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309947 {
9948 hddLog(VOS_TRACE_LEVEL_FATAL,
9949 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07009950 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309951 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009952
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309953 pAdapter->device_mode = session_type;
9954 pAdapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
9955
Katya Nigame7b69a82015-04-28 15:24:06 +05309956 // Register wireless extensions
9957 if( VOS_STATUS_SUCCESS != (status = hdd_register_wext(pAdapter->dev)))
9958 {
9959 hddLog(VOS_TRACE_LEVEL_FATAL,
9960 "hdd_register_wext() failed with status code %08d [x%08x]",
9961 status, status );
9962 status = VOS_STATUS_E_FAILURE;
9963 }
9964
Jeff Johnson295189b2012-06-20 16:38:30 -07009965#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29)
9966 pAdapter->dev->netdev_ops = &wlan_mon_drv_ops;
9967#else
9968 pAdapter->dev->open = hdd_mon_open;
9969 pAdapter->dev->hard_start_xmit = hdd_mon_hard_start_xmit;
Katya Nigame7b69a82015-04-28 15:24:06 +05309970 pAdapter->dev->stop = hdd_mon_stop;
9971 pAdapter->dev->do_ioctl = hdd_mon_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07009972#endif
Katya Nigame7b69a82015-04-28 15:24:06 +05309973 hdd_init_mon_mode( pAdapter );
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05309974 hdd_initialize_adapter_common(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009975 hdd_init_tx_rx( pAdapter );
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309976
9977 if (VOS_MONITOR_MODE != hdd_get_conparam())
9978 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
9979
Jeff Johnson295189b2012-06-20 16:38:30 -07009980 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +05309981 status = hdd_register_interface( pAdapter, rtnl_held );
Katya Nigame7b69a82015-04-28 15:24:06 +05309982 //Stop the Interface TX queue.
9983 netif_tx_disable(pAdapter->dev);
9984 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07009985 }
9986 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07009987 case WLAN_HDD_FTM:
9988 {
9989 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
9990
9991 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309992 {
9993 hddLog(VOS_TRACE_LEVEL_FATAL,
9994 FL("failed to allocate adapter for session %d"), session_type);
9995 return NULL;
9996 }
9997
Jeff Johnson295189b2012-06-20 16:38:30 -07009998 /* Assign NL80211_IFTYPE_STATION as interface type to resolve Kernel Warning
9999 * message while loading driver in FTM mode. */
10000 pAdapter->wdev.iftype = NL80211_IFTYPE_STATION;
10001 pAdapter->device_mode = session_type;
10002 status = hdd_register_interface( pAdapter, rtnl_held );
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +053010003
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053010004 hdd_initialize_adapter_common(pAdapter);
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +053010005 hdd_init_tx_rx( pAdapter );
10006
10007 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +053010008 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +053010009 netif_tx_disable(pAdapter->dev);
10010 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070010011 }
10012 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070010013 default:
10014 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010015 hddLog(VOS_TRACE_LEVEL_FATAL,"%s Invalid session type %d",
10016 __func__, session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -070010017 VOS_ASSERT(0);
10018 return NULL;
10019 }
10020 }
10021
Jeff Johnson295189b2012-06-20 16:38:30 -070010022 if( VOS_STATUS_SUCCESS == status )
10023 {
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053010024 //Add it to the hdd's session list.
Jeff Johnson295189b2012-06-20 16:38:30 -070010025 pHddAdapterNode = vos_mem_malloc( sizeof( hdd_adapter_list_node_t ) );
10026 if( NULL == pHddAdapterNode )
10027 {
10028 status = VOS_STATUS_E_NOMEM;
10029 }
10030 else
10031 {
10032 pHddAdapterNode->pAdapter = pAdapter;
10033 status = hdd_add_adapter_back ( pHddCtx,
10034 pHddAdapterNode );
10035 }
10036 }
10037
10038 if( VOS_STATUS_SUCCESS != status )
10039 {
10040 if( NULL != pAdapter )
10041 {
10042 hdd_cleanup_adapter( pHddCtx, pAdapter, rtnl_held );
10043 pAdapter = NULL;
10044 }
10045 if( NULL != pHddAdapterNode )
10046 {
10047 vos_mem_free( pHddAdapterNode );
10048 }
10049
10050 goto resume_bmps;
10051 }
10052
10053 if(VOS_STATUS_SUCCESS == status)
10054 {
10055 wlan_hdd_set_concurrency_mode(pHddCtx, session_type);
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -070010056 //Initialize the WoWL service
10057 if(!hdd_init_wowl(pAdapter))
10058 {
10059 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_init_wowl failed",__func__);
10060 goto err_free_netdev;
10061 }
Manjeet Singh3ed79242017-01-11 19:04:32 +053010062 //Initialize the TSF capture data
10063 wlan_hdd_tsf_init(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010064 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010065 return pAdapter;
10066
10067err_free_netdev:
Jeff Johnson295189b2012-06-20 16:38:30 -070010068 wlan_hdd_release_intf_addr( pHddCtx,
10069 pAdapter->macAddressCurrent.bytes );
Hanumanth Reddy Pothulaab8e1942018-05-24 18:10:39 +053010070 free_netdev(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070010071
10072resume_bmps:
10073 //If bmps disabled enable it
10074 if(VOS_STATUS_SUCCESS == exitbmpsStatus)
10075 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010076 if (pHddCtx->hdd_wlan_suspended)
10077 {
10078 hdd_set_pwrparams(pHddCtx);
10079 }
10080 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070010081 }
10082 return NULL;
10083}
10084
10085VOS_STATUS hdd_close_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
10086 tANI_U8 rtnl_held )
10087{
10088 hdd_adapter_list_node_t *pAdapterNode, *pCurrent, *pNext;
10089 VOS_STATUS status;
10090
10091 status = hdd_get_front_adapter ( pHddCtx, &pCurrent );
10092 if( VOS_STATUS_SUCCESS != status )
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010093 {
10094 hddLog(VOS_TRACE_LEVEL_WARN,"%s: adapter list empty %d",
10095 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070010096 return status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010097 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010098
10099 while ( pCurrent->pAdapter != pAdapter )
10100 {
10101 status = hdd_get_next_adapter ( pHddCtx, pCurrent, &pNext );
10102 if( VOS_STATUS_SUCCESS != status )
10103 break;
10104
10105 pCurrent = pNext;
10106 }
10107 pAdapterNode = pCurrent;
10108 if( VOS_STATUS_SUCCESS == status )
10109 {
10110 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
10111 hdd_cleanup_adapter( pHddCtx, pAdapterNode->pAdapter, rtnl_held );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010112
10113#ifdef FEATURE_WLAN_TDLS
10114
10115 /* A Mutex Lock is introduced while changing/initializing the mode to
10116 * protect the concurrent access for the Adapters by TDLS module.
10117 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +053010118 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010119#endif
10120
Jeff Johnson295189b2012-06-20 16:38:30 -070010121 hdd_remove_adapter( pHddCtx, pAdapterNode );
10122 vos_mem_free( pAdapterNode );
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080010123 pAdapterNode = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010124
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053010125#ifdef FEATURE_WLAN_TDLS
10126 mutex_unlock(&pHddCtx->tdls_lock);
10127#endif
10128
Jeff Johnson295189b2012-06-20 16:38:30 -070010129
10130 /* If there is a single session of STA/P2P client, re-enable BMPS */
Agarwal Ashish51325b52014-06-16 16:50:49 +053010131 if ((!vos_concurrent_open_sessions_running()) &&
10132 ((pHddCtx->no_of_open_sessions[VOS_STA_MODE] >= 1) ||
10133 (pHddCtx->no_of_open_sessions[VOS_P2P_CLIENT_MODE] >= 1)))
Jeff Johnson295189b2012-06-20 16:38:30 -070010134 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010135 if (pHddCtx->hdd_wlan_suspended)
10136 {
10137 hdd_set_pwrparams(pHddCtx);
10138 }
10139 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070010140 }
10141
10142 return VOS_STATUS_SUCCESS;
10143 }
10144
10145 return VOS_STATUS_E_FAILURE;
10146}
10147
10148VOS_STATUS hdd_close_all_adapters( hdd_context_t *pHddCtx )
10149{
10150 hdd_adapter_list_node_t *pHddAdapterNode;
10151 VOS_STATUS status;
10152
10153 ENTER();
10154
10155 do
10156 {
10157 status = hdd_remove_front_adapter( pHddCtx, &pHddAdapterNode );
10158 if( pHddAdapterNode && VOS_STATUS_SUCCESS == status )
10159 {
10160 hdd_cleanup_adapter( pHddCtx, pHddAdapterNode->pAdapter, FALSE );
10161 vos_mem_free( pHddAdapterNode );
10162 }
10163 }while( NULL != pHddAdapterNode && VOS_STATUS_E_EMPTY != status );
10164
10165 EXIT();
10166
10167 return VOS_STATUS_SUCCESS;
10168}
10169
10170void wlan_hdd_reset_prob_rspies(hdd_adapter_t* pHostapdAdapter)
10171{
10172 v_U8_t addIE[1] = {0};
10173
10174 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10175 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,(tANI_U8*)addIE, 0, NULL,
10176 eANI_BOOLEAN_FALSE) )
10177 {
10178 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010179 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010180 }
10181
10182 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10183 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
10184 eANI_BOOLEAN_FALSE) )
10185 {
10186 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010187 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010188 }
10189
10190 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
10191 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
10192 eANI_BOOLEAN_FALSE) )
10193 {
10194 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -080010195 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -070010196 }
10197}
10198
Anurag Chouhan83026002016-12-13 22:46:21 +053010199VOS_STATUS hdd_cleanup_ap_events(hdd_adapter_t *adapter)
10200{
10201#ifdef DHCP_SERVER_OFFLOAD
10202 vos_event_destroy(&adapter->dhcp_status.vos_event);
10203#endif
Anurag Chouhan0b29de02016-12-16 13:18:40 +053010204#ifdef MDNS_OFFLOAD
10205 vos_event_destroy(&adapter->mdns_status.vos_event);
10206#endif
Anurag Chouhan83026002016-12-13 22:46:21 +053010207 return VOS_STATUS_SUCCESS;
10208}
10209
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010210int wlan_hdd_stop_mon(hdd_context_t *hdd_ctx, bool wait)
10211{
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010212 hdd_adapter_t *adapter;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010213 hdd_mon_ctx_t *mon_ctx;
10214 void (*func_ptr)(void *context) = NULL;
10215 int ret = 0;
10216 void *cookie = NULL;
10217 struct hdd_request *request;
10218 static const struct hdd_request_params params = {
10219 .priv_size = 0,
10220 .timeout_ms = MON_MODE_MSG_TIMEOUT,
10221 };
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010222
10223 adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_MONITOR);
10224 if (!adapter) {
10225 hddLog(LOGE, FL("Invalid STA + MON mode"));
10226 return -EINVAL;
10227 }
10228
10229 mon_ctx = WLAN_HDD_GET_MONITOR_CTX_PTR(adapter);
10230 if (!mon_ctx)
10231 return 0;
10232
10233 if (mon_ctx->state != MON_MODE_START)
10234 return 0;
10235
10236 mon_ctx->state = MON_MODE_STOP;
10237 if (wait) {
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010238 func_ptr = hdd_mon_post_msg_cb;
10239 request = hdd_request_alloc(&params);
10240 if (!request) {
10241 hddLog(VOS_TRACE_LEVEL_ERROR,
10242 FL("Request allocation failure"));
10243 return -ENOMEM;
10244 }
10245 cookie = hdd_request_cookie(request);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010246 }
10247
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010248 /*
10249 * If func_ptr is NULL, on receiving WDI_MON_START_RSP or
10250 * WDI_MON_STOP_RSP hdd_mon_post_msg_cb() won't be invoked
10251 * and so uninitialized cookie won't be accessed.
10252 */
10253 if (VOS_STATUS_SUCCESS != wlan_hdd_mon_postMsg(cookie,
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010254 mon_ctx,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010255 func_ptr)) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010256 hddLog(LOGE, FL("failed to stop MON MODE"));
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010257 ret = -EINVAL;
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010258 }
10259
10260 if (!wait)
10261 goto bmps_roaming;
10262
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010263 if (!ret)
10264 ret = hdd_request_wait_for_response(request);
10265 hdd_request_put(request);
10266 if (ret) {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010267 hddLog(LOGE,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053010268 FL("timeout on stop monitor mode completion %d"), ret);
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010269 return -EINVAL;
10270 }
10271
10272bmps_roaming:
10273 hddLog(LOG1, FL("Enable BMPS"));
10274 hdd_enable_bmps_imps(hdd_ctx);
10275 hdd_restore_roaming(hdd_ctx);
10276
10277 return 0;
10278}
10279
10280bool wlan_hdd_check_monitor_state(hdd_context_t *hdd_ctx)
10281{
10282 hdd_adapter_t *mon_adapter;
10283 hdd_mon_ctx_t *mon_ctx;
10284
10285 if (hdd_ctx->concurrency_mode != VOS_STA_MON)
10286 return false;
10287
10288 mon_adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_MONITOR);
10289 if (!mon_adapter) {
10290 hddLog(LOGE, FL("Invalid concurrency mode"));
10291 return false;
10292 }
10293
10294 mon_ctx = WLAN_HDD_GET_MONITOR_CTX_PTR(mon_adapter);
10295 if (mon_ctx->state == MON_MODE_START)
10296 return true;
10297
10298 return false;
10299}
10300
10301int wlan_hdd_check_and_stop_mon(hdd_adapter_t *sta_adapter, bool wait)
10302{
10303 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(sta_adapter);
10304
10305 if ((sta_adapter->device_mode != WLAN_HDD_INFRA_STATION) ||
10306 !wlan_hdd_check_monitor_state(hdd_ctx))
10307 return 0;
10308
10309 if (wlan_hdd_stop_mon(hdd_ctx, wait))
10310 return -EINVAL;
10311
10312 return 0;
10313}
10314
10315void hdd_disable_roaming(hdd_context_t *hdd_ctx)
10316{
10317 if (!hdd_ctx)
10318 return;
10319
10320 if (!hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled) {
10321 hdd_ctx->roaming_ini_original = CFG_LFR_FEATURE_ENABLED_MIN;
10322 return;
10323 }
10324
10325 hddLog(LOG1, FL("Disable driver and firmware roaming"));
10326
10327 hdd_ctx->roaming_ini_original =
10328 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled;
10329
10330 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled =
10331 CFG_LFR_FEATURE_ENABLED_MIN;
10332
10333 sme_UpdateIsFastRoamIniFeatureEnabled(hdd_ctx->hHal,
10334 CFG_LFR_FEATURE_ENABLED_MIN);
10335}
10336
10337void hdd_restore_roaming(hdd_context_t *hdd_ctx)
10338{
10339 if (!hdd_ctx->roaming_ini_original)
10340 return;
10341
10342 hddLog(LOG1, FL("Enable driver and firmware roaming"));
10343
10344 hdd_ctx->cfg_ini->isFastRoamIniFeatureEnabled =
10345 CFG_LFR_FEATURE_ENABLED_MAX;
10346
10347 hdd_ctx->roaming_ini_original = CFG_LFR_FEATURE_ENABLED_MIN;
10348
10349 sme_UpdateIsFastRoamIniFeatureEnabled(hdd_ctx->hHal,
10350 CFG_LFR_FEATURE_ENABLED_MAX);
10351}
Anurag Chouhan83026002016-12-13 22:46:21 +053010352
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010353VOS_STATUS hdd_stop_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
10354 const v_BOOL_t bCloseSession )
Jeff Johnson295189b2012-06-20 16:38:30 -070010355{
10356 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
10357 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010358 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010359 union iwreq_data wrqu;
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010360 v_U8_t retry = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010361 long ret;
Nirav Shah7e3c8132015-06-22 23:51:42 +053010362 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -070010363
Anand N Sunkad26d71b92014-12-24 18:08:22 +053010364 if (pHddCtx->isLogpInProgress) {
10365 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
10366 "%s:LOGP in Progress. Ignore!!!",__func__);
10367 return VOS_STATUS_E_FAILURE;
10368 }
10369
Jeff Johnson295189b2012-06-20 16:38:30 -070010370 ENTER();
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010371
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010372 pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -070010373 switch(pAdapter->device_mode)
10374 {
Nirav Shah0cf4d892015-11-05 16:27:27 +053010375 case WLAN_HDD_IBSS:
10376 if ( VOS_TRUE == bCloseSession )
10377 {
10378 status = hdd_sta_id_hash_detach(pAdapter);
10379 if (status != VOS_STATUS_SUCCESS)
10380 hddLog(VOS_TRACE_LEVEL_ERROR,
10381 FL("sta id hash detach failed"));
10382 }
10383
Jeff Johnson295189b2012-06-20 16:38:30 -070010384 case WLAN_HDD_INFRA_STATION:
10385 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -070010386 case WLAN_HDD_P2P_DEVICE:
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010387 {
10388 hdd_station_ctx_t *pstation = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Mahesh A Saptasagare4d05d42015-07-02 16:17:20 +053010389#ifdef FEATURE_WLAN_TDLS
10390 mutex_lock(&pHddCtx->tdls_lock);
10391 wlan_hdd_tdls_exit(pAdapter, TRUE);
10392 mutex_unlock(&pHddCtx->tdls_lock);
10393#endif
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010394 if(hdd_connIsConnected(pstation) ||
10395 (pstation->conn_info.connState == eConnectionState_Connecting))
Jeff Johnson295189b2012-06-20 16:38:30 -070010396 {
10397 if (pWextState->roamProfile.BSSType == eCSR_BSS_TYPE_START_IBSS)
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010398 {
10399 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Jeff Johnson295189b2012-06-20 16:38:30 -070010400 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
10401 pAdapter->sessionId,
10402 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010403 /* Success implies disconnect command got queued up successfully
10404 * Or cmd not queued as scan for SSID is in progress
10405 */
10406 if((eHAL_STATUS_SUCCESS == halStatus) ||
10407 (eHAL_STATUS_CMD_NOT_QUEUED == halStatus))
10408 {
10409 ret = wait_for_completion_timeout(
10410 &pAdapter->disconnect_comp_var,
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010411 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010412 if (ret <= 0 &&
10413 (eHAL_STATUS_CMD_NOT_QUEUED != halStatus))
10414 {
10415 hddLog(VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010416 "%s: wait on disconnect_comp_var failed %ld",
10417 __func__, ret);
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010418 }
10419 }
10420 else
10421 {
10422 hddLog(LOGE, "%s: failed to post disconnect event to SME",
10423 __func__);
10424 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010425 }
10426 else
10427 {
Abhinav Kumare548f1e2018-07-12 16:40:43 +053010428 wlan_hdd_disconnect(pAdapter, eCSR_DISCONNECT_REASON_DEAUTH);
Jeff Johnson295189b2012-06-20 16:38:30 -070010429 }
10430 memset(&wrqu, '\0', sizeof(wrqu));
10431 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
10432 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
10433 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
10434 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010435 else if(pstation->conn_info.connState ==
10436 eConnectionState_Disconnecting)
10437 {
10438 ret = wait_for_completion_interruptible_timeout(
10439 &pAdapter->disconnect_comp_var,
10440 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
10441 if (ret <= 0)
10442 {
10443 hddLog(VOS_TRACE_LEVEL_ERROR,
10444 FL("wait on disconnect_comp_var failed %ld"), ret);
10445 }
10446 }
Sachin Ahuja27dd2402016-08-01 20:30:31 +053010447 if(pScanInfo != NULL && pHddCtx->scan_info.mScanPending)
Jeff Johnson295189b2012-06-20 16:38:30 -070010448 {
Mahesh A Saptasagar0b61dcc2016-02-15 14:23:38 +053010449 wlan_hdd_scan_abort(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010450 }
Abhishek Singh3ac179b2015-09-21 10:01:34 +053010451 if ((pAdapter->device_mode != WLAN_HDD_INFRA_STATION) &&
10452 (pAdapter->device_mode != WLAN_HDD_IBSS))
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010453 {
10454 while (pAdapter->is_roc_inprogress)
10455 {
10456 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10457 "%s: ROC in progress for session %d!!!",
10458 __func__, pAdapter->sessionId);
10459 // waiting for ROC to expire
10460 msleep(500);
10461 /* In GO present case , if retry exceeds 3,
10462 it means something went wrong. */
10463 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION )
10464 {
10465 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10466 "%s: ROC completion is not received.!!!", __func__);
Deepthi Gowri70498252015-01-20 15:56:45 +053010467 if (eHAL_STATUS_SUCCESS !=
10468 sme_CancelRemainOnChannel( WLAN_HDD_GET_HAL_CTX( pAdapter),
10469 pAdapter->sessionId ))
10470 {
10471 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10472 FL("Failed to Cancel Remain on Channel"));
10473 }
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010474 wait_for_completion_interruptible_timeout(
10475 &pAdapter->cancel_rem_on_chan_var,
10476 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
10477 break;
10478 }
10479 }
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010480 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010481 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +053010482#ifdef WLAN_NS_OFFLOAD
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010483 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +053010484#endif
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010485
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010486 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010487
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010488 /* It is possible that the caller of this function does not
10489 * wish to close the session
10490 */
10491 if (VOS_TRUE == bCloseSession &&
10492 test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -070010493 {
10494 INIT_COMPLETION(pAdapter->session_close_comp_var);
10495 if (eHAL_STATUS_SUCCESS ==
Agrawal Ashish5a3522c2016-03-02 15:08:28 +053010496 sme_CloseSession(pHddCtx->hHal, pAdapter->sessionId, FALSE,
10497 VOS_FALSE, hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -070010498 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010499 unsigned long ret;
10500
Jeff Johnson295189b2012-06-20 16:38:30 -070010501 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010502 ret = wait_for_completion_timeout(
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010503 &pAdapter->session_close_comp_var,
10504 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010505 if ( 0 >= ret)
10506 {
10507 hddLog(LOGE, "%s: failure waiting for session_close_comp_var %ld",
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010508 __func__, ret);
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010509 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010510 }
10511 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +053010512 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010513 break;
10514
10515 case WLAN_HDD_SOFTAP:
Abhishek Singh3dc4c972019-05-09 11:04:24 +053010516 /* Delete all associated STAs before stopping AP */
10517 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10518 hdd_del_all_sta(pAdapter);
10519 /* Fall through */
Jeff Johnson295189b2012-06-20 16:38:30 -070010520 case WLAN_HDD_P2P_GO:
Abhishek Singh3dc4c972019-05-09 11:04:24 +053010521
Nirav Shah0cf4d892015-11-05 16:27:27 +053010522 if ( VOS_TRUE == bCloseSession )
10523 {
10524 status = hdd_sta_id_hash_detach(pAdapter);
10525 if (status != VOS_STATUS_SUCCESS)
10526 hddLog(VOS_TRACE_LEVEL_ERROR,
10527 FL("sta id hash detach failed"));
10528 }
10529
Jeff Johnson295189b2012-06-20 16:38:30 -070010530 //Any softap specific cleanup here...
Anurag Chouhan83026002016-12-13 22:46:21 +053010531 hdd_cleanup_ap_events(pAdapter);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010532 if (pAdapter->device_mode == WLAN_HDD_P2P_GO) {
10533 while (pAdapter->is_roc_inprogress) {
10534 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10535 "%s: ROC in progress for session %d!!!",
10536 __func__, pAdapter->sessionId);
10537 msleep(500);
10538 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION ) {
10539 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10540 "%s: ROC completion is not received.!!!", __func__);
10541 WLANSAP_CancelRemainOnChannel(
10542 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
10543 wait_for_completion_interruptible_timeout(
10544 &pAdapter->cancel_rem_on_chan_var,
10545 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
10546 break;
10547 }
10548 }
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +053010549
Anand N Sunkaddc63c792015-06-03 14:33:24 +053010550 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +053010551 }
Agrawal Ashish17ef5082016-10-17 18:33:21 +053010552#ifdef SAP_AUTH_OFFLOAD
10553 if (pHddCtx->cfg_ini->enable_sap_auth_offload)
10554 hdd_set_sap_auth_offload(pAdapter, FALSE);
10555#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070010556 mutex_lock(&pHddCtx->sap_lock);
10557 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10558 {
10559 VOS_STATUS status;
10560 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hanumanth Reddy Pothula74ba68c2018-06-22 17:52:09 +053010561 hdd_hostapd_state_t *pHostapdState =
10562 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070010563
Hanumanth Reddy Pothula74ba68c2018-06-22 17:52:09 +053010564 vos_event_reset(&pHostapdState->vosEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -070010565 //Stop Bss.
10566 status = WLANSAP_StopBss(pHddCtx->pvosContext);
10567 if (VOS_IS_STATUS_SUCCESS(status))
10568 {
Jeff Johnson295189b2012-06-20 16:38:30 -070010569 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
10570
10571 if (!VOS_IS_STATUS_SUCCESS(status))
10572 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010573 hddLog(LOGE, "%s: failure waiting for WLANSAP_StopBss %d",
10574 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070010575 }
10576 }
10577 else
10578 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010579 hddLog(LOGE, "%s: failure in WLANSAP_StopBss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010580 }
10581 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
Agarwal Ashish51325b52014-06-16 16:50:49 +053010582 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -070010583
10584 if (eHAL_STATUS_FAILURE ==
10585 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
10586 0, NULL, eANI_BOOLEAN_FALSE))
10587 {
10588 hddLog(LOGE,
10589 "%s: Failed to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010590 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010591 }
10592
10593 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pAdapter))->hHal,
10594 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
10595 eANI_BOOLEAN_FALSE) )
10596 {
10597 hddLog(LOGE,
10598 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
10599 }
10600
10601 // Reset WNI_CFG_PROBE_RSP Flags
10602 wlan_hdd_reset_prob_rspies(pAdapter);
10603 kfree(pAdapter->sessionCtx.ap.beacon);
10604 pAdapter->sessionCtx.ap.beacon = NULL;
10605 }
10606 mutex_unlock(&pHddCtx->sap_lock);
Hanumanth Reddy Pothulab4537b82018-03-02 12:20:38 +053010607
10608#ifdef WLAN_NS_OFFLOAD
10609 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
10610#endif
10611 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
10612
Jeff Johnson295189b2012-06-20 16:38:30 -070010613 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -070010614
Jeff Johnson295189b2012-06-20 16:38:30 -070010615 case WLAN_HDD_MONITOR:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053010616 if (VOS_MONITOR_MODE != hdd_get_conparam())
10617 wlan_hdd_stop_mon(pHddCtx, true);
10618 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -070010619
Jeff Johnson295189b2012-06-20 16:38:30 -070010620 default:
10621 break;
10622 }
10623
10624 EXIT();
10625 return VOS_STATUS_SUCCESS;
10626}
10627
Kapil Gupta137ef892016-12-13 19:38:00 +053010628/**
10629 * wlan_hdd_restart_sap() - to restart SAP in driver internally
10630 * @ap_adapter: - Pointer to SAP hdd_adapter_t structure
10631 *
10632 * wlan_hdd_restart_sap first delete SAP and do cleanup.
10633 * After that WLANSAP_StartBss start re-start process of SAP.
10634 *
10635 * Return: None
10636 */
10637static void wlan_hdd_restart_sap(hdd_adapter_t *ap_adapter)
10638{
10639 hdd_ap_ctx_t *pHddApCtx;
10640 hdd_hostapd_state_t *pHostapdState;
10641 VOS_STATUS vos_status;
10642 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(ap_adapter);
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010643#ifdef USE_CFG80211_DEL_STA_V2
Kapil Gupta137ef892016-12-13 19:38:00 +053010644 struct station_del_parameters delStaParams;
10645#endif
10646 tsap_Config_t *pConfig;
10647
10648 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10649 pConfig = &pHddApCtx->sapConfig;
10650
10651 mutex_lock(&pHddCtx->sap_lock);
10652 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053010653#ifdef USE_CFG80211_DEL_STA_V2
Kapil Gupta137ef892016-12-13 19:38:00 +053010654 delStaParams.mac = NULL;
10655 delStaParams.subtype = SIR_MAC_MGMT_DEAUTH >> 4;
10656 delStaParams.reason_code = eCsrForcedDeauthSta;
10657 wlan_hdd_cfg80211_del_station(ap_adapter->wdev.wiphy, ap_adapter->dev,
10658 &delStaParams);
10659#else
10660 wlan_hdd_cfg80211_del_station(ap_adapter->wdev.wiphy, ap_adapter->dev,
10661 NULL);
10662#endif
10663 hdd_cleanup_actionframe(pHddCtx, ap_adapter);
10664
10665 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10666 vos_event_reset(&pHostapdState->vosEvent);
10667
10668 if (VOS_STATUS_SUCCESS == WLANSAP_StopBss(pHddCtx->pvosContext)) {
10669 vos_status = vos_wait_single_event(&pHostapdState->vosEvent,
10670 10000);
10671 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10672 hddLog(LOGE, FL("SAP Stop Failed"));
10673 goto end;
10674 }
10675 }
10676 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
10677 wlan_hdd_decr_active_session(pHddCtx, ap_adapter->device_mode);
10678 hddLog(LOG1, FL("SAP Stop Success"));
10679
10680 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
10681 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
10682 goto end;
10683 }
10684
Hanumanth Reddy Pothula74ba68c2018-06-22 17:52:09 +053010685 vos_event_reset(&pHostapdState->vosEvent);
Kapil Gupta137ef892016-12-13 19:38:00 +053010686 if (WLANSAP_StartBss(pHddCtx->pvosContext, hdd_hostapd_SAPEventCB,
10687 pConfig, (v_PVOID_t)ap_adapter->dev) != VOS_STATUS_SUCCESS) {
10688 hddLog(LOGE, FL("SAP Start Bss fail"));
10689 goto end;
10690 }
10691
10692 hddLog(LOG1, FL("Waiting for SAP to start"));
10693 vos_status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
10694 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10695 hddLog(LOGE, FL("SAP Start failed"));
10696 goto end;
10697 }
10698 hddLog(LOG1, FL("SAP Start Success"));
10699 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
10700 wlan_hdd_incr_active_session(pHddCtx, ap_adapter->device_mode);
10701 pHostapdState->bCommit = TRUE;
Anurag Chouhanb2951ae2017-03-12 13:41:35 +053010702 if (!VOS_IS_STATUS_SUCCESS(hdd_dhcp_mdns_offload(ap_adapter))) {
10703 hddLog(VOS_TRACE_LEVEL_ERROR, FL("DHCP/MDNS offload Failed!!"));
10704 vos_event_reset(&pHostapdState->vosEvent);
10705 if (VOS_STATUS_SUCCESS == WLANSAP_StopBss(pHddCtx->pvosContext)) {
10706 vos_status = vos_wait_single_event(&pHostapdState->vosEvent,
10707 10000);
10708 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
10709 hddLog(LOGE, FL("SAP Stop Failed"));
10710 goto end;
10711 }
10712 }
10713 }
Kapil Gupta137ef892016-12-13 19:38:00 +053010714 }
10715end:
10716 mutex_unlock(&pHddCtx->sap_lock);
10717 return;
10718}
10719
10720/**
10721 * __hdd_sap_restart_handle() - to handle restarting of SAP
10722 * @work: name of the work
10723 *
10724 * Purpose of this function is to trigger sap start. this function
10725 * will be called from workqueue.
10726 *
10727 * Return: void.
10728 */
10729static void __hdd_sap_restart_handle(struct work_struct *work)
10730{
10731 hdd_adapter_t *sap_adapter;
10732 hdd_context_t *hdd_ctx = container_of(work,
10733 hdd_context_t,
10734 sap_start_work);
10735 if (0 != wlan_hdd_validate_context(hdd_ctx)) {
10736 vos_ssr_unprotect(__func__);
10737 return;
10738 }
10739 sap_adapter = hdd_get_adapter(hdd_ctx,
10740 WLAN_HDD_SOFTAP);
10741 if (sap_adapter == NULL) {
10742 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10743 FL("sap_adapter is NULL"));
10744 vos_ssr_unprotect(__func__);
10745 return;
10746 }
10747
10748 if (hdd_ctx->is_ch_avoid_in_progress) {
10749 sap_adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
10750 wlan_hdd_restart_sap(sap_adapter);
10751 hdd_change_ch_avoidance_status(hdd_ctx, false);
10752 }
Agrawal Ashish574b3e62017-02-09 18:58:34 +053010753 if (hdd_ctx->cfg_ini->enable_sap_auth_offload)
10754 wlan_hdd_restart_sap(sap_adapter);
Kapil Gupta137ef892016-12-13 19:38:00 +053010755}
10756
10757/**
10758 * hdd_sap_restart_handle() - to handle restarting of SAP
10759 * @work: name of the work
10760 *
10761 * Purpose of this function is to trigger sap start. this function
10762 * will be called from workqueue.
10763 *
10764 * Return: void.
10765 */
10766static void hdd_sap_restart_handle(struct work_struct *work)
10767{
10768 vos_ssr_protect(__func__);
10769 __hdd_sap_restart_handle(work);
10770 vos_ssr_unprotect(__func__);
10771}
10772
10773
Abhishek Singh78c691f2017-11-30 13:48:44 +053010774/**
10775 * __hdd_force_scc_with_ecsa_handle() - to handle force scc using ecsa
10776 * @work: name of the work
10777 *
10778 * Purpose of this function is to force SCC using ECSA. This function
10779 * will be called from workqueue.
10780 *
10781 * Return: void.
10782 */
10783static void
10784__hdd_force_scc_with_ecsa_handle(struct work_struct *work)
10785{
10786 hdd_adapter_t *sap_adapter;
10787 hdd_station_ctx_t *sta_ctx;
10788 hdd_adapter_t *sta_adapter;
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010789 ptSapContext sap_ctx = NULL;
10790 v_CONTEXT_t vos_ctx;
10791 tANI_U8 target_channel;
10792 tsap_Config_t *sap_config;
10793 bool sta_sap_scc_on_dfs_chan;
10794 eNVChannelEnabledType chan_state;
Abhishek Singh78c691f2017-11-30 13:48:44 +053010795 hdd_context_t *hdd_ctx = container_of(to_delayed_work(work),
10796 hdd_context_t,
10797 ecsa_chan_change_work);
10798
10799 if (wlan_hdd_validate_context(hdd_ctx))
10800 return;
10801
10802 sap_adapter = hdd_get_adapter(hdd_ctx,
10803 WLAN_HDD_SOFTAP);
10804 if (!sap_adapter) {
10805 hddLog(LOGE, FL("sap_adapter is NULL"));
10806 return;
10807 }
10808
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010809 vos_ctx = hdd_ctx->pvosContext;
10810 if (!vos_ctx) {
10811 hddLog(LOGE, FL("vos_ctx is NULL"));
10812 return;
10813 }
10814
10815 sap_ctx = VOS_GET_SAP_CB(vos_ctx);
10816 if (!sap_ctx) {
10817 hddLog(LOGE, FL("sap_ctx is NULL"));
10818 return;
10819 }
10820
10821 sap_config = &sap_adapter->sessionCtx.ap.sapConfig;
10822
10823 sta_sap_scc_on_dfs_chan = hdd_is_sta_sap_scc_allowed_on_dfs_chan(hdd_ctx);
10824
Abhishek Singh78c691f2017-11-30 13:48:44 +053010825 sta_adapter = hdd_get_adapter(hdd_ctx,
10826 WLAN_HDD_INFRA_STATION);
10827 if (!sta_adapter) {
10828 hddLog(LOGE, FL("sta_adapter is NULL"));
10829 return;
10830 }
Abhishek Singh78c691f2017-11-30 13:48:44 +053010831
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010832 if (wlansap_chk_n_set_chan_change_in_progress(sap_ctx))
Abhishek Singh78c691f2017-11-30 13:48:44 +053010833 return;
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010834 INIT_COMPLETION(sap_ctx->ecsa_info.chan_switch_comp);
10835
10836 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(sta_adapter);
10837 if (sta_ctx->conn_info.connState != eConnectionState_Associated) {
10838 if (sta_ctx->conn_info.connState == eConnectionState_NotConnected) {
10839 chan_state = vos_nv_getChannelEnabledState(sap_ctx->channel);
10840 hddLog(LOG1, FL("sta not in connected state %d, sta_sap_scc_on_dfs_chan %d, chan_state %d"),
10841 sta_ctx->conn_info.connState, sta_sap_scc_on_dfs_chan,
10842 chan_state);
10843 if (sta_sap_scc_on_dfs_chan &&
10844 (chan_state == NV_CHANNEL_DFS)) {
10845 hddLog(LOGE, FL("Switch SAP to user configured channel"));
10846 target_channel = sap_config->user_config_channel;
10847 goto switch_channel;
10848 }
10849 }
10850 goto abort;
Abhishek Singh78c691f2017-11-30 13:48:44 +053010851 }
10852
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010853 target_channel = sta_ctx->conn_info.operationChannel;
10854switch_channel:
10855 hddLog(LOGE, FL("Switch SAP to %d channel"),
10856 target_channel);
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010857 if (!wlansap_set_channel_change(vos_ctx, target_channel, true))
10858 return;
10859
10860abort:
10861 wlansap_reset_chan_change_in_progress(sap_ctx);
10862 complete(&sap_ctx->ecsa_info.chan_switch_comp);
Abhishek Singh78c691f2017-11-30 13:48:44 +053010863}
10864
10865/**
10866 * hdd_force_scc_with_ecsa_handle() - to handle force scc using ecsa
10867 * @work: name of the work
10868 *
10869 * Purpose of this function is to force SCC using ECSA. This function
10870 * will be called from workqueue.
10871 *
10872 * Return: void.
10873 */
10874static void
10875hdd_force_scc_with_ecsa_handle(struct work_struct *work)
10876{
10877 vos_ssr_protect(__func__);
10878 __hdd_force_scc_with_ecsa_handle(work);
10879 vos_ssr_unprotect(__func__);
10880}
10881
Abhishek Singh10e17cf2018-03-12 14:34:22 +053010882int hdd_wait_for_ecsa_complete(hdd_context_t *hdd_ctx)
10883{
10884 int ret;
10885 ptSapContext sap_ctx = NULL;
10886 v_CONTEXT_t vos_ctx;
10887
10888 vos_ctx = hdd_ctx->pvosContext;
10889 if (!vos_ctx) {
10890 hddLog(LOGE, FL("vos_ctx is NULL"));
10891 return 0;
10892 }
10893
10894 sap_ctx = VOS_GET_SAP_CB(vos_ctx);
10895 if (!sap_ctx) {
10896 hddLog(LOG1, FL("sap_ctx is NULL"));
10897 return 0;
10898 }
10899 if(!sap_ctx->isSapSessionOpen) {
10900 hddLog(LOG1, FL("sap session not opened, SAP in state %d"),
10901 sap_ctx->sapsMachine);
10902 return 0;
10903 }
10904
10905 if (!wlansap_get_change_in_progress(sap_ctx)) {
10906 hddLog(LOG1, FL("channel switch not in progress"));
10907 return 0;
10908 }
10909 ret = wait_for_completion_timeout(&sap_ctx->ecsa_info.chan_switch_comp,
10910 msecs_to_jiffies(HDD_SAP_CHAN_CNG_WAIT_TIME));
10911 if (!ret)
10912 {
10913 hddLog(LOGE, FL("Timeout waiting for SAP channel switch"));
10914 return ret;
10915 }
10916
10917 return 0;
10918}
10919
10920
Ganesh Kondabattini3655a6d2018-01-08 20:25:39 +053010921/**
10922 * hdd_is_sta_sap_scc_allowed_on_dfs_chan() - check if sta+sap scc allowed on
10923 * dfs chan
10924 * @hdd_ctx: pointer to hdd context
10925 *
10926 * This function used to check if sta+sap scc allowed on DFS channel.
10927 *
10928 * Return: None
10929 */
10930bool hdd_is_sta_sap_scc_allowed_on_dfs_chan(hdd_context_t *hdd_ctx)
10931{
10932 if (hdd_ctx->cfg_ini->force_scc_with_ecsa &&
10933 hdd_ctx->cfg_ini->sta_sap_scc_on_dfs_chan)
10934 return true;
10935 else
10936 return false;
10937}
10938
Jeff Johnson295189b2012-06-20 16:38:30 -070010939VOS_STATUS hdd_stop_all_adapters( hdd_context_t *pHddCtx )
10940{
10941 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10942 VOS_STATUS status;
10943 hdd_adapter_t *pAdapter;
10944
10945 ENTER();
10946
10947 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10948
10949 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10950 {
10951 pAdapter = pAdapterNode->pAdapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070010952
Agarwal Ashish3a38bd12014-06-12 15:16:52 +053010953 hdd_stop_adapter( pHddCtx, pAdapter, VOS_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -070010954
10955 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10956 pAdapterNode = pNext;
10957 }
10958
10959 EXIT();
10960
10961 return VOS_STATUS_SUCCESS;
10962}
10963
Rajeev Kumarf999e582014-01-09 17:33:29 -080010964
10965#ifdef FEATURE_WLAN_BATCH_SCAN
10966/**---------------------------------------------------------------------------
10967
10968 \brief hdd_deinit_batch_scan () - This function cleans up batch scan data
10969 structures
10970
10971 \param - pAdapter Pointer to HDD adapter
10972
10973 \return - None
10974
10975 --------------------------------------------------------------------------*/
10976void hdd_deinit_batch_scan(hdd_adapter_t *pAdapter)
10977{
10978 tHddBatchScanRsp *pNode;
10979 tHddBatchScanRsp *pPrev;
10980
Siddharth Bhalb3e9b792014-02-24 15:14:16 +053010981 if (NULL == pAdapter)
Rajeev Kumarf999e582014-01-09 17:33:29 -080010982 {
Siddharth Bhalb3e9b792014-02-24 15:14:16 +053010983 hddLog(VOS_TRACE_LEVEL_ERROR,
10984 "%s: Adapter context is Null", __func__);
10985 return;
10986 }
10987
10988 pNode = pAdapter->pBatchScanRsp;
10989 while (pNode)
10990 {
10991 pPrev = pNode;
10992 pNode = pNode->pNext;
10993 vos_mem_free((v_VOID_t * )pPrev);
Rajeev Kumarf999e582014-01-09 17:33:29 -080010994 }
10995
10996 pAdapter->pBatchScanRsp = NULL;
10997 pAdapter->numScanList = 0;
10998 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
10999 pAdapter->prev_batch_id = 0;
11000
11001 return;
11002}
11003#endif
11004
11005
Jeff Johnson295189b2012-06-20 16:38:30 -070011006VOS_STATUS hdd_reset_all_adapters( hdd_context_t *pHddCtx )
11007{
11008 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11009 VOS_STATUS status;
11010 hdd_adapter_t *pAdapter;
11011
11012 ENTER();
11013
11014 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11015
11016 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11017 {
11018 pAdapter = pAdapterNode->pAdapter;
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +053011019 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -070011020 netif_tx_disable(pAdapter->dev);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011021
11022 if (pHddCtx->cfg_ini->sap_internal_restart &&
11023 pAdapter->device_mode == WLAN_HDD_SOFTAP) {
11024 hddLog(LOG1, FL("driver supports sap restart"));
11025 vos_flush_work(&pHddCtx->sap_start_work);
11026 hdd_sap_indicate_disconnect_for_sta(pAdapter);
11027 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +053011028 hdd_softap_deinit_tx_rx(pAdapter, true);
11029 hdd_sap_destroy_timers(pAdapter);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011030 } else {
11031 netif_carrier_off(pAdapter->dev);
11032 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011033
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070011034 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011035
11036 if (pAdapter->device_mode == WLAN_HDD_MONITOR)
11037 pAdapter->sessionCtx.monitor.state = MON_MODE_STOP;
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070011038
Jeff Johnson295189b2012-06-20 16:38:30 -070011039 hdd_deinit_tx_rx(pAdapter);
Agarwal Ashish6267caa2014-08-06 19:16:21 +053011040
Katya Nigam1fd24402015-02-16 14:52:19 +053011041 if(pAdapter->device_mode == WLAN_HDD_IBSS )
11042 hdd_ibss_deinit_tx_rx(pAdapter);
11043
Nirav Shah7e3c8132015-06-22 23:51:42 +053011044 status = hdd_sta_id_hash_detach(pAdapter);
11045 if (status != VOS_STATUS_SUCCESS)
11046 hddLog(VOS_TRACE_LEVEL_ERROR,
11047 FL("sta id hash detach failed for session id %d"),
11048 pAdapter->sessionId);
11049
Agarwal Ashish6267caa2014-08-06 19:16:21 +053011050 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
11051
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +053011052 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
11053 {
11054 hdd_wmm_adapter_close( pAdapter );
11055 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
11056 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011057
Siddharth Bhal2db319d2014-12-03 12:37:18 +053011058 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
11059 {
11060 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
11061 }
11062
Rajeev Kumarf999e582014-01-09 17:33:29 -080011063#ifdef FEATURE_WLAN_BATCH_SCAN
11064 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
11065 {
11066 hdd_deinit_batch_scan(pAdapter);
11067 }
11068#endif
11069
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +053011070#ifdef FEATURE_WLAN_TDLS
11071 mutex_lock(&pHddCtx->tdls_lock);
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +053011072 wlan_hdd_tdls_exit(pAdapter, TRUE);
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +053011073 mutex_unlock(&pHddCtx->tdls_lock);
11074#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070011075 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11076 pAdapterNode = pNext;
11077 }
11078
11079 EXIT();
11080
11081 return VOS_STATUS_SUCCESS;
11082}
11083
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011084/**
Abhishek Singh5a597e62016-12-05 15:16:30 +053011085 * hdd_get_bss_entry() - Get the bss entry matching the chan, bssid and ssid
11086 * @wiphy: wiphy
11087 * @channel: channel of the BSS to find
11088 * @bssid: bssid of the BSS to find
11089 * @ssid: ssid of the BSS to find
11090 * @ssid_len: ssid len of of the BSS to find
11091 *
11092 * The API is a wrapper to get bss from kernel matching the chan,
11093 * bssid and ssid
11094 *
11095 * Return: Void
11096 */
11097#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
11098 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
11099
11100struct cfg80211_bss* hdd_get_bss_entry(struct wiphy *wiphy,
11101 struct ieee80211_channel *channel,
11102 const u8 *bssid,
11103 const u8 *ssid, size_t ssid_len)
11104{
11105 return cfg80211_get_bss(wiphy, channel, bssid,
11106 ssid, ssid_len,
11107 WLAN_CAPABILITY_ESS,
11108 WLAN_CAPABILITY_ESS);
11109}
11110#else
11111struct cfg80211_bss* hdd_get_bss_entry(struct wiphy *wiphy,
11112 struct ieee80211_channel *channel,
11113 const u8 *bssid,
11114 const u8 *ssid, size_t ssid_len)
11115{
11116 return cfg80211_get_bss(wiphy, channel, bssid,
11117 ssid, ssid_len,
11118 IEEE80211_BSS_TYPE_ESS,
11119 IEEE80211_PRIVACY_ANY);
11120}
11121#endif
11122
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011123#if defined(CFG80211_CONNECT_BSS) || \
11124 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
11125
11126#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) || \
11127 defined (CFG80211_CONNECT_TIMEOUT_REASON_CODE)
11128/**
11129 * hdd_connect_bss() - helper function to send connection status to supplicant
11130 * @dev: network device
11131 * @bssid: bssid to which we want to associate
11132 * @bss: information about connected bss
11133 * @req_ie: Request Information Element
11134 * @req_ie_len: len of the req IE
11135 * @resp_ie: Response IE
11136 * @resp_ie_len: len of ht response IE
11137 * @status: status
11138 * @gfp: Kernel Flag
11139 *
11140 * This is a helper function to send connection status to supplicant
11141 * and gets invoked from wrapper API
11142 *
11143 * Return: Void
11144 */
11145static void hdd_connect_bss(struct net_device *dev,
11146 const u8 *bssid,
11147 struct cfg80211_bss *bss,
11148 const u8 *req_ie,
11149 size_t req_ie_len,
11150 const u8 *resp_ie,
11151 size_t resp_ie_len,
11152 u16 status,
11153 gfp_t gfp)
11154{
11155 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
11156 resp_ie, resp_ie_len, status, gfp, NL80211_TIMEOUT_UNSPECIFIED);
11157}
11158#else
11159/**
11160 * hdd_connect_bss() - helper function to send connection status to supplicant
11161 * @dev: network device
11162 * @bssid: bssid to which we want to associate
11163 * @bss: information about connected bss
11164 * @req_ie: Request Information Element
11165 * @req_ie_len: len of the req IE
11166 * @resp_ie: Response IE
11167 * @resp_ie_len: len of ht response IE
11168 * @status: status
11169 * @gfp: Kernel Flag
11170 *
11171 * This is a helper function to send connection status to supplicant
11172 * and gets invoked from wrapper API
11173 *
11174 * Return: Void
11175 */
11176static void hdd_connect_bss(struct net_device *dev,
11177 const u8 *bssid,
11178 struct cfg80211_bss *bss,
11179 const u8 *req_ie,
11180 size_t req_ie_len,
11181 const u8 *resp_ie,
11182 size_t resp_ie_len,
11183 u16 status,
11184 gfp_t gfp)
11185{
11186 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
11187 resp_ie, resp_ie_len, status, gfp);
11188}
11189#endif
11190
Abhishek Singh5a597e62016-12-05 15:16:30 +053011191/**
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011192 * hdd_connect_result() - API to send connection status to supplicant
11193 * @dev: network device
11194 * @bssid: bssid to which we want to associate
11195 * @roam_info: information about connected bss
11196 * @req_ie: Request Information Element
11197 * @req_ie_len: len of the req IE
11198 * @resp_ie: Response IE
11199 * @resp_ie_len: len of ht response IE
11200 * @status: status
11201 * @gfp: Kernel Flag
11202 *
11203 * The API is a wrapper to send connection status to supplicant
11204 *
11205 * Return: Void
11206 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011207void hdd_connect_result(struct net_device *dev,
11208 const u8 *bssid,
11209 tCsrRoamInfo *roam_info,
11210 const u8 *req_ie,
11211 size_t req_ie_len,
11212 const u8 *resp_ie,
11213 size_t resp_ie_len,
11214 u16 status,
11215 gfp_t gfp)
11216{
11217 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
11218 struct cfg80211_bss *bss = NULL;
11219
11220 if (WLAN_STATUS_SUCCESS == status) {
11221 struct ieee80211_channel *chan;
11222 int freq;
11223 int chan_no = roam_info->pBssDesc->channelId;;
11224
11225 if (chan_no <= 14)
11226 freq = ieee80211_channel_to_frequency(chan_no,
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011227 HDD_NL80211_BAND_2GHZ);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011228 else
11229 freq = ieee80211_channel_to_frequency(chan_no,
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011230 HDD_NL80211_BAND_5GHZ);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011231
11232 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
Abhishek Singh5a597e62016-12-05 15:16:30 +053011233 bss = hdd_get_bss_entry(padapter->wdev.wiphy,
11234 chan, bssid,
11235 roam_info->u.pConnectedProfile->SSID.ssId,
11236 roam_info->u.pConnectedProfile->SSID.length);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011237 }
11238
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011239 hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie, resp_ie_len,
11240 status, gfp);
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011241}
11242#else
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053011243/**
11244 * hdd_connect_result() - API to send connection status to supplicant
11245 * @dev: network device
11246 * @bssid: bssid to which we want to associate
11247 * @roam_info: information about connected bss
11248 * @req_ie: Request Information Element
11249 * @req_ie_len: len of the req IE
11250 * @resp_ie: Response IE
11251 * @resp_ie_len: len of ht response IE
11252 * @status: status
11253 * @gfp: Kernel Flag
11254 *
11255 * The API is a wrapper to send connection status to supplicant
11256 *
11257 * Return: Void
11258 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011259void hdd_connect_result(struct net_device *dev,
11260 const u8 *bssid,
11261 tCsrRoamInfo *roam_info,
11262 const u8 *req_ie,
11263 size_t req_ie_len,
11264 const u8 * resp_ie,
11265 size_t resp_ie_len,
11266 u16 status,
11267 gfp_t gfp)
11268{
11269 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
11270 resp_ie, resp_ie_len, status, gfp);
11271}
11272#endif
11273
Jeff Johnson295189b2012-06-20 16:38:30 -070011274VOS_STATUS hdd_start_all_adapters( hdd_context_t *pHddCtx )
11275{
11276 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11277 VOS_STATUS status;
11278 hdd_adapter_t *pAdapter;
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011279 eConnectionState connState;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011280 v_CONTEXT_t pVosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011281
11282 ENTER();
11283
11284 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11285
11286 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11287 {
11288 pAdapter = pAdapterNode->pAdapter;
11289
Kumar Anand82c009f2014-05-29 00:29:42 -070011290 hdd_wmm_init( pAdapter );
11291
Jeff Johnson295189b2012-06-20 16:38:30 -070011292 switch(pAdapter->device_mode)
11293 {
11294 case WLAN_HDD_INFRA_STATION:
11295 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -070011296 case WLAN_HDD_P2P_DEVICE:
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011297
11298 connState = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState;
11299
Jeff Johnson295189b2012-06-20 16:38:30 -070011300 hdd_init_station_mode(pAdapter);
11301 /* Open the gates for HDD to receive Wext commands */
11302 pAdapter->isLinkUpSvcNeeded = FALSE;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070011303 pHddCtx->scan_info.mScanPending = FALSE;
11304 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070011305
11306 //Trigger the initial scan
Mukul Sharmae74e42c2015-08-06 23:55:49 +053011307 if (!pHddCtx->isLogpInProgress)
11308 hdd_wlan_initial_scan(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070011309
11310 //Indicate disconnect event to supplicant if associated previously
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011311 if (eConnectionState_Associated == connState ||
11312 eConnectionState_IbssConnected == connState )
Jeff Johnson295189b2012-06-20 16:38:30 -070011313 {
11314 union iwreq_data wrqu;
11315 memset(&wrqu, '\0', sizeof(wrqu));
11316 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
11317 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
11318 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -070011319 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070011320
Jeff Johnson295189b2012-06-20 16:38:30 -070011321 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagar9ff4bcc2016-06-01 17:17:50 +053011322 wlan_hdd_cfg80211_indicate_disconnect(pAdapter->dev, false,
Mahesh A Saptasagarb5a15142016-05-25 11:27:43 +053011323 WLAN_REASON_UNSPECIFIED);
Jeff Johnson295189b2012-06-20 16:38:30 -070011324 }
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011325 else if (eConnectionState_Connecting == connState)
11326 {
11327 /*
11328 * Indicate connect failure to supplicant if we were in the
11329 * process of connecting
11330 */
Abhishek Singhbbe0b2a2016-12-05 11:57:36 +053011331 hdd_connect_result(pAdapter->dev, NULL, NULL,
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +053011332 NULL, 0, NULL, 0,
11333 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
11334 GFP_KERNEL);
11335 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011336 break;
11337
11338 case WLAN_HDD_SOFTAP:
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011339 if (pHddCtx->cfg_ini->sap_internal_restart) {
Hanumanth Reddy Pothula15bc0fa2017-02-03 17:24:17 +053011340 hdd_init_ap_mode(pAdapter, true);
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053011341 status = hdd_sta_id_hash_attach(pAdapter);
11342 if (VOS_STATUS_SUCCESS != status)
11343 {
11344 hddLog(VOS_TRACE_LEVEL_FATAL,
11345 FL("failed to attach hash for"));
11346 }
11347 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011348 break;
11349
11350 case WLAN_HDD_P2P_GO:
Sameer Thalappiledf0d792013-08-09 14:31:03 -070011351 hddLog(VOS_TRACE_LEVEL_ERROR, "%s [SSR] send stop ap to supplicant",
Jeff Johnson295189b2012-06-20 16:38:30 -070011352 __func__);
Sameer Thalappiledf0d792013-08-09 14:31:03 -070011353 cfg80211_ap_stopped(pAdapter->dev, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -070011354 break;
11355
11356 case WLAN_HDD_MONITOR:
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011357 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
11358
11359 hddLog(VOS_TRACE_LEVEL_INFO, FL("[SSR] monitor mode"));
11360 if (!pVosContext) {
11361 hddLog(VOS_TRACE_LEVEL_ERROR, FL("vos context is NULL"));
11362 break;
11363 }
11364
11365 hdd_init_tx_rx(pAdapter);
11366 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk);
Jeff Johnson295189b2012-06-20 16:38:30 -070011367 break;
Hanumanth Reddy Pothulada449f12018-03-13 18:19:19 +053011368
Jeff Johnson295189b2012-06-20 16:38:30 -070011369 default:
11370 break;
11371 }
11372
11373 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11374 pAdapterNode = pNext;
11375 }
11376
11377 EXIT();
11378
11379 return VOS_STATUS_SUCCESS;
11380}
11381
11382VOS_STATUS hdd_reconnect_all_adapters( hdd_context_t *pHddCtx )
11383{
11384 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11385 hdd_adapter_t *pAdapter;
11386 VOS_STATUS status;
11387 v_U32_t roamId;
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011388 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070011389
11390 ENTER();
11391
11392 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11393
11394 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11395 {
11396 pAdapter = pAdapterNode->pAdapter;
11397
11398 if( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
11399 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
11400 {
11401 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11402 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
11403
Abhishek Singhf4669da2014-05-26 15:07:49 +053011404 hddLog(VOS_TRACE_LEVEL_INFO,
11405 "%s: Set HDD connState to eConnectionState_NotConnected",
11406 __func__);
Ganesh Kondabattini04338412015-09-14 15:39:09 +053011407 spin_lock_bh(&pAdapter->lock_for_active_session);
11408 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState)
11409 {
11410 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
11411 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011412 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Ganesh Kondabattini04338412015-09-14 15:39:09 +053011413 spin_unlock_bh(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -070011414 init_completion(&pAdapter->disconnect_comp_var);
11415 sme_RoamDisconnect(pHddCtx->hHal, pAdapter->sessionId,
11416 eCSR_DISCONNECT_REASON_UNSPECIFIED);
11417
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011418 ret = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -070011419 &pAdapter->disconnect_comp_var,
11420 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +053011421 if (0 >= ret)
11422 hddLog(LOGE, "%s: failure waiting for disconnect_comp_var %ld",
11423 __func__, ret);
Jeff Johnson295189b2012-06-20 16:38:30 -070011424
11425 pWextState->roamProfile.csrPersona = pAdapter->device_mode;
11426 pHddCtx->isAmpAllowed = VOS_FALSE;
11427 sme_RoamConnect(pHddCtx->hHal,
11428 pAdapter->sessionId, &(pWextState->roamProfile),
11429 &roamId);
11430 }
11431
11432 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11433 pAdapterNode = pNext;
11434 }
11435
11436 EXIT();
11437
11438 return VOS_STATUS_SUCCESS;
11439}
11440
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011441void hdd_dump_concurrency_info(hdd_context_t *pHddCtx)
11442{
11443 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11444 VOS_STATUS status;
11445 hdd_adapter_t *pAdapter;
11446 hdd_station_ctx_t *pHddStaCtx;
11447 hdd_ap_ctx_t *pHddApCtx;
11448 hdd_hostapd_state_t * pHostapdState;
11449 tCsrBssid staBssid = { 0 }, p2pBssid = { 0 }, apBssid = { 0 };
11450 v_U8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
11451 const char *p2pMode = "DEV";
11452 const char *ccMode = "Standalone";
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011453
11454 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11455 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11456 {
11457 pAdapter = pAdapterNode->pAdapter;
11458 switch (pAdapter->device_mode) {
11459 case WLAN_HDD_INFRA_STATION:
11460 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11461 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
11462 staChannel = pHddStaCtx->conn_info.operationChannel;
11463 memcpy(staBssid, pHddStaCtx->conn_info.bssId, sizeof(staBssid));
11464 }
11465 break;
11466 case WLAN_HDD_P2P_CLIENT:
11467 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
11468 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
11469 p2pChannel = pHddStaCtx->conn_info.operationChannel;
11470 memcpy(p2pBssid, pHddStaCtx->conn_info.bssId, sizeof(p2pBssid));
11471 p2pMode = "CLI";
11472 }
11473 break;
11474 case WLAN_HDD_P2P_GO:
11475 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
11476 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
11477 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
11478 p2pChannel = pHddApCtx->operatingChannel;
11479 memcpy(p2pBssid, pAdapter->macAddressCurrent.bytes, sizeof(p2pBssid));
11480 }
11481 p2pMode = "GO";
11482 break;
11483 case WLAN_HDD_SOFTAP:
11484 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
11485 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
11486 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
11487 apChannel = pHddApCtx->operatingChannel;
11488 memcpy(apBssid, pAdapter->macAddressCurrent.bytes, sizeof(apBssid));
11489 }
11490 break;
11491 default:
11492 break;
11493 }
11494 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11495 pAdapterNode = pNext;
11496 }
11497 if (staChannel > 0 && (apChannel > 0 || p2pChannel > 0)) {
11498 ccMode = (p2pChannel==staChannel||apChannel==staChannel) ? "SCC" : "MCC";
11499 }
Yeshwanth Sriram Guntuka0004c0b2017-12-06 14:43:49 +053011500 hddLog(VOS_TRACE_LEVEL_ERROR, "wlan(%d) " MAC_ADDRESS_STR " %s",
11501 staChannel, MAC_ADDR_ARRAY(staBssid), ccMode);
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011502 if (p2pChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +053011503 hddLog(VOS_TRACE_LEVEL_ERROR, "p2p-%s(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011504 p2pMode, p2pChannel, MAC_ADDR_ARRAY(p2pBssid));
11505 }
11506 if (apChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +053011507 hddLog(VOS_TRACE_LEVEL_ERROR, "AP(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -070011508 apChannel, MAC_ADDR_ARRAY(apBssid));
11509 }
11510
11511 if (p2pChannel > 0 && apChannel > 0) {
11512 hddLog(VOS_TRACE_LEVEL_ERROR, "Error concurrent SAP %d and P2P %d which is not support", apChannel, p2pChannel);
11513 }
11514}
11515
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011516bool hdd_is_ssr_required( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070011517{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011518 return (isSsrRequired == HDD_SSR_REQUIRED);
Jeff Johnson295189b2012-06-20 16:38:30 -070011519}
11520
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011521/* Once SSR is disabled then it cannot be set. */
11522void hdd_set_ssr_required( e_hdd_ssr_required value)
Jeff Johnson295189b2012-06-20 16:38:30 -070011523{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -070011524 if (HDD_SSR_DISABLED == isSsrRequired)
11525 return;
11526
Jeff Johnson295189b2012-06-20 16:38:30 -070011527 isSsrRequired = value;
11528}
11529
Hema Aparna Medicharla6b4d4f32015-06-23 04:09:12 +053011530void hdd_set_pre_close( hdd_context_t *pHddCtx)
11531{
11532 sme_PreClose(pHddCtx->hHal);
11533}
11534
Jeff Johnson295189b2012-06-20 16:38:30 -070011535VOS_STATUS hdd_get_front_adapter( hdd_context_t *pHddCtx,
11536 hdd_adapter_list_node_t** ppAdapterNode)
11537{
11538 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011539 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011540 status = hdd_list_peek_front ( &pHddCtx->hddAdapters,
11541 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011542 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011543 return status;
11544}
11545
11546VOS_STATUS hdd_get_next_adapter( hdd_context_t *pHddCtx,
11547 hdd_adapter_list_node_t* pAdapterNode,
11548 hdd_adapter_list_node_t** pNextAdapterNode)
11549{
11550 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011551 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011552 status = hdd_list_peek_next ( &pHddCtx->hddAdapters,
11553 (hdd_list_node_t*) pAdapterNode,
11554 (hdd_list_node_t**)pNextAdapterNode );
11555
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011556 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011557 return status;
11558}
11559
11560VOS_STATUS hdd_remove_adapter( hdd_context_t *pHddCtx,
11561 hdd_adapter_list_node_t* pAdapterNode)
11562{
11563 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011564 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011565 status = hdd_list_remove_node ( &pHddCtx->hddAdapters,
11566 &pAdapterNode->node );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011567 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011568 return status;
11569}
11570
11571VOS_STATUS hdd_remove_front_adapter( hdd_context_t *pHddCtx,
11572 hdd_adapter_list_node_t** ppAdapterNode)
11573{
11574 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011575 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011576 status = hdd_list_remove_front( &pHddCtx->hddAdapters,
11577 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011578 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011579 return status;
11580}
11581
11582VOS_STATUS hdd_add_adapter_back( hdd_context_t *pHddCtx,
11583 hdd_adapter_list_node_t* pAdapterNode)
11584{
11585 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011586 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011587 status = hdd_list_insert_back ( &pHddCtx->hddAdapters,
11588 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011589 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011590 return status;
11591}
11592
11593VOS_STATUS hdd_add_adapter_front( hdd_context_t *pHddCtx,
11594 hdd_adapter_list_node_t* pAdapterNode)
11595{
11596 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011597 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011598 status = hdd_list_insert_front ( &pHddCtx->hddAdapters,
11599 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +053011600 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011601 return status;
11602}
11603
11604hdd_adapter_t * hdd_get_adapter_by_macaddr( hdd_context_t *pHddCtx,
11605 tSirMacAddr macAddr )
11606{
11607 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11608 hdd_adapter_t *pAdapter;
11609 VOS_STATUS status;
11610
11611 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11612
11613 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11614 {
11615 pAdapter = pAdapterNode->pAdapter;
11616
11617 if( pAdapter && vos_mem_compare( pAdapter->macAddressCurrent.bytes,
11618 macAddr, sizeof(tSirMacAddr) ) )
11619 {
11620 return pAdapter;
11621 }
11622 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11623 pAdapterNode = pNext;
11624 }
11625
11626 return NULL;
11627
11628}
11629
11630hdd_adapter_t * hdd_get_adapter_by_name( hdd_context_t *pHddCtx, tANI_U8 *name )
11631{
11632 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11633 hdd_adapter_t *pAdapter;
11634 VOS_STATUS status;
11635
11636 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11637
11638 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11639 {
11640 pAdapter = pAdapterNode->pAdapter;
11641
11642 if( pAdapter && !strncmp( pAdapter->dev->name, (const char *)name,
11643 IFNAMSIZ ) )
11644 {
11645 return pAdapter;
11646 }
11647 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11648 pAdapterNode = pNext;
11649 }
11650
11651 return NULL;
11652
11653}
11654
Ganesh Kondabattinicbfdc392015-09-11 19:12:59 +053011655hdd_adapter_t *hdd_get_adapter_by_sme_session_id( hdd_context_t *pHddCtx,
11656 tANI_U32 sme_session_id )
11657{
11658 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11659 hdd_adapter_t *pAdapter;
11660 VOS_STATUS vos_status;
11661
11662
11663 vos_status = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
11664
11665 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == vos_status))
11666 {
11667 pAdapter = pAdapterNode->pAdapter;
11668
11669 if (pAdapter->sessionId == sme_session_id)
11670 return pAdapter;
11671
11672 vos_status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
11673 pAdapterNode = pNext;
11674 }
11675
11676 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
11677 "%s: sme_session_id %d does not exist with host",
11678 __func__, sme_session_id);
11679
11680 return NULL;
11681}
11682
Jeff Johnson295189b2012-06-20 16:38:30 -070011683hdd_adapter_t * hdd_get_adapter( hdd_context_t *pHddCtx, device_mode_t mode )
11684{
11685 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11686 hdd_adapter_t *pAdapter;
11687 VOS_STATUS status;
11688
11689 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11690
11691 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11692 {
11693 pAdapter = pAdapterNode->pAdapter;
11694
11695 if( pAdapter && (mode == pAdapter->device_mode) )
11696 {
11697 return pAdapter;
11698 }
11699 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11700 pAdapterNode = pNext;
11701 }
11702
11703 return NULL;
11704
11705}
11706
11707//Remove this function later
11708hdd_adapter_t * hdd_get_mon_adapter( hdd_context_t *pHddCtx )
11709{
11710 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11711 hdd_adapter_t *pAdapter;
11712 VOS_STATUS status;
11713
11714 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11715
11716 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11717 {
11718 pAdapter = pAdapterNode->pAdapter;
11719
11720 if( pAdapter && WLAN_HDD_MONITOR == pAdapter->device_mode )
11721 {
11722 return pAdapter;
11723 }
11724
11725 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11726 pAdapterNode = pNext;
11727 }
11728
11729 return NULL;
11730
11731}
11732
Jeff Johnson295189b2012-06-20 16:38:30 -070011733/**---------------------------------------------------------------------------
11734
Mahesh A Saptasgar64534612014-09-23 13:13:33 +053011735 \brief hdd_get_operating_channel() -
Jeff Johnson295189b2012-06-20 16:38:30 -070011736
11737 This API returns the operating channel of the requested device mode
11738
11739 \param - pHddCtx - Pointer to the HDD context.
11740 - mode - Device mode for which operating channel is required
11741 suported modes - WLAN_HDD_INFRA_STATION, WLAN_HDD_P2P_CLIENT
11742 WLAN_HDD_SOFTAP, WLAN_HDD_P2P_GO.
11743 \return - channel number. "0" id the requested device is not found OR it is not connected.
11744 --------------------------------------------------------------------------*/
11745v_U8_t hdd_get_operating_channel( hdd_context_t *pHddCtx, device_mode_t mode )
11746{
11747 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
11748 VOS_STATUS status;
11749 hdd_adapter_t *pAdapter;
11750 v_U8_t operatingChannel = 0;
11751
11752 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
11753
11754 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
11755 {
11756 pAdapter = pAdapterNode->pAdapter;
11757
11758 if( mode == pAdapter->device_mode )
11759 {
11760 switch(pAdapter->device_mode)
11761 {
11762 case WLAN_HDD_INFRA_STATION:
11763 case WLAN_HDD_P2P_CLIENT:
11764 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
11765 operatingChannel = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.operationChannel;
11766 break;
11767 case WLAN_HDD_SOFTAP:
11768 case WLAN_HDD_P2P_GO:
11769 /*softap connection info */
11770 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
11771 operatingChannel = (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->operatingChannel;
11772 break;
11773 default:
11774 break;
11775 }
11776
11777 break; //Found the device of interest. break the loop
11778 }
11779
11780 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
11781 pAdapterNode = pNext;
11782 }
11783 return operatingChannel;
11784}
11785
11786#ifdef WLAN_FEATURE_PACKET_FILTERING
11787/**---------------------------------------------------------------------------
11788
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011789 \brief __hdd_set_multicast_list() -
Jeff Johnson295189b2012-06-20 16:38:30 -070011790
11791 This used to set the multicast address list.
11792
11793 \param - dev - Pointer to the WLAN device.
11794 - skb - Pointer to OS packet (sk_buff).
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011795 \return - success/fail
Jeff Johnson295189b2012-06-20 16:38:30 -070011796
11797 --------------------------------------------------------------------------*/
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011798static void __hdd_set_multicast_list(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -070011799{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011800 hdd_adapter_t *pAdapter;
11801 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -070011802 int mc_count;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011803 int i = 0, ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011804 struct netdev_hw_addr *ha;
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011805
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011806 ENTER();
11807
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011808 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011809 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070011810 {
11811 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011812 "%s: Adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070011813 return;
11814 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011815 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11816 ret = wlan_hdd_validate_context(pHddCtx);
11817 if (0 != ret)
11818 {
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011819 return;
11820 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011821 if (dev->flags & IFF_ALLMULTI)
11822 {
11823 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011824 "%s: allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011825 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011826 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011827 else
Jeff Johnson295189b2012-06-20 16:38:30 -070011828 {
11829 mc_count = netdev_mc_count(dev);
11830 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011831 "%s: mc_count = %u", __func__, mc_count);
Jeff Johnson295189b2012-06-20 16:38:30 -070011832 if (mc_count > WLAN_HDD_MAX_MC_ADDR_LIST)
11833 {
11834 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011835 "%s: No free filter available; allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011836 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070011837 return;
11838 }
11839
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011840 pAdapter->mc_addr_list.mc_cnt = mc_count;
Jeff Johnson295189b2012-06-20 16:38:30 -070011841
11842 netdev_for_each_mc_addr(ha, dev) {
11843 if (i == mc_count)
11844 break;
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011845 memset(&(pAdapter->mc_addr_list.addr[i][0]), 0, ETH_ALEN);
11846 memcpy(&(pAdapter->mc_addr_list.addr[i][0]), ha->addr, ETH_ALEN);
Arif Hussain6d2a3322013-11-17 19:50:10 -080011847 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mlist[%d] = "MAC_ADDRESS_STR,
Mahesh A Saptasagar74088392015-02-05 17:22:09 +053011848 __func__, i,
Gopichand Nakkala0f276812013-02-24 14:45:51 +053011849 MAC_ADDR_ARRAY(pAdapter->mc_addr_list.addr[i]));
Jeff Johnson295189b2012-06-20 16:38:30 -070011850 i++;
11851 }
11852 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011853
Ganesh Kondabattinifb37e652015-10-09 15:46:47 +053011854 if (pHddCtx->hdd_wlan_suspended)
11855 {
11856 /*
11857 * Configure the Mcast address list to FW
11858 * If wlan is already in suspend mode
11859 */
11860 wlan_hdd_set_mc_addr_list(pAdapter, TRUE);
11861 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +053011862 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -070011863 return;
11864}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +053011865
11866static void hdd_set_multicast_list(struct net_device *dev)
11867{
11868 vos_ssr_protect(__func__);
11869 __hdd_set_multicast_list(dev);
11870 vos_ssr_unprotect(__func__);
11871}
Jeff Johnson295189b2012-06-20 16:38:30 -070011872#endif
11873
11874/**---------------------------------------------------------------------------
11875
11876 \brief hdd_select_queue() -
11877
11878 This function is registered with the Linux OS for network
11879 core to decide which queue to use first.
11880
11881 \param - dev - Pointer to the WLAN device.
11882 - skb - Pointer to OS packet (sk_buff).
11883 \return - ac, Queue Index/access category corresponding to UP in IP header
11884
11885 --------------------------------------------------------------------------*/
11886v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053011887 struct sk_buff *skb
11888#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
11889 , void *accel_priv
11890#endif
11891#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
11892 , select_queue_fallback_t fallback
11893#endif
11894)
Jeff Johnson295189b2012-06-20 16:38:30 -070011895{
11896 return hdd_wmm_select_queue(dev, skb);
11897}
11898
11899
11900/**---------------------------------------------------------------------------
11901
11902 \brief hdd_wlan_initial_scan() -
11903
11904 This function triggers the initial scan
11905
11906 \param - pAdapter - Pointer to the HDD adapter.
11907
11908 --------------------------------------------------------------------------*/
11909void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter)
11910{
11911 tCsrScanRequest scanReq;
11912 tCsrChannelInfo channelInfo;
11913 eHalStatus halStatus;
Jeff Johnson02797792013-10-26 19:17:13 -070011914 tANI_U32 scanId;
Jeff Johnson295189b2012-06-20 16:38:30 -070011915 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
11916
11917 vos_mem_zero(&scanReq, sizeof(tCsrScanRequest));
11918 vos_mem_set(&scanReq.bssid, sizeof(tCsrBssid), 0xff);
11919 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
11920
11921 if(sme_Is11dSupported(pHddCtx->hHal))
11922 {
11923 halStatus = sme_ScanGetBaseChannels( pHddCtx->hHal, &channelInfo );
11924 if ( HAL_STATUS_SUCCESS( halStatus ) )
11925 {
11926 scanReq.ChannelInfo.ChannelList = vos_mem_malloc(channelInfo.numOfChannels);
11927 if( !scanReq.ChannelInfo.ChannelList )
11928 {
11929 hddLog(VOS_TRACE_LEVEL_ERROR, "%s kmalloc failed", __func__);
11930 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080011931 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011932 return;
11933 }
11934 vos_mem_copy(scanReq.ChannelInfo.ChannelList, channelInfo.ChannelList,
11935 channelInfo.numOfChannels);
11936 scanReq.ChannelInfo.numOfChannels = channelInfo.numOfChannels;
11937 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -080011938 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011939 }
11940
11941 scanReq.scanType = eSIR_PASSIVE_SCAN;
11942 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
11943 scanReq.maxChnTime = pHddCtx->cfg_ini->nPassiveMaxChnTime;
11944 scanReq.minChnTime = pHddCtx->cfg_ini->nPassiveMinChnTime;
11945 }
11946 else
11947 {
11948 scanReq.scanType = eSIR_ACTIVE_SCAN;
11949 scanReq.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
11950 scanReq.maxChnTime = pHddCtx->cfg_ini->nActiveMaxChnTime;
11951 scanReq.minChnTime = pHddCtx->cfg_ini->nActiveMinChnTime;
11952 }
11953
11954 halStatus = sme_ScanRequest(pHddCtx->hHal, pAdapter->sessionId, &scanReq, &scanId, NULL, NULL);
11955 if ( !HAL_STATUS_SUCCESS( halStatus ) )
11956 {
11957 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_ScanRequest failed status code %d",
11958 __func__, halStatus );
11959 }
11960
11961 if(sme_Is11dSupported(pHddCtx->hHal))
11962 vos_mem_free(scanReq.ChannelInfo.ChannelList);
11963}
11964
Jeff Johnson295189b2012-06-20 16:38:30 -070011965/**---------------------------------------------------------------------------
11966
11967 \brief hdd_full_power_callback() - HDD full power callback function
11968
11969 This is the function invoked by SME to inform the result of a full power
11970 request issued by HDD
11971
11972 \param - callbackcontext - Pointer to cookie
11973 \param - status - result of request
11974
11975 \return - None
11976
11977 --------------------------------------------------------------------------*/
11978static void hdd_full_power_callback(void *callbackContext, eHalStatus status)
11979{
Jeff Johnson72a40512013-12-19 10:14:15 -080011980 struct statsContext *pContext = callbackContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070011981
11982 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070011983 "%s: context = %pK, status = %d", __func__, pContext, status);
Jeff Johnson295189b2012-06-20 16:38:30 -070011984
11985 if (NULL == callbackContext)
11986 {
11987 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070011988 "%s: Bad param, context [%pK]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011989 __func__, callbackContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070011990 return;
11991 }
11992
Jeff Johnson72a40512013-12-19 10:14:15 -080011993 /* there is a race condition that exists between this callback
11994 function and the caller since the caller could time out either
11995 before or while this code is executing. we use a spinlock to
11996 serialize these actions */
11997 spin_lock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070011998
11999 if (POWER_CONTEXT_MAGIC != pContext->magic)
12000 {
12001 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -080012002 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012003 hddLog(VOS_TRACE_LEVEL_WARN,
12004 "%s: Invalid context, magic [%08x]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012005 __func__, pContext->magic);
Jeff Johnson295189b2012-06-20 16:38:30 -070012006 return;
12007 }
12008
Jeff Johnson72a40512013-12-19 10:14:15 -080012009 /* context is valid so caller is still waiting */
12010
12011 /* paranoia: invalidate the magic */
12012 pContext->magic = 0;
12013
12014 /* notify the caller */
Jeff Johnson295189b2012-06-20 16:38:30 -070012015 complete(&pContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -080012016
12017 /* serialization is complete */
12018 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012019}
12020
Katya Nigamf0511f62015-05-05 16:40:57 +053012021void wlan_hdd_mon_set_typesubtype( hdd_mon_ctx_t *pMonCtx,int type)
12022{
12023 pMonCtx->typeSubtypeBitmap = 0;
12024 if( type%10 ) /* Management Packets */
12025 pMonCtx->typeSubtypeBitmap |= 0xFFFF;
12026 type/=10;
12027 if( type%10 ) /* Control Packets */
12028 pMonCtx->typeSubtypeBitmap |= 0xFFFF0000;
12029 type/=10;
12030 if( type%10 ) /* Data Packets */
12031 pMonCtx->typeSubtypeBitmap |= 0xFFFF00000000;
12032}
12033
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012034VOS_STATUS wlan_hdd_mon_postMsg(void *context, hdd_mon_ctx_t *pMonCtx,
12035 void* callback)
Katya Nigamf0511f62015-05-05 16:40:57 +053012036{
12037 vos_msg_t monMsg;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012038 tSirMonModeReq *pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +053012039
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012040 if (MON_MODE_START == pMonCtx->state)
12041 monMsg.type = WDA_MON_START_REQ;
12042 else if (MON_MODE_STOP == pMonCtx->state)
12043 monMsg.type = WDA_MON_STOP_REQ;
12044 else {
12045 hddLog(VOS_TRACE_LEVEL_ERROR,
12046 FL("invalid monitor state %d"), pMonCtx->state);
Katya Nigamf0511f62015-05-05 16:40:57 +053012047 return VOS_STATUS_E_FAILURE;
12048 }
12049
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012050 pMonModeReq = vos_mem_malloc(sizeof(tSirMonModeReq));
12051 if (pMonModeReq == NULL) {
12052 hddLog(VOS_TRACE_LEVEL_ERROR,
12053 FL("fail to allocate memory for monitor mode req"));
12054 return VOS_STATUS_E_FAILURE;
12055 }
Katya Nigamf0511f62015-05-05 16:40:57 +053012056
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012057 pMonModeReq->context = context;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012058 pMonModeReq->data = pMonCtx;
12059 pMonModeReq->callback = callback;
Katya Nigamf0511f62015-05-05 16:40:57 +053012060
Katya Nigamf0511f62015-05-05 16:40:57 +053012061 monMsg.reserved = 0;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012062 monMsg.bodyptr = pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +053012063 monMsg.bodyval = 0;
12064
12065 if (VOS_STATUS_SUCCESS != vos_mq_post_message(
12066 VOS_MODULE_ID_WDA,(vos_msg_t *)&monMsg)) {
12067 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: : Failed to post Msg to HAL",__func__);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012068 vos_mem_free(pMonModeReq);
Katya Nigamf0511f62015-05-05 16:40:57 +053012069 }
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012070 return VOS_STATUS_SUCCESS;
Katya Nigamf0511f62015-05-05 16:40:57 +053012071}
12072
Katya Nigame7b69a82015-04-28 15:24:06 +053012073void wlan_hdd_mon_close(hdd_context_t *pHddCtx)
12074{
12075 VOS_STATUS vosStatus;
12076 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012077 hdd_mon_ctx_t *pMonCtx = NULL;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012078 int ret;
12079 void *cookie;
12080 struct hdd_request *request;
12081 static const struct hdd_request_params params = {
12082 .priv_size = 0,
12083 .timeout_ms = MON_MODE_MSG_TIMEOUT,
12084 };
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053012085
Katya Nigame7b69a82015-04-28 15:24:06 +053012086 hdd_adapter_t *pAdapter = hdd_get_adapter(pHddCtx,WLAN_HDD_MONITOR);
12087 if(pAdapter == NULL || pVosContext == NULL)
12088 {
12089 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:pAdapter is NULL",__func__);
12090 return ;
12091 }
Katya Nigamf0511f62015-05-05 16:40:57 +053012092
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012093 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
12094 if (pMonCtx!= NULL && pMonCtx->state == MON_MODE_START) {
12095 pMonCtx->state = MON_MODE_STOP;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012096 request = hdd_request_alloc(&params);
12097 if (!request) {
12098 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Request allocation failure"));
12099 return;
12100 }
12101 cookie = hdd_request_cookie(request);
12102
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012103 if (VOS_STATUS_SUCCESS !=
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012104 wlan_hdd_mon_postMsg(cookie, pMonCtx,
12105 hdd_mon_post_msg_cb)) {
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012106 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12107 FL("failed to post MON MODE REQ"));
12108 pMonCtx->state = MON_MODE_START;
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012109 goto req_put;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012110 }
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012111
12112 ret = hdd_request_wait_for_response(request);
12113 if (ret)
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012114 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hanumanth Reddy Pothulab8be9ab2018-04-12 20:03:05 +053012115 FL("timeout on monitor mode completion %d"), ret);
12116
12117req_put:
12118 hdd_request_put(request);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +053012119 }
12120
Katya Nigame7b69a82015-04-28 15:24:06 +053012121 hdd_UnregisterWext(pAdapter->dev);
12122
12123 vos_mon_stop( pVosContext );
12124
12125 vosStatus = vos_sched_close( pVosContext );
12126 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
12127 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
12128 "%s: Failed to close VOSS Scheduler",__func__);
12129 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12130 }
12131
12132 vosStatus = vos_nv_close();
12133 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12134 {
12135 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12136 "%s: Failed to close NV", __func__);
12137 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12138 }
12139
12140 vos_close(pVosContext);
12141
12142 #ifdef WLAN_KD_READY_NOTIFIER
12143 nl_srv_exit(pHddCtx->ptt_pid);
12144 #else
12145 nl_srv_exit();
12146 #endif
12147
Katya Nigame7b69a82015-04-28 15:24:06 +053012148 hdd_close_all_adapters( pHddCtx );
Katya Nigame7b69a82015-04-28 15:24:06 +053012149}
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012150/**
12151 * hdd_wlan_free_wiphy_channels - free Channel pointer for wiphy
12152 * @ wiphy: the wiphy to validate against
12153 *
12154 * Return: void
12155 */
12156void hdd_wlan_free_wiphy_channels(struct wiphy *wiphy)
12157{
12158 int i =0;
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053012159 for (i = 0; i < HDD_NUM_NL80211_BANDS; i++)
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012160 {
12161 if (NULL != wiphy->bands[i] &&
12162 (NULL != wiphy->bands[i]->channels))
12163 {
12164 vos_mem_free(wiphy->bands[i]->channels);
12165 wiphy->bands[i]->channels = NULL;
12166 }
12167 }
12168}
Jeff Johnson295189b2012-06-20 16:38:30 -070012169/**---------------------------------------------------------------------------
12170
12171 \brief hdd_wlan_exit() - HDD WLAN exit function
12172
12173 This is the driver exit point (invoked during rmmod)
12174
12175 \param - pHddCtx - Pointer to the HDD Context
12176
12177 \return - None
12178
12179 --------------------------------------------------------------------------*/
12180void hdd_wlan_exit(hdd_context_t *pHddCtx)
12181{
12182 eHalStatus halStatus;
12183 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
12184 VOS_STATUS vosStatus;
Gopichand Nakkala66923aa2013-03-06 23:17:24 +053012185 struct wiphy *wiphy = pHddCtx->wiphy;
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080012186 hdd_adapter_t* pAdapter = NULL;
Jeff Johnson72a40512013-12-19 10:14:15 -080012187 struct statsContext powerContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070012188 long lrc;
c_hpothu5ab05e92014-06-13 17:34:05 +053012189 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070012190
12191 ENTER();
12192
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012193
Katya Nigame7b69a82015-04-28 15:24:06 +053012194 if (VOS_MONITOR_MODE == hdd_get_conparam())
12195 {
12196 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: MONITOR MODE",__func__);
12197 wlan_hdd_mon_close(pHddCtx);
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053012198 goto free_hdd_ctx;
Katya Nigame7b69a82015-04-28 15:24:06 +053012199 }
12200 else if (VOS_FTM_MODE != hdd_get_conparam())
Jeff Johnson88ba7742013-02-27 14:36:02 -080012201 {
12202 // Unloading, restart logic is no more required.
12203 wlan_hdd_restart_deinit(pHddCtx);
Jeff Johnsone7245742012-09-05 17:12:55 -070012204
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053012205#ifdef FEATURE_WLAN_TDLS
12206 /* At the time of driver unloading; if tdls connection is present;
12207 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer.
12208 * wlan_hdd_tdls_find_peer always checks for valid context;
12209 * as load/unload in progress there can be a race condition.
12210 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer only
12211 * when tdls state is enabled.
12212 * As soon as driver set load/unload flag; tdls flag also needs
12213 * to be disabled so that hdd_rx_packet_cbk won't call
12214 * wlan_hdd_tdls_find_peer.
12215 */
Masti, Narayanraddi20494af2015-12-17 20:56:42 +053012216 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE,
12217 HDD_SET_TDLS_MODE_SOURCE_USER);
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053012218#endif
12219
c_hpothu5ab05e92014-06-13 17:34:05 +053012220 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
12221 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
Jeff Johnson295189b2012-06-20 16:38:30 -070012222 {
c_hpothu5ab05e92014-06-13 17:34:05 +053012223 pAdapter = pAdapterNode->pAdapter;
12224 if (NULL != pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070012225 {
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +053012226 /* Disable TX on the interface, after this hard_start_xmit() will
12227 * not be called on that interface
12228 */
12229 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
12230 netif_tx_disable(pAdapter->dev);
12231
12232 /* Mark the interface status as "down" for outside world */
12233 netif_carrier_off(pAdapter->dev);
12234
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053012235 /* DeInit the adapter. This ensures that all data packets
12236 * are freed.
12237 */
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053012238#ifdef FEATURE_WLAN_TDLS
12239 mutex_lock(&pHddCtx->tdls_lock);
12240#endif
c_hpothu002231a2015-02-05 14:58:51 +053012241 hdd_deinit_adapter(pHddCtx, pAdapter, FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053012242#ifdef FEATURE_WLAN_TDLS
12243 mutex_unlock(&pHddCtx->tdls_lock);
12244#endif
Masti, Narayanraddi26378462016-01-05 18:20:28 +053012245 vos_flush_delayed_work(&pHddCtx->scan_ctxt.scan_work);
12246
12247 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053012248
c_hpothu5ab05e92014-06-13 17:34:05 +053012249 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053012250 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
12251 WLAN_HDD_MONITOR == pAdapter->device_mode)
c_hpothu5ab05e92014-06-13 17:34:05 +053012252 {
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053012253 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
12254 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
12255 wlan_hdd_cfg80211_deregister_frames(pAdapter);
12256
c_hpothu5ab05e92014-06-13 17:34:05 +053012257 hdd_UnregisterWext(pAdapter->dev);
12258 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012259
Jeff Johnson295189b2012-06-20 16:38:30 -070012260 }
c_hpothu5ab05e92014-06-13 17:34:05 +053012261 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
12262 pAdapterNode = pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -070012263 }
mukul sharmabab477d2015-06-11 17:14:55 +053012264
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012265 // Cancel any outstanding scan requests. We are about to close all
12266 // of our adapters, but an adapter structure is what SME passes back
12267 // to our callback function. Hence if there are any outstanding scan
12268 // requests then there is a race condition between when the adapter
12269 // is closed and when the callback is invoked.We try to resolve that
12270 // race condition here by canceling any outstanding scans before we
12271 // close the adapters.
12272 // Note that the scans may be cancelled in an asynchronous manner,
12273 // so ideally there needs to be some kind of synchronization. Rather
12274 // than introduce a new synchronization here, we will utilize the
12275 // fact that we are about to Request Full Power, and since that is
12276 // synchronized, the expectation is that by the time Request Full
12277 // Power has completed all scans will be cancelled.
12278 if (pHddCtx->scan_info.mScanPending)
12279 {
Hema Aparna Medicharlaf05f6cd2015-01-21 14:44:19 +053012280 if(NULL != pAdapter)
12281 {
12282 hddLog(VOS_TRACE_LEVEL_INFO,
12283 FL("abort scan mode: %d sessionId: %d"),
12284 pAdapter->device_mode,
12285 pAdapter->sessionId);
12286 }
12287 hdd_abort_mac_scan(pHddCtx,
12288 pHddCtx->scan_info.sessionId,
12289 eCSR_SCAN_ABORT_DEFAULT);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053012290 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012291 }
c_hpothu5ab05e92014-06-13 17:34:05 +053012292 else
Jeff Johnson88ba7742013-02-27 14:36:02 -080012293 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012294 hddLog(VOS_TRACE_LEVEL_INFO,"%s: FTM MODE",__func__);
Hanumantha Reddy Pothula45af96b2015-02-12 16:07:58 +053012295 if (pHddCtx->ftm.ftm_state == WLAN_FTM_STARTING)
12296 {
12297 INIT_COMPLETION(pHddCtx->ftm.startCmpVar);
12298 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
12299 "%s: in middle of FTM START", __func__);
12300 lrc = wait_for_completion_timeout(&pHddCtx->ftm.startCmpVar,
12301 msecs_to_jiffies(20000));
12302 if(!lrc)
12303 {
12304 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
12305 "%s: timedout on ftmStartCmpVar fatal error", __func__);
12306 }
12307 }
Jeff Johnson88ba7742013-02-27 14:36:02 -080012308 wlan_hdd_ftm_close(pHddCtx);
12309 goto free_hdd_ctx;
12310 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012311
Jeff Johnson295189b2012-06-20 16:38:30 -070012312 /* DeRegister with platform driver as client for Suspend/Resume */
12313 vosStatus = hddDeregisterPmOps(pHddCtx);
12314 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
12315 {
12316 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDeregisterPmOps failed",__func__);
12317 VOS_ASSERT(0);
12318 }
12319
12320 vosStatus = hddDevTmUnregisterNotifyCallback(pHddCtx);
12321 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
12322 {
12323 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
12324 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012325
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012326 //Stop the traffic monitor timer
Mahesh A Saptasagard461e432016-07-20 15:01:40 +053012327 if ((pHddCtx->cfg_ini->dynSplitscan) && (VOS_TIMER_STATE_RUNNING ==
12328 vos_timer_getCurrentState(&pHddCtx->tx_rx_trafficTmr)))
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012329 {
12330 vos_timer_stop(&pHddCtx->tx_rx_trafficTmr);
12331 }
12332
12333 // Destroy the traffic monitor timer
Mahesh A Saptasagard461e432016-07-20 15:01:40 +053012334 if ((pHddCtx->cfg_ini->dynSplitscan) &&
12335 (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
12336 &pHddCtx->tx_rx_trafficTmr))))
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012337 {
12338 hddLog(VOS_TRACE_LEVEL_ERROR,
12339 "%s: Cannot deallocate Traffic monitor timer", __func__);
12340 }
12341
Bhargav Shahd0715912015-10-01 18:17:37 +053012342 if (VOS_TIMER_STATE_RUNNING ==
12343 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
12344 vos_timer_stop(&pHddCtx->delack_timer);
12345 }
12346
12347 if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
12348 &pHddCtx->delack_timer))) {
12349 hddLog(VOS_TRACE_LEVEL_ERROR,
12350 "%s: Cannot deallocate Bus bandwidth timer", __func__);
12351 }
12352
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053012353 if (VOS_TIMER_STATE_RUNNING ==
12354 vos_timer_getCurrentState(&pHddCtx->tdls_source_timer)) {
12355 vos_timer_stop(&pHddCtx->tdls_source_timer);
12356 }
12357
Abhishek Singh8a3e4dc2017-01-02 10:39:18 +053012358 vos_set_snoc_high_freq_voting(false);
12359
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053012360 vos_timer_destroy(&pHddCtx->tdls_source_timer);
12361
Jeff Johnson295189b2012-06-20 16:38:30 -070012362 //Disable IMPS/BMPS as we do not want the device to enter any power
12363 //save mode during shutdown
12364 sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
12365 sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
12366 sme_DisablePowerSave(pHddCtx->hHal, ePMC_UAPSD_MODE_POWER_SAVE);
12367
12368 //Ensure that device is in full power as we will touch H/W during vos_Stop
12369 init_completion(&powerContext.completion);
12370 powerContext.magic = POWER_CONTEXT_MAGIC;
12371
12372 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_power_callback,
12373 &powerContext, eSME_FULL_PWR_NEEDED_BY_HDD);
12374
12375 if (eHAL_STATUS_SUCCESS != halStatus)
12376 {
12377 if (eHAL_STATUS_PMC_PENDING == halStatus)
12378 {
12379 /* request was sent -- wait for the response */
12380 lrc = wait_for_completion_interruptible_timeout(
12381 &powerContext.completion,
12382 msecs_to_jiffies(WLAN_WAIT_TIME_POWER));
Jeff Johnson295189b2012-06-20 16:38:30 -070012383 if (lrc <= 0)
12384 {
12385 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: %s while requesting full power",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012386 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson295189b2012-06-20 16:38:30 -070012387 }
12388 }
12389 else
12390 {
12391 hddLog(VOS_TRACE_LEVEL_ERROR,
12392 "%s: Request for Full Power failed, status %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012393 __func__, halStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -070012394 /* continue -- need to clean up as much as possible */
12395 }
12396 }
Hanumantha Reddy Pothula81b42b22015-05-12 13:52:00 +053012397 if ((eHAL_STATUS_SUCCESS == halStatus) ||
12398 (eHAL_STATUS_PMC_PENDING == halStatus && lrc > 0))
12399 {
12400 /* This will issue a dump command which will clean up
12401 BTQM queues and unblock MC thread */
12402 vos_fwDumpReq(274, 0, 0, 0, 0, 1);
12403 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012404
Jeff Johnson72a40512013-12-19 10:14:15 -080012405 /* either we never sent a request, we sent a request and received a
12406 response or we sent a request and timed out. if we never sent a
12407 request or if we sent a request and got a response, we want to
12408 clear the magic out of paranoia. if we timed out there is a
12409 race condition such that the callback function could be
12410 executing at the same time we are. of primary concern is if the
12411 callback function had already verified the "magic" but had not
12412 yet set the completion variable when a timeout occurred. we
12413 serialize these activities by invalidating the magic while
12414 holding a shared spinlock which will cause us to block if the
12415 callback is currently executing */
12416 spin_lock(&hdd_context_lock);
12417 powerContext.magic = 0;
12418 spin_unlock(&hdd_context_lock);
12419
Hema Aparna Medicharlaa6cf65e2015-06-01 16:23:28 +053012420 /* If Device is shutdown, no point for SME to wait for responses
12421 from device. Pre Close SME */
12422 if(wcnss_device_is_shutdown())
12423 {
12424 sme_PreClose(pHddCtx->hHal);
12425 }
Yue Ma0d4891e2013-08-06 17:01:45 -070012426 hdd_debugfs_exit(pHddCtx);
12427
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012428#ifdef WLAN_NS_OFFLOAD
Ratheesh S P36dbc932015-08-07 14:28:57 +053012429 hddLog(LOG1, FL("Unregister IPv6 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012430 unregister_inet6addr_notifier(&pHddCtx->ipv6_notifier);
12431#endif
Ratheesh S P36dbc932015-08-07 14:28:57 +053012432 hddLog(LOG1, FL("Unregister IPv4 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053012433 unregister_inetaddr_notifier(&pHddCtx->ipv4_notifier);
12434
Jeff Johnson295189b2012-06-20 16:38:30 -070012435 // Unregister the Net Device Notifier
12436 unregister_netdevice_notifier(&hdd_netdev_notifier);
12437
Jeff Johnson295189b2012-06-20 16:38:30 -070012438 hdd_stop_all_adapters( pHddCtx );
12439
Jeff Johnson295189b2012-06-20 16:38:30 -070012440#ifdef WLAN_BTAMP_FEATURE
12441 vosStatus = WLANBAP_Stop(pVosContext);
12442 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12443 {
12444 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12445 "%s: Failed to stop BAP",__func__);
12446 }
12447#endif //WLAN_BTAMP_FEATURE
12448
12449 //Stop all the modules
12450 vosStatus = vos_stop( pVosContext );
12451 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12452 {
12453 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
12454 "%s: Failed to stop VOSS",__func__);
12455 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053012456 if (isSsrPanicOnFailure())
12457 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -070012458 }
12459
Jeff Johnson295189b2012-06-20 16:38:30 -070012460 //This requires pMac access, Call this before vos_close().
Jeff Johnson295189b2012-06-20 16:38:30 -070012461 hdd_unregister_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070012462
12463 //Close the scheduler before calling vos_close to make sure no thread is
12464 // scheduled after the each module close is called i.e after all the data
12465 // structures are freed.
12466 vosStatus = vos_sched_close( pVosContext );
12467 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
12468 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
12469 "%s: Failed to close VOSS Scheduler",__func__);
12470 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12471 }
Jeff Johnsone7245742012-09-05 17:12:55 -070012472#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
12473 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012474 vos_wake_lock_destroy(&pHddCtx->rx_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -070012475#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080012476 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012477 vos_wake_lock_destroy(&pHddCtx->sap_wake_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012478
Mihir Shete7a24b5f2013-12-21 12:18:31 +053012479#ifdef CONFIG_ENABLE_LINUX_REG
12480 vosStatus = vos_nv_close();
12481 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
12482 {
12483 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
12484 "%s: Failed to close NV", __func__);
12485 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
12486 }
12487#endif
12488
Jeff Johnson295189b2012-06-20 16:38:30 -070012489 //Close VOSS
12490 //This frees pMac(HAL) context. There should not be any call that requires pMac access after this.
12491 vos_close(pVosContext);
12492
Jeff Johnson295189b2012-06-20 16:38:30 -070012493 //Close Watchdog
12494 if(pHddCtx->cfg_ini->fIsLogpEnabled)
12495 vos_watchdog_close(pVosContext);
12496
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053012497 //Clean up HDD Nlink Service
12498 send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0);
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053012499
Manjeet Singh47ee8472016-04-11 11:57:18 +053012500 hdd_close_tx_queues(pHddCtx);
c_manjeecfd1efb2015-09-25 19:32:34 +053012501 wlan_free_fwr_mem_dump_buffer();
c_manjeecfd1efb2015-09-25 19:32:34 +053012502
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012503#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053012504 if (pHddCtx->cfg_ini->wlanLoggingEnable)
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012505 {
12506 wlan_logging_sock_deactivate_svc();
12507 }
12508#endif
12509
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053012510#ifdef WLAN_KD_READY_NOTIFIER
12511 nl_srv_exit(pHddCtx->ptt_pid);
12512#else
12513 nl_srv_exit();
12514#endif /* WLAN_KD_READY_NOTIFIER */
12515
Abhishek Singh00b71972016-01-07 10:51:04 +053012516#ifdef WLAN_FEATURE_RMC
12517 hdd_close_cesium_nl_sock();
12518#endif /* WLAN_FEATURE_RMC */
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053012519
Jeff Johnson295189b2012-06-20 16:38:30 -070012520 hdd_close_all_adapters( pHddCtx );
12521
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053012522 vos_flush_delayed_work(&pHddCtx->spoof_mac_addr_work);
Abhishek Singh78c691f2017-11-30 13:48:44 +053012523 vos_flush_delayed_work(&pHddCtx->ecsa_chan_change_work);
Kapil Gupta137ef892016-12-13 19:38:00 +053012524 vos_flush_work(&pHddCtx->sap_start_work);
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053012525
Hanumantha Reddy Pothula97f9bc92015-08-10 17:21:20 +053012526free_hdd_ctx:
Jeff Johnson295189b2012-06-20 16:38:30 -070012527 /* free the power on lock from platform driver */
12528 if (free_riva_power_on_lock("wlan"))
12529 {
12530 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to free power on lock",
12531 __func__);
12532 }
12533
Ashish Kumar Dhanotiya95e5bc22018-04-19 17:06:33 +053012534 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
12535 wlan_hdd_free_cache_channels(pHddCtx);
12536
c_hpothu78c7b602014-05-17 17:35:49 +053012537 //Free up dynamically allocated members inside HDD Adapter
12538 if (pHddCtx->cfg_ini)
12539 {
12540 kfree(pHddCtx->cfg_ini);
12541 pHddCtx->cfg_ini= NULL;
12542 }
12543
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053012544 hdd_request_manager_deinit();
12545
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053012546 /* FTM/MONITOR mode, WIPHY did not registered
Leo Changf04ddad2013-09-18 13:46:38 -070012547 If un-register here, system crash will happen */
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053012548 if (!(VOS_FTM_MODE == hdd_get_conparam() ||
12549 VOS_MONITOR_MODE == hdd_get_conparam()))
Leo Changf04ddad2013-09-18 13:46:38 -070012550 {
12551 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012552 hdd_wlan_free_wiphy_channels(wiphy);
Leo Changf04ddad2013-09-18 13:46:38 -070012553 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012554 wiphy_free(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070012555 if (hdd_is_ssr_required())
12556 {
12557 /* WDI timeout had happened during unload, so SSR is needed here */
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -070012558 subsystem_restart("wcnss");
Jeff Johnson295189b2012-06-20 16:38:30 -070012559 msleep(5000);
12560 }
12561 hdd_set_ssr_required (VOS_FALSE);
12562}
12563
12564
12565/**---------------------------------------------------------------------------
12566
12567 \brief hdd_update_config_from_nv() - Function to update the contents of
12568 the running configuration with parameters taken from NV storage
12569
12570 \param - pHddCtx - Pointer to the HDD global context
12571
12572 \return - VOS_STATUS_SUCCESS if successful
12573
12574 --------------------------------------------------------------------------*/
12575static VOS_STATUS hdd_update_config_from_nv(hdd_context_t* pHddCtx)
12576{
Jeff Johnson295189b2012-06-20 16:38:30 -070012577 v_BOOL_t itemIsValid = VOS_FALSE;
12578 VOS_STATUS status;
12579 v_MACADDR_t macFromNV[VOS_MAX_CONCURRENCY_PERSONA];
12580 v_U8_t macLoop;
12581
12582 /*If the NV is valid then get the macaddress from nv else get it from qcom_cfg.ini*/
12583 status = vos_nv_getValidity(VNV_FIELD_IMAGE, &itemIsValid);
12584 if(status != VOS_STATUS_SUCCESS)
12585 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080012586 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_getValidity() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070012587 return VOS_STATUS_E_FAILURE;
12588 }
12589
12590 if (itemIsValid == VOS_TRUE)
12591 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080012592 hddLog(VOS_TRACE_LEVEL_INFO_HIGH," Reading the Macaddress from NV");
Jeff Johnson295189b2012-06-20 16:38:30 -070012593 status = vos_nv_readMultiMacAddress((v_U8_t *)&macFromNV[0].bytes[0],
12594 VOS_MAX_CONCURRENCY_PERSONA);
12595 if(status != VOS_STATUS_SUCCESS)
12596 {
12597 /* Get MAC from NV fail, not update CFG info
12598 * INI MAC value will be used for MAC setting */
Arif Hussain6d2a3322013-11-17 19:50:10 -080012599 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_readMacAddress() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070012600 return VOS_STATUS_E_FAILURE;
12601 }
12602
12603 /* If first MAC is not valid, treat all others are not valid
12604 * Then all MACs will be got from ini file */
12605 if(vos_is_macaddr_zero(&macFromNV[0]))
12606 {
12607 /* MAC address in NV file is not configured yet */
12608 hddLog(VOS_TRACE_LEVEL_WARN, "Invalid MAC in NV file");
12609 return VOS_STATUS_E_INVAL;
12610 }
12611
12612 /* Get MAC address from NV, update CFG info */
12613 for(macLoop = 0; macLoop < VOS_MAX_CONCURRENCY_PERSONA; macLoop++)
12614 {
12615 if(vos_is_macaddr_zero(&macFromNV[macLoop]))
12616 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053012617 hddLog(VOS_TRACE_LEVEL_ERROR,"not valid MAC from NV for %d", macLoop);
Jeff Johnson295189b2012-06-20 16:38:30 -070012618 /* This MAC is not valid, skip it
12619 * This MAC will be got from ini file */
12620 }
12621 else
12622 {
12623 vos_mem_copy((v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[macLoop].bytes[0],
12624 (v_U8_t *)&macFromNV[macLoop].bytes[0],
12625 VOS_MAC_ADDR_SIZE);
12626 }
12627 }
12628 }
12629 else
12630 {
12631 hddLog(VOS_TRACE_LEVEL_ERROR, "NV ITEM, MAC Not valid");
12632 return VOS_STATUS_E_FAILURE;
12633 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012634
Jeff Johnson295189b2012-06-20 16:38:30 -070012635
12636 return VOS_STATUS_SUCCESS;
12637}
12638
12639/**---------------------------------------------------------------------------
12640
12641 \brief hdd_post_voss_start_config() - HDD post voss start config helper
12642
12643 \param - pAdapter - Pointer to the HDD
12644
12645 \return - None
12646
12647 --------------------------------------------------------------------------*/
12648VOS_STATUS hdd_post_voss_start_config(hdd_context_t* pHddCtx)
12649{
12650 eHalStatus halStatus;
12651 v_U32_t listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012652 tANI_U32 ignoreDtim;
Jeff Johnson295189b2012-06-20 16:38:30 -070012653
Jeff Johnson295189b2012-06-20 16:38:30 -070012654
12655 // Send ready indication to the HDD. This will kick off the MAC
12656 // into a 'running' state and should kick off an initial scan.
12657 halStatus = sme_HDDReadyInd( pHddCtx->hHal );
12658 if ( !HAL_STATUS_SUCCESS( halStatus ) )
12659 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +053012660 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: sme_HDDReadyInd() failed with status "
Jeff Johnson295189b2012-06-20 16:38:30 -070012661 "code %08d [x%08x]",__func__, halStatus, halStatus );
12662 return VOS_STATUS_E_FAILURE;
12663 }
12664
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012665 // Set default LI and ignoreDtim into HDD context,
Jeff Johnson295189b2012-06-20 16:38:30 -070012666 // otherwise under some race condition, HDD will set 0 LI value into RIVA,
12667 // And RIVA will crash
12668 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, &listenInterval);
12669 pHddCtx->hdd_actual_LI_value = listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053012670 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, &ignoreDtim);
12671 pHddCtx->hdd_actual_ignore_DTIM_value = ignoreDtim;
12672
12673
Jeff Johnson295189b2012-06-20 16:38:30 -070012674 return VOS_STATUS_SUCCESS;
12675}
12676
Jeff Johnson295189b2012-06-20 16:38:30 -070012677/* wake lock APIs for HDD */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012678void hdd_prevent_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070012679{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012680
12681 vos_wake_lock_acquire(&wlan_wake_lock, reason);
12682
Jeff Johnson295189b2012-06-20 16:38:30 -070012683}
12684
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012685void hdd_allow_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070012686{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012687
12688 vos_wake_lock_release(&wlan_wake_lock, reason);
12689
Jeff Johnson295189b2012-06-20 16:38:30 -070012690}
12691
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012692void hdd_prevent_suspend_timeout(v_U32_t timeout, uint32_t reason)
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070012693{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012694
12695 vos_wake_lock_timeout_release(&wlan_wake_lock, timeout,
12696 reason);
12697
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070012698}
12699
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053012700/**
12701 * hdd_get_feature_caps_cb() - Callback invoked from WDA
12702 * @cookie: to identify HDD request to firmware
12703 *
12704 * This function is invoked from WDA when feature capabilities response
12705 * is received from firmware.
12706 *
12707 * Return: None
12708 */
12709static void hdd_get_feature_caps_cb(void *cookie)
12710{
12711 struct hdd_request *request;
12712
12713 request = hdd_request_get(cookie);
12714 if (!request) {
12715 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Obsolete request"));
12716 return;
12717 }
12718
12719 pr_info("%s: Firmware feature capabilities received\n", __func__);
12720
12721 hdd_request_complete(request);
12722 hdd_request_put(request);
12723}
12724
12725/**
12726 * hdd_get_feature_caps() - Get features supported by firmware
12727 * @hdd_ctx: Pointer to HDD context
12728 *
12729 * This function uses request manager framework to get the feature
12730 * capabilities from firmware.
12731 *
12732 * Return: None
12733 */
12734static void hdd_get_feature_caps(hdd_context_t *hdd_ctx)
12735{
12736 VOS_STATUS status;
12737 void *cookie;
12738 int ret;
12739 struct hdd_request *request;
12740 static const struct hdd_request_params params = {
12741 .priv_size = 0,
12742 .timeout_ms = WLAN_WAIT_TIME_FEATURE_CAPS,
12743 };
12744 struct sir_feature_caps_params caps_params = {0};
12745
12746 request = hdd_request_alloc(&params);
12747 if (!request) {
12748 pr_err("%s: Request allocation failure\n", __func__);
12749 return;
12750 }
12751
12752 cookie = hdd_request_cookie(request);
12753 caps_params.user_data = cookie;
12754 caps_params.feature_caps_cb = hdd_get_feature_caps_cb;
12755
12756 status = sme_featureCapsExchange(&caps_params);
12757 if (status != VOS_STATUS_SUCCESS) {
12758 pr_err("%s: Unable to get feature caps\n", __func__);
12759 goto end;
12760 }
12761
12762 /* request was sent -- wait for the response */
12763 ret = hdd_request_wait_for_response(request);
12764 if (ret) {
12765 pr_err("%s: SME timeout while retrieving feature caps\n",
12766 __func__);
12767 goto end;
12768 }
12769
12770end:
12771 hdd_request_put(request);
12772}
12773
Jeff Johnson295189b2012-06-20 16:38:30 -070012774/**---------------------------------------------------------------------------
12775
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012776 \brief hdd_exchange_version_and_caps() - HDD function to exchange version and capability
12777 information between Host and Riva
12778
12779 This function gets reported version of FW
12780 It also finds the version of Riva headers used to compile the host
12781 It compares the above two and prints a warning if they are different
12782 It gets the SW and HW version string
12783 Finally, it exchanges capabilities between host and Riva i.e. host and riva exchange a msg
12784 indicating the features they support through a bitmap
12785
12786 \param - pHddCtx - Pointer to HDD context
12787
12788 \return - void
12789
12790 --------------------------------------------------------------------------*/
12791
12792void hdd_exchange_version_and_caps(hdd_context_t *pHddCtx)
12793{
12794
12795 tSirVersionType versionCompiled;
12796 tSirVersionType versionReported;
12797 tSirVersionString versionString;
12798 tANI_U8 fwFeatCapsMsgSupported = 0;
12799 VOS_STATUS vstatus;
12800
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080012801 memset(&versionCompiled, 0, sizeof(versionCompiled));
12802 memset(&versionReported, 0, sizeof(versionReported));
12803
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012804 /* retrieve and display WCNSS version information */
12805 do {
12806
12807 vstatus = sme_GetWcnssWlanCompiledVersion(pHddCtx->hHal,
12808 &versionCompiled);
12809 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12810 {
12811 hddLog(VOS_TRACE_LEVEL_FATAL,
12812 "%s: unable to retrieve WCNSS WLAN compiled version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012813 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012814 break;
12815 }
12816
12817 vstatus = sme_GetWcnssWlanReportedVersion(pHddCtx->hHal,
12818 &versionReported);
12819 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12820 {
12821 hddLog(VOS_TRACE_LEVEL_FATAL,
12822 "%s: unable to retrieve WCNSS WLAN reported version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012823 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012824 break;
12825 }
12826
12827 if ((versionCompiled.major != versionReported.major) ||
12828 (versionCompiled.minor != versionReported.minor) ||
12829 (versionCompiled.version != versionReported.version) ||
12830 (versionCompiled.revision != versionReported.revision))
12831 {
12832 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
12833 "Host expected %u.%u.%u.%u\n",
12834 WLAN_MODULE_NAME,
12835 (int)versionReported.major,
12836 (int)versionReported.minor,
12837 (int)versionReported.version,
12838 (int)versionReported.revision,
12839 (int)versionCompiled.major,
12840 (int)versionCompiled.minor,
12841 (int)versionCompiled.version,
12842 (int)versionCompiled.revision);
12843 }
12844 else
12845 {
12846 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
12847 WLAN_MODULE_NAME,
12848 (int)versionReported.major,
12849 (int)versionReported.minor,
12850 (int)versionReported.version,
12851 (int)versionReported.revision);
12852 }
12853
12854 vstatus = sme_GetWcnssSoftwareVersion(pHddCtx->hHal,
12855 versionString,
12856 sizeof(versionString));
12857 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12858 {
12859 hddLog(VOS_TRACE_LEVEL_FATAL,
12860 "%s: unable to retrieve WCNSS software version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012861 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012862 break;
12863 }
12864
12865 pr_info("%s: WCNSS software version %s\n",
12866 WLAN_MODULE_NAME, versionString);
Sushant Kaushik084f6592015-09-10 13:11:56 +053012867 vos_mem_copy(pHddCtx->fw_Version, versionString, sizeof(versionString));
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012868
12869 vstatus = sme_GetWcnssHardwareVersion(pHddCtx->hHal,
12870 versionString,
12871 sizeof(versionString));
12872 if (!VOS_IS_STATUS_SUCCESS(vstatus))
12873 {
12874 hddLog(VOS_TRACE_LEVEL_FATAL,
12875 "%s: unable to retrieve WCNSS hardware version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012876 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012877 break;
12878 }
12879
12880 pr_info("%s: WCNSS hardware version %s\n",
12881 WLAN_MODULE_NAME, versionString);
12882
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012883 /* 1.Check if FW version is greater than 0.1.1.0. Only then send host-FW capability exchange message
12884 2.Host-FW capability exchange message is only present on riva 1.1 so
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012885 send the message only if it the riva is 1.1
12886 minor numbers for different riva branches:
12887 0 -> (1.0)Mainline Build
12888 1 -> (1.1)Mainline Build
12889 2->(1.04) Stability Build
12890 */
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012891 if (((versionReported.major>0) || (versionReported.minor>1) ||
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012892 ((versionReported.minor>=1) && (versionReported.version>=1)))
12893 && ((versionReported.major == 1) && (versionReported.minor >= 1)))
12894 fwFeatCapsMsgSupported = 1;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070012895
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012896 if (fwFeatCapsMsgSupported)
Yathish9f22e662012-12-10 14:21:35 -080012897 {
12898#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
12899 if(!pHddCtx->cfg_ini->fEnableActiveModeOffload)
12900 sme_disableFeatureCapablity(WLANACTIVE_OFFLOAD);
12901#endif
Ravi Joshid2ca7c42013-07-23 08:37:49 -070012902 /* Indicate if IBSS heartbeat monitoring needs to be offloaded */
12903 if (!pHddCtx->cfg_ini->enableIbssHeartBeatOffload)
12904 {
12905 sme_disableFeatureCapablity(IBSS_HEARTBEAT_OFFLOAD);
12906 }
12907
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053012908 hdd_get_feature_caps(pHddCtx);
Yathish9f22e662012-12-10 14:21:35 -080012909 }
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070012910
12911 } while (0);
12912
12913}
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053012914
Neelansh Mittaledafed22014-09-04 18:54:39 +053012915void wlan_hdd_send_svc_nlink_msg(int type, void *data, int len)
12916{
12917 struct sk_buff *skb;
12918 struct nlmsghdr *nlh;
12919 tAniMsgHdr *ani_hdr;
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053012920 int flags = GFP_KERNEL;
Bhargav shah23c94942015-10-13 12:48:35 +053012921 void *nl_data = NULL;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012922
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053012923 if (in_interrupt() || irqs_disabled() || in_atomic())
12924 flags = GFP_ATOMIC;
12925
12926 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
Neelansh Mittaledafed22014-09-04 18:54:39 +053012927
12928 if(skb == NULL) {
12929 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12930 "%s: alloc_skb failed", __func__);
12931 return;
12932 }
12933
12934 nlh = (struct nlmsghdr *)skb->data;
12935 nlh->nlmsg_pid = 0; /* from kernel */
12936 nlh->nlmsg_flags = 0;
12937 nlh->nlmsg_seq = 0;
12938 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12939
12940 ani_hdr = NLMSG_DATA(nlh);
12941 ani_hdr->type = type;
12942
12943 switch(type) {
12944 case WLAN_SVC_SAP_RESTART_IND:
12945 ani_hdr->length = 0;
12946 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
12947 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr)));
12948 break;
Bhargav Shahd0715912015-10-01 18:17:37 +053012949 case WLAN_SVC_WLAN_TP_IND:
12950 ani_hdr->length = len;
12951 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)
12952 + len));
12953 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12954 memcpy(nl_data, data, len);
12955 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
12956 break;
Bhargav shah23c94942015-10-13 12:48:35 +053012957 case WLAN_MSG_RPS_ENABLE_IND:
12958 ani_hdr->length = len;
12959 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12960 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12961 memcpy(nl_data, data, len);
12962 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
12963 break;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012964 default:
12965 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12966 "Attempt to send unknown nlink message %d", type);
12967 kfree_skb(skb);
12968 return;
12969 }
12970
12971 nl_srv_bcast(skb);
12972
12973 return;
12974}
12975
Bhargav Shahd0715912015-10-01 18:17:37 +053012976/**
12977 * hdd_request_tcp_delack() - Find the Delack value based on RX packet
12978 * @pHddCtx: Valid Global HDD context pointer
12979 * @rx_packets: Number of RX packet in perticular time
12980 *
12981 * Based on the RX packet this function calculate next value of tcp delack.
12982 * This function compare rx packet value to high and low threshold limit.
12983 *
12984 * Return: void
12985 */
12986void hdd_request_tcp_delack(hdd_context_t *pHddCtx, uint64_t rx_packets)
12987{
12988 /* average of rx_packets and prev_rx is taken so that
12989 bus width doesnot fluctuate much */
12990 uint64_t temp_rx = (rx_packets + pHddCtx->prev_rx)/2;
Alok Kumarf3724462018-04-05 15:18:54 +053012991 enum wlan_tp_level next_rx_level = pHddCtx->cur_rx_level;
Neelansh Mittaledafed22014-09-04 18:54:39 +053012992
Bhargav Shahd0715912015-10-01 18:17:37 +053012993 pHddCtx->prev_rx = rx_packets;
12994 if (temp_rx > pHddCtx->cfg_ini->tcpDelAckThresholdHigh)
Alok Kumarf3724462018-04-05 15:18:54 +053012995 next_rx_level = WLAN_SVC_TP_HIGH;
Bhargav Shahd0715912015-10-01 18:17:37 +053012996 else if (temp_rx <= pHddCtx->cfg_ini->tcpDelAckThresholdLow)
Alok Kumarf3724462018-04-05 15:18:54 +053012997 next_rx_level = WLAN_SVC_TP_LOW;
Bhargav Shahd0715912015-10-01 18:17:37 +053012998
12999 hdd_set_delack_value(pHddCtx, next_rx_level);
13000}
13001
13002#define HDD_BW_GET_DIFF(x, y) ((x) >= (y) ? (x) - (y) : (ULONG_MAX - (y) + (x)))
13003
13004/**
13005 * hdd_tcp_delack_compute_function() - get link status
13006 * @priv: Valid Global HDD context pointer
13007 *
13008 * This function find number of RX packet during timer life span.
13009 * It request tcp delack with number of RX packet and re-configure delack timer
13010 * for tcpDelAckComputeInterval timer interval.
13011 *
13012 * Return: void
13013 */
13014void hdd_tcp_delack_compute_function(void *priv)
13015{
13016 hdd_context_t *pHddCtx = (hdd_context_t *)priv;
13017 hdd_adapter_t *pAdapter = NULL;
13018 v_U32_t rx_packets = 0;
13019 hdd_adapter_list_node_t *pAdapterNode = NULL;
13020 VOS_STATUS status = 0;
13021
13022 for (status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
13023 NULL != pAdapterNode && VOS_STATUS_SUCCESS == status;
13024 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pAdapterNode)) {
13025 if ((pAdapter = pAdapterNode->pAdapter) == NULL)
13026 continue;
13027
13028 rx_packets += HDD_BW_GET_DIFF(pAdapter->stats.rx_packets,
13029 pAdapter->prev_rx_packets);
13030 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
13031 }
13032
13033 hdd_request_tcp_delack(pHddCtx, rx_packets);
13034
13035 vos_timer_start(&pHddCtx->delack_timer,
13036 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
13037}
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070013038
13039/**---------------------------------------------------------------------------
13040
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013041 \brief hdd_is_5g_supported() - HDD function to know if hardware supports 5GHz
13042
13043 \param - pHddCtx - Pointer to the hdd context
13044
13045 \return - true if hardware supports 5GHz
13046
13047 --------------------------------------------------------------------------*/
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +053013048boolean hdd_is_5g_supported(hdd_context_t * pHddCtx)
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013049{
13050 /* If wcnss_wlan_iris_xo_mode() returns WCNSS_XO_48MHZ(1);
13051 * then hardware support 5Ghz.
13052 */
13053 if (WCNSS_XO_48MHZ == wcnss_wlan_iris_xo_mode())
13054 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053013055 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware supports 5Ghz", __func__);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013056 return true;
13057 }
13058 else
13059 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053013060 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware doesn't supports 5Ghz",
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013061 __func__);
13062 return false;
13063 }
13064}
13065
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013066/**---------------------------------------------------------------------------
13067
13068 \brief hdd_generate_iface_mac_addr_auto() - HDD Mac Interface Auto
13069 generate function
13070
13071 This is generate the random mac address for WLAN interface
13072
13073 \param - pHddCtx - Pointer to HDD context
13074 idx - Start interface index to get auto
13075 generated mac addr.
13076 mac_addr - Mac address
13077
13078 \return - 0 for success, < 0 for failure
13079
13080 --------------------------------------------------------------------------*/
13081
13082static int hdd_generate_iface_mac_addr_auto(hdd_context_t *pHddCtx,
13083 int idx, v_MACADDR_t mac_addr)
13084{
13085 int i;
13086 unsigned int serialno;
13087 serialno = wcnss_get_serial_number();
13088
13089 if (0 != serialno)
13090 {
13091 /* MAC address has 3 bytes of OUI so we have a maximum of 3
13092 bytes of the serial number that can be used to generate
13093 the other 3 bytes of the MAC address. Mask off all but
13094 the lower 3 bytes (this will also make sure we don't
13095 overflow in the next step) */
13096 serialno &= 0x00FFFFFF;
13097
13098 /* we need a unique address for each session */
13099 serialno *= VOS_MAX_CONCURRENCY_PERSONA;
13100
13101 /* autogen other Mac addresses */
13102 for (i = idx; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
13103 {
13104 /* start with the entire default address */
13105 pHddCtx->cfg_ini->intfMacAddr[i] = mac_addr;
13106 /* then replace the lower 3 bytes */
13107 pHddCtx->cfg_ini->intfMacAddr[i].bytes[3] = (serialno >> 16) & 0xFF;
13108 pHddCtx->cfg_ini->intfMacAddr[i].bytes[4] = (serialno >> 8) & 0xFF;
13109 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] = serialno & 0xFF;
13110
Nachiket Kukadede2e24f2017-09-25 16:24:27 +053013111 if (0 == memcmp(&pHddCtx->cfg_ini->intfMacAddr[i].bytes[0],
13112 &mac_addr.bytes[0], VOS_MAC_ADDR_SIZE))
13113 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] +=
13114 VOS_MAX_CONCURRENCY_PERSONA;
13115
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013116 serialno++;
13117 hddLog(VOS_TRACE_LEVEL_ERROR,
13118 "%s: Derived Mac Addr: "
13119 MAC_ADDRESS_STR, __func__,
13120 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[i].bytes));
13121 }
13122
13123 }
13124 else
13125 {
13126 hddLog(LOGE, FL("Failed to Get Serial NO"));
13127 return -1;
13128 }
13129 return 0;
13130}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013131
Katya Nigame7b69a82015-04-28 15:24:06 +053013132int wlan_hdd_mon_open(hdd_context_t *pHddCtx)
13133{
13134 VOS_STATUS status;
13135 v_CONTEXT_t pVosContext= NULL;
13136 hdd_adapter_t *pAdapter= NULL;
13137
13138 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
13139
13140 if (NULL == pVosContext)
13141 {
13142 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13143 "%s: Trying to open VOSS without a PreOpen", __func__);
13144 VOS_ASSERT(0);
13145 return VOS_STATUS_E_FAILURE;
13146 }
13147
13148 status = vos_nv_open();
13149 if (!VOS_IS_STATUS_SUCCESS(status))
13150 {
13151 /* NV module cannot be initialized */
13152 hddLog( VOS_TRACE_LEVEL_FATAL,
13153 "%s: vos_nv_open failed", __func__);
13154 return VOS_STATUS_E_FAILURE;
13155 }
13156
13157 status = vos_init_wiphy_from_nv_bin();
13158 if (!VOS_IS_STATUS_SUCCESS(status))
13159 {
13160 /* NV module cannot be initialized */
13161 hddLog( VOS_TRACE_LEVEL_FATAL,
13162 "%s: vos_init_wiphy failed", __func__);
13163 goto err_vos_nv_close;
13164 }
13165
13166 status = vos_open( &pVosContext, pHddCtx->parent_dev);
13167 if ( !VOS_IS_STATUS_SUCCESS( status ))
13168 {
13169 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
13170 goto err_vos_nv_close;
13171 }
13172
13173 status = vos_mon_start( pVosContext );
13174 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13175 {
13176 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
13177 goto err_vosclose;
13178 }
13179
13180 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053013181 sme_featureCapsExchange(NULL);
Katya Nigame7b69a82015-04-28 15:24:06 +053013182 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
13183
13184 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_MONITOR, "wlan%d",
13185 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
13186 if( pAdapter == NULL )
13187 {
13188 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
13189 goto err_close_adapter;
13190 }
13191
13192 //Initialize the nlink service
13193 if(nl_srv_init() != 0)
13194 {
13195 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
13196 goto err_close_adapter;
13197 }
13198 return VOS_STATUS_SUCCESS;
13199
13200err_close_adapter:
13201 hdd_close_all_adapters( pHddCtx );
13202 vos_mon_stop( pVosContext );
13203err_vosclose:
13204 status = vos_sched_close( pVosContext );
13205 if (!VOS_IS_STATUS_SUCCESS(status)) {
13206 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
13207 "%s: Failed to close VOSS Scheduler", __func__);
13208 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
13209 }
13210 vos_close(pVosContext );
13211
13212err_vos_nv_close:
13213 vos_nv_close();
13214
13215return status;
13216}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013217/**---------------------------------------------------------------------------
13218
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013219 \brief hdd_11d_scan_done - callback to be executed when 11d scan is
13220 completed to flush out the scan results
13221
13222 11d scan is done during driver load and is a passive scan on all
13223 channels supported by the device, 11d scans may find some APs on
13224 frequencies which are forbidden to be used in the regulatory domain
13225 the device is operating in. If these APs are notified to the supplicant
13226 it may try to connect to these APs, thus flush out all the scan results
13227 which are present in SME after 11d scan is done.
13228
13229 \return - eHalStatus
13230
13231 --------------------------------------------------------------------------*/
13232static eHalStatus hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
13233 tANI_U32 scanId, eCsrScanStatus status)
13234{
13235 ENTER();
13236
13237 sme_ScanFlushResult(halHandle, 0);
13238
13239 EXIT();
13240
13241 return eHAL_STATUS_SUCCESS;
13242}
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013243/**---------------------------------------------------------------------------
13244
13245 \brief hdd_init_frame_logging_done - callback to be executed when mgmt frame
13246 logging is completed successfully.
13247
13248 \return - None
13249
13250 --------------------------------------------------------------------------*/
c_manjeecfd1efb2015-09-25 19:32:34 +053013251void hdd_init_frame_logging_done(void *fwlogInitCbContext, tAniLoggingInitRsp *pRsp)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013252{
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013253 hdd_context_t* pHddCtx = (hdd_context_t*)fwlogInitCbContext;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013254
13255 if (NULL == pHddCtx)
13256 {
13257 hddLog(VOS_TRACE_LEVEL_ERROR,
13258 "%s: HDD context is NULL",__func__);
13259 return;
13260 }
13261
c_manjeecfd1efb2015-09-25 19:32:34 +053013262 if ((pRsp->status == VOS_STATUS_SUCCESS) &&
Mahesh A Saptasagarfabb1a02015-06-29 12:17:04 +053013263 (TRUE == pHddCtx->cfg_ini->enableMgmtLogging))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013264 {
13265 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init successful"));
13266 pHddCtx->mgmt_frame_logging = TRUE;
13267 }
13268 else
13269 {
13270 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init not success"));
13271 pHddCtx->mgmt_frame_logging = FALSE;
c_manjeecfd1efb2015-09-25 19:32:34 +053013272 return;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013273 }
13274
c_manjeecfd1efb2015-09-25 19:32:34 +053013275 /*Check feature supported by FW*/
13276 if(TRUE == sme_IsFeatureSupportedByFW(MEMORY_DUMP_SUPPORTED))
13277 {
13278 //Store fwr mem dump size given by firmware.
13279 wlan_store_fwr_mem_dump_size(pRsp->fw_mem_dump_max_size);
13280 }
13281 else
13282 {
13283 wlan_store_fwr_mem_dump_size(0);
13284 }
13285
13286
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013287}
13288/**---------------------------------------------------------------------------
13289
13290 \brief hdd_init_frame_logging - function to initialize frame logging.
13291 Currently only Mgmt Frames are logged in both TX
13292 and Rx direction and are sent to userspace
13293 application using logger thread when queried.
13294
13295 \return - None
13296
13297 --------------------------------------------------------------------------*/
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013298void hdd_init_frame_logging(hdd_context_t* pHddCtx)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013299{
13300 eHalStatus halStatus = eHAL_STATUS_FAILURE;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013301 tSirFWLoggingInitParam wlanFWLoggingInitParam = {0};
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013302
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013303 if (TRUE != sme_IsFeatureSupportedByFW(MGMT_FRAME_LOGGING) &&
13304 TRUE != sme_IsFeatureSupportedByFW(LOGGING_ENHANCEMENT))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013305 {
13306 hddLog(VOS_TRACE_LEVEL_INFO, FL("MGMT_FRAME_LOGGING not supp by FW"));
13307 return;
13308 }
13309
sheenam monga1a0202d2020-01-03 15:20:57 +053013310 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Configuring %s %s %s Logging",__func__,
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013311 pHddCtx->cfg_ini->enableFWLogging?"FW Log,":"",
13312 pHddCtx->cfg_ini->enableContFWLogging ? "Cont FW log,":"",
sheenam monga1a0202d2020-01-03 15:20:57 +053013313 pHddCtx->cfg_ini->enableMgmtLogging ? "Mgmt Pkt Log":"");
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013314
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013315 if (pHddCtx->cfg_ini->enableFWLogging ||
13316 pHddCtx->cfg_ini->enableContFWLogging)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013317 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013318 wlanFWLoggingInitParam.enableFlag |= WLAN_QXDM_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013319 }
13320
Sushant Kaushik46804902015-07-08 14:46:03 +053013321 if (pHddCtx->cfg_ini->enableMgmtLogging)
13322 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013323 wlanFWLoggingInitParam.enableFlag |= WLAN_FRAME_LOG_EN;
Sushant Kaushik46804902015-07-08 14:46:03 +053013324 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013325 if (pHddCtx->cfg_ini->enableBMUHWtracing)
13326 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013327 wlanFWLoggingInitParam.enableFlag |= WLAN_BMUHW_TRACE_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013328 }
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013329 if( wlanFWLoggingInitParam.enableFlag == 0 )
c_manjeecfd1efb2015-09-25 19:32:34 +053013330 {
13331 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Logging not enabled", __func__);
13332 return;
13333 }
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013334 wlanFWLoggingInitParam.frameType = WLAN_FRAME_LOGGING_FRAMETYPE_MGMT;
13335 wlanFWLoggingInitParam.frameSize = WLAN_MGMT_LOGGING_FRAMESIZE_128BYTES;
13336 wlanFWLoggingInitParam.bufferMode = WLAN_FRAME_LOGGING_BUFFERMODE_CIRCULAR;
13337 wlanFWLoggingInitParam.continuousFrameLogging =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013338 pHddCtx->cfg_ini->enableContFWLogging;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013339
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013340 wlanFWLoggingInitParam.enableFlag &= ~WLAN_DPU_TXP_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013341
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013342 wlanFWLoggingInitParam.minLogBufferSize =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013343 pHddCtx->cfg_ini->minLoggingBufferSize;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013344 wlanFWLoggingInitParam.maxLogBufferSize =
Siddharth Bhald1be97f2015-05-27 22:39:59 +053013345 pHddCtx->cfg_ini->maxLoggingBufferSize;
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013346 wlanFWLoggingInitParam.fwlogInitCallback = hdd_init_frame_logging_done;
13347 wlanFWLoggingInitParam.fwlogInitCbContext= pHddCtx;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013348
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013349 halStatus = sme_InitMgmtFrameLogging(pHddCtx->hHal, &wlanFWLoggingInitParam);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013350
13351 if (eHAL_STATUS_SUCCESS != halStatus)
13352 {
Sreelakshmi Konamkid8784d92016-04-14 14:59:13 +053013353 hddLog(LOGE, FL("sme_InitMgmtFrameLogging failed, returned %d"),
13354 halStatus);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053013355 }
13356
13357 return;
13358}
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013359
Bhargav shah23c94942015-10-13 12:48:35 +053013360static void hdd_dp_util_send_rps_ind(hdd_context_t *hdd_ctxt)
13361{
13362 hdd_adapter_t *adapter;
13363 hdd_adapter_list_node_t *adapter_node, *next;
13364 VOS_STATUS status = VOS_STATUS_SUCCESS;
13365 struct wlan_rps_data rps_data;
13366 int count;
13367
13368 if(!hdd_ctxt->cfg_ini->rps_mask)
13369 {
13370 return;
13371 }
13372
13373 for (count=0; count < WLAN_SVC_IFACE_NUM_QUEUES; count++)
13374 {
13375 rps_data.cpu_map[count] = hdd_ctxt->cfg_ini->rps_mask;
13376 }
13377
13378 rps_data.num_queues = WLAN_SVC_IFACE_NUM_QUEUES;
13379
13380 hddLog(LOG1, FL("0x%x 0x%x 0x%x 0x%x 0x%x 0x%x"),
13381 rps_data.cpu_map[0], rps_data.cpu_map[1],rps_data.cpu_map[2],
13382 rps_data.cpu_map[3], rps_data.cpu_map[4], rps_data.cpu_map[5]);
13383
13384 status = hdd_get_front_adapter (hdd_ctxt, &adapter_node);
13385
13386 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status)
13387 {
13388 adapter = adapter_node->pAdapter;
13389 if (NULL != adapter) {
13390 strlcpy(rps_data.ifname, adapter->dev->name,
13391 sizeof(rps_data.ifname));
13392 wlan_hdd_send_svc_nlink_msg(WLAN_MSG_RPS_ENABLE_IND,
13393 (void *)&rps_data,sizeof(rps_data));
13394 }
13395 status = hdd_get_next_adapter (hdd_ctxt, adapter_node, &next);
13396 adapter_node = next;
13397 }
13398}
13399
Masti, Narayanraddi26378462016-01-05 18:20:28 +053013400void wlan_hdd_schedule_defer_scan(struct work_struct *work)
13401{
13402 scan_context_t *scan_ctx =
13403 container_of(work, scan_context_t, scan_work.work);
13404
13405 if (NULL == scan_ctx)
13406 {
13407 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13408 FL("scan_ctx is NULL"));
13409 return;
13410 }
13411
13412 if (unlikely(TDLS_CTX_MAGIC != scan_ctx->magic))
13413 return;
13414
13415 scan_ctx->attempt++;
13416
13417 wlan_hdd_cfg80211_scan(scan_ctx->wiphy,
13418#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13419 scan_ctx->dev,
13420#endif
13421 scan_ctx->scan_request);
13422}
13423
13424int wlan_hdd_copy_defer_scan_context(hdd_context_t *pHddCtx,
13425 struct wiphy *wiphy,
13426#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13427 struct net_device *dev,
13428#endif
13429 struct cfg80211_scan_request *request)
13430{
13431 scan_context_t *scan_ctx;
13432
13433 ENTER();
13434 if (0 != (wlan_hdd_validate_context(pHddCtx)))
13435 {
13436 return -1;
13437 }
13438
13439 scan_ctx = &pHddCtx->scan_ctxt;
13440
13441 scan_ctx->wiphy = wiphy;
13442#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13443 scan_ctx->dev = dev;
13444#endif
13445
13446 scan_ctx->scan_request = request;
13447
13448 EXIT();
13449 return 0;
13450}
13451
13452void wlan_hdd_defer_scan_init_work(hdd_context_t *pHddCtx,
13453 struct wiphy *wiphy,
13454#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13455 struct net_device *dev,
13456#endif
13457 struct cfg80211_scan_request *request,
13458 unsigned long delay)
13459{
13460 if (TDLS_CTX_MAGIC != pHddCtx->scan_ctxt.magic)
13461 {
13462#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
13463 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, dev, request);
13464#else
13465 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, request);
13466#endif
13467 pHddCtx->scan_ctxt.attempt = 0;
13468 pHddCtx->scan_ctxt.magic = TDLS_CTX_MAGIC;
13469 }
13470 schedule_delayed_work(&pHddCtx->scan_ctxt.scan_work, delay);
13471}
13472
13473void wlan_hdd_init_deinit_defer_scan_context(scan_context_t *scan_ctx)
13474{
13475 scan_ctx->magic = 0;
13476 scan_ctx->attempt = 0;
13477 scan_ctx->reject = 0;
13478 scan_ctx->scan_request = NULL;
13479
13480 return;
13481}
13482
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053013483/**---------------------------------------------------------------------------
13484
Jeff Johnson295189b2012-06-20 16:38:30 -070013485 \brief hdd_wlan_startup() - HDD init function
13486
13487 This is the driver startup code executed once a WLAN device has been detected
13488
13489 \param - dev - Pointer to the underlying device
13490
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080013491 \return - 0 for success, < 0 for failure
Jeff Johnson295189b2012-06-20 16:38:30 -070013492
13493 --------------------------------------------------------------------------*/
13494
13495int hdd_wlan_startup(struct device *dev )
13496{
13497 VOS_STATUS status;
13498 hdd_adapter_t *pAdapter = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -070013499 hdd_adapter_t *pP2pAdapter = NULL;
Arunk Khandavalli95608be2019-01-22 13:12:54 +053013500 hdd_adapter_t *softapAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070013501 hdd_context_t *pHddCtx = NULL;
13502 v_CONTEXT_t pVosContext= NULL;
13503#ifdef WLAN_BTAMP_FEATURE
13504 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
13505 WLANBAP_ConfigType btAmpConfig;
13506 hdd_config_t *pConfig;
13507#endif
13508 int ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070013509 struct wiphy *wiphy;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013510 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -070013511
13512 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -070013513 /*
13514 * cfg80211: wiphy allocation
13515 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013516 wiphy = wlan_hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t)) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070013517
13518 if(wiphy == NULL)
13519 {
13520 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080013521 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070013522 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013523 pHddCtx = wiphy_priv(wiphy);
13524
Jeff Johnson295189b2012-06-20 16:38:30 -070013525 //Initialize the adapter context to zeros.
13526 vos_mem_zero(pHddCtx, sizeof( hdd_context_t ));
13527
Jeff Johnson295189b2012-06-20 16:38:30 -070013528 pHddCtx->wiphy = wiphy;
Sushant Kaushik83392fa2015-05-05 17:44:40 +053013529 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Mihir Shete18156292014-03-11 15:38:30 +053013530 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_LOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070013531
13532 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
13533
Siddharth Bhalcd92b782015-06-29 12:25:40 +053013534 /* register for riva power on lock to platform driver
13535 * Locking power early to ensure FW doesn't reset by kernel while
13536 * host driver is busy initializing itself */
13537 if (req_riva_power_on_lock("wlan"))
13538 {
13539 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: req riva power on lock failed",
13540 __func__);
13541 goto err_free_hdd_context;
13542 }
13543
Jeff Johnson295189b2012-06-20 16:38:30 -070013544 /*Get vos context here bcoz vos_open requires it*/
13545 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
13546
Madan Mohan Koyyalamudi0b78e152012-11-28 15:46:51 -080013547 if(pVosContext == NULL)
13548 {
13549 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed vos_get_global_context",__func__);
13550 goto err_free_hdd_context;
13551 }
13552
Jeff Johnson295189b2012-06-20 16:38:30 -070013553 //Save the Global VOSS context in adapter context for future.
13554 pHddCtx->pvosContext = pVosContext;
13555
13556 //Save the adapter context in global context for future.
13557 ((VosContextType*)(pVosContext))->pHDDContext = (v_VOID_t*)pHddCtx;
13558
Jeff Johnson295189b2012-06-20 16:38:30 -070013559 pHddCtx->parent_dev = dev;
Sreelakshmi Konamkif0646d52016-12-09 12:35:31 +053013560 pHddCtx->last_scan_reject_session_id = 0xFF;
13561 pHddCtx->last_scan_reject_reason = 0;
Sreelakshmi Konamki20ebed92016-10-27 12:13:30 +053013562 pHddCtx->last_scan_reject_timestamp = 0;
Abhishek Singhe4b12562017-06-20 16:53:39 +053013563 pHddCtx->scan_reject_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070013564
13565 init_completion(&pHddCtx->full_pwr_comp_var);
13566 init_completion(&pHddCtx->standby_comp_var);
13567 init_completion(&pHddCtx->req_bmps_comp_var);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070013568 init_completion(&pHddCtx->scan_info.scan_req_completion_event);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -080013569 init_completion(&pHddCtx->scan_info.abortscan_event_var);
Kiet Lam46b8e4e2013-11-06 21:49:53 +053013570 init_completion(&pHddCtx->wiphy_channel_update_event);
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053013571 init_completion(&pHddCtx->ssr_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053013572 init_completion(&pHddCtx->mc_sus_event_var);
13573 init_completion(&pHddCtx->tx_sus_event_var);
13574 init_completion(&pHddCtx->rx_sus_event_var);
13575
Amar Singhala49cbc52013-10-08 18:37:44 -070013576
mukul sharma4bd8d2e2015-08-13 20:33:25 +053013577 hdd_init_ll_stats_ctx(pHddCtx);
Anurag Chouhan6ee81542017-02-09 18:09:27 +053013578 hdd_init_nud_stats_ctx(pHddCtx);
mukul sharma4bd8d2e2015-08-13 20:33:25 +053013579
Amar Singhala49cbc52013-10-08 18:37:44 -070013580#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhalfddc28c2013-09-05 13:03:40 -070013581 init_completion(&pHddCtx->linux_reg_req);
Amar Singhala49cbc52013-10-08 18:37:44 -070013582#else
13583 init_completion(&pHddCtx->driver_crda_req);
13584#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013585
Padma, Santhosh Kumara1aa4a32015-06-19 19:00:46 +053013586#ifdef WLAN_FEATURE_EXTSCAN
13587 init_completion(&pHddCtx->ext_scan_context.response_event);
13588#endif /* WLAN_FEATURE_EXTSCAN */
13589
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053013590 spin_lock_init(&pHddCtx->schedScan_lock);
Kapil Gupta137ef892016-12-13 19:38:00 +053013591 vos_spin_lock_init(&pHddCtx->sap_update_info_lock);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053013592
Jeff Johnson295189b2012-06-20 16:38:30 -070013593 hdd_list_init( &pHddCtx->hddAdapters, MAX_NUMBER_OF_ADAPTERS );
13594
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053013595 vos_init_delayed_work(&pHddCtx->spoof_mac_addr_work,
13596 hdd_processSpoofMacAddrRequest);
Kapil Gupta137ef892016-12-13 19:38:00 +053013597 vos_init_work(&pHddCtx->sap_start_work, hdd_sap_restart_handle);
Abhishek Singh78c691f2017-11-30 13:48:44 +053013598 vos_init_delayed_work(&pHddCtx->ecsa_chan_change_work,
13599 hdd_force_scc_with_ecsa_handle);
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053013600
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053013601#ifdef FEATURE_WLAN_TDLS
13602 /* tdls_lock is initialized before an hdd_open_adapter ( which is
13603 * invoked by other instances also) to protect the concurrent
13604 * access for the Adapters by TDLS module.
13605 */
13606 mutex_init(&pHddCtx->tdls_lock);
13607#endif
Siddharth Bhal76972212014-10-15 16:22:51 +053013608 mutex_init(&pHddCtx->spoofMacAddr.macSpoofingLock);
Mukul Sharma1fd6efd2015-02-14 00:29:14 +053013609 mutex_init(&pHddCtx->wmmLock);
13610
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +053013611 hdd_init_offloaded_packets_ctx(pHddCtx);
Agarwal Ashish1f422872014-07-22 00:11:55 +053013612 /* By default Strict Regulatory For FCC should be false */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053013613
Agarwal Ashish1f422872014-07-22 00:11:55 +053013614 pHddCtx->nEnableStrictRegulatoryForFCC = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070013615 // Load all config first as TL config is needed during vos_open
13616 pHddCtx->cfg_ini = (hdd_config_t*) kmalloc(sizeof(hdd_config_t), GFP_KERNEL);
13617 if(pHddCtx->cfg_ini == NULL)
13618 {
13619 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed kmalloc hdd_config_t",__func__);
13620 goto err_free_hdd_context;
13621 }
13622
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053013623 hdd_request_manager_init();
13624
Jeff Johnson295189b2012-06-20 16:38:30 -070013625 vos_mem_zero(pHddCtx->cfg_ini, sizeof( hdd_config_t ));
13626
13627 // Read and parse the qcom_cfg.ini file
13628 status = hdd_parse_config_ini( pHddCtx );
13629 if ( VOS_STATUS_SUCCESS != status )
13630 {
13631 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: error parsing %s",
13632 __func__, WLAN_INI_FILE);
13633 goto err_config;
13634 }
Arif Hussaind5218912013-12-05 01:10:55 -080013635#ifdef MEMORY_DEBUG
13636 if (pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled)
13637 vos_mem_init();
13638
13639 hddLog(VOS_TRACE_LEVEL_INFO, "%s: gEnableMemoryDebug=%d",
13640 __func__, pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled);
13641#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013642
Gopichand Nakkalab8f0f1a2013-05-23 18:19:48 +053013643 /* INI has been read, initialise the configuredMcastBcastFilter with
13644 * INI value as this will serve as the default value
13645 */
13646 pHddCtx->configuredMcastBcastFilter = pHddCtx->cfg_ini->mcastBcastFilterSetting;
13647 hddLog(VOS_TRACE_LEVEL_INFO, "Setting configuredMcastBcastFilter: %d",
13648 pHddCtx->cfg_ini->mcastBcastFilterSetting);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053013649
13650 if (false == hdd_is_5g_supported(pHddCtx))
13651 {
13652 //5Ghz is not supported.
13653 if (1 != pHddCtx->cfg_ini->nBandCapability)
13654 {
13655 hddLog(VOS_TRACE_LEVEL_INFO,
13656 "%s: Setting pHddCtx->cfg_ini->nBandCapability = 1", __func__);
13657 pHddCtx->cfg_ini->nBandCapability = 1;
13658 }
13659 }
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +053013660
13661 /* If SNR Monitoring is enabled, FW has to parse all beacons
13662 * for calcaluting and storing the average SNR, so set Nth beacon
13663 * filter to 1 to enable FW to parse all the beaocons
13664 */
13665 if (1 == pHddCtx->cfg_ini->fEnableSNRMonitoring)
13666 {
13667 /* The log level is deliberately set to WARN as overriding
13668 * nthBeaconFilter to 1 will increase power cosumption and this
13669 * might just prove helpful to detect the power issue.
13670 */
13671 hddLog(VOS_TRACE_LEVEL_WARN,
13672 "%s: Setting pHddCtx->cfg_ini->nthBeaconFilter = 1", __func__);
13673 pHddCtx->cfg_ini->nthBeaconFilter = 1;
13674 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013675 /*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013676 * cfg80211: Initialization ...
Jeff Johnson295189b2012-06-20 16:38:30 -070013677 */
Manjeet Singh61016fa2016-12-02 11:10:19 +053013678 if (0 < wlan_hdd_cfg80211_init(dev, wiphy, pHddCtx->cfg_ini))
Jeff Johnson295189b2012-06-20 16:38:30 -070013679 {
Manjeet Singh61016fa2016-12-02 11:10:19 +053013680 hddLog(VOS_TRACE_LEVEL_FATAL,
13681 "%s: wlan_hdd_cfg80211_init return failure", __func__);
13682 goto err_config;
Jeff Johnson295189b2012-06-20 16:38:30 -070013683 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013684
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013685 // Update VOS trace levels based upon the cfg.ini
13686 hdd_vos_trace_enable(VOS_MODULE_ID_BAP,
13687 pHddCtx->cfg_ini->vosTraceEnableBAP);
13688 hdd_vos_trace_enable(VOS_MODULE_ID_TL,
13689 pHddCtx->cfg_ini->vosTraceEnableTL);
13690 hdd_vos_trace_enable(VOS_MODULE_ID_WDI,
13691 pHddCtx->cfg_ini->vosTraceEnableWDI);
13692 hdd_vos_trace_enable(VOS_MODULE_ID_HDD,
13693 pHddCtx->cfg_ini->vosTraceEnableHDD);
13694 hdd_vos_trace_enable(VOS_MODULE_ID_SME,
13695 pHddCtx->cfg_ini->vosTraceEnableSME);
13696 hdd_vos_trace_enable(VOS_MODULE_ID_PE,
13697 pHddCtx->cfg_ini->vosTraceEnablePE);
Katya Nigam70d68332013-09-16 16:49:45 +053013698 hdd_vos_trace_enable(VOS_MODULE_ID_PMC,
13699 pHddCtx->cfg_ini->vosTraceEnablePMC);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013700 hdd_vos_trace_enable(VOS_MODULE_ID_WDA,
13701 pHddCtx->cfg_ini->vosTraceEnableWDA);
13702 hdd_vos_trace_enable(VOS_MODULE_ID_SYS,
13703 pHddCtx->cfg_ini->vosTraceEnableSYS);
13704 hdd_vos_trace_enable(VOS_MODULE_ID_VOSS,
13705 pHddCtx->cfg_ini->vosTraceEnableVOSS);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013706 hdd_vos_trace_enable(VOS_MODULE_ID_SAP,
13707 pHddCtx->cfg_ini->vosTraceEnableSAP);
13708 hdd_vos_trace_enable(VOS_MODULE_ID_HDD_SOFTAP,
13709 pHddCtx->cfg_ini->vosTraceEnableHDDSAP);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080013710
Jeff Johnson295189b2012-06-20 16:38:30 -070013711 // Update WDI trace levels based upon the cfg.ini
13712 hdd_wdi_trace_enable(eWLAN_MODULE_DAL,
13713 pHddCtx->cfg_ini->wdiTraceEnableDAL);
13714 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_CTRL,
13715 pHddCtx->cfg_ini->wdiTraceEnableCTL);
13716 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_DATA,
13717 pHddCtx->cfg_ini->wdiTraceEnableDAT);
13718 hdd_wdi_trace_enable(eWLAN_MODULE_PAL,
13719 pHddCtx->cfg_ini->wdiTraceEnablePAL);
Jeff Johnson295189b2012-06-20 16:38:30 -070013720
Jeff Johnson88ba7742013-02-27 14:36:02 -080013721 if (VOS_FTM_MODE == hdd_get_conparam())
13722 {
Jeff Johnson295189b2012-06-20 16:38:30 -070013723 if ( VOS_STATUS_SUCCESS != wlan_hdd_ftm_open(pHddCtx) )
13724 {
13725 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_ftm_open Failed",__func__);
13726 goto err_free_hdd_context;
13727 }
13728 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: FTM driver loaded success fully",__func__);
Sachin Ahuja38ef5e02015-03-13 17:31:16 +053013729 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
c_hpothu2de0ef62014-04-15 16:16:15 +053013730 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -070013731 return VOS_STATUS_SUCCESS;
Jeff Johnson88ba7742013-02-27 14:36:02 -080013732 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013733
Katya Nigame7b69a82015-04-28 15:24:06 +053013734 if( VOS_MONITOR_MODE == hdd_get_conparam())
13735 {
13736 if ( VOS_STATUS_SUCCESS != wlan_hdd_mon_open(pHddCtx))
13737 {
13738 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_mon_open Failed",__func__);
13739 goto err_free_hdd_context;
13740 }
13741 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Driver loaded in Monitor Mode",__func__);
13742 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
13743 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
13744 return VOS_STATUS_SUCCESS;
13745 }
13746
Jeff Johnson88ba7742013-02-27 14:36:02 -080013747 //Open watchdog module
Jeff Johnson295189b2012-06-20 16:38:30 -070013748 if(pHddCtx->cfg_ini->fIsLogpEnabled)
13749 {
13750 status = vos_watchdog_open(pVosContext,
13751 &((VosContextType*)pVosContext)->vosWatchdog, sizeof(VosWatchdogContext));
13752
13753 if(!VOS_IS_STATUS_SUCCESS( status ))
13754 {
13755 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_watchdog_open failed",__func__);
Ashish Kumar Dhanotiya532bdef2017-05-09 17:31:59 +053013756 goto err_config;
Jeff Johnson295189b2012-06-20 16:38:30 -070013757 }
13758 }
13759
13760 pHddCtx->isLogpInProgress = FALSE;
13761 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
13762
Amar Singhala49cbc52013-10-08 18:37:44 -070013763#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070013764 /* initialize the NV module. This is required so that
13765 we can initialize the channel information in wiphy
13766 from the NV.bin data. The channel information in
13767 wiphy needs to be initialized before wiphy registration */
13768
13769 status = vos_nv_open();
13770 if (!VOS_IS_STATUS_SUCCESS(status))
13771 {
13772 /* NV module cannot be initialized */
13773 hddLog( VOS_TRACE_LEVEL_FATAL,
13774 "%s: vos_nv_open failed", __func__);
Vinay Krishna Eranna2025d892014-09-18 16:51:42 +053013775 goto err_wdclose;
Amar Singhal0a402232013-10-11 20:57:16 -070013776 }
13777
13778 status = vos_init_wiphy_from_nv_bin();
13779 if (!VOS_IS_STATUS_SUCCESS(status))
13780 {
13781 /* NV module cannot be initialized */
13782 hddLog( VOS_TRACE_LEVEL_FATAL,
13783 "%s: vos_init_wiphy failed", __func__);
13784 goto err_vos_nv_close;
13785 }
13786
Amar Singhala49cbc52013-10-08 18:37:44 -070013787#endif
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013788 //Initialize the nlink service
13789 if(nl_srv_init() != 0)
13790 {
13791 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
13792 goto err_vos_nv_close;
13793 }
13794
13795#ifdef WLAN_KD_READY_NOTIFIER
13796 pHddCtx->kd_nl_init = 1;
13797#endif /* WLAN_KD_READY_NOTIFIER */
13798
Girish Gowlibf0e1ab2015-01-19 16:05:16 +053013799 vos_set_roam_delay_stats_enabled(pHddCtx->cfg_ini->gEnableRoamDelayStats);
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053013800 status = vos_open( &pVosContext, pHddCtx->parent_dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070013801 if ( !VOS_IS_STATUS_SUCCESS( status ))
13802 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013803 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053013804 goto err_nl_srv;
Jeff Johnson295189b2012-06-20 16:38:30 -070013805 }
13806
Jeff Johnson295189b2012-06-20 16:38:30 -070013807 pHddCtx->hHal = (tHalHandle)vos_get_context( VOS_MODULE_ID_SME, pVosContext );
13808
13809 if ( NULL == pHddCtx->hHal )
13810 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013811 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: HAL context is null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070013812 goto err_vosclose;
13813 }
13814
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013815 status = vos_preStart( pHddCtx->pvosContext );
13816 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13817 {
13818 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_preStart failed", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013819 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013820 }
Jeff Johnsone7245742012-09-05 17:12:55 -070013821
Arif Hussaineaf68602013-12-30 23:10:44 -080013822 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan)
13823 {
13824 pHddCtx->cfg_ini->enableDFSChnlScan = enable_dfs_chan_scan;
13825 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_dfs_chan_scan set to %d",
13826 __func__, enable_dfs_chan_scan);
13827 }
13828 if (0 == enable_11d || 1 == enable_11d)
13829 {
13830 pHddCtx->cfg_ini->Is11dSupportEnabled = enable_11d;
13831 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_11d set to %d",
13832 __func__, enable_11d);
13833 }
13834
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013835 /* Note that the vos_preStart() sequence triggers the cfg download.
13836 The cfg download must occur before we update the SME config
13837 since the SME config operation must access the cfg database */
Jeff Johnson295189b2012-06-20 16:38:30 -070013838 status = hdd_set_sme_config( pHddCtx );
13839
13840 if ( VOS_STATUS_SUCCESS != status )
13841 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013842 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed hdd_set_sme_config", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013843 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013844 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013845
Jeff Johnson295189b2012-06-20 16:38:30 -070013846 /* In the integrated architecture we update the configuration from
13847 the INI file and from NV before vOSS has been started so that
13848 the final contents are available to send down to the cCPU */
13849
13850 // Apply the cfg.ini to cfg.dat
13851 if (FALSE == hdd_update_config_dat(pHddCtx))
13852 {
13853 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013854 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013855 }
13856
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013857 // Get mac addr from platform driver
13858 ret = wcnss_get_wlan_mac_address((char*)&mac_addr.bytes);
13859
13860 if ((0 == ret) && (!vos_is_macaddr_zero(&mac_addr)))
Jeff Johnson295189b2012-06-20 16:38:30 -070013861 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013862 /* Store the mac addr for first interface */
13863 pHddCtx->cfg_ini->intfMacAddr[0] = mac_addr;
13864
13865 hddLog(VOS_TRACE_LEVEL_ERROR,
13866 "%s: WLAN Mac Addr: "
13867 MAC_ADDRESS_STR, __func__,
13868 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
13869
13870 /* Here, passing Arg2 as 1 because we do not want to change the
13871 last 3 bytes (means non OUI bytes) of first interface mac
13872 addr.
13873 */
13874 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 1, mac_addr))
13875 {
13876 hddLog(VOS_TRACE_LEVEL_ERROR,
13877 "%s: Failed to generate wlan interface mac addr "
13878 "using MAC from ini file ", __func__);
13879 }
13880 }
13881 else if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
13882 {
13883 // Apply the NV to cfg.dat
13884 /* Prima Update MAC address only at here */
Jeff Johnson295189b2012-06-20 16:38:30 -070013885#ifdef WLAN_AUTOGEN_MACADDR_FEATURE
13886 /* There was not a valid set of MAC Addresses in NV. See if the
13887 default addresses were modified by the cfg.ini settings. If so,
13888 we'll use them, but if not, we'll autogenerate a set of MAC
13889 addresses based upon the device serial number */
13890
13891 static const v_MACADDR_t default_address =
13892 {{0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}};
Jeff Johnson295189b2012-06-20 16:38:30 -070013893
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013894 if (0 == memcmp(&default_address, &pHddCtx->cfg_ini->intfMacAddr[0],
13895 sizeof(default_address)))
Jeff Johnson295189b2012-06-20 16:38:30 -070013896 {
13897 /* cfg.ini has the default address, invoke autogen logic */
13898
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013899 /* Here, passing Arg2 as 0 because we want to change the
13900 last 3 bytes (means non OUI bytes) of all the interfaces
13901 mac addr.
13902 */
13903 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 0,
13904 default_address))
Jeff Johnson295189b2012-06-20 16:38:30 -070013905 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013906 hddLog(VOS_TRACE_LEVEL_ERROR,
13907 "%s: Failed to generate wlan interface mac addr "
13908 "using MAC from ini file " MAC_ADDRESS_STR, __func__,
13909 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
Jeff Johnson295189b2012-06-20 16:38:30 -070013910 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013911 }
13912 else
13913#endif //WLAN_AUTOGEN_MACADDR_FEATURE
13914 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080013915 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -070013916 "%s: Invalid MAC address in NV, using MAC from ini file "
13917 MAC_ADDRESS_STR, __func__,
13918 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
13919 }
13920 }
13921 {
13922 eHalStatus halStatus;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013923
13924 /* Set the MAC Address Currently this is used by HAL to
13925 * add self sta. Remove this once self sta is added as
13926 * part of session open.
13927 */
Jeff Johnson295189b2012-06-20 16:38:30 -070013928 halStatus = cfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
13929 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
13930 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]) );
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053013931
Jeff Johnson295189b2012-06-20 16:38:30 -070013932 if (!HAL_STATUS_SUCCESS( halStatus ))
13933 {
13934 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
13935 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013936 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013937 }
13938 }
Jeff Johnson295189b2012-06-20 16:38:30 -070013939
13940 /*Start VOSS which starts up the SME/MAC/HAL modules and everything else
13941 Note: Firmware image will be read and downloaded inside vos_start API */
13942 status = vos_start( pHddCtx->pvosContext );
13943 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13944 {
13945 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053013946 if (isSsrPanicOnFailure())
13947 VOS_BUG(0);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013948 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070013949 }
13950
Leo Chang6cec3e22014-01-21 15:33:49 -080013951#ifdef FEATURE_WLAN_CH_AVOID
13952 /* Plug in avoid channel notification callback
13953 * This should happen before ADD_SELF_STA
13954 * FW will send first IND with ADD_SELF_STA REQ from host */
Pradeep Reddy POTTETI5c2e16d2014-06-27 16:47:38 +053013955
13956 /* check the Channel Avoidance is enabled */
13957 if (TRUE == pHddCtx->cfg_ini->fenableCHAvoidance)
13958 {
13959 sme_AddChAvoidCallback(pHddCtx->hHal,
13960 hdd_hostapd_ch_avoid_cb);
13961 }
Leo Chang6cec3e22014-01-21 15:33:49 -080013962#endif /* FEATURE_WLAN_CH_AVOID */
13963
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070013964 /* Exchange capability info between Host and FW and also get versioning info from FW */
13965 hdd_exchange_version_and_caps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070013966
Agarwal Ashishad9281b2014-06-10 14:57:30 +053013967#ifdef CONFIG_ENABLE_LINUX_REG
13968 status = wlan_hdd_init_channels(pHddCtx);
13969 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13970 {
13971 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels failed",
13972 __func__);
13973 goto err_vosstop;
13974 }
13975#endif
13976
Jeff Johnson295189b2012-06-20 16:38:30 -070013977 status = hdd_post_voss_start_config( pHddCtx );
13978 if ( !VOS_IS_STATUS_SUCCESS( status ) )
13979 {
13980 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_post_voss_start_config failed",
13981 __func__);
13982 goto err_vosstop;
13983 }
Amar Singhala49cbc52013-10-08 18:37:44 -070013984
Rajeev Kumar Sirasanagandla2bb30b82019-01-07 22:30:16 +053013985 wlan_hdd_cfg80211_scan_randomization_init(wiphy);
13986
Amar Singhala49cbc52013-10-08 18:37:44 -070013987#ifndef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053013988 wlan_hdd_cfg80211_update_reg_info( wiphy );
13989
13990 /* registration of wiphy dev with cfg80211 */
13991 if (0 > wlan_hdd_cfg80211_register(wiphy))
13992 {
13993 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
13994 goto err_vosstop;
13995 }
Amar Singhala49cbc52013-10-08 18:37:44 -070013996#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070013997
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013998#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013999 /* registration of wiphy dev with cfg80211 */
14000 if (0 > wlan_hdd_cfg80211_register(wiphy))
14001 {
14002 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
14003 goto err_vosstop;
14004 }
14005
Agarwal Ashish6db9d532014-09-30 18:19:10 +053014006 status = wlan_hdd_init_channels_for_cc(pHddCtx, INIT);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053014007 if ( !VOS_IS_STATUS_SUCCESS( status ) )
14008 {
14009 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels_for_cc failed",
14010 __func__);
14011 goto err_unregister_wiphy;
14012 }
14013#endif
14014
c_hpothu4a298be2014-12-22 21:12:51 +053014015 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
14016
Rajeev Kumar Sirasanagandla4c068d42019-02-22 21:39:36 +053014017#ifdef SAP_AUTH_OFFLOAD
14018 if (!sme_IsFeatureSupportedByFW(SAP_OFFLOADS))
14019 {
14020 hddLog(VOS_TRACE_LEVEL_INFO, FL(" SAP AUTH OFFLOAD not supp by FW"));
14021 pHddCtx->cfg_ini->enable_sap_auth_offload = 0;
14022 }
14023#endif
14024
Jeff Johnson295189b2012-06-20 16:38:30 -070014025 if (VOS_STA_SAP_MODE == hdd_get_conparam())
14026 {
14027 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP, "softap.%d",
14028 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
14029 }
14030 else
14031 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014032 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_INFRA_STATION, "wlan%d",
14033 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
14034 if (pAdapter != NULL)
14035 {
Katya Nigama7d81d72014-11-12 12:44:34 +053014036 if (pHddCtx->cfg_ini->isP2pDeviceAddrAdministrated && !(pHddCtx->cfg_ini->intfMacAddr[0].bytes[0] & 0x02))
Jeff Johnson295189b2012-06-20 16:38:30 -070014037 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053014038 vos_mem_copy( pHddCtx->p2pDeviceAddress.bytes,
14039 pHddCtx->cfg_ini->intfMacAddr[0].bytes,
14040 sizeof(tSirMacAddr));
Madan Mohan Koyyalamudiedfc1b72012-10-18 20:25:55 -070014041
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053014042 /* Generate the P2P Device Address. This consists of the device's
14043 * primary MAC address with the locally administered bit set.
14044 */
14045 pHddCtx->p2pDeviceAddress.bytes[0] |= 0x02;
Jeff Johnsone7245742012-09-05 17:12:55 -070014046 }
14047 else
14048 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053014049 tANI_U8* p2p_dev_addr = wlan_hdd_get_intf_addr(pHddCtx);
14050 if (p2p_dev_addr != NULL)
14051 {
14052 vos_mem_copy(&pHddCtx->p2pDeviceAddress.bytes[0],
14053 p2p_dev_addr, VOS_MAC_ADDR_SIZE);
14054 }
14055 else
14056 {
14057 hddLog(VOS_TRACE_LEVEL_FATAL,
14058 "%s: Failed to allocate mac_address for p2p_device",
14059 __func__);
14060 goto err_close_adapter;
14061 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014062 }
Jeff Johnsone7245742012-09-05 17:12:55 -070014063
14064 pP2pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_P2P_DEVICE, "p2p%d",
14065 &pHddCtx->p2pDeviceAddress.bytes[0], FALSE );
14066 if ( NULL == pP2pAdapter )
14067 {
14068 hddLog(VOS_TRACE_LEVEL_FATAL,
14069 "%s: Failed to do hdd_open_adapter for P2P Device Interface",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070014070 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070014071 goto err_close_adapter;
14072 }
Jeff Johnsone7245742012-09-05 17:12:55 -070014073 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014074 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014075
14076 if( pAdapter == NULL )
14077 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080014078 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
14079 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070014080 }
Jeff Johnsone7245742012-09-05 17:12:55 -070014081
Ashish Kumar Dhanotiya3ac85a22019-02-12 19:10:14 +053014082 if ((strlen(pHddCtx->cfg_ini->enabledefaultSAP) != 0) &&
14083 (strcmp(pHddCtx->cfg_ini->enabledefaultSAP, "") != 0)) {
Arunk Khandavalli95608be2019-01-22 13:12:54 +053014084 softapAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP,
14085 pHddCtx->cfg_ini->enabledefaultSAP,
14086 wlan_hdd_get_intf_addr(pHddCtx), FALSE);
14087 if (!softapAdapter) {
14088 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
14089 goto err_close_adapter;
14090 }
14091 }
14092
Arif Hussain66559122013-11-21 10:11:40 -080014093 if (country_code)
14094 {
14095 eHalStatus ret;
Arif Hussaincb607082013-12-20 11:57:42 -080014096 INIT_COMPLETION(pAdapter->change_country_code);
Arif Hussain66559122013-11-21 10:11:40 -080014097 hdd_checkandupdate_dfssetting(pAdapter, country_code);
14098#ifndef CONFIG_ENABLE_LINUX_REG
14099 hdd_checkandupdate_phymode(pAdapter, country_code);
14100#endif
Arif Hussaineaf68602013-12-30 23:10:44 -080014101 ret = sme_ChangeCountryCode(pHddCtx->hHal,
14102 (void *)(tSmeChangeCountryCallback)
14103 wlan_hdd_change_country_code_callback,
Arif Hussain66559122013-11-21 10:11:40 -080014104 country_code,
14105 pAdapter, pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +053014106 eSIR_TRUE, eSIR_TRUE);
Arif Hussain66559122013-11-21 10:11:40 -080014107 if (eHAL_STATUS_SUCCESS == ret)
14108 {
Arif Hussaincb607082013-12-20 11:57:42 -080014109 ret = wait_for_completion_interruptible_timeout(
14110 &pAdapter->change_country_code,
14111 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
14112
14113 if (0 >= ret)
14114 {
14115 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14116 "%s: SME while setting country code timed out", __func__);
14117 }
Arif Hussain66559122013-11-21 10:11:40 -080014118 }
14119 else
14120 {
Arif Hussaincb607082013-12-20 11:57:42 -080014121 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14122 "%s: SME Change Country code from module param fail ret=%d",
14123 __func__, ret);
Arif Hussain66559122013-11-21 10:11:40 -080014124 }
14125 }
14126
Jeff Johnson295189b2012-06-20 16:38:30 -070014127#ifdef WLAN_BTAMP_FEATURE
14128 vStatus = WLANBAP_Open(pVosContext);
14129 if(!VOS_IS_STATUS_SUCCESS(vStatus))
14130 {
14131 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14132 "%s: Failed to open BAP",__func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070014133 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070014134 }
14135
14136 vStatus = BSL_Init(pVosContext);
14137 if(!VOS_IS_STATUS_SUCCESS(vStatus))
14138 {
14139 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14140 "%s: Failed to Init BSL",__func__);
14141 goto err_bap_close;
14142 }
14143 vStatus = WLANBAP_Start(pVosContext);
14144 if (!VOS_IS_STATUS_SUCCESS(vStatus))
14145 {
14146 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14147 "%s: Failed to start TL",__func__);
14148 goto err_bap_close;
14149 }
14150
14151 pConfig = pHddCtx->cfg_ini;
14152 btAmpConfig.ucPreferredChannel = pConfig->preferredChannel;
14153 status = WLANBAP_SetConfig(&btAmpConfig);
14154
14155#endif //WLAN_BTAMP_FEATURE
Jeff Johnsone7245742012-09-05 17:12:55 -070014156
Mihir Shete9c238772014-10-15 14:35:16 +053014157 /*
14158 * UapsdMask is 0xf if U-APSD is enbaled for all AC's...
14159 * The value of CFG_QOS_WMM_UAPSD_MASK_DEFAULT is 0xaa(Magic Value)
14160 * which is greater than 0xf. So the below check is safe to make
14161 * sure that there is no entry for UapsdMask in the ini
14162 */
14163 if (CFG_QOS_WMM_UAPSD_MASK_DEFAULT == pHddCtx->cfg_ini->UapsdMask)
14164 {
14165 if(IS_DYNAMIC_WMM_PS_ENABLED)
14166 {
14167 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Enable UAPSD for VI & VO",
14168 __func__);
14169 pHddCtx->cfg_ini->UapsdMask =
14170 CFG_QOS_WMM_UAPSD_MASK_DYMANIC_WMM_PS_DEFAULT;
14171 }
14172 else
14173 {
14174 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Do not enable UAPSD",
14175 __func__);
14176 pHddCtx->cfg_ini->UapsdMask =
14177 CFG_QOS_WMM_UAPSD_MASK_LEGACY_WMM_PS_DEFAULT;
14178 }
14179 }
14180
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -070014181#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
14182 if(!(IS_ROAM_SCAN_OFFLOAD_FEATURE_ENABLE))
14183 {
14184 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: ROAM_SCAN_OFFLOAD Feature not supported",__func__);
14185 pHddCtx->cfg_ini->isRoamOffloadScanEnabled = 0;
14186 sme_UpdateRoamScanOffloadEnabled((tHalHandle)(pHddCtx->hHal),
14187 pHddCtx->cfg_ini->isRoamOffloadScanEnabled);
14188 }
14189#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014190
Agarwal Ashish4b87f922014-06-18 03:03:21 +053014191 wlan_hdd_tdls_init(pHddCtx);
14192
Masti, Narayanraddi26378462016-01-05 18:20:28 +053014193 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
14194
14195 vos_init_delayed_work(&pHddCtx->scan_ctxt.scan_work,
14196 wlan_hdd_schedule_defer_scan);
14197
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053014198 sme_Register11dScanDoneCallback(pHddCtx->hHal, hdd_11d_scan_done);
14199
Jeff Johnson295189b2012-06-20 16:38:30 -070014200 /* Register with platform driver as client for Suspend/Resume */
14201 status = hddRegisterPmOps(pHddCtx);
14202 if ( !VOS_IS_STATUS_SUCCESS( status ) )
14203 {
14204 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddRegisterPmOps failed",__func__);
14205#ifdef WLAN_BTAMP_FEATURE
14206 goto err_bap_stop;
14207#else
Jeff Johnsone7245742012-09-05 17:12:55 -070014208 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070014209#endif //WLAN_BTAMP_FEATURE
14210 }
14211
Yue Ma0d4891e2013-08-06 17:01:45 -070014212 /* Open debugfs interface */
14213 if (VOS_STATUS_SUCCESS != hdd_debugfs_init(pAdapter))
14214 {
14215 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
14216 "%s: hdd_debugfs_init failed!", __func__);
Yue Ma0d4891e2013-08-06 17:01:45 -070014217 }
14218
Jeff Johnson295189b2012-06-20 16:38:30 -070014219 /* Register TM level change handler function to the platform */
14220 status = hddDevTmRegisterNotifyCallback(pHddCtx);
14221 if ( !VOS_IS_STATUS_SUCCESS( status ) )
14222 {
14223 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmRegisterNotifyCallback failed",__func__);
14224 goto err_unregister_pmops;
14225 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014226
Jeff Johnson295189b2012-06-20 16:38:30 -070014227 // register net device notifier for device change notification
14228 ret = register_netdevice_notifier(&hdd_netdev_notifier);
14229
14230 if(ret < 0)
14231 {
14232 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: register_netdevice_notifier failed",__func__);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053014233 goto err_unregister_pmops;
Jeff Johnson295189b2012-06-20 16:38:30 -070014234 }
14235
Jeff Johnson295189b2012-06-20 16:38:30 -070014236 //Initialize the BTC service
14237 if(btc_activate_service(pHddCtx) != 0)
14238 {
14239 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: btc_activate_service failed",__func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053014240 goto err_reg_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -070014241 }
14242
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053014243#ifdef FEATURE_OEM_DATA_SUPPORT
14244 //Initialize the OEM service
14245 if (oem_activate_service(pHddCtx) != 0)
14246 {
14247 hddLog(VOS_TRACE_LEVEL_FATAL,
14248 "%s: oem_activate_service failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014249 goto err_btc_activate_service;
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053014250 }
14251#endif
14252
Jeff Johnson295189b2012-06-20 16:38:30 -070014253#ifdef PTT_SOCK_SVC_ENABLE
14254 //Initialize the PTT service
14255 if(ptt_sock_activate_svc(pHddCtx) != 0)
14256 {
14257 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: ptt_sock_activate_svc failed",__func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014258 goto err_oem_activate_service;
Jeff Johnson295189b2012-06-20 16:38:30 -070014259 }
14260#endif
14261
Abhishek Singh00b71972016-01-07 10:51:04 +053014262#ifdef WLAN_FEATURE_RMC
14263 if (hdd_open_cesium_nl_sock() < 0)
14264 {
14265 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_open_cesium_nl_sock failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014266 goto err_ptt_sock_activate_svc;
Abhishek Singh00b71972016-01-07 10:51:04 +053014267 }
14268#endif
14269
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014270#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14271 if(pHddCtx->cfg_ini && pHddCtx->cfg_ini->wlanLoggingEnable)
14272 {
Deepthi Gowri78083a32014-11-04 12:55:51 +053014273 if(wlan_logging_sock_activate_svc(
14274 pHddCtx->cfg_ini->wlanLoggingFEToConsole,
Sushant Kaushik33200572015-08-05 16:46:20 +053014275 pHddCtx->cfg_ini->wlanLoggingNumBuf,
14276 pHddCtx->cfg_ini->wlanPerPktStatsLogEnable,
14277 pHddCtx->cfg_ini->wlanPerPktStatsNumBuf))
Deepthi Gowri78083a32014-11-04 12:55:51 +053014278 {
14279 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wlan_logging_sock_activate_svc"
14280 " failed", __func__);
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014281 goto err_open_cesium_nl_sock;
Deepthi Gowri78083a32014-11-04 12:55:51 +053014282 }
14283 //TODO: To Remove enableDhcpDebug and use gEnableDebugLog for
14284 //EAPOL and DHCP
Sachin Ahuja8c65f382014-12-12 15:34:21 +053014285 if (!pHddCtx->cfg_ini->gEnableDebugLog)
14286 pHddCtx->cfg_ini->gEnableDebugLog =
Sushant Kaushik6e4e2bc2015-10-05 17:23:07 +053014287 VOS_PKT_PROTO_TYPE_EAPOL | VOS_PKT_PROTO_TYPE_DHCP |
14288 VOS_PKT_PROTO_TYPE_ARP;
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014289 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014290
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014291 if (pHddCtx->cfg_ini->wlanLoggingEnable &&
14292 (pHddCtx->cfg_ini->enableFWLogging ||
Siddharth Bhaldb963232015-06-25 19:34:35 +053014293 pHddCtx->cfg_ini->enableMgmtLogging ||
sheenam monga1a0202d2020-01-03 15:20:57 +053014294 pHddCtx->cfg_ini->enableContFWLogging))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014295 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014296 hdd_init_frame_logging(pHddCtx);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014297 }
14298 else
14299 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053014300 hddLog(VOS_TRACE_LEVEL_INFO, FL("Logging disabled in ini"));
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014301 }
14302
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053014303#endif
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053014304
Sushant Kaushik215778f2015-05-21 14:05:36 +053014305 if (vos_is_multicast_logging())
14306 wlan_logging_set_log_level();
14307
Jeff Johnson295189b2012-06-20 16:38:30 -070014308 hdd_register_mcast_bcast_filter(pHddCtx);
Bala Venkateshe65810a2019-02-18 20:32:36 +053014309
14310 /* Action frame registered in one adapter which will
14311 * applicable to all interfaces
14312 */
14313 wlan_hdd_cfg80211_register_frames(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070014314
14315 mutex_init(&pHddCtx->sap_lock);
Mahesh A Saptasagar60627942014-10-13 13:55:14 +053014316 mutex_init(&pHddCtx->roc_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070014317
Jeff Johnsone7245742012-09-05 17:12:55 -070014318#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
14319 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014320 vos_wake_lock_init(&pHddCtx->rx_wake_lock,
Jeff Johnsone7245742012-09-05 17:12:55 -070014321 "qcom_rx_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014322
Jeff Johnsone7245742012-09-05 17:12:55 -070014323#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080014324 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014325 vos_wake_lock_init(&pHddCtx->sap_wake_lock,
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080014326 "qcom_sap_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014327
Jeff Johnsone7245742012-09-05 17:12:55 -070014328
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070014329 vos_event_init(&pHddCtx->scan_info.scan_finished_event);
14330 pHddCtx->scan_info.scan_pending_option = WEXT_SCAN_PENDING_GIVEUP;
Jeff Johnson295189b2012-06-20 16:38:30 -070014331
Katya Nigam5c306ea2014-06-19 15:39:54 +053014332 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070014333 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014334 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Katya Nigam5c306ea2014-06-19 15:39:54 +053014335
14336#ifdef FEATURE_WLAN_SCAN_PNO
14337 /*SME must send channel update configuration to RIVA*/
14338 sme_UpdateChannelConfig(pHddCtx->hHal);
14339#endif
Abhishek Singhf644b272014-08-21 02:59:39 +053014340 /* Send the update default channel list to the FW*/
14341 sme_UpdateChannelList(pHddCtx->hHal);
Mukul Sharma45063942015-04-01 20:07:59 +053014342
14343 /* Fwr capabilities received, Set the Dot11 mode */
Abhishek Singh41ebce12016-02-03 10:43:21 +053014344 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
14345 hdd_cfg_xlate_to_csr_phy_mode(pHddCtx->cfg_ini->dot11Mode));
Mukul Sharma45063942015-04-01 20:07:59 +053014346 sme_SetDefDot11Mode(pHddCtx->hHal);
14347
Abhishek Singha306a442013-11-07 18:39:01 +053014348#ifndef CONFIG_ENABLE_LINUX_REG
14349 /*updating wiphy so that regulatory user hints can be processed*/
14350 if (wiphy)
14351 {
14352 regulatory_hint(wiphy, "00");
14353 }
14354#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070014355 // Initialize the restart logic
14356 wlan_hdd_restart_init(pHddCtx);
Chilam NG571c65a2013-01-19 12:27:36 +053014357
Hanumanth Reddy Pothula146bca42016-11-08 12:01:07 +053014358 if (pHddCtx->cfg_ini->fIsLogpEnabled) {
14359 vos_wdthread_init_timer_work(vos_process_wd_timer);
14360 /* Initialize the timer to detect thread stuck issues */
14361 vos_thread_stuck_timer_init(
14362 &((VosContextType*)pVosContext)->vosWatchdog);
14363 }
14364
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070014365 //Register the traffic monitor timer now
14366 if ( pHddCtx->cfg_ini->dynSplitscan)
14367 {
14368 vos_timer_init(&pHddCtx->tx_rx_trafficTmr,
14369 VOS_TIMER_TYPE_SW,
14370 hdd_tx_rx_pkt_cnt_stat_timer_handler,
14371 (void *)pHddCtx);
14372 }
Srinivas Dasari030bad32015-02-18 23:23:54 +053014373 wlan_hdd_cfg80211_nan_init(pHddCtx);
14374
Bhargav Shahd0715912015-10-01 18:17:37 +053014375 mutex_init(&pHddCtx->cur_rx_level_lock);
14376 vos_timer_init(&pHddCtx->delack_timer, VOS_TIMER_TYPE_SW,
14377 hdd_tcp_delack_compute_function,(void *)pHddCtx);
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053014378 vos_timer_init(&pHddCtx->tdls_source_timer, VOS_TIMER_TYPE_SW,
14379 wlan_hdd_change_tdls_mode, (void *)pHddCtx);
Bhargav Shahd0715912015-10-01 18:17:37 +053014380
Dino Mycle6fb96c12014-06-10 11:52:40 +053014381#ifdef WLAN_FEATURE_EXTSCAN
14382 sme_EXTScanRegisterCallback(pHddCtx->hHal,
14383 wlan_hdd_cfg80211_extscan_callback,
14384 pHddCtx);
14385#endif /* WLAN_FEATURE_EXTSCAN */
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014386
Padma, Santhosh Kumar2ccac212015-10-20 17:27:27 +053014387#ifdef FEATURE_OEM_DATA_SUPPORT
14388 sme_OemDataRegisterCallback(pHddCtx->hHal,
14389 wlan_hdd_cfg80211_oemdata_callback,
14390 pHddCtx);
14391#endif /* FEATURE_OEM_DATA_SUPPORT */
14392
Gupta, Kapil7c34b322015-09-30 13:12:35 +053014393 sme_set_rssi_threshold_breached_cb(pHddCtx->hHal, hdd_rssi_threshold_breached_cb);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014394#ifdef WLAN_NS_OFFLOAD
14395 // Register IPv6 notifier to notify if any change in IP
14396 // So that we can reconfigure the offload parameters
14397 pHddCtx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
14398 ret = register_inet6addr_notifier(&pHddCtx->ipv6_notifier);
14399 if (ret)
14400 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014401 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014402 }
14403 else
14404 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014405 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014406 }
14407#endif
14408
Sravan Kumar Kairamb0edc612016-10-26 13:55:24 +053014409 vos_mem_set((uint8_t *)&pHddCtx->bad_sta, HDD_MAX_STA_COUNT, 0);
14410
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014411 // Register IPv4 notifier to notify if any change in IP
14412 // So that we can reconfigure the offload parameters
14413 pHddCtx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
14414 ret = register_inetaddr_notifier(&pHddCtx->ipv4_notifier);
14415 if (ret)
14416 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014417 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014418 }
14419 else
14420 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053014421 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014422 }
Bhargav shah23c94942015-10-13 12:48:35 +053014423 hdd_dp_util_send_rps_ind(pHddCtx);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053014424
Nishank Aggarwalc11826c2016-12-15 18:54:10 +053014425 pHddCtx->is_ap_mode_wow_supported =
14426 sme_IsFeatureSupportedByFW(SAP_MODE_WOW);
Sravan Kumar Kairam091e5b62017-01-23 14:14:20 +053014427
Hanumanth Reddy Pothulae92bcc12017-05-19 13:56:35 +053014428 pHddCtx->is_fatal_event_log_sup =
14429 sme_IsFeatureSupportedByFW(FATAL_EVENT_LOGGING);
14430 hddLog(VOS_TRACE_LEVEL_INFO, FL("FATAL_EVENT_LOGGING: %d"),
14431 pHddCtx->is_fatal_event_log_sup);
14432
Sravan Kumar Kairam091e5b62017-01-23 14:14:20 +053014433 hdd_assoc_registerFwdEapolCB(pVosContext);
14434
Ashish Kumar Dhanotiya32d092b2018-02-20 21:43:57 +053014435 mutex_init(&pHddCtx->cache_channel_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070014436 goto success;
14437
Hanumanth Reddy Pothula13789c42017-09-12 15:18:13 +053014438err_open_cesium_nl_sock:
14439#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14440 hdd_close_cesium_nl_sock();
14441#endif
14442
14443err_ptt_sock_activate_svc:
14444#ifdef PTT_SOCK_SVC_ENABLE
14445 ptt_sock_deactivate_svc(pHddCtx);
14446#endif
14447
14448err_oem_activate_service:
14449#ifdef FEATURE_OEM_DATA_SUPPORT
14450 oem_deactivate_service();
14451#endif
14452
14453err_btc_activate_service:
14454 btc_deactivate_service();
14455
Jeff Johnson295189b2012-06-20 16:38:30 -070014456err_reg_netdev:
14457 unregister_netdevice_notifier(&hdd_netdev_notifier);
14458
Jeff Johnson295189b2012-06-20 16:38:30 -070014459err_unregister_pmops:
14460 hddDevTmUnregisterNotifyCallback(pHddCtx);
14461 hddDeregisterPmOps(pHddCtx);
14462
Yue Ma0d4891e2013-08-06 17:01:45 -070014463 hdd_debugfs_exit(pHddCtx);
14464
Jeff Johnson295189b2012-06-20 16:38:30 -070014465#ifdef WLAN_BTAMP_FEATURE
14466err_bap_stop:
14467 WLANBAP_Stop(pVosContext);
14468#endif
14469
14470#ifdef WLAN_BTAMP_FEATURE
14471err_bap_close:
14472 WLANBAP_Close(pVosContext);
14473#endif
14474
Jeff Johnson295189b2012-06-20 16:38:30 -070014475err_close_adapter:
14476 hdd_close_all_adapters( pHddCtx );
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053014477#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053014478err_unregister_wiphy:
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053014479#endif
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053014480 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053014481 hdd_wlan_free_wiphy_channels(wiphy);
14482
Jeff Johnson295189b2012-06-20 16:38:30 -070014483err_vosstop:
14484 vos_stop(pVosContext);
14485
Amar Singhala49cbc52013-10-08 18:37:44 -070014486err_vosclose:
Jeff Johnson295189b2012-06-20 16:38:30 -070014487 status = vos_sched_close( pVosContext );
14488 if (!VOS_IS_STATUS_SUCCESS(status)) {
14489 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
14490 "%s: Failed to close VOSS Scheduler", __func__);
14491 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
14492 }
Amar Singhala49cbc52013-10-08 18:37:44 -070014493 vos_close(pVosContext );
14494
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053014495err_nl_srv:
14496#ifdef WLAN_KD_READY_NOTIFIER
14497 nl_srv_exit(pHddCtx->ptt_pid);
14498#else
14499 nl_srv_exit();
14500#endif /* WLAN_KD_READY_NOTIFIER */
Amar Singhal0a402232013-10-11 20:57:16 -070014501err_vos_nv_close:
14502
c_hpothue6a36282014-03-19 12:27:38 +053014503#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070014504 vos_nv_close();
14505
c_hpothu70f8d812014-03-22 22:59:23 +053014506#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014507
14508err_wdclose:
14509 if(pHddCtx->cfg_ini->fIsLogpEnabled)
14510 vos_watchdog_close(pVosContext);
14511
Jeff Johnson295189b2012-06-20 16:38:30 -070014512err_config:
Hanumanth Reddy Pothula1efcd162018-03-14 14:32:27 +053014513 hdd_request_manager_deinit();
Jeff Johnson295189b2012-06-20 16:38:30 -070014514 kfree(pHddCtx->cfg_ini);
14515 pHddCtx->cfg_ini= NULL;
14516
14517err_free_hdd_context:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014518 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053014519 free_riva_power_on_lock("wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070014520 wiphy_free(wiphy) ;
14521 //kfree(wdev) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070014522 VOS_BUG(1);
14523
Madan Mohan Koyyalamudid57ae632012-11-06 18:42:48 -080014524 if (hdd_is_ssr_required())
14525 {
14526 /* WDI timeout had happened during load, so SSR is needed here */
14527 subsystem_restart("wcnss");
14528 msleep(5000);
14529 }
14530 hdd_set_ssr_required (VOS_FALSE);
14531
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080014532 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070014533
14534success:
14535 EXIT();
14536 return 0;
14537}
14538
14539/**---------------------------------------------------------------------------
14540
Jeff Johnson32d95a32012-09-10 13:15:23 -070014541 \brief hdd_driver_init() - Core Driver Init Function
Jeff Johnson295189b2012-06-20 16:38:30 -070014542
Jeff Johnson32d95a32012-09-10 13:15:23 -070014543 This is the driver entry point - called in different timeline depending
14544 on whether the driver is statically or dynamically linked
Jeff Johnson295189b2012-06-20 16:38:30 -070014545
14546 \param - None
14547
14548 \return - 0 for success, non zero for failure
14549
14550 --------------------------------------------------------------------------*/
Jeff Johnson32d95a32012-09-10 13:15:23 -070014551static int hdd_driver_init( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070014552{
14553 VOS_STATUS status;
14554 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070014555 struct device *dev = NULL;
14556 int ret_status = 0;
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014557#ifdef HAVE_WCNSS_CAL_DOWNLOAD
14558 int max_retries = 0;
14559#endif
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014560#ifdef HAVE_CBC_DONE
14561 int max_cbc_retries = 0;
14562#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014563
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014564#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14565 wlan_logging_sock_init_svc();
14566#endif
14567
Jeff Johnson295189b2012-06-20 16:38:30 -070014568 ENTER();
14569
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014570 vos_wake_lock_init(&wlan_wake_lock, "wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070014571
14572 pr_info("%s: loading driver v%s\n", WLAN_MODULE_NAME,
14573 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
14574
Jeff Johnson295189b2012-06-20 16:38:30 -070014575#ifdef ANI_BUS_TYPE_PCI
14576
14577 dev = wcnss_wlan_get_device();
14578
14579#endif // ANI_BUS_TYPE_PCI
14580
14581#ifdef ANI_BUS_TYPE_PLATFORM
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014582
14583#ifdef HAVE_WCNSS_CAL_DOWNLOAD
14584 /* wait until WCNSS driver downloads NV */
Ravi Kumar Bokka7a139e62016-11-17 21:32:55 +053014585 while (!wcnss_device_ready() && 10 >= ++max_retries) {
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014586 msleep(1000);
14587 }
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014588
Ravi Kumar Bokka7a139e62016-11-17 21:32:55 +053014589 if (max_retries >= 10) {
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014590 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WCNSS driver not ready", __func__);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014591 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014592#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14593 wlan_logging_sock_deinit_svc();
14594#endif
14595
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070014596 return -ENODEV;
14597 }
14598#endif
14599
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053014600#ifdef HAVE_CBC_DONE
14601 while (!wcnss_cbc_complete() && 10 >= ++max_cbc_retries) {
14602 msleep(1000);
14603 }
14604 if (max_cbc_retries >= 10) {
14605 hddLog(VOS_TRACE_LEVEL_FATAL, "%s:CBC not completed", __func__);
14606 }
14607#endif
14608
Jeff Johnson295189b2012-06-20 16:38:30 -070014609 dev = wcnss_wlan_get_device();
14610#endif // ANI_BUS_TYPE_PLATFORM
14611
14612
14613 do {
14614 if (NULL == dev) {
14615 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: WLAN device not found!!",__func__);
14616 ret_status = -1;
14617 break;
14618 }
14619
Jeff Johnson295189b2012-06-20 16:38:30 -070014620#ifdef TIMER_MANAGER
14621 vos_timer_manager_init();
14622#endif
14623
14624 /* Preopen VOSS so that it is ready to start at least SAL */
14625 status = vos_preOpen(&pVosContext);
14626
14627 if (!VOS_IS_STATUS_SUCCESS(status))
14628 {
14629 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to preOpen VOSS", __func__);
14630 ret_status = -1;
14631 break;
14632 }
14633
Sushant Kaushik02beb352015-06-04 15:15:01 +053014634 hddTraceInit();
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +053014635 hdd_register_debug_callback();
14636
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014637#ifndef MODULE
14638 /* For statically linked driver, call hdd_set_conparam to update curr_con_mode
14639 */
14640 hdd_set_conparam((v_UINT_t)con_mode);
14641#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014642
14643 // Call our main init function
Jeff Johnsonbc676b42013-02-14 16:04:08 -080014644 if (hdd_wlan_startup(dev))
14645 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014646 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WLAN Driver Initialization failed",
Jeff Johnsonbc676b42013-02-14 16:04:08 -080014647 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070014648 vos_preClose( &pVosContext );
14649 ret_status = -1;
14650 break;
14651 }
14652
Jeff Johnson295189b2012-06-20 16:38:30 -070014653 } while (0);
14654
14655 if (0 != ret_status)
14656 {
Jeff Johnson295189b2012-06-20 16:38:30 -070014657#ifdef TIMER_MANAGER
14658 vos_timer_exit();
14659#endif
14660#ifdef MEMORY_DEBUG
14661 vos_mem_exit();
14662#endif
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014663 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014664#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14665 wlan_logging_sock_deinit_svc();
14666#endif
14667
Jeff Johnson295189b2012-06-20 16:38:30 -070014668 pr_err("%s: driver load failure\n", WLAN_MODULE_NAME);
14669 }
14670 else
14671 {
14672 //Send WLAN UP indication to Nlink Service
14673 send_btc_nlink_msg(WLAN_MODULE_UP_IND, 0);
14674
14675 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Jeff Johnson295189b2012-06-20 16:38:30 -070014676 }
14677
14678 EXIT();
14679
14680 return ret_status;
14681}
14682
Jeff Johnson32d95a32012-09-10 13:15:23 -070014683/**---------------------------------------------------------------------------
14684
14685 \brief hdd_module_init() - Init Function
14686
14687 This is the driver entry point (invoked when module is loaded using insmod)
14688
14689 \param - None
14690
14691 \return - 0 for success, non zero for failure
14692
14693 --------------------------------------------------------------------------*/
14694#ifdef MODULE
14695static int __init hdd_module_init ( void)
14696{
14697 return hdd_driver_init();
14698}
Jeff Johnson32d95a32012-09-10 13:15:23 -070014699#else /* #ifdef MODULE */
14700static int __init hdd_module_init ( void)
14701{
14702 /* Driver initialization is delayed to fwpath_changed_handler */
14703 return 0;
14704}
Jeff Johnson32d95a32012-09-10 13:15:23 -070014705#endif /* #ifdef MODULE */
14706
Jeff Johnson295189b2012-06-20 16:38:30 -070014707
14708/**---------------------------------------------------------------------------
14709
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014710 \brief hdd_driver_exit() - Exit function
Jeff Johnson295189b2012-06-20 16:38:30 -070014711
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014712 This is the driver exit point (invoked when module is unloaded using rmmod
14713 or con_mode was changed by userspace)
Jeff Johnson295189b2012-06-20 16:38:30 -070014714
14715 \param - None
14716
14717 \return - None
14718
14719 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014720static void hdd_driver_exit(void)
Jeff Johnson295189b2012-06-20 16:38:30 -070014721{
14722 hdd_context_t *pHddCtx = NULL;
14723 v_CONTEXT_t pVosContext = NULL;
Agarwal Ashish5e414792014-06-08 15:25:23 +053014724 v_REGDOMAIN_t regId;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053014725 unsigned long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070014726
14727 pr_info("%s: unloading driver v%s\n", WLAN_MODULE_NAME, QWLAN_VERSIONSTR);
14728
14729 //Get the global vos context
14730 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
14731
14732 if(!pVosContext)
14733 {
14734 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
14735 goto done;
14736 }
14737
14738 //Get the HDD context.
14739 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
14740
14741 if(!pHddCtx)
14742 {
14743 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: module exit called before probe",__func__);
14744 }
Katya Nigame7b69a82015-04-28 15:24:06 +053014745 else if (VOS_MONITOR_MODE == hdd_get_conparam())
14746 {
14747 hddLog(VOS_TRACE_LEVEL_INFO,"%s: MONITOR MODE",__func__);
14748 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
14749 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
14750 hdd_wlan_exit(pHddCtx);
14751 vos_preClose( &pVosContext );
14752 goto done;
14753 }
Jeff Johnson295189b2012-06-20 16:38:30 -070014754 else
14755 {
Siddharth Bhal2e5871b2015-03-24 16:20:51 +053014756 /* We wait for active entry threads to exit from driver
14757 * by waiting until rtnl_lock is available.
14758 */
14759 rtnl_lock();
14760 rtnl_unlock();
14761
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014762 INIT_COMPLETION(pHddCtx->ssr_comp_var);
14763 if ((pHddCtx->isLogpInProgress) && (FALSE ==
14764 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)))
14765 {
Siddharth Bhala204f572015-01-17 02:03:36 +053014766 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014767 "%s:SSR in Progress; block rmmod !!!", __func__);
Siddharth Bhala204f572015-01-17 02:03:36 +053014768 rc = wait_for_completion_timeout(&pHddCtx->ssr_comp_var,
14769 msecs_to_jiffies(30000));
14770 if(!rc)
14771 {
14772 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
14773 "%s:SSR timedout, fatal error", __func__);
14774 VOS_BUG(0);
14775 }
14776 }
14777
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053014778 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
14779 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -070014780
c_hpothu8adb97b2014-12-08 19:38:20 +053014781 /* Driver Need to send country code 00 in below condition
14782 * 1) If gCountryCodePriority is set to 1; and last country
14783 * code set is through 11d. This needs to be done in case
14784 * when NV country code is 00.
14785 * This Needs to be done as when kernel store last country
14786 * code and if stored country code is not through 11d,
14787 * in sme_HandleChangeCountryCodeByUser we will disable 11d
14788 * in next load/unload as soon as we get any country through
14789 * 11d. In sme_HandleChangeCountryCodeByUser
14790 * pMsg->countryCode will be last countryCode and
14791 * pMac->scan.countryCode11d will be country through 11d so
14792 * due to mismatch driver will disable 11d.
14793 *
14794 */
Agarwal Ashish8db39882014-07-30 21:56:07 +053014795
c_hpothu8adb97b2014-12-08 19:38:20 +053014796 if ((eANI_BOOLEAN_TRUE == sme_Is11dCountrycode(pHddCtx->hHal) &&
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053014797 pHddCtx->cfg_ini->fSupplicantCountryCodeHasPriority &&
Abhishek Singh2a705962014-10-30 14:47:28 +053014798 sme_Is11dSupported(pHddCtx->hHal)))
c_hpothu8adb97b2014-12-08 19:38:20 +053014799 {
14800 hddLog(VOS_TRACE_LEVEL_INFO,
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053014801 FL("CountryCode 00 is being set while unloading driver"));
c_hpothu8adb97b2014-12-08 19:38:20 +053014802 vos_nv_getRegDomainFromCountryCode(&regId , "00", COUNTRY_USER);
14803 }
Agarwal Ashish5e414792014-06-08 15:25:23 +053014804
c_hpothu8adb97b2014-12-08 19:38:20 +053014805 //Do all the cleanup before deregistering the driver
14806 hdd_wlan_exit(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070014807 }
14808
Jeff Johnson295189b2012-06-20 16:38:30 -070014809 vos_preClose( &pVosContext );
14810
14811#ifdef TIMER_MANAGER
14812 vos_timer_exit();
14813#endif
14814#ifdef MEMORY_DEBUG
14815 vos_mem_exit();
14816#endif
14817
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014818#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
14819 wlan_logging_sock_deinit_svc();
14820#endif
14821
Jeff Johnson295189b2012-06-20 16:38:30 -070014822done:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053014823 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053014824
Jeff Johnson295189b2012-06-20 16:38:30 -070014825 pr_info("%s: driver unloaded\n", WLAN_MODULE_NAME);
14826}
14827
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014828/**---------------------------------------------------------------------------
14829
14830 \brief hdd_module_exit() - Exit function
14831
14832 This is the driver exit point (invoked when module is unloaded using rmmod)
14833
14834 \param - None
14835
14836 \return - None
14837
14838 --------------------------------------------------------------------------*/
14839static void __exit hdd_module_exit(void)
14840{
14841 hdd_driver_exit();
14842}
14843
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014844#ifdef MODULE
14845static int fwpath_changed_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014846 const struct kernel_param *kp)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014847{
Jeff Johnson76052702013-04-16 13:55:05 -070014848 return param_set_copystring(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014849}
14850
14851static int con_mode_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014852 const struct kernel_param *kp)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014853{
Madan Mohan Koyyalamudif2f8d8b2012-10-11 17:06:59 -070014854 return param_set_int(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014855}
14856#else /* #ifdef MODULE */
14857/**---------------------------------------------------------------------------
14858
Jeff Johnson76052702013-04-16 13:55:05 -070014859 \brief kickstart_driver
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014860
Jeff Johnson76052702013-04-16 13:55:05 -070014861 This is the driver entry point
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014862 - delayed driver initialization when driver is statically linked
Jeff Johnson76052702013-04-16 13:55:05 -070014863 - invoked when module parameter fwpath is modified from userspace to signal
14864 initializing the WLAN driver or when con_mode is modified from userspace
14865 to signal a switch in operating mode
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014866
14867 \return - 0 for success, non zero for failure
14868
14869 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -070014870static int kickstart_driver(void)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014871{
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014872 int ret_status;
14873
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014874 if (!wlan_hdd_inited) {
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014875 ret_status = hdd_driver_init();
14876 wlan_hdd_inited = ret_status ? 0 : 1;
14877 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014878 }
14879
14880 hdd_driver_exit();
Jeff Johnson76052702013-04-16 13:55:05 -070014881
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014882 msleep(200);
Jeff Johnson76052702013-04-16 13:55:05 -070014883
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070014884 ret_status = hdd_driver_init();
14885 wlan_hdd_inited = ret_status ? 0 : 1;
14886 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070014887}
14888
Jeff Johnson295189b2012-06-20 16:38:30 -070014889/**---------------------------------------------------------------------------
14890
Jeff Johnson76052702013-04-16 13:55:05 -070014891 \brief fwpath_changed_handler() - Handler Function
14892
14893 Handle changes to the fwpath parameter
14894
14895 \return - 0 for success, non zero for failure
14896
14897 --------------------------------------------------------------------------*/
14898static int fwpath_changed_handler(const char *kmessage,
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014899 const struct kernel_param *kp)
Jeff Johnson76052702013-04-16 13:55:05 -070014900{
14901 int ret;
14902
14903 ret = param_set_copystring(kmessage, kp);
14904 if (0 == ret)
14905 ret = kickstart_driver();
14906 return ret;
14907}
14908
14909/**---------------------------------------------------------------------------
14910
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014911 \brief con_mode_handler() -
14912
14913 Handler function for module param con_mode when it is changed by userspace
14914 Dynamically linked - do nothing
14915 Statically linked - exit and init driver, as in rmmod and insmod
14916
Jeff Johnson76052702013-04-16 13:55:05 -070014917 \param -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014918
Jeff Johnson76052702013-04-16 13:55:05 -070014919 \return -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014920
14921 --------------------------------------------------------------------------*/
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053014922static int con_mode_handler(const char *kmessage,
14923 const struct kernel_param *kp)
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014924{
Jeff Johnson76052702013-04-16 13:55:05 -070014925 int ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014926
Jeff Johnson76052702013-04-16 13:55:05 -070014927 ret = param_set_int(kmessage, kp);
14928 if (0 == ret)
14929 ret = kickstart_driver();
14930 return ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014931}
14932#endif /* #ifdef MODULE */
14933
14934/**---------------------------------------------------------------------------
14935
Jeff Johnson295189b2012-06-20 16:38:30 -070014936 \brief hdd_get_conparam() -
14937
14938 This is the driver exit point (invoked when module is unloaded using rmmod)
14939
14940 \param - None
14941
14942 \return - tVOS_CON_MODE
14943
14944 --------------------------------------------------------------------------*/
14945tVOS_CON_MODE hdd_get_conparam ( void )
14946{
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014947#ifdef MODULE
Jeff Johnson295189b2012-06-20 16:38:30 -070014948 return (tVOS_CON_MODE)con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014949#else
14950 return (tVOS_CON_MODE)curr_con_mode;
14951#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014952}
14953void hdd_set_conparam ( v_UINT_t newParam )
14954{
14955 con_mode = newParam;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014956#ifndef MODULE
14957 curr_con_mode = con_mode;
14958#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070014959}
14960/**---------------------------------------------------------------------------
14961
14962 \brief hdd_softap_sta_deauth() - function
14963
14964 This to take counter measure to handle deauth req from HDD
14965
14966 \param - pAdapter - Pointer to the HDD
14967
14968 \param - enable - boolean value
14969
14970 \return - None
14971
14972 --------------------------------------------------------------------------*/
14973
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053014974VOS_STATUS hdd_softap_sta_deauth(hdd_adapter_t *pAdapter,
14975 struct tagCsrDelStaParams *pDelStaParams)
Jeff Johnson295189b2012-06-20 16:38:30 -070014976{
Jeff Johnson295189b2012-06-20 16:38:30 -070014977 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080014978 VOS_STATUS vosStatus = VOS_STATUS_E_FAULT;
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014979 struct hdd_cache_sta_info *cache_sta_info;
14980 ptSapContext pSapCtx = VOS_GET_SAP_CB(pVosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014981
14982 ENTER();
14983
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070014984 hddLog(LOG1, "hdd_softap_sta_deauth:(%pK, false)",
Rajesh Chauhan18488fc2013-08-22 10:15:03 -070014985 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070014986
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053014987 if (!pSapCtx) {
14988 hddLog(LOGE, "sap context is NULL");
14989 return vosStatus;
14990 }
14991
14992 cache_sta_info = hdd_get_cache_stainfo(pSapCtx->cache_sta_info,
14993 pDelStaParams->peerMacAddr);
14994 if (cache_sta_info) {
14995 cache_sta_info->reason_code = pDelStaParams->reason_code;
14996 cache_sta_info->rx_rate =
14997 wlan_tl_get_sta_rx_rate(pVosContext, cache_sta_info->ucSTAId);
14998 WLANTL_GetSAPStaRSSi(pVosContext, cache_sta_info->ucSTAId,
14999 &cache_sta_info->rssi);
15000 }
15001
Jeff Johnson295189b2012-06-20 16:38:30 -070015002 //Ignore request to deauth bcmc station
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053015003 if (pDelStaParams->peerMacAddr[0] & 0x1)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080015004 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070015005
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053015006 vosStatus = WLANSAP_DeauthSta(pVosContext, pDelStaParams);
Jeff Johnson295189b2012-06-20 16:38:30 -070015007
15008 EXIT();
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080015009 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070015010}
15011
15012/**---------------------------------------------------------------------------
15013
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015014 \brief hdd_del_all_sta() - function
15015
15016 This function removes all the stations associated on stopping AP/P2P GO.
15017
15018 \param - pAdapter - Pointer to the HDD
15019
15020 \return - None
15021
15022 --------------------------------------------------------------------------*/
15023
15024int hdd_del_all_sta(hdd_adapter_t *pAdapter)
15025{
15026 v_U16_t i;
15027 VOS_STATUS vos_status;
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053015028 v_CONTEXT_t pVosContext = ( WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
15029 ptSapContext pSapCtx = NULL;
15030 pSapCtx = VOS_GET_SAP_CB(pVosContext);
15031 if(pSapCtx == NULL){
15032 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15033 FL("psapCtx is NULL"));
15034 return 1;
15035 }
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015036 ENTER();
15037
15038 hddLog(VOS_TRACE_LEVEL_INFO,
15039 "%s: Delete all STAs associated.",__func__);
15040 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
15041 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
15042 )
15043 {
15044 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
15045 {
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053015046 if ((pSapCtx->aStaInfo[i].isUsed) &&
15047 (!pSapCtx->aStaInfo[i].isDeauthInProgress))
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015048 {
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053015049 struct tagCsrDelStaParams delStaParams;
15050
15051 WLANSAP_PopulateDelStaParams(
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053015052 pSapCtx->aStaInfo[i].macAddrSTA.bytes,
Sushant Kaushik4cd28f62014-12-26 14:23:50 +053015053 eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
15054 SIR_MAC_MGMT_DEAUTH >> 4,
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053015055 &delStaParams);
15056 vos_status = hdd_softap_sta_deauth(pAdapter, &delStaParams);
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015057 if (VOS_IS_STATUS_SUCCESS(vos_status))
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053015058 pSapCtx->aStaInfo[i].isDeauthInProgress = TRUE;
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053015059 }
15060 }
15061 }
15062
15063 EXIT();
15064 return 0;
15065}
15066
15067/**---------------------------------------------------------------------------
15068
Jeff Johnson295189b2012-06-20 16:38:30 -070015069 \brief hdd_softap_sta_disassoc() - function
15070
15071 This to take counter measure to handle deauth req from HDD
15072
15073 \param - pAdapter - Pointer to the HDD
15074
15075 \param - enable - boolean value
15076
15077 \return - None
15078
15079 --------------------------------------------------------------------------*/
15080
15081void hdd_softap_sta_disassoc(hdd_adapter_t *pAdapter,v_U8_t *pDestMacAddress)
15082{
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053015083 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
15084 struct hdd_cache_sta_info *cache_sta_info;
15085 ptSapContext pSapCtx = VOS_GET_SAP_CB(pVosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070015086
15087 ENTER();
15088
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070015089 hddLog( LOGE, "hdd_softap_sta_disassoc:(%pK, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070015090
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053015091 if (!pSapCtx) {
15092 hddLog(LOGE, "sap context is NULL");
15093 return ;
15094 }
15095
Jeff Johnson295189b2012-06-20 16:38:30 -070015096 //Ignore request to disassoc bcmc station
15097 if( pDestMacAddress[0] & 0x1 )
15098 return;
15099
Hanumanth Reddy Pothula57323632017-12-06 17:55:09 +053015100 cache_sta_info = hdd_get_cache_stainfo(pSapCtx->cache_sta_info,
15101 pDestMacAddress);
15102 if (cache_sta_info) {
15103 cache_sta_info->reason_code = eSIR_MAC_DEAUTH_LEAVING_BSS_REASON;
15104 cache_sta_info->rx_rate =
15105 wlan_tl_get_sta_rx_rate(pVosContext, cache_sta_info->ucSTAId);
15106 WLANTL_GetSAPStaRSSi(pVosContext, cache_sta_info->ucSTAId,
15107 &cache_sta_info->rssi);
15108 }
15109
Jeff Johnson295189b2012-06-20 16:38:30 -070015110 WLANSAP_DisassocSta(pVosContext,pDestMacAddress);
15111}
15112
15113void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *pAdapter,v_BOOL_t enable)
15114{
15115 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
15116
15117 ENTER();
15118
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070015119 hddLog( LOGE, "hdd_softap_tkip_mic_fail_counter_measure:(%pK, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070015120
15121 WLANSAP_SetCounterMeasure(pVosContext, (v_BOOL_t)enable);
15122}
15123
Jeff Johnson295189b2012-06-20 16:38:30 -070015124/**---------------------------------------------------------------------------
15125 *
15126 * \brief hdd_get__concurrency_mode() -
15127 *
15128 *
15129 * \param - None
15130 *
15131 * \return - CONCURRENCY MODE
15132 *
15133 * --------------------------------------------------------------------------*/
15134tVOS_CONCURRENCY_MODE hdd_get_concurrency_mode ( void )
15135{
15136 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
15137 hdd_context_t *pHddCtx;
15138
15139 if (NULL != pVosContext)
15140 {
15141 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
15142 if (NULL != pHddCtx)
15143 {
15144 return (tVOS_CONCURRENCY_MODE)pHddCtx->concurrency_mode;
15145 }
15146 }
15147
15148 /* we are in an invalid state :( */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070015149 hddLog(LOGE, "%s: Invalid context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070015150 return VOS_STA;
15151}
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015152v_BOOL_t
15153wlan_hdd_is_GO_power_collapse_allowed (hdd_context_t* pHddCtx)
15154{
15155 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070015156
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015157 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_GO);
15158 if (pAdapter == NULL)
15159 {
15160 hddLog(VOS_TRACE_LEVEL_INFO,
15161 FL("GO doesn't exist"));
15162 return TRUE;
15163 }
15164 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
15165 {
15166 hddLog(VOS_TRACE_LEVEL_INFO,
15167 FL("GO started"));
15168 return TRUE;
15169 }
15170 else
15171 /* wait till GO changes its interface to p2p device */
15172 hddLog(VOS_TRACE_LEVEL_INFO,
15173 FL("Del_bss called, avoid apps suspend"));
15174 return FALSE;
15175
15176}
Jeff Johnson295189b2012-06-20 16:38:30 -070015177/* Decide whether to allow/not the apps power collapse.
15178 * Allow apps power collapse if we are in connected state.
15179 * if not, allow only if we are in IMPS */
15180v_BOOL_t hdd_is_apps_power_collapse_allowed(hdd_context_t* pHddCtx)
15181{
15182 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
Srikant Kuppafef66a72013-01-30 17:32:44 -080015183 tANI_BOOLEAN scanRspPending = csrNeighborRoamScanRspPending(pHddCtx->hHal);
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080015184 tANI_BOOLEAN inMiddleOfRoaming = csrNeighborMiddleOfRoaming(pHddCtx->hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -070015185 hdd_config_t *pConfig = pHddCtx->cfg_ini;
15186 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15187 hdd_adapter_t *pAdapter = NULL;
15188 VOS_STATUS status;
Yathish9f22e662012-12-10 14:21:35 -080015189 tVOS_CONCURRENCY_MODE concurrent_state = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070015190
Jeff Johnson295189b2012-06-20 16:38:30 -070015191 if (VOS_STA_SAP_MODE == hdd_get_conparam())
15192 return TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -070015193
Yathish9f22e662012-12-10 14:21:35 -080015194 concurrent_state = hdd_get_concurrency_mode();
15195
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015196 if ((concurrent_state == (VOS_STA | VOS_P2P_GO)) &&
15197 !(wlan_hdd_is_GO_power_collapse_allowed(pHddCtx)))
15198 return FALSE;
Yathish9f22e662012-12-10 14:21:35 -080015199#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015200
Yathish9f22e662012-12-10 14:21:35 -080015201 if(((concurrent_state == (VOS_STA | VOS_P2P_CLIENT)) ||
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053015202 (concurrent_state == (VOS_STA | VOS_P2P_GO)))&&
Yathish9f22e662012-12-10 14:21:35 -080015203 (IS_ACTIVEMODE_OFFLOAD_FEATURE_ENABLE))
15204 return TRUE;
15205#endif
15206
Jeff Johnson295189b2012-06-20 16:38:30 -070015207 /*loop through all adapters. TBD fix for Concurrency */
15208 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15209 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
15210 {
15211 pAdapter = pAdapterNode->pAdapter;
15212 if ( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
15213 || (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
15214 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080015215 if (((pConfig->fIsImpsEnabled || pConfig->fIsBmpsEnabled)
c_hpothu4e8faac2014-05-16 17:38:44 +053015216 && (pmcState != IMPS && pmcState != BMPS && pmcState != UAPSD
c_hpothu1c6957d2015-01-06 18:19:47 +053015217 && pmcState != STOPPED && pmcState != STANDBY &&
15218 pmcState != WOWL)) ||
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080015219 (eANI_BOOLEAN_TRUE == scanRspPending) ||
15220 (eANI_BOOLEAN_TRUE == inMiddleOfRoaming))
Jeff Johnson295189b2012-06-20 16:38:30 -070015221 {
Mukul Sharma4be88422015-03-09 20:29:07 +053015222 if(pmcState == FULL_POWER &&
15223 sme_IsCoexScoIndicationSet(pHddCtx->hHal))
15224 {
15225 /*
15226 * When SCO indication comes from Coex module , host will
15227 * enter in to full power mode, but this should not prevent
15228 * apps processor power collapse.
15229 */
15230 hddLog(LOG1,
15231 FL("Allow apps power collapse"
15232 "even when sco indication is set"));
15233 return TRUE;
15234 }
Srikant Kuppafef66a72013-01-30 17:32:44 -080015235 hddLog( LOGE, "%s: do not allow APPS power collapse-"
Deepthi Gowri03a979f2016-11-03 15:20:19 +053015236 "pmcState = %d scanRspPending = %d "
15237 "inMiddleOfRoaming = %d connected = %d",
15238 __func__, pmcState, scanRspPending,
15239 inMiddleOfRoaming, hdd_connIsConnected(
15240 WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )));
15241 wlan_hdd_get_tdls_stats(pAdapter);
15242 return FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070015243 }
15244 }
15245 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15246 pAdapterNode = pNext;
15247 }
15248 return TRUE;
15249}
15250
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -080015251/* Decides whether to send suspend notification to Riva
15252 * if any adapter is in BMPS; then it is required */
15253v_BOOL_t hdd_is_suspend_notify_allowed(hdd_context_t* pHddCtx)
15254{
15255 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
15256 hdd_config_t *pConfig = pHddCtx->cfg_ini;
15257
15258 if (pConfig->fIsBmpsEnabled && (pmcState == BMPS))
15259 {
15260 return TRUE;
15261 }
15262 return FALSE;
15263}
15264
Jeff Johnson295189b2012-06-20 16:38:30 -070015265void wlan_hdd_set_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15266{
15267 switch(mode)
15268 {
Chilam Ngc4244af2013-04-01 15:37:32 -070015269 case VOS_STA_MODE:
15270 case VOS_P2P_CLIENT_MODE:
15271 case VOS_P2P_GO_MODE:
15272 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053015273 case VOS_MONITOR_MODE:
Jeff Johnsone7245742012-09-05 17:12:55 -070015274 pHddCtx->concurrency_mode |= (1 << mode);
Agarwal Ashish51325b52014-06-16 16:50:49 +053015275 pHddCtx->no_of_open_sessions[mode]++;
Jeff Johnson295189b2012-06-20 16:38:30 -070015276 break;
15277 default:
15278 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070015279 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053015280 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
15281 "Number of open sessions for mode %d = %d"),
15282 pHddCtx->concurrency_mode, mode,
15283 pHddCtx->no_of_open_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070015284}
15285
15286
15287void wlan_hdd_clear_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15288{
15289 switch(mode)
15290 {
Chilam Ngc4244af2013-04-01 15:37:32 -070015291 case VOS_STA_MODE:
15292 case VOS_P2P_CLIENT_MODE:
15293 case VOS_P2P_GO_MODE:
15294 case VOS_STA_SAP_MODE:
Rajeev Kumar Sirasanagandla8f11d542017-11-14 17:56:55 +053015295 case VOS_MONITOR_MODE:
Agarwal Ashish51325b52014-06-16 16:50:49 +053015296 pHddCtx->no_of_open_sessions[mode]--;
15297 if (!(pHddCtx->no_of_open_sessions[mode]))
15298 pHddCtx->concurrency_mode &= (~(1 << mode));
Jeff Johnson295189b2012-06-20 16:38:30 -070015299 break;
15300 default:
15301 break;
15302 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053015303 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
15304 "Number of open sessions for mode %d = %d"),
15305 pHddCtx->concurrency_mode, mode, pHddCtx->no_of_open_sessions[mode]);
15306
15307}
15308/**---------------------------------------------------------------------------
15309 *
15310 * \brief wlan_hdd_incr_active_session()
15311 *
15312 * This function increments the number of active sessions
15313 * maintained per device mode
15314 * Incase of STA/P2P CLI/IBSS upon connection indication it is incremented
15315 * Incase of SAP/P2P GO upon bss start it is incremented
15316 *
15317 * \param pHddCtx - HDD Context
15318 * \param mode - device mode
15319 *
15320 * \return - None
15321 *
15322 * --------------------------------------------------------------------------*/
15323void wlan_hdd_incr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15324{
15325 switch (mode) {
15326 case VOS_STA_MODE:
15327 case VOS_P2P_CLIENT_MODE:
15328 case VOS_P2P_GO_MODE:
15329 case VOS_STA_SAP_MODE:
15330 pHddCtx->no_of_active_sessions[mode]++;
15331 break;
15332 default:
15333 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
15334 break;
15335 }
15336 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
15337 mode,
15338 pHddCtx->no_of_active_sessions[mode]);
15339}
15340
15341/**---------------------------------------------------------------------------
15342 *
15343 * \brief wlan_hdd_decr_active_session()
15344 *
15345 * This function decrements the number of active sessions
15346 * maintained per device mode
15347 * Incase of STA/P2P CLI/IBSS upon disconnection it is decremented
15348 * Incase of SAP/P2P GO upon bss stop it is decremented
15349 *
15350 * \param pHddCtx - HDD Context
15351 * \param mode - device mode
15352 *
15353 * \return - None
15354 *
15355 * --------------------------------------------------------------------------*/
15356void wlan_hdd_decr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
15357{
Bhargav Shahd0715912015-10-01 18:17:37 +053015358
Agarwal Ashish51325b52014-06-16 16:50:49 +053015359 switch (mode) {
15360 case VOS_STA_MODE:
15361 case VOS_P2P_CLIENT_MODE:
15362 case VOS_P2P_GO_MODE:
15363 case VOS_STA_SAP_MODE:
Agarwal Ashish5325f522014-08-06 00:58:44 +053015364 if (pHddCtx->no_of_active_sessions[mode] > 0)
15365 pHddCtx->no_of_active_sessions[mode]--;
15366 else
15367 hddLog(VOS_TRACE_LEVEL_INFO, FL(" No.# of Active sessions"
15368 "is already Zero"));
Agarwal Ashish51325b52014-06-16 16:50:49 +053015369 break;
15370 default:
15371 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
15372 break;
15373 }
15374 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
15375 mode,
15376 pHddCtx->no_of_active_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070015377}
15378
Jeff Johnsone7245742012-09-05 17:12:55 -070015379/**---------------------------------------------------------------------------
15380 *
15381 * \brief wlan_hdd_restart_init
15382 *
15383 * This function initalizes restart timer/flag. An internal function.
15384 *
15385 * \param - pHddCtx
15386 *
15387 * \return - None
15388 *
15389 * --------------------------------------------------------------------------*/
15390
15391static void wlan_hdd_restart_init(hdd_context_t *pHddCtx)
15392{
15393 /* Initialize */
15394 pHddCtx->hdd_restart_retries = 0;
15395 atomic_set(&pHddCtx->isRestartInProgress, 0);
15396 vos_timer_init(&pHddCtx->hdd_restart_timer,
15397 VOS_TIMER_TYPE_SW,
15398 wlan_hdd_restart_timer_cb,
15399 pHddCtx);
15400}
15401/**---------------------------------------------------------------------------
15402 *
15403 * \brief wlan_hdd_restart_deinit
15404 *
15405 * This function cleans up the resources used. An internal function.
15406 *
15407 * \param - pHddCtx
15408 *
15409 * \return - None
15410 *
15411 * --------------------------------------------------------------------------*/
15412
15413static void wlan_hdd_restart_deinit(hdd_context_t* pHddCtx)
15414{
15415
15416 VOS_STATUS vos_status;
15417 /* Block any further calls */
15418 atomic_set(&pHddCtx->isRestartInProgress, 1);
15419 /* Cleanup */
15420 vos_status = vos_timer_stop( &pHddCtx->hdd_restart_timer );
15421 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053015422 hddLog(LOGE, FL("Failed to stop HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070015423 vos_status = vos_timer_destroy(&pHddCtx->hdd_restart_timer);
15424 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053015425 hddLog(LOGE, FL("Failed to destroy HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070015426
15427}
15428
15429/**---------------------------------------------------------------------------
15430 *
15431 * \brief wlan_hdd_framework_restart
15432 *
15433 * This function uses a cfg80211 API to start a framework initiated WLAN
15434 * driver module unload/load.
15435 *
15436 * Also this API keep retrying (WLAN_HDD_RESTART_RETRY_MAX_CNT).
15437 *
15438 *
15439 * \param - pHddCtx
15440 *
15441 * \return - VOS_STATUS_SUCCESS: Success
15442 * VOS_STATUS_E_EMPTY: Adapter is Empty
15443 * VOS_STATUS_E_NOMEM: No memory
15444
15445 * --------------------------------------------------------------------------*/
15446
15447static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx)
15448{
15449 VOS_STATUS status = VOS_STATUS_SUCCESS;
15450 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015451 int len = (sizeof (struct ieee80211_mgmt));
15452 struct ieee80211_mgmt *mgmt = NULL;
15453
15454 /* Prepare the DEAUTH managment frame with reason code */
15455 mgmt = kzalloc(len, GFP_KERNEL);
15456 if(mgmt == NULL)
15457 {
15458 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
15459 "%s: memory allocation failed (%d bytes)", __func__, len);
15460 return VOS_STATUS_E_NOMEM;
15461 }
15462 mgmt->u.deauth.reason_code = WLAN_REASON_DISASSOC_LOW_ACK;
Jeff Johnsone7245742012-09-05 17:12:55 -070015463
15464 /* Iterate over all adapters/devices */
15465 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015466 if ((NULL == pAdapterNode) || (VOS_STATUS_SUCCESS != status))
15467 {
15468 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsonc135a9a2017-09-19 08:37:24 -070015469 FL("fail to get adapter: %pK %d"), pAdapterNode, status);
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015470 goto end;
15471 }
15472
Jeff Johnsone7245742012-09-05 17:12:55 -070015473 do
15474 {
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015475 if(pAdapterNode->pAdapter &&
15476 WLAN_HDD_ADAPTER_MAGIC == pAdapterNode->pAdapter->magic)
Jeff Johnsone7245742012-09-05 17:12:55 -070015477 {
15478 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
15479 "restarting the driver(intf:\'%s\' mode:%d :try %d)",
15480 pAdapterNode->pAdapter->dev->name,
15481 pAdapterNode->pAdapter->device_mode,
15482 pHddCtx->hdd_restart_retries + 1);
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015483 /*
15484 * CFG80211 event to restart the driver
15485 *
15486 * 'cfg80211_send_unprot_deauth' sends a
15487 * NL80211_CMD_UNPROT_DEAUTHENTICATE event to supplicant at any state
15488 * of SME(Linux Kernel) state machine.
15489 *
15490 * Reason code WLAN_REASON_DISASSOC_LOW_ACK is currently used to restart
15491 * the driver.
15492 *
15493 */
Abhishek Singh00b71972016-01-07 10:51:04 +053015494
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053015495#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
15496 cfg80211_rx_unprot_mlme_mgmt(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len);
15497#else
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015498 cfg80211_send_unprot_deauth(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053015499#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070015500 }
15501 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15502 pAdapterNode = pNext;
15503 } while((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status));
15504
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053015505 end:
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070015506 /* Free the allocated management frame */
15507 kfree(mgmt);
15508
Jeff Johnsone7245742012-09-05 17:12:55 -070015509 /* Retry until we unload or reach max count */
15510 if(++pHddCtx->hdd_restart_retries < WLAN_HDD_RESTART_RETRY_MAX_CNT)
15511 vos_timer_start(&pHddCtx->hdd_restart_timer, WLAN_HDD_RESTART_RETRY_DELAY_MS);
15512
15513 return status;
15514
15515}
15516/**---------------------------------------------------------------------------
15517 *
15518 * \brief wlan_hdd_restart_timer_cb
15519 *
15520 * Restart timer callback. An internal function.
15521 *
15522 * \param - User data:
15523 *
15524 * \return - None
15525 *
15526 * --------------------------------------------------------------------------*/
15527
15528void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback)
15529{
15530 hdd_context_t *pHddCtx = usrDataForCallback;
15531 wlan_hdd_framework_restart(pHddCtx);
15532 return;
15533
15534}
15535
15536
15537/**---------------------------------------------------------------------------
15538 *
15539 * \brief wlan_hdd_restart_driver
15540 *
15541 * This function sends an event to supplicant to restart the WLAN driver.
15542 *
15543 * This function is called from vos_wlanRestart.
15544 *
15545 * \param - pHddCtx
15546 *
15547 * \return - VOS_STATUS_SUCCESS: Success
15548 * VOS_STATUS_E_EMPTY: Adapter is Empty
15549 * VOS_STATUS_E_ALREADY: Request already in progress
15550
15551 * --------------------------------------------------------------------------*/
15552VOS_STATUS wlan_hdd_restart_driver(hdd_context_t *pHddCtx)
15553{
15554 VOS_STATUS status = VOS_STATUS_SUCCESS;
15555
15556 /* A tight check to make sure reentrancy */
15557 if(atomic_xchg(&pHddCtx->isRestartInProgress, 1))
15558 {
Mihir Shetefd528652014-06-23 19:07:50 +053015559 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsone7245742012-09-05 17:12:55 -070015560 "%s: WLAN restart is already in progress", __func__);
15561
15562 return VOS_STATUS_E_ALREADY;
15563 }
Sameer Thalappil0c164f52013-03-28 15:27:56 -070015564 /* Send reset FIQ to WCNSS to invoke SSR. */
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -080015565#ifdef HAVE_WCNSS_RESET_INTR
Siddharth Bhal864e7e82015-04-07 20:07:24 +053015566 wcnss_reset_fiq(TRUE);
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -070015567#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070015568
Jeff Johnsone7245742012-09-05 17:12:55 -070015569 return status;
15570}
15571
Bhargav Shahd0715912015-10-01 18:17:37 +053015572/**
15573 * hdd_get_total_sessions() - provide total number of active sessions
15574 * @pHddCtx: Valid Global HDD context pointer
15575 *
15576 * This function iterates through pAdaptors and find the number of all active
15577 * sessions. This active sessions includes connected sta, p2p client and number
15578 * of client connected to sap/p2p go.
15579 *
15580 * Return: Total number of active sessions.
15581 */
15582v_U8_t hdd_get_total_sessions(hdd_context_t *pHddCtx)
15583{
15584 v_U8_t active_session = 0;
15585 hdd_station_ctx_t *pHddStaCtx;
15586 hdd_adapter_list_node_t *pAdapterNode, *pNext;
15587 hdd_adapter_t *pAdapter;
15588 VOS_STATUS status;
15589
15590 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
15591 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
15592 pAdapter = pAdapterNode->pAdapter;
15593 switch (pAdapter->device_mode) {
15594 case VOS_STA_MODE:
15595 case VOS_P2P_CLIENT_MODE:
15596 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
15597 if(eConnectionState_Associated == pHddStaCtx->conn_info.connState)
15598 active_session += 1;
15599 break;
15600 case VOS_STA_SAP_MODE:
15601 case VOS_P2P_GO_MODE:
15602 active_session += hdd_softap_get_connected_sta(pAdapter);
15603 break;
15604 default:
15605 break;
15606 }
15607
15608 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
15609 pAdapterNode = pNext;
15610 }
15611
15612 return active_session;
15613}
15614
15615/**
15616 * hdd_set_delack_value() - Set delack value
15617 * @pHddCtx: Valid Global HDD context pointer
15618 * @next_rx_level: Value to set for delack
15619 *
15620 * This function compare present value and next value of delack. If the both
15621 * are diffrent then it sets next value .
15622 *
15623 * Return: void.
15624 */
15625void hdd_set_delack_value(hdd_context_t *pHddCtx, v_U32_t next_rx_level)
15626{
15627 if (pHddCtx->cur_rx_level != next_rx_level) {
Alok Kumarf3724462018-04-05 15:18:54 +053015628 struct wlan_rx_tp_data rx_tp_data = {0};
15629
Bhargav Shahd0715912015-10-01 18:17:37 +053015630 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15631 "%s: TCP DELACK trigger level %d",
15632 __func__, next_rx_level);
15633 mutex_lock(&pHddCtx->cur_rx_level_lock);
15634 pHddCtx->cur_rx_level = next_rx_level;
15635 mutex_unlock(&pHddCtx->cur_rx_level_lock);
Alok Kumarf3724462018-04-05 15:18:54 +053015636
15637 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
15638 rx_tp_data.level = next_rx_level;
15639
15640 wlan_hdd_send_svc_nlink_msg(WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
15641 sizeof(rx_tp_data));
Bhargav Shahd0715912015-10-01 18:17:37 +053015642 }
15643}
15644
15645/**
15646 * hdd_set_default_stop_delack_timer() - Start delack timer
15647 * @pHddCtx: Valid Global HDD context pointer
15648 *
15649 * This function stop delack timer and set delack value to default..
15650 *
15651 * Return: void.
15652 */
15653
15654void hdd_set_default_stop_delack_timer(hdd_context_t *pHddCtx)
15655{
15656 if (VOS_TIMER_STATE_RUNNING !=
15657 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
15658 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15659 "%s: Can not stop timer", __func__);
15660 return;
15661 }
15662
15663 vos_timer_stop(&pHddCtx->delack_timer);
Alok Kumarf3724462018-04-05 15:18:54 +053015664 hdd_set_delack_value(pHddCtx, WLAN_SVC_TP_LOW);
Bhargav Shahd0715912015-10-01 18:17:37 +053015665}
15666
15667/**
15668 * hdd_start_delack_timer() - Start delack timer
15669 * @pHddCtx: Valid Global HDD context pointer
15670 *
15671 * This function starts the delack timer for tcpDelAckComputeInterval time
15672 * interval.The default timer value is 2 second.
15673 *
15674 * Return: void.
15675 */
15676void hdd_start_delack_timer(hdd_context_t *pHddCtx)
15677{
15678 if (VOS_TIMER_STATE_RUNNING ==
15679 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
15680 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15681 "%s: Timer is already running", __func__);
15682 return;
15683 }
15684
15685 vos_timer_start(&pHddCtx->delack_timer,
15686 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
15687}
15688
15689/**
15690 * hdd_update_prev_rx_packet_count() - Update previous rx packet count
15691 * @pHddCtx: Valid Global HDD context pointer
15692 *
15693 * This function updates the prev_rx_packets count from the corresponding
15694 * pAdapter states. This prev_rx_packets will diffed with the packet count
15695 * at the end of delack timer. That can give number of RX packet is spacific
15696 * time.
15697 *
15698 * Return: void.
15699 */
15700void hdd_update_prev_rx_packet_count(hdd_context_t *pHddCtx)
15701{
15702 hdd_adapter_list_node_t *pAdapterNode, *pNext;
15703 hdd_adapter_t *pAdapter;
15704 VOS_STATUS status;
15705
15706 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15707 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
15708 pAdapter = pAdapterNode->pAdapter;
15709 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
15710 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15711 pAdapterNode = pNext;
15712 }
15713}
15714
15715/**
15716 * hdd_manage_delack_timer() - start\stop delack timer
15717 * @pHddCtx: Valid Global HDD context pointer
15718 *
15719 * This function check the number of concerent session present, it starts the
15720 * delack timer if only one session is present.
15721 * In the case of BT_COEX and TDLS mode it blindly stop delack functionality.
15722 *
15723 * Return: void.
15724 */
15725void hdd_manage_delack_timer(hdd_context_t *pHddCtx)
15726{
15727 uint8_t sessions;
15728
15729 if (!pHddCtx->cfg_ini->enable_delack) {
15730 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
15731 "%s: TCP DELACK is not enabled", __func__);
15732 return;
15733 }
15734
15735 /* Blindly stop timer of BTCOEX and TDLS Session is up */
15736 if (pHddCtx->mode != 0) {
15737 hdd_set_default_stop_delack_timer(pHddCtx);
15738 return;
15739 }
15740
15741 sessions = hdd_get_total_sessions(pHddCtx);
15742 if (sessions == 1) {
15743 hdd_update_prev_rx_packet_count(pHddCtx);
15744 hdd_start_delack_timer(pHddCtx);
15745 } else {
15746 hdd_set_default_stop_delack_timer(pHddCtx);
15747 }
15748}
15749
Mihir Shetee1093ba2014-01-21 20:13:32 +053015750/**---------------------------------------------------------------------------
15751 *
15752 * \brief wlan_hdd_init_channels
15753 *
15754 * This function is used to initialize the channel list in CSR
15755 *
15756 * This function is called from hdd_wlan_startup
15757 *
15758 * \param - pHddCtx: HDD context
15759 *
15760 * \return - VOS_STATUS_SUCCESS: Success
15761 * VOS_STATUS_E_FAULT: Failure reported by SME
15762
15763 * --------------------------------------------------------------------------*/
15764static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx)
15765{
15766 eHalStatus status;
15767
15768 status = sme_InitChannels(pHddCtx->hHal);
15769 if (HAL_STATUS_SUCCESS(status))
15770 {
15771 return VOS_STATUS_SUCCESS;
15772 }
15773 else
15774 {
15775 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Channel initialization failed(%d)",
15776 __func__, status);
15777 return VOS_STATUS_E_FAULT;
15778 }
15779}
15780
Mihir Shete04206452014-11-20 17:50:58 +053015781#ifdef CONFIG_ENABLE_LINUX_REG
Agarwal Ashish6db9d532014-09-30 18:19:10 +053015782VOS_STATUS wlan_hdd_init_channels_for_cc(hdd_context_t *pHddCtx, driver_load_type init )
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053015783{
15784 eHalStatus status;
15785
Rajeev Kumar Sirasanagandlaf8fc27c2018-12-06 14:56:43 +053015786 if (init == INIT && init_by_reg_core_user) {
15787 init_by_reg_core_user = false;
15788 pr_info("driver regulatory hint is not required");
15789
15790 return VOS_STATUS_SUCCESS;
15791 }
15792
Agarwal Ashish6db9d532014-09-30 18:19:10 +053015793 status = sme_InitChannelsForCC(pHddCtx->hHal, init);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053015794 if (HAL_STATUS_SUCCESS(status))
15795 {
15796 return VOS_STATUS_SUCCESS;
15797 }
15798 else
15799 {
15800 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Issue reg hint failed(%d)",
15801 __func__, status);
15802 return VOS_STATUS_E_FAULT;
15803 }
15804}
Mihir Shete04206452014-11-20 17:50:58 +053015805#endif
Sudhir Sattayappa Kohallib1d8c3a2013-06-18 14:47:20 -070015806/*
15807 * API to find if there is any STA or P2P-Client is connected
15808 */
15809VOS_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *pHddCtx)
15810{
15811 return sme_isSta_p2p_clientConnected(pHddCtx->hHal);
15812}
Jeff Johnsone7245742012-09-05 17:12:55 -070015813
Mihir Shetee2ae82a2015-03-16 14:08:49 +053015814
15815/*
15816 * API to find if the firmware will send logs using DXE channel
15817 */
15818v_U8_t hdd_is_fw_logging_enabled(void)
15819{
15820 hdd_context_t *pHddCtx;
15821
15822 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
15823 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
15824
Sravan Kumar Kairam1d5bf8e2019-03-21 00:33:56 +053015825 return (pHddCtx && pHddCtx->cfg_ini->wlanLoggingEnable &&
15826 pHddCtx->cfg_ini->enableMgmtLogging);
Mihir Shetee2ae82a2015-03-16 14:08:49 +053015827}
15828
Agarwal Ashish57e84372014-12-05 18:26:53 +053015829/*
Mihir Shetebe94ebb2015-05-26 12:07:14 +053015830 * API to find if the firmware will send trace logs using DXE channel
15831 */
15832v_U8_t hdd_is_fw_ev_logging_enabled(void)
15833{
15834 hdd_context_t *pHddCtx;
15835
15836 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
15837 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
15838
Sravan Kumar Kairam1d5bf8e2019-03-21 00:33:56 +053015839 return (pHddCtx && pHddCtx->cfg_ini->wlanLoggingEnable &&
15840 pHddCtx->cfg_ini->enableFWLogging);
Mihir Shetebe94ebb2015-05-26 12:07:14 +053015841}
Sravan Kumar Kairam1d5bf8e2019-03-21 00:33:56 +053015842
Mihir Shetebe94ebb2015-05-26 12:07:14 +053015843/*
Agarwal Ashish57e84372014-12-05 18:26:53 +053015844 * API to find if there is any session connected
15845 */
15846VOS_STATUS hdd_is_any_session_connected(hdd_context_t *pHddCtx)
15847{
15848 return sme_is_any_session_connected(pHddCtx->hHal);
15849}
15850
15851
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015852int wlan_hdd_scan_abort(hdd_adapter_t *pAdapter)
15853{
15854 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
15855 hdd_scaninfo_t *pScanInfo = NULL;
Girish Gowli4bf7a632014-06-12 13:42:11 +053015856 long status = 0;
c_hpothua3d45d52015-01-05 14:11:17 +053015857 tSirAbortScanStatus abortScanStatus;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015858
15859 pScanInfo = &pHddCtx->scan_info;
Ratnam Rachuric7681132015-06-30 10:35:13 +053015860 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015861 if (pScanInfo->mScanPending)
15862 {
c_hpothua3d45d52015-01-05 14:11:17 +053015863 abortScanStatus = hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
15864 eCSR_SCAN_ABORT_DEFAULT);
15865 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
15866 FL("abortScanStatus: %d"), abortScanStatus);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015867
c_hpothua3d45d52015-01-05 14:11:17 +053015868 /* If there is active scan command lets wait for the completion else
15869 * there is no need to wait as scan command might be in the SME pending
15870 * command list.
15871 */
15872 if (abortScanStatus == eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY)
15873 {
Mukul Sharmab392b642017-08-17 17:45:29 +053015874 status = wait_for_completion_timeout(
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015875 &pScanInfo->abortscan_event_var,
15876 msecs_to_jiffies(5000));
c_hpothua3d45d52015-01-05 14:11:17 +053015877 if (0 >= status)
15878 {
15879 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Girish Gowli4bf7a632014-06-12 13:42:11 +053015880 "%s: Timeout or Interrupt occurred while waiting for abort"
15881 "scan, status- %ld", __func__, status);
c_hpothua3d45d52015-01-05 14:11:17 +053015882 return -ETIMEDOUT;
15883 }
15884 }
15885 else if (abortScanStatus == eSIR_ABORT_SCAN_FAILURE)
15886 {
15887 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
15888 FL("hdd_abort_mac_scan failed"));
15889 return -VOS_STATUS_E_FAILURE;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015890 }
15891 }
Girish Gowli4bf7a632014-06-12 13:42:11 +053015892 return 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053015893}
15894
Abhishek Singh7d624e12015-11-30 14:29:27 +053015895/**
15896 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
15897 * user space
15898 * @frame_ind: Management frame data to be informed.
15899 *
15900 * This function is used to indicate management frame to
15901 * user space
15902 *
15903 * Return: None
15904 *
15905 */
15906void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
15907{
15908 hdd_context_t *hdd_ctx = NULL;
15909 hdd_adapter_t *adapter = NULL;
15910 v_CONTEXT_t vos_context = NULL;
Pragaspathi Thilagaraj4aa58d52019-05-27 18:35:26 +053015911 struct ieee80211_mgmt *mgmt =
15912 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Abhishek Singh7d624e12015-11-30 14:29:27 +053015913
15914 /* Get the global VOSS context.*/
15915 vos_context = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
15916 if (!vos_context) {
15917 hddLog(LOGE, FL("Global VOS context is Null"));
15918 return;
15919 }
15920 /* Get the HDD context.*/
15921 hdd_ctx =
15922 (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, vos_context );
15923
15924 if (0 != wlan_hdd_validate_context(hdd_ctx))
15925 {
15926 return;
15927 }
Pragaspathi Thilagaraj4aa58d52019-05-27 18:35:26 +053015928
15929 if (frame_ind->frameLen < ieee80211_hdrlen(mgmt->frame_control)) {
15930 hddLog(LOGE, FL(" Invalid frame length"));
15931 return;
15932 }
15933
Abhishek Singh7d624e12015-11-30 14:29:27 +053015934 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
15935 frame_ind->sessionId);
15936
15937 if ((NULL != adapter) &&
15938 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
15939 __hdd_indicate_mgmt_frame(adapter,
15940 frame_ind->frameLen,
15941 frame_ind->frameBuf,
15942 frame_ind->frameType,
15943 frame_ind->rxChan,
15944 frame_ind->rxRssi);
15945 return;
15946
15947}
15948
c_hpothu225aa7c2014-10-22 17:45:13 +053015949VOS_STATUS wlan_hdd_cancel_remain_on_channel(hdd_context_t *pHddCtx)
15950{
15951 hdd_adapter_t *pAdapter;
15952 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15953 VOS_STATUS vosStatus;
15954
15955 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
15956 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
15957 {
15958 pAdapter = pAdapterNode->pAdapter;
15959 if (NULL != pAdapter)
15960 {
15961 if (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode ||
15962 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
15963 WLAN_HDD_P2P_GO == pAdapter->device_mode)
15964 {
15965 hddLog(LOG1, FL("abort ROC deviceMode: %d"),
15966 pAdapter->device_mode);
15967 if (VOS_STATUS_SUCCESS !=
15968 wlan_hdd_cancel_existing_remain_on_channel(pAdapter))
15969 {
15970 hddLog(LOGE, FL("failed to abort ROC"));
15971 return VOS_STATUS_E_FAILURE;
15972 }
15973 }
15974 }
15975 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
15976 pAdapterNode = pNext;
15977 }
15978 return VOS_STATUS_SUCCESS;
15979}
Mahesh A Saptasagard477b092015-02-06 15:12:16 +053015980
Mihir Shete0be28772015-02-17 18:42:14 +053015981hdd_remain_on_chan_ctx_t *hdd_get_remain_on_channel_ctx(hdd_context_t *pHddCtx)
15982{
15983 hdd_adapter_t *pAdapter;
15984 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
15985 hdd_cfg80211_state_t *cfgState;
15986 hdd_remain_on_chan_ctx_t *pRemainChanCtx = NULL;
15987 VOS_STATUS vosStatus;
15988
15989 vosStatus = hdd_get_front_adapter (pHddCtx, &pAdapterNode);
15990 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
15991 {
15992 pAdapter = pAdapterNode->pAdapter;
15993 if (NULL != pAdapter)
15994 {
15995 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter);
15996 pRemainChanCtx = cfgState->remain_on_chan_ctx;
15997 if (pRemainChanCtx)
15998 break;
15999 }
16000 vosStatus = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
16001 pAdapterNode = pNext;
16002 }
16003 return pRemainChanCtx;
16004}
16005
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +053016006/**
16007 * wlan_hdd_handle_dfs_chan_scan () - handles disable/enable DFS channels
16008 *
16009 * @pHddCtx: HDD context within host driver
16010 * @dfsScanMode: dfsScanMode passed from ioctl
16011 *
16012 */
16013
16014VOS_STATUS wlan_hdd_handle_dfs_chan_scan(hdd_context_t *pHddCtx,
16015 tANI_U8 dfsScanMode)
16016{
16017 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
16018 hdd_adapter_t *pAdapter;
16019 VOS_STATUS vosStatus;
16020 hdd_station_ctx_t *pHddStaCtx;
16021 eHalStatus status = eHAL_STATUS_SUCCESS;
16022
16023 if(!pHddCtx)
16024 {
16025 hddLog(LOGE, FL("HDD context is Null"));
16026 return eHAL_STATUS_FAILURE;
16027 }
16028
16029 if (pHddCtx->scan_info.mScanPending)
16030 {
16031 hddLog(LOG1, FL("Aborting scan for sessionId: %d"),
16032 pHddCtx->scan_info.sessionId);
16033 hdd_abort_mac_scan(pHddCtx,
16034 pHddCtx->scan_info.sessionId,
16035 eCSR_SCAN_ABORT_DEFAULT);
16036 }
16037
16038 if (!dfsScanMode)
16039 {
16040 vosStatus = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
16041 while ((NULL != pAdapterNode) &&
16042 (VOS_STATUS_SUCCESS == vosStatus))
16043 {
16044 pAdapter = pAdapterNode->pAdapter;
16045
16046 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
16047 {
16048 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
16049
16050 if(!pHddStaCtx)
16051 {
16052 hddLog(LOGE, FL("HDD STA context is Null"));
16053 return eHAL_STATUS_FAILURE;
16054 }
16055
16056 /* if STA is already connected on DFS channel,
16057 disconnect immediately*/
16058 if (hdd_connIsConnected(pHddStaCtx) &&
16059 (NV_CHANNEL_DFS ==
16060 vos_nv_getChannelEnabledState(
16061 pHddStaCtx->conn_info.operationChannel)))
16062 {
16063 status = sme_RoamDisconnect(pHddCtx->hHal,
16064 pAdapter->sessionId,
16065 eCSR_DISCONNECT_REASON_UNSPECIFIED);
16066 hddLog(LOG1, FL("Client connected on DFS channel %d,"
16067 "sme_RoamDisconnect returned with status: %d"
16068 "for sessionid: %d"), pHddStaCtx->conn_info.
16069 operationChannel, status, pAdapter->sessionId);
16070 }
16071 }
16072
16073 vosStatus = hdd_get_next_adapter(pHddCtx, pAdapterNode,
16074 &pNext);
16075 pAdapterNode = pNext;
16076 }
16077 }
16078
16079 sme_UpdateDFSScanMode(pHddCtx->hHal, dfsScanMode);
16080 sme_UpdateDFSRoamMode(pHddCtx->hHal,
16081 (dfsScanMode != DFS_CHNL_SCAN_DISABLED));
16082
16083 status = sme_HandleDFSChanScan(pHddCtx->hHal);
16084 if (!HAL_STATUS_SUCCESS(status))
16085 {
16086 hddLog(LOGE,
16087 FL("Failed in sme_HandleDFSChanScan (err=%d)"), status);
16088 return status;
16089 }
16090
16091 return status;
16092}
16093
Nirav Shah7e3c8132015-06-22 23:51:42 +053016094static int hdd_log2_ceil(unsigned value)
16095{
16096 /* need to switch to unsigned math so that negative values
16097 * will right-shift towards 0 instead of -1
16098 */
16099 unsigned tmp = value;
16100 int log2 = -1;
16101
16102 if (value == 0)
16103 return 0;
16104
16105 while (tmp) {
16106 log2++;
16107 tmp >>= 1;
16108 }
16109 if (1U << log2 != value)
16110 log2++;
16111
16112 return log2;
16113}
16114
16115/**
16116 * hdd_sta_id_hash_attach() - initialize sta id to macaddr hash
16117 * @pAdapter: adapter handle
16118 *
16119 * Return: vos status
16120 */
16121VOS_STATUS hdd_sta_id_hash_attach(hdd_adapter_t *pAdapter)
16122{
16123 int hash_elem, log2, i;
16124
16125 spin_lock_bh( &pAdapter->sta_hash_lock);
16126 if (pAdapter->is_sta_id_hash_initialized == VOS_TRUE) {
16127 spin_unlock_bh( &pAdapter->sta_hash_lock);
16128 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16129 "%s: hash already attached for session id %d",
16130 __func__, pAdapter->sessionId);
16131 return VOS_STATUS_SUCCESS;
16132 }
16133 spin_unlock_bh( &pAdapter->sta_hash_lock);
16134
16135 hash_elem = WLAN_MAX_STA_COUNT;
16136 hash_elem *= HDD_STA_ID_HASH_MULTIPLIER;
16137 log2 = hdd_log2_ceil(hash_elem);
16138 hash_elem = 1 << log2;
16139
16140 pAdapter->sta_id_hash.mask = hash_elem - 1;
16141 pAdapter->sta_id_hash.idx_bits = log2;
16142 pAdapter->sta_id_hash.bins =
16143 vos_mem_malloc(hash_elem *sizeof(hdd_list_t));
16144 if (!pAdapter->sta_id_hash.bins) {
16145 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16146 "%s: malloc failed for session %d",
16147 __func__, pAdapter->sessionId);
16148 return VOS_STATUS_E_NOMEM;
16149 }
16150
16151 for (i = 0; i < hash_elem; i++)
16152 hdd_list_init(&pAdapter->sta_id_hash.bins[i], WLAN_MAX_STA_COUNT);
16153
16154 spin_lock_bh( &pAdapter->sta_hash_lock);
16155 pAdapter->is_sta_id_hash_initialized = VOS_TRUE;
16156 spin_unlock_bh( &pAdapter->sta_hash_lock);
16157 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16158 "%s: Station ID Hash attached for session id %d",
16159 __func__, pAdapter->sessionId);
16160
16161 return VOS_STATUS_SUCCESS;
16162}
16163
16164/**
16165 * hdd_sta_id_hash_detach() - deinit sta_id to macaddr hash
16166 * @pAdapter: adapter handle
16167 *
16168 * Return: vos status
16169 */
16170VOS_STATUS hdd_sta_id_hash_detach(hdd_adapter_t *pAdapter)
16171{
16172 int hash_elem, i;
16173 v_SIZE_t size;
16174
16175 spin_lock_bh( &pAdapter->sta_hash_lock);
16176 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16177 spin_unlock_bh( &pAdapter->sta_hash_lock);
16178 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16179 "%s: hash not initialized for session id %d",
16180 __func__, pAdapter->sessionId);
16181 return VOS_STATUS_SUCCESS;
16182 }
16183
16184 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
16185 spin_unlock_bh( &pAdapter->sta_hash_lock);
16186
16187 hash_elem = 1 << pAdapter->sta_id_hash.idx_bits;
16188
16189 /* free all station info*/
16190 for (i = 0; i < hash_elem; i++) {
16191 hdd_list_size(&pAdapter->sta_id_hash.bins[i], &size);
16192 if (size != 0) {
16193 VOS_STATUS status;
16194 hdd_staid_hash_node_t *sta_info_node = NULL;
16195 hdd_staid_hash_node_t *next_node = NULL;
16196 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[i],
16197 (hdd_list_node_t**) &sta_info_node );
16198
16199 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16200 {
16201 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[i],
16202 &sta_info_node->node);
16203 vos_mem_free(sta_info_node);
16204
16205 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[i],
16206 (hdd_list_node_t*)sta_info_node,
16207 (hdd_list_node_t**)&next_node);
16208 sta_info_node = next_node;
16209 }
16210 }
16211 }
16212
16213 vos_mem_free(pAdapter->sta_id_hash.bins);
16214 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16215 "%s: Station ID Hash detached for session id %d",
16216 __func__, pAdapter->sessionId);
16217 return VOS_STATUS_SUCCESS;
16218}
16219
16220/**
16221 * hdd_sta_id_hash_calculate_index() - derive index from macaddr
16222 * @pAdapter: adapter handle
16223 * @mac_addr_in: input mac address
16224 *
16225 * Return: index derived from mac address
16226 */
16227int hdd_sta_id_hash_calculate_index(hdd_adapter_t *pAdapter,
16228 v_MACADDR_t *mac_addr_in)
16229{
16230 uint16 index;
16231 struct hdd_align_mac_addr_t * mac_addr =
16232 (struct hdd_align_mac_addr_t *)mac_addr_in;
16233
16234 index = mac_addr->bytes_ab ^
16235 mac_addr->bytes_cd ^ mac_addr->bytes_ef;
16236 index ^= index >> pAdapter->sta_id_hash.idx_bits;
16237 index &= pAdapter->sta_id_hash.mask;
16238 return index;
16239}
16240
16241/**
16242 * hdd_sta_id_hash_add_entry() - add entry in hash
16243 * @pAdapter: adapter handle
16244 * @sta_id: station id
16245 * @mac_addr: mac address
16246 *
16247 * Return: vos status
16248 */
16249VOS_STATUS hdd_sta_id_hash_add_entry(hdd_adapter_t *pAdapter,
16250 v_U8_t sta_id, v_MACADDR_t *mac_addr)
16251{
16252 uint16 index;
16253 hdd_staid_hash_node_t *sta_info_node = NULL;
16254
Nirav Shah7e3c8132015-06-22 23:51:42 +053016255 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
16256 sta_info_node = vos_mem_malloc(sizeof(hdd_staid_hash_node_t));
16257 if (!sta_info_node) {
Nirav Shah7e3c8132015-06-22 23:51:42 +053016258 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16259 "%s: malloc failed", __func__);
16260 return VOS_STATUS_E_NOMEM;
16261 }
16262
16263 sta_info_node->sta_id = sta_id;
16264 vos_mem_copy(&sta_info_node->mac_addr, mac_addr, sizeof(v_MACADDR_t));
16265
Nirav Shah303ed5c2015-08-24 10:29:25 +053016266 spin_lock_bh( &pAdapter->sta_hash_lock);
16267 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16268 spin_unlock_bh( &pAdapter->sta_hash_lock);
16269 vos_mem_free(sta_info_node);
16270 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
16271 "%s: hash is not initialized for session id %d",
16272 __func__, pAdapter->sessionId);
16273 return VOS_STATUS_E_FAILURE;
16274 }
16275
Nirav Shah7e3c8132015-06-22 23:51:42 +053016276 hdd_list_insert_back ( &pAdapter->sta_id_hash.bins[index],
16277 (hdd_list_node_t*) sta_info_node );
16278 spin_unlock_bh( &pAdapter->sta_hash_lock);
16279 return VOS_STATUS_SUCCESS;
16280}
16281
16282/**
16283 * hdd_sta_id_hash_remove_entry() - remove entry from hash
16284 * @pAdapter: adapter handle
16285 * @sta_id: station id
16286 * @mac_addr: mac address
16287 *
16288 * Return: vos status
16289 */
16290VOS_STATUS hdd_sta_id_hash_remove_entry(hdd_adapter_t *pAdapter,
16291 v_U8_t sta_id, v_MACADDR_t *mac_addr)
16292{
16293 uint16 index;
16294 VOS_STATUS status;
16295 hdd_staid_hash_node_t *sta_info_node = NULL;
16296 hdd_staid_hash_node_t *next_node = NULL;
16297
16298 spin_lock_bh( &pAdapter->sta_hash_lock);
16299 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16300 spin_unlock_bh( &pAdapter->sta_hash_lock);
16301 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
16302 "%s: hash is not initialized for session id %d",
16303 __func__, pAdapter->sessionId);
16304 return VOS_STATUS_E_FAILURE;
16305 }
16306
16307 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
16308 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
16309 (hdd_list_node_t**) &sta_info_node );
16310
16311 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16312 {
16313 if (sta_info_node->sta_id == sta_id) {
16314 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[index],
16315 &sta_info_node->node);
16316 vos_mem_free(sta_info_node);
16317 break;
16318 }
16319 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
16320 (hdd_list_node_t*)sta_info_node, (hdd_list_node_t**)&next_node);
16321 sta_info_node = next_node;
16322 }
16323 spin_unlock_bh( &pAdapter->sta_hash_lock);
16324 return status;
16325}
16326
16327/**
16328 * hdd_sta_id_find_from_mac_addr() - find sta id from mac address
16329 * @pAdapter: adapter handle
16330 * @mac_addr_in: mac address
16331 *
16332 * Return: station id
16333 */
16334int hdd_sta_id_find_from_mac_addr(hdd_adapter_t *pAdapter,
16335 v_MACADDR_t *mac_addr_in)
16336{
16337 uint8 is_found = 0;
16338 uint8 sta_id = HDD_WLAN_INVALID_STA_ID;
16339 uint16 index;
16340 VOS_STATUS status;
16341 hdd_staid_hash_node_t *sta_info_node = NULL;
16342 hdd_staid_hash_node_t *next_node = NULL;
16343
16344 spin_lock_bh( &pAdapter->sta_hash_lock);
16345 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
16346 spin_unlock_bh( &pAdapter->sta_hash_lock);
Bhargav Shahce3b32c2015-08-10 12:29:24 +053016347 hddLog(VOS_TRACE_LEVEL_INFO,
Nirav Shah7e3c8132015-06-22 23:51:42 +053016348 FL("hash is not initialized for session id %d"),
16349 pAdapter->sessionId);
16350 return HDD_WLAN_INVALID_STA_ID;
16351 }
16352
16353 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr_in);
16354 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
16355 (hdd_list_node_t**) &sta_info_node );
16356
16357 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
16358 {
16359 if (vos_mem_compare(&sta_info_node->mac_addr,
16360 mac_addr_in, sizeof(v_MACADDR_t))) {
16361 is_found = 1;
16362 sta_id = sta_info_node->sta_id;
16363 break;
16364 }
16365 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
16366 (hdd_list_node_t*)sta_info_node,
16367 (hdd_list_node_t**)&next_node);
16368 sta_info_node = next_node;
16369 }
16370 spin_unlock_bh( &pAdapter->sta_hash_lock);
16371 return sta_id;
16372}
16373
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053016374void hdd_initialize_adapter_common(hdd_adapter_t *pAdapter)
16375{
16376 if (NULL == pAdapter)
16377 {
16378 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL ", __func__);
16379 return;
16380 }
16381 init_completion(&pAdapter->session_open_comp_var);
16382 init_completion(&pAdapter->session_close_comp_var);
16383 init_completion(&pAdapter->disconnect_comp_var);
16384 init_completion(&pAdapter->linkup_event_var);
16385 init_completion(&pAdapter->cancel_rem_on_chan_var);
16386 init_completion(&pAdapter->rem_on_chan_ready_event);
16387 init_completion(&pAdapter->pno_comp_var);
16388#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
16389 init_completion(&pAdapter->offchannel_tx_event);
16390#endif
16391 init_completion(&pAdapter->tx_action_cnf_event);
16392#ifdef FEATURE_WLAN_TDLS
16393 init_completion(&pAdapter->tdls_add_station_comp);
16394 init_completion(&pAdapter->tdls_del_station_comp);
16395 init_completion(&pAdapter->tdls_mgmt_comp);
16396 init_completion(&pAdapter->tdls_link_establish_req_comp);
16397#endif
16398
16399#ifdef WLAN_FEATURE_RMC
16400 init_completion(&pAdapter->ibss_peer_info_comp);
16401#endif /* WLAN_FEATURE_RMC */
16402 init_completion(&pAdapter->ula_complete);
16403 init_completion(&pAdapter->change_country_code);
16404
16405#ifdef FEATURE_WLAN_BATCH_SCAN
16406 init_completion(&pAdapter->hdd_set_batch_scan_req_var);
16407 init_completion(&pAdapter->hdd_get_batch_scan_req_var);
16408#endif
Kapil Gupta2b44acb2016-12-30 16:49:51 +053016409 init_completion(&pAdapter->wlan_suspend_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053016410
16411 return;
16412}
c_manjeecfd1efb2015-09-25 19:32:34 +053016413
Anurag Chouhan0b29de02016-12-16 13:18:40 +053016414#ifdef MDNS_OFFLOAD
16415
16416/**
16417 * hdd_mdns_enable_offload_done() - mdns enable offload response api
16418 * @padapter: holds adapter
16419 * @status: response status
16420 *
16421 * Return - None
16422 */
16423void hdd_mdns_enable_offload_done(void *padapter, VOS_STATUS status)
16424{
16425 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16426
16427 ENTER();
16428
16429 if (NULL == adapter)
16430 {
16431 hddLog(VOS_TRACE_LEVEL_ERROR,
16432 "%s: adapter is NULL",__func__);
16433 return;
16434 }
16435
16436 adapter->mdns_status.mdns_enable_status = status;
16437 vos_event_set(&adapter->mdns_status.vos_event);
16438 return;
16439}
16440
16441/**
16442 * hdd_mdns_fqdn_offload_done() - mdns fqdn offload response api
16443 * @padapter: holds adapter
16444 * @status: responce status
16445 *
16446 * Return - None
16447 */
16448void hdd_mdns_fqdn_offload_done(void *padapter, VOS_STATUS status)
16449{
16450 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16451
16452 ENTER();
16453
16454 if (NULL == adapter)
16455 {
16456 hddLog(VOS_TRACE_LEVEL_ERROR,
16457 "%s: adapter is NULL",__func__);
16458 return;
16459 }
16460
16461 adapter->mdns_status.mdns_fqdn_status = status;
16462 return;
16463}
16464
16465/**
16466 * hdd_mdns_resp_offload_done() - mdns resp offload response api
16467 * @padapter: holds adapter
16468 * @status: responce status
16469 *
16470 * Return - None
16471 */
16472void hdd_mdns_resp_offload_done(void *padapter, VOS_STATUS status)
16473{
16474 hdd_adapter_t* adapter = (hdd_adapter_t*) padapter;
16475
16476 ENTER();
16477
16478 if (NULL == adapter)
16479 {
16480 hddLog(VOS_TRACE_LEVEL_ERROR,
16481 "%s: adapter is NULL",__func__);
16482 return;
16483 }
16484
16485 adapter->mdns_status.mdns_resp_status = status;
16486 return;
16487}
16488
16489/**
16490 * wlan_hdd_mdns_process_response_dname() - Process mDNS domain name
16491 * @response: Pointer to a struct hdd_mdns_resp_info
16492 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16493 *
16494 * This function will pack the whole domain name without compression. It will
16495 * add the leading len for each field and add zero length octet to terminate
16496 * the domain name.
16497 *
16498 * Return: Return boolean. TRUE for success, FALSE for fail.
16499 */
16500static bool
16501wlan_hdd_mdns_process_response_dname(struct hdd_mdns_resp_info *response,
16502 sir_mdns_resp_info resp_info)
16503{
16504 uint8_t num;
16505 uint16_t idx;
16506 uint8_t len = 0;
16507
16508 if ((response == NULL) || (response->data == NULL) ||
16509 (response->offset == NULL)) {
16510 hddLog(LOGE, FL("Either data or offset in response is NULL!"));
16511 return FALSE;
16512 }
16513
16514 if ((resp_info == NULL) ||
16515 (resp_info->resp_len >= MAX_MDNS_RESP_LEN)) {
16516 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16517 return FALSE;
16518 }
16519
16520 for (num = 0; num < response->num_entries; num++) {
16521 response->offset[num] =
16522 resp_info->resp_len + MDNS_HEADER_LEN;
16523 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16524 len = strlen((char *)&response->data[idx]);
16525 if ((resp_info->resp_len + len + 1) >= MAX_MDNS_RESP_LEN) {
16526 hddLog(LOGE, FL("resp_len exceeds %d!"),
16527 MAX_MDNS_RESP_LEN);
16528 return FALSE;
16529 }
16530 resp_info->resp_data[resp_info->resp_len] = len;
16531 resp_info->resp_len++;
16532 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16533 &response->data[idx], len);
16534 resp_info->resp_len += len;
16535 }
16536
16537 /* The domain name terminates with the zero length octet */
16538 if (num == response->num_entries) {
16539 if (resp_info->resp_len >= MAX_MDNS_RESP_LEN) {
16540 hddLog(LOGE, FL("resp_len exceeds %d!"),
16541 MAX_MDNS_RESP_LEN);
16542 return FALSE;
16543 }
16544 resp_info->resp_data[resp_info->resp_len] = 0;
16545 resp_info->resp_len++;
16546 }
16547
16548 return TRUE;
16549}
16550
16551/**
16552 * wlan_hdd_mdns_format_response_u16() - Form uint16_t response data
16553 * @value: The uint16_t value is formed to the struct tSirMDNSResponseInfo
16554 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16555 *
16556 * Return: None
16557 */
16558static void wlan_hdd_mdns_format_response_u16(uint16_t value,
16559 sir_mdns_resp_info resp_info)
16560{
16561 uint8_t val_u8;
16562
16563 if ((resp_info == NULL) || (resp_info->resp_data == NULL))
16564 return;
16565 val_u8 = (value & 0xff00) >> 8;
16566 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16567 val_u8 = value & 0xff;
16568 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16569}
16570
16571/**
16572 * wlan_hdd_mdns_format_response_u32() - Form uint32_t response data
16573 * @value: The uint32_t value is formed to the struct tSirMDNSResponseInfo
16574 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16575 *
16576 * Return: None
16577 */
16578static void wlan_hdd_mdns_format_response_u32(uint32_t value,
16579 sir_mdns_resp_info resp_info)
16580{
16581 uint8_t val_u8;
16582
16583 if ((resp_info == NULL) || (resp_info->resp_data == NULL))
16584 return;
16585 val_u8 = (value & 0xff000000) >> 24;
16586 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16587 val_u8 = (value & 0xff0000) >> 16;
16588 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16589 val_u8 = (value & 0xff00) >> 8;
16590 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16591 val_u8 = value & 0xff;
16592 resp_info->resp_data[resp_info->resp_len++] = val_u8;
16593}
16594
16595/**
16596 * wlan_hdd_mdns_process_response_misc() - Process misc info in mDNS response
16597 * @resp_type: Response type for mDNS
16598 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16599 *
16600 * This function will pack the response type, class and TTL (Time To Live).
16601 *
16602 * Return: Return boolean. TRUE for success, FALSE for fail.
16603 */
16604static bool wlan_hdd_mdns_process_response_misc(uint16_t resp_type,
16605 sir_mdns_resp_info resp_info)
16606{
16607 uint16_t len;
16608
16609 if (resp_info == NULL) {
16610 hddLog(LOGE, FL("resp_info is NULL!"));
16611 return FALSE;
16612 }
16613
16614 len = resp_info->resp_len + (2 * sizeof(uint16_t) + sizeof(uint32_t));
16615 if (len >= MAX_MDNS_RESP_LEN) {
16616 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16617 return FALSE;
16618 }
16619
16620 /* Fill Type, Class, TTL */
16621 wlan_hdd_mdns_format_response_u16(resp_type, resp_info);
16622 wlan_hdd_mdns_format_response_u16(MDNS_CLASS, resp_info);
16623 wlan_hdd_mdns_format_response_u32(MDNS_TTL, resp_info);
16624
16625 return TRUE;
16626}
16627
16628/**
16629 * wlan_hdd_mdns_compress_data() - Compress the domain name in mDNS response
16630 * @resp_info: Pointer to a struct tSirMDNSResponseInfo
16631 * @response_dst: The response which domain name is compressed.
16632 * @response_src: The response which domain name is matched with response_dst.
16633 * Its offset is used for data compression.
16634 * @num_matched: The number of matched entries between response_dst and
16635 * response_src
16636 *
16637 * This function will form the different fields of domain name in response_dst
16638 * if any. Then use the offset of the matched domain name in response_src to
16639 * compress the matched domain name.
16640 *
16641 * Return: Return boolean. TRUE for success, FALSE for fail.
16642 */
16643static bool
16644wlan_hdd_mdns_compress_data(sir_mdns_resp_info resp_info,
16645 struct hdd_mdns_resp_info *response_dst,
16646 struct hdd_mdns_resp_info *response_src,
16647 uint8_t num_matched)
16648{
16649 uint8_t num, num_diff;
16650 uint16_t value, idx;
16651 uint8_t len = 0;
16652
16653 if ((response_src == NULL) || (response_dst == NULL) ||
16654 (resp_info == NULL)) {
16655 hddLog(LOGE, FL("response info is NULL!"));
16656 return FALSE;
16657 }
16658
16659 if (response_dst->num_entries < num_matched) {
16660 hddLog(LOGE, FL("num_entries is less than num_matched!"));
16661 return FALSE;
16662 }
16663
16664 if (resp_info->resp_len >= MAX_MDNS_RESP_LEN) {
16665 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16666 return FALSE;
16667 }
16668
16669 num_diff = response_dst->num_entries - num_matched;
16670 if ((num_diff > 0) && (response_dst->data == NULL)) {
16671 hddLog(LOGE, FL("response_dst->data is NULL!"));
16672 return FALSE;
16673 }
16674
16675 /*
16676 * Handle the unmatched string at the beginning
16677 * Store the length of octets and the octets
16678 */
16679 for (num = 0; num < num_diff; num++) {
16680 response_dst->offset[num] =
16681 resp_info->resp_len + MDNS_HEADER_LEN;
16682 idx = num * MAX_LEN_DOMAINNAME_FIELD;
16683 len = strlen((char *)&response_dst->data[idx]);
16684 if ((resp_info->resp_len + len + 1) >= MAX_MDNS_RESP_LEN) {
16685 hddLog(LOGE, FL("resp_len exceeds %d!"),
16686 MAX_MDNS_RESP_LEN);
16687 return FALSE;
16688 }
16689 resp_info->resp_data[resp_info->resp_len] = len;
16690 resp_info->resp_len++;
16691 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
16692 &response_dst->data[idx], len);
16693 resp_info->resp_len += len;
16694 }
16695 /*
16696 * Handle the matched string from the end
16697 * Just keep the offset and mask the leading two bit
16698 */
16699 if (response_src->num_entries >= num_matched) {
16700 num_diff = response_src->num_entries - num_matched;
16701 value = response_src->offset[num_diff];
16702 if (value > 0) {
16703 value |= 0xc000;
16704 if ((resp_info->resp_len + sizeof(uint16_t)) >=
16705 MAX_MDNS_RESP_LEN) {
16706 hddLog(LOGE, FL("resp_len exceeds %d!"),
16707 MAX_MDNS_RESP_LEN);
16708 return FALSE;
16709 }
16710 wlan_hdd_mdns_format_response_u16(value, resp_info);
16711 return TRUE;
16712 }
16713 }
16714 return FALSE;
16715}
16716
16717/**
16718 * wlan_hdd_mdns_reset_response() - Reset the response info
16719 * @response: The response which info is reset.
16720 *
16721 * Return: None
16722 */
16723static void wlan_hdd_mdns_reset_response(struct hdd_mdns_resp_info *response)
16724{
16725 if (response == NULL)
16726 return;
16727 response->num_entries = 0;
16728 response->data = NULL;
16729 response->offset = NULL;
16730}
16731
16732/**
16733 * wlan_hdd_mdns_init_response() - Initialize the response info
16734 * @response: The response which info is initiatized.
16735 * @resp_dname: The domain name string which might be tokenized.
16736 *
16737 * This function will allocate the memory for both response->data and
16738 * response->offset. Besides, it will also tokenize the domain name to some
16739 * entries and fill response->num_entries with the num of entries.
16740 *
16741 * Return: Return boolean. TRUE for success, FALSE for fail.
16742 */
16743static bool wlan_hdd_mdns_init_response(struct hdd_mdns_resp_info *response,
16744 uint8_t *resp_dname, char separator)
16745{
16746 uint16_t size;
16747
16748 if ((resp_dname == NULL) || (response == NULL)) {
16749 hddLog(LOGE, FL("resp_dname or response is NULL!"));
16750 return FALSE;
16751 }
16752
16753 size = MAX_NUM_FIELD_DOMAINNAME * MAX_LEN_DOMAINNAME_FIELD;
16754 response->data = vos_mem_malloc(size);
16755 if (response->data) {
16756 vos_mem_zero(response->data, size);
16757 if (VOS_STATUS_SUCCESS !=
16758 hdd_string_to_string_array((char *)resp_dname,
16759 response->data,
16760 separator,
16761 &response->num_entries,
16762 MAX_NUM_FIELD_DOMAINNAME,
16763 MAX_LEN_DOMAINNAME_FIELD)) {
16764 hddLog(LOGE, FL("hdd_string_to_string_array fail!"));
16765 goto err_init_resp;
16766 }
16767
16768 if ((response->num_entries > 0) &&
16769 (strlen((char *)&response->data[0]) > 0)) {
16770 size = sizeof(uint16_t) * response->num_entries;
16771 response->offset = vos_mem_malloc(size);
16772 if (response->offset) {
16773 vos_mem_zero(response->offset, size);
16774 return TRUE;
16775 }
16776 }
16777 }
16778
16779err_init_resp:
16780 if (response->data)
16781 vos_mem_free(response->data);
16782 wlan_hdd_mdns_reset_response(response);
16783 return FALSE;
16784}
16785
16786/**
16787 * wlan_hdd_mdns_find_entries_from_end() - Find the matched entries
16788 * @response1: The response info is used to be compared.
16789 * @response2: The response info is used to be compared.
16790 *
16791 * This function will find the matched entries from the end.
16792 *
16793 * Return: Return the number of the matched entries.
16794 */
16795static uint8_t
16796wlan_hdd_mdns_find_entries_from_end(struct hdd_mdns_resp_info *response1,
16797 struct hdd_mdns_resp_info *response2)
16798{
16799 uint8_t min, len1, i;
16800 uint16_t num1, num2;
16801 uint8_t num_matched = 0;
16802
16803 min = VOS_MIN(response1->num_entries, response2->num_entries);
16804
16805 for (i = 1; i <= min; i++) {
16806 num1 = (response1->num_entries - i);
16807 num1 *= MAX_LEN_DOMAINNAME_FIELD;
16808 num2 = (response2->num_entries - i);
16809 num2 *= MAX_LEN_DOMAINNAME_FIELD;
16810 len1 = strlen((char *)&response1->data[num1]);
16811
16812 if ((len1 == 0) ||
16813 (len1 != strlen((char *)&response2->data[num2])))
16814 break;
16815 if (memcmp(&response1->data[num1],
16816 &response2->data[num2], len1))
16817 break;
16818 else
16819 num_matched++;
16820 }
16821
16822 return num_matched;
16823}
16824
16825/**
16826 * wlan_hdd_mdns_find_max() - Find the maximum number of the matched entries
16827 * @matchedlist: Pointer to the array of struct hdd_mdns_resp_matched
16828 * @numlist: The number of the elements in the array matchedlist.
16829 *
16830 * Find the max number of the matched entries among the array matchedlist.
16831 *
16832 * Return: None
16833 */
16834static void wlan_hdd_mdns_find_max(struct hdd_mdns_resp_matched *matchedlist,
16835 uint8_t numlist)
16836{
16837 int j;
16838 struct hdd_mdns_resp_matched tmp;
16839
16840 /* At least two values are used for sorting */
16841 if ((numlist < 2) || (matchedlist == NULL)) {
16842 hddLog(LOGE, FL("At least two values are used for sorting!"));
16843 return;
16844 }
16845
16846 for (j = 0; j < numlist-1; j++) {
16847 if (matchedlist[j].num_matched >
16848 matchedlist[j+1].num_matched) {
16849 vos_mem_copy(&tmp, &matchedlist[j],
16850 sizeof(struct hdd_mdns_resp_matched));
16851 vos_mem_copy(&matchedlist[j], &matchedlist[j+1],
16852 sizeof(struct hdd_mdns_resp_matched));
16853 vos_mem_copy(&matchedlist[j+1], &tmp,
16854 sizeof(struct hdd_mdns_resp_matched));
16855 }
16856 }
16857}
16858
16859/**
16860 * wlan_hdd_mdns_pack_response_type_a() - Pack Type A response
16861 * @ini_config: Pointer to the struct hdd_config_t
16862 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16863 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16864 *
16865 * Type A response include QName, response type, class, TTL and Ipv4.
16866 *
16867 * Return: Return boolean. TRUE for success, FALSE for fail.
16868 */
16869static bool
16870wlan_hdd_mdns_pack_response_type_a(hdd_config_t *ini_config,
16871 sir_mdns_resp_info resp_info,
16872 struct hdd_mdns_resp_info *resptype_a)
16873{
16874 uint16_t value;
16875 uint32_t len;
16876
16877 ENTER();
16878 if ((ini_config == NULL) || (resp_info == NULL) ||
16879 (resptype_a == NULL)) {
16880 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16881 return FALSE;
16882 }
16883
16884 /* No Type A response */
16885 if (strlen((char *)ini_config->mdns_resp_type_a) <= 0)
16886 return TRUE;
16887
16888 /* Wrong response is assigned, just ignore this response */
16889 if (!wlan_hdd_mdns_init_response(resptype_a,
16890 ini_config->mdns_resp_type_a, '.'))
16891 return TRUE;
16892
16893 /* Process response domain name */
16894 if (!wlan_hdd_mdns_process_response_dname(resptype_a, resp_info)) {
16895 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
16896 MDNS_TYPE_A);
16897 return FALSE;
16898 }
16899
16900 /* Process response Type, Class, TTL */
16901 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_A, resp_info)) {
16902 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
16903 MDNS_TYPE_A);
16904 return FALSE;
16905 }
16906
16907 /* Process response RDLength, RData */
16908 len = sizeof(uint16_t) + sizeof(uint32_t);
16909 len += resp_info->resp_len;
16910 if (len >= MAX_MDNS_RESP_LEN) {
16911 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
16912 return FALSE;
16913 }
16914 value = sizeof(uint32_t);
16915 wlan_hdd_mdns_format_response_u16(value, resp_info);
16916 wlan_hdd_mdns_format_response_u32(ini_config->mdns_resp_type_a_ipv4,
16917 resp_info);
16918
16919 EXIT();
16920 return TRUE;
16921}
16922
16923/**
16924 * wlan_hdd_mdns_pack_response_type_txt() - Pack Type Txt response
16925 * @ini_config: Pointer to the struct hdd_config_t
16926 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
16927 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type txt
16928 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
16929 *
16930 * Type Txt response include QName, response type, class, TTL and text content.
16931 * Also, it will find the matched QName from resptype_A and compress the data.
16932 *
16933 * Return: Return boolean. TRUE for success, FALSE for fail.
16934 */
16935static bool
16936wlan_hdd_mdns_pack_response_type_txt(hdd_config_t *ini_config,
16937 sir_mdns_resp_info resp_info,
16938 struct hdd_mdns_resp_info *resptype_txt,
16939 struct hdd_mdns_resp_info *resptype_a)
16940{
16941 uint8_t num_matched;
16942 uint8_t num;
16943 uint16_t idx;
16944 uint16_t value = 0;
16945 uint32_t len;
16946 uint32_t total_len;
16947 bool status;
16948 struct hdd_mdns_resp_info resptype_content;
16949
16950 ENTER();
16951
16952 if ((ini_config == NULL) || (resp_info == NULL) ||
16953 (resptype_txt == NULL)) {
16954 hddLog(LOGE, FL("ini_config or response info is NULL!"));
16955 return FALSE;
16956 }
16957
16958 /* No Type Txt response */
16959 if (strlen((char *)ini_config->mdns_resp_type_txt) <= 0)
16960 return TRUE;
16961
16962 /* Wrong response is assigned, just ignore this response */
16963 if (!wlan_hdd_mdns_init_response(resptype_txt,
16964 ini_config->mdns_resp_type_txt, '.'))
16965 return TRUE;
16966
16967 /*
16968 * For data compression
16969 * Check if any strings are matched with Type A response
16970 */
16971 if (resptype_a && (resptype_a->num_entries > 0)) {
16972 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_txt,
16973 resptype_a);
16974 if (num_matched > 0) {
16975 if (!wlan_hdd_mdns_compress_data(resp_info,
16976 resptype_txt, resptype_a, num_matched)) {
16977 hddLog(LOGE, FL("Fail to compress mDNS "
16978 "response (%d)!"), MDNS_TYPE_TXT);
16979 return FALSE;
16980 }
16981 } else {
16982 /*
16983 * num_matched is zero. Error!
16984 * At least ".local" is needed.
16985 */
16986 hddLog(LOGE, FL("No matched string! Fail to pack mDNS "
16987 "response (%d)!"), MDNS_TYPE_TXT);
16988 return FALSE;
16989 }
16990 } else {
16991 /* no TypeA response, so show the whole data */
16992 if (!wlan_hdd_mdns_process_response_dname(resptype_txt,
16993 resp_info)) {
16994 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
16995 MDNS_TYPE_TXT);
16996 return FALSE;
16997 }
16998 }
16999
17000 /* Process response Type, Class, TTL */
17001 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_TXT, resp_info)) {
17002 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17003 MDNS_TYPE_TXT);
17004 return FALSE;
17005 }
17006
17007 /*
17008 * Process response RDLength, RData.
17009 * TypeTxt RData include len.
17010 */
17011 status = wlan_hdd_mdns_init_response(&resptype_content,
17012 ini_config->mdns_resp_type_txt_content,
17013 '/');
17014 if (status == FALSE) {
17015 hddLog(LOGE, FL("wlan_hdd_mdns_init_response FAIL"));
17016 return FALSE;
17017 }
17018
17019 for (num = 0; num < resptype_content.num_entries; num++) {
17020 idx = num * MAX_LEN_DOMAINNAME_FIELD;
17021 value += strlen((char *)&resptype_content.data[idx]);
17022 }
17023
17024 /* content len is uint16_t */
17025 total_len = sizeof(uint16_t);
17026 total_len += resp_info->resp_len + value +
17027 resptype_content.num_entries;
17028
17029 if (total_len >= MAX_MDNS_RESP_LEN) {
17030 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
17031 return FALSE;
17032 }
17033 wlan_hdd_mdns_format_response_u16(value + resptype_content.num_entries,
17034 resp_info);
17035
17036 for (num = 0; num < resptype_content.num_entries; num++) {
17037 idx = num * MAX_LEN_DOMAINNAME_FIELD;
17038 len = strlen((char *)&resptype_content.data[idx]);
17039 resp_info->resp_data[resp_info->resp_len] = len;
17040 resp_info->resp_len++;
17041
17042 vos_mem_copy(&resp_info->resp_data[resp_info->resp_len],
17043 &resptype_content.data[idx], len);
17044
17045 resp_info->resp_len += len;
17046 hddLog(LOG1, FL("index = %d, len = %d, str = %s"),
17047 num, len, &resptype_content.data[idx]);
17048 }
17049
17050 EXIT();
17051 return TRUE;
17052}
17053
17054/**
17055 * wlan_hdd_mdns_pack_response_type_ptr_dname() - Pack Type PTR domain name
17056 * @ini_config: Pointer to the struct hdd_config_t
17057 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17058 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17059 * domain name
17060 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17061 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17062 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17063 *
17064 * The Type Ptr response include Type PTR domain name in its data field.
17065 * Also, it will find the matched QName from the existing resptype_ptr,
17066 * resptype_txt, resptype_a and then compress the data.
17067 *
17068 * Return: Return boolean. TRUE for success, FALSE for fail.
17069 */
17070static bool
17071wlan_hdd_mdns_pack_response_type_ptr_dname(hdd_config_t *ini_config,
17072 sir_mdns_resp_info resp_info,
17073 struct hdd_mdns_resp_info *resptype_ptr_dn,
17074 struct hdd_mdns_resp_info *resptype_ptr,
17075 struct hdd_mdns_resp_info *resptype_txt,
17076 struct hdd_mdns_resp_info *resptype_a)
17077{
17078 uint8_t num_matched, numlist, size;
17079 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17080 struct hdd_mdns_resp_info *resp;
17081
17082 if ((ini_config == NULL) || (resp_info == NULL) ||
17083 (resptype_ptr == NULL) || (resptype_ptr_dn == NULL)) {
17084 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17085 return FALSE;
17086 }
17087
17088 /* No Type Ptr domain name response */
17089 if (strlen((char *)ini_config->mdns_resp_type_ptr_dname) <= 0)
17090 return TRUE;
17091
17092 /* Wrong response is assigned, just ignore this response */
17093 if (!wlan_hdd_mdns_init_response(resptype_ptr_dn,
17094 ini_config->mdns_resp_type_ptr_dname, '.'))
17095 return TRUE;
17096
17097 /*
17098 * For data compression
17099 * Check if any strings are matched with previous
17100 * response.
17101 */
17102 numlist = 0;
17103 size = (MAX_MDNS_RESP_TYPE-1);
17104 size *= sizeof(struct hdd_mdns_resp_matched);
17105 vos_mem_zero(matchedlist, size);
17106 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_ptr_dn,
17107 resptype_ptr);
17108 if (num_matched > 0) {
17109 matchedlist[numlist].num_matched = num_matched;
17110 matchedlist[numlist].type = MDNS_TYPE_PTR;
17111 numlist++;
17112 }
17113 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17114 num_matched = wlan_hdd_mdns_find_entries_from_end(
17115 resptype_ptr_dn, resptype_txt);
17116 if (num_matched > 0) {
17117 matchedlist[numlist].num_matched = num_matched;
17118 matchedlist[numlist].type = MDNS_TYPE_TXT;
17119 numlist++;
17120 }
17121 }
17122 if (resptype_a && (resptype_a->num_entries > 0)) {
17123 num_matched = wlan_hdd_mdns_find_entries_from_end(
17124 resptype_ptr_dn,resptype_a);
17125 if (num_matched > 0) {
17126 matchedlist[numlist].num_matched = num_matched;
17127 matchedlist[numlist].type = MDNS_TYPE_A;
17128 numlist++;
17129 }
17130 }
17131 if (numlist > 0) {
17132 if (numlist > 1)
17133 wlan_hdd_mdns_find_max(matchedlist, numlist);
17134 resp = NULL;
17135 switch (matchedlist[numlist-1].type) {
17136 case MDNS_TYPE_A:
17137 resp = resptype_a;
17138 break;
17139 case MDNS_TYPE_TXT:
17140 resp = resptype_txt;
17141 break;
17142 case MDNS_TYPE_PTR:
17143 resp = resptype_ptr;
17144 break;
17145 default:
17146 hddLog(LOGE, FL("Fail to compress mDNS response "
17147 "(%d)!"), MDNS_TYPE_PTR_DNAME);
17148 return FALSE;
17149 }
17150 num_matched = matchedlist[numlist-1].num_matched;
17151 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_ptr_dn,
17152 resp, num_matched)) {
17153 hddLog(LOGE, FL("Fail to compress mDNS response "
17154 "(%d)!"), MDNS_TYPE_PTR_DNAME);
17155 return FALSE;
17156 }
17157 } else {
17158 /* num = 0 -> no matched string */
17159 if (!wlan_hdd_mdns_process_response_dname(resptype_ptr_dn,
17160 resp_info)) {
17161 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17162 MDNS_TYPE_PTR_DNAME);
17163 return FALSE;
17164 }
17165 }
17166
17167 return TRUE;
17168}
17169
17170/**
17171 * wlan_hdd_mdns_pack_response_type_ptr() - Pack Type PTR response
17172 * @ini_config: Pointer to the struct hdd_config_t
17173 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17174 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17175 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17176 * domain name
17177 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17178 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17179 *
17180 * The Type Ptr response include QName, response type, class, TTL and
17181 * Type PTR domain name. Also, it will find the matched QName from the
17182 * existing resptype_txt, resptype_a and then compress the data.
17183 *
17184 * Return: Return boolean. TRUE for success, FALSE for fail.
17185 */
17186static bool
17187wlan_hdd_mdns_pack_response_type_ptr(hdd_config_t *ini_config,
17188 sir_mdns_resp_info resp_info,
17189 struct hdd_mdns_resp_info *resptype_ptr,
17190 struct hdd_mdns_resp_info *resptype_ptr_dn,
17191 struct hdd_mdns_resp_info *resptype_txt,
17192 struct hdd_mdns_resp_info *resptype_a)
17193{
17194 uint8_t num_matched, num_matched1;
17195 uint16_t value;
17196 uint8_t val_u8;
17197 uint32_t offset_data_len, len;
17198
17199 ENTER();
17200 if ((ini_config == NULL) || (resp_info == NULL) ||
17201 (resptype_ptr == NULL) || (resptype_ptr_dn == NULL)) {
17202 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17203 return FALSE;
17204 }
17205
17206 /* No Type Ptr response */
17207 if (strlen((char *)ini_config->mdns_resp_type_ptr) <= 0)
17208 return TRUE;
17209
17210 /* Wrong response is assigned, just ignore this response */
17211 if (!wlan_hdd_mdns_init_response(resptype_ptr,
17212 ini_config->mdns_resp_type_ptr, '.'))
17213 return TRUE;
17214
17215 /*
17216 * For data compression
17217 * Check if any strings are matched with Type A response
17218 */
17219 num_matched = 0;
17220 num_matched1 = 0;
17221 if (resptype_a && (resptype_a->num_entries > 0)) {
17222 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_ptr,
17223 resptype_a);
17224 }
17225 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17226 num_matched1 = wlan_hdd_mdns_find_entries_from_end(
17227 resptype_ptr, resptype_txt);
17228 }
17229 if ((num_matched != num_matched1) ||
17230 ((num_matched > 0) && (num_matched1 > 0))) {
17231 if (num_matched >= num_matched1) {
17232 if (!wlan_hdd_mdns_compress_data(resp_info,
17233 resptype_ptr, resptype_a, num_matched)) {
17234 hddLog(LOGE, FL("Fail to compress mDNS "
17235 "response (%d)!"), MDNS_TYPE_PTR);
17236 return FALSE;
17237 }
17238 } else {
17239 /* num_matched is less than num_matched1 */
17240 if (!wlan_hdd_mdns_compress_data(resp_info,
17241 resptype_ptr, resptype_txt, num_matched1)) {
17242 hddLog(LOGE, FL("Fail to compress mDNS "
17243 "response (%d)!"), MDNS_TYPE_PTR);
17244 return FALSE;
17245 }
17246 }
17247 } else {
17248 /*
17249 * Both num_matched and num_matched1 are zero.
17250 * no TypeA & TypeTxt
17251 */
17252 if (!wlan_hdd_mdns_process_response_dname(resptype_ptr,
17253 resp_info)) {
17254 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17255 MDNS_TYPE_PTR);
17256 return FALSE;
17257 }
17258 }
17259
17260 /* Process response Type, Class, TTL */
17261 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_PTR, resp_info)) {
17262 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17263 MDNS_TYPE_PTR);
17264 return FALSE;
17265 }
17266
17267 /*
17268 * Process response RDLength, RData (Ptr domain name)
17269 * Save the offset of RData length
17270 */
17271 offset_data_len = resp_info->resp_len;
17272 resp_info->resp_len += sizeof(uint16_t);
17273
17274 if (!wlan_hdd_mdns_pack_response_type_ptr_dname(ini_config, resp_info,
17275 resptype_ptr_dn, resptype_ptr,
17276 resptype_txt, resptype_a)) {
17277 return FALSE;
17278 }
17279 /* Set the RData length */
17280 len = offset_data_len + sizeof(uint16_t);
17281 if ((resptype_ptr_dn->num_entries > 0) &&
17282 (resp_info->resp_len > len)) {
17283 value = resp_info->resp_len - len;
17284 val_u8 = (value & 0xff00) >> 8;
17285 resp_info->resp_data[offset_data_len] = val_u8;
17286 val_u8 = value & 0xff;
17287 resp_info->resp_data[offset_data_len+1] = val_u8;
17288 } else {
17289 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17290 MDNS_TYPE_PTR);
17291 return FALSE;
17292 }
17293
17294 EXIT();
17295 return TRUE;
17296}
17297
17298/**
17299 * wlan_hdd_mdns_pack_response_type_srv_target()- Pack Type Service Target
17300 * @ini_config: Pointer to the struct hdd_config_t
17301 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17302 * @resptype_srv_tgt: Pointer to the struct hdd_mdns_resp_info of Type Srv
17303 * target
17304 * @resptype_srv: Pointer to the struct hdd_mdns_resp_info of Type Srv
17305 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17306 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17307 * domain name
17308 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17309 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17310 *
17311 * The Type service target is one of the data field in the Type SRV response.
17312 * Also, it will find the matched QName from the existing resptype_srv,
17313 * resptype_ptr, resptype_ptr_dn, resptype_txt, resptype_a and then compress
17314 * the data.
17315 *
17316 * Return: Return boolean. TRUE for success, FALSE for fail.
17317 */
17318static bool
17319wlan_hdd_mdns_pack_response_type_srv_target(hdd_config_t *ini_config,
17320 sir_mdns_resp_info resp_info,
17321 struct hdd_mdns_resp_info *resptype_srv_tgt,
17322 struct hdd_mdns_resp_info *resptype_srv,
17323 struct hdd_mdns_resp_info *resptype_ptr,
17324 struct hdd_mdns_resp_info *resptype_ptr_dn,
17325 struct hdd_mdns_resp_info *resptype_txt,
17326 struct hdd_mdns_resp_info *resptype_a)
17327{
17328 uint8_t num_matched, num, size;
17329 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17330 struct hdd_mdns_resp_info *resp;
17331
17332 if ((ini_config == NULL) || (resp_info == NULL) ||
17333 (resptype_srv == NULL) || (resptype_srv_tgt == NULL)) {
17334 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17335 return FALSE;
17336 }
17337
17338 /* No Type Srv Target response */
17339 if (strlen((char *)ini_config->mdns_resp_type_srv_target) <= 0)
17340 return TRUE;
17341
17342 /* Wrong response is assigned, just ignore this response */
17343 if (!wlan_hdd_mdns_init_response(resptype_srv_tgt,
17344 ini_config->mdns_resp_type_srv_target, '.'))
17345 return TRUE;
17346
17347 /*
17348 * For data compression
17349 * Check if any strings are matched with previous response.
17350 */
17351 num = 0;
17352 size = (MAX_MDNS_RESP_TYPE-1);
17353 size *= sizeof(struct hdd_mdns_resp_matched);
17354 vos_mem_zero(matchedlist, size);
17355 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv_tgt,
17356 resptype_srv);
17357 if (num_matched > 0) {
17358 matchedlist[num].num_matched = num_matched;
17359 matchedlist[num].type = MDNS_TYPE_SRV;
17360 num++;
17361 }
17362 if (resptype_ptr && (resptype_ptr->num_entries > 0)) {
17363 if (resptype_ptr_dn && (resptype_ptr_dn->num_entries > 0)) {
17364 num_matched = wlan_hdd_mdns_find_entries_from_end(
17365 resptype_srv_tgt, resptype_ptr_dn);
17366 if (num_matched > 0) {
17367 matchedlist[num].num_matched = num_matched;
17368 matchedlist[num].type = MDNS_TYPE_PTR_DNAME;
17369 num++;
17370 }
17371 }
17372 num_matched = wlan_hdd_mdns_find_entries_from_end(
17373 resptype_srv_tgt, resptype_ptr);
17374 if (num_matched > 0) {
17375 matchedlist[num].num_matched = num_matched;
17376 matchedlist[num].type = MDNS_TYPE_PTR;
17377 num++;
17378 }
17379 }
17380 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17381 num_matched = wlan_hdd_mdns_find_entries_from_end(
17382 resptype_srv_tgt, resptype_txt);
17383 if (num_matched > 0) {
17384 matchedlist[num].num_matched = num_matched;
17385 matchedlist[num].type = MDNS_TYPE_TXT;
17386 num++;
17387 }
17388 }
17389 if (resptype_a && (resptype_a->num_entries > 0)) {
17390 num_matched = wlan_hdd_mdns_find_entries_from_end(
17391 resptype_srv_tgt, resptype_a);
17392 if (num_matched > 0) {
17393 matchedlist[num].num_matched = num_matched;
17394 matchedlist[num].type = MDNS_TYPE_A;
17395 num++;
17396 }
17397 }
17398 if (num > 0) {
17399 if (num > 1)
17400 wlan_hdd_mdns_find_max(matchedlist, num);
17401 resp = NULL;
17402 switch (matchedlist[num-1].type) {
17403 case MDNS_TYPE_A:
17404 resp = resptype_a;
17405 break;
17406 case MDNS_TYPE_TXT:
17407 resp = resptype_txt;
17408 break;
17409 case MDNS_TYPE_PTR:
17410 resp = resptype_ptr;
17411 break;
17412 case MDNS_TYPE_PTR_DNAME:
17413 resp = resptype_ptr_dn;
17414 break;
17415 case MDNS_TYPE_SRV:
17416 resp = resptype_srv;
17417 break;
17418 default:
17419 hddLog(LOGE, FL("Fail to compress mDNS response "
17420 "(%d)!"), MDNS_TYPE_SRV_TARGET);
17421 return FALSE;
17422 }
17423 num_matched = matchedlist[num-1].num_matched;
17424 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_srv_tgt,
17425 resp, num_matched)) {
17426 hddLog(LOGE, FL("Fail to compress mDNS response "
17427 "(%d)!"), MDNS_TYPE_SRV_TARGET);
17428 return FALSE;
17429 }
17430 } else {
17431 /* num = 0 -> no matched string */
17432 if (!wlan_hdd_mdns_process_response_dname(resptype_srv_tgt,
17433 resp_info)) {
17434 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17435 MDNS_TYPE_SRV_TARGET);
17436 return FALSE;
17437 }
17438 }
17439
17440 return TRUE;
17441}
17442
17443/**
17444 * wlan_hdd_mdns_pack_response_type_srv()- Pack Type Service response
17445 * @ini_config: Pointer to the struct hdd_config_t
17446 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17447 * @resptype_srv: Pointer to the struct hdd_mdns_resp_info of Type Srv
17448 * @resptype_srv_tgt: Pointer to the struct hdd_mdns_resp_info of Type Srv
17449 * target
17450 * @resptype_ptr: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17451 * @resptype_ptr_dn: Pointer to the struct hdd_mdns_resp_info of Type Ptr
17452 * domain name
17453 * @resptype_txt: Pointer to the struct hdd_mdns_resp_info of Type Txt
17454 * @resptype_a: Pointer to the struct hdd_mdns_resp_info of Type A
17455 *
17456 * The Type SRV (Service) response include QName, response type, class, TTL
17457 * and four kinds of data fields. Also, it will find the matched QName from
17458 * the existing resptype_ptr, resptype_ptr_dn, resptype_txt, resptype_a and
17459 * then compress the data.
17460 *
17461 * Return: Return boolean. TRUE for success, FALSE for fail.
17462 */
17463static bool
17464wlan_hdd_mdns_pack_response_type_srv(hdd_config_t *ini_config,
17465 sir_mdns_resp_info resp_info,
17466 struct hdd_mdns_resp_info *resptype_srv,
17467 struct hdd_mdns_resp_info *resptype_srv_tgt,
17468 struct hdd_mdns_resp_info *resptype_ptr,
17469 struct hdd_mdns_resp_info *resptype_ptr_dn,
17470 struct hdd_mdns_resp_info *resptype_txt,
17471 struct hdd_mdns_resp_info *resptype_a)
17472{
17473 uint8_t num_matched, num, size;
17474 uint16_t value;
17475 uint8_t val_u8;
17476 uint32_t offset_data_len, len;
17477 struct hdd_mdns_resp_info *resp;
17478 struct hdd_mdns_resp_matched matchedlist[MAX_MDNS_RESP_TYPE-1];
17479
17480 ENTER();
17481
17482 if ((ini_config == NULL) || (resp_info == NULL) ||
17483 (resptype_srv == NULL) || (resptype_srv_tgt == NULL)) {
17484 hddLog(LOGE, FL("ini_config or response info is NULL!"));
17485 return FALSE;
17486 }
17487
17488 /* No Type Srv response */
17489 if (strlen((char *)ini_config->mdns_resp_type_srv) <= 0)
17490 return TRUE;
17491
17492 /* Wrong response is assigned, just ignore this response */
17493 if (!wlan_hdd_mdns_init_response(resptype_srv,
17494 ini_config->mdns_resp_type_srv, '.'))
17495 return TRUE;
17496
17497 /*
17498 * For data compression
17499 * Check if any strings are matched with Type A response
17500 */
17501 num = 0;
17502 size = (MAX_MDNS_RESP_TYPE-1);
17503 size *= sizeof(struct hdd_mdns_resp_matched);
17504 vos_mem_zero(matchedlist, size);
17505 if (resptype_ptr && (resptype_ptr->num_entries > 0)) {
17506 if (resptype_ptr_dn && (resptype_ptr_dn->num_entries > 0)) {
17507 num_matched = wlan_hdd_mdns_find_entries_from_end(
17508 resptype_srv,
17509 resptype_ptr_dn);
17510 if (num_matched > 0) {
17511 matchedlist[num].num_matched = num_matched;
17512 matchedlist[num].type = MDNS_TYPE_PTR_DNAME;
17513 num++;
17514 }
17515 }
17516 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17517 resptype_ptr);
17518 if (num_matched > 0) {
17519 matchedlist[num].num_matched = num_matched;
17520 matchedlist[num].type = MDNS_TYPE_PTR;
17521 num++;
17522 }
17523 }
17524 if (resptype_txt && (resptype_txt->num_entries > 0)) {
17525 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17526 resptype_txt);
17527 if (num_matched > 0) {
17528 matchedlist[num].num_matched =num_matched;
17529 matchedlist[num].type = MDNS_TYPE_TXT;
17530 num++;
17531 }
17532 }
17533 if (resptype_a && (resptype_a->num_entries > 0)) {
17534 num_matched = wlan_hdd_mdns_find_entries_from_end(resptype_srv,
17535 resptype_a);
17536 if (num_matched > 0) {
17537 matchedlist[num].num_matched = num_matched;
17538 matchedlist[num].type = MDNS_TYPE_A;
17539 num++;
17540 }
17541 }
17542 if (num > 0) {
17543 if (num > 1)
17544 wlan_hdd_mdns_find_max(matchedlist, num);
17545 resp = NULL;
17546 switch (matchedlist[num-1].type) {
17547 case MDNS_TYPE_A:
17548 resp = resptype_a;
17549 break;
17550 case MDNS_TYPE_TXT:
17551 resp = resptype_txt;
17552 break;
17553 case MDNS_TYPE_PTR:
17554 resp = resptype_ptr;
17555 break;
17556 case MDNS_TYPE_PTR_DNAME:
17557 resp = resptype_ptr_dn;
17558 break;
17559 default:
17560 hddLog(LOGE, FL("Fail to compress mDNS response "
17561 "(%d)!"), MDNS_TYPE_SRV);
17562 return FALSE;
17563 }
17564 num_matched = matchedlist[num-1].num_matched;
17565 if (!wlan_hdd_mdns_compress_data(resp_info, resptype_srv,
17566 resp, num_matched)) {
17567 hddLog(LOGE, FL("Fail to compress mDNS response "
17568 "(%d)!"), MDNS_TYPE_SRV);
17569 return FALSE;
17570 }
17571 } else {
17572 /* num = 0 -> no matched string */
17573 if (!wlan_hdd_mdns_process_response_dname(resptype_srv,
17574 resp_info)) {
17575 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17576 MDNS_TYPE_SRV);
17577 return FALSE;
17578 }
17579 }
17580
17581 /* Process response Type, Class, TTL */
17582 if (!wlan_hdd_mdns_process_response_misc(MDNS_TYPE_SRV, resp_info)) {
17583 hddLog(LOGE, FL("Fail to process mDNS misc response (%d)!"),
17584 MDNS_TYPE_SRV);
17585 return FALSE;
17586 }
17587
17588 /*
17589 * Process response RDLength, RData (Srv target name)
17590 * Save the offset of RData length
17591 */
17592 offset_data_len = resp_info->resp_len;
17593 resp_info->resp_len += sizeof(uint16_t);
17594
17595 len = resp_info->resp_len + (3 * sizeof(uint16_t));
17596 if (len >= MAX_MDNS_RESP_LEN) {
17597 hddLog(LOGE, FL("resp_len exceeds %d!"), MAX_MDNS_RESP_LEN);
17598 return FALSE;
17599 }
17600
17601 /* set Srv Priority */
17602 value = ini_config->mdns_resp_type_srv_priority;
17603 wlan_hdd_mdns_format_response_u16(value, resp_info);
17604 /* set Srv Weight */
17605 value = ini_config->mdns_resp_type_srv_weight;
17606 wlan_hdd_mdns_format_response_u16(value, resp_info);
17607 /* set Srv Port */
17608 value = ini_config->mdns_resp_type_srv_port;
17609 wlan_hdd_mdns_format_response_u16(value, resp_info);
17610
17611 if (!wlan_hdd_mdns_pack_response_type_srv_target(ini_config, resp_info,
17612 resptype_srv_tgt, resptype_srv,
17613 resptype_ptr, resptype_ptr_dn,
17614 resptype_txt, resptype_a)) {
17615 return FALSE;
17616 }
17617 /* Set the RData length */
17618 len = offset_data_len + sizeof(uint16_t);
17619 if ((resptype_srv_tgt->num_entries > 0) &&
17620 (resp_info->resp_len > len)) {
17621 value = resp_info->resp_len - len;
17622 val_u8 = (value & 0xff00) >> 8;
17623 resp_info->resp_data[offset_data_len] = val_u8;
17624 val_u8 = value & 0xff;
17625 resp_info->resp_data[offset_data_len+1] = val_u8;
17626 } else {
17627 hddLog(LOGE, FL("Fail to process mDNS response (%d)!"),
17628 MDNS_TYPE_SRV);
17629 return FALSE;
17630 }
17631
17632 EXIT();
17633 return TRUE;
17634}
17635
17636/**
17637 * wlan_hdd_mdns_free_mem() - Free the allocated memory
17638 * @response: Pointer to the struct hdd_mdns_resp_info
17639 *
17640 * Return: None
17641 */
17642static void wlan_hdd_mdns_free_mem(struct hdd_mdns_resp_info *response)
17643{
17644 if (response && response->data)
17645 vos_mem_free(response->data);
17646 if (response && response->offset)
17647 vos_mem_free(response->offset);
17648}
17649
17650/**
17651 * wlan_hdd_mdns_pack_response() - Pack mDNS response
17652 * @ini_config: Pointer to the struct hdd_config_t
17653 * @resp_info: Pointer to the struct tSirMDNSResponseInfo
17654 *
17655 * This function will pack four types of responses (Type A, Type Txt, Type Ptr
17656 * and Type Service). Each response contains QName, response type, class, TTL
17657 * and data fields.
17658 *
17659 * Return: Return boolean. TRUE for success, FALSE for fail.
17660 */
17661static bool wlan_hdd_mdns_pack_response(hdd_config_t *ini_config,
17662 sir_mdns_resp_info resp_info)
17663{
17664 struct hdd_mdns_resp_info resptype_a, resptype_txt;
17665 struct hdd_mdns_resp_info resptype_ptr, resptype_ptr_dn;
17666 struct hdd_mdns_resp_info resptype_srv, resptype_srv_tgt;
17667 uint32_t num_res_records = 0;
17668 bool status = FALSE;
17669
17670 ENTER();
17671
17672 wlan_hdd_mdns_reset_response(&resptype_a);
17673 wlan_hdd_mdns_reset_response(&resptype_txt);
17674 wlan_hdd_mdns_reset_response(&resptype_ptr);
17675 wlan_hdd_mdns_reset_response(&resptype_ptr_dn);
17676 wlan_hdd_mdns_reset_response(&resptype_srv);
17677 wlan_hdd_mdns_reset_response(&resptype_srv_tgt);
17678
17679 resp_info->resp_len = 0;
17680
17681 /* Process Type A response */
17682 if (!wlan_hdd_mdns_pack_response_type_a(ini_config, resp_info,
17683 &resptype_a))
17684 goto err_resptype_a;
17685
17686 if ((resptype_a.num_entries > 0) &&
17687 (strlen((char *)&resptype_a.data[0]) > 0))
17688 num_res_records++;
17689
17690 /* Process Type TXT response */
17691 if (!wlan_hdd_mdns_pack_response_type_txt(ini_config, resp_info,
17692 &resptype_txt, &resptype_a))
17693 goto err_resptype_txt;
17694
17695 if ((resptype_txt.num_entries > 0) &&
17696 (strlen((char *)&resptype_txt.data[0]) > 0))
17697 num_res_records++;
17698
17699 /* Process Type PTR response */
17700 if (!wlan_hdd_mdns_pack_response_type_ptr(ini_config, resp_info,
17701 &resptype_ptr, &resptype_ptr_dn,
17702 &resptype_txt, &resptype_a))
17703 goto err_resptype_ptr;
17704
17705 if ((resptype_ptr.num_entries > 0) &&
17706 (strlen((char *)&resptype_ptr.data[0]) > 0))
17707 num_res_records++;
17708
17709 /* Process Type SRV response */
17710 if (!wlan_hdd_mdns_pack_response_type_srv(ini_config, resp_info,
17711 &resptype_srv, &resptype_srv_tgt,
17712 &resptype_ptr, &resptype_ptr_dn,
17713 &resptype_txt, &resptype_a))
17714 goto err_resptype_srv;
17715
17716 if ((resptype_srv.num_entries > 0) &&
17717 (strlen((char *)&resptype_srv.data[0]) > 0))
17718 num_res_records++;
17719
17720 resp_info->resourceRecord_count = num_res_records;
17721 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
17722 "%s: Pack mDNS response data successfully!", __func__);
17723 status = TRUE;
17724
17725err_resptype_srv:
17726 wlan_hdd_mdns_free_mem(&resptype_srv);
17727 wlan_hdd_mdns_free_mem(&resptype_srv_tgt);
17728
17729err_resptype_ptr:
17730 wlan_hdd_mdns_free_mem(&resptype_ptr);
17731 wlan_hdd_mdns_free_mem(&resptype_ptr_dn);
17732
17733err_resptype_txt:
17734 wlan_hdd_mdns_free_mem(&resptype_txt);
17735
17736err_resptype_a:
17737 wlan_hdd_mdns_free_mem(&resptype_a);
17738
17739 EXIT();
17740 return status;
17741}
17742
17743/**
17744 * wlan_hdd_set_mdns_offload() - Enable mDNS offload
17745 * @hostapd_adapter: Pointer to the struct hdd_adapter_t
17746 *
17747 * This function will set FQDN/unique FQDN (full qualified domain name)
17748 * and the mDNS response. Then send them to SME.
17749 *
17750 * Return: Return boolean. TRUE for success, FALSE for fail.
17751 */
17752bool wlan_hdd_set_mdns_offload(hdd_adapter_t *hostapd_adapter)
17753{
17754 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(hostapd_adapter);
17755 sir_mdns_offload_info mdns_offload_info;
17756 sir_mdns_fqdn_info mdns_fqdn_info;
17757 sir_mdns_resp_info mdns_resp_info;
17758 uint32_t fqdn_len, ufqdn_len;
17759
17760 ENTER();
17761
17762 /* 1. Prepare the MDNS fqdn request to send to SME */
17763 fqdn_len = strlen(hdd_ctx->cfg_ini->mdns_fqdn);
17764 ufqdn_len = strlen(hdd_ctx->cfg_ini->mdns_uniquefqdn);
17765 if ((fqdn_len == 0) && (ufqdn_len == 0)) {
17766 hddLog(LOGE, FL("No mDNS FQDN or UFQDN is assigned fqdn_len %d,"
17767 "ufqdn_len %d!"), fqdn_len, ufqdn_len);
17768 return FALSE;
17769 }
17770
17771 mdns_fqdn_info = vos_mem_malloc(sizeof(*mdns_fqdn_info));
17772 if (NULL == mdns_fqdn_info) {
17773 hddLog(LOGE, FL("could not allocate tSirMDNSFqdnInfo!"));
17774 return FALSE;
17775 }
17776 /* MDNS fqdn request */
17777 if (fqdn_len > 0) {
17778 vos_mem_zero(mdns_fqdn_info, sizeof(*mdns_fqdn_info));
17779 mdns_fqdn_info->bss_idx = hostapd_adapter->sessionId;
17780 mdns_fqdn_info->fqdn_type = MDNS_FQDN_TYPE_GENERAL;
17781 mdns_fqdn_info->fqdn_len = fqdn_len;
17782 mdns_fqdn_info->mdns_fqdn_callback = hdd_mdns_fqdn_offload_done;
17783 mdns_fqdn_info->mdns_fqdn_cb_context = hostapd_adapter;
17784 vos_mem_copy(mdns_fqdn_info->fqdn_data,
17785 hdd_ctx->cfg_ini->mdns_fqdn,
17786 mdns_fqdn_info->fqdn_len);
17787
17788 if (eHAL_STATUS_SUCCESS !=
17789 sme_set_mdns_fqdn(hdd_ctx->hHal, mdns_fqdn_info)) {
17790 hddLog(LOGE, FL("sme_set_mdns_fqdn fail!"));
17791 vos_mem_free(mdns_fqdn_info);
17792 return FALSE;
17793 }
17794 }
17795 /* MDNS unique fqdn request */
17796 if (ufqdn_len > 0) {
17797 vos_mem_zero(mdns_fqdn_info, sizeof(*mdns_fqdn_info));
17798 mdns_fqdn_info->bss_idx = hostapd_adapter->sessionId;
17799 mdns_fqdn_info->fqdn_type = MDNS_FQDN_TYPE_UNIQUE;
17800 mdns_fqdn_info->fqdn_len = ufqdn_len;
17801 mdns_fqdn_info->mdns_fqdn_callback = hdd_mdns_fqdn_offload_done;
17802 mdns_fqdn_info->mdns_fqdn_cb_context = hostapd_adapter;
17803 vos_mem_copy(mdns_fqdn_info->fqdn_data,
17804 hdd_ctx->cfg_ini->mdns_uniquefqdn,
17805 mdns_fqdn_info->fqdn_len);
17806 if (eHAL_STATUS_SUCCESS !=
17807 sme_set_mdns_fqdn(hdd_ctx->hHal, mdns_fqdn_info)) {
17808 hddLog(LOGE, FL("sme_set_mdns_fqdn fail!"));
17809 vos_mem_free(mdns_fqdn_info);
17810 return FALSE;
17811 }
17812 }
17813 vos_mem_free(mdns_fqdn_info);
17814
17815 /* 2. Prepare the MDNS response request to send to SME */
17816 mdns_resp_info = vos_mem_malloc(sizeof(*mdns_resp_info));
17817 if (NULL == mdns_resp_info) {
17818 hddLog(LOGE, FL("could not allocate tSirMDNSResponseInfo!"));
17819 return FALSE;
17820 }
17821
17822 vos_mem_zero(mdns_resp_info, sizeof(*mdns_resp_info));
17823 mdns_resp_info->bss_idx = hostapd_adapter->sessionId;
17824 mdns_resp_info->mdns_resp_callback = hdd_mdns_resp_offload_done;
17825 mdns_resp_info->mdns_resp_cb_context = hostapd_adapter;
17826 if (!wlan_hdd_mdns_pack_response(hdd_ctx->cfg_ini, mdns_resp_info)) {
17827 hddLog(LOGE, FL("wlan_hdd_pack_mdns_response fail!"));
17828 vos_mem_free(mdns_resp_info);
17829 return FALSE;
17830 }
17831 if (eHAL_STATUS_SUCCESS !=
17832 sme_set_mdns_resp(hdd_ctx->hHal, mdns_resp_info)) {
17833 hddLog(LOGE, FL("sme_set_mdns_resp fail!"));
17834 vos_mem_free(mdns_resp_info);
17835 return FALSE;
17836 }
17837 vos_mem_free(mdns_resp_info);
17838
17839 /* 3. Prepare the MDNS Enable request to send to SME */
17840 mdns_offload_info = vos_mem_malloc(sizeof(*mdns_offload_info));
17841 if (NULL == mdns_offload_info) {
17842 hddLog(LOGE, FL("could not allocate tSirMDNSOffloadInfo!"));
17843 return FALSE;
17844 }
17845
17846 vos_mem_zero(mdns_offload_info, sizeof(*mdns_offload_info));
17847
17848 mdns_offload_info->bss_idx = hostapd_adapter->sessionId;
17849 mdns_offload_info->enable = hdd_ctx->cfg_ini->enable_mdns_offload;
17850 mdns_offload_info->mdns_enable_callback = hdd_mdns_enable_offload_done;
17851 mdns_offload_info->mdns_enable_cb_context = hostapd_adapter;
17852 if (eHAL_STATUS_SUCCESS !=
17853 sme_set_mdns_offload(hdd_ctx->hHal, mdns_offload_info)) {
17854 hddLog(LOGE, FL("sme_set_mdns_offload fail!"));
17855 vos_mem_free(mdns_offload_info);
17856 return FALSE;
17857 }
17858
17859 vos_mem_free(mdns_offload_info);
17860 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
17861 "%s: enable mDNS offload successfully!", __func__);
17862 return TRUE;
17863}
Manjeet Singh3ed79242017-01-11 19:04:32 +053017864
17865
Anurag Chouhan0b29de02016-12-16 13:18:40 +053017866#endif /* MDNS_OFFLOAD */
c_manjeecfd1efb2015-09-25 19:32:34 +053017867
Hanumanth Reddy Pothulad864f312017-01-18 16:16:08 +053017868/**
17869 * wlan_hdd_start_sap() - This function starts bss of SAP.
17870 * @ap_adapter: SAP adapter
17871 *
17872 * This function will process the starting of sap adapter.
17873 *
17874 * Return: void.
17875 */
17876void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter)
17877{
17878 hdd_ap_ctx_t *hdd_ap_ctx;
17879 hdd_hostapd_state_t *hostapd_state;
17880 VOS_STATUS vos_status;
17881 hdd_context_t *hdd_ctx;
17882 tsap_Config_t *pConfig;
17883
17884 if (NULL == ap_adapter) {
17885 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
17886 FL("ap_adapter is NULL here"));
17887 return;
17888 }
17889
17890 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
17891 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
17892 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
17893 pConfig = &ap_adapter->sessionCtx.ap.sapConfig;
17894
17895 mutex_lock(&hdd_ctx->sap_lock);
17896 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
17897 goto end;
17898
17899 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
17900 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
17901 goto end;
17902 }
17903
17904 vos_event_reset(&hostapd_state->vosEvent);
17905 if (WLANSAP_StartBss(hdd_ctx->pvosContext, hdd_hostapd_SAPEventCB,
17906 &hdd_ap_ctx->sapConfig, (v_PVOID_t)ap_adapter->dev)
17907 != VOS_STATUS_SUCCESS) {
17908 goto end;
17909 }
17910
17911 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
17912 FL("Waiting for SAP to start"));
17913 vos_status = vos_wait_single_event(&hostapd_state->vosEvent, 10000);
17914 if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
17915 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
17916 FL("SAP Start failed"));
17917 goto end;
17918 }
17919 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
17920 FL("SAP Start Success"));
17921 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
17922
17923 wlan_hdd_incr_active_session(hdd_ctx, ap_adapter->device_mode);
17924 hostapd_state->bCommit = TRUE;
17925
17926end:
17927 mutex_unlock(&hdd_ctx->sap_lock);
17928 return;
17929}
17930
Manjeet Singh3ed79242017-01-11 19:04:32 +053017931#ifdef WLAN_FEATURE_TSF
17932
17933/**
17934 * hdd_tsf_cb() - handle tsf request callback
17935 *
17936 * @pcb_cxt: pointer to the hdd_contex
17937 * @ptsf: pointer to struct stsf
17938 *
17939 * Based on the request sent .
17940 *
17941 * Return: Describe the execute result of this routine
17942 */
17943static int hdd_tsf_cb(void *pcb_ctx, struct stsf *ptsf)
17944{
17945 hdd_context_t *hddctx;
17946 int status;
17947 hdd_adapter_t* adapter = (hdd_adapter_t*)pcb_ctx;
17948
17949 if (pcb_ctx == NULL || ptsf == NULL) {
17950 hddLog(VOS_TRACE_LEVEL_ERROR,
17951 FL("HDD context is not valid"));
17952 return -EINVAL;
17953 }
17954
17955 hddctx = (hdd_context_t *)pcb_ctx;
17956 status = wlan_hdd_validate_context(hddctx);
17957 if (0 != status)
17958 return -EINVAL;
17959
17960 if (NULL == adapter) {
17961 hddLog(VOS_TRACE_LEVEL_ERROR,
17962 FL("failed to find adapter"));
17963 return -EINVAL;
17964 }
17965
17966 hddLog(VOS_TRACE_LEVEL_INFO,
17967 FL("tsf cb handle event, device_mode is %d"),
17968 adapter->device_mode);
17969
17970 /* copy the return value to hdd_tsf_ctx in adapter*/
17971 if (ptsf->tsf_req_status) {
17972
17973 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17974 adapter->tsf_cap_ctx.tsf_get_state = TSF_NOT_RETURNED_BY_FW;
17975 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17976 vos_event_set (&adapter->tsf_cap_ctx.tsf_capture_done_event);
17977 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17978
17979 hddLog(VOS_TRACE_LEVEL_ERROR, FL("tsf req failure :%d"),
17980 ptsf->tsf_req_status);
17981 return ptsf->tsf_req_status;
17982 }
17983 /* If this is a get request.Store the tsf values in adapter. */
17984 if (!ptsf->set_tsf_req) {
17985 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17986 adapter->tsf_cap_ctx.tsf_low = ptsf->tsf_low;
17987 adapter->tsf_cap_ctx.tsf_high = ptsf->tsf_high;
17988 adapter->tsf_cap_ctx.tsf_get_state = TSF_RETURN;
17989 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
17990 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
17991
17992 hddLog(VOS_TRACE_LEVEL_INFO,
17993 FL("hdd_get_tsf_cb sta=%u, tsf_low=%u, tsf_high=%u"),
17994 adapter->sessionId, ptsf->tsf_low, ptsf->tsf_high);
17995 }
17996 else {
17997 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
17998 adapter->tsf_cap_ctx.tsf_capture_state = TSF_CAP_STATE;
17999 adapter->tsf_cap_ctx.tsf_get_state = TSF_CURRENT_IN_CAP_STATE;
18000 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18001 }
18002 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18003 vos_event_set (&adapter->tsf_cap_ctx.tsf_capture_done_event);
18004 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18005
18006 /* free allocated mem */
18007 vos_mem_free(ptsf);
18008
18009 return 0;
18010}
18011
18012/**
18013 * hdd_capture_tsf() - capture tsf
18014 *
18015 * @adapter: pointer to adapter
18016 * @buf: pointer to upper layer buf
18017 * @len : the length of buf
18018 *
18019 * This function returns tsf value to uplayer.
18020 *
18021 * Return: Describe the execute result of this routine
18022 */
18023int hdd_capture_tsf(hdd_adapter_t *adapter, uint32_t *buf, int len)
18024{
18025 int ret = 0;
18026 hdd_station_ctx_t *hdd_sta_ctx;
18027 hdd_context_t *hdd_ctx;
18028 tSirCapTsfParams cap_tsf_params;
18029 VOS_STATUS status;
18030
18031 if (adapter == NULL || buf == NULL) {
18032 hddLog(VOS_TRACE_LEVEL_ERROR,
18033 FL("invalid pointer"));
18034 return -EINVAL;
18035 }
18036 if (len != 1)
18037 return -EINVAL;
18038
18039 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
18040
18041 if (wlan_hdd_validate_context(hdd_ctx)) {
18042 hddLog(VOS_TRACE_LEVEL_ERROR,
18043 FL("invalid hdd ctx"));
18044 return -EINVAL;
18045 }
18046 if (adapter->device_mode == WLAN_HDD_INFRA_STATION ||
18047 adapter->device_mode == WLAN_HDD_P2P_CLIENT) {
18048 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
18049 if (hdd_sta_ctx->conn_info.connState !=
18050 eConnectionState_Associated) {
18051
18052 hddLog(VOS_TRACE_LEVEL_INFO,
18053 FL("failed to cap tsf, not connect with ap"));
18054 buf[0] = TSF_STA_NOT_CONNECTED_NO_TSF;
18055 return ret;
18056 }
18057 }
18058 if ((adapter->device_mode == WLAN_HDD_SOFTAP ||
18059 adapter->device_mode == WLAN_HDD_P2P_GO) &&
18060 !(test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))) {
18061 hddLog(VOS_TRACE_LEVEL_INFO,
18062 FL("Soft AP / P2p GO not beaconing"));
18063 buf[0] = TSF_SAP_NOT_STARTED_NO_TSF;
18064 return ret;
18065 }
18066 if (adapter->tsf_cap_ctx.tsf_capture_state == TSF_CAP_STATE) {
18067 hddLog(VOS_TRACE_LEVEL_INFO,
18068 FL("current in capture state, pls reset"));
18069 buf[0] = TSF_CURRENT_IN_CAP_STATE;
18070 } else {
18071 hddLog(VOS_TRACE_LEVEL_INFO, FL("ioctl issue cap tsf cmd"));
18072 buf[0] = TSF_RETURN;
18073 cap_tsf_params.session_id = adapter->sessionId;
18074 cap_tsf_params.tsf_rsp_cb_func = hdd_tsf_cb;
18075 cap_tsf_params.tsf_rsp_cb_ctx = adapter;
18076
18077 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18078 adapter->tsf_cap_ctx.tsf_capture_state = TSF_CAP_STATE;
18079 adapter->tsf_cap_ctx.tsf_get_state = TSF_CURRENT_IN_CAP_STATE;
18080 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18081
18082 ret = sme_capture_tsf_req(hdd_ctx->hHal, cap_tsf_params);
18083
18084 if (ret != VOS_STATUS_SUCCESS) {
18085 hddLog(VOS_TRACE_LEVEL_ERROR, FL("capture fail"));
18086 buf[0] = TSF_CAPTURE_FAIL;
18087 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18088 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18089 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18090 return -EINVAL;
18091 }
18092 /* wait till we get a response from fw */
18093 status = vos_wait_single_event(&adapter->tsf_cap_ctx.
18094 tsf_capture_done_event,
18095 HDD_TSF_CAP_REQ_TIMEOUT);
18096
18097 if (!VOS_IS_STATUS_SUCCESS(status)) {
18098 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
18099 ("capture tsf vos wait for single_event failed!! %d"),
18100 adapter->tsf_cap_ctx.tsf_get_state);
18101
18102 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18103 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18104 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18105
18106 return -EINVAL;
18107 }
18108 }
18109 buf[0] = TSF_RETURN;
18110 hddLog(VOS_TRACE_LEVEL_INFO,
18111 FL("ioctl return cap tsf cmd, ret = %d"), ret);
18112 return ret;
18113}
18114
18115/**
18116 * hdd_indicate_tsf() - return tsf to uplayer
18117 *
18118 * @adapter: pointer to adapter
18119 * @buf: pointer to uplayer buf
18120 * @len : the length of buf
18121 *
18122 * This function returns tsf value to uplayer.
18123 *
18124 * Return: Describe the execute result of this routine
18125 */
18126int hdd_indicate_tsf(hdd_adapter_t *adapter, uint32_t *buf, int len)
18127{
18128 int ret = 0;
18129 hdd_station_ctx_t *hdd_sta_ctx;
18130 hdd_context_t *hdd_ctx;
18131 tSirCapTsfParams cap_tsf_params;
18132 VOS_STATUS status;
18133
18134 if (adapter == NULL || buf == NULL) {
18135 hddLog(VOS_TRACE_LEVEL_ERROR,
18136 FL("invalid pointer"));
18137 return -EINVAL;
18138 }
18139 if (len != 3)
18140 return -EINVAL;
18141
18142 buf [1] = 0;
18143 buf [2] = 0;
18144 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
18145
18146 if (wlan_hdd_validate_context(hdd_ctx)) {
18147 hddLog(VOS_TRACE_LEVEL_ERROR,
18148 FL("invalid hdd ctx"));
18149 return -EINVAL;
18150 }
18151 if (adapter->device_mode == WLAN_HDD_INFRA_STATION ||
18152 adapter->device_mode == WLAN_HDD_P2P_CLIENT) {
18153 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
18154 if (hdd_sta_ctx->conn_info.connState !=
18155 eConnectionState_Associated) {
18156
18157 hddLog(VOS_TRACE_LEVEL_INFO,
18158 FL("failed to cap tsf, not connect with ap"));
18159 buf[0] = TSF_STA_NOT_CONNECTED_NO_TSF;
18160 return ret;
18161 }
18162 }
18163 if ((adapter->device_mode == WLAN_HDD_SOFTAP ||
18164 adapter->device_mode == WLAN_HDD_P2P_GO) &&
18165 !(test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))) {
18166 hddLog(VOS_TRACE_LEVEL_INFO,
18167 FL("Soft AP / P2p GO not beaconing"));
18168 buf[0] = TSF_SAP_NOT_STARTED_NO_TSF;
18169 return ret;
18170 }
18171
18172 if (adapter->tsf_cap_ctx.tsf_capture_state != TSF_CAP_STATE ||
18173 adapter->tsf_cap_ctx.tsf_get_state != TSF_CURRENT_IN_CAP_STATE ) {
18174 hddLog(VOS_TRACE_LEVEL_INFO,
18175 FL("Not in capture state,Enter capture state first"));
18176 buf[0] = TSF_GET_FAIL;
18177 } else {
18178 hddLog(VOS_TRACE_LEVEL_INFO, FL("ioctl issue cap tsf cmd"));
18179 cap_tsf_params.session_id = adapter->sessionId;
18180 cap_tsf_params.tsf_rsp_cb_func = hdd_tsf_cb;
18181 cap_tsf_params.tsf_rsp_cb_ctx = adapter;
18182
18183 ret = sme_get_tsf_req(hdd_ctx->hHal, cap_tsf_params);
18184
18185 if (ret != VOS_STATUS_SUCCESS) {
18186 hddLog(VOS_TRACE_LEVEL_ERROR, FL("capture fail"));
18187 buf[0] = TSF_CAPTURE_FAIL;
18188 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18189 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18190 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18191 return -EINVAL;
18192 }
18193 /* wait till we get a response from fw */
18194 status = vos_wait_single_event(&adapter->tsf_cap_ctx.
18195 tsf_capture_done_event,
18196 HDD_TSF_GET_REQ_TIMEOUT);
18197
18198 if (!VOS_IS_STATUS_SUCCESS(status)) {
18199 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
18200 ("capture tsf vos wait for single_event failed!! %d"),
18201 status);
18202
18203 vos_spin_lock_acquire(&adapter->tsf_cap_ctx.tsf_lock);
18204 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18205 vos_spin_lock_release(&adapter->tsf_cap_ctx.tsf_lock);
18206 return status;
18207 }
18208 buf[1] = adapter->tsf_cap_ctx.tsf_low;
18209 buf[2] = adapter->tsf_cap_ctx.tsf_high;
18210
18211 hddLog(VOS_TRACE_LEVEL_INFO,
18212 FL("get tsf cmd,status=%u, tsf_low=%u, tsf_high=%u"),
18213 buf[0], buf[1], buf[2]);
18214 }
18215 hddLog(VOS_TRACE_LEVEL_INFO,
18216 FL("ioctl return cap tsf cmd, ret = %d"), ret);
18217 return ret;
18218}
18219
18220void wlan_hdd_tsf_init(hdd_adapter_t *adapter)
18221{
18222
18223 if (adapter == NULL) {
18224 hddLog(VOS_TRACE_LEVEL_ERROR,
18225 FL("TSF init on a null adapter!"));
18226 return;
18227 }
18228
18229 adapter->tsf_cap_ctx.tsf_get_state = TSF_RETURN;
18230 adapter->tsf_cap_ctx.tsf_capture_state = TSF_IDLE;
18231 vos_event_init(&adapter->tsf_cap_ctx.tsf_capture_done_event);
18232 vos_spin_lock_init(&adapter->tsf_cap_ctx.tsf_lock);
18233 adapter->tsf_cap_ctx.tsf_high = 0;
18234 adapter->tsf_cap_ctx.tsf_low = 0;
18235}
18236
18237#endif
18238
Hanumanth Reddy Pothula972e1df2018-06-14 13:33:47 +053018239bool hdd_is_cli_iface_up(hdd_context_t *hdd_ctx)
18240{
18241 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
18242 hdd_adapter_t *adapter;
18243 VOS_STATUS status;
18244
18245 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
18246 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status) {
18247 adapter = adapter_node->pAdapter;
18248 if ((adapter->device_mode == WLAN_HDD_INFRA_STATION ||
18249 adapter->device_mode == WLAN_HDD_P2P_CLIENT) &&
18250 test_bit(DEVICE_IFACE_OPENED,
18251 &adapter->event_flags)){
18252 return true;
18253 }
18254 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
18255 adapter_node = next;
18256 }
18257
18258 return false;
18259}
18260
Jeff Johnson295189b2012-06-20 16:38:30 -070018261//Register the module init/exit functions
18262module_init(hdd_module_init);
18263module_exit(hdd_module_exit);
18264
18265MODULE_LICENSE("Dual BSD/GPL");
18266MODULE_AUTHOR("Qualcomm Atheros, Inc.");
18267MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
18268
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018269static const struct kernel_param_ops con_mode_ops = {
18270 .set = con_mode_handler,
18271 .get = param_get_int,
18272};
18273
18274static const struct kernel_param_ops fwpath_ops = {
18275 .set = fwpath_changed_handler,
18276 .get = param_get_string,
18277};
18278
Hanumanth Reddy Pothula99219872018-06-08 14:45:18 +053018279#ifdef MODULE
18280module_param(con_mode, int, 0);
18281#else
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018282module_param_cb(con_mode, &con_mode_ops, &con_mode,
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070018283 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Hanumanth Reddy Pothula99219872018-06-08 14:45:18 +053018284#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -070018285
Ashish Kumar Dhanotiyafb3fd972018-04-30 12:46:52 +053018286module_param_cb(fwpath, &fwpath_ops, &fwpath,
Jeff Johnson32d95a32012-09-10 13:15:23 -070018287 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Arif Hussain66559122013-11-21 10:11:40 -080018288
18289module_param(enable_dfs_chan_scan, int,
18290 S_IRUSR | S_IRGRP | S_IROTH);
18291
18292module_param(enable_11d, int,
18293 S_IRUSR | S_IRGRP | S_IROTH);
18294
18295module_param(country_code, charp,
18296 S_IRUSR | S_IRGRP | S_IROTH);