blob: 91f7e5f62f69c6c93de877fe6038ebe245e2a581 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +05302 * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved.
Kiet Lam842dad02014-02-18 18:44:02 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
Kiet Lama7f454d2014-07-24 12:04:06 -070023 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080026 */
Kiet Lam842dad02014-02-18 18:44:02 -080027
28
Kiet Lama7f454d2014-07-24 12:04:06 -070029
30
Jeff Johnson295189b2012-06-20 16:38:30 -070031/*========================================================================
32
33 \file wlan_hdd_main.c
34
35 \brief WLAN Host Device Driver implementation
36
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38 ========================================================================*/
39
40/**=========================================================================
41
42 EDIT HISTORY FOR FILE
43
44
45 This section contains comments describing changes made to the module.
46 Notice that changes are listed in reverse chronological order.
47
48
49 $Header:$ $DateTime: $ $Author: $
50
51
52 when who what, where, why
53 -------- --- --------------------------------------------------------
54 04/5/09 Shailender Created module.
55 02/24/10 Sudhir.S.Kohalli Added to support param for SoftAP module
56 06/03/10 js - Added support to hostapd driven deauth/disassoc/mic failure
57 ==========================================================================*/
58
59/*--------------------------------------------------------------------------
60 Include Files
61 ------------------------------------------------------------------------*/
62//#include <wlan_qct_driver.h>
63#include <wlan_hdd_includes.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070064#include <vos_api.h>
65#include <vos_sched.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070066#include <linux/etherdevice.h>
67#include <linux/firmware.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070068#ifdef ANI_BUS_TYPE_PLATFORM
69#include <linux/wcnss_wlan.h>
70#endif //ANI_BUS_TYPE_PLATFORM
71#ifdef ANI_BUS_TYPE_PCI
72#include "wcnss_wlan.h"
73#endif /* ANI_BUS_TYPE_PCI */
74#include <wlan_hdd_tx_rx.h>
75#include <palTimer.h>
76#include <wniApi.h>
77#include <wlan_nlink_srv.h>
78#include <wlan_btc_svc.h>
79#include <wlan_hdd_cfg.h>
80#include <wlan_ptt_sock_svc.h>
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053081#include <wlan_logging_sock_svc.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070082#include <wlan_hdd_wowl.h>
83#include <wlan_hdd_misc.h>
84#include <wlan_hdd_wext.h>
85#ifdef WLAN_BTAMP_FEATURE
86#include <bap_hdd_main.h>
87#include <bapInternal.h>
88#endif // WLAN_BTAMP_FEATURE
Sushant Kaushik4b7cb302014-01-06 17:45:01 +053089#include "wlan_hdd_trace.h"
90#include "vos_types.h"
91#include "vos_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070092#include <linux/wireless.h>
93#include <net/cfg80211.h>
Vinay Krishna Erannad9cbdb32014-01-16 12:59:10 +053094#include <linux/inetdevice.h>
95#include <net/addrconf.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070096#include "wlan_hdd_cfg80211.h"
97#include "wlan_hdd_p2p.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070098#include <linux/rtnetlink.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070099int wlan_hdd_ftm_start(hdd_context_t *pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -0700100#include "sapApi.h"
101#include <linux/semaphore.h>
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -0700102#include <linux/ctype.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530103#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
104#include <soc/qcom/subsystem_restart.h>
105#else
Jeff Johnson295189b2012-06-20 16:38:30 -0700106#include <mach/subsystem_restart.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530107#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700108#include <wlan_hdd_hostapd.h>
109#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson295189b2012-06-20 16:38:30 -0700110#include "cfgApi.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700111#include "wlan_hdd_dev_pwr.h"
112#ifdef WLAN_BTAMP_FEATURE
113#include "bap_hdd_misc.h"
114#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700115#include "wlan_qct_pal_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700116#include "qwlan_version.h"
Yathish9f22e662012-12-10 14:21:35 -0800117#include "wlan_qct_wda.h"
Chilam NG571c65a2013-01-19 12:27:36 +0530118#ifdef FEATURE_WLAN_TDLS
119#include "wlan_hdd_tdls.h"
120#endif
Yue Ma0d4891e2013-08-06 17:01:45 -0700121#include "wlan_hdd_debugfs.h"
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +0530122#include "sapInternal.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700123
124#ifdef MODULE
125#define WLAN_MODULE_NAME module_name(THIS_MODULE)
126#else
127#define WLAN_MODULE_NAME "wlan"
128#endif
129
130#ifdef TIMER_MANAGER
131#define TIMER_MANAGER_STR " +TIMER_MANAGER"
132#else
133#define TIMER_MANAGER_STR ""
134#endif
135
136#ifdef MEMORY_DEBUG
137#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
138#else
139#define MEMORY_DEBUG_STR ""
140#endif
Kaushik, Sushant7005e372014-04-08 11:36:54 +0530141#define MAX_WAIT_FOR_ROC_COMPLETION 3
Jeff Johnson295189b2012-06-20 16:38:30 -0700142/* the Android framework expects this param even though we don't use it */
143#define BUF_LEN 20
Jeff Johnson76052702013-04-16 13:55:05 -0700144static char fwpath_buffer[BUF_LEN];
145static struct kparam_string fwpath = {
146 .string = fwpath_buffer,
147 .maxlen = BUF_LEN,
148};
Arif Hussain66559122013-11-21 10:11:40 -0800149
150static char *country_code;
151static int enable_11d = -1;
152static int enable_dfs_chan_scan = -1;
c_hpothu92367912014-05-01 15:18:17 +0530153static int gbcnMissRate = -1;
Arif Hussain66559122013-11-21 10:11:40 -0800154
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700155#ifndef MODULE
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700156static int wlan_hdd_inited;
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700157#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700158
Jeff Johnsone7245742012-09-05 17:12:55 -0700159/*
Jeff Johnson72a40512013-12-19 10:14:15 -0800160 * spinlock for synchronizing asynchronous request/response
161 * (full description of use in wlan_hdd_main.h)
162 */
163DEFINE_SPINLOCK(hdd_context_lock);
164
165/*
Jeff Johnsone7245742012-09-05 17:12:55 -0700166 * The rate at which the driver sends RESTART event to supplicant
167 * once the function 'vos_wlanRestart()' is called
168 *
169 */
170#define WLAN_HDD_RESTART_RETRY_DELAY_MS 5000 /* 5 second */
171#define WLAN_HDD_RESTART_RETRY_MAX_CNT 5 /* 5 retries */
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -0700172
173/*
174 * Size of Driver command strings from upper layer
175 */
176#define SIZE_OF_SETROAMMODE 11 /* size of SETROAMMODE */
177#define SIZE_OF_GETROAMMODE 11 /* size of GETROAMMODE */
178
Abhishek Singh00b71972016-01-07 10:51:04 +0530179#ifdef WLAN_FEATURE_RMC
180/*
181 * Ibss prop IE from command will be of size:
182 * size = sizeof(oui) + sizeof(oui_data) + 1(Element ID) + 1(EID Length)
183 * OUI_DATA should be at least 3 bytes long
184 */
185#define WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH (3)
186#endif
187
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800188#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700189#define TID_MIN_VALUE 0
190#define TID_MAX_VALUE 15
191static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
192 tAniTrafStrmMetrics* pTsmMetrics);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800193static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
194 tCsrEseBeaconReq *pEseBcnReq);
195#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700196
Atul Mittal1d722422014-03-19 11:15:07 +0530197/*
198 * Maximum buffer size used for returning the data back to user space
199 */
200#define WLAN_MAX_BUF_SIZE 1024
201#define WLAN_PRIV_DATA_MAX_LEN 8192
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -0700202
Abhishek Singh00b71972016-01-07 10:51:04 +0530203/*
204 * When ever we need to print IBSSPEERINFOALL for morethan 16 STA
205 * we will split the printing.
206 */
207#define NUM_OF_STA_DATA_TO_PRINT 16
208
209#ifdef WLAN_FEATURE_RMC
210#define WLAN_NLINK_CESIUM 30
211#endif
212
c_hpothu92367912014-05-01 15:18:17 +0530213//wait time for beacon miss rate.
214#define BCN_MISS_RATE_TIME 500
215
Sushant Kaushik83392fa2015-05-05 17:44:40 +0530216static vos_wake_lock_t wlan_wake_lock;
217
Jeff Johnson295189b2012-06-20 16:38:30 -0700218/* set when SSR is needed after unload */
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -0700219static e_hdd_ssr_required isSsrRequired = HDD_SSR_NOT_REQUIRED;
Jeff Johnson295189b2012-06-20 16:38:30 -0700220
221//internal function declaration
Jeff Johnsone7245742012-09-05 17:12:55 -0700222static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx);
223static void wlan_hdd_restart_init(hdd_context_t *pHddCtx);
224static void wlan_hdd_restart_deinit(hdd_context_t *pHddCtx);
Abhishek Singh00b71972016-01-07 10:51:04 +0530225
226#ifdef WLAN_FEATURE_RMC
227static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo);
228
229static int hdd_open_cesium_nl_sock(void);
230static void hdd_close_cesium_nl_sock(void);
231static struct sock *cesium_nl_srv_sock;
232static v_U16_t cesium_pid;
233
234static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
235 tANI_U8 *tx_fail_count,
236 tANI_U16 *pid);
237
238static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg);
239
240#endif /* WLAN_FEATURE_RMC */
Jeff Johnsone7245742012-09-05 17:12:55 -0700241void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback);
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800242void hdd_set_wlan_suspend_mode(bool suspend);
Jeff Johnsone7245742012-09-05 17:12:55 -0700243
Jeff Johnson295189b2012-06-20 16:38:30 -0700244v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +0530245 struct sk_buff *skb
246#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
247 , void *accel_priv
248#endif
249#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
250 , select_queue_fallback_t fallback
251#endif
252);
Jeff Johnson295189b2012-06-20 16:38:30 -0700253
254#ifdef WLAN_FEATURE_PACKET_FILTERING
255static void hdd_set_multicast_list(struct net_device *dev);
256#endif
257
258void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter);
259
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800260#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -0800261void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand);
262static VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels);
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700263static VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid,
264 tANI_U8 *pChannel, tANI_U8 *pDwellTime,
265 tANI_U8 **pBuf, tANI_U8 *pBufLen);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -0700266static VOS_STATUS hdd_parse_reassoc_command_data(tANI_U8 *pValue,
267 tANI_U8 *pTargetApBssid,
268 tANI_U8 *pChannel);
Srinivas Girigowdade697412013-02-14 16:31:48 -0800269#endif
Ratheesh S P21280412015-05-19 14:21:52 +0530270
271/* Store WLAN driver info in a global variable such that crash debugger
272 can extract it from driver debug symbol and crashdump for post processing */
273tANI_U8 g_wlan_driver[ ] = "pronto_driver";
274
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800275#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700276VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe, tANI_U8 *pCckmIeLen);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800277#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700278
Mihir Shetee1093ba2014-01-21 20:13:32 +0530279static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx);
Sushant Kaushik8bc7df22014-04-09 17:55:29 +0530280const char * hdd_device_modetoString(v_U8_t device_mode)
281{
282 switch(device_mode)
283 {
284 CASE_RETURN_STRING( WLAN_HDD_INFRA_STATION );
285 CASE_RETURN_STRING( WLAN_HDD_SOFTAP );
286 CASE_RETURN_STRING( WLAN_HDD_P2P_CLIENT );
287 CASE_RETURN_STRING( WLAN_HDD_P2P_GO );
288 CASE_RETURN_STRING( WLAN_HDD_MONITOR);
289 CASE_RETURN_STRING( WLAN_HDD_FTM );
290 CASE_RETURN_STRING( WLAN_HDD_IBSS );
291 CASE_RETURN_STRING( WLAN_HDD_P2P_DEVICE );
292 default:
293 return "device_mode Unknown";
294 }
295}
Mihir Shetee1093ba2014-01-21 20:13:32 +0530296
Mukul Sharmaa78cf6b2015-02-24 16:59:01 +0530297static int __hdd_netdev_notifier_call(struct notifier_block * nb,
Jeff Johnson295189b2012-06-20 16:38:30 -0700298 unsigned long state,
299 void *ndev)
300{
301 struct net_device *dev = ndev;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700302 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson27cee452013-03-27 11:10:24 -0700303 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -0700304#ifdef WLAN_BTAMP_FEATURE
305 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -0700306#endif
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530307 long result;
Jeff Johnson295189b2012-06-20 16:38:30 -0700308
309 //Make sure that this callback corresponds to our device.
Jeff Johnson27cee452013-03-27 11:10:24 -0700310 if ((strncmp(dev->name, "wlan", 4)) &&
Amar Singhal4c723bd2013-03-25 18:14:15 -0700311 (strncmp(dev->name, "p2p", 3)))
312 return NOTIFY_DONE;
313
Jeff Johnson295189b2012-06-20 16:38:30 -0700314 if (!dev->ieee80211_ptr)
Jeff Johnson27cee452013-03-27 11:10:24 -0700315 return NOTIFY_DONE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700316
Jeff Johnson27cee452013-03-27 11:10:24 -0700317 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700318 {
Jeff Johnsona8a1a482012-12-12 16:49:33 -0800319 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Adapter Null Pointer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700320 VOS_ASSERT(0);
321 return NOTIFY_DONE;
322 }
323
Jeff Johnson27cee452013-03-27 11:10:24 -0700324 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
325 if (NULL == pHddCtx)
326 {
327 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Context Null Pointer", __func__);
328 VOS_ASSERT(0);
329 return NOTIFY_DONE;
330 }
Sameer Thalappil14067972014-01-23 14:54:54 -0800331 if (pHddCtx->isLogpInProgress)
332 return NOTIFY_DONE;
333
Jeff Johnson27cee452013-03-27 11:10:24 -0700334
335 hddLog(VOS_TRACE_LEVEL_INFO, "%s: %s New Net Device State = %lu",
336 __func__, dev->name, state);
Jeff Johnson295189b2012-06-20 16:38:30 -0700337
338 switch (state) {
339 case NETDEV_REGISTER:
340 break;
341
342 case NETDEV_UNREGISTER:
343 break;
344
345 case NETDEV_UP:
346 break;
347
348 case NETDEV_DOWN:
349 break;
350
351 case NETDEV_CHANGE:
Jeff Johnsone7245742012-09-05 17:12:55 -0700352 if(TRUE == pAdapter->isLinkUpSvcNeeded)
353 complete(&pAdapter->linkup_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700354 break;
355
356 case NETDEV_GOING_DOWN:
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530357 result = wlan_hdd_scan_abort(pAdapter);
Girish Gowli4bf7a632014-06-12 13:42:11 +0530358 if (result < 0)
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530359 {
360 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
361 "%s: Timeout occurred while waiting for abortscan %ld",
362 __func__, result);
Jeff Johnson295189b2012-06-20 16:38:30 -0700363 }
364 else
365 {
366 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530367 "%s: Scan Abort Successful" , __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700368 }
369#ifdef WLAN_BTAMP_FEATURE
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700370 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s: disabling AMP", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700371 status = WLANBAP_StopAmp();
372 if(VOS_STATUS_SUCCESS != status )
373 {
374 pHddCtx->isAmpAllowed = VOS_TRUE;
375 hddLog(VOS_TRACE_LEVEL_FATAL,
376 "%s: Failed to stop AMP", __func__);
377 }
378 else
379 {
380 //a state m/c implementation in PAL is TBD to avoid this delay
381 msleep(500);
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700382 if ( pHddCtx->isAmpAllowed )
383 {
384 WLANBAP_DeregisterFromHCI();
385 pHddCtx->isAmpAllowed = VOS_FALSE;
386 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700387 }
388#endif //WLAN_BTAMP_FEATURE
389 break;
390
391 default:
392 break;
393 }
394
395 return NOTIFY_DONE;
396}
397
Mukul Sharmaa78cf6b2015-02-24 16:59:01 +0530398static int hdd_netdev_notifier_call(struct notifier_block * nb,
399 unsigned long state,
400 void *ndev)
401{
402 int ret;
403 vos_ssr_protect(__func__);
404 ret = __hdd_netdev_notifier_call( nb, state, ndev);
405 vos_ssr_unprotect(__func__);
406 return ret;
407}
408
Jeff Johnson295189b2012-06-20 16:38:30 -0700409struct notifier_block hdd_netdev_notifier = {
410 .notifier_call = hdd_netdev_notifier_call,
411};
412
413/*---------------------------------------------------------------------------
414 * Function definitions
415 *-------------------------------------------------------------------------*/
Jeff Johnson295189b2012-06-20 16:38:30 -0700416void hdd_unregister_mcast_bcast_filter(hdd_context_t *pHddCtx);
417void hdd_register_mcast_bcast_filter(hdd_context_t *pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -0700418//variable to hold the insmod parameters
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700419static int con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -0700420#ifndef MODULE
421/* current con_mode - used only for statically linked driver
422 * con_mode is changed by userspace to indicate a mode change which will
423 * result in calling the module exit and init functions. The module
424 * exit function will clean up based on the value of con_mode prior to it
425 * being changed by userspace. So curr_con_mode records the current con_mode
426 * for exit when con_mode becomes the next mode for init
427 */
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700428static int curr_con_mode;
Jeff Johnson295189b2012-06-20 16:38:30 -0700429#endif
430
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +0530431#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
432/**
433 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
434 * @hdd_ctx: hdd global context
435 *
436 * Return: none
437 */
438static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
439{
440 uint8_t i;
441
442 mutex_init(&hdd_ctx->op_ctx.op_lock);
443 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++)
444 {
445 hdd_ctx->op_ctx.op_table[i].request_id = 0;
446 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
447 }
448}
449#else
450static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
451{
452}
453#endif
454
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -0800455/**---------------------------------------------------------------------------
456
457 \brief hdd_vos_trace_enable() - Configure initial VOS Trace enable
458
459 Called immediately after the cfg.ini is read in order to configure
460 the desired trace levels.
461
462 \param - moduleId - module whose trace level is being configured
463 \param - bitmask - bitmask of log levels to be enabled
464
465 \return - void
466
467 --------------------------------------------------------------------------*/
468static void hdd_vos_trace_enable(VOS_MODULE_ID moduleId, v_U32_t bitmask)
469{
470 wpt_tracelevel level;
471
472 /* if the bitmask is the default value, then a bitmask was not
473 specified in cfg.ini, so leave the logging level alone (it
474 will remain at the "compiled in" default value) */
475 if (CFG_VOS_TRACE_ENABLE_DEFAULT == bitmask)
476 {
477 return;
478 }
479
480 /* a mask was specified. start by disabling all logging */
481 vos_trace_setValue(moduleId, VOS_TRACE_LEVEL_NONE, 0);
482
483 /* now cycle through the bitmask until all "set" bits are serviced */
484 level = VOS_TRACE_LEVEL_FATAL;
485 while (0 != bitmask)
486 {
487 if (bitmask & 1)
488 {
489 vos_trace_setValue(moduleId, level, 1);
490 }
491 level++;
492 bitmask >>= 1;
493 }
494}
495
496
Jeff Johnson295189b2012-06-20 16:38:30 -0700497/**---------------------------------------------------------------------------
498
499 \brief hdd_wdi_trace_enable() - Configure initial WDI Trace enable
500
501 Called immediately after the cfg.ini is read in order to configure
502 the desired trace levels in the WDI.
503
504 \param - moduleId - module whose trace level is being configured
505 \param - bitmask - bitmask of log levels to be enabled
506
507 \return - void
508
509 --------------------------------------------------------------------------*/
510static void hdd_wdi_trace_enable(wpt_moduleid moduleId, v_U32_t bitmask)
511{
512 wpt_tracelevel level;
513
514 /* if the bitmask is the default value, then a bitmask was not
515 specified in cfg.ini, so leave the logging level alone (it
516 will remain at the "compiled in" default value) */
517 if (CFG_WDI_TRACE_ENABLE_DEFAULT == bitmask)
518 {
519 return;
520 }
521
522 /* a mask was specified. start by disabling all logging */
523 wpalTraceSetLevel(moduleId, eWLAN_PAL_TRACE_LEVEL_NONE, 0);
524
525 /* now cycle through the bitmask until all "set" bits are serviced */
526 level = eWLAN_PAL_TRACE_LEVEL_FATAL;
527 while (0 != bitmask)
528 {
529 if (bitmask & 1)
530 {
531 wpalTraceSetLevel(moduleId, level, 1);
532 }
533 level++;
534 bitmask >>= 1;
535 }
536}
Jeff Johnson295189b2012-06-20 16:38:30 -0700537
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530538/*
539 * FUNCTION: wlan_hdd_validate_context
540 * This function is used to check the HDD context
541 */
542int wlan_hdd_validate_context(hdd_context_t *pHddCtx)
543{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530544
545 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
546 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530547 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530548 "%s: HDD context is Null", __func__);
549 return -ENODEV;
550 }
551
552 if (pHddCtx->isLogpInProgress)
553 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530554 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu8adb97b2014-12-08 19:38:20 +0530555 "%s: LOGP %s. Ignore!!", __func__,
556 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)
557 ?"failed":"in Progress");
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530558 return -EAGAIN;
559 }
560
Mihir Shete18156292014-03-11 15:38:30 +0530561 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530562 {
Mahesh A Saptasagar886997a2015-03-04 13:15:51 +0530563 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530564 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
565 return -EAGAIN;
566 }
567 return 0;
568}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700569#ifdef CONFIG_ENABLE_LINUX_REG
570void hdd_checkandupdate_phymode( hdd_context_t *pHddCtx)
571{
572 hdd_adapter_t *pAdapter = NULL;
573 hdd_station_ctx_t *pHddStaCtx = NULL;
574 eCsrPhyMode phyMode;
575 hdd_config_t *cfg_param = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530576
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700577 if (NULL == pHddCtx)
578 {
579 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
580 "HDD Context is null !!");
581 return ;
582 }
583
584 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
585 if (NULL == pAdapter)
586 {
587 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
588 "pAdapter is null !!");
589 return ;
590 }
591
592 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
593 if (NULL == pHddStaCtx)
594 {
595 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
596 "pHddStaCtx is null !!");
597 return ;
598 }
599
600 cfg_param = pHddCtx->cfg_ini;
601 if (NULL == cfg_param)
602 {
603 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
604 "cfg_params not available !!");
605 return ;
606 }
607
608 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
609
610 if (!pHddCtx->isVHT80Allowed)
611 {
612 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
613 (eCSR_DOT11_MODE_11ac == phyMode) ||
614 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
615 {
616 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
617 "Setting phymode to 11n!!");
618 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
619 }
620 }
621 else
622 {
623 /*New country Supports 11ac as well resetting value back from .ini*/
624 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
625 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
626 return ;
627 }
628
629 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
630 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
631 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
632 {
633 VOS_STATUS vosStatus;
634
635 // need to issue a disconnect to CSR.
636 INIT_COMPLETION(pAdapter->disconnect_comp_var);
637 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
638 pAdapter->sessionId,
639 eCSR_DISCONNECT_REASON_UNSPECIFIED );
640
641 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530642 {
643 long ret;
644
645 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700646 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530647 if (0 >= ret)
648 hddLog(LOGE, FL("failure waiting for disconnect_comp_var %ld"),
649 ret);
650 }
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700651
652 }
653}
654#else
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530655void hdd_checkandupdate_phymode( hdd_adapter_t *pAdapter, char *country_code)
656{
657 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
658 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
659 hdd_config_t *cfg_param;
660 eCsrPhyMode phyMode;
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530661 long ret;
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530662
663 if (NULL == pHddCtx)
664 {
665 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
666 "HDD Context is null !!");
667 return ;
668 }
669
670 cfg_param = pHddCtx->cfg_ini;
671
672 if (NULL == cfg_param)
673 {
674 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
675 "cfg_params not available !!");
676 return ;
677 }
678
679 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
680
681 if (NULL != strstr(cfg_param->listOfNon11acCountryCode, country_code))
682 {
683 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
684 (eCSR_DOT11_MODE_11ac == phyMode) ||
685 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
686 {
687 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
688 "Setting phymode to 11n!!");
689 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
690 }
691 }
692 else
693 {
694 /*New country Supports 11ac as well resetting value back from .ini*/
695 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
696 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
697 return ;
698 }
699
700 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
701 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
702 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
703 {
704 VOS_STATUS vosStatus;
705
706 // need to issue a disconnect to CSR.
707 INIT_COMPLETION(pAdapter->disconnect_comp_var);
708 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
709 pAdapter->sessionId,
710 eCSR_DISCONNECT_REASON_UNSPECIFIED );
711
712 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530713 {
714 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530715 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530716 if (ret <= 0)
717 {
718 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
719 "wait on disconnect_comp_var is failed %ld", ret);
720 }
721 }
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530722
723 }
724}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700725#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530726
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700727void hdd_checkandupdate_dfssetting( hdd_adapter_t *pAdapter, char *country_code)
728{
729 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
730 hdd_config_t *cfg_param;
731
732 if (NULL == pHddCtx)
733 {
734 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
735 "HDD Context is null !!");
736 return ;
737 }
738
739 cfg_param = pHddCtx->cfg_ini;
740
741 if (NULL == cfg_param)
742 {
743 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
744 "cfg_params not available !!");
745 return ;
746 }
747
Agarwal Ashish738843c2014-09-25 12:27:56 +0530748 if (NULL != strstr(cfg_param->listOfNonDfsCountryCode, country_code) ||
749 pHddCtx->disable_dfs_flag == TRUE)
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700750 {
751 /*New country doesn't support DFS */
752 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
753 }
754 else
755 {
756 /*New country Supports DFS as well resetting value back from .ini*/
757 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter), cfg_param->enableDFSChnlScan);
758 }
759
760}
761
Abhishek Singh00b71972016-01-07 10:51:04 +0530762#ifdef WLAN_FEATURE_RMC
763static int hdd_parse_setrmcenable_command(tANI_U8 *pValue, tANI_U8 *pRmcEnable)
764{
765 tANI_U8 *inPtr = pValue;
766 int tempInt;
767 int v = 0;
768 char buf[32];
769 *pRmcEnable = 0;
770
771 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
772 /*no argument after the command*/
773 if (NULL == inPtr)
774 {
775 return 0;
776 }
777
778 /*no space after the command*/
779 else if (SPACE_ASCII_VALUE != *inPtr)
780 {
781 return 0;
782 }
783
784 /*removing empty spaces*/
785 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
786
787 /*no argument followed by spaces*/
788 if ('\0' == *inPtr)
789 {
790 return 0;
791 }
792
793 /* getting the first argument which enables or disables RMC
794 * for input IP v4 address*/
795 sscanf(inPtr, "%32s ", buf);
796 v = kstrtos32(buf, 10, &tempInt);
797 if ( v < 0)
798 {
799 return -EINVAL;
800 }
801
802 *pRmcEnable = tempInt;
803
804 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
805 "ucRmcEnable: %d", *pRmcEnable);
806
807 return 0;
808}
809
810/* Function header left blank Intentionally */
811static int hdd_parse_setrmcactionperiod_command(tANI_U8 *pValue,
812 tANI_U32 *pActionPeriod)
813{
814 tANI_U8 *inPtr = pValue;
815 int tempInt;
816 int v = 0;
817 char buf[32];
818 *pActionPeriod = 0;
819
820 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
821 /*no argument after the command*/
822 if (NULL == inPtr)
823 {
824 return -EINVAL;
825 }
826
827 /*no space after the command*/
828 else if (SPACE_ASCII_VALUE != *inPtr)
829 {
830 return -EINVAL;
831 }
832
833 /*removing empty spaces*/
834 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
835
836 /*no argument followed by spaces*/
837 if ('\0' == *inPtr)
838 {
839 return 0;
840 }
841
842 /* getting the first argument which enables or disables RMC
843 * for input IP v4 address*/
844 sscanf(inPtr, "%32s ", buf);
845 v = kstrtos32(buf, 10, &tempInt);
846 if ( v < 0)
847 {
848 return -EINVAL;
849 }
850
851 /* Range checking for passed paramter */
852 if (tempInt < WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY_STAMIN ||
853 tempInt > WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY_STAMAX)
854 {
855 return -EINVAL;
856 }
857
858 *pActionPeriod = tempInt;
859
860 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
861 "uActionPeriod: %d", *pActionPeriod);
862
863 return 0;
864}
865
866/* Function header left blank Intentionally */
867static int hdd_parse_setrmcrate_command(tANI_U8 *pValue,
868 tANI_U32 *pRate, tTxrateinfoflags *pTxFlags)
869{
870 tANI_U8 *inPtr = pValue;
871 int tempInt;
872 int v = 0;
873 char buf[32];
874 *pRate = 0;
875 *pTxFlags = 0;
876
877 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
878 /*no argument after the command*/
879 if (NULL == inPtr)
880 {
881 return -EINVAL;
882 }
883
884 /*no space after the command*/
885 else if (SPACE_ASCII_VALUE != *inPtr)
886 {
887 return -EINVAL;
888 }
889
890 /*removing empty spaces*/
891 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
892
893 /*no argument followed by spaces*/
894 if ('\0' == *inPtr)
895 {
896 return 0;
897 }
898
899 /*
900 * getting the first argument which sets multicast rate.
901 */
902 sscanf(inPtr, "%32s ", buf);
903 v = kstrtos32(buf, 10, &tempInt);
904 if ( v < 0)
905 {
906 return -EINVAL;
907 }
908
909 /*
910 * Validate the multicast rate.
911 */
912 switch (tempInt)
913 {
914 default:
915 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
916 "Unsupported rate: %d", tempInt);
917 return -EINVAL;
918 case 0:
919 case 6:
920 case 9:
921 case 12:
922 case 18:
923 case 24:
924 case 36:
925 case 48:
926 case 54:
927 *pTxFlags = eHAL_TX_RATE_LEGACY;
928 *pRate = tempInt * 10;
929 break;
930 case 65:
931 *pTxFlags = eHAL_TX_RATE_HT20;
932 *pRate = tempInt * 10;
933 break;
934 case 72:
935 *pTxFlags = eHAL_TX_RATE_HT20 | eHAL_TX_RATE_SGI;
936 *pRate = 722; /* fractional rate 72.2 Mbps */
937 break;
938 }
939
940 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
941 "Rate: %d", *pRate);
942
943 return 0;
944}
945
946/**---------------------------------------------------------------------------
947
948 \brief hdd_cfg80211_get_ibss_peer_info_cb() - Callback function for IBSS
949 Peer Info request
950
951 This is an asynchronous callback function from SME when the peer info
952 is received
953
954 \pUserData -> Adapter private data
955 \pPeerInfoRsp -> Peer info response
956
957 \return - 0 for success non-zero for failure
958 --------------------------------------------------------------------------*/
959static void
960hdd_cfg80211_get_ibss_peer_info_cb(v_VOID_t *pUserData, v_VOID_t *pPeerInfoRsp)
961{
962 hdd_adapter_t *pAdapter = (hdd_adapter_t *)pUserData;
963 tSirPeerInfoRspParams *pPeerInfo = (tSirPeerInfoRspParams *)pPeerInfoRsp;
964 hdd_station_ctx_t *pStaCtx;
965 v_U8_t i;
966
967 /*Sanity check*/
968 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
969 {
970 hddLog(LOGE,
971 FL("invalid adapter or adapter has invalid magic"));
972 return;
973 }
974
975 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
976 if (NULL != pStaCtx && NULL != pPeerInfo &&
977 eHAL_STATUS_SUCCESS == pPeerInfo->status)
978 {
979 pStaCtx->ibss_peer_info.status = pPeerInfo->status;
980 pStaCtx->ibss_peer_info.numIBSSPeers = pPeerInfo->numPeers;
981
982 /* Paranoia check */
983 if (pPeerInfo->numPeers < HDD_MAX_NUM_IBSS_STA)
984 {
985 for (i = 0; i < pPeerInfo->numPeers; i++)
986 {
987 memcpy(&pStaCtx->ibss_peer_info.ibssPeerList[i],
988 &pPeerInfo->peerInfoParams[i],
989 sizeof(hdd_ibss_peer_info_params_t));
990 }
991 hddLog(LOG1,
992 FL("Peer Info copied in HDD"));
993 }
994 else
995 {
996 hddLog(LOGE,
997 FL(" Number of peers %d returned is more than limit %d"),
998 pPeerInfo->numPeers, HDD_MAX_NUM_IBSS_STA);
999 }
1000 }
1001 else
1002 {
1003 hddLog(LOG1,
1004 FL("peerInfo returned is NULL"));
1005 }
1006
1007 complete(&pAdapter->ibss_peer_info_comp);
1008}
1009
1010/**---------------------------------------------------------------------------
1011
1012 \brief hdd_cfg80211_get_ibss_peer_info_all() -
1013
1014 Request function to get IBSS peer info from lower layers
1015
1016 \pAdapter -> Adapter context
1017
1018 \return - 0 for success non-zero for failure
1019 --------------------------------------------------------------------------*/
1020static
1021VOS_STATUS hdd_cfg80211_get_ibss_peer_info_all(hdd_adapter_t *pAdapter)
1022{
1023 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1024 long status;
1025 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1026
1027 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1028
1029 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1030 hdd_cfg80211_get_ibss_peer_info_cb,
1031 VOS_TRUE, 0xFF);
1032
1033 if (VOS_STATUS_SUCCESS == retStatus)
1034 {
1035 status = wait_for_completion_interruptible_timeout
1036 (&pAdapter->ibss_peer_info_comp,
1037 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1038
1039 /* status will be 0 if timed out */
1040 if (status <= 0)
1041 {
1042 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1043 __func__, status);
1044 retStatus = VOS_STATUS_E_FAILURE;
1045 return retStatus;
1046 }
1047 }
1048 else
1049 {
1050 hddLog(VOS_TRACE_LEVEL_WARN,
1051 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1052 }
1053
1054 return retStatus;
1055}
1056
1057/**---------------------------------------------------------------------------
1058
1059 \brief hdd_cfg80211_get_ibss_peer_info() -
1060
1061 Request function to get IBSS peer info from lower layers
1062
1063 \pAdapter -> Adapter context
1064 \staIdx -> Sta index for which the peer info is requested
1065
1066 \return - 0 for success non-zero for failure
1067 --------------------------------------------------------------------------*/
1068static VOS_STATUS
1069hdd_cfg80211_get_ibss_peer_info(hdd_adapter_t *pAdapter, v_U8_t staIdx)
1070{
1071 long status;
1072 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
1073 VOS_STATUS retStatus = VOS_STATUS_E_FAILURE;
1074
1075 INIT_COMPLETION(pAdapter->ibss_peer_info_comp);
1076
1077 retStatus = sme_RequestIBSSPeerInfo(hHal, pAdapter,
1078 hdd_cfg80211_get_ibss_peer_info_cb,
1079 VOS_FALSE, staIdx);
1080
1081 if (VOS_STATUS_SUCCESS == retStatus)
1082 {
1083 status = wait_for_completion_interruptible_timeout
1084 (&pAdapter->ibss_peer_info_comp,
1085 msecs_to_jiffies(IBSS_PEER_INFO_REQ_TIMOEUT));
1086
1087 /* status = 0 on timeout */
1088 if (status <= 0)
1089 {
1090 hddLog(VOS_TRACE_LEVEL_WARN, "%s: Warning: IBSS_PEER_INFO_TIMEOUT %ld",
1091 __func__, status);
1092 retStatus = VOS_STATUS_E_FAILURE;
1093 return retStatus;
1094 }
1095 }
1096 else
1097 {
1098 hddLog(VOS_TRACE_LEVEL_WARN,
1099 "%s: Warning: sme_RequestIBSSPeerInfo Request failed", __func__);
1100 }
1101
1102 return retStatus;
1103}
1104
1105/* Function header left blank Intentionally */
1106VOS_STATUS
1107hdd_parse_get_ibss_peer_info(tANI_U8 *pValue, v_MACADDR_t *pPeerMacAddr)
1108{
1109 tANI_U8 *inPtr = pValue;
1110 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1111
1112 /*no argument after the command*/
1113 if (NULL == inPtr)
1114 {
1115 return VOS_STATUS_E_FAILURE;;
1116 }
1117
1118 /*no space after the command*/
1119 else if (SPACE_ASCII_VALUE != *inPtr)
1120 {
1121 return VOS_STATUS_E_FAILURE;;
1122 }
1123
1124 /*removing empty spaces*/
1125 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
1126
1127 /*no argument followed by spaces*/
1128 if ('\0' == *inPtr)
1129 {
1130 return VOS_STATUS_E_FAILURE;;
1131 }
1132
1133 /*getting the first argument ie the peer mac address */
1134 if (inPtr[2] != ':' || inPtr[5] != ':' || inPtr[8] != ':' ||
1135 inPtr[11] != ':' || inPtr[14] != ':')
1136 {
1137 return VOS_STATUS_E_FAILURE;;
1138 }
1139 sscanf(inPtr, "%2x:%2x:%2x:%2x:%2x:%2x",
1140 (unsigned int *)&pPeerMacAddr->bytes[0],
1141 (unsigned int *)&pPeerMacAddr->bytes[1],
1142 (unsigned int *)&pPeerMacAddr->bytes[2],
1143 (unsigned int *)&pPeerMacAddr->bytes[3],
1144 (unsigned int *)&pPeerMacAddr->bytes[4],
1145 (unsigned int *)&pPeerMacAddr->bytes[5]);
1146
1147 /* The command buffer seems to be fine */
1148 return VOS_STATUS_SUCCESS;
1149}
1150
1151/* Function header left blank Intentionally */
1152static int hdd_parse_set_ibss_oui_data_command(tANI_U8 *command, tANI_U8 *ie,
1153 tANI_U32 limit)
1154{
1155 tANI_U8 len;
1156 tANI_U8 data;
1157
1158 /* skip white space */
1159 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1160 {
1161 command++;
1162 limit--;
1163 }
1164
1165 /* skip element id and element length */
1166 len = 2;
1167
1168 /* extract oui */
1169 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1170 (limit > 1))
1171 {
1172 /* Convert ASCII to decimal */
1173 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1174 ie[len++] = data;
1175 command += 2;
1176 limit -= 2;
1177 }
1178
1179 /* skip white space */
1180 while ((SPACE_ASCII_VALUE == *command) && ('\0' != *command))
1181 {
1182 command++;
1183 limit--;
1184 }
1185
1186 /* extract data */
1187 while ((SPACE_ASCII_VALUE != *command) && ('\0' != *command) &&
1188 (limit > 1))
1189 {
1190 /* Convert ASCII to decimal */
1191 data = ((*command -'0') << 4) | (*(command + 1) - '0');
1192 ie[len++] = data;
1193 command += 2;
1194 limit -= 2;
1195 }
1196
1197 /* fill element id and element length */
1198 ie[0] = IE_EID_VENDOR;
1199 ie[1] = len - 2;
1200
1201 return len;
1202}
1203
1204static tANI_U32 hdd_find_ibss_wpa_ie_pos(tANI_U8 *addIePtr, tANI_U32 addIeLen)
1205{
1206 tANI_U32 ieLenPresent = 0;
1207 int left = addIeLen;
1208 v_U8_t *ptr = addIePtr;
1209 v_U8_t elem_id,elem_len;
1210
1211 while(left >= 2)
1212 {
1213 elem_id = ptr[0];
1214 elem_len = ptr[1];
1215 left -= 2;
1216 if(elem_len > left)
1217 {
1218 hddLog(LOGE,
1219 FL("****Invalid elem_len=%d left=%d*****"),
1220 elem_len,left);
1221 return 0;
1222 }
1223 if ((elem_id == IE_EID_VENDOR) &&
1224 (left >= WPA_OUI_TYPE_SIZE))
1225 {
1226 if (!memcmp(&ptr[2], WPA_OUI_TYPE,
1227 WPA_OUI_TYPE_SIZE))
1228 {
1229 ieLenPresent += elem_len + 2;
1230 return ieLenPresent;
1231 }
1232 }
1233 ieLenPresent += (elem_len + 2);
1234 left -= elem_len;
1235 ptr += (elem_len + 2);
1236 }
1237 return 0;
1238}
1239
1240#endif /* WLAN_FEATURE_RMC */
1241
Rajeev79dbe4c2013-10-05 11:03:42 +05301242#ifdef FEATURE_WLAN_BATCH_SCAN
1243
1244/**---------------------------------------------------------------------------
1245
1246 \brief hdd_extract_assigned_int_from_str() - Extracts assigned integer from
1247 input string
1248
1249 This function extracts assigned integer from string in below format:
1250 "STRING=10" : extracts integer 10 from this string
1251
1252 \param - pInPtr Pointer to input string
1253 \param - base Base for string to int conversion(10 for decimal 16 for hex)
1254 \param - pOutPtr Pointer to variable in which extracted integer needs to be
1255 assigned
1256 \param - pLastArg to tell whether it is last arguement in input string or
1257 not
1258
1259 \return - NULL for failure cases
1260 pointer to next arguement in input string for success cases
1261 --------------------------------------------------------------------------*/
1262static tANI_U8 *
1263hdd_extract_assigned_int_from_str
1264(
1265 tANI_U8 *pInPtr,
1266 tANI_U8 base,
1267 tANI_U32 *pOutPtr,
1268 tANI_U8 *pLastArg
1269)
1270{
1271 int tempInt;
1272 int v = 0;
1273 char buf[32];
1274 int val = 0;
1275 *pLastArg = FALSE;
1276
1277 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1278 if (NULL == pInPtr)
1279 {
1280 return NULL;
1281 }
1282
1283 pInPtr++;
1284
1285 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1286
1287 val = sscanf(pInPtr, "%32s ", buf);
1288 if (val < 0 && val > strlen(pInPtr))
1289 {
1290 return NULL;
1291 }
1292 pInPtr += val;
1293 v = kstrtos32(buf, base, &tempInt);
1294 if (v < 0)
1295 {
1296 return NULL;
1297 }
Rajeev Kumar4d93d842014-01-02 18:31:21 -08001298 if (tempInt < 0)
1299 {
1300 tempInt = 0;
1301 }
Rajeev79dbe4c2013-10-05 11:03:42 +05301302 *pOutPtr = tempInt;
1303
1304 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1305 if (NULL == pInPtr)
1306 {
1307 *pLastArg = TRUE;
1308 return NULL;
1309 }
1310 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1311
1312 return pInPtr;
1313}
1314
1315/**---------------------------------------------------------------------------
1316
1317 \brief hdd_extract_assigned_char_from_str() - Extracts assigned char from
1318 input string
1319
1320 This function extracts assigned character from string in below format:
1321 "STRING=A" : extracts char 'A' from this string
1322
1323 \param - pInPtr Pointer to input string
1324 \param - pOutPtr Pointer to variable in which extracted char needs to be
1325 assigned
1326 \param - pLastArg to tell whether it is last arguement in input string or
1327 not
1328
1329 \return - NULL for failure cases
1330 pointer to next arguement in input string for success cases
1331 --------------------------------------------------------------------------*/
1332static tANI_U8 *
1333hdd_extract_assigned_char_from_str
1334(
1335 tANI_U8 *pInPtr,
1336 tANI_U8 *pOutPtr,
1337 tANI_U8 *pLastArg
1338)
1339{
1340 *pLastArg = FALSE;
1341
1342 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
1343 if (NULL == pInPtr)
1344 {
1345 return NULL;
1346 }
1347
1348 pInPtr++;
1349
1350 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1351
1352 *pOutPtr = *pInPtr;
1353
1354 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
1355 if (NULL == pInPtr)
1356 {
1357 *pLastArg = TRUE;
1358 return NULL;
1359 }
1360 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
1361
1362 return pInPtr;
1363}
1364
1365
1366/**---------------------------------------------------------------------------
1367
1368 \brief hdd_parse_set_batchscan_command () - HDD parse set batch scan command
1369
1370 This function parses set batch scan command in below format:
1371 WLS_BATCHING_SET <space> followed by below arguements
1372 "SCANFREQ=XX" : Optional defaults to 30 sec
1373 "MSCAN=XX" : Required number of scans to attempt to batch
1374 "BESTN=XX" : Best Network (RSSI) defaults to 16
1375 "CHANNEL=<X,Y>" : optional defaults to all channels, can list 'A'or` B.
1376 A. implies only 5 GHz , B. implies only 2.4GHz
1377 "RTT=X" : optional defaults to 0
1378 returns the MIN of MSCAN or the max # of scans firmware can cache or -1 on
1379 error
1380
1381 For example input commands:
1382 1) WLS_BATCHING_SET SCANFREQ=60 MSCAN=10 BESTN=20 CHANNEL=A RTT=0 -> This is
1383 translated into set batch scan with following parameters:
1384 a) Frequence 60 seconds
1385 b) Batch 10 scans together
1386 c) Best RSSI to be 20
1387 d) 5GHz band only
1388 e) RTT is equal to 0
1389
1390 \param - pValue Pointer to input channel list
1391 \param - pHddSetBatchScanReq Pointer to HDD batch scan request structure
1392
1393 \return - 0 for success non-zero for failure
1394
1395 --------------------------------------------------------------------------*/
1396static int
1397hdd_parse_set_batchscan_command
1398(
1399 tANI_U8 *pValue,
1400 tSirSetBatchScanReq *pHddSetBatchScanReq
1401)
1402{
1403 tANI_U8 *inPtr = pValue;
1404 tANI_U8 val = 0;
1405 tANI_U8 lastArg = 0;
Abhishek Singh00b71972016-01-07 10:51:04 +05301406 tANI_U32 nScanFreq = HDD_SET_BATCH_SCAN_DEFAULT_FREQ;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001407 tANI_U32 nMscan;
Abhishek Singh00b71972016-01-07 10:51:04 +05301408 tANI_U32 nBestN = HDD_SET_BATCH_SCAN_BEST_NETWORK;
1409 tANI_U8 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1410 tANI_U32 nRtt = 0;
Rajeev Kumarc933d982013-11-18 20:04:20 -08001411 tANI_U32 temp;
Rajeev79dbe4c2013-10-05 11:03:42 +05301412
Rajeev79dbe4c2013-10-05 11:03:42 +05301413 /*go to space after WLS_BATCHING_SET command*/
1414 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
1415 /*no argument after the command*/
1416 if (NULL == inPtr)
1417 {
1418 return -EINVAL;
1419 }
1420
1421 /*no space after the command*/
1422 else if (SPACE_ASCII_VALUE != *inPtr)
1423 {
1424 return -EINVAL;
1425 }
1426
1427 /*removing empty spaces*/
1428 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
1429
1430 /*no argument followed by spaces*/
1431 if ('\0' == *inPtr)
1432 {
1433 return -EINVAL;
1434 }
1435
1436 /*check and parse SCANFREQ*/
1437 if ((strncmp(inPtr, "SCANFREQ", 8) == 0))
1438 {
1439 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001440 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001441
Rajeev Kumarc933d982013-11-18 20:04:20 -08001442 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001443 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001444 nScanFreq = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001445 }
1446
Rajeev79dbe4c2013-10-05 11:03:42 +05301447 if ( (NULL == inPtr) || (TRUE == lastArg))
1448 {
1449 return -EINVAL;
1450 }
1451 }
1452
1453 /*check and parse MSCAN*/
1454 if ((strncmp(inPtr, "MSCAN", 5) == 0))
1455 {
1456 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001457 &nMscan, &lastArg);
1458
1459 if (0 == nMscan)
1460 {
1461 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1462 "invalid MSCAN=%d", nMscan);
1463 return -EINVAL;
1464 }
1465
Rajeev79dbe4c2013-10-05 11:03:42 +05301466 if (TRUE == lastArg)
1467 {
1468 goto done;
1469 }
1470 else if (NULL == inPtr)
1471 {
1472 return -EINVAL;
1473 }
1474 }
1475 else
1476 {
1477 return -EINVAL;
1478 }
1479
1480 /*check and parse BESTN*/
1481 if ((strncmp(inPtr, "BESTN", 5) == 0))
1482 {
1483 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -08001484 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001485
Rajeev Kumarc933d982013-11-18 20:04:20 -08001486 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001487 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001488 nBestN = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001489 }
1490
Rajeev79dbe4c2013-10-05 11:03:42 +05301491 if (TRUE == lastArg)
1492 {
1493 goto done;
1494 }
1495 else if (NULL == inPtr)
1496 {
1497 return -EINVAL;
1498 }
1499 }
1500
1501 /*check and parse CHANNEL*/
1502 if ((strncmp(inPtr, "CHANNEL", 7) == 0))
1503 {
1504 inPtr = hdd_extract_assigned_char_from_str(inPtr, &val, &lastArg);
Rajeev Kumarc933d982013-11-18 20:04:20 -08001505
Rajeev79dbe4c2013-10-05 11:03:42 +05301506 if (('A' == val) || ('a' == val))
1507 {
c_hpothuebf89732014-02-25 13:00:24 +05301508 ucRfBand = HDD_SET_BATCH_SCAN_5GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301509 }
1510 else if (('B' == val) || ('b' == val))
1511 {
c_hpothuebf89732014-02-25 13:00:24 +05301512 ucRfBand = HDD_SET_BATCH_SCAN_24GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +05301513 }
1514 else
1515 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001516 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
1517 }
1518
1519 if (TRUE == lastArg)
1520 {
1521 goto done;
1522 }
1523 else if (NULL == inPtr)
1524 {
Rajeev79dbe4c2013-10-05 11:03:42 +05301525 return -EINVAL;
1526 }
1527 }
1528
1529 /*check and parse RTT*/
1530 if ((strncmp(inPtr, "RTT", 3) == 0))
1531 {
1532 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001533 &nRtt, &lastArg);
Rajeev79dbe4c2013-10-05 11:03:42 +05301534 if (TRUE == lastArg)
1535 {
1536 goto done;
1537 }
1538 if (NULL == inPtr)
1539 {
1540 return -EINVAL;
1541 }
1542 }
1543
1544
1545done:
1546
Rajeev Kumar45e64a72013-11-18 19:48:15 -08001547 pHddSetBatchScanReq->scanFrequency = nScanFreq;
1548 pHddSetBatchScanReq->numberOfScansToBatch = nMscan;
1549 pHddSetBatchScanReq->bestNetwork = nBestN;
1550 pHddSetBatchScanReq->rfBand = ucRfBand;
1551 pHddSetBatchScanReq->rtt = nRtt;
1552
Rajeev79dbe4c2013-10-05 11:03:42 +05301553 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1554 "Received WLS_BATCHING_SET with SCANFREQ=%d "
1555 "MSCAN=%d BESTN=%d CHANNEL=%d RTT=%d",
1556 pHddSetBatchScanReq->scanFrequency,
1557 pHddSetBatchScanReq->numberOfScansToBatch,
1558 pHddSetBatchScanReq->bestNetwork,
1559 pHddSetBatchScanReq->rfBand,
1560 pHddSetBatchScanReq->rtt);
1561
1562 return 0;
1563}/*End of hdd_parse_set_batchscan_command*/
1564
1565/**---------------------------------------------------------------------------
1566
1567 \brief hdd_set_batch_scan_req_callback () - This function is called after
1568 receiving set batch scan response from FW and it saves set batch scan
1569 response data FW to HDD context and sets the completion event on
1570 which hdd_ioctl is waiting
1571
1572 \param - callbackContext Pointer to HDD adapter
1573 \param - pRsp Pointer to set batch scan response data received from FW
1574
1575 \return - nothing
1576
1577 --------------------------------------------------------------------------*/
1578static void hdd_set_batch_scan_req_callback
1579(
1580 void *callbackContext,
1581 tSirSetBatchScanRsp *pRsp
1582)
1583{
1584 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
1585 tSirSetBatchScanRsp *pHddSetBatchScanRsp;
1586
1587 /*sanity check*/
1588 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
1589 {
1590 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1591 "%s: Invalid pAdapter magic", __func__);
1592 VOS_ASSERT(0);
1593 return;
1594 }
1595 pHddSetBatchScanRsp = &pAdapter->hddSetBatchScanRsp;
1596
1597 /*save set batch scan response*/
1598 pHddSetBatchScanRsp->nScansToBatch = pRsp->nScansToBatch;
1599
1600 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
1601 "Received set batch scan rsp from FW with nScansToBatch=%d",
1602 pHddSetBatchScanRsp->nScansToBatch);
1603
1604 pAdapter->hdd_wait_for_set_batch_scan_rsp = FALSE;
1605 complete(&pAdapter->hdd_set_batch_scan_req_var);
1606
1607 return;
1608}/*End of hdd_set_batch_scan_req_callback*/
1609
1610
1611/**---------------------------------------------------------------------------
1612
1613 \brief hdd_populate_batch_scan_rsp_queue () - This function stores AP meta
1614 info in hdd batch scan response queue
1615
1616 \param - pAdapter Pointer to hdd adapter
1617 \param - pAPMetaInfo Pointer to access point meta info
1618 \param - scanId scan ID of batch scan response
1619 \param - isLastAp tells whether AP is last AP in batch scan response or not
1620
1621 \return - nothing
1622
1623 --------------------------------------------------------------------------*/
1624static void hdd_populate_batch_scan_rsp_queue( hdd_adapter_t* pAdapter,
1625 tpSirBatchScanNetworkInfo pApMetaInfo, tANI_U32 scanId, v_BOOL_t isLastAp)
1626{
1627 tHddBatchScanRsp *pHead;
1628 tHddBatchScanRsp *pNode;
1629 tHddBatchScanRsp *pPrev;
1630 tHddBatchScanRsp *pTemp;
1631 tANI_U8 ssidLen;
1632
1633 /*head of hdd batch scan response queue*/
1634 pHead = pAdapter->pBatchScanRsp;
1635
1636 pNode = (tHddBatchScanRsp *)vos_mem_malloc(sizeof(tHddBatchScanRsp));
1637 if (NULL == pNode)
1638 {
1639 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1640 "%s: Could not allocate memory", __func__);
1641 VOS_ASSERT(0);
1642 return;
1643 }
1644
1645 vos_mem_copy(pNode->ApInfo.bssid, pApMetaInfo->bssid,
1646 sizeof(pNode->ApInfo.bssid));
1647 ssidLen = strlen(pApMetaInfo->ssid);
1648 if (SIR_MAX_SSID_SIZE < ssidLen)
1649 {
1650 /*invalid scan result*/
1651 vos_mem_free(pNode);
1652 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1653 "%s: Invalid AP meta info ssidlen %d", __func__, ssidLen);
1654 return;
1655 }
1656 vos_mem_copy(pNode->ApInfo.ssid, pApMetaInfo->ssid, ssidLen);
1657 /*null terminate ssid*/
1658 pNode->ApInfo.ssid[ssidLen] = '\0';
1659 pNode->ApInfo.ch = pApMetaInfo->ch;
1660 pNode->ApInfo.rssi = pApMetaInfo->rssi;
1661 pNode->ApInfo.age = pApMetaInfo->timestamp;
1662 pNode->ApInfo.batchId = scanId;
1663 pNode->ApInfo.isLastAp = isLastAp;
1664
1665 pNode->pNext = NULL;
1666 if (NULL == pHead)
1667 {
1668 pAdapter->pBatchScanRsp = pNode;
1669 }
1670 else
1671 {
1672 pTemp = pHead;
1673 while (NULL != pTemp)
1674 {
1675 pPrev = pTemp;
1676 pTemp = pTemp->pNext;
1677 }
1678 pPrev->pNext = pNode;
1679 }
1680
1681 return;
1682}/*End of hdd_populate_batch_scan_rsp_queue*/
1683
1684/**---------------------------------------------------------------------------
1685
1686 \brief hdd_batch_scan_result_ind_callback () - This function is called after
1687 receiving batch scan response indication from FW. It saves get batch scan
1688 response data in HDD batch scan response queue. This callback sets the
1689 completion event on which hdd_ioctl is waiting only after getting complete
1690 batch scan response data from FW
1691
1692 \param - callbackContext Pointer to HDD adapter
1693 \param - pRsp Pointer to get batch scan response data received from FW
1694
1695 \return - nothing
1696
1697 --------------------------------------------------------------------------*/
1698static void hdd_batch_scan_result_ind_callback
1699(
1700 void *callbackContext,
1701 void *pRsp
1702)
1703{
1704 v_BOOL_t isLastAp;
1705 tANI_U32 numApMetaInfo;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001706 tANI_U32 numNetworkInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301707 tANI_U32 numberScanList;
1708 tANI_U32 nextScanListOffset;
1709 tANI_U32 nextApMetaInfoOffset;
1710 hdd_adapter_t* pAdapter;
1711 tpSirBatchScanList pScanList;
1712 tpSirBatchScanNetworkInfo pApMetaInfo;
1713 tpSirBatchScanResultIndParam pBatchScanRsp;/*batch scan rsp data from FW*/
1714 tSirSetBatchScanReq *pReq;
1715
1716 pAdapter = (hdd_adapter_t *)callbackContext;
1717 /*sanity check*/
Rajeev Kumar5286bb92013-12-05 11:52:10 -08001718 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
Rajeev79dbe4c2013-10-05 11:03:42 +05301719 {
1720 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1721 "%s: Invalid pAdapter magic", __func__);
1722 VOS_ASSERT(0);
1723 return;
1724 }
1725
1726 /*initialize locals*/
1727 pReq = &pAdapter->hddSetBatchScanReq;
1728 pBatchScanRsp = (tpSirBatchScanResultIndParam)pRsp;
1729 isLastAp = FALSE;
1730 numApMetaInfo = 0;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001731 numNetworkInScanList = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05301732 numberScanList = 0;
1733 nextScanListOffset = 0;
1734 nextApMetaInfoOffset = 0;
1735 pScanList = NULL;
1736 pApMetaInfo = NULL;
1737
1738 if ((NULL == pBatchScanRsp) || (NULL == pReq))
1739 {
1740 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1741 "%s: pBatchScanRsp is %p pReq %p", __func__, pBatchScanRsp, pReq);
1742 isLastAp = TRUE;
1743 goto done;
1744 }
1745
1746 pAdapter->numScanList = numberScanList = pBatchScanRsp->numScanLists;
1747 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1748 "Batch scan rsp: numberScalList %d", numberScanList);
1749
1750 if ((!numberScanList) || (numberScanList > pReq->numberOfScansToBatch))
1751 {
1752 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1753 "%s: numberScanList %d", __func__, numberScanList);
1754 isLastAp = TRUE;
1755 goto done;
1756 }
1757
1758 while (numberScanList)
1759 {
Rajeev Kumarce651e42013-10-21 18:57:15 -07001760 pScanList = (tpSirBatchScanList)((tANI_U8 *)pBatchScanRsp->scanResults +
Rajeev79dbe4c2013-10-05 11:03:42 +05301761 nextScanListOffset);
1762 if (NULL == pScanList)
1763 {
1764 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1765 "%s: pScanList is %p", __func__, pScanList);
1766 isLastAp = TRUE;
1767 goto done;
1768 }
Rajeev Kumarce651e42013-10-21 18:57:15 -07001769 numNetworkInScanList = numApMetaInfo = pScanList->numNetworksInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301770 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumarce651e42013-10-21 18:57:15 -07001771 "Batch scan rsp: numApMetaInfo %d scanId %d",
1772 numApMetaInfo, pScanList->scanId);
Rajeev79dbe4c2013-10-05 11:03:42 +05301773
1774 if ((!numApMetaInfo) || (numApMetaInfo > pReq->bestNetwork))
1775 {
1776 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1777 "%s: numApMetaInfo %d", __func__, numApMetaInfo);
1778 isLastAp = TRUE;
1779 goto done;
1780 }
1781
Rajeev Kumarce651e42013-10-21 18:57:15 -07001782 /*Initialize next AP meta info offset for next scan list*/
1783 nextApMetaInfoOffset = 0;
1784
Rajeev79dbe4c2013-10-05 11:03:42 +05301785 while (numApMetaInfo)
1786 {
1787 pApMetaInfo = (tpSirBatchScanNetworkInfo)(pScanList->scanList +
1788 nextApMetaInfoOffset);
1789 if (NULL == pApMetaInfo)
1790 {
1791 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1792 "%s: pApMetaInfo is %p", __func__, pApMetaInfo);
1793 isLastAp = TRUE;
1794 goto done;
1795 }
1796 /*calculate AP age*/
1797 pApMetaInfo->timestamp =
1798 pBatchScanRsp->timestamp - pApMetaInfo->timestamp;
1799
1800 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussaina7c8e412013-11-20 11:06:42 -08001801 "%s: bssId "MAC_ADDRESS_STR
1802 " ch %d rssi %d timestamp %d", __func__,
1803 MAC_ADDR_ARRAY(pApMetaInfo->bssid),
1804 pApMetaInfo->ch, pApMetaInfo->rssi,
1805 pApMetaInfo->timestamp);
Rajeev79dbe4c2013-10-05 11:03:42 +05301806
1807 /*mark last AP in batch scan response*/
1808 if ((TRUE == pBatchScanRsp->isLastResult) &&
1809 (1 == numberScanList) && (1 == numApMetaInfo))
1810 {
1811 isLastAp = TRUE;
1812 }
1813
1814 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1815 /*store batch scan repsonse in hdd queue*/
1816 hdd_populate_batch_scan_rsp_queue(pAdapter, pApMetaInfo,
1817 pScanList->scanId, isLastAp);
1818 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1819
1820 nextApMetaInfoOffset += sizeof(tSirBatchScanNetworkInfo);
1821 numApMetaInfo--;
1822 }
1823
Rajeev Kumarce651e42013-10-21 18:57:15 -07001824 nextScanListOffset += ((sizeof(tSirBatchScanList) - sizeof(tANI_U8))
1825 + (sizeof(tSirBatchScanNetworkInfo)
1826 * numNetworkInScanList));
Rajeev79dbe4c2013-10-05 11:03:42 +05301827 numberScanList--;
1828 }
1829
1830done:
1831
1832 /*notify hdd_ioctl only if complete batch scan rsp is received and it was
1833 requested from hdd_ioctl*/
1834 if ((TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp) &&
1835 (TRUE == isLastAp))
1836 {
1837 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
1838 complete(&pAdapter->hdd_get_batch_scan_req_var);
1839 }
1840
1841 return;
1842}/*End of hdd_batch_scan_result_ind_callback*/
1843
1844/**---------------------------------------------------------------------------
1845
1846 \brief hdd_format_batch_scan_rsp () - This function formats batch scan
1847 response as per batch scan FR request format by putting proper markers
1848
1849 \param - pDest pointer to destination buffer
1850 \param - cur_len current length
1851 \param - tot_len total remaining size which can be written to user space
1852 \param - pApMetaInfo Pointer to get batch scan response AP meta info
1853 \param - pAdapter Pointer to HDD adapter
1854
1855 \return - ret no of characters written
1856
1857 --------------------------------------------------------------------------*/
1858static tANI_U32
1859hdd_format_batch_scan_rsp
1860(
1861 tANI_U8 *pDest,
1862 tANI_U32 cur_len,
1863 tANI_U32 tot_len,
1864 tHddBatchScanRsp *pApMetaInfo,
1865 hdd_adapter_t* pAdapter
1866)
1867{
1868 tANI_U32 ret = 0;
1869 tANI_U32 rem_len = 0;
1870 tANI_U8 temp_len = 0;
1871 tANI_U8 temp_total_len = 0;
1872 tANI_U8 temp[HDD_BATCH_SCAN_AP_META_INFO_SIZE];
1873 tANI_U8 *pTemp = temp;
1874
1875 /*Batch scan reponse needs to be returned to user space in
1876 following format:
1877 "scancount=X\n" where X is the number of scans in current batch
1878 batch
1879 "trunc\n" optional present if current scan truncated
1880 "bssid=XX:XX:XX:XX:XX:XX\n"
1881 "ssid=XXXX\n"
1882 "freq=X\n" frequency in Mhz
1883 "level=XX\n"
1884 "age=X\n" ms
1885 "dist=X\n" cm (-1 if not available)
1886 "errror=X\n" (-1if not available)
1887 "====\n" (end of ap marker)
1888 "####\n" (end of scan marker)
1889 "----\n" (end of results)*/
1890 /*send scan result in above format to user space based on
1891 available length*/
1892 /*The GET response may have more data than the driver can return in its
1893 buffer. In that case the buffer should be filled to the nearest complete
1894 scan, ending with "%%%%".Subsequent callsshould return the remaining data
1895 starting with the next scan (optional .trunc\n., .apcount=X\n., etc).
1896 The final buffer should end with "----\n"*/
1897
1898 /*sanity*/
1899 if (cur_len > tot_len)
1900 {
1901 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1902 "%s: invaid cur_len %d tot_len %d", __func__, cur_len, tot_len);
1903 return 0;
1904 }
1905 else
1906 {
1907 rem_len = (tot_len - cur_len);
1908 }
1909
1910 /*end scan marker*/
1911 if (pApMetaInfo->ApInfo.batchId != pAdapter->prev_batch_id)
1912 {
1913 temp_len = snprintf(pTemp, sizeof(temp), "####\n");
1914 pTemp += temp_len;
1915 temp_total_len += temp_len;
1916 }
1917
1918 /*bssid*/
1919 temp_len = snprintf(pTemp, sizeof(temp),
1920 "bssid=0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n",
1921 pApMetaInfo->ApInfo.bssid[0], pApMetaInfo->ApInfo.bssid[1],
1922 pApMetaInfo->ApInfo.bssid[2], pApMetaInfo->ApInfo.bssid[3],
1923 pApMetaInfo->ApInfo.bssid[4], pApMetaInfo->ApInfo.bssid[5]);
1924 pTemp += temp_len;
1925 temp_total_len += temp_len;
1926
1927 /*ssid*/
1928 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "ssid=%s\n",
1929 pApMetaInfo->ApInfo.ssid);
1930 pTemp += temp_len;
1931 temp_total_len += temp_len;
1932
1933 /*freq*/
1934 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "freq=%d\n",
Rajeev Kumarc40f7512013-11-04 14:13:23 -08001935 sme_ChnToFreq(pApMetaInfo->ApInfo.ch));
Rajeev79dbe4c2013-10-05 11:03:42 +05301936 pTemp += temp_len;
1937 temp_total_len += temp_len;
1938
1939 /*level*/
1940 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "level=%d\n",
1941 pApMetaInfo->ApInfo.rssi);
1942 pTemp += temp_len;
1943 temp_total_len += temp_len;
1944
1945 /*age*/
Jeff Johnson02797792013-10-26 19:17:13 -07001946 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "age=%d\n",
Rajeev79dbe4c2013-10-05 11:03:42 +05301947 pApMetaInfo->ApInfo.age);
1948 pTemp += temp_len;
1949 temp_total_len += temp_len;
1950
1951 /*dist*/
1952 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "dist=-1\n");
1953 pTemp += temp_len;
1954 temp_total_len += temp_len;
1955
1956 /*error*/
1957 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "error=-1\n");
1958 pTemp += temp_len;
1959 temp_total_len += temp_len;
1960
1961 /*end AP marker*/
1962 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "====\n");
1963 pTemp += temp_len;
1964 temp_total_len += temp_len;
1965
1966 /*last AP in batch scan response*/
1967 if(TRUE == pApMetaInfo->ApInfo.isLastAp)
1968 {
1969 /*end scan marker*/
1970 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "####\n");
1971 pTemp += temp_len;
1972 temp_total_len += temp_len;
1973
1974 /*end batch scan result marker*/
1975 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "----\n");
1976 pTemp += temp_len;
1977 temp_total_len += temp_len;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08001978
Rajeev79dbe4c2013-10-05 11:03:42 +05301979 }
1980
1981 if (temp_total_len < rem_len)
1982 {
1983 ret = temp_total_len + 1;
1984 strlcpy(pDest, temp, ret);
1985 pAdapter->isTruncated = FALSE;
1986 }
1987 else
1988 {
1989 pAdapter->isTruncated = TRUE;
1990 if (rem_len >= strlen("%%%%"))
1991 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001992 ret = snprintf(pDest, sizeof(temp), "%%%%");
Rajeev79dbe4c2013-10-05 11:03:42 +05301993 }
Rajeev Kumarc933d982013-11-18 20:04:20 -08001994 else
Rajeev79dbe4c2013-10-05 11:03:42 +05301995 {
1996 ret = 0;
1997 }
1998 }
1999
2000 return ret;
2001
2002}/*End of hdd_format_batch_scan_rsp*/
2003
2004/**---------------------------------------------------------------------------
2005
2006 \brief hdd_populate_user_batch_scan_rsp() - This function populates user data
2007 buffer starting with head of hdd batch scan response queue
2008
2009 \param - pAdapter Pointer to HDD adapter
2010 \param - pDest Pointer to user data buffer
2011 \param - cur_len current offset in user buffer
2012 \param - rem_len remaining no of bytes in user buffer
2013
2014 \return - number of bytes written in user buffer
2015
2016 --------------------------------------------------------------------------*/
2017
2018tANI_U32 hdd_populate_user_batch_scan_rsp
2019(
2020 hdd_adapter_t* pAdapter,
2021 tANI_U8 *pDest,
2022 tANI_U32 cur_len,
2023 tANI_U32 rem_len
2024)
2025{
2026 tHddBatchScanRsp *pHead;
2027 tHddBatchScanRsp *pPrev;
2028 tANI_U32 len;
2029
Rajeev79dbe4c2013-10-05 11:03:42 +05302030 pAdapter->isTruncated = FALSE;
2031
2032 /*head of hdd batch scan response queue*/
2033 pHead = pAdapter->pBatchScanRsp;
2034 while (pHead)
2035 {
2036 len = hdd_format_batch_scan_rsp(pDest, cur_len, rem_len, pHead,
2037 pAdapter);
2038 pDest += len;
Rajeev Kumar292d2bb2013-10-23 15:01:44 -07002039 pDest--;
Rajeev79dbe4c2013-10-05 11:03:42 +05302040 cur_len += len;
2041 if(TRUE == pAdapter->isTruncated)
2042 {
2043 /*result is truncated return rest of scan rsp in next req*/
2044 cur_len = rem_len;
2045 break;
2046 }
2047 pPrev = pHead;
2048 pHead = pHead->pNext;
2049 pAdapter->pBatchScanRsp = pHead;
Rajeev Kumarbe17d8b2014-01-10 15:39:45 -08002050 if (TRUE == pPrev->ApInfo.isLastAp)
2051 {
2052 pAdapter->prev_batch_id = 0;
2053 }
2054 else
2055 {
2056 pAdapter->prev_batch_id = pPrev->ApInfo.batchId;
2057 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302058 vos_mem_free(pPrev);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002059 pPrev = NULL;
Rajeev79dbe4c2013-10-05 11:03:42 +05302060 }
2061
2062 return cur_len;
2063}/*End of hdd_populate_user_batch_scan_rsp*/
2064
2065/**---------------------------------------------------------------------------
2066
2067 \brief hdd_return_batch_scan_rsp_to_user () - This function returns batch
2068 scan response data from HDD queue to user space
2069 It does following in detail:
2070 a) if HDD has enough data in its queue then it 1st copies data to user
2071 space and then send get batch scan indication message to FW. In this
2072 case it does not wait on any event and batch scan response data will
2073 be populated in HDD response queue in MC thread context after receiving
2074 indication from FW
2075 b) else send get batch scan indication message to FW and wait on an event
2076 which will be set once HDD receives complete batch scan response from
2077 FW and then this function returns batch scan response to user space
2078
2079 \param - pAdapter Pointer to HDD adapter
2080 \param - pPrivData Pointer to priv_data
2081
2082 \return - 0 for success -EFAULT for failure
2083
2084 --------------------------------------------------------------------------*/
2085
2086int hdd_return_batch_scan_rsp_to_user
2087(
2088 hdd_adapter_t* pAdapter,
2089 hdd_priv_data_t *pPrivData,
2090 tANI_U8 *command
2091)
2092{
2093 tANI_U8 *pDest;
2094 tANI_U32 count = 0;
2095 tANI_U32 len = 0;
2096 tANI_U32 cur_len = 0;
2097 tANI_U32 rem_len = 0;
2098 eHalStatus halStatus;
2099 unsigned long rc;
2100 tSirTriggerBatchScanResultInd *pReq;
2101
2102 pReq = &pAdapter->hddTriggerBatchScanResultInd;
2103 pReq->param = 0;/*batch scan client*/
2104 pDest = (tANI_U8 *)(command + pPrivData->used_len);
2105 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
2106
2107 cur_len = pPrivData->used_len;
2108 if (pPrivData->total_len > pPrivData->used_len)
2109 {
2110 rem_len = pPrivData->total_len - pPrivData->used_len;
2111 }
2112 else
2113 {
2114 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2115 "%s: Invalid user data buffer total_len %d used_len %d",
2116 __func__, pPrivData->total_len, pPrivData->used_len);
2117 return -EFAULT;
2118 }
2119
2120 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2121 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2122 cur_len, rem_len);
2123 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2124
2125 /*enough scan result available in cache to return to user space or
2126 scan result needs to be fetched 1st from fw and then return*/
Rajeev Kumar99db6262013-11-11 15:23:36 -08002127 if (len == cur_len)
Rajeev79dbe4c2013-10-05 11:03:42 +05302128 {
2129 pAdapter->hdd_wait_for_get_batch_scan_rsp = TRUE;
2130 halStatus = sme_TriggerBatchScanResultInd(
2131 WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2132 pAdapter->sessionId, hdd_batch_scan_result_ind_callback,
2133 pAdapter);
2134 if ( eHAL_STATUS_SUCCESS == halStatus )
2135 {
2136 if (TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp)
2137 {
2138 INIT_COMPLETION(pAdapter->hdd_get_batch_scan_req_var);
2139 rc = wait_for_completion_timeout(
2140 &pAdapter->hdd_get_batch_scan_req_var,
2141 msecs_to_jiffies(HDD_GET_BATCH_SCAN_RSP_TIME_OUT));
Abhishek Singh00b71972016-01-07 10:51:04 +05302142 if (0 >= rc)
Rajeev79dbe4c2013-10-05 11:03:42 +05302143 {
2144 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Abhishek Singh00b71972016-01-07 10:51:04 +05302145 "%s: wait on hdd_get_batch_scan_req_var failed %ld",
2146 __func__, rc);
Rajeev79dbe4c2013-10-05 11:03:42 +05302147 return -EFAULT;
2148 }
2149 }
2150
2151 len = snprintf(pDest, HDD_BATCH_SCAN_AP_META_INFO_SIZE,
Jeff Johnson02797792013-10-26 19:17:13 -07002152 "scancount=%u\n", pAdapter->numScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05302153 pDest += len;
2154 cur_len += len;
2155
2156 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2157 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
2158 cur_len, rem_len);
2159 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2160
2161 count = 0;
2162 len = (len - pPrivData->used_len);
2163 pDest = (command + pPrivData->used_len);
2164 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002165 "NEW BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302166 while(count < len)
2167 {
2168 printk("%c", *(pDest + count));
2169 count++;
2170 }
2171 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2172 "%s: copy %d data to user buffer", __func__, len);
2173 if (copy_to_user(pPrivData->buf, pDest, len))
2174 {
2175 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2176 "%s: failed to copy data to user buffer", __func__);
2177 return -EFAULT;
2178 }
2179 }
2180 else
2181 {
2182 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2183 "sme_GetBatchScanScan returned failure halStatus %d",
2184 halStatus);
2185 return -EINVAL;
2186 }
2187 }
2188 else
2189 {
Rajeev79dbe4c2013-10-05 11:03:42 +05302190 count = 0;
2191 len = (len - pPrivData->used_len);
2192 pDest = (command + pPrivData->used_len);
2193 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08002194 "REMAINING TRUNCATED BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05302195 while(count < len)
2196 {
2197 printk("%c", *(pDest + count));
2198 count++;
2199 }
Rajeev Kumar99db6262013-11-11 15:23:36 -08002200 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2201 "%s: copy %d data to user buffer", __func__, len);
Rajeev79dbe4c2013-10-05 11:03:42 +05302202 if (copy_to_user(pPrivData->buf, pDest, len))
2203 {
2204 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2205 "%s: failed to copy data to user buffer", __func__);
2206 return -EFAULT;
2207 }
Rajeev79dbe4c2013-10-05 11:03:42 +05302208 }
2209
2210 return 0;
2211} /*End of hdd_return_batch_scan_rsp_to_user*/
2212
Rajeev Kumar8b373292014-01-08 20:36:55 -08002213/**---------------------------------------------------------------------------
2214
2215 \brief hdd_handle_batch_scan_ioctl () - This function handles WLS_BATCHING
2216 IOCTLs from user space. Following BATCH SCAN DEV IOCTs are handled:
2217 WLS_BATCHING VERSION
2218 WLS_BATCHING SET
2219 WLS_BATCHING GET
2220 WLS_BATCHING STOP
2221
2222 \param - pAdapter Pointer to HDD adapter
2223 \param - pPrivdata Pointer to priv_data
2224 \param - command Pointer to command
2225
2226 \return - 0 for success -EFAULT for failure
2227
2228 --------------------------------------------------------------------------*/
2229
2230int hdd_handle_batch_scan_ioctl
2231(
2232 hdd_adapter_t *pAdapter,
2233 hdd_priv_data_t *pPrivdata,
2234 tANI_U8 *command
2235)
2236{
2237 int ret = 0;
Yue Mae36e3552014-03-05 17:06:20 -08002238 hdd_context_t *pHddCtx;
2239
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302240 ENTER();
2241
Yue Mae36e3552014-03-05 17:06:20 -08002242 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2243 ret = wlan_hdd_validate_context(pHddCtx);
2244 if (ret)
2245 {
Yue Mae36e3552014-03-05 17:06:20 -08002246 goto exit;
2247 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002248
2249 if (strncmp(command, "WLS_BATCHING VERSION", 20) == 0)
2250 {
2251 char extra[32];
2252 tANI_U8 len = 0;
2253 tANI_U8 version = HDD_BATCH_SCAN_VERSION;
2254
2255 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2256 {
2257 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2258 "%s: Batch scan feature is not supported by FW", __func__);
2259 ret = -EINVAL;
2260 goto exit;
2261 }
2262
2263 len = scnprintf(extra, sizeof(extra), "WLS_BATCHING_VERSION %d",
2264 version);
2265 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2266 {
2267 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2268 "%s: failed to copy data to user buffer", __func__);
2269 ret = -EFAULT;
2270 goto exit;
2271 }
2272 ret = HDD_BATCH_SCAN_VERSION;
2273 }
2274 else if (strncmp(command, "WLS_BATCHING SET", 16) == 0)
2275 {
2276 int status;
2277 tANI_U8 *value = (command + 16);
2278 eHalStatus halStatus;
2279 unsigned long rc;
2280 tSirSetBatchScanReq *pReq = &pAdapter->hddSetBatchScanReq;
2281 tSirSetBatchScanRsp *pRsp = &pAdapter->hddSetBatchScanRsp;
2282
2283 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2284 {
2285 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2286 "%s: Batch scan feature is not supported by FW", __func__);
2287 ret = -EINVAL;
2288 goto exit;
2289 }
2290
2291 if ((WLAN_HDD_INFRA_STATION != pAdapter->device_mode) &&
2292 (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) &&
2293 (WLAN_HDD_P2P_GO != pAdapter->device_mode) &&
2294 (WLAN_HDD_P2P_DEVICE != pAdapter->device_mode))
2295 {
2296 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302297 "Received WLS_BATCHING SET command in invalid mode %s (%d) "
Rajeev Kumar8b373292014-01-08 20:36:55 -08002298 "WLS_BATCHING_SET is only allowed in infra STA/P2P client mode",
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302299 hdd_device_modetoString(pAdapter->device_mode),
2300 pAdapter->device_mode);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002301 ret = -EINVAL;
2302 goto exit;
2303 }
2304
2305 status = hdd_parse_set_batchscan_command(value, pReq);
2306 if (status)
2307 {
2308 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2309 "Invalid WLS_BATCHING SET command");
2310 ret = -EINVAL;
2311 goto exit;
2312 }
2313
2314
2315 pAdapter->hdd_wait_for_set_batch_scan_rsp = TRUE;
2316 halStatus = sme_SetBatchScanReq(WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
2317 pAdapter->sessionId, hdd_set_batch_scan_req_callback,
2318 pAdapter);
2319
2320 if ( eHAL_STATUS_SUCCESS == halStatus )
2321 {
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302322 char extra[32];
2323 tANI_U8 len = 0;
2324 tANI_U8 mScan = 0;
2325
Rajeev Kumar8b373292014-01-08 20:36:55 -08002326 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2327 "sme_SetBatchScanReq returned success halStatus %d",
2328 halStatus);
2329 if (TRUE == pAdapter->hdd_wait_for_set_batch_scan_rsp)
2330 {
2331 INIT_COMPLETION(pAdapter->hdd_set_batch_scan_req_var);
2332 rc = wait_for_completion_timeout(
2333 &pAdapter->hdd_set_batch_scan_req_var,
2334 msecs_to_jiffies(HDD_SET_BATCH_SCAN_REQ_TIME_OUT));
2335 if (0 == rc)
2336 {
2337 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2338 "%s: Timeout waiting for set batch scan to complete",
2339 __func__);
2340 ret = -EINVAL;
2341 goto exit;
2342 }
2343 }
2344 if ( !pRsp->nScansToBatch )
2345 {
2346 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2347 "%s: Received set batch scan failure response from FW",
2348 __func__);
2349 ret = -EINVAL;
2350 goto exit;
2351 }
2352 /*As per the Batch Scan Framework API we should return the MIN of
2353 either MSCAN or the max # of scans firmware can cache*/
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302354 mScan = MIN(pReq->numberOfScansToBatch , pRsp->nScansToBatch);
Rajeev Kumar8b373292014-01-08 20:36:55 -08002355
2356 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STARTED;
2357
2358 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2359 "%s: request MSCAN %d response MSCAN %d ret %d",
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05302360 __func__, pReq->numberOfScansToBatch, pRsp->nScansToBatch, mScan);
2361 len = scnprintf(extra, sizeof(extra), "%d", mScan);
2362 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
2363 {
2364 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2365 "%s: failed to copy MSCAN value to user buffer", __func__);
2366 ret = -EFAULT;
2367 goto exit;
2368 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08002369 }
2370 else
2371 {
2372 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2373 "sme_SetBatchScanReq returned failure halStatus %d",
2374 halStatus);
2375 ret = -EINVAL;
2376 goto exit;
2377 }
2378 }
2379 else if (strncmp(command, "WLS_BATCHING STOP", 17) == 0)
2380 {
2381 eHalStatus halStatus;
2382 tSirStopBatchScanInd *pInd = &pAdapter->hddStopBatchScanInd;
2383 pInd->param = 0;
2384
2385 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2386 {
2387 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2388 "%s: Batch scan feature is not supported by FW", __func__);
2389 ret = -EINVAL;
2390 goto exit;
2391 }
2392
2393 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2394 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302395 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002396 "Batch scan is not yet enabled batch scan state %d",
2397 pAdapter->batchScanState);
2398 ret = -EINVAL;
2399 goto exit;
2400 }
2401
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002402 mutex_lock(&pAdapter->hdd_batch_scan_lock);
2403 hdd_deinit_batch_scan(pAdapter);
2404 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
2405
Rajeev Kumar8b373292014-01-08 20:36:55 -08002406 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
2407
2408 halStatus = sme_StopBatchScanInd(WLAN_HDD_GET_HAL_CTX(pAdapter), pInd,
2409 pAdapter->sessionId);
2410 if ( eHAL_STATUS_SUCCESS == halStatus )
2411 {
2412 ret = 0;
2413 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2414 "sme_StopBatchScanInd returned success halStatus %d",
2415 halStatus);
2416 }
2417 else
2418 {
2419 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2420 "sme_StopBatchScanInd returned failure halStatus %d",
2421 halStatus);
2422 ret = -EINVAL;
2423 goto exit;
2424 }
2425 }
2426 else if (strncmp(command, "WLS_BATCHING GET", 16) == 0)
2427 {
2428 tANI_U32 remain_len;
2429
2430 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
2431 {
2432 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2433 "%s: Batch scan feature is not supported by FW", __func__);
2434 ret = -EINVAL;
2435 goto exit;
2436 }
2437
2438 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
2439 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05302440 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08002441 "Batch scan is not yet enabled could not return results"
2442 "Batch Scan state %d",
2443 pAdapter->batchScanState);
2444 ret = -EINVAL;
2445 goto exit;
2446 }
2447
2448 pPrivdata->used_len = 16;
2449 remain_len = pPrivdata->total_len - pPrivdata->used_len;
2450 if (remain_len < pPrivdata->total_len)
2451 {
2452 /*Clear previous batch scan response data if any*/
2453 vos_mem_zero((tANI_U8 *)(command + pPrivdata->used_len), remain_len);
2454 }
2455 else
2456 {
2457 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2458 "Invalid total length from user space can't fetch batch"
2459 " scan response total_len %d used_len %d remain len %d",
2460 pPrivdata->total_len, pPrivdata->used_len, remain_len);
2461 ret = -EINVAL;
2462 goto exit;
2463 }
2464 ret = hdd_return_batch_scan_rsp_to_user(pAdapter, pPrivdata, command);
2465 }
2466
2467exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302468 EXIT();
Rajeev Kumar8b373292014-01-08 20:36:55 -08002469 return ret;
2470}
2471
2472
Rajeev79dbe4c2013-10-05 11:03:42 +05302473#endif/*End of FEATURE_WLAN_BATCH_SCAN*/
2474
c_hpothu92367912014-05-01 15:18:17 +05302475static void getBcnMissRateCB(VOS_STATUS status, int bcnMissRate, void *data)
2476{
c_hpothu39eb1e32014-06-26 16:31:50 +05302477 bcnMissRateContext_t *pCBCtx;
2478
2479 if (NULL == data)
2480 {
2481 hddLog(VOS_TRACE_LEVEL_ERROR, FL("argument data is NULL"));
2482 return;
2483 }
c_hpothu92367912014-05-01 15:18:17 +05302484
2485 /* there is a race condition that exists between this callback
2486 function and the caller since the caller could time out either
2487 before or while this code is executing. we use a spinlock to
2488 serialize these actions */
2489 spin_lock(&hdd_context_lock);
2490
c_hpothu39eb1e32014-06-26 16:31:50 +05302491 pCBCtx = (bcnMissRateContext_t *)data;
c_hpothu92367912014-05-01 15:18:17 +05302492 gbcnMissRate = -1;
2493
c_hpothu39eb1e32014-06-26 16:31:50 +05302494 if (pCBCtx->magic != BCN_MISS_RATE_CONTEXT_MAGIC)
c_hpothu92367912014-05-01 15:18:17 +05302495 {
2496 hddLog(VOS_TRACE_LEVEL_ERROR,
c_hpothu39eb1e32014-06-26 16:31:50 +05302497 FL("invalid context magic: %08x"), pCBCtx->magic);
c_hpothu92367912014-05-01 15:18:17 +05302498 spin_unlock(&hdd_context_lock);
2499 return ;
2500 }
2501
2502 if (VOS_STATUS_SUCCESS == status)
2503 {
c_hpothu39eb1e32014-06-26 16:31:50 +05302504 gbcnMissRate = bcnMissRate;
c_hpothu92367912014-05-01 15:18:17 +05302505 }
c_hpothu39eb1e32014-06-26 16:31:50 +05302506 else
2507 {
2508 hddLog(VOS_TRACE_LEVEL_ERROR, FL("failed to get bcnMissRate"));
2509 }
2510
c_hpothu92367912014-05-01 15:18:17 +05302511 complete(&(pCBCtx->completion));
2512 spin_unlock(&hdd_context_lock);
2513
2514 return;
2515}
2516
Abhishek Singh08aa7762014-12-16 13:59:03 +05302517void hdd_FWStatisCB( VOS_STATUS status,
2518 tSirFwStatsResult *fwStatsResult, void *pContext )
Satyanarayana Dash72806012014-12-02 14:30:08 +05302519{
2520 fwStatsContext_t *fwStatsCtx;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302521 hdd_adapter_t *pAdapter;
2522
2523 hddLog(VOS_TRACE_LEVEL_INFO, FL(" with status = %d"),status);
2524
Abhishek Singh08aa7762014-12-16 13:59:03 +05302525 if (NULL == pContext)
Satyanarayana Dash72806012014-12-02 14:30:08 +05302526 {
2527 hddLog(VOS_TRACE_LEVEL_ERROR, FL("argument data is NULL"));
2528 return;
2529 }
2530 /* there is a race condition that exists between this callback
2531 function and the caller since the caller could time out either
2532 before or while this code is executing. we use a spinlock to
2533 serialize these actions */
2534 spin_lock(&hdd_context_lock);
Abhishek Singh08aa7762014-12-16 13:59:03 +05302535 fwStatsCtx = (fwStatsContext_t *) pContext;
Satyanarayana Dash72806012014-12-02 14:30:08 +05302536 if (fwStatsCtx->magic != FW_STATS_CONTEXT_MAGIC)
2537 {
2538 hddLog(VOS_TRACE_LEVEL_ERROR,
2539 FL("invalid context magic: %08x"), fwStatsCtx->magic);
2540 spin_unlock(&hdd_context_lock);
2541 return;
2542 }
2543 pAdapter = fwStatsCtx->pAdapter;
2544 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2545 {
2546 hddLog(VOS_TRACE_LEVEL_ERROR,
2547 FL("pAdapter returned is NULL or invalid"));
2548 spin_unlock(&hdd_context_lock);
2549 return;
2550 }
2551 pAdapter->fwStatsRsp.type = 0;
Abhishek Singh08aa7762014-12-16 13:59:03 +05302552 if ((VOS_STATUS_SUCCESS == status) && (NULL != fwStatsResult))
Satyanarayana Dash72806012014-12-02 14:30:08 +05302553 {
Satyanarayana Dash72806012014-12-02 14:30:08 +05302554 switch( fwStatsResult->type )
2555 {
2556 case FW_UBSP_STATS:
2557 {
Abhishek Singh08aa7762014-12-16 13:59:03 +05302558 memcpy(&pAdapter->fwStatsRsp,fwStatsResult,sizeof(tSirFwStatsResult));
Satyanarayana Dash72806012014-12-02 14:30:08 +05302559 hddLog(VOS_TRACE_LEVEL_INFO,
2560 FL("ubsp_enter_cnt = %d ubsp_jump_ddr_cnt = %d"),
Abhishek Singh08aa7762014-12-16 13:59:03 +05302561 pAdapter->fwStatsRsp.fwStatsData.ubspStats.ubsp_enter_cnt,
2562 pAdapter->fwStatsRsp.fwStatsData.ubspStats.ubsp_jump_ddr_cnt);
Satyanarayana Dash72806012014-12-02 14:30:08 +05302563 }
2564 break;
2565 default:
2566 {
2567 hddLog(VOS_TRACE_LEVEL_ERROR,
2568 FL(" No handling for stats type %d"),fwStatsResult->type);
2569 }
2570 }
2571 }
2572 complete(&(fwStatsCtx->completion));
2573 spin_unlock(&hdd_context_lock);
2574 return;
2575}
2576
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302577static int hdd_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command, char *extra, tANI_U8 n, tANI_U8 *len)
2578{
2579 int ret = 0;
2580
2581 if (!pCfg || !command || !extra || !len)
2582 {
2583 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2584 "%s: argument passsed for GETDWELLTIME is incorrect", __func__);
2585 ret = -EINVAL;
2586 return ret;
2587 }
2588
2589 if (strncmp(command, "GETDWELLTIME ACTIVE MAX", 23) == 0)
2590 {
2591 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MAX %u\n",
2592 (int)pCfg->nActiveMaxChnTime);
2593 return ret;
2594 }
2595 else if (strncmp(command, "GETDWELLTIME ACTIVE MIN", 23) == 0)
2596 {
2597 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MIN %u\n",
2598 (int)pCfg->nActiveMinChnTime);
2599 return ret;
2600 }
2601 else if (strncmp(command, "GETDWELLTIME PASSIVE MAX", 24) == 0)
2602 {
2603 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MAX %u\n",
2604 (int)pCfg->nPassiveMaxChnTime);
2605 return ret;
2606 }
2607 else if (strncmp(command, "GETDWELLTIME PASSIVE MIN", 24) == 0)
2608 {
2609 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MIN %u\n",
2610 (int)pCfg->nPassiveMinChnTime);
2611 return ret;
2612 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302613 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
2614 {
2615 *len = scnprintf(extra, n, "GETDWELLTIME %u \n",
2616 (int)pCfg->nActiveMaxChnTime);
2617 return ret;
2618 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302619 else
2620 {
2621 ret = -EINVAL;
2622 }
2623
2624 return ret;
2625}
2626
2627static int hdd_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
2628{
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302629 tHalHandle hHal;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302630 hdd_config_t *pCfg;
2631 tANI_U8 *value = command;
2632 int val = 0, ret = 0, temp = 0;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302633 tSmeConfigParams smeConfig;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302634
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302635 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
2636 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302637 {
2638 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2639 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
2640 ret = -EINVAL;
2641 return ret;
2642 }
2643
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302644 vos_mem_zero(&smeConfig, sizeof(smeConfig));
2645 sme_GetConfigParam(hHal, &smeConfig);
2646
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302647 if (strncmp(command, "SETDWELLTIME ACTIVE MAX", 23) == 0 )
2648 {
2649 value = value + 24;
2650 temp = kstrtou32(value, 10, &val);
2651 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
2652 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
2653 {
2654 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2655 "%s: argument passed for SETDWELLTIME ACTIVE MAX is incorrect", __func__);
2656 ret = -EFAULT;
2657 return ret;
2658 }
2659 pCfg->nActiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302660 smeConfig.csrConfig.nActiveMaxChnTime = val;
2661 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302662 }
2663 else if (strncmp(command, "SETDWELLTIME ACTIVE MIN", 23) == 0)
2664 {
2665 value = value + 24;
2666 temp = kstrtou32(value, 10, &val);
2667 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_MIN ||
2668 val > CFG_ACTIVE_MIN_CHANNEL_TIME_MAX )
2669 {
2670 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2671 "%s: argument passsed for SETDWELLTIME ACTIVE MIN is incorrect", __func__);
2672 ret = -EFAULT;
2673 return ret;
2674 }
2675 pCfg->nActiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302676 smeConfig.csrConfig.nActiveMinChnTime = val;
2677 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302678 }
2679 else if (strncmp(command, "SETDWELLTIME PASSIVE MAX", 24) == 0)
2680 {
2681 value = value + 25;
2682 temp = kstrtou32(value, 10, &val);
2683 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_MIN ||
2684 val > CFG_PASSIVE_MAX_CHANNEL_TIME_MAX )
2685 {
2686 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2687 "%s: argument passed for SETDWELLTIME PASSIVE MAX is incorrect", __func__);
2688 ret = -EFAULT;
2689 return ret;
2690 }
2691 pCfg->nPassiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302692 smeConfig.csrConfig.nPassiveMaxChnTime = val;
2693 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302694 }
2695 else if (strncmp(command, "SETDWELLTIME PASSIVE MIN", 24) == 0)
2696 {
2697 value = value + 25;
2698 temp = kstrtou32(value, 10, &val);
2699 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_MIN ||
2700 val > CFG_PASSIVE_MIN_CHANNEL_TIME_MAX )
2701 {
2702 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2703 "%s: argument passed for SETDWELLTIME PASSIVE MIN is incorrect", __func__);
2704 ret = -EFAULT;
2705 return ret;
2706 }
2707 pCfg->nPassiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302708 smeConfig.csrConfig.nPassiveMinChnTime = val;
2709 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302710 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302711 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
2712 {
2713 value = value + 13;
2714 temp = kstrtou32(value, 10, &val);
2715 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
2716 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
2717 {
2718 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2719 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
2720 ret = -EFAULT;
2721 return ret;
2722 }
2723 pCfg->nActiveMaxChnTime = val;
2724 smeConfig.csrConfig.nActiveMaxChnTime = val;
2725 sme_UpdateConfig(hHal, &smeConfig);
2726 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302727 else
2728 {
2729 ret = -EINVAL;
2730 }
2731
2732 return ret;
2733}
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05302734static int hdd_cmd_setFccChannel(hdd_context_t *pHddCtx, tANI_U8 *cmd,
2735 tANI_U8 cmd_len)
2736{
2737 tANI_U8 *value;
2738 tANI_U8 fcc_constraint;
2739
2740 eHalStatus status;
2741 int ret = 0;
2742 value = cmd + cmd_len + 1;
2743
2744 ret = kstrtou8(value, 10, &fcc_constraint);
2745 if ((ret < 0) || (fcc_constraint > 1)) {
2746 /*
2747 * If the input value is greater than max value of datatype,
2748 * then also it is a failure
2749 */
2750 hddLog(VOS_TRACE_LEVEL_ERROR,
2751 "%s: value out of range", __func__);
2752 return -EINVAL;
2753 }
2754
2755 status = sme_handleSetFccChannel(pHddCtx->hHal, fcc_constraint);
2756 if (status != eHAL_STATUS_SUCCESS)
2757 ret = -EPERM;
2758
2759 return ret;
2760}
2761
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05302762/**---------------------------------------------------------------------------
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05302763
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05302764 \brief hdd_enable_disable_ca_event() - When Host sends IOCTL (enabled),
2765 FW will send *ONE* CA ind to Host(even though it is duplicate).
2766 When Host send IOCTL (disable), FW doesn't perform any action.
2767 Whenever any change in CA *and* WLAN is in SAP/P2P-GO mode, FW
2768 sends CA ind to host. (regard less of IOCTL status)
2769 \param - pHddCtx - HDD context
2770 \param - command - command received from framework
2771 \param - cmd_len - len of the command
2772
2773 \return - 0 on success, appropriate error values on failure.
2774
2775 --------------------------------------------------------------------------*/
2776int hdd_enable_disable_ca_event(hdd_context_t *pHddCtx, tANI_U8* command, tANI_U8 cmd_len)
2777{
2778 tANI_U8 set_value;
2779 int ret = 0;
2780 eHalStatus status;
2781
2782 ret = wlan_hdd_validate_context(pHddCtx);
2783 if (0 != ret)
2784 {
2785 ret = -EINVAL;
2786 goto exit;
2787 }
2788
2789 if (pHddCtx->cfg_ini->gOptimizeCAevent == 0)
2790 {
2791 hddLog(VOS_TRACE_LEVEL_ERROR, "Enable gOptimizeCAevent"
2792 " ini param to control channel avooidance indication");
2793 ret = 0;
2794 goto exit;
2795 }
2796
2797 set_value = command[cmd_len + 1] - '0';
2798 status = sme_enableDisableChanAvoidIndEvent(pHddCtx->hHal, set_value);
2799 if (status != eHAL_STATUS_SUCCESS)
2800 {
2801 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to send"
2802 " enableDisableChanAoidance command to SME\n", __func__);
2803 ret = -EINVAL;
2804 }
2805
2806exit:
2807 return ret;
2808}
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302809
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002810static int hdd_driver_command(hdd_adapter_t *pAdapter,
2811 hdd_priv_data_t *ppriv_data)
Jeff Johnson295189b2012-06-20 16:38:30 -07002812{
Jeff Johnson295189b2012-06-20 16:38:30 -07002813 hdd_priv_data_t priv_data;
2814 tANI_U8 *command = NULL;
Kaushik, Sushant96122442014-10-21 16:40:18 +05302815 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2816 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002817 int ret = 0;
Kaushik, Sushant96122442014-10-21 16:40:18 +05302818 int status;
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05302819#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
2820 struct cfg80211_mgmt_tx_params params;
2821#endif
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302822
2823 ENTER();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002824 /*
2825 * Note that valid pointers are provided by caller
2826 */
Jeff Johnson295189b2012-06-20 16:38:30 -07002827
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002828 /* copy to local struct to avoid numerous changes to legacy code */
2829 priv_data = *ppriv_data;
Jeff Johnson295189b2012-06-20 16:38:30 -07002830
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002831 if (priv_data.total_len <= 0 ||
2832 priv_data.total_len > WLAN_PRIV_DATA_MAX_LEN)
Sameer Thalappil8ef3a0e2013-04-05 14:36:04 -07002833 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002834 hddLog(VOS_TRACE_LEVEL_WARN,
2835 "%s:invalid priv_data.total_len(%d)!!!", __func__,
2836 priv_data.total_len);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07002837 ret = -EINVAL;
2838 goto exit;
2839 }
Kaushik, Sushant96122442014-10-21 16:40:18 +05302840 status = wlan_hdd_validate_context(pHddCtx);
2841 if (0 != status)
2842 {
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302843 ret = -EINVAL;
2844 goto exit;
Kaushik, Sushant96122442014-10-21 16:40:18 +05302845 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07002846 /* Allocate +1 for '\0' */
2847 command = kmalloc(priv_data.total_len + 1, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07002848 if (!command)
2849 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002850 hddLog(VOS_TRACE_LEVEL_ERROR,
2851 "%s: failed to allocate memory", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002852 ret = -ENOMEM;
2853 goto exit;
2854 }
2855
2856 if (copy_from_user(command, priv_data.buf, priv_data.total_len))
2857 {
2858 ret = -EFAULT;
2859 goto exit;
2860 }
2861
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002862 /* Make sure the command is NUL-terminated */
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07002863 command[priv_data.total_len] = '\0';
2864
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002865 /* at one time the following block of code was conditional. braces
2866 * have been retained to avoid re-indenting the legacy code
2867 */
Jeff Johnson295189b2012-06-20 16:38:30 -07002868 {
2869 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
2870
2871 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07002872 "%s: Received %s cmd from Wi-Fi GUI***", __func__, command);
Jeff Johnson295189b2012-06-20 16:38:30 -07002873
2874 if (strncmp(command, "P2P_DEV_ADDR", 12) == 0 )
2875 {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302876 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2877 TRACE_CODE_HDD_P2P_DEV_ADDR_IOCTL,
2878 pAdapter->sessionId, (unsigned)
2879 (*(pHddCtx->p2pDeviceAddress.bytes+2)<<24 |
2880 *(pHddCtx->p2pDeviceAddress.bytes+3)<<16 |
2881 *(pHddCtx->p2pDeviceAddress.bytes+4)<<8 |
2882 *(pHddCtx->p2pDeviceAddress.bytes+5))));
Jeff Johnson295189b2012-06-20 16:38:30 -07002883 if (copy_to_user(priv_data.buf, pHddCtx->p2pDeviceAddress.bytes,
2884 sizeof(tSirMacAddr)))
2885 {
2886 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002887 "%s: failed to copy data to user buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002888 ret = -EFAULT;
2889 }
2890 }
Amar Singhal0974e402013-02-12 14:27:46 -08002891 else if(strncmp(command, "SETBAND", 7) == 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07002892 {
Amar Singhal0974e402013-02-12 14:27:46 -08002893 tANI_U8 *ptr = command ;
Srinivas Girigowdade697412013-02-14 16:31:48 -08002894
Jeff Johnson295189b2012-06-20 16:38:30 -07002895 /* Change band request received */
Srinivas Girigowdade697412013-02-14 16:31:48 -08002896
2897 /* First 8 bytes will have "SETBAND " and
Jeff Johnson295189b2012-06-20 16:38:30 -07002898 * 9 byte will have band setting value */
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07002899 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Amar Singhal0974e402013-02-12 14:27:46 -08002900 "%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 +05302901 if(VOS_FTM_MODE != hdd_get_conparam())
2902 {
2903 /* Change band request received */
2904 ret = hdd_setBand_helper(pAdapter->dev, ptr);
2905 if(ret < 0)
2906 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
2907 "%s: failed to set band ret=%d", __func__, ret);
2908 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08002909 }
Kiet Lamf040f472013-11-20 21:15:23 +05302910 else if(strncmp(command, "SETWMMPS", 8) == 0)
2911 {
2912 tANI_U8 *ptr = command;
2913 ret = hdd_wmmps_helper(pAdapter, ptr);
2914 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05302915
2916 else if(strncmp(command, "TDLSSCAN", 8) == 0)
2917 {
2918 tANI_U8 *ptr = command;
2919 ret = hdd_set_tdls_scan_type(pAdapter, ptr);
2920 }
2921
Jeff Johnson32d95a32012-09-10 13:15:23 -07002922 else if ( strncasecmp(command, "COUNTRY", 7) == 0 )
2923 {
2924 char *country_code;
2925
2926 country_code = command + 8;
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07002927
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002928 INIT_COMPLETION(pAdapter->change_country_code);
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07002929 hdd_checkandupdate_dfssetting(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07002930#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +05302931 hdd_checkandupdate_phymode(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07002932#endif
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002933 ret = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2934 (void *)(tSmeChangeCountryCallback)
2935 wlan_hdd_change_country_code_callback,
Abhishek Singha306a442013-11-07 18:39:01 +05302936 country_code, pAdapter, pHddCtx->pvosContext, eSIR_TRUE, eSIR_TRUE);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002937 if (eHAL_STATUS_SUCCESS == ret)
2938 {
2939 ret = wait_for_completion_interruptible_timeout(
2940 &pAdapter->change_country_code,
2941 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
2942 if (0 >= ret)
2943 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002944 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: SME while setting country code timed out %d",
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302945 __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002946 }
2947 }
2948 else
Jeff Johnson32d95a32012-09-10 13:15:23 -07002949 {
2950 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002951 "%s: SME Change Country code fail ret=%d", __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002952 ret = -EINVAL;
Jeff Johnson32d95a32012-09-10 13:15:23 -07002953 }
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002954
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07002955 }
2956 /*
2957 command should be a string having format
2958 SET_SAP_CHANNEL_LIST <num of channels> <the channels seperated by spaces>
2959 */
Amar Singhal0974e402013-02-12 14:27:46 -08002960 else if(strncmp(command, "SET_SAP_CHANNEL_LIST", 20) == 0)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07002961 {
Amar Singhal0974e402013-02-12 14:27:46 -08002962 tANI_U8 *ptr = command;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07002963
2964 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002965 " Received Command to Set Preferred Channels for SAP in %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07002966
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -08002967 ret = sapSetPreferredChannel(ptr);
Jeff Johnson32d95a32012-09-10 13:15:23 -07002968 }
Sameer Thalappil45931fb2013-02-01 11:18:05 -08002969 else if(strncmp(command, "SETSUSPENDMODE", 14) == 0)
2970 {
2971 int suspend = 0;
2972 tANI_U8 *ptr = (tANI_U8*)command + 15;
2973
2974 suspend = *ptr - '0';
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302975 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2976 TRACE_CODE_HDD_SETSUSPENDMODE_IOCTL,
2977 pAdapter->sessionId, suspend));
Sameer Thalappil45931fb2013-02-01 11:18:05 -08002978 hdd_set_wlan_suspend_mode(suspend);
2979 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08002980#ifdef WLAN_FEATURE_NEIGHBOR_ROAMING
2981 else if (strncmp(command, "SETROAMTRIGGER", 14) == 0)
2982 {
2983 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002984 tANI_S8 rssi = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08002985 tANI_U8 lookUpThreshold = CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_DEFAULT;
2986 eHalStatus status = eHAL_STATUS_SUCCESS;
2987
2988 /* Move pointer to ahead of SETROAMTRIGGER<delimiter> */
2989 value = value + 15;
2990
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002991 /* Convert the value from ascii to integer */
2992 ret = kstrtos8(value, 10, &rssi);
2993 if (ret < 0)
2994 {
2995 /* If the input value is greater than max value of datatype, then also
2996 kstrtou8 fails */
2997 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2998 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdafa7157d2013-10-31 10:14:22 -07002999 __func__,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003000 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
3001 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
3002 ret = -EINVAL;
3003 goto exit;
3004 }
3005
Srinivas Girigowdade697412013-02-14 16:31:48 -08003006 lookUpThreshold = abs(rssi);
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003007
Srinivas Girigowdade697412013-02-14 16:31:48 -08003008 if ((lookUpThreshold < CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN) ||
3009 (lookUpThreshold > CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX))
3010 {
3011 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3012 "Neighbor lookup threshold value %d is out of range"
3013 " (Min: %d Max: %d)", lookUpThreshold,
3014 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
3015 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
3016 ret = -EINVAL;
3017 goto exit;
3018 }
3019
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303020 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3021 TRACE_CODE_HDD_SETROAMTRIGGER_IOCTL,
3022 pAdapter->sessionId, lookUpThreshold));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003023 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3024 "%s: Received Command to Set Roam trigger"
3025 " (Neighbor lookup threshold) = %d", __func__, lookUpThreshold);
3026
3027 pHddCtx->cfg_ini->nNeighborLookupRssiThreshold = lookUpThreshold;
3028 status = sme_setNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold);
3029 if (eHAL_STATUS_SUCCESS != status)
3030 {
3031 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3032 "%s: Failed to set roam trigger, try again", __func__);
3033 ret = -EPERM;
3034 goto exit;
3035 }
3036
3037 /* Set Reassoc threshold to (lookup rssi threshold + 5 dBm) */
mukul sharmad6e1fdd2014-06-23 19:19:09 +05303038 pHddCtx->cfg_ini->nNeighborReassocRssiThreshold = lookUpThreshold + 5;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003039 sme_setNeighborReassocRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold + 5);
3040 }
3041 else if (strncmp(command, "GETROAMTRIGGER", 14) == 0)
3042 {
3043 tANI_U8 lookUpThreshold = sme_getNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal));
3044 int rssi = (-1) * lookUpThreshold;
3045 char extra[32];
3046 tANI_U8 len = 0;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303047 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3048 TRACE_CODE_HDD_GETROAMTRIGGER_IOCTL,
3049 pAdapter->sessionId, lookUpThreshold));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003050 len = scnprintf(extra, sizeof(extra), "%s %d", command, rssi);
Srinivas Girigowda91719232015-07-13 15:10:10 +05303051 len = VOS_MIN(priv_data.total_len, len + 1);
3052 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08003053 {
3054 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3055 "%s: failed to copy data to user buffer", __func__);
3056 ret = -EFAULT;
3057 goto exit;
3058 }
3059 }
3060 else if (strncmp(command, "SETROAMSCANPERIOD", 17) == 0)
3061 {
3062 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003063 tANI_U8 roamScanPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003064 tANI_U16 neighborEmptyScanRefreshPeriod = CFG_EMPTY_SCAN_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003065
Srinivas Girigowdade697412013-02-14 16:31:48 -08003066 /* input refresh period is in terms of seconds */
3067 /* Move pointer to ahead of SETROAMSCANPERIOD<delimiter> */
3068 value = value + 18;
3069 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003070 ret = kstrtou8(value, 10, &roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08003071 if (ret < 0)
3072 {
3073 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003074 kstrtou8 fails */
Srinivas Girigowdade697412013-02-14 16:31:48 -08003075 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003076 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdade697412013-02-14 16:31:48 -08003077 __func__,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07003078 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
3079 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003080 ret = -EINVAL;
3081 goto exit;
3082 }
3083
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003084 if ((roamScanPeriod < (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000)) ||
3085 (roamScanPeriod > (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000)))
Srinivas Girigowdade697412013-02-14 16:31:48 -08003086 {
3087 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003088 "Roam scan period value %d is out of range"
3089 " (Min: %d Max: %d)", roamScanPeriod,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07003090 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
3091 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003092 ret = -EINVAL;
3093 goto exit;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303094 }
3095 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3096 TRACE_CODE_HDD_SETROAMSCANPERIOD_IOCTL,
3097 pAdapter->sessionId, roamScanPeriod));
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003098 neighborEmptyScanRefreshPeriod = roamScanPeriod * 1000;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003099
3100 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3101 "%s: Received Command to Set roam scan period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003102 " (Empty Scan refresh period) = %d", __func__, roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08003103
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003104 pHddCtx->cfg_ini->nEmptyScanRefreshPeriod = neighborEmptyScanRefreshPeriod;
3105 sme_UpdateEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborEmptyScanRefreshPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08003106 }
3107 else if (strncmp(command, "GETROAMSCANPERIOD", 17) == 0)
3108 {
3109 tANI_U16 nEmptyScanRefreshPeriod = sme_getEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
3110 char extra[32];
3111 tANI_U8 len = 0;
3112
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303113 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3114 TRACE_CODE_HDD_GETROAMSCANPERIOD_IOCTL,
3115 pAdapter->sessionId, nEmptyScanRefreshPeriod));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003116 len = scnprintf(extra, sizeof(extra), "%s %d",
3117 "GETROAMSCANPERIOD", (nEmptyScanRefreshPeriod/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003118 /* Returned value is in units of seconds */
Ratnam Rachuria72ba112015-07-17 13:27:03 +05303119 len = VOS_MIN(priv_data.total_len, len + 1);
3120 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08003121 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3122 "%s: failed to copy data to user buffer", __func__);
3123 ret = -EFAULT;
3124 goto exit;
3125 }
3126 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003127 else if (strncmp(command, "SETROAMSCANREFRESHPERIOD", 24) == 0)
3128 {
3129 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003130 tANI_U8 roamScanRefreshPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003131 tANI_U16 neighborScanRefreshPeriod = CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003132
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003133 /* input refresh period is in terms of seconds */
3134 /* Move pointer to ahead of SETROAMSCANREFRESHPERIOD<delimiter> */
3135 value = value + 25;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003136
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003137 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003138 ret = kstrtou8(value, 10, &roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003139 if (ret < 0)
3140 {
3141 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003142 kstrtou8 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003143 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003144 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003145 __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003146 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
3147 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
3148 ret = -EINVAL;
3149 goto exit;
3150 }
3151
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003152 if ((roamScanRefreshPeriod < (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000)) ||
3153 (roamScanRefreshPeriod > (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000)))
3154 {
3155 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3156 "Neighbor scan results refresh period value %d is out of range"
3157 " (Min: %d Max: %d)", roamScanRefreshPeriod,
3158 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
3159 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
3160 ret = -EINVAL;
3161 goto exit;
3162 }
3163 neighborScanRefreshPeriod = roamScanRefreshPeriod * 1000;
3164
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003165 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3166 "%s: Received Command to Set roam scan refresh period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003167 " (Scan refresh period) = %d", __func__, roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003168
3169 pHddCtx->cfg_ini->nNeighborResultsRefreshPeriod = neighborScanRefreshPeriod;
3170 sme_setNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborScanRefreshPeriod);
3171 }
3172 else if (strncmp(command, "GETROAMSCANREFRESHPERIOD", 24) == 0)
3173 {
3174 tANI_U16 value = sme_getNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
3175 char extra[32];
3176 tANI_U8 len = 0;
3177
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003178 len = scnprintf(extra, sizeof(extra), "%s %d",
3179 "GETROAMSCANREFRESHPERIOD", (value/1000));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003180 /* Returned value is in units of seconds */
Ratnam Rachuri2c9d6702015-07-17 13:25:16 +05303181 len = VOS_MIN(priv_data.total_len, len + 1);
3182 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003183 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3184 "%s: failed to copy data to user buffer", __func__);
3185 ret = -EFAULT;
3186 goto exit;
3187 }
3188 }
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07003189#ifdef FEATURE_WLAN_LFR
3190 /* SETROAMMODE */
3191 else if (strncmp(command, "SETROAMMODE", SIZE_OF_SETROAMMODE) == 0)
3192 {
3193 tANI_U8 *value = command;
3194 tANI_BOOLEAN roamMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
3195
3196 /* Move pointer to ahead of SETROAMMODE<delimiter> */
3197 value = value + SIZE_OF_SETROAMMODE + 1;
3198
3199 /* Convert the value from ascii to integer */
3200 ret = kstrtou8(value, SIZE_OF_SETROAMMODE, &roamMode);
3201 if (ret < 0)
3202 {
3203 /* If the input value is greater than max value of datatype, then also
3204 kstrtou8 fails */
3205 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3206 "%s: kstrtou8 failed range [%d - %d]", __func__,
3207 CFG_LFR_FEATURE_ENABLED_MIN,
3208 CFG_LFR_FEATURE_ENABLED_MAX);
3209 ret = -EINVAL;
3210 goto exit;
3211 }
3212 if ((roamMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
3213 (roamMode > CFG_LFR_FEATURE_ENABLED_MAX))
3214 {
3215 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3216 "Roam Mode value %d is out of range"
3217 " (Min: %d Max: %d)", roamMode,
3218 CFG_LFR_FEATURE_ENABLED_MIN,
3219 CFG_LFR_FEATURE_ENABLED_MAX);
3220 ret = -EINVAL;
3221 goto exit;
3222 }
3223
3224 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3225 "%s: Received Command to Set Roam Mode = %d", __func__, roamMode);
3226 /*
3227 * Note that
3228 * SETROAMMODE 0 is to enable LFR while
3229 * SETROAMMODE 1 is to disable LFR, but
3230 * NotifyIsFastRoamIniFeatureEnabled 0/1 is to enable/disable.
3231 * So, we have to invert the value to call sme_UpdateIsFastRoamIniFeatureEnabled.
3232 */
3233 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
3234 roamMode = CFG_LFR_FEATURE_ENABLED_MAX; /* Roam enable */
3235 else
3236 roamMode = CFG_LFR_FEATURE_ENABLED_MIN; /* Roam disable */
3237
3238 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = roamMode;
3239 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), roamMode);
3240 }
3241 /* GETROAMMODE */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05303242 else if (strncmp(command, "GETROAMMODE", SIZE_OF_GETROAMMODE) == 0)
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07003243 {
3244 tANI_BOOLEAN roamMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
3245 char extra[32];
3246 tANI_U8 len = 0;
3247
3248 /*
3249 * roamMode value shall be inverted because the sementics is different.
3250 */
3251 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
3252 roamMode = CFG_LFR_FEATURE_ENABLED_MAX;
3253 else
3254 roamMode = CFG_LFR_FEATURE_ENABLED_MIN;
3255
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003256 len = scnprintf(extra, sizeof(extra), "%s %d", command, roamMode);
Ratnam Rachuri28693eb2015-07-17 13:23:42 +05303257 len = VOS_MIN(priv_data.total_len, len + 1);
3258 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07003259 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3260 "%s: failed to copy data to user buffer", __func__);
3261 ret = -EFAULT;
3262 goto exit;
3263 }
3264 }
3265#endif
Srinivas Girigowdade697412013-02-14 16:31:48 -08003266#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003267#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08003268 else if (strncmp(command, "SETROAMDELTA", 12) == 0)
3269 {
3270 tANI_U8 *value = command;
3271 tANI_U8 roamRssiDiff = CFG_ROAM_RSSI_DIFF_DEFAULT;
3272
3273 /* Move pointer to ahead of SETROAMDELTA<delimiter> */
3274 value = value + 13;
3275 /* Convert the value from ascii to integer */
3276 ret = kstrtou8(value, 10, &roamRssiDiff);
3277 if (ret < 0)
3278 {
3279 /* If the input value is greater than max value of datatype, then also
3280 kstrtou8 fails */
3281 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3282 "%s: kstrtou8 failed range [%d - %d]", __func__,
3283 CFG_ROAM_RSSI_DIFF_MIN,
3284 CFG_ROAM_RSSI_DIFF_MAX);
3285 ret = -EINVAL;
3286 goto exit;
3287 }
3288
3289 if ((roamRssiDiff < CFG_ROAM_RSSI_DIFF_MIN) ||
3290 (roamRssiDiff > CFG_ROAM_RSSI_DIFF_MAX))
3291 {
3292 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3293 "Roam rssi diff value %d is out of range"
3294 " (Min: %d Max: %d)", roamRssiDiff,
3295 CFG_ROAM_RSSI_DIFF_MIN,
3296 CFG_ROAM_RSSI_DIFF_MAX);
3297 ret = -EINVAL;
3298 goto exit;
3299 }
3300
3301 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3302 "%s: Received Command to Set roam rssi diff = %d", __func__, roamRssiDiff);
3303
3304 pHddCtx->cfg_ini->RoamRssiDiff = roamRssiDiff;
3305 sme_UpdateRoamRssiDiff((tHalHandle)(pHddCtx->hHal), roamRssiDiff);
3306 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05303307 else if (strncmp(command, "GETROAMDELTA", 12) == 0)
Srinivas Girigowdade697412013-02-14 16:31:48 -08003308 {
3309 tANI_U8 roamRssiDiff = sme_getRoamRssiDiff((tHalHandle)(pHddCtx->hHal));
3310 char extra[32];
3311 tANI_U8 len = 0;
3312
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303313 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3314 TRACE_CODE_HDD_GETROAMDELTA_IOCTL,
3315 pAdapter->sessionId, roamRssiDiff));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003316 len = scnprintf(extra, sizeof(extra), "%s %d",
3317 command, roamRssiDiff);
Ratnam Rachuri22a3b402015-07-17 13:21:49 +05303318 len = VOS_MIN(priv_data.total_len, len + 1);
3319 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08003320 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3321 "%s: failed to copy data to user buffer", __func__);
3322 ret = -EFAULT;
3323 goto exit;
3324 }
3325 }
3326#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003327#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08003328 else if (strncmp(command, "GETBAND", 7) == 0)
3329 {
3330 int band = -1;
3331 char extra[32];
3332 tANI_U8 len = 0;
3333 hdd_getBand_helper(pHddCtx, &band);
3334
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303335 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3336 TRACE_CODE_HDD_GETBAND_IOCTL,
3337 pAdapter->sessionId, band));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003338 len = scnprintf(extra, sizeof(extra), "%s %d", command, band);
Ratnam Rachuri52139592015-07-17 13:17:29 +05303339 len = VOS_MIN(priv_data.total_len, len + 1);
3340 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdade697412013-02-14 16:31:48 -08003341 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3342 "%s: failed to copy data to user buffer", __func__);
3343 ret = -EFAULT;
3344 goto exit;
3345 }
3346 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08003347 else if (strncmp(command, "SETROAMSCANCHANNELS", 19) == 0)
3348 {
3349 tANI_U8 *value = command;
3350 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
3351 tANI_U8 numChannels = 0;
3352 eHalStatus status = eHAL_STATUS_SUCCESS;
3353
3354 status = hdd_parse_channellist(value, ChannelList, &numChannels);
3355 if (eHAL_STATUS_SUCCESS != status)
3356 {
3357 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3358 "%s: Failed to parse channel list information", __func__);
3359 ret = -EINVAL;
3360 goto exit;
3361 }
3362
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303363 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3364 TRACE_CODE_HDD_SETROAMSCANCHANNELS_IOCTL,
3365 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003366 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
3367 {
3368 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3369 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
3370 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3371 ret = -EINVAL;
3372 goto exit;
3373 }
3374 status = sme_ChangeRoamScanChannelList((tHalHandle)(pHddCtx->hHal), ChannelList,
3375 numChannels);
3376 if (eHAL_STATUS_SUCCESS != status)
3377 {
3378 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3379 "%s: Failed to update channel list information", __func__);
3380 ret = -EINVAL;
3381 goto exit;
3382 }
3383 }
3384 else if (strncmp(command, "GETROAMSCANCHANNELS", 19) == 0)
3385 {
3386 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
3387 tANI_U8 numChannels = 0;
Jeff Johnson51b67782013-04-05 12:35:41 -07003388 tANI_U8 j = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003389 char extra[128] = {0};
Jeff Johnson51b67782013-04-05 12:35:41 -07003390 int len;
Srinivas Girigowdade697412013-02-14 16:31:48 -08003391
3392 if (eHAL_STATUS_SUCCESS != sme_getRoamScanChannelList( (tHalHandle)(pHddCtx->hHal),
3393 ChannelList, &numChannels ))
3394 {
3395 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3396 "%s: failed to get roam scan channel list", __func__);
3397 ret = -EFAULT;
3398 goto exit;
3399 }
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303400 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3401 TRACE_CODE_HDD_GETROAMSCANCHANNELS_IOCTL,
3402 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08003403 /* output channel list is of the format
3404 [Number of roam scan channels][Channel1][Channel2]... */
3405 /* copy the number of channels in the 0th index */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003406 len = scnprintf(extra, sizeof(extra), "%s %d", command, numChannels);
Sushant Kaushika08ca192015-09-16 15:52:04 +05303407 for (j = 0; (j < numChannels) && len <= sizeof(extra); j++)
Srinivas Girigowdade697412013-02-14 16:31:48 -08003408 {
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003409 len += scnprintf(extra + len, sizeof(extra) - len, " %d",
3410 ChannelList[j]);
Srinivas Girigowdade697412013-02-14 16:31:48 -08003411 }
3412
Sushant Kaushikc9b8be52015-07-15 16:41:27 +05303413 len = VOS_MIN(priv_data.total_len, len + 1);
3414 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdade697412013-02-14 16:31:48 -08003415 {
3416 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3417 "%s: failed to copy data to user buffer", __func__);
3418 ret = -EFAULT;
3419 goto exit;
3420 }
3421 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003422 else if (strncmp(command, "GETCCXMODE", 10) == 0)
3423 {
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003424 tANI_BOOLEAN eseMode = sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003425 char extra[32];
3426 tANI_U8 len = 0;
3427
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003428 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003429 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003430 if (eseMode &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003431 hdd_is_okc_mode_enabled(pHddCtx) &&
3432 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
3433 {
3434 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003435 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003436 " hence this operation is not permitted!", __func__);
3437 ret = -EPERM;
3438 goto exit;
3439 }
3440
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003441 len = scnprintf(extra, sizeof(extra), "%s %d",
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003442 "GETCCXMODE", eseMode);
Sushant Kaushikf8abd352015-07-15 16:37:49 +05303443 len = VOS_MIN(priv_data.total_len, len + 1);
3444 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003445 {
3446 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3447 "%s: failed to copy data to user buffer", __func__);
3448 ret = -EFAULT;
3449 goto exit;
3450 }
3451 }
3452 else if (strncmp(command, "GETOKCMODE", 10) == 0)
3453 {
3454 tANI_BOOLEAN okcMode = hdd_is_okc_mode_enabled(pHddCtx);
3455 char extra[32];
3456 tANI_U8 len = 0;
3457
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003458 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003459 then this operation is not permitted (return FAILURE) */
3460 if (okcMode &&
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003461 sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003462 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
3463 {
3464 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003465 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003466 " hence this operation is not permitted!", __func__);
3467 ret = -EPERM;
3468 goto exit;
3469 }
3470
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003471 len = scnprintf(extra, sizeof(extra), "%s %d",
3472 "GETOKCMODE", okcMode);
Sushant Kaushikbc2fb5c2015-07-15 16:43:16 +05303473 len = VOS_MIN(priv_data.total_len, len + 1);
3474 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003475 {
3476 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3477 "%s: failed to copy data to user buffer", __func__);
3478 ret = -EFAULT;
3479 goto exit;
3480 }
3481 }
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07003482 else if (strncmp(command, "GETFASTROAM", 11) == 0)
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003483 {
3484 tANI_BOOLEAN lfrMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
3485 char extra[32];
3486 tANI_U8 len = 0;
3487
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003488 len = scnprintf(extra, sizeof(extra), "%s %d",
3489 "GETFASTROAM", lfrMode);
Sushant Kaushik4da7ec92015-07-15 16:39:32 +05303490 len = VOS_MIN(priv_data.total_len, len + 1);
3491 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003492 {
3493 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3494 "%s: failed to copy data to user buffer", __func__);
3495 ret = -EFAULT;
3496 goto exit;
3497 }
3498 }
3499 else if (strncmp(command, "GETFASTTRANSITION", 17) == 0)
3500 {
3501 tANI_BOOLEAN ft = sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal));
3502 char extra[32];
3503 tANI_U8 len = 0;
3504
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003505 len = scnprintf(extra, sizeof(extra), "%s %d",
3506 "GETFASTTRANSITION", ft);
Sushant Kaushik231a4452015-07-15 16:23:56 +05303507 len = VOS_MIN(priv_data.total_len, len + 1);
3508 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003509 {
3510 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3511 "%s: failed to copy data to user buffer", __func__);
3512 ret = -EFAULT;
3513 goto exit;
3514 }
3515 }
3516 else if (strncmp(command, "SETROAMSCANCHANNELMINTIME", 25) == 0)
3517 {
3518 tANI_U8 *value = command;
3519 tANI_U8 minTime = CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_DEFAULT;
3520
3521 /* Move pointer to ahead of SETROAMSCANCHANNELMINTIME<delimiter> */
3522 value = value + 26;
3523 /* Convert the value from ascii to integer */
3524 ret = kstrtou8(value, 10, &minTime);
3525 if (ret < 0)
3526 {
3527 /* If the input value is greater than max value of datatype, then also
3528 kstrtou8 fails */
3529 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3530 "%s: kstrtou8 failed range [%d - %d]", __func__,
3531 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
3532 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
3533 ret = -EINVAL;
3534 goto exit;
3535 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003536 if ((minTime < CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN) ||
3537 (minTime > CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX))
3538 {
3539 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3540 "scan min channel time value %d is out of range"
3541 " (Min: %d Max: %d)", minTime,
3542 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
3543 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
3544 ret = -EINVAL;
3545 goto exit;
3546 }
3547
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303548 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3549 TRACE_CODE_HDD_SETROAMSCANCHANNELMINTIME_IOCTL,
3550 pAdapter->sessionId, minTime));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003551 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3552 "%s: Received Command to change channel min time = %d", __func__, minTime);
3553
3554 pHddCtx->cfg_ini->nNeighborScanMinChanTime = minTime;
3555 sme_setNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal), minTime);
3556 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003557 else if (strncmp(command, "SENDACTIONFRAME", 15) == 0)
3558 {
3559 tANI_U8 *value = command;
3560 tANI_U8 channel = 0;
3561 tANI_U8 dwellTime = 0;
3562 tANI_U8 bufLen = 0;
3563 tANI_U8 *buf = NULL;
3564 tSirMacAddr targetApBssid;
3565 eHalStatus status = eHAL_STATUS_SUCCESS;
3566 struct ieee80211_channel chan;
3567 tANI_U8 finalLen = 0;
3568 tANI_U8 *finalBuf = NULL;
3569 tANI_U8 temp = 0;
3570 u64 cookie;
3571 hdd_station_ctx_t *pHddStaCtx = NULL;
3572 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3573
3574 /* if not associated, no need to send action frame */
3575 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
3576 {
3577 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
3578 ret = -EINVAL;
3579 goto exit;
3580 }
3581
3582 status = hdd_parse_send_action_frame_data(value, targetApBssid, &channel,
3583 &dwellTime, &buf, &bufLen);
3584 if (eHAL_STATUS_SUCCESS != status)
3585 {
3586 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3587 "%s: Failed to parse send action frame data", __func__);
3588 ret = -EINVAL;
3589 goto exit;
3590 }
3591
3592 /* if the target bssid is different from currently associated AP,
3593 then no need to send action frame */
3594 if (VOS_TRUE != vos_mem_compare(targetApBssid,
3595 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
3596 {
3597 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:STA is not associated to this AP!",__func__);
3598 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07003599 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08003600 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003601 goto exit;
3602 }
3603
3604 /* if the channel number is different from operating channel then
3605 no need to send action frame */
3606 if (channel != pHddStaCtx->conn_info.operationChannel)
3607 {
3608 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3609 "%s: channel(%d) is different from operating channel(%d)",
3610 __func__, channel, pHddStaCtx->conn_info.operationChannel);
3611 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07003612 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08003613 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003614 goto exit;
3615 }
3616 chan.center_freq = sme_ChnToFreq(channel);
3617
3618 finalLen = bufLen + 24;
3619 finalBuf = vos_mem_malloc(finalLen);
3620 if (NULL == finalBuf)
3621 {
3622 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:memory allocation failed",__func__);
3623 ret = -ENOMEM;
Jeff Johnson11c33152013-04-16 17:52:40 -07003624 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08003625 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003626 goto exit;
3627 }
3628 vos_mem_zero(finalBuf, finalLen);
3629
3630 /* Fill subtype */
3631 temp = SIR_MAC_MGMT_ACTION << 4;
3632 vos_mem_copy(finalBuf + 0, &temp, sizeof(temp));
3633
3634 /* Fill type */
3635 temp = SIR_MAC_MGMT_FRAME;
3636 vos_mem_copy(finalBuf + 2, &temp, sizeof(temp));
3637
3638 /* Fill destination address (bssid of the AP) */
3639 vos_mem_copy(finalBuf + 4, targetApBssid, sizeof(targetApBssid));
3640
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07003641 /* Fill source address (STA mac address) */
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003642 vos_mem_copy(finalBuf + 10, pAdapter->macAddressCurrent.bytes, sizeof(pAdapter->macAddressCurrent.bytes));
3643
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07003644 /* Fill BSSID (AP mac address) */
3645 vos_mem_copy(finalBuf + 16, targetApBssid, sizeof(targetApBssid));
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003646
3647 /* Fill received buffer from 24th address */
3648 vos_mem_copy(finalBuf + 24, buf, bufLen);
3649
Jeff Johnson11c33152013-04-16 17:52:40 -07003650 /* done with the parsed buffer */
3651 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08003652 buf = NULL;
Jeff Johnson11c33152013-04-16 17:52:40 -07003653
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05303654#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
3655 params.chan = &chan;
3656 params.offchan = 0;
3657 params.wait = dwellTime;
3658 params.buf = finalBuf;
3659 params.len = finalLen;
3660 params.no_cck = 1;
3661 params.dont_wait_for_ack = 1;
3662 ret = wlan_hdd_mgmt_tx(NULL, &pAdapter->wdev, &params, &cookie);
3663#else
DARAM SUDHA39eede62014-02-12 11:16:40 +05303664 wlan_hdd_mgmt_tx( NULL,
Yue Maf49ba872013-08-19 12:04:25 -07003665#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
3666 &(pAdapter->wdev),
3667#else
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07003668 pAdapter->dev,
Yue Maf49ba872013-08-19 12:04:25 -07003669#endif
3670 &chan, 0,
3671#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
3672 NL80211_CHAN_HT20, 1,
3673#endif
3674 dwellTime, finalBuf, finalLen, 1,
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003675 1, &cookie );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05303676#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)*/
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003677 vos_mem_free(finalBuf);
3678 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003679 else if (strncmp(command, "GETROAMSCANCHANNELMINTIME", 25) == 0)
3680 {
3681 tANI_U16 val = sme_getNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal));
3682 char extra[32];
3683 tANI_U8 len = 0;
3684
3685 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003686 len = scnprintf(extra, sizeof(extra), "%s %d",
3687 "GETROAMSCANCHANNELMINTIME", val);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303688 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3689 TRACE_CODE_HDD_GETROAMSCANCHANNELMINTIME_IOCTL,
3690 pAdapter->sessionId, val));
Sushant Kaushikbb8c52c2015-07-15 16:36:23 +05303691 len = VOS_MIN(priv_data.total_len, len + 1);
3692 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003693 {
3694 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3695 "%s: failed to copy data to user buffer", __func__);
3696 ret = -EFAULT;
3697 goto exit;
3698 }
3699 }
3700 else if (strncmp(command, "SETSCANCHANNELTIME", 18) == 0)
3701 {
3702 tANI_U8 *value = command;
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07003703 tANI_U16 maxTime = CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003704
3705 /* Move pointer to ahead of SETSCANCHANNELTIME<delimiter> */
3706 value = value + 19;
3707 /* Convert the value from ascii to integer */
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07003708 ret = kstrtou16(value, 10, &maxTime);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003709 if (ret < 0)
3710 {
3711 /* If the input value is greater than max value of datatype, then also
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07003712 kstrtou16 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003713 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07003714 "%s: kstrtou16 failed range [%d - %d]", __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003715 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
3716 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
3717 ret = -EINVAL;
3718 goto exit;
3719 }
3720
3721 if ((maxTime < CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN) ||
3722 (maxTime > CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX))
3723 {
3724 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3725 "lfr mode value %d is out of range"
3726 " (Min: %d Max: %d)", maxTime,
3727 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
3728 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
3729 ret = -EINVAL;
3730 goto exit;
3731 }
3732
3733 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3734 "%s: Received Command to change channel max time = %d", __func__, maxTime);
3735
3736 pHddCtx->cfg_ini->nNeighborScanMaxChanTime = maxTime;
3737 sme_setNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal), maxTime);
3738 }
3739 else if (strncmp(command, "GETSCANCHANNELTIME", 18) == 0)
3740 {
3741 tANI_U16 val = sme_getNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal));
3742 char extra[32];
3743 tANI_U8 len = 0;
3744
3745 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003746 len = scnprintf(extra, sizeof(extra), "%s %d",
3747 "GETSCANCHANNELTIME", val);
Ratheesh S Pacbfa932015-07-16 15:27:18 +05303748 len = VOS_MIN(priv_data.total_len, len + 1);
3749 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003750 {
3751 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3752 "%s: failed to copy data to user buffer", __func__);
3753 ret = -EFAULT;
3754 goto exit;
3755 }
3756 }
3757 else if (strncmp(command, "SETSCANHOMETIME", 15) == 0)
3758 {
3759 tANI_U8 *value = command;
3760 tANI_U16 val = CFG_NEIGHBOR_SCAN_TIMER_PERIOD_DEFAULT;
3761
3762 /* Move pointer to ahead of SETSCANHOMETIME<delimiter> */
3763 value = value + 16;
3764 /* Convert the value from ascii to integer */
3765 ret = kstrtou16(value, 10, &val);
3766 if (ret < 0)
3767 {
3768 /* If the input value is greater than max value of datatype, then also
3769 kstrtou16 fails */
3770 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3771 "%s: kstrtou16 failed range [%d - %d]", __func__,
3772 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
3773 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
3774 ret = -EINVAL;
3775 goto exit;
3776 }
3777
3778 if ((val < CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN) ||
3779 (val > CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX))
3780 {
3781 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3782 "scan home time value %d is out of range"
3783 " (Min: %d Max: %d)", val,
3784 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
3785 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
3786 ret = -EINVAL;
3787 goto exit;
3788 }
3789
3790 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3791 "%s: Received Command to change scan home time = %d", __func__, val);
3792
3793 pHddCtx->cfg_ini->nNeighborScanPeriod = val;
3794 sme_setNeighborScanPeriod((tHalHandle)(pHddCtx->hHal), val);
3795 }
3796 else if (strncmp(command, "GETSCANHOMETIME", 15) == 0)
3797 {
3798 tANI_U16 val = sme_getNeighborScanPeriod((tHalHandle)(pHddCtx->hHal));
3799 char extra[32];
3800 tANI_U8 len = 0;
3801
3802 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003803 len = scnprintf(extra, sizeof(extra), "%s %d",
3804 "GETSCANHOMETIME", val);
Ratheesh S P728d7c62015-07-16 15:38:58 +05303805 len = VOS_MIN(priv_data.total_len, len + 1);
3806 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003807 {
3808 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3809 "%s: failed to copy data to user buffer", __func__);
3810 ret = -EFAULT;
3811 goto exit;
3812 }
3813 }
3814 else if (strncmp(command, "SETROAMINTRABAND", 16) == 0)
3815 {
3816 tANI_U8 *value = command;
3817 tANI_U8 val = CFG_ROAM_INTRA_BAND_DEFAULT;
3818
3819 /* Move pointer to ahead of SETROAMINTRABAND<delimiter> */
3820 value = value + 17;
3821 /* Convert the value from ascii to integer */
3822 ret = kstrtou8(value, 10, &val);
3823 if (ret < 0)
3824 {
3825 /* If the input value is greater than max value of datatype, then also
3826 kstrtou8 fails */
3827 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3828 "%s: kstrtou8 failed range [%d - %d]", __func__,
3829 CFG_ROAM_INTRA_BAND_MIN,
3830 CFG_ROAM_INTRA_BAND_MAX);
3831 ret = -EINVAL;
3832 goto exit;
3833 }
3834
3835 if ((val < CFG_ROAM_INTRA_BAND_MIN) ||
3836 (val > CFG_ROAM_INTRA_BAND_MAX))
3837 {
3838 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3839 "intra band mode value %d is out of range"
3840 " (Min: %d Max: %d)", val,
3841 CFG_ROAM_INTRA_BAND_MIN,
3842 CFG_ROAM_INTRA_BAND_MAX);
3843 ret = -EINVAL;
3844 goto exit;
3845 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003846 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3847 "%s: Received Command to change intra band = %d", __func__, val);
3848
3849 pHddCtx->cfg_ini->nRoamIntraBand = val;
3850 sme_setRoamIntraBand((tHalHandle)(pHddCtx->hHal), val);
3851 }
3852 else if (strncmp(command, "GETROAMINTRABAND", 16) == 0)
3853 {
3854 tANI_U16 val = sme_getRoamIntraBand((tHalHandle)(pHddCtx->hHal));
3855 char extra[32];
3856 tANI_U8 len = 0;
3857
3858 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003859 len = scnprintf(extra, sizeof(extra), "%s %d",
3860 "GETROAMINTRABAND", val);
Ratheesh S P2dd2a3e2015-07-16 15:34:23 +05303861 len = VOS_MIN(priv_data.total_len, len + 1);
3862 if (copy_to_user(priv_data.buf, &extra, len))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003863 {
3864 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3865 "%s: failed to copy data to user buffer", __func__);
3866 ret = -EFAULT;
3867 goto exit;
3868 }
3869 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003870 else if (strncmp(command, "SETSCANNPROBES", 14) == 0)
3871 {
3872 tANI_U8 *value = command;
3873 tANI_U8 nProbes = CFG_ROAM_SCAN_N_PROBES_DEFAULT;
3874
3875 /* Move pointer to ahead of SETSCANNPROBES<delimiter> */
3876 value = value + 15;
3877 /* Convert the value from ascii to integer */
3878 ret = kstrtou8(value, 10, &nProbes);
3879 if (ret < 0)
3880 {
3881 /* If the input value is greater than max value of datatype, then also
3882 kstrtou8 fails */
3883 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3884 "%s: kstrtou8 failed range [%d - %d]", __func__,
3885 CFG_ROAM_SCAN_N_PROBES_MIN,
3886 CFG_ROAM_SCAN_N_PROBES_MAX);
3887 ret = -EINVAL;
3888 goto exit;
3889 }
3890
3891 if ((nProbes < CFG_ROAM_SCAN_N_PROBES_MIN) ||
3892 (nProbes > CFG_ROAM_SCAN_N_PROBES_MAX))
3893 {
3894 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3895 "NProbes value %d is out of range"
3896 " (Min: %d Max: %d)", nProbes,
3897 CFG_ROAM_SCAN_N_PROBES_MIN,
3898 CFG_ROAM_SCAN_N_PROBES_MAX);
3899 ret = -EINVAL;
3900 goto exit;
3901 }
3902
3903 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3904 "%s: Received Command to Set nProbes = %d", __func__, nProbes);
3905
3906 pHddCtx->cfg_ini->nProbes = nProbes;
3907 sme_UpdateRoamScanNProbes((tHalHandle)(pHddCtx->hHal), nProbes);
3908 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05303909 else if (strncmp(command, "GETSCANNPROBES", 14) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003910 {
3911 tANI_U8 val = sme_getRoamScanNProbes((tHalHandle)(pHddCtx->hHal));
3912 char extra[32];
3913 tANI_U8 len = 0;
3914
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003915 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri6da525d2015-08-07 13:55:54 +05303916 len = VOS_MIN(priv_data.total_len, len + 1);
3917 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003918 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3919 "%s: failed to copy data to user buffer", __func__);
3920 ret = -EFAULT;
3921 goto exit;
3922 }
3923 }
3924 else if (strncmp(command, "SETSCANHOMEAWAYTIME", 19) == 0)
3925 {
3926 tANI_U8 *value = command;
3927 tANI_U16 homeAwayTime = CFG_ROAM_SCAN_HOME_AWAY_TIME_DEFAULT;
3928
3929 /* Move pointer to ahead of SETSCANHOMEAWAYTIME<delimiter> */
3930 /* input value is in units of msec */
3931 value = value + 20;
3932 /* Convert the value from ascii to integer */
3933 ret = kstrtou16(value, 10, &homeAwayTime);
3934 if (ret < 0)
3935 {
3936 /* If the input value is greater than max value of datatype, then also
3937 kstrtou8 fails */
3938 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3939 "%s: kstrtou8 failed range [%d - %d]", __func__,
3940 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
3941 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
3942 ret = -EINVAL;
3943 goto exit;
3944 }
3945
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003946 if ((homeAwayTime < CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN) ||
3947 (homeAwayTime > CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX))
3948 {
3949 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3950 "homeAwayTime value %d is out of range"
3951 " (Min: %d Max: %d)", homeAwayTime,
3952 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
3953 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
3954 ret = -EINVAL;
3955 goto exit;
3956 }
3957
3958 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3959 "%s: Received Command to Set scan away time = %d", __func__, homeAwayTime);
Srinivas Girigowda6cf0b822013-06-27 14:00:20 -07003960 if (pHddCtx->cfg_ini->nRoamScanHomeAwayTime != homeAwayTime)
3961 {
3962 pHddCtx->cfg_ini->nRoamScanHomeAwayTime = homeAwayTime;
3963 sme_UpdateRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal), homeAwayTime, eANI_BOOLEAN_TRUE);
3964 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003965 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05303966 else if (strncmp(command, "GETSCANHOMEAWAYTIME", 19) == 0)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003967 {
3968 tANI_U16 val = sme_getRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal));
3969 char extra[32];
3970 tANI_U8 len = 0;
3971
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003972 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Ratnam Rachuri51a5ad12015-08-07 14:06:37 +05303973 len = VOS_MIN(priv_data.total_len, len + 1);
3974 if (copy_to_user(priv_data.buf, &extra, len)) {
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003975 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3976 "%s: failed to copy data to user buffer", __func__);
3977 ret = -EFAULT;
3978 goto exit;
3979 }
3980 }
3981 else if (strncmp(command, "REASSOC", 7) == 0)
3982 {
3983 tANI_U8 *value = command;
3984 tANI_U8 channel = 0;
3985 tSirMacAddr targetApBssid;
3986 eHalStatus status = eHAL_STATUS_SUCCESS;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07003987#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3988 tCsrHandoffRequest handoffInfo;
3989#endif
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003990 hdd_station_ctx_t *pHddStaCtx = NULL;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003991 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3992
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003993 /* if not associated, no need to proceed with reassoc */
3994 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
3995 {
3996 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
3997 ret = -EINVAL;
3998 goto exit;
3999 }
4000
4001 status = hdd_parse_reassoc_command_data(value, targetApBssid, &channel);
4002 if (eHAL_STATUS_SUCCESS != status)
4003 {
4004 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4005 "%s: Failed to parse reassoc command data", __func__);
4006 ret = -EINVAL;
4007 goto exit;
4008 }
4009
4010 /* if the target bssid is same as currently associated AP,
4011 then no need to proceed with reassoc */
4012 if (VOS_TRUE == vos_mem_compare(targetApBssid,
4013 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
4014 {
4015 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Reassoc BSSID is same as currently associated AP bssid",__func__);
c_manjee6de1f452015-12-08 14:13:28 +05304016 ret = 0;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004017 goto exit;
4018 }
4019
4020 /* Check channel number is a valid channel number */
4021 if(VOS_STATUS_SUCCESS !=
4022 wlan_hdd_validate_operation_channel(pAdapter, channel))
4023 {
4024 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004025 "%s: Invalid Channel [%d]", __func__, channel);
c_manjee6de1f452015-12-08 14:13:28 +05304026
4027 ret = -EINVAL;
4028 goto exit;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004029 }
4030
4031 /* Proceed with reassoc */
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07004032#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4033 handoffInfo.channel = channel;
4034 vos_mem_copy(handoffInfo.bssid, targetApBssid, sizeof(tSirMacAddr));
4035 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
4036#endif
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004037 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07004038 else if (strncmp(command, "SETWESMODE", 10) == 0)
4039 {
4040 tANI_U8 *value = command;
4041 tANI_BOOLEAN wesMode = CFG_ENABLE_WES_MODE_NAME_DEFAULT;
4042
4043 /* Move pointer to ahead of SETWESMODE<delimiter> */
4044 value = value + 11;
4045 /* Convert the value from ascii to integer */
4046 ret = kstrtou8(value, 10, &wesMode);
4047 if (ret < 0)
4048 {
4049 /* If the input value is greater than max value of datatype, then also
4050 kstrtou8 fails */
4051 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4052 "%s: kstrtou8 failed range [%d - %d]", __func__,
4053 CFG_ENABLE_WES_MODE_NAME_MIN,
4054 CFG_ENABLE_WES_MODE_NAME_MAX);
4055 ret = -EINVAL;
4056 goto exit;
4057 }
4058
4059 if ((wesMode < CFG_ENABLE_WES_MODE_NAME_MIN) ||
4060 (wesMode > CFG_ENABLE_WES_MODE_NAME_MAX))
4061 {
4062 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4063 "WES Mode value %d is out of range"
4064 " (Min: %d Max: %d)", wesMode,
4065 CFG_ENABLE_WES_MODE_NAME_MIN,
4066 CFG_ENABLE_WES_MODE_NAME_MAX);
4067 ret = -EINVAL;
4068 goto exit;
4069 }
4070 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4071 "%s: Received Command to Set WES Mode rssi diff = %d", __func__, wesMode);
4072
4073 pHddCtx->cfg_ini->isWESModeEnabled = wesMode;
4074 sme_UpdateWESMode((tHalHandle)(pHddCtx->hHal), wesMode);
4075 }
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304076 else if (strncmp(command, "GETWESMODE", 10) == 0)
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07004077 {
4078 tANI_BOOLEAN wesMode = sme_GetWESMode((tHalHandle)(pHddCtx->hHal));
4079 char extra[32];
4080 tANI_U8 len = 0;
4081
Arif Hussain826d9412013-11-12 16:44:54 -08004082 len = scnprintf(extra, sizeof(extra), "%s %d", command, wesMode);
Ratnam Rachuri8fe90c62015-08-07 14:03:26 +05304083 len = VOS_MIN(priv_data.total_len, len + 1);
4084 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07004085 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4086 "%s: failed to copy data to user buffer", __func__);
4087 ret = -EFAULT;
4088 goto exit;
4089 }
4090 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004091#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE || FEATURE_WLAN_LFR */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004092#ifdef FEATURE_WLAN_LFR
4093 else if (strncmp(command, "SETFASTROAM", 11) == 0)
4094 {
4095 tANI_U8 *value = command;
4096 tANI_U8 lfrMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
4097
4098 /* Move pointer to ahead of SETFASTROAM<delimiter> */
4099 value = value + 12;
4100 /* Convert the value from ascii to integer */
4101 ret = kstrtou8(value, 10, &lfrMode);
4102 if (ret < 0)
4103 {
4104 /* If the input value is greater than max value of datatype, then also
4105 kstrtou8 fails */
4106 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4107 "%s: kstrtou8 failed range [%d - %d]", __func__,
4108 CFG_LFR_FEATURE_ENABLED_MIN,
4109 CFG_LFR_FEATURE_ENABLED_MAX);
4110 ret = -EINVAL;
4111 goto exit;
4112 }
4113
4114 if ((lfrMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
4115 (lfrMode > CFG_LFR_FEATURE_ENABLED_MAX))
4116 {
4117 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4118 "lfr mode value %d is out of range"
4119 " (Min: %d Max: %d)", lfrMode,
4120 CFG_LFR_FEATURE_ENABLED_MIN,
4121 CFG_LFR_FEATURE_ENABLED_MAX);
4122 ret = -EINVAL;
4123 goto exit;
4124 }
4125
4126 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4127 "%s: Received Command to change lfr mode = %d", __func__, lfrMode);
4128
4129 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = lfrMode;
4130 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), lfrMode);
4131 }
4132#endif
4133#ifdef WLAN_FEATURE_VOWIFI_11R
4134 else if (strncmp(command, "SETFASTTRANSITION", 17) == 0)
4135 {
4136 tANI_U8 *value = command;
4137 tANI_U8 ft = CFG_FAST_TRANSITION_ENABLED_NAME_DEFAULT;
4138
4139 /* Move pointer to ahead of SETFASTROAM<delimiter> */
4140 value = value + 18;
4141 /* Convert the value from ascii to integer */
4142 ret = kstrtou8(value, 10, &ft);
4143 if (ret < 0)
4144 {
4145 /* If the input value is greater than max value of datatype, then also
4146 kstrtou8 fails */
4147 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4148 "%s: kstrtou8 failed range [%d - %d]", __func__,
4149 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
4150 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
4151 ret = -EINVAL;
4152 goto exit;
4153 }
4154
4155 if ((ft < CFG_FAST_TRANSITION_ENABLED_NAME_MIN) ||
4156 (ft > CFG_FAST_TRANSITION_ENABLED_NAME_MAX))
4157 {
4158 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4159 "ft mode value %d is out of range"
4160 " (Min: %d Max: %d)", ft,
4161 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
4162 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
4163 ret = -EINVAL;
4164 goto exit;
4165 }
4166
4167 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4168 "%s: Received Command to change ft mode = %d", __func__, ft);
4169
4170 pHddCtx->cfg_ini->isFastTransitionEnabled = ft;
4171 sme_UpdateFastTransitionEnabled((tHalHandle)(pHddCtx->hHal), ft);
4172 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304173 else if (strncmp(command, "SETDFSSCANMODE", 14) == 0)
4174 {
4175 tANI_U8 *value = command;
4176 tANI_U8 dfsScanMode = DFS_CHNL_SCAN_ENABLED_NORMAL;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304177
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304178 /* Move pointer to ahead of SETDFSSCANMODE<delimiter> */
4179 value = value + 15;
4180 /* Convert the value from ascii to integer */
4181 ret = kstrtou8(value, 10, &dfsScanMode);
4182 if (ret < 0)
4183 {
4184 /* If the input value is greater than max value of
4185 datatype, then also kstrtou8 fails
4186 */
4187 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4188 "%s: kstrtou8 failed range [%d - %d]", __func__,
4189 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
4190 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
4191 ret = -EINVAL;
4192 goto exit;
4193 }
4194
4195 if ((dfsScanMode < CFG_ENABLE_DFS_CHNL_SCAN_MIN) ||
4196 (dfsScanMode > CFG_ENABLE_DFS_CHNL_SCAN_MAX))
4197 {
4198 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4199 "dfsScanMode value %d is out of range"
4200 " (Min: %d Max: %d)", dfsScanMode,
4201 CFG_ENABLE_DFS_CHNL_SCAN_MIN,
4202 CFG_ENABLE_DFS_CHNL_SCAN_MAX);
4203 ret = -EINVAL;
4204 goto exit;
4205 }
4206 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4207 "%s: Received Command to Set DFS Scan Mode = %d",
4208 __func__, dfsScanMode);
4209
4210 ret = wlan_hdd_handle_dfs_chan_scan(pHddCtx, dfsScanMode);
4211 }
4212 else if (strncmp(command, "GETDFSSCANMODE", 14) == 0)
4213 {
4214 tANI_U8 dfsScanMode = sme_GetDFSScanMode(pHddCtx->hHal);
4215 char extra[32];
4216 tANI_U8 len = 0;
4217
4218 len = scnprintf(extra, sizeof(extra), "%s %d", command, dfsScanMode);
Ratheesh S P767224e2015-07-16 15:35:51 +05304219 len = VOS_MIN(priv_data.total_len, len + 1);
4220 if (copy_to_user(priv_data.buf, &extra, len))
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304221 {
4222 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4223 "%s: failed to copy data to user buffer", __func__);
4224 ret = -EFAULT;
4225 goto exit;
4226 }
4227 }
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304228 else if (strncmp(command, "FASTREASSOC", 11) == 0)
4229 {
4230 tANI_U8 *value = command;
Padma, Santhosh Kumarf4582d32014-11-06 19:24:51 +05304231 tANI_U8 channel = 0;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304232 tSirMacAddr targetApBssid;
4233 tANI_U8 trigger = 0;
4234 eHalStatus status = eHAL_STATUS_SUCCESS;
Padma, Santhosh Kumarb980a6f2014-11-06 19:07:24 +05304235 tHalHandle hHal;
4236 v_U32_t roamId = 0;
4237 tCsrRoamModifyProfileFields modProfileFields;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304238 hdd_station_ctx_t *pHddStaCtx = NULL;
4239 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Padma, Santhosh Kumarb980a6f2014-11-06 19:07:24 +05304240 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304241
4242 /* if not associated, no need to proceed with reassoc */
4243 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
4244 {
4245 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
4246 ret = -EINVAL;
4247 goto exit;
4248 }
4249
Padma, Santhosh Kumarf4582d32014-11-06 19:24:51 +05304250 status = hdd_parse_reassoc_command_data(value, targetApBssid, &channel);
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304251 if (eHAL_STATUS_SUCCESS != status)
4252 {
4253 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4254 "%s: Failed to parse reassoc command data", __func__);
4255 ret = -EINVAL;
4256 goto exit;
4257 }
4258
4259 /* if the target bssid is same as currently associated AP,
Padma, Santhosh Kumarb980a6f2014-11-06 19:07:24 +05304260 issue reassoc to same AP */
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304261 if (VOS_TRUE == vos_mem_compare(targetApBssid,
4262 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
4263 {
AnjaneeDevi Kapparapu228d0c52015-11-09 12:32:21 +05304264 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4265 "%s:11r Reassoc BSSID is same as currently associated AP bssid",
4266 __func__);
Padma, Santhosh Kumarb980a6f2014-11-06 19:07:24 +05304267 sme_GetModifyProfileFields(hHal, pAdapter->sessionId,
4268 &modProfileFields);
4269 sme_RoamReassoc(hHal, pAdapter->sessionId,
4270 NULL, modProfileFields, &roamId, 1);
AnjaneeDevi Kapparapu228d0c52015-11-09 12:32:21 +05304271 return 0;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304272 }
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05304273
4274 /* Check channel number is a valid channel number */
4275 if(VOS_STATUS_SUCCESS !=
4276 wlan_hdd_validate_operation_channel(pAdapter, channel))
4277 {
4278 hddLog(VOS_TRACE_LEVEL_ERROR,
4279 "%s: Invalid Channel [%d]", __func__, channel);
AnjaneeDevi Kapparapu228d0c52015-11-09 12:32:21 +05304280 return -EINVAL;
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05304281 }
4282
Padma, Santhosh Kumarf4582d32014-11-06 19:24:51 +05304283 trigger = eSME_ROAM_TRIGGER_SCAN;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304284
4285 /* Proceed with scan/roam */
4286 smeIssueFastRoamNeighborAPEvent(WLAN_HDD_GET_HAL_CTX(pAdapter),
4287 &targetApBssid[0],
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05304288 (tSmeFastRoamTrigger)(trigger),
4289 channel);
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05304290 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004291#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004292#ifdef FEATURE_WLAN_ESE
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004293 else if (strncmp(command, "SETCCXMODE", 10) == 0)
4294 {
4295 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004296 tANI_U8 eseMode = CFG_ESE_FEATURE_ENABLED_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004297
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004298 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004299 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004300 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004301 hdd_is_okc_mode_enabled(pHddCtx) &&
4302 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4303 {
4304 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004305 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004306 " hence this operation is not permitted!", __func__);
4307 ret = -EPERM;
4308 goto exit;
4309 }
4310
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004311 /* Move pointer to ahead of SETCCXMODE<delimiter> */
4312 value = value + 11;
4313 /* Convert the value from ascii to integer */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004314 ret = kstrtou8(value, 10, &eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004315 if (ret < 0)
4316 {
4317 /* If the input value is greater than max value of datatype, then also
4318 kstrtou8 fails */
4319 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4320 "%s: kstrtou8 failed range [%d - %d]", __func__,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004321 CFG_ESE_FEATURE_ENABLED_MIN,
4322 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004323 ret = -EINVAL;
4324 goto exit;
4325 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004326 if ((eseMode < CFG_ESE_FEATURE_ENABLED_MIN) ||
4327 (eseMode > CFG_ESE_FEATURE_ENABLED_MAX))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004328 {
4329 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004330 "Ese mode value %d is out of range"
4331 " (Min: %d Max: %d)", eseMode,
4332 CFG_ESE_FEATURE_ENABLED_MIN,
4333 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004334 ret = -EINVAL;
4335 goto exit;
4336 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004337 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004338 "%s: Received Command to change ese mode = %d", __func__, eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004339
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004340 pHddCtx->cfg_ini->isEseIniFeatureEnabled = eseMode;
4341 sme_UpdateIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal), eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004342 }
4343#endif
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004344 else if (strncmp(command, "SETROAMSCANCONTROL", 18) == 0)
4345 {
4346 tANI_U8 *value = command;
4347 tANI_BOOLEAN roamScanControl = 0;
4348
4349 /* Move pointer to ahead of SETROAMSCANCONTROL<delimiter> */
4350 value = value + 19;
4351 /* Convert the value from ascii to integer */
4352 ret = kstrtou8(value, 10, &roamScanControl);
4353 if (ret < 0)
4354 {
4355 /* If the input value is greater than max value of datatype, then also
4356 kstrtou8 fails */
4357 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4358 "%s: kstrtou8 failed ", __func__);
4359 ret = -EINVAL;
4360 goto exit;
4361 }
4362
4363 if (0 != roamScanControl)
4364 {
4365 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4366 "roam scan control invalid value = %d",
4367 roamScanControl);
4368 ret = -EINVAL;
4369 goto exit;
4370 }
4371 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4372 "%s: Received Command to Set roam scan control = %d", __func__, roamScanControl);
4373
4374 sme_SetRoamScanControl((tHalHandle)(pHddCtx->hHal), roamScanControl);
4375 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004376#ifdef FEATURE_WLAN_OKC
4377 else if (strncmp(command, "SETOKCMODE", 10) == 0)
4378 {
4379 tANI_U8 *value = command;
4380 tANI_U8 okcMode = CFG_OKC_FEATURE_ENABLED_DEFAULT;
4381
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004382 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004383 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004384 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004385 hdd_is_okc_mode_enabled(pHddCtx) &&
4386 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
4387 {
4388 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004389 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07004390 " hence this operation is not permitted!", __func__);
4391 ret = -EPERM;
4392 goto exit;
4393 }
4394
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004395 /* Move pointer to ahead of SETOKCMODE<delimiter> */
4396 value = value + 11;
4397 /* Convert the value from ascii to integer */
4398 ret = kstrtou8(value, 10, &okcMode);
4399 if (ret < 0)
4400 {
4401 /* If the input value is greater than max value of datatype, then also
4402 kstrtou8 fails */
4403 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4404 "%s: kstrtou8 failed range [%d - %d]", __func__,
4405 CFG_OKC_FEATURE_ENABLED_MIN,
4406 CFG_OKC_FEATURE_ENABLED_MAX);
4407 ret = -EINVAL;
4408 goto exit;
4409 }
4410
4411 if ((okcMode < CFG_OKC_FEATURE_ENABLED_MIN) ||
4412 (okcMode > CFG_OKC_FEATURE_ENABLED_MAX))
4413 {
4414 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4415 "Okc mode value %d is out of range"
4416 " (Min: %d Max: %d)", okcMode,
4417 CFG_OKC_FEATURE_ENABLED_MIN,
4418 CFG_OKC_FEATURE_ENABLED_MAX);
4419 ret = -EINVAL;
4420 goto exit;
4421 }
4422
4423 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4424 "%s: Received Command to change okc mode = %d", __func__, okcMode);
4425
4426 pHddCtx->cfg_ini->isOkcIniFeatureEnabled = okcMode;
4427 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07004428#endif /* FEATURE_WLAN_OKC */
Mahesh A Saptasagarec7d1092015-04-02 13:41:34 +05304429 else if (strncmp(command, "GETROAMSCANCONTROL", 18) == 0)
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004430 {
4431 tANI_BOOLEAN roamScanControl = sme_GetRoamScanControl((tHalHandle)(pHddCtx->hHal));
4432 char extra[32];
4433 tANI_U8 len = 0;
4434
Sameer Thalappilb0a30232013-09-27 15:37:48 -07004435 len = scnprintf(extra, sizeof(extra), "%s %d",
4436 command, roamScanControl);
Ratnam Rachuri083ada82015-08-07 14:01:05 +05304437 len = VOS_MIN(priv_data.total_len, len + 1);
4438 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004439 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4440 "%s: failed to copy data to user buffer", __func__);
4441 ret = -EFAULT;
4442 goto exit;
4443 }
4444 }
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05304445#ifdef WLAN_FEATURE_PACKET_FILTERING
4446 else if (strncmp(command, "ENABLE_PKTFILTER_IPV6", 21) == 0)
4447 {
4448 tANI_U8 filterType = 0;
4449 tANI_U8 *value = command;
4450
4451 /* Move pointer to ahead of ENABLE_PKTFILTER_IPV6<delimiter> */
4452 value = value + 22;
4453
4454 /* Convert the value from ascii to integer */
4455 ret = kstrtou8(value, 10, &filterType);
4456 if (ret < 0)
4457 {
4458 /* If the input value is greater than max value of datatype,
4459 * then also kstrtou8 fails
4460 */
4461 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4462 "%s: kstrtou8 failed range ", __func__);
4463 ret = -EINVAL;
4464 goto exit;
4465 }
4466
4467 if (filterType != 0 && filterType != 1)
4468 {
4469 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4470 "%s: Accepted Values are 0 and 1 ", __func__);
4471 ret = -EINVAL;
4472 goto exit;
4473 }
4474 wlan_hdd_setIPv6Filter(WLAN_HDD_GET_CTX(pAdapter), filterType,
4475 pAdapter->sessionId);
4476 }
4477#endif
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05304478 else if (strncmp(command, "BTCOEXMODE", 10) == 0 )
4479 {
Kiet Lamad161252014-07-22 11:23:32 -07004480 char *dhcpPhase;
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05304481 int ret;
4482
Kiet Lamad161252014-07-22 11:23:32 -07004483 dhcpPhase = command + 11;
4484 if ('1' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05304485 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05304486 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07004487 FL("send DHCP START indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05304488
4489 pHddCtx->btCoexModeSet = TRUE;
Kiet Lamad161252014-07-22 11:23:32 -07004490
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05304491 ret = wlan_hdd_scan_abort(pAdapter);
4492 if (ret < 0)
4493 {
4494 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4495 FL("failed to abort existing scan %d"), ret);
4496 }
4497
Kiet Lamad161252014-07-22 11:23:32 -07004498 sme_DHCPStartInd(pHddCtx->hHal, pAdapter->device_mode,
4499 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05304500 }
Kiet Lamad161252014-07-22 11:23:32 -07004501 else if ('2' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05304502 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05304503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07004504 FL("send DHCP STOP indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05304505
4506 pHddCtx->btCoexModeSet = FALSE;
Kiet Lamad161252014-07-22 11:23:32 -07004507
4508 sme_DHCPStopInd(pHddCtx->hHal, pAdapter->device_mode,
4509 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05304510 }
4511 }
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07004512 else if (strncmp(command, "SCAN-ACTIVE", 11) == 0)
4513 {
Abhishek Singh58749d62016-02-03 15:27:20 +05304514 hddLog(LOG1,
4515 FL("making default scan to ACTIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05304516 pHddCtx->scan_info.scan_mode = eSIR_ACTIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07004517 }
4518 else if (strncmp(command, "SCAN-PASSIVE", 12) == 0)
4519 {
Abhishek Singh58749d62016-02-03 15:27:20 +05304520 hddLog(LOG1,
4521 FL("making default scan to PASSIVE"));
c_hpothudbefd3e2014-04-28 15:59:47 +05304522 pHddCtx->scan_info.scan_mode = eSIR_PASSIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07004523 }
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05304524 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
4525 {
4526 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
4527 char extra[32];
4528 tANI_U8 len = 0;
4529
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05304530 memset(extra, 0, sizeof(extra));
4531 ret = hdd_get_dwell_time(pCfg, command, extra, sizeof(extra), &len);
Ratnam Rachuri12d5d462015-08-07 14:10:23 +05304532 len = VOS_MIN(priv_data.total_len, len + 1);
4533 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len)) {
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05304534 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4535 "%s: failed to copy data to user buffer", __func__);
4536 ret = -EFAULT;
4537 goto exit;
4538 }
4539 ret = len;
4540 }
4541 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
4542 {
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05304543 ret = hdd_set_dwell_time(pAdapter, command);
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05304544 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07004545 else if ( strncasecmp(command, "MIRACAST", 8) == 0 )
4546 {
4547 tANI_U8 filterType = 0;
4548 tANI_U8 *value;
4549 value = command + 9;
4550
4551 /* Convert the value from ascii to integer */
4552 ret = kstrtou8(value, 10, &filterType);
4553 if (ret < 0)
4554 {
4555 /* If the input value is greater than max value of datatype,
4556 * then also kstrtou8 fails
4557 */
4558 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4559 "%s: kstrtou8 failed range ", __func__);
4560 ret = -EINVAL;
4561 goto exit;
4562 }
4563 if ((filterType < WLAN_HDD_DRIVER_MIRACAST_CFG_MIN_VAL ) ||
4564 (filterType > WLAN_HDD_DRIVER_MIRACAST_CFG_MAX_VAL))
4565 {
4566 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4567 "%s: Accepted Values are 0 to 2. 0-Disabled, 1-Source,"
4568 " 2-Sink ", __func__);
4569 ret = -EINVAL;
4570 goto exit;
4571 }
4572 //Filtertype value should be either 0-Disabled, 1-Source, 2-sink
4573 pHddCtx->drvr_miracast = filterType;
Kaushik, Sushant96122442014-10-21 16:40:18 +05304574 pScanInfo = &pHddCtx->scan_info;
4575 if (filterType && pScanInfo != NULL &&
4576 pHddCtx->scan_info.mScanPending)
4577 {
4578 /*Miracast Session started. Abort Scan */
4579 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4580 "%s, Aborting Scan For Miracast",__func__);
4581 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
4582 eCSR_SCAN_ABORT_DEFAULT);
4583 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07004584 hdd_tx_rx_pkt_cnt_stat_timer_handler(pHddCtx);
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05304585 sme_SetMiracastMode(pHddCtx->hHal, pHddCtx->drvr_miracast);
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07004586 }
Leo Chang614d2072013-08-22 14:59:44 -07004587 else if (strncmp(command, "SETMCRATE", 9) == 0)
4588 {
Leo Chang614d2072013-08-22 14:59:44 -07004589 tANI_U8 *value = command;
4590 int targetRate;
Leo Chang1f98cbd2013-10-17 15:03:52 -07004591 tSirRateUpdateInd *rateUpdate;
4592 eHalStatus status;
Leo Chang614d2072013-08-22 14:59:44 -07004593
4594 /* Only valid for SAP mode */
4595 if (WLAN_HDD_SOFTAP != pAdapter->device_mode)
4596 {
4597 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4598 "%s: SAP mode is not running", __func__);
4599 ret = -EFAULT;
4600 goto exit;
4601 }
4602
4603 /* Move pointer to ahead of SETMCRATE<delimiter> */
4604 /* input value is in units of hundred kbps */
4605 value = value + 10;
4606 /* Convert the value from ascii to integer, decimal base */
4607 ret = kstrtouint(value, 10, &targetRate);
4608
Leo Chang1f98cbd2013-10-17 15:03:52 -07004609 rateUpdate = (tSirRateUpdateInd *)vos_mem_malloc(sizeof(tSirRateUpdateInd));
4610 if (NULL == rateUpdate)
Leo Chang614d2072013-08-22 14:59:44 -07004611 {
Leo Chang1f98cbd2013-10-17 15:03:52 -07004612 hddLog(VOS_TRACE_LEVEL_ERROR,
4613 "%s: SETMCRATE indication alloc fail", __func__);
4614 ret = -EFAULT;
4615 goto exit;
4616 }
4617 vos_mem_zero(rateUpdate, sizeof(tSirRateUpdateInd ));
4618
4619 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4620 "MC Target rate %d", targetRate);
4621 /* Ignore unicast */
4622 rateUpdate->ucastDataRate = -1;
4623 rateUpdate->mcastDataRate24GHz = targetRate;
4624 rateUpdate->mcastDataRate5GHz = targetRate;
4625 rateUpdate->mcastDataRate24GHzTxFlag = 0;
4626 rateUpdate->mcastDataRate5GHzTxFlag = 0;
4627 status = sme_SendRateUpdateInd(pHddCtx->hHal, rateUpdate);
4628 if (eHAL_STATUS_SUCCESS != status)
4629 {
4630 hddLog(VOS_TRACE_LEVEL_ERROR,
4631 "%s: SET_MC_RATE failed", __func__);
4632 vos_mem_free(rateUpdate);
4633 ret = -EFAULT;
4634 goto exit;
Leo Chang614d2072013-08-22 14:59:44 -07004635 }
4636 }
Rajeev79dbe4c2013-10-05 11:03:42 +05304637#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev Kumar8b373292014-01-08 20:36:55 -08004638 else if (strncmp(command, "WLS_BATCHING", 12) == 0)
Rajeev79dbe4c2013-10-05 11:03:42 +05304639 {
Rajeev Kumar8b373292014-01-08 20:36:55 -08004640 ret = hdd_handle_batch_scan_ioctl(pAdapter, &priv_data, command);
Rajeev79dbe4c2013-10-05 11:03:42 +05304641 }
4642#endif
Abhishek Singh00b71972016-01-07 10:51:04 +05304643#ifdef WLAN_FEATURE_RMC
4644 else if ((strncasecmp(command, "SETIBSSBEACONOUIDATA", 20) == 0) &&
4645 (WLAN_HDD_IBSS == pAdapter->device_mode))
4646 {
4647 int i = 0;
4648 tANI_U8 *ibss_ie;
4649 tANI_U32 command_len;
4650 tANI_U8 *value = command;
4651 tHalHandle hHal = pHddCtx->hHal;
4652 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
4653 tANI_U32 ibss_ie_length;
4654 tANI_U32 len, present;
4655 tANI_U8 *addIE;
4656 tANI_U8 *addIEData;
4657
4658 hddLog(LOG1,
4659 FL(" received command %s"),((char *) value));
4660 /* validate argument of command */
4661 if (strlen(value) <= 21)
4662 {
4663 hddLog(LOGE,
4664 FL("No arguements in command length %zu"), strlen(value));
4665 ret = -EFAULT;
4666 goto exit;
4667 }
4668
4669 /* moving to arguments of commands */
4670 value = value + 21;
4671 command_len = strlen(value);
4672
4673 /* oui_data can't be less than 3 bytes */
4674 if (command_len <= (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH))
4675 {
4676 hddLog(LOGE,
4677 FL("Invalid SETIBSSBEACONOUIDATA command length %d"),
4678 command_len);
4679 ret = -EFAULT;
4680 goto exit;
4681 }
4682 ibss_ie = vos_mem_malloc(command_len);
4683 if (!ibss_ie) {
4684 hddLog(LOGE,
4685 FL("Could not allocate memory for command length %d"),
4686 command_len);
4687 ret = -ENOMEM;
4688 goto exit;
4689 }
4690 vos_mem_zero(ibss_ie, command_len);
4691
4692 ibss_ie_length = hdd_parse_set_ibss_oui_data_command(value, ibss_ie,
4693 command_len);
4694 if (ibss_ie_length < (2 * WLAN_HDD_IBSS_MIN_OUI_DATA_LENGTH)) {
4695 hddLog(LOGE, FL("Could not parse command %s return length %d"),
4696 value, ibss_ie_length);
4697 ret = -EFAULT;
4698 vos_mem_free(ibss_ie);
4699 goto exit;
4700 }
4701
4702 hddLog(LOG1, FL("ibss_ie length %d ibss_ie:"), ibss_ie_length);
4703 while (i < ibss_ie_length)
4704 hddLog(LOG1, FL("0x%x"), ibss_ie[i++]);
4705
4706 /* Populate Vendor IE in Beacon */
4707 if ((ccmCfgGetInt(hHal,
4708 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
4709 &present)) != eHAL_STATUS_SUCCESS)
4710 {
4711 hddLog(LOGE,
4712 FL("unable to ftch WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
4713 ret = -EFAULT;
4714 vos_mem_free(ibss_ie);
4715 goto exit;
4716 }
4717
4718 addIE = vos_mem_malloc(WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
4719 if (!addIE) {
4720 hddLog(LOGE,
4721 FL("Could not allocate memory for command length %d"),
4722 command_len);
4723 vos_mem_free(ibss_ie);
4724 ret = -ENOMEM;
4725 goto exit;
4726 }
4727 vos_mem_zero(addIE, WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN);
4728
4729 if (present)
4730 {
4731 if ((wlan_cfgGetStrLen(pMac,
4732 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, &len)) != eSIR_SUCCESS)
4733 {
4734 hddLog(LOGE,
4735 FL("unable to fetch WNI_CFG_PROBE_RSP_BCN_ADDNIE_LEN"));
4736 ret = -EFAULT;
4737 vos_mem_free(ibss_ie);
4738 vos_mem_free(addIE);
4739 goto exit;
4740 }
4741
4742 if (len <= WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN && len &&
4743 ((len + ibss_ie_length) <=
4744 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA_LEN))
4745 {
4746 if ((ccmCfgGetStr(hHal,
4747 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, &len))
4748 != eHAL_STATUS_SUCCESS)
4749 {
4750 hddLog(LOGE,
4751 FL("unable to fetch WNI_PROBE_RSP_BCN_ADDNIE_DATA"));
4752 ret = -EFAULT;
4753 vos_mem_free(ibss_ie);
4754 vos_mem_free(addIE);
4755 goto exit;
4756 }
4757 else
4758 {
4759 /* Curruntly only WPA IE is added before Vendor IE
4760 * so we can blindly place the Vendor IE after WPA
4761 * IE. If no WPA IE found replace all with Vendor IE.
4762 */
4763 len = hdd_find_ibss_wpa_ie_pos(addIE, len);
4764 }
4765 }
4766 else
4767 {
4768 hddLog(LOGE,
4769 FL("IE len exceed limit len %d,ibss_ie_length %d "),
4770 len, ibss_ie_length);
4771 ret = -EFAULT;
4772 vos_mem_free(addIE);
4773 vos_mem_free(ibss_ie);
4774 goto exit;
4775 }
4776 }
4777 else {
4778 len = 0;
4779 }
4780
4781 vos_mem_copy (addIE + len , ibss_ie, ibss_ie_length);
4782 len += ibss_ie_length;
4783
4784 if (ccmCfgSetStr(hHal,
4785 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, addIE, len, NULL,
4786 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
4787 {
4788 hddLog(LOGE,
4789 FL("unable to set WNI_CFG_PRBE_RSP_BCN_ADDNIE_DATA"));
4790 ret = -EFAULT;
4791 vos_mem_free(ibss_ie);
4792 vos_mem_free(addIE);
4793 goto exit;
4794 }
4795 vos_mem_free(addIE);
4796 if (ccmCfgSetInt(hHal,
4797 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
4798 eANI_BOOLEAN_FALSE) != eHAL_STATUS_SUCCESS)
4799 {
4800 hddLog(LOGE,
4801 FL("unble to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG"));
4802 ret = -EFAULT;
4803 vos_mem_free(ibss_ie);
4804 goto exit;
4805 }
4806
4807 /* Populate Vendor IE in probe resp */
4808 if ((ccmCfgGetInt(hHal,
4809 WNI_CFG_PROBE_RSP_ADDNIE_FLAG,
4810 &present)) != eHAL_STATUS_SUCCESS)
4811 {
4812 hddLog(LOGE,
4813 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
4814 ret = -EFAULT;
4815 vos_mem_free(ibss_ie);
4816 goto exit;
4817 }
4818
4819 addIEData = vos_mem_malloc(WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
4820 if (!addIEData) {
4821 hddLog(LOGE,
4822 FL("Could not allocate memory for command length %d"),
4823 command_len);
4824 vos_mem_free(ibss_ie);
4825 ret = -ENOMEM;
4826 goto exit;
4827 }
4828 vos_mem_zero(addIEData, WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN);
4829
4830 if (present) {
4831 if (eSIR_SUCCESS != wlan_cfgGetStrLen(pMac,
4832 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, &len)) {
4833 hddLog(LOGE,
4834 FL("unable to fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
4835 ret = -EFAULT;
4836 vos_mem_free(ibss_ie);
4837 vos_mem_free(addIEData);
4838 goto exit;
4839 }
4840 if (len < WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN && len &&
4841 (ibss_ie_length + len) <=
4842 WNI_CFG_PROBE_RSP_ADDNIE_DATA1_LEN) {
4843
4844 if ((ccmCfgGetStr(hHal,
4845 WNI_CFG_PROBE_RSP_ADDNIE_DATA1, addIEData, &len))
4846 != eHAL_STATUS_SUCCESS) {
4847 hddLog(LOGE,
4848 FL("unable fetch WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
4849 ret = -EFAULT;
4850 vos_mem_free(ibss_ie);
4851 vos_mem_free(addIEData);
4852 goto exit;
4853 }
4854 else {
4855 /* Curruntly only WPA IE is added before Vendor IE
4856 * so we can blindly place the Vendor IE after WPA
4857 * IE. If no WPA IE found replace all with Vendor IE.
4858 */
4859 len = hdd_find_ibss_wpa_ie_pos(addIEData, len);
4860 }
4861 }
4862 else
4863 {
4864 hddLog(LOGE,
4865 FL("IE len exceed limit len %d,ibss_ie_length %d "),
4866 len, ibss_ie_length);
4867 ret = -EFAULT;
4868 vos_mem_free(addIEData);
4869 vos_mem_free(ibss_ie);
4870 goto exit;
4871 }
4872 } /* probe rsp ADD IE present */
4873 else {
4874 /* probe rsp add IE is not present */
4875 len = 0;
4876 }
4877
4878 vos_mem_copy(addIEData +len , ibss_ie, ibss_ie_length);
4879 len += ibss_ie_length;
4880
4881 vos_mem_free(ibss_ie);
4882
4883 if (ccmCfgSetStr(hHal,
4884 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
4885 (tANI_U8*)(addIEData),
4886 len, NULL,
4887 eANI_BOOLEAN_FALSE)
4888 == eHAL_STATUS_FAILURE) {
4889 hddLog(LOGE,
4890 FL("unable to copy to WNI_CFG_PROBE_RSP_ADDNIE_DATA1"));
4891 ret = -EFAULT;
4892 vos_mem_free(addIEData);
4893 goto exit;
4894 }
4895 vos_mem_free(addIEData);
4896 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
4897 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
4898 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
4899 {
4900 hddLog(LOGE,
4901 FL("unable to copy WNI_CFG_PROBE_RSP_ADDNIE_FLAG"));
4902 ret = -EFAULT;
4903 goto exit;
4904 }
4905 }
4906 else if (strncasecmp(command, "SETRMCENABLE", 12) == 0)
4907 {
4908 tANI_U8 *value = command;
4909 tANI_U8 ucRmcEnable = 0;
4910 int status;
4911
4912 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
4913 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
4914 {
4915 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4916 "Received SETRMCENABLE command in invalid mode %d "
4917 "SETRMCENABLE command is only allowed in IBSS or SOFTAP mode",
4918 pAdapter->device_mode);
4919 ret = -EINVAL;
4920 goto exit;
4921 }
4922
4923 status = hdd_parse_setrmcenable_command(value, &ucRmcEnable);
4924 if (status)
4925 {
4926 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4927 "Invalid SETRMCENABLE command ");
4928 ret = -EINVAL;
4929 goto exit;
4930 }
4931
4932 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4933 "%s: ucRmcEnable %d ", __func__, ucRmcEnable);
4934
4935 if (TRUE == ucRmcEnable)
4936 {
4937 status = sme_EnableRMC( (tHalHandle)(pHddCtx->hHal),
4938 pAdapter->sessionId );
4939 }
4940 else if(FALSE == ucRmcEnable)
4941 {
4942 status = sme_DisableRMC( (tHalHandle)(pHddCtx->hHal),
4943 pAdapter->sessionId );
4944 }
4945 else
4946 {
4947 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4948 "Invalid SETRMCENABLE command %d", ucRmcEnable);
4949 ret = -EINVAL;
4950 goto exit;
4951 }
4952
4953 if (VOS_STATUS_SUCCESS != status)
4954 {
4955 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4956 "%s: SETRMC %d failed status %d", __func__, ucRmcEnable,
4957 status);
4958 ret = -EINVAL;
4959 goto exit;
4960 }
4961 }
4962 else if (strncasecmp(command, "SETRMCACTIONPERIOD", 18) == 0)
4963 {
4964 tANI_U8 *value = command;
4965 tANI_U32 uActionPeriod = 0;
4966 int status;
4967
4968 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
4969 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
4970 {
4971 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4972 "Received SETRMC command in invalid mode %d "
4973 "SETRMC command is only allowed in IBSS or SOFTAP mode",
4974 pAdapter->device_mode);
4975 ret = -EINVAL;
4976 goto exit;
4977 }
4978
4979 status = hdd_parse_setrmcactionperiod_command(value, &uActionPeriod);
4980 if (status)
4981 {
4982 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4983 "Invalid SETRMCACTIONPERIOD command ");
4984 ret = -EINVAL;
4985 goto exit;
4986 }
4987
4988 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4989 "%s: uActionPeriod %d ", __func__, uActionPeriod);
4990
4991 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_RMC_ACTION_PERIOD_FREQUENCY,
4992 uActionPeriod, NULL, eANI_BOOLEAN_FALSE))
4993 {
4994 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4995 "%s: Could not set SETRMCACTIONPERIOD %d", __func__, uActionPeriod);
4996 ret = -EINVAL;
4997 goto exit;
4998 }
4999
5000 }
5001 else if (strncasecmp(command, "GETIBSSPEERINFOALL", 18) == 0)
5002 {
5003 /* Peer Info All Command */
5004 int status = eHAL_STATUS_SUCCESS;
5005 hdd_station_ctx_t *pHddStaCtx = NULL;
5006 char *extra = NULL;
5007 int idx = 0, length = 0;
5008 v_MACADDR_t *macAddr;
5009 v_U32_t txRateMbps = 0, numOfBytestoPrint = 0;
5010
5011 if (WLAN_HDD_IBSS == pAdapter->device_mode)
5012 {
5013 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5014 }
5015 else
5016 {
5017 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5018 "%s: pAdapter is not valid for this device mode",
5019 __func__);
5020 ret = -EINVAL;
5021 goto exit;
5022 }
5023
5024 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5025 "%s: Received GETIBSSPEERINFOALL Command", __func__);
5026
5027
5028 /* Handle the command */
5029 status = hdd_cfg80211_get_ibss_peer_info_all(pAdapter);
5030 if (VOS_STATUS_SUCCESS == status)
5031 {
5032 /* The variable extra needed to be allocated on the heap since
5033 * amount of memory required to copy the data for 32 devices
5034 * exceeds the size of 1024 bytes of default stack size. On
5035 * 64 bit devices, the default max stack size of 2048 bytes
5036 */
5037 extra = kmalloc(WLAN_MAX_BUF_SIZE, GFP_KERNEL);
5038
5039 if (NULL == extra)
5040 {
5041 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5042 "%s:kmalloc failed", __func__);
5043 ret = -EINVAL;
5044 goto exit;
5045 }
5046
5047 /* Copy number of stations */
5048 length = scnprintf( extra, WLAN_MAX_BUF_SIZE, "%d ",
5049 pHddStaCtx->ibss_peer_info.numIBSSPeers);
5050 numOfBytestoPrint = length;
5051 for (idx = 0; idx < pHddStaCtx->ibss_peer_info.numIBSSPeers; idx++)
5052 {
5053 macAddr =
5054 hdd_wlan_get_ibss_mac_addr_from_staid(pAdapter,
5055 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
5056 if (NULL != macAddr)
5057 {
5058 txRateMbps =
5059 ((pHddStaCtx->ibss_peer_info.ibssPeerList[idx].txRate)*500*1000)/1000000;
5060
5061 length += scnprintf( (extra + length), WLAN_MAX_BUF_SIZE - length,
5062 "%02x:%02x:%02x:%02x:%02x:%02x %d %d ",
5063 macAddr->bytes[0], macAddr->bytes[1], macAddr->bytes[2],
5064 macAddr->bytes[3], macAddr->bytes[4], macAddr->bytes[5],
5065 (int)txRateMbps,
5066 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[idx].rssi);
5067 }
5068 else
5069 {
5070 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5071 "%s: MAC ADDR is NULL for staIdx: %d", __func__,
5072 pHddStaCtx->ibss_peer_info.ibssPeerList[idx].staIdx);
5073 }
5074
5075 /*
5076 * VOS_TRACE() macro has limitation of 512 bytes for the print
5077 * buffer. Hence printing the data in two chunks. The first chunk
5078 * will have the data for 16 devices and the second chunk will
5079 * have the rest.
5080 */
5081 if (idx < NUM_OF_STA_DATA_TO_PRINT)
5082 {
5083 numOfBytestoPrint = length;
5084 }
5085 }
5086
5087 /*
5088 * Copy the data back into buffer, if the data to copy is
5089 * morethan 512 bytes than we will split the data and do
5090 * it in two shots
5091 */
5092 if (copy_to_user(priv_data.buf, extra, numOfBytestoPrint))
5093 {
5094 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5095 "%s: Copy into user data buffer failed ", __func__);
5096 ret = -EFAULT;
5097 kfree(extra);
5098 goto exit;
5099 }
5100 priv_data.buf[numOfBytestoPrint] = '\0';
5101 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
5102 "%s", priv_data.buf);
5103
5104 if (length > numOfBytestoPrint)
5105 {
5106 if (copy_to_user(priv_data.buf + numOfBytestoPrint,
5107 extra + numOfBytestoPrint,
5108 length - numOfBytestoPrint + 1))
5109 {
5110 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5111 "%s: Copy into user data buffer failed ", __func__);
5112 ret = -EFAULT;
5113 kfree(extra);
5114 goto exit;
5115 }
5116 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
5117 "%s", &priv_data.buf[numOfBytestoPrint]);
5118 }
5119
5120 /* Free temporary buffer */
5121 kfree(extra);
5122 }
5123
5124 else
5125 {
5126 /* Command failed, log error */
5127 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5128 "%s: GETIBSSPEERINFOALL command failed with status code %d",
5129 __func__, status);
5130 ret = -EINVAL;
5131 goto exit;
5132 }
5133 ret = 0;
5134 }
5135 else if(strncasecmp(command, "GETIBSSPEERINFO", 15) == 0)
5136 {
5137 /* Peer Info <Peer Addr> command */
5138 tANI_U8 *value = command;
5139 VOS_STATUS status;
5140 hdd_station_ctx_t *pHddStaCtx = NULL;
5141 char extra[128] = { 0 };
5142 v_U32_t length = 0;
5143 v_U8_t staIdx = 0;
5144 v_U32_t txRateMbps = 0;
5145 v_MACADDR_t peerMacAddr;
5146
5147 if (WLAN_HDD_IBSS == pAdapter->device_mode)
5148 {
5149 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5150 }
5151 else
5152 {
5153 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5154 "%s: pAdapter is not valid for this device mode",
5155 __func__);
5156 ret = -EINVAL;
5157 goto exit;
5158 }
5159
5160 /* if there are no peers, no need to continue with the command */
5161 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5162 "%s: Received GETIBSSPEERINFO Command", __func__);
5163
5164 if (eConnectionState_IbssConnected != pHddStaCtx->conn_info.connState)
5165 {
5166 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5167 "%s:No IBSS Peers coalesced", __func__);
5168 ret = -EINVAL;
5169 goto exit;
5170 }
5171
5172 /* Parse the incoming command buffer */
5173 status = hdd_parse_get_ibss_peer_info(value, &peerMacAddr);
5174 if (VOS_STATUS_SUCCESS != status)
5175 {
5176 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5177 "%s: Invalid GETIBSSPEERINFO command", __func__);
5178 ret = -EINVAL;
5179 goto exit;
5180 }
5181
5182 /* Get station index for the peer mac address */
5183 hdd_Ibss_GetStaId(pHddStaCtx, &peerMacAddr, &staIdx);
5184
5185 if (staIdx > HDD_MAX_NUM_IBSS_STA)
5186 {
5187 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5188 "%s: Invalid StaIdx %d returned", __func__, staIdx);
5189 ret = -EINVAL;
5190 goto exit;
5191 }
5192
5193 /* Handle the command */
5194 status = hdd_cfg80211_get_ibss_peer_info(pAdapter, staIdx);
5195 if (VOS_STATUS_SUCCESS == status)
5196 {
5197 v_U32_t txRate = pHddStaCtx->ibss_peer_info.ibssPeerList[0].txRate;
5198 txRateMbps = (txRate * 500 * 1000)/1000000;
5199
5200 length = scnprintf( extra, sizeof(extra), "%d %d", (int)txRateMbps,
5201 (int)pHddStaCtx->ibss_peer_info.ibssPeerList[0].rssi);
5202
5203 /* Copy the data back into buffer */
5204 if (copy_to_user(priv_data.buf, &extra, length+ 1))
5205 {
5206 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5207 "%s: copy data to user buffer failed GETIBSSPEERINFO command",
5208 __func__);
5209 ret = -EFAULT;
5210 goto exit;
5211 }
5212 }
5213 else
5214 {
5215 /* Command failed, log error */
5216 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5217 "%s: GETIBSSPEERINFO command failed with status code %d",
5218 __func__, status);
5219 ret = -EINVAL;
5220 goto exit;
5221 }
5222
5223 /* Success ! */
5224 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
5225 "%s", priv_data.buf);
5226 ret = 0;
5227 }
5228 else if (strncasecmp(command, "SETRMCTXRATE", 12) == 0)
5229 {
5230 tANI_U8 *value = command;
5231 tANI_U32 uRate = 0;
5232 tTxrateinfoflags txFlags = 0;
5233 tSirRateUpdateInd *rateUpdateParams;
5234 int status;
5235
5236 if ((WLAN_HDD_IBSS != pAdapter->device_mode) &&
5237 (WLAN_HDD_SOFTAP != pAdapter->device_mode))
5238 {
5239 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5240 "Received SETRMCTXRATE command in invalid mode %d "
5241 "SETRMC command is only allowed in IBSS or SOFTAP mode",
5242 pAdapter->device_mode);
5243 ret = -EINVAL;
5244 goto exit;
5245 }
5246
5247 status = hdd_parse_setrmcrate_command(value, &uRate, &txFlags);
5248 if (status)
5249 {
5250 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5251 "Invalid SETRMCTXRATE command ");
5252 ret = -EINVAL;
5253 goto exit;
5254 }
5255
5256 rateUpdateParams = vos_mem_malloc(sizeof(tSirRateUpdateInd));
5257 if (NULL == rateUpdateParams)
5258 {
5259 ret = -EINVAL;
5260 goto exit;
5261 }
5262
5263 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5264 "%s: uRate %d ", __func__, uRate);
5265
5266 vos_mem_zero(rateUpdateParams, sizeof(tSirRateUpdateInd ));
5267
5268 /* -1 implies ignore this param */
5269 rateUpdateParams->ucastDataRate = -1;
5270
5271 /*
5272 * Fill the user specifieed RMC rate param
5273 * and the derived tx flags.
5274 */
5275 rateUpdateParams->rmcDataRate = uRate;
5276 rateUpdateParams->rmcDataRateTxFlag = txFlags;
5277
5278 status = sme_SendRateUpdateInd((tHalHandle)(pHddCtx->hHal), rateUpdateParams);
5279 }
5280 else if (strncasecmp(command, "SETIBSSTXFAILEVENT", 18) == 0 )
5281 {
5282 char *value;
5283 tANI_U8 tx_fail_count = 0;
5284 tANI_U16 pid = 0;
5285
5286 value = command;
5287
5288 ret = hdd_ParseIBSSTXFailEventParams(value, &tx_fail_count, &pid);
5289
5290 if (0 != ret)
5291 {
5292 hddLog(VOS_TRACE_LEVEL_INFO,
5293 "%s: Failed to parse SETIBSSTXFAILEVENT arguments",
5294 __func__);
5295 goto exit;
5296 }
5297
5298 hddLog(VOS_TRACE_LEVEL_INFO, "%s: tx_fail_cnt=%hhu, pid=%hu",
5299 __func__, tx_fail_count, pid);
5300
5301 if (0 == tx_fail_count)
5302 {
5303 // Disable TX Fail Indication
5304 if (eHAL_STATUS_SUCCESS ==
5305 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
5306 tx_fail_count,
5307 NULL))
5308 {
5309 cesium_pid = 0;
5310 }
5311 else
5312 {
5313 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5314 "%s: failed to disable TX Fail Event ", __func__);
5315 ret = -EINVAL;
5316 }
5317 }
5318 else
5319 {
5320 if (eHAL_STATUS_SUCCESS ==
5321 sme_TXFailMonitorStartStopInd(pHddCtx->hHal,
5322 tx_fail_count,
5323 (void*)hdd_tx_fail_ind_callback))
5324 {
5325 cesium_pid = pid;
5326 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5327 "%s: Registered Cesium pid %u", __func__,
5328 cesium_pid);
5329 }
5330 else
5331 {
5332 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5333 "%s: Failed to enable TX Fail Monitoring", __func__);
5334 ret = -EINVAL;
5335 }
5336 }
5337 }
5338
5339#endif /* WLAN_FEATURE_RMC */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005340#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005341 else if (strncmp(command, "SETCCXROAMSCANCHANNELS", 22) == 0)
5342 {
5343 tANI_U8 *value = command;
5344 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
5345 tANI_U8 numChannels = 0;
5346 eHalStatus status = eHAL_STATUS_SUCCESS;
5347
5348 status = hdd_parse_channellist(value, ChannelList, &numChannels);
5349 if (eHAL_STATUS_SUCCESS != status)
5350 {
5351 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5352 "%s: Failed to parse channel list information", __func__);
5353 ret = -EINVAL;
5354 goto exit;
5355 }
5356
5357 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
5358 {
5359 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5360 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
5361 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
5362 ret = -EINVAL;
5363 goto exit;
5364 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005365 status = sme_SetEseRoamScanChannelList((tHalHandle)(pHddCtx->hHal),
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005366 ChannelList,
5367 numChannels);
5368 if (eHAL_STATUS_SUCCESS != status)
5369 {
5370 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5371 "%s: Failed to update channel list information", __func__);
5372 ret = -EINVAL;
5373 goto exit;
5374 }
5375 }
5376 else if (strncmp(command, "GETTSMSTATS", 11) == 0)
5377 {
5378 tANI_U8 *value = command;
5379 char extra[128] = {0};
5380 int len = 0;
5381 tANI_U8 tid = 0;
5382 hdd_station_ctx_t *pHddStaCtx = NULL;
5383 tAniTrafStrmMetrics tsmMetrics;
5384 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5385
5386 /* if not associated, return error */
5387 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
5388 {
5389 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:Not associated!",__func__);
5390 ret = -EINVAL;
5391 goto exit;
5392 }
5393
5394 /* Move pointer to ahead of GETTSMSTATS<delimiter> */
5395 value = value + 12;
5396 /* Convert the value from ascii to integer */
5397 ret = kstrtou8(value, 10, &tid);
5398 if (ret < 0)
5399 {
5400 /* If the input value is greater than max value of datatype, then also
5401 kstrtou8 fails */
5402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5403 "%s: kstrtou8 failed range [%d - %d]", __func__,
5404 TID_MIN_VALUE,
5405 TID_MAX_VALUE);
5406 ret = -EINVAL;
5407 goto exit;
5408 }
5409
5410 if ((tid < TID_MIN_VALUE) || (tid > TID_MAX_VALUE))
5411 {
5412 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5413 "tid value %d is out of range"
5414 " (Min: %d Max: %d)", tid,
5415 TID_MIN_VALUE,
5416 TID_MAX_VALUE);
5417 ret = -EINVAL;
5418 goto exit;
5419 }
5420
5421 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5422 "%s: Received Command to get tsm stats tid = %d", __func__, tid);
5423
5424 if (VOS_STATUS_SUCCESS != hdd_get_tsm_stats(pAdapter, tid, &tsmMetrics))
5425 {
5426 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5427 "%s: failed to get tsm stats", __func__);
5428 ret = -EFAULT;
5429 goto exit;
5430 }
5431
5432 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5433 "UplinkPktQueueDly(%d)\n"
5434 "UplinkPktQueueDlyHist[0](%d)\n"
5435 "UplinkPktQueueDlyHist[1](%d)\n"
5436 "UplinkPktQueueDlyHist[2](%d)\n"
5437 "UplinkPktQueueDlyHist[3](%d)\n"
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05305438 "UplinkPktTxDly(%u)\n"
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005439 "UplinkPktLoss(%d)\n"
5440 "UplinkPktCount(%d)\n"
5441 "RoamingCount(%d)\n"
5442 "RoamingDly(%d)", tsmMetrics.UplinkPktQueueDly,
5443 tsmMetrics.UplinkPktQueueDlyHist[0],
5444 tsmMetrics.UplinkPktQueueDlyHist[1],
5445 tsmMetrics.UplinkPktQueueDlyHist[2],
5446 tsmMetrics.UplinkPktQueueDlyHist[3],
5447 tsmMetrics.UplinkPktTxDly, tsmMetrics.UplinkPktLoss,
5448 tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount, tsmMetrics.RoamingDly);
5449
5450 /* Output TSM stats is of the format
5451 GETTSMSTATS [PktQueueDly] [PktQueueDlyHist[0]]:[PktQueueDlyHist[1]] ...[RoamingDly]
5452 eg., GETTSMSTATS 10 1:0:0:161 20 1 17 8 39800 */
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005453 len = scnprintf(extra, sizeof(extra), "%s %d %d:%d:%d:%d %u %d %d %d %d", command,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005454 tsmMetrics.UplinkPktQueueDly, tsmMetrics.UplinkPktQueueDlyHist[0],
5455 tsmMetrics.UplinkPktQueueDlyHist[1], tsmMetrics.UplinkPktQueueDlyHist[2],
5456 tsmMetrics.UplinkPktQueueDlyHist[3], tsmMetrics.UplinkPktTxDly,
5457 tsmMetrics.UplinkPktLoss, tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount,
5458 tsmMetrics.RoamingDly);
5459
Ratnam Rachurid53009c2015-08-07 13:59:00 +05305460 len = VOS_MIN(priv_data.total_len, len + 1);
5461 if (copy_to_user(priv_data.buf, &extra, len)) {
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005462 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5463 "%s: failed to copy data to user buffer", __func__);
5464 ret = -EFAULT;
5465 goto exit;
5466 }
5467 }
5468 else if (strncmp(command, "SETCCKMIE", 9) == 0)
5469 {
5470 tANI_U8 *value = command;
5471 tANI_U8 *cckmIe = NULL;
5472 tANI_U8 cckmIeLen = 0;
5473 eHalStatus status = eHAL_STATUS_SUCCESS;
5474
5475 status = hdd_parse_get_cckm_ie(value, &cckmIe, &cckmIeLen);
5476 if (eHAL_STATUS_SUCCESS != status)
5477 {
5478 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5479 "%s: Failed to parse cckm ie data", __func__);
5480 ret = -EINVAL;
5481 goto exit;
5482 }
5483
5484 if (cckmIeLen > DOT11F_IE_RSN_MAX_LEN)
5485 {
5486 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5487 "%s: CCKM Ie input length is more than max[%d]", __func__,
5488 DOT11F_IE_RSN_MAX_LEN);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08005489 vos_mem_free(cckmIe);
5490 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005491 ret = -EINVAL;
5492 goto exit;
5493 }
5494 sme_SetCCKMIe((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, cckmIe, cckmIeLen);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08005495 vos_mem_free(cckmIe);
5496 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005497 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005498 else if (strncmp(command, "CCXBEACONREQ", 12) == 0)
5499 {
5500 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005501 tCsrEseBeaconReq eseBcnReq;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005502 eHalStatus status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07005503
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005504 status = hdd_parse_ese_beacon_req(value, &eseBcnReq);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005505 if (eHAL_STATUS_SUCCESS != status)
5506 {
5507 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005508 "%s: Failed to parse ese beacon req", __func__);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005509 ret = -EINVAL;
5510 goto exit;
5511 }
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07005512 if (!hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))) {
5513 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not associated"));
5514 hdd_indicateEseBcnReportNoResults (pAdapter,
5515 eseBcnReq.bcnReq[0].measurementToken,
5516 0x02, //BIT(1) set for measurement done
5517 0); // no BSS
5518 goto exit;
5519 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005520
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005521 status = sme_SetEseBeaconRequest((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, &eseBcnReq);
5522 if (eHAL_STATUS_SUCCESS != status)
5523 {
5524 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5525 "%s: sme_SetEseBeaconRequest failed (%d)", __func__, status);
5526 ret = -EINVAL;
5527 goto exit;
5528 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005529 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005530#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
c_hpothu92367912014-05-01 15:18:17 +05305531 else if (strncmp(command, "GETBCNMISSRATE", 14) == 0)
5532 {
5533 eHalStatus status;
5534 char buf[32], len;
5535 long waitRet;
5536 bcnMissRateContext_t getBcnMissRateCtx;
5537
5538 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5539
5540 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
5541 {
5542 hddLog(VOS_TRACE_LEVEL_WARN,
5543 FL("GETBCNMISSRATE: STA is not in connected state"));
5544 ret = -1;
5545 goto exit;
5546 }
5547
5548 init_completion(&(getBcnMissRateCtx.completion));
5549 getBcnMissRateCtx.magic = BCN_MISS_RATE_CONTEXT_MAGIC;
5550
5551 status = sme_getBcnMissRate((tHalHandle)(pHddCtx->hHal),
5552 pAdapter->sessionId,
5553 (void *)getBcnMissRateCB,
5554 (void *)(&getBcnMissRateCtx));
5555 if( eHAL_STATUS_SUCCESS != status)
5556 {
5557 hddLog(VOS_TRACE_LEVEL_INFO,
5558 FL("GETBCNMISSRATE: fail to post WDA cmd"));
5559 ret = -EINVAL;
5560 goto exit;
5561 }
5562
5563 waitRet = wait_for_completion_interruptible_timeout
5564 (&getBcnMissRateCtx.completion, BCN_MISS_RATE_TIME);
5565 if(waitRet <= 0)
5566 {
5567 hddLog(VOS_TRACE_LEVEL_ERROR,
5568 FL("failed to wait on bcnMissRateComp %d"), ret);
5569
5570 //Make magic number to zero so that callback is not called.
5571 spin_lock(&hdd_context_lock);
5572 getBcnMissRateCtx.magic = 0x0;
5573 spin_unlock(&hdd_context_lock);
5574 ret = -EINVAL;
5575 goto exit;
5576 }
5577
5578 hddLog(VOS_TRACE_LEVEL_INFO,
5579 FL("GETBCNMISSRATE: bcnMissRate: %d"), gbcnMissRate);
5580
5581 len = snprintf(buf, sizeof(buf), "GETBCNMISSRATE %d", gbcnMissRate);
5582 if (copy_to_user(priv_data.buf, &buf, len + 1))
5583 {
5584 hddLog(VOS_TRACE_LEVEL_ERROR,
5585 "%s: failed to copy data to user buffer", __func__);
5586 ret = -EFAULT;
5587 goto exit;
5588 }
5589 ret = len;
5590 }
Atul Mittal87ec2422014-09-24 13:12:50 +05305591#ifdef FEATURE_WLAN_TDLS
5592 else if (strncmp(command, "TDLSSECONDARYCHANNELOFFSET", 26) == 0) {
5593 tANI_U8 *value = command;
5594 int set_value;
5595 /* Move pointer to ahead of TDLSOFFCH*/
5596 value += 26;
c_manjeebbc40212015-12-08 13:52:59 +05305597 if (!(sscanf(value, "%d", &set_value))) {
5598 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5599 FL("No input identified"));
5600 ret = -EINVAL;
5601 goto exit;
5602 }
5603
Atul Mittal87ec2422014-09-24 13:12:50 +05305604 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5605 "%s: Tdls offchannel offset:%d",
5606 __func__, set_value);
5607 ret = iw_set_tdlssecoffchanneloffset(pHddCtx, set_value);
5608 if (ret < 0)
5609 {
5610 ret = -EINVAL;
5611 goto exit;
5612 }
5613
5614 } else if (strncmp(command, "TDLSOFFCHANNELMODE", 18) == 0) {
5615 tANI_U8 *value = command;
5616 int set_value;
5617 /* Move pointer to ahead of tdlsoffchnmode*/
5618 value += 18;
c_manjee82323892015-12-08 12:40:34 +05305619 ret = sscanf(value, "%d", &set_value);
5620 if (ret != 1) {
5621 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5622 FL("No input identified"));
5623 ret = -EINVAL;
5624 goto exit;
5625 }
Atul Mittal87ec2422014-09-24 13:12:50 +05305626 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5627 "%s: Tdls offchannel mode:%d",
5628 __func__, set_value);
5629 ret = iw_set_tdlsoffchannelmode(pAdapter, set_value);
5630 if (ret < 0)
5631 {
5632 ret = -EINVAL;
5633 goto exit;
5634 }
5635 } else if (strncmp(command, "TDLSOFFCHANNEL", 14) == 0) {
5636 tANI_U8 *value = command;
5637 int set_value;
5638 /* Move pointer to ahead of TDLSOFFCH*/
5639 value += 14;
c_manjeef6ccaf52015-12-08 11:52:11 +05305640 ret = sscanf(value, "%d", &set_value);
5641 if (ret != 1) {
5642 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5643 "Wrong value is given for hdd_set_tdls_offchannel");
5644 ret = -EINVAL;
5645 goto exit;
5646 }
5647
Atul Mittal87ec2422014-09-24 13:12:50 +05305648 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5649 "%s: Tdls offchannel num: %d",
5650 __func__, set_value);
5651 ret = iw_set_tdlsoffchannel(pHddCtx, set_value);
5652 if (ret < 0)
5653 {
5654 ret = -EINVAL;
5655 goto exit;
5656 }
5657 }
5658#endif
Satyanarayana Dash72806012014-12-02 14:30:08 +05305659 else if (strncmp(command, "GETFWSTATS", 10) == 0)
5660 {
5661 eHalStatus status;
5662 char *buf = NULL;
5663 char len;
5664 long waitRet;
5665 fwStatsContext_t fwStatsCtx;
Abhishek Singh08aa7762014-12-16 13:59:03 +05305666 tSirFwStatsResult *fwStatsRsp = &(pAdapter->fwStatsRsp);
Satyanarayana Dash72806012014-12-02 14:30:08 +05305667 tANI_U8 *ptr = command;
5668 int stats = *(ptr + 11) - '0';
5669
5670 hddLog(VOS_TRACE_LEVEL_INFO, FL("stats = %d "),stats);
5671 if (!IS_FEATURE_FW_STATS_ENABLE)
5672 {
5673 hddLog(VOS_TRACE_LEVEL_INFO,
5674 FL("Get Firmware stats feature not supported"));
5675 ret = -EINVAL;
5676 goto exit;
5677 }
5678
5679 if (FW_STATS_MAX <= stats || 0 >= stats)
5680 {
5681 hddLog(VOS_TRACE_LEVEL_INFO,
5682 FL(" stats %d not supported"),stats);
5683 ret = -EINVAL;
5684 goto exit;
5685 }
5686
5687 init_completion(&(fwStatsCtx.completion));
5688 fwStatsCtx.magic = FW_STATS_CONTEXT_MAGIC;
5689 fwStatsCtx.pAdapter = pAdapter;
5690 fwStatsRsp->type = 0;
5691 status = sme_GetFwStats( (tHalHandle)pHddCtx->hHal, stats,
Abhishek Singh08aa7762014-12-16 13:59:03 +05305692 &fwStatsCtx, hdd_FWStatisCB);
Satyanarayana Dash72806012014-12-02 14:30:08 +05305693 if (eHAL_STATUS_SUCCESS != status)
5694 {
5695 hddLog(VOS_TRACE_LEVEL_ERROR,
5696 FL(" fail to post WDA cmd status = %d"), status);
5697 ret = -EINVAL;
5698 goto exit;
5699 }
5700 waitRet = wait_for_completion_timeout
5701 (&(fwStatsCtx.completion), FW_STATE_WAIT_TIME);
5702 if (waitRet <= 0)
5703 {
5704 hddLog(VOS_TRACE_LEVEL_ERROR,
5705 FL("failed to wait on GwtFwstats"));
5706 //Make magic number to zero so that callback is not executed.
5707 spin_lock(&hdd_context_lock);
5708 fwStatsCtx.magic = 0x0;
5709 spin_unlock(&hdd_context_lock);
5710 ret = -EINVAL;
5711 goto exit;
5712 }
5713 if (fwStatsRsp->type)
5714 {
5715 buf = kmalloc(FW_STATE_RSP_LEN, GFP_KERNEL);
5716 if (!buf)
5717 {
5718 hddLog(VOS_TRACE_LEVEL_ERROR,
5719 FL(" failed to allocate memory"));
5720 ret = -ENOMEM;
5721 goto exit;
5722 }
5723 switch( fwStatsRsp->type )
5724 {
5725 case FW_UBSP_STATS:
5726 {
5727 len = snprintf(buf, FW_STATE_RSP_LEN,
5728 "GETFWSTATS: ubsp_enter_cnt %d ubsp_jump_ddr_cnt %d",
Abhishek Singh08aa7762014-12-16 13:59:03 +05305729 fwStatsRsp->fwStatsData.ubspStats.ubsp_enter_cnt,
5730 fwStatsRsp->fwStatsData.ubspStats.ubsp_jump_ddr_cnt);
Satyanarayana Dash72806012014-12-02 14:30:08 +05305731 }
5732 break;
5733 default:
5734 {
5735 hddLog(VOS_TRACE_LEVEL_ERROR, FL( "No handling for stats type %d"),fwStatsRsp->type);
5736 ret = -EFAULT;
5737 kfree(buf);
5738 goto exit;
5739 }
5740 }
5741 if (copy_to_user(priv_data.buf, buf, len + 1))
5742 {
5743 hddLog(VOS_TRACE_LEVEL_ERROR,
5744 FL(" failed to copy data to user buffer"));
5745 ret = -EFAULT;
5746 kfree(buf);
5747 goto exit;
5748 }
5749 ret = len;
5750 kfree(buf);
5751 }
5752 else
5753 {
5754 hddLog(VOS_TRACE_LEVEL_ERROR,
5755 FL("failed to fetch the stats"));
5756 ret = -EFAULT;
5757 goto exit;
5758 }
5759
5760 }
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05305761 else if (strncasecmp(command, "SET_FCC_CHANNEL", 15) == 0)
5762 {
5763 /*
5764 * this command wld be called by user-space when it detects WLAN
5765 * ON after airplane mode is set. When APM is set, WLAN turns off.
5766 * But it can be turned back on. Otherwise; when APM is turned back
5767 * off, WLAN wld turn back on. So at that point the command is
5768 * expected to come down. 0 means disable, 1 means enable. The
5769 * constraint is removed when parameter 1 is set or different
5770 * country code is set
5771 */
5772 ret = hdd_cmd_setFccChannel(pHddCtx, command, 15);
5773 }
Mahesh A Saptasagarbeca12c2015-09-07 16:21:06 +05305774 else if (strncasecmp(command, "DISABLE_CA_EVENT", 16) == 0)
5775 {
5776 ret = hdd_enable_disable_ca_event(pHddCtx, command, 16);
5777 }
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07005778 else {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05305779 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
5780 TRACE_CODE_HDD_UNSUPPORTED_IOCTL,
5781 pAdapter->sessionId, 0));
Satyanarayana Dash72806012014-12-02 14:30:08 +05305782 hddLog( VOS_TRACE_LEVEL_WARN, FL("Unsupported GUI command %s"),
5783 command);
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07005784 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005785 }
5786exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05305787 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005788 if (command)
5789 {
5790 kfree(command);
5791 }
5792 return ret;
5793}
5794
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07005795#ifdef CONFIG_COMPAT
5796static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
5797{
5798 struct {
5799 compat_uptr_t buf;
5800 int used_len;
5801 int total_len;
5802 } compat_priv_data;
5803 hdd_priv_data_t priv_data;
5804 int ret = 0;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005805
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07005806 /*
5807 * Note that pAdapter and ifr have already been verified by caller,
5808 * and HDD context has also been validated
5809 */
5810 if (copy_from_user(&compat_priv_data, ifr->ifr_data,
5811 sizeof(compat_priv_data))) {
5812 ret = -EFAULT;
5813 goto exit;
5814 }
5815 priv_data.buf = compat_ptr(compat_priv_data.buf);
5816 priv_data.used_len = compat_priv_data.used_len;
5817 priv_data.total_len = compat_priv_data.total_len;
5818 ret = hdd_driver_command(pAdapter, &priv_data);
5819 exit:
5820 return ret;
5821}
5822#else /* CONFIG_COMPAT */
5823static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
5824{
5825 /* will never be invoked */
5826 return 0;
5827}
5828#endif /* CONFIG_COMPAT */
5829
5830static int hdd_driver_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
5831{
5832 hdd_priv_data_t priv_data;
5833 int ret = 0;
5834
5835 /*
5836 * Note that pAdapter and ifr have already been verified by caller,
5837 * and HDD context has also been validated
5838 */
5839 if (copy_from_user(&priv_data, ifr->ifr_data, sizeof(priv_data))) {
5840 ret = -EFAULT;
5841 } else {
5842 ret = hdd_driver_command(pAdapter, &priv_data);
5843 }
5844 return ret;
5845}
5846
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305847int __hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07005848{
5849 hdd_adapter_t *pAdapter;
5850 hdd_context_t *pHddCtx;
5851 int ret;
5852
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05305853 ENTER();
5854
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07005855 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
5856 if (NULL == pAdapter) {
5857 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
5858 "%s: HDD adapter context is Null", __func__);
5859 ret = -ENODEV;
5860 goto exit;
5861 }
5862 if (dev != pAdapter->dev) {
5863 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
5864 "%s: HDD adapter/dev inconsistency", __func__);
5865 ret = -ENODEV;
5866 goto exit;
5867 }
5868
5869 if ((!ifr) || (!ifr->ifr_data)) {
5870 ret = -EINVAL;
5871 goto exit;
5872 }
5873
5874 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5875 ret = wlan_hdd_validate_context(pHddCtx);
5876 if (ret) {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07005877 ret = -EBUSY;
5878 goto exit;
5879 }
5880
5881 switch (cmd) {
5882 case (SIOCDEVPRIVATE + 1):
5883 if (is_compat_task())
5884 ret = hdd_driver_compat_ioctl(pAdapter, ifr);
5885 else
5886 ret = hdd_driver_ioctl(pAdapter, ifr);
5887 break;
5888 default:
5889 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unknown ioctl %d",
5890 __func__, cmd);
5891 ret = -EINVAL;
5892 break;
5893 }
5894 exit:
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05305895 EXIT();
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07005896 return ret;
5897}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005898
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305899int hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
5900{
5901 int ret;
5902
5903 vos_ssr_protect(__func__);
5904 ret = __hdd_ioctl(dev, ifr, cmd);
5905 vos_ssr_unprotect(__func__);
5906
5907 return ret;
5908}
5909
Katya Nigame7b69a82015-04-28 15:24:06 +05305910int hdd_mon_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
5911{
5912 return 0;
5913}
5914
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005915#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005916/**---------------------------------------------------------------------------
5917
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005918 \brief hdd_parse_ese_beacon_req() - Parse ese beacon request
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005919
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005920 This function parses the ese beacon request passed in the format
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005921 CCXBEACONREQ<space><Number of fields><space><Measurement token>
5922 <space>Channel 1<space>Scan Mode <space>Meas Duration<space>Channel N
5923 <space>Scan Mode N<space>Meas Duration N
5924 if the Number of bcn req fields (N) does not match with the actual number of fields passed
5925 then take N.
5926 <Meas Token><Channel><Scan Mode> and <Meas Duration> are treated as one pair
5927 For example, CCXBEACONREQ 2 1 1 1 30 2 44 0 40.
5928 This function does not take care of removing duplicate channels from the list
5929
5930 \param - pValue Pointer to data
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005931 \param - pEseBcnReq output pointer to store parsed ie information
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005932
5933 \return - 0 for success non-zero for failure
5934
5935 --------------------------------------------------------------------------*/
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005936static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
5937 tCsrEseBeaconReq *pEseBcnReq)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005938{
5939 tANI_U8 *inPtr = pValue;
5940 int tempInt = 0;
5941 int j = 0, i = 0, v = 0;
5942 char buf[32];
5943
5944 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
5945 /*no argument after the command*/
5946 if (NULL == inPtr)
5947 {
5948 return -EINVAL;
5949 }
5950 /*no space after the command*/
5951 else if (SPACE_ASCII_VALUE != *inPtr)
5952 {
5953 return -EINVAL;
5954 }
5955
5956 /*removing empty spaces*/
5957 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
5958
5959 /*no argument followed by spaces*/
5960 if ('\0' == *inPtr) return -EINVAL;
5961
5962 /*getting the first argument ie measurement token*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08005963 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005964 if (1 != v) return -EINVAL;
5965
5966 v = kstrtos32(buf, 10, &tempInt);
5967 if ( v < 0) return -EINVAL;
5968
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005969 pEseBcnReq->numBcnReqIe = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005970
5971 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005972 "Number of Bcn Req Ie fields(%d)", pEseBcnReq->numBcnReqIe);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005973
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005974 for (j = 0; j < (pEseBcnReq->numBcnReqIe); j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005975 {
5976 for (i = 0; i < 4; i++)
5977 {
5978 /*inPtr pointing to the beginning of first space after number of ie fields*/
5979 inPtr = strpbrk( inPtr, " " );
5980 /*no ie data after the number of ie fields argument*/
5981 if (NULL == inPtr) return -EINVAL;
5982
5983 /*removing empty space*/
5984 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
5985
5986 /*no ie data after the number of ie fields argument and spaces*/
5987 if ( '\0' == *inPtr ) return -EINVAL;
5988
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08005989 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08005990 if (1 != v) return -EINVAL;
5991
5992 v = kstrtos32(buf, 10, &tempInt);
5993 if (v < 0) return -EINVAL;
5994
5995 switch (i)
5996 {
5997 case 0: /* Measurement token */
5998 if (tempInt <= 0)
5999 {
6000 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6001 "Invalid Measurement Token(%d)", tempInt);
6002 return -EINVAL;
6003 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006004 pEseBcnReq->bcnReq[j].measurementToken = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006005 break;
6006
6007 case 1: /* Channel number */
6008 if ((tempInt <= 0) ||
6009 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
6010 {
6011 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6012 "Invalid Channel Number(%d)", tempInt);
6013 return -EINVAL;
6014 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006015 pEseBcnReq->bcnReq[j].channel = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006016 break;
6017
6018 case 2: /* Scan mode */
Varun Reddy Yeturu0b18d5a2013-12-04 11:42:23 -08006019 if ((tempInt < eSIR_PASSIVE_SCAN) || (tempInt > eSIR_BEACON_TABLE))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006020 {
6021 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6022 "Invalid Scan Mode(%d) Expected{0|1|2}", tempInt);
6023 return -EINVAL;
6024 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006025 pEseBcnReq->bcnReq[j].scanMode= tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006026 break;
6027
6028 case 3: /* Measurement duration */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006029 if (((tempInt <= 0) && (pEseBcnReq->bcnReq[j].scanMode != eSIR_BEACON_TABLE)) ||
6030 ((tempInt < 0) && (pEseBcnReq->bcnReq[j].scanMode == eSIR_BEACON_TABLE)))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006031 {
6032 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6033 "Invalid Measurement Duration(%d)", tempInt);
6034 return -EINVAL;
6035 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006036 pEseBcnReq->bcnReq[j].measurementDuration = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006037 break;
6038 }
6039 }
6040 }
6041
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006042 for (j = 0; j < pEseBcnReq->numBcnReqIe; j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006043 {
6044 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05306045 "Index(%d) Measurement Token(%u)Channel(%u) Scan Mode(%u) Measurement Duration(%u)\n",
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006046 j,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006047 pEseBcnReq->bcnReq[j].measurementToken,
6048 pEseBcnReq->bcnReq[j].channel,
6049 pEseBcnReq->bcnReq[j].scanMode,
6050 pEseBcnReq->bcnReq[j].measurementDuration);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08006051 }
6052
6053 return VOS_STATUS_SUCCESS;
6054}
6055
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006056static void hdd_GetTsmStatsCB( tAniTrafStrmMetrics tsmMetrics, const tANI_U32 staId, void *pContext )
6057{
6058 struct statsContext *pStatsContext = NULL;
6059 hdd_adapter_t *pAdapter = NULL;
6060
6061 if (NULL == pContext)
6062 {
6063 hddLog(VOS_TRACE_LEVEL_ERROR,
6064 "%s: Bad param, pContext [%p]",
6065 __func__, pContext);
6066 return;
6067 }
6068
Jeff Johnson72a40512013-12-19 10:14:15 -08006069 /* there is a race condition that exists between this callback
6070 function and the caller since the caller could time out either
6071 before or while this code is executing. we use a spinlock to
6072 serialize these actions */
6073 spin_lock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006074
6075 pStatsContext = pContext;
6076 pAdapter = pStatsContext->pAdapter;
6077 if ((NULL == pAdapter) || (STATS_CONTEXT_MAGIC != pStatsContext->magic))
6078 {
6079 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -08006080 spin_unlock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006081 hddLog(VOS_TRACE_LEVEL_WARN,
6082 "%s: Invalid context, pAdapter [%p] magic [%08x]",
6083 __func__, pAdapter, pStatsContext->magic);
6084 return;
6085 }
6086
Jeff Johnson72a40512013-12-19 10:14:15 -08006087 /* context is valid so caller is still waiting */
6088
6089 /* paranoia: invalidate the magic */
6090 pStatsContext->magic = 0;
6091
6092 /* copy over the tsm stats */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006093 pAdapter->tsmStats.UplinkPktQueueDly = tsmMetrics.UplinkPktQueueDly;
6094 vos_mem_copy(pAdapter->tsmStats.UplinkPktQueueDlyHist,
6095 tsmMetrics.UplinkPktQueueDlyHist,
6096 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist)/
6097 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist[0]));
6098 pAdapter->tsmStats.UplinkPktTxDly = tsmMetrics.UplinkPktTxDly;
6099 pAdapter->tsmStats.UplinkPktLoss = tsmMetrics.UplinkPktLoss;
6100 pAdapter->tsmStats.UplinkPktCount = tsmMetrics.UplinkPktCount;
6101 pAdapter->tsmStats.RoamingCount = tsmMetrics.RoamingCount;
6102 pAdapter->tsmStats.RoamingDly = tsmMetrics.RoamingDly;
6103
Jeff Johnson72a40512013-12-19 10:14:15 -08006104 /* notify the caller */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006105 complete(&pStatsContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -08006106
6107 /* serialization is complete */
6108 spin_unlock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006109}
6110
6111
6112
6113static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
6114 tAniTrafStrmMetrics* pTsmMetrics)
6115{
6116 hdd_station_ctx_t *pHddStaCtx = NULL;
6117 eHalStatus hstatus;
Jeff Johnson72a40512013-12-19 10:14:15 -08006118 VOS_STATUS vstatus = VOS_STATUS_SUCCESS;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006119 long lrc;
6120 struct statsContext context;
6121 hdd_context_t *pHddCtx = NULL;
6122
6123 if (NULL == pAdapter)
6124 {
6125 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL", __func__);
6126 return VOS_STATUS_E_FAULT;
6127 }
6128
6129 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6130 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6131
6132 /* we are connected prepare our callback context */
6133 init_completion(&context.completion);
6134 context.pAdapter = pAdapter;
6135 context.magic = STATS_CONTEXT_MAGIC;
6136
6137 /* query tsm stats */
6138 hstatus = sme_GetTsmStats(pHddCtx->hHal, hdd_GetTsmStatsCB,
6139 pHddStaCtx->conn_info.staId[ 0 ],
6140 pHddStaCtx->conn_info.bssId,
6141 &context, pHddCtx->pvosContext, tid);
6142
6143 if (eHAL_STATUS_SUCCESS != hstatus)
6144 {
Jeff Johnson72a40512013-12-19 10:14:15 -08006145 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unable to retrieve statistics",
6146 __func__);
6147 vstatus = VOS_STATUS_E_FAULT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006148 }
6149 else
6150 {
6151 /* request was sent -- wait for the response */
6152 lrc = wait_for_completion_interruptible_timeout(&context.completion,
6153 msecs_to_jiffies(WLAN_WAIT_TIME_STATS));
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006154 if (lrc <= 0)
6155 {
6156 hddLog(VOS_TRACE_LEVEL_ERROR,
6157 "%s: SME %s while retrieving statistics",
6158 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson72a40512013-12-19 10:14:15 -08006159 vstatus = VOS_STATUS_E_TIMEOUT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006160 }
6161 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006162
Jeff Johnson72a40512013-12-19 10:14:15 -08006163 /* either we never sent a request, we sent a request and received a
6164 response or we sent a request and timed out. if we never sent a
6165 request or if we sent a request and got a response, we want to
6166 clear the magic out of paranoia. if we timed out there is a
6167 race condition such that the callback function could be
6168 executing at the same time we are. of primary concern is if the
6169 callback function had already verified the "magic" but had not
6170 yet set the completion variable when a timeout occurred. we
6171 serialize these activities by invalidating the magic while
6172 holding a shared spinlock which will cause us to block if the
6173 callback is currently executing */
6174 spin_lock(&hdd_context_lock);
6175 context.magic = 0;
6176 spin_unlock(&hdd_context_lock);
6177
6178 if (VOS_STATUS_SUCCESS == vstatus)
6179 {
6180 pTsmMetrics->UplinkPktQueueDly = pAdapter->tsmStats.UplinkPktQueueDly;
6181 vos_mem_copy(pTsmMetrics->UplinkPktQueueDlyHist,
6182 pAdapter->tsmStats.UplinkPktQueueDlyHist,
6183 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist)/
6184 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist[0]));
6185 pTsmMetrics->UplinkPktTxDly = pAdapter->tsmStats.UplinkPktTxDly;
6186 pTsmMetrics->UplinkPktLoss = pAdapter->tsmStats.UplinkPktLoss;
6187 pTsmMetrics->UplinkPktCount = pAdapter->tsmStats.UplinkPktCount;
6188 pTsmMetrics->RoamingCount = pAdapter->tsmStats.RoamingCount;
6189 pTsmMetrics->RoamingDly = pAdapter->tsmStats.RoamingDly;
6190 }
6191 return vstatus;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006192}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006193#endif /*FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006194
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006195#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08006196void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand)
6197{
6198 eCsrBand band = -1;
6199 sme_GetFreqBand((tHalHandle)(pHddCtx->hHal), &band);
6200 switch (band)
6201 {
6202 case eCSR_BAND_ALL:
6203 *pBand = WLAN_HDD_UI_BAND_AUTO;
6204 break;
6205
6206 case eCSR_BAND_24:
6207 *pBand = WLAN_HDD_UI_BAND_2_4_GHZ;
6208 break;
6209
6210 case eCSR_BAND_5G:
6211 *pBand = WLAN_HDD_UI_BAND_5_GHZ;
6212 break;
6213
6214 default:
6215 hddLog( VOS_TRACE_LEVEL_WARN, "%s: Invalid Band %d", __func__, band);
6216 *pBand = -1;
6217 break;
6218 }
6219}
6220
6221/**---------------------------------------------------------------------------
6222
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006223 \brief hdd_parse_send_action_frame_data() - HDD Parse send action frame data
6224
6225 This function parses the send action frame data passed in the format
6226 SENDACTIONFRAME<space><bssid><space><channel><space><dwelltime><space><data>
6227
Srinivas Girigowda56076852013-08-20 14:00:50 -07006228 \param - pValue Pointer to input data
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006229 \param - pTargetApBssid Pointer to target Ap bssid
6230 \param - pChannel Pointer to the Target AP channel
6231 \param - pDwellTime Pointer to the time to stay off-channel after transmitting action frame
6232 \param - pBuf Pointer to data
6233 \param - pBufLen Pointer to data length
6234
6235 \return - 0 for success non-zero for failure
6236
6237 --------------------------------------------------------------------------*/
6238VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid, tANI_U8 *pChannel,
6239 tANI_U8 *pDwellTime, tANI_U8 **pBuf, tANI_U8 *pBufLen)
6240{
6241 tANI_U8 *inPtr = pValue;
6242 tANI_U8 *dataEnd;
6243 int tempInt;
6244 int j = 0;
6245 int i = 0;
6246 int v = 0;
6247 tANI_U8 tempBuf[32];
6248 tANI_U8 tempByte = 0;
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006249 /* 12 hexa decimal digits, 5 ':' and '\0' */
6250 tANI_U8 macAddress[18];
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006251
6252 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
6253 /*no argument after the command*/
6254 if (NULL == inPtr)
6255 {
6256 return -EINVAL;
6257 }
6258
6259 /*no space after the command*/
6260 else if (SPACE_ASCII_VALUE != *inPtr)
6261 {
6262 return -EINVAL;
6263 }
6264
6265 /*removing empty spaces*/
6266 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
6267
6268 /*no argument followed by spaces*/
6269 if ('\0' == *inPtr)
6270 {
6271 return -EINVAL;
6272 }
6273
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006274 v = sscanf(inPtr, "%17s", macAddress);
6275 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006276 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006277 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6278 "Invalid MAC address or All hex inputs are not read (%d)", v);
6279 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006280 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006281
6282 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
6283 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
6284 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
6285 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
6286 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
6287 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006288
6289 /* point to the next argument */
6290 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
6291 /*no argument after the command*/
6292 if (NULL == inPtr) return -EINVAL;
6293
6294 /*removing empty spaces*/
6295 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
6296
6297 /*no argument followed by spaces*/
6298 if ('\0' == *inPtr)
6299 {
6300 return -EINVAL;
6301 }
6302
6303 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006304 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006305 if (1 != v) return -EINVAL;
6306
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006307 v = kstrtos32(tempBuf, 10, &tempInt);
Agarwal Ashish353b3a82014-04-08 14:55:11 +05306308 if ( v < 0 || tempInt <= 0 || tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX )
Kiet Lambe150c22013-11-21 16:30:32 +05306309 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006310
6311 *pChannel = tempInt;
6312
6313 /* point to the next argument */
6314 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
6315 /*no argument after the command*/
6316 if (NULL == inPtr) return -EINVAL;
6317 /*removing empty spaces*/
6318 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
6319
6320 /*no argument followed by spaces*/
6321 if ('\0' == *inPtr)
6322 {
6323 return -EINVAL;
6324 }
6325
6326 /*getting the next argument ie the dwell time */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006327 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006328 if (1 != v) return -EINVAL;
6329
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006330 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda5a6e0672014-01-09 14:42:57 -08006331 if ( v < 0 || tempInt < 0) return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006332
6333 *pDwellTime = tempInt;
6334
6335 /* point to the next argument */
6336 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
6337 /*no argument after the command*/
6338 if (NULL == inPtr) return -EINVAL;
6339 /*removing empty spaces*/
6340 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
6341
6342 /*no argument followed by spaces*/
6343 if ('\0' == *inPtr)
6344 {
6345 return -EINVAL;
6346 }
6347
6348 /* find the length of data */
6349 dataEnd = inPtr;
6350 while(('\0' != *dataEnd) )
6351 {
6352 dataEnd++;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006353 }
Kiet Lambe150c22013-11-21 16:30:32 +05306354 *pBufLen = dataEnd - inPtr ;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006355 if ( *pBufLen <= 0) return -EINVAL;
6356
Srinivas Girigowdab5ae85d2013-06-03 10:51:45 -07006357 /* Allocate the number of bytes based on the number of input characters
6358 whether it is even or odd.
6359 if the number of input characters are even, then we need N/2 byte.
6360 if the number of input characters are odd, then we need do (N+1)/2 to
6361 compensate rounding off.
6362 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
6363 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
6364 *pBuf = vos_mem_malloc((*pBufLen + 1)/2);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006365 if (NULL == *pBuf)
6366 {
6367 hddLog(VOS_TRACE_LEVEL_FATAL,
6368 "%s: vos_mem_alloc failed ", __func__);
6369 return -EINVAL;
6370 }
6371
6372 /* the buffer received from the upper layer is character buffer,
6373 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
6374 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
6375 and f0 in 3rd location */
6376 for (i = 0, j = 0; j < *pBufLen; j += 2)
6377 {
Kiet Lambe150c22013-11-21 16:30:32 +05306378 if( j+1 == *pBufLen)
6379 {
6380 tempByte = hdd_parse_hex(inPtr[j]);
6381 }
6382 else
6383 {
6384 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
6385 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006386 (*pBuf)[i++] = tempByte;
6387 }
6388 *pBufLen = i;
6389 return VOS_STATUS_SUCCESS;
6390}
6391
Srinivas Girigowda100eb322013-03-15 16:48:20 -07006392/**---------------------------------------------------------------------------
6393
Srinivas Girigowdade697412013-02-14 16:31:48 -08006394 \brief hdd_parse_channellist() - HDD Parse channel list
6395
6396 This function parses the channel list passed in the format
6397 SETROAMSCANCHANNELS<space><Number of channels><space>Channel 1<space>Channel 2<space>Channel N
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07006398 if the Number of channels (N) does not match with the actual number of channels passed
6399 then take the minimum of N and count of (Ch1, Ch2, ...Ch M)
6400 For example, if SETROAMSCANCHANNELS 3 36 40 44 48, only 36, 40 and 44 shall be taken.
6401 If SETROAMSCANCHANNELS 5 36 40 44 48, ignore 5 and take 36, 40, 44 and 48.
6402 This function does not take care of removing duplicate channels from the list
Srinivas Girigowdade697412013-02-14 16:31:48 -08006403
6404 \param - pValue Pointer to input channel list
6405 \param - ChannelList Pointer to local output array to record channel list
6406 \param - pNumChannels Pointer to number of roam scan channels
6407
6408 \return - 0 for success non-zero for failure
6409
6410 --------------------------------------------------------------------------*/
6411VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels)
6412{
6413 tANI_U8 *inPtr = pValue;
6414 int tempInt;
6415 int j = 0;
6416 int v = 0;
6417 char buf[32];
6418
6419 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
6420 /*no argument after the command*/
6421 if (NULL == inPtr)
6422 {
6423 return -EINVAL;
6424 }
6425
6426 /*no space after the command*/
6427 else if (SPACE_ASCII_VALUE != *inPtr)
6428 {
6429 return -EINVAL;
6430 }
6431
6432 /*removing empty spaces*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07006433 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08006434
6435 /*no argument followed by spaces*/
6436 if ('\0' == *inPtr)
6437 {
6438 return -EINVAL;
6439 }
6440
6441 /*getting the first argument ie the number of channels*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006442 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006443 if (1 != v) return -EINVAL;
6444
Srinivas Girigowdade697412013-02-14 16:31:48 -08006445 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07006446 if ((v < 0) ||
6447 (tempInt <= 0) ||
6448 (tempInt > WNI_CFG_VALID_CHANNEL_LIST_LEN))
6449 {
6450 return -EINVAL;
6451 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08006452
6453 *pNumChannels = tempInt;
6454
6455 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6456 "Number of channels are: %d", *pNumChannels);
6457
6458 for (j = 0; j < (*pNumChannels); j++)
6459 {
6460 /*inPtr pointing to the beginning of first space after number of channels*/
6461 inPtr = strpbrk( inPtr, " " );
6462 /*no channel list after the number of channels argument*/
6463 if (NULL == inPtr)
6464 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07006465 if (0 != j)
6466 {
6467 *pNumChannels = j;
6468 return VOS_STATUS_SUCCESS;
6469 }
6470 else
6471 {
6472 return -EINVAL;
6473 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08006474 }
6475
6476 /*removing empty space*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07006477 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08006478
6479 /*no channel list after the number of channels argument and spaces*/
6480 if ( '\0' == *inPtr )
6481 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07006482 if (0 != j)
6483 {
6484 *pNumChannels = j;
6485 return VOS_STATUS_SUCCESS;
6486 }
6487 else
6488 {
6489 return -EINVAL;
6490 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08006491 }
6492
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006493 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006494 if (1 != v) return -EINVAL;
6495
Srinivas Girigowdade697412013-02-14 16:31:48 -08006496 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07006497 if ((v < 0) ||
6498 (tempInt <= 0) ||
6499 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
6500 {
6501 return -EINVAL;
6502 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08006503 pChannelList[j] = tempInt;
6504
6505 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6506 "Channel %d added to preferred channel list",
6507 pChannelList[j] );
6508 }
6509
Srinivas Girigowdade697412013-02-14 16:31:48 -08006510 return VOS_STATUS_SUCCESS;
6511}
6512
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006513
6514/**---------------------------------------------------------------------------
6515
6516 \brief hdd_parse_reassoc_command_data() - HDD Parse reassoc command data
6517
6518 This function parses the reasoc command data passed in the format
6519 REASSOC<space><bssid><space><channel>
6520
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006521 \param - pValue Pointer to input data (its a NUL terminated string)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006522 \param - pTargetApBssid Pointer to target Ap bssid
6523 \param - pChannel Pointer to the Target AP channel
6524
6525 \return - 0 for success non-zero for failure
6526
6527 --------------------------------------------------------------------------*/
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006528VOS_STATUS hdd_parse_reassoc_command_data(tANI_U8 *pValue,
6529 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006530{
6531 tANI_U8 *inPtr = pValue;
6532 int tempInt;
6533 int v = 0;
6534 tANI_U8 tempBuf[32];
Kiet Lamaa8e15a2014-02-11 23:30:06 -08006535 /* 12 hexa decimal digits, 5 ':' and '\0' */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006536 tANI_U8 macAddress[18];
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006537
6538 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
6539 /*no argument after the command*/
6540 if (NULL == inPtr)
6541 {
6542 return -EINVAL;
6543 }
6544
6545 /*no space after the command*/
6546 else if (SPACE_ASCII_VALUE != *inPtr)
6547 {
6548 return -EINVAL;
6549 }
6550
6551 /*removing empty spaces*/
6552 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
6553
6554 /*no argument followed by spaces*/
6555 if ('\0' == *inPtr)
6556 {
6557 return -EINVAL;
6558 }
6559
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006560 v = sscanf(inPtr, "%17s", macAddress);
6561 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006562 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006563 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6564 "Invalid MAC address or All hex inputs are not read (%d)", v);
6565 return -EINVAL;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006566 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006567
6568 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
6569 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
6570 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
6571 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
6572 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
6573 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006574
6575 /* point to the next argument */
6576 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
6577 /*no argument after the command*/
6578 if (NULL == inPtr) return -EINVAL;
6579
6580 /*removing empty spaces*/
6581 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
6582
6583 /*no argument followed by spaces*/
6584 if ('\0' == *inPtr)
6585 {
6586 return -EINVAL;
6587 }
6588
6589 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08006590 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006591 if (1 != v) return -EINVAL;
6592
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006593 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006594 if ((v < 0) ||
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05306595 (tempInt < 0) ||
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006596 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
6597 {
6598 return -EINVAL;
6599 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07006600
6601 *pChannel = tempInt;
6602 return VOS_STATUS_SUCCESS;
6603}
6604
6605#endif
6606
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006607#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006608/**---------------------------------------------------------------------------
6609
6610 \brief hdd_parse_get_cckm_ie() - HDD Parse and fetch the CCKM IE
6611
6612 This function parses the SETCCKM IE command
6613 SETCCKMIE<space><ie data>
6614
6615 \param - pValue Pointer to input data
6616 \param - pCckmIe Pointer to output cckm Ie
6617 \param - pCckmIeLen Pointer to output cckm ie length
6618
6619 \return - 0 for success non-zero for failure
6620
6621 --------------------------------------------------------------------------*/
6622VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe,
6623 tANI_U8 *pCckmIeLen)
6624{
6625 tANI_U8 *inPtr = pValue;
6626 tANI_U8 *dataEnd;
6627 int j = 0;
6628 int i = 0;
6629 tANI_U8 tempByte = 0;
6630
6631 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
6632 /*no argument after the command*/
6633 if (NULL == inPtr)
6634 {
6635 return -EINVAL;
6636 }
6637
6638 /*no space after the command*/
6639 else if (SPACE_ASCII_VALUE != *inPtr)
6640 {
6641 return -EINVAL;
6642 }
6643
6644 /*removing empty spaces*/
6645 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
6646
6647 /*no argument followed by spaces*/
6648 if ('\0' == *inPtr)
6649 {
6650 return -EINVAL;
6651 }
6652
6653 /* find the length of data */
6654 dataEnd = inPtr;
6655 while(('\0' != *dataEnd) )
6656 {
6657 dataEnd++;
6658 ++(*pCckmIeLen);
6659 }
6660 if ( *pCckmIeLen <= 0) return -EINVAL;
6661
6662 /* Allocate the number of bytes based on the number of input characters
6663 whether it is even or odd.
6664 if the number of input characters are even, then we need N/2 byte.
6665 if the number of input characters are odd, then we need do (N+1)/2 to
6666 compensate rounding off.
6667 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
6668 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
6669 *pCckmIe = vos_mem_malloc((*pCckmIeLen + 1)/2);
6670 if (NULL == *pCckmIe)
6671 {
6672 hddLog(VOS_TRACE_LEVEL_FATAL,
6673 "%s: vos_mem_alloc failed ", __func__);
6674 return -EINVAL;
6675 }
6676 vos_mem_zero(*pCckmIe, (*pCckmIeLen + 1)/2);
6677 /* the buffer received from the upper layer is character buffer,
6678 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
6679 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
6680 and f0 in 3rd location */
6681 for (i = 0, j = 0; j < *pCckmIeLen; j += 2)
6682 {
6683 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
6684 (*pCckmIe)[i++] = tempByte;
6685 }
6686 *pCckmIeLen = i;
6687
6688 return VOS_STATUS_SUCCESS;
6689}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08006690#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07006691
Jeff Johnson295189b2012-06-20 16:38:30 -07006692/**---------------------------------------------------------------------------
6693
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07006694 \brief hdd_is_valid_mac_address() - Validate MAC address
6695
6696 This function validates whether the given MAC address is valid or not
6697 Expected MAC address is of the format XX:XX:XX:XX:XX:XX
6698 where X is the hexa decimal digit character and separated by ':'
6699 This algorithm works even if MAC address is not separated by ':'
6700
6701 This code checks given input string mac contains exactly 12 hexadecimal digits.
6702 and a separator colon : appears in the input string only after
6703 an even number of hex digits.
6704
6705 \param - pMacAddr pointer to the input MAC address
6706 \return - 1 for valid and 0 for invalid
6707
6708 --------------------------------------------------------------------------*/
6709
6710v_BOOL_t hdd_is_valid_mac_address(const tANI_U8 *pMacAddr)
6711{
6712 int xdigit = 0;
6713 int separator = 0;
6714 while (*pMacAddr)
6715 {
6716 if (isxdigit(*pMacAddr))
6717 {
6718 xdigit++;
6719 }
6720 else if (':' == *pMacAddr)
6721 {
6722 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
6723 break;
6724
6725 ++separator;
6726 }
6727 else
6728 {
6729 separator = -1;
6730 /* Invalid MAC found */
6731 return 0;
6732 }
6733 ++pMacAddr;
6734 }
6735 return (xdigit == 12 && (separator == 5 || separator == 0));
6736}
6737
6738/**---------------------------------------------------------------------------
6739
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306740 \brief __hdd_open() - HDD Open function
Jeff Johnson295189b2012-06-20 16:38:30 -07006741
6742 \param - dev Pointer to net_device structure
6743
6744 \return - 0 for success non-zero for failure
6745
6746 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306747int __hdd_open(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07006748{
6749 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6750 hdd_context_t *pHddCtx;
6751 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
6752 VOS_STATUS status;
6753 v_BOOL_t in_standby = TRUE;
6754
6755 if (NULL == pAdapter)
6756 {
6757 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05306758 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006759 return -ENODEV;
6760 }
6761
6762 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05306763 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
6764 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson295189b2012-06-20 16:38:30 -07006765 if (NULL == pHddCtx)
6766 {
6767 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006768 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006769 return -ENODEV;
6770 }
6771
6772 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
6773 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
6774 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07006775 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
6776 {
6777 hddLog(VOS_TRACE_LEVEL_INFO, "%s: chip already out of standby",
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05306778 __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07006779 in_standby = FALSE;
6780 break;
6781 }
6782 else
6783 {
6784 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
6785 pAdapterNode = pNext;
6786 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006787 }
6788
6789 if (TRUE == in_standby)
6790 {
6791 if (VOS_STATUS_SUCCESS != wlan_hdd_exit_lowpower(pHddCtx, pAdapter))
6792 {
6793 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to bring "
6794 "wlan out of power save", __func__);
6795 return -EINVAL;
6796 }
6797 }
6798
Jeff Johnson6a81ca42013-04-05 10:37:08 -07006799 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07006800 if (hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
6801 {
6802 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006803 "%s: Enabling Tx Queues", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006804 /* Enable TX queues only when we are connected */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05306805 hddLog(VOS_TRACE_LEVEL_INFO, FL("Enabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006806 netif_tx_start_all_queues(dev);
6807 }
6808
6809 return 0;
6810}
6811
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306812/**---------------------------------------------------------------------------
6813
6814 \brief hdd_open() - Wrapper function for __hdd_open to protect it from SSR
6815
6816 This is called in response to ifconfig up
6817
6818 \param - dev Pointer to net_device structure
6819
6820 \return - 0 for success non-zero for failure
6821
6822 --------------------------------------------------------------------------*/
6823int hdd_open(struct net_device *dev)
6824{
6825 int ret;
6826
6827 vos_ssr_protect(__func__);
6828 ret = __hdd_open(dev);
6829 vos_ssr_unprotect(__func__);
6830
6831 return ret;
6832}
6833
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05306834int __hdd_mon_open (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07006835{
6836 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6837
6838 if(pAdapter == NULL) {
6839 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006840 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006841 return -EINVAL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006842 }
6843
Jeff Johnson295189b2012-06-20 16:38:30 -07006844 return 0;
6845}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05306846
6847int hdd_mon_open (struct net_device *dev)
6848{
6849 int ret;
6850
6851 vos_ssr_protect(__func__);
6852 ret = __hdd_mon_open(dev);
6853 vos_ssr_unprotect(__func__);
6854
6855 return ret;
6856}
6857
Katya Nigame7b69a82015-04-28 15:24:06 +05306858int hdd_mon_stop(struct net_device *dev)
6859{
6860 return 0;
6861}
6862
Jeff Johnson295189b2012-06-20 16:38:30 -07006863/**---------------------------------------------------------------------------
6864
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306865 \brief __hdd_stop() - HDD stop function
Jeff Johnson295189b2012-06-20 16:38:30 -07006866
6867 \param - dev Pointer to net_device structure
6868
6869 \return - 0 for success non-zero for failure
6870
6871 --------------------------------------------------------------------------*/
6872
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306873int __hdd_stop (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07006874{
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05306875 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006876 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6877 hdd_context_t *pHddCtx;
6878 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
6879 VOS_STATUS status;
6880 v_BOOL_t enter_standby = TRUE;
6881
6882 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006883 if (NULL == pAdapter)
6884 {
6885 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05306886 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006887 return -ENODEV;
6888 }
Sachin Ahuja9b4958f2015-01-15 21:37:00 +05306889 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05306890 pAdapter->sessionId, pAdapter->device_mode));
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05306891
6892 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6893 ret = wlan_hdd_validate_context(pHddCtx);
6894 if (ret)
Jeff Johnson295189b2012-06-20 16:38:30 -07006895 {
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05306896 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07006897 }
6898
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306899 /* Nothing to be done if the interface is not opened */
6900 if (VOS_FALSE == test_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags))
6901 {
6902 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6903 "%s: NETDEV Interface is not OPENED", __func__);
6904 return -ENODEV;
6905 }
6906
6907 /* Make sure the interface is marked as closed */
Jeff Johnson6a81ca42013-04-05 10:37:08 -07006908 clear_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07006909 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disabling OS Tx queues", __func__);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306910
6911 /* Disable TX on the interface, after this hard_start_xmit() will not
6912 * be called on that interface
6913 */
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05306914 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006915 netif_tx_disable(pAdapter->dev);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306916
6917 /* Mark the interface status as "down" for outside world */
Jeff Johnson295189b2012-06-20 16:38:30 -07006918 netif_carrier_off(pAdapter->dev);
6919
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306920 /* The interface is marked as down for outside world (aka kernel)
6921 * But the driver is pretty much alive inside. The driver needs to
6922 * tear down the existing connection on the netdev (session)
6923 * cleanup the data pipes and wait until the control plane is stabilized
6924 * for this interface. The call also needs to wait until the above
6925 * mentioned actions are completed before returning to the caller.
6926 * Notice that the hdd_stop_adapter is requested not to close the session
6927 * That is intentional to be able to scan if it is a STA/P2P interface
6928 */
6929 hdd_stop_adapter(pHddCtx, pAdapter, VOS_FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05306930#ifdef FEATURE_WLAN_TDLS
6931 mutex_lock(&pHddCtx->tdls_lock);
6932#endif
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306933 /* DeInit the adapter. This ensures datapath cleanup as well */
c_hpothu002231a2015-02-05 14:58:51 +05306934 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05306935#ifdef FEATURE_WLAN_TDLS
6936 mutex_unlock(&pHddCtx->tdls_lock);
6937#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006938 /* SoftAP ifaces should never go in power save mode
6939 making sure same here. */
6940 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode )
6941 || (WLAN_HDD_MONITOR == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07006942 || (WLAN_HDD_P2P_GO == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07006943 )
6944 {
6945 /* SoftAP mode, so return from here */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306946 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6947 "%s: In SAP MODE", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006948 EXIT();
6949 return 0;
6950 }
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306951 /* Find if any iface is up. If any iface is up then can't put device to
6952 * sleep/power save mode
6953 */
Jeff Johnson295189b2012-06-20 16:38:30 -07006954 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
6955 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
6956 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07006957 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
6958 {
6959 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Still other ifaces are up cannot "
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05306960 "put device to sleep", __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07006961 enter_standby = FALSE;
6962 break;
6963 }
6964 else
6965 {
6966 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
6967 pAdapterNode = pNext;
6968 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006969 }
6970
6971 if (TRUE == enter_standby)
6972 {
6973 hddLog(VOS_TRACE_LEVEL_INFO, "%s: All Interfaces are Down "
6974 "entering standby", __func__);
6975 if (VOS_STATUS_SUCCESS != wlan_hdd_enter_lowpower(pHddCtx))
6976 {
6977 /*log and return success*/
6978 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to put "
6979 "wlan in power save", __func__);
6980 }
6981 }
6982
6983 EXIT();
6984 return 0;
6985}
6986
6987/**---------------------------------------------------------------------------
6988
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306989 \brief hdd_stop() - wrapper_function for __hdd_stop to protect it from SSR
Jeff Johnson295189b2012-06-20 16:38:30 -07006990
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05306991 This is called in response to ifconfig down
6992
6993 \param - dev Pointer to net_device structure
6994
6995 \return - 0 for success non-zero for failure
6996-----------------------------------------------------------------------------*/
6997int hdd_stop (struct net_device *dev)
6998{
6999 int ret;
7000
7001 vos_ssr_protect(__func__);
7002 ret = __hdd_stop(dev);
7003 vos_ssr_unprotect(__func__);
7004
7005 return ret;
7006}
7007
7008/**---------------------------------------------------------------------------
7009
7010 \brief __hdd_uninit() - HDD uninit function
Jeff Johnson295189b2012-06-20 16:38:30 -07007011
7012 \param - dev Pointer to net_device structure
7013
7014 \return - void
7015
7016 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307017static void __hdd_uninit (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07007018{
7019 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307020 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007021 ENTER();
7022
7023 do
7024 {
7025 if (NULL == pAdapter)
7026 {
7027 hddLog(VOS_TRACE_LEVEL_FATAL,
7028 "%s: NULL pAdapter", __func__);
7029 break;
7030 }
7031
7032 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
7033 {
7034 hddLog(VOS_TRACE_LEVEL_FATAL,
7035 "%s: Invalid magic", __func__);
7036 break;
7037 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307038 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7039 if (NULL == pHddCtx)
Jeff Johnson295189b2012-06-20 16:38:30 -07007040 {
7041 hddLog(VOS_TRACE_LEVEL_FATAL,
7042 "%s: NULL pHddCtx", __func__);
7043 break;
7044 }
7045
7046 if (dev != pAdapter->dev)
7047 {
7048 hddLog(VOS_TRACE_LEVEL_FATAL,
7049 "%s: Invalid device reference", __func__);
7050 /* we haven't validated all cases so let this go for now */
7051 }
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307052#ifdef FEATURE_WLAN_TDLS
7053 mutex_lock(&pHddCtx->tdls_lock);
7054#endif
c_hpothu002231a2015-02-05 14:58:51 +05307055 hdd_deinit_adapter(pHddCtx, pAdapter, TRUE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05307056#ifdef FEATURE_WLAN_TDLS
7057 mutex_unlock(&pHddCtx->tdls_lock);
7058#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007059
7060 /* after uninit our adapter structure will no longer be valid */
7061 pAdapter->dev = NULL;
7062 pAdapter->magic = 0;
7063 } while (0);
7064
7065 EXIT();
7066}
7067
7068/**---------------------------------------------------------------------------
7069
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307070 \brief hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
7071
7072 This is called during the netdev unregister to uninitialize all data
7073associated with the device
7074
7075 \param - dev Pointer to net_device structure
7076
7077 \return - void
7078
7079 --------------------------------------------------------------------------*/
7080static void hdd_uninit (struct net_device *dev)
7081{
7082 vos_ssr_protect(__func__);
7083 __hdd_uninit(dev);
7084 vos_ssr_unprotect(__func__);
7085}
7086
7087/**---------------------------------------------------------------------------
7088
Jeff Johnson295189b2012-06-20 16:38:30 -07007089 \brief hdd_release_firmware() -
7090
7091 This function calls the release firmware API to free the firmware buffer.
7092
7093 \param - pFileName Pointer to the File Name.
7094 pCtx - Pointer to the adapter .
7095
7096
7097 \return - 0 for success, non zero for failure
7098
7099 --------------------------------------------------------------------------*/
7100
7101VOS_STATUS hdd_release_firmware(char *pFileName,v_VOID_t *pCtx)
7102{
7103 VOS_STATUS status = VOS_STATUS_SUCCESS;
7104 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
7105 ENTER();
7106
7107
7108 if (!strcmp(WLAN_FW_FILE, pFileName)) {
7109
7110 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"%s: Loaded firmware file is %s",__func__,pFileName);
7111
7112 if(pHddCtx->fw) {
7113 release_firmware(pHddCtx->fw);
7114 pHddCtx->fw = NULL;
7115 }
7116 else
7117 status = VOS_STATUS_E_FAILURE;
7118 }
7119 else if (!strcmp(WLAN_NV_FILE,pFileName)) {
7120 if(pHddCtx->nv) {
7121 release_firmware(pHddCtx->nv);
7122 pHddCtx->nv = NULL;
7123 }
7124 else
7125 status = VOS_STATUS_E_FAILURE;
7126
7127 }
7128
7129 EXIT();
7130 return status;
7131}
7132
7133/**---------------------------------------------------------------------------
7134
7135 \brief hdd_request_firmware() -
7136
7137 This function reads the firmware file using the request firmware
7138 API and returns the the firmware data and the firmware file size.
7139
7140 \param - pfileName - Pointer to the file name.
7141 - pCtx - Pointer to the adapter .
7142 - ppfw_data - Pointer to the pointer of the firmware data.
7143 - pSize - Pointer to the file size.
7144
7145 \return - VOS_STATUS_SUCCESS for success, VOS_STATUS_E_FAILURE for failure
7146
7147 --------------------------------------------------------------------------*/
7148
7149
7150VOS_STATUS hdd_request_firmware(char *pfileName,v_VOID_t *pCtx,v_VOID_t **ppfw_data, v_SIZE_t *pSize)
7151{
7152 int status;
7153 VOS_STATUS retval = VOS_STATUS_SUCCESS;
7154 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
7155 ENTER();
7156
7157 if( (!strcmp(WLAN_FW_FILE, pfileName)) ) {
7158
7159 status = request_firmware(&pHddCtx->fw, pfileName, pHddCtx->parent_dev);
7160
7161 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
7162 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Firmware %s download failed",
7163 __func__, pfileName);
7164 retval = VOS_STATUS_E_FAILURE;
7165 }
7166
7167 else {
7168 *ppfw_data = (v_VOID_t *)pHddCtx->fw->data;
7169 *pSize = pHddCtx->fw->size;
7170 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Firmware size = %d",
7171 __func__, *pSize);
7172 }
7173 }
7174 else if(!strcmp(WLAN_NV_FILE, pfileName)) {
7175
7176 status = request_firmware(&pHddCtx->nv, pfileName, pHddCtx->parent_dev);
7177
7178 if(status || !pHddCtx->nv || !pHddCtx->nv->data) {
7179 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: nv %s download failed",
7180 __func__, pfileName);
7181 retval = VOS_STATUS_E_FAILURE;
7182 }
7183
7184 else {
7185 *ppfw_data = (v_VOID_t *)pHddCtx->nv->data;
7186 *pSize = pHddCtx->nv->size;
7187 hddLog(VOS_TRACE_LEVEL_INFO, "%s: nv file size = %d",
7188 __func__, *pSize);
7189 }
7190 }
7191
7192 EXIT();
7193 return retval;
7194}
7195/**---------------------------------------------------------------------------
7196 \brief hdd_full_pwr_cbk() - HDD full power callbackfunction
7197
7198 This is the function invoked by SME to inform the result of a full power
7199 request issued by HDD
7200
7201 \param - callbackcontext - Pointer to cookie
7202 status - result of request
7203
7204 \return - None
7205
7206--------------------------------------------------------------------------*/
7207void hdd_full_pwr_cbk(void *callbackContext, eHalStatus status)
7208{
7209 hdd_context_t *pHddCtx = (hdd_context_t*)callbackContext;
7210
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07007211 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"HDD full Power callback status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007212 if(&pHddCtx->full_pwr_comp_var)
7213 {
7214 complete(&pHddCtx->full_pwr_comp_var);
7215 }
7216}
7217
Abhishek Singh00b71972016-01-07 10:51:04 +05307218#ifdef WLAN_FEATURE_RMC
7219static void hdd_tx_fail_ind_callback(v_U8_t *MacAddr, v_U8_t seqNo)
7220{
7221 int payload_len;
7222 struct sk_buff *skb;
7223 struct nlmsghdr *nlh;
7224 v_U8_t *data;
7225
7226 payload_len = ETH_ALEN;
7227
7228 if (0 == cesium_pid)
7229 {
7230 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: cesium process not registered",
7231 __func__);
7232 return;
7233 }
7234
7235 if ((skb = nlmsg_new(payload_len,GFP_ATOMIC)) == NULL)
7236 {
7237 hddLog(VOS_TRACE_LEVEL_ERROR,
7238 "%s: nlmsg_new() failed for msg size[%d]",
7239 __func__, NLMSG_SPACE(payload_len));
7240 return;
7241 }
7242
7243 nlh = nlmsg_put(skb, cesium_pid, seqNo, 0, payload_len, NLM_F_REQUEST);
7244
7245 if (NULL == nlh)
7246 {
7247 hddLog(VOS_TRACE_LEVEL_ERROR,
7248 "%s: nlmsg_put() failed for msg size[%d]",
7249 __func__, NLMSG_SPACE(payload_len));
7250
7251 kfree_skb(skb);
7252 return;
7253 }
7254
7255 data = nlmsg_data(nlh);
7256 memcpy(data, MacAddr, ETH_ALEN);
7257
7258 if (nlmsg_unicast(cesium_nl_srv_sock, skb, cesium_pid) < 0)
7259 {
7260 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: nlmsg_unicast() failed for msg size[%d]",
7261 __func__, NLMSG_SPACE(payload_len));
7262 }
7263
7264 return;
7265}
7266
7267/**---------------------------------------------------------------------------
7268 \brief hdd_ParseuserParams - return a pointer to the next argument
7269
7270 \return - status
7271
7272--------------------------------------------------------------------------*/
7273static int hdd_ParseUserParams(tANI_U8 *pValue, tANI_U8 **ppArg)
7274{
7275 tANI_U8 *pVal;
7276
7277 pVal = strchr(pValue, ' ');
7278
7279 if (NULL == pVal)
7280 {
7281 /* no argument remains */
7282 return -EINVAL;
7283 }
7284 else if (SPACE_ASCII_VALUE != *pVal)
7285 {
7286 /* no space after the current argument */
7287 return -EINVAL;
7288 }
7289
7290 pVal++;
7291
7292 /* remove empty spaces */
7293 while ((SPACE_ASCII_VALUE == *pVal) && ('\0' != *pVal))
7294 {
7295 pVal++;
7296 }
7297
7298 /* no argument followed by spaces */
7299 if ('\0' == *pVal)
7300 {
7301 return -EINVAL;
7302 }
7303
7304 *ppArg = pVal;
7305
7306 return 0;
7307}
7308
7309/**----------------------------------------------------------------------------
7310 \brief hdd_ParseIBSSTXFailEventParams - Parse params for SETIBSSTXFAILEVENT
7311
7312 \return - status
7313
7314------------------------------------------------------------------------------*/
7315static int hdd_ParseIBSSTXFailEventParams(tANI_U8 *pValue,
7316 tANI_U8 *tx_fail_count,
7317 tANI_U16 *pid)
7318{
7319 tANI_U8 *param = NULL;
7320 int ret;
7321
7322 ret = hdd_ParseUserParams(pValue, &param);
7323
7324 if (0 == ret && NULL != param)
7325 {
7326 if (1 != sscanf(param, "%hhu", tx_fail_count))
7327 {
7328 ret = -EINVAL;
7329 goto done;
7330 }
7331 }
7332 else
7333 {
7334 goto done;
7335 }
7336
7337 if (0 == *tx_fail_count)
7338 {
7339 *pid = 0;
7340 goto done;
7341 }
7342
7343 pValue = param;
7344 pValue++;
7345
7346 ret = hdd_ParseUserParams(pValue, &param);
7347
7348 if (0 == ret)
7349 {
7350 if (1 != sscanf(param, "%hu", pid))
7351 {
7352 ret = -EINVAL;
7353 goto done;
7354 }
7355 }
7356 else
7357 {
7358 goto done;
7359 }
7360
7361done:
7362 return ret;
7363}
7364
7365static int hdd_open_cesium_nl_sock()
7366{
7367#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
7368 struct netlink_kernel_cfg cfg = {
7369 .groups = WLAN_NLINK_MCAST_GRP_ID,
7370 .input = NULL
7371 };
7372#endif
7373 int ret = 0;
7374
7375#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
7376 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
7377#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
7378 THIS_MODULE,
7379#endif
7380 &cfg);
7381#else
7382 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
7383 WLAN_NLINK_MCAST_GRP_ID, NULL, NULL, THIS_MODULE);
7384#endif
7385
7386 if (cesium_nl_srv_sock == NULL)
7387 {
7388 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7389 "NLINK: cesium netlink_kernel_create failed");
7390 ret = -ECONNREFUSED;
7391 }
7392
7393 return ret;
7394}
7395
7396static void hdd_close_cesium_nl_sock()
7397{
7398 if (NULL != cesium_nl_srv_sock)
7399 {
7400 netlink_kernel_release(cesium_nl_srv_sock);
7401 cesium_nl_srv_sock = NULL;
7402 }
7403}
7404#endif /* WLAN_FEATURE_RMC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007405/**---------------------------------------------------------------------------
7406
7407 \brief hdd_req_bmps_cbk() - HDD Request BMPS callback function
7408
7409 This is the function invoked by SME to inform the result of BMPS
7410 request issued by HDD
7411
7412 \param - callbackcontext - Pointer to cookie
7413 status - result of request
7414
7415 \return - None
7416
7417--------------------------------------------------------------------------*/
7418void hdd_req_bmps_cbk(void *callbackContext, eHalStatus status)
7419{
7420
7421 struct completion *completion_var = (struct completion*) callbackContext;
7422
Arif Hussain6d2a3322013-11-17 19:50:10 -08007423 hddLog(VOS_TRACE_LEVEL_ERROR, "HDD BMPS request Callback, status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007424 if(completion_var != NULL)
7425 {
7426 complete(completion_var);
7427 }
7428}
7429
7430/**---------------------------------------------------------------------------
7431
7432 \brief hdd_get_cfg_file_size() -
7433
7434 This function reads the configuration file using the request firmware
7435 API and returns the configuration file size.
7436
7437 \param - pCtx - Pointer to the adapter .
7438 - pFileName - Pointer to the file name.
7439 - pBufSize - Pointer to the buffer size.
7440
7441 \return - 0 for success, non zero for failure
7442
7443 --------------------------------------------------------------------------*/
7444
7445VOS_STATUS hdd_get_cfg_file_size(v_VOID_t *pCtx, char *pFileName, v_SIZE_t *pBufSize)
7446{
7447 int status;
7448 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
7449
7450 ENTER();
7451
7452 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
7453
7454 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
7455 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
7456 status = VOS_STATUS_E_FAILURE;
7457 }
7458 else {
7459 *pBufSize = pHddCtx->fw->size;
7460 hddLog(VOS_TRACE_LEVEL_INFO, "%s: CFG size = %d", __func__, *pBufSize);
7461 release_firmware(pHddCtx->fw);
7462 pHddCtx->fw = NULL;
7463 }
7464
7465 EXIT();
7466 return VOS_STATUS_SUCCESS;
7467}
7468
7469/**---------------------------------------------------------------------------
7470
7471 \brief hdd_read_cfg_file() -
7472
7473 This function reads the configuration file using the request firmware
7474 API and returns the cfg data and the buffer size of the configuration file.
7475
7476 \param - pCtx - Pointer to the adapter .
7477 - pFileName - Pointer to the file name.
7478 - pBuffer - Pointer to the data buffer.
7479 - pBufSize - Pointer to the buffer size.
7480
7481 \return - 0 for success, non zero for failure
7482
7483 --------------------------------------------------------------------------*/
7484
7485VOS_STATUS hdd_read_cfg_file(v_VOID_t *pCtx, char *pFileName,
7486 v_VOID_t *pBuffer, v_SIZE_t *pBufSize)
7487{
7488 int status;
7489 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
7490
7491 ENTER();
7492
7493 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
7494
7495 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
7496 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
7497 return VOS_STATUS_E_FAILURE;
7498 }
7499 else {
7500 if(*pBufSize != pHddCtx->fw->size) {
7501 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Caller sets invalid CFG "
7502 "file size", __func__);
7503 release_firmware(pHddCtx->fw);
7504 pHddCtx->fw = NULL;
7505 return VOS_STATUS_E_FAILURE;
7506 }
7507 else {
7508 if(pBuffer) {
7509 vos_mem_copy(pBuffer,pHddCtx->fw->data,*pBufSize);
7510 }
7511 release_firmware(pHddCtx->fw);
7512 pHddCtx->fw = NULL;
7513 }
7514 }
7515
7516 EXIT();
7517
7518 return VOS_STATUS_SUCCESS;
7519}
7520
7521/**---------------------------------------------------------------------------
7522
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307523 \brief __hdd_set_mac_address() -
Jeff Johnson295189b2012-06-20 16:38:30 -07007524
7525 This function sets the user specified mac address using
7526 the command ifconfig wlanX hw ether <mac adress>.
7527
7528 \param - dev - Pointer to the net device.
7529 - addr - Pointer to the sockaddr.
7530 \return - 0 for success, non zero for failure
7531
7532 --------------------------------------------------------------------------*/
7533
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307534static int __hdd_set_mac_address(struct net_device *dev, void *addr)
Jeff Johnson295189b2012-06-20 16:38:30 -07007535{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05307536 hdd_adapter_t *pAdapter;
7537 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007538 struct sockaddr *psta_mac_addr = addr;
7539 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05307540 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007541
7542 ENTER();
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05307543 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7544 if (NULL == pAdapter)
7545 {
7546 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7547 "%s: Adapter is NULL",__func__);
7548 return -EINVAL;
7549 }
7550 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7551 ret = wlan_hdd_validate_context(pHddCtx);
7552 if (0 != ret)
7553 {
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05307554 return ret;
7555 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007556
7557 memcpy(&pAdapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007558 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
7559
7560 EXIT();
7561 return halStatus;
7562}
7563
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307564/**---------------------------------------------------------------------------
7565
7566 \brief hdd_set_mac_address() -
7567
7568 Wrapper function to protect __hdd_set_mac_address() function from ssr
7569
7570 \param - dev - Pointer to the net device.
7571 - addr - Pointer to the sockaddr.
7572 \return - 0 for success, non zero for failure
7573
7574 --------------------------------------------------------------------------*/
7575static int hdd_set_mac_address(struct net_device *dev, void *addr)
7576{
7577 int ret;
7578
7579 vos_ssr_protect(__func__);
7580 ret = __hdd_set_mac_address(dev, addr);
7581 vos_ssr_unprotect(__func__);
7582
7583 return ret;
7584}
7585
Jeff Johnson295189b2012-06-20 16:38:30 -07007586tANI_U8* wlan_hdd_get_intf_addr(hdd_context_t* pHddCtx)
7587{
7588 int i;
7589 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
7590 {
Abhishek Singheb183782014-02-06 13:37:21 +05307591 if( 0 == ((pHddCtx->cfg_ini->intfAddrMask) & (1 << i)) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007592 break;
7593 }
7594
7595 if( VOS_MAX_CONCURRENCY_PERSONA == i)
7596 return NULL;
7597
7598 pHddCtx->cfg_ini->intfAddrMask |= (1 << i);
7599 return &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0];
7600}
7601
7602void wlan_hdd_release_intf_addr(hdd_context_t* pHddCtx, tANI_U8* releaseAddr)
7603{
7604 int i;
7605 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
7606 {
7607 if ( !memcmp(releaseAddr, &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], 6) )
7608 {
7609 pHddCtx->cfg_ini->intfAddrMask &= ~(1 << i);
7610 break;
7611 }
7612 }
7613 return;
7614}
7615
7616#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
7617 static struct net_device_ops wlan_drv_ops = {
7618 .ndo_open = hdd_open,
7619 .ndo_stop = hdd_stop,
7620 .ndo_uninit = hdd_uninit,
7621 .ndo_start_xmit = hdd_hard_start_xmit,
7622 .ndo_tx_timeout = hdd_tx_timeout,
7623 .ndo_get_stats = hdd_stats,
7624 .ndo_do_ioctl = hdd_ioctl,
7625 .ndo_set_mac_address = hdd_set_mac_address,
7626 .ndo_select_queue = hdd_select_queue,
7627#ifdef WLAN_FEATURE_PACKET_FILTERING
7628#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0))
7629 .ndo_set_rx_mode = hdd_set_multicast_list,
7630#else
7631 .ndo_set_multicast_list = hdd_set_multicast_list,
7632#endif //LINUX_VERSION_CODE
7633#endif
7634 };
Jeff Johnson295189b2012-06-20 16:38:30 -07007635 static struct net_device_ops wlan_mon_drv_ops = {
7636 .ndo_open = hdd_mon_open,
Katya Nigame7b69a82015-04-28 15:24:06 +05307637 .ndo_stop = hdd_mon_stop,
Jeff Johnson295189b2012-06-20 16:38:30 -07007638 .ndo_uninit = hdd_uninit,
7639 .ndo_start_xmit = hdd_mon_hard_start_xmit,
7640 .ndo_tx_timeout = hdd_tx_timeout,
7641 .ndo_get_stats = hdd_stats,
Katya Nigame7b69a82015-04-28 15:24:06 +05307642 .ndo_do_ioctl = hdd_mon_ioctl,
Jeff Johnson295189b2012-06-20 16:38:30 -07007643 .ndo_set_mac_address = hdd_set_mac_address,
7644 };
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +05307645
Jeff Johnson295189b2012-06-20 16:38:30 -07007646#endif
7647
7648void hdd_set_station_ops( struct net_device *pWlanDev )
7649{
7650#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
Jeff Johnson295189b2012-06-20 16:38:30 -07007651 pWlanDev->netdev_ops = &wlan_drv_ops;
7652#else
7653 pWlanDev->open = hdd_open;
7654 pWlanDev->stop = hdd_stop;
7655 pWlanDev->uninit = hdd_uninit;
7656 pWlanDev->hard_start_xmit = NULL;
7657 pWlanDev->tx_timeout = hdd_tx_timeout;
7658 pWlanDev->get_stats = hdd_stats;
7659 pWlanDev->do_ioctl = hdd_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07007660 pWlanDev->set_mac_address = hdd_set_mac_address;
7661#endif
7662}
7663
Katya Nigam1fd24402015-02-16 14:52:19 +05307664void hdd_set_ibss_ops( hdd_adapter_t *pAdapter )
7665{
7666 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
7667 wlan_drv_ops.ndo_start_xmit = hdd_ibss_hard_start_xmit;
7668 #else
7669 pAdapter->dev->hard_start_xmit = hdd_ibss_hard_start_xmit;
7670 #endif
7671}
7672
Jeff Johnsoneed415b2013-01-18 16:11:20 -08007673static hdd_adapter_t* hdd_alloc_station_adapter( hdd_context_t *pHddCtx, tSirMacAddr macAddr, const char* name )
Jeff Johnson295189b2012-06-20 16:38:30 -07007674{
7675 struct net_device *pWlanDev = NULL;
7676 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007677 /*
7678 * cfg80211 initialization and registration....
7679 */
Anand N Sunkadc34abbd2015-07-29 09:52:59 +05307680 pWlanDev = alloc_netdev_mq(sizeof( hdd_adapter_t ), name,
7681#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0))
7682 NET_NAME_UNKNOWN,
7683#endif
7684 ether_setup, NUM_TX_QUEUES);
Jeff Johnson295189b2012-06-20 16:38:30 -07007685 if(pWlanDev != NULL)
7686 {
7687
7688 //Save the pointer to the net_device in the HDD adapter
7689 pAdapter = (hdd_adapter_t*) netdev_priv( pWlanDev );
7690
Jeff Johnson295189b2012-06-20 16:38:30 -07007691 vos_mem_zero( pAdapter, sizeof( hdd_adapter_t ) );
7692
7693 pAdapter->dev = pWlanDev;
7694 pAdapter->pHddCtx = pHddCtx;
7695 pAdapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Agarwal Ashish47d18112014-08-04 19:55:07 +05307696 spin_lock_init(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -07007697
Rajeev79dbe4c2013-10-05 11:03:42 +05307698#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev79dbe4c2013-10-05 11:03:42 +05307699 pAdapter->pBatchScanRsp = NULL;
7700 pAdapter->numScanList = 0;
Rajeev Kumar20140c12013-10-21 19:39:02 -07007701 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08007702 pAdapter->prev_batch_id = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05307703 mutex_init(&pAdapter->hdd_batch_scan_lock);
7704#endif
7705
Jeff Johnson295189b2012-06-20 16:38:30 -07007706 pAdapter->isLinkUpSvcNeeded = FALSE;
7707 pAdapter->higherDtimTransition = eANI_BOOLEAN_TRUE;
7708 //Init the net_device structure
7709 strlcpy(pWlanDev->name, name, IFNAMSIZ);
7710
7711 vos_mem_copy(pWlanDev->dev_addr, (void *)macAddr, sizeof(tSirMacAddr));
7712 vos_mem_copy( pAdapter->macAddressCurrent.bytes, macAddr, sizeof(tSirMacAddr));
7713 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
7714 pWlanDev->hard_header_len += LIBRA_HW_NEEDED_HEADROOM;
7715
7716 hdd_set_station_ops( pAdapter->dev );
7717
7718 pWlanDev->destructor = free_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -07007719 pWlanDev->ieee80211_ptr = &pAdapter->wdev ;
7720 pAdapter->wdev.wiphy = pHddCtx->wiphy;
7721 pAdapter->wdev.netdev = pWlanDev;
Jeff Johnson295189b2012-06-20 16:38:30 -07007722 /* set pWlanDev's parent to underlying device */
7723 SET_NETDEV_DEV(pWlanDev, pHddCtx->parent_dev);
Kumar Anand82c009f2014-05-29 00:29:42 -07007724
7725 hdd_wmm_init( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07007726 }
7727
7728 return pAdapter;
7729}
7730
7731VOS_STATUS hdd_register_interface( hdd_adapter_t *pAdapter, tANI_U8 rtnl_lock_held )
7732{
7733 struct net_device *pWlanDev = pAdapter->dev;
7734 //hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
7735 //hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
7736 //eHalStatus halStatus = eHAL_STATUS_SUCCESS;
7737
7738 if( rtnl_lock_held )
7739 {
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -08007740 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007741 if( dev_alloc_name(pWlanDev, pWlanDev->name) < 0 )
7742 {
7743 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:dev_alloc_name",__func__);
7744 return VOS_STATUS_E_FAILURE;
7745 }
7746 }
7747 if (register_netdevice(pWlanDev))
7748 {
7749 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:register_netdev",__func__);
7750 return VOS_STATUS_E_FAILURE;
7751 }
7752 }
7753 else
7754 {
7755 if(register_netdev(pWlanDev))
7756 {
7757 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed:register_netdev",__func__);
7758 return VOS_STATUS_E_FAILURE;
7759 }
7760 }
7761 set_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags);
7762
7763 return VOS_STATUS_SUCCESS;
7764}
7765
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007766static eHalStatus hdd_smeCloseSessionCallback(void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07007767{
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007768 hdd_adapter_t *pAdapter = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07007769
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007770 if (NULL == pAdapter)
7771 {
7772 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: NULL pAdapter", __func__);
7773 return eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07007774 }
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007775
7776 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
7777 {
7778 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Invalid magic", __func__);
7779 return eHAL_STATUS_NOT_INITIALIZED;
7780 }
7781
7782 clear_bit(SME_SESSION_OPENED, &pAdapter->event_flags);
7783
Sameer Thalappilbee426e2013-10-30 10:30:30 -07007784#ifndef WLAN_OPEN_SOURCE
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007785 /* need to make sure all of our scheduled work has completed.
7786 * This callback is called from MC thread context, so it is safe to
7787 * to call below flush workqueue API from here.
Sameer Thalappilbee426e2013-10-30 10:30:30 -07007788 *
7789 * Even though this is called from MC thread context, if there is a faulty
7790 * work item in the system, that can hang this call forever. So flushing
7791 * this global work queue is not safe; and now we make sure that
7792 * individual work queues are stopped correctly. But the cancel work queue
7793 * is a GPL only API, so the proprietary version of the driver would still
7794 * rely on the global work queue flush.
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007795 */
7796 flush_scheduled_work();
Sameer Thalappilbee426e2013-10-30 10:30:30 -07007797#endif
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007798
7799 /* We can be blocked while waiting for scheduled work to be
7800 * flushed, and the adapter structure can potentially be freed, in
7801 * which case the magic will have been reset. So make sure the
7802 * magic is still good, and hence the adapter structure is still
7803 * valid, before signaling completion */
7804 if (WLAN_HDD_ADAPTER_MAGIC == pAdapter->magic)
7805 {
7806 complete(&pAdapter->session_close_comp_var);
7807 }
7808
Jeff Johnson295189b2012-06-20 16:38:30 -07007809 return eHAL_STATUS_SUCCESS;
7810}
7811
7812VOS_STATUS hdd_init_station_mode( hdd_adapter_t *pAdapter )
7813{
7814 struct net_device *pWlanDev = pAdapter->dev;
7815 hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
7816 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
7817 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
7818 VOS_STATUS status = VOS_STATUS_E_FAILURE;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307819 long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007820
Nirav Shah7e3c8132015-06-22 23:51:42 +05307821 spin_lock_init( &pAdapter->sta_hash_lock);
7822 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
7823
Jeff Johnson295189b2012-06-20 16:38:30 -07007824 INIT_COMPLETION(pAdapter->session_open_comp_var);
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07007825 sme_SetCurrDeviceMode(pHddCtx->hHal, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07007826 //Open a SME session for future operation
7827 halStatus = sme_OpenSession( pHddCtx->hHal, hdd_smeRoamCallback, pAdapter,
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07007828 (tANI_U8 *)&pAdapter->macAddressCurrent, &pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007829 if ( !HAL_STATUS_SUCCESS( halStatus ) )
7830 {
7831 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007832 "sme_OpenSession() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07007833 halStatus, halStatus );
7834 status = VOS_STATUS_E_FAILURE;
7835 goto error_sme_open;
7836 }
7837
7838 //Block on a completion variable. Can't wait forever though.
Vinay Krishna Eranna0fe2e7c2014-04-09 21:32:08 +05307839 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07007840 &pAdapter->session_open_comp_var,
7841 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307842 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07007843 {
7844 hddLog(VOS_TRACE_LEVEL_FATAL,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307845 "Session is not opened within timeout period code %ld", rc );
Jeff Johnson295189b2012-06-20 16:38:30 -07007846 status = VOS_STATUS_E_FAILURE;
7847 goto error_sme_open;
7848 }
7849
7850 // Register wireless extensions
7851 if( eHAL_STATUS_SUCCESS != (halStatus = hdd_register_wext(pWlanDev)))
7852 {
7853 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007854 "hdd_register_wext() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07007855 halStatus, halStatus );
7856 status = VOS_STATUS_E_FAILURE;
7857 goto error_register_wext;
7858 }
Katya Nigam1fd24402015-02-16 14:52:19 +05307859
Jeff Johnson295189b2012-06-20 16:38:30 -07007860 //Safe to register the hard_start_xmit function again
Katya Nigam1fd24402015-02-16 14:52:19 +05307861 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
7862 wlan_drv_ops.ndo_start_xmit = hdd_hard_start_xmit;
7863 #else
7864 pWlanDev->hard_start_xmit = hdd_hard_start_xmit;
7865 #endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007866
7867 //Set the Connection State to Not Connected
Abhishek Singhf4669da2014-05-26 15:07:49 +05307868 hddLog(VOS_TRACE_LEVEL_INFO,
7869 "%s: Set HDD connState to eConnectionState_NotConnected",
7870 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007871 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
7872
7873 //Set the default operation channel
7874 pHddStaCtx->conn_info.operationChannel = pHddCtx->cfg_ini->OperatingChannel;
7875
7876 /* Make the default Auth Type as OPEN*/
7877 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
7878
7879 if( VOS_STATUS_SUCCESS != ( status = hdd_init_tx_rx( pAdapter ) ) )
7880 {
7881 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007882 "hdd_init_tx_rx() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07007883 status, status );
7884 goto error_init_txrx;
7885 }
7886
7887 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
7888
7889 if( VOS_STATUS_SUCCESS != ( status = hdd_wmm_adapter_init( pAdapter ) ) )
7890 {
7891 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007892 "hdd_wmm_adapter_init() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07007893 status, status );
7894 goto error_wmm_init;
7895 }
7896
7897 set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
7898
7899 return VOS_STATUS_SUCCESS;
7900
7901error_wmm_init:
7902 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
7903 hdd_deinit_tx_rx(pAdapter);
7904error_init_txrx:
7905 hdd_UnregisterWext(pWlanDev);
7906error_register_wext:
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007907 if (test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07007908 {
7909 INIT_COMPLETION(pAdapter->session_close_comp_var);
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007910 if (eHAL_STATUS_SUCCESS == sme_CloseSession(pHddCtx->hHal,
Agrawal Ashish5a3522c2016-03-02 15:08:28 +05307911 pAdapter->sessionId, FALSE, VOS_TRUE,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007912 hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07007913 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307914 unsigned long rc;
7915
Jeff Johnson295189b2012-06-20 16:38:30 -07007916 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307917 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07007918 &pAdapter->session_close_comp_var,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07007919 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307920 if (rc <= 0)
7921 hddLog(VOS_TRACE_LEVEL_ERROR,
7922 FL("Session is not opened within timeout period code %ld"), rc);
Jeff Johnson295189b2012-06-20 16:38:30 -07007923 }
7924}
7925error_sme_open:
7926 return status;
7927}
7928
Jeff Johnson295189b2012-06-20 16:38:30 -07007929void hdd_cleanup_actionframe( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
7930{
7931 hdd_cfg80211_state_t *cfgState;
7932
7933 cfgState = WLAN_HDD_GET_CFG_STATE_PTR( pAdapter );
7934
7935 if( NULL != cfgState->buf )
7936 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307937 long rc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007938 INIT_COMPLETION(pAdapter->tx_action_cnf_event);
7939 rc = wait_for_completion_interruptible_timeout(
7940 &pAdapter->tx_action_cnf_event,
7941 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307942 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07007943 {
Deepthi Gowri91b3e9c2015-08-25 13:14:58 +05307944 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7945 "%s ERROR: HDD Wait for Action Confirmation Failed!! %ld"
7946 , __func__, rc);
7947
7948 // Inform tx status as FAILURE to upper layer and free cfgState->buf
7949 hdd_sendActionCnf( pAdapter, FALSE );
Jeff Johnson295189b2012-06-20 16:38:30 -07007950 }
7951 }
7952 return;
7953}
Jeff Johnson295189b2012-06-20 16:38:30 -07007954
c_hpothu002231a2015-02-05 14:58:51 +05307955void hdd_deinit_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
Jeff Johnson295189b2012-06-20 16:38:30 -07007956{
7957 ENTER();
7958 switch ( pAdapter->device_mode )
7959 {
Katya Nigam1fd24402015-02-16 14:52:19 +05307960 case WLAN_HDD_IBSS:
7961 {
7962 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
7963 {
7964 hdd_ibss_deinit_tx_rx( pAdapter );
7965 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
7966 }
7967 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007968 case WLAN_HDD_INFRA_STATION:
7969 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07007970 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07007971 {
7972 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
7973 {
7974 hdd_deinit_tx_rx( pAdapter );
7975 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
7976 }
7977
7978 if(test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
7979 {
7980 hdd_wmm_adapter_close( pAdapter );
7981 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
7982 }
7983
Jeff Johnson295189b2012-06-20 16:38:30 -07007984 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007985 break;
7986 }
7987
7988 case WLAN_HDD_SOFTAP:
7989 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07007990 {
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05307991
7992 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
7993 {
7994 hdd_wmm_adapter_close( pAdapter );
7995 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
7996 }
7997
Jeff Johnson295189b2012-06-20 16:38:30 -07007998 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007999
c_hpothu002231a2015-02-05 14:58:51 +05308000 hdd_unregister_hostapd(pAdapter, rtnl_held);
Jeff Johnson295189b2012-06-20 16:38:30 -07008001 hdd_set_conparam( 0 );
Jeff Johnson295189b2012-06-20 16:38:30 -07008002 break;
8003 }
8004
8005 case WLAN_HDD_MONITOR:
8006 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008007 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
8008 {
8009 hdd_deinit_tx_rx( pAdapter );
8010 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
8011 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008012 break;
8013 }
8014
8015
8016 default:
8017 break;
8018 }
8019
8020 EXIT();
8021}
8022
8023void hdd_cleanup_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
8024{
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08008025 struct net_device *pWlanDev = NULL;
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05308026
8027 ENTER();
8028 if (NULL == pAdapter)
8029 {
8030 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8031 "%s: HDD adapter is Null", __func__);
8032 return;
8033 }
8034
8035 pWlanDev = pAdapter->dev;
Jeff Johnson295189b2012-06-20 16:38:30 -07008036
Rajeev79dbe4c2013-10-05 11:03:42 +05308037#ifdef FEATURE_WLAN_BATCH_SCAN
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05308038 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
8039 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Rajeev Kumarf999e582014-01-09 17:33:29 -08008040 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05308041 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
8042 )
8043 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08008044 if (pAdapter)
Rajeev79dbe4c2013-10-05 11:03:42 +05308045 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08008046 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
8047 {
8048 hdd_deinit_batch_scan(pAdapter);
8049 }
Rajeev79dbe4c2013-10-05 11:03:42 +05308050 }
Rajeev Kumarf999e582014-01-09 17:33:29 -08008051 }
Rajeev79dbe4c2013-10-05 11:03:42 +05308052#endif
8053
Jeff Johnson295189b2012-06-20 16:38:30 -07008054 if(test_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags)) {
8055 if( rtnl_held )
8056 {
8057 unregister_netdevice(pWlanDev);
8058 }
8059 else
8060 {
8061 unregister_netdev(pWlanDev);
8062 }
8063 // note that the pAdapter is no longer valid at this point
8064 // since the memory has been reclaimed
8065 }
8066
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05308067 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07008068}
8069
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008070void hdd_set_pwrparams(hdd_context_t *pHddCtx)
8071{
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308072 VOS_STATUS status;
8073 hdd_adapter_t *pAdapter = NULL;
8074 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008075
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308076 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008077
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308078 /*loop through all adapters.*/
8079 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008080 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308081 pAdapter = pAdapterNode->pAdapter;
8082 if ( (WLAN_HDD_INFRA_STATION != pAdapter->device_mode)
8083 && (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008084
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308085 { // we skip this registration for modes other than STA and P2P client modes.
8086 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8087 pAdapterNode = pNext;
8088 continue;
8089 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008090
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308091 //Apply Dynamic DTIM For P2P
8092 //Only if ignoreDynamicDtimInP2pMode is not set in ini
8093 if ((pHddCtx->cfg_ini->enableDynamicDTIM ||
8094 pHddCtx->cfg_ini->enableModulatedDTIM) &&
8095 ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
8096 ((WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) &&
8097 !(pHddCtx->cfg_ini->ignoreDynamicDtimInP2pMode))) &&
8098 (eANI_BOOLEAN_TRUE == pAdapter->higherDtimTransition) &&
8099 (eConnectionState_Associated ==
8100 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState) &&
8101 (pHddCtx->cfg_ini->fIsBmpsEnabled))
8102 {
8103 tSirSetPowerParamsReq powerRequest = { 0 };
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008104
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308105 powerRequest.uIgnoreDTIM = 1;
8106 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
8107
8108 if (pHddCtx->cfg_ini->enableModulatedDTIM)
8109 {
8110 powerRequest.uDTIMPeriod = pHddCtx->cfg_ini->enableModulatedDTIM;
8111 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
8112 }
8113 else
8114 {
8115 powerRequest.uListenInterval = pHddCtx->cfg_ini->enableDynamicDTIM;
8116 }
8117
8118 /* Update ignoreDTIM and ListedInterval in CFG to remain at the DTIM
8119 * specified during Enter/Exit BMPS when LCD off*/
8120 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
8121 NULL, eANI_BOOLEAN_FALSE);
8122 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
8123 NULL, eANI_BOOLEAN_FALSE);
8124
8125 /* switch to the DTIM specified in cfg.ini */
8126 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Abhishek Singh1e390cf2015-10-27 13:45:17 +05308127 "Switch to DTIM %d Listen interval %d",
8128 powerRequest.uDTIMPeriod,
8129 powerRequest.uListenInterval);
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308130 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
8131 break;
8132
8133 }
8134
8135 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8136 pAdapterNode = pNext;
8137 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008138}
8139
8140void hdd_reset_pwrparams(hdd_context_t *pHddCtx)
8141{
8142 /*Switch back to DTIM 1*/
8143 tSirSetPowerParamsReq powerRequest = { 0 };
8144
8145 powerRequest.uIgnoreDTIM = pHddCtx->hdd_actual_ignore_DTIM_value;
8146 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
Yue Mac24062f2013-05-13 17:01:29 -07008147 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08008148
8149 /* Update ignoreDTIM and ListedInterval in CFG with default values */
8150 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
8151 NULL, eANI_BOOLEAN_FALSE);
8152 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
8153 NULL, eANI_BOOLEAN_FALSE);
8154
8155 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8156 "Switch to DTIM%d",powerRequest.uListenInterval);
8157 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
8158
8159}
8160
Jeff Johnson295189b2012-06-20 16:38:30 -07008161VOS_STATUS hdd_enable_bmps_imps(hdd_context_t *pHddCtx)
8162{
8163 VOS_STATUS status = VOS_STATUS_SUCCESS;
Sushant Kaushik4928e542014-12-29 15:25:54 +05308164 if (WLAN_HDD_IS_UNLOAD_IN_PROGRESS(pHddCtx))
8165 {
8166 hddLog( LOGE, FL("Wlan Unload in progress"));
8167 return VOS_STATUS_E_PERM;
8168 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008169 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
8170 {
8171 sme_EnablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
8172 }
8173
8174 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
8175 {
8176 sme_StartAutoBmpsTimer(pHddCtx->hHal);
8177 }
8178
8179 if (pHddCtx->cfg_ini->fIsImpsEnabled)
8180 {
8181 sme_EnablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
8182 }
8183
8184 return status;
8185}
8186
8187VOS_STATUS hdd_disable_bmps_imps(hdd_context_t *pHddCtx, tANI_U8 session_type)
8188{
8189 hdd_adapter_t *pAdapter = NULL;
8190 eHalStatus halStatus;
8191 VOS_STATUS status = VOS_STATUS_E_INVAL;
8192 v_BOOL_t disableBmps = FALSE;
8193 v_BOOL_t disableImps = FALSE;
8194
8195 switch(session_type)
8196 {
8197 case WLAN_HDD_INFRA_STATION:
8198 case WLAN_HDD_SOFTAP:
Jeff Johnson295189b2012-06-20 16:38:30 -07008199 case WLAN_HDD_P2P_CLIENT:
8200 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07008201 //Exit BMPS -> Is Sta/P2P Client is already connected
8202 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
8203 if((NULL != pAdapter)&&
8204 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
8205 {
8206 disableBmps = TRUE;
8207 }
8208
8209 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_CLIENT);
8210 if((NULL != pAdapter)&&
8211 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
8212 {
8213 disableBmps = TRUE;
8214 }
8215
8216 //Exit both Bmps and Imps incase of Go/SAP Mode
8217 if((WLAN_HDD_SOFTAP == session_type) ||
8218 (WLAN_HDD_P2P_GO == session_type))
8219 {
8220 disableBmps = TRUE;
8221 disableImps = TRUE;
8222 }
8223
8224 if(TRUE == disableImps)
8225 {
8226 if (pHddCtx->cfg_ini->fIsImpsEnabled)
8227 {
8228 sme_DisablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
8229 }
8230 }
8231
8232 if(TRUE == disableBmps)
8233 {
8234 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
8235 {
8236 halStatus = sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
8237
8238 if(eHAL_STATUS_SUCCESS != halStatus)
8239 {
8240 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08008241 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Disable Power Save", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008242 VOS_ASSERT(0);
8243 return status;
8244 }
8245 }
8246
8247 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
8248 {
8249 halStatus = sme_StopAutoBmpsTimer(pHddCtx->hHal);
8250
8251 if(eHAL_STATUS_SUCCESS != halStatus)
8252 {
8253 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08008254 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Stop Auto Bmps Timer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008255 VOS_ASSERT(0);
8256 return status;
8257 }
8258 }
8259 }
8260
8261 if((TRUE == disableBmps) ||
8262 (TRUE == disableImps))
8263 {
8264 /* Now, get the chip into Full Power now */
8265 INIT_COMPLETION(pHddCtx->full_pwr_comp_var);
8266 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_pwr_cbk,
8267 pHddCtx, eSME_FULL_PWR_NEEDED_BY_HDD);
8268
8269 if(halStatus != eHAL_STATUS_SUCCESS)
8270 {
8271 if(halStatus == eHAL_STATUS_PMC_PENDING)
8272 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308273 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07008274 //Block on a completion variable. Can't wait forever though
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308275 ret = wait_for_completion_interruptible_timeout(
8276 &pHddCtx->full_pwr_comp_var,
8277 msecs_to_jiffies(1000));
8278 if (ret <= 0)
8279 {
8280 hddLog(VOS_TRACE_LEVEL_ERROR,
8281 "%s: wait on full_pwr_comp_var failed %ld",
8282 __func__, ret);
8283 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008284 }
8285 else
8286 {
8287 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08008288 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Request for Full Power failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008289 VOS_ASSERT(0);
8290 return status;
8291 }
8292 }
8293
8294 status = VOS_STATUS_SUCCESS;
8295 }
8296
8297 break;
8298 }
8299 return status;
8300}
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05308301
8302void hdd_monPostMsgCb(tANI_U32 *magic, struct completion *cmpVar)
8303{
8304 if (magic == NULL || cmpVar == NULL) {
8305 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8306 FL("invalid arguments %p %p"), magic, cmpVar);
8307 return;
8308 }
8309 if (*magic != MON_MODE_MSG_MAGIC) {
8310 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8311 FL("maic: %x"), *magic);
8312 return;
8313 }
8314
8315 complete(cmpVar);
8316 return;
8317}
8318
Katya Nigame7b69a82015-04-28 15:24:06 +05308319void hdd_init_mon_mode (hdd_adapter_t *pAdapter)
8320 {
8321 hdd_mon_ctx_t *pMonCtx = NULL;
8322 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
8323
8324 pMonCtx->state = 0;
8325 pMonCtx->ChannelNo = 1;
8326 pMonCtx->ChannelBW = 20;
Katya Nigamd7d3a1f2015-06-11 14:04:24 +05308327 pMonCtx->crcCheckEnabled = 1;
8328 pMonCtx->typeSubtypeBitmap = 0xFFFF00000000;
8329 pMonCtx->is80211to803ConReq = 1;
Katya Nigame7b69a82015-04-28 15:24:06 +05308330 pMonCtx->numOfMacFilters = 0;
8331 }
8332
Jeff Johnson295189b2012-06-20 16:38:30 -07008333
8334hdd_adapter_t* hdd_open_adapter( hdd_context_t *pHddCtx, tANI_U8 session_type,
Jeff Johnsoneed415b2013-01-18 16:11:20 -08008335 const char *iface_name, tSirMacAddr macAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -07008336 tANI_U8 rtnl_held )
8337{
8338 hdd_adapter_t *pAdapter = NULL;
8339 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
8340 VOS_STATUS status = VOS_STATUS_E_FAILURE;
8341 VOS_STATUS exitbmpsStatus;
8342
Arif Hussain6d2a3322013-11-17 19:50:10 -08008343 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s iface =%s type = %d",__func__,iface_name,session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07008344
Nirav Shah436658f2014-02-28 17:05:45 +05308345 if(macAddr == NULL)
8346 {
8347 /* Not received valid macAddr */
8348 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8349 "%s:Unable to add virtual intf: Not able to get"
8350 "valid mac address",__func__);
8351 return NULL;
8352 }
8353
Jeff Johnson295189b2012-06-20 16:38:30 -07008354 //Disable BMPS incase of Concurrency
8355 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, session_type);
8356
8357 if(VOS_STATUS_E_FAILURE == exitbmpsStatus)
8358 {
8359 //Fail to Exit BMPS
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308360 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Exit BMPS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008361 VOS_ASSERT(0);
8362 return NULL;
8363 }
8364
8365 switch(session_type)
8366 {
8367 case WLAN_HDD_INFRA_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07008368 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07008369 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07008370 {
8371 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
8372
8373 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308374 {
8375 hddLog(VOS_TRACE_LEVEL_FATAL,
8376 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07008377 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308378 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008379
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308380#ifdef FEATURE_WLAN_TDLS
8381 /* A Mutex Lock is introduced while changing/initializing the mode to
8382 * protect the concurrent access for the Adapters by TDLS module.
8383 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05308384 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308385#endif
8386
Jeff Johnsone7245742012-09-05 17:12:55 -07008387 pAdapter->wdev.iftype = (session_type == WLAN_HDD_P2P_CLIENT) ?
8388 NL80211_IFTYPE_P2P_CLIENT:
8389 NL80211_IFTYPE_STATION;
Jeff Johnson295189b2012-06-20 16:38:30 -07008390
Jeff Johnson295189b2012-06-20 16:38:30 -07008391 pAdapter->device_mode = session_type;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308392#ifdef FEATURE_WLAN_TDLS
8393 mutex_unlock(&pHddCtx->tdls_lock);
8394#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05308395
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05308396 hdd_initialize_adapter_common(pAdapter);
Sunil Dutt66485cb2013-12-19 19:05:03 +05308397 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07008398 if( VOS_STATUS_SUCCESS != status )
8399 goto err_free_netdev;
8400
8401 status = hdd_register_interface( pAdapter, rtnl_held );
8402 if( VOS_STATUS_SUCCESS != status )
8403 {
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308404#ifdef FEATURE_WLAN_TDLS
8405 mutex_lock(&pHddCtx->tdls_lock);
8406#endif
c_hpothu002231a2015-02-05 14:58:51 +05308407 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +05308408#ifdef FEATURE_WLAN_TDLS
8409 mutex_unlock(&pHddCtx->tdls_lock);
8410#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008411 goto err_free_netdev;
8412 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05308413
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05308414 // Workqueue which gets scheduled in IPv4 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05308415 vos_init_work(&pAdapter->ipv4NotifierWorkQueue, hdd_ipv4_notifier_work_queue);
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05308416
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05308417#ifdef WLAN_NS_OFFLOAD
8418 // Workqueue which gets scheduled in IPv6 notification callback.
Anand N Sunkaddc63c792015-06-03 14:33:24 +05308419 vos_init_work(&pAdapter->ipv6NotifierWorkQueue, hdd_ipv6_notifier_work_queue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05308420#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008421 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308422 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008423 netif_tx_disable(pAdapter->dev);
8424 //netif_tx_disable(pWlanDev);
8425 netif_carrier_off(pAdapter->dev);
8426
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05308427 if (WLAN_HDD_P2P_CLIENT == session_type ||
8428 WLAN_HDD_P2P_DEVICE == session_type)
8429 {
8430 /* Initialize the work queue to defer the
8431 * back to back RoC request */
Anand N Sunkaddc63c792015-06-03 14:33:24 +05308432 vos_init_delayed_work(&pAdapter->roc_work,
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05308433 hdd_p2p_roc_work_queue);
8434 }
8435
Jeff Johnson295189b2012-06-20 16:38:30 -07008436 break;
8437 }
8438
Jeff Johnson295189b2012-06-20 16:38:30 -07008439 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07008440 case WLAN_HDD_SOFTAP:
8441 {
8442 pAdapter = hdd_wlan_create_ap_dev( pHddCtx, macAddr, (tANI_U8 *)iface_name );
8443 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308444 {
8445 hddLog(VOS_TRACE_LEVEL_FATAL,
8446 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07008447 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308448 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008449
Jeff Johnson295189b2012-06-20 16:38:30 -07008450 pAdapter->wdev.iftype = (session_type == WLAN_HDD_SOFTAP) ?
8451 NL80211_IFTYPE_AP:
8452 NL80211_IFTYPE_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07008453 pAdapter->device_mode = session_type;
8454
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05308455 hdd_initialize_adapter_common(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07008456 status = hdd_init_ap_mode(pAdapter);
8457 if( VOS_STATUS_SUCCESS != status )
8458 goto err_free_netdev;
8459
Nirav Shah7e3c8132015-06-22 23:51:42 +05308460 status = hdd_sta_id_hash_attach(pAdapter);
8461 if (VOS_STATUS_SUCCESS != status)
8462 {
8463 hddLog(VOS_TRACE_LEVEL_FATAL,
8464 FL("failed to attach hash for session %d"), session_type);
8465 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
8466 goto err_free_netdev;
8467 }
8468
Jeff Johnson295189b2012-06-20 16:38:30 -07008469 status = hdd_register_hostapd( pAdapter, rtnl_held );
8470 if( VOS_STATUS_SUCCESS != status )
8471 {
c_hpothu002231a2015-02-05 14:58:51 +05308472 hdd_deinit_adapter(pHddCtx, pAdapter, rtnl_held);
Jeff Johnson295189b2012-06-20 16:38:30 -07008473 goto err_free_netdev;
8474 }
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308475 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008476 netif_tx_disable(pAdapter->dev);
8477 netif_carrier_off(pAdapter->dev);
8478
8479 hdd_set_conparam( 1 );
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05308480
8481 if (WLAN_HDD_P2P_GO == session_type)
8482 {
8483 /* Initialize the work queue to
8484 * defer the back to back RoC request */
8485 INIT_DELAYED_WORK(&pAdapter->roc_work,
8486 hdd_p2p_roc_work_queue);
8487 }
Bhargav Shahd0715912015-10-01 18:17:37 +05308488
Jeff Johnson295189b2012-06-20 16:38:30 -07008489 break;
8490 }
8491 case WLAN_HDD_MONITOR:
8492 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008493 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
8494 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308495 {
8496 hddLog(VOS_TRACE_LEVEL_FATAL,
8497 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07008498 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308499 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008500
Katya Nigame7b69a82015-04-28 15:24:06 +05308501 // Register wireless extensions
8502 if( VOS_STATUS_SUCCESS != (status = hdd_register_wext(pAdapter->dev)))
8503 {
8504 hddLog(VOS_TRACE_LEVEL_FATAL,
8505 "hdd_register_wext() failed with status code %08d [x%08x]",
8506 status, status );
8507 status = VOS_STATUS_E_FAILURE;
8508 }
8509
Jeff Johnson295189b2012-06-20 16:38:30 -07008510 pAdapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
8511 pAdapter->device_mode = session_type;
Jeff Johnson295189b2012-06-20 16:38:30 -07008512#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29)
8513 pAdapter->dev->netdev_ops = &wlan_mon_drv_ops;
8514#else
8515 pAdapter->dev->open = hdd_mon_open;
8516 pAdapter->dev->hard_start_xmit = hdd_mon_hard_start_xmit;
Katya Nigame7b69a82015-04-28 15:24:06 +05308517 pAdapter->dev->stop = hdd_mon_stop;
8518 pAdapter->dev->do_ioctl = hdd_mon_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07008519#endif
Katya Nigame7b69a82015-04-28 15:24:06 +05308520 status = hdd_register_interface( pAdapter, rtnl_held );
8521 hdd_init_mon_mode( pAdapter );
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05308522 hdd_initialize_adapter_common(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07008523 hdd_init_tx_rx( pAdapter );
8524 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
Katya Nigame7b69a82015-04-28 15:24:06 +05308525 //Stop the Interface TX queue.
8526 netif_tx_disable(pAdapter->dev);
8527 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07008528 }
8529 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07008530 case WLAN_HDD_FTM:
8531 {
8532 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
8533
8534 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308535 {
8536 hddLog(VOS_TRACE_LEVEL_FATAL,
8537 FL("failed to allocate adapter for session %d"), session_type);
8538 return NULL;
8539 }
8540
Jeff Johnson295189b2012-06-20 16:38:30 -07008541 /* Assign NL80211_IFTYPE_STATION as interface type to resolve Kernel Warning
8542 * message while loading driver in FTM mode. */
8543 pAdapter->wdev.iftype = NL80211_IFTYPE_STATION;
8544 pAdapter->device_mode = session_type;
8545 status = hdd_register_interface( pAdapter, rtnl_held );
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05308546
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05308547 hdd_initialize_adapter_common(pAdapter);
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05308548 hdd_init_tx_rx( pAdapter );
8549
8550 //Stop the Interface TX queue.
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05308551 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05308552 netif_tx_disable(pAdapter->dev);
8553 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07008554 }
8555 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07008556 default:
8557 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308558 hddLog(VOS_TRACE_LEVEL_FATAL,"%s Invalid session type %d",
8559 __func__, session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07008560 VOS_ASSERT(0);
8561 return NULL;
8562 }
8563 }
8564
Jeff Johnson295189b2012-06-20 16:38:30 -07008565 if( VOS_STATUS_SUCCESS == status )
8566 {
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +05308567 //Add it to the hdd's session list.
Jeff Johnson295189b2012-06-20 16:38:30 -07008568 pHddAdapterNode = vos_mem_malloc( sizeof( hdd_adapter_list_node_t ) );
8569 if( NULL == pHddAdapterNode )
8570 {
8571 status = VOS_STATUS_E_NOMEM;
8572 }
8573 else
8574 {
8575 pHddAdapterNode->pAdapter = pAdapter;
8576 status = hdd_add_adapter_back ( pHddCtx,
8577 pHddAdapterNode );
8578 }
8579 }
8580
8581 if( VOS_STATUS_SUCCESS != status )
8582 {
8583 if( NULL != pAdapter )
8584 {
8585 hdd_cleanup_adapter( pHddCtx, pAdapter, rtnl_held );
8586 pAdapter = NULL;
8587 }
8588 if( NULL != pHddAdapterNode )
8589 {
8590 vos_mem_free( pHddAdapterNode );
8591 }
8592
8593 goto resume_bmps;
8594 }
8595
8596 if(VOS_STATUS_SUCCESS == status)
8597 {
8598 wlan_hdd_set_concurrency_mode(pHddCtx, session_type);
8599
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -07008600 //Initialize the WoWL service
8601 if(!hdd_init_wowl(pAdapter))
8602 {
8603 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_init_wowl failed",__func__);
8604 goto err_free_netdev;
8605 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008606 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008607 return pAdapter;
8608
8609err_free_netdev:
8610 free_netdev(pAdapter->dev);
8611 wlan_hdd_release_intf_addr( pHddCtx,
8612 pAdapter->macAddressCurrent.bytes );
8613
8614resume_bmps:
8615 //If bmps disabled enable it
8616 if(VOS_STATUS_SUCCESS == exitbmpsStatus)
8617 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308618 if (pHddCtx->hdd_wlan_suspended)
8619 {
8620 hdd_set_pwrparams(pHddCtx);
8621 }
8622 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07008623 }
8624 return NULL;
8625}
8626
8627VOS_STATUS hdd_close_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
8628 tANI_U8 rtnl_held )
8629{
8630 hdd_adapter_list_node_t *pAdapterNode, *pCurrent, *pNext;
8631 VOS_STATUS status;
8632
8633 status = hdd_get_front_adapter ( pHddCtx, &pCurrent );
8634 if( VOS_STATUS_SUCCESS != status )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308635 {
8636 hddLog(VOS_TRACE_LEVEL_WARN,"%s: adapter list empty %d",
8637 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008638 return status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308639 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008640
8641 while ( pCurrent->pAdapter != pAdapter )
8642 {
8643 status = hdd_get_next_adapter ( pHddCtx, pCurrent, &pNext );
8644 if( VOS_STATUS_SUCCESS != status )
8645 break;
8646
8647 pCurrent = pNext;
8648 }
8649 pAdapterNode = pCurrent;
8650 if( VOS_STATUS_SUCCESS == status )
8651 {
8652 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
8653 hdd_cleanup_adapter( pHddCtx, pAdapterNode->pAdapter, rtnl_held );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308654
8655#ifdef FEATURE_WLAN_TDLS
8656
8657 /* A Mutex Lock is introduced while changing/initializing the mode to
8658 * protect the concurrent access for the Adapters by TDLS module.
8659 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05308660 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308661#endif
8662
Jeff Johnson295189b2012-06-20 16:38:30 -07008663 hdd_remove_adapter( pHddCtx, pAdapterNode );
8664 vos_mem_free( pAdapterNode );
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08008665 pAdapterNode = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008666
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308667#ifdef FEATURE_WLAN_TDLS
8668 mutex_unlock(&pHddCtx->tdls_lock);
8669#endif
8670
Jeff Johnson295189b2012-06-20 16:38:30 -07008671
8672 /* If there is a single session of STA/P2P client, re-enable BMPS */
Agarwal Ashish51325b52014-06-16 16:50:49 +05308673 if ((!vos_concurrent_open_sessions_running()) &&
8674 ((pHddCtx->no_of_open_sessions[VOS_STA_MODE] >= 1) ||
8675 (pHddCtx->no_of_open_sessions[VOS_P2P_CLIENT_MODE] >= 1)))
Jeff Johnson295189b2012-06-20 16:38:30 -07008676 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308677 if (pHddCtx->hdd_wlan_suspended)
8678 {
8679 hdd_set_pwrparams(pHddCtx);
8680 }
8681 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07008682 }
8683
8684 return VOS_STATUS_SUCCESS;
8685 }
8686
8687 return VOS_STATUS_E_FAILURE;
8688}
8689
8690VOS_STATUS hdd_close_all_adapters( hdd_context_t *pHddCtx )
8691{
8692 hdd_adapter_list_node_t *pHddAdapterNode;
8693 VOS_STATUS status;
8694
8695 ENTER();
8696
8697 do
8698 {
8699 status = hdd_remove_front_adapter( pHddCtx, &pHddAdapterNode );
8700 if( pHddAdapterNode && VOS_STATUS_SUCCESS == status )
8701 {
8702 hdd_cleanup_adapter( pHddCtx, pHddAdapterNode->pAdapter, FALSE );
8703 vos_mem_free( pHddAdapterNode );
8704 }
8705 }while( NULL != pHddAdapterNode && VOS_STATUS_E_EMPTY != status );
8706
8707 EXIT();
8708
8709 return VOS_STATUS_SUCCESS;
8710}
8711
8712void wlan_hdd_reset_prob_rspies(hdd_adapter_t* pHostapdAdapter)
8713{
8714 v_U8_t addIE[1] = {0};
8715
8716 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
8717 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,(tANI_U8*)addIE, 0, NULL,
8718 eANI_BOOLEAN_FALSE) )
8719 {
8720 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08008721 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07008722 }
8723
8724 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
8725 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
8726 eANI_BOOLEAN_FALSE) )
8727 {
8728 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08008729 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07008730 }
8731
8732 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
8733 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
8734 eANI_BOOLEAN_FALSE) )
8735 {
8736 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08008737 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07008738 }
8739}
8740
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308741VOS_STATUS hdd_stop_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
8742 const v_BOOL_t bCloseSession )
Jeff Johnson295189b2012-06-20 16:38:30 -07008743{
8744 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
8745 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Kaushik, Sushant4975a572014-10-21 16:07:48 +05308746 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008747 union iwreq_data wrqu;
Kaushik, Sushant7005e372014-04-08 11:36:54 +05308748 v_U8_t retry = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308749 long ret;
Nirav Shah7e3c8132015-06-22 23:51:42 +05308750 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008751
Anand N Sunkad26d71b92014-12-24 18:08:22 +05308752 if (pHddCtx->isLogpInProgress) {
8753 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8754 "%s:LOGP in Progress. Ignore!!!",__func__);
8755 return VOS_STATUS_E_FAILURE;
8756 }
8757
Jeff Johnson295189b2012-06-20 16:38:30 -07008758 ENTER();
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +05308759
Kaushik, Sushant4975a572014-10-21 16:07:48 +05308760 pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07008761 switch(pAdapter->device_mode)
8762 {
Nirav Shah0cf4d892015-11-05 16:27:27 +05308763 case WLAN_HDD_IBSS:
8764 if ( VOS_TRUE == bCloseSession )
8765 {
8766 status = hdd_sta_id_hash_detach(pAdapter);
8767 if (status != VOS_STATUS_SUCCESS)
8768 hddLog(VOS_TRACE_LEVEL_ERROR,
8769 FL("sta id hash detach failed"));
8770 }
8771
Jeff Johnson295189b2012-06-20 16:38:30 -07008772 case WLAN_HDD_INFRA_STATION:
8773 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07008774 case WLAN_HDD_P2P_DEVICE:
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05308775 {
8776 hdd_station_ctx_t *pstation = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Mahesh A Saptasagare4d05d42015-07-02 16:17:20 +05308777#ifdef FEATURE_WLAN_TDLS
8778 mutex_lock(&pHddCtx->tdls_lock);
8779 wlan_hdd_tdls_exit(pAdapter, TRUE);
8780 mutex_unlock(&pHddCtx->tdls_lock);
8781#endif
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05308782 if( hdd_connIsConnected(pstation) ||
8783 (pstation->conn_info.connState == eConnectionState_Connecting) )
Jeff Johnson295189b2012-06-20 16:38:30 -07008784 {
8785 if (pWextState->roamProfile.BSSType == eCSR_BSS_TYPE_START_IBSS)
8786 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
8787 pAdapter->sessionId,
8788 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
8789 else
8790 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
8791 pAdapter->sessionId,
8792 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Abhishek Singh7b52ed52016-02-11 17:45:54 +05308793 /* Success implies disconnect command got queued up successfully
8794 * Or cmd not queued as scan for SSID is in progress
8795 */
8796 if((eHAL_STATUS_SUCCESS == halStatus) ||
8797 (eHAL_STATUS_CMD_NOT_QUEUED == halStatus))
Jeff Johnson295189b2012-06-20 16:38:30 -07008798 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308799 ret = wait_for_completion_interruptible_timeout(
8800 &pAdapter->disconnect_comp_var,
8801 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Abhishek Singh7b52ed52016-02-11 17:45:54 +05308802 if (ret <= 0 &&
8803 (eHAL_STATUS_CMD_NOT_QUEUED != halStatus))
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308804 {
8805 hddLog(VOS_TRACE_LEVEL_ERROR,
8806 "%s: wait on disconnect_comp_var failed %ld",
8807 __func__, ret);
8808 }
8809 }
8810 else
8811 {
8812 hddLog(LOGE, "%s: failed to post disconnect event to SME",
8813 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008814 }
8815 memset(&wrqu, '\0', sizeof(wrqu));
8816 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8817 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
8818 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
8819 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05308820 else if(pstation->conn_info.connState ==
8821 eConnectionState_Disconnecting)
8822 {
8823 ret = wait_for_completion_interruptible_timeout(
8824 &pAdapter->disconnect_comp_var,
8825 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
8826 if (ret <= 0)
8827 {
8828 hddLog(VOS_TRACE_LEVEL_ERROR,
8829 FL("wait on disconnect_comp_var failed %ld"), ret);
8830 }
8831 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +05308832 else if(pScanInfo != NULL && pHddCtx->scan_info.mScanPending)
Jeff Johnson295189b2012-06-20 16:38:30 -07008833 {
Mahesh A Saptasagar0b61dcc2016-02-15 14:23:38 +05308834 wlan_hdd_scan_abort(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07008835 }
Abhishek Singh3ac179b2015-09-21 10:01:34 +05308836 if ((pAdapter->device_mode != WLAN_HDD_INFRA_STATION) &&
8837 (pAdapter->device_mode != WLAN_HDD_IBSS))
Kaushik, Sushant7005e372014-04-08 11:36:54 +05308838 {
8839 while (pAdapter->is_roc_inprogress)
8840 {
8841 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8842 "%s: ROC in progress for session %d!!!",
8843 __func__, pAdapter->sessionId);
8844 // waiting for ROC to expire
8845 msleep(500);
8846 /* In GO present case , if retry exceeds 3,
8847 it means something went wrong. */
8848 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION )
8849 {
8850 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8851 "%s: ROC completion is not received.!!!", __func__);
Deepthi Gowri70498252015-01-20 15:56:45 +05308852 if (eHAL_STATUS_SUCCESS !=
8853 sme_CancelRemainOnChannel( WLAN_HDD_GET_HAL_CTX( pAdapter),
8854 pAdapter->sessionId ))
8855 {
8856 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8857 FL("Failed to Cancel Remain on Channel"));
8858 }
Kaushik, Sushant7005e372014-04-08 11:36:54 +05308859 wait_for_completion_interruptible_timeout(
8860 &pAdapter->cancel_rem_on_chan_var,
8861 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
8862 break;
8863 }
8864 }
Anand N Sunkaddc63c792015-06-03 14:33:24 +05308865 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +05308866 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05308867#ifdef WLAN_NS_OFFLOAD
Anand N Sunkaddc63c792015-06-03 14:33:24 +05308868 vos_flush_work(&pAdapter->ipv6NotifierWorkQueue);
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05308869#endif
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +05308870
Anand N Sunkaddc63c792015-06-03 14:33:24 +05308871 vos_flush_work(&pAdapter->ipv4NotifierWorkQueue);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +05308872
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308873 /* It is possible that the caller of this function does not
8874 * wish to close the session
8875 */
8876 if (VOS_TRUE == bCloseSession &&
8877 test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07008878 {
8879 INIT_COMPLETION(pAdapter->session_close_comp_var);
8880 if (eHAL_STATUS_SUCCESS ==
Agrawal Ashish5a3522c2016-03-02 15:08:28 +05308881 sme_CloseSession(pHddCtx->hHal, pAdapter->sessionId, FALSE,
8882 VOS_FALSE, hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07008883 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308884 unsigned long ret;
8885
Jeff Johnson295189b2012-06-20 16:38:30 -07008886 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308887 ret = wait_for_completion_timeout(
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308888 &pAdapter->session_close_comp_var,
8889 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308890 if ( 0 >= ret)
8891 {
8892 hddLog(LOGE, "%s: failure waiting for session_close_comp_var %ld",
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05308893 __func__, ret);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308894 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008895 }
8896 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05308897 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008898 break;
8899
8900 case WLAN_HDD_SOFTAP:
8901 case WLAN_HDD_P2P_GO:
Nirav Shah0cf4d892015-11-05 16:27:27 +05308902 if ( VOS_TRUE == bCloseSession )
8903 {
8904 status = hdd_sta_id_hash_detach(pAdapter);
8905 if (status != VOS_STATUS_SUCCESS)
8906 hddLog(VOS_TRACE_LEVEL_ERROR,
8907 FL("sta id hash detach failed"));
8908 }
8909
Jeff Johnson295189b2012-06-20 16:38:30 -07008910 //Any softap specific cleanup here...
Kaushik, Sushant7005e372014-04-08 11:36:54 +05308911 if (pAdapter->device_mode == WLAN_HDD_P2P_GO) {
8912 while (pAdapter->is_roc_inprogress) {
8913 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8914 "%s: ROC in progress for session %d!!!",
8915 __func__, pAdapter->sessionId);
8916 msleep(500);
8917 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION ) {
8918 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8919 "%s: ROC completion is not received.!!!", __func__);
8920 WLANSAP_CancelRemainOnChannel(
8921 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
8922 wait_for_completion_interruptible_timeout(
8923 &pAdapter->cancel_rem_on_chan_var,
8924 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
8925 break;
8926 }
8927 }
Ganesh Kondabattinibabfb492014-12-17 20:25:29 +05308928
Anand N Sunkaddc63c792015-06-03 14:33:24 +05308929 vos_flush_delayed_work(&pAdapter->roc_work);
Kaushik, Sushant7005e372014-04-08 11:36:54 +05308930 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008931 mutex_lock(&pHddCtx->sap_lock);
8932 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
8933 {
8934 VOS_STATUS status;
8935 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8936
8937 //Stop Bss.
8938 status = WLANSAP_StopBss(pHddCtx->pvosContext);
8939 if (VOS_IS_STATUS_SUCCESS(status))
8940 {
8941 hdd_hostapd_state_t *pHostapdState =
8942 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8943
8944 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
8945
8946 if (!VOS_IS_STATUS_SUCCESS(status))
8947 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308948 hddLog(LOGE, "%s: failure waiting for WLANSAP_StopBss %d",
8949 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07008950 }
8951 }
8952 else
8953 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008954 hddLog(LOGE, "%s: failure in WLANSAP_StopBss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008955 }
8956 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
Agarwal Ashish51325b52014-06-16 16:50:49 +05308957 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07008958
8959 if (eHAL_STATUS_FAILURE ==
8960 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
8961 0, NULL, eANI_BOOLEAN_FALSE))
8962 {
8963 hddLog(LOGE,
8964 "%s: Failed to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008965 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008966 }
8967
8968 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pAdapter))->hHal,
8969 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
8970 eANI_BOOLEAN_FALSE) )
8971 {
8972 hddLog(LOGE,
8973 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
8974 }
8975
8976 // Reset WNI_CFG_PROBE_RSP Flags
8977 wlan_hdd_reset_prob_rspies(pAdapter);
8978 kfree(pAdapter->sessionCtx.ap.beacon);
8979 pAdapter->sessionCtx.ap.beacon = NULL;
8980 }
8981 mutex_unlock(&pHddCtx->sap_lock);
8982 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -07008983
Jeff Johnson295189b2012-06-20 16:38:30 -07008984 case WLAN_HDD_MONITOR:
8985 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -07008986
Jeff Johnson295189b2012-06-20 16:38:30 -07008987 default:
8988 break;
8989 }
8990
8991 EXIT();
8992 return VOS_STATUS_SUCCESS;
8993}
8994
8995VOS_STATUS hdd_stop_all_adapters( hdd_context_t *pHddCtx )
8996{
8997 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8998 VOS_STATUS status;
8999 hdd_adapter_t *pAdapter;
9000
9001 ENTER();
9002
9003 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9004
9005 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9006 {
9007 pAdapter = pAdapterNode->pAdapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07009008
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05309009 hdd_stop_adapter( pHddCtx, pAdapter, VOS_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07009010
9011 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9012 pAdapterNode = pNext;
9013 }
9014
9015 EXIT();
9016
9017 return VOS_STATUS_SUCCESS;
9018}
9019
Rajeev Kumarf999e582014-01-09 17:33:29 -08009020
9021#ifdef FEATURE_WLAN_BATCH_SCAN
9022/**---------------------------------------------------------------------------
9023
9024 \brief hdd_deinit_batch_scan () - This function cleans up batch scan data
9025 structures
9026
9027 \param - pAdapter Pointer to HDD adapter
9028
9029 \return - None
9030
9031 --------------------------------------------------------------------------*/
9032void hdd_deinit_batch_scan(hdd_adapter_t *pAdapter)
9033{
9034 tHddBatchScanRsp *pNode;
9035 tHddBatchScanRsp *pPrev;
9036
Siddharth Bhalb3e9b792014-02-24 15:14:16 +05309037 if (NULL == pAdapter)
Rajeev Kumarf999e582014-01-09 17:33:29 -08009038 {
Siddharth Bhalb3e9b792014-02-24 15:14:16 +05309039 hddLog(VOS_TRACE_LEVEL_ERROR,
9040 "%s: Adapter context is Null", __func__);
9041 return;
9042 }
9043
9044 pNode = pAdapter->pBatchScanRsp;
9045 while (pNode)
9046 {
9047 pPrev = pNode;
9048 pNode = pNode->pNext;
9049 vos_mem_free((v_VOID_t * )pPrev);
Rajeev Kumarf999e582014-01-09 17:33:29 -08009050 }
9051
9052 pAdapter->pBatchScanRsp = NULL;
9053 pAdapter->numScanList = 0;
9054 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
9055 pAdapter->prev_batch_id = 0;
9056
9057 return;
9058}
9059#endif
9060
9061
Jeff Johnson295189b2012-06-20 16:38:30 -07009062VOS_STATUS hdd_reset_all_adapters( hdd_context_t *pHddCtx )
9063{
9064 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9065 VOS_STATUS status;
9066 hdd_adapter_t *pAdapter;
9067
9068 ENTER();
9069
9070 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9071
9072 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9073 {
9074 pAdapter = pAdapterNode->pAdapter;
Padma, Santhosh Kumar9dacb5c2014-12-17 19:22:56 +05309075 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
Jeff Johnson295189b2012-06-20 16:38:30 -07009076 netif_tx_disable(pAdapter->dev);
9077 netif_carrier_off(pAdapter->dev);
9078
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -07009079 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
9080
Jeff Johnson295189b2012-06-20 16:38:30 -07009081 hdd_deinit_tx_rx(pAdapter);
Agarwal Ashish6267caa2014-08-06 19:16:21 +05309082
Katya Nigam1fd24402015-02-16 14:52:19 +05309083 if(pAdapter->device_mode == WLAN_HDD_IBSS )
9084 hdd_ibss_deinit_tx_rx(pAdapter);
9085
Nirav Shah7e3c8132015-06-22 23:51:42 +05309086 status = hdd_sta_id_hash_detach(pAdapter);
9087 if (status != VOS_STATUS_SUCCESS)
9088 hddLog(VOS_TRACE_LEVEL_ERROR,
9089 FL("sta id hash detach failed for session id %d"),
9090 pAdapter->sessionId);
9091
Agarwal Ashish6267caa2014-08-06 19:16:21 +05309092 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
9093
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05309094 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
9095 {
9096 hdd_wmm_adapter_close( pAdapter );
9097 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
9098 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009099
Siddharth Bhal2db319d2014-12-03 12:37:18 +05309100 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
9101 {
9102 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
9103 }
9104
Rajeev Kumarf999e582014-01-09 17:33:29 -08009105#ifdef FEATURE_WLAN_BATCH_SCAN
9106 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
9107 {
9108 hdd_deinit_batch_scan(pAdapter);
9109 }
9110#endif
9111
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05309112#ifdef FEATURE_WLAN_TDLS
9113 mutex_lock(&pHddCtx->tdls_lock);
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05309114 wlan_hdd_tdls_exit(pAdapter, TRUE);
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05309115 mutex_unlock(&pHddCtx->tdls_lock);
9116#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009117 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9118 pAdapterNode = pNext;
9119 }
9120
9121 EXIT();
9122
9123 return VOS_STATUS_SUCCESS;
9124}
9125
9126VOS_STATUS hdd_start_all_adapters( hdd_context_t *pHddCtx )
9127{
9128 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9129 VOS_STATUS status;
9130 hdd_adapter_t *pAdapter;
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05309131 eConnectionState connState;
Jeff Johnson295189b2012-06-20 16:38:30 -07009132
9133 ENTER();
9134
9135 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9136
9137 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9138 {
9139 pAdapter = pAdapterNode->pAdapter;
9140
Kumar Anand82c009f2014-05-29 00:29:42 -07009141 hdd_wmm_init( pAdapter );
9142
Jeff Johnson295189b2012-06-20 16:38:30 -07009143 switch(pAdapter->device_mode)
9144 {
9145 case WLAN_HDD_INFRA_STATION:
9146 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07009147 case WLAN_HDD_P2P_DEVICE:
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05309148
9149 connState = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState;
9150
Jeff Johnson295189b2012-06-20 16:38:30 -07009151 hdd_init_station_mode(pAdapter);
9152 /* Open the gates for HDD to receive Wext commands */
9153 pAdapter->isLinkUpSvcNeeded = FALSE;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07009154 pHddCtx->scan_info.mScanPending = FALSE;
9155 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07009156
9157 //Trigger the initial scan
Mukul Sharmae74e42c2015-08-06 23:55:49 +05309158 if (!pHddCtx->isLogpInProgress)
9159 hdd_wlan_initial_scan(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009160
9161 //Indicate disconnect event to supplicant if associated previously
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05309162 if (eConnectionState_Associated == connState ||
9163 eConnectionState_IbssConnected == connState )
Jeff Johnson295189b2012-06-20 16:38:30 -07009164 {
9165 union iwreq_data wrqu;
9166 memset(&wrqu, '\0', sizeof(wrqu));
9167 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
9168 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
9169 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -07009170 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07009171
Jeff Johnson295189b2012-06-20 16:38:30 -07009172 /* indicate disconnected event to nl80211 */
9173 cfg80211_disconnected(pAdapter->dev, WLAN_REASON_UNSPECIFIED,
9174 NULL, 0, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07009175 }
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05309176 else if (eConnectionState_Connecting == connState)
9177 {
9178 /*
9179 * Indicate connect failure to supplicant if we were in the
9180 * process of connecting
9181 */
9182 cfg80211_connect_result(pAdapter->dev, NULL,
9183 NULL, 0, NULL, 0,
9184 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
9185 GFP_KERNEL);
9186 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009187 break;
9188
9189 case WLAN_HDD_SOFTAP:
9190 /* softAP can handle SSR */
9191 break;
9192
9193 case WLAN_HDD_P2P_GO:
Sameer Thalappiledf0d792013-08-09 14:31:03 -07009194 hddLog(VOS_TRACE_LEVEL_ERROR, "%s [SSR] send stop ap to supplicant",
Jeff Johnson295189b2012-06-20 16:38:30 -07009195 __func__);
Sameer Thalappiledf0d792013-08-09 14:31:03 -07009196 cfg80211_ap_stopped(pAdapter->dev, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07009197 break;
9198
9199 case WLAN_HDD_MONITOR:
9200 /* monitor interface start */
9201 break;
9202 default:
9203 break;
9204 }
9205
9206 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9207 pAdapterNode = pNext;
9208 }
9209
9210 EXIT();
9211
9212 return VOS_STATUS_SUCCESS;
9213}
9214
9215VOS_STATUS hdd_reconnect_all_adapters( hdd_context_t *pHddCtx )
9216{
9217 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9218 hdd_adapter_t *pAdapter;
9219 VOS_STATUS status;
9220 v_U32_t roamId;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309221 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07009222
9223 ENTER();
9224
9225 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9226
9227 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9228 {
9229 pAdapter = pAdapterNode->pAdapter;
9230
9231 if( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
9232 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
9233 {
9234 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9235 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
9236
Abhishek Singhf4669da2014-05-26 15:07:49 +05309237 hddLog(VOS_TRACE_LEVEL_INFO,
9238 "%s: Set HDD connState to eConnectionState_NotConnected",
9239 __func__);
Ganesh Kondabattini04338412015-09-14 15:39:09 +05309240 spin_lock_bh(&pAdapter->lock_for_active_session);
9241 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState)
9242 {
9243 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
9244 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009245 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Ganesh Kondabattini04338412015-09-14 15:39:09 +05309246 spin_unlock_bh(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -07009247 init_completion(&pAdapter->disconnect_comp_var);
9248 sme_RoamDisconnect(pHddCtx->hHal, pAdapter->sessionId,
9249 eCSR_DISCONNECT_REASON_UNSPECIFIED);
9250
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309251 ret = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07009252 &pAdapter->disconnect_comp_var,
9253 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309254 if (0 >= ret)
9255 hddLog(LOGE, "%s: failure waiting for disconnect_comp_var %ld",
9256 __func__, ret);
Jeff Johnson295189b2012-06-20 16:38:30 -07009257
9258 pWextState->roamProfile.csrPersona = pAdapter->device_mode;
9259 pHddCtx->isAmpAllowed = VOS_FALSE;
9260 sme_RoamConnect(pHddCtx->hHal,
9261 pAdapter->sessionId, &(pWextState->roamProfile),
9262 &roamId);
9263 }
9264
9265 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9266 pAdapterNode = pNext;
9267 }
9268
9269 EXIT();
9270
9271 return VOS_STATUS_SUCCESS;
9272}
9273
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -07009274void hdd_dump_concurrency_info(hdd_context_t *pHddCtx)
9275{
9276 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9277 VOS_STATUS status;
9278 hdd_adapter_t *pAdapter;
9279 hdd_station_ctx_t *pHddStaCtx;
9280 hdd_ap_ctx_t *pHddApCtx;
9281 hdd_hostapd_state_t * pHostapdState;
9282 tCsrBssid staBssid = { 0 }, p2pBssid = { 0 }, apBssid = { 0 };
9283 v_U8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
9284 const char *p2pMode = "DEV";
9285 const char *ccMode = "Standalone";
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -07009286
9287 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9288 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9289 {
9290 pAdapter = pAdapterNode->pAdapter;
9291 switch (pAdapter->device_mode) {
9292 case WLAN_HDD_INFRA_STATION:
9293 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9294 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
9295 staChannel = pHddStaCtx->conn_info.operationChannel;
9296 memcpy(staBssid, pHddStaCtx->conn_info.bssId, sizeof(staBssid));
9297 }
9298 break;
9299 case WLAN_HDD_P2P_CLIENT:
9300 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9301 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
9302 p2pChannel = pHddStaCtx->conn_info.operationChannel;
9303 memcpy(p2pBssid, pHddStaCtx->conn_info.bssId, sizeof(p2pBssid));
9304 p2pMode = "CLI";
9305 }
9306 break;
9307 case WLAN_HDD_P2P_GO:
9308 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
9309 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
9310 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
9311 p2pChannel = pHddApCtx->operatingChannel;
9312 memcpy(p2pBssid, pAdapter->macAddressCurrent.bytes, sizeof(p2pBssid));
9313 }
9314 p2pMode = "GO";
9315 break;
9316 case WLAN_HDD_SOFTAP:
9317 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
9318 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
9319 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
9320 apChannel = pHddApCtx->operatingChannel;
9321 memcpy(apBssid, pAdapter->macAddressCurrent.bytes, sizeof(apBssid));
9322 }
9323 break;
9324 default:
9325 break;
9326 }
9327 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9328 pAdapterNode = pNext;
9329 }
9330 if (staChannel > 0 && (apChannel > 0 || p2pChannel > 0)) {
9331 ccMode = (p2pChannel==staChannel||apChannel==staChannel) ? "SCC" : "MCC";
9332 }
Sushant Kaushikdc3184b2015-10-09 12:00:21 +05309333 hddLog(VOS_TRACE_LEVEL_ERROR, "wlan(%d) " MAC_ADDRESS_STR " %s",
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -07009334 staChannel, MAC_ADDR_ARRAY(staBssid), ccMode);
9335 if (p2pChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +05309336 hddLog(VOS_TRACE_LEVEL_ERROR, "p2p-%s(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -07009337 p2pMode, p2pChannel, MAC_ADDR_ARRAY(p2pBssid));
9338 }
9339 if (apChannel > 0) {
Sushant Kaushikdc3184b2015-10-09 12:00:21 +05309340 hddLog(VOS_TRACE_LEVEL_ERROR, "AP(%d) " MAC_ADDRESS_STR,
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -07009341 apChannel, MAC_ADDR_ARRAY(apBssid));
9342 }
9343
9344 if (p2pChannel > 0 && apChannel > 0) {
9345 hddLog(VOS_TRACE_LEVEL_ERROR, "Error concurrent SAP %d and P2P %d which is not support", apChannel, p2pChannel);
9346 }
9347}
9348
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07009349bool hdd_is_ssr_required( void)
Jeff Johnson295189b2012-06-20 16:38:30 -07009350{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07009351 return (isSsrRequired == HDD_SSR_REQUIRED);
Jeff Johnson295189b2012-06-20 16:38:30 -07009352}
9353
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07009354/* Once SSR is disabled then it cannot be set. */
9355void hdd_set_ssr_required( e_hdd_ssr_required value)
Jeff Johnson295189b2012-06-20 16:38:30 -07009356{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07009357 if (HDD_SSR_DISABLED == isSsrRequired)
9358 return;
9359
Jeff Johnson295189b2012-06-20 16:38:30 -07009360 isSsrRequired = value;
9361}
9362
Hema Aparna Medicharla6b4d4f32015-06-23 04:09:12 +05309363void hdd_set_pre_close( hdd_context_t *pHddCtx)
9364{
9365 sme_PreClose(pHddCtx->hHal);
9366}
9367
Jeff Johnson295189b2012-06-20 16:38:30 -07009368VOS_STATUS hdd_get_front_adapter( hdd_context_t *pHddCtx,
9369 hdd_adapter_list_node_t** ppAdapterNode)
9370{
9371 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309372 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009373 status = hdd_list_peek_front ( &pHddCtx->hddAdapters,
9374 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309375 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009376 return status;
9377}
9378
9379VOS_STATUS hdd_get_next_adapter( hdd_context_t *pHddCtx,
9380 hdd_adapter_list_node_t* pAdapterNode,
9381 hdd_adapter_list_node_t** pNextAdapterNode)
9382{
9383 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309384 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009385 status = hdd_list_peek_next ( &pHddCtx->hddAdapters,
9386 (hdd_list_node_t*) pAdapterNode,
9387 (hdd_list_node_t**)pNextAdapterNode );
9388
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309389 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009390 return status;
9391}
9392
9393VOS_STATUS hdd_remove_adapter( hdd_context_t *pHddCtx,
9394 hdd_adapter_list_node_t* pAdapterNode)
9395{
9396 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309397 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009398 status = hdd_list_remove_node ( &pHddCtx->hddAdapters,
9399 &pAdapterNode->node );
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309400 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009401 return status;
9402}
9403
9404VOS_STATUS hdd_remove_front_adapter( hdd_context_t *pHddCtx,
9405 hdd_adapter_list_node_t** ppAdapterNode)
9406{
9407 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309408 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009409 status = hdd_list_remove_front( &pHddCtx->hddAdapters,
9410 (hdd_list_node_t**) ppAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309411 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009412 return status;
9413}
9414
9415VOS_STATUS hdd_add_adapter_back( hdd_context_t *pHddCtx,
9416 hdd_adapter_list_node_t* pAdapterNode)
9417{
9418 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309419 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009420 status = hdd_list_insert_back ( &pHddCtx->hddAdapters,
9421 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309422 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009423 return status;
9424}
9425
9426VOS_STATUS hdd_add_adapter_front( hdd_context_t *pHddCtx,
9427 hdd_adapter_list_node_t* pAdapterNode)
9428{
9429 VOS_STATUS status;
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309430 spin_lock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009431 status = hdd_list_insert_front ( &pHddCtx->hddAdapters,
9432 (hdd_list_node_t*) pAdapterNode );
Mukul Sharmaae1266d2015-06-26 15:29:53 +05309433 spin_unlock_bh(&pHddCtx->hddAdapters.lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009434 return status;
9435}
9436
9437hdd_adapter_t * hdd_get_adapter_by_macaddr( hdd_context_t *pHddCtx,
9438 tSirMacAddr macAddr )
9439{
9440 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9441 hdd_adapter_t *pAdapter;
9442 VOS_STATUS status;
9443
9444 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9445
9446 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9447 {
9448 pAdapter = pAdapterNode->pAdapter;
9449
9450 if( pAdapter && vos_mem_compare( pAdapter->macAddressCurrent.bytes,
9451 macAddr, sizeof(tSirMacAddr) ) )
9452 {
9453 return pAdapter;
9454 }
9455 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9456 pAdapterNode = pNext;
9457 }
9458
9459 return NULL;
9460
9461}
9462
9463hdd_adapter_t * hdd_get_adapter_by_name( hdd_context_t *pHddCtx, tANI_U8 *name )
9464{
9465 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9466 hdd_adapter_t *pAdapter;
9467 VOS_STATUS status;
9468
9469 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9470
9471 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9472 {
9473 pAdapter = pAdapterNode->pAdapter;
9474
9475 if( pAdapter && !strncmp( pAdapter->dev->name, (const char *)name,
9476 IFNAMSIZ ) )
9477 {
9478 return pAdapter;
9479 }
9480 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9481 pAdapterNode = pNext;
9482 }
9483
9484 return NULL;
9485
9486}
9487
Ganesh Kondabattinicbfdc392015-09-11 19:12:59 +05309488hdd_adapter_t *hdd_get_adapter_by_sme_session_id( hdd_context_t *pHddCtx,
9489 tANI_U32 sme_session_id )
9490{
9491 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9492 hdd_adapter_t *pAdapter;
9493 VOS_STATUS vos_status;
9494
9495
9496 vos_status = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
9497
9498 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == vos_status))
9499 {
9500 pAdapter = pAdapterNode->pAdapter;
9501
9502 if (pAdapter->sessionId == sme_session_id)
9503 return pAdapter;
9504
9505 vos_status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
9506 pAdapterNode = pNext;
9507 }
9508
9509 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9510 "%s: sme_session_id %d does not exist with host",
9511 __func__, sme_session_id);
9512
9513 return NULL;
9514}
9515
Jeff Johnson295189b2012-06-20 16:38:30 -07009516hdd_adapter_t * hdd_get_adapter( hdd_context_t *pHddCtx, device_mode_t mode )
9517{
9518 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9519 hdd_adapter_t *pAdapter;
9520 VOS_STATUS status;
9521
9522 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9523
9524 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9525 {
9526 pAdapter = pAdapterNode->pAdapter;
9527
9528 if( pAdapter && (mode == pAdapter->device_mode) )
9529 {
9530 return pAdapter;
9531 }
9532 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9533 pAdapterNode = pNext;
9534 }
9535
9536 return NULL;
9537
9538}
9539
9540//Remove this function later
9541hdd_adapter_t * hdd_get_mon_adapter( hdd_context_t *pHddCtx )
9542{
9543 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9544 hdd_adapter_t *pAdapter;
9545 VOS_STATUS status;
9546
9547 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9548
9549 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9550 {
9551 pAdapter = pAdapterNode->pAdapter;
9552
9553 if( pAdapter && WLAN_HDD_MONITOR == pAdapter->device_mode )
9554 {
9555 return pAdapter;
9556 }
9557
9558 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9559 pAdapterNode = pNext;
9560 }
9561
9562 return NULL;
9563
9564}
9565
Jeff Johnson295189b2012-06-20 16:38:30 -07009566/**---------------------------------------------------------------------------
9567
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05309568 \brief hdd_get_operating_channel() -
Jeff Johnson295189b2012-06-20 16:38:30 -07009569
9570 This API returns the operating channel of the requested device mode
9571
9572 \param - pHddCtx - Pointer to the HDD context.
9573 - mode - Device mode for which operating channel is required
9574 suported modes - WLAN_HDD_INFRA_STATION, WLAN_HDD_P2P_CLIENT
9575 WLAN_HDD_SOFTAP, WLAN_HDD_P2P_GO.
9576 \return - channel number. "0" id the requested device is not found OR it is not connected.
9577 --------------------------------------------------------------------------*/
9578v_U8_t hdd_get_operating_channel( hdd_context_t *pHddCtx, device_mode_t mode )
9579{
9580 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9581 VOS_STATUS status;
9582 hdd_adapter_t *pAdapter;
9583 v_U8_t operatingChannel = 0;
9584
9585 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9586
9587 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9588 {
9589 pAdapter = pAdapterNode->pAdapter;
9590
9591 if( mode == pAdapter->device_mode )
9592 {
9593 switch(pAdapter->device_mode)
9594 {
9595 case WLAN_HDD_INFRA_STATION:
9596 case WLAN_HDD_P2P_CLIENT:
9597 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
9598 operatingChannel = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.operationChannel;
9599 break;
9600 case WLAN_HDD_SOFTAP:
9601 case WLAN_HDD_P2P_GO:
9602 /*softap connection info */
9603 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
9604 operatingChannel = (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->operatingChannel;
9605 break;
9606 default:
9607 break;
9608 }
9609
9610 break; //Found the device of interest. break the loop
9611 }
9612
9613 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9614 pAdapterNode = pNext;
9615 }
9616 return operatingChannel;
9617}
9618
9619#ifdef WLAN_FEATURE_PACKET_FILTERING
9620/**---------------------------------------------------------------------------
9621
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05309622 \brief __hdd_set_multicast_list() -
Jeff Johnson295189b2012-06-20 16:38:30 -07009623
9624 This used to set the multicast address list.
9625
9626 \param - dev - Pointer to the WLAN device.
9627 - skb - Pointer to OS packet (sk_buff).
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05309628 \return - success/fail
Jeff Johnson295189b2012-06-20 16:38:30 -07009629
9630 --------------------------------------------------------------------------*/
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05309631static void __hdd_set_multicast_list(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07009632{
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05309633 hdd_adapter_t *pAdapter;
9634 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07009635 int mc_count;
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05309636 int i = 0, ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07009637 struct netdev_hw_addr *ha;
Gopichand Nakkala0f276812013-02-24 14:45:51 +05309638
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05309639 ENTER();
9640
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05309641 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala0f276812013-02-24 14:45:51 +05309642 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -07009643 {
9644 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala0f276812013-02-24 14:45:51 +05309645 "%s: Adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009646 return;
9647 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05309648 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9649 ret = wlan_hdd_validate_context(pHddCtx);
9650 if (0 != ret)
9651 {
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05309652 return;
9653 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009654 if (dev->flags & IFF_ALLMULTI)
9655 {
9656 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07009657 "%s: allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +05309658 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07009659 }
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05309660 else
Jeff Johnson295189b2012-06-20 16:38:30 -07009661 {
9662 mc_count = netdev_mc_count(dev);
9663 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07009664 "%s: mc_count = %u", __func__, mc_count);
Jeff Johnson295189b2012-06-20 16:38:30 -07009665 if (mc_count > WLAN_HDD_MAX_MC_ADDR_LIST)
9666 {
9667 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07009668 "%s: No free filter available; allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +05309669 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07009670 return;
9671 }
9672
Gopichand Nakkala0f276812013-02-24 14:45:51 +05309673 pAdapter->mc_addr_list.mc_cnt = mc_count;
Jeff Johnson295189b2012-06-20 16:38:30 -07009674
9675 netdev_for_each_mc_addr(ha, dev) {
9676 if (i == mc_count)
9677 break;
Gopichand Nakkala0f276812013-02-24 14:45:51 +05309678 memset(&(pAdapter->mc_addr_list.addr[i][0]), 0, ETH_ALEN);
9679 memcpy(&(pAdapter->mc_addr_list.addr[i][0]), ha->addr, ETH_ALEN);
Arif Hussain6d2a3322013-11-17 19:50:10 -08009680 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mlist[%d] = "MAC_ADDRESS_STR,
Mahesh A Saptasagar74088392015-02-05 17:22:09 +05309681 __func__, i,
Gopichand Nakkala0f276812013-02-24 14:45:51 +05309682 MAC_ADDR_ARRAY(pAdapter->mc_addr_list.addr[i]));
Jeff Johnson295189b2012-06-20 16:38:30 -07009683 i++;
9684 }
9685 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05309686
Ganesh Kondabattinifb37e652015-10-09 15:46:47 +05309687 if (pHddCtx->hdd_wlan_suspended)
9688 {
9689 /*
9690 * Configure the Mcast address list to FW
9691 * If wlan is already in suspend mode
9692 */
9693 wlan_hdd_set_mc_addr_list(pAdapter, TRUE);
9694 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05309695 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07009696 return;
9697}
Mahesh A Saptasagard68eb282014-12-17 14:20:19 +05309698
9699static void hdd_set_multicast_list(struct net_device *dev)
9700{
9701 vos_ssr_protect(__func__);
9702 __hdd_set_multicast_list(dev);
9703 vos_ssr_unprotect(__func__);
9704}
Jeff Johnson295189b2012-06-20 16:38:30 -07009705#endif
9706
9707/**---------------------------------------------------------------------------
9708
9709 \brief hdd_select_queue() -
9710
9711 This function is registered with the Linux OS for network
9712 core to decide which queue to use first.
9713
9714 \param - dev - Pointer to the WLAN device.
9715 - skb - Pointer to OS packet (sk_buff).
9716 \return - ac, Queue Index/access category corresponding to UP in IP header
9717
9718 --------------------------------------------------------------------------*/
9719v_U16_t hdd_select_queue(struct net_device *dev,
Anand N Sunkade9adb1b2015-07-29 09:56:45 +05309720 struct sk_buff *skb
9721#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
9722 , void *accel_priv
9723#endif
9724#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
9725 , select_queue_fallback_t fallback
9726#endif
9727)
Jeff Johnson295189b2012-06-20 16:38:30 -07009728{
9729 return hdd_wmm_select_queue(dev, skb);
9730}
9731
9732
9733/**---------------------------------------------------------------------------
9734
9735 \brief hdd_wlan_initial_scan() -
9736
9737 This function triggers the initial scan
9738
9739 \param - pAdapter - Pointer to the HDD adapter.
9740
9741 --------------------------------------------------------------------------*/
9742void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter)
9743{
9744 tCsrScanRequest scanReq;
9745 tCsrChannelInfo channelInfo;
9746 eHalStatus halStatus;
Jeff Johnson02797792013-10-26 19:17:13 -07009747 tANI_U32 scanId;
Jeff Johnson295189b2012-06-20 16:38:30 -07009748 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9749
9750 vos_mem_zero(&scanReq, sizeof(tCsrScanRequest));
9751 vos_mem_set(&scanReq.bssid, sizeof(tCsrBssid), 0xff);
9752 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
9753
9754 if(sme_Is11dSupported(pHddCtx->hHal))
9755 {
9756 halStatus = sme_ScanGetBaseChannels( pHddCtx->hHal, &channelInfo );
9757 if ( HAL_STATUS_SUCCESS( halStatus ) )
9758 {
9759 scanReq.ChannelInfo.ChannelList = vos_mem_malloc(channelInfo.numOfChannels);
9760 if( !scanReq.ChannelInfo.ChannelList )
9761 {
9762 hddLog(VOS_TRACE_LEVEL_ERROR, "%s kmalloc failed", __func__);
9763 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08009764 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009765 return;
9766 }
9767 vos_mem_copy(scanReq.ChannelInfo.ChannelList, channelInfo.ChannelList,
9768 channelInfo.numOfChannels);
9769 scanReq.ChannelInfo.numOfChannels = channelInfo.numOfChannels;
9770 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08009771 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009772 }
9773
9774 scanReq.scanType = eSIR_PASSIVE_SCAN;
9775 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
9776 scanReq.maxChnTime = pHddCtx->cfg_ini->nPassiveMaxChnTime;
9777 scanReq.minChnTime = pHddCtx->cfg_ini->nPassiveMinChnTime;
9778 }
9779 else
9780 {
9781 scanReq.scanType = eSIR_ACTIVE_SCAN;
9782 scanReq.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
9783 scanReq.maxChnTime = pHddCtx->cfg_ini->nActiveMaxChnTime;
9784 scanReq.minChnTime = pHddCtx->cfg_ini->nActiveMinChnTime;
9785 }
9786
9787 halStatus = sme_ScanRequest(pHddCtx->hHal, pAdapter->sessionId, &scanReq, &scanId, NULL, NULL);
9788 if ( !HAL_STATUS_SUCCESS( halStatus ) )
9789 {
9790 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_ScanRequest failed status code %d",
9791 __func__, halStatus );
9792 }
9793
9794 if(sme_Is11dSupported(pHddCtx->hHal))
9795 vos_mem_free(scanReq.ChannelInfo.ChannelList);
9796}
9797
mukul sharmabab477d2015-06-11 17:14:55 +05309798void hdd_purge_cmd_list_all_adapters( hdd_context_t *pHddCtx )
9799{
9800 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
9801 VOS_STATUS status;
9802 hdd_adapter_t *pAdapter;
9803
9804 ENTER();
9805
9806 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9807
9808 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9809 {
9810 pAdapter = pAdapterNode->pAdapter;
9811
9812 status = sme_PurgeCmdList(pHddCtx->hHal, pAdapter->sessionId);
9813 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9814 pAdapterNode = pNext;
9815 }
9816
9817 EXIT();
9818}
Jeff Johnson295189b2012-06-20 16:38:30 -07009819/**---------------------------------------------------------------------------
9820
9821 \brief hdd_full_power_callback() - HDD full power callback function
9822
9823 This is the function invoked by SME to inform the result of a full power
9824 request issued by HDD
9825
9826 \param - callbackcontext - Pointer to cookie
9827 \param - status - result of request
9828
9829 \return - None
9830
9831 --------------------------------------------------------------------------*/
9832static void hdd_full_power_callback(void *callbackContext, eHalStatus status)
9833{
Jeff Johnson72a40512013-12-19 10:14:15 -08009834 struct statsContext *pContext = callbackContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07009835
9836 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05309837 "%s: context = %p, status = %d", __func__, pContext, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07009838
9839 if (NULL == callbackContext)
9840 {
9841 hddLog(VOS_TRACE_LEVEL_ERROR,
9842 "%s: Bad param, context [%p]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07009843 __func__, callbackContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07009844 return;
9845 }
9846
Jeff Johnson72a40512013-12-19 10:14:15 -08009847 /* there is a race condition that exists between this callback
9848 function and the caller since the caller could time out either
9849 before or while this code is executing. we use a spinlock to
9850 serialize these actions */
9851 spin_lock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009852
9853 if (POWER_CONTEXT_MAGIC != pContext->magic)
9854 {
9855 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -08009856 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009857 hddLog(VOS_TRACE_LEVEL_WARN,
9858 "%s: Invalid context, magic [%08x]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07009859 __func__, pContext->magic);
Jeff Johnson295189b2012-06-20 16:38:30 -07009860 return;
9861 }
9862
Jeff Johnson72a40512013-12-19 10:14:15 -08009863 /* context is valid so caller is still waiting */
9864
9865 /* paranoia: invalidate the magic */
9866 pContext->magic = 0;
9867
9868 /* notify the caller */
Jeff Johnson295189b2012-06-20 16:38:30 -07009869 complete(&pContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -08009870
9871 /* serialization is complete */
9872 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009873}
9874
Katya Nigamf0511f62015-05-05 16:40:57 +05309875void wlan_hdd_mon_set_typesubtype( hdd_mon_ctx_t *pMonCtx,int type)
9876{
9877 pMonCtx->typeSubtypeBitmap = 0;
9878 if( type%10 ) /* Management Packets */
9879 pMonCtx->typeSubtypeBitmap |= 0xFFFF;
9880 type/=10;
9881 if( type%10 ) /* Control Packets */
9882 pMonCtx->typeSubtypeBitmap |= 0xFFFF0000;
9883 type/=10;
9884 if( type%10 ) /* Data Packets */
9885 pMonCtx->typeSubtypeBitmap |= 0xFFFF00000000;
9886}
9887
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309888VOS_STATUS wlan_hdd_mon_postMsg(tANI_U32 *magic, struct completion *cmpVar,
9889 hdd_mon_ctx_t *pMonCtx , void* callback)
Katya Nigamf0511f62015-05-05 16:40:57 +05309890{
9891 vos_msg_t monMsg;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309892 tSirMonModeReq *pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +05309893
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309894 if (MON_MODE_START == pMonCtx->state)
9895 monMsg.type = WDA_MON_START_REQ;
9896 else if (MON_MODE_STOP == pMonCtx->state)
9897 monMsg.type = WDA_MON_STOP_REQ;
9898 else {
9899 hddLog(VOS_TRACE_LEVEL_ERROR,
9900 FL("invalid monitor state %d"), pMonCtx->state);
Katya Nigamf0511f62015-05-05 16:40:57 +05309901 return VOS_STATUS_E_FAILURE;
9902 }
9903
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309904 pMonModeReq = vos_mem_malloc(sizeof(tSirMonModeReq));
9905 if (pMonModeReq == NULL) {
9906 hddLog(VOS_TRACE_LEVEL_ERROR,
9907 FL("fail to allocate memory for monitor mode req"));
9908 return VOS_STATUS_E_FAILURE;
9909 }
Katya Nigamf0511f62015-05-05 16:40:57 +05309910
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309911 pMonModeReq->magic = magic;
9912 pMonModeReq->cmpVar = cmpVar;
9913 pMonModeReq->data = pMonCtx;
9914 pMonModeReq->callback = callback;
Katya Nigamf0511f62015-05-05 16:40:57 +05309915
Katya Nigamf0511f62015-05-05 16:40:57 +05309916 monMsg.reserved = 0;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309917 monMsg.bodyptr = pMonModeReq;
Katya Nigamf0511f62015-05-05 16:40:57 +05309918 monMsg.bodyval = 0;
9919
9920 if (VOS_STATUS_SUCCESS != vos_mq_post_message(
9921 VOS_MODULE_ID_WDA,(vos_msg_t *)&monMsg)) {
9922 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: : Failed to post Msg to HAL",__func__);
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309923 vos_mem_free(pMonModeReq);
Katya Nigamf0511f62015-05-05 16:40:57 +05309924 }
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309925 return VOS_STATUS_SUCCESS;
Katya Nigamf0511f62015-05-05 16:40:57 +05309926}
9927
Katya Nigame7b69a82015-04-28 15:24:06 +05309928void wlan_hdd_mon_close(hdd_context_t *pHddCtx)
9929{
9930 VOS_STATUS vosStatus;
9931 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309932 long ret;
9933 hdd_mon_ctx_t *pMonCtx = NULL;
9934 v_U32_t magic;
9935 struct completion cmpVar;
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +05309936
Katya Nigame7b69a82015-04-28 15:24:06 +05309937 hdd_adapter_t *pAdapter = hdd_get_adapter(pHddCtx,WLAN_HDD_MONITOR);
9938 if(pAdapter == NULL || pVosContext == NULL)
9939 {
9940 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:pAdapter is NULL",__func__);
9941 return ;
9942 }
Katya Nigamf0511f62015-05-05 16:40:57 +05309943
Hanumantha Reddy Pothula91cdd7f2015-09-03 21:25:16 +05309944 pMonCtx = WLAN_HDD_GET_MONITOR_CTX_PTR(pAdapter);
9945 if (pMonCtx!= NULL && pMonCtx->state == MON_MODE_START) {
9946 pMonCtx->state = MON_MODE_STOP;
9947 magic = MON_MODE_MSG_MAGIC;
9948 init_completion(&cmpVar);
9949 if (VOS_STATUS_SUCCESS !=
9950 wlan_hdd_mon_postMsg(&magic, &cmpVar,
9951 pMonCtx, hdd_monPostMsgCb)) {
9952 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9953 FL("failed to post MON MODE REQ"));
9954 pMonCtx->state = MON_MODE_START;
9955 magic = 0;
9956 return;
9957 }
9958 ret = wait_for_completion_timeout(&cmpVar, MON_MODE_MSG_TIMEOUT);
9959 magic = 0;
9960 if (ret <= 0 ) {
9961 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9962 FL("timeout on monitor mode completion %ld"), ret);
9963 }
9964 }
9965
Katya Nigame7b69a82015-04-28 15:24:06 +05309966 hdd_UnregisterWext(pAdapter->dev);
9967
9968 vos_mon_stop( pVosContext );
9969
9970 vosStatus = vos_sched_close( pVosContext );
9971 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
9972 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
9973 "%s: Failed to close VOSS Scheduler",__func__);
9974 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
9975 }
9976
9977 vosStatus = vos_nv_close();
9978 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
9979 {
9980 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9981 "%s: Failed to close NV", __func__);
9982 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
9983 }
9984
9985 vos_close(pVosContext);
9986
9987 #ifdef WLAN_KD_READY_NOTIFIER
9988 nl_srv_exit(pHddCtx->ptt_pid);
9989 #else
9990 nl_srv_exit();
9991 #endif
9992
Katya Nigame7b69a82015-04-28 15:24:06 +05309993 hdd_close_all_adapters( pHddCtx );
Katya Nigame7b69a82015-04-28 15:24:06 +05309994}
Agrawal Ashish33ec71e2015-11-26 20:20:58 +05309995/**
9996 * hdd_wlan_free_wiphy_channels - free Channel pointer for wiphy
9997 * @ wiphy: the wiphy to validate against
9998 *
9999 * Return: void
10000 */
10001void hdd_wlan_free_wiphy_channels(struct wiphy *wiphy)
10002{
10003 int i =0;
10004 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
10005 {
10006 if (NULL != wiphy->bands[i] &&
10007 (NULL != wiphy->bands[i]->channels))
10008 {
10009 vos_mem_free(wiphy->bands[i]->channels);
10010 wiphy->bands[i]->channels = NULL;
10011 }
10012 }
10013}
Jeff Johnson295189b2012-06-20 16:38:30 -070010014/**---------------------------------------------------------------------------
10015
10016 \brief hdd_wlan_exit() - HDD WLAN exit function
10017
10018 This is the driver exit point (invoked during rmmod)
10019
10020 \param - pHddCtx - Pointer to the HDD Context
10021
10022 \return - None
10023
10024 --------------------------------------------------------------------------*/
10025void hdd_wlan_exit(hdd_context_t *pHddCtx)
10026{
10027 eHalStatus halStatus;
10028 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
10029 VOS_STATUS vosStatus;
Gopichand Nakkala66923aa2013-03-06 23:17:24 +053010030 struct wiphy *wiphy = pHddCtx->wiphy;
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080010031 hdd_adapter_t* pAdapter = NULL;
Jeff Johnson72a40512013-12-19 10:14:15 -080010032 struct statsContext powerContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070010033 long lrc;
c_hpothu5ab05e92014-06-13 17:34:05 +053010034 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010035
10036 ENTER();
10037
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053010038
Katya Nigame7b69a82015-04-28 15:24:06 +053010039 if (VOS_MONITOR_MODE == hdd_get_conparam())
10040 {
10041 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: MONITOR MODE",__func__);
10042 wlan_hdd_mon_close(pHddCtx);
Hanumantha Reddy Pothulac99bc062015-09-08 14:59:26 +053010043 goto free_hdd_ctx;
Katya Nigame7b69a82015-04-28 15:24:06 +053010044 }
10045 else if (VOS_FTM_MODE != hdd_get_conparam())
Jeff Johnson88ba7742013-02-27 14:36:02 -080010046 {
10047 // Unloading, restart logic is no more required.
10048 wlan_hdd_restart_deinit(pHddCtx);
Jeff Johnsone7245742012-09-05 17:12:55 -070010049
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053010050#ifdef FEATURE_WLAN_TDLS
10051 /* At the time of driver unloading; if tdls connection is present;
10052 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer.
10053 * wlan_hdd_tdls_find_peer always checks for valid context;
10054 * as load/unload in progress there can be a race condition.
10055 * hdd_rx_packet_cbk calls wlan_hdd_tdls_find_peer only
10056 * when tdls state is enabled.
10057 * As soon as driver set load/unload flag; tdls flag also needs
10058 * to be disabled so that hdd_rx_packet_cbk won't call
10059 * wlan_hdd_tdls_find_peer.
10060 */
Masti, Narayanraddi20494af2015-12-17 20:56:42 +053010061 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE,
10062 HDD_SET_TDLS_MODE_SOURCE_USER);
Agarwal Ashishb20e0ff2014-12-17 22:50:19 +053010063#endif
10064
c_hpothu5ab05e92014-06-13 17:34:05 +053010065 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10066 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
Jeff Johnson295189b2012-06-20 16:38:30 -070010067 {
c_hpothu5ab05e92014-06-13 17:34:05 +053010068 pAdapter = pAdapterNode->pAdapter;
10069 if (NULL != pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -070010070 {
Mahesh A Saptasagar305e2632015-03-04 12:57:33 +053010071 /* Disable TX on the interface, after this hard_start_xmit() will
10072 * not be called on that interface
10073 */
10074 hddLog(VOS_TRACE_LEVEL_INFO, FL("Disabling queues"));
10075 netif_tx_disable(pAdapter->dev);
10076
10077 /* Mark the interface status as "down" for outside world */
10078 netif_carrier_off(pAdapter->dev);
10079
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053010080 /* DeInit the adapter. This ensures that all data packets
10081 * are freed.
10082 */
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053010083#ifdef FEATURE_WLAN_TDLS
10084 mutex_lock(&pHddCtx->tdls_lock);
10085#endif
c_hpothu002231a2015-02-05 14:58:51 +053010086 hdd_deinit_adapter(pHddCtx, pAdapter, FALSE);
Mahesh A Saptasagar02e36e82015-01-14 20:39:19 +053010087#ifdef FEATURE_WLAN_TDLS
10088 mutex_unlock(&pHddCtx->tdls_lock);
10089#endif
Masti, Narayanraddi26378462016-01-05 18:20:28 +053010090 vos_flush_delayed_work(&pHddCtx->scan_ctxt.scan_work);
10091
10092 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +053010093
c_hpothu5ab05e92014-06-13 17:34:05 +053010094 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
10095 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
10096 {
10097 wlan_hdd_cfg80211_deregister_frames(pAdapter);
10098 hdd_UnregisterWext(pAdapter->dev);
10099 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010100
Jeff Johnson295189b2012-06-20 16:38:30 -070010101 }
c_hpothu5ab05e92014-06-13 17:34:05 +053010102 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10103 pAdapterNode = pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -070010104 }
mukul sharmabab477d2015-06-11 17:14:55 +053010105
10106 //Purge all sme cmd's for all interface
10107 hdd_purge_cmd_list_all_adapters(pHddCtx);
10108
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010109 // Cancel any outstanding scan requests. We are about to close all
10110 // of our adapters, but an adapter structure is what SME passes back
10111 // to our callback function. Hence if there are any outstanding scan
10112 // requests then there is a race condition between when the adapter
10113 // is closed and when the callback is invoked.We try to resolve that
10114 // race condition here by canceling any outstanding scans before we
10115 // close the adapters.
10116 // Note that the scans may be cancelled in an asynchronous manner,
10117 // so ideally there needs to be some kind of synchronization. Rather
10118 // than introduce a new synchronization here, we will utilize the
10119 // fact that we are about to Request Full Power, and since that is
10120 // synchronized, the expectation is that by the time Request Full
10121 // Power has completed all scans will be cancelled.
10122 if (pHddCtx->scan_info.mScanPending)
10123 {
Hema Aparna Medicharlaf05f6cd2015-01-21 14:44:19 +053010124 if(NULL != pAdapter)
10125 {
10126 hddLog(VOS_TRACE_LEVEL_INFO,
10127 FL("abort scan mode: %d sessionId: %d"),
10128 pAdapter->device_mode,
10129 pAdapter->sessionId);
10130 }
10131 hdd_abort_mac_scan(pHddCtx,
10132 pHddCtx->scan_info.sessionId,
10133 eCSR_SCAN_ABORT_DEFAULT);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010134 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010135 }
c_hpothu5ab05e92014-06-13 17:34:05 +053010136 else
Jeff Johnson88ba7742013-02-27 14:36:02 -080010137 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010138 hddLog(VOS_TRACE_LEVEL_INFO,"%s: FTM MODE",__func__);
Hanumantha Reddy Pothula45af96b2015-02-12 16:07:58 +053010139 if (pHddCtx->ftm.ftm_state == WLAN_FTM_STARTING)
10140 {
10141 INIT_COMPLETION(pHddCtx->ftm.startCmpVar);
10142 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
10143 "%s: in middle of FTM START", __func__);
10144 lrc = wait_for_completion_timeout(&pHddCtx->ftm.startCmpVar,
10145 msecs_to_jiffies(20000));
10146 if(!lrc)
10147 {
10148 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
10149 "%s: timedout on ftmStartCmpVar fatal error", __func__);
10150 }
10151 }
Jeff Johnson88ba7742013-02-27 14:36:02 -080010152 wlan_hdd_ftm_close(pHddCtx);
10153 goto free_hdd_ctx;
10154 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010155
Jeff Johnson295189b2012-06-20 16:38:30 -070010156 /* DeRegister with platform driver as client for Suspend/Resume */
10157 vosStatus = hddDeregisterPmOps(pHddCtx);
10158 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
10159 {
10160 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDeregisterPmOps failed",__func__);
10161 VOS_ASSERT(0);
10162 }
10163
10164 vosStatus = hddDevTmUnregisterNotifyCallback(pHddCtx);
10165 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
10166 {
10167 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
10168 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010169
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070010170 //Stop the traffic monitor timer
10171 if ( VOS_TIMER_STATE_RUNNING ==
10172 vos_timer_getCurrentState(&pHddCtx->tx_rx_trafficTmr))
10173 {
10174 vos_timer_stop(&pHddCtx->tx_rx_trafficTmr);
10175 }
10176
10177 // Destroy the traffic monitor timer
10178 if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
10179 &pHddCtx->tx_rx_trafficTmr)))
10180 {
10181 hddLog(VOS_TRACE_LEVEL_ERROR,
10182 "%s: Cannot deallocate Traffic monitor timer", __func__);
10183 }
10184
Bhargav Shahd0715912015-10-01 18:17:37 +053010185 if (VOS_TIMER_STATE_RUNNING ==
10186 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
10187 vos_timer_stop(&pHddCtx->delack_timer);
10188 }
10189
10190 if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
10191 &pHddCtx->delack_timer))) {
10192 hddLog(VOS_TRACE_LEVEL_ERROR,
10193 "%s: Cannot deallocate Bus bandwidth timer", __func__);
10194 }
10195
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053010196 if (VOS_TIMER_STATE_RUNNING ==
10197 vos_timer_getCurrentState(&pHddCtx->tdls_source_timer)) {
10198 vos_timer_stop(&pHddCtx->tdls_source_timer);
10199 }
10200
10201 vos_timer_destroy(&pHddCtx->tdls_source_timer);
10202
Jeff Johnson295189b2012-06-20 16:38:30 -070010203 //Disable IMPS/BMPS as we do not want the device to enter any power
10204 //save mode during shutdown
10205 sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
10206 sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
10207 sme_DisablePowerSave(pHddCtx->hHal, ePMC_UAPSD_MODE_POWER_SAVE);
10208
10209 //Ensure that device is in full power as we will touch H/W during vos_Stop
10210 init_completion(&powerContext.completion);
10211 powerContext.magic = POWER_CONTEXT_MAGIC;
10212
10213 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_power_callback,
10214 &powerContext, eSME_FULL_PWR_NEEDED_BY_HDD);
10215
10216 if (eHAL_STATUS_SUCCESS != halStatus)
10217 {
10218 if (eHAL_STATUS_PMC_PENDING == halStatus)
10219 {
10220 /* request was sent -- wait for the response */
10221 lrc = wait_for_completion_interruptible_timeout(
10222 &powerContext.completion,
10223 msecs_to_jiffies(WLAN_WAIT_TIME_POWER));
Jeff Johnson295189b2012-06-20 16:38:30 -070010224 if (lrc <= 0)
10225 {
10226 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: %s while requesting full power",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010227 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson295189b2012-06-20 16:38:30 -070010228 }
10229 }
10230 else
10231 {
10232 hddLog(VOS_TRACE_LEVEL_ERROR,
10233 "%s: Request for Full Power failed, status %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010234 __func__, halStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -070010235 /* continue -- need to clean up as much as possible */
10236 }
10237 }
Hanumantha Reddy Pothula81b42b22015-05-12 13:52:00 +053010238 if ((eHAL_STATUS_SUCCESS == halStatus) ||
10239 (eHAL_STATUS_PMC_PENDING == halStatus && lrc > 0))
10240 {
10241 /* This will issue a dump command which will clean up
10242 BTQM queues and unblock MC thread */
10243 vos_fwDumpReq(274, 0, 0, 0, 0, 1);
10244 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010245
Jeff Johnson72a40512013-12-19 10:14:15 -080010246 /* either we never sent a request, we sent a request and received a
10247 response or we sent a request and timed out. if we never sent a
10248 request or if we sent a request and got a response, we want to
10249 clear the magic out of paranoia. if we timed out there is a
10250 race condition such that the callback function could be
10251 executing at the same time we are. of primary concern is if the
10252 callback function had already verified the "magic" but had not
10253 yet set the completion variable when a timeout occurred. we
10254 serialize these activities by invalidating the magic while
10255 holding a shared spinlock which will cause us to block if the
10256 callback is currently executing */
10257 spin_lock(&hdd_context_lock);
10258 powerContext.magic = 0;
10259 spin_unlock(&hdd_context_lock);
10260
Hema Aparna Medicharlaa6cf65e2015-06-01 16:23:28 +053010261 /* If Device is shutdown, no point for SME to wait for responses
10262 from device. Pre Close SME */
10263 if(wcnss_device_is_shutdown())
10264 {
10265 sme_PreClose(pHddCtx->hHal);
10266 }
Yue Ma0d4891e2013-08-06 17:01:45 -070010267 hdd_debugfs_exit(pHddCtx);
10268
Ratheesh S P35ed8b12015-04-27 14:01:07 +053010269#ifdef WLAN_NS_OFFLOAD
Ratheesh S P36dbc932015-08-07 14:28:57 +053010270 hddLog(LOG1, FL("Unregister IPv6 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053010271 unregister_inet6addr_notifier(&pHddCtx->ipv6_notifier);
10272#endif
Ratheesh S P36dbc932015-08-07 14:28:57 +053010273 hddLog(LOG1, FL("Unregister IPv4 notifier"));
Ratheesh S P35ed8b12015-04-27 14:01:07 +053010274 unregister_inetaddr_notifier(&pHddCtx->ipv4_notifier);
10275
Jeff Johnson295189b2012-06-20 16:38:30 -070010276 // Unregister the Net Device Notifier
10277 unregister_netdevice_notifier(&hdd_netdev_notifier);
10278
Jeff Johnson295189b2012-06-20 16:38:30 -070010279 hdd_stop_all_adapters( pHddCtx );
10280
Jeff Johnson295189b2012-06-20 16:38:30 -070010281#ifdef WLAN_BTAMP_FEATURE
10282 vosStatus = WLANBAP_Stop(pVosContext);
10283 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
10284 {
10285 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
10286 "%s: Failed to stop BAP",__func__);
10287 }
10288#endif //WLAN_BTAMP_FEATURE
10289
10290 //Stop all the modules
10291 vosStatus = vos_stop( pVosContext );
10292 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
10293 {
10294 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
10295 "%s: Failed to stop VOSS",__func__);
10296 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053010297 if (isSsrPanicOnFailure())
10298 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -070010299 }
10300
Jeff Johnson295189b2012-06-20 16:38:30 -070010301 //This requires pMac access, Call this before vos_close().
Jeff Johnson295189b2012-06-20 16:38:30 -070010302 hdd_unregister_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070010303
10304 //Close the scheduler before calling vos_close to make sure no thread is
10305 // scheduled after the each module close is called i.e after all the data
10306 // structures are freed.
10307 vosStatus = vos_sched_close( pVosContext );
10308 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
10309 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
10310 "%s: Failed to close VOSS Scheduler",__func__);
10311 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
10312 }
Jeff Johnsone7245742012-09-05 17:12:55 -070010313#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
10314 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053010315 vos_wake_lock_destroy(&pHddCtx->rx_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -070010316#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080010317 /* Destroy the wake lock */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053010318 vos_wake_lock_destroy(&pHddCtx->sap_wake_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070010319
Mihir Shete7a24b5f2013-12-21 12:18:31 +053010320#ifdef CONFIG_ENABLE_LINUX_REG
10321 vosStatus = vos_nv_close();
10322 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
10323 {
10324 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
10325 "%s: Failed to close NV", __func__);
10326 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
10327 }
10328#endif
10329
Jeff Johnson295189b2012-06-20 16:38:30 -070010330 //Close VOSS
10331 //This frees pMac(HAL) context. There should not be any call that requires pMac access after this.
10332 vos_close(pVosContext);
10333
Jeff Johnson295189b2012-06-20 16:38:30 -070010334 //Close Watchdog
10335 if(pHddCtx->cfg_ini->fIsLogpEnabled)
10336 vos_watchdog_close(pVosContext);
10337
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053010338 //Clean up HDD Nlink Service
10339 send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0);
Gopichand Nakkalaa0358482013-06-12 17:05:47 +053010340
c_manjeecfd1efb2015-09-25 19:32:34 +053010341 wlan_free_fwr_mem_dump_buffer();
10342 memdump_deinit();
10343
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053010344#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053010345 if (pHddCtx->cfg_ini->wlanLoggingEnable)
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053010346 {
10347 wlan_logging_sock_deactivate_svc();
10348 }
10349#endif
10350
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053010351#ifdef WLAN_KD_READY_NOTIFIER
10352 nl_srv_exit(pHddCtx->ptt_pid);
10353#else
10354 nl_srv_exit();
10355#endif /* WLAN_KD_READY_NOTIFIER */
10356
Abhishek Singh00b71972016-01-07 10:51:04 +053010357#ifdef WLAN_FEATURE_RMC
10358 hdd_close_cesium_nl_sock();
10359#endif /* WLAN_FEATURE_RMC */
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +053010360
Jeff Johnson295189b2012-06-20 16:38:30 -070010361 hdd_close_all_adapters( pHddCtx );
10362
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053010363 vos_flush_delayed_work(&pHddCtx->spoof_mac_addr_work);
10364
Hanumantha Reddy Pothula97f9bc92015-08-10 17:21:20 +053010365free_hdd_ctx:
Jeff Johnson295189b2012-06-20 16:38:30 -070010366 /* free the power on lock from platform driver */
10367 if (free_riva_power_on_lock("wlan"))
10368 {
10369 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to free power on lock",
10370 __func__);
10371 }
10372
c_hpothu78c7b602014-05-17 17:35:49 +053010373 //Free up dynamically allocated members inside HDD Adapter
10374 if (pHddCtx->cfg_ini)
10375 {
10376 kfree(pHddCtx->cfg_ini);
10377 pHddCtx->cfg_ini= NULL;
10378 }
10379
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053010380 /* FTM/MONITOR mode, WIPHY did not registered
Leo Changf04ddad2013-09-18 13:46:38 -070010381 If un-register here, system crash will happen */
Hanumantha Reddy Pothula6fe221c2016-01-28 15:01:09 +053010382 if (!(VOS_FTM_MODE == hdd_get_conparam() ||
10383 VOS_MONITOR_MODE == hdd_get_conparam()))
Leo Changf04ddad2013-09-18 13:46:38 -070010384 {
10385 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053010386 hdd_wlan_free_wiphy_channels(wiphy);
Leo Changf04ddad2013-09-18 13:46:38 -070010387 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010388 wiphy_free(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070010389 if (hdd_is_ssr_required())
10390 {
10391 /* WDI timeout had happened during unload, so SSR is needed here */
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -070010392 subsystem_restart("wcnss");
Jeff Johnson295189b2012-06-20 16:38:30 -070010393 msleep(5000);
10394 }
10395 hdd_set_ssr_required (VOS_FALSE);
10396}
10397
10398
10399/**---------------------------------------------------------------------------
10400
10401 \brief hdd_update_config_from_nv() - Function to update the contents of
10402 the running configuration with parameters taken from NV storage
10403
10404 \param - pHddCtx - Pointer to the HDD global context
10405
10406 \return - VOS_STATUS_SUCCESS if successful
10407
10408 --------------------------------------------------------------------------*/
10409static VOS_STATUS hdd_update_config_from_nv(hdd_context_t* pHddCtx)
10410{
Jeff Johnson295189b2012-06-20 16:38:30 -070010411 v_BOOL_t itemIsValid = VOS_FALSE;
10412 VOS_STATUS status;
10413 v_MACADDR_t macFromNV[VOS_MAX_CONCURRENCY_PERSONA];
10414 v_U8_t macLoop;
10415
10416 /*If the NV is valid then get the macaddress from nv else get it from qcom_cfg.ini*/
10417 status = vos_nv_getValidity(VNV_FIELD_IMAGE, &itemIsValid);
10418 if(status != VOS_STATUS_SUCCESS)
10419 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080010420 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_getValidity() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070010421 return VOS_STATUS_E_FAILURE;
10422 }
10423
10424 if (itemIsValid == VOS_TRUE)
10425 {
Arif Hussain6d2a3322013-11-17 19:50:10 -080010426 hddLog(VOS_TRACE_LEVEL_INFO_HIGH," Reading the Macaddress from NV");
Jeff Johnson295189b2012-06-20 16:38:30 -070010427 status = vos_nv_readMultiMacAddress((v_U8_t *)&macFromNV[0].bytes[0],
10428 VOS_MAX_CONCURRENCY_PERSONA);
10429 if(status != VOS_STATUS_SUCCESS)
10430 {
10431 /* Get MAC from NV fail, not update CFG info
10432 * INI MAC value will be used for MAC setting */
Arif Hussain6d2a3322013-11-17 19:50:10 -080010433 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_readMacAddress() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -070010434 return VOS_STATUS_E_FAILURE;
10435 }
10436
10437 /* If first MAC is not valid, treat all others are not valid
10438 * Then all MACs will be got from ini file */
10439 if(vos_is_macaddr_zero(&macFromNV[0]))
10440 {
10441 /* MAC address in NV file is not configured yet */
10442 hddLog(VOS_TRACE_LEVEL_WARN, "Invalid MAC in NV file");
10443 return VOS_STATUS_E_INVAL;
10444 }
10445
10446 /* Get MAC address from NV, update CFG info */
10447 for(macLoop = 0; macLoop < VOS_MAX_CONCURRENCY_PERSONA; macLoop++)
10448 {
10449 if(vos_is_macaddr_zero(&macFromNV[macLoop]))
10450 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010451 hddLog(VOS_TRACE_LEVEL_ERROR,"not valid MAC from NV for %d", macLoop);
Jeff Johnson295189b2012-06-20 16:38:30 -070010452 /* This MAC is not valid, skip it
10453 * This MAC will be got from ini file */
10454 }
10455 else
10456 {
10457 vos_mem_copy((v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[macLoop].bytes[0],
10458 (v_U8_t *)&macFromNV[macLoop].bytes[0],
10459 VOS_MAC_ADDR_SIZE);
10460 }
10461 }
10462 }
10463 else
10464 {
10465 hddLog(VOS_TRACE_LEVEL_ERROR, "NV ITEM, MAC Not valid");
10466 return VOS_STATUS_E_FAILURE;
10467 }
Jeff Johnson295189b2012-06-20 16:38:30 -070010468
Jeff Johnson295189b2012-06-20 16:38:30 -070010469
10470 return VOS_STATUS_SUCCESS;
10471}
10472
10473/**---------------------------------------------------------------------------
10474
10475 \brief hdd_post_voss_start_config() - HDD post voss start config helper
10476
10477 \param - pAdapter - Pointer to the HDD
10478
10479 \return - None
10480
10481 --------------------------------------------------------------------------*/
10482VOS_STATUS hdd_post_voss_start_config(hdd_context_t* pHddCtx)
10483{
10484 eHalStatus halStatus;
10485 v_U32_t listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010486 tANI_U32 ignoreDtim;
Jeff Johnson295189b2012-06-20 16:38:30 -070010487
Jeff Johnson295189b2012-06-20 16:38:30 -070010488
10489 // Send ready indication to the HDD. This will kick off the MAC
10490 // into a 'running' state and should kick off an initial scan.
10491 halStatus = sme_HDDReadyInd( pHddCtx->hHal );
10492 if ( !HAL_STATUS_SUCCESS( halStatus ) )
10493 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +053010494 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: sme_HDDReadyInd() failed with status "
Jeff Johnson295189b2012-06-20 16:38:30 -070010495 "code %08d [x%08x]",__func__, halStatus, halStatus );
10496 return VOS_STATUS_E_FAILURE;
10497 }
10498
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010499 // Set default LI and ignoreDtim into HDD context,
Jeff Johnson295189b2012-06-20 16:38:30 -070010500 // otherwise under some race condition, HDD will set 0 LI value into RIVA,
10501 // And RIVA will crash
10502 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, &listenInterval);
10503 pHddCtx->hdd_actual_LI_value = listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +053010504 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, &ignoreDtim);
10505 pHddCtx->hdd_actual_ignore_DTIM_value = ignoreDtim;
10506
10507
Jeff Johnson295189b2012-06-20 16:38:30 -070010508 return VOS_STATUS_SUCCESS;
10509}
10510
Jeff Johnson295189b2012-06-20 16:38:30 -070010511/* wake lock APIs for HDD */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053010512void hdd_prevent_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070010513{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053010514
10515 vos_wake_lock_acquire(&wlan_wake_lock, reason);
10516
Jeff Johnson295189b2012-06-20 16:38:30 -070010517}
10518
Sushant Kaushik83392fa2015-05-05 17:44:40 +053010519void hdd_allow_suspend(uint32_t reason)
Jeff Johnson295189b2012-06-20 16:38:30 -070010520{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053010521
10522 vos_wake_lock_release(&wlan_wake_lock, reason);
10523
Jeff Johnson295189b2012-06-20 16:38:30 -070010524}
10525
Sushant Kaushik83392fa2015-05-05 17:44:40 +053010526void hdd_prevent_suspend_timeout(v_U32_t timeout, uint32_t reason)
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070010527{
Sushant Kaushik83392fa2015-05-05 17:44:40 +053010528
10529 vos_wake_lock_timeout_release(&wlan_wake_lock, timeout,
10530 reason);
10531
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -070010532}
10533
Jeff Johnson295189b2012-06-20 16:38:30 -070010534/**---------------------------------------------------------------------------
10535
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010536 \brief hdd_exchange_version_and_caps() - HDD function to exchange version and capability
10537 information between Host and Riva
10538
10539 This function gets reported version of FW
10540 It also finds the version of Riva headers used to compile the host
10541 It compares the above two and prints a warning if they are different
10542 It gets the SW and HW version string
10543 Finally, it exchanges capabilities between host and Riva i.e. host and riva exchange a msg
10544 indicating the features they support through a bitmap
10545
10546 \param - pHddCtx - Pointer to HDD context
10547
10548 \return - void
10549
10550 --------------------------------------------------------------------------*/
10551
10552void hdd_exchange_version_and_caps(hdd_context_t *pHddCtx)
10553{
10554
10555 tSirVersionType versionCompiled;
10556 tSirVersionType versionReported;
10557 tSirVersionString versionString;
10558 tANI_U8 fwFeatCapsMsgSupported = 0;
10559 VOS_STATUS vstatus;
10560
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -080010561 memset(&versionCompiled, 0, sizeof(versionCompiled));
10562 memset(&versionReported, 0, sizeof(versionReported));
10563
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010564 /* retrieve and display WCNSS version information */
10565 do {
10566
10567 vstatus = sme_GetWcnssWlanCompiledVersion(pHddCtx->hHal,
10568 &versionCompiled);
10569 if (!VOS_IS_STATUS_SUCCESS(vstatus))
10570 {
10571 hddLog(VOS_TRACE_LEVEL_FATAL,
10572 "%s: unable to retrieve WCNSS WLAN compiled version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010573 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010574 break;
10575 }
10576
10577 vstatus = sme_GetWcnssWlanReportedVersion(pHddCtx->hHal,
10578 &versionReported);
10579 if (!VOS_IS_STATUS_SUCCESS(vstatus))
10580 {
10581 hddLog(VOS_TRACE_LEVEL_FATAL,
10582 "%s: unable to retrieve WCNSS WLAN reported version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010583 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010584 break;
10585 }
10586
10587 if ((versionCompiled.major != versionReported.major) ||
10588 (versionCompiled.minor != versionReported.minor) ||
10589 (versionCompiled.version != versionReported.version) ||
10590 (versionCompiled.revision != versionReported.revision))
10591 {
10592 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
10593 "Host expected %u.%u.%u.%u\n",
10594 WLAN_MODULE_NAME,
10595 (int)versionReported.major,
10596 (int)versionReported.minor,
10597 (int)versionReported.version,
10598 (int)versionReported.revision,
10599 (int)versionCompiled.major,
10600 (int)versionCompiled.minor,
10601 (int)versionCompiled.version,
10602 (int)versionCompiled.revision);
10603 }
10604 else
10605 {
10606 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
10607 WLAN_MODULE_NAME,
10608 (int)versionReported.major,
10609 (int)versionReported.minor,
10610 (int)versionReported.version,
10611 (int)versionReported.revision);
10612 }
10613
10614 vstatus = sme_GetWcnssSoftwareVersion(pHddCtx->hHal,
10615 versionString,
10616 sizeof(versionString));
10617 if (!VOS_IS_STATUS_SUCCESS(vstatus))
10618 {
10619 hddLog(VOS_TRACE_LEVEL_FATAL,
10620 "%s: unable to retrieve WCNSS software version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010621 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010622 break;
10623 }
10624
10625 pr_info("%s: WCNSS software version %s\n",
10626 WLAN_MODULE_NAME, versionString);
Sushant Kaushik084f6592015-09-10 13:11:56 +053010627 vos_mem_copy(pHddCtx->fw_Version, versionString, sizeof(versionString));
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010628
10629 vstatus = sme_GetWcnssHardwareVersion(pHddCtx->hHal,
10630 versionString,
10631 sizeof(versionString));
10632 if (!VOS_IS_STATUS_SUCCESS(vstatus))
10633 {
10634 hddLog(VOS_TRACE_LEVEL_FATAL,
10635 "%s: unable to retrieve WCNSS hardware version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010636 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010637 break;
10638 }
10639
10640 pr_info("%s: WCNSS hardware version %s\n",
10641 WLAN_MODULE_NAME, versionString);
10642
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070010643 /* 1.Check if FW version is greater than 0.1.1.0. Only then send host-FW capability exchange message
10644 2.Host-FW capability exchange message is only present on riva 1.1 so
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010645 send the message only if it the riva is 1.1
10646 minor numbers for different riva branches:
10647 0 -> (1.0)Mainline Build
10648 1 -> (1.1)Mainline Build
10649 2->(1.04) Stability Build
10650 */
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070010651 if (((versionReported.major>0) || (versionReported.minor>1) ||
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010652 ((versionReported.minor>=1) && (versionReported.version>=1)))
10653 && ((versionReported.major == 1) && (versionReported.minor >= 1)))
10654 fwFeatCapsMsgSupported = 1;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070010655
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010656 if (fwFeatCapsMsgSupported)
Yathish9f22e662012-12-10 14:21:35 -080010657 {
10658#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
10659 if(!pHddCtx->cfg_ini->fEnableActiveModeOffload)
10660 sme_disableFeatureCapablity(WLANACTIVE_OFFLOAD);
10661#endif
Ravi Joshid2ca7c42013-07-23 08:37:49 -070010662 /* Indicate if IBSS heartbeat monitoring needs to be offloaded */
10663 if (!pHddCtx->cfg_ini->enableIbssHeartBeatOffload)
10664 {
10665 sme_disableFeatureCapablity(IBSS_HEARTBEAT_OFFLOAD);
10666 }
10667
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010668 sme_featureCapsExchange(pHddCtx->hHal);
Yathish9f22e662012-12-10 14:21:35 -080010669 }
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010670
10671 } while (0);
10672
10673}
Neelansh Mittaledafed22014-09-04 18:54:39 +053010674void wlan_hdd_send_svc_nlink_msg(int type, void *data, int len)
10675{
10676 struct sk_buff *skb;
10677 struct nlmsghdr *nlh;
10678 tAniMsgHdr *ani_hdr;
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053010679 int flags = GFP_KERNEL;
Bhargav shah23c94942015-10-13 12:48:35 +053010680 void *nl_data = NULL;
Neelansh Mittaledafed22014-09-04 18:54:39 +053010681
Hanumantha Reddy Pothulacf2c7ea2015-04-27 14:50:47 +053010682 if (in_interrupt() || irqs_disabled() || in_atomic())
10683 flags = GFP_ATOMIC;
10684
10685 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
Neelansh Mittaledafed22014-09-04 18:54:39 +053010686
10687 if(skb == NULL) {
10688 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10689 "%s: alloc_skb failed", __func__);
10690 return;
10691 }
10692
10693 nlh = (struct nlmsghdr *)skb->data;
10694 nlh->nlmsg_pid = 0; /* from kernel */
10695 nlh->nlmsg_flags = 0;
10696 nlh->nlmsg_seq = 0;
10697 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10698
10699 ani_hdr = NLMSG_DATA(nlh);
10700 ani_hdr->type = type;
10701
10702 switch(type) {
10703 case WLAN_SVC_SAP_RESTART_IND:
10704 ani_hdr->length = 0;
10705 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
10706 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr)));
10707 break;
Bhargav Shahd0715912015-10-01 18:17:37 +053010708 case WLAN_SVC_WLAN_TP_IND:
10709 ani_hdr->length = len;
10710 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)
10711 + len));
10712 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10713 memcpy(nl_data, data, len);
10714 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
10715 break;
Bhargav shah23c94942015-10-13 12:48:35 +053010716 case WLAN_MSG_RPS_ENABLE_IND:
10717 ani_hdr->length = len;
10718 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10719 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10720 memcpy(nl_data, data, len);
10721 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len));
10722 break;
Neelansh Mittaledafed22014-09-04 18:54:39 +053010723 default:
10724 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10725 "Attempt to send unknown nlink message %d", type);
10726 kfree_skb(skb);
10727 return;
10728 }
10729
10730 nl_srv_bcast(skb);
10731
10732 return;
10733}
10734
Bhargav Shahd0715912015-10-01 18:17:37 +053010735/**
10736 * hdd_request_tcp_delack() - Find the Delack value based on RX packet
10737 * @pHddCtx: Valid Global HDD context pointer
10738 * @rx_packets: Number of RX packet in perticular time
10739 *
10740 * Based on the RX packet this function calculate next value of tcp delack.
10741 * This function compare rx packet value to high and low threshold limit.
10742 *
10743 * Return: void
10744 */
10745void hdd_request_tcp_delack(hdd_context_t *pHddCtx, uint64_t rx_packets)
10746{
10747 /* average of rx_packets and prev_rx is taken so that
10748 bus width doesnot fluctuate much */
10749 uint64_t temp_rx = (rx_packets + pHddCtx->prev_rx)/2;
10750 TP_IND_TYPE next_rx_level = pHddCtx->cur_rx_level;
Neelansh Mittaledafed22014-09-04 18:54:39 +053010751
Bhargav Shahd0715912015-10-01 18:17:37 +053010752 pHddCtx->prev_rx = rx_packets;
10753 if (temp_rx > pHddCtx->cfg_ini->tcpDelAckThresholdHigh)
10754 next_rx_level = TP_IND_HIGH;
10755 else if (temp_rx <= pHddCtx->cfg_ini->tcpDelAckThresholdLow)
10756 next_rx_level = TP_IND_LOW;
10757
10758 hdd_set_delack_value(pHddCtx, next_rx_level);
10759}
10760
10761#define HDD_BW_GET_DIFF(x, y) ((x) >= (y) ? (x) - (y) : (ULONG_MAX - (y) + (x)))
10762
10763/**
10764 * hdd_tcp_delack_compute_function() - get link status
10765 * @priv: Valid Global HDD context pointer
10766 *
10767 * This function find number of RX packet during timer life span.
10768 * It request tcp delack with number of RX packet and re-configure delack timer
10769 * for tcpDelAckComputeInterval timer interval.
10770 *
10771 * Return: void
10772 */
10773void hdd_tcp_delack_compute_function(void *priv)
10774{
10775 hdd_context_t *pHddCtx = (hdd_context_t *)priv;
10776 hdd_adapter_t *pAdapter = NULL;
10777 v_U32_t rx_packets = 0;
10778 hdd_adapter_list_node_t *pAdapterNode = NULL;
10779 VOS_STATUS status = 0;
10780
10781 for (status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
10782 NULL != pAdapterNode && VOS_STATUS_SUCCESS == status;
10783 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pAdapterNode)) {
10784 if ((pAdapter = pAdapterNode->pAdapter) == NULL)
10785 continue;
10786
10787 rx_packets += HDD_BW_GET_DIFF(pAdapter->stats.rx_packets,
10788 pAdapter->prev_rx_packets);
10789 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
10790 }
10791
10792 hdd_request_tcp_delack(pHddCtx, rx_packets);
10793
10794 vos_timer_start(&pHddCtx->delack_timer,
10795 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
10796}
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070010797
10798/**---------------------------------------------------------------------------
10799
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053010800 \brief hdd_is_5g_supported() - HDD function to know if hardware supports 5GHz
10801
10802 \param - pHddCtx - Pointer to the hdd context
10803
10804 \return - true if hardware supports 5GHz
10805
10806 --------------------------------------------------------------------------*/
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +053010807boolean hdd_is_5g_supported(hdd_context_t * pHddCtx)
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053010808{
10809 /* If wcnss_wlan_iris_xo_mode() returns WCNSS_XO_48MHZ(1);
10810 * then hardware support 5Ghz.
10811 */
10812 if (WCNSS_XO_48MHZ == wcnss_wlan_iris_xo_mode())
10813 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053010814 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware supports 5Ghz", __func__);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053010815 return true;
10816 }
10817 else
10818 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053010819 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Hardware doesn't supports 5Ghz",
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053010820 __func__);
10821 return false;
10822 }
10823}
10824
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053010825/**---------------------------------------------------------------------------
10826
10827 \brief hdd_generate_iface_mac_addr_auto() - HDD Mac Interface Auto
10828 generate function
10829
10830 This is generate the random mac address for WLAN interface
10831
10832 \param - pHddCtx - Pointer to HDD context
10833 idx - Start interface index to get auto
10834 generated mac addr.
10835 mac_addr - Mac address
10836
10837 \return - 0 for success, < 0 for failure
10838
10839 --------------------------------------------------------------------------*/
10840
10841static int hdd_generate_iface_mac_addr_auto(hdd_context_t *pHddCtx,
10842 int idx, v_MACADDR_t mac_addr)
10843{
10844 int i;
10845 unsigned int serialno;
10846 serialno = wcnss_get_serial_number();
10847
10848 if (0 != serialno)
10849 {
10850 /* MAC address has 3 bytes of OUI so we have a maximum of 3
10851 bytes of the serial number that can be used to generate
10852 the other 3 bytes of the MAC address. Mask off all but
10853 the lower 3 bytes (this will also make sure we don't
10854 overflow in the next step) */
10855 serialno &= 0x00FFFFFF;
10856
10857 /* we need a unique address for each session */
10858 serialno *= VOS_MAX_CONCURRENCY_PERSONA;
10859
10860 /* autogen other Mac addresses */
10861 for (i = idx; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
10862 {
10863 /* start with the entire default address */
10864 pHddCtx->cfg_ini->intfMacAddr[i] = mac_addr;
10865 /* then replace the lower 3 bytes */
10866 pHddCtx->cfg_ini->intfMacAddr[i].bytes[3] = (serialno >> 16) & 0xFF;
10867 pHddCtx->cfg_ini->intfMacAddr[i].bytes[4] = (serialno >> 8) & 0xFF;
10868 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] = serialno & 0xFF;
10869
10870 serialno++;
10871 hddLog(VOS_TRACE_LEVEL_ERROR,
10872 "%s: Derived Mac Addr: "
10873 MAC_ADDRESS_STR, __func__,
10874 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[i].bytes));
10875 }
10876
10877 }
10878 else
10879 {
10880 hddLog(LOGE, FL("Failed to Get Serial NO"));
10881 return -1;
10882 }
10883 return 0;
10884}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053010885
Katya Nigame7b69a82015-04-28 15:24:06 +053010886int wlan_hdd_mon_open(hdd_context_t *pHddCtx)
10887{
10888 VOS_STATUS status;
10889 v_CONTEXT_t pVosContext= NULL;
10890 hdd_adapter_t *pAdapter= NULL;
10891
10892 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
10893
10894 if (NULL == pVosContext)
10895 {
10896 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10897 "%s: Trying to open VOSS without a PreOpen", __func__);
10898 VOS_ASSERT(0);
10899 return VOS_STATUS_E_FAILURE;
10900 }
10901
10902 status = vos_nv_open();
10903 if (!VOS_IS_STATUS_SUCCESS(status))
10904 {
10905 /* NV module cannot be initialized */
10906 hddLog( VOS_TRACE_LEVEL_FATAL,
10907 "%s: vos_nv_open failed", __func__);
10908 return VOS_STATUS_E_FAILURE;
10909 }
10910
10911 status = vos_init_wiphy_from_nv_bin();
10912 if (!VOS_IS_STATUS_SUCCESS(status))
10913 {
10914 /* NV module cannot be initialized */
10915 hddLog( VOS_TRACE_LEVEL_FATAL,
10916 "%s: vos_init_wiphy failed", __func__);
10917 goto err_vos_nv_close;
10918 }
10919
10920 status = vos_open( &pVosContext, pHddCtx->parent_dev);
10921 if ( !VOS_IS_STATUS_SUCCESS( status ))
10922 {
10923 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
10924 goto err_vos_nv_close;
10925 }
10926
10927 status = vos_mon_start( pVosContext );
10928 if ( !VOS_IS_STATUS_SUCCESS( status ) )
10929 {
10930 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
10931 goto err_vosclose;
10932 }
10933
10934 WLANTL_SetMonRxCbk( pVosContext, hdd_rx_packet_monitor_cbk );
10935 WDA_featureCapsExchange(pVosContext);
10936 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
10937
10938 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_MONITOR, "wlan%d",
10939 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
10940 if( pAdapter == NULL )
10941 {
10942 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
10943 goto err_close_adapter;
10944 }
10945
10946 //Initialize the nlink service
10947 if(nl_srv_init() != 0)
10948 {
10949 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
10950 goto err_close_adapter;
10951 }
10952 return VOS_STATUS_SUCCESS;
10953
10954err_close_adapter:
10955 hdd_close_all_adapters( pHddCtx );
10956 vos_mon_stop( pVosContext );
10957err_vosclose:
10958 status = vos_sched_close( pVosContext );
10959 if (!VOS_IS_STATUS_SUCCESS(status)) {
10960 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
10961 "%s: Failed to close VOSS Scheduler", __func__);
10962 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
10963 }
10964 vos_close(pVosContext );
10965
10966err_vos_nv_close:
10967 vos_nv_close();
10968
10969return status;
10970}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053010971/**---------------------------------------------------------------------------
10972
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053010973 \brief hdd_11d_scan_done - callback to be executed when 11d scan is
10974 completed to flush out the scan results
10975
10976 11d scan is done during driver load and is a passive scan on all
10977 channels supported by the device, 11d scans may find some APs on
10978 frequencies which are forbidden to be used in the regulatory domain
10979 the device is operating in. If these APs are notified to the supplicant
10980 it may try to connect to these APs, thus flush out all the scan results
10981 which are present in SME after 11d scan is done.
10982
10983 \return - eHalStatus
10984
10985 --------------------------------------------------------------------------*/
10986static eHalStatus hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
10987 tANI_U32 scanId, eCsrScanStatus status)
10988{
10989 ENTER();
10990
10991 sme_ScanFlushResult(halHandle, 0);
10992
10993 EXIT();
10994
10995 return eHAL_STATUS_SUCCESS;
10996}
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053010997/**---------------------------------------------------------------------------
10998
10999 \brief hdd_init_frame_logging_done - callback to be executed when mgmt frame
11000 logging is completed successfully.
11001
11002 \return - None
11003
11004 --------------------------------------------------------------------------*/
c_manjeecfd1efb2015-09-25 19:32:34 +053011005void hdd_init_frame_logging_done(void *fwlogInitCbContext, tAniLoggingInitRsp *pRsp)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011006{
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011007 hdd_context_t* pHddCtx = (hdd_context_t*)fwlogInitCbContext;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011008
11009 if (NULL == pHddCtx)
11010 {
11011 hddLog(VOS_TRACE_LEVEL_ERROR,
11012 "%s: HDD context is NULL",__func__);
11013 return;
11014 }
11015
c_manjeecfd1efb2015-09-25 19:32:34 +053011016 if ((pRsp->status == VOS_STATUS_SUCCESS) &&
Mahesh A Saptasagarfabb1a02015-06-29 12:17:04 +053011017 (TRUE == pHddCtx->cfg_ini->enableMgmtLogging))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011018 {
11019 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init successful"));
11020 pHddCtx->mgmt_frame_logging = TRUE;
11021 }
11022 else
11023 {
11024 hddLog(VOS_TRACE_LEVEL_INFO, FL("Mgmt Frame Logging init not success"));
11025 pHddCtx->mgmt_frame_logging = FALSE;
c_manjeecfd1efb2015-09-25 19:32:34 +053011026 return;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011027 }
11028
c_manjeecfd1efb2015-09-25 19:32:34 +053011029 /*Check feature supported by FW*/
11030 if(TRUE == sme_IsFeatureSupportedByFW(MEMORY_DUMP_SUPPORTED))
11031 {
11032 //Store fwr mem dump size given by firmware.
11033 wlan_store_fwr_mem_dump_size(pRsp->fw_mem_dump_max_size);
11034 }
11035 else
11036 {
11037 wlan_store_fwr_mem_dump_size(0);
11038 }
11039
11040
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011041}
11042/**---------------------------------------------------------------------------
11043
11044 \brief hdd_init_frame_logging - function to initialize frame logging.
11045 Currently only Mgmt Frames are logged in both TX
11046 and Rx direction and are sent to userspace
11047 application using logger thread when queried.
11048
11049 \return - None
11050
11051 --------------------------------------------------------------------------*/
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011052void hdd_init_frame_logging(hdd_context_t* pHddCtx)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011053{
11054 eHalStatus halStatus = eHAL_STATUS_FAILURE;
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011055 tpSirFWLoggingInitParam wlanFWLoggingInitParam;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011056
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011057 if (TRUE != sme_IsFeatureSupportedByFW(MGMT_FRAME_LOGGING) &&
11058 TRUE != sme_IsFeatureSupportedByFW(LOGGING_ENHANCEMENT))
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011059 {
11060 hddLog(VOS_TRACE_LEVEL_INFO, FL("MGMT_FRAME_LOGGING not supp by FW"));
11061 return;
11062 }
11063
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011064 wlanFWLoggingInitParam = vos_mem_malloc(sizeof(tSirFWLoggingInitParam));
11065 if(NULL == wlanFWLoggingInitParam)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011066 {
11067 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_mem_alloc failed ", __func__);
11068 return;
11069 }
11070
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011071 vos_mem_set(wlanFWLoggingInitParam, sizeof(tSirFWLoggingInitParam), 0);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011072
c_manjeecfd1efb2015-09-25 19:32:34 +053011073 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Configuring %s %s %s %s Logging",__func__,
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011074 pHddCtx->cfg_ini->enableFWLogging?"FW Log,":"",
11075 pHddCtx->cfg_ini->enableContFWLogging ? "Cont FW log,":"",
c_manjeecfd1efb2015-09-25 19:32:34 +053011076 pHddCtx->cfg_ini->enableMgmtLogging ? "Mgmt Pkt Log":"",
11077 pHddCtx->cfg_ini->enableFwrMemDump ? "Fw Mem dump":"");
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011078
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011079 if (pHddCtx->cfg_ini->enableFWLogging ||
11080 pHddCtx->cfg_ini->enableContFWLogging)
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011081 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011082 wlanFWLoggingInitParam->enableFlag |= WLAN_QXDM_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011083 }
11084
Sushant Kaushik46804902015-07-08 14:46:03 +053011085 if (pHddCtx->cfg_ini->enableMgmtLogging)
11086 {
11087 wlanFWLoggingInitParam->enableFlag |= WLAN_FRAME_LOG_EN;
11088 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011089 if (pHddCtx->cfg_ini->enableBMUHWtracing)
11090 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011091 wlanFWLoggingInitParam->enableFlag |= WLAN_BMUHW_TRACE_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011092 }
c_manjeecfd1efb2015-09-25 19:32:34 +053011093 if(pHddCtx->cfg_ini->enableFwrMemDump &&
11094 (TRUE == sme_IsFeatureSupportedByFW(MEMORY_DUMP_SUPPORTED)))
11095 {
11096 wlanFWLoggingInitParam->enableFlag |= WLAN_FW_MEM_DUMP_EN;
11097 }
11098 if( wlanFWLoggingInitParam->enableFlag == 0 )
11099 {
11100 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Logging not enabled", __func__);
11101 return;
11102 }
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011103 wlanFWLoggingInitParam->frameType = WLAN_FRAME_LOGGING_FRAMETYPE_MGMT;
11104 wlanFWLoggingInitParam->frameSize = WLAN_MGMT_LOGGING_FRAMESIZE_128BYTES;
11105 wlanFWLoggingInitParam->bufferMode = WLAN_FRAME_LOGGING_BUFFERMODE_CIRCULAR;
11106 wlanFWLoggingInitParam->continuousFrameLogging =
11107 pHddCtx->cfg_ini->enableContFWLogging;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011108
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011109 wlanFWLoggingInitParam->enableFlag &= ~WLAN_DPU_TXP_LOG_EN;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011110
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011111 wlanFWLoggingInitParam->minLogBufferSize =
11112 pHddCtx->cfg_ini->minLoggingBufferSize;
11113 wlanFWLoggingInitParam->maxLogBufferSize =
11114 pHddCtx->cfg_ini->maxLoggingBufferSize;
11115 wlanFWLoggingInitParam->fwlogInitCallback = hdd_init_frame_logging_done;
11116 wlanFWLoggingInitParam->fwlogInitCbContext= pHddCtx;
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011117
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011118 halStatus = sme_InitMgmtFrameLogging(pHddCtx->hHal, wlanFWLoggingInitParam);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011119
11120 if (eHAL_STATUS_SUCCESS != halStatus)
11121 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053011122 vos_mem_free(wlanFWLoggingInitParam);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053011123 }
11124
11125 return;
11126}
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053011127
Bhargav shah23c94942015-10-13 12:48:35 +053011128static void hdd_dp_util_send_rps_ind(hdd_context_t *hdd_ctxt)
11129{
11130 hdd_adapter_t *adapter;
11131 hdd_adapter_list_node_t *adapter_node, *next;
11132 VOS_STATUS status = VOS_STATUS_SUCCESS;
11133 struct wlan_rps_data rps_data;
11134 int count;
11135
11136 if(!hdd_ctxt->cfg_ini->rps_mask)
11137 {
11138 return;
11139 }
11140
11141 for (count=0; count < WLAN_SVC_IFACE_NUM_QUEUES; count++)
11142 {
11143 rps_data.cpu_map[count] = hdd_ctxt->cfg_ini->rps_mask;
11144 }
11145
11146 rps_data.num_queues = WLAN_SVC_IFACE_NUM_QUEUES;
11147
11148 hddLog(LOG1, FL("0x%x 0x%x 0x%x 0x%x 0x%x 0x%x"),
11149 rps_data.cpu_map[0], rps_data.cpu_map[1],rps_data.cpu_map[2],
11150 rps_data.cpu_map[3], rps_data.cpu_map[4], rps_data.cpu_map[5]);
11151
11152 status = hdd_get_front_adapter (hdd_ctxt, &adapter_node);
11153
11154 while (NULL != adapter_node && VOS_STATUS_SUCCESS == status)
11155 {
11156 adapter = adapter_node->pAdapter;
11157 if (NULL != adapter) {
11158 strlcpy(rps_data.ifname, adapter->dev->name,
11159 sizeof(rps_data.ifname));
11160 wlan_hdd_send_svc_nlink_msg(WLAN_MSG_RPS_ENABLE_IND,
11161 (void *)&rps_data,sizeof(rps_data));
11162 }
11163 status = hdd_get_next_adapter (hdd_ctxt, adapter_node, &next);
11164 adapter_node = next;
11165 }
11166}
11167
Masti, Narayanraddi26378462016-01-05 18:20:28 +053011168void wlan_hdd_schedule_defer_scan(struct work_struct *work)
11169{
11170 scan_context_t *scan_ctx =
11171 container_of(work, scan_context_t, scan_work.work);
11172
11173 if (NULL == scan_ctx)
11174 {
11175 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
11176 FL("scan_ctx is NULL"));
11177 return;
11178 }
11179
11180 if (unlikely(TDLS_CTX_MAGIC != scan_ctx->magic))
11181 return;
11182
11183 scan_ctx->attempt++;
11184
11185 wlan_hdd_cfg80211_scan(scan_ctx->wiphy,
11186#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
11187 scan_ctx->dev,
11188#endif
11189 scan_ctx->scan_request);
11190}
11191
11192int wlan_hdd_copy_defer_scan_context(hdd_context_t *pHddCtx,
11193 struct wiphy *wiphy,
11194#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
11195 struct net_device *dev,
11196#endif
11197 struct cfg80211_scan_request *request)
11198{
11199 scan_context_t *scan_ctx;
11200
11201 ENTER();
11202 if (0 != (wlan_hdd_validate_context(pHddCtx)))
11203 {
11204 return -1;
11205 }
11206
11207 scan_ctx = &pHddCtx->scan_ctxt;
11208
11209 scan_ctx->wiphy = wiphy;
11210#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
11211 scan_ctx->dev = dev;
11212#endif
11213
11214 scan_ctx->scan_request = request;
11215
11216 EXIT();
11217 return 0;
11218}
11219
11220void wlan_hdd_defer_scan_init_work(hdd_context_t *pHddCtx,
11221 struct wiphy *wiphy,
11222#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
11223 struct net_device *dev,
11224#endif
11225 struct cfg80211_scan_request *request,
11226 unsigned long delay)
11227{
11228 if (TDLS_CTX_MAGIC != pHddCtx->scan_ctxt.magic)
11229 {
11230#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
11231 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, dev, request);
11232#else
11233 wlan_hdd_copy_defer_scan_context(pHddCtx, wiphy, request);
11234#endif
11235 pHddCtx->scan_ctxt.attempt = 0;
11236 pHddCtx->scan_ctxt.magic = TDLS_CTX_MAGIC;
11237 }
11238 schedule_delayed_work(&pHddCtx->scan_ctxt.scan_work, delay);
11239}
11240
11241void wlan_hdd_init_deinit_defer_scan_context(scan_context_t *scan_ctx)
11242{
11243 scan_ctx->magic = 0;
11244 scan_ctx->attempt = 0;
11245 scan_ctx->reject = 0;
11246 scan_ctx->scan_request = NULL;
11247
11248 return;
11249}
11250
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053011251/**---------------------------------------------------------------------------
11252
Jeff Johnson295189b2012-06-20 16:38:30 -070011253 \brief hdd_wlan_startup() - HDD init function
11254
11255 This is the driver startup code executed once a WLAN device has been detected
11256
11257 \param - dev - Pointer to the underlying device
11258
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080011259 \return - 0 for success, < 0 for failure
Jeff Johnson295189b2012-06-20 16:38:30 -070011260
11261 --------------------------------------------------------------------------*/
11262
11263int hdd_wlan_startup(struct device *dev )
11264{
11265 VOS_STATUS status;
11266 hdd_adapter_t *pAdapter = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -070011267 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070011268 hdd_context_t *pHddCtx = NULL;
11269 v_CONTEXT_t pVosContext= NULL;
11270#ifdef WLAN_BTAMP_FEATURE
11271 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
11272 WLANBAP_ConfigType btAmpConfig;
11273 hdd_config_t *pConfig;
11274#endif
11275 int ret;
Jeff Johnson295189b2012-06-20 16:38:30 -070011276 struct wiphy *wiphy;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053011277 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -070011278
11279 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -070011280 /*
11281 * cfg80211: wiphy allocation
11282 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053011283 wiphy = wlan_hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t)) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070011284
11285 if(wiphy == NULL)
11286 {
11287 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080011288 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070011289 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011290 pHddCtx = wiphy_priv(wiphy);
11291
Jeff Johnson295189b2012-06-20 16:38:30 -070011292 //Initialize the adapter context to zeros.
11293 vos_mem_zero(pHddCtx, sizeof( hdd_context_t ));
11294
Jeff Johnson295189b2012-06-20 16:38:30 -070011295 pHddCtx->wiphy = wiphy;
Sushant Kaushik83392fa2015-05-05 17:44:40 +053011296 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Mihir Shete18156292014-03-11 15:38:30 +053011297 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_LOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070011298
11299 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
11300
Siddharth Bhalcd92b782015-06-29 12:25:40 +053011301 /* register for riva power on lock to platform driver
11302 * Locking power early to ensure FW doesn't reset by kernel while
11303 * host driver is busy initializing itself */
11304 if (req_riva_power_on_lock("wlan"))
11305 {
11306 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: req riva power on lock failed",
11307 __func__);
11308 goto err_free_hdd_context;
11309 }
11310
Jeff Johnson295189b2012-06-20 16:38:30 -070011311 /*Get vos context here bcoz vos_open requires it*/
11312 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
11313
Madan Mohan Koyyalamudi0b78e152012-11-28 15:46:51 -080011314 if(pVosContext == NULL)
11315 {
11316 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed vos_get_global_context",__func__);
11317 goto err_free_hdd_context;
11318 }
11319
Jeff Johnson295189b2012-06-20 16:38:30 -070011320 //Save the Global VOSS context in adapter context for future.
11321 pHddCtx->pvosContext = pVosContext;
11322
11323 //Save the adapter context in global context for future.
11324 ((VosContextType*)(pVosContext))->pHDDContext = (v_VOID_t*)pHddCtx;
11325
Jeff Johnson295189b2012-06-20 16:38:30 -070011326 pHddCtx->parent_dev = dev;
11327
11328 init_completion(&pHddCtx->full_pwr_comp_var);
11329 init_completion(&pHddCtx->standby_comp_var);
11330 init_completion(&pHddCtx->req_bmps_comp_var);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070011331 init_completion(&pHddCtx->scan_info.scan_req_completion_event);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -080011332 init_completion(&pHddCtx->scan_info.abortscan_event_var);
Kiet Lam46b8e4e2013-11-06 21:49:53 +053011333 init_completion(&pHddCtx->wiphy_channel_update_event);
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053011334 init_completion(&pHddCtx->ssr_comp_var);
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053011335 init_completion(&pHddCtx->mc_sus_event_var);
11336 init_completion(&pHddCtx->tx_sus_event_var);
11337 init_completion(&pHddCtx->rx_sus_event_var);
11338
Amar Singhala49cbc52013-10-08 18:37:44 -070011339
mukul sharma4bd8d2e2015-08-13 20:33:25 +053011340 hdd_init_ll_stats_ctx(pHddCtx);
11341
Amar Singhala49cbc52013-10-08 18:37:44 -070011342#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhalfddc28c2013-09-05 13:03:40 -070011343 init_completion(&pHddCtx->linux_reg_req);
Amar Singhala49cbc52013-10-08 18:37:44 -070011344#else
11345 init_completion(&pHddCtx->driver_crda_req);
11346#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070011347
Padma, Santhosh Kumara1aa4a32015-06-19 19:00:46 +053011348#ifdef WLAN_FEATURE_EXTSCAN
11349 init_completion(&pHddCtx->ext_scan_context.response_event);
11350#endif /* WLAN_FEATURE_EXTSCAN */
11351
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053011352 spin_lock_init(&pHddCtx->schedScan_lock);
11353
Jeff Johnson295189b2012-06-20 16:38:30 -070011354 hdd_list_init( &pHddCtx->hddAdapters, MAX_NUMBER_OF_ADAPTERS );
11355
Padma, Santhosh Kumar9cd38332015-11-17 12:18:10 +053011356 vos_init_delayed_work(&pHddCtx->spoof_mac_addr_work,
11357 hdd_processSpoofMacAddrRequest);
11358
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053011359#ifdef FEATURE_WLAN_TDLS
11360 /* tdls_lock is initialized before an hdd_open_adapter ( which is
11361 * invoked by other instances also) to protect the concurrent
11362 * access for the Adapters by TDLS module.
11363 */
11364 mutex_init(&pHddCtx->tdls_lock);
11365#endif
Siddharth Bhal76972212014-10-15 16:22:51 +053011366 mutex_init(&pHddCtx->spoofMacAddr.macSpoofingLock);
Mukul Sharma1fd6efd2015-02-14 00:29:14 +053011367 mutex_init(&pHddCtx->wmmLock);
11368
Srinivas Girigowda8bf64cb2015-09-30 19:50:09 +053011369 hdd_init_offloaded_packets_ctx(pHddCtx);
Agarwal Ashish1f422872014-07-22 00:11:55 +053011370 /* By default Strict Regulatory For FCC should be false */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +053011371
Agarwal Ashish1f422872014-07-22 00:11:55 +053011372 pHddCtx->nEnableStrictRegulatoryForFCC = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -070011373 // Load all config first as TL config is needed during vos_open
11374 pHddCtx->cfg_ini = (hdd_config_t*) kmalloc(sizeof(hdd_config_t), GFP_KERNEL);
11375 if(pHddCtx->cfg_ini == NULL)
11376 {
11377 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed kmalloc hdd_config_t",__func__);
11378 goto err_free_hdd_context;
11379 }
11380
11381 vos_mem_zero(pHddCtx->cfg_ini, sizeof( hdd_config_t ));
11382
11383 // Read and parse the qcom_cfg.ini file
11384 status = hdd_parse_config_ini( pHddCtx );
11385 if ( VOS_STATUS_SUCCESS != status )
11386 {
11387 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: error parsing %s",
11388 __func__, WLAN_INI_FILE);
11389 goto err_config;
11390 }
Arif Hussaind5218912013-12-05 01:10:55 -080011391#ifdef MEMORY_DEBUG
11392 if (pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled)
11393 vos_mem_init();
11394
11395 hddLog(VOS_TRACE_LEVEL_INFO, "%s: gEnableMemoryDebug=%d",
11396 __func__, pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled);
11397#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070011398
Gopichand Nakkalab8f0f1a2013-05-23 18:19:48 +053011399 /* INI has been read, initialise the configuredMcastBcastFilter with
11400 * INI value as this will serve as the default value
11401 */
11402 pHddCtx->configuredMcastBcastFilter = pHddCtx->cfg_ini->mcastBcastFilterSetting;
11403 hddLog(VOS_TRACE_LEVEL_INFO, "Setting configuredMcastBcastFilter: %d",
11404 pHddCtx->cfg_ini->mcastBcastFilterSetting);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +053011405
11406 if (false == hdd_is_5g_supported(pHddCtx))
11407 {
11408 //5Ghz is not supported.
11409 if (1 != pHddCtx->cfg_ini->nBandCapability)
11410 {
11411 hddLog(VOS_TRACE_LEVEL_INFO,
11412 "%s: Setting pHddCtx->cfg_ini->nBandCapability = 1", __func__);
11413 pHddCtx->cfg_ini->nBandCapability = 1;
11414 }
11415 }
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +053011416
11417 /* If SNR Monitoring is enabled, FW has to parse all beacons
11418 * for calcaluting and storing the average SNR, so set Nth beacon
11419 * filter to 1 to enable FW to parse all the beaocons
11420 */
11421 if (1 == pHddCtx->cfg_ini->fEnableSNRMonitoring)
11422 {
11423 /* The log level is deliberately set to WARN as overriding
11424 * nthBeaconFilter to 1 will increase power cosumption and this
11425 * might just prove helpful to detect the power issue.
11426 */
11427 hddLog(VOS_TRACE_LEVEL_WARN,
11428 "%s: Setting pHddCtx->cfg_ini->nthBeaconFilter = 1", __func__);
11429 pHddCtx->cfg_ini->nthBeaconFilter = 1;
11430 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011431 /*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053011432 * cfg80211: Initialization ...
Jeff Johnson295189b2012-06-20 16:38:30 -070011433 */
Manjunathappa Prakasheec4ddf2014-01-13 18:23:51 -080011434 if (VOS_FTM_MODE != hdd_get_conparam())
Jeff Johnson295189b2012-06-20 16:38:30 -070011435 {
Manjunathappa Prakasheec4ddf2014-01-13 18:23:51 -080011436 if (0 < wlan_hdd_cfg80211_init(dev, wiphy, pHddCtx->cfg_ini))
11437 {
11438 hddLog(VOS_TRACE_LEVEL_FATAL,
11439 "%s: wlan_hdd_cfg80211_init return failure", __func__);
11440 goto err_config;
11441 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011442 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011443
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080011444 // Update VOS trace levels based upon the cfg.ini
11445 hdd_vos_trace_enable(VOS_MODULE_ID_BAP,
11446 pHddCtx->cfg_ini->vosTraceEnableBAP);
11447 hdd_vos_trace_enable(VOS_MODULE_ID_TL,
11448 pHddCtx->cfg_ini->vosTraceEnableTL);
11449 hdd_vos_trace_enable(VOS_MODULE_ID_WDI,
11450 pHddCtx->cfg_ini->vosTraceEnableWDI);
11451 hdd_vos_trace_enable(VOS_MODULE_ID_HDD,
11452 pHddCtx->cfg_ini->vosTraceEnableHDD);
11453 hdd_vos_trace_enable(VOS_MODULE_ID_SME,
11454 pHddCtx->cfg_ini->vosTraceEnableSME);
11455 hdd_vos_trace_enable(VOS_MODULE_ID_PE,
11456 pHddCtx->cfg_ini->vosTraceEnablePE);
Katya Nigam70d68332013-09-16 16:49:45 +053011457 hdd_vos_trace_enable(VOS_MODULE_ID_PMC,
11458 pHddCtx->cfg_ini->vosTraceEnablePMC);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080011459 hdd_vos_trace_enable(VOS_MODULE_ID_WDA,
11460 pHddCtx->cfg_ini->vosTraceEnableWDA);
11461 hdd_vos_trace_enable(VOS_MODULE_ID_SYS,
11462 pHddCtx->cfg_ini->vosTraceEnableSYS);
11463 hdd_vos_trace_enable(VOS_MODULE_ID_VOSS,
11464 pHddCtx->cfg_ini->vosTraceEnableVOSS);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080011465 hdd_vos_trace_enable(VOS_MODULE_ID_SAP,
11466 pHddCtx->cfg_ini->vosTraceEnableSAP);
11467 hdd_vos_trace_enable(VOS_MODULE_ID_HDD_SOFTAP,
11468 pHddCtx->cfg_ini->vosTraceEnableHDDSAP);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -080011469
Jeff Johnson295189b2012-06-20 16:38:30 -070011470 // Update WDI trace levels based upon the cfg.ini
11471 hdd_wdi_trace_enable(eWLAN_MODULE_DAL,
11472 pHddCtx->cfg_ini->wdiTraceEnableDAL);
11473 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_CTRL,
11474 pHddCtx->cfg_ini->wdiTraceEnableCTL);
11475 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_DATA,
11476 pHddCtx->cfg_ini->wdiTraceEnableDAT);
11477 hdd_wdi_trace_enable(eWLAN_MODULE_PAL,
11478 pHddCtx->cfg_ini->wdiTraceEnablePAL);
Jeff Johnson295189b2012-06-20 16:38:30 -070011479
Jeff Johnson88ba7742013-02-27 14:36:02 -080011480 if (VOS_FTM_MODE == hdd_get_conparam())
11481 {
Jeff Johnson295189b2012-06-20 16:38:30 -070011482 if ( VOS_STATUS_SUCCESS != wlan_hdd_ftm_open(pHddCtx) )
11483 {
11484 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_ftm_open Failed",__func__);
11485 goto err_free_hdd_context;
11486 }
11487 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: FTM driver loaded success fully",__func__);
Sachin Ahuja38ef5e02015-03-13 17:31:16 +053011488 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
c_hpothu2de0ef62014-04-15 16:16:15 +053011489 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -070011490 return VOS_STATUS_SUCCESS;
Jeff Johnson88ba7742013-02-27 14:36:02 -080011491 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011492
Katya Nigame7b69a82015-04-28 15:24:06 +053011493 if( VOS_MONITOR_MODE == hdd_get_conparam())
11494 {
11495 if ( VOS_STATUS_SUCCESS != wlan_hdd_mon_open(pHddCtx))
11496 {
11497 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_mon_open Failed",__func__);
11498 goto err_free_hdd_context;
11499 }
11500 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Driver loaded in Monitor Mode",__func__);
11501 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
11502 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
11503 return VOS_STATUS_SUCCESS;
11504 }
11505
Jeff Johnson88ba7742013-02-27 14:36:02 -080011506 //Open watchdog module
Jeff Johnson295189b2012-06-20 16:38:30 -070011507 if(pHddCtx->cfg_ini->fIsLogpEnabled)
11508 {
11509 status = vos_watchdog_open(pVosContext,
11510 &((VosContextType*)pVosContext)->vosWatchdog, sizeof(VosWatchdogContext));
11511
11512 if(!VOS_IS_STATUS_SUCCESS( status ))
11513 {
11514 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_watchdog_open failed",__func__);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053011515 goto err_wdclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070011516 }
11517 }
11518
11519 pHddCtx->isLogpInProgress = FALSE;
11520 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
11521
Amar Singhala49cbc52013-10-08 18:37:44 -070011522#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070011523 /* initialize the NV module. This is required so that
11524 we can initialize the channel information in wiphy
11525 from the NV.bin data. The channel information in
11526 wiphy needs to be initialized before wiphy registration */
11527
11528 status = vos_nv_open();
11529 if (!VOS_IS_STATUS_SUCCESS(status))
11530 {
11531 /* NV module cannot be initialized */
11532 hddLog( VOS_TRACE_LEVEL_FATAL,
11533 "%s: vos_nv_open failed", __func__);
Vinay Krishna Eranna2025d892014-09-18 16:51:42 +053011534 goto err_wdclose;
Amar Singhal0a402232013-10-11 20:57:16 -070011535 }
11536
11537 status = vos_init_wiphy_from_nv_bin();
11538 if (!VOS_IS_STATUS_SUCCESS(status))
11539 {
11540 /* NV module cannot be initialized */
11541 hddLog( VOS_TRACE_LEVEL_FATAL,
11542 "%s: vos_init_wiphy failed", __func__);
11543 goto err_vos_nv_close;
11544 }
11545
Amar Singhala49cbc52013-10-08 18:37:44 -070011546#endif
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053011547 //Initialize the nlink service
11548 if(nl_srv_init() != 0)
11549 {
11550 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
11551 goto err_vos_nv_close;
11552 }
11553
11554#ifdef WLAN_KD_READY_NOTIFIER
11555 pHddCtx->kd_nl_init = 1;
11556#endif /* WLAN_KD_READY_NOTIFIER */
11557
Girish Gowlibf0e1ab2015-01-19 16:05:16 +053011558 vos_set_roam_delay_stats_enabled(pHddCtx->cfg_ini->gEnableRoamDelayStats);
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053011559 status = vos_open( &pVosContext, pHddCtx->parent_dev);
Jeff Johnson295189b2012-06-20 16:38:30 -070011560 if ( !VOS_IS_STATUS_SUCCESS( status ))
11561 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011562 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053011563 goto err_nl_srv;
Jeff Johnson295189b2012-06-20 16:38:30 -070011564 }
11565
Jeff Johnson295189b2012-06-20 16:38:30 -070011566 pHddCtx->hHal = (tHalHandle)vos_get_context( VOS_MODULE_ID_SME, pVosContext );
11567
11568 if ( NULL == pHddCtx->hHal )
11569 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011570 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: HAL context is null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070011571 goto err_vosclose;
11572 }
11573
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011574 status = vos_preStart( pHddCtx->pvosContext );
11575 if ( !VOS_IS_STATUS_SUCCESS( status ) )
11576 {
11577 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_preStart failed", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053011578 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011579 }
Jeff Johnsone7245742012-09-05 17:12:55 -070011580
Arif Hussaineaf68602013-12-30 23:10:44 -080011581 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan)
11582 {
11583 pHddCtx->cfg_ini->enableDFSChnlScan = enable_dfs_chan_scan;
11584 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_dfs_chan_scan set to %d",
11585 __func__, enable_dfs_chan_scan);
11586 }
11587 if (0 == enable_11d || 1 == enable_11d)
11588 {
11589 pHddCtx->cfg_ini->Is11dSupportEnabled = enable_11d;
11590 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_11d set to %d",
11591 __func__, enable_11d);
11592 }
11593
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011594 /* Note that the vos_preStart() sequence triggers the cfg download.
11595 The cfg download must occur before we update the SME config
11596 since the SME config operation must access the cfg database */
Jeff Johnson295189b2012-06-20 16:38:30 -070011597 status = hdd_set_sme_config( pHddCtx );
11598
11599 if ( VOS_STATUS_SUCCESS != status )
11600 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011601 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed hdd_set_sme_config", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053011602 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011603 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011604
Jeff Johnson295189b2012-06-20 16:38:30 -070011605 /* In the integrated architecture we update the configuration from
11606 the INI file and from NV before vOSS has been started so that
11607 the final contents are available to send down to the cCPU */
11608
11609 // Apply the cfg.ini to cfg.dat
11610 if (FALSE == hdd_update_config_dat(pHddCtx))
11611 {
11612 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053011613 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070011614 }
11615
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053011616 // Get mac addr from platform driver
11617 ret = wcnss_get_wlan_mac_address((char*)&mac_addr.bytes);
11618
11619 if ((0 == ret) && (!vos_is_macaddr_zero(&mac_addr)))
Jeff Johnson295189b2012-06-20 16:38:30 -070011620 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053011621 /* Store the mac addr for first interface */
11622 pHddCtx->cfg_ini->intfMacAddr[0] = mac_addr;
11623
11624 hddLog(VOS_TRACE_LEVEL_ERROR,
11625 "%s: WLAN Mac Addr: "
11626 MAC_ADDRESS_STR, __func__,
11627 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
11628
11629 /* Here, passing Arg2 as 1 because we do not want to change the
11630 last 3 bytes (means non OUI bytes) of first interface mac
11631 addr.
11632 */
11633 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 1, mac_addr))
11634 {
11635 hddLog(VOS_TRACE_LEVEL_ERROR,
11636 "%s: Failed to generate wlan interface mac addr "
11637 "using MAC from ini file ", __func__);
11638 }
11639 }
11640 else if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
11641 {
11642 // Apply the NV to cfg.dat
11643 /* Prima Update MAC address only at here */
Jeff Johnson295189b2012-06-20 16:38:30 -070011644#ifdef WLAN_AUTOGEN_MACADDR_FEATURE
11645 /* There was not a valid set of MAC Addresses in NV. See if the
11646 default addresses were modified by the cfg.ini settings. If so,
11647 we'll use them, but if not, we'll autogenerate a set of MAC
11648 addresses based upon the device serial number */
11649
11650 static const v_MACADDR_t default_address =
11651 {{0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}};
Jeff Johnson295189b2012-06-20 16:38:30 -070011652
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053011653 if (0 == memcmp(&default_address, &pHddCtx->cfg_ini->intfMacAddr[0],
11654 sizeof(default_address)))
Jeff Johnson295189b2012-06-20 16:38:30 -070011655 {
11656 /* cfg.ini has the default address, invoke autogen logic */
11657
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053011658 /* Here, passing Arg2 as 0 because we want to change the
11659 last 3 bytes (means non OUI bytes) of all the interfaces
11660 mac addr.
11661 */
11662 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 0,
11663 default_address))
Jeff Johnson295189b2012-06-20 16:38:30 -070011664 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053011665 hddLog(VOS_TRACE_LEVEL_ERROR,
11666 "%s: Failed to generate wlan interface mac addr "
11667 "using MAC from ini file " MAC_ADDRESS_STR, __func__,
11668 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
Jeff Johnson295189b2012-06-20 16:38:30 -070011669 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011670 }
11671 else
11672#endif //WLAN_AUTOGEN_MACADDR_FEATURE
11673 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011674 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -070011675 "%s: Invalid MAC address in NV, using MAC from ini file "
11676 MAC_ADDRESS_STR, __func__,
11677 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
11678 }
11679 }
11680 {
11681 eHalStatus halStatus;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053011682
11683 /* Set the MAC Address Currently this is used by HAL to
11684 * add self sta. Remove this once self sta is added as
11685 * part of session open.
11686 */
Jeff Johnson295189b2012-06-20 16:38:30 -070011687 halStatus = cfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
11688 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
11689 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]) );
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +053011690
Jeff Johnson295189b2012-06-20 16:38:30 -070011691 if (!HAL_STATUS_SUCCESS( halStatus ))
11692 {
11693 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
11694 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053011695 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070011696 }
11697 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011698
11699 /*Start VOSS which starts up the SME/MAC/HAL modules and everything else
11700 Note: Firmware image will be read and downloaded inside vos_start API */
11701 status = vos_start( pHddCtx->pvosContext );
11702 if ( !VOS_IS_STATUS_SUCCESS( status ) )
11703 {
11704 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
Hanumantha Reddy Pothulabd9601a2016-02-12 13:22:27 +053011705 if (isSsrPanicOnFailure())
11706 VOS_BUG(0);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053011707 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -070011708 }
11709
Leo Chang6cec3e22014-01-21 15:33:49 -080011710#ifdef FEATURE_WLAN_CH_AVOID
11711 /* Plug in avoid channel notification callback
11712 * This should happen before ADD_SELF_STA
11713 * FW will send first IND with ADD_SELF_STA REQ from host */
Pradeep Reddy POTTETI5c2e16d2014-06-27 16:47:38 +053011714
11715 /* check the Channel Avoidance is enabled */
11716 if (TRUE == pHddCtx->cfg_ini->fenableCHAvoidance)
11717 {
11718 sme_AddChAvoidCallback(pHddCtx->hHal,
11719 hdd_hostapd_ch_avoid_cb);
11720 }
Leo Chang6cec3e22014-01-21 15:33:49 -080011721#endif /* FEATURE_WLAN_CH_AVOID */
11722
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -070011723 /* Exchange capability info between Host and FW and also get versioning info from FW */
11724 hdd_exchange_version_and_caps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070011725
Agarwal Ashishad9281b2014-06-10 14:57:30 +053011726#ifdef CONFIG_ENABLE_LINUX_REG
11727 status = wlan_hdd_init_channels(pHddCtx);
11728 if ( !VOS_IS_STATUS_SUCCESS( status ) )
11729 {
11730 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels failed",
11731 __func__);
11732 goto err_vosstop;
11733 }
11734#endif
11735
Jeff Johnson295189b2012-06-20 16:38:30 -070011736 status = hdd_post_voss_start_config( pHddCtx );
11737 if ( !VOS_IS_STATUS_SUCCESS( status ) )
11738 {
11739 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_post_voss_start_config failed",
11740 __func__);
11741 goto err_vosstop;
11742 }
Amar Singhala49cbc52013-10-08 18:37:44 -070011743
11744#ifndef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053011745 wlan_hdd_cfg80211_update_reg_info( wiphy );
11746
11747 /* registration of wiphy dev with cfg80211 */
11748 if (0 > wlan_hdd_cfg80211_register(wiphy))
11749 {
11750 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
11751 goto err_vosstop;
11752 }
Amar Singhala49cbc52013-10-08 18:37:44 -070011753#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070011754
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053011755#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053011756 /* registration of wiphy dev with cfg80211 */
11757 if (0 > wlan_hdd_cfg80211_register(wiphy))
11758 {
11759 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
11760 goto err_vosstop;
11761 }
11762
Agarwal Ashish6db9d532014-09-30 18:19:10 +053011763 status = wlan_hdd_init_channels_for_cc(pHddCtx, INIT);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053011764 if ( !VOS_IS_STATUS_SUCCESS( status ) )
11765 {
11766 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels_for_cc failed",
11767 __func__);
11768 goto err_unregister_wiphy;
11769 }
11770#endif
11771
c_hpothu4a298be2014-12-22 21:12:51 +053011772 wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx);
11773
Jeff Johnson295189b2012-06-20 16:38:30 -070011774 if (VOS_STA_SAP_MODE == hdd_get_conparam())
11775 {
11776 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP, "softap.%d",
11777 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
11778 }
11779 else
11780 {
Jeff Johnson295189b2012-06-20 16:38:30 -070011781 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_INFRA_STATION, "wlan%d",
11782 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
11783 if (pAdapter != NULL)
11784 {
Katya Nigama7d81d72014-11-12 12:44:34 +053011785 if (pHddCtx->cfg_ini->isP2pDeviceAddrAdministrated && !(pHddCtx->cfg_ini->intfMacAddr[0].bytes[0] & 0x02))
Jeff Johnson295189b2012-06-20 16:38:30 -070011786 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053011787 vos_mem_copy( pHddCtx->p2pDeviceAddress.bytes,
11788 pHddCtx->cfg_ini->intfMacAddr[0].bytes,
11789 sizeof(tSirMacAddr));
Madan Mohan Koyyalamudiedfc1b72012-10-18 20:25:55 -070011790
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053011791 /* Generate the P2P Device Address. This consists of the device's
11792 * primary MAC address with the locally administered bit set.
11793 */
11794 pHddCtx->p2pDeviceAddress.bytes[0] |= 0x02;
Jeff Johnsone7245742012-09-05 17:12:55 -070011795 }
11796 else
11797 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +053011798 tANI_U8* p2p_dev_addr = wlan_hdd_get_intf_addr(pHddCtx);
11799 if (p2p_dev_addr != NULL)
11800 {
11801 vos_mem_copy(&pHddCtx->p2pDeviceAddress.bytes[0],
11802 p2p_dev_addr, VOS_MAC_ADDR_SIZE);
11803 }
11804 else
11805 {
11806 hddLog(VOS_TRACE_LEVEL_FATAL,
11807 "%s: Failed to allocate mac_address for p2p_device",
11808 __func__);
11809 goto err_close_adapter;
11810 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011811 }
Jeff Johnsone7245742012-09-05 17:12:55 -070011812
11813 pP2pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_P2P_DEVICE, "p2p%d",
11814 &pHddCtx->p2pDeviceAddress.bytes[0], FALSE );
11815 if ( NULL == pP2pAdapter )
11816 {
11817 hddLog(VOS_TRACE_LEVEL_FATAL,
11818 "%s: Failed to do hdd_open_adapter for P2P Device Interface",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070011819 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070011820 goto err_close_adapter;
11821 }
Jeff Johnsone7245742012-09-05 17:12:55 -070011822 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011823 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011824
11825 if( pAdapter == NULL )
11826 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -080011827 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
11828 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070011829 }
Jeff Johnsone7245742012-09-05 17:12:55 -070011830
Arif Hussain66559122013-11-21 10:11:40 -080011831 if (country_code)
11832 {
11833 eHalStatus ret;
Arif Hussaincb607082013-12-20 11:57:42 -080011834 INIT_COMPLETION(pAdapter->change_country_code);
Arif Hussain66559122013-11-21 10:11:40 -080011835 hdd_checkandupdate_dfssetting(pAdapter, country_code);
11836#ifndef CONFIG_ENABLE_LINUX_REG
11837 hdd_checkandupdate_phymode(pAdapter, country_code);
11838#endif
Arif Hussaineaf68602013-12-30 23:10:44 -080011839 ret = sme_ChangeCountryCode(pHddCtx->hHal,
11840 (void *)(tSmeChangeCountryCallback)
11841 wlan_hdd_change_country_code_callback,
Arif Hussain66559122013-11-21 10:11:40 -080011842 country_code,
11843 pAdapter, pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +053011844 eSIR_TRUE, eSIR_TRUE);
Arif Hussain66559122013-11-21 10:11:40 -080011845 if (eHAL_STATUS_SUCCESS == ret)
11846 {
Arif Hussaincb607082013-12-20 11:57:42 -080011847 ret = wait_for_completion_interruptible_timeout(
11848 &pAdapter->change_country_code,
11849 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
11850
11851 if (0 >= ret)
11852 {
11853 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11854 "%s: SME while setting country code timed out", __func__);
11855 }
Arif Hussain66559122013-11-21 10:11:40 -080011856 }
11857 else
11858 {
Arif Hussaincb607082013-12-20 11:57:42 -080011859 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11860 "%s: SME Change Country code from module param fail ret=%d",
11861 __func__, ret);
Arif Hussain66559122013-11-21 10:11:40 -080011862 }
11863 }
11864
Jeff Johnson295189b2012-06-20 16:38:30 -070011865#ifdef WLAN_BTAMP_FEATURE
11866 vStatus = WLANBAP_Open(pVosContext);
11867 if(!VOS_IS_STATUS_SUCCESS(vStatus))
11868 {
11869 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11870 "%s: Failed to open BAP",__func__);
Jeff Johnsone7245742012-09-05 17:12:55 -070011871 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070011872 }
11873
11874 vStatus = BSL_Init(pVosContext);
11875 if(!VOS_IS_STATUS_SUCCESS(vStatus))
11876 {
11877 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11878 "%s: Failed to Init BSL",__func__);
11879 goto err_bap_close;
11880 }
11881 vStatus = WLANBAP_Start(pVosContext);
11882 if (!VOS_IS_STATUS_SUCCESS(vStatus))
11883 {
11884 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11885 "%s: Failed to start TL",__func__);
11886 goto err_bap_close;
11887 }
11888
11889 pConfig = pHddCtx->cfg_ini;
11890 btAmpConfig.ucPreferredChannel = pConfig->preferredChannel;
11891 status = WLANBAP_SetConfig(&btAmpConfig);
11892
11893#endif //WLAN_BTAMP_FEATURE
Jeff Johnsone7245742012-09-05 17:12:55 -070011894
Mihir Shete9c238772014-10-15 14:35:16 +053011895 /*
11896 * UapsdMask is 0xf if U-APSD is enbaled for all AC's...
11897 * The value of CFG_QOS_WMM_UAPSD_MASK_DEFAULT is 0xaa(Magic Value)
11898 * which is greater than 0xf. So the below check is safe to make
11899 * sure that there is no entry for UapsdMask in the ini
11900 */
11901 if (CFG_QOS_WMM_UAPSD_MASK_DEFAULT == pHddCtx->cfg_ini->UapsdMask)
11902 {
11903 if(IS_DYNAMIC_WMM_PS_ENABLED)
11904 {
11905 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Enable UAPSD for VI & VO",
11906 __func__);
11907 pHddCtx->cfg_ini->UapsdMask =
11908 CFG_QOS_WMM_UAPSD_MASK_DYMANIC_WMM_PS_DEFAULT;
11909 }
11910 else
11911 {
11912 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Do not enable UAPSD",
11913 __func__);
11914 pHddCtx->cfg_ini->UapsdMask =
11915 CFG_QOS_WMM_UAPSD_MASK_LEGACY_WMM_PS_DEFAULT;
11916 }
11917 }
11918
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -070011919#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
11920 if(!(IS_ROAM_SCAN_OFFLOAD_FEATURE_ENABLE))
11921 {
11922 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: ROAM_SCAN_OFFLOAD Feature not supported",__func__);
11923 pHddCtx->cfg_ini->isRoamOffloadScanEnabled = 0;
11924 sme_UpdateRoamScanOffloadEnabled((tHalHandle)(pHddCtx->hHal),
11925 pHddCtx->cfg_ini->isRoamOffloadScanEnabled);
11926 }
11927#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070011928
Agarwal Ashish4b87f922014-06-18 03:03:21 +053011929 wlan_hdd_tdls_init(pHddCtx);
11930
Masti, Narayanraddi26378462016-01-05 18:20:28 +053011931 wlan_hdd_init_deinit_defer_scan_context(&pHddCtx->scan_ctxt);
11932
11933 vos_init_delayed_work(&pHddCtx->scan_ctxt.scan_work,
11934 wlan_hdd_schedule_defer_scan);
11935
Mihir Shetefc7ff5b2014-01-27 11:30:05 +053011936 sme_Register11dScanDoneCallback(pHddCtx->hHal, hdd_11d_scan_done);
11937
Jeff Johnson295189b2012-06-20 16:38:30 -070011938 /* Register with platform driver as client for Suspend/Resume */
11939 status = hddRegisterPmOps(pHddCtx);
11940 if ( !VOS_IS_STATUS_SUCCESS( status ) )
11941 {
11942 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddRegisterPmOps failed",__func__);
11943#ifdef WLAN_BTAMP_FEATURE
11944 goto err_bap_stop;
11945#else
Jeff Johnsone7245742012-09-05 17:12:55 -070011946 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -070011947#endif //WLAN_BTAMP_FEATURE
11948 }
11949
Yue Ma0d4891e2013-08-06 17:01:45 -070011950 /* Open debugfs interface */
11951 if (VOS_STATUS_SUCCESS != hdd_debugfs_init(pAdapter))
11952 {
11953 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
11954 "%s: hdd_debugfs_init failed!", __func__);
Yue Ma0d4891e2013-08-06 17:01:45 -070011955 }
11956
Jeff Johnson295189b2012-06-20 16:38:30 -070011957 /* Register TM level change handler function to the platform */
11958 status = hddDevTmRegisterNotifyCallback(pHddCtx);
11959 if ( !VOS_IS_STATUS_SUCCESS( status ) )
11960 {
11961 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmRegisterNotifyCallback failed",__func__);
11962 goto err_unregister_pmops;
11963 }
Jeff Johnson295189b2012-06-20 16:38:30 -070011964
Jeff Johnson295189b2012-06-20 16:38:30 -070011965 // register net device notifier for device change notification
11966 ret = register_netdevice_notifier(&hdd_netdev_notifier);
11967
11968 if(ret < 0)
11969 {
11970 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: register_netdevice_notifier failed",__func__);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053011971 goto err_unregister_pmops;
Jeff Johnson295189b2012-06-20 16:38:30 -070011972 }
11973
Jeff Johnson295189b2012-06-20 16:38:30 -070011974 //Initialize the BTC service
11975 if(btc_activate_service(pHddCtx) != 0)
11976 {
11977 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: btc_activate_service failed",__func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053011978 goto err_reg_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -070011979 }
11980
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053011981#ifdef FEATURE_OEM_DATA_SUPPORT
11982 //Initialize the OEM service
11983 if (oem_activate_service(pHddCtx) != 0)
11984 {
11985 hddLog(VOS_TRACE_LEVEL_FATAL,
11986 "%s: oem_activate_service failed", __func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053011987 goto err_reg_netdev;
Padma, Santhosh Kumar2762e9d2015-10-20 15:02:57 +053011988 }
11989#endif
11990
Jeff Johnson295189b2012-06-20 16:38:30 -070011991#ifdef PTT_SOCK_SVC_ENABLE
11992 //Initialize the PTT service
11993 if(ptt_sock_activate_svc(pHddCtx) != 0)
11994 {
11995 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: ptt_sock_activate_svc failed",__func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053011996 goto err_reg_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -070011997 }
11998#endif
11999
Abhishek Singh00b71972016-01-07 10:51:04 +053012000#ifdef WLAN_FEATURE_RMC
12001 if (hdd_open_cesium_nl_sock() < 0)
12002 {
12003 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_open_cesium_nl_sock failed", __func__);
12004 goto err_reg_netdev;
12005 }
12006#endif
12007
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012008#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12009 if(pHddCtx->cfg_ini && pHddCtx->cfg_ini->wlanLoggingEnable)
12010 {
Deepthi Gowri78083a32014-11-04 12:55:51 +053012011 if(wlan_logging_sock_activate_svc(
12012 pHddCtx->cfg_ini->wlanLoggingFEToConsole,
Sushant Kaushik33200572015-08-05 16:46:20 +053012013 pHddCtx->cfg_ini->wlanLoggingNumBuf,
12014 pHddCtx->cfg_ini->wlanPerPktStatsLogEnable,
12015 pHddCtx->cfg_ini->wlanPerPktStatsNumBuf))
Deepthi Gowri78083a32014-11-04 12:55:51 +053012016 {
12017 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wlan_logging_sock_activate_svc"
12018 " failed", __func__);
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053012019 goto err_reg_netdev;
Deepthi Gowri78083a32014-11-04 12:55:51 +053012020 }
12021 //TODO: To Remove enableDhcpDebug and use gEnableDebugLog for
12022 //EAPOL and DHCP
Sachin Ahuja8c65f382014-12-12 15:34:21 +053012023 if (!pHddCtx->cfg_ini->gEnableDebugLog)
12024 pHddCtx->cfg_ini->gEnableDebugLog =
Sushant Kaushik6e4e2bc2015-10-05 17:23:07 +053012025 VOS_PKT_PROTO_TYPE_EAPOL | VOS_PKT_PROTO_TYPE_DHCP |
12026 VOS_PKT_PROTO_TYPE_ARP;
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012027 }
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012028
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012029 if (pHddCtx->cfg_ini->wlanLoggingEnable &&
12030 (pHddCtx->cfg_ini->enableFWLogging ||
Siddharth Bhaldb963232015-06-25 19:34:35 +053012031 pHddCtx->cfg_ini->enableMgmtLogging ||
c_manjeecfd1efb2015-09-25 19:32:34 +053012032 pHddCtx->cfg_ini->enableContFWLogging ||
12033 pHddCtx->cfg_ini->enableFwrMemDump )
12034 )
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012035 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012036 hdd_init_frame_logging(pHddCtx);
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012037 }
12038 else
12039 {
Siddharth Bhald1be97f2015-05-27 22:39:59 +053012040 hddLog(VOS_TRACE_LEVEL_INFO, FL("Logging disabled in ini"));
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012041 }
12042
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053012043#endif
Siddharth Bhalb7c421c2015-02-27 00:26:09 +053012044
12045
Sushant Kaushik215778f2015-05-21 14:05:36 +053012046 if (vos_is_multicast_logging())
12047 wlan_logging_set_log_level();
12048
Jeff Johnson295189b2012-06-20 16:38:30 -070012049 hdd_register_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070012050 if (VOS_STA_SAP_MODE != hdd_get_conparam())
Jeff Johnson295189b2012-06-20 16:38:30 -070012051 {
Madan Mohan Koyyalamudic537df22012-10-22 15:07:08 -070012052 /* Action frame registered in one adapter which will
12053 * applicable to all interfaces
12054 */
Agarwal Ashish8fa0e9a2014-05-23 00:40:12 +053012055 wlan_hdd_cfg80211_register_frames(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -070012056 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012057
12058 mutex_init(&pHddCtx->sap_lock);
Mahesh A Saptasagar60627942014-10-13 13:55:14 +053012059 mutex_init(&pHddCtx->roc_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -070012060
Jeff Johnsone7245742012-09-05 17:12:55 -070012061#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
12062 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012063 vos_wake_lock_init(&pHddCtx->rx_wake_lock,
Jeff Johnsone7245742012-09-05 17:12:55 -070012064 "qcom_rx_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012065
Jeff Johnsone7245742012-09-05 17:12:55 -070012066#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080012067 /* Initialize the wake lcok */
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012068 vos_wake_lock_init(&pHddCtx->sap_wake_lock,
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -080012069 "qcom_sap_wakelock");
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012070
Jeff Johnsone7245742012-09-05 17:12:55 -070012071
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -070012072 vos_event_init(&pHddCtx->scan_info.scan_finished_event);
12073 pHddCtx->scan_info.scan_pending_option = WEXT_SCAN_PENDING_GIVEUP;
Jeff Johnson295189b2012-06-20 16:38:30 -070012074
Katya Nigam5c306ea2014-06-19 15:39:54 +053012075 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -070012076 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012077 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Katya Nigam5c306ea2014-06-19 15:39:54 +053012078
12079#ifdef FEATURE_WLAN_SCAN_PNO
12080 /*SME must send channel update configuration to RIVA*/
12081 sme_UpdateChannelConfig(pHddCtx->hHal);
12082#endif
Abhishek Singhf644b272014-08-21 02:59:39 +053012083 /* Send the update default channel list to the FW*/
12084 sme_UpdateChannelList(pHddCtx->hHal);
Mukul Sharma45063942015-04-01 20:07:59 +053012085
12086 /* Fwr capabilities received, Set the Dot11 mode */
Abhishek Singh41ebce12016-02-03 10:43:21 +053012087 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
12088 hdd_cfg_xlate_to_csr_phy_mode(pHddCtx->cfg_ini->dot11Mode));
Mukul Sharma45063942015-04-01 20:07:59 +053012089 sme_SetDefDot11Mode(pHddCtx->hHal);
12090
Abhishek Singha306a442013-11-07 18:39:01 +053012091#ifndef CONFIG_ENABLE_LINUX_REG
12092 /*updating wiphy so that regulatory user hints can be processed*/
12093 if (wiphy)
12094 {
12095 regulatory_hint(wiphy, "00");
12096 }
12097#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070012098 // Initialize the restart logic
12099 wlan_hdd_restart_init(pHddCtx);
Chilam NG571c65a2013-01-19 12:27:36 +053012100
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -070012101 //Register the traffic monitor timer now
12102 if ( pHddCtx->cfg_ini->dynSplitscan)
12103 {
12104 vos_timer_init(&pHddCtx->tx_rx_trafficTmr,
12105 VOS_TIMER_TYPE_SW,
12106 hdd_tx_rx_pkt_cnt_stat_timer_handler,
12107 (void *)pHddCtx);
12108 }
Srinivas Dasari030bad32015-02-18 23:23:54 +053012109 wlan_hdd_cfg80211_nan_init(pHddCtx);
12110
Bhargav Shahd0715912015-10-01 18:17:37 +053012111 mutex_init(&pHddCtx->cur_rx_level_lock);
12112 vos_timer_init(&pHddCtx->delack_timer, VOS_TIMER_TYPE_SW,
12113 hdd_tcp_delack_compute_function,(void *)pHddCtx);
Masti, Narayanraddi44b0db02015-12-22 11:54:35 +053012114 vos_timer_init(&pHddCtx->tdls_source_timer, VOS_TIMER_TYPE_SW,
12115 wlan_hdd_change_tdls_mode, (void *)pHddCtx);
Bhargav Shahd0715912015-10-01 18:17:37 +053012116
Dino Mycle6fb96c12014-06-10 11:52:40 +053012117#ifdef WLAN_FEATURE_EXTSCAN
12118 sme_EXTScanRegisterCallback(pHddCtx->hHal,
12119 wlan_hdd_cfg80211_extscan_callback,
12120 pHddCtx);
12121#endif /* WLAN_FEATURE_EXTSCAN */
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012122
Padma, Santhosh Kumar2ccac212015-10-20 17:27:27 +053012123#ifdef FEATURE_OEM_DATA_SUPPORT
12124 sme_OemDataRegisterCallback(pHddCtx->hHal,
12125 wlan_hdd_cfg80211_oemdata_callback,
12126 pHddCtx);
12127#endif /* FEATURE_OEM_DATA_SUPPORT */
12128
Gupta, Kapil7c34b322015-09-30 13:12:35 +053012129 sme_set_rssi_threshold_breached_cb(pHddCtx->hHal, hdd_rssi_threshold_breached_cb);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012130#ifdef WLAN_NS_OFFLOAD
12131 // Register IPv6 notifier to notify if any change in IP
12132 // So that we can reconfigure the offload parameters
12133 pHddCtx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
12134 ret = register_inet6addr_notifier(&pHddCtx->ipv6_notifier);
12135 if (ret)
12136 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053012137 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012138 }
12139 else
12140 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053012141 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv6 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012142 }
12143#endif
12144
12145 // Register IPv4 notifier to notify if any change in IP
12146 // So that we can reconfigure the offload parameters
12147 pHddCtx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
12148 ret = register_inetaddr_notifier(&pHddCtx->ipv4_notifier);
12149 if (ret)
12150 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053012151 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012152 }
12153 else
12154 {
Ratheesh S P36dbc932015-08-07 14:28:57 +053012155 hddLog(VOS_TRACE_LEVEL_INFO, FL("Registered IPv4 notifier"));
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012156 }
c_manjeecfd1efb2015-09-25 19:32:34 +053012157 /*Fw mem dump procfs initialization*/
12158 memdump_init();
Bhargav shah23c94942015-10-13 12:48:35 +053012159 hdd_dp_util_send_rps_ind(pHddCtx);
Vinay Krishna Erannaf97ef5c2014-12-26 17:47:19 +053012160
Jeff Johnson295189b2012-06-20 16:38:30 -070012161 goto success;
12162
Jeff Johnson295189b2012-06-20 16:38:30 -070012163err_reg_netdev:
12164 unregister_netdevice_notifier(&hdd_netdev_notifier);
12165
Jeff Johnson295189b2012-06-20 16:38:30 -070012166err_unregister_pmops:
12167 hddDevTmUnregisterNotifyCallback(pHddCtx);
12168 hddDeregisterPmOps(pHddCtx);
12169
Yue Ma0d4891e2013-08-06 17:01:45 -070012170 hdd_debugfs_exit(pHddCtx);
12171
Jeff Johnson295189b2012-06-20 16:38:30 -070012172#ifdef WLAN_BTAMP_FEATURE
12173err_bap_stop:
12174 WLANBAP_Stop(pVosContext);
12175#endif
12176
12177#ifdef WLAN_BTAMP_FEATURE
12178err_bap_close:
12179 WLANBAP_Close(pVosContext);
12180#endif
12181
Jeff Johnson295189b2012-06-20 16:38:30 -070012182err_close_adapter:
12183 hdd_close_all_adapters( pHddCtx );
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053012184#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053012185err_unregister_wiphy:
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +053012186#endif
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +053012187 wiphy_unregister(wiphy) ;
Agrawal Ashish33ec71e2015-11-26 20:20:58 +053012188 hdd_wlan_free_wiphy_channels(wiphy);
12189
Jeff Johnson295189b2012-06-20 16:38:30 -070012190err_vosstop:
12191 vos_stop(pVosContext);
12192
Amar Singhala49cbc52013-10-08 18:37:44 -070012193err_vosclose:
Jeff Johnson295189b2012-06-20 16:38:30 -070012194 status = vos_sched_close( pVosContext );
12195 if (!VOS_IS_STATUS_SUCCESS(status)) {
12196 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
12197 "%s: Failed to close VOSS Scheduler", __func__);
12198 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
12199 }
Amar Singhala49cbc52013-10-08 18:37:44 -070012200 vos_close(pVosContext );
12201
Mahesh A Saptasagarc3ed0122016-01-19 16:45:11 +053012202err_nl_srv:
12203#ifdef WLAN_KD_READY_NOTIFIER
12204 nl_srv_exit(pHddCtx->ptt_pid);
12205#else
12206 nl_srv_exit();
12207#endif /* WLAN_KD_READY_NOTIFIER */
Amar Singhal0a402232013-10-11 20:57:16 -070012208err_vos_nv_close:
12209
c_hpothue6a36282014-03-19 12:27:38 +053012210#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -070012211 vos_nv_close();
12212
c_hpothu70f8d812014-03-22 22:59:23 +053012213#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070012214
12215err_wdclose:
12216 if(pHddCtx->cfg_ini->fIsLogpEnabled)
12217 vos_watchdog_close(pVosContext);
12218
Jeff Johnson295189b2012-06-20 16:38:30 -070012219err_config:
12220 kfree(pHddCtx->cfg_ini);
12221 pHddCtx->cfg_ini= NULL;
12222
12223err_free_hdd_context:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012224 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_INIT);
Siddharth Bhalcd92b782015-06-29 12:25:40 +053012225 free_riva_power_on_lock("wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070012226 wiphy_free(wiphy) ;
12227 //kfree(wdev) ;
Jeff Johnson295189b2012-06-20 16:38:30 -070012228 VOS_BUG(1);
12229
Madan Mohan Koyyalamudid57ae632012-11-06 18:42:48 -080012230 if (hdd_is_ssr_required())
12231 {
12232 /* WDI timeout had happened during load, so SSR is needed here */
12233 subsystem_restart("wcnss");
12234 msleep(5000);
12235 }
12236 hdd_set_ssr_required (VOS_FALSE);
12237
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -080012238 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -070012239
12240success:
12241 EXIT();
12242 return 0;
12243}
12244
12245/**---------------------------------------------------------------------------
12246
Jeff Johnson32d95a32012-09-10 13:15:23 -070012247 \brief hdd_driver_init() - Core Driver Init Function
Jeff Johnson295189b2012-06-20 16:38:30 -070012248
Jeff Johnson32d95a32012-09-10 13:15:23 -070012249 This is the driver entry point - called in different timeline depending
12250 on whether the driver is statically or dynamically linked
Jeff Johnson295189b2012-06-20 16:38:30 -070012251
12252 \param - None
12253
12254 \return - 0 for success, non zero for failure
12255
12256 --------------------------------------------------------------------------*/
Jeff Johnson32d95a32012-09-10 13:15:23 -070012257static int hdd_driver_init( void)
Jeff Johnson295189b2012-06-20 16:38:30 -070012258{
12259 VOS_STATUS status;
12260 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070012261 struct device *dev = NULL;
12262 int ret_status = 0;
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070012263#ifdef HAVE_WCNSS_CAL_DOWNLOAD
12264 int max_retries = 0;
12265#endif
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053012266#ifdef HAVE_CBC_DONE
12267 int max_cbc_retries = 0;
12268#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070012269
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053012270#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12271 wlan_logging_sock_init_svc();
12272#endif
12273
Jeff Johnson295189b2012-06-20 16:38:30 -070012274 ENTER();
12275
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012276 vos_wake_lock_init(&wlan_wake_lock, "wlan");
Jeff Johnson295189b2012-06-20 16:38:30 -070012277
12278 pr_info("%s: loading driver v%s\n", WLAN_MODULE_NAME,
12279 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
12280
Jeff Johnson295189b2012-06-20 16:38:30 -070012281#ifdef ANI_BUS_TYPE_PCI
12282
12283 dev = wcnss_wlan_get_device();
12284
12285#endif // ANI_BUS_TYPE_PCI
12286
12287#ifdef ANI_BUS_TYPE_PLATFORM
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070012288
12289#ifdef HAVE_WCNSS_CAL_DOWNLOAD
12290 /* wait until WCNSS driver downloads NV */
12291 while (!wcnss_device_ready() && 5 >= ++max_retries) {
12292 msleep(1000);
12293 }
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053012294
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070012295 if (max_retries >= 5) {
12296 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WCNSS driver not ready", __func__);
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012297 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053012298#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12299 wlan_logging_sock_deinit_svc();
12300#endif
12301
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -070012302 return -ENODEV;
12303 }
12304#endif
12305
Siddharth Bhalc7e79b62014-10-10 22:37:38 +053012306#ifdef HAVE_CBC_DONE
12307 while (!wcnss_cbc_complete() && 10 >= ++max_cbc_retries) {
12308 msleep(1000);
12309 }
12310 if (max_cbc_retries >= 10) {
12311 hddLog(VOS_TRACE_LEVEL_FATAL, "%s:CBC not completed", __func__);
12312 }
12313#endif
12314
Jeff Johnson295189b2012-06-20 16:38:30 -070012315 dev = wcnss_wlan_get_device();
12316#endif // ANI_BUS_TYPE_PLATFORM
12317
12318
12319 do {
12320 if (NULL == dev) {
12321 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: WLAN device not found!!",__func__);
12322 ret_status = -1;
12323 break;
12324 }
12325
Jeff Johnson295189b2012-06-20 16:38:30 -070012326#ifdef TIMER_MANAGER
12327 vos_timer_manager_init();
12328#endif
12329
12330 /* Preopen VOSS so that it is ready to start at least SAL */
12331 status = vos_preOpen(&pVosContext);
12332
12333 if (!VOS_IS_STATUS_SUCCESS(status))
12334 {
12335 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to preOpen VOSS", __func__);
12336 ret_status = -1;
12337 break;
12338 }
12339
Sushant Kaushik02beb352015-06-04 15:15:01 +053012340 hddTraceInit();
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +053012341 hdd_register_debug_callback();
12342
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012343#ifndef MODULE
12344 /* For statically linked driver, call hdd_set_conparam to update curr_con_mode
12345 */
12346 hdd_set_conparam((v_UINT_t)con_mode);
12347#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070012348
12349 // Call our main init function
Jeff Johnsonbc676b42013-02-14 16:04:08 -080012350 if (hdd_wlan_startup(dev))
12351 {
Jeff Johnson295189b2012-06-20 16:38:30 -070012352 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WLAN Driver Initialization failed",
Jeff Johnsonbc676b42013-02-14 16:04:08 -080012353 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070012354 vos_preClose( &pVosContext );
12355 ret_status = -1;
12356 break;
12357 }
12358
Jeff Johnson295189b2012-06-20 16:38:30 -070012359 } while (0);
12360
12361 if (0 != ret_status)
12362 {
Jeff Johnson295189b2012-06-20 16:38:30 -070012363#ifdef TIMER_MANAGER
12364 vos_timer_exit();
12365#endif
12366#ifdef MEMORY_DEBUG
12367 vos_mem_exit();
12368#endif
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012369 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053012370#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12371 wlan_logging_sock_deinit_svc();
12372#endif
12373
Jeff Johnson295189b2012-06-20 16:38:30 -070012374 pr_err("%s: driver load failure\n", WLAN_MODULE_NAME);
12375 }
12376 else
12377 {
12378 //Send WLAN UP indication to Nlink Service
12379 send_btc_nlink_msg(WLAN_MODULE_UP_IND, 0);
12380
12381 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Jeff Johnson295189b2012-06-20 16:38:30 -070012382 }
12383
12384 EXIT();
12385
12386 return ret_status;
12387}
12388
Jeff Johnson32d95a32012-09-10 13:15:23 -070012389/**---------------------------------------------------------------------------
12390
12391 \brief hdd_module_init() - Init Function
12392
12393 This is the driver entry point (invoked when module is loaded using insmod)
12394
12395 \param - None
12396
12397 \return - 0 for success, non zero for failure
12398
12399 --------------------------------------------------------------------------*/
12400#ifdef MODULE
12401static int __init hdd_module_init ( void)
12402{
12403 return hdd_driver_init();
12404}
Jeff Johnson32d95a32012-09-10 13:15:23 -070012405#else /* #ifdef MODULE */
12406static int __init hdd_module_init ( void)
12407{
12408 /* Driver initialization is delayed to fwpath_changed_handler */
12409 return 0;
12410}
Jeff Johnson32d95a32012-09-10 13:15:23 -070012411#endif /* #ifdef MODULE */
12412
Jeff Johnson295189b2012-06-20 16:38:30 -070012413
12414/**---------------------------------------------------------------------------
12415
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012416 \brief hdd_driver_exit() - Exit function
Jeff Johnson295189b2012-06-20 16:38:30 -070012417
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012418 This is the driver exit point (invoked when module is unloaded using rmmod
12419 or con_mode was changed by userspace)
Jeff Johnson295189b2012-06-20 16:38:30 -070012420
12421 \param - None
12422
12423 \return - None
12424
12425 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012426static void hdd_driver_exit(void)
Jeff Johnson295189b2012-06-20 16:38:30 -070012427{
12428 hdd_context_t *pHddCtx = NULL;
12429 v_CONTEXT_t pVosContext = NULL;
Agarwal Ashish5e414792014-06-08 15:25:23 +053012430 v_REGDOMAIN_t regId;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +053012431 unsigned long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070012432
12433 pr_info("%s: unloading driver v%s\n", WLAN_MODULE_NAME, QWLAN_VERSIONSTR);
12434
12435 //Get the global vos context
12436 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
12437
12438 if(!pVosContext)
12439 {
12440 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
12441 goto done;
12442 }
12443
12444 //Get the HDD context.
12445 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
12446
12447 if(!pHddCtx)
12448 {
12449 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: module exit called before probe",__func__);
12450 }
Katya Nigame7b69a82015-04-28 15:24:06 +053012451 else if (VOS_MONITOR_MODE == hdd_get_conparam())
12452 {
12453 hddLog(VOS_TRACE_LEVEL_INFO,"%s: MONITOR MODE",__func__);
12454 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
12455 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
12456 hdd_wlan_exit(pHddCtx);
12457 vos_preClose( &pVosContext );
12458 goto done;
12459 }
Jeff Johnson295189b2012-06-20 16:38:30 -070012460 else
12461 {
Siddharth Bhal2e5871b2015-03-24 16:20:51 +053012462 /* We wait for active entry threads to exit from driver
12463 * by waiting until rtnl_lock is available.
12464 */
12465 rtnl_lock();
12466 rtnl_unlock();
12467
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053012468 INIT_COMPLETION(pHddCtx->ssr_comp_var);
12469 if ((pHddCtx->isLogpInProgress) && (FALSE ==
12470 vos_is_wlan_in_badState(VOS_MODULE_ID_HDD, NULL)))
12471 {
Siddharth Bhala204f572015-01-17 02:03:36 +053012472 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053012473 "%s:SSR in Progress; block rmmod !!!", __func__);
Siddharth Bhala204f572015-01-17 02:03:36 +053012474 rc = wait_for_completion_timeout(&pHddCtx->ssr_comp_var,
12475 msecs_to_jiffies(30000));
12476 if(!rc)
12477 {
12478 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
12479 "%s:SSR timedout, fatal error", __func__);
12480 VOS_BUG(0);
12481 }
12482 }
12483
Siddharth Bhal3c29dca2015-02-19 00:41:40 +053012484 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
12485 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -070012486
c_hpothu8adb97b2014-12-08 19:38:20 +053012487 /* Driver Need to send country code 00 in below condition
12488 * 1) If gCountryCodePriority is set to 1; and last country
12489 * code set is through 11d. This needs to be done in case
12490 * when NV country code is 00.
12491 * This Needs to be done as when kernel store last country
12492 * code and if stored country code is not through 11d,
12493 * in sme_HandleChangeCountryCodeByUser we will disable 11d
12494 * in next load/unload as soon as we get any country through
12495 * 11d. In sme_HandleChangeCountryCodeByUser
12496 * pMsg->countryCode will be last countryCode and
12497 * pMac->scan.countryCode11d will be country through 11d so
12498 * due to mismatch driver will disable 11d.
12499 *
12500 */
Agarwal Ashish8db39882014-07-30 21:56:07 +053012501
c_hpothu8adb97b2014-12-08 19:38:20 +053012502 if ((eANI_BOOLEAN_TRUE == sme_Is11dCountrycode(pHddCtx->hHal) &&
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053012503 pHddCtx->cfg_ini->fSupplicantCountryCodeHasPriority &&
Abhishek Singh2a705962014-10-30 14:47:28 +053012504 sme_Is11dSupported(pHddCtx->hHal)))
c_hpothu8adb97b2014-12-08 19:38:20 +053012505 {
12506 hddLog(VOS_TRACE_LEVEL_INFO,
Agarwal Ashish8dcd2862014-07-25 11:58:52 +053012507 FL("CountryCode 00 is being set while unloading driver"));
c_hpothu8adb97b2014-12-08 19:38:20 +053012508 vos_nv_getRegDomainFromCountryCode(&regId , "00", COUNTRY_USER);
12509 }
Agarwal Ashish5e414792014-06-08 15:25:23 +053012510
c_hpothu8adb97b2014-12-08 19:38:20 +053012511 //Do all the cleanup before deregistering the driver
12512 hdd_wlan_exit(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -070012513 }
12514
Jeff Johnson295189b2012-06-20 16:38:30 -070012515 vos_preClose( &pVosContext );
12516
12517#ifdef TIMER_MANAGER
12518 vos_timer_exit();
12519#endif
12520#ifdef MEMORY_DEBUG
12521 vos_mem_exit();
12522#endif
12523
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053012524#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12525 wlan_logging_sock_deinit_svc();
12526#endif
12527
Jeff Johnson295189b2012-06-20 16:38:30 -070012528done:
Sushant Kaushik83392fa2015-05-05 17:44:40 +053012529 vos_wake_lock_destroy(&wlan_wake_lock);
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +053012530
Jeff Johnson295189b2012-06-20 16:38:30 -070012531 pr_info("%s: driver unloaded\n", WLAN_MODULE_NAME);
12532}
12533
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012534/**---------------------------------------------------------------------------
12535
12536 \brief hdd_module_exit() - Exit function
12537
12538 This is the driver exit point (invoked when module is unloaded using rmmod)
12539
12540 \param - None
12541
12542 \return - None
12543
12544 --------------------------------------------------------------------------*/
12545static void __exit hdd_module_exit(void)
12546{
12547 hdd_driver_exit();
12548}
12549
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012550#ifdef MODULE
12551static int fwpath_changed_handler(const char *kmessage,
12552 struct kernel_param *kp)
12553{
Jeff Johnson76052702013-04-16 13:55:05 -070012554 return param_set_copystring(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012555}
12556
12557static int con_mode_handler(const char *kmessage,
12558 struct kernel_param *kp)
12559{
Madan Mohan Koyyalamudif2f8d8b2012-10-11 17:06:59 -070012560 return param_set_int(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012561}
12562#else /* #ifdef MODULE */
12563/**---------------------------------------------------------------------------
12564
Jeff Johnson76052702013-04-16 13:55:05 -070012565 \brief kickstart_driver
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012566
Jeff Johnson76052702013-04-16 13:55:05 -070012567 This is the driver entry point
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012568 - delayed driver initialization when driver is statically linked
Jeff Johnson76052702013-04-16 13:55:05 -070012569 - invoked when module parameter fwpath is modified from userspace to signal
12570 initializing the WLAN driver or when con_mode is modified from userspace
12571 to signal a switch in operating mode
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012572
12573 \return - 0 for success, non zero for failure
12574
12575 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -070012576static int kickstart_driver(void)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012577{
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070012578 int ret_status;
12579
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012580 if (!wlan_hdd_inited) {
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070012581 ret_status = hdd_driver_init();
12582 wlan_hdd_inited = ret_status ? 0 : 1;
12583 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012584 }
12585
12586 hdd_driver_exit();
Jeff Johnson76052702013-04-16 13:55:05 -070012587
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012588 msleep(200);
Jeff Johnson76052702013-04-16 13:55:05 -070012589
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -070012590 ret_status = hdd_driver_init();
12591 wlan_hdd_inited = ret_status ? 0 : 1;
12592 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -070012593}
12594
Jeff Johnson295189b2012-06-20 16:38:30 -070012595/**---------------------------------------------------------------------------
12596
Jeff Johnson76052702013-04-16 13:55:05 -070012597 \brief fwpath_changed_handler() - Handler Function
12598
12599 Handle changes to the fwpath parameter
12600
12601 \return - 0 for success, non zero for failure
12602
12603 --------------------------------------------------------------------------*/
12604static int fwpath_changed_handler(const char *kmessage,
12605 struct kernel_param *kp)
12606{
12607 int ret;
12608
12609 ret = param_set_copystring(kmessage, kp);
12610 if (0 == ret)
12611 ret = kickstart_driver();
12612 return ret;
12613}
12614
12615/**---------------------------------------------------------------------------
12616
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012617 \brief con_mode_handler() -
12618
12619 Handler function for module param con_mode when it is changed by userspace
12620 Dynamically linked - do nothing
12621 Statically linked - exit and init driver, as in rmmod and insmod
12622
Jeff Johnson76052702013-04-16 13:55:05 -070012623 \param -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012624
Jeff Johnson76052702013-04-16 13:55:05 -070012625 \return -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012626
12627 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -070012628static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012629{
Jeff Johnson76052702013-04-16 13:55:05 -070012630 int ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012631
Jeff Johnson76052702013-04-16 13:55:05 -070012632 ret = param_set_int(kmessage, kp);
12633 if (0 == ret)
12634 ret = kickstart_driver();
12635 return ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012636}
12637#endif /* #ifdef MODULE */
12638
12639/**---------------------------------------------------------------------------
12640
Jeff Johnson295189b2012-06-20 16:38:30 -070012641 \brief hdd_get_conparam() -
12642
12643 This is the driver exit point (invoked when module is unloaded using rmmod)
12644
12645 \param - None
12646
12647 \return - tVOS_CON_MODE
12648
12649 --------------------------------------------------------------------------*/
12650tVOS_CON_MODE hdd_get_conparam ( void )
12651{
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012652#ifdef MODULE
Jeff Johnson295189b2012-06-20 16:38:30 -070012653 return (tVOS_CON_MODE)con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012654#else
12655 return (tVOS_CON_MODE)curr_con_mode;
12656#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070012657}
12658void hdd_set_conparam ( v_UINT_t newParam )
12659{
12660 con_mode = newParam;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070012661#ifndef MODULE
12662 curr_con_mode = con_mode;
12663#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070012664}
12665/**---------------------------------------------------------------------------
12666
12667 \brief hdd_softap_sta_deauth() - function
12668
12669 This to take counter measure to handle deauth req from HDD
12670
12671 \param - pAdapter - Pointer to the HDD
12672
12673 \param - enable - boolean value
12674
12675 \return - None
12676
12677 --------------------------------------------------------------------------*/
12678
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053012679VOS_STATUS hdd_softap_sta_deauth(hdd_adapter_t *pAdapter,
12680 struct tagCsrDelStaParams *pDelStaParams)
Jeff Johnson295189b2012-06-20 16:38:30 -070012681{
Jeff Johnson295189b2012-06-20 16:38:30 -070012682 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080012683 VOS_STATUS vosStatus = VOS_STATUS_E_FAULT;
Jeff Johnson295189b2012-06-20 16:38:30 -070012684
12685 ENTER();
12686
Rajesh Chauhan18488fc2013-08-22 10:15:03 -070012687 hddLog(LOG1, "hdd_softap_sta_deauth:(%p, false)",
12688 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070012689
12690 //Ignore request to deauth bcmc station
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053012691 if (pDelStaParams->peerMacAddr[0] & 0x1)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080012692 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070012693
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053012694 vosStatus = WLANSAP_DeauthSta(pVosContext, pDelStaParams);
Jeff Johnson295189b2012-06-20 16:38:30 -070012695
12696 EXIT();
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -080012697 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -070012698}
12699
12700/**---------------------------------------------------------------------------
12701
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053012702 \brief hdd_del_all_sta() - function
12703
12704 This function removes all the stations associated on stopping AP/P2P GO.
12705
12706 \param - pAdapter - Pointer to the HDD
12707
12708 \return - None
12709
12710 --------------------------------------------------------------------------*/
12711
12712int hdd_del_all_sta(hdd_adapter_t *pAdapter)
12713{
12714 v_U16_t i;
12715 VOS_STATUS vos_status;
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053012716 v_CONTEXT_t pVosContext = ( WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
12717 ptSapContext pSapCtx = NULL;
12718 pSapCtx = VOS_GET_SAP_CB(pVosContext);
12719 if(pSapCtx == NULL){
12720 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
12721 FL("psapCtx is NULL"));
12722 return 1;
12723 }
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053012724 ENTER();
12725
12726 hddLog(VOS_TRACE_LEVEL_INFO,
12727 "%s: Delete all STAs associated.",__func__);
12728 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
12729 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
12730 )
12731 {
12732 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
12733 {
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053012734 if ((pSapCtx->aStaInfo[i].isUsed) &&
12735 (!pSapCtx->aStaInfo[i].isDeauthInProgress))
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053012736 {
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053012737 struct tagCsrDelStaParams delStaParams;
12738
12739 WLANSAP_PopulateDelStaParams(
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053012740 pSapCtx->aStaInfo[i].macAddrSTA.bytes,
Sushant Kaushik4cd28f62014-12-26 14:23:50 +053012741 eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
12742 SIR_MAC_MGMT_DEAUTH >> 4,
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +053012743 &delStaParams);
12744 vos_status = hdd_softap_sta_deauth(pAdapter, &delStaParams);
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053012745 if (VOS_IS_STATUS_SUCCESS(vos_status))
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +053012746 pSapCtx->aStaInfo[i].isDeauthInProgress = TRUE;
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +053012747 }
12748 }
12749 }
12750
12751 EXIT();
12752 return 0;
12753}
12754
12755/**---------------------------------------------------------------------------
12756
Jeff Johnson295189b2012-06-20 16:38:30 -070012757 \brief hdd_softap_sta_disassoc() - function
12758
12759 This to take counter measure to handle deauth req from HDD
12760
12761 \param - pAdapter - Pointer to the HDD
12762
12763 \param - enable - boolean value
12764
12765 \return - None
12766
12767 --------------------------------------------------------------------------*/
12768
12769void hdd_softap_sta_disassoc(hdd_adapter_t *pAdapter,v_U8_t *pDestMacAddress)
12770{
12771 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
12772
12773 ENTER();
12774
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +053012775 hddLog( LOGE, "hdd_softap_sta_disassoc:(%p, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070012776
12777 //Ignore request to disassoc bcmc station
12778 if( pDestMacAddress[0] & 0x1 )
12779 return;
12780
12781 WLANSAP_DisassocSta(pVosContext,pDestMacAddress);
12782}
12783
12784void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *pAdapter,v_BOOL_t enable)
12785{
12786 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
12787
12788 ENTER();
12789
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +053012790 hddLog( LOGE, "hdd_softap_tkip_mic_fail_counter_measure:(%p, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070012791
12792 WLANSAP_SetCounterMeasure(pVosContext, (v_BOOL_t)enable);
12793}
12794
Jeff Johnson295189b2012-06-20 16:38:30 -070012795/**---------------------------------------------------------------------------
12796 *
12797 * \brief hdd_get__concurrency_mode() -
12798 *
12799 *
12800 * \param - None
12801 *
12802 * \return - CONCURRENCY MODE
12803 *
12804 * --------------------------------------------------------------------------*/
12805tVOS_CONCURRENCY_MODE hdd_get_concurrency_mode ( void )
12806{
12807 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
12808 hdd_context_t *pHddCtx;
12809
12810 if (NULL != pVosContext)
12811 {
12812 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
12813 if (NULL != pHddCtx)
12814 {
12815 return (tVOS_CONCURRENCY_MODE)pHddCtx->concurrency_mode;
12816 }
12817 }
12818
12819 /* we are in an invalid state :( */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070012820 hddLog(LOGE, "%s: Invalid context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070012821 return VOS_STA;
12822}
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053012823v_BOOL_t
12824wlan_hdd_is_GO_power_collapse_allowed (hdd_context_t* pHddCtx)
12825{
12826 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070012827
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053012828 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_GO);
12829 if (pAdapter == NULL)
12830 {
12831 hddLog(VOS_TRACE_LEVEL_INFO,
12832 FL("GO doesn't exist"));
12833 return TRUE;
12834 }
12835 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
12836 {
12837 hddLog(VOS_TRACE_LEVEL_INFO,
12838 FL("GO started"));
12839 return TRUE;
12840 }
12841 else
12842 /* wait till GO changes its interface to p2p device */
12843 hddLog(VOS_TRACE_LEVEL_INFO,
12844 FL("Del_bss called, avoid apps suspend"));
12845 return FALSE;
12846
12847}
Jeff Johnson295189b2012-06-20 16:38:30 -070012848/* Decide whether to allow/not the apps power collapse.
12849 * Allow apps power collapse if we are in connected state.
12850 * if not, allow only if we are in IMPS */
12851v_BOOL_t hdd_is_apps_power_collapse_allowed(hdd_context_t* pHddCtx)
12852{
12853 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
Srikant Kuppafef66a72013-01-30 17:32:44 -080012854 tANI_BOOLEAN scanRspPending = csrNeighborRoamScanRspPending(pHddCtx->hHal);
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080012855 tANI_BOOLEAN inMiddleOfRoaming = csrNeighborMiddleOfRoaming(pHddCtx->hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -070012856 hdd_config_t *pConfig = pHddCtx->cfg_ini;
12857 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
12858 hdd_adapter_t *pAdapter = NULL;
12859 VOS_STATUS status;
Yathish9f22e662012-12-10 14:21:35 -080012860 tVOS_CONCURRENCY_MODE concurrent_state = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070012861
Jeff Johnson295189b2012-06-20 16:38:30 -070012862 if (VOS_STA_SAP_MODE == hdd_get_conparam())
12863 return TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -070012864
Yathish9f22e662012-12-10 14:21:35 -080012865 concurrent_state = hdd_get_concurrency_mode();
12866
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053012867 if ((concurrent_state == (VOS_STA | VOS_P2P_GO)) &&
12868 !(wlan_hdd_is_GO_power_collapse_allowed(pHddCtx)))
12869 return FALSE;
Yathish9f22e662012-12-10 14:21:35 -080012870#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053012871
Yathish9f22e662012-12-10 14:21:35 -080012872 if(((concurrent_state == (VOS_STA | VOS_P2P_CLIENT)) ||
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053012873 (concurrent_state == (VOS_STA | VOS_P2P_GO)))&&
Yathish9f22e662012-12-10 14:21:35 -080012874 (IS_ACTIVEMODE_OFFLOAD_FEATURE_ENABLE))
12875 return TRUE;
12876#endif
12877
Jeff Johnson295189b2012-06-20 16:38:30 -070012878 /*loop through all adapters. TBD fix for Concurrency */
12879 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
12880 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
12881 {
12882 pAdapter = pAdapterNode->pAdapter;
12883 if ( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
12884 || (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
12885 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080012886 if (((pConfig->fIsImpsEnabled || pConfig->fIsBmpsEnabled)
c_hpothu4e8faac2014-05-16 17:38:44 +053012887 && (pmcState != IMPS && pmcState != BMPS && pmcState != UAPSD
c_hpothu1c6957d2015-01-06 18:19:47 +053012888 && pmcState != STOPPED && pmcState != STANDBY &&
12889 pmcState != WOWL)) ||
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080012890 (eANI_BOOLEAN_TRUE == scanRspPending) ||
12891 (eANI_BOOLEAN_TRUE == inMiddleOfRoaming))
Jeff Johnson295189b2012-06-20 16:38:30 -070012892 {
Mukul Sharma4be88422015-03-09 20:29:07 +053012893 if(pmcState == FULL_POWER &&
12894 sme_IsCoexScoIndicationSet(pHddCtx->hHal))
12895 {
12896 /*
12897 * When SCO indication comes from Coex module , host will
12898 * enter in to full power mode, but this should not prevent
12899 * apps processor power collapse.
12900 */
12901 hddLog(LOG1,
12902 FL("Allow apps power collapse"
12903 "even when sco indication is set"));
12904 return TRUE;
12905 }
Srikant Kuppafef66a72013-01-30 17:32:44 -080012906 hddLog( LOGE, "%s: do not allow APPS power collapse-"
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080012907 "pmcState = %d scanRspPending = %d inMiddleOfRoaming = %d",
12908 __func__, pmcState, scanRspPending, inMiddleOfRoaming );
Jeff Johnson295189b2012-06-20 16:38:30 -070012909 return FALSE;
12910 }
12911 }
12912 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
12913 pAdapterNode = pNext;
12914 }
12915 return TRUE;
12916}
12917
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -080012918/* Decides whether to send suspend notification to Riva
12919 * if any adapter is in BMPS; then it is required */
12920v_BOOL_t hdd_is_suspend_notify_allowed(hdd_context_t* pHddCtx)
12921{
12922 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
12923 hdd_config_t *pConfig = pHddCtx->cfg_ini;
12924
12925 if (pConfig->fIsBmpsEnabled && (pmcState == BMPS))
12926 {
12927 return TRUE;
12928 }
12929 return FALSE;
12930}
12931
Jeff Johnson295189b2012-06-20 16:38:30 -070012932void wlan_hdd_set_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
12933{
12934 switch(mode)
12935 {
Chilam Ngc4244af2013-04-01 15:37:32 -070012936 case VOS_STA_MODE:
12937 case VOS_P2P_CLIENT_MODE:
12938 case VOS_P2P_GO_MODE:
12939 case VOS_STA_SAP_MODE:
Jeff Johnsone7245742012-09-05 17:12:55 -070012940 pHddCtx->concurrency_mode |= (1 << mode);
Agarwal Ashish51325b52014-06-16 16:50:49 +053012941 pHddCtx->no_of_open_sessions[mode]++;
Jeff Johnson295189b2012-06-20 16:38:30 -070012942 break;
12943 default:
12944 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070012945 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053012946 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
12947 "Number of open sessions for mode %d = %d"),
12948 pHddCtx->concurrency_mode, mode,
12949 pHddCtx->no_of_open_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070012950}
12951
12952
12953void wlan_hdd_clear_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
12954{
12955 switch(mode)
12956 {
Chilam Ngc4244af2013-04-01 15:37:32 -070012957 case VOS_STA_MODE:
12958 case VOS_P2P_CLIENT_MODE:
12959 case VOS_P2P_GO_MODE:
12960 case VOS_STA_SAP_MODE:
Agarwal Ashish51325b52014-06-16 16:50:49 +053012961 pHddCtx->no_of_open_sessions[mode]--;
12962 if (!(pHddCtx->no_of_open_sessions[mode]))
12963 pHddCtx->concurrency_mode &= (~(1 << mode));
Jeff Johnson295189b2012-06-20 16:38:30 -070012964 break;
12965 default:
12966 break;
12967 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053012968 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
12969 "Number of open sessions for mode %d = %d"),
12970 pHddCtx->concurrency_mode, mode, pHddCtx->no_of_open_sessions[mode]);
12971
12972}
12973/**---------------------------------------------------------------------------
12974 *
12975 * \brief wlan_hdd_incr_active_session()
12976 *
12977 * This function increments the number of active sessions
12978 * maintained per device mode
12979 * Incase of STA/P2P CLI/IBSS upon connection indication it is incremented
12980 * Incase of SAP/P2P GO upon bss start it is incremented
12981 *
12982 * \param pHddCtx - HDD Context
12983 * \param mode - device mode
12984 *
12985 * \return - None
12986 *
12987 * --------------------------------------------------------------------------*/
12988void wlan_hdd_incr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
12989{
12990 switch (mode) {
12991 case VOS_STA_MODE:
12992 case VOS_P2P_CLIENT_MODE:
12993 case VOS_P2P_GO_MODE:
12994 case VOS_STA_SAP_MODE:
12995 pHddCtx->no_of_active_sessions[mode]++;
12996 break;
12997 default:
12998 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
12999 break;
13000 }
13001 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
13002 mode,
13003 pHddCtx->no_of_active_sessions[mode]);
13004}
13005
13006/**---------------------------------------------------------------------------
13007 *
13008 * \brief wlan_hdd_decr_active_session()
13009 *
13010 * This function decrements the number of active sessions
13011 * maintained per device mode
13012 * Incase of STA/P2P CLI/IBSS upon disconnection it is decremented
13013 * Incase of SAP/P2P GO upon bss stop it is decremented
13014 *
13015 * \param pHddCtx - HDD Context
13016 * \param mode - device mode
13017 *
13018 * \return - None
13019 *
13020 * --------------------------------------------------------------------------*/
13021void wlan_hdd_decr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
13022{
Bhargav Shahd0715912015-10-01 18:17:37 +053013023
Agarwal Ashish51325b52014-06-16 16:50:49 +053013024 switch (mode) {
13025 case VOS_STA_MODE:
13026 case VOS_P2P_CLIENT_MODE:
13027 case VOS_P2P_GO_MODE:
13028 case VOS_STA_SAP_MODE:
Agarwal Ashish5325f522014-08-06 00:58:44 +053013029 if (pHddCtx->no_of_active_sessions[mode] > 0)
13030 pHddCtx->no_of_active_sessions[mode]--;
13031 else
13032 hddLog(VOS_TRACE_LEVEL_INFO, FL(" No.# of Active sessions"
13033 "is already Zero"));
Agarwal Ashish51325b52014-06-16 16:50:49 +053013034 break;
13035 default:
13036 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
13037 break;
13038 }
13039 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
13040 mode,
13041 pHddCtx->no_of_active_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070013042}
13043
Jeff Johnsone7245742012-09-05 17:12:55 -070013044/**---------------------------------------------------------------------------
13045 *
13046 * \brief wlan_hdd_restart_init
13047 *
13048 * This function initalizes restart timer/flag. An internal function.
13049 *
13050 * \param - pHddCtx
13051 *
13052 * \return - None
13053 *
13054 * --------------------------------------------------------------------------*/
13055
13056static void wlan_hdd_restart_init(hdd_context_t *pHddCtx)
13057{
13058 /* Initialize */
13059 pHddCtx->hdd_restart_retries = 0;
13060 atomic_set(&pHddCtx->isRestartInProgress, 0);
13061 vos_timer_init(&pHddCtx->hdd_restart_timer,
13062 VOS_TIMER_TYPE_SW,
13063 wlan_hdd_restart_timer_cb,
13064 pHddCtx);
13065}
13066/**---------------------------------------------------------------------------
13067 *
13068 * \brief wlan_hdd_restart_deinit
13069 *
13070 * This function cleans up the resources used. An internal function.
13071 *
13072 * \param - pHddCtx
13073 *
13074 * \return - None
13075 *
13076 * --------------------------------------------------------------------------*/
13077
13078static void wlan_hdd_restart_deinit(hdd_context_t* pHddCtx)
13079{
13080
13081 VOS_STATUS vos_status;
13082 /* Block any further calls */
13083 atomic_set(&pHddCtx->isRestartInProgress, 1);
13084 /* Cleanup */
13085 vos_status = vos_timer_stop( &pHddCtx->hdd_restart_timer );
13086 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053013087 hddLog(LOGE, FL("Failed to stop HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070013088 vos_status = vos_timer_destroy(&pHddCtx->hdd_restart_timer);
13089 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053013090 hddLog(LOGE, FL("Failed to destroy HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070013091
13092}
13093
13094/**---------------------------------------------------------------------------
13095 *
13096 * \brief wlan_hdd_framework_restart
13097 *
13098 * This function uses a cfg80211 API to start a framework initiated WLAN
13099 * driver module unload/load.
13100 *
13101 * Also this API keep retrying (WLAN_HDD_RESTART_RETRY_MAX_CNT).
13102 *
13103 *
13104 * \param - pHddCtx
13105 *
13106 * \return - VOS_STATUS_SUCCESS: Success
13107 * VOS_STATUS_E_EMPTY: Adapter is Empty
13108 * VOS_STATUS_E_NOMEM: No memory
13109
13110 * --------------------------------------------------------------------------*/
13111
13112static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx)
13113{
13114 VOS_STATUS status = VOS_STATUS_SUCCESS;
13115 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070013116 int len = (sizeof (struct ieee80211_mgmt));
13117 struct ieee80211_mgmt *mgmt = NULL;
13118
13119 /* Prepare the DEAUTH managment frame with reason code */
13120 mgmt = kzalloc(len, GFP_KERNEL);
13121 if(mgmt == NULL)
13122 {
13123 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
13124 "%s: memory allocation failed (%d bytes)", __func__, len);
13125 return VOS_STATUS_E_NOMEM;
13126 }
13127 mgmt->u.deauth.reason_code = WLAN_REASON_DISASSOC_LOW_ACK;
Jeff Johnsone7245742012-09-05 17:12:55 -070013128
13129 /* Iterate over all adapters/devices */
13130 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053013131 if ((NULL == pAdapterNode) || (VOS_STATUS_SUCCESS != status))
13132 {
13133 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13134 FL("fail to get adapter: %p %d"), pAdapterNode, status);
13135 goto end;
13136 }
13137
Jeff Johnsone7245742012-09-05 17:12:55 -070013138 do
13139 {
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053013140 if(pAdapterNode->pAdapter &&
13141 WLAN_HDD_ADAPTER_MAGIC == pAdapterNode->pAdapter->magic)
Jeff Johnsone7245742012-09-05 17:12:55 -070013142 {
13143 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
13144 "restarting the driver(intf:\'%s\' mode:%d :try %d)",
13145 pAdapterNode->pAdapter->dev->name,
13146 pAdapterNode->pAdapter->device_mode,
13147 pHddCtx->hdd_restart_retries + 1);
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070013148 /*
13149 * CFG80211 event to restart the driver
13150 *
13151 * 'cfg80211_send_unprot_deauth' sends a
13152 * NL80211_CMD_UNPROT_DEAUTHENTICATE event to supplicant at any state
13153 * of SME(Linux Kernel) state machine.
13154 *
13155 * Reason code WLAN_REASON_DISASSOC_LOW_ACK is currently used to restart
13156 * the driver.
13157 *
13158 */
Abhishek Singh00b71972016-01-07 10:51:04 +053013159
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053013160#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
13161 cfg80211_rx_unprot_mlme_mgmt(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len);
13162#else
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070013163 cfg80211_send_unprot_deauth(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len );
Anand N Sunkade9adb1b2015-07-29 09:56:45 +053013164#endif
Jeff Johnsone7245742012-09-05 17:12:55 -070013165 }
13166 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
13167 pAdapterNode = pNext;
13168 } while((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status));
13169
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +053013170 end:
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070013171 /* Free the allocated management frame */
13172 kfree(mgmt);
13173
Jeff Johnsone7245742012-09-05 17:12:55 -070013174 /* Retry until we unload or reach max count */
13175 if(++pHddCtx->hdd_restart_retries < WLAN_HDD_RESTART_RETRY_MAX_CNT)
13176 vos_timer_start(&pHddCtx->hdd_restart_timer, WLAN_HDD_RESTART_RETRY_DELAY_MS);
13177
13178 return status;
13179
13180}
13181/**---------------------------------------------------------------------------
13182 *
13183 * \brief wlan_hdd_restart_timer_cb
13184 *
13185 * Restart timer callback. An internal function.
13186 *
13187 * \param - User data:
13188 *
13189 * \return - None
13190 *
13191 * --------------------------------------------------------------------------*/
13192
13193void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback)
13194{
13195 hdd_context_t *pHddCtx = usrDataForCallback;
13196 wlan_hdd_framework_restart(pHddCtx);
13197 return;
13198
13199}
13200
13201
13202/**---------------------------------------------------------------------------
13203 *
13204 * \brief wlan_hdd_restart_driver
13205 *
13206 * This function sends an event to supplicant to restart the WLAN driver.
13207 *
13208 * This function is called from vos_wlanRestart.
13209 *
13210 * \param - pHddCtx
13211 *
13212 * \return - VOS_STATUS_SUCCESS: Success
13213 * VOS_STATUS_E_EMPTY: Adapter is Empty
13214 * VOS_STATUS_E_ALREADY: Request already in progress
13215
13216 * --------------------------------------------------------------------------*/
13217VOS_STATUS wlan_hdd_restart_driver(hdd_context_t *pHddCtx)
13218{
13219 VOS_STATUS status = VOS_STATUS_SUCCESS;
13220
13221 /* A tight check to make sure reentrancy */
13222 if(atomic_xchg(&pHddCtx->isRestartInProgress, 1))
13223 {
Mihir Shetefd528652014-06-23 19:07:50 +053013224 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsone7245742012-09-05 17:12:55 -070013225 "%s: WLAN restart is already in progress", __func__);
13226
13227 return VOS_STATUS_E_ALREADY;
13228 }
Sameer Thalappil0c164f52013-03-28 15:27:56 -070013229 /* Send reset FIQ to WCNSS to invoke SSR. */
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -080013230#ifdef HAVE_WCNSS_RESET_INTR
Siddharth Bhal864e7e82015-04-07 20:07:24 +053013231 wcnss_reset_fiq(TRUE);
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -070013232#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070013233
Jeff Johnsone7245742012-09-05 17:12:55 -070013234 return status;
13235}
13236
Bhargav Shahd0715912015-10-01 18:17:37 +053013237/**
13238 * hdd_get_total_sessions() - provide total number of active sessions
13239 * @pHddCtx: Valid Global HDD context pointer
13240 *
13241 * This function iterates through pAdaptors and find the number of all active
13242 * sessions. This active sessions includes connected sta, p2p client and number
13243 * of client connected to sap/p2p go.
13244 *
13245 * Return: Total number of active sessions.
13246 */
13247v_U8_t hdd_get_total_sessions(hdd_context_t *pHddCtx)
13248{
13249 v_U8_t active_session = 0;
13250 hdd_station_ctx_t *pHddStaCtx;
13251 hdd_adapter_list_node_t *pAdapterNode, *pNext;
13252 hdd_adapter_t *pAdapter;
13253 VOS_STATUS status;
13254
13255 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
13256 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
13257 pAdapter = pAdapterNode->pAdapter;
13258 switch (pAdapter->device_mode) {
13259 case VOS_STA_MODE:
13260 case VOS_P2P_CLIENT_MODE:
13261 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
13262 if(eConnectionState_Associated == pHddStaCtx->conn_info.connState)
13263 active_session += 1;
13264 break;
13265 case VOS_STA_SAP_MODE:
13266 case VOS_P2P_GO_MODE:
13267 active_session += hdd_softap_get_connected_sta(pAdapter);
13268 break;
13269 default:
13270 break;
13271 }
13272
13273 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
13274 pAdapterNode = pNext;
13275 }
13276
13277 return active_session;
13278}
13279
13280/**
13281 * hdd_set_delack_value() - Set delack value
13282 * @pHddCtx: Valid Global HDD context pointer
13283 * @next_rx_level: Value to set for delack
13284 *
13285 * This function compare present value and next value of delack. If the both
13286 * are diffrent then it sets next value .
13287 *
13288 * Return: void.
13289 */
13290void hdd_set_delack_value(hdd_context_t *pHddCtx, v_U32_t next_rx_level)
13291{
13292 if (pHddCtx->cur_rx_level != next_rx_level) {
13293 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
13294 "%s: TCP DELACK trigger level %d",
13295 __func__, next_rx_level);
13296 mutex_lock(&pHddCtx->cur_rx_level_lock);
13297 pHddCtx->cur_rx_level = next_rx_level;
13298 mutex_unlock(&pHddCtx->cur_rx_level_lock);
13299 wlan_hdd_send_svc_nlink_msg(WLAN_SVC_WLAN_TP_IND, &next_rx_level,
13300 sizeof(next_rx_level));
13301 }
13302}
13303
13304/**
13305 * hdd_set_default_stop_delack_timer() - Start delack timer
13306 * @pHddCtx: Valid Global HDD context pointer
13307 *
13308 * This function stop delack timer and set delack value to default..
13309 *
13310 * Return: void.
13311 */
13312
13313void hdd_set_default_stop_delack_timer(hdd_context_t *pHddCtx)
13314{
13315 if (VOS_TIMER_STATE_RUNNING !=
13316 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
13317 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
13318 "%s: Can not stop timer", __func__);
13319 return;
13320 }
13321
13322 vos_timer_stop(&pHddCtx->delack_timer);
13323 hdd_set_delack_value(pHddCtx, TP_IND_LOW);
13324}
13325
13326/**
13327 * hdd_start_delack_timer() - Start delack timer
13328 * @pHddCtx: Valid Global HDD context pointer
13329 *
13330 * This function starts the delack timer for tcpDelAckComputeInterval time
13331 * interval.The default timer value is 2 second.
13332 *
13333 * Return: void.
13334 */
13335void hdd_start_delack_timer(hdd_context_t *pHddCtx)
13336{
13337 if (VOS_TIMER_STATE_RUNNING ==
13338 vos_timer_getCurrentState(&pHddCtx->delack_timer)) {
13339 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
13340 "%s: Timer is already running", __func__);
13341 return;
13342 }
13343
13344 vos_timer_start(&pHddCtx->delack_timer,
13345 pHddCtx->cfg_ini->tcpDelAckComputeInterval);
13346}
13347
13348/**
13349 * hdd_update_prev_rx_packet_count() - Update previous rx packet count
13350 * @pHddCtx: Valid Global HDD context pointer
13351 *
13352 * This function updates the prev_rx_packets count from the corresponding
13353 * pAdapter states. This prev_rx_packets will diffed with the packet count
13354 * at the end of delack timer. That can give number of RX packet is spacific
13355 * time.
13356 *
13357 * Return: void.
13358 */
13359void hdd_update_prev_rx_packet_count(hdd_context_t *pHddCtx)
13360{
13361 hdd_adapter_list_node_t *pAdapterNode, *pNext;
13362 hdd_adapter_t *pAdapter;
13363 VOS_STATUS status;
13364
13365 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
13366 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status) {
13367 pAdapter = pAdapterNode->pAdapter;
13368 pAdapter->prev_rx_packets = pAdapter->stats.rx_packets;
13369 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
13370 pAdapterNode = pNext;
13371 }
13372}
13373
13374/**
13375 * hdd_manage_delack_timer() - start\stop delack timer
13376 * @pHddCtx: Valid Global HDD context pointer
13377 *
13378 * This function check the number of concerent session present, it starts the
13379 * delack timer if only one session is present.
13380 * In the case of BT_COEX and TDLS mode it blindly stop delack functionality.
13381 *
13382 * Return: void.
13383 */
13384void hdd_manage_delack_timer(hdd_context_t *pHddCtx)
13385{
13386 uint8_t sessions;
13387
13388 if (!pHddCtx->cfg_ini->enable_delack) {
13389 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_DEBUG,
13390 "%s: TCP DELACK is not enabled", __func__);
13391 return;
13392 }
13393
13394 /* Blindly stop timer of BTCOEX and TDLS Session is up */
13395 if (pHddCtx->mode != 0) {
13396 hdd_set_default_stop_delack_timer(pHddCtx);
13397 return;
13398 }
13399
13400 sessions = hdd_get_total_sessions(pHddCtx);
13401 if (sessions == 1) {
13402 hdd_update_prev_rx_packet_count(pHddCtx);
13403 hdd_start_delack_timer(pHddCtx);
13404 } else {
13405 hdd_set_default_stop_delack_timer(pHddCtx);
13406 }
13407}
13408
Mihir Shetee1093ba2014-01-21 20:13:32 +053013409/**---------------------------------------------------------------------------
13410 *
13411 * \brief wlan_hdd_init_channels
13412 *
13413 * This function is used to initialize the channel list in CSR
13414 *
13415 * This function is called from hdd_wlan_startup
13416 *
13417 * \param - pHddCtx: HDD context
13418 *
13419 * \return - VOS_STATUS_SUCCESS: Success
13420 * VOS_STATUS_E_FAULT: Failure reported by SME
13421
13422 * --------------------------------------------------------------------------*/
13423static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx)
13424{
13425 eHalStatus status;
13426
13427 status = sme_InitChannels(pHddCtx->hHal);
13428 if (HAL_STATUS_SUCCESS(status))
13429 {
13430 return VOS_STATUS_SUCCESS;
13431 }
13432 else
13433 {
13434 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Channel initialization failed(%d)",
13435 __func__, status);
13436 return VOS_STATUS_E_FAULT;
13437 }
13438}
13439
Mihir Shete04206452014-11-20 17:50:58 +053013440#ifdef CONFIG_ENABLE_LINUX_REG
Agarwal Ashish6db9d532014-09-30 18:19:10 +053013441VOS_STATUS wlan_hdd_init_channels_for_cc(hdd_context_t *pHddCtx, driver_load_type init )
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013442{
13443 eHalStatus status;
13444
Agarwal Ashish6db9d532014-09-30 18:19:10 +053013445 status = sme_InitChannelsForCC(pHddCtx->hHal, init);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053013446 if (HAL_STATUS_SUCCESS(status))
13447 {
13448 return VOS_STATUS_SUCCESS;
13449 }
13450 else
13451 {
13452 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Issue reg hint failed(%d)",
13453 __func__, status);
13454 return VOS_STATUS_E_FAULT;
13455 }
13456}
Mihir Shete04206452014-11-20 17:50:58 +053013457#endif
Sudhir Sattayappa Kohallib1d8c3a2013-06-18 14:47:20 -070013458/*
13459 * API to find if there is any STA or P2P-Client is connected
13460 */
13461VOS_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *pHddCtx)
13462{
13463 return sme_isSta_p2p_clientConnected(pHddCtx->hHal);
13464}
Jeff Johnsone7245742012-09-05 17:12:55 -070013465
Mihir Shetee2ae82a2015-03-16 14:08:49 +053013466
13467/*
13468 * API to find if the firmware will send logs using DXE channel
13469 */
13470v_U8_t hdd_is_fw_logging_enabled(void)
13471{
13472 hdd_context_t *pHddCtx;
13473
13474 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
13475 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
13476
Sachin Ahuja084313e2015-05-21 17:57:10 +053013477 return (pHddCtx && pHddCtx->cfg_ini->enableMgmtLogging);
Mihir Shetee2ae82a2015-03-16 14:08:49 +053013478}
13479
Agarwal Ashish57e84372014-12-05 18:26:53 +053013480/*
Mihir Shetebe94ebb2015-05-26 12:07:14 +053013481 * API to find if the firmware will send trace logs using DXE channel
13482 */
13483v_U8_t hdd_is_fw_ev_logging_enabled(void)
13484{
13485 hdd_context_t *pHddCtx;
13486
13487 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD,
13488 vos_get_global_context(VOS_MODULE_ID_HDD, NULL));
13489
13490 return (pHddCtx && pHddCtx->cfg_ini->enableFWLogging);
13491}
13492/*
Agarwal Ashish57e84372014-12-05 18:26:53 +053013493 * API to find if there is any session connected
13494 */
13495VOS_STATUS hdd_is_any_session_connected(hdd_context_t *pHddCtx)
13496{
13497 return sme_is_any_session_connected(pHddCtx->hHal);
13498}
13499
13500
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053013501int wlan_hdd_scan_abort(hdd_adapter_t *pAdapter)
13502{
13503 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
13504 hdd_scaninfo_t *pScanInfo = NULL;
Girish Gowli4bf7a632014-06-12 13:42:11 +053013505 long status = 0;
c_hpothua3d45d52015-01-05 14:11:17 +053013506 tSirAbortScanStatus abortScanStatus;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053013507
13508 pScanInfo = &pHddCtx->scan_info;
Ratnam Rachuric7681132015-06-30 10:35:13 +053013509 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053013510 if (pScanInfo->mScanPending)
13511 {
c_hpothua3d45d52015-01-05 14:11:17 +053013512 abortScanStatus = hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
13513 eCSR_SCAN_ABORT_DEFAULT);
13514 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
13515 FL("abortScanStatus: %d"), abortScanStatus);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053013516
c_hpothua3d45d52015-01-05 14:11:17 +053013517 /* If there is active scan command lets wait for the completion else
13518 * there is no need to wait as scan command might be in the SME pending
13519 * command list.
13520 */
13521 if (abortScanStatus == eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY)
13522 {
c_hpothua3d45d52015-01-05 14:11:17 +053013523 status = wait_for_completion_interruptible_timeout(
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053013524 &pScanInfo->abortscan_event_var,
13525 msecs_to_jiffies(5000));
c_hpothua3d45d52015-01-05 14:11:17 +053013526 if (0 >= status)
13527 {
13528 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Girish Gowli4bf7a632014-06-12 13:42:11 +053013529 "%s: Timeout or Interrupt occurred while waiting for abort"
13530 "scan, status- %ld", __func__, status);
c_hpothua3d45d52015-01-05 14:11:17 +053013531 return -ETIMEDOUT;
13532 }
13533 }
13534 else if (abortScanStatus == eSIR_ABORT_SCAN_FAILURE)
13535 {
13536 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13537 FL("hdd_abort_mac_scan failed"));
13538 return -VOS_STATUS_E_FAILURE;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053013539 }
13540 }
Girish Gowli4bf7a632014-06-12 13:42:11 +053013541 return 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053013542}
13543
Abhishek Singh7d624e12015-11-30 14:29:27 +053013544/**
13545 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
13546 * user space
13547 * @frame_ind: Management frame data to be informed.
13548 *
13549 * This function is used to indicate management frame to
13550 * user space
13551 *
13552 * Return: None
13553 *
13554 */
13555void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
13556{
13557 hdd_context_t *hdd_ctx = NULL;
13558 hdd_adapter_t *adapter = NULL;
13559 v_CONTEXT_t vos_context = NULL;
13560
13561 /* Get the global VOSS context.*/
13562 vos_context = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
13563 if (!vos_context) {
13564 hddLog(LOGE, FL("Global VOS context is Null"));
13565 return;
13566 }
13567 /* Get the HDD context.*/
13568 hdd_ctx =
13569 (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, vos_context );
13570
13571 if (0 != wlan_hdd_validate_context(hdd_ctx))
13572 {
13573 return;
13574 }
13575 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
13576 frame_ind->sessionId);
13577
13578 if ((NULL != adapter) &&
13579 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
13580 __hdd_indicate_mgmt_frame(adapter,
13581 frame_ind->frameLen,
13582 frame_ind->frameBuf,
13583 frame_ind->frameType,
13584 frame_ind->rxChan,
13585 frame_ind->rxRssi);
13586 return;
13587
13588}
13589
c_hpothu225aa7c2014-10-22 17:45:13 +053013590VOS_STATUS wlan_hdd_cancel_remain_on_channel(hdd_context_t *pHddCtx)
13591{
13592 hdd_adapter_t *pAdapter;
13593 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
13594 VOS_STATUS vosStatus;
13595
13596 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
13597 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
13598 {
13599 pAdapter = pAdapterNode->pAdapter;
13600 if (NULL != pAdapter)
13601 {
13602 if (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode ||
13603 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
13604 WLAN_HDD_P2P_GO == pAdapter->device_mode)
13605 {
13606 hddLog(LOG1, FL("abort ROC deviceMode: %d"),
13607 pAdapter->device_mode);
13608 if (VOS_STATUS_SUCCESS !=
13609 wlan_hdd_cancel_existing_remain_on_channel(pAdapter))
13610 {
13611 hddLog(LOGE, FL("failed to abort ROC"));
13612 return VOS_STATUS_E_FAILURE;
13613 }
13614 }
13615 }
13616 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
13617 pAdapterNode = pNext;
13618 }
13619 return VOS_STATUS_SUCCESS;
13620}
Mahesh A Saptasagard477b092015-02-06 15:12:16 +053013621
Mihir Shete0be28772015-02-17 18:42:14 +053013622hdd_remain_on_chan_ctx_t *hdd_get_remain_on_channel_ctx(hdd_context_t *pHddCtx)
13623{
13624 hdd_adapter_t *pAdapter;
13625 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
13626 hdd_cfg80211_state_t *cfgState;
13627 hdd_remain_on_chan_ctx_t *pRemainChanCtx = NULL;
13628 VOS_STATUS vosStatus;
13629
13630 vosStatus = hdd_get_front_adapter (pHddCtx, &pAdapterNode);
13631 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
13632 {
13633 pAdapter = pAdapterNode->pAdapter;
13634 if (NULL != pAdapter)
13635 {
13636 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter);
13637 pRemainChanCtx = cfgState->remain_on_chan_ctx;
13638 if (pRemainChanCtx)
13639 break;
13640 }
13641 vosStatus = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
13642 pAdapterNode = pNext;
13643 }
13644 return pRemainChanCtx;
13645}
13646
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +053013647/**
13648 * wlan_hdd_handle_dfs_chan_scan () - handles disable/enable DFS channels
13649 *
13650 * @pHddCtx: HDD context within host driver
13651 * @dfsScanMode: dfsScanMode passed from ioctl
13652 *
13653 */
13654
13655VOS_STATUS wlan_hdd_handle_dfs_chan_scan(hdd_context_t *pHddCtx,
13656 tANI_U8 dfsScanMode)
13657{
13658 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
13659 hdd_adapter_t *pAdapter;
13660 VOS_STATUS vosStatus;
13661 hdd_station_ctx_t *pHddStaCtx;
13662 eHalStatus status = eHAL_STATUS_SUCCESS;
13663
13664 if(!pHddCtx)
13665 {
13666 hddLog(LOGE, FL("HDD context is Null"));
13667 return eHAL_STATUS_FAILURE;
13668 }
13669
13670 if (pHddCtx->scan_info.mScanPending)
13671 {
13672 hddLog(LOG1, FL("Aborting scan for sessionId: %d"),
13673 pHddCtx->scan_info.sessionId);
13674 hdd_abort_mac_scan(pHddCtx,
13675 pHddCtx->scan_info.sessionId,
13676 eCSR_SCAN_ABORT_DEFAULT);
13677 }
13678
13679 if (!dfsScanMode)
13680 {
13681 vosStatus = hdd_get_front_adapter( pHddCtx, &pAdapterNode);
13682 while ((NULL != pAdapterNode) &&
13683 (VOS_STATUS_SUCCESS == vosStatus))
13684 {
13685 pAdapter = pAdapterNode->pAdapter;
13686
13687 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
13688 {
13689 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
13690
13691 if(!pHddStaCtx)
13692 {
13693 hddLog(LOGE, FL("HDD STA context is Null"));
13694 return eHAL_STATUS_FAILURE;
13695 }
13696
13697 /* if STA is already connected on DFS channel,
13698 disconnect immediately*/
13699 if (hdd_connIsConnected(pHddStaCtx) &&
13700 (NV_CHANNEL_DFS ==
13701 vos_nv_getChannelEnabledState(
13702 pHddStaCtx->conn_info.operationChannel)))
13703 {
13704 status = sme_RoamDisconnect(pHddCtx->hHal,
13705 pAdapter->sessionId,
13706 eCSR_DISCONNECT_REASON_UNSPECIFIED);
13707 hddLog(LOG1, FL("Client connected on DFS channel %d,"
13708 "sme_RoamDisconnect returned with status: %d"
13709 "for sessionid: %d"), pHddStaCtx->conn_info.
13710 operationChannel, status, pAdapter->sessionId);
13711 }
13712 }
13713
13714 vosStatus = hdd_get_next_adapter(pHddCtx, pAdapterNode,
13715 &pNext);
13716 pAdapterNode = pNext;
13717 }
13718 }
13719
13720 sme_UpdateDFSScanMode(pHddCtx->hHal, dfsScanMode);
13721 sme_UpdateDFSRoamMode(pHddCtx->hHal,
13722 (dfsScanMode != DFS_CHNL_SCAN_DISABLED));
13723
13724 status = sme_HandleDFSChanScan(pHddCtx->hHal);
13725 if (!HAL_STATUS_SUCCESS(status))
13726 {
13727 hddLog(LOGE,
13728 FL("Failed in sme_HandleDFSChanScan (err=%d)"), status);
13729 return status;
13730 }
13731
13732 return status;
13733}
13734
Nirav Shah7e3c8132015-06-22 23:51:42 +053013735static int hdd_log2_ceil(unsigned value)
13736{
13737 /* need to switch to unsigned math so that negative values
13738 * will right-shift towards 0 instead of -1
13739 */
13740 unsigned tmp = value;
13741 int log2 = -1;
13742
13743 if (value == 0)
13744 return 0;
13745
13746 while (tmp) {
13747 log2++;
13748 tmp >>= 1;
13749 }
13750 if (1U << log2 != value)
13751 log2++;
13752
13753 return log2;
13754}
13755
13756/**
13757 * hdd_sta_id_hash_attach() - initialize sta id to macaddr hash
13758 * @pAdapter: adapter handle
13759 *
13760 * Return: vos status
13761 */
13762VOS_STATUS hdd_sta_id_hash_attach(hdd_adapter_t *pAdapter)
13763{
13764 int hash_elem, log2, i;
13765
13766 spin_lock_bh( &pAdapter->sta_hash_lock);
13767 if (pAdapter->is_sta_id_hash_initialized == VOS_TRUE) {
13768 spin_unlock_bh( &pAdapter->sta_hash_lock);
13769 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13770 "%s: hash already attached for session id %d",
13771 __func__, pAdapter->sessionId);
13772 return VOS_STATUS_SUCCESS;
13773 }
13774 spin_unlock_bh( &pAdapter->sta_hash_lock);
13775
13776 hash_elem = WLAN_MAX_STA_COUNT;
13777 hash_elem *= HDD_STA_ID_HASH_MULTIPLIER;
13778 log2 = hdd_log2_ceil(hash_elem);
13779 hash_elem = 1 << log2;
13780
13781 pAdapter->sta_id_hash.mask = hash_elem - 1;
13782 pAdapter->sta_id_hash.idx_bits = log2;
13783 pAdapter->sta_id_hash.bins =
13784 vos_mem_malloc(hash_elem *sizeof(hdd_list_t));
13785 if (!pAdapter->sta_id_hash.bins) {
13786 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13787 "%s: malloc failed for session %d",
13788 __func__, pAdapter->sessionId);
13789 return VOS_STATUS_E_NOMEM;
13790 }
13791
13792 for (i = 0; i < hash_elem; i++)
13793 hdd_list_init(&pAdapter->sta_id_hash.bins[i], WLAN_MAX_STA_COUNT);
13794
13795 spin_lock_bh( &pAdapter->sta_hash_lock);
13796 pAdapter->is_sta_id_hash_initialized = VOS_TRUE;
13797 spin_unlock_bh( &pAdapter->sta_hash_lock);
13798 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
13799 "%s: Station ID Hash attached for session id %d",
13800 __func__, pAdapter->sessionId);
13801
13802 return VOS_STATUS_SUCCESS;
13803}
13804
13805/**
13806 * hdd_sta_id_hash_detach() - deinit sta_id to macaddr hash
13807 * @pAdapter: adapter handle
13808 *
13809 * Return: vos status
13810 */
13811VOS_STATUS hdd_sta_id_hash_detach(hdd_adapter_t *pAdapter)
13812{
13813 int hash_elem, i;
13814 v_SIZE_t size;
13815
13816 spin_lock_bh( &pAdapter->sta_hash_lock);
13817 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
13818 spin_unlock_bh( &pAdapter->sta_hash_lock);
13819 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
13820 "%s: hash not initialized for session id %d",
13821 __func__, pAdapter->sessionId);
13822 return VOS_STATUS_SUCCESS;
13823 }
13824
13825 pAdapter->is_sta_id_hash_initialized = VOS_FALSE;
13826 spin_unlock_bh( &pAdapter->sta_hash_lock);
13827
13828 hash_elem = 1 << pAdapter->sta_id_hash.idx_bits;
13829
13830 /* free all station info*/
13831 for (i = 0; i < hash_elem; i++) {
13832 hdd_list_size(&pAdapter->sta_id_hash.bins[i], &size);
13833 if (size != 0) {
13834 VOS_STATUS status;
13835 hdd_staid_hash_node_t *sta_info_node = NULL;
13836 hdd_staid_hash_node_t *next_node = NULL;
13837 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[i],
13838 (hdd_list_node_t**) &sta_info_node );
13839
13840 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
13841 {
13842 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[i],
13843 &sta_info_node->node);
13844 vos_mem_free(sta_info_node);
13845
13846 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[i],
13847 (hdd_list_node_t*)sta_info_node,
13848 (hdd_list_node_t**)&next_node);
13849 sta_info_node = next_node;
13850 }
13851 }
13852 }
13853
13854 vos_mem_free(pAdapter->sta_id_hash.bins);
13855 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
13856 "%s: Station ID Hash detached for session id %d",
13857 __func__, pAdapter->sessionId);
13858 return VOS_STATUS_SUCCESS;
13859}
13860
13861/**
13862 * hdd_sta_id_hash_calculate_index() - derive index from macaddr
13863 * @pAdapter: adapter handle
13864 * @mac_addr_in: input mac address
13865 *
13866 * Return: index derived from mac address
13867 */
13868int hdd_sta_id_hash_calculate_index(hdd_adapter_t *pAdapter,
13869 v_MACADDR_t *mac_addr_in)
13870{
13871 uint16 index;
13872 struct hdd_align_mac_addr_t * mac_addr =
13873 (struct hdd_align_mac_addr_t *)mac_addr_in;
13874
13875 index = mac_addr->bytes_ab ^
13876 mac_addr->bytes_cd ^ mac_addr->bytes_ef;
13877 index ^= index >> pAdapter->sta_id_hash.idx_bits;
13878 index &= pAdapter->sta_id_hash.mask;
13879 return index;
13880}
13881
13882/**
13883 * hdd_sta_id_hash_add_entry() - add entry in hash
13884 * @pAdapter: adapter handle
13885 * @sta_id: station id
13886 * @mac_addr: mac address
13887 *
13888 * Return: vos status
13889 */
13890VOS_STATUS hdd_sta_id_hash_add_entry(hdd_adapter_t *pAdapter,
13891 v_U8_t sta_id, v_MACADDR_t *mac_addr)
13892{
13893 uint16 index;
13894 hdd_staid_hash_node_t *sta_info_node = NULL;
13895
Nirav Shah7e3c8132015-06-22 23:51:42 +053013896 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
13897 sta_info_node = vos_mem_malloc(sizeof(hdd_staid_hash_node_t));
13898 if (!sta_info_node) {
Nirav Shah7e3c8132015-06-22 23:51:42 +053013899 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13900 "%s: malloc failed", __func__);
13901 return VOS_STATUS_E_NOMEM;
13902 }
13903
13904 sta_info_node->sta_id = sta_id;
13905 vos_mem_copy(&sta_info_node->mac_addr, mac_addr, sizeof(v_MACADDR_t));
13906
Nirav Shah303ed5c2015-08-24 10:29:25 +053013907 spin_lock_bh( &pAdapter->sta_hash_lock);
13908 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
13909 spin_unlock_bh( &pAdapter->sta_hash_lock);
13910 vos_mem_free(sta_info_node);
13911 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
13912 "%s: hash is not initialized for session id %d",
13913 __func__, pAdapter->sessionId);
13914 return VOS_STATUS_E_FAILURE;
13915 }
13916
Nirav Shah7e3c8132015-06-22 23:51:42 +053013917 hdd_list_insert_back ( &pAdapter->sta_id_hash.bins[index],
13918 (hdd_list_node_t*) sta_info_node );
13919 spin_unlock_bh( &pAdapter->sta_hash_lock);
13920 return VOS_STATUS_SUCCESS;
13921}
13922
13923/**
13924 * hdd_sta_id_hash_remove_entry() - remove entry from hash
13925 * @pAdapter: adapter handle
13926 * @sta_id: station id
13927 * @mac_addr: mac address
13928 *
13929 * Return: vos status
13930 */
13931VOS_STATUS hdd_sta_id_hash_remove_entry(hdd_adapter_t *pAdapter,
13932 v_U8_t sta_id, v_MACADDR_t *mac_addr)
13933{
13934 uint16 index;
13935 VOS_STATUS status;
13936 hdd_staid_hash_node_t *sta_info_node = NULL;
13937 hdd_staid_hash_node_t *next_node = NULL;
13938
13939 spin_lock_bh( &pAdapter->sta_hash_lock);
13940 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
13941 spin_unlock_bh( &pAdapter->sta_hash_lock);
13942 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
13943 "%s: hash is not initialized for session id %d",
13944 __func__, pAdapter->sessionId);
13945 return VOS_STATUS_E_FAILURE;
13946 }
13947
13948 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr);
13949 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
13950 (hdd_list_node_t**) &sta_info_node );
13951
13952 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
13953 {
13954 if (sta_info_node->sta_id == sta_id) {
13955 status = hdd_list_remove_node( &pAdapter->sta_id_hash.bins[index],
13956 &sta_info_node->node);
13957 vos_mem_free(sta_info_node);
13958 break;
13959 }
13960 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
13961 (hdd_list_node_t*)sta_info_node, (hdd_list_node_t**)&next_node);
13962 sta_info_node = next_node;
13963 }
13964 spin_unlock_bh( &pAdapter->sta_hash_lock);
13965 return status;
13966}
13967
13968/**
13969 * hdd_sta_id_find_from_mac_addr() - find sta id from mac address
13970 * @pAdapter: adapter handle
13971 * @mac_addr_in: mac address
13972 *
13973 * Return: station id
13974 */
13975int hdd_sta_id_find_from_mac_addr(hdd_adapter_t *pAdapter,
13976 v_MACADDR_t *mac_addr_in)
13977{
13978 uint8 is_found = 0;
13979 uint8 sta_id = HDD_WLAN_INVALID_STA_ID;
13980 uint16 index;
13981 VOS_STATUS status;
13982 hdd_staid_hash_node_t *sta_info_node = NULL;
13983 hdd_staid_hash_node_t *next_node = NULL;
13984
13985 spin_lock_bh( &pAdapter->sta_hash_lock);
13986 if (pAdapter->is_sta_id_hash_initialized != VOS_TRUE) {
13987 spin_unlock_bh( &pAdapter->sta_hash_lock);
Bhargav Shahce3b32c2015-08-10 12:29:24 +053013988 hddLog(VOS_TRACE_LEVEL_INFO,
Nirav Shah7e3c8132015-06-22 23:51:42 +053013989 FL("hash is not initialized for session id %d"),
13990 pAdapter->sessionId);
13991 return HDD_WLAN_INVALID_STA_ID;
13992 }
13993
13994 index = hdd_sta_id_hash_calculate_index(pAdapter, mac_addr_in);
13995 status = hdd_list_peek_front ( &pAdapter->sta_id_hash.bins[index],
13996 (hdd_list_node_t**) &sta_info_node );
13997
13998 while ( NULL != sta_info_node && VOS_STATUS_SUCCESS == status )
13999 {
14000 if (vos_mem_compare(&sta_info_node->mac_addr,
14001 mac_addr_in, sizeof(v_MACADDR_t))) {
14002 is_found = 1;
14003 sta_id = sta_info_node->sta_id;
14004 break;
14005 }
14006 status = hdd_list_peek_next (&pAdapter->sta_id_hash.bins[index],
14007 (hdd_list_node_t*)sta_info_node,
14008 (hdd_list_node_t**)&next_node);
14009 sta_info_node = next_node;
14010 }
14011 spin_unlock_bh( &pAdapter->sta_hash_lock);
14012 return sta_id;
14013}
14014
c_manjeecfd1efb2015-09-25 19:32:34 +053014015/*FW memory dump feature*/
14016/**
14017 * This structure hold information about the /proc file
14018 *
14019 */
14020static struct proc_dir_entry *proc_file, *proc_dir;
14021
14022/**
14023 * memdump_read() - perform read operation in memory dump proc file
14024 *
14025 * @file - handle for the proc file.
14026 * @buf - pointer to user space buffer.
14027 * @count - number of bytes to be read.
14028 * @pos - offset in the from buffer.
14029 *
14030 * This function performs read operation for the memory dump proc file.
14031 *
14032 * Return: number of bytes read on success, error code otherwise.
14033 */
14034static ssize_t memdump_read(struct file *file, char __user *buf,
14035 size_t count, loff_t *pos)
14036{
14037 int status;
14038 hdd_context_t *hdd_ctx = (hdd_context_t *)PDE_DATA(file_inode(file));
14039 size_t ret_count;
c_manjeef1495642015-10-13 18:35:01 +053014040 loff_t bytes_left;
c_manjeecfd1efb2015-09-25 19:32:34 +053014041 ENTER();
14042
14043 hddLog(LOG1, FL("Read req for size:%zu pos:%llu"), count, *pos);
14044 status = wlan_hdd_validate_context(hdd_ctx);
14045 if (0 != status) {
14046 return -EINVAL;
14047 }
14048
14049 if (!wlan_fwr_mem_dump_test_and_set_read_allowed_bit()) {
14050 hddLog(LOGE, FL("Current mem dump request timed out/failed"));
14051 return -EINVAL;
14052 }
14053
14054 /* run fs_read_handler in an atomic context*/
14055 vos_ssr_protect(__func__);
c_manjeef1495642015-10-13 18:35:01 +053014056 ret_count = wlan_fwr_mem_dump_fsread_handler( buf, count, pos, &bytes_left);
14057 if(bytes_left == 0)
c_manjeecfd1efb2015-09-25 19:32:34 +053014058 {
14059 /*Free the fwr mem dump buffer */
14060 wlan_free_fwr_mem_dump_buffer();
14061 wlan_set_fwr_mem_dump_state(FW_MEM_DUMP_IDLE);
c_manjeef1495642015-10-13 18:35:01 +053014062 ret_count=0;
c_manjeecfd1efb2015-09-25 19:32:34 +053014063 }
14064 /*if SSR/unload code is waiting for memdump_read to finish,signal it*/
14065 vos_ssr_unprotect(__func__);
14066 EXIT();
14067 return ret_count;
14068}
14069
14070/**
14071 * struct memdump_fops - file operations for memory dump feature
14072 * @read - read function for memory dump operation.
14073 *
14074 * This structure initialize the file operation handle for memory
14075 * dump feature
14076 */
14077static const struct file_operations memdump_fops = {
14078 read: memdump_read
14079};
14080
14081/*
14082* wlan_hdd_fw_mem_dump_cb : callback for Fw mem dump request
14083* To be passed by HDD to WDA and called upon receiving of response
14084* from firmware
14085* @fwMemDumpReqContext : memory dump request context
14086* @dump_rsp : dump response from HAL
14087* Returns none
14088*/
14089void wlan_hdd_fw_mem_dump_cb(void *fwMemDumpReqContext,
14090 tAniFwrDumpRsp *dump_rsp)
14091{
c_manjeef1495642015-10-13 18:35:01 +053014092 struct hdd_fw_mem_dump_req_ctx *pHddFwMemDumpCtx = (struct hdd_fw_mem_dump_req_ctx *)fwMemDumpReqContext;
c_manjeecfd1efb2015-09-25 19:32:34 +053014093
c_manjeef1495642015-10-13 18:35:01 +053014094 ENTER();
14095 spin_lock(&hdd_context_lock);
14096 if(!pHddFwMemDumpCtx || (FW_MEM_DUMP_MAGIC != pHddFwMemDumpCtx->magic)) {
14097 spin_unlock(&hdd_context_lock);
14098 return;
14099 }
14100 /* report the status to requesting function and free mem.*/
c_manjeecfd1efb2015-09-25 19:32:34 +053014101 if (dump_rsp->dump_status != eHAL_STATUS_SUCCESS) {
c_manjeef1495642015-10-13 18:35:01 +053014102 hddLog(LOGE, FL("fw dump request declined by fwr"));
14103 //set the request completion variable
14104 complete(&(pHddFwMemDumpCtx->req_completion));
c_manjeecfd1efb2015-09-25 19:32:34 +053014105 //Free the allocated fwr dump
14106 wlan_free_fwr_mem_dump_buffer();
14107 wlan_set_fwr_mem_dump_state(FW_MEM_DUMP_IDLE);
c_manjeecfd1efb2015-09-25 19:32:34 +053014108 }
c_manjeef1495642015-10-13 18:35:01 +053014109 else {
14110 hddLog(LOG1, FL("fw dump request accepted by fwr"));
14111 /* register the HDD callback which will be called by SVC */
14112 wlan_set_svc_fw_mem_dump_req_cb((void*)wlan_hdd_fw_mem_dump_req_cb,(void*)pHddFwMemDumpCtx);
14113 }
14114 spin_unlock(&hdd_context_lock);
c_manjeecfd1efb2015-09-25 19:32:34 +053014115 EXIT();
14116
14117}
14118
14119/**
14120 * memdump_procfs_remove() - Remove file/dir under procfs for memory dump
14121 *
14122 * This function removes file/dir under proc file system that was
14123 * processing firmware memory dump
14124 *
14125 * Return: None
14126 */
14127static void memdump_procfs_remove(void)
14128{
14129 remove_proc_entry(PROCFS_MEMDUMP_NAME, proc_dir);
14130 hddLog(LOG1 , FL("/proc/%s/%s removed\n"),
14131 PROCFS_MEMDUMP_DIR, PROCFS_MEMDUMP_NAME);
14132 remove_proc_entry(PROCFS_MEMDUMP_DIR, NULL);
14133 hddLog(LOG1 , FL("/proc/%s removed\n"), PROCFS_MEMDUMP_DIR);
14134}
14135
14136/**
14137 * memdump_procfs_init() - Initialize procfs for memory dump
14138 *
14139 * @vos_ctx - Global vos context.
14140 *
14141 * This function create file under proc file system to be used later for
14142 * processing firmware memory dump
14143 *
14144 * Return: 0 on success, error code otherwise.
14145 */
14146static int memdump_procfs_init(void *vos_ctx)
14147{
14148 hdd_context_t *hdd_ctx;
14149
14150 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
14151 if (!hdd_ctx) {
14152 hddLog(LOGE , FL("Invalid HDD context"));
14153 return -EINVAL;
14154 }
14155
14156 proc_dir = proc_mkdir(PROCFS_MEMDUMP_DIR, NULL);
14157 if (proc_dir == NULL) {
14158 remove_proc_entry(PROCFS_MEMDUMP_DIR, NULL);
14159 hddLog(LOGE , FL("Error: Could not initialize /proc/%s"),
14160 PROCFS_MEMDUMP_DIR);
14161 return -ENOMEM;
14162 }
14163
14164 proc_file = proc_create_data(PROCFS_MEMDUMP_NAME,
14165 S_IRUSR | S_IWUSR, proc_dir,
14166 &memdump_fops, hdd_ctx);
14167 if (proc_file == NULL) {
14168 remove_proc_entry(PROCFS_MEMDUMP_NAME, proc_dir);
14169 hddLog(LOGE , FL("Error: Could not initialize /proc/%s"),
14170 PROCFS_MEMDUMP_NAME);
14171 return -ENOMEM;
14172 }
14173
14174 hddLog(LOG1 , FL("/proc/%s/%s created"),
14175 PROCFS_MEMDUMP_DIR, PROCFS_MEMDUMP_NAME);
14176
14177 return 0;
14178}
14179
14180/**
14181 * memdump_init() - Initialization function for memory dump feature
14182 *
14183 * This function creates proc file for memdump feature and registers
14184 * HDD callback function with SME.
14185 *
14186 * Return - 0 on success, error otherwise
14187 */
14188int memdump_init(void)
14189{
14190 hdd_context_t *hdd_ctx;
14191 void *vos_ctx;
14192 int status = 0;
14193
14194 vos_ctx = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
14195 if (!vos_ctx) {
14196 hddLog(LOGE, FL("Invalid VOS context"));
14197 return -EINVAL;
14198 }
14199
14200 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
14201 if (!hdd_ctx) {
14202 hddLog(LOGE , FL("Invalid HDD context"));
14203 return -EINVAL;
14204 }
14205
14206 status = memdump_procfs_init(vos_ctx);
14207 if (status) {
14208 hddLog(LOGE , FL("Failed to create proc file"));
14209 return status;
14210 }
14211
14212 return 0;
14213}
14214
14215/**
14216 * memdump_deinit() - De initialize memdump feature
14217 *
14218 * This function removes proc file created for memdump feature.
14219 *
14220 * Return: None
14221 */
14222int memdump_deinit(void)
14223{
14224 hdd_context_t *hdd_ctx;
14225 void *vos_ctx;
14226
14227 vos_ctx = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
14228 if (!vos_ctx) {
14229 hddLog(LOGE, FL("Invalid VOS context"));
14230 return -EINVAL;
14231 }
14232
14233 hdd_ctx = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx);
14234 if(!hdd_ctx) {
14235 hddLog(LOGE , FL("Invalid HDD context"));
14236 return -EINVAL;
14237 }
14238
14239 memdump_procfs_remove();
14240 return 0;
14241}
14242
14243/**
14244 * wlan_hdd_fw_mem_dump_req(pHddCtx) - common API(cfg80211/ioctl) for requesting fw mem dump to SME
14245 * Return: HAL status
14246 */
14247
14248int wlan_hdd_fw_mem_dump_req(hdd_context_t * pHddCtx)
14249{
14250 tAniFwrDumpReq fw_mem_dump_req={0};
c_manjeef1495642015-10-13 18:35:01 +053014251 struct hdd_fw_mem_dump_req_ctx fw_mem_dump_ctx;
c_manjeecfd1efb2015-09-25 19:32:34 +053014252 eHalStatus status = eHAL_STATUS_FAILURE;
Abhishek Singh4eca9822015-12-09 18:07:34 +053014253 int ret=0, result;
c_manjeecfd1efb2015-09-25 19:32:34 +053014254 ENTER();
c_manjeef1495642015-10-13 18:35:01 +053014255
c_manjeecfd1efb2015-09-25 19:32:34 +053014256 /*Check whether a dump request is already going on
14257 *Caution this function will free previously held memory if new dump request is allowed*/
14258 if (!wlan_fwr_mem_dump_test_and_set_write_allowed_bit()) {
14259 hddLog(LOGE, FL("Fw memdump already in progress"));
14260 return -EBUSY;
14261 }
14262 //Allocate memory for fw mem dump buffer
14263 ret = wlan_fwr_mem_dump_buffer_allocation();
14264 if(ret == -EFAULT)
14265 {
14266 hddLog(LOGE, FL("Fwr mem dump not supported by FW"));
14267 return ret;
14268 }
14269 if (0 != ret) {
14270 hddLog(LOGE, FL("Fwr mem Allocation failed"));
14271 return -ENOMEM;
14272 }
c_manjeef1495642015-10-13 18:35:01 +053014273 init_completion(&fw_mem_dump_ctx.req_completion);
14274 fw_mem_dump_ctx.magic = FW_MEM_DUMP_MAGIC;
14275 fw_mem_dump_ctx.status = false;
14276
c_manjeecfd1efb2015-09-25 19:32:34 +053014277 fw_mem_dump_req.fwMemDumpReqCallback = wlan_hdd_fw_mem_dump_cb;
c_manjeef1495642015-10-13 18:35:01 +053014278 fw_mem_dump_req.fwMemDumpReqContext = &fw_mem_dump_ctx;
c_manjeecfd1efb2015-09-25 19:32:34 +053014279 status = sme_FwMemDumpReq(pHddCtx->hHal, &fw_mem_dump_req);
14280 if(eHAL_STATUS_SUCCESS != status)
14281 {
14282 hddLog(VOS_TRACE_LEVEL_ERROR,
14283 "%s: fw_mem_dump_req failed ", __func__);
14284 wlan_free_fwr_mem_dump_buffer();
c_manjeef1495642015-10-13 18:35:01 +053014285 ret = -EFAULT;
14286 goto cleanup;
c_manjeecfd1efb2015-09-25 19:32:34 +053014287 }
c_manjeef1495642015-10-13 18:35:01 +053014288 /*wait for fw mem dump completion to send event to userspace*/
Abhishek Singh4eca9822015-12-09 18:07:34 +053014289 result =
14290 wait_for_completion_timeout(&fw_mem_dump_ctx.req_completion,
14291 msecs_to_jiffies(FW_MEM_DUMP_TIMEOUT_MS));
14292 if (0 >= result )
c_manjeef1495642015-10-13 18:35:01 +053014293 {
14294 hddLog(VOS_TRACE_LEVEL_ERROR,
Abhishek Singh4eca9822015-12-09 18:07:34 +053014295 "%s: fw_mem_dump_req timeout %d ", __func__,result);
14296 ret = -ETIMEDOUT;
c_manjeef1495642015-10-13 18:35:01 +053014297 }
14298cleanup:
14299 spin_lock(&hdd_context_lock);
14300 fw_mem_dump_ctx.magic = 0;
Abhishek Singh4eca9822015-12-09 18:07:34 +053014301 if(!ret && !fw_mem_dump_ctx.status)
14302 ret = -EFAULT;
c_manjeef1495642015-10-13 18:35:01 +053014303 spin_unlock(&hdd_context_lock);
c_manjeecfd1efb2015-09-25 19:32:34 +053014304
c_manjeef1495642015-10-13 18:35:01 +053014305 EXIT();
Abhishek Singh4eca9822015-12-09 18:07:34 +053014306 return ret;
c_manjeef1495642015-10-13 18:35:01 +053014307}
14308
14309/**
14310 * HDD callback which will be called by SVC to indicate mem dump completion.
14311 */
14312void wlan_hdd_fw_mem_dump_req_cb(struct hdd_fw_mem_dump_req_ctx* pHddFwMemDumpCtx)
14313{
14314 if (!pHddFwMemDumpCtx) {
14315 hddLog(VOS_TRACE_LEVEL_ERROR,
14316 "%s: HDD context not valid ", __func__);
14317 return;
14318 }
14319 spin_lock(&hdd_context_lock);
14320 /* check the req magic and set status */
14321 if (pHddFwMemDumpCtx->magic == FW_MEM_DUMP_MAGIC)
14322 {
14323 pHddFwMemDumpCtx->status = true;
14324 //signal the completion
14325 complete(&(pHddFwMemDumpCtx->req_completion));
14326 }
14327 else
14328 {
14329 hddLog(VOS_TRACE_LEVEL_ERROR,
14330 "%s: fw mem dump request possible timeout ", __func__);
14331 }
14332 spin_unlock(&hdd_context_lock);
c_manjeecfd1efb2015-09-25 19:32:34 +053014333}
14334
Mahesh A Saptasagar67ab9222015-10-21 15:38:41 +053014335void hdd_initialize_adapter_common(hdd_adapter_t *pAdapter)
14336{
14337 if (NULL == pAdapter)
14338 {
14339 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL ", __func__);
14340 return;
14341 }
14342 init_completion(&pAdapter->session_open_comp_var);
14343 init_completion(&pAdapter->session_close_comp_var);
14344 init_completion(&pAdapter->disconnect_comp_var);
14345 init_completion(&pAdapter->linkup_event_var);
14346 init_completion(&pAdapter->cancel_rem_on_chan_var);
14347 init_completion(&pAdapter->rem_on_chan_ready_event);
14348 init_completion(&pAdapter->pno_comp_var);
14349#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
14350 init_completion(&pAdapter->offchannel_tx_event);
14351#endif
14352 init_completion(&pAdapter->tx_action_cnf_event);
14353#ifdef FEATURE_WLAN_TDLS
14354 init_completion(&pAdapter->tdls_add_station_comp);
14355 init_completion(&pAdapter->tdls_del_station_comp);
14356 init_completion(&pAdapter->tdls_mgmt_comp);
14357 init_completion(&pAdapter->tdls_link_establish_req_comp);
14358#endif
14359
14360#ifdef WLAN_FEATURE_RMC
14361 init_completion(&pAdapter->ibss_peer_info_comp);
14362#endif /* WLAN_FEATURE_RMC */
14363 init_completion(&pAdapter->ula_complete);
14364 init_completion(&pAdapter->change_country_code);
14365
14366#ifdef FEATURE_WLAN_BATCH_SCAN
14367 init_completion(&pAdapter->hdd_set_batch_scan_req_var);
14368 init_completion(&pAdapter->hdd_get_batch_scan_req_var);
14369#endif
14370
14371 return;
14372}
c_manjeecfd1efb2015-09-25 19:32:34 +053014373
14374
Jeff Johnson295189b2012-06-20 16:38:30 -070014375//Register the module init/exit functions
14376module_init(hdd_module_init);
14377module_exit(hdd_module_exit);
14378
14379MODULE_LICENSE("Dual BSD/GPL");
14380MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14381MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14382
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070014383module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
14384 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Jeff Johnson32d95a32012-09-10 13:15:23 -070014385
Jeff Johnson76052702013-04-16 13:55:05 -070014386module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
Jeff Johnson32d95a32012-09-10 13:15:23 -070014387 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Arif Hussain66559122013-11-21 10:11:40 -080014388
14389module_param(enable_dfs_chan_scan, int,
14390 S_IRUSR | S_IRGRP | S_IROTH);
14391
14392module_param(enable_11d, int,
14393 S_IRUSR | S_IRGRP | S_IROTH);
14394
14395module_param(country_code, charp,
14396 S_IRUSR | S_IRGRP | S_IROTH);