blob: 13b783ae493857b94babcca91ccb123fbf04f700 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lam842dad02014-02-18 18:44:02 -08002 * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
3 *
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
37 Copyright 2008 (c) Qualcomm, Incorporated. All Rights Reserved.
38
39 Qualcomm Confidential and Proprietary.
40
41 ========================================================================*/
42
43/**=========================================================================
44
45 EDIT HISTORY FOR FILE
46
47
48 This section contains comments describing changes made to the module.
49 Notice that changes are listed in reverse chronological order.
50
51
52 $Header:$ $DateTime: $ $Author: $
53
54
55 when who what, where, why
56 -------- --- --------------------------------------------------------
57 04/5/09 Shailender Created module.
58 02/24/10 Sudhir.S.Kohalli Added to support param for SoftAP module
59 06/03/10 js - Added support to hostapd driven deauth/disassoc/mic failure
60 ==========================================================================*/
61
62/*--------------------------------------------------------------------------
63 Include Files
64 ------------------------------------------------------------------------*/
65//#include <wlan_qct_driver.h>
66#include <wlan_hdd_includes.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070067#include <vos_api.h>
68#include <vos_sched.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070069#include <linux/etherdevice.h>
70#include <linux/firmware.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070071#ifdef ANI_BUS_TYPE_PLATFORM
72#include <linux/wcnss_wlan.h>
73#endif //ANI_BUS_TYPE_PLATFORM
74#ifdef ANI_BUS_TYPE_PCI
75#include "wcnss_wlan.h"
76#endif /* ANI_BUS_TYPE_PCI */
77#include <wlan_hdd_tx_rx.h>
78#include <palTimer.h>
79#include <wniApi.h>
80#include <wlan_nlink_srv.h>
81#include <wlan_btc_svc.h>
82#include <wlan_hdd_cfg.h>
83#include <wlan_ptt_sock_svc.h>
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053084#include <wlan_logging_sock_svc.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070085#include <wlan_hdd_wowl.h>
86#include <wlan_hdd_misc.h>
87#include <wlan_hdd_wext.h>
88#ifdef WLAN_BTAMP_FEATURE
89#include <bap_hdd_main.h>
90#include <bapInternal.h>
91#endif // WLAN_BTAMP_FEATURE
Sushant Kaushik4b7cb302014-01-06 17:45:01 +053092#include "wlan_hdd_trace.h"
93#include "vos_types.h"
94#include "vos_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070095#include <linux/wireless.h>
96#include <net/cfg80211.h>
Vinay Krishna Erannad9cbdb32014-01-16 12:59:10 +053097#include <linux/inetdevice.h>
98#include <net/addrconf.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070099#include "wlan_hdd_cfg80211.h"
100#include "wlan_hdd_p2p.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700101#include <linux/rtnetlink.h>
Jeff Johnson295189b2012-06-20 16:38:30 -0700102int wlan_hdd_ftm_start(hdd_context_t *pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -0700103#include "sapApi.h"
104#include <linux/semaphore.h>
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -0700105#include <linux/ctype.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530106#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
107#include <soc/qcom/subsystem_restart.h>
108#else
Jeff Johnson295189b2012-06-20 16:38:30 -0700109#include <mach/subsystem_restart.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +0530110#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700111#include <wlan_hdd_hostapd.h>
112#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson295189b2012-06-20 16:38:30 -0700113#include "cfgApi.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700114#include "wlan_hdd_dev_pwr.h"
115#ifdef WLAN_BTAMP_FEATURE
116#include "bap_hdd_misc.h"
117#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700118#include "wlan_qct_pal_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700119#include "qwlan_version.h"
Yathish9f22e662012-12-10 14:21:35 -0800120#include "wlan_qct_wda.h"
Chilam NG571c65a2013-01-19 12:27:36 +0530121#ifdef FEATURE_WLAN_TDLS
122#include "wlan_hdd_tdls.h"
123#endif
Yue Ma0d4891e2013-08-06 17:01:45 -0700124#include "wlan_hdd_debugfs.h"
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +0530125#include "sapInternal.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700126
127#ifdef MODULE
128#define WLAN_MODULE_NAME module_name(THIS_MODULE)
129#else
130#define WLAN_MODULE_NAME "wlan"
131#endif
132
133#ifdef TIMER_MANAGER
134#define TIMER_MANAGER_STR " +TIMER_MANAGER"
135#else
136#define TIMER_MANAGER_STR ""
137#endif
138
139#ifdef MEMORY_DEBUG
140#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
141#else
142#define MEMORY_DEBUG_STR ""
143#endif
Kaushik, Sushant7005e372014-04-08 11:36:54 +0530144#define MAX_WAIT_FOR_ROC_COMPLETION 3
Jeff Johnson295189b2012-06-20 16:38:30 -0700145/* the Android framework expects this param even though we don't use it */
146#define BUF_LEN 20
Jeff Johnson76052702013-04-16 13:55:05 -0700147static char fwpath_buffer[BUF_LEN];
148static struct kparam_string fwpath = {
149 .string = fwpath_buffer,
150 .maxlen = BUF_LEN,
151};
Arif Hussain66559122013-11-21 10:11:40 -0800152
153static char *country_code;
154static int enable_11d = -1;
155static int enable_dfs_chan_scan = -1;
c_hpothu92367912014-05-01 15:18:17 +0530156static int gbcnMissRate = -1;
Arif Hussain66559122013-11-21 10:11:40 -0800157
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700158#ifndef MODULE
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700159static int wlan_hdd_inited;
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700160#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700161
Jeff Johnsone7245742012-09-05 17:12:55 -0700162/*
Jeff Johnson72a40512013-12-19 10:14:15 -0800163 * spinlock for synchronizing asynchronous request/response
164 * (full description of use in wlan_hdd_main.h)
165 */
166DEFINE_SPINLOCK(hdd_context_lock);
167
168/*
Jeff Johnsone7245742012-09-05 17:12:55 -0700169 * The rate at which the driver sends RESTART event to supplicant
170 * once the function 'vos_wlanRestart()' is called
171 *
172 */
173#define WLAN_HDD_RESTART_RETRY_DELAY_MS 5000 /* 5 second */
174#define WLAN_HDD_RESTART_RETRY_MAX_CNT 5 /* 5 retries */
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -0700175
176/*
177 * Size of Driver command strings from upper layer
178 */
179#define SIZE_OF_SETROAMMODE 11 /* size of SETROAMMODE */
180#define SIZE_OF_GETROAMMODE 11 /* size of GETROAMMODE */
181
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800182#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700183#define TID_MIN_VALUE 0
184#define TID_MAX_VALUE 15
185static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
186 tAniTrafStrmMetrics* pTsmMetrics);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800187static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
188 tCsrEseBeaconReq *pEseBcnReq);
189#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700190
Atul Mittal1d722422014-03-19 11:15:07 +0530191/*
192 * Maximum buffer size used for returning the data back to user space
193 */
194#define WLAN_MAX_BUF_SIZE 1024
195#define WLAN_PRIV_DATA_MAX_LEN 8192
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -0700196
c_hpothu92367912014-05-01 15:18:17 +0530197//wait time for beacon miss rate.
198#define BCN_MISS_RATE_TIME 500
199
Sameer Thalappil50dc0092013-02-19 17:23:33 -0800200#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -0700201static struct wake_lock wlan_wake_lock;
Jeff Johnsone7245742012-09-05 17:12:55 -0700202#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700203/* set when SSR is needed after unload */
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -0700204static e_hdd_ssr_required isSsrRequired = HDD_SSR_NOT_REQUIRED;
Jeff Johnson295189b2012-06-20 16:38:30 -0700205
206//internal function declaration
Jeff Johnsone7245742012-09-05 17:12:55 -0700207static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx);
208static void wlan_hdd_restart_init(hdd_context_t *pHddCtx);
209static void wlan_hdd_restart_deinit(hdd_context_t *pHddCtx);
210void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback);
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800211void hdd_set_wlan_suspend_mode(bool suspend);
Jeff Johnsone7245742012-09-05 17:12:55 -0700212
Jeff Johnson295189b2012-06-20 16:38:30 -0700213v_U16_t hdd_select_queue(struct net_device *dev,
214 struct sk_buff *skb);
215
216#ifdef WLAN_FEATURE_PACKET_FILTERING
217static void hdd_set_multicast_list(struct net_device *dev);
218#endif
219
220void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter);
221
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800222#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -0800223void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand);
224static VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels);
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700225static VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid,
226 tANI_U8 *pChannel, tANI_U8 *pDwellTime,
227 tANI_U8 **pBuf, tANI_U8 *pBufLen);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -0700228static VOS_STATUS hdd_parse_reassoc_command_data(tANI_U8 *pValue,
229 tANI_U8 *pTargetApBssid,
230 tANI_U8 *pChannel);
Srinivas Girigowdade697412013-02-14 16:31:48 -0800231#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800232#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700233VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe, tANI_U8 *pCckmIeLen);
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800234#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -0700235
Mihir Shetee1093ba2014-01-21 20:13:32 +0530236static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx);
Sushant Kaushik8bc7df22014-04-09 17:55:29 +0530237const char * hdd_device_modetoString(v_U8_t device_mode)
238{
239 switch(device_mode)
240 {
241 CASE_RETURN_STRING( WLAN_HDD_INFRA_STATION );
242 CASE_RETURN_STRING( WLAN_HDD_SOFTAP );
243 CASE_RETURN_STRING( WLAN_HDD_P2P_CLIENT );
244 CASE_RETURN_STRING( WLAN_HDD_P2P_GO );
245 CASE_RETURN_STRING( WLAN_HDD_MONITOR);
246 CASE_RETURN_STRING( WLAN_HDD_FTM );
247 CASE_RETURN_STRING( WLAN_HDD_IBSS );
248 CASE_RETURN_STRING( WLAN_HDD_P2P_DEVICE );
249 default:
250 return "device_mode Unknown";
251 }
252}
Mihir Shetee1093ba2014-01-21 20:13:32 +0530253
Jeff Johnson295189b2012-06-20 16:38:30 -0700254static int hdd_netdev_notifier_call(struct notifier_block * nb,
255 unsigned long state,
256 void *ndev)
257{
258 struct net_device *dev = ndev;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700259 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson27cee452013-03-27 11:10:24 -0700260 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -0700261#ifdef WLAN_BTAMP_FEATURE
262 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -0700263#endif
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530264 long result;
Jeff Johnson295189b2012-06-20 16:38:30 -0700265
266 //Make sure that this callback corresponds to our device.
Jeff Johnson27cee452013-03-27 11:10:24 -0700267 if ((strncmp(dev->name, "wlan", 4)) &&
Amar Singhal4c723bd2013-03-25 18:14:15 -0700268 (strncmp(dev->name, "p2p", 3)))
269 return NOTIFY_DONE;
270
Jeff Johnson295189b2012-06-20 16:38:30 -0700271 if (!dev->ieee80211_ptr)
Jeff Johnson27cee452013-03-27 11:10:24 -0700272 return NOTIFY_DONE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700273
Jeff Johnson27cee452013-03-27 11:10:24 -0700274 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700275 {
Jeff Johnsona8a1a482012-12-12 16:49:33 -0800276 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Adapter Null Pointer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700277 VOS_ASSERT(0);
278 return NOTIFY_DONE;
279 }
280
Jeff Johnson27cee452013-03-27 11:10:24 -0700281 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
282 if (NULL == pHddCtx)
283 {
284 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Context Null Pointer", __func__);
285 VOS_ASSERT(0);
286 return NOTIFY_DONE;
287 }
Sameer Thalappil14067972014-01-23 14:54:54 -0800288 if (pHddCtx->isLogpInProgress)
289 return NOTIFY_DONE;
290
Jeff Johnson27cee452013-03-27 11:10:24 -0700291
292 hddLog(VOS_TRACE_LEVEL_INFO, "%s: %s New Net Device State = %lu",
293 __func__, dev->name, state);
Jeff Johnson295189b2012-06-20 16:38:30 -0700294
295 switch (state) {
296 case NETDEV_REGISTER:
297 break;
298
299 case NETDEV_UNREGISTER:
300 break;
301
302 case NETDEV_UP:
303 break;
304
305 case NETDEV_DOWN:
306 break;
307
308 case NETDEV_CHANGE:
Jeff Johnsone7245742012-09-05 17:12:55 -0700309 if(TRUE == pAdapter->isLinkUpSvcNeeded)
310 complete(&pAdapter->linkup_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700311 break;
312
313 case NETDEV_GOING_DOWN:
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530314 result = wlan_hdd_scan_abort(pAdapter);
Girish Gowli4bf7a632014-06-12 13:42:11 +0530315 if (result < 0)
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530316 {
317 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
318 "%s: Timeout occurred while waiting for abortscan %ld",
319 __func__, result);
Jeff Johnson295189b2012-06-20 16:38:30 -0700320 }
321 else
322 {
323 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +0530324 "%s: Scan Abort Successful" , __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700325 }
326#ifdef WLAN_BTAMP_FEATURE
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700327 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s: disabling AMP", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700328 status = WLANBAP_StopAmp();
329 if(VOS_STATUS_SUCCESS != status )
330 {
331 pHddCtx->isAmpAllowed = VOS_TRUE;
332 hddLog(VOS_TRACE_LEVEL_FATAL,
333 "%s: Failed to stop AMP", __func__);
334 }
335 else
336 {
337 //a state m/c implementation in PAL is TBD to avoid this delay
338 msleep(500);
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700339 if ( pHddCtx->isAmpAllowed )
340 {
341 WLANBAP_DeregisterFromHCI();
342 pHddCtx->isAmpAllowed = VOS_FALSE;
343 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700344 }
345#endif //WLAN_BTAMP_FEATURE
346 break;
347
348 default:
349 break;
350 }
351
352 return NOTIFY_DONE;
353}
354
355struct notifier_block hdd_netdev_notifier = {
356 .notifier_call = hdd_netdev_notifier_call,
357};
358
359/*---------------------------------------------------------------------------
360 * Function definitions
361 *-------------------------------------------------------------------------*/
Jeff Johnson295189b2012-06-20 16:38:30 -0700362void hdd_unregister_mcast_bcast_filter(hdd_context_t *pHddCtx);
363void hdd_register_mcast_bcast_filter(hdd_context_t *pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -0700364//variable to hold the insmod parameters
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700365static int con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -0700366#ifndef MODULE
367/* current con_mode - used only for statically linked driver
368 * con_mode is changed by userspace to indicate a mode change which will
369 * result in calling the module exit and init functions. The module
370 * exit function will clean up based on the value of con_mode prior to it
371 * being changed by userspace. So curr_con_mode records the current con_mode
372 * for exit when con_mode becomes the next mode for init
373 */
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700374static int curr_con_mode;
Jeff Johnson295189b2012-06-20 16:38:30 -0700375#endif
376
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -0800377/**---------------------------------------------------------------------------
378
379 \brief hdd_vos_trace_enable() - Configure initial VOS Trace enable
380
381 Called immediately after the cfg.ini is read in order to configure
382 the desired trace levels.
383
384 \param - moduleId - module whose trace level is being configured
385 \param - bitmask - bitmask of log levels to be enabled
386
387 \return - void
388
389 --------------------------------------------------------------------------*/
390static void hdd_vos_trace_enable(VOS_MODULE_ID moduleId, v_U32_t bitmask)
391{
392 wpt_tracelevel level;
393
394 /* if the bitmask is the default value, then a bitmask was not
395 specified in cfg.ini, so leave the logging level alone (it
396 will remain at the "compiled in" default value) */
397 if (CFG_VOS_TRACE_ENABLE_DEFAULT == bitmask)
398 {
399 return;
400 }
401
402 /* a mask was specified. start by disabling all logging */
403 vos_trace_setValue(moduleId, VOS_TRACE_LEVEL_NONE, 0);
404
405 /* now cycle through the bitmask until all "set" bits are serviced */
406 level = VOS_TRACE_LEVEL_FATAL;
407 while (0 != bitmask)
408 {
409 if (bitmask & 1)
410 {
411 vos_trace_setValue(moduleId, level, 1);
412 }
413 level++;
414 bitmask >>= 1;
415 }
416}
417
418
Jeff Johnson295189b2012-06-20 16:38:30 -0700419/**---------------------------------------------------------------------------
420
421 \brief hdd_wdi_trace_enable() - Configure initial WDI Trace enable
422
423 Called immediately after the cfg.ini is read in order to configure
424 the desired trace levels in the WDI.
425
426 \param - moduleId - module whose trace level is being configured
427 \param - bitmask - bitmask of log levels to be enabled
428
429 \return - void
430
431 --------------------------------------------------------------------------*/
432static void hdd_wdi_trace_enable(wpt_moduleid moduleId, v_U32_t bitmask)
433{
434 wpt_tracelevel level;
435
436 /* if the bitmask is the default value, then a bitmask was not
437 specified in cfg.ini, so leave the logging level alone (it
438 will remain at the "compiled in" default value) */
439 if (CFG_WDI_TRACE_ENABLE_DEFAULT == bitmask)
440 {
441 return;
442 }
443
444 /* a mask was specified. start by disabling all logging */
445 wpalTraceSetLevel(moduleId, eWLAN_PAL_TRACE_LEVEL_NONE, 0);
446
447 /* now cycle through the bitmask until all "set" bits are serviced */
448 level = eWLAN_PAL_TRACE_LEVEL_FATAL;
449 while (0 != bitmask)
450 {
451 if (bitmask & 1)
452 {
453 wpalTraceSetLevel(moduleId, level, 1);
454 }
455 level++;
456 bitmask >>= 1;
457 }
458}
Jeff Johnson295189b2012-06-20 16:38:30 -0700459
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530460/*
461 * FUNCTION: wlan_hdd_validate_context
462 * This function is used to check the HDD context
463 */
464int wlan_hdd_validate_context(hdd_context_t *pHddCtx)
465{
466 ENTER();
467
468 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
469 {
470 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
471 "%s: HDD context is Null", __func__);
472 return -ENODEV;
473 }
474
475 if (pHddCtx->isLogpInProgress)
476 {
477 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
478 "%s: LOGP in Progress. Ignore!!!", __func__);
479 return -EAGAIN;
480 }
481
Mihir Shete18156292014-03-11 15:38:30 +0530482 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530483 {
484 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
485 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
486 return -EAGAIN;
487 }
488 return 0;
489}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700490#ifdef CONFIG_ENABLE_LINUX_REG
491void hdd_checkandupdate_phymode( hdd_context_t *pHddCtx)
492{
493 hdd_adapter_t *pAdapter = NULL;
494 hdd_station_ctx_t *pHddStaCtx = NULL;
495 eCsrPhyMode phyMode;
496 hdd_config_t *cfg_param = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +0530497
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700498 if (NULL == pHddCtx)
499 {
500 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
501 "HDD Context is null !!");
502 return ;
503 }
504
505 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
506 if (NULL == pAdapter)
507 {
508 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
509 "pAdapter is null !!");
510 return ;
511 }
512
513 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
514 if (NULL == pHddStaCtx)
515 {
516 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
517 "pHddStaCtx is null !!");
518 return ;
519 }
520
521 cfg_param = pHddCtx->cfg_ini;
522 if (NULL == cfg_param)
523 {
524 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
525 "cfg_params not available !!");
526 return ;
527 }
528
529 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
530
531 if (!pHddCtx->isVHT80Allowed)
532 {
533 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
534 (eCSR_DOT11_MODE_11ac == phyMode) ||
535 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
536 {
537 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
538 "Setting phymode to 11n!!");
539 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
540 }
541 }
542 else
543 {
544 /*New country Supports 11ac as well resetting value back from .ini*/
545 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
546 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
547 return ;
548 }
549
550 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
551 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
552 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
553 {
554 VOS_STATUS vosStatus;
555
556 // need to issue a disconnect to CSR.
557 INIT_COMPLETION(pAdapter->disconnect_comp_var);
558 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
559 pAdapter->sessionId,
560 eCSR_DISCONNECT_REASON_UNSPECIFIED );
561
562 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530563 {
564 long ret;
565
566 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700567 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530568 if (0 >= ret)
569 hddLog(LOGE, FL("failure waiting for disconnect_comp_var %ld"),
570 ret);
571 }
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700572
573 }
574}
575#else
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530576void hdd_checkandupdate_phymode( hdd_adapter_t *pAdapter, char *country_code)
577{
578 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
579 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
580 hdd_config_t *cfg_param;
581 eCsrPhyMode phyMode;
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530582 long ret;
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530583
584 if (NULL == pHddCtx)
585 {
586 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
587 "HDD Context is null !!");
588 return ;
589 }
590
591 cfg_param = pHddCtx->cfg_ini;
592
593 if (NULL == cfg_param)
594 {
595 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
596 "cfg_params not available !!");
597 return ;
598 }
599
600 phyMode = sme_GetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter));
601
602 if (NULL != strstr(cfg_param->listOfNon11acCountryCode, country_code))
603 {
604 if ((eCSR_DOT11_MODE_AUTO == phyMode) ||
605 (eCSR_DOT11_MODE_11ac == phyMode) ||
606 (eCSR_DOT11_MODE_11ac_ONLY == phyMode))
607 {
608 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
609 "Setting phymode to 11n!!");
610 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_DOT11_MODE_11n);
611 }
612 }
613 else
614 {
615 /*New country Supports 11ac as well resetting value back from .ini*/
616 sme_SetPhyMode(WLAN_HDD_GET_HAL_CTX(pAdapter),
617 hdd_cfg_xlate_to_csr_phy_mode(cfg_param->dot11Mode));
618 return ;
619 }
620
621 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
622 ((eCSR_CFG_DOT11_MODE_11AC_ONLY == pHddStaCtx->conn_info.dot11Mode) ||
623 (eCSR_CFG_DOT11_MODE_11AC == pHddStaCtx->conn_info.dot11Mode)))
624 {
625 VOS_STATUS vosStatus;
626
627 // need to issue a disconnect to CSR.
628 INIT_COMPLETION(pAdapter->disconnect_comp_var);
629 vosStatus = sme_RoamDisconnect(WLAN_HDD_GET_HAL_CTX(pAdapter),
630 pAdapter->sessionId,
631 eCSR_DISCONNECT_REASON_UNSPECIFIED );
632
633 if (VOS_STATUS_SUCCESS == vosStatus)
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530634 {
635 ret = wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530636 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +0530637 if (ret <= 0)
638 {
639 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
640 "wait on disconnect_comp_var is failed %ld", ret);
641 }
642 }
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530643
644 }
645}
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -0700646#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +0530647
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700648void hdd_checkandupdate_dfssetting( hdd_adapter_t *pAdapter, char *country_code)
649{
650 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
651 hdd_config_t *cfg_param;
652
653 if (NULL == pHddCtx)
654 {
655 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
656 "HDD Context is null !!");
657 return ;
658 }
659
660 cfg_param = pHddCtx->cfg_ini;
661
662 if (NULL == cfg_param)
663 {
664 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
665 "cfg_params not available !!");
666 return ;
667 }
668
Agarwal Ashish738843c2014-09-25 12:27:56 +0530669 if (NULL != strstr(cfg_param->listOfNonDfsCountryCode, country_code) ||
670 pHddCtx->disable_dfs_flag == TRUE)
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -0700671 {
672 /*New country doesn't support DFS */
673 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
674 }
675 else
676 {
677 /*New country Supports DFS as well resetting value back from .ini*/
678 sme_UpdateDfsSetting(WLAN_HDD_GET_HAL_CTX(pAdapter), cfg_param->enableDFSChnlScan);
679 }
680
681}
682
Rajeev79dbe4c2013-10-05 11:03:42 +0530683#ifdef FEATURE_WLAN_BATCH_SCAN
684
685/**---------------------------------------------------------------------------
686
687 \brief hdd_extract_assigned_int_from_str() - Extracts assigned integer from
688 input string
689
690 This function extracts assigned integer from string in below format:
691 "STRING=10" : extracts integer 10 from this string
692
693 \param - pInPtr Pointer to input string
694 \param - base Base for string to int conversion(10 for decimal 16 for hex)
695 \param - pOutPtr Pointer to variable in which extracted integer needs to be
696 assigned
697 \param - pLastArg to tell whether it is last arguement in input string or
698 not
699
700 \return - NULL for failure cases
701 pointer to next arguement in input string for success cases
702 --------------------------------------------------------------------------*/
703static tANI_U8 *
704hdd_extract_assigned_int_from_str
705(
706 tANI_U8 *pInPtr,
707 tANI_U8 base,
708 tANI_U32 *pOutPtr,
709 tANI_U8 *pLastArg
710)
711{
712 int tempInt;
713 int v = 0;
714 char buf[32];
715 int val = 0;
716 *pLastArg = FALSE;
717
718 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
719 if (NULL == pInPtr)
720 {
721 return NULL;
722 }
723
724 pInPtr++;
725
726 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
727
728 val = sscanf(pInPtr, "%32s ", buf);
729 if (val < 0 && val > strlen(pInPtr))
730 {
731 return NULL;
732 }
733 pInPtr += val;
734 v = kstrtos32(buf, base, &tempInt);
735 if (v < 0)
736 {
737 return NULL;
738 }
Rajeev Kumar4d93d842014-01-02 18:31:21 -0800739 if (tempInt < 0)
740 {
741 tempInt = 0;
742 }
Rajeev79dbe4c2013-10-05 11:03:42 +0530743 *pOutPtr = tempInt;
744
745 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
746 if (NULL == pInPtr)
747 {
748 *pLastArg = TRUE;
749 return NULL;
750 }
751 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
752
753 return pInPtr;
754}
755
756/**---------------------------------------------------------------------------
757
758 \brief hdd_extract_assigned_char_from_str() - Extracts assigned char from
759 input string
760
761 This function extracts assigned character from string in below format:
762 "STRING=A" : extracts char 'A' from this string
763
764 \param - pInPtr Pointer to input string
765 \param - pOutPtr Pointer to variable in which extracted char needs to be
766 assigned
767 \param - pLastArg to tell whether it is last arguement in input string or
768 not
769
770 \return - NULL for failure cases
771 pointer to next arguement in input string for success cases
772 --------------------------------------------------------------------------*/
773static tANI_U8 *
774hdd_extract_assigned_char_from_str
775(
776 tANI_U8 *pInPtr,
777 tANI_U8 *pOutPtr,
778 tANI_U8 *pLastArg
779)
780{
781 *pLastArg = FALSE;
782
783 pInPtr = strnchr(pInPtr, strlen(pInPtr), EQUALS_TO_ASCII_VALUE);
784 if (NULL == pInPtr)
785 {
786 return NULL;
787 }
788
789 pInPtr++;
790
791 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
792
793 *pOutPtr = *pInPtr;
794
795 pInPtr = strnchr(pInPtr, strlen(pInPtr), SPACE_ASCII_VALUE);
796 if (NULL == pInPtr)
797 {
798 *pLastArg = TRUE;
799 return NULL;
800 }
801 while ((SPACE_ASCII_VALUE == *pInPtr) && ('\0' != *pInPtr)) pInPtr++;
802
803 return pInPtr;
804}
805
806
807/**---------------------------------------------------------------------------
808
809 \brief hdd_parse_set_batchscan_command () - HDD parse set batch scan command
810
811 This function parses set batch scan command in below format:
812 WLS_BATCHING_SET <space> followed by below arguements
813 "SCANFREQ=XX" : Optional defaults to 30 sec
814 "MSCAN=XX" : Required number of scans to attempt to batch
815 "BESTN=XX" : Best Network (RSSI) defaults to 16
816 "CHANNEL=<X,Y>" : optional defaults to all channels, can list 'A'or` B.
817 A. implies only 5 GHz , B. implies only 2.4GHz
818 "RTT=X" : optional defaults to 0
819 returns the MIN of MSCAN or the max # of scans firmware can cache or -1 on
820 error
821
822 For example input commands:
823 1) WLS_BATCHING_SET SCANFREQ=60 MSCAN=10 BESTN=20 CHANNEL=A RTT=0 -> This is
824 translated into set batch scan with following parameters:
825 a) Frequence 60 seconds
826 b) Batch 10 scans together
827 c) Best RSSI to be 20
828 d) 5GHz band only
829 e) RTT is equal to 0
830
831 \param - pValue Pointer to input channel list
832 \param - pHddSetBatchScanReq Pointer to HDD batch scan request structure
833
834 \return - 0 for success non-zero for failure
835
836 --------------------------------------------------------------------------*/
837static int
838hdd_parse_set_batchscan_command
839(
840 tANI_U8 *pValue,
841 tSirSetBatchScanReq *pHddSetBatchScanReq
842)
843{
844 tANI_U8 *inPtr = pValue;
845 tANI_U8 val = 0;
846 tANI_U8 lastArg = 0;
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800847 tANI_U32 nScanFreq;
848 tANI_U32 nMscan;
849 tANI_U32 nBestN;
850 tANI_U8 ucRfBand;
851 tANI_U32 nRtt;
Rajeev Kumarc933d982013-11-18 20:04:20 -0800852 tANI_U32 temp;
Rajeev79dbe4c2013-10-05 11:03:42 +0530853
854 /*initialize default values*/
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800855 nScanFreq = HDD_SET_BATCH_SCAN_DEFAULT_FREQ;
856 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
857 nRtt = 0;
858 nBestN = HDD_SET_BATCH_SCAN_BEST_NETWORK;
Rajeev79dbe4c2013-10-05 11:03:42 +0530859
860 /*go to space after WLS_BATCHING_SET command*/
861 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
862 /*no argument after the command*/
863 if (NULL == inPtr)
864 {
865 return -EINVAL;
866 }
867
868 /*no space after the command*/
869 else if (SPACE_ASCII_VALUE != *inPtr)
870 {
871 return -EINVAL;
872 }
873
874 /*removing empty spaces*/
875 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
876
877 /*no argument followed by spaces*/
878 if ('\0' == *inPtr)
879 {
880 return -EINVAL;
881 }
882
883 /*check and parse SCANFREQ*/
884 if ((strncmp(inPtr, "SCANFREQ", 8) == 0))
885 {
886 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -0800887 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800888
Rajeev Kumarc933d982013-11-18 20:04:20 -0800889 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800890 {
Rajeev Kumarc933d982013-11-18 20:04:20 -0800891 nScanFreq = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800892 }
893
Rajeev79dbe4c2013-10-05 11:03:42 +0530894 if ( (NULL == inPtr) || (TRUE == lastArg))
895 {
896 return -EINVAL;
897 }
898 }
899
900 /*check and parse MSCAN*/
901 if ((strncmp(inPtr, "MSCAN", 5) == 0))
902 {
903 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800904 &nMscan, &lastArg);
905
906 if (0 == nMscan)
907 {
908 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
909 "invalid MSCAN=%d", nMscan);
910 return -EINVAL;
911 }
912
Rajeev79dbe4c2013-10-05 11:03:42 +0530913 if (TRUE == lastArg)
914 {
915 goto done;
916 }
917 else if (NULL == inPtr)
918 {
919 return -EINVAL;
920 }
921 }
922 else
923 {
924 return -EINVAL;
925 }
926
927 /*check and parse BESTN*/
928 if ((strncmp(inPtr, "BESTN", 5) == 0))
929 {
930 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumarc933d982013-11-18 20:04:20 -0800931 &temp, &lastArg);
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800932
Rajeev Kumarc933d982013-11-18 20:04:20 -0800933 if (0 != temp)
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800934 {
Rajeev Kumarc933d982013-11-18 20:04:20 -0800935 nBestN = temp;
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800936 }
937
Rajeev79dbe4c2013-10-05 11:03:42 +0530938 if (TRUE == lastArg)
939 {
940 goto done;
941 }
942 else if (NULL == inPtr)
943 {
944 return -EINVAL;
945 }
946 }
947
948 /*check and parse CHANNEL*/
949 if ((strncmp(inPtr, "CHANNEL", 7) == 0))
950 {
951 inPtr = hdd_extract_assigned_char_from_str(inPtr, &val, &lastArg);
Rajeev Kumarc933d982013-11-18 20:04:20 -0800952
Rajeev79dbe4c2013-10-05 11:03:42 +0530953 if (('A' == val) || ('a' == val))
954 {
c_hpothuebf89732014-02-25 13:00:24 +0530955 ucRfBand = HDD_SET_BATCH_SCAN_5GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +0530956 }
957 else if (('B' == val) || ('b' == val))
958 {
c_hpothuebf89732014-02-25 13:00:24 +0530959 ucRfBand = HDD_SET_BATCH_SCAN_24GHz_BAND_ONLY;
Rajeev79dbe4c2013-10-05 11:03:42 +0530960 }
961 else
962 {
Rajeev Kumarc933d982013-11-18 20:04:20 -0800963 ucRfBand = HDD_SET_BATCH_SCAN_DEFAULT_BAND;
964 }
965
966 if (TRUE == lastArg)
967 {
968 goto done;
969 }
970 else if (NULL == inPtr)
971 {
Rajeev79dbe4c2013-10-05 11:03:42 +0530972 return -EINVAL;
973 }
974 }
975
976 /*check and parse RTT*/
977 if ((strncmp(inPtr, "RTT", 3) == 0))
978 {
979 inPtr = hdd_extract_assigned_int_from_str(inPtr, 10,
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800980 &nRtt, &lastArg);
Rajeev79dbe4c2013-10-05 11:03:42 +0530981 if (TRUE == lastArg)
982 {
983 goto done;
984 }
985 if (NULL == inPtr)
986 {
987 return -EINVAL;
988 }
989 }
990
991
992done:
993
Rajeev Kumar45e64a72013-11-18 19:48:15 -0800994 pHddSetBatchScanReq->scanFrequency = nScanFreq;
995 pHddSetBatchScanReq->numberOfScansToBatch = nMscan;
996 pHddSetBatchScanReq->bestNetwork = nBestN;
997 pHddSetBatchScanReq->rfBand = ucRfBand;
998 pHddSetBatchScanReq->rtt = nRtt;
999
Rajeev79dbe4c2013-10-05 11:03:42 +05301000 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1001 "Received WLS_BATCHING_SET with SCANFREQ=%d "
1002 "MSCAN=%d BESTN=%d CHANNEL=%d RTT=%d",
1003 pHddSetBatchScanReq->scanFrequency,
1004 pHddSetBatchScanReq->numberOfScansToBatch,
1005 pHddSetBatchScanReq->bestNetwork,
1006 pHddSetBatchScanReq->rfBand,
1007 pHddSetBatchScanReq->rtt);
1008
1009 return 0;
1010}/*End of hdd_parse_set_batchscan_command*/
1011
1012/**---------------------------------------------------------------------------
1013
1014 \brief hdd_set_batch_scan_req_callback () - This function is called after
1015 receiving set batch scan response from FW and it saves set batch scan
1016 response data FW to HDD context and sets the completion event on
1017 which hdd_ioctl is waiting
1018
1019 \param - callbackContext Pointer to HDD adapter
1020 \param - pRsp Pointer to set batch scan response data received from FW
1021
1022 \return - nothing
1023
1024 --------------------------------------------------------------------------*/
1025static void hdd_set_batch_scan_req_callback
1026(
1027 void *callbackContext,
1028 tSirSetBatchScanRsp *pRsp
1029)
1030{
1031 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
1032 tSirSetBatchScanRsp *pHddSetBatchScanRsp;
1033
1034 /*sanity check*/
1035 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
1036 {
1037 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1038 "%s: Invalid pAdapter magic", __func__);
1039 VOS_ASSERT(0);
1040 return;
1041 }
1042 pHddSetBatchScanRsp = &pAdapter->hddSetBatchScanRsp;
1043
1044 /*save set batch scan response*/
1045 pHddSetBatchScanRsp->nScansToBatch = pRsp->nScansToBatch;
1046
1047 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
1048 "Received set batch scan rsp from FW with nScansToBatch=%d",
1049 pHddSetBatchScanRsp->nScansToBatch);
1050
1051 pAdapter->hdd_wait_for_set_batch_scan_rsp = FALSE;
1052 complete(&pAdapter->hdd_set_batch_scan_req_var);
1053
1054 return;
1055}/*End of hdd_set_batch_scan_req_callback*/
1056
1057
1058/**---------------------------------------------------------------------------
1059
1060 \brief hdd_populate_batch_scan_rsp_queue () - This function stores AP meta
1061 info in hdd batch scan response queue
1062
1063 \param - pAdapter Pointer to hdd adapter
1064 \param - pAPMetaInfo Pointer to access point meta info
1065 \param - scanId scan ID of batch scan response
1066 \param - isLastAp tells whether AP is last AP in batch scan response or not
1067
1068 \return - nothing
1069
1070 --------------------------------------------------------------------------*/
1071static void hdd_populate_batch_scan_rsp_queue( hdd_adapter_t* pAdapter,
1072 tpSirBatchScanNetworkInfo pApMetaInfo, tANI_U32 scanId, v_BOOL_t isLastAp)
1073{
1074 tHddBatchScanRsp *pHead;
1075 tHddBatchScanRsp *pNode;
1076 tHddBatchScanRsp *pPrev;
1077 tHddBatchScanRsp *pTemp;
1078 tANI_U8 ssidLen;
1079
1080 /*head of hdd batch scan response queue*/
1081 pHead = pAdapter->pBatchScanRsp;
1082
1083 pNode = (tHddBatchScanRsp *)vos_mem_malloc(sizeof(tHddBatchScanRsp));
1084 if (NULL == pNode)
1085 {
1086 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1087 "%s: Could not allocate memory", __func__);
1088 VOS_ASSERT(0);
1089 return;
1090 }
1091
1092 vos_mem_copy(pNode->ApInfo.bssid, pApMetaInfo->bssid,
1093 sizeof(pNode->ApInfo.bssid));
1094 ssidLen = strlen(pApMetaInfo->ssid);
1095 if (SIR_MAX_SSID_SIZE < ssidLen)
1096 {
1097 /*invalid scan result*/
1098 vos_mem_free(pNode);
1099 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1100 "%s: Invalid AP meta info ssidlen %d", __func__, ssidLen);
1101 return;
1102 }
1103 vos_mem_copy(pNode->ApInfo.ssid, pApMetaInfo->ssid, ssidLen);
1104 /*null terminate ssid*/
1105 pNode->ApInfo.ssid[ssidLen] = '\0';
1106 pNode->ApInfo.ch = pApMetaInfo->ch;
1107 pNode->ApInfo.rssi = pApMetaInfo->rssi;
1108 pNode->ApInfo.age = pApMetaInfo->timestamp;
1109 pNode->ApInfo.batchId = scanId;
1110 pNode->ApInfo.isLastAp = isLastAp;
1111
1112 pNode->pNext = NULL;
1113 if (NULL == pHead)
1114 {
1115 pAdapter->pBatchScanRsp = pNode;
1116 }
1117 else
1118 {
1119 pTemp = pHead;
1120 while (NULL != pTemp)
1121 {
1122 pPrev = pTemp;
1123 pTemp = pTemp->pNext;
1124 }
1125 pPrev->pNext = pNode;
1126 }
1127
1128 return;
1129}/*End of hdd_populate_batch_scan_rsp_queue*/
1130
1131/**---------------------------------------------------------------------------
1132
1133 \brief hdd_batch_scan_result_ind_callback () - This function is called after
1134 receiving batch scan response indication from FW. It saves get batch scan
1135 response data in HDD batch scan response queue. This callback sets the
1136 completion event on which hdd_ioctl is waiting only after getting complete
1137 batch scan response data from FW
1138
1139 \param - callbackContext Pointer to HDD adapter
1140 \param - pRsp Pointer to get batch scan response data received from FW
1141
1142 \return - nothing
1143
1144 --------------------------------------------------------------------------*/
1145static void hdd_batch_scan_result_ind_callback
1146(
1147 void *callbackContext,
1148 void *pRsp
1149)
1150{
1151 v_BOOL_t isLastAp;
1152 tANI_U32 numApMetaInfo;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001153 tANI_U32 numNetworkInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301154 tANI_U32 numberScanList;
1155 tANI_U32 nextScanListOffset;
1156 tANI_U32 nextApMetaInfoOffset;
1157 hdd_adapter_t* pAdapter;
1158 tpSirBatchScanList pScanList;
1159 tpSirBatchScanNetworkInfo pApMetaInfo;
1160 tpSirBatchScanResultIndParam pBatchScanRsp;/*batch scan rsp data from FW*/
1161 tSirSetBatchScanReq *pReq;
1162
1163 pAdapter = (hdd_adapter_t *)callbackContext;
1164 /*sanity check*/
Rajeev Kumar5286bb92013-12-05 11:52:10 -08001165 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
Rajeev79dbe4c2013-10-05 11:03:42 +05301166 {
1167 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1168 "%s: Invalid pAdapter magic", __func__);
1169 VOS_ASSERT(0);
1170 return;
1171 }
1172
1173 /*initialize locals*/
1174 pReq = &pAdapter->hddSetBatchScanReq;
1175 pBatchScanRsp = (tpSirBatchScanResultIndParam)pRsp;
1176 isLastAp = FALSE;
1177 numApMetaInfo = 0;
Rajeev Kumarce651e42013-10-21 18:57:15 -07001178 numNetworkInScanList = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05301179 numberScanList = 0;
1180 nextScanListOffset = 0;
1181 nextApMetaInfoOffset = 0;
1182 pScanList = NULL;
1183 pApMetaInfo = NULL;
1184
1185 if ((NULL == pBatchScanRsp) || (NULL == pReq))
1186 {
1187 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1188 "%s: pBatchScanRsp is %p pReq %p", __func__, pBatchScanRsp, pReq);
1189 isLastAp = TRUE;
1190 goto done;
1191 }
1192
1193 pAdapter->numScanList = numberScanList = pBatchScanRsp->numScanLists;
1194 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1195 "Batch scan rsp: numberScalList %d", numberScanList);
1196
1197 if ((!numberScanList) || (numberScanList > pReq->numberOfScansToBatch))
1198 {
1199 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1200 "%s: numberScanList %d", __func__, numberScanList);
1201 isLastAp = TRUE;
1202 goto done;
1203 }
1204
1205 while (numberScanList)
1206 {
Rajeev Kumarce651e42013-10-21 18:57:15 -07001207 pScanList = (tpSirBatchScanList)((tANI_U8 *)pBatchScanRsp->scanResults +
Rajeev79dbe4c2013-10-05 11:03:42 +05301208 nextScanListOffset);
1209 if (NULL == pScanList)
1210 {
1211 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1212 "%s: pScanList is %p", __func__, pScanList);
1213 isLastAp = TRUE;
1214 goto done;
1215 }
Rajeev Kumarce651e42013-10-21 18:57:15 -07001216 numNetworkInScanList = numApMetaInfo = pScanList->numNetworksInScanList;
Rajeev79dbe4c2013-10-05 11:03:42 +05301217 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumarce651e42013-10-21 18:57:15 -07001218 "Batch scan rsp: numApMetaInfo %d scanId %d",
1219 numApMetaInfo, pScanList->scanId);
Rajeev79dbe4c2013-10-05 11:03:42 +05301220
1221 if ((!numApMetaInfo) || (numApMetaInfo > pReq->bestNetwork))
1222 {
1223 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1224 "%s: numApMetaInfo %d", __func__, numApMetaInfo);
1225 isLastAp = TRUE;
1226 goto done;
1227 }
1228
Rajeev Kumarce651e42013-10-21 18:57:15 -07001229 /*Initialize next AP meta info offset for next scan list*/
1230 nextApMetaInfoOffset = 0;
1231
Rajeev79dbe4c2013-10-05 11:03:42 +05301232 while (numApMetaInfo)
1233 {
1234 pApMetaInfo = (tpSirBatchScanNetworkInfo)(pScanList->scanList +
1235 nextApMetaInfoOffset);
1236 if (NULL == pApMetaInfo)
1237 {
1238 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1239 "%s: pApMetaInfo is %p", __func__, pApMetaInfo);
1240 isLastAp = TRUE;
1241 goto done;
1242 }
1243 /*calculate AP age*/
1244 pApMetaInfo->timestamp =
1245 pBatchScanRsp->timestamp - pApMetaInfo->timestamp;
1246
1247 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussaina7c8e412013-11-20 11:06:42 -08001248 "%s: bssId "MAC_ADDRESS_STR
1249 " ch %d rssi %d timestamp %d", __func__,
1250 MAC_ADDR_ARRAY(pApMetaInfo->bssid),
1251 pApMetaInfo->ch, pApMetaInfo->rssi,
1252 pApMetaInfo->timestamp);
Rajeev79dbe4c2013-10-05 11:03:42 +05301253
1254 /*mark last AP in batch scan response*/
1255 if ((TRUE == pBatchScanRsp->isLastResult) &&
1256 (1 == numberScanList) && (1 == numApMetaInfo))
1257 {
1258 isLastAp = TRUE;
1259 }
1260
1261 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1262 /*store batch scan repsonse in hdd queue*/
1263 hdd_populate_batch_scan_rsp_queue(pAdapter, pApMetaInfo,
1264 pScanList->scanId, isLastAp);
1265 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1266
1267 nextApMetaInfoOffset += sizeof(tSirBatchScanNetworkInfo);
1268 numApMetaInfo--;
1269 }
1270
Rajeev Kumarce651e42013-10-21 18:57:15 -07001271 nextScanListOffset += ((sizeof(tSirBatchScanList) - sizeof(tANI_U8))
1272 + (sizeof(tSirBatchScanNetworkInfo)
1273 * numNetworkInScanList));
Rajeev79dbe4c2013-10-05 11:03:42 +05301274 numberScanList--;
1275 }
1276
1277done:
1278
1279 /*notify hdd_ioctl only if complete batch scan rsp is received and it was
1280 requested from hdd_ioctl*/
1281 if ((TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp) &&
1282 (TRUE == isLastAp))
1283 {
1284 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
1285 complete(&pAdapter->hdd_get_batch_scan_req_var);
1286 }
1287
1288 return;
1289}/*End of hdd_batch_scan_result_ind_callback*/
1290
1291/**---------------------------------------------------------------------------
1292
1293 \brief hdd_format_batch_scan_rsp () - This function formats batch scan
1294 response as per batch scan FR request format by putting proper markers
1295
1296 \param - pDest pointer to destination buffer
1297 \param - cur_len current length
1298 \param - tot_len total remaining size which can be written to user space
1299 \param - pApMetaInfo Pointer to get batch scan response AP meta info
1300 \param - pAdapter Pointer to HDD adapter
1301
1302 \return - ret no of characters written
1303
1304 --------------------------------------------------------------------------*/
1305static tANI_U32
1306hdd_format_batch_scan_rsp
1307(
1308 tANI_U8 *pDest,
1309 tANI_U32 cur_len,
1310 tANI_U32 tot_len,
1311 tHddBatchScanRsp *pApMetaInfo,
1312 hdd_adapter_t* pAdapter
1313)
1314{
1315 tANI_U32 ret = 0;
1316 tANI_U32 rem_len = 0;
1317 tANI_U8 temp_len = 0;
1318 tANI_U8 temp_total_len = 0;
1319 tANI_U8 temp[HDD_BATCH_SCAN_AP_META_INFO_SIZE];
1320 tANI_U8 *pTemp = temp;
1321
1322 /*Batch scan reponse needs to be returned to user space in
1323 following format:
1324 "scancount=X\n" where X is the number of scans in current batch
1325 batch
1326 "trunc\n" optional present if current scan truncated
1327 "bssid=XX:XX:XX:XX:XX:XX\n"
1328 "ssid=XXXX\n"
1329 "freq=X\n" frequency in Mhz
1330 "level=XX\n"
1331 "age=X\n" ms
1332 "dist=X\n" cm (-1 if not available)
1333 "errror=X\n" (-1if not available)
1334 "====\n" (end of ap marker)
1335 "####\n" (end of scan marker)
1336 "----\n" (end of results)*/
1337 /*send scan result in above format to user space based on
1338 available length*/
1339 /*The GET response may have more data than the driver can return in its
1340 buffer. In that case the buffer should be filled to the nearest complete
1341 scan, ending with "%%%%".Subsequent callsshould return the remaining data
1342 starting with the next scan (optional .trunc\n., .apcount=X\n., etc).
1343 The final buffer should end with "----\n"*/
1344
1345 /*sanity*/
1346 if (cur_len > tot_len)
1347 {
1348 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1349 "%s: invaid cur_len %d tot_len %d", __func__, cur_len, tot_len);
1350 return 0;
1351 }
1352 else
1353 {
1354 rem_len = (tot_len - cur_len);
1355 }
1356
1357 /*end scan marker*/
1358 if (pApMetaInfo->ApInfo.batchId != pAdapter->prev_batch_id)
1359 {
1360 temp_len = snprintf(pTemp, sizeof(temp), "####\n");
1361 pTemp += temp_len;
1362 temp_total_len += temp_len;
1363 }
1364
1365 /*bssid*/
1366 temp_len = snprintf(pTemp, sizeof(temp),
1367 "bssid=0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n",
1368 pApMetaInfo->ApInfo.bssid[0], pApMetaInfo->ApInfo.bssid[1],
1369 pApMetaInfo->ApInfo.bssid[2], pApMetaInfo->ApInfo.bssid[3],
1370 pApMetaInfo->ApInfo.bssid[4], pApMetaInfo->ApInfo.bssid[5]);
1371 pTemp += temp_len;
1372 temp_total_len += temp_len;
1373
1374 /*ssid*/
1375 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "ssid=%s\n",
1376 pApMetaInfo->ApInfo.ssid);
1377 pTemp += temp_len;
1378 temp_total_len += temp_len;
1379
1380 /*freq*/
1381 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "freq=%d\n",
Rajeev Kumarc40f7512013-11-04 14:13:23 -08001382 sme_ChnToFreq(pApMetaInfo->ApInfo.ch));
Rajeev79dbe4c2013-10-05 11:03:42 +05301383 pTemp += temp_len;
1384 temp_total_len += temp_len;
1385
1386 /*level*/
1387 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "level=%d\n",
1388 pApMetaInfo->ApInfo.rssi);
1389 pTemp += temp_len;
1390 temp_total_len += temp_len;
1391
1392 /*age*/
Jeff Johnson02797792013-10-26 19:17:13 -07001393 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "age=%d\n",
Rajeev79dbe4c2013-10-05 11:03:42 +05301394 pApMetaInfo->ApInfo.age);
1395 pTemp += temp_len;
1396 temp_total_len += temp_len;
1397
1398 /*dist*/
1399 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "dist=-1\n");
1400 pTemp += temp_len;
1401 temp_total_len += temp_len;
1402
1403 /*error*/
1404 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "error=-1\n");
1405 pTemp += temp_len;
1406 temp_total_len += temp_len;
1407
1408 /*end AP marker*/
1409 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "====\n");
1410 pTemp += temp_len;
1411 temp_total_len += temp_len;
1412
1413 /*last AP in batch scan response*/
1414 if(TRUE == pApMetaInfo->ApInfo.isLastAp)
1415 {
1416 /*end scan marker*/
1417 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "####\n");
1418 pTemp += temp_len;
1419 temp_total_len += temp_len;
1420
1421 /*end batch scan result marker*/
1422 temp_len = snprintf(pTemp, (sizeof(temp) - temp_total_len), "----\n");
1423 pTemp += temp_len;
1424 temp_total_len += temp_len;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08001425
Rajeev79dbe4c2013-10-05 11:03:42 +05301426 }
1427
1428 if (temp_total_len < rem_len)
1429 {
1430 ret = temp_total_len + 1;
1431 strlcpy(pDest, temp, ret);
1432 pAdapter->isTruncated = FALSE;
1433 }
1434 else
1435 {
1436 pAdapter->isTruncated = TRUE;
1437 if (rem_len >= strlen("%%%%"))
1438 {
Rajeev Kumarc933d982013-11-18 20:04:20 -08001439 ret = snprintf(pDest, sizeof(temp), "%%%%");
Rajeev79dbe4c2013-10-05 11:03:42 +05301440 }
Rajeev Kumarc933d982013-11-18 20:04:20 -08001441 else
Rajeev79dbe4c2013-10-05 11:03:42 +05301442 {
1443 ret = 0;
1444 }
1445 }
1446
1447 return ret;
1448
1449}/*End of hdd_format_batch_scan_rsp*/
1450
1451/**---------------------------------------------------------------------------
1452
1453 \brief hdd_populate_user_batch_scan_rsp() - This function populates user data
1454 buffer starting with head of hdd batch scan response queue
1455
1456 \param - pAdapter Pointer to HDD adapter
1457 \param - pDest Pointer to user data buffer
1458 \param - cur_len current offset in user buffer
1459 \param - rem_len remaining no of bytes in user buffer
1460
1461 \return - number of bytes written in user buffer
1462
1463 --------------------------------------------------------------------------*/
1464
1465tANI_U32 hdd_populate_user_batch_scan_rsp
1466(
1467 hdd_adapter_t* pAdapter,
1468 tANI_U8 *pDest,
1469 tANI_U32 cur_len,
1470 tANI_U32 rem_len
1471)
1472{
1473 tHddBatchScanRsp *pHead;
1474 tHddBatchScanRsp *pPrev;
1475 tANI_U32 len;
1476
Rajeev79dbe4c2013-10-05 11:03:42 +05301477 pAdapter->isTruncated = FALSE;
1478
1479 /*head of hdd batch scan response queue*/
1480 pHead = pAdapter->pBatchScanRsp;
1481 while (pHead)
1482 {
1483 len = hdd_format_batch_scan_rsp(pDest, cur_len, rem_len, pHead,
1484 pAdapter);
1485 pDest += len;
Rajeev Kumar292d2bb2013-10-23 15:01:44 -07001486 pDest--;
Rajeev79dbe4c2013-10-05 11:03:42 +05301487 cur_len += len;
1488 if(TRUE == pAdapter->isTruncated)
1489 {
1490 /*result is truncated return rest of scan rsp in next req*/
1491 cur_len = rem_len;
1492 break;
1493 }
1494 pPrev = pHead;
1495 pHead = pHead->pNext;
1496 pAdapter->pBatchScanRsp = pHead;
Rajeev Kumarbe17d8b2014-01-10 15:39:45 -08001497 if (TRUE == pPrev->ApInfo.isLastAp)
1498 {
1499 pAdapter->prev_batch_id = 0;
1500 }
1501 else
1502 {
1503 pAdapter->prev_batch_id = pPrev->ApInfo.batchId;
1504 }
Rajeev79dbe4c2013-10-05 11:03:42 +05301505 vos_mem_free(pPrev);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08001506 pPrev = NULL;
Rajeev79dbe4c2013-10-05 11:03:42 +05301507 }
1508
1509 return cur_len;
1510}/*End of hdd_populate_user_batch_scan_rsp*/
1511
1512/**---------------------------------------------------------------------------
1513
1514 \brief hdd_return_batch_scan_rsp_to_user () - This function returns batch
1515 scan response data from HDD queue to user space
1516 It does following in detail:
1517 a) if HDD has enough data in its queue then it 1st copies data to user
1518 space and then send get batch scan indication message to FW. In this
1519 case it does not wait on any event and batch scan response data will
1520 be populated in HDD response queue in MC thread context after receiving
1521 indication from FW
1522 b) else send get batch scan indication message to FW and wait on an event
1523 which will be set once HDD receives complete batch scan response from
1524 FW and then this function returns batch scan response to user space
1525
1526 \param - pAdapter Pointer to HDD adapter
1527 \param - pPrivData Pointer to priv_data
1528
1529 \return - 0 for success -EFAULT for failure
1530
1531 --------------------------------------------------------------------------*/
1532
1533int hdd_return_batch_scan_rsp_to_user
1534(
1535 hdd_adapter_t* pAdapter,
1536 hdd_priv_data_t *pPrivData,
1537 tANI_U8 *command
1538)
1539{
1540 tANI_U8 *pDest;
1541 tANI_U32 count = 0;
1542 tANI_U32 len = 0;
1543 tANI_U32 cur_len = 0;
1544 tANI_U32 rem_len = 0;
1545 eHalStatus halStatus;
1546 unsigned long rc;
1547 tSirTriggerBatchScanResultInd *pReq;
1548
1549 pReq = &pAdapter->hddTriggerBatchScanResultInd;
1550 pReq->param = 0;/*batch scan client*/
1551 pDest = (tANI_U8 *)(command + pPrivData->used_len);
1552 pAdapter->hdd_wait_for_get_batch_scan_rsp = FALSE;
1553
1554 cur_len = pPrivData->used_len;
1555 if (pPrivData->total_len > pPrivData->used_len)
1556 {
1557 rem_len = pPrivData->total_len - pPrivData->used_len;
1558 }
1559 else
1560 {
1561 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1562 "%s: Invalid user data buffer total_len %d used_len %d",
1563 __func__, pPrivData->total_len, pPrivData->used_len);
1564 return -EFAULT;
1565 }
1566
1567 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1568 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
1569 cur_len, rem_len);
1570 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1571
1572 /*enough scan result available in cache to return to user space or
1573 scan result needs to be fetched 1st from fw and then return*/
Rajeev Kumar99db6262013-11-11 15:23:36 -08001574 if (len == cur_len)
Rajeev79dbe4c2013-10-05 11:03:42 +05301575 {
1576 pAdapter->hdd_wait_for_get_batch_scan_rsp = TRUE;
1577 halStatus = sme_TriggerBatchScanResultInd(
1578 WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
1579 pAdapter->sessionId, hdd_batch_scan_result_ind_callback,
1580 pAdapter);
1581 if ( eHAL_STATUS_SUCCESS == halStatus )
1582 {
1583 if (TRUE == pAdapter->hdd_wait_for_get_batch_scan_rsp)
1584 {
1585 INIT_COMPLETION(pAdapter->hdd_get_batch_scan_req_var);
1586 rc = wait_for_completion_timeout(
1587 &pAdapter->hdd_get_batch_scan_req_var,
1588 msecs_to_jiffies(HDD_GET_BATCH_SCAN_RSP_TIME_OUT));
1589 if (0 == rc)
1590 {
1591 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1592 "%s: Timeout waiting to fetch batch scan rsp from fw",
1593 __func__);
1594 return -EFAULT;
1595 }
1596 }
1597
1598 len = snprintf(pDest, HDD_BATCH_SCAN_AP_META_INFO_SIZE,
Jeff Johnson02797792013-10-26 19:17:13 -07001599 "scancount=%u\n", pAdapter->numScanList);
Rajeev79dbe4c2013-10-05 11:03:42 +05301600 pDest += len;
1601 cur_len += len;
1602
1603 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1604 len = hdd_populate_user_batch_scan_rsp(pAdapter, pDest,
1605 cur_len, rem_len);
1606 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1607
1608 count = 0;
1609 len = (len - pPrivData->used_len);
1610 pDest = (command + pPrivData->used_len);
1611 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08001612 "NEW BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05301613 while(count < len)
1614 {
1615 printk("%c", *(pDest + count));
1616 count++;
1617 }
1618 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1619 "%s: copy %d data to user buffer", __func__, len);
1620 if (copy_to_user(pPrivData->buf, pDest, len))
1621 {
1622 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1623 "%s: failed to copy data to user buffer", __func__);
1624 return -EFAULT;
1625 }
1626 }
1627 else
1628 {
1629 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1630 "sme_GetBatchScanScan returned failure halStatus %d",
1631 halStatus);
1632 return -EINVAL;
1633 }
1634 }
1635 else
1636 {
Rajeev79dbe4c2013-10-05 11:03:42 +05301637 count = 0;
1638 len = (len - pPrivData->used_len);
1639 pDest = (command + pPrivData->used_len);
1640 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Rajeev Kumar99db6262013-11-11 15:23:36 -08001641 "REMAINING TRUNCATED BATCH SCAN RESULT:");
Rajeev79dbe4c2013-10-05 11:03:42 +05301642 while(count < len)
1643 {
1644 printk("%c", *(pDest + count));
1645 count++;
1646 }
Rajeev Kumar99db6262013-11-11 15:23:36 -08001647 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1648 "%s: copy %d data to user buffer", __func__, len);
Rajeev79dbe4c2013-10-05 11:03:42 +05301649 if (copy_to_user(pPrivData->buf, pDest, len))
1650 {
1651 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1652 "%s: failed to copy data to user buffer", __func__);
1653 return -EFAULT;
1654 }
Rajeev79dbe4c2013-10-05 11:03:42 +05301655 }
1656
1657 return 0;
1658} /*End of hdd_return_batch_scan_rsp_to_user*/
1659
Rajeev Kumar8b373292014-01-08 20:36:55 -08001660
1661/**---------------------------------------------------------------------------
1662
1663 \brief hdd_handle_batch_scan_ioctl () - This function handles WLS_BATCHING
1664 IOCTLs from user space. Following BATCH SCAN DEV IOCTs are handled:
1665 WLS_BATCHING VERSION
1666 WLS_BATCHING SET
1667 WLS_BATCHING GET
1668 WLS_BATCHING STOP
1669
1670 \param - pAdapter Pointer to HDD adapter
1671 \param - pPrivdata Pointer to priv_data
1672 \param - command Pointer to command
1673
1674 \return - 0 for success -EFAULT for failure
1675
1676 --------------------------------------------------------------------------*/
1677
1678int hdd_handle_batch_scan_ioctl
1679(
1680 hdd_adapter_t *pAdapter,
1681 hdd_priv_data_t *pPrivdata,
1682 tANI_U8 *command
1683)
1684{
1685 int ret = 0;
Yue Mae36e3552014-03-05 17:06:20 -08001686 hdd_context_t *pHddCtx;
1687
1688 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1689 ret = wlan_hdd_validate_context(pHddCtx);
1690 if (ret)
1691 {
1692 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1693 "%s: HDD context is not valid!", __func__);
1694 goto exit;
1695 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08001696
1697 if (strncmp(command, "WLS_BATCHING VERSION", 20) == 0)
1698 {
1699 char extra[32];
1700 tANI_U8 len = 0;
1701 tANI_U8 version = HDD_BATCH_SCAN_VERSION;
1702
1703 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
1704 {
1705 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1706 "%s: Batch scan feature is not supported by FW", __func__);
1707 ret = -EINVAL;
1708 goto exit;
1709 }
1710
1711 len = scnprintf(extra, sizeof(extra), "WLS_BATCHING_VERSION %d",
1712 version);
1713 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
1714 {
1715 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1716 "%s: failed to copy data to user buffer", __func__);
1717 ret = -EFAULT;
1718 goto exit;
1719 }
1720 ret = HDD_BATCH_SCAN_VERSION;
1721 }
1722 else if (strncmp(command, "WLS_BATCHING SET", 16) == 0)
1723 {
1724 int status;
1725 tANI_U8 *value = (command + 16);
1726 eHalStatus halStatus;
1727 unsigned long rc;
1728 tSirSetBatchScanReq *pReq = &pAdapter->hddSetBatchScanReq;
1729 tSirSetBatchScanRsp *pRsp = &pAdapter->hddSetBatchScanRsp;
1730
1731 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
1732 {
1733 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1734 "%s: Batch scan feature is not supported by FW", __func__);
1735 ret = -EINVAL;
1736 goto exit;
1737 }
1738
1739 if ((WLAN_HDD_INFRA_STATION != pAdapter->device_mode) &&
1740 (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) &&
1741 (WLAN_HDD_P2P_GO != pAdapter->device_mode) &&
1742 (WLAN_HDD_P2P_DEVICE != pAdapter->device_mode))
1743 {
1744 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05301745 "Received WLS_BATCHING SET command in invalid mode %s (%d) "
Rajeev Kumar8b373292014-01-08 20:36:55 -08001746 "WLS_BATCHING_SET is only allowed in infra STA/P2P client mode",
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05301747 hdd_device_modetoString(pAdapter->device_mode),
1748 pAdapter->device_mode);
Rajeev Kumar8b373292014-01-08 20:36:55 -08001749 ret = -EINVAL;
1750 goto exit;
1751 }
1752
1753 status = hdd_parse_set_batchscan_command(value, pReq);
1754 if (status)
1755 {
1756 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1757 "Invalid WLS_BATCHING SET command");
1758 ret = -EINVAL;
1759 goto exit;
1760 }
1761
1762
1763 pAdapter->hdd_wait_for_set_batch_scan_rsp = TRUE;
1764 halStatus = sme_SetBatchScanReq(WLAN_HDD_GET_HAL_CTX(pAdapter), pReq,
1765 pAdapter->sessionId, hdd_set_batch_scan_req_callback,
1766 pAdapter);
1767
1768 if ( eHAL_STATUS_SUCCESS == halStatus )
1769 {
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05301770 char extra[32];
1771 tANI_U8 len = 0;
1772 tANI_U8 mScan = 0;
1773
Rajeev Kumar8b373292014-01-08 20:36:55 -08001774 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1775 "sme_SetBatchScanReq returned success halStatus %d",
1776 halStatus);
1777 if (TRUE == pAdapter->hdd_wait_for_set_batch_scan_rsp)
1778 {
1779 INIT_COMPLETION(pAdapter->hdd_set_batch_scan_req_var);
1780 rc = wait_for_completion_timeout(
1781 &pAdapter->hdd_set_batch_scan_req_var,
1782 msecs_to_jiffies(HDD_SET_BATCH_SCAN_REQ_TIME_OUT));
1783 if (0 == rc)
1784 {
1785 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1786 "%s: Timeout waiting for set batch scan to complete",
1787 __func__);
1788 ret = -EINVAL;
1789 goto exit;
1790 }
1791 }
1792 if ( !pRsp->nScansToBatch )
1793 {
1794 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1795 "%s: Received set batch scan failure response from FW",
1796 __func__);
1797 ret = -EINVAL;
1798 goto exit;
1799 }
1800 /*As per the Batch Scan Framework API we should return the MIN of
1801 either MSCAN or the max # of scans firmware can cache*/
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05301802 mScan = MIN(pReq->numberOfScansToBatch , pRsp->nScansToBatch);
Rajeev Kumar8b373292014-01-08 20:36:55 -08001803
1804 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STARTED;
1805
1806 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1807 "%s: request MSCAN %d response MSCAN %d ret %d",
Mahesh A Saptasagar5f568172014-05-14 17:02:33 +05301808 __func__, pReq->numberOfScansToBatch, pRsp->nScansToBatch, mScan);
1809 len = scnprintf(extra, sizeof(extra), "%d", mScan);
1810 if (copy_to_user(pPrivdata->buf, &extra, len + 1))
1811 {
1812 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1813 "%s: failed to copy MSCAN value to user buffer", __func__);
1814 ret = -EFAULT;
1815 goto exit;
1816 }
Rajeev Kumar8b373292014-01-08 20:36:55 -08001817 }
1818 else
1819 {
1820 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1821 "sme_SetBatchScanReq returned failure halStatus %d",
1822 halStatus);
1823 ret = -EINVAL;
1824 goto exit;
1825 }
1826 }
1827 else if (strncmp(command, "WLS_BATCHING STOP", 17) == 0)
1828 {
1829 eHalStatus halStatus;
1830 tSirStopBatchScanInd *pInd = &pAdapter->hddStopBatchScanInd;
1831 pInd->param = 0;
1832
1833 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
1834 {
1835 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1836 "%s: Batch scan feature is not supported by FW", __func__);
1837 ret = -EINVAL;
1838 goto exit;
1839 }
1840
1841 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
1842 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05301843 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08001844 "Batch scan is not yet enabled batch scan state %d",
1845 pAdapter->batchScanState);
1846 ret = -EINVAL;
1847 goto exit;
1848 }
1849
Kiet Lamaa8e15a2014-02-11 23:30:06 -08001850 mutex_lock(&pAdapter->hdd_batch_scan_lock);
1851 hdd_deinit_batch_scan(pAdapter);
1852 mutex_unlock(&pAdapter->hdd_batch_scan_lock);
1853
Rajeev Kumar8b373292014-01-08 20:36:55 -08001854 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
1855
1856 halStatus = sme_StopBatchScanInd(WLAN_HDD_GET_HAL_CTX(pAdapter), pInd,
1857 pAdapter->sessionId);
1858 if ( eHAL_STATUS_SUCCESS == halStatus )
1859 {
1860 ret = 0;
1861 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1862 "sme_StopBatchScanInd returned success halStatus %d",
1863 halStatus);
1864 }
1865 else
1866 {
1867 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1868 "sme_StopBatchScanInd returned failure halStatus %d",
1869 halStatus);
1870 ret = -EINVAL;
1871 goto exit;
1872 }
1873 }
1874 else if (strncmp(command, "WLS_BATCHING GET", 16) == 0)
1875 {
1876 tANI_U32 remain_len;
1877
1878 if (FALSE == sme_IsFeatureSupportedByFW(BATCH_SCAN))
1879 {
1880 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1881 "%s: Batch scan feature is not supported by FW", __func__);
1882 ret = -EINVAL;
1883 goto exit;
1884 }
1885
1886 if (eHDD_BATCH_SCAN_STATE_STARTED != pAdapter->batchScanState)
1887 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05301888 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Rajeev Kumar8b373292014-01-08 20:36:55 -08001889 "Batch scan is not yet enabled could not return results"
1890 "Batch Scan state %d",
1891 pAdapter->batchScanState);
1892 ret = -EINVAL;
1893 goto exit;
1894 }
1895
1896 pPrivdata->used_len = 16;
1897 remain_len = pPrivdata->total_len - pPrivdata->used_len;
1898 if (remain_len < pPrivdata->total_len)
1899 {
1900 /*Clear previous batch scan response data if any*/
1901 vos_mem_zero((tANI_U8 *)(command + pPrivdata->used_len), remain_len);
1902 }
1903 else
1904 {
1905 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1906 "Invalid total length from user space can't fetch batch"
1907 " scan response total_len %d used_len %d remain len %d",
1908 pPrivdata->total_len, pPrivdata->used_len, remain_len);
1909 ret = -EINVAL;
1910 goto exit;
1911 }
1912 ret = hdd_return_batch_scan_rsp_to_user(pAdapter, pPrivdata, command);
1913 }
1914
1915exit:
1916
1917 return ret;
1918}
1919
1920
Rajeev79dbe4c2013-10-05 11:03:42 +05301921#endif/*End of FEATURE_WLAN_BATCH_SCAN*/
1922
c_hpothu92367912014-05-01 15:18:17 +05301923static void getBcnMissRateCB(VOS_STATUS status, int bcnMissRate, void *data)
1924{
c_hpothu39eb1e32014-06-26 16:31:50 +05301925 bcnMissRateContext_t *pCBCtx;
1926
1927 if (NULL == data)
1928 {
1929 hddLog(VOS_TRACE_LEVEL_ERROR, FL("argument data is NULL"));
1930 return;
1931 }
c_hpothu92367912014-05-01 15:18:17 +05301932
1933 /* there is a race condition that exists between this callback
1934 function and the caller since the caller could time out either
1935 before or while this code is executing. we use a spinlock to
1936 serialize these actions */
1937 spin_lock(&hdd_context_lock);
1938
c_hpothu39eb1e32014-06-26 16:31:50 +05301939 pCBCtx = (bcnMissRateContext_t *)data;
c_hpothu92367912014-05-01 15:18:17 +05301940 gbcnMissRate = -1;
1941
c_hpothu39eb1e32014-06-26 16:31:50 +05301942 if (pCBCtx->magic != BCN_MISS_RATE_CONTEXT_MAGIC)
c_hpothu92367912014-05-01 15:18:17 +05301943 {
1944 hddLog(VOS_TRACE_LEVEL_ERROR,
c_hpothu39eb1e32014-06-26 16:31:50 +05301945 FL("invalid context magic: %08x"), pCBCtx->magic);
c_hpothu92367912014-05-01 15:18:17 +05301946 spin_unlock(&hdd_context_lock);
1947 return ;
1948 }
1949
1950 if (VOS_STATUS_SUCCESS == status)
1951 {
c_hpothu39eb1e32014-06-26 16:31:50 +05301952 gbcnMissRate = bcnMissRate;
c_hpothu92367912014-05-01 15:18:17 +05301953 }
c_hpothu39eb1e32014-06-26 16:31:50 +05301954 else
1955 {
1956 hddLog(VOS_TRACE_LEVEL_ERROR, FL("failed to get bcnMissRate"));
1957 }
1958
c_hpothu92367912014-05-01 15:18:17 +05301959 complete(&(pCBCtx->completion));
1960 spin_unlock(&hdd_context_lock);
1961
1962 return;
1963}
1964
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05301965static int hdd_get_dwell_time(hdd_config_t *pCfg, tANI_U8 *command, char *extra, tANI_U8 n, tANI_U8 *len)
1966{
1967 int ret = 0;
1968
1969 if (!pCfg || !command || !extra || !len)
1970 {
1971 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1972 "%s: argument passsed for GETDWELLTIME is incorrect", __func__);
1973 ret = -EINVAL;
1974 return ret;
1975 }
1976
1977 if (strncmp(command, "GETDWELLTIME ACTIVE MAX", 23) == 0)
1978 {
1979 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MAX %u\n",
1980 (int)pCfg->nActiveMaxChnTime);
1981 return ret;
1982 }
1983 else if (strncmp(command, "GETDWELLTIME ACTIVE MIN", 23) == 0)
1984 {
1985 *len = scnprintf(extra, n, "GETDWELLTIME ACTIVE MIN %u\n",
1986 (int)pCfg->nActiveMinChnTime);
1987 return ret;
1988 }
1989 else if (strncmp(command, "GETDWELLTIME PASSIVE MAX", 24) == 0)
1990 {
1991 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MAX %u\n",
1992 (int)pCfg->nPassiveMaxChnTime);
1993 return ret;
1994 }
1995 else if (strncmp(command, "GETDWELLTIME PASSIVE MIN", 24) == 0)
1996 {
1997 *len = scnprintf(extra, n, "GETDWELLTIME PASSIVE MIN %u\n",
1998 (int)pCfg->nPassiveMinChnTime);
1999 return ret;
2000 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302001 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
2002 {
2003 *len = scnprintf(extra, n, "GETDWELLTIME %u \n",
2004 (int)pCfg->nActiveMaxChnTime);
2005 return ret;
2006 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302007 else
2008 {
2009 ret = -EINVAL;
2010 }
2011
2012 return ret;
2013}
2014
2015static int hdd_set_dwell_time(hdd_adapter_t *pAdapter, tANI_U8 *command)
2016{
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302017 tHalHandle hHal;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302018 hdd_config_t *pCfg;
2019 tANI_U8 *value = command;
2020 int val = 0, ret = 0, temp = 0;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302021 tSmeConfigParams smeConfig;
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302022
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302023 if (!pAdapter || !command || !(pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini)
2024 || !(hHal = (WLAN_HDD_GET_HAL_CTX(pAdapter))))
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302025 {
2026 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2027 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
2028 ret = -EINVAL;
2029 return ret;
2030 }
2031
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302032 vos_mem_zero(&smeConfig, sizeof(smeConfig));
2033 sme_GetConfigParam(hHal, &smeConfig);
2034
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302035 if (strncmp(command, "SETDWELLTIME ACTIVE MAX", 23) == 0 )
2036 {
2037 value = value + 24;
2038 temp = kstrtou32(value, 10, &val);
2039 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
2040 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
2041 {
2042 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2043 "%s: argument passed for SETDWELLTIME ACTIVE MAX is incorrect", __func__);
2044 ret = -EFAULT;
2045 return ret;
2046 }
2047 pCfg->nActiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302048 smeConfig.csrConfig.nActiveMaxChnTime = val;
2049 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302050 }
2051 else if (strncmp(command, "SETDWELLTIME ACTIVE MIN", 23) == 0)
2052 {
2053 value = value + 24;
2054 temp = kstrtou32(value, 10, &val);
2055 if (temp !=0 || val < CFG_ACTIVE_MIN_CHANNEL_TIME_MIN ||
2056 val > CFG_ACTIVE_MIN_CHANNEL_TIME_MAX )
2057 {
2058 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2059 "%s: argument passsed for SETDWELLTIME ACTIVE MIN is incorrect", __func__);
2060 ret = -EFAULT;
2061 return ret;
2062 }
2063 pCfg->nActiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302064 smeConfig.csrConfig.nActiveMinChnTime = val;
2065 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302066 }
2067 else if (strncmp(command, "SETDWELLTIME PASSIVE MAX", 24) == 0)
2068 {
2069 value = value + 25;
2070 temp = kstrtou32(value, 10, &val);
2071 if (temp != 0 || val < CFG_PASSIVE_MAX_CHANNEL_TIME_MIN ||
2072 val > CFG_PASSIVE_MAX_CHANNEL_TIME_MAX )
2073 {
2074 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2075 "%s: argument passed for SETDWELLTIME PASSIVE MAX is incorrect", __func__);
2076 ret = -EFAULT;
2077 return ret;
2078 }
2079 pCfg->nPassiveMaxChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302080 smeConfig.csrConfig.nPassiveMaxChnTime = val;
2081 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302082 }
2083 else if (strncmp(command, "SETDWELLTIME PASSIVE MIN", 24) == 0)
2084 {
2085 value = value + 25;
2086 temp = kstrtou32(value, 10, &val);
2087 if (temp != 0 || val < CFG_PASSIVE_MIN_CHANNEL_TIME_MIN ||
2088 val > CFG_PASSIVE_MIN_CHANNEL_TIME_MAX )
2089 {
2090 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2091 "%s: argument passed for SETDWELLTIME PASSIVE MIN is incorrect", __func__);
2092 ret = -EFAULT;
2093 return ret;
2094 }
2095 pCfg->nPassiveMinChnTime = val;
Rajesh Babu Prathipatib09815c2014-07-05 11:22:24 +05302096 smeConfig.csrConfig.nPassiveMinChnTime = val;
2097 sme_UpdateConfig(hHal, &smeConfig);
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302098 }
Rajesh Babu Prathipati0fd227e2014-07-05 12:50:00 +05302099 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
2100 {
2101 value = value + 13;
2102 temp = kstrtou32(value, 10, &val);
2103 if (temp != 0 || val < CFG_ACTIVE_MAX_CHANNEL_TIME_MIN ||
2104 val > CFG_ACTIVE_MAX_CHANNEL_TIME_MAX )
2105 {
2106 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2107 "%s: argument passed for SETDWELLTIME is incorrect", __func__);
2108 ret = -EFAULT;
2109 return ret;
2110 }
2111 pCfg->nActiveMaxChnTime = val;
2112 smeConfig.csrConfig.nActiveMaxChnTime = val;
2113 sme_UpdateConfig(hHal, &smeConfig);
2114 }
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05302115 else
2116 {
2117 ret = -EINVAL;
2118 }
2119
2120 return ret;
2121}
2122
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002123static int hdd_driver_command(hdd_adapter_t *pAdapter,
2124 hdd_priv_data_t *ppriv_data)
Jeff Johnson295189b2012-06-20 16:38:30 -07002125{
Jeff Johnson295189b2012-06-20 16:38:30 -07002126 hdd_priv_data_t priv_data;
2127 tANI_U8 *command = NULL;
Kaushik, Sushant96122442014-10-21 16:40:18 +05302128 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2129 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002130 int ret = 0;
Kaushik, Sushant96122442014-10-21 16:40:18 +05302131 int status;
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002132 /*
2133 * Note that valid pointers are provided by caller
2134 */
Jeff Johnson295189b2012-06-20 16:38:30 -07002135
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002136 /* copy to local struct to avoid numerous changes to legacy code */
2137 priv_data = *ppriv_data;
Jeff Johnson295189b2012-06-20 16:38:30 -07002138
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002139 if (priv_data.total_len <= 0 ||
2140 priv_data.total_len > WLAN_PRIV_DATA_MAX_LEN)
Sameer Thalappil8ef3a0e2013-04-05 14:36:04 -07002141 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002142 hddLog(VOS_TRACE_LEVEL_WARN,
2143 "%s:invalid priv_data.total_len(%d)!!!", __func__,
2144 priv_data.total_len);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07002145 ret = -EINVAL;
2146 goto exit;
2147 }
Kaushik, Sushant96122442014-10-21 16:40:18 +05302148 status = wlan_hdd_validate_context(pHddCtx);
2149 if (0 != status)
2150 {
2151 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2152 "%s: HDD context is not valid", __func__);
2153 return status;
2154 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07002155 /* Allocate +1 for '\0' */
2156 command = kmalloc(priv_data.total_len + 1, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07002157 if (!command)
2158 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002159 hddLog(VOS_TRACE_LEVEL_ERROR,
2160 "%s: failed to allocate memory", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002161 ret = -ENOMEM;
2162 goto exit;
2163 }
2164
2165 if (copy_from_user(command, priv_data.buf, priv_data.total_len))
2166 {
2167 ret = -EFAULT;
2168 goto exit;
2169 }
2170
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002171 /* Make sure the command is NUL-terminated */
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07002172 command[priv_data.total_len] = '\0';
2173
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002174 /* at one time the following block of code was conditional. braces
2175 * have been retained to avoid re-indenting the legacy code
2176 */
Jeff Johnson295189b2012-06-20 16:38:30 -07002177 {
2178 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
2179
2180 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07002181 "%s: Received %s cmd from Wi-Fi GUI***", __func__, command);
Jeff Johnson295189b2012-06-20 16:38:30 -07002182
2183 if (strncmp(command, "P2P_DEV_ADDR", 12) == 0 )
2184 {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302185 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2186 TRACE_CODE_HDD_P2P_DEV_ADDR_IOCTL,
2187 pAdapter->sessionId, (unsigned)
2188 (*(pHddCtx->p2pDeviceAddress.bytes+2)<<24 |
2189 *(pHddCtx->p2pDeviceAddress.bytes+3)<<16 |
2190 *(pHddCtx->p2pDeviceAddress.bytes+4)<<8 |
2191 *(pHddCtx->p2pDeviceAddress.bytes+5))));
Jeff Johnson295189b2012-06-20 16:38:30 -07002192 if (copy_to_user(priv_data.buf, pHddCtx->p2pDeviceAddress.bytes,
2193 sizeof(tSirMacAddr)))
2194 {
2195 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002196 "%s: failed to copy data to user buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002197 ret = -EFAULT;
2198 }
2199 }
Amar Singhal0974e402013-02-12 14:27:46 -08002200 else if(strncmp(command, "SETBAND", 7) == 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07002201 {
Amar Singhal0974e402013-02-12 14:27:46 -08002202 tANI_U8 *ptr = command ;
Srinivas Girigowdade697412013-02-14 16:31:48 -08002203
Jeff Johnson295189b2012-06-20 16:38:30 -07002204 /* Change band request received */
Srinivas Girigowdade697412013-02-14 16:31:48 -08002205
2206 /* First 8 bytes will have "SETBAND " and
Jeff Johnson295189b2012-06-20 16:38:30 -07002207 * 9 byte will have band setting value */
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07002208 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Amar Singhal0974e402013-02-12 14:27:46 -08002209 "%s: SetBandCommand Info comm %s UL %d, TL %d", __func__, command, priv_data.used_len, priv_data.total_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07002210 /* Change band request received */
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002211 ret = hdd_setBand_helper(pAdapter->dev, ptr);
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05302212 if(ret < 0)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302213 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002214 "%s: failed to set band ret=%d", __func__, ret);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002215 }
Kiet Lamf040f472013-11-20 21:15:23 +05302216 else if(strncmp(command, "SETWMMPS", 8) == 0)
2217 {
2218 tANI_U8 *ptr = command;
2219 ret = hdd_wmmps_helper(pAdapter, ptr);
2220 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07002221 else if ( strncasecmp(command, "COUNTRY", 7) == 0 )
2222 {
2223 char *country_code;
2224
2225 country_code = command + 8;
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07002226
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002227 INIT_COMPLETION(pAdapter->change_country_code);
Tushnim Bhattacharyya9cdf6082013-04-21 16:33:30 -07002228 hdd_checkandupdate_dfssetting(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07002229#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkaladacbcb52013-04-18 16:41:54 +05302230 hdd_checkandupdate_phymode(pAdapter, country_code);
Tushnim Bhattacharyya71ccecc2013-10-14 16:22:56 -07002231#endif
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002232 ret = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2233 (void *)(tSmeChangeCountryCallback)
2234 wlan_hdd_change_country_code_callback,
Abhishek Singha306a442013-11-07 18:39:01 +05302235 country_code, pAdapter, pHddCtx->pvosContext, eSIR_TRUE, eSIR_TRUE);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002236 if (eHAL_STATUS_SUCCESS == ret)
2237 {
2238 ret = wait_for_completion_interruptible_timeout(
2239 &pAdapter->change_country_code,
2240 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
2241 if (0 >= ret)
2242 {
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002243 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: SME while setting country code timed out %d",
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302244 __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002245 }
2246 }
2247 else
Jeff Johnson32d95a32012-09-10 13:15:23 -07002248 {
2249 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002250 "%s: SME Change Country code fail ret=%d", __func__, ret);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002251 ret = -EINVAL;
Jeff Johnson32d95a32012-09-10 13:15:23 -07002252 }
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07002253
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07002254 }
2255 /*
2256 command should be a string having format
2257 SET_SAP_CHANNEL_LIST <num of channels> <the channels seperated by spaces>
2258 */
Amar Singhal0974e402013-02-12 14:27:46 -08002259 else if(strncmp(command, "SET_SAP_CHANNEL_LIST", 20) == 0)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07002260 {
Amar Singhal0974e402013-02-12 14:27:46 -08002261 tANI_U8 *ptr = command;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07002262
2263 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002264 " Received Command to Set Preferred Channels for SAP in %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07002265
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -08002266 ret = sapSetPreferredChannel(ptr);
Jeff Johnson32d95a32012-09-10 13:15:23 -07002267 }
Sameer Thalappil45931fb2013-02-01 11:18:05 -08002268 else if(strncmp(command, "SETSUSPENDMODE", 14) == 0)
2269 {
2270 int suspend = 0;
2271 tANI_U8 *ptr = (tANI_U8*)command + 15;
2272
2273 suspend = *ptr - '0';
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302274 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2275 TRACE_CODE_HDD_SETSUSPENDMODE_IOCTL,
2276 pAdapter->sessionId, suspend));
Sameer Thalappil45931fb2013-02-01 11:18:05 -08002277 hdd_set_wlan_suspend_mode(suspend);
2278 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08002279#ifdef WLAN_FEATURE_NEIGHBOR_ROAMING
2280 else if (strncmp(command, "SETROAMTRIGGER", 14) == 0)
2281 {
2282 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002283 tANI_S8 rssi = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08002284 tANI_U8 lookUpThreshold = CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_DEFAULT;
2285 eHalStatus status = eHAL_STATUS_SUCCESS;
2286
2287 /* Move pointer to ahead of SETROAMTRIGGER<delimiter> */
2288 value = value + 15;
2289
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002290 /* Convert the value from ascii to integer */
2291 ret = kstrtos8(value, 10, &rssi);
2292 if (ret < 0)
2293 {
2294 /* If the input value is greater than max value of datatype, then also
2295 kstrtou8 fails */
2296 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2297 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdafa7157d2013-10-31 10:14:22 -07002298 __func__,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002299 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
2300 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
2301 ret = -EINVAL;
2302 goto exit;
2303 }
2304
Srinivas Girigowdade697412013-02-14 16:31:48 -08002305 lookUpThreshold = abs(rssi);
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002306
Srinivas Girigowdade697412013-02-14 16:31:48 -08002307 if ((lookUpThreshold < CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN) ||
2308 (lookUpThreshold > CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX))
2309 {
2310 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2311 "Neighbor lookup threshold value %d is out of range"
2312 " (Min: %d Max: %d)", lookUpThreshold,
2313 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MIN,
2314 CFG_NEIGHBOR_LOOKUP_RSSI_THRESHOLD_MAX);
2315 ret = -EINVAL;
2316 goto exit;
2317 }
2318
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302319 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2320 TRACE_CODE_HDD_SETROAMTRIGGER_IOCTL,
2321 pAdapter->sessionId, lookUpThreshold));
Srinivas Girigowdade697412013-02-14 16:31:48 -08002322 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2323 "%s: Received Command to Set Roam trigger"
2324 " (Neighbor lookup threshold) = %d", __func__, lookUpThreshold);
2325
2326 pHddCtx->cfg_ini->nNeighborLookupRssiThreshold = lookUpThreshold;
2327 status = sme_setNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold);
2328 if (eHAL_STATUS_SUCCESS != status)
2329 {
2330 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2331 "%s: Failed to set roam trigger, try again", __func__);
2332 ret = -EPERM;
2333 goto exit;
2334 }
2335
2336 /* Set Reassoc threshold to (lookup rssi threshold + 5 dBm) */
mukul sharmad6e1fdd2014-06-23 19:19:09 +05302337 pHddCtx->cfg_ini->nNeighborReassocRssiThreshold = lookUpThreshold + 5;
Srinivas Girigowdade697412013-02-14 16:31:48 -08002338 sme_setNeighborReassocRssiThreshold((tHalHandle)(pHddCtx->hHal), lookUpThreshold + 5);
2339 }
2340 else if (strncmp(command, "GETROAMTRIGGER", 14) == 0)
2341 {
2342 tANI_U8 lookUpThreshold = sme_getNeighborLookupRssiThreshold((tHalHandle)(pHddCtx->hHal));
2343 int rssi = (-1) * lookUpThreshold;
2344 char extra[32];
2345 tANI_U8 len = 0;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302346 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2347 TRACE_CODE_HDD_GETROAMTRIGGER_IOCTL,
2348 pAdapter->sessionId, lookUpThreshold));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002349 len = scnprintf(extra, sizeof(extra), "%s %d", command, rssi);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002350 if (copy_to_user(priv_data.buf, &extra, len + 1))
2351 {
2352 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2353 "%s: failed to copy data to user buffer", __func__);
2354 ret = -EFAULT;
2355 goto exit;
2356 }
2357 }
2358 else if (strncmp(command, "SETROAMSCANPERIOD", 17) == 0)
2359 {
2360 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002361 tANI_U8 roamScanPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002362 tANI_U16 neighborEmptyScanRefreshPeriod = CFG_EMPTY_SCAN_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002363
Srinivas Girigowdade697412013-02-14 16:31:48 -08002364 /* input refresh period is in terms of seconds */
2365 /* Move pointer to ahead of SETROAMSCANPERIOD<delimiter> */
2366 value = value + 18;
2367 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002368 ret = kstrtou8(value, 10, &roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002369 if (ret < 0)
2370 {
2371 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002372 kstrtou8 fails */
Srinivas Girigowdade697412013-02-14 16:31:48 -08002373 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002374 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdade697412013-02-14 16:31:48 -08002375 __func__,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07002376 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
2377 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08002378 ret = -EINVAL;
2379 goto exit;
2380 }
2381
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002382 if ((roamScanPeriod < (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000)) ||
2383 (roamScanPeriod > (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000)))
Srinivas Girigowdade697412013-02-14 16:31:48 -08002384 {
2385 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002386 "Roam scan period value %d is out of range"
2387 " (Min: %d Max: %d)", roamScanPeriod,
Srinivas Girigowdab8edd1e2013-03-19 11:42:08 -07002388 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MIN/1000),
2389 (CFG_EMPTY_SCAN_REFRESH_PERIOD_MAX/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08002390 ret = -EINVAL;
2391 goto exit;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302392 }
2393 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2394 TRACE_CODE_HDD_SETROAMSCANPERIOD_IOCTL,
2395 pAdapter->sessionId, roamScanPeriod));
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002396 neighborEmptyScanRefreshPeriod = roamScanPeriod * 1000;
Srinivas Girigowdade697412013-02-14 16:31:48 -08002397
2398 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2399 "%s: Received Command to Set roam scan period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002400 " (Empty Scan refresh period) = %d", __func__, roamScanPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002401
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002402 pHddCtx->cfg_ini->nEmptyScanRefreshPeriod = neighborEmptyScanRefreshPeriod;
2403 sme_UpdateEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborEmptyScanRefreshPeriod);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002404 }
2405 else if (strncmp(command, "GETROAMSCANPERIOD", 17) == 0)
2406 {
2407 tANI_U16 nEmptyScanRefreshPeriod = sme_getEmptyScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
2408 char extra[32];
2409 tANI_U8 len = 0;
2410
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302411 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2412 TRACE_CODE_HDD_GETROAMSCANPERIOD_IOCTL,
2413 pAdapter->sessionId, nEmptyScanRefreshPeriod));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002414 len = scnprintf(extra, sizeof(extra), "%s %d",
2415 "GETROAMSCANPERIOD", (nEmptyScanRefreshPeriod/1000));
Srinivas Girigowdade697412013-02-14 16:31:48 -08002416 /* Returned value is in units of seconds */
2417 if (copy_to_user(priv_data.buf, &extra, len + 1))
2418 {
2419 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2420 "%s: failed to copy data to user buffer", __func__);
2421 ret = -EFAULT;
2422 goto exit;
2423 }
2424 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002425 else if (strncmp(command, "SETROAMSCANREFRESHPERIOD", 24) == 0)
2426 {
2427 tANI_U8 *value = command;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002428 tANI_U8 roamScanRefreshPeriod = 0;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002429 tANI_U16 neighborScanRefreshPeriod = CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_DEFAULT;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002430
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002431 /* input refresh period is in terms of seconds */
2432 /* Move pointer to ahead of SETROAMSCANREFRESHPERIOD<delimiter> */
2433 value = value + 25;
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002434
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002435 /* Convert the value from ascii to integer */
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002436 ret = kstrtou8(value, 10, &roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002437 if (ret < 0)
2438 {
2439 /* If the input value is greater than max value of datatype, then also
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002440 kstrtou8 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002441 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002442 "%s: kstrtou8 failed Input value may be out of range[%d - %d]",
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002443 __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002444 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
2445 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
2446 ret = -EINVAL;
2447 goto exit;
2448 }
2449
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002450 if ((roamScanRefreshPeriod < (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000)) ||
2451 (roamScanRefreshPeriod > (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000)))
2452 {
2453 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2454 "Neighbor scan results refresh period value %d is out of range"
2455 " (Min: %d Max: %d)", roamScanRefreshPeriod,
2456 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MIN/1000),
2457 (CFG_NEIGHBOR_SCAN_RESULTS_REFRESH_PERIOD_MAX/1000));
2458 ret = -EINVAL;
2459 goto exit;
2460 }
2461 neighborScanRefreshPeriod = roamScanRefreshPeriod * 1000;
2462
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002463 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2464 "%s: Received Command to Set roam scan refresh period"
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002465 " (Scan refresh period) = %d", __func__, roamScanRefreshPeriod);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002466
2467 pHddCtx->cfg_ini->nNeighborResultsRefreshPeriod = neighborScanRefreshPeriod;
2468 sme_setNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal), neighborScanRefreshPeriod);
2469 }
2470 else if (strncmp(command, "GETROAMSCANREFRESHPERIOD", 24) == 0)
2471 {
2472 tANI_U16 value = sme_getNeighborScanRefreshPeriod((tHalHandle)(pHddCtx->hHal));
2473 char extra[32];
2474 tANI_U8 len = 0;
2475
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002476 len = scnprintf(extra, sizeof(extra), "%s %d",
2477 "GETROAMSCANREFRESHPERIOD", (value/1000));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002478 /* Returned value is in units of seconds */
2479 if (copy_to_user(priv_data.buf, &extra, len + 1))
2480 {
2481 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2482 "%s: failed to copy data to user buffer", __func__);
2483 ret = -EFAULT;
2484 goto exit;
2485 }
2486 }
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07002487#ifdef FEATURE_WLAN_LFR
2488 /* SETROAMMODE */
2489 else if (strncmp(command, "SETROAMMODE", SIZE_OF_SETROAMMODE) == 0)
2490 {
2491 tANI_U8 *value = command;
2492 tANI_BOOLEAN roamMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
2493
2494 /* Move pointer to ahead of SETROAMMODE<delimiter> */
2495 value = value + SIZE_OF_SETROAMMODE + 1;
2496
2497 /* Convert the value from ascii to integer */
2498 ret = kstrtou8(value, SIZE_OF_SETROAMMODE, &roamMode);
2499 if (ret < 0)
2500 {
2501 /* If the input value is greater than max value of datatype, then also
2502 kstrtou8 fails */
2503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2504 "%s: kstrtou8 failed range [%d - %d]", __func__,
2505 CFG_LFR_FEATURE_ENABLED_MIN,
2506 CFG_LFR_FEATURE_ENABLED_MAX);
2507 ret = -EINVAL;
2508 goto exit;
2509 }
2510 if ((roamMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
2511 (roamMode > CFG_LFR_FEATURE_ENABLED_MAX))
2512 {
2513 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2514 "Roam Mode value %d is out of range"
2515 " (Min: %d Max: %d)", roamMode,
2516 CFG_LFR_FEATURE_ENABLED_MIN,
2517 CFG_LFR_FEATURE_ENABLED_MAX);
2518 ret = -EINVAL;
2519 goto exit;
2520 }
2521
2522 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2523 "%s: Received Command to Set Roam Mode = %d", __func__, roamMode);
2524 /*
2525 * Note that
2526 * SETROAMMODE 0 is to enable LFR while
2527 * SETROAMMODE 1 is to disable LFR, but
2528 * NotifyIsFastRoamIniFeatureEnabled 0/1 is to enable/disable.
2529 * So, we have to invert the value to call sme_UpdateIsFastRoamIniFeatureEnabled.
2530 */
2531 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
2532 roamMode = CFG_LFR_FEATURE_ENABLED_MAX; /* Roam enable */
2533 else
2534 roamMode = CFG_LFR_FEATURE_ENABLED_MIN; /* Roam disable */
2535
2536 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = roamMode;
2537 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), roamMode);
2538 }
2539 /* GETROAMMODE */
2540 else if (strncmp(priv_data.buf, "GETROAMMODE", SIZE_OF_GETROAMMODE) == 0)
2541 {
2542 tANI_BOOLEAN roamMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
2543 char extra[32];
2544 tANI_U8 len = 0;
2545
2546 /*
2547 * roamMode value shall be inverted because the sementics is different.
2548 */
2549 if (CFG_LFR_FEATURE_ENABLED_MIN == roamMode)
2550 roamMode = CFG_LFR_FEATURE_ENABLED_MAX;
2551 else
2552 roamMode = CFG_LFR_FEATURE_ENABLED_MIN;
2553
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002554 len = scnprintf(extra, sizeof(extra), "%s %d", command, roamMode);
Varun Reddy Yeturu6d99ac82013-05-08 14:15:35 -07002555 if (copy_to_user(priv_data.buf, &extra, len + 1))
2556 {
2557 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2558 "%s: failed to copy data to user buffer", __func__);
2559 ret = -EFAULT;
2560 goto exit;
2561 }
2562 }
2563#endif
Srinivas Girigowdade697412013-02-14 16:31:48 -08002564#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002565#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08002566 else if (strncmp(command, "SETROAMDELTA", 12) == 0)
2567 {
2568 tANI_U8 *value = command;
2569 tANI_U8 roamRssiDiff = CFG_ROAM_RSSI_DIFF_DEFAULT;
2570
2571 /* Move pointer to ahead of SETROAMDELTA<delimiter> */
2572 value = value + 13;
2573 /* Convert the value from ascii to integer */
2574 ret = kstrtou8(value, 10, &roamRssiDiff);
2575 if (ret < 0)
2576 {
2577 /* If the input value is greater than max value of datatype, then also
2578 kstrtou8 fails */
2579 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2580 "%s: kstrtou8 failed range [%d - %d]", __func__,
2581 CFG_ROAM_RSSI_DIFF_MIN,
2582 CFG_ROAM_RSSI_DIFF_MAX);
2583 ret = -EINVAL;
2584 goto exit;
2585 }
2586
2587 if ((roamRssiDiff < CFG_ROAM_RSSI_DIFF_MIN) ||
2588 (roamRssiDiff > CFG_ROAM_RSSI_DIFF_MAX))
2589 {
2590 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2591 "Roam rssi diff value %d is out of range"
2592 " (Min: %d Max: %d)", roamRssiDiff,
2593 CFG_ROAM_RSSI_DIFF_MIN,
2594 CFG_ROAM_RSSI_DIFF_MAX);
2595 ret = -EINVAL;
2596 goto exit;
2597 }
2598
2599 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2600 "%s: Received Command to Set roam rssi diff = %d", __func__, roamRssiDiff);
2601
2602 pHddCtx->cfg_ini->RoamRssiDiff = roamRssiDiff;
2603 sme_UpdateRoamRssiDiff((tHalHandle)(pHddCtx->hHal), roamRssiDiff);
2604 }
2605 else if (strncmp(priv_data.buf, "GETROAMDELTA", 12) == 0)
2606 {
2607 tANI_U8 roamRssiDiff = sme_getRoamRssiDiff((tHalHandle)(pHddCtx->hHal));
2608 char extra[32];
2609 tANI_U8 len = 0;
2610
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302611 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2612 TRACE_CODE_HDD_GETROAMDELTA_IOCTL,
2613 pAdapter->sessionId, roamRssiDiff));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002614 len = scnprintf(extra, sizeof(extra), "%s %d",
2615 command, roamRssiDiff);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002616 if (copy_to_user(priv_data.buf, &extra, len + 1))
2617 {
2618 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2619 "%s: failed to copy data to user buffer", __func__);
2620 ret = -EFAULT;
2621 goto exit;
2622 }
2623 }
2624#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002625#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08002626 else if (strncmp(command, "GETBAND", 7) == 0)
2627 {
2628 int band = -1;
2629 char extra[32];
2630 tANI_U8 len = 0;
2631 hdd_getBand_helper(pHddCtx, &band);
2632
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302633 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2634 TRACE_CODE_HDD_GETBAND_IOCTL,
2635 pAdapter->sessionId, band));
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002636 len = scnprintf(extra, sizeof(extra), "%s %d", command, band);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002637 if (copy_to_user(priv_data.buf, &extra, len + 1))
2638 {
2639 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2640 "%s: failed to copy data to user buffer", __func__);
2641 ret = -EFAULT;
2642 goto exit;
2643 }
2644 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08002645 else if (strncmp(command, "SETROAMSCANCHANNELS", 19) == 0)
2646 {
2647 tANI_U8 *value = command;
2648 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
2649 tANI_U8 numChannels = 0;
2650 eHalStatus status = eHAL_STATUS_SUCCESS;
2651
2652 status = hdd_parse_channellist(value, ChannelList, &numChannels);
2653 if (eHAL_STATUS_SUCCESS != status)
2654 {
2655 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2656 "%s: Failed to parse channel list information", __func__);
2657 ret = -EINVAL;
2658 goto exit;
2659 }
2660
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302661 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2662 TRACE_CODE_HDD_SETROAMSCANCHANNELS_IOCTL,
2663 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08002664 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
2665 {
2666 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2667 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
2668 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
2669 ret = -EINVAL;
2670 goto exit;
2671 }
2672 status = sme_ChangeRoamScanChannelList((tHalHandle)(pHddCtx->hHal), ChannelList,
2673 numChannels);
2674 if (eHAL_STATUS_SUCCESS != status)
2675 {
2676 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2677 "%s: Failed to update channel list information", __func__);
2678 ret = -EINVAL;
2679 goto exit;
2680 }
2681 }
2682 else if (strncmp(command, "GETROAMSCANCHANNELS", 19) == 0)
2683 {
2684 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
2685 tANI_U8 numChannels = 0;
Jeff Johnson51b67782013-04-05 12:35:41 -07002686 tANI_U8 j = 0;
Srinivas Girigowdade697412013-02-14 16:31:48 -08002687 char extra[128] = {0};
Jeff Johnson51b67782013-04-05 12:35:41 -07002688 int len;
Srinivas Girigowdade697412013-02-14 16:31:48 -08002689
2690 if (eHAL_STATUS_SUCCESS != sme_getRoamScanChannelList( (tHalHandle)(pHddCtx->hHal),
2691 ChannelList, &numChannels ))
2692 {
2693 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2694 "%s: failed to get roam scan channel list", __func__);
2695 ret = -EFAULT;
2696 goto exit;
2697 }
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302698 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2699 TRACE_CODE_HDD_GETROAMSCANCHANNELS_IOCTL,
2700 pAdapter->sessionId, numChannels));
Srinivas Girigowdade697412013-02-14 16:31:48 -08002701 /* output channel list is of the format
2702 [Number of roam scan channels][Channel1][Channel2]... */
2703 /* copy the number of channels in the 0th index */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002704 len = scnprintf(extra, sizeof(extra), "%s %d", command, numChannels);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002705 for (j = 0; (j < numChannels); j++)
2706 {
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002707 len += scnprintf(extra + len, sizeof(extra) - len, " %d",
2708 ChannelList[j]);
Srinivas Girigowdade697412013-02-14 16:31:48 -08002709 }
2710
2711 if (copy_to_user(priv_data.buf, &extra, len + 1))
2712 {
2713 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2714 "%s: failed to copy data to user buffer", __func__);
2715 ret = -EFAULT;
2716 goto exit;
2717 }
2718 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002719 else if (strncmp(command, "GETCCXMODE", 10) == 0)
2720 {
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002721 tANI_BOOLEAN eseMode = sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002722 char extra[32];
2723 tANI_U8 len = 0;
2724
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002725 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07002726 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002727 if (eseMode &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07002728 hdd_is_okc_mode_enabled(pHddCtx) &&
2729 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
2730 {
2731 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002732 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07002733 " hence this operation is not permitted!", __func__);
2734 ret = -EPERM;
2735 goto exit;
2736 }
2737
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002738 len = scnprintf(extra, sizeof(extra), "%s %d",
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002739 "GETCCXMODE", eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002740 if (copy_to_user(priv_data.buf, &extra, len + 1))
2741 {
2742 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2743 "%s: failed to copy data to user buffer", __func__);
2744 ret = -EFAULT;
2745 goto exit;
2746 }
2747 }
2748 else if (strncmp(command, "GETOKCMODE", 10) == 0)
2749 {
2750 tANI_BOOLEAN okcMode = hdd_is_okc_mode_enabled(pHddCtx);
2751 char extra[32];
2752 tANI_U8 len = 0;
2753
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002754 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07002755 then this operation is not permitted (return FAILURE) */
2756 if (okcMode &&
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002757 sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07002758 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
2759 {
2760 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002761 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07002762 " hence this operation is not permitted!", __func__);
2763 ret = -EPERM;
2764 goto exit;
2765 }
2766
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002767 len = scnprintf(extra, sizeof(extra), "%s %d",
2768 "GETOKCMODE", okcMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002769 if (copy_to_user(priv_data.buf, &extra, len + 1))
2770 {
2771 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2772 "%s: failed to copy data to user buffer", __func__);
2773 ret = -EFAULT;
2774 goto exit;
2775 }
2776 }
Srinivas Girigowdacb4c6412013-07-02 10:19:12 -07002777 else if (strncmp(command, "GETFASTROAM", 11) == 0)
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002778 {
2779 tANI_BOOLEAN lfrMode = sme_getIsLfrFeatureEnabled((tHalHandle)(pHddCtx->hHal));
2780 char extra[32];
2781 tANI_U8 len = 0;
2782
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002783 len = scnprintf(extra, sizeof(extra), "%s %d",
2784 "GETFASTROAM", lfrMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002785 if (copy_to_user(priv_data.buf, &extra, len + 1))
2786 {
2787 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2788 "%s: failed to copy data to user buffer", __func__);
2789 ret = -EFAULT;
2790 goto exit;
2791 }
2792 }
2793 else if (strncmp(command, "GETFASTTRANSITION", 17) == 0)
2794 {
2795 tANI_BOOLEAN ft = sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal));
2796 char extra[32];
2797 tANI_U8 len = 0;
2798
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002799 len = scnprintf(extra, sizeof(extra), "%s %d",
2800 "GETFASTTRANSITION", ft);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002801 if (copy_to_user(priv_data.buf, &extra, len + 1))
2802 {
2803 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2804 "%s: failed to copy data to user buffer", __func__);
2805 ret = -EFAULT;
2806 goto exit;
2807 }
2808 }
2809 else if (strncmp(command, "SETROAMSCANCHANNELMINTIME", 25) == 0)
2810 {
2811 tANI_U8 *value = command;
2812 tANI_U8 minTime = CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_DEFAULT;
2813
2814 /* Move pointer to ahead of SETROAMSCANCHANNELMINTIME<delimiter> */
2815 value = value + 26;
2816 /* Convert the value from ascii to integer */
2817 ret = kstrtou8(value, 10, &minTime);
2818 if (ret < 0)
2819 {
2820 /* If the input value is greater than max value of datatype, then also
2821 kstrtou8 fails */
2822 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2823 "%s: kstrtou8 failed range [%d - %d]", __func__,
2824 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
2825 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
2826 ret = -EINVAL;
2827 goto exit;
2828 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002829 if ((minTime < CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN) ||
2830 (minTime > CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX))
2831 {
2832 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2833 "scan min channel time value %d is out of range"
2834 " (Min: %d Max: %d)", minTime,
2835 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MIN,
2836 CFG_NEIGHBOR_SCAN_MIN_CHAN_TIME_MAX);
2837 ret = -EINVAL;
2838 goto exit;
2839 }
2840
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302841 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2842 TRACE_CODE_HDD_SETROAMSCANCHANNELMINTIME_IOCTL,
2843 pAdapter->sessionId, minTime));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002844 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2845 "%s: Received Command to change channel min time = %d", __func__, minTime);
2846
2847 pHddCtx->cfg_ini->nNeighborScanMinChanTime = minTime;
2848 sme_setNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal), minTime);
2849 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07002850 else if (strncmp(command, "SENDACTIONFRAME", 15) == 0)
2851 {
2852 tANI_U8 *value = command;
2853 tANI_U8 channel = 0;
2854 tANI_U8 dwellTime = 0;
2855 tANI_U8 bufLen = 0;
2856 tANI_U8 *buf = NULL;
2857 tSirMacAddr targetApBssid;
2858 eHalStatus status = eHAL_STATUS_SUCCESS;
2859 struct ieee80211_channel chan;
2860 tANI_U8 finalLen = 0;
2861 tANI_U8 *finalBuf = NULL;
2862 tANI_U8 temp = 0;
2863 u64 cookie;
2864 hdd_station_ctx_t *pHddStaCtx = NULL;
2865 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2866
2867 /* if not associated, no need to send action frame */
2868 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
2869 {
2870 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
2871 ret = -EINVAL;
2872 goto exit;
2873 }
2874
2875 status = hdd_parse_send_action_frame_data(value, targetApBssid, &channel,
2876 &dwellTime, &buf, &bufLen);
2877 if (eHAL_STATUS_SUCCESS != status)
2878 {
2879 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2880 "%s: Failed to parse send action frame data", __func__);
2881 ret = -EINVAL;
2882 goto exit;
2883 }
2884
2885 /* if the target bssid is different from currently associated AP,
2886 then no need to send action frame */
2887 if (VOS_TRUE != vos_mem_compare(targetApBssid,
2888 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
2889 {
2890 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:STA is not associated to this AP!",__func__);
2891 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07002892 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002893 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07002894 goto exit;
2895 }
2896
2897 /* if the channel number is different from operating channel then
2898 no need to send action frame */
2899 if (channel != pHddStaCtx->conn_info.operationChannel)
2900 {
2901 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2902 "%s: channel(%d) is different from operating channel(%d)",
2903 __func__, channel, pHddStaCtx->conn_info.operationChannel);
2904 ret = -EINVAL;
Jeff Johnson11c33152013-04-16 17:52:40 -07002905 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002906 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07002907 goto exit;
2908 }
2909 chan.center_freq = sme_ChnToFreq(channel);
2910
2911 finalLen = bufLen + 24;
2912 finalBuf = vos_mem_malloc(finalLen);
2913 if (NULL == finalBuf)
2914 {
2915 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:memory allocation failed",__func__);
2916 ret = -ENOMEM;
Jeff Johnson11c33152013-04-16 17:52:40 -07002917 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002918 buf = NULL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07002919 goto exit;
2920 }
2921 vos_mem_zero(finalBuf, finalLen);
2922
2923 /* Fill subtype */
2924 temp = SIR_MAC_MGMT_ACTION << 4;
2925 vos_mem_copy(finalBuf + 0, &temp, sizeof(temp));
2926
2927 /* Fill type */
2928 temp = SIR_MAC_MGMT_FRAME;
2929 vos_mem_copy(finalBuf + 2, &temp, sizeof(temp));
2930
2931 /* Fill destination address (bssid of the AP) */
2932 vos_mem_copy(finalBuf + 4, targetApBssid, sizeof(targetApBssid));
2933
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07002934 /* Fill source address (STA mac address) */
Srinivas Girigowda100eb322013-03-15 16:48:20 -07002935 vos_mem_copy(finalBuf + 10, pAdapter->macAddressCurrent.bytes, sizeof(pAdapter->macAddressCurrent.bytes));
2936
Srinivas Girigowdab27c0192013-06-03 10:19:56 -07002937 /* Fill BSSID (AP mac address) */
2938 vos_mem_copy(finalBuf + 16, targetApBssid, sizeof(targetApBssid));
Srinivas Girigowda100eb322013-03-15 16:48:20 -07002939
2940 /* Fill received buffer from 24th address */
2941 vos_mem_copy(finalBuf + 24, buf, bufLen);
2942
Jeff Johnson11c33152013-04-16 17:52:40 -07002943 /* done with the parsed buffer */
2944 vos_mem_free(buf);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08002945 buf = NULL;
Jeff Johnson11c33152013-04-16 17:52:40 -07002946
DARAM SUDHA39eede62014-02-12 11:16:40 +05302947 wlan_hdd_mgmt_tx( NULL,
Yue Maf49ba872013-08-19 12:04:25 -07002948#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
2949 &(pAdapter->wdev),
2950#else
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07002951 pAdapter->dev,
Yue Maf49ba872013-08-19 12:04:25 -07002952#endif
2953 &chan, 0,
2954#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2955 NL80211_CHAN_HT20, 1,
2956#endif
2957 dwellTime, finalBuf, finalLen, 1,
Srinivas Girigowda100eb322013-03-15 16:48:20 -07002958 1, &cookie );
2959 vos_mem_free(finalBuf);
2960 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002961 else if (strncmp(command, "GETROAMSCANCHANNELMINTIME", 25) == 0)
2962 {
2963 tANI_U16 val = sme_getNeighborScanMinChanTime((tHalHandle)(pHddCtx->hHal));
2964 char extra[32];
2965 tANI_U8 len = 0;
2966
2967 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002968 len = scnprintf(extra, sizeof(extra), "%s %d",
2969 "GETROAMSCANCHANNELMINTIME", val);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302970 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2971 TRACE_CODE_HDD_GETROAMSCANCHANNELMINTIME_IOCTL,
2972 pAdapter->sessionId, val));
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002973 if (copy_to_user(priv_data.buf, &extra, len + 1))
2974 {
2975 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2976 "%s: failed to copy data to user buffer", __func__);
2977 ret = -EFAULT;
2978 goto exit;
2979 }
2980 }
2981 else if (strncmp(command, "SETSCANCHANNELTIME", 18) == 0)
2982 {
2983 tANI_U8 *value = command;
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07002984 tANI_U16 maxTime = CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002985
2986 /* Move pointer to ahead of SETSCANCHANNELTIME<delimiter> */
2987 value = value + 19;
2988 /* Convert the value from ascii to integer */
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07002989 ret = kstrtou16(value, 10, &maxTime);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002990 if (ret < 0)
2991 {
2992 /* If the input value is greater than max value of datatype, then also
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07002993 kstrtou16 fails */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002994 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu3885a662013-06-19 07:10:37 -07002995 "%s: kstrtou16 failed range [%d - %d]", __func__,
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07002996 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
2997 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
2998 ret = -EINVAL;
2999 goto exit;
3000 }
3001
3002 if ((maxTime < CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN) ||
3003 (maxTime > CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX))
3004 {
3005 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3006 "lfr mode value %d is out of range"
3007 " (Min: %d Max: %d)", maxTime,
3008 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MIN,
3009 CFG_NEIGHBOR_SCAN_MAX_CHAN_TIME_MAX);
3010 ret = -EINVAL;
3011 goto exit;
3012 }
3013
3014 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3015 "%s: Received Command to change channel max time = %d", __func__, maxTime);
3016
3017 pHddCtx->cfg_ini->nNeighborScanMaxChanTime = maxTime;
3018 sme_setNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal), maxTime);
3019 }
3020 else if (strncmp(command, "GETSCANCHANNELTIME", 18) == 0)
3021 {
3022 tANI_U16 val = sme_getNeighborScanMaxChanTime((tHalHandle)(pHddCtx->hHal));
3023 char extra[32];
3024 tANI_U8 len = 0;
3025
3026 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003027 len = scnprintf(extra, sizeof(extra), "%s %d",
3028 "GETSCANCHANNELTIME", val);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003029 if (copy_to_user(priv_data.buf, &extra, len + 1))
3030 {
3031 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3032 "%s: failed to copy data to user buffer", __func__);
3033 ret = -EFAULT;
3034 goto exit;
3035 }
3036 }
3037 else if (strncmp(command, "SETSCANHOMETIME", 15) == 0)
3038 {
3039 tANI_U8 *value = command;
3040 tANI_U16 val = CFG_NEIGHBOR_SCAN_TIMER_PERIOD_DEFAULT;
3041
3042 /* Move pointer to ahead of SETSCANHOMETIME<delimiter> */
3043 value = value + 16;
3044 /* Convert the value from ascii to integer */
3045 ret = kstrtou16(value, 10, &val);
3046 if (ret < 0)
3047 {
3048 /* If the input value is greater than max value of datatype, then also
3049 kstrtou16 fails */
3050 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3051 "%s: kstrtou16 failed range [%d - %d]", __func__,
3052 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
3053 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
3054 ret = -EINVAL;
3055 goto exit;
3056 }
3057
3058 if ((val < CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN) ||
3059 (val > CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX))
3060 {
3061 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3062 "scan home time value %d is out of range"
3063 " (Min: %d Max: %d)", val,
3064 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MIN,
3065 CFG_NEIGHBOR_SCAN_TIMER_PERIOD_MAX);
3066 ret = -EINVAL;
3067 goto exit;
3068 }
3069
3070 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3071 "%s: Received Command to change scan home time = %d", __func__, val);
3072
3073 pHddCtx->cfg_ini->nNeighborScanPeriod = val;
3074 sme_setNeighborScanPeriod((tHalHandle)(pHddCtx->hHal), val);
3075 }
3076 else if (strncmp(command, "GETSCANHOMETIME", 15) == 0)
3077 {
3078 tANI_U16 val = sme_getNeighborScanPeriod((tHalHandle)(pHddCtx->hHal));
3079 char extra[32];
3080 tANI_U8 len = 0;
3081
3082 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003083 len = scnprintf(extra, sizeof(extra), "%s %d",
3084 "GETSCANHOMETIME", val);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003085 if (copy_to_user(priv_data.buf, &extra, len + 1))
3086 {
3087 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3088 "%s: failed to copy data to user buffer", __func__);
3089 ret = -EFAULT;
3090 goto exit;
3091 }
3092 }
3093 else if (strncmp(command, "SETROAMINTRABAND", 16) == 0)
3094 {
3095 tANI_U8 *value = command;
3096 tANI_U8 val = CFG_ROAM_INTRA_BAND_DEFAULT;
3097
3098 /* Move pointer to ahead of SETROAMINTRABAND<delimiter> */
3099 value = value + 17;
3100 /* Convert the value from ascii to integer */
3101 ret = kstrtou8(value, 10, &val);
3102 if (ret < 0)
3103 {
3104 /* If the input value is greater than max value of datatype, then also
3105 kstrtou8 fails */
3106 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3107 "%s: kstrtou8 failed range [%d - %d]", __func__,
3108 CFG_ROAM_INTRA_BAND_MIN,
3109 CFG_ROAM_INTRA_BAND_MAX);
3110 ret = -EINVAL;
3111 goto exit;
3112 }
3113
3114 if ((val < CFG_ROAM_INTRA_BAND_MIN) ||
3115 (val > CFG_ROAM_INTRA_BAND_MAX))
3116 {
3117 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3118 "intra band mode value %d is out of range"
3119 " (Min: %d Max: %d)", val,
3120 CFG_ROAM_INTRA_BAND_MIN,
3121 CFG_ROAM_INTRA_BAND_MAX);
3122 ret = -EINVAL;
3123 goto exit;
3124 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003125 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3126 "%s: Received Command to change intra band = %d", __func__, val);
3127
3128 pHddCtx->cfg_ini->nRoamIntraBand = val;
3129 sme_setRoamIntraBand((tHalHandle)(pHddCtx->hHal), val);
3130 }
3131 else if (strncmp(command, "GETROAMINTRABAND", 16) == 0)
3132 {
3133 tANI_U16 val = sme_getRoamIntraBand((tHalHandle)(pHddCtx->hHal));
3134 char extra[32];
3135 tANI_U8 len = 0;
3136
3137 /* value is interms of msec */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003138 len = scnprintf(extra, sizeof(extra), "%s %d",
3139 "GETROAMINTRABAND", val);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003140 if (copy_to_user(priv_data.buf, &extra, len + 1))
3141 {
3142 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3143 "%s: failed to copy data to user buffer", __func__);
3144 ret = -EFAULT;
3145 goto exit;
3146 }
3147 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003148 else if (strncmp(command, "SETSCANNPROBES", 14) == 0)
3149 {
3150 tANI_U8 *value = command;
3151 tANI_U8 nProbes = CFG_ROAM_SCAN_N_PROBES_DEFAULT;
3152
3153 /* Move pointer to ahead of SETSCANNPROBES<delimiter> */
3154 value = value + 15;
3155 /* Convert the value from ascii to integer */
3156 ret = kstrtou8(value, 10, &nProbes);
3157 if (ret < 0)
3158 {
3159 /* If the input value is greater than max value of datatype, then also
3160 kstrtou8 fails */
3161 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3162 "%s: kstrtou8 failed range [%d - %d]", __func__,
3163 CFG_ROAM_SCAN_N_PROBES_MIN,
3164 CFG_ROAM_SCAN_N_PROBES_MAX);
3165 ret = -EINVAL;
3166 goto exit;
3167 }
3168
3169 if ((nProbes < CFG_ROAM_SCAN_N_PROBES_MIN) ||
3170 (nProbes > CFG_ROAM_SCAN_N_PROBES_MAX))
3171 {
3172 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3173 "NProbes value %d is out of range"
3174 " (Min: %d Max: %d)", nProbes,
3175 CFG_ROAM_SCAN_N_PROBES_MIN,
3176 CFG_ROAM_SCAN_N_PROBES_MAX);
3177 ret = -EINVAL;
3178 goto exit;
3179 }
3180
3181 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3182 "%s: Received Command to Set nProbes = %d", __func__, nProbes);
3183
3184 pHddCtx->cfg_ini->nProbes = nProbes;
3185 sme_UpdateRoamScanNProbes((tHalHandle)(pHddCtx->hHal), nProbes);
3186 }
3187 else if (strncmp(priv_data.buf, "GETSCANNPROBES", 14) == 0)
3188 {
3189 tANI_U8 val = sme_getRoamScanNProbes((tHalHandle)(pHddCtx->hHal));
3190 char extra[32];
3191 tANI_U8 len = 0;
3192
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003193 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003194 if (copy_to_user(priv_data.buf, &extra, len + 1))
3195 {
3196 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3197 "%s: failed to copy data to user buffer", __func__);
3198 ret = -EFAULT;
3199 goto exit;
3200 }
3201 }
3202 else if (strncmp(command, "SETSCANHOMEAWAYTIME", 19) == 0)
3203 {
3204 tANI_U8 *value = command;
3205 tANI_U16 homeAwayTime = CFG_ROAM_SCAN_HOME_AWAY_TIME_DEFAULT;
3206
3207 /* Move pointer to ahead of SETSCANHOMEAWAYTIME<delimiter> */
3208 /* input value is in units of msec */
3209 value = value + 20;
3210 /* Convert the value from ascii to integer */
3211 ret = kstrtou16(value, 10, &homeAwayTime);
3212 if (ret < 0)
3213 {
3214 /* If the input value is greater than max value of datatype, then also
3215 kstrtou8 fails */
3216 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3217 "%s: kstrtou8 failed range [%d - %d]", __func__,
3218 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
3219 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
3220 ret = -EINVAL;
3221 goto exit;
3222 }
3223
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003224 if ((homeAwayTime < CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN) ||
3225 (homeAwayTime > CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX))
3226 {
3227 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3228 "homeAwayTime value %d is out of range"
3229 " (Min: %d Max: %d)", homeAwayTime,
3230 CFG_ROAM_SCAN_HOME_AWAY_TIME_MIN,
3231 CFG_ROAM_SCAN_HOME_AWAY_TIME_MAX);
3232 ret = -EINVAL;
3233 goto exit;
3234 }
3235
3236 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3237 "%s: Received Command to Set scan away time = %d", __func__, homeAwayTime);
Srinivas Girigowda6cf0b822013-06-27 14:00:20 -07003238 if (pHddCtx->cfg_ini->nRoamScanHomeAwayTime != homeAwayTime)
3239 {
3240 pHddCtx->cfg_ini->nRoamScanHomeAwayTime = homeAwayTime;
3241 sme_UpdateRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal), homeAwayTime, eANI_BOOLEAN_TRUE);
3242 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003243 }
3244 else if (strncmp(priv_data.buf, "GETSCANHOMEAWAYTIME", 19) == 0)
3245 {
3246 tANI_U16 val = sme_getRoamScanHomeAwayTime((tHalHandle)(pHddCtx->hHal));
3247 char extra[32];
3248 tANI_U8 len = 0;
3249
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003250 len = scnprintf(extra, sizeof(extra), "%s %d", command, val);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003251 if (copy_to_user(priv_data.buf, &extra, len + 1))
3252 {
3253 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3254 "%s: failed to copy data to user buffer", __func__);
3255 ret = -EFAULT;
3256 goto exit;
3257 }
3258 }
3259 else if (strncmp(command, "REASSOC", 7) == 0)
3260 {
3261 tANI_U8 *value = command;
3262 tANI_U8 channel = 0;
3263 tSirMacAddr targetApBssid;
3264 eHalStatus status = eHAL_STATUS_SUCCESS;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07003265#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3266 tCsrHandoffRequest handoffInfo;
3267#endif
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003268 hdd_station_ctx_t *pHddStaCtx = NULL;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003269 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3270
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003271 /* if not associated, no need to proceed with reassoc */
3272 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
3273 {
3274 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
3275 ret = -EINVAL;
3276 goto exit;
3277 }
3278
3279 status = hdd_parse_reassoc_command_data(value, targetApBssid, &channel);
3280 if (eHAL_STATUS_SUCCESS != status)
3281 {
3282 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3283 "%s: Failed to parse reassoc command data", __func__);
3284 ret = -EINVAL;
3285 goto exit;
3286 }
3287
3288 /* if the target bssid is same as currently associated AP,
3289 then no need to proceed with reassoc */
3290 if (VOS_TRUE == vos_mem_compare(targetApBssid,
3291 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
3292 {
3293 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Reassoc BSSID is same as currently associated AP bssid",__func__);
3294 ret = -EINVAL;
3295 goto exit;
3296 }
3297
3298 /* Check channel number is a valid channel number */
3299 if(VOS_STATUS_SUCCESS !=
3300 wlan_hdd_validate_operation_channel(pAdapter, channel))
3301 {
3302 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08003303 "%s: Invalid Channel [%d]", __func__, channel);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003304 return -EINVAL;
3305 }
3306
3307 /* Proceed with reassoc */
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07003308#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3309 handoffInfo.channel = channel;
3310 vos_mem_copy(handoffInfo.bssid, targetApBssid, sizeof(tSirMacAddr));
3311 sme_HandoffRequest(pHddCtx->hHal, &handoffInfo);
3312#endif
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07003313 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07003314 else if (strncmp(command, "SETWESMODE", 10) == 0)
3315 {
3316 tANI_U8 *value = command;
3317 tANI_BOOLEAN wesMode = CFG_ENABLE_WES_MODE_NAME_DEFAULT;
3318
3319 /* Move pointer to ahead of SETWESMODE<delimiter> */
3320 value = value + 11;
3321 /* Convert the value from ascii to integer */
3322 ret = kstrtou8(value, 10, &wesMode);
3323 if (ret < 0)
3324 {
3325 /* If the input value is greater than max value of datatype, then also
3326 kstrtou8 fails */
3327 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3328 "%s: kstrtou8 failed range [%d - %d]", __func__,
3329 CFG_ENABLE_WES_MODE_NAME_MIN,
3330 CFG_ENABLE_WES_MODE_NAME_MAX);
3331 ret = -EINVAL;
3332 goto exit;
3333 }
3334
3335 if ((wesMode < CFG_ENABLE_WES_MODE_NAME_MIN) ||
3336 (wesMode > CFG_ENABLE_WES_MODE_NAME_MAX))
3337 {
3338 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3339 "WES Mode value %d is out of range"
3340 " (Min: %d Max: %d)", wesMode,
3341 CFG_ENABLE_WES_MODE_NAME_MIN,
3342 CFG_ENABLE_WES_MODE_NAME_MAX);
3343 ret = -EINVAL;
3344 goto exit;
3345 }
3346 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3347 "%s: Received Command to Set WES Mode rssi diff = %d", __func__, wesMode);
3348
3349 pHddCtx->cfg_ini->isWESModeEnabled = wesMode;
3350 sme_UpdateWESMode((tHalHandle)(pHddCtx->hHal), wesMode);
3351 }
3352 else if (strncmp(priv_data.buf, "GETWESMODE", 10) == 0)
3353 {
3354 tANI_BOOLEAN wesMode = sme_GetWESMode((tHalHandle)(pHddCtx->hHal));
3355 char extra[32];
3356 tANI_U8 len = 0;
3357
Arif Hussain826d9412013-11-12 16:44:54 -08003358 len = scnprintf(extra, sizeof(extra), "%s %d", command, wesMode);
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07003359 if (copy_to_user(priv_data.buf, &extra, len + 1))
3360 {
3361 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3362 "%s: failed to copy data to user buffer", __func__);
3363 ret = -EFAULT;
3364 goto exit;
3365 }
3366 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003367#endif /* WLAN_FEATURE_VOWIFI_11R || FEATURE_WLAN_ESE || FEATURE_WLAN_LFR */
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003368#ifdef FEATURE_WLAN_LFR
3369 else if (strncmp(command, "SETFASTROAM", 11) == 0)
3370 {
3371 tANI_U8 *value = command;
3372 tANI_U8 lfrMode = CFG_LFR_FEATURE_ENABLED_DEFAULT;
3373
3374 /* Move pointer to ahead of SETFASTROAM<delimiter> */
3375 value = value + 12;
3376 /* Convert the value from ascii to integer */
3377 ret = kstrtou8(value, 10, &lfrMode);
3378 if (ret < 0)
3379 {
3380 /* If the input value is greater than max value of datatype, then also
3381 kstrtou8 fails */
3382 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3383 "%s: kstrtou8 failed range [%d - %d]", __func__,
3384 CFG_LFR_FEATURE_ENABLED_MIN,
3385 CFG_LFR_FEATURE_ENABLED_MAX);
3386 ret = -EINVAL;
3387 goto exit;
3388 }
3389
3390 if ((lfrMode < CFG_LFR_FEATURE_ENABLED_MIN) ||
3391 (lfrMode > CFG_LFR_FEATURE_ENABLED_MAX))
3392 {
3393 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3394 "lfr mode value %d is out of range"
3395 " (Min: %d Max: %d)", lfrMode,
3396 CFG_LFR_FEATURE_ENABLED_MIN,
3397 CFG_LFR_FEATURE_ENABLED_MAX);
3398 ret = -EINVAL;
3399 goto exit;
3400 }
3401
3402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3403 "%s: Received Command to change lfr mode = %d", __func__, lfrMode);
3404
3405 pHddCtx->cfg_ini->isFastRoamIniFeatureEnabled = lfrMode;
3406 sme_UpdateIsFastRoamIniFeatureEnabled((tHalHandle)(pHddCtx->hHal), lfrMode);
3407 }
3408#endif
3409#ifdef WLAN_FEATURE_VOWIFI_11R
3410 else if (strncmp(command, "SETFASTTRANSITION", 17) == 0)
3411 {
3412 tANI_U8 *value = command;
3413 tANI_U8 ft = CFG_FAST_TRANSITION_ENABLED_NAME_DEFAULT;
3414
3415 /* Move pointer to ahead of SETFASTROAM<delimiter> */
3416 value = value + 18;
3417 /* Convert the value from ascii to integer */
3418 ret = kstrtou8(value, 10, &ft);
3419 if (ret < 0)
3420 {
3421 /* If the input value is greater than max value of datatype, then also
3422 kstrtou8 fails */
3423 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3424 "%s: kstrtou8 failed range [%d - %d]", __func__,
3425 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
3426 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
3427 ret = -EINVAL;
3428 goto exit;
3429 }
3430
3431 if ((ft < CFG_FAST_TRANSITION_ENABLED_NAME_MIN) ||
3432 (ft > CFG_FAST_TRANSITION_ENABLED_NAME_MAX))
3433 {
3434 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3435 "ft mode value %d is out of range"
3436 " (Min: %d Max: %d)", ft,
3437 CFG_FAST_TRANSITION_ENABLED_NAME_MIN,
3438 CFG_FAST_TRANSITION_ENABLED_NAME_MAX);
3439 ret = -EINVAL;
3440 goto exit;
3441 }
3442
3443 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3444 "%s: Received Command to change ft mode = %d", __func__, ft);
3445
3446 pHddCtx->cfg_ini->isFastTransitionEnabled = ft;
3447 sme_UpdateFastTransitionEnabled((tHalHandle)(pHddCtx->hHal), ft);
3448 }
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05303449
3450 else if (strncmp(command, "FASTREASSOC", 11) == 0)
3451 {
3452 tANI_U8 *value = command;
Padma, Santhosh Kumarf4582d32014-11-06 19:24:51 +05303453 tANI_U8 channel = 0;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05303454 tSirMacAddr targetApBssid;
3455 tANI_U8 trigger = 0;
3456 eHalStatus status = eHAL_STATUS_SUCCESS;
Padma, Santhosh Kumarb980a6f2014-11-06 19:07:24 +05303457 tHalHandle hHal;
3458 v_U32_t roamId = 0;
3459 tCsrRoamModifyProfileFields modProfileFields;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05303460 hdd_station_ctx_t *pHddStaCtx = NULL;
3461 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Padma, Santhosh Kumarb980a6f2014-11-06 19:07:24 +05303462 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05303463
3464 /* if not associated, no need to proceed with reassoc */
3465 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
3466 {
3467 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:Not associated!",__func__);
3468 ret = -EINVAL;
3469 goto exit;
3470 }
3471
Padma, Santhosh Kumarf4582d32014-11-06 19:24:51 +05303472 status = hdd_parse_reassoc_command_data(value, targetApBssid, &channel);
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05303473 if (eHAL_STATUS_SUCCESS != status)
3474 {
3475 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3476 "%s: Failed to parse reassoc command data", __func__);
3477 ret = -EINVAL;
3478 goto exit;
3479 }
3480
3481 /* if the target bssid is same as currently associated AP,
Padma, Santhosh Kumarb980a6f2014-11-06 19:07:24 +05303482 issue reassoc to same AP */
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05303483 if (VOS_TRUE == vos_mem_compare(targetApBssid,
3484 pHddStaCtx->conn_info.bssId, sizeof(tSirMacAddr)))
3485 {
3486 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3487 "%s:11r Reassoc BSSID is same as currently associated AP bssid",
3488 __func__);
Padma, Santhosh Kumarb980a6f2014-11-06 19:07:24 +05303489 sme_GetModifyProfileFields(hHal, pAdapter->sessionId,
3490 &modProfileFields);
3491 sme_RoamReassoc(hHal, pAdapter->sessionId,
3492 NULL, modProfileFields, &roamId, 1);
3493 return 0;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05303494 }
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05303495
3496 /* Check channel number is a valid channel number */
3497 if(VOS_STATUS_SUCCESS !=
3498 wlan_hdd_validate_operation_channel(pAdapter, channel))
3499 {
3500 hddLog(VOS_TRACE_LEVEL_ERROR,
3501 "%s: Invalid Channel [%d]", __func__, channel);
3502 return -EINVAL;
3503 }
3504
Padma, Santhosh Kumarf4582d32014-11-06 19:24:51 +05303505 trigger = eSME_ROAM_TRIGGER_SCAN;
Madan Mohan Koyyalamudi48101412013-09-11 23:09:37 +05303506
3507 /* Proceed with scan/roam */
3508 smeIssueFastRoamNeighborAPEvent(WLAN_HDD_GET_HAL_CTX(pAdapter),
3509 &targetApBssid[0],
3510 (tSmeFastRoamTrigger)(trigger));
3511 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003512#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003513#ifdef FEATURE_WLAN_ESE
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003514 else if (strncmp(command, "SETCCXMODE", 10) == 0)
3515 {
3516 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003517 tANI_U8 eseMode = CFG_ESE_FEATURE_ENABLED_DEFAULT;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003518
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003519 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003520 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003521 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003522 hdd_is_okc_mode_enabled(pHddCtx) &&
3523 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
3524 {
3525 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003526 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003527 " hence this operation is not permitted!", __func__);
3528 ret = -EPERM;
3529 goto exit;
3530 }
3531
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003532 /* Move pointer to ahead of SETCCXMODE<delimiter> */
3533 value = value + 11;
3534 /* Convert the value from ascii to integer */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003535 ret = kstrtou8(value, 10, &eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003536 if (ret < 0)
3537 {
3538 /* If the input value is greater than max value of datatype, then also
3539 kstrtou8 fails */
3540 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3541 "%s: kstrtou8 failed range [%d - %d]", __func__,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003542 CFG_ESE_FEATURE_ENABLED_MIN,
3543 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003544 ret = -EINVAL;
3545 goto exit;
3546 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003547 if ((eseMode < CFG_ESE_FEATURE_ENABLED_MIN) ||
3548 (eseMode > CFG_ESE_FEATURE_ENABLED_MAX))
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003549 {
3550 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003551 "Ese mode value %d is out of range"
3552 " (Min: %d Max: %d)", eseMode,
3553 CFG_ESE_FEATURE_ENABLED_MIN,
3554 CFG_ESE_FEATURE_ENABLED_MAX);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003555 ret = -EINVAL;
3556 goto exit;
3557 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003558 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003559 "%s: Received Command to change ese mode = %d", __func__, eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003560
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003561 pHddCtx->cfg_ini->isEseIniFeatureEnabled = eseMode;
3562 sme_UpdateIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal), eseMode);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003563 }
3564#endif
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003565 else if (strncmp(command, "SETROAMSCANCONTROL", 18) == 0)
3566 {
3567 tANI_U8 *value = command;
3568 tANI_BOOLEAN roamScanControl = 0;
3569
3570 /* Move pointer to ahead of SETROAMSCANCONTROL<delimiter> */
3571 value = value + 19;
3572 /* Convert the value from ascii to integer */
3573 ret = kstrtou8(value, 10, &roamScanControl);
3574 if (ret < 0)
3575 {
3576 /* If the input value is greater than max value of datatype, then also
3577 kstrtou8 fails */
3578 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3579 "%s: kstrtou8 failed ", __func__);
3580 ret = -EINVAL;
3581 goto exit;
3582 }
3583
3584 if (0 != roamScanControl)
3585 {
3586 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3587 "roam scan control invalid value = %d",
3588 roamScanControl);
3589 ret = -EINVAL;
3590 goto exit;
3591 }
3592 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3593 "%s: Received Command to Set roam scan control = %d", __func__, roamScanControl);
3594
3595 sme_SetRoamScanControl((tHalHandle)(pHddCtx->hHal), roamScanControl);
3596 }
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003597#ifdef FEATURE_WLAN_OKC
3598 else if (strncmp(command, "SETOKCMODE", 10) == 0)
3599 {
3600 tANI_U8 *value = command;
3601 tANI_U8 okcMode = CFG_OKC_FEATURE_ENABLED_DEFAULT;
3602
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003603 /* Check if the features OKC/ESE/11R are supported simultaneously,
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003604 then this operation is not permitted (return FAILURE) */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003605 if (sme_getIsEseFeatureEnabled((tHalHandle)(pHddCtx->hHal)) &&
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003606 hdd_is_okc_mode_enabled(pHddCtx) &&
3607 sme_getIsFtFeatureEnabled((tHalHandle)(pHddCtx->hHal)))
3608 {
3609 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003610 "%s: OKC/ESE/11R are supported simultaneously"
Srinivas Girigowdac6745a32013-07-15 19:19:10 -07003611 " hence this operation is not permitted!", __func__);
3612 ret = -EPERM;
3613 goto exit;
3614 }
3615
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07003616 /* Move pointer to ahead of SETOKCMODE<delimiter> */
3617 value = value + 11;
3618 /* Convert the value from ascii to integer */
3619 ret = kstrtou8(value, 10, &okcMode);
3620 if (ret < 0)
3621 {
3622 /* If the input value is greater than max value of datatype, then also
3623 kstrtou8 fails */
3624 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3625 "%s: kstrtou8 failed range [%d - %d]", __func__,
3626 CFG_OKC_FEATURE_ENABLED_MIN,
3627 CFG_OKC_FEATURE_ENABLED_MAX);
3628 ret = -EINVAL;
3629 goto exit;
3630 }
3631
3632 if ((okcMode < CFG_OKC_FEATURE_ENABLED_MIN) ||
3633 (okcMode > CFG_OKC_FEATURE_ENABLED_MAX))
3634 {
3635 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3636 "Okc mode value %d is out of range"
3637 " (Min: %d Max: %d)", okcMode,
3638 CFG_OKC_FEATURE_ENABLED_MIN,
3639 CFG_OKC_FEATURE_ENABLED_MAX);
3640 ret = -EINVAL;
3641 goto exit;
3642 }
3643
3644 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3645 "%s: Received Command to change okc mode = %d", __func__, okcMode);
3646
3647 pHddCtx->cfg_ini->isOkcIniFeatureEnabled = okcMode;
3648 }
Srinivas Girigowdaad34ca92013-10-22 10:54:29 -07003649#endif /* FEATURE_WLAN_OKC */
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003650 else if (strncmp(priv_data.buf, "GETROAMSCANCONTROL", 18) == 0)
3651 {
3652 tANI_BOOLEAN roamScanControl = sme_GetRoamScanControl((tHalHandle)(pHddCtx->hHal));
3653 char extra[32];
3654 tANI_U8 len = 0;
3655
Sameer Thalappilb0a30232013-09-27 15:37:48 -07003656 len = scnprintf(extra, sizeof(extra), "%s %d",
3657 command, roamScanControl);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07003658 if (copy_to_user(priv_data.buf, &extra, len + 1))
3659 {
3660 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3661 "%s: failed to copy data to user buffer", __func__);
3662 ret = -EFAULT;
3663 goto exit;
3664 }
3665 }
Gopichand Nakkala227c7f32013-06-26 22:44:57 +05303666#ifdef WLAN_FEATURE_PACKET_FILTERING
3667 else if (strncmp(command, "ENABLE_PKTFILTER_IPV6", 21) == 0)
3668 {
3669 tANI_U8 filterType = 0;
3670 tANI_U8 *value = command;
3671
3672 /* Move pointer to ahead of ENABLE_PKTFILTER_IPV6<delimiter> */
3673 value = value + 22;
3674
3675 /* Convert the value from ascii to integer */
3676 ret = kstrtou8(value, 10, &filterType);
3677 if (ret < 0)
3678 {
3679 /* If the input value is greater than max value of datatype,
3680 * then also kstrtou8 fails
3681 */
3682 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3683 "%s: kstrtou8 failed range ", __func__);
3684 ret = -EINVAL;
3685 goto exit;
3686 }
3687
3688 if (filterType != 0 && filterType != 1)
3689 {
3690 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3691 "%s: Accepted Values are 0 and 1 ", __func__);
3692 ret = -EINVAL;
3693 goto exit;
3694 }
3695 wlan_hdd_setIPv6Filter(WLAN_HDD_GET_CTX(pAdapter), filterType,
3696 pAdapter->sessionId);
3697 }
3698#endif
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05303699 else if (strncmp(command, "BTCOEXMODE", 10) == 0 )
3700 {
Kiet Lamad161252014-07-22 11:23:32 -07003701 char *dhcpPhase;
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05303702 int ret;
3703
Kiet Lamad161252014-07-22 11:23:32 -07003704 dhcpPhase = command + 11;
3705 if ('1' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05303706 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05303707 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07003708 FL("send DHCP START indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05303709
3710 pHddCtx->btCoexModeSet = TRUE;
Kiet Lamad161252014-07-22 11:23:32 -07003711
Satyanarayana Dash1faea4f2014-09-22 16:21:04 +05303712 ret = wlan_hdd_scan_abort(pAdapter);
3713 if (ret < 0)
3714 {
3715 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3716 FL("failed to abort existing scan %d"), ret);
3717 }
3718
Kiet Lamad161252014-07-22 11:23:32 -07003719 sme_DHCPStartInd(pHddCtx->hHal, pAdapter->device_mode,
3720 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05303721 }
Kiet Lamad161252014-07-22 11:23:32 -07003722 else if ('2' == *dhcpPhase)
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05303723 {
Deepthi Gowribfd17132014-11-14 17:59:04 +05303724 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiet Lamad161252014-07-22 11:23:32 -07003725 FL("send DHCP STOP indication"));
c_hpothu9b781ba2013-12-30 20:57:45 +05303726
3727 pHddCtx->btCoexModeSet = FALSE;
Kiet Lamad161252014-07-22 11:23:32 -07003728
3729 sme_DHCPStopInd(pHddCtx->hHal, pAdapter->device_mode,
3730 pAdapter->sessionId);
Sundaresan Ramachandran76e48e82013-07-15 13:07:17 +05303731 }
3732 }
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07003733 else if (strncmp(command, "SCAN-ACTIVE", 11) == 0)
3734 {
c_hpothudbefd3e2014-04-28 15:59:47 +05303735 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3736 FL("making default scan to ACTIVE"));
3737 pHddCtx->scan_info.scan_mode = eSIR_ACTIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07003738 }
3739 else if (strncmp(command, "SCAN-PASSIVE", 12) == 0)
3740 {
c_hpothudbefd3e2014-04-28 15:59:47 +05303741 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3742 FL("making default scan to PASSIVE"));
3743 pHddCtx->scan_info.scan_mode = eSIR_PASSIVE_SCAN;
Jeff Johnsonf54df2c2013-07-24 11:43:39 -07003744 }
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05303745 else if (strncmp(command, "GETDWELLTIME", 12) == 0)
3746 {
3747 hdd_config_t *pCfg = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
3748 char extra[32];
3749 tANI_U8 len = 0;
3750
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303751 memset(extra, 0, sizeof(extra));
3752 ret = hdd_get_dwell_time(pCfg, command, extra, sizeof(extra), &len);
3753 if (ret != 0 || copy_to_user(priv_data.buf, &extra, len + 1))
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05303754 {
3755 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3756 "%s: failed to copy data to user buffer", __func__);
3757 ret = -EFAULT;
3758 goto exit;
3759 }
3760 ret = len;
3761 }
3762 else if (strncmp(command, "SETDWELLTIME", 12) == 0)
3763 {
Rajesh Babu Prathipatic7baf6f2014-05-30 10:08:16 +05303764 ret = hdd_set_dwell_time(pAdapter, command);
Hanumantha Reddy Pothula212243c2013-08-01 17:28:31 +05303765 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07003766 else if ( strncasecmp(command, "MIRACAST", 8) == 0 )
3767 {
3768 tANI_U8 filterType = 0;
3769 tANI_U8 *value;
3770 value = command + 9;
3771
3772 /* Convert the value from ascii to integer */
3773 ret = kstrtou8(value, 10, &filterType);
3774 if (ret < 0)
3775 {
3776 /* If the input value is greater than max value of datatype,
3777 * then also kstrtou8 fails
3778 */
3779 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3780 "%s: kstrtou8 failed range ", __func__);
3781 ret = -EINVAL;
3782 goto exit;
3783 }
3784 if ((filterType < WLAN_HDD_DRIVER_MIRACAST_CFG_MIN_VAL ) ||
3785 (filterType > WLAN_HDD_DRIVER_MIRACAST_CFG_MAX_VAL))
3786 {
3787 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3788 "%s: Accepted Values are 0 to 2. 0-Disabled, 1-Source,"
3789 " 2-Sink ", __func__);
3790 ret = -EINVAL;
3791 goto exit;
3792 }
3793 //Filtertype value should be either 0-Disabled, 1-Source, 2-sink
3794 pHddCtx->drvr_miracast = filterType;
Kaushik, Sushant96122442014-10-21 16:40:18 +05303795 pScanInfo = &pHddCtx->scan_info;
3796 if (filterType && pScanInfo != NULL &&
3797 pHddCtx->scan_info.mScanPending)
3798 {
3799 /*Miracast Session started. Abort Scan */
3800 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3801 "%s, Aborting Scan For Miracast",__func__);
3802 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
3803 eCSR_SCAN_ABORT_DEFAULT);
3804 }
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07003805 hdd_tx_rx_pkt_cnt_stat_timer_handler(pHddCtx);
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05303806 sme_SetMiracastMode(pHddCtx->hHal, pHddCtx->drvr_miracast);
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07003807 }
Leo Chang614d2072013-08-22 14:59:44 -07003808 else if (strncmp(command, "SETMCRATE", 9) == 0)
3809 {
Leo Chang614d2072013-08-22 14:59:44 -07003810 tANI_U8 *value = command;
3811 int targetRate;
Leo Chang1f98cbd2013-10-17 15:03:52 -07003812 tSirRateUpdateInd *rateUpdate;
3813 eHalStatus status;
Leo Chang614d2072013-08-22 14:59:44 -07003814
3815 /* Only valid for SAP mode */
3816 if (WLAN_HDD_SOFTAP != pAdapter->device_mode)
3817 {
3818 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3819 "%s: SAP mode is not running", __func__);
3820 ret = -EFAULT;
3821 goto exit;
3822 }
3823
3824 /* Move pointer to ahead of SETMCRATE<delimiter> */
3825 /* input value is in units of hundred kbps */
3826 value = value + 10;
3827 /* Convert the value from ascii to integer, decimal base */
3828 ret = kstrtouint(value, 10, &targetRate);
3829
Leo Chang1f98cbd2013-10-17 15:03:52 -07003830 rateUpdate = (tSirRateUpdateInd *)vos_mem_malloc(sizeof(tSirRateUpdateInd));
3831 if (NULL == rateUpdate)
Leo Chang614d2072013-08-22 14:59:44 -07003832 {
Leo Chang1f98cbd2013-10-17 15:03:52 -07003833 hddLog(VOS_TRACE_LEVEL_ERROR,
3834 "%s: SETMCRATE indication alloc fail", __func__);
3835 ret = -EFAULT;
3836 goto exit;
3837 }
3838 vos_mem_zero(rateUpdate, sizeof(tSirRateUpdateInd ));
3839
3840 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3841 "MC Target rate %d", targetRate);
3842 /* Ignore unicast */
3843 rateUpdate->ucastDataRate = -1;
3844 rateUpdate->mcastDataRate24GHz = targetRate;
3845 rateUpdate->mcastDataRate5GHz = targetRate;
3846 rateUpdate->mcastDataRate24GHzTxFlag = 0;
3847 rateUpdate->mcastDataRate5GHzTxFlag = 0;
3848 status = sme_SendRateUpdateInd(pHddCtx->hHal, rateUpdate);
3849 if (eHAL_STATUS_SUCCESS != status)
3850 {
3851 hddLog(VOS_TRACE_LEVEL_ERROR,
3852 "%s: SET_MC_RATE failed", __func__);
3853 vos_mem_free(rateUpdate);
3854 ret = -EFAULT;
3855 goto exit;
Leo Chang614d2072013-08-22 14:59:44 -07003856 }
3857 }
Rajeev79dbe4c2013-10-05 11:03:42 +05303858#ifdef FEATURE_WLAN_BATCH_SCAN
Rajeev Kumar8b373292014-01-08 20:36:55 -08003859 else if (strncmp(command, "WLS_BATCHING", 12) == 0)
Rajeev79dbe4c2013-10-05 11:03:42 +05303860 {
Rajeev Kumar8b373292014-01-08 20:36:55 -08003861 ret = hdd_handle_batch_scan_ioctl(pAdapter, &priv_data, command);
Rajeev79dbe4c2013-10-05 11:03:42 +05303862 }
3863#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003864#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07003865 else if (strncmp(command, "SETCCXROAMSCANCHANNELS", 22) == 0)
3866 {
3867 tANI_U8 *value = command;
3868 tANI_U8 ChannelList[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
3869 tANI_U8 numChannels = 0;
3870 eHalStatus status = eHAL_STATUS_SUCCESS;
3871
3872 status = hdd_parse_channellist(value, ChannelList, &numChannels);
3873 if (eHAL_STATUS_SUCCESS != status)
3874 {
3875 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3876 "%s: Failed to parse channel list information", __func__);
3877 ret = -EINVAL;
3878 goto exit;
3879 }
3880
3881 if (numChannels > WNI_CFG_VALID_CHANNEL_LIST_LEN)
3882 {
3883 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3884 "%s: number of channels (%d) supported exceeded max (%d)", __func__,
3885 numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3886 ret = -EINVAL;
3887 goto exit;
3888 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003889 status = sme_SetEseRoamScanChannelList((tHalHandle)(pHddCtx->hHal),
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07003890 ChannelList,
3891 numChannels);
3892 if (eHAL_STATUS_SUCCESS != status)
3893 {
3894 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3895 "%s: Failed to update channel list information", __func__);
3896 ret = -EINVAL;
3897 goto exit;
3898 }
3899 }
3900 else if (strncmp(command, "GETTSMSTATS", 11) == 0)
3901 {
3902 tANI_U8 *value = command;
3903 char extra[128] = {0};
3904 int len = 0;
3905 tANI_U8 tid = 0;
3906 hdd_station_ctx_t *pHddStaCtx = NULL;
3907 tAniTrafStrmMetrics tsmMetrics;
3908 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3909
3910 /* if not associated, return error */
3911 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
3912 {
3913 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s:Not associated!",__func__);
3914 ret = -EINVAL;
3915 goto exit;
3916 }
3917
3918 /* Move pointer to ahead of GETTSMSTATS<delimiter> */
3919 value = value + 12;
3920 /* Convert the value from ascii to integer */
3921 ret = kstrtou8(value, 10, &tid);
3922 if (ret < 0)
3923 {
3924 /* If the input value is greater than max value of datatype, then also
3925 kstrtou8 fails */
3926 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3927 "%s: kstrtou8 failed range [%d - %d]", __func__,
3928 TID_MIN_VALUE,
3929 TID_MAX_VALUE);
3930 ret = -EINVAL;
3931 goto exit;
3932 }
3933
3934 if ((tid < TID_MIN_VALUE) || (tid > TID_MAX_VALUE))
3935 {
3936 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3937 "tid value %d is out of range"
3938 " (Min: %d Max: %d)", tid,
3939 TID_MIN_VALUE,
3940 TID_MAX_VALUE);
3941 ret = -EINVAL;
3942 goto exit;
3943 }
3944
3945 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3946 "%s: Received Command to get tsm stats tid = %d", __func__, tid);
3947
3948 if (VOS_STATUS_SUCCESS != hdd_get_tsm_stats(pAdapter, tid, &tsmMetrics))
3949 {
3950 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3951 "%s: failed to get tsm stats", __func__);
3952 ret = -EFAULT;
3953 goto exit;
3954 }
3955
3956 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3957 "UplinkPktQueueDly(%d)\n"
3958 "UplinkPktQueueDlyHist[0](%d)\n"
3959 "UplinkPktQueueDlyHist[1](%d)\n"
3960 "UplinkPktQueueDlyHist[2](%d)\n"
3961 "UplinkPktQueueDlyHist[3](%d)\n"
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05303962 "UplinkPktTxDly(%u)\n"
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07003963 "UplinkPktLoss(%d)\n"
3964 "UplinkPktCount(%d)\n"
3965 "RoamingCount(%d)\n"
3966 "RoamingDly(%d)", tsmMetrics.UplinkPktQueueDly,
3967 tsmMetrics.UplinkPktQueueDlyHist[0],
3968 tsmMetrics.UplinkPktQueueDlyHist[1],
3969 tsmMetrics.UplinkPktQueueDlyHist[2],
3970 tsmMetrics.UplinkPktQueueDlyHist[3],
3971 tsmMetrics.UplinkPktTxDly, tsmMetrics.UplinkPktLoss,
3972 tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount, tsmMetrics.RoamingDly);
3973
3974 /* Output TSM stats is of the format
3975 GETTSMSTATS [PktQueueDly] [PktQueueDlyHist[0]]:[PktQueueDlyHist[1]] ...[RoamingDly]
3976 eg., GETTSMSTATS 10 1:0:0:161 20 1 17 8 39800 */
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08003977 len = scnprintf(extra, sizeof(extra), "%s %d %d:%d:%d:%d %u %d %d %d %d", command,
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07003978 tsmMetrics.UplinkPktQueueDly, tsmMetrics.UplinkPktQueueDlyHist[0],
3979 tsmMetrics.UplinkPktQueueDlyHist[1], tsmMetrics.UplinkPktQueueDlyHist[2],
3980 tsmMetrics.UplinkPktQueueDlyHist[3], tsmMetrics.UplinkPktTxDly,
3981 tsmMetrics.UplinkPktLoss, tsmMetrics.UplinkPktCount, tsmMetrics.RoamingCount,
3982 tsmMetrics.RoamingDly);
3983
3984 if (copy_to_user(priv_data.buf, &extra, len + 1))
3985 {
3986 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3987 "%s: failed to copy data to user buffer", __func__);
3988 ret = -EFAULT;
3989 goto exit;
3990 }
3991 }
3992 else if (strncmp(command, "SETCCKMIE", 9) == 0)
3993 {
3994 tANI_U8 *value = command;
3995 tANI_U8 *cckmIe = NULL;
3996 tANI_U8 cckmIeLen = 0;
3997 eHalStatus status = eHAL_STATUS_SUCCESS;
3998
3999 status = hdd_parse_get_cckm_ie(value, &cckmIe, &cckmIeLen);
4000 if (eHAL_STATUS_SUCCESS != status)
4001 {
4002 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4003 "%s: Failed to parse cckm ie data", __func__);
4004 ret = -EINVAL;
4005 goto exit;
4006 }
4007
4008 if (cckmIeLen > DOT11F_IE_RSN_MAX_LEN)
4009 {
4010 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4011 "%s: CCKM Ie input length is more than max[%d]", __func__,
4012 DOT11F_IE_RSN_MAX_LEN);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004013 vos_mem_free(cckmIe);
4014 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004015 ret = -EINVAL;
4016 goto exit;
4017 }
4018 sme_SetCCKMIe((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, cckmIe, cckmIeLen);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08004019 vos_mem_free(cckmIe);
4020 cckmIe = NULL;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004021 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004022 else if (strncmp(command, "CCXBEACONREQ", 12) == 0)
4023 {
4024 tANI_U8 *value = command;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004025 tCsrEseBeaconReq eseBcnReq;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004026 eHalStatus status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07004027
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004028 status = hdd_parse_ese_beacon_req(value, &eseBcnReq);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004029 if (eHAL_STATUS_SUCCESS != status)
4030 {
4031 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004032 "%s: Failed to parse ese beacon req", __func__);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004033 ret = -EINVAL;
4034 goto exit;
4035 }
Srinivas Girigowda0c6d7fe2014-05-28 18:18:10 -07004036 if (!hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))) {
4037 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not associated"));
4038 hdd_indicateEseBcnReportNoResults (pAdapter,
4039 eseBcnReq.bcnReq[0].measurementToken,
4040 0x02, //BIT(1) set for measurement done
4041 0); // no BSS
4042 goto exit;
4043 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004044
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004045 status = sme_SetEseBeaconRequest((tHalHandle)(pHddCtx->hHal), pAdapter->sessionId, &eseBcnReq);
4046 if (eHAL_STATUS_SUCCESS != status)
4047 {
4048 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4049 "%s: sme_SetEseBeaconRequest failed (%d)", __func__, status);
4050 ret = -EINVAL;
4051 goto exit;
4052 }
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004053 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004054#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
c_hpothu92367912014-05-01 15:18:17 +05304055 else if (strncmp(command, "GETBCNMISSRATE", 14) == 0)
4056 {
4057 eHalStatus status;
4058 char buf[32], len;
4059 long waitRet;
4060 bcnMissRateContext_t getBcnMissRateCtx;
4061
4062 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4063
4064 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
4065 {
4066 hddLog(VOS_TRACE_LEVEL_WARN,
4067 FL("GETBCNMISSRATE: STA is not in connected state"));
4068 ret = -1;
4069 goto exit;
4070 }
4071
4072 init_completion(&(getBcnMissRateCtx.completion));
4073 getBcnMissRateCtx.magic = BCN_MISS_RATE_CONTEXT_MAGIC;
4074
4075 status = sme_getBcnMissRate((tHalHandle)(pHddCtx->hHal),
4076 pAdapter->sessionId,
4077 (void *)getBcnMissRateCB,
4078 (void *)(&getBcnMissRateCtx));
4079 if( eHAL_STATUS_SUCCESS != status)
4080 {
4081 hddLog(VOS_TRACE_LEVEL_INFO,
4082 FL("GETBCNMISSRATE: fail to post WDA cmd"));
4083 ret = -EINVAL;
4084 goto exit;
4085 }
4086
4087 waitRet = wait_for_completion_interruptible_timeout
4088 (&getBcnMissRateCtx.completion, BCN_MISS_RATE_TIME);
4089 if(waitRet <= 0)
4090 {
4091 hddLog(VOS_TRACE_LEVEL_ERROR,
4092 FL("failed to wait on bcnMissRateComp %d"), ret);
4093
4094 //Make magic number to zero so that callback is not called.
4095 spin_lock(&hdd_context_lock);
4096 getBcnMissRateCtx.magic = 0x0;
4097 spin_unlock(&hdd_context_lock);
4098 ret = -EINVAL;
4099 goto exit;
4100 }
4101
4102 hddLog(VOS_TRACE_LEVEL_INFO,
4103 FL("GETBCNMISSRATE: bcnMissRate: %d"), gbcnMissRate);
4104
4105 len = snprintf(buf, sizeof(buf), "GETBCNMISSRATE %d", gbcnMissRate);
4106 if (copy_to_user(priv_data.buf, &buf, len + 1))
4107 {
4108 hddLog(VOS_TRACE_LEVEL_ERROR,
4109 "%s: failed to copy data to user buffer", __func__);
4110 ret = -EFAULT;
4111 goto exit;
4112 }
4113 ret = len;
4114 }
Atul Mittal87ec2422014-09-24 13:12:50 +05304115#ifdef FEATURE_WLAN_TDLS
4116 else if (strncmp(command, "TDLSSECONDARYCHANNELOFFSET", 26) == 0) {
4117 tANI_U8 *value = command;
4118 int set_value;
4119 /* Move pointer to ahead of TDLSOFFCH*/
4120 value += 26;
4121 sscanf(value, "%d", &set_value);
4122 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4123 "%s: Tdls offchannel offset:%d",
4124 __func__, set_value);
4125 ret = iw_set_tdlssecoffchanneloffset(pHddCtx, set_value);
4126 if (ret < 0)
4127 {
4128 ret = -EINVAL;
4129 goto exit;
4130 }
4131
4132 } else if (strncmp(command, "TDLSOFFCHANNELMODE", 18) == 0) {
4133 tANI_U8 *value = command;
4134 int set_value;
4135 /* Move pointer to ahead of tdlsoffchnmode*/
4136 value += 18;
4137 sscanf(value, "%d", &set_value);
4138 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4139 "%s: Tdls offchannel mode:%d",
4140 __func__, set_value);
4141 ret = iw_set_tdlsoffchannelmode(pAdapter, set_value);
4142 if (ret < 0)
4143 {
4144 ret = -EINVAL;
4145 goto exit;
4146 }
4147 } else if (strncmp(command, "TDLSOFFCHANNEL", 14) == 0) {
4148 tANI_U8 *value = command;
4149 int set_value;
4150 /* Move pointer to ahead of TDLSOFFCH*/
4151 value += 14;
4152 sscanf(value, "%d", &set_value);
4153 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4154 "%s: Tdls offchannel num: %d",
4155 __func__, set_value);
4156 ret = iw_set_tdlsoffchannel(pHddCtx, set_value);
4157 if (ret < 0)
4158 {
4159 ret = -EINVAL;
4160 goto exit;
4161 }
4162 }
4163#endif
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07004164 else {
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304165 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4166 TRACE_CODE_HDD_UNSUPPORTED_IOCTL,
4167 pAdapter->sessionId, 0));
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -07004168 hddLog( VOS_TRACE_LEVEL_WARN, "%s: Unsupported GUI command %s",
4169 __func__, command);
4170 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004171 }
4172exit:
4173 if (command)
4174 {
4175 kfree(command);
4176 }
4177 return ret;
4178}
4179
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004180#ifdef CONFIG_COMPAT
4181static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
4182{
4183 struct {
4184 compat_uptr_t buf;
4185 int used_len;
4186 int total_len;
4187 } compat_priv_data;
4188 hdd_priv_data_t priv_data;
4189 int ret = 0;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004190
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004191 /*
4192 * Note that pAdapter and ifr have already been verified by caller,
4193 * and HDD context has also been validated
4194 */
4195 if (copy_from_user(&compat_priv_data, ifr->ifr_data,
4196 sizeof(compat_priv_data))) {
4197 ret = -EFAULT;
4198 goto exit;
4199 }
4200 priv_data.buf = compat_ptr(compat_priv_data.buf);
4201 priv_data.used_len = compat_priv_data.used_len;
4202 priv_data.total_len = compat_priv_data.total_len;
4203 ret = hdd_driver_command(pAdapter, &priv_data);
4204 exit:
4205 return ret;
4206}
4207#else /* CONFIG_COMPAT */
4208static int hdd_driver_compat_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
4209{
4210 /* will never be invoked */
4211 return 0;
4212}
4213#endif /* CONFIG_COMPAT */
4214
4215static int hdd_driver_ioctl(hdd_adapter_t *pAdapter, struct ifreq *ifr)
4216{
4217 hdd_priv_data_t priv_data;
4218 int ret = 0;
4219
4220 /*
4221 * Note that pAdapter and ifr have already been verified by caller,
4222 * and HDD context has also been validated
4223 */
4224 if (copy_from_user(&priv_data, ifr->ifr_data, sizeof(priv_data))) {
4225 ret = -EFAULT;
4226 } else {
4227 ret = hdd_driver_command(pAdapter, &priv_data);
4228 }
4229 return ret;
4230}
4231
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05304232int __hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004233{
4234 hdd_adapter_t *pAdapter;
4235 hdd_context_t *pHddCtx;
4236 int ret;
4237
4238 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
4239 if (NULL == pAdapter) {
4240 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4241 "%s: HDD adapter context is Null", __func__);
4242 ret = -ENODEV;
4243 goto exit;
4244 }
4245 if (dev != pAdapter->dev) {
4246 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4247 "%s: HDD adapter/dev inconsistency", __func__);
4248 ret = -ENODEV;
4249 goto exit;
4250 }
4251
4252 if ((!ifr) || (!ifr->ifr_data)) {
4253 ret = -EINVAL;
4254 goto exit;
4255 }
4256
4257 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4258 ret = wlan_hdd_validate_context(pHddCtx);
4259 if (ret) {
Mahesh A Saptasagar5b16d0a2014-11-03 17:55:29 +05304260 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnsond6e7b3f2014-03-20 12:12:11 -07004261 "%s: invalid context", __func__);
4262 ret = -EBUSY;
4263 goto exit;
4264 }
4265
4266 switch (cmd) {
4267 case (SIOCDEVPRIVATE + 1):
4268 if (is_compat_task())
4269 ret = hdd_driver_compat_ioctl(pAdapter, ifr);
4270 else
4271 ret = hdd_driver_ioctl(pAdapter, ifr);
4272 break;
4273 default:
4274 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unknown ioctl %d",
4275 __func__, cmd);
4276 ret = -EINVAL;
4277 break;
4278 }
4279 exit:
4280 return ret;
4281}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004282
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05304283int hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4284{
4285 int ret;
4286
4287 vos_ssr_protect(__func__);
4288 ret = __hdd_ioctl(dev, ifr, cmd);
4289 vos_ssr_unprotect(__func__);
4290
4291 return ret;
4292}
4293
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004294#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004295/**---------------------------------------------------------------------------
4296
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004297 \brief hdd_parse_ese_beacon_req() - Parse ese beacon request
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004298
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004299 This function parses the ese beacon request passed in the format
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004300 CCXBEACONREQ<space><Number of fields><space><Measurement token>
4301 <space>Channel 1<space>Scan Mode <space>Meas Duration<space>Channel N
4302 <space>Scan Mode N<space>Meas Duration N
4303 if the Number of bcn req fields (N) does not match with the actual number of fields passed
4304 then take N.
4305 <Meas Token><Channel><Scan Mode> and <Meas Duration> are treated as one pair
4306 For example, CCXBEACONREQ 2 1 1 1 30 2 44 0 40.
4307 This function does not take care of removing duplicate channels from the list
4308
4309 \param - pValue Pointer to data
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004310 \param - pEseBcnReq output pointer to store parsed ie information
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004311
4312 \return - 0 for success non-zero for failure
4313
4314 --------------------------------------------------------------------------*/
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004315static VOS_STATUS hdd_parse_ese_beacon_req(tANI_U8 *pValue,
4316 tCsrEseBeaconReq *pEseBcnReq)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004317{
4318 tANI_U8 *inPtr = pValue;
4319 int tempInt = 0;
4320 int j = 0, i = 0, v = 0;
4321 char buf[32];
4322
4323 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
4324 /*no argument after the command*/
4325 if (NULL == inPtr)
4326 {
4327 return -EINVAL;
4328 }
4329 /*no space after the command*/
4330 else if (SPACE_ASCII_VALUE != *inPtr)
4331 {
4332 return -EINVAL;
4333 }
4334
4335 /*removing empty spaces*/
4336 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
4337
4338 /*no argument followed by spaces*/
4339 if ('\0' == *inPtr) return -EINVAL;
4340
4341 /*getting the first argument ie measurement token*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004342 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004343 if (1 != v) return -EINVAL;
4344
4345 v = kstrtos32(buf, 10, &tempInt);
4346 if ( v < 0) return -EINVAL;
4347
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004348 pEseBcnReq->numBcnReqIe = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004349
4350 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004351 "Number of Bcn Req Ie fields(%d)", pEseBcnReq->numBcnReqIe);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004352
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004353 for (j = 0; j < (pEseBcnReq->numBcnReqIe); j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004354 {
4355 for (i = 0; i < 4; i++)
4356 {
4357 /*inPtr pointing to the beginning of first space after number of ie fields*/
4358 inPtr = strpbrk( inPtr, " " );
4359 /*no ie data after the number of ie fields argument*/
4360 if (NULL == inPtr) return -EINVAL;
4361
4362 /*removing empty space*/
4363 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
4364
4365 /*no ie data after the number of ie fields argument and spaces*/
4366 if ( '\0' == *inPtr ) return -EINVAL;
4367
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004368 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004369 if (1 != v) return -EINVAL;
4370
4371 v = kstrtos32(buf, 10, &tempInt);
4372 if (v < 0) return -EINVAL;
4373
4374 switch (i)
4375 {
4376 case 0: /* Measurement token */
4377 if (tempInt <= 0)
4378 {
4379 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4380 "Invalid Measurement Token(%d)", tempInt);
4381 return -EINVAL;
4382 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004383 pEseBcnReq->bcnReq[j].measurementToken = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004384 break;
4385
4386 case 1: /* Channel number */
4387 if ((tempInt <= 0) ||
4388 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
4389 {
4390 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4391 "Invalid Channel Number(%d)", tempInt);
4392 return -EINVAL;
4393 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004394 pEseBcnReq->bcnReq[j].channel = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004395 break;
4396
4397 case 2: /* Scan mode */
Varun Reddy Yeturu0b18d5a2013-12-04 11:42:23 -08004398 if ((tempInt < eSIR_PASSIVE_SCAN) || (tempInt > eSIR_BEACON_TABLE))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004399 {
4400 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4401 "Invalid Scan Mode(%d) Expected{0|1|2}", tempInt);
4402 return -EINVAL;
4403 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004404 pEseBcnReq->bcnReq[j].scanMode= tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004405 break;
4406
4407 case 3: /* Measurement duration */
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004408 if (((tempInt <= 0) && (pEseBcnReq->bcnReq[j].scanMode != eSIR_BEACON_TABLE)) ||
4409 ((tempInt < 0) && (pEseBcnReq->bcnReq[j].scanMode == eSIR_BEACON_TABLE)))
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004410 {
4411 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4412 "Invalid Measurement Duration(%d)", tempInt);
4413 return -EINVAL;
4414 }
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004415 pEseBcnReq->bcnReq[j].measurementDuration = tempInt;
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004416 break;
4417 }
4418 }
4419 }
4420
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004421 for (j = 0; j < pEseBcnReq->numBcnReqIe; j++)
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004422 {
4423 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arun Kumar Khandavallie8768212014-02-17 16:43:34 +05304424 "Index(%d) Measurement Token(%u)Channel(%u) Scan Mode(%u) Measurement Duration(%u)\n",
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004425 j,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004426 pEseBcnReq->bcnReq[j].measurementToken,
4427 pEseBcnReq->bcnReq[j].channel,
4428 pEseBcnReq->bcnReq[j].scanMode,
4429 pEseBcnReq->bcnReq[j].measurementDuration);
Srinivas Girigowda91ccbe82013-11-10 16:37:38 -08004430 }
4431
4432 return VOS_STATUS_SUCCESS;
4433}
4434
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004435static void hdd_GetTsmStatsCB( tAniTrafStrmMetrics tsmMetrics, const tANI_U32 staId, void *pContext )
4436{
4437 struct statsContext *pStatsContext = NULL;
4438 hdd_adapter_t *pAdapter = NULL;
4439
4440 if (NULL == pContext)
4441 {
4442 hddLog(VOS_TRACE_LEVEL_ERROR,
4443 "%s: Bad param, pContext [%p]",
4444 __func__, pContext);
4445 return;
4446 }
4447
Jeff Johnson72a40512013-12-19 10:14:15 -08004448 /* there is a race condition that exists between this callback
4449 function and the caller since the caller could time out either
4450 before or while this code is executing. we use a spinlock to
4451 serialize these actions */
4452 spin_lock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004453
4454 pStatsContext = pContext;
4455 pAdapter = pStatsContext->pAdapter;
4456 if ((NULL == pAdapter) || (STATS_CONTEXT_MAGIC != pStatsContext->magic))
4457 {
4458 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -08004459 spin_unlock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004460 hddLog(VOS_TRACE_LEVEL_WARN,
4461 "%s: Invalid context, pAdapter [%p] magic [%08x]",
4462 __func__, pAdapter, pStatsContext->magic);
4463 return;
4464 }
4465
Jeff Johnson72a40512013-12-19 10:14:15 -08004466 /* context is valid so caller is still waiting */
4467
4468 /* paranoia: invalidate the magic */
4469 pStatsContext->magic = 0;
4470
4471 /* copy over the tsm stats */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004472 pAdapter->tsmStats.UplinkPktQueueDly = tsmMetrics.UplinkPktQueueDly;
4473 vos_mem_copy(pAdapter->tsmStats.UplinkPktQueueDlyHist,
4474 tsmMetrics.UplinkPktQueueDlyHist,
4475 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist)/
4476 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist[0]));
4477 pAdapter->tsmStats.UplinkPktTxDly = tsmMetrics.UplinkPktTxDly;
4478 pAdapter->tsmStats.UplinkPktLoss = tsmMetrics.UplinkPktLoss;
4479 pAdapter->tsmStats.UplinkPktCount = tsmMetrics.UplinkPktCount;
4480 pAdapter->tsmStats.RoamingCount = tsmMetrics.RoamingCount;
4481 pAdapter->tsmStats.RoamingDly = tsmMetrics.RoamingDly;
4482
Jeff Johnson72a40512013-12-19 10:14:15 -08004483 /* notify the caller */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004484 complete(&pStatsContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -08004485
4486 /* serialization is complete */
4487 spin_unlock(&hdd_context_lock);
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004488}
4489
4490
4491
4492static VOS_STATUS hdd_get_tsm_stats(hdd_adapter_t *pAdapter, const tANI_U8 tid,
4493 tAniTrafStrmMetrics* pTsmMetrics)
4494{
4495 hdd_station_ctx_t *pHddStaCtx = NULL;
4496 eHalStatus hstatus;
Jeff Johnson72a40512013-12-19 10:14:15 -08004497 VOS_STATUS vstatus = VOS_STATUS_SUCCESS;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004498 long lrc;
4499 struct statsContext context;
4500 hdd_context_t *pHddCtx = NULL;
4501
4502 if (NULL == pAdapter)
4503 {
4504 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: pAdapter is NULL", __func__);
4505 return VOS_STATUS_E_FAULT;
4506 }
4507
4508 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4509 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4510
4511 /* we are connected prepare our callback context */
4512 init_completion(&context.completion);
4513 context.pAdapter = pAdapter;
4514 context.magic = STATS_CONTEXT_MAGIC;
4515
4516 /* query tsm stats */
4517 hstatus = sme_GetTsmStats(pHddCtx->hHal, hdd_GetTsmStatsCB,
4518 pHddStaCtx->conn_info.staId[ 0 ],
4519 pHddStaCtx->conn_info.bssId,
4520 &context, pHddCtx->pvosContext, tid);
4521
4522 if (eHAL_STATUS_SUCCESS != hstatus)
4523 {
Jeff Johnson72a40512013-12-19 10:14:15 -08004524 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unable to retrieve statistics",
4525 __func__);
4526 vstatus = VOS_STATUS_E_FAULT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004527 }
4528 else
4529 {
4530 /* request was sent -- wait for the response */
4531 lrc = wait_for_completion_interruptible_timeout(&context.completion,
4532 msecs_to_jiffies(WLAN_WAIT_TIME_STATS));
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004533 if (lrc <= 0)
4534 {
4535 hddLog(VOS_TRACE_LEVEL_ERROR,
4536 "%s: SME %s while retrieving statistics",
4537 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson72a40512013-12-19 10:14:15 -08004538 vstatus = VOS_STATUS_E_TIMEOUT;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004539 }
4540 }
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004541
Jeff Johnson72a40512013-12-19 10:14:15 -08004542 /* either we never sent a request, we sent a request and received a
4543 response or we sent a request and timed out. if we never sent a
4544 request or if we sent a request and got a response, we want to
4545 clear the magic out of paranoia. if we timed out there is a
4546 race condition such that the callback function could be
4547 executing at the same time we are. of primary concern is if the
4548 callback function had already verified the "magic" but had not
4549 yet set the completion variable when a timeout occurred. we
4550 serialize these activities by invalidating the magic while
4551 holding a shared spinlock which will cause us to block if the
4552 callback is currently executing */
4553 spin_lock(&hdd_context_lock);
4554 context.magic = 0;
4555 spin_unlock(&hdd_context_lock);
4556
4557 if (VOS_STATUS_SUCCESS == vstatus)
4558 {
4559 pTsmMetrics->UplinkPktQueueDly = pAdapter->tsmStats.UplinkPktQueueDly;
4560 vos_mem_copy(pTsmMetrics->UplinkPktQueueDlyHist,
4561 pAdapter->tsmStats.UplinkPktQueueDlyHist,
4562 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist)/
4563 sizeof(pAdapter->tsmStats.UplinkPktQueueDlyHist[0]));
4564 pTsmMetrics->UplinkPktTxDly = pAdapter->tsmStats.UplinkPktTxDly;
4565 pTsmMetrics->UplinkPktLoss = pAdapter->tsmStats.UplinkPktLoss;
4566 pTsmMetrics->UplinkPktCount = pAdapter->tsmStats.UplinkPktCount;
4567 pTsmMetrics->RoamingCount = pAdapter->tsmStats.RoamingCount;
4568 pTsmMetrics->RoamingDly = pAdapter->tsmStats.RoamingDly;
4569 }
4570 return vstatus;
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004571}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004572#endif /*FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004573
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004574#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowdade697412013-02-14 16:31:48 -08004575void hdd_getBand_helper(hdd_context_t *pHddCtx, int *pBand)
4576{
4577 eCsrBand band = -1;
4578 sme_GetFreqBand((tHalHandle)(pHddCtx->hHal), &band);
4579 switch (band)
4580 {
4581 case eCSR_BAND_ALL:
4582 *pBand = WLAN_HDD_UI_BAND_AUTO;
4583 break;
4584
4585 case eCSR_BAND_24:
4586 *pBand = WLAN_HDD_UI_BAND_2_4_GHZ;
4587 break;
4588
4589 case eCSR_BAND_5G:
4590 *pBand = WLAN_HDD_UI_BAND_5_GHZ;
4591 break;
4592
4593 default:
4594 hddLog( VOS_TRACE_LEVEL_WARN, "%s: Invalid Band %d", __func__, band);
4595 *pBand = -1;
4596 break;
4597 }
4598}
4599
4600/**---------------------------------------------------------------------------
4601
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004602 \brief hdd_parse_send_action_frame_data() - HDD Parse send action frame data
4603
4604 This function parses the send action frame data passed in the format
4605 SENDACTIONFRAME<space><bssid><space><channel><space><dwelltime><space><data>
4606
Srinivas Girigowda56076852013-08-20 14:00:50 -07004607 \param - pValue Pointer to input data
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004608 \param - pTargetApBssid Pointer to target Ap bssid
4609 \param - pChannel Pointer to the Target AP channel
4610 \param - pDwellTime Pointer to the time to stay off-channel after transmitting action frame
4611 \param - pBuf Pointer to data
4612 \param - pBufLen Pointer to data length
4613
4614 \return - 0 for success non-zero for failure
4615
4616 --------------------------------------------------------------------------*/
4617VOS_STATUS hdd_parse_send_action_frame_data(tANI_U8 *pValue, tANI_U8 *pTargetApBssid, tANI_U8 *pChannel,
4618 tANI_U8 *pDwellTime, tANI_U8 **pBuf, tANI_U8 *pBufLen)
4619{
4620 tANI_U8 *inPtr = pValue;
4621 tANI_U8 *dataEnd;
4622 int tempInt;
4623 int j = 0;
4624 int i = 0;
4625 int v = 0;
4626 tANI_U8 tempBuf[32];
4627 tANI_U8 tempByte = 0;
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004628 /* 12 hexa decimal digits, 5 ':' and '\0' */
4629 tANI_U8 macAddress[18];
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004630
4631 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
4632 /*no argument after the command*/
4633 if (NULL == inPtr)
4634 {
4635 return -EINVAL;
4636 }
4637
4638 /*no space after the command*/
4639 else if (SPACE_ASCII_VALUE != *inPtr)
4640 {
4641 return -EINVAL;
4642 }
4643
4644 /*removing empty spaces*/
4645 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
4646
4647 /*no argument followed by spaces*/
4648 if ('\0' == *inPtr)
4649 {
4650 return -EINVAL;
4651 }
4652
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004653 v = sscanf(inPtr, "%17s", macAddress);
4654 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004655 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004656 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4657 "Invalid MAC address or All hex inputs are not read (%d)", v);
4658 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004659 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004660
4661 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
4662 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
4663 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
4664 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
4665 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
4666 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004667
4668 /* point to the next argument */
4669 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
4670 /*no argument after the command*/
4671 if (NULL == inPtr) return -EINVAL;
4672
4673 /*removing empty spaces*/
4674 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
4675
4676 /*no argument followed by spaces*/
4677 if ('\0' == *inPtr)
4678 {
4679 return -EINVAL;
4680 }
4681
4682 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004683 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004684 if (1 != v) return -EINVAL;
4685
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004686 v = kstrtos32(tempBuf, 10, &tempInt);
Agarwal Ashish353b3a82014-04-08 14:55:11 +05304687 if ( v < 0 || tempInt <= 0 || tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX )
Kiet Lambe150c22013-11-21 16:30:32 +05304688 return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004689
4690 *pChannel = tempInt;
4691
4692 /* point to the next argument */
4693 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
4694 /*no argument after the command*/
4695 if (NULL == inPtr) return -EINVAL;
4696 /*removing empty spaces*/
4697 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
4698
4699 /*no argument followed by spaces*/
4700 if ('\0' == *inPtr)
4701 {
4702 return -EINVAL;
4703 }
4704
4705 /*getting the next argument ie the dwell time */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004706 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004707 if (1 != v) return -EINVAL;
4708
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004709 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda5a6e0672014-01-09 14:42:57 -08004710 if ( v < 0 || tempInt < 0) return -EINVAL;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004711
4712 *pDwellTime = tempInt;
4713
4714 /* point to the next argument */
4715 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
4716 /*no argument after the command*/
4717 if (NULL == inPtr) return -EINVAL;
4718 /*removing empty spaces*/
4719 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
4720
4721 /*no argument followed by spaces*/
4722 if ('\0' == *inPtr)
4723 {
4724 return -EINVAL;
4725 }
4726
4727 /* find the length of data */
4728 dataEnd = inPtr;
4729 while(('\0' != *dataEnd) )
4730 {
4731 dataEnd++;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004732 }
Kiet Lambe150c22013-11-21 16:30:32 +05304733 *pBufLen = dataEnd - inPtr ;
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004734 if ( *pBufLen <= 0) return -EINVAL;
4735
Srinivas Girigowdab5ae85d2013-06-03 10:51:45 -07004736 /* Allocate the number of bytes based on the number of input characters
4737 whether it is even or odd.
4738 if the number of input characters are even, then we need N/2 byte.
4739 if the number of input characters are odd, then we need do (N+1)/2 to
4740 compensate rounding off.
4741 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
4742 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
4743 *pBuf = vos_mem_malloc((*pBufLen + 1)/2);
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004744 if (NULL == *pBuf)
4745 {
4746 hddLog(VOS_TRACE_LEVEL_FATAL,
4747 "%s: vos_mem_alloc failed ", __func__);
4748 return -EINVAL;
4749 }
4750
4751 /* the buffer received from the upper layer is character buffer,
4752 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
4753 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
4754 and f0 in 3rd location */
4755 for (i = 0, j = 0; j < *pBufLen; j += 2)
4756 {
Kiet Lambe150c22013-11-21 16:30:32 +05304757 if( j+1 == *pBufLen)
4758 {
4759 tempByte = hdd_parse_hex(inPtr[j]);
4760 }
4761 else
4762 {
4763 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
4764 }
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004765 (*pBuf)[i++] = tempByte;
4766 }
4767 *pBufLen = i;
4768 return VOS_STATUS_SUCCESS;
4769}
4770
Srinivas Girigowda100eb322013-03-15 16:48:20 -07004771/**---------------------------------------------------------------------------
4772
Srinivas Girigowdade697412013-02-14 16:31:48 -08004773 \brief hdd_parse_channellist() - HDD Parse channel list
4774
4775 This function parses the channel list passed in the format
4776 SETROAMSCANCHANNELS<space><Number of channels><space>Channel 1<space>Channel 2<space>Channel N
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07004777 if the Number of channels (N) does not match with the actual number of channels passed
4778 then take the minimum of N and count of (Ch1, Ch2, ...Ch M)
4779 For example, if SETROAMSCANCHANNELS 3 36 40 44 48, only 36, 40 and 44 shall be taken.
4780 If SETROAMSCANCHANNELS 5 36 40 44 48, ignore 5 and take 36, 40, 44 and 48.
4781 This function does not take care of removing duplicate channels from the list
Srinivas Girigowdade697412013-02-14 16:31:48 -08004782
4783 \param - pValue Pointer to input channel list
4784 \param - ChannelList Pointer to local output array to record channel list
4785 \param - pNumChannels Pointer to number of roam scan channels
4786
4787 \return - 0 for success non-zero for failure
4788
4789 --------------------------------------------------------------------------*/
4790VOS_STATUS hdd_parse_channellist(tANI_U8 *pValue, tANI_U8 *pChannelList, tANI_U8 *pNumChannels)
4791{
4792 tANI_U8 *inPtr = pValue;
4793 int tempInt;
4794 int j = 0;
4795 int v = 0;
4796 char buf[32];
4797
4798 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
4799 /*no argument after the command*/
4800 if (NULL == inPtr)
4801 {
4802 return -EINVAL;
4803 }
4804
4805 /*no space after the command*/
4806 else if (SPACE_ASCII_VALUE != *inPtr)
4807 {
4808 return -EINVAL;
4809 }
4810
4811 /*removing empty spaces*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07004812 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004813
4814 /*no argument followed by spaces*/
4815 if ('\0' == *inPtr)
4816 {
4817 return -EINVAL;
4818 }
4819
4820 /*getting the first argument ie the number of channels*/
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004821 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004822 if (1 != v) return -EINVAL;
4823
Srinivas Girigowdade697412013-02-14 16:31:48 -08004824 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07004825 if ((v < 0) ||
4826 (tempInt <= 0) ||
4827 (tempInt > WNI_CFG_VALID_CHANNEL_LIST_LEN))
4828 {
4829 return -EINVAL;
4830 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004831
4832 *pNumChannels = tempInt;
4833
4834 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
4835 "Number of channels are: %d", *pNumChannels);
4836
4837 for (j = 0; j < (*pNumChannels); j++)
4838 {
4839 /*inPtr pointing to the beginning of first space after number of channels*/
4840 inPtr = strpbrk( inPtr, " " );
4841 /*no channel list after the number of channels argument*/
4842 if (NULL == inPtr)
4843 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07004844 if (0 != j)
4845 {
4846 *pNumChannels = j;
4847 return VOS_STATUS_SUCCESS;
4848 }
4849 else
4850 {
4851 return -EINVAL;
4852 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004853 }
4854
4855 /*removing empty space*/
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07004856 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr)) inPtr++;
Srinivas Girigowdade697412013-02-14 16:31:48 -08004857
4858 /*no channel list after the number of channels argument and spaces*/
4859 if ( '\0' == *inPtr )
4860 {
Srinivas Girigowdacf9a9b42013-03-21 11:55:24 -07004861 if (0 != j)
4862 {
4863 *pNumChannels = j;
4864 return VOS_STATUS_SUCCESS;
4865 }
4866 else
4867 {
4868 return -EINVAL;
4869 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004870 }
4871
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004872 v = sscanf(inPtr, "%31s ", buf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004873 if (1 != v) return -EINVAL;
4874
Srinivas Girigowdade697412013-02-14 16:31:48 -08004875 v = kstrtos32(buf, 10, &tempInt);
Jeff Johnsona1f9afb2013-04-03 09:13:31 -07004876 if ((v < 0) ||
4877 (tempInt <= 0) ||
4878 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
4879 {
4880 return -EINVAL;
4881 }
Srinivas Girigowdade697412013-02-14 16:31:48 -08004882 pChannelList[j] = tempInt;
4883
4884 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
4885 "Channel %d added to preferred channel list",
4886 pChannelList[j] );
4887 }
4888
Srinivas Girigowdade697412013-02-14 16:31:48 -08004889 return VOS_STATUS_SUCCESS;
4890}
4891
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004892
4893/**---------------------------------------------------------------------------
4894
4895 \brief hdd_parse_reassoc_command_data() - HDD Parse reassoc command data
4896
4897 This function parses the reasoc command data passed in the format
4898 REASSOC<space><bssid><space><channel>
4899
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004900 \param - pValue Pointer to input data (its a NUL terminated string)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004901 \param - pTargetApBssid Pointer to target Ap bssid
4902 \param - pChannel Pointer to the Target AP channel
4903
4904 \return - 0 for success non-zero for failure
4905
4906 --------------------------------------------------------------------------*/
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004907VOS_STATUS hdd_parse_reassoc_command_data(tANI_U8 *pValue,
4908 tANI_U8 *pTargetApBssid, tANI_U8 *pChannel)
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004909{
4910 tANI_U8 *inPtr = pValue;
4911 int tempInt;
4912 int v = 0;
4913 tANI_U8 tempBuf[32];
Kiet Lamaa8e15a2014-02-11 23:30:06 -08004914 /* 12 hexa decimal digits, 5 ':' and '\0' */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004915 tANI_U8 macAddress[18];
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004916
4917 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
4918 /*no argument after the command*/
4919 if (NULL == inPtr)
4920 {
4921 return -EINVAL;
4922 }
4923
4924 /*no space after the command*/
4925 else if (SPACE_ASCII_VALUE != *inPtr)
4926 {
4927 return -EINVAL;
4928 }
4929
4930 /*removing empty spaces*/
4931 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
4932
4933 /*no argument followed by spaces*/
4934 if ('\0' == *inPtr)
4935 {
4936 return -EINVAL;
4937 }
4938
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004939 v = sscanf(inPtr, "%17s", macAddress);
4940 if (!((1 == v) && hdd_is_valid_mac_address(macAddress)))
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004941 {
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004942 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4943 "Invalid MAC address or All hex inputs are not read (%d)", v);
4944 return -EINVAL;
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004945 }
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004946
4947 pTargetApBssid[0] = hdd_parse_hex(macAddress[0]) << 4 | hdd_parse_hex(macAddress[1]);
4948 pTargetApBssid[1] = hdd_parse_hex(macAddress[3]) << 4 | hdd_parse_hex(macAddress[4]);
4949 pTargetApBssid[2] = hdd_parse_hex(macAddress[6]) << 4 | hdd_parse_hex(macAddress[7]);
4950 pTargetApBssid[3] = hdd_parse_hex(macAddress[9]) << 4 | hdd_parse_hex(macAddress[10]);
4951 pTargetApBssid[4] = hdd_parse_hex(macAddress[12]) << 4 | hdd_parse_hex(macAddress[13]);
4952 pTargetApBssid[5] = hdd_parse_hex(macAddress[15]) << 4 | hdd_parse_hex(macAddress[16]);
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004953
4954 /* point to the next argument */
4955 inPtr = strnchr(inPtr, strlen(inPtr), SPACE_ASCII_VALUE);
4956 /*no argument after the command*/
4957 if (NULL == inPtr) return -EINVAL;
4958
4959 /*removing empty spaces*/
4960 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
4961
4962 /*no argument followed by spaces*/
4963 if ('\0' == *inPtr)
4964 {
4965 return -EINVAL;
4966 }
4967
4968 /*getting the next argument ie the channel number */
Srinivas Girigowda4081bb12014-01-06 17:12:58 -08004969 v = sscanf(inPtr, "%31s ", tempBuf);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004970 if (1 != v) return -EINVAL;
4971
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004972 v = kstrtos32(tempBuf, 10, &tempInt);
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004973 if ((v < 0) ||
Padma, Santhosh Kumar0fa809b2014-11-13 14:56:56 +05304974 (tempInt < 0) ||
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07004975 (tempInt > WNI_CFG_CURRENT_CHANNEL_STAMAX))
4976 {
4977 return -EINVAL;
4978 }
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07004979
4980 *pChannel = tempInt;
4981 return VOS_STATUS_SUCCESS;
4982}
4983
4984#endif
4985
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08004986#if defined(FEATURE_WLAN_ESE) && defined(FEATURE_WLAN_ESE_UPLOAD)
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07004987/**---------------------------------------------------------------------------
4988
4989 \brief hdd_parse_get_cckm_ie() - HDD Parse and fetch the CCKM IE
4990
4991 This function parses the SETCCKM IE command
4992 SETCCKMIE<space><ie data>
4993
4994 \param - pValue Pointer to input data
4995 \param - pCckmIe Pointer to output cckm Ie
4996 \param - pCckmIeLen Pointer to output cckm ie length
4997
4998 \return - 0 for success non-zero for failure
4999
5000 --------------------------------------------------------------------------*/
5001VOS_STATUS hdd_parse_get_cckm_ie(tANI_U8 *pValue, tANI_U8 **pCckmIe,
5002 tANI_U8 *pCckmIeLen)
5003{
5004 tANI_U8 *inPtr = pValue;
5005 tANI_U8 *dataEnd;
5006 int j = 0;
5007 int i = 0;
5008 tANI_U8 tempByte = 0;
5009
5010 inPtr = strnchr(pValue, strlen(pValue), SPACE_ASCII_VALUE);
5011 /*no argument after the command*/
5012 if (NULL == inPtr)
5013 {
5014 return -EINVAL;
5015 }
5016
5017 /*no space after the command*/
5018 else if (SPACE_ASCII_VALUE != *inPtr)
5019 {
5020 return -EINVAL;
5021 }
5022
5023 /*removing empty spaces*/
5024 while ((SPACE_ASCII_VALUE == *inPtr) && ('\0' != *inPtr) ) inPtr++;
5025
5026 /*no argument followed by spaces*/
5027 if ('\0' == *inPtr)
5028 {
5029 return -EINVAL;
5030 }
5031
5032 /* find the length of data */
5033 dataEnd = inPtr;
5034 while(('\0' != *dataEnd) )
5035 {
5036 dataEnd++;
5037 ++(*pCckmIeLen);
5038 }
5039 if ( *pCckmIeLen <= 0) return -EINVAL;
5040
5041 /* Allocate the number of bytes based on the number of input characters
5042 whether it is even or odd.
5043 if the number of input characters are even, then we need N/2 byte.
5044 if the number of input characters are odd, then we need do (N+1)/2 to
5045 compensate rounding off.
5046 For example, if N = 18, then (18 + 1)/2 = 9 bytes are enough.
5047 If N = 19, then we need 10 bytes, hence (19 + 1)/2 = 10 bytes */
5048 *pCckmIe = vos_mem_malloc((*pCckmIeLen + 1)/2);
5049 if (NULL == *pCckmIe)
5050 {
5051 hddLog(VOS_TRACE_LEVEL_FATAL,
5052 "%s: vos_mem_alloc failed ", __func__);
5053 return -EINVAL;
5054 }
5055 vos_mem_zero(*pCckmIe, (*pCckmIeLen + 1)/2);
5056 /* the buffer received from the upper layer is character buffer,
5057 we need to prepare the buffer taking 2 characters in to a U8 hex decimal number
5058 for example 7f0000f0...form a buffer to contain 7f in 0th location, 00 in 1st
5059 and f0 in 3rd location */
5060 for (i = 0, j = 0; j < *pCckmIeLen; j += 2)
5061 {
5062 tempByte = (hdd_parse_hex(inPtr[j]) << 4) | (hdd_parse_hex(inPtr[j + 1]));
5063 (*pCckmIe)[i++] = tempByte;
5064 }
5065 *pCckmIeLen = i;
5066
5067 return VOS_STATUS_SUCCESS;
5068}
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005069#endif /* FEATURE_WLAN_ESE && FEATURE_WLAN_ESE_UPLOAD */
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07005070
Jeff Johnson295189b2012-06-20 16:38:30 -07005071/**---------------------------------------------------------------------------
5072
Srinivas Girigowda0c69aee2013-10-09 17:21:01 -07005073 \brief hdd_is_valid_mac_address() - Validate MAC address
5074
5075 This function validates whether the given MAC address is valid or not
5076 Expected MAC address is of the format XX:XX:XX:XX:XX:XX
5077 where X is the hexa decimal digit character and separated by ':'
5078 This algorithm works even if MAC address is not separated by ':'
5079
5080 This code checks given input string mac contains exactly 12 hexadecimal digits.
5081 and a separator colon : appears in the input string only after
5082 an even number of hex digits.
5083
5084 \param - pMacAddr pointer to the input MAC address
5085 \return - 1 for valid and 0 for invalid
5086
5087 --------------------------------------------------------------------------*/
5088
5089v_BOOL_t hdd_is_valid_mac_address(const tANI_U8 *pMacAddr)
5090{
5091 int xdigit = 0;
5092 int separator = 0;
5093 while (*pMacAddr)
5094 {
5095 if (isxdigit(*pMacAddr))
5096 {
5097 xdigit++;
5098 }
5099 else if (':' == *pMacAddr)
5100 {
5101 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
5102 break;
5103
5104 ++separator;
5105 }
5106 else
5107 {
5108 separator = -1;
5109 /* Invalid MAC found */
5110 return 0;
5111 }
5112 ++pMacAddr;
5113 }
5114 return (xdigit == 12 && (separator == 5 || separator == 0));
5115}
5116
5117/**---------------------------------------------------------------------------
5118
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305119 \brief __hdd_open() - HDD Open function
Jeff Johnson295189b2012-06-20 16:38:30 -07005120
5121 \param - dev Pointer to net_device structure
5122
5123 \return - 0 for success non-zero for failure
5124
5125 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305126int __hdd_open(struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07005127{
5128 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
5129 hdd_context_t *pHddCtx;
5130 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
5131 VOS_STATUS status;
5132 v_BOOL_t in_standby = TRUE;
5133
5134 if (NULL == pAdapter)
5135 {
5136 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05305137 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005138 return -ENODEV;
5139 }
5140
5141 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05305142 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
5143 pAdapter->sessionId, pAdapter->device_mode));
Jeff Johnson295189b2012-06-20 16:38:30 -07005144 if (NULL == pHddCtx)
5145 {
5146 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005147 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005148 return -ENODEV;
5149 }
5150
5151 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
5152 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
5153 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07005154 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
5155 {
5156 hddLog(VOS_TRACE_LEVEL_INFO, "%s: chip already out of standby",
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05305157 __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07005158 in_standby = FALSE;
5159 break;
5160 }
5161 else
5162 {
5163 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
5164 pAdapterNode = pNext;
5165 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005166 }
5167
5168 if (TRUE == in_standby)
5169 {
5170 if (VOS_STATUS_SUCCESS != wlan_hdd_exit_lowpower(pHddCtx, pAdapter))
5171 {
5172 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to bring "
5173 "wlan out of power save", __func__);
5174 return -EINVAL;
5175 }
5176 }
5177
Jeff Johnson6a81ca42013-04-05 10:37:08 -07005178 set_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07005179 if (hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
5180 {
5181 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005182 "%s: Enabling Tx Queues", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005183 /* Enable TX queues only when we are connected */
5184 netif_tx_start_all_queues(dev);
5185 }
5186
5187 return 0;
5188}
5189
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305190/**---------------------------------------------------------------------------
5191
5192 \brief hdd_open() - Wrapper function for __hdd_open to protect it from SSR
5193
5194 This is called in response to ifconfig up
5195
5196 \param - dev Pointer to net_device structure
5197
5198 \return - 0 for success non-zero for failure
5199
5200 --------------------------------------------------------------------------*/
5201int hdd_open(struct net_device *dev)
5202{
5203 int ret;
5204
5205 vos_ssr_protect(__func__);
5206 ret = __hdd_open(dev);
5207 vos_ssr_unprotect(__func__);
5208
5209 return ret;
5210}
5211
Jeff Johnson295189b2012-06-20 16:38:30 -07005212int hdd_mon_open (struct net_device *dev)
5213{
5214 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
5215
5216 if(pAdapter == NULL) {
5217 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005218 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08005219 return -EINVAL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005220 }
5221
5222 netif_start_queue(dev);
5223
5224 return 0;
5225}
5226/**---------------------------------------------------------------------------
5227
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305228 \brief __hdd_stop() - HDD stop function
Jeff Johnson295189b2012-06-20 16:38:30 -07005229
5230 \param - dev Pointer to net_device structure
5231
5232 \return - 0 for success non-zero for failure
5233
5234 --------------------------------------------------------------------------*/
5235
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305236int __hdd_stop (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07005237{
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05305238 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005239 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
5240 hdd_context_t *pHddCtx;
5241 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
5242 VOS_STATUS status;
5243 v_BOOL_t enter_standby = TRUE;
5244
5245 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07005246 if (NULL == pAdapter)
5247 {
5248 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Agarwal Ashish971c2882013-10-30 20:11:12 +05305249 "%s: pAdapter is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005250 return -ENODEV;
5251 }
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05305252 MTRACE(vos_trace(VOS_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
5253 pAdapter->sessionId, pAdapter->device_mode));
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05305254
5255 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5256 ret = wlan_hdd_validate_context(pHddCtx);
5257 if (ret)
Jeff Johnson295189b2012-06-20 16:38:30 -07005258 {
Vinay Krishna Eranna90f43532014-10-27 16:45:54 +05305259 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5260 "%s: HDD context is not valid!", __func__);
5261 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07005262 }
5263
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05305264 /* Nothing to be done if the interface is not opened */
5265 if (VOS_FALSE == test_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags))
5266 {
5267 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5268 "%s: NETDEV Interface is not OPENED", __func__);
5269 return -ENODEV;
5270 }
5271
5272 /* Make sure the interface is marked as closed */
Jeff Johnson6a81ca42013-04-05 10:37:08 -07005273 clear_bit(DEVICE_IFACE_OPENED, &pAdapter->event_flags);
Jeff Johnson295189b2012-06-20 16:38:30 -07005274 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disabling OS Tx queues", __func__);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05305275
5276 /* Disable TX on the interface, after this hard_start_xmit() will not
5277 * be called on that interface
5278 */
Jeff Johnson295189b2012-06-20 16:38:30 -07005279 netif_tx_disable(pAdapter->dev);
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05305280
5281 /* Mark the interface status as "down" for outside world */
Jeff Johnson295189b2012-06-20 16:38:30 -07005282 netif_carrier_off(pAdapter->dev);
5283
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05305284 /* The interface is marked as down for outside world (aka kernel)
5285 * But the driver is pretty much alive inside. The driver needs to
5286 * tear down the existing connection on the netdev (session)
5287 * cleanup the data pipes and wait until the control plane is stabilized
5288 * for this interface. The call also needs to wait until the above
5289 * mentioned actions are completed before returning to the caller.
5290 * Notice that the hdd_stop_adapter is requested not to close the session
5291 * That is intentional to be able to scan if it is a STA/P2P interface
5292 */
5293 hdd_stop_adapter(pHddCtx, pAdapter, VOS_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -07005294
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05305295 /* DeInit the adapter. This ensures datapath cleanup as well */
5296 hdd_deinit_adapter(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005297 /* SoftAP ifaces should never go in power save mode
5298 making sure same here. */
5299 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode )
5300 || (WLAN_HDD_MONITOR == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07005301 || (WLAN_HDD_P2P_GO == pAdapter->device_mode )
Jeff Johnson295189b2012-06-20 16:38:30 -07005302 )
5303 {
5304 /* SoftAP mode, so return from here */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05305305 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5306 "%s: In SAP MODE", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005307 EXIT();
5308 return 0;
5309 }
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05305310 /* Find if any iface is up. If any iface is up then can't put device to
5311 * sleep/power save mode
5312 */
Jeff Johnson295189b2012-06-20 16:38:30 -07005313 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
5314 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
5315 {
Jeff Johnson6a81ca42013-04-05 10:37:08 -07005316 if (test_bit(DEVICE_IFACE_OPENED, &pAdapterNode->pAdapter->event_flags))
5317 {
5318 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Still other ifaces are up cannot "
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05305319 "put device to sleep", __func__);
Jeff Johnson6a81ca42013-04-05 10:37:08 -07005320 enter_standby = FALSE;
5321 break;
5322 }
5323 else
5324 {
5325 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
5326 pAdapterNode = pNext;
5327 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005328 }
5329
5330 if (TRUE == enter_standby)
5331 {
5332 hddLog(VOS_TRACE_LEVEL_INFO, "%s: All Interfaces are Down "
5333 "entering standby", __func__);
5334 if (VOS_STATUS_SUCCESS != wlan_hdd_enter_lowpower(pHddCtx))
5335 {
5336 /*log and return success*/
5337 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to put "
5338 "wlan in power save", __func__);
5339 }
5340 }
5341
5342 EXIT();
5343 return 0;
5344}
5345
5346/**---------------------------------------------------------------------------
5347
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305348 \brief hdd_stop() - wrapper_function for __hdd_stop to protect it from SSR
Jeff Johnson295189b2012-06-20 16:38:30 -07005349
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305350 This is called in response to ifconfig down
5351
5352 \param - dev Pointer to net_device structure
5353
5354 \return - 0 for success non-zero for failure
5355-----------------------------------------------------------------------------*/
5356int hdd_stop (struct net_device *dev)
5357{
5358 int ret;
5359
5360 vos_ssr_protect(__func__);
5361 ret = __hdd_stop(dev);
5362 vos_ssr_unprotect(__func__);
5363
5364 return ret;
5365}
5366
5367/**---------------------------------------------------------------------------
5368
5369 \brief __hdd_uninit() - HDD uninit function
Jeff Johnson295189b2012-06-20 16:38:30 -07005370
5371 \param - dev Pointer to net_device structure
5372
5373 \return - void
5374
5375 --------------------------------------------------------------------------*/
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305376static void __hdd_uninit (struct net_device *dev)
Jeff Johnson295189b2012-06-20 16:38:30 -07005377{
5378 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
5379
5380 ENTER();
5381
5382 do
5383 {
5384 if (NULL == pAdapter)
5385 {
5386 hddLog(VOS_TRACE_LEVEL_FATAL,
5387 "%s: NULL pAdapter", __func__);
5388 break;
5389 }
5390
5391 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
5392 {
5393 hddLog(VOS_TRACE_LEVEL_FATAL,
5394 "%s: Invalid magic", __func__);
5395 break;
5396 }
5397
5398 if (NULL == pAdapter->pHddCtx)
5399 {
5400 hddLog(VOS_TRACE_LEVEL_FATAL,
5401 "%s: NULL pHddCtx", __func__);
5402 break;
5403 }
5404
5405 if (dev != pAdapter->dev)
5406 {
5407 hddLog(VOS_TRACE_LEVEL_FATAL,
5408 "%s: Invalid device reference", __func__);
5409 /* we haven't validated all cases so let this go for now */
5410 }
5411
5412 hdd_deinit_adapter(pAdapter->pHddCtx, pAdapter);
5413
5414 /* after uninit our adapter structure will no longer be valid */
5415 pAdapter->dev = NULL;
5416 pAdapter->magic = 0;
5417 } while (0);
5418
5419 EXIT();
5420}
5421
5422/**---------------------------------------------------------------------------
5423
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305424 \brief hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
5425
5426 This is called during the netdev unregister to uninitialize all data
5427associated with the device
5428
5429 \param - dev Pointer to net_device structure
5430
5431 \return - void
5432
5433 --------------------------------------------------------------------------*/
5434static void hdd_uninit (struct net_device *dev)
5435{
5436 vos_ssr_protect(__func__);
5437 __hdd_uninit(dev);
5438 vos_ssr_unprotect(__func__);
5439}
5440
5441/**---------------------------------------------------------------------------
5442
Jeff Johnson295189b2012-06-20 16:38:30 -07005443 \brief hdd_release_firmware() -
5444
5445 This function calls the release firmware API to free the firmware buffer.
5446
5447 \param - pFileName Pointer to the File Name.
5448 pCtx - Pointer to the adapter .
5449
5450
5451 \return - 0 for success, non zero for failure
5452
5453 --------------------------------------------------------------------------*/
5454
5455VOS_STATUS hdd_release_firmware(char *pFileName,v_VOID_t *pCtx)
5456{
5457 VOS_STATUS status = VOS_STATUS_SUCCESS;
5458 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
5459 ENTER();
5460
5461
5462 if (!strcmp(WLAN_FW_FILE, pFileName)) {
5463
5464 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"%s: Loaded firmware file is %s",__func__,pFileName);
5465
5466 if(pHddCtx->fw) {
5467 release_firmware(pHddCtx->fw);
5468 pHddCtx->fw = NULL;
5469 }
5470 else
5471 status = VOS_STATUS_E_FAILURE;
5472 }
5473 else if (!strcmp(WLAN_NV_FILE,pFileName)) {
5474 if(pHddCtx->nv) {
5475 release_firmware(pHddCtx->nv);
5476 pHddCtx->nv = NULL;
5477 }
5478 else
5479 status = VOS_STATUS_E_FAILURE;
5480
5481 }
5482
5483 EXIT();
5484 return status;
5485}
5486
5487/**---------------------------------------------------------------------------
5488
5489 \brief hdd_request_firmware() -
5490
5491 This function reads the firmware file using the request firmware
5492 API and returns the the firmware data and the firmware file size.
5493
5494 \param - pfileName - Pointer to the file name.
5495 - pCtx - Pointer to the adapter .
5496 - ppfw_data - Pointer to the pointer of the firmware data.
5497 - pSize - Pointer to the file size.
5498
5499 \return - VOS_STATUS_SUCCESS for success, VOS_STATUS_E_FAILURE for failure
5500
5501 --------------------------------------------------------------------------*/
5502
5503
5504VOS_STATUS hdd_request_firmware(char *pfileName,v_VOID_t *pCtx,v_VOID_t **ppfw_data, v_SIZE_t *pSize)
5505{
5506 int status;
5507 VOS_STATUS retval = VOS_STATUS_SUCCESS;
5508 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
5509 ENTER();
5510
5511 if( (!strcmp(WLAN_FW_FILE, pfileName)) ) {
5512
5513 status = request_firmware(&pHddCtx->fw, pfileName, pHddCtx->parent_dev);
5514
5515 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
5516 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Firmware %s download failed",
5517 __func__, pfileName);
5518 retval = VOS_STATUS_E_FAILURE;
5519 }
5520
5521 else {
5522 *ppfw_data = (v_VOID_t *)pHddCtx->fw->data;
5523 *pSize = pHddCtx->fw->size;
5524 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Firmware size = %d",
5525 __func__, *pSize);
5526 }
5527 }
5528 else if(!strcmp(WLAN_NV_FILE, pfileName)) {
5529
5530 status = request_firmware(&pHddCtx->nv, pfileName, pHddCtx->parent_dev);
5531
5532 if(status || !pHddCtx->nv || !pHddCtx->nv->data) {
5533 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: nv %s download failed",
5534 __func__, pfileName);
5535 retval = VOS_STATUS_E_FAILURE;
5536 }
5537
5538 else {
5539 *ppfw_data = (v_VOID_t *)pHddCtx->nv->data;
5540 *pSize = pHddCtx->nv->size;
5541 hddLog(VOS_TRACE_LEVEL_INFO, "%s: nv file size = %d",
5542 __func__, *pSize);
5543 }
5544 }
5545
5546 EXIT();
5547 return retval;
5548}
5549/**---------------------------------------------------------------------------
5550 \brief hdd_full_pwr_cbk() - HDD full power callbackfunction
5551
5552 This is the function invoked by SME to inform the result of a full power
5553 request issued by HDD
5554
5555 \param - callbackcontext - Pointer to cookie
5556 status - result of request
5557
5558 \return - None
5559
5560--------------------------------------------------------------------------*/
5561void hdd_full_pwr_cbk(void *callbackContext, eHalStatus status)
5562{
5563 hdd_context_t *pHddCtx = (hdd_context_t*)callbackContext;
5564
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07005565 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"HDD full Power callback status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07005566 if(&pHddCtx->full_pwr_comp_var)
5567 {
5568 complete(&pHddCtx->full_pwr_comp_var);
5569 }
5570}
5571
5572/**---------------------------------------------------------------------------
5573
5574 \brief hdd_req_bmps_cbk() - HDD Request BMPS callback function
5575
5576 This is the function invoked by SME to inform the result of BMPS
5577 request issued by HDD
5578
5579 \param - callbackcontext - Pointer to cookie
5580 status - result of request
5581
5582 \return - None
5583
5584--------------------------------------------------------------------------*/
5585void hdd_req_bmps_cbk(void *callbackContext, eHalStatus status)
5586{
5587
5588 struct completion *completion_var = (struct completion*) callbackContext;
5589
Arif Hussain6d2a3322013-11-17 19:50:10 -08005590 hddLog(VOS_TRACE_LEVEL_ERROR, "HDD BMPS request Callback, status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07005591 if(completion_var != NULL)
5592 {
5593 complete(completion_var);
5594 }
5595}
5596
5597/**---------------------------------------------------------------------------
5598
5599 \brief hdd_get_cfg_file_size() -
5600
5601 This function reads the configuration file using the request firmware
5602 API and returns the configuration file size.
5603
5604 \param - pCtx - Pointer to the adapter .
5605 - pFileName - Pointer to the file name.
5606 - pBufSize - Pointer to the buffer size.
5607
5608 \return - 0 for success, non zero for failure
5609
5610 --------------------------------------------------------------------------*/
5611
5612VOS_STATUS hdd_get_cfg_file_size(v_VOID_t *pCtx, char *pFileName, v_SIZE_t *pBufSize)
5613{
5614 int status;
5615 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
5616
5617 ENTER();
5618
5619 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
5620
5621 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
5622 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
5623 status = VOS_STATUS_E_FAILURE;
5624 }
5625 else {
5626 *pBufSize = pHddCtx->fw->size;
5627 hddLog(VOS_TRACE_LEVEL_INFO, "%s: CFG size = %d", __func__, *pBufSize);
5628 release_firmware(pHddCtx->fw);
5629 pHddCtx->fw = NULL;
5630 }
5631
5632 EXIT();
5633 return VOS_STATUS_SUCCESS;
5634}
5635
5636/**---------------------------------------------------------------------------
5637
5638 \brief hdd_read_cfg_file() -
5639
5640 This function reads the configuration file using the request firmware
5641 API and returns the cfg data and the buffer size of the configuration file.
5642
5643 \param - pCtx - Pointer to the adapter .
5644 - pFileName - Pointer to the file name.
5645 - pBuffer - Pointer to the data buffer.
5646 - pBufSize - Pointer to the buffer size.
5647
5648 \return - 0 for success, non zero for failure
5649
5650 --------------------------------------------------------------------------*/
5651
5652VOS_STATUS hdd_read_cfg_file(v_VOID_t *pCtx, char *pFileName,
5653 v_VOID_t *pBuffer, v_SIZE_t *pBufSize)
5654{
5655 int status;
5656 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
5657
5658 ENTER();
5659
5660 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
5661
5662 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
5663 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
5664 return VOS_STATUS_E_FAILURE;
5665 }
5666 else {
5667 if(*pBufSize != pHddCtx->fw->size) {
5668 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Caller sets invalid CFG "
5669 "file size", __func__);
5670 release_firmware(pHddCtx->fw);
5671 pHddCtx->fw = NULL;
5672 return VOS_STATUS_E_FAILURE;
5673 }
5674 else {
5675 if(pBuffer) {
5676 vos_mem_copy(pBuffer,pHddCtx->fw->data,*pBufSize);
5677 }
5678 release_firmware(pHddCtx->fw);
5679 pHddCtx->fw = NULL;
5680 }
5681 }
5682
5683 EXIT();
5684
5685 return VOS_STATUS_SUCCESS;
5686}
5687
5688/**---------------------------------------------------------------------------
5689
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305690 \brief __hdd_set_mac_address() -
Jeff Johnson295189b2012-06-20 16:38:30 -07005691
5692 This function sets the user specified mac address using
5693 the command ifconfig wlanX hw ether <mac adress>.
5694
5695 \param - dev - Pointer to the net device.
5696 - addr - Pointer to the sockaddr.
5697 \return - 0 for success, non zero for failure
5698
5699 --------------------------------------------------------------------------*/
5700
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305701static int __hdd_set_mac_address(struct net_device *dev, void *addr)
Jeff Johnson295189b2012-06-20 16:38:30 -07005702{
5703 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
5704 struct sockaddr *psta_mac_addr = addr;
5705 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
5706
5707 ENTER();
5708
5709 memcpy(&pAdapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005710 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
5711
5712 EXIT();
5713 return halStatus;
5714}
5715
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05305716/**---------------------------------------------------------------------------
5717
5718 \brief hdd_set_mac_address() -
5719
5720 Wrapper function to protect __hdd_set_mac_address() function from ssr
5721
5722 \param - dev - Pointer to the net device.
5723 - addr - Pointer to the sockaddr.
5724 \return - 0 for success, non zero for failure
5725
5726 --------------------------------------------------------------------------*/
5727static int hdd_set_mac_address(struct net_device *dev, void *addr)
5728{
5729 int ret;
5730
5731 vos_ssr_protect(__func__);
5732 ret = __hdd_set_mac_address(dev, addr);
5733 vos_ssr_unprotect(__func__);
5734
5735 return ret;
5736}
5737
Jeff Johnson295189b2012-06-20 16:38:30 -07005738tANI_U8* wlan_hdd_get_intf_addr(hdd_context_t* pHddCtx)
5739{
5740 int i;
5741 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
5742 {
Abhishek Singheb183782014-02-06 13:37:21 +05305743 if( 0 == ((pHddCtx->cfg_ini->intfAddrMask) & (1 << i)) )
Jeff Johnson295189b2012-06-20 16:38:30 -07005744 break;
5745 }
5746
5747 if( VOS_MAX_CONCURRENCY_PERSONA == i)
5748 return NULL;
5749
5750 pHddCtx->cfg_ini->intfAddrMask |= (1 << i);
5751 return &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0];
5752}
5753
5754void wlan_hdd_release_intf_addr(hdd_context_t* pHddCtx, tANI_U8* releaseAddr)
5755{
5756 int i;
5757 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
5758 {
5759 if ( !memcmp(releaseAddr, &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], 6) )
5760 {
5761 pHddCtx->cfg_ini->intfAddrMask &= ~(1 << i);
5762 break;
5763 }
5764 }
5765 return;
5766}
5767
5768#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
5769 static struct net_device_ops wlan_drv_ops = {
5770 .ndo_open = hdd_open,
5771 .ndo_stop = hdd_stop,
5772 .ndo_uninit = hdd_uninit,
5773 .ndo_start_xmit = hdd_hard_start_xmit,
5774 .ndo_tx_timeout = hdd_tx_timeout,
5775 .ndo_get_stats = hdd_stats,
5776 .ndo_do_ioctl = hdd_ioctl,
5777 .ndo_set_mac_address = hdd_set_mac_address,
5778 .ndo_select_queue = hdd_select_queue,
5779#ifdef WLAN_FEATURE_PACKET_FILTERING
5780#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0))
5781 .ndo_set_rx_mode = hdd_set_multicast_list,
5782#else
5783 .ndo_set_multicast_list = hdd_set_multicast_list,
5784#endif //LINUX_VERSION_CODE
5785#endif
5786 };
Jeff Johnson295189b2012-06-20 16:38:30 -07005787 static struct net_device_ops wlan_mon_drv_ops = {
5788 .ndo_open = hdd_mon_open,
5789 .ndo_stop = hdd_stop,
5790 .ndo_uninit = hdd_uninit,
5791 .ndo_start_xmit = hdd_mon_hard_start_xmit,
5792 .ndo_tx_timeout = hdd_tx_timeout,
5793 .ndo_get_stats = hdd_stats,
5794 .ndo_do_ioctl = hdd_ioctl,
5795 .ndo_set_mac_address = hdd_set_mac_address,
5796 };
Jeff Johnson295189b2012-06-20 16:38:30 -07005797
5798#endif
5799
5800void hdd_set_station_ops( struct net_device *pWlanDev )
5801{
5802#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
Jeff Johnson295189b2012-06-20 16:38:30 -07005803 pWlanDev->netdev_ops = &wlan_drv_ops;
5804#else
5805 pWlanDev->open = hdd_open;
5806 pWlanDev->stop = hdd_stop;
5807 pWlanDev->uninit = hdd_uninit;
5808 pWlanDev->hard_start_xmit = NULL;
5809 pWlanDev->tx_timeout = hdd_tx_timeout;
5810 pWlanDev->get_stats = hdd_stats;
5811 pWlanDev->do_ioctl = hdd_ioctl;
Jeff Johnson295189b2012-06-20 16:38:30 -07005812 pWlanDev->set_mac_address = hdd_set_mac_address;
5813#endif
5814}
5815
Jeff Johnsoneed415b2013-01-18 16:11:20 -08005816static hdd_adapter_t* hdd_alloc_station_adapter( hdd_context_t *pHddCtx, tSirMacAddr macAddr, const char* name )
Jeff Johnson295189b2012-06-20 16:38:30 -07005817{
5818 struct net_device *pWlanDev = NULL;
5819 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005820 /*
5821 * cfg80211 initialization and registration....
5822 */
5823 pWlanDev = alloc_netdev_mq(sizeof( hdd_adapter_t ), name, ether_setup, NUM_TX_QUEUES);
5824
Jeff Johnson295189b2012-06-20 16:38:30 -07005825 if(pWlanDev != NULL)
5826 {
5827
5828 //Save the pointer to the net_device in the HDD adapter
5829 pAdapter = (hdd_adapter_t*) netdev_priv( pWlanDev );
5830
Jeff Johnson295189b2012-06-20 16:38:30 -07005831 vos_mem_zero( pAdapter, sizeof( hdd_adapter_t ) );
5832
5833 pAdapter->dev = pWlanDev;
5834 pAdapter->pHddCtx = pHddCtx;
5835 pAdapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Agarwal Ashish47d18112014-08-04 19:55:07 +05305836 spin_lock_init(&pAdapter->lock_for_active_session);
Jeff Johnson295189b2012-06-20 16:38:30 -07005837
5838 init_completion(&pAdapter->session_open_comp_var);
5839 init_completion(&pAdapter->session_close_comp_var);
5840 init_completion(&pAdapter->disconnect_comp_var);
5841 init_completion(&pAdapter->linkup_event_var);
5842 init_completion(&pAdapter->cancel_rem_on_chan_var);
5843 init_completion(&pAdapter->rem_on_chan_ready_event);
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05305844 init_completion(&pAdapter->pno_comp_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07005845#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
5846 init_completion(&pAdapter->offchannel_tx_event);
5847#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005848 init_completion(&pAdapter->tx_action_cnf_event);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005849#ifdef FEATURE_WLAN_TDLS
5850 init_completion(&pAdapter->tdls_add_station_comp);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07005851 init_completion(&pAdapter->tdls_del_station_comp);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08005852 init_completion(&pAdapter->tdls_mgmt_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05305853 init_completion(&pAdapter->tdls_link_establish_req_comp);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005854#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005855 init_completion(&pHddCtx->mc_sus_event_var);
5856 init_completion(&pHddCtx->tx_sus_event_var);
Gopichand Nakkala05621412013-06-19 19:37:38 +05305857 init_completion(&pHddCtx->rx_sus_event_var);
Jeff Johnson9efb9aa2013-03-15 13:59:27 -07005858 init_completion(&pAdapter->ula_complete);
Sameer Thalappilda4eb6a2013-09-25 11:45:07 -07005859 init_completion(&pAdapter->change_country_code);
Jeff Johnson295189b2012-06-20 16:38:30 -07005860
Rajeev79dbe4c2013-10-05 11:03:42 +05305861#ifdef FEATURE_WLAN_BATCH_SCAN
5862 init_completion(&pAdapter->hdd_set_batch_scan_req_var);
5863 init_completion(&pAdapter->hdd_get_batch_scan_req_var);
5864 pAdapter->pBatchScanRsp = NULL;
5865 pAdapter->numScanList = 0;
Rajeev Kumar20140c12013-10-21 19:39:02 -07005866 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
Kiet Lamaa8e15a2014-02-11 23:30:06 -08005867 pAdapter->prev_batch_id = 0;
Rajeev79dbe4c2013-10-05 11:03:42 +05305868 mutex_init(&pAdapter->hdd_batch_scan_lock);
5869#endif
5870
Jeff Johnson295189b2012-06-20 16:38:30 -07005871 pAdapter->isLinkUpSvcNeeded = FALSE;
5872 pAdapter->higherDtimTransition = eANI_BOOLEAN_TRUE;
5873 //Init the net_device structure
5874 strlcpy(pWlanDev->name, name, IFNAMSIZ);
5875
5876 vos_mem_copy(pWlanDev->dev_addr, (void *)macAddr, sizeof(tSirMacAddr));
5877 vos_mem_copy( pAdapter->macAddressCurrent.bytes, macAddr, sizeof(tSirMacAddr));
5878 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
5879 pWlanDev->hard_header_len += LIBRA_HW_NEEDED_HEADROOM;
5880
5881 hdd_set_station_ops( pAdapter->dev );
5882
5883 pWlanDev->destructor = free_netdev;
Jeff Johnson295189b2012-06-20 16:38:30 -07005884 pWlanDev->ieee80211_ptr = &pAdapter->wdev ;
5885 pAdapter->wdev.wiphy = pHddCtx->wiphy;
5886 pAdapter->wdev.netdev = pWlanDev;
Jeff Johnson295189b2012-06-20 16:38:30 -07005887 /* set pWlanDev's parent to underlying device */
5888 SET_NETDEV_DEV(pWlanDev, pHddCtx->parent_dev);
Kumar Anand82c009f2014-05-29 00:29:42 -07005889
5890 hdd_wmm_init( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07005891 }
5892
5893 return pAdapter;
5894}
5895
5896VOS_STATUS hdd_register_interface( hdd_adapter_t *pAdapter, tANI_U8 rtnl_lock_held )
5897{
5898 struct net_device *pWlanDev = pAdapter->dev;
5899 //hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
5900 //hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
5901 //eHalStatus halStatus = eHAL_STATUS_SUCCESS;
5902
5903 if( rtnl_lock_held )
5904 {
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -08005905 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
Jeff Johnson295189b2012-06-20 16:38:30 -07005906 if( dev_alloc_name(pWlanDev, pWlanDev->name) < 0 )
5907 {
5908 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:dev_alloc_name",__func__);
5909 return VOS_STATUS_E_FAILURE;
5910 }
5911 }
5912 if (register_netdevice(pWlanDev))
5913 {
5914 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:register_netdev",__func__);
5915 return VOS_STATUS_E_FAILURE;
5916 }
5917 }
5918 else
5919 {
5920 if(register_netdev(pWlanDev))
5921 {
5922 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed:register_netdev",__func__);
5923 return VOS_STATUS_E_FAILURE;
5924 }
5925 }
5926 set_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags);
5927
5928 return VOS_STATUS_SUCCESS;
5929}
5930
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07005931static eHalStatus hdd_smeCloseSessionCallback(void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07005932{
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07005933 hdd_adapter_t *pAdapter = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07005934
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07005935 if (NULL == pAdapter)
5936 {
5937 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: NULL pAdapter", __func__);
5938 return eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07005939 }
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07005940
5941 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
5942 {
5943 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Invalid magic", __func__);
5944 return eHAL_STATUS_NOT_INITIALIZED;
5945 }
5946
5947 clear_bit(SME_SESSION_OPENED, &pAdapter->event_flags);
5948
Sameer Thalappilbee426e2013-10-30 10:30:30 -07005949#ifndef WLAN_OPEN_SOURCE
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07005950 /* need to make sure all of our scheduled work has completed.
5951 * This callback is called from MC thread context, so it is safe to
5952 * to call below flush workqueue API from here.
Sameer Thalappilbee426e2013-10-30 10:30:30 -07005953 *
5954 * Even though this is called from MC thread context, if there is a faulty
5955 * work item in the system, that can hang this call forever. So flushing
5956 * this global work queue is not safe; and now we make sure that
5957 * individual work queues are stopped correctly. But the cancel work queue
5958 * is a GPL only API, so the proprietary version of the driver would still
5959 * rely on the global work queue flush.
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07005960 */
5961 flush_scheduled_work();
Sameer Thalappilbee426e2013-10-30 10:30:30 -07005962#endif
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07005963
5964 /* We can be blocked while waiting for scheduled work to be
5965 * flushed, and the adapter structure can potentially be freed, in
5966 * which case the magic will have been reset. So make sure the
5967 * magic is still good, and hence the adapter structure is still
5968 * valid, before signaling completion */
5969 if (WLAN_HDD_ADAPTER_MAGIC == pAdapter->magic)
5970 {
5971 complete(&pAdapter->session_close_comp_var);
5972 }
5973
Jeff Johnson295189b2012-06-20 16:38:30 -07005974 return eHAL_STATUS_SUCCESS;
5975}
5976
5977VOS_STATUS hdd_init_station_mode( hdd_adapter_t *pAdapter )
5978{
5979 struct net_device *pWlanDev = pAdapter->dev;
5980 hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
5981 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
5982 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
5983 VOS_STATUS status = VOS_STATUS_E_FAILURE;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05305984 long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005985
5986 INIT_COMPLETION(pAdapter->session_open_comp_var);
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07005987 sme_SetCurrDeviceMode(pHddCtx->hHal, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07005988 //Open a SME session for future operation
5989 halStatus = sme_OpenSession( pHddCtx->hHal, hdd_smeRoamCallback, pAdapter,
Kiran Kumar Lokere0ad5cd32013-06-25 11:26:22 -07005990 (tANI_U8 *)&pAdapter->macAddressCurrent, &pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005991 if ( !HAL_STATUS_SUCCESS( halStatus ) )
5992 {
5993 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07005994 "sme_OpenSession() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07005995 halStatus, halStatus );
5996 status = VOS_STATUS_E_FAILURE;
5997 goto error_sme_open;
5998 }
5999
6000 //Block on a completion variable. Can't wait forever though.
Vinay Krishna Eranna0fe2e7c2014-04-09 21:32:08 +05306001 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07006002 &pAdapter->session_open_comp_var,
6003 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306004 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07006005 {
6006 hddLog(VOS_TRACE_LEVEL_FATAL,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306007 "Session is not opened within timeout period code %ld", rc );
Jeff Johnson295189b2012-06-20 16:38:30 -07006008 status = VOS_STATUS_E_FAILURE;
6009 goto error_sme_open;
6010 }
6011
6012 // Register wireless extensions
6013 if( eHAL_STATUS_SUCCESS != (halStatus = hdd_register_wext(pWlanDev)))
6014 {
6015 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07006016 "hdd_register_wext() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07006017 halStatus, halStatus );
6018 status = VOS_STATUS_E_FAILURE;
6019 goto error_register_wext;
6020 }
6021 //Safe to register the hard_start_xmit function again
6022#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
6023 wlan_drv_ops.ndo_start_xmit = hdd_hard_start_xmit;
6024#else
6025 pWlanDev->hard_start_xmit = hdd_hard_start_xmit;
6026#endif
6027
6028 //Set the Connection State to Not Connected
Abhishek Singhf4669da2014-05-26 15:07:49 +05306029 hddLog(VOS_TRACE_LEVEL_INFO,
6030 "%s: Set HDD connState to eConnectionState_NotConnected",
6031 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006032 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6033
6034 //Set the default operation channel
6035 pHddStaCtx->conn_info.operationChannel = pHddCtx->cfg_ini->OperatingChannel;
6036
6037 /* Make the default Auth Type as OPEN*/
6038 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
6039
6040 if( VOS_STATUS_SUCCESS != ( status = hdd_init_tx_rx( pAdapter ) ) )
6041 {
6042 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07006043 "hdd_init_tx_rx() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07006044 status, status );
6045 goto error_init_txrx;
6046 }
6047
6048 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
6049
6050 if( VOS_STATUS_SUCCESS != ( status = hdd_wmm_adapter_init( pAdapter ) ) )
6051 {
6052 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07006053 "hdd_wmm_adapter_init() failed with status code %08d [x%08x]",
Jeff Johnson295189b2012-06-20 16:38:30 -07006054 status, status );
6055 goto error_wmm_init;
6056 }
6057
6058 set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
6059
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006060#ifdef FEATURE_WLAN_TDLS
Agarwal Ashish4b87f922014-06-18 03:03:21 +05306061 if(0 != wlan_hdd_sta_tdls_init(pAdapter))
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006062 {
6063 status = VOS_STATUS_E_FAILURE;
Agarwal Ashish4b87f922014-06-18 03:03:21 +05306064 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wlan_hdd_sta_tdls_init failed",__func__);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006065 goto error_tdls_init;
6066 }
6067 set_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
6068#endif
6069
Jeff Johnson295189b2012-06-20 16:38:30 -07006070 return VOS_STATUS_SUCCESS;
6071
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006072#ifdef FEATURE_WLAN_TDLS
6073error_tdls_init:
6074 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
6075 hdd_wmm_adapter_close(pAdapter);
6076#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006077error_wmm_init:
6078 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
6079 hdd_deinit_tx_rx(pAdapter);
6080error_init_txrx:
6081 hdd_UnregisterWext(pWlanDev);
6082error_register_wext:
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07006083 if (test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07006084 {
6085 INIT_COMPLETION(pAdapter->session_close_comp_var);
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07006086 if (eHAL_STATUS_SUCCESS == sme_CloseSession(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07006087 pAdapter->sessionId,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07006088 hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07006089 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306090 unsigned long rc;
6091
Jeff Johnson295189b2012-06-20 16:38:30 -07006092 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306093 rc = wait_for_completion_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07006094 &pAdapter->session_close_comp_var,
Jeff Johnsonc6ab5b92013-04-15 17:02:05 -07006095 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306096 if (rc <= 0)
6097 hddLog(VOS_TRACE_LEVEL_ERROR,
6098 FL("Session is not opened within timeout period code %ld"), rc);
Jeff Johnson295189b2012-06-20 16:38:30 -07006099 }
6100}
6101error_sme_open:
6102 return status;
6103}
6104
Jeff Johnson295189b2012-06-20 16:38:30 -07006105void hdd_cleanup_actionframe( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
6106{
6107 hdd_cfg80211_state_t *cfgState;
6108
6109 cfgState = WLAN_HDD_GET_CFG_STATE_PTR( pAdapter );
6110
6111 if( NULL != cfgState->buf )
6112 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306113 long rc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006114 INIT_COMPLETION(pAdapter->tx_action_cnf_event);
6115 rc = wait_for_completion_interruptible_timeout(
6116 &pAdapter->tx_action_cnf_event,
6117 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306118 if (rc <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07006119 {
Sudhir Sattayappa Kohalli8ee532d2013-02-15 13:16:26 -08006120 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306121 "%s ERROR: HDD Wait for Action Confirmation Failed!! %ld"
6122 , __func__, rc);
Jeff Johnson295189b2012-06-20 16:38:30 -07006123 }
6124 }
6125 return;
6126}
Jeff Johnson295189b2012-06-20 16:38:30 -07006127
6128void hdd_deinit_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
6129{
6130 ENTER();
6131 switch ( pAdapter->device_mode )
6132 {
6133 case WLAN_HDD_INFRA_STATION:
6134 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07006135 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07006136 {
6137 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
6138 {
6139 hdd_deinit_tx_rx( pAdapter );
6140 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
6141 }
6142
6143 if(test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
6144 {
6145 hdd_wmm_adapter_close( pAdapter );
6146 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
6147 }
6148
Jeff Johnson295189b2012-06-20 16:38:30 -07006149 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006150#ifdef FEATURE_WLAN_TDLS
6151 if(test_bit(TDLS_INIT_DONE, &pAdapter->event_flags))
6152 {
6153 wlan_hdd_tdls_exit(pAdapter);
6154 clear_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
6155 }
6156#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006157
6158 break;
6159 }
6160
6161 case WLAN_HDD_SOFTAP:
6162 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07006163 {
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05306164
6165 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
6166 {
6167 hdd_wmm_adapter_close( pAdapter );
6168 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
6169 }
6170
Jeff Johnson295189b2012-06-20 16:38:30 -07006171 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006172
6173 hdd_unregister_hostapd(pAdapter);
6174 hdd_set_conparam( 0 );
Jeff Johnson295189b2012-06-20 16:38:30 -07006175 wlan_hdd_set_monitor_tx_adapter( WLAN_HDD_GET_CTX(pAdapter), NULL );
Jeff Johnson295189b2012-06-20 16:38:30 -07006176 break;
6177 }
6178
6179 case WLAN_HDD_MONITOR:
6180 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006181 hdd_adapter_t* pAdapterforTx = pAdapter->sessionCtx.monitor.pAdapterForTx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006182 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
6183 {
6184 hdd_deinit_tx_rx( pAdapter );
6185 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
6186 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006187 if(NULL != pAdapterforTx)
6188 {
6189 hdd_cleanup_actionframe(pHddCtx, pAdapterforTx);
6190 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006191 break;
6192 }
6193
6194
6195 default:
6196 break;
6197 }
6198
6199 EXIT();
6200}
6201
6202void hdd_cleanup_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
6203{
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08006204 struct net_device *pWlanDev = NULL;
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05306205
6206 ENTER();
6207 if (NULL == pAdapter)
6208 {
6209 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6210 "%s: HDD adapter is Null", __func__);
6211 return;
6212 }
6213
6214 pWlanDev = pAdapter->dev;
Jeff Johnson295189b2012-06-20 16:38:30 -07006215
Rajeev79dbe4c2013-10-05 11:03:42 +05306216#ifdef FEATURE_WLAN_BATCH_SCAN
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05306217 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
6218 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Rajeev Kumarf999e582014-01-09 17:33:29 -08006219 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05306220 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
6221 )
6222 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08006223 if (pAdapter)
Rajeev79dbe4c2013-10-05 11:03:42 +05306224 {
Rajeev Kumarf999e582014-01-09 17:33:29 -08006225 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
6226 {
6227 hdd_deinit_batch_scan(pAdapter);
6228 }
Rajeev79dbe4c2013-10-05 11:03:42 +05306229 }
Rajeev Kumarf999e582014-01-09 17:33:29 -08006230 }
Rajeev79dbe4c2013-10-05 11:03:42 +05306231#endif
6232
Jeff Johnson295189b2012-06-20 16:38:30 -07006233 if(test_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags)) {
6234 if( rtnl_held )
6235 {
6236 unregister_netdevice(pWlanDev);
6237 }
6238 else
6239 {
6240 unregister_netdev(pWlanDev);
6241 }
6242 // note that the pAdapter is no longer valid at this point
6243 // since the memory has been reclaimed
6244 }
6245
Srinivas, Dasari693dfc52013-12-27 17:29:09 +05306246 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006247}
6248
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006249void hdd_set_pwrparams(hdd_context_t *pHddCtx)
6250{
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306251 VOS_STATUS status;
6252 hdd_adapter_t *pAdapter = NULL;
6253 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006254
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306255 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006256
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306257 /*loop through all adapters.*/
6258 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006259 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306260 pAdapter = pAdapterNode->pAdapter;
6261 if ( (WLAN_HDD_INFRA_STATION != pAdapter->device_mode)
6262 && (WLAN_HDD_P2P_CLIENT != pAdapter->device_mode) )
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006263
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306264 { // we skip this registration for modes other than STA and P2P client modes.
6265 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
6266 pAdapterNode = pNext;
6267 continue;
6268 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006269
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306270 //Apply Dynamic DTIM For P2P
6271 //Only if ignoreDynamicDtimInP2pMode is not set in ini
6272 if ((pHddCtx->cfg_ini->enableDynamicDTIM ||
6273 pHddCtx->cfg_ini->enableModulatedDTIM) &&
6274 ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
6275 ((WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) &&
6276 !(pHddCtx->cfg_ini->ignoreDynamicDtimInP2pMode))) &&
6277 (eANI_BOOLEAN_TRUE == pAdapter->higherDtimTransition) &&
6278 (eConnectionState_Associated ==
6279 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState) &&
6280 (pHddCtx->cfg_ini->fIsBmpsEnabled))
6281 {
6282 tSirSetPowerParamsReq powerRequest = { 0 };
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006283
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306284 powerRequest.uIgnoreDTIM = 1;
6285 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
6286
6287 if (pHddCtx->cfg_ini->enableModulatedDTIM)
6288 {
6289 powerRequest.uDTIMPeriod = pHddCtx->cfg_ini->enableModulatedDTIM;
6290 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
6291 }
6292 else
6293 {
6294 powerRequest.uListenInterval = pHddCtx->cfg_ini->enableDynamicDTIM;
6295 }
6296
6297 /* Update ignoreDTIM and ListedInterval in CFG to remain at the DTIM
6298 * specified during Enter/Exit BMPS when LCD off*/
6299 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
6300 NULL, eANI_BOOLEAN_FALSE);
6301 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
6302 NULL, eANI_BOOLEAN_FALSE);
6303
6304 /* switch to the DTIM specified in cfg.ini */
6305 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6306 "Switch to DTIM %d", powerRequest.uListenInterval);
6307 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
6308 break;
6309
6310 }
6311
6312 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
6313 pAdapterNode = pNext;
6314 }
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006315}
6316
6317void hdd_reset_pwrparams(hdd_context_t *pHddCtx)
6318{
6319 /*Switch back to DTIM 1*/
6320 tSirSetPowerParamsReq powerRequest = { 0 };
6321
6322 powerRequest.uIgnoreDTIM = pHddCtx->hdd_actual_ignore_DTIM_value;
6323 powerRequest.uListenInterval = pHddCtx->hdd_actual_LI_value;
Yue Mac24062f2013-05-13 17:01:29 -07006324 powerRequest.uMaxLIModulatedDTIM = pHddCtx->cfg_ini->fMaxLIModulatedDTIM;
Tushnim Bhattacharyya3a37def2013-02-24 11:11:15 -08006325
6326 /* Update ignoreDTIM and ListedInterval in CFG with default values */
6327 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, powerRequest.uIgnoreDTIM,
6328 NULL, eANI_BOOLEAN_FALSE);
6329 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, powerRequest.uListenInterval,
6330 NULL, eANI_BOOLEAN_FALSE);
6331
6332 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
6333 "Switch to DTIM%d",powerRequest.uListenInterval);
6334 sme_SetPowerParams( pHddCtx->hHal, &powerRequest, TRUE);
6335
6336}
6337
Jeff Johnson295189b2012-06-20 16:38:30 -07006338VOS_STATUS hdd_enable_bmps_imps(hdd_context_t *pHddCtx)
6339{
6340 VOS_STATUS status = VOS_STATUS_SUCCESS;
6341
6342 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
6343 {
6344 sme_EnablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
6345 }
6346
6347 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
6348 {
6349 sme_StartAutoBmpsTimer(pHddCtx->hHal);
6350 }
6351
6352 if (pHddCtx->cfg_ini->fIsImpsEnabled)
6353 {
6354 sme_EnablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
6355 }
6356
6357 return status;
6358}
6359
6360VOS_STATUS hdd_disable_bmps_imps(hdd_context_t *pHddCtx, tANI_U8 session_type)
6361{
6362 hdd_adapter_t *pAdapter = NULL;
6363 eHalStatus halStatus;
6364 VOS_STATUS status = VOS_STATUS_E_INVAL;
6365 v_BOOL_t disableBmps = FALSE;
6366 v_BOOL_t disableImps = FALSE;
6367
6368 switch(session_type)
6369 {
6370 case WLAN_HDD_INFRA_STATION:
6371 case WLAN_HDD_SOFTAP:
Jeff Johnson295189b2012-06-20 16:38:30 -07006372 case WLAN_HDD_P2P_CLIENT:
6373 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07006374 //Exit BMPS -> Is Sta/P2P Client is already connected
6375 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6376 if((NULL != pAdapter)&&
6377 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
6378 {
6379 disableBmps = TRUE;
6380 }
6381
6382 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_CLIENT);
6383 if((NULL != pAdapter)&&
6384 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
6385 {
6386 disableBmps = TRUE;
6387 }
6388
6389 //Exit both Bmps and Imps incase of Go/SAP Mode
6390 if((WLAN_HDD_SOFTAP == session_type) ||
6391 (WLAN_HDD_P2P_GO == session_type))
6392 {
6393 disableBmps = TRUE;
6394 disableImps = TRUE;
6395 }
6396
6397 if(TRUE == disableImps)
6398 {
6399 if (pHddCtx->cfg_ini->fIsImpsEnabled)
6400 {
6401 sme_DisablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
6402 }
6403 }
6404
6405 if(TRUE == disableBmps)
6406 {
6407 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
6408 {
6409 halStatus = sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
6410
6411 if(eHAL_STATUS_SUCCESS != halStatus)
6412 {
6413 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08006414 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Disable Power Save", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006415 VOS_ASSERT(0);
6416 return status;
6417 }
6418 }
6419
6420 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
6421 {
6422 halStatus = sme_StopAutoBmpsTimer(pHddCtx->hHal);
6423
6424 if(eHAL_STATUS_SUCCESS != halStatus)
6425 {
6426 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08006427 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Stop Auto Bmps Timer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006428 VOS_ASSERT(0);
6429 return status;
6430 }
6431 }
6432 }
6433
6434 if((TRUE == disableBmps) ||
6435 (TRUE == disableImps))
6436 {
6437 /* Now, get the chip into Full Power now */
6438 INIT_COMPLETION(pHddCtx->full_pwr_comp_var);
6439 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_pwr_cbk,
6440 pHddCtx, eSME_FULL_PWR_NEEDED_BY_HDD);
6441
6442 if(halStatus != eHAL_STATUS_SUCCESS)
6443 {
6444 if(halStatus == eHAL_STATUS_PMC_PENDING)
6445 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306446 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07006447 //Block on a completion variable. Can't wait forever though
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306448 ret = wait_for_completion_interruptible_timeout(
6449 &pHddCtx->full_pwr_comp_var,
6450 msecs_to_jiffies(1000));
6451 if (ret <= 0)
6452 {
6453 hddLog(VOS_TRACE_LEVEL_ERROR,
6454 "%s: wait on full_pwr_comp_var failed %ld",
6455 __func__, ret);
6456 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006457 }
6458 else
6459 {
6460 status = VOS_STATUS_E_FAILURE;
Arif Hussain6d2a3322013-11-17 19:50:10 -08006461 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Request for Full Power failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006462 VOS_ASSERT(0);
6463 return status;
6464 }
6465 }
6466
6467 status = VOS_STATUS_SUCCESS;
6468 }
6469
6470 break;
6471 }
6472 return status;
6473}
6474
6475hdd_adapter_t* hdd_open_adapter( hdd_context_t *pHddCtx, tANI_U8 session_type,
Jeff Johnsoneed415b2013-01-18 16:11:20 -08006476 const char *iface_name, tSirMacAddr macAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -07006477 tANI_U8 rtnl_held )
6478{
6479 hdd_adapter_t *pAdapter = NULL;
6480 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
6481 VOS_STATUS status = VOS_STATUS_E_FAILURE;
6482 VOS_STATUS exitbmpsStatus;
6483
Arif Hussain6d2a3322013-11-17 19:50:10 -08006484 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s iface =%s type = %d",__func__,iface_name,session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006485
Nirav Shah436658f2014-02-28 17:05:45 +05306486 if(macAddr == NULL)
6487 {
6488 /* Not received valid macAddr */
6489 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6490 "%s:Unable to add virtual intf: Not able to get"
6491 "valid mac address",__func__);
6492 return NULL;
6493 }
6494
Jeff Johnson295189b2012-06-20 16:38:30 -07006495 //Disable BMPS incase of Concurrency
6496 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, session_type);
6497
6498 if(VOS_STATUS_E_FAILURE == exitbmpsStatus)
6499 {
6500 //Fail to Exit BMPS
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306501 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Exit BMPS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006502 VOS_ASSERT(0);
6503 return NULL;
6504 }
6505
6506 switch(session_type)
6507 {
6508 case WLAN_HDD_INFRA_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07006509 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07006510 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07006511 {
6512 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
6513
6514 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306515 {
6516 hddLog(VOS_TRACE_LEVEL_FATAL,
6517 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006518 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306519 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006520
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05306521#ifdef FEATURE_WLAN_TDLS
6522 /* A Mutex Lock is introduced while changing/initializing the mode to
6523 * protect the concurrent access for the Adapters by TDLS module.
6524 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05306525 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05306526#endif
6527
Jeff Johnsone7245742012-09-05 17:12:55 -07006528 pAdapter->wdev.iftype = (session_type == WLAN_HDD_P2P_CLIENT) ?
6529 NL80211_IFTYPE_P2P_CLIENT:
6530 NL80211_IFTYPE_STATION;
Jeff Johnson295189b2012-06-20 16:38:30 -07006531
Jeff Johnson295189b2012-06-20 16:38:30 -07006532 pAdapter->device_mode = session_type;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05306533#ifdef FEATURE_WLAN_TDLS
6534 mutex_unlock(&pHddCtx->tdls_lock);
6535#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05306536
6537 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07006538 if( VOS_STATUS_SUCCESS != status )
6539 goto err_free_netdev;
6540
6541 status = hdd_register_interface( pAdapter, rtnl_held );
6542 if( VOS_STATUS_SUCCESS != status )
6543 {
6544 hdd_deinit_adapter(pHddCtx, pAdapter);
6545 goto err_free_netdev;
6546 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05306547
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05306548 // Workqueue which gets scheduled in IPv4 notification callback.
6549 INIT_WORK(&pAdapter->ipv4NotifierWorkQueue, hdd_ipv4_notifier_work_queue);
6550
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05306551#ifdef WLAN_NS_OFFLOAD
6552 // Workqueue which gets scheduled in IPv6 notification callback.
6553 INIT_WORK(&pAdapter->ipv6NotifierWorkQueue, hdd_ipv6_notifier_work_queue);
6554#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006555 //Stop the Interface TX queue.
6556 netif_tx_disable(pAdapter->dev);
6557 //netif_tx_disable(pWlanDev);
6558 netif_carrier_off(pAdapter->dev);
6559
6560 break;
6561 }
6562
Jeff Johnson295189b2012-06-20 16:38:30 -07006563 case WLAN_HDD_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07006564 case WLAN_HDD_SOFTAP:
6565 {
6566 pAdapter = hdd_wlan_create_ap_dev( pHddCtx, macAddr, (tANI_U8 *)iface_name );
6567 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306568 {
6569 hddLog(VOS_TRACE_LEVEL_FATAL,
6570 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006571 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306572 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006573
Jeff Johnson295189b2012-06-20 16:38:30 -07006574 pAdapter->wdev.iftype = (session_type == WLAN_HDD_SOFTAP) ?
6575 NL80211_IFTYPE_AP:
6576 NL80211_IFTYPE_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006577 pAdapter->device_mode = session_type;
6578
6579 status = hdd_init_ap_mode(pAdapter);
6580 if( VOS_STATUS_SUCCESS != status )
6581 goto err_free_netdev;
6582
6583 status = hdd_register_hostapd( pAdapter, rtnl_held );
6584 if( VOS_STATUS_SUCCESS != status )
6585 {
6586 hdd_deinit_adapter(pHddCtx, pAdapter);
6587 goto err_free_netdev;
6588 }
6589
6590 netif_tx_disable(pAdapter->dev);
6591 netif_carrier_off(pAdapter->dev);
6592
6593 hdd_set_conparam( 1 );
6594 break;
6595 }
6596 case WLAN_HDD_MONITOR:
6597 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006598 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
6599 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306600 {
6601 hddLog(VOS_TRACE_LEVEL_FATAL,
6602 FL("failed to allocate adapter for session %d"), session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006603 return NULL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306604 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006605
6606 pAdapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
6607 pAdapter->device_mode = session_type;
6608 status = hdd_register_interface( pAdapter, rtnl_held );
6609#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29)
6610 pAdapter->dev->netdev_ops = &wlan_mon_drv_ops;
6611#else
6612 pAdapter->dev->open = hdd_mon_open;
6613 pAdapter->dev->hard_start_xmit = hdd_mon_hard_start_xmit;
6614#endif
6615 hdd_init_tx_rx( pAdapter );
6616 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
6617 //Set adapter to be used for data tx. It will use either GO or softap.
6618 pAdapter->sessionCtx.monitor.pAdapterForTx =
6619 hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_SOFTAP);
Jeff Johnson295189b2012-06-20 16:38:30 -07006620 if (NULL == pAdapter->sessionCtx.monitor.pAdapterForTx)
6621 {
6622 pAdapter->sessionCtx.monitor.pAdapterForTx =
6623 hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_GO);
6624 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006625 /* This workqueue will be used to transmit management packet over
6626 * monitor interface. */
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006627 if (NULL == pAdapter->sessionCtx.monitor.pAdapterForTx) {
6628 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:hdd_get_adapter",__func__);
6629 return NULL;
6630 }
Madan Mohan Koyyalamudi9f40ceb2012-10-18 19:22:56 -07006631
Jeff Johnson295189b2012-06-20 16:38:30 -07006632 INIT_WORK(&pAdapter->sessionCtx.monitor.pAdapterForTx->monTxWorkQueue,
6633 hdd_mon_tx_work_queue);
Jeff Johnson295189b2012-06-20 16:38:30 -07006634 }
6635 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006636 case WLAN_HDD_FTM:
6637 {
6638 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
6639
6640 if( NULL == pAdapter )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306641 {
6642 hddLog(VOS_TRACE_LEVEL_FATAL,
6643 FL("failed to allocate adapter for session %d"), session_type);
6644 return NULL;
6645 }
6646
Jeff Johnson295189b2012-06-20 16:38:30 -07006647 /* Assign NL80211_IFTYPE_STATION as interface type to resolve Kernel Warning
6648 * message while loading driver in FTM mode. */
6649 pAdapter->wdev.iftype = NL80211_IFTYPE_STATION;
6650 pAdapter->device_mode = session_type;
6651 status = hdd_register_interface( pAdapter, rtnl_held );
Madan Mohan Koyyalamudif89ac9f2013-09-19 16:58:12 +05306652
6653 hdd_init_tx_rx( pAdapter );
6654
6655 //Stop the Interface TX queue.
6656 netif_tx_disable(pAdapter->dev);
6657 netif_carrier_off(pAdapter->dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07006658 }
6659 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006660 default:
6661 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306662 hddLog(VOS_TRACE_LEVEL_FATAL,"%s Invalid session type %d",
6663 __func__, session_type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006664 VOS_ASSERT(0);
6665 return NULL;
6666 }
6667 }
6668
Jeff Johnson295189b2012-06-20 16:38:30 -07006669 if( VOS_STATUS_SUCCESS == status )
6670 {
6671 //Add it to the hdd's session list.
6672 pHddAdapterNode = vos_mem_malloc( sizeof( hdd_adapter_list_node_t ) );
6673 if( NULL == pHddAdapterNode )
6674 {
6675 status = VOS_STATUS_E_NOMEM;
6676 }
6677 else
6678 {
6679 pHddAdapterNode->pAdapter = pAdapter;
6680 status = hdd_add_adapter_back ( pHddCtx,
6681 pHddAdapterNode );
6682 }
6683 }
6684
6685 if( VOS_STATUS_SUCCESS != status )
6686 {
6687 if( NULL != pAdapter )
6688 {
6689 hdd_cleanup_adapter( pHddCtx, pAdapter, rtnl_held );
6690 pAdapter = NULL;
6691 }
6692 if( NULL != pHddAdapterNode )
6693 {
6694 vos_mem_free( pHddAdapterNode );
6695 }
6696
6697 goto resume_bmps;
6698 }
6699
6700 if(VOS_STATUS_SUCCESS == status)
6701 {
6702 wlan_hdd_set_concurrency_mode(pHddCtx, session_type);
6703
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -07006704 //Initialize the WoWL service
6705 if(!hdd_init_wowl(pAdapter))
6706 {
6707 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_init_wowl failed",__func__);
6708 goto err_free_netdev;
6709 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006710 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006711 return pAdapter;
6712
6713err_free_netdev:
6714 free_netdev(pAdapter->dev);
6715 wlan_hdd_release_intf_addr( pHddCtx,
6716 pAdapter->macAddressCurrent.bytes );
6717
6718resume_bmps:
6719 //If bmps disabled enable it
6720 if(VOS_STATUS_SUCCESS == exitbmpsStatus)
6721 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306722 if (pHddCtx->hdd_wlan_suspended)
6723 {
6724 hdd_set_pwrparams(pHddCtx);
6725 }
6726 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006727 }
6728 return NULL;
6729}
6730
6731VOS_STATUS hdd_close_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
6732 tANI_U8 rtnl_held )
6733{
6734 hdd_adapter_list_node_t *pAdapterNode, *pCurrent, *pNext;
6735 VOS_STATUS status;
6736
6737 status = hdd_get_front_adapter ( pHddCtx, &pCurrent );
6738 if( VOS_STATUS_SUCCESS != status )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306739 {
6740 hddLog(VOS_TRACE_LEVEL_WARN,"%s: adapter list empty %d",
6741 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006742 return status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306743 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006744
6745 while ( pCurrent->pAdapter != pAdapter )
6746 {
6747 status = hdd_get_next_adapter ( pHddCtx, pCurrent, &pNext );
6748 if( VOS_STATUS_SUCCESS != status )
6749 break;
6750
6751 pCurrent = pNext;
6752 }
6753 pAdapterNode = pCurrent;
6754 if( VOS_STATUS_SUCCESS == status )
6755 {
6756 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
6757 hdd_cleanup_adapter( pHddCtx, pAdapterNode->pAdapter, rtnl_held );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05306758
6759#ifdef FEATURE_WLAN_TDLS
6760
6761 /* A Mutex Lock is introduced while changing/initializing the mode to
6762 * protect the concurrent access for the Adapters by TDLS module.
6763 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05306764 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05306765#endif
6766
Jeff Johnson295189b2012-06-20 16:38:30 -07006767 hdd_remove_adapter( pHddCtx, pAdapterNode );
6768 vos_mem_free( pAdapterNode );
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08006769 pAdapterNode = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006770
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05306771#ifdef FEATURE_WLAN_TDLS
6772 mutex_unlock(&pHddCtx->tdls_lock);
6773#endif
6774
Jeff Johnson295189b2012-06-20 16:38:30 -07006775
6776 /* If there is a single session of STA/P2P client, re-enable BMPS */
Agarwal Ashish51325b52014-06-16 16:50:49 +05306777 if ((!vos_concurrent_open_sessions_running()) &&
6778 ((pHddCtx->no_of_open_sessions[VOS_STA_MODE] >= 1) ||
6779 (pHddCtx->no_of_open_sessions[VOS_P2P_CLIENT_MODE] >= 1)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006780 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306781 if (pHddCtx->hdd_wlan_suspended)
6782 {
6783 hdd_set_pwrparams(pHddCtx);
6784 }
6785 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006786 }
6787
6788 return VOS_STATUS_SUCCESS;
6789 }
6790
6791 return VOS_STATUS_E_FAILURE;
6792}
6793
6794VOS_STATUS hdd_close_all_adapters( hdd_context_t *pHddCtx )
6795{
6796 hdd_adapter_list_node_t *pHddAdapterNode;
6797 VOS_STATUS status;
6798
6799 ENTER();
6800
6801 do
6802 {
6803 status = hdd_remove_front_adapter( pHddCtx, &pHddAdapterNode );
6804 if( pHddAdapterNode && VOS_STATUS_SUCCESS == status )
6805 {
6806 hdd_cleanup_adapter( pHddCtx, pHddAdapterNode->pAdapter, FALSE );
6807 vos_mem_free( pHddAdapterNode );
6808 }
6809 }while( NULL != pHddAdapterNode && VOS_STATUS_E_EMPTY != status );
6810
6811 EXIT();
6812
6813 return VOS_STATUS_SUCCESS;
6814}
6815
6816void wlan_hdd_reset_prob_rspies(hdd_adapter_t* pHostapdAdapter)
6817{
6818 v_U8_t addIE[1] = {0};
6819
6820 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
6821 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,(tANI_U8*)addIE, 0, NULL,
6822 eANI_BOOLEAN_FALSE) )
6823 {
6824 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006825 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07006826 }
6827
6828 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
6829 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
6830 eANI_BOOLEAN_FALSE) )
6831 {
6832 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006833 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07006834 }
6835
6836 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
6837 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
6838 eANI_BOOLEAN_FALSE) )
6839 {
6840 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006841 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07006842 }
6843}
6844
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306845VOS_STATUS hdd_stop_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
6846 const v_BOOL_t bCloseSession )
Jeff Johnson295189b2012-06-20 16:38:30 -07006847{
6848 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
6849 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Kaushik, Sushant4975a572014-10-21 16:07:48 +05306850 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006851 union iwreq_data wrqu;
Kaushik, Sushant7005e372014-04-08 11:36:54 +05306852 v_U8_t retry = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306853 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07006854
6855 ENTER();
Kaushik, Sushant4975a572014-10-21 16:07:48 +05306856 pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07006857 switch(pAdapter->device_mode)
6858 {
6859 case WLAN_HDD_INFRA_STATION:
6860 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07006861 case WLAN_HDD_P2P_DEVICE:
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05306862 {
6863 hdd_station_ctx_t *pstation = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6864 if( hdd_connIsConnected(pstation) ||
6865 (pstation->conn_info.connState == eConnectionState_Connecting) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006866 {
6867 if (pWextState->roamProfile.BSSType == eCSR_BSS_TYPE_START_IBSS)
6868 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
6869 pAdapter->sessionId,
6870 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6871 else
6872 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
6873 pAdapter->sessionId,
6874 eCSR_DISCONNECT_REASON_UNSPECIFIED);
6875 //success implies disconnect command got queued up successfully
6876 if(halStatus == eHAL_STATUS_SUCCESS)
6877 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306878 ret = wait_for_completion_interruptible_timeout(
6879 &pAdapter->disconnect_comp_var,
6880 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6881 if (ret <= 0)
6882 {
6883 hddLog(VOS_TRACE_LEVEL_ERROR,
6884 "%s: wait on disconnect_comp_var failed %ld",
6885 __func__, ret);
6886 }
6887 }
6888 else
6889 {
6890 hddLog(LOGE, "%s: failed to post disconnect event to SME",
6891 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006892 }
6893 memset(&wrqu, '\0', sizeof(wrqu));
6894 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6895 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
6896 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
6897 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05306898 else if(pstation->conn_info.connState ==
6899 eConnectionState_Disconnecting)
6900 {
6901 ret = wait_for_completion_interruptible_timeout(
6902 &pAdapter->disconnect_comp_var,
6903 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6904 if (ret <= 0)
6905 {
6906 hddLog(VOS_TRACE_LEVEL_ERROR,
6907 FL("wait on disconnect_comp_var failed %ld"), ret);
6908 }
6909 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +05306910 else if(pScanInfo != NULL && pHddCtx->scan_info.mScanPending)
Jeff Johnson295189b2012-06-20 16:38:30 -07006911 {
Kaushik, Sushant4975a572014-10-21 16:07:48 +05306912 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05306913 eCSR_SCAN_ABORT_DEFAULT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006914 }
Kaushik, Sushant7005e372014-04-08 11:36:54 +05306915 if (pAdapter->device_mode != WLAN_HDD_INFRA_STATION)
6916 {
6917 while (pAdapter->is_roc_inprogress)
6918 {
6919 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6920 "%s: ROC in progress for session %d!!!",
6921 __func__, pAdapter->sessionId);
6922 // waiting for ROC to expire
6923 msleep(500);
6924 /* In GO present case , if retry exceeds 3,
6925 it means something went wrong. */
6926 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION )
6927 {
6928 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6929 "%s: ROC completion is not received.!!!", __func__);
6930 sme_CancelRemainOnChannel(WLAN_HDD_GET_HAL_CTX(pAdapter),
6931 pAdapter->sessionId);
6932 wait_for_completion_interruptible_timeout(
6933 &pAdapter->cancel_rem_on_chan_var,
6934 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
6935 break;
6936 }
6937 }
6938 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05306939#ifdef WLAN_NS_OFFLOAD
Vinay Krishna Eranna941360f2014-01-16 15:38:22 +05306940#ifdef WLAN_OPEN_SOURCE
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05306941 cancel_work_sync(&pAdapter->ipv6NotifierWorkQueue);
6942#endif
Vinay Krishna Eranna941360f2014-01-16 15:38:22 +05306943 if (pAdapter->ipv6_notifier_registered)
6944 {
6945 hddLog(LOG1, FL("Unregistered IPv6 notifier"));
6946 unregister_inet6addr_notifier(&pAdapter->ipv6_notifier);
6947 pAdapter->ipv6_notifier_registered = false;
6948 }
Vinay Krishna Erannad5b2be22013-12-01 17:00:15 +05306949#endif
Vinay Krishna Erannad9cbdb32014-01-16 12:59:10 +05306950 if (pAdapter->ipv4_notifier_registered)
6951 {
6952 hddLog(LOG1, FL("Unregistered IPv4 notifier"));
6953 unregister_inetaddr_notifier(&pAdapter->ipv4_notifier);
6954 pAdapter->ipv4_notifier_registered = false;
6955 }
Vinay Krishna Eranna4d055d42013-12-17 17:02:01 +05306956#ifdef WLAN_OPEN_SOURCE
6957 cancel_work_sync(&pAdapter->ipv4NotifierWorkQueue);
6958#endif
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306959 /* It is possible that the caller of this function does not
6960 * wish to close the session
6961 */
6962 if (VOS_TRUE == bCloseSession &&
6963 test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07006964 {
6965 INIT_COMPLETION(pAdapter->session_close_comp_var);
6966 if (eHAL_STATUS_SUCCESS ==
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306967 sme_CloseSession(pHddCtx->hHal, pAdapter->sessionId,
6968 hdd_smeCloseSessionCallback, pAdapter))
Jeff Johnson295189b2012-06-20 16:38:30 -07006969 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306970 unsigned long ret;
6971
Jeff Johnson295189b2012-06-20 16:38:30 -07006972 //Block on a completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306973 ret = wait_for_completion_timeout(
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306974 &pAdapter->session_close_comp_var,
6975 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306976 if ( 0 >= ret)
6977 {
6978 hddLog(LOGE, "%s: failure waiting for session_close_comp_var %ld",
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05306979 __func__, ret);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306980 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006981 }
6982 }
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05306983 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006984 break;
6985
6986 case WLAN_HDD_SOFTAP:
6987 case WLAN_HDD_P2P_GO:
6988 //Any softap specific cleanup here...
Kaushik, Sushant7005e372014-04-08 11:36:54 +05306989 if (pAdapter->device_mode == WLAN_HDD_P2P_GO) {
6990 while (pAdapter->is_roc_inprogress) {
6991 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6992 "%s: ROC in progress for session %d!!!",
6993 __func__, pAdapter->sessionId);
6994 msleep(500);
6995 if ( retry++ > MAX_WAIT_FOR_ROC_COMPLETION ) {
6996 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6997 "%s: ROC completion is not received.!!!", __func__);
6998 WLANSAP_CancelRemainOnChannel(
6999 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
7000 wait_for_completion_interruptible_timeout(
7001 &pAdapter->cancel_rem_on_chan_var,
7002 msecs_to_jiffies(WAIT_CANCEL_REM_CHAN));
7003 break;
7004 }
7005 }
7006 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007007 mutex_lock(&pHddCtx->sap_lock);
7008 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
7009 {
7010 VOS_STATUS status;
7011 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7012
7013 //Stop Bss.
7014 status = WLANSAP_StopBss(pHddCtx->pvosContext);
7015 if (VOS_IS_STATUS_SUCCESS(status))
7016 {
7017 hdd_hostapd_state_t *pHostapdState =
7018 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
7019
7020 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
7021
7022 if (!VOS_IS_STATUS_SUCCESS(status))
7023 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307024 hddLog(LOGE, "%s: failure waiting for WLANSAP_StopBss %d",
7025 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007026 }
7027 }
7028 else
7029 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007030 hddLog(LOGE, "%s: failure in WLANSAP_StopBss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007031 }
7032 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
Agarwal Ashish51325b52014-06-16 16:50:49 +05307033 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07007034
7035 if (eHAL_STATUS_FAILURE ==
7036 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
7037 0, NULL, eANI_BOOLEAN_FALSE))
7038 {
7039 hddLog(LOGE,
7040 "%s: Failed to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007041 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007042 }
7043
7044 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pAdapter))->hHal,
7045 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
7046 eANI_BOOLEAN_FALSE) )
7047 {
7048 hddLog(LOGE,
7049 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
7050 }
7051
7052 // Reset WNI_CFG_PROBE_RSP Flags
7053 wlan_hdd_reset_prob_rspies(pAdapter);
7054 kfree(pAdapter->sessionCtx.ap.beacon);
7055 pAdapter->sessionCtx.ap.beacon = NULL;
7056 }
7057 mutex_unlock(&pHddCtx->sap_lock);
7058 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -07007059
Jeff Johnson295189b2012-06-20 16:38:30 -07007060 case WLAN_HDD_MONITOR:
Sameer Thalappilbee426e2013-10-30 10:30:30 -07007061#ifdef WLAN_OPEN_SOURCE
7062 cancel_work_sync(&pAdapter->sessionCtx.monitor.pAdapterForTx->monTxWorkQueue);
7063#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007064 break;
Sameer Thalappilbee426e2013-10-30 10:30:30 -07007065
Jeff Johnson295189b2012-06-20 16:38:30 -07007066 default:
7067 break;
7068 }
7069
7070 EXIT();
7071 return VOS_STATUS_SUCCESS;
7072}
7073
7074VOS_STATUS hdd_stop_all_adapters( hdd_context_t *pHddCtx )
7075{
7076 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7077 VOS_STATUS status;
7078 hdd_adapter_t *pAdapter;
7079
7080 ENTER();
7081
7082 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7083
7084 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7085 {
7086 pAdapter = pAdapterNode->pAdapter;
7087 netif_tx_disable(pAdapter->dev);
7088 netif_carrier_off(pAdapter->dev);
7089
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307090 hdd_stop_adapter( pHddCtx, pAdapter, VOS_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07007091
7092 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7093 pAdapterNode = pNext;
7094 }
7095
7096 EXIT();
7097
7098 return VOS_STATUS_SUCCESS;
7099}
7100
Rajeev Kumarf999e582014-01-09 17:33:29 -08007101
7102#ifdef FEATURE_WLAN_BATCH_SCAN
7103/**---------------------------------------------------------------------------
7104
7105 \brief hdd_deinit_batch_scan () - This function cleans up batch scan data
7106 structures
7107
7108 \param - pAdapter Pointer to HDD adapter
7109
7110 \return - None
7111
7112 --------------------------------------------------------------------------*/
7113void hdd_deinit_batch_scan(hdd_adapter_t *pAdapter)
7114{
7115 tHddBatchScanRsp *pNode;
7116 tHddBatchScanRsp *pPrev;
7117
Siddharth Bhalb3e9b792014-02-24 15:14:16 +05307118 if (NULL == pAdapter)
Rajeev Kumarf999e582014-01-09 17:33:29 -08007119 {
Siddharth Bhalb3e9b792014-02-24 15:14:16 +05307120 hddLog(VOS_TRACE_LEVEL_ERROR,
7121 "%s: Adapter context is Null", __func__);
7122 return;
7123 }
7124
7125 pNode = pAdapter->pBatchScanRsp;
7126 while (pNode)
7127 {
7128 pPrev = pNode;
7129 pNode = pNode->pNext;
7130 vos_mem_free((v_VOID_t * )pPrev);
Rajeev Kumarf999e582014-01-09 17:33:29 -08007131 }
7132
7133 pAdapter->pBatchScanRsp = NULL;
7134 pAdapter->numScanList = 0;
7135 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
7136 pAdapter->prev_batch_id = 0;
7137
7138 return;
7139}
7140#endif
7141
7142
Jeff Johnson295189b2012-06-20 16:38:30 -07007143VOS_STATUS hdd_reset_all_adapters( hdd_context_t *pHddCtx )
7144{
7145 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7146 VOS_STATUS status;
7147 hdd_adapter_t *pAdapter;
7148
7149 ENTER();
7150
7151 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7152
7153 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7154 {
7155 pAdapter = pAdapterNode->pAdapter;
7156 netif_tx_disable(pAdapter->dev);
7157 netif_carrier_off(pAdapter->dev);
7158
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -07007159 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
7160
Jeff Johnson295189b2012-06-20 16:38:30 -07007161 hdd_deinit_tx_rx(pAdapter);
Agarwal Ashish6267caa2014-08-06 19:16:21 +05307162
7163 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
7164
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05307165 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
7166 {
7167 hdd_wmm_adapter_close( pAdapter );
7168 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
7169 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007170
Rajeev Kumarf999e582014-01-09 17:33:29 -08007171#ifdef FEATURE_WLAN_BATCH_SCAN
7172 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
7173 {
7174 hdd_deinit_batch_scan(pAdapter);
7175 }
7176#endif
7177
Jeff Johnson295189b2012-06-20 16:38:30 -07007178 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7179 pAdapterNode = pNext;
7180 }
7181
7182 EXIT();
7183
7184 return VOS_STATUS_SUCCESS;
7185}
7186
7187VOS_STATUS hdd_start_all_adapters( hdd_context_t *pHddCtx )
7188{
7189 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7190 VOS_STATUS status;
7191 hdd_adapter_t *pAdapter;
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05307192 eConnectionState connState;
Jeff Johnson295189b2012-06-20 16:38:30 -07007193
7194 ENTER();
7195
7196 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7197
7198 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7199 {
7200 pAdapter = pAdapterNode->pAdapter;
7201
Kumar Anand82c009f2014-05-29 00:29:42 -07007202 hdd_wmm_init( pAdapter );
7203
Jeff Johnson295189b2012-06-20 16:38:30 -07007204 switch(pAdapter->device_mode)
7205 {
7206 case WLAN_HDD_INFRA_STATION:
7207 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07007208 case WLAN_HDD_P2P_DEVICE:
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05307209
7210 connState = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState;
7211
Jeff Johnson295189b2012-06-20 16:38:30 -07007212 hdd_init_station_mode(pAdapter);
7213 /* Open the gates for HDD to receive Wext commands */
7214 pAdapter->isLinkUpSvcNeeded = FALSE;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07007215 pHddCtx->scan_info.mScanPending = FALSE;
7216 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007217
7218 //Trigger the initial scan
7219 hdd_wlan_initial_scan(pAdapter);
7220
7221 //Indicate disconnect event to supplicant if associated previously
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05307222 if (eConnectionState_Associated == connState ||
7223 eConnectionState_IbssConnected == connState )
Jeff Johnson295189b2012-06-20 16:38:30 -07007224 {
7225 union iwreq_data wrqu;
7226 memset(&wrqu, '\0', sizeof(wrqu));
7227 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
7228 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
7229 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -07007230 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007231
Jeff Johnson295189b2012-06-20 16:38:30 -07007232 /* indicate disconnected event to nl80211 */
7233 cfg80211_disconnected(pAdapter->dev, WLAN_REASON_UNSPECIFIED,
7234 NULL, 0, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07007235 }
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05307236 else if (eConnectionState_Connecting == connState)
7237 {
7238 /*
7239 * Indicate connect failure to supplicant if we were in the
7240 * process of connecting
7241 */
7242 cfg80211_connect_result(pAdapter->dev, NULL,
7243 NULL, 0, NULL, 0,
7244 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
7245 GFP_KERNEL);
7246 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007247 break;
7248
7249 case WLAN_HDD_SOFTAP:
7250 /* softAP can handle SSR */
7251 break;
7252
7253 case WLAN_HDD_P2P_GO:
Sameer Thalappiledf0d792013-08-09 14:31:03 -07007254 hddLog(VOS_TRACE_LEVEL_ERROR, "%s [SSR] send stop ap to supplicant",
Jeff Johnson295189b2012-06-20 16:38:30 -07007255 __func__);
Sameer Thalappiledf0d792013-08-09 14:31:03 -07007256 cfg80211_ap_stopped(pAdapter->dev, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07007257 break;
7258
7259 case WLAN_HDD_MONITOR:
7260 /* monitor interface start */
7261 break;
7262 default:
7263 break;
7264 }
7265
7266 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7267 pAdapterNode = pNext;
7268 }
7269
7270 EXIT();
7271
7272 return VOS_STATUS_SUCCESS;
7273}
7274
7275VOS_STATUS hdd_reconnect_all_adapters( hdd_context_t *pHddCtx )
7276{
7277 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7278 hdd_adapter_t *pAdapter;
7279 VOS_STATUS status;
7280 v_U32_t roamId;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307281 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07007282
7283 ENTER();
7284
7285 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7286
7287 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7288 {
7289 pAdapter = pAdapterNode->pAdapter;
7290
7291 if( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
7292 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
7293 {
7294 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7295 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
7296
Abhishek Singhf4669da2014-05-26 15:07:49 +05307297 hddLog(VOS_TRACE_LEVEL_INFO,
7298 "%s: Set HDD connState to eConnectionState_NotConnected",
7299 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007300 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
7301 init_completion(&pAdapter->disconnect_comp_var);
7302 sme_RoamDisconnect(pHddCtx->hHal, pAdapter->sessionId,
7303 eCSR_DISCONNECT_REASON_UNSPECIFIED);
7304
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307305 ret = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07007306 &pAdapter->disconnect_comp_var,
7307 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307308 if (0 >= ret)
7309 hddLog(LOGE, "%s: failure waiting for disconnect_comp_var %ld",
7310 __func__, ret);
Jeff Johnson295189b2012-06-20 16:38:30 -07007311
7312 pWextState->roamProfile.csrPersona = pAdapter->device_mode;
7313 pHddCtx->isAmpAllowed = VOS_FALSE;
7314 sme_RoamConnect(pHddCtx->hHal,
7315 pAdapter->sessionId, &(pWextState->roamProfile),
7316 &roamId);
7317 }
7318
7319 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7320 pAdapterNode = pNext;
7321 }
7322
7323 EXIT();
7324
7325 return VOS_STATUS_SUCCESS;
7326}
7327
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -07007328void hdd_dump_concurrency_info(hdd_context_t *pHddCtx)
7329{
7330 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7331 VOS_STATUS status;
7332 hdd_adapter_t *pAdapter;
7333 hdd_station_ctx_t *pHddStaCtx;
7334 hdd_ap_ctx_t *pHddApCtx;
7335 hdd_hostapd_state_t * pHostapdState;
7336 tCsrBssid staBssid = { 0 }, p2pBssid = { 0 }, apBssid = { 0 };
7337 v_U8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
7338 const char *p2pMode = "DEV";
7339 const char *ccMode = "Standalone";
7340 int n;
7341
7342 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7343 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7344 {
7345 pAdapter = pAdapterNode->pAdapter;
7346 switch (pAdapter->device_mode) {
7347 case WLAN_HDD_INFRA_STATION:
7348 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7349 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
7350 staChannel = pHddStaCtx->conn_info.operationChannel;
7351 memcpy(staBssid, pHddStaCtx->conn_info.bssId, sizeof(staBssid));
7352 }
7353 break;
7354 case WLAN_HDD_P2P_CLIENT:
7355 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7356 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
7357 p2pChannel = pHddStaCtx->conn_info.operationChannel;
7358 memcpy(p2pBssid, pHddStaCtx->conn_info.bssId, sizeof(p2pBssid));
7359 p2pMode = "CLI";
7360 }
7361 break;
7362 case WLAN_HDD_P2P_GO:
7363 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
7364 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
7365 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
7366 p2pChannel = pHddApCtx->operatingChannel;
7367 memcpy(p2pBssid, pAdapter->macAddressCurrent.bytes, sizeof(p2pBssid));
7368 }
7369 p2pMode = "GO";
7370 break;
7371 case WLAN_HDD_SOFTAP:
7372 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
7373 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
7374 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
7375 apChannel = pHddApCtx->operatingChannel;
7376 memcpy(apBssid, pAdapter->macAddressCurrent.bytes, sizeof(apBssid));
7377 }
7378 break;
7379 default:
7380 break;
7381 }
7382 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7383 pAdapterNode = pNext;
7384 }
7385 if (staChannel > 0 && (apChannel > 0 || p2pChannel > 0)) {
7386 ccMode = (p2pChannel==staChannel||apChannel==staChannel) ? "SCC" : "MCC";
7387 }
7388 n = pr_info("wlan(%d) " MAC_ADDRESS_STR " %s",
7389 staChannel, MAC_ADDR_ARRAY(staBssid), ccMode);
7390 if (p2pChannel > 0) {
7391 n += pr_info("p2p-%s(%d) " MAC_ADDRESS_STR,
7392 p2pMode, p2pChannel, MAC_ADDR_ARRAY(p2pBssid));
7393 }
7394 if (apChannel > 0) {
7395 n += pr_info("AP(%d) " MAC_ADDRESS_STR,
7396 apChannel, MAC_ADDR_ARRAY(apBssid));
7397 }
7398
7399 if (p2pChannel > 0 && apChannel > 0) {
7400 hddLog(VOS_TRACE_LEVEL_ERROR, "Error concurrent SAP %d and P2P %d which is not support", apChannel, p2pChannel);
7401 }
7402}
7403
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07007404bool hdd_is_ssr_required( void)
Jeff Johnson295189b2012-06-20 16:38:30 -07007405{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07007406 return (isSsrRequired == HDD_SSR_REQUIRED);
Jeff Johnson295189b2012-06-20 16:38:30 -07007407}
7408
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07007409/* Once SSR is disabled then it cannot be set. */
7410void hdd_set_ssr_required( e_hdd_ssr_required value)
Jeff Johnson295189b2012-06-20 16:38:30 -07007411{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07007412 if (HDD_SSR_DISABLED == isSsrRequired)
7413 return;
7414
Jeff Johnson295189b2012-06-20 16:38:30 -07007415 isSsrRequired = value;
7416}
7417
7418VOS_STATUS hdd_get_front_adapter( hdd_context_t *pHddCtx,
7419 hdd_adapter_list_node_t** ppAdapterNode)
7420{
7421 VOS_STATUS status;
7422 spin_lock(&pHddCtx->hddAdapters.lock);
7423 status = hdd_list_peek_front ( &pHddCtx->hddAdapters,
7424 (hdd_list_node_t**) ppAdapterNode );
7425 spin_unlock(&pHddCtx->hddAdapters.lock);
7426 return status;
7427}
7428
7429VOS_STATUS hdd_get_next_adapter( hdd_context_t *pHddCtx,
7430 hdd_adapter_list_node_t* pAdapterNode,
7431 hdd_adapter_list_node_t** pNextAdapterNode)
7432{
7433 VOS_STATUS status;
7434 spin_lock(&pHddCtx->hddAdapters.lock);
7435 status = hdd_list_peek_next ( &pHddCtx->hddAdapters,
7436 (hdd_list_node_t*) pAdapterNode,
7437 (hdd_list_node_t**)pNextAdapterNode );
7438
7439 spin_unlock(&pHddCtx->hddAdapters.lock);
7440 return status;
7441}
7442
7443VOS_STATUS hdd_remove_adapter( hdd_context_t *pHddCtx,
7444 hdd_adapter_list_node_t* pAdapterNode)
7445{
7446 VOS_STATUS status;
7447 spin_lock(&pHddCtx->hddAdapters.lock);
7448 status = hdd_list_remove_node ( &pHddCtx->hddAdapters,
7449 &pAdapterNode->node );
7450 spin_unlock(&pHddCtx->hddAdapters.lock);
7451 return status;
7452}
7453
7454VOS_STATUS hdd_remove_front_adapter( hdd_context_t *pHddCtx,
7455 hdd_adapter_list_node_t** ppAdapterNode)
7456{
7457 VOS_STATUS status;
7458 spin_lock(&pHddCtx->hddAdapters.lock);
7459 status = hdd_list_remove_front( &pHddCtx->hddAdapters,
7460 (hdd_list_node_t**) ppAdapterNode );
7461 spin_unlock(&pHddCtx->hddAdapters.lock);
7462 return status;
7463}
7464
7465VOS_STATUS hdd_add_adapter_back( hdd_context_t *pHddCtx,
7466 hdd_adapter_list_node_t* pAdapterNode)
7467{
7468 VOS_STATUS status;
7469 spin_lock(&pHddCtx->hddAdapters.lock);
7470 status = hdd_list_insert_back ( &pHddCtx->hddAdapters,
7471 (hdd_list_node_t*) pAdapterNode );
7472 spin_unlock(&pHddCtx->hddAdapters.lock);
7473 return status;
7474}
7475
7476VOS_STATUS hdd_add_adapter_front( hdd_context_t *pHddCtx,
7477 hdd_adapter_list_node_t* pAdapterNode)
7478{
7479 VOS_STATUS status;
7480 spin_lock(&pHddCtx->hddAdapters.lock);
7481 status = hdd_list_insert_front ( &pHddCtx->hddAdapters,
7482 (hdd_list_node_t*) pAdapterNode );
7483 spin_unlock(&pHddCtx->hddAdapters.lock);
7484 return status;
7485}
7486
7487hdd_adapter_t * hdd_get_adapter_by_macaddr( hdd_context_t *pHddCtx,
7488 tSirMacAddr macAddr )
7489{
7490 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7491 hdd_adapter_t *pAdapter;
7492 VOS_STATUS status;
7493
7494 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7495
7496 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7497 {
7498 pAdapter = pAdapterNode->pAdapter;
7499
7500 if( pAdapter && vos_mem_compare( pAdapter->macAddressCurrent.bytes,
7501 macAddr, sizeof(tSirMacAddr) ) )
7502 {
7503 return pAdapter;
7504 }
7505 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7506 pAdapterNode = pNext;
7507 }
7508
7509 return NULL;
7510
7511}
7512
7513hdd_adapter_t * hdd_get_adapter_by_name( hdd_context_t *pHddCtx, tANI_U8 *name )
7514{
7515 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7516 hdd_adapter_t *pAdapter;
7517 VOS_STATUS status;
7518
7519 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7520
7521 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7522 {
7523 pAdapter = pAdapterNode->pAdapter;
7524
7525 if( pAdapter && !strncmp( pAdapter->dev->name, (const char *)name,
7526 IFNAMSIZ ) )
7527 {
7528 return pAdapter;
7529 }
7530 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7531 pAdapterNode = pNext;
7532 }
7533
7534 return NULL;
7535
7536}
7537
7538hdd_adapter_t * hdd_get_adapter( hdd_context_t *pHddCtx, device_mode_t mode )
7539{
7540 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7541 hdd_adapter_t *pAdapter;
7542 VOS_STATUS status;
7543
7544 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7545
7546 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7547 {
7548 pAdapter = pAdapterNode->pAdapter;
7549
7550 if( pAdapter && (mode == pAdapter->device_mode) )
7551 {
7552 return pAdapter;
7553 }
7554 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7555 pAdapterNode = pNext;
7556 }
7557
7558 return NULL;
7559
7560}
7561
7562//Remove this function later
7563hdd_adapter_t * hdd_get_mon_adapter( hdd_context_t *pHddCtx )
7564{
7565 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7566 hdd_adapter_t *pAdapter;
7567 VOS_STATUS status;
7568
7569 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7570
7571 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7572 {
7573 pAdapter = pAdapterNode->pAdapter;
7574
7575 if( pAdapter && WLAN_HDD_MONITOR == pAdapter->device_mode )
7576 {
7577 return pAdapter;
7578 }
7579
7580 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7581 pAdapterNode = pNext;
7582 }
7583
7584 return NULL;
7585
7586}
7587
Jeff Johnson295189b2012-06-20 16:38:30 -07007588/**---------------------------------------------------------------------------
7589
7590 \brief hdd_set_monitor_tx_adapter() -
7591
7592 This API initializes the adapter to be used while transmitting on monitor
7593 adapter.
7594
7595 \param - pHddCtx - Pointer to the HDD context.
7596 pAdapter - Adapter that will used for TX. This can be NULL.
7597 \return - None.
7598 --------------------------------------------------------------------------*/
7599void wlan_hdd_set_monitor_tx_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
7600{
7601 hdd_adapter_t *pMonAdapter;
7602
7603 pMonAdapter = hdd_get_adapter( pHddCtx, WLAN_HDD_MONITOR );
7604
7605 if( NULL != pMonAdapter )
7606 {
7607 pMonAdapter->sessionCtx.monitor.pAdapterForTx = pAdapter;
7608 }
7609}
Jeff Johnson295189b2012-06-20 16:38:30 -07007610/**---------------------------------------------------------------------------
7611
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307612 \brief hdd_get_operating_channel() -
Jeff Johnson295189b2012-06-20 16:38:30 -07007613
7614 This API returns the operating channel of the requested device mode
7615
7616 \param - pHddCtx - Pointer to the HDD context.
7617 - mode - Device mode for which operating channel is required
7618 suported modes - WLAN_HDD_INFRA_STATION, WLAN_HDD_P2P_CLIENT
7619 WLAN_HDD_SOFTAP, WLAN_HDD_P2P_GO.
7620 \return - channel number. "0" id the requested device is not found OR it is not connected.
7621 --------------------------------------------------------------------------*/
7622v_U8_t hdd_get_operating_channel( hdd_context_t *pHddCtx, device_mode_t mode )
7623{
7624 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7625 VOS_STATUS status;
7626 hdd_adapter_t *pAdapter;
7627 v_U8_t operatingChannel = 0;
7628
7629 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7630
7631 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7632 {
7633 pAdapter = pAdapterNode->pAdapter;
7634
7635 if( mode == pAdapter->device_mode )
7636 {
7637 switch(pAdapter->device_mode)
7638 {
7639 case WLAN_HDD_INFRA_STATION:
7640 case WLAN_HDD_P2P_CLIENT:
7641 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
7642 operatingChannel = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.operationChannel;
7643 break;
7644 case WLAN_HDD_SOFTAP:
7645 case WLAN_HDD_P2P_GO:
7646 /*softap connection info */
7647 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
7648 operatingChannel = (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->operatingChannel;
7649 break;
7650 default:
7651 break;
7652 }
7653
7654 break; //Found the device of interest. break the loop
7655 }
7656
7657 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7658 pAdapterNode = pNext;
7659 }
7660 return operatingChannel;
7661}
7662
7663#ifdef WLAN_FEATURE_PACKET_FILTERING
7664/**---------------------------------------------------------------------------
7665
7666 \brief hdd_set_multicast_list() -
7667
7668 This used to set the multicast address list.
7669
7670 \param - dev - Pointer to the WLAN device.
7671 - skb - Pointer to OS packet (sk_buff).
7672 \return - success/fail
7673
7674 --------------------------------------------------------------------------*/
7675static void hdd_set_multicast_list(struct net_device *dev)
7676{
7677 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07007678 int mc_count;
7679 int i = 0;
7680 struct netdev_hw_addr *ha;
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307681
7682 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -07007683 {
7684 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307685 "%s: Adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007686 return;
7687 }
7688
7689 if (dev->flags & IFF_ALLMULTI)
7690 {
7691 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007692 "%s: allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307693 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007694 }
7695 else
7696 {
7697 mc_count = netdev_mc_count(dev);
7698 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007699 "%s: mc_count = %u", __func__, mc_count);
Jeff Johnson295189b2012-06-20 16:38:30 -07007700 if (mc_count > WLAN_HDD_MAX_MC_ADDR_LIST)
7701 {
7702 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007703 "%s: No free filter available; allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307704 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007705 return;
7706 }
7707
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307708 pAdapter->mc_addr_list.mc_cnt = mc_count;
Jeff Johnson295189b2012-06-20 16:38:30 -07007709
7710 netdev_for_each_mc_addr(ha, dev) {
7711 if (i == mc_count)
7712 break;
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307713 memset(&(pAdapter->mc_addr_list.addr[i][0]), 0, ETH_ALEN);
7714 memcpy(&(pAdapter->mc_addr_list.addr[i][0]), ha->addr, ETH_ALEN);
Arif Hussain6d2a3322013-11-17 19:50:10 -08007715 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mlist[%d] = "MAC_ADDRESS_STR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007716 __func__, i,
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307717 MAC_ADDR_ARRAY(pAdapter->mc_addr_list.addr[i]));
Jeff Johnson295189b2012-06-20 16:38:30 -07007718 i++;
7719 }
7720 }
7721 return;
7722}
7723#endif
7724
7725/**---------------------------------------------------------------------------
7726
7727 \brief hdd_select_queue() -
7728
7729 This function is registered with the Linux OS for network
7730 core to decide which queue to use first.
7731
7732 \param - dev - Pointer to the WLAN device.
7733 - skb - Pointer to OS packet (sk_buff).
7734 \return - ac, Queue Index/access category corresponding to UP in IP header
7735
7736 --------------------------------------------------------------------------*/
7737v_U16_t hdd_select_queue(struct net_device *dev,
7738 struct sk_buff *skb)
7739{
7740 return hdd_wmm_select_queue(dev, skb);
7741}
7742
7743
7744/**---------------------------------------------------------------------------
7745
7746 \brief hdd_wlan_initial_scan() -
7747
7748 This function triggers the initial scan
7749
7750 \param - pAdapter - Pointer to the HDD adapter.
7751
7752 --------------------------------------------------------------------------*/
7753void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter)
7754{
7755 tCsrScanRequest scanReq;
7756 tCsrChannelInfo channelInfo;
7757 eHalStatus halStatus;
Jeff Johnson02797792013-10-26 19:17:13 -07007758 tANI_U32 scanId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007759 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7760
7761 vos_mem_zero(&scanReq, sizeof(tCsrScanRequest));
7762 vos_mem_set(&scanReq.bssid, sizeof(tCsrBssid), 0xff);
7763 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
7764
7765 if(sme_Is11dSupported(pHddCtx->hHal))
7766 {
7767 halStatus = sme_ScanGetBaseChannels( pHddCtx->hHal, &channelInfo );
7768 if ( HAL_STATUS_SUCCESS( halStatus ) )
7769 {
7770 scanReq.ChannelInfo.ChannelList = vos_mem_malloc(channelInfo.numOfChannels);
7771 if( !scanReq.ChannelInfo.ChannelList )
7772 {
7773 hddLog(VOS_TRACE_LEVEL_ERROR, "%s kmalloc failed", __func__);
7774 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08007775 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007776 return;
7777 }
7778 vos_mem_copy(scanReq.ChannelInfo.ChannelList, channelInfo.ChannelList,
7779 channelInfo.numOfChannels);
7780 scanReq.ChannelInfo.numOfChannels = channelInfo.numOfChannels;
7781 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08007782 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007783 }
7784
7785 scanReq.scanType = eSIR_PASSIVE_SCAN;
7786 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
7787 scanReq.maxChnTime = pHddCtx->cfg_ini->nPassiveMaxChnTime;
7788 scanReq.minChnTime = pHddCtx->cfg_ini->nPassiveMinChnTime;
7789 }
7790 else
7791 {
7792 scanReq.scanType = eSIR_ACTIVE_SCAN;
7793 scanReq.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
7794 scanReq.maxChnTime = pHddCtx->cfg_ini->nActiveMaxChnTime;
7795 scanReq.minChnTime = pHddCtx->cfg_ini->nActiveMinChnTime;
7796 }
7797
7798 halStatus = sme_ScanRequest(pHddCtx->hHal, pAdapter->sessionId, &scanReq, &scanId, NULL, NULL);
7799 if ( !HAL_STATUS_SUCCESS( halStatus ) )
7800 {
7801 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_ScanRequest failed status code %d",
7802 __func__, halStatus );
7803 }
7804
7805 if(sme_Is11dSupported(pHddCtx->hHal))
7806 vos_mem_free(scanReq.ChannelInfo.ChannelList);
7807}
7808
Jeff Johnson295189b2012-06-20 16:38:30 -07007809/**---------------------------------------------------------------------------
7810
7811 \brief hdd_full_power_callback() - HDD full power callback function
7812
7813 This is the function invoked by SME to inform the result of a full power
7814 request issued by HDD
7815
7816 \param - callbackcontext - Pointer to cookie
7817 \param - status - result of request
7818
7819 \return - None
7820
7821 --------------------------------------------------------------------------*/
7822static void hdd_full_power_callback(void *callbackContext, eHalStatus status)
7823{
Jeff Johnson72a40512013-12-19 10:14:15 -08007824 struct statsContext *pContext = callbackContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07007825
7826 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05307827 "%s: context = %p, status = %d", __func__, pContext, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007828
7829 if (NULL == callbackContext)
7830 {
7831 hddLog(VOS_TRACE_LEVEL_ERROR,
7832 "%s: Bad param, context [%p]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007833 __func__, callbackContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07007834 return;
7835 }
7836
Jeff Johnson72a40512013-12-19 10:14:15 -08007837 /* there is a race condition that exists between this callback
7838 function and the caller since the caller could time out either
7839 before or while this code is executing. we use a spinlock to
7840 serialize these actions */
7841 spin_lock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07007842
7843 if (POWER_CONTEXT_MAGIC != pContext->magic)
7844 {
7845 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -08007846 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07007847 hddLog(VOS_TRACE_LEVEL_WARN,
7848 "%s: Invalid context, magic [%08x]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007849 __func__, pContext->magic);
Jeff Johnson295189b2012-06-20 16:38:30 -07007850 return;
7851 }
7852
Jeff Johnson72a40512013-12-19 10:14:15 -08007853 /* context is valid so caller is still waiting */
7854
7855 /* paranoia: invalidate the magic */
7856 pContext->magic = 0;
7857
7858 /* notify the caller */
Jeff Johnson295189b2012-06-20 16:38:30 -07007859 complete(&pContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -08007860
7861 /* serialization is complete */
7862 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07007863}
7864
7865/**---------------------------------------------------------------------------
7866
7867 \brief hdd_wlan_exit() - HDD WLAN exit function
7868
7869 This is the driver exit point (invoked during rmmod)
7870
7871 \param - pHddCtx - Pointer to the HDD Context
7872
7873 \return - None
7874
7875 --------------------------------------------------------------------------*/
7876void hdd_wlan_exit(hdd_context_t *pHddCtx)
7877{
7878 eHalStatus halStatus;
7879 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
7880 VOS_STATUS vosStatus;
Gopichand Nakkala66923aa2013-03-06 23:17:24 +05307881 struct wiphy *wiphy = pHddCtx->wiphy;
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08007882 hdd_adapter_t* pAdapter = NULL;
Jeff Johnson72a40512013-12-19 10:14:15 -08007883 struct statsContext powerContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07007884 long lrc;
c_hpothu5ab05e92014-06-13 17:34:05 +05307885 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007886
7887 ENTER();
7888
Jeff Johnson88ba7742013-02-27 14:36:02 -08007889 if (VOS_FTM_MODE != hdd_get_conparam())
7890 {
7891 // Unloading, restart logic is no more required.
7892 wlan_hdd_restart_deinit(pHddCtx);
Jeff Johnsone7245742012-09-05 17:12:55 -07007893
c_hpothu5ab05e92014-06-13 17:34:05 +05307894 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7895 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
Jeff Johnson295189b2012-06-20 16:38:30 -07007896 {
c_hpothu5ab05e92014-06-13 17:34:05 +05307897 pAdapter = pAdapterNode->pAdapter;
7898 if (NULL != pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -07007899 {
c_hpothu5ab05e92014-06-13 17:34:05 +05307900 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
7901 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
7902 {
7903 wlan_hdd_cfg80211_deregister_frames(pAdapter);
7904 hdd_UnregisterWext(pAdapter->dev);
7905 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +05307906
Jeff Johnson295189b2012-06-20 16:38:30 -07007907 }
c_hpothu5ab05e92014-06-13 17:34:05 +05307908 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7909 pAdapterNode = pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -07007910 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +05307911 // Cancel any outstanding scan requests. We are about to close all
7912 // of our adapters, but an adapter structure is what SME passes back
7913 // to our callback function. Hence if there are any outstanding scan
7914 // requests then there is a race condition between when the adapter
7915 // is closed and when the callback is invoked.We try to resolve that
7916 // race condition here by canceling any outstanding scans before we
7917 // close the adapters.
7918 // Note that the scans may be cancelled in an asynchronous manner,
7919 // so ideally there needs to be some kind of synchronization. Rather
7920 // than introduce a new synchronization here, we will utilize the
7921 // fact that we are about to Request Full Power, and since that is
7922 // synchronized, the expectation is that by the time Request Full
7923 // Power has completed all scans will be cancelled.
7924 if (pHddCtx->scan_info.mScanPending)
7925 {
7926 hddLog(VOS_TRACE_LEVEL_INFO,
7927 FL("abort scan mode: %d sessionId: %d"),
7928 pAdapter->device_mode,
7929 pAdapter->sessionId);
7930 hdd_abort_mac_scan(pHddCtx,
7931 pHddCtx->scan_info.sessionId,
7932 eCSR_SCAN_ABORT_DEFAULT);
7933 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007934 }
c_hpothu5ab05e92014-06-13 17:34:05 +05307935 else
Jeff Johnson88ba7742013-02-27 14:36:02 -08007936 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307937 hddLog(VOS_TRACE_LEVEL_INFO,"%s: FTM MODE",__func__);
Jeff Johnson88ba7742013-02-27 14:36:02 -08007938 wlan_hdd_ftm_close(pHddCtx);
7939 goto free_hdd_ctx;
7940 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307941
Jeff Johnson295189b2012-06-20 16:38:30 -07007942 /* DeRegister with platform driver as client for Suspend/Resume */
7943 vosStatus = hddDeregisterPmOps(pHddCtx);
7944 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
7945 {
7946 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDeregisterPmOps failed",__func__);
7947 VOS_ASSERT(0);
7948 }
7949
7950 vosStatus = hddDevTmUnregisterNotifyCallback(pHddCtx);
7951 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
7952 {
7953 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
7954 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007955
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07007956 //Stop the traffic monitor timer
7957 if ( VOS_TIMER_STATE_RUNNING ==
7958 vos_timer_getCurrentState(&pHddCtx->tx_rx_trafficTmr))
7959 {
7960 vos_timer_stop(&pHddCtx->tx_rx_trafficTmr);
7961 }
7962
7963 // Destroy the traffic monitor timer
7964 if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
7965 &pHddCtx->tx_rx_trafficTmr)))
7966 {
7967 hddLog(VOS_TRACE_LEVEL_ERROR,
7968 "%s: Cannot deallocate Traffic monitor timer", __func__);
7969 }
7970
Jeff Johnson295189b2012-06-20 16:38:30 -07007971 //Disable IMPS/BMPS as we do not want the device to enter any power
7972 //save mode during shutdown
7973 sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
7974 sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
7975 sme_DisablePowerSave(pHddCtx->hHal, ePMC_UAPSD_MODE_POWER_SAVE);
7976
7977 //Ensure that device is in full power as we will touch H/W during vos_Stop
7978 init_completion(&powerContext.completion);
7979 powerContext.magic = POWER_CONTEXT_MAGIC;
7980
7981 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_power_callback,
7982 &powerContext, eSME_FULL_PWR_NEEDED_BY_HDD);
7983
7984 if (eHAL_STATUS_SUCCESS != halStatus)
7985 {
7986 if (eHAL_STATUS_PMC_PENDING == halStatus)
7987 {
7988 /* request was sent -- wait for the response */
7989 lrc = wait_for_completion_interruptible_timeout(
7990 &powerContext.completion,
7991 msecs_to_jiffies(WLAN_WAIT_TIME_POWER));
Jeff Johnson295189b2012-06-20 16:38:30 -07007992 if (lrc <= 0)
7993 {
7994 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: %s while requesting full power",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007995 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson295189b2012-06-20 16:38:30 -07007996 }
7997 }
7998 else
7999 {
8000 hddLog(VOS_TRACE_LEVEL_ERROR,
8001 "%s: Request for Full Power failed, status %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008002 __func__, halStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07008003 /* continue -- need to clean up as much as possible */
8004 }
8005 }
8006
Jeff Johnson72a40512013-12-19 10:14:15 -08008007 /* either we never sent a request, we sent a request and received a
8008 response or we sent a request and timed out. if we never sent a
8009 request or if we sent a request and got a response, we want to
8010 clear the magic out of paranoia. if we timed out there is a
8011 race condition such that the callback function could be
8012 executing at the same time we are. of primary concern is if the
8013 callback function had already verified the "magic" but had not
8014 yet set the completion variable when a timeout occurred. we
8015 serialize these activities by invalidating the magic while
8016 holding a shared spinlock which will cause us to block if the
8017 callback is currently executing */
8018 spin_lock(&hdd_context_lock);
8019 powerContext.magic = 0;
8020 spin_unlock(&hdd_context_lock);
8021
Yue Ma0d4891e2013-08-06 17:01:45 -07008022 hdd_debugfs_exit(pHddCtx);
8023
Jeff Johnson295189b2012-06-20 16:38:30 -07008024 // Unregister the Net Device Notifier
8025 unregister_netdevice_notifier(&hdd_netdev_notifier);
8026
Jeff Johnson295189b2012-06-20 16:38:30 -07008027 hdd_stop_all_adapters( pHddCtx );
8028
Jeff Johnson295189b2012-06-20 16:38:30 -07008029#ifdef WLAN_BTAMP_FEATURE
8030 vosStatus = WLANBAP_Stop(pVosContext);
8031 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
8032 {
8033 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
8034 "%s: Failed to stop BAP",__func__);
8035 }
8036#endif //WLAN_BTAMP_FEATURE
8037
8038 //Stop all the modules
8039 vosStatus = vos_stop( pVosContext );
8040 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
8041 {
8042 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8043 "%s: Failed to stop VOSS",__func__);
8044 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
8045 }
8046
Jeff Johnson295189b2012-06-20 16:38:30 -07008047 //This requires pMac access, Call this before vos_close().
Jeff Johnson295189b2012-06-20 16:38:30 -07008048 hdd_unregister_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07008049
8050 //Close the scheduler before calling vos_close to make sure no thread is
8051 // scheduled after the each module close is called i.e after all the data
8052 // structures are freed.
8053 vosStatus = vos_sched_close( pVosContext );
8054 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
8055 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
8056 "%s: Failed to close VOSS Scheduler",__func__);
8057 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
8058 }
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008059#ifdef WLAN_OPEN_SOURCE
Jeff Johnsone7245742012-09-05 17:12:55 -07008060#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
8061 /* Destroy the wake lock */
8062 wake_lock_destroy(&pHddCtx->rx_wake_lock);
8063#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -08008064 /* Destroy the wake lock */
8065 wake_lock_destroy(&pHddCtx->sap_wake_lock);
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008066#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008067
Mihir Shete7a24b5f2013-12-21 12:18:31 +05308068#ifdef CONFIG_ENABLE_LINUX_REG
8069 vosStatus = vos_nv_close();
8070 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
8071 {
8072 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
8073 "%s: Failed to close NV", __func__);
8074 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
8075 }
8076#endif
8077
Jeff Johnson295189b2012-06-20 16:38:30 -07008078 //Close VOSS
8079 //This frees pMac(HAL) context. There should not be any call that requires pMac access after this.
8080 vos_close(pVosContext);
8081
Jeff Johnson295189b2012-06-20 16:38:30 -07008082 //Close Watchdog
8083 if(pHddCtx->cfg_ini->fIsLogpEnabled)
8084 vos_watchdog_close(pVosContext);
8085
Gopichand Nakkalaa0358482013-06-12 17:05:47 +05308086 //Clean up HDD Nlink Service
8087 send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0);
Gopichand Nakkalaa0358482013-06-12 17:05:47 +05308088
Vinay Krishna Erannad938c422014-03-10 17:14:21 +05308089#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05308090 if (pHddCtx->cfg_ini->wlanLoggingEnable)
Vinay Krishna Erannad938c422014-03-10 17:14:21 +05308091 {
8092 wlan_logging_sock_deactivate_svc();
8093 }
8094#endif
8095
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +05308096#ifdef WLAN_KD_READY_NOTIFIER
8097 nl_srv_exit(pHddCtx->ptt_pid);
8098#else
8099 nl_srv_exit();
8100#endif /* WLAN_KD_READY_NOTIFIER */
8101
8102
Jeff Johnson295189b2012-06-20 16:38:30 -07008103 hdd_close_all_adapters( pHddCtx );
8104
Jeff Johnson295189b2012-06-20 16:38:30 -07008105 /* free the power on lock from platform driver */
8106 if (free_riva_power_on_lock("wlan"))
8107 {
8108 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to free power on lock",
8109 __func__);
8110 }
8111
Jeff Johnson88ba7742013-02-27 14:36:02 -08008112free_hdd_ctx:
c_hpothu78c7b602014-05-17 17:35:49 +05308113
8114 //Free up dynamically allocated members inside HDD Adapter
8115 if (pHddCtx->cfg_ini)
8116 {
8117 kfree(pHddCtx->cfg_ini);
8118 pHddCtx->cfg_ini= NULL;
8119 }
8120
Leo Changf04ddad2013-09-18 13:46:38 -07008121 /* FTM mode, WIPHY did not registered
8122 If un-register here, system crash will happen */
8123 if (VOS_FTM_MODE != hdd_get_conparam())
8124 {
8125 wiphy_unregister(wiphy) ;
8126 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008127 wiphy_free(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -07008128 if (hdd_is_ssr_required())
8129 {
8130 /* WDI timeout had happened during unload, so SSR is needed here */
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -07008131 subsystem_restart("wcnss");
Jeff Johnson295189b2012-06-20 16:38:30 -07008132 msleep(5000);
8133 }
8134 hdd_set_ssr_required (VOS_FALSE);
8135}
8136
8137
8138/**---------------------------------------------------------------------------
8139
8140 \brief hdd_update_config_from_nv() - Function to update the contents of
8141 the running configuration with parameters taken from NV storage
8142
8143 \param - pHddCtx - Pointer to the HDD global context
8144
8145 \return - VOS_STATUS_SUCCESS if successful
8146
8147 --------------------------------------------------------------------------*/
8148static VOS_STATUS hdd_update_config_from_nv(hdd_context_t* pHddCtx)
8149{
Jeff Johnson295189b2012-06-20 16:38:30 -07008150 v_BOOL_t itemIsValid = VOS_FALSE;
8151 VOS_STATUS status;
8152 v_MACADDR_t macFromNV[VOS_MAX_CONCURRENCY_PERSONA];
8153 v_U8_t macLoop;
8154
8155 /*If the NV is valid then get the macaddress from nv else get it from qcom_cfg.ini*/
8156 status = vos_nv_getValidity(VNV_FIELD_IMAGE, &itemIsValid);
8157 if(status != VOS_STATUS_SUCCESS)
8158 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008159 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_getValidity() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07008160 return VOS_STATUS_E_FAILURE;
8161 }
8162
8163 if (itemIsValid == VOS_TRUE)
8164 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008165 hddLog(VOS_TRACE_LEVEL_INFO_HIGH," Reading the Macaddress from NV");
Jeff Johnson295189b2012-06-20 16:38:30 -07008166 status = vos_nv_readMultiMacAddress((v_U8_t *)&macFromNV[0].bytes[0],
8167 VOS_MAX_CONCURRENCY_PERSONA);
8168 if(status != VOS_STATUS_SUCCESS)
8169 {
8170 /* Get MAC from NV fail, not update CFG info
8171 * INI MAC value will be used for MAC setting */
Arif Hussain6d2a3322013-11-17 19:50:10 -08008172 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_readMacAddress() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07008173 return VOS_STATUS_E_FAILURE;
8174 }
8175
8176 /* If first MAC is not valid, treat all others are not valid
8177 * Then all MACs will be got from ini file */
8178 if(vos_is_macaddr_zero(&macFromNV[0]))
8179 {
8180 /* MAC address in NV file is not configured yet */
8181 hddLog(VOS_TRACE_LEVEL_WARN, "Invalid MAC in NV file");
8182 return VOS_STATUS_E_INVAL;
8183 }
8184
8185 /* Get MAC address from NV, update CFG info */
8186 for(macLoop = 0; macLoop < VOS_MAX_CONCURRENCY_PERSONA; macLoop++)
8187 {
8188 if(vos_is_macaddr_zero(&macFromNV[macLoop]))
8189 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308190 hddLog(VOS_TRACE_LEVEL_ERROR,"not valid MAC from NV for %d", macLoop);
Jeff Johnson295189b2012-06-20 16:38:30 -07008191 /* This MAC is not valid, skip it
8192 * This MAC will be got from ini file */
8193 }
8194 else
8195 {
8196 vos_mem_copy((v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[macLoop].bytes[0],
8197 (v_U8_t *)&macFromNV[macLoop].bytes[0],
8198 VOS_MAC_ADDR_SIZE);
8199 }
8200 }
8201 }
8202 else
8203 {
8204 hddLog(VOS_TRACE_LEVEL_ERROR, "NV ITEM, MAC Not valid");
8205 return VOS_STATUS_E_FAILURE;
8206 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008207
Jeff Johnson295189b2012-06-20 16:38:30 -07008208
8209 return VOS_STATUS_SUCCESS;
8210}
8211
8212/**---------------------------------------------------------------------------
8213
8214 \brief hdd_post_voss_start_config() - HDD post voss start config helper
8215
8216 \param - pAdapter - Pointer to the HDD
8217
8218 \return - None
8219
8220 --------------------------------------------------------------------------*/
8221VOS_STATUS hdd_post_voss_start_config(hdd_context_t* pHddCtx)
8222{
8223 eHalStatus halStatus;
8224 v_U32_t listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308225 tANI_U32 ignoreDtim;
Jeff Johnson295189b2012-06-20 16:38:30 -07008226
Jeff Johnson295189b2012-06-20 16:38:30 -07008227
8228 // Send ready indication to the HDD. This will kick off the MAC
8229 // into a 'running' state and should kick off an initial scan.
8230 halStatus = sme_HDDReadyInd( pHddCtx->hHal );
8231 if ( !HAL_STATUS_SUCCESS( halStatus ) )
8232 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05308233 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: sme_HDDReadyInd() failed with status "
Jeff Johnson295189b2012-06-20 16:38:30 -07008234 "code %08d [x%08x]",__func__, halStatus, halStatus );
8235 return VOS_STATUS_E_FAILURE;
8236 }
8237
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308238 // Set default LI and ignoreDtim into HDD context,
Jeff Johnson295189b2012-06-20 16:38:30 -07008239 // otherwise under some race condition, HDD will set 0 LI value into RIVA,
8240 // And RIVA will crash
8241 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, &listenInterval);
8242 pHddCtx->hdd_actual_LI_value = listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308243 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, &ignoreDtim);
8244 pHddCtx->hdd_actual_ignore_DTIM_value = ignoreDtim;
8245
8246
Jeff Johnson295189b2012-06-20 16:38:30 -07008247 return VOS_STATUS_SUCCESS;
8248}
8249
Jeff Johnson295189b2012-06-20 16:38:30 -07008250/* wake lock APIs for HDD */
8251void hdd_prevent_suspend(void)
8252{
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008253#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07008254 wake_lock(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07008255#else
8256 wcnss_prevent_suspend();
8257#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008258}
8259
8260void hdd_allow_suspend(void)
8261{
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008262#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07008263 wake_unlock(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07008264#else
8265 wcnss_allow_suspend();
8266#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008267}
8268
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05308269void hdd_prevent_suspend_timeout(v_U32_t timeout)
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07008270{
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008271#ifdef WLAN_OPEN_SOURCE
Amar Singhal6144c002013-05-03 16:11:42 -07008272 wake_lock_timeout(&wlan_wake_lock, msecs_to_jiffies(timeout));
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07008273#else
8274 /* Do nothing as there is no API in wcnss for timeout*/
8275#endif
8276}
8277
Jeff Johnson295189b2012-06-20 16:38:30 -07008278/**---------------------------------------------------------------------------
8279
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008280 \brief hdd_exchange_version_and_caps() - HDD function to exchange version and capability
8281 information between Host and Riva
8282
8283 This function gets reported version of FW
8284 It also finds the version of Riva headers used to compile the host
8285 It compares the above two and prints a warning if they are different
8286 It gets the SW and HW version string
8287 Finally, it exchanges capabilities between host and Riva i.e. host and riva exchange a msg
8288 indicating the features they support through a bitmap
8289
8290 \param - pHddCtx - Pointer to HDD context
8291
8292 \return - void
8293
8294 --------------------------------------------------------------------------*/
8295
8296void hdd_exchange_version_and_caps(hdd_context_t *pHddCtx)
8297{
8298
8299 tSirVersionType versionCompiled;
8300 tSirVersionType versionReported;
8301 tSirVersionString versionString;
8302 tANI_U8 fwFeatCapsMsgSupported = 0;
8303 VOS_STATUS vstatus;
8304
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08008305 memset(&versionCompiled, 0, sizeof(versionCompiled));
8306 memset(&versionReported, 0, sizeof(versionReported));
8307
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008308 /* retrieve and display WCNSS version information */
8309 do {
8310
8311 vstatus = sme_GetWcnssWlanCompiledVersion(pHddCtx->hHal,
8312 &versionCompiled);
8313 if (!VOS_IS_STATUS_SUCCESS(vstatus))
8314 {
8315 hddLog(VOS_TRACE_LEVEL_FATAL,
8316 "%s: unable to retrieve WCNSS WLAN compiled version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008317 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008318 break;
8319 }
8320
8321 vstatus = sme_GetWcnssWlanReportedVersion(pHddCtx->hHal,
8322 &versionReported);
8323 if (!VOS_IS_STATUS_SUCCESS(vstatus))
8324 {
8325 hddLog(VOS_TRACE_LEVEL_FATAL,
8326 "%s: unable to retrieve WCNSS WLAN reported version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008327 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008328 break;
8329 }
8330
8331 if ((versionCompiled.major != versionReported.major) ||
8332 (versionCompiled.minor != versionReported.minor) ||
8333 (versionCompiled.version != versionReported.version) ||
8334 (versionCompiled.revision != versionReported.revision))
8335 {
8336 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
8337 "Host expected %u.%u.%u.%u\n",
8338 WLAN_MODULE_NAME,
8339 (int)versionReported.major,
8340 (int)versionReported.minor,
8341 (int)versionReported.version,
8342 (int)versionReported.revision,
8343 (int)versionCompiled.major,
8344 (int)versionCompiled.minor,
8345 (int)versionCompiled.version,
8346 (int)versionCompiled.revision);
8347 }
8348 else
8349 {
8350 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
8351 WLAN_MODULE_NAME,
8352 (int)versionReported.major,
8353 (int)versionReported.minor,
8354 (int)versionReported.version,
8355 (int)versionReported.revision);
8356 }
8357
8358 vstatus = sme_GetWcnssSoftwareVersion(pHddCtx->hHal,
8359 versionString,
8360 sizeof(versionString));
8361 if (!VOS_IS_STATUS_SUCCESS(vstatus))
8362 {
8363 hddLog(VOS_TRACE_LEVEL_FATAL,
8364 "%s: unable to retrieve WCNSS software version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008365 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008366 break;
8367 }
8368
8369 pr_info("%s: WCNSS software version %s\n",
8370 WLAN_MODULE_NAME, versionString);
8371
8372 vstatus = sme_GetWcnssHardwareVersion(pHddCtx->hHal,
8373 versionString,
8374 sizeof(versionString));
8375 if (!VOS_IS_STATUS_SUCCESS(vstatus))
8376 {
8377 hddLog(VOS_TRACE_LEVEL_FATAL,
8378 "%s: unable to retrieve WCNSS hardware version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008379 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008380 break;
8381 }
8382
8383 pr_info("%s: WCNSS hardware version %s\n",
8384 WLAN_MODULE_NAME, versionString);
8385
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07008386 /* 1.Check if FW version is greater than 0.1.1.0. Only then send host-FW capability exchange message
8387 2.Host-FW capability exchange message is only present on riva 1.1 so
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008388 send the message only if it the riva is 1.1
8389 minor numbers for different riva branches:
8390 0 -> (1.0)Mainline Build
8391 1 -> (1.1)Mainline Build
8392 2->(1.04) Stability Build
8393 */
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07008394 if (((versionReported.major>0) || (versionReported.minor>1) ||
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008395 ((versionReported.minor>=1) && (versionReported.version>=1)))
8396 && ((versionReported.major == 1) && (versionReported.minor >= 1)))
8397 fwFeatCapsMsgSupported = 1;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07008398
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008399 if (fwFeatCapsMsgSupported)
Yathish9f22e662012-12-10 14:21:35 -08008400 {
8401#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
8402 if(!pHddCtx->cfg_ini->fEnableActiveModeOffload)
8403 sme_disableFeatureCapablity(WLANACTIVE_OFFLOAD);
8404#endif
Ravi Joshid2ca7c42013-07-23 08:37:49 -07008405 /* Indicate if IBSS heartbeat monitoring needs to be offloaded */
8406 if (!pHddCtx->cfg_ini->enableIbssHeartBeatOffload)
8407 {
8408 sme_disableFeatureCapablity(IBSS_HEARTBEAT_OFFLOAD);
8409 }
8410
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008411 sme_featureCapsExchange(pHddCtx->hHal);
Yathish9f22e662012-12-10 14:21:35 -08008412 }
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008413
8414 } while (0);
8415
8416}
Neelansh Mittaledafed22014-09-04 18:54:39 +05308417void wlan_hdd_send_svc_nlink_msg(int type, void *data, int len)
8418{
8419 struct sk_buff *skb;
8420 struct nlmsghdr *nlh;
8421 tAniMsgHdr *ani_hdr;
8422
8423 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), GFP_KERNEL);
8424
8425 if(skb == NULL) {
8426 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8427 "%s: alloc_skb failed", __func__);
8428 return;
8429 }
8430
8431 nlh = (struct nlmsghdr *)skb->data;
8432 nlh->nlmsg_pid = 0; /* from kernel */
8433 nlh->nlmsg_flags = 0;
8434 nlh->nlmsg_seq = 0;
8435 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
8436
8437 ani_hdr = NLMSG_DATA(nlh);
8438 ani_hdr->type = type;
8439
8440 switch(type) {
8441 case WLAN_SVC_SAP_RESTART_IND:
8442 ani_hdr->length = 0;
8443 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
8444 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr)));
8445 break;
8446 default:
8447 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8448 "Attempt to send unknown nlink message %d", type);
8449 kfree_skb(skb);
8450 return;
8451 }
8452
8453 nl_srv_bcast(skb);
8454
8455 return;
8456}
8457
8458
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008459
8460/**---------------------------------------------------------------------------
8461
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308462 \brief hdd_is_5g_supported() - HDD function to know if hardware supports 5GHz
8463
8464 \param - pHddCtx - Pointer to the hdd context
8465
8466 \return - true if hardware supports 5GHz
8467
8468 --------------------------------------------------------------------------*/
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +05308469boolean hdd_is_5g_supported(hdd_context_t * pHddCtx)
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308470{
8471 /* If wcnss_wlan_iris_xo_mode() returns WCNSS_XO_48MHZ(1);
8472 * then hardware support 5Ghz.
8473 */
8474 if (WCNSS_XO_48MHZ == wcnss_wlan_iris_xo_mode())
8475 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308476 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Hardware supports 5Ghz", __func__);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308477 return true;
8478 }
8479 else
8480 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308481 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Hardware doesn't supports 5Ghz",
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308482 __func__);
8483 return false;
8484 }
8485}
8486
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308487/**---------------------------------------------------------------------------
8488
8489 \brief hdd_generate_iface_mac_addr_auto() - HDD Mac Interface Auto
8490 generate function
8491
8492 This is generate the random mac address for WLAN interface
8493
8494 \param - pHddCtx - Pointer to HDD context
8495 idx - Start interface index to get auto
8496 generated mac addr.
8497 mac_addr - Mac address
8498
8499 \return - 0 for success, < 0 for failure
8500
8501 --------------------------------------------------------------------------*/
8502
8503static int hdd_generate_iface_mac_addr_auto(hdd_context_t *pHddCtx,
8504 int idx, v_MACADDR_t mac_addr)
8505{
8506 int i;
8507 unsigned int serialno;
8508 serialno = wcnss_get_serial_number();
8509
8510 if (0 != serialno)
8511 {
8512 /* MAC address has 3 bytes of OUI so we have a maximum of 3
8513 bytes of the serial number that can be used to generate
8514 the other 3 bytes of the MAC address. Mask off all but
8515 the lower 3 bytes (this will also make sure we don't
8516 overflow in the next step) */
8517 serialno &= 0x00FFFFFF;
8518
8519 /* we need a unique address for each session */
8520 serialno *= VOS_MAX_CONCURRENCY_PERSONA;
8521
8522 /* autogen other Mac addresses */
8523 for (i = idx; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
8524 {
8525 /* start with the entire default address */
8526 pHddCtx->cfg_ini->intfMacAddr[i] = mac_addr;
8527 /* then replace the lower 3 bytes */
8528 pHddCtx->cfg_ini->intfMacAddr[i].bytes[3] = (serialno >> 16) & 0xFF;
8529 pHddCtx->cfg_ini->intfMacAddr[i].bytes[4] = (serialno >> 8) & 0xFF;
8530 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] = serialno & 0xFF;
8531
8532 serialno++;
8533 hddLog(VOS_TRACE_LEVEL_ERROR,
8534 "%s: Derived Mac Addr: "
8535 MAC_ADDRESS_STR, __func__,
8536 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[i].bytes));
8537 }
8538
8539 }
8540 else
8541 {
8542 hddLog(LOGE, FL("Failed to Get Serial NO"));
8543 return -1;
8544 }
8545 return 0;
8546}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308547
8548/**---------------------------------------------------------------------------
8549
Mihir Shetefc7ff5b2014-01-27 11:30:05 +05308550 \brief hdd_11d_scan_done - callback to be executed when 11d scan is
8551 completed to flush out the scan results
8552
8553 11d scan is done during driver load and is a passive scan on all
8554 channels supported by the device, 11d scans may find some APs on
8555 frequencies which are forbidden to be used in the regulatory domain
8556 the device is operating in. If these APs are notified to the supplicant
8557 it may try to connect to these APs, thus flush out all the scan results
8558 which are present in SME after 11d scan is done.
8559
8560 \return - eHalStatus
8561
8562 --------------------------------------------------------------------------*/
8563static eHalStatus hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
8564 tANI_U32 scanId, eCsrScanStatus status)
8565{
8566 ENTER();
8567
8568 sme_ScanFlushResult(halHandle, 0);
8569
8570 EXIT();
8571
8572 return eHAL_STATUS_SUCCESS;
8573}
8574
8575/**---------------------------------------------------------------------------
8576
Jeff Johnson295189b2012-06-20 16:38:30 -07008577 \brief hdd_wlan_startup() - HDD init function
8578
8579 This is the driver startup code executed once a WLAN device has been detected
8580
8581 \param - dev - Pointer to the underlying device
8582
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08008583 \return - 0 for success, < 0 for failure
Jeff Johnson295189b2012-06-20 16:38:30 -07008584
8585 --------------------------------------------------------------------------*/
8586
8587int hdd_wlan_startup(struct device *dev )
8588{
8589 VOS_STATUS status;
8590 hdd_adapter_t *pAdapter = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07008591 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008592 hdd_context_t *pHddCtx = NULL;
8593 v_CONTEXT_t pVosContext= NULL;
8594#ifdef WLAN_BTAMP_FEATURE
8595 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
8596 WLANBAP_ConfigType btAmpConfig;
8597 hdd_config_t *pConfig;
8598#endif
8599 int ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07008600 struct wiphy *wiphy;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308601 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -07008602
8603 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07008604 /*
8605 * cfg80211: wiphy allocation
8606 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05308607 wiphy = wlan_hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t)) ;
Jeff Johnson295189b2012-06-20 16:38:30 -07008608
8609 if(wiphy == NULL)
8610 {
8611 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08008612 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07008613 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008614 pHddCtx = wiphy_priv(wiphy);
8615
Jeff Johnson295189b2012-06-20 16:38:30 -07008616 //Initialize the adapter context to zeros.
8617 vos_mem_zero(pHddCtx, sizeof( hdd_context_t ));
8618
Jeff Johnson295189b2012-06-20 16:38:30 -07008619 pHddCtx->wiphy = wiphy;
Jeff Johnson295189b2012-06-20 16:38:30 -07008620 hdd_prevent_suspend();
Mihir Shete18156292014-03-11 15:38:30 +05308621 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_LOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008622
8623 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
8624
8625 /*Get vos context here bcoz vos_open requires it*/
8626 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
8627
Madan Mohan Koyyalamudi0b78e152012-11-28 15:46:51 -08008628 if(pVosContext == NULL)
8629 {
8630 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed vos_get_global_context",__func__);
8631 goto err_free_hdd_context;
8632 }
8633
Jeff Johnson295189b2012-06-20 16:38:30 -07008634 //Save the Global VOSS context in adapter context for future.
8635 pHddCtx->pvosContext = pVosContext;
8636
8637 //Save the adapter context in global context for future.
8638 ((VosContextType*)(pVosContext))->pHDDContext = (v_VOID_t*)pHddCtx;
8639
Jeff Johnson295189b2012-06-20 16:38:30 -07008640 pHddCtx->parent_dev = dev;
8641
8642 init_completion(&pHddCtx->full_pwr_comp_var);
8643 init_completion(&pHddCtx->standby_comp_var);
8644 init_completion(&pHddCtx->req_bmps_comp_var);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07008645 init_completion(&pHddCtx->scan_info.scan_req_completion_event);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08008646 init_completion(&pHddCtx->scan_info.abortscan_event_var);
Kiet Lam46b8e4e2013-11-06 21:49:53 +05308647 init_completion(&pHddCtx->wiphy_channel_update_event);
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05308648 init_completion(&pHddCtx->ssr_comp_var);
Amar Singhala49cbc52013-10-08 18:37:44 -07008649
8650#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhalfddc28c2013-09-05 13:03:40 -07008651 init_completion(&pHddCtx->linux_reg_req);
Amar Singhala49cbc52013-10-08 18:37:44 -07008652#else
8653 init_completion(&pHddCtx->driver_crda_req);
8654#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008655
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308656 spin_lock_init(&pHddCtx->schedScan_lock);
8657
Jeff Johnson295189b2012-06-20 16:38:30 -07008658 hdd_list_init( &pHddCtx->hddAdapters, MAX_NUMBER_OF_ADAPTERS );
8659
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308660#ifdef FEATURE_WLAN_TDLS
8661 /* tdls_lock is initialized before an hdd_open_adapter ( which is
8662 * invoked by other instances also) to protect the concurrent
8663 * access for the Adapters by TDLS module.
8664 */
8665 mutex_init(&pHddCtx->tdls_lock);
8666#endif
Siddharth Bhal76972212014-10-15 16:22:51 +05308667 mutex_init(&pHddCtx->spoofMacAddr.macSpoofingLock);
Agarwal Ashish1f422872014-07-22 00:11:55 +05308668 /* By default Strict Regulatory For FCC should be false */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308669
Agarwal Ashish1f422872014-07-22 00:11:55 +05308670 pHddCtx->nEnableStrictRegulatoryForFCC = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07008671 // Load all config first as TL config is needed during vos_open
8672 pHddCtx->cfg_ini = (hdd_config_t*) kmalloc(sizeof(hdd_config_t), GFP_KERNEL);
8673 if(pHddCtx->cfg_ini == NULL)
8674 {
8675 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed kmalloc hdd_config_t",__func__);
8676 goto err_free_hdd_context;
8677 }
8678
8679 vos_mem_zero(pHddCtx->cfg_ini, sizeof( hdd_config_t ));
8680
8681 // Read and parse the qcom_cfg.ini file
8682 status = hdd_parse_config_ini( pHddCtx );
8683 if ( VOS_STATUS_SUCCESS != status )
8684 {
8685 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: error parsing %s",
8686 __func__, WLAN_INI_FILE);
8687 goto err_config;
8688 }
Arif Hussaind5218912013-12-05 01:10:55 -08008689#ifdef MEMORY_DEBUG
8690 if (pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled)
8691 vos_mem_init();
8692
8693 hddLog(VOS_TRACE_LEVEL_INFO, "%s: gEnableMemoryDebug=%d",
8694 __func__, pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled);
8695#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008696
Gopichand Nakkalab8f0f1a2013-05-23 18:19:48 +05308697 /* INI has been read, initialise the configuredMcastBcastFilter with
8698 * INI value as this will serve as the default value
8699 */
8700 pHddCtx->configuredMcastBcastFilter = pHddCtx->cfg_ini->mcastBcastFilterSetting;
8701 hddLog(VOS_TRACE_LEVEL_INFO, "Setting configuredMcastBcastFilter: %d",
8702 pHddCtx->cfg_ini->mcastBcastFilterSetting);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308703
8704 if (false == hdd_is_5g_supported(pHddCtx))
8705 {
8706 //5Ghz is not supported.
8707 if (1 != pHddCtx->cfg_ini->nBandCapability)
8708 {
8709 hddLog(VOS_TRACE_LEVEL_INFO,
8710 "%s: Setting pHddCtx->cfg_ini->nBandCapability = 1", __func__);
8711 pHddCtx->cfg_ini->nBandCapability = 1;
8712 }
8713 }
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308714
8715 /* If SNR Monitoring is enabled, FW has to parse all beacons
8716 * for calcaluting and storing the average SNR, so set Nth beacon
8717 * filter to 1 to enable FW to parse all the beaocons
8718 */
8719 if (1 == pHddCtx->cfg_ini->fEnableSNRMonitoring)
8720 {
8721 /* The log level is deliberately set to WARN as overriding
8722 * nthBeaconFilter to 1 will increase power cosumption and this
8723 * might just prove helpful to detect the power issue.
8724 */
8725 hddLog(VOS_TRACE_LEVEL_WARN,
8726 "%s: Setting pHddCtx->cfg_ini->nthBeaconFilter = 1", __func__);
8727 pHddCtx->cfg_ini->nthBeaconFilter = 1;
8728 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008729 /*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05308730 * cfg80211: Initialization ...
Jeff Johnson295189b2012-06-20 16:38:30 -07008731 */
Manjunathappa Prakasheec4ddf2014-01-13 18:23:51 -08008732 if (VOS_FTM_MODE != hdd_get_conparam())
Jeff Johnson295189b2012-06-20 16:38:30 -07008733 {
Manjunathappa Prakasheec4ddf2014-01-13 18:23:51 -08008734 if (0 < wlan_hdd_cfg80211_init(dev, wiphy, pHddCtx->cfg_ini))
8735 {
8736 hddLog(VOS_TRACE_LEVEL_FATAL,
8737 "%s: wlan_hdd_cfg80211_init return failure", __func__);
8738 goto err_config;
8739 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008740 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008741
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08008742 // Update VOS trace levels based upon the cfg.ini
8743 hdd_vos_trace_enable(VOS_MODULE_ID_BAP,
8744 pHddCtx->cfg_ini->vosTraceEnableBAP);
8745 hdd_vos_trace_enable(VOS_MODULE_ID_TL,
8746 pHddCtx->cfg_ini->vosTraceEnableTL);
8747 hdd_vos_trace_enable(VOS_MODULE_ID_WDI,
8748 pHddCtx->cfg_ini->vosTraceEnableWDI);
8749 hdd_vos_trace_enable(VOS_MODULE_ID_HDD,
8750 pHddCtx->cfg_ini->vosTraceEnableHDD);
8751 hdd_vos_trace_enable(VOS_MODULE_ID_SME,
8752 pHddCtx->cfg_ini->vosTraceEnableSME);
8753 hdd_vos_trace_enable(VOS_MODULE_ID_PE,
8754 pHddCtx->cfg_ini->vosTraceEnablePE);
Katya Nigam70d68332013-09-16 16:49:45 +05308755 hdd_vos_trace_enable(VOS_MODULE_ID_PMC,
8756 pHddCtx->cfg_ini->vosTraceEnablePMC);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08008757 hdd_vos_trace_enable(VOS_MODULE_ID_WDA,
8758 pHddCtx->cfg_ini->vosTraceEnableWDA);
8759 hdd_vos_trace_enable(VOS_MODULE_ID_SYS,
8760 pHddCtx->cfg_ini->vosTraceEnableSYS);
8761 hdd_vos_trace_enable(VOS_MODULE_ID_VOSS,
8762 pHddCtx->cfg_ini->vosTraceEnableVOSS);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08008763 hdd_vos_trace_enable(VOS_MODULE_ID_SAP,
8764 pHddCtx->cfg_ini->vosTraceEnableSAP);
8765 hdd_vos_trace_enable(VOS_MODULE_ID_HDD_SOFTAP,
8766 pHddCtx->cfg_ini->vosTraceEnableHDDSAP);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08008767
Jeff Johnson295189b2012-06-20 16:38:30 -07008768 // Update WDI trace levels based upon the cfg.ini
8769 hdd_wdi_trace_enable(eWLAN_MODULE_DAL,
8770 pHddCtx->cfg_ini->wdiTraceEnableDAL);
8771 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_CTRL,
8772 pHddCtx->cfg_ini->wdiTraceEnableCTL);
8773 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_DATA,
8774 pHddCtx->cfg_ini->wdiTraceEnableDAT);
8775 hdd_wdi_trace_enable(eWLAN_MODULE_PAL,
8776 pHddCtx->cfg_ini->wdiTraceEnablePAL);
Jeff Johnson295189b2012-06-20 16:38:30 -07008777
Jeff Johnson88ba7742013-02-27 14:36:02 -08008778 if (VOS_FTM_MODE == hdd_get_conparam())
8779 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008780 if ( VOS_STATUS_SUCCESS != wlan_hdd_ftm_open(pHddCtx) )
8781 {
8782 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_ftm_open Failed",__func__);
8783 goto err_free_hdd_context;
8784 }
8785 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: FTM driver loaded success fully",__func__);
c_hpothu2de0ef62014-04-15 16:16:15 +05308786
8787 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -07008788 return VOS_STATUS_SUCCESS;
Jeff Johnson88ba7742013-02-27 14:36:02 -08008789 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008790
Jeff Johnson88ba7742013-02-27 14:36:02 -08008791 //Open watchdog module
Jeff Johnson295189b2012-06-20 16:38:30 -07008792 if(pHddCtx->cfg_ini->fIsLogpEnabled)
8793 {
8794 status = vos_watchdog_open(pVosContext,
8795 &((VosContextType*)pVosContext)->vosWatchdog, sizeof(VosWatchdogContext));
8796
8797 if(!VOS_IS_STATUS_SUCCESS( status ))
8798 {
8799 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_watchdog_open failed",__func__);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05308800 goto err_wdclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07008801 }
8802 }
8803
8804 pHddCtx->isLogpInProgress = FALSE;
8805 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
8806
Amar Singhala49cbc52013-10-08 18:37:44 -07008807#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -07008808 /* initialize the NV module. This is required so that
8809 we can initialize the channel information in wiphy
8810 from the NV.bin data. The channel information in
8811 wiphy needs to be initialized before wiphy registration */
8812
8813 status = vos_nv_open();
8814 if (!VOS_IS_STATUS_SUCCESS(status))
8815 {
8816 /* NV module cannot be initialized */
8817 hddLog( VOS_TRACE_LEVEL_FATAL,
8818 "%s: vos_nv_open failed", __func__);
Vinay Krishna Eranna2025d892014-09-18 16:51:42 +05308819 goto err_wdclose;
Amar Singhal0a402232013-10-11 20:57:16 -07008820 }
8821
8822 status = vos_init_wiphy_from_nv_bin();
8823 if (!VOS_IS_STATUS_SUCCESS(status))
8824 {
8825 /* NV module cannot be initialized */
8826 hddLog( VOS_TRACE_LEVEL_FATAL,
8827 "%s: vos_init_wiphy failed", __func__);
8828 goto err_vos_nv_close;
8829 }
8830
Amar Singhala49cbc52013-10-08 18:37:44 -07008831#endif
8832
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +05308833 status = vos_open( &pVosContext, pHddCtx->parent_dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07008834 if ( !VOS_IS_STATUS_SUCCESS( status ))
8835 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008836 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
Mihir Shetee1093ba2014-01-21 20:13:32 +05308837 goto err_vos_nv_close;
Jeff Johnson295189b2012-06-20 16:38:30 -07008838 }
8839
Jeff Johnson295189b2012-06-20 16:38:30 -07008840 pHddCtx->hHal = (tHalHandle)vos_get_context( VOS_MODULE_ID_SME, pVosContext );
8841
8842 if ( NULL == pHddCtx->hHal )
8843 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008844 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: HAL context is null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008845 goto err_vosclose;
8846 }
8847
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008848 status = vos_preStart( pHddCtx->pvosContext );
8849 if ( !VOS_IS_STATUS_SUCCESS( status ) )
8850 {
8851 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_preStart failed", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308852 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008853 }
Jeff Johnsone7245742012-09-05 17:12:55 -07008854
Arif Hussaineaf68602013-12-30 23:10:44 -08008855 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan)
8856 {
8857 pHddCtx->cfg_ini->enableDFSChnlScan = enable_dfs_chan_scan;
8858 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_dfs_chan_scan set to %d",
8859 __func__, enable_dfs_chan_scan);
8860 }
8861 if (0 == enable_11d || 1 == enable_11d)
8862 {
8863 pHddCtx->cfg_ini->Is11dSupportEnabled = enable_11d;
8864 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_11d set to %d",
8865 __func__, enable_11d);
8866 }
8867
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008868 /* Note that the vos_preStart() sequence triggers the cfg download.
8869 The cfg download must occur before we update the SME config
8870 since the SME config operation must access the cfg database */
Jeff Johnson295189b2012-06-20 16:38:30 -07008871 status = hdd_set_sme_config( pHddCtx );
8872
8873 if ( VOS_STATUS_SUCCESS != status )
8874 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008875 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed hdd_set_sme_config", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308876 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008877 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008878
Jeff Johnson295189b2012-06-20 16:38:30 -07008879 /* In the integrated architecture we update the configuration from
8880 the INI file and from NV before vOSS has been started so that
8881 the final contents are available to send down to the cCPU */
8882
8883 // Apply the cfg.ini to cfg.dat
8884 if (FALSE == hdd_update_config_dat(pHddCtx))
8885 {
8886 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308887 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07008888 }
8889
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308890 // Get mac addr from platform driver
8891 ret = wcnss_get_wlan_mac_address((char*)&mac_addr.bytes);
8892
8893 if ((0 == ret) && (!vos_is_macaddr_zero(&mac_addr)))
Jeff Johnson295189b2012-06-20 16:38:30 -07008894 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308895 /* Store the mac addr for first interface */
8896 pHddCtx->cfg_ini->intfMacAddr[0] = mac_addr;
8897
8898 hddLog(VOS_TRACE_LEVEL_ERROR,
8899 "%s: WLAN Mac Addr: "
8900 MAC_ADDRESS_STR, __func__,
8901 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
8902
8903 /* Here, passing Arg2 as 1 because we do not want to change the
8904 last 3 bytes (means non OUI bytes) of first interface mac
8905 addr.
8906 */
8907 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 1, mac_addr))
8908 {
8909 hddLog(VOS_TRACE_LEVEL_ERROR,
8910 "%s: Failed to generate wlan interface mac addr "
8911 "using MAC from ini file ", __func__);
8912 }
8913 }
8914 else if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
8915 {
8916 // Apply the NV to cfg.dat
8917 /* Prima Update MAC address only at here */
Jeff Johnson295189b2012-06-20 16:38:30 -07008918#ifdef WLAN_AUTOGEN_MACADDR_FEATURE
8919 /* There was not a valid set of MAC Addresses in NV. See if the
8920 default addresses were modified by the cfg.ini settings. If so,
8921 we'll use them, but if not, we'll autogenerate a set of MAC
8922 addresses based upon the device serial number */
8923
8924 static const v_MACADDR_t default_address =
8925 {{0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}};
Jeff Johnson295189b2012-06-20 16:38:30 -07008926
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308927 if (0 == memcmp(&default_address, &pHddCtx->cfg_ini->intfMacAddr[0],
8928 sizeof(default_address)))
Jeff Johnson295189b2012-06-20 16:38:30 -07008929 {
8930 /* cfg.ini has the default address, invoke autogen logic */
8931
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308932 /* Here, passing Arg2 as 0 because we want to change the
8933 last 3 bytes (means non OUI bytes) of all the interfaces
8934 mac addr.
8935 */
8936 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 0,
8937 default_address))
Jeff Johnson295189b2012-06-20 16:38:30 -07008938 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308939 hddLog(VOS_TRACE_LEVEL_ERROR,
8940 "%s: Failed to generate wlan interface mac addr "
8941 "using MAC from ini file " MAC_ADDRESS_STR, __func__,
8942 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
Jeff Johnson295189b2012-06-20 16:38:30 -07008943 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008944 }
8945 else
8946#endif //WLAN_AUTOGEN_MACADDR_FEATURE
8947 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008948 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07008949 "%s: Invalid MAC address in NV, using MAC from ini file "
8950 MAC_ADDRESS_STR, __func__,
8951 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
8952 }
8953 }
8954 {
8955 eHalStatus halStatus;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308956
8957 /* Set the MAC Address Currently this is used by HAL to
8958 * add self sta. Remove this once self sta is added as
8959 * part of session open.
8960 */
Jeff Johnson295189b2012-06-20 16:38:30 -07008961 halStatus = cfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
8962 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
8963 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]) );
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308964
Jeff Johnson295189b2012-06-20 16:38:30 -07008965 if (!HAL_STATUS_SUCCESS( halStatus ))
8966 {
8967 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
8968 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308969 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07008970 }
8971 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008972
8973 /*Start VOSS which starts up the SME/MAC/HAL modules and everything else
8974 Note: Firmware image will be read and downloaded inside vos_start API */
8975 status = vos_start( pHddCtx->pvosContext );
8976 if ( !VOS_IS_STATUS_SUCCESS( status ) )
8977 {
8978 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308979 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07008980 }
8981
Leo Chang6cec3e22014-01-21 15:33:49 -08008982#ifdef FEATURE_WLAN_CH_AVOID
8983 /* Plug in avoid channel notification callback
8984 * This should happen before ADD_SELF_STA
8985 * FW will send first IND with ADD_SELF_STA REQ from host */
Pradeep Reddy POTTETI5c2e16d2014-06-27 16:47:38 +05308986
8987 /* check the Channel Avoidance is enabled */
8988 if (TRUE == pHddCtx->cfg_ini->fenableCHAvoidance)
8989 {
8990 sme_AddChAvoidCallback(pHddCtx->hHal,
8991 hdd_hostapd_ch_avoid_cb);
8992 }
Leo Chang6cec3e22014-01-21 15:33:49 -08008993#endif /* FEATURE_WLAN_CH_AVOID */
8994
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008995 /* Exchange capability info between Host and FW and also get versioning info from FW */
8996 hdd_exchange_version_and_caps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07008997
Agarwal Ashishad9281b2014-06-10 14:57:30 +05308998#ifdef CONFIG_ENABLE_LINUX_REG
8999 status = wlan_hdd_init_channels(pHddCtx);
9000 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9001 {
9002 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels failed",
9003 __func__);
9004 goto err_vosstop;
9005 }
9006#endif
9007
Jeff Johnson295189b2012-06-20 16:38:30 -07009008 status = hdd_post_voss_start_config( pHddCtx );
9009 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9010 {
9011 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_post_voss_start_config failed",
9012 __func__);
9013 goto err_vosstop;
9014 }
Amar Singhala49cbc52013-10-08 18:37:44 -07009015
9016#ifndef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05309017 wlan_hdd_cfg80211_update_reg_info( wiphy );
9018
9019 /* registration of wiphy dev with cfg80211 */
9020 if (0 > wlan_hdd_cfg80211_register(wiphy))
9021 {
9022 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
9023 goto err_vosstop;
9024 }
Amar Singhala49cbc52013-10-08 18:37:44 -07009025#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009026
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05309027#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05309028 /* registration of wiphy dev with cfg80211 */
9029 if (0 > wlan_hdd_cfg80211_register(wiphy))
9030 {
9031 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
9032 goto err_vosstop;
9033 }
9034
Agarwal Ashish6db9d532014-09-30 18:19:10 +05309035 status = wlan_hdd_init_channels_for_cc(pHddCtx, INIT);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05309036 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9037 {
9038 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels_for_cc failed",
9039 __func__);
9040 goto err_unregister_wiphy;
9041 }
9042#endif
9043
Jeff Johnson295189b2012-06-20 16:38:30 -07009044 if (VOS_STA_SAP_MODE == hdd_get_conparam())
9045 {
9046 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP, "softap.%d",
9047 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
9048 }
9049 else
9050 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009051 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_INFRA_STATION, "wlan%d",
9052 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
9053 if (pAdapter != NULL)
9054 {
Katya Nigama7d81d72014-11-12 12:44:34 +05309055 if (pHddCtx->cfg_ini->isP2pDeviceAddrAdministrated && !(pHddCtx->cfg_ini->intfMacAddr[0].bytes[0] & 0x02))
Jeff Johnson295189b2012-06-20 16:38:30 -07009056 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05309057 vos_mem_copy( pHddCtx->p2pDeviceAddress.bytes,
9058 pHddCtx->cfg_ini->intfMacAddr[0].bytes,
9059 sizeof(tSirMacAddr));
Madan Mohan Koyyalamudiedfc1b72012-10-18 20:25:55 -07009060
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05309061 /* Generate the P2P Device Address. This consists of the device's
9062 * primary MAC address with the locally administered bit set.
9063 */
9064 pHddCtx->p2pDeviceAddress.bytes[0] |= 0x02;
Jeff Johnsone7245742012-09-05 17:12:55 -07009065 }
9066 else
9067 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05309068 tANI_U8* p2p_dev_addr = wlan_hdd_get_intf_addr(pHddCtx);
9069 if (p2p_dev_addr != NULL)
9070 {
9071 vos_mem_copy(&pHddCtx->p2pDeviceAddress.bytes[0],
9072 p2p_dev_addr, VOS_MAC_ADDR_SIZE);
9073 }
9074 else
9075 {
9076 hddLog(VOS_TRACE_LEVEL_FATAL,
9077 "%s: Failed to allocate mac_address for p2p_device",
9078 __func__);
9079 goto err_close_adapter;
9080 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009081 }
Jeff Johnsone7245742012-09-05 17:12:55 -07009082
9083 pP2pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_P2P_DEVICE, "p2p%d",
9084 &pHddCtx->p2pDeviceAddress.bytes[0], FALSE );
9085 if ( NULL == pP2pAdapter )
9086 {
9087 hddLog(VOS_TRACE_LEVEL_FATAL,
9088 "%s: Failed to do hdd_open_adapter for P2P Device Interface",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07009089 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07009090 goto err_close_adapter;
9091 }
Jeff Johnsone7245742012-09-05 17:12:55 -07009092 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009093 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009094
9095 if( pAdapter == NULL )
9096 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08009097 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
9098 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07009099 }
Jeff Johnsone7245742012-09-05 17:12:55 -07009100
Arif Hussain66559122013-11-21 10:11:40 -08009101 if (country_code)
9102 {
9103 eHalStatus ret;
Arif Hussaincb607082013-12-20 11:57:42 -08009104 INIT_COMPLETION(pAdapter->change_country_code);
Arif Hussain66559122013-11-21 10:11:40 -08009105 hdd_checkandupdate_dfssetting(pAdapter, country_code);
9106#ifndef CONFIG_ENABLE_LINUX_REG
9107 hdd_checkandupdate_phymode(pAdapter, country_code);
9108#endif
Arif Hussaineaf68602013-12-30 23:10:44 -08009109 ret = sme_ChangeCountryCode(pHddCtx->hHal,
9110 (void *)(tSmeChangeCountryCallback)
9111 wlan_hdd_change_country_code_callback,
Arif Hussain66559122013-11-21 10:11:40 -08009112 country_code,
9113 pAdapter, pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +05309114 eSIR_TRUE, eSIR_TRUE);
Arif Hussain66559122013-11-21 10:11:40 -08009115 if (eHAL_STATUS_SUCCESS == ret)
9116 {
Arif Hussaincb607082013-12-20 11:57:42 -08009117 ret = wait_for_completion_interruptible_timeout(
9118 &pAdapter->change_country_code,
9119 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
9120
9121 if (0 >= ret)
9122 {
9123 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9124 "%s: SME while setting country code timed out", __func__);
9125 }
Arif Hussain66559122013-11-21 10:11:40 -08009126 }
9127 else
9128 {
Arif Hussaincb607082013-12-20 11:57:42 -08009129 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9130 "%s: SME Change Country code from module param fail ret=%d",
9131 __func__, ret);
Arif Hussain66559122013-11-21 10:11:40 -08009132 }
9133 }
9134
Jeff Johnson295189b2012-06-20 16:38:30 -07009135#ifdef WLAN_BTAMP_FEATURE
9136 vStatus = WLANBAP_Open(pVosContext);
9137 if(!VOS_IS_STATUS_SUCCESS(vStatus))
9138 {
9139 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9140 "%s: Failed to open BAP",__func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07009141 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07009142 }
9143
9144 vStatus = BSL_Init(pVosContext);
9145 if(!VOS_IS_STATUS_SUCCESS(vStatus))
9146 {
9147 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9148 "%s: Failed to Init BSL",__func__);
9149 goto err_bap_close;
9150 }
9151 vStatus = WLANBAP_Start(pVosContext);
9152 if (!VOS_IS_STATUS_SUCCESS(vStatus))
9153 {
9154 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9155 "%s: Failed to start TL",__func__);
9156 goto err_bap_close;
9157 }
9158
9159 pConfig = pHddCtx->cfg_ini;
9160 btAmpConfig.ucPreferredChannel = pConfig->preferredChannel;
9161 status = WLANBAP_SetConfig(&btAmpConfig);
9162
9163#endif //WLAN_BTAMP_FEATURE
Jeff Johnsone7245742012-09-05 17:12:55 -07009164
Mihir Shete9c238772014-10-15 14:35:16 +05309165 /*
9166 * UapsdMask is 0xf if U-APSD is enbaled for all AC's...
9167 * The value of CFG_QOS_WMM_UAPSD_MASK_DEFAULT is 0xaa(Magic Value)
9168 * which is greater than 0xf. So the below check is safe to make
9169 * sure that there is no entry for UapsdMask in the ini
9170 */
9171 if (CFG_QOS_WMM_UAPSD_MASK_DEFAULT == pHddCtx->cfg_ini->UapsdMask)
9172 {
9173 if(IS_DYNAMIC_WMM_PS_ENABLED)
9174 {
9175 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Enable UAPSD for VI & VO",
9176 __func__);
9177 pHddCtx->cfg_ini->UapsdMask =
9178 CFG_QOS_WMM_UAPSD_MASK_DYMANIC_WMM_PS_DEFAULT;
9179 }
9180 else
9181 {
9182 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Do not enable UAPSD",
9183 __func__);
9184 pHddCtx->cfg_ini->UapsdMask =
9185 CFG_QOS_WMM_UAPSD_MASK_LEGACY_WMM_PS_DEFAULT;
9186 }
9187 }
9188
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07009189#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
9190 if(!(IS_ROAM_SCAN_OFFLOAD_FEATURE_ENABLE))
9191 {
9192 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: ROAM_SCAN_OFFLOAD Feature not supported",__func__);
9193 pHddCtx->cfg_ini->isRoamOffloadScanEnabled = 0;
9194 sme_UpdateRoamScanOffloadEnabled((tHalHandle)(pHddCtx->hHal),
9195 pHddCtx->cfg_ini->isRoamOffloadScanEnabled);
9196 }
9197#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009198
Agarwal Ashish4b87f922014-06-18 03:03:21 +05309199 wlan_hdd_tdls_init(pHddCtx);
9200
Mihir Shetefc7ff5b2014-01-27 11:30:05 +05309201 sme_Register11dScanDoneCallback(pHddCtx->hHal, hdd_11d_scan_done);
9202
Jeff Johnson295189b2012-06-20 16:38:30 -07009203 /* Register with platform driver as client for Suspend/Resume */
9204 status = hddRegisterPmOps(pHddCtx);
9205 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9206 {
9207 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddRegisterPmOps failed",__func__);
9208#ifdef WLAN_BTAMP_FEATURE
9209 goto err_bap_stop;
9210#else
Jeff Johnsone7245742012-09-05 17:12:55 -07009211 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07009212#endif //WLAN_BTAMP_FEATURE
9213 }
9214
Yue Ma0d4891e2013-08-06 17:01:45 -07009215 /* Open debugfs interface */
9216 if (VOS_STATUS_SUCCESS != hdd_debugfs_init(pAdapter))
9217 {
9218 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9219 "%s: hdd_debugfs_init failed!", __func__);
Yue Ma0d4891e2013-08-06 17:01:45 -07009220 }
9221
Jeff Johnson295189b2012-06-20 16:38:30 -07009222 /* Register TM level change handler function to the platform */
9223 status = hddDevTmRegisterNotifyCallback(pHddCtx);
9224 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9225 {
9226 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmRegisterNotifyCallback failed",__func__);
9227 goto err_unregister_pmops;
9228 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009229
9230 /* register for riva power on lock to platform driver */
9231 if (req_riva_power_on_lock("wlan"))
9232 {
9233 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: req riva power on lock failed",
9234 __func__);
9235 goto err_unregister_pmops;
9236 }
9237
Jeff Johnson295189b2012-06-20 16:38:30 -07009238 // register net device notifier for device change notification
9239 ret = register_netdevice_notifier(&hdd_netdev_notifier);
9240
9241 if(ret < 0)
9242 {
9243 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: register_netdevice_notifier failed",__func__);
9244 goto err_free_power_on_lock;
9245 }
9246
9247 //Initialize the nlink service
9248 if(nl_srv_init() != 0)
9249 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05309250 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009251 goto err_reg_netdev;
9252 }
9253
Leo Chang4ce1cc52013-10-21 18:27:15 -07009254#ifdef WLAN_KD_READY_NOTIFIER
9255 pHddCtx->kd_nl_init = 1;
9256#endif /* WLAN_KD_READY_NOTIFIER */
9257
Jeff Johnson295189b2012-06-20 16:38:30 -07009258 //Initialize the BTC service
9259 if(btc_activate_service(pHddCtx) != 0)
9260 {
9261 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: btc_activate_service failed",__func__);
9262 goto err_nl_srv;
9263 }
9264
9265#ifdef PTT_SOCK_SVC_ENABLE
9266 //Initialize the PTT service
9267 if(ptt_sock_activate_svc(pHddCtx) != 0)
9268 {
9269 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: ptt_sock_activate_svc failed",__func__);
9270 goto err_nl_srv;
9271 }
9272#endif
9273
Vinay Krishna Erannad938c422014-03-10 17:14:21 +05309274#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9275 if(pHddCtx->cfg_ini && pHddCtx->cfg_ini->wlanLoggingEnable)
9276 {
Deepthi Gowri78083a32014-11-04 12:55:51 +05309277 if(wlan_logging_sock_activate_svc(
9278 pHddCtx->cfg_ini->wlanLoggingFEToConsole,
9279 pHddCtx->cfg_ini->wlanLoggingNumBuf))
9280 {
9281 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wlan_logging_sock_activate_svc"
9282 " failed", __func__);
9283 goto err_nl_srv;
9284 }
9285 //TODO: To Remove enableDhcpDebug and use gEnableDebugLog for
9286 //EAPOL and DHCP
9287 pHddCtx->cfg_ini->enableDhcpDebug = CFG_DEBUG_DHCP_ENABLE;
9288 pHddCtx->cfg_ini->gEnableDebugLog = VOS_PKT_PROTO_TYPE_EAPOL;
Vinay Krishna Erannad938c422014-03-10 17:14:21 +05309289 }
9290#endif
9291
Jeff Johnson295189b2012-06-20 16:38:30 -07009292 hdd_register_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07009293 if (VOS_STA_SAP_MODE != hdd_get_conparam())
Jeff Johnson295189b2012-06-20 16:38:30 -07009294 {
Madan Mohan Koyyalamudic537df22012-10-22 15:07:08 -07009295 /* Action frame registered in one adapter which will
9296 * applicable to all interfaces
9297 */
Agarwal Ashish8fa0e9a2014-05-23 00:40:12 +05309298 wlan_hdd_cfg80211_register_frames(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009299 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009300
9301 mutex_init(&pHddCtx->sap_lock);
Mahesh A Saptasagar60627942014-10-13 13:55:14 +05309302 mutex_init(&pHddCtx->roc_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009303
Jeff Johnson295189b2012-06-20 16:38:30 -07009304
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009305#ifdef WLAN_OPEN_SOURCE
Jeff Johnsone7245742012-09-05 17:12:55 -07009306#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
9307 /* Initialize the wake lcok */
9308 wake_lock_init(&pHddCtx->rx_wake_lock,
9309 WAKE_LOCK_SUSPEND,
9310 "qcom_rx_wakelock");
9311#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -08009312 /* Initialize the wake lcok */
9313 wake_lock_init(&pHddCtx->sap_wake_lock,
9314 WAKE_LOCK_SUSPEND,
9315 "qcom_sap_wakelock");
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009316#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07009317
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07009318 vos_event_init(&pHddCtx->scan_info.scan_finished_event);
9319 pHddCtx->scan_info.scan_pending_option = WEXT_SCAN_PENDING_GIVEUP;
Jeff Johnson295189b2012-06-20 16:38:30 -07009320
Katya Nigam5c306ea2014-06-19 15:39:54 +05309321 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07009322 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
9323 hdd_allow_suspend();
Katya Nigam5c306ea2014-06-19 15:39:54 +05309324
9325#ifdef FEATURE_WLAN_SCAN_PNO
9326 /*SME must send channel update configuration to RIVA*/
9327 sme_UpdateChannelConfig(pHddCtx->hHal);
9328#endif
Abhishek Singhf644b272014-08-21 02:59:39 +05309329 /* Send the update default channel list to the FW*/
9330 sme_UpdateChannelList(pHddCtx->hHal);
Abhishek Singha306a442013-11-07 18:39:01 +05309331#ifndef CONFIG_ENABLE_LINUX_REG
9332 /*updating wiphy so that regulatory user hints can be processed*/
9333 if (wiphy)
9334 {
9335 regulatory_hint(wiphy, "00");
9336 }
9337#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07009338 // Initialize the restart logic
9339 wlan_hdd_restart_init(pHddCtx);
Chilam NG571c65a2013-01-19 12:27:36 +05309340
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07009341 //Register the traffic monitor timer now
9342 if ( pHddCtx->cfg_ini->dynSplitscan)
9343 {
9344 vos_timer_init(&pHddCtx->tx_rx_trafficTmr,
9345 VOS_TIMER_TYPE_SW,
9346 hdd_tx_rx_pkt_cnt_stat_timer_handler,
9347 (void *)pHddCtx);
9348 }
Dino Mycle6fb96c12014-06-10 11:52:40 +05309349#ifdef WLAN_FEATURE_EXTSCAN
9350 sme_EXTScanRegisterCallback(pHddCtx->hHal,
9351 wlan_hdd_cfg80211_extscan_callback,
9352 pHddCtx);
9353#endif /* WLAN_FEATURE_EXTSCAN */
Jeff Johnson295189b2012-06-20 16:38:30 -07009354 goto success;
9355
9356err_nl_srv:
Leo Chang59cdc7e2013-07-10 10:08:21 -07009357#ifdef WLAN_KD_READY_NOTIFIER
9358 nl_srv_exit(pHddCtx->ptt_pid);
9359#else
Jeff Johnson295189b2012-06-20 16:38:30 -07009360 nl_srv_exit();
Leo Chang59cdc7e2013-07-10 10:08:21 -07009361#endif /* WLAN_KD_READY_NOTIFIER */
Jeff Johnson295189b2012-06-20 16:38:30 -07009362err_reg_netdev:
9363 unregister_netdevice_notifier(&hdd_netdev_notifier);
9364
9365err_free_power_on_lock:
9366 free_riva_power_on_lock("wlan");
9367
9368err_unregister_pmops:
9369 hddDevTmUnregisterNotifyCallback(pHddCtx);
9370 hddDeregisterPmOps(pHddCtx);
9371
Yue Ma0d4891e2013-08-06 17:01:45 -07009372 hdd_debugfs_exit(pHddCtx);
9373
Jeff Johnson295189b2012-06-20 16:38:30 -07009374#ifdef WLAN_BTAMP_FEATURE
9375err_bap_stop:
9376 WLANBAP_Stop(pVosContext);
9377#endif
9378
9379#ifdef WLAN_BTAMP_FEATURE
9380err_bap_close:
9381 WLANBAP_Close(pVosContext);
9382#endif
9383
Jeff Johnson295189b2012-06-20 16:38:30 -07009384err_close_adapter:
9385 hdd_close_all_adapters( pHddCtx );
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +05309386#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05309387err_unregister_wiphy:
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +05309388#endif
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05309389 wiphy_unregister(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -07009390err_vosstop:
9391 vos_stop(pVosContext);
9392
Amar Singhala49cbc52013-10-08 18:37:44 -07009393err_vosclose:
Jeff Johnson295189b2012-06-20 16:38:30 -07009394 status = vos_sched_close( pVosContext );
9395 if (!VOS_IS_STATUS_SUCCESS(status)) {
9396 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
9397 "%s: Failed to close VOSS Scheduler", __func__);
9398 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
9399 }
Amar Singhala49cbc52013-10-08 18:37:44 -07009400 vos_close(pVosContext );
9401
Amar Singhal0a402232013-10-11 20:57:16 -07009402err_vos_nv_close:
9403
c_hpothue6a36282014-03-19 12:27:38 +05309404#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -07009405 vos_nv_close();
9406
c_hpothu70f8d812014-03-22 22:59:23 +05309407#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009408
9409err_wdclose:
9410 if(pHddCtx->cfg_ini->fIsLogpEnabled)
9411 vos_watchdog_close(pVosContext);
9412
Jeff Johnson295189b2012-06-20 16:38:30 -07009413err_config:
9414 kfree(pHddCtx->cfg_ini);
9415 pHddCtx->cfg_ini= NULL;
9416
9417err_free_hdd_context:
9418 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07009419 wiphy_free(wiphy) ;
9420 //kfree(wdev) ;
Jeff Johnson295189b2012-06-20 16:38:30 -07009421 VOS_BUG(1);
9422
Madan Mohan Koyyalamudid57ae632012-11-06 18:42:48 -08009423 if (hdd_is_ssr_required())
9424 {
9425 /* WDI timeout had happened during load, so SSR is needed here */
9426 subsystem_restart("wcnss");
9427 msleep(5000);
9428 }
9429 hdd_set_ssr_required (VOS_FALSE);
9430
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08009431 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07009432
9433success:
9434 EXIT();
9435 return 0;
9436}
9437
9438/**---------------------------------------------------------------------------
9439
Jeff Johnson32d95a32012-09-10 13:15:23 -07009440 \brief hdd_driver_init() - Core Driver Init Function
Jeff Johnson295189b2012-06-20 16:38:30 -07009441
Jeff Johnson32d95a32012-09-10 13:15:23 -07009442 This is the driver entry point - called in different timeline depending
9443 on whether the driver is statically or dynamically linked
Jeff Johnson295189b2012-06-20 16:38:30 -07009444
9445 \param - None
9446
9447 \return - 0 for success, non zero for failure
9448
9449 --------------------------------------------------------------------------*/
Jeff Johnson32d95a32012-09-10 13:15:23 -07009450static int hdd_driver_init( void)
Jeff Johnson295189b2012-06-20 16:38:30 -07009451{
9452 VOS_STATUS status;
9453 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009454 struct device *dev = NULL;
9455 int ret_status = 0;
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -07009456#ifdef HAVE_WCNSS_CAL_DOWNLOAD
9457 int max_retries = 0;
9458#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009459
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309460#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9461 wlan_logging_sock_init_svc();
9462#endif
9463
Jeff Johnson295189b2012-06-20 16:38:30 -07009464 ENTER();
9465
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009466#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07009467 wake_lock_init(&wlan_wake_lock, WAKE_LOCK_SUSPEND, "wlan");
Jeff Johnsone7245742012-09-05 17:12:55 -07009468#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009469
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05309470 hddTraceInit();
Jeff Johnson295189b2012-06-20 16:38:30 -07009471 pr_info("%s: loading driver v%s\n", WLAN_MODULE_NAME,
9472 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
9473
Jeff Johnson295189b2012-06-20 16:38:30 -07009474#ifdef ANI_BUS_TYPE_PCI
9475
9476 dev = wcnss_wlan_get_device();
9477
9478#endif // ANI_BUS_TYPE_PCI
9479
9480#ifdef ANI_BUS_TYPE_PLATFORM
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -07009481
9482#ifdef HAVE_WCNSS_CAL_DOWNLOAD
9483 /* wait until WCNSS driver downloads NV */
9484 while (!wcnss_device_ready() && 5 >= ++max_retries) {
9485 msleep(1000);
9486 }
9487 if (max_retries >= 5) {
9488 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WCNSS driver not ready", __func__);
madan mohan koyyalamudi8c96ce12013-07-10 19:14:39 +05309489#ifdef WLAN_OPEN_SOURCE
9490 wake_lock_destroy(&wlan_wake_lock);
9491#endif
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309492
9493#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9494 wlan_logging_sock_deinit_svc();
9495#endif
9496
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -07009497 return -ENODEV;
9498 }
9499#endif
9500
Jeff Johnson295189b2012-06-20 16:38:30 -07009501 dev = wcnss_wlan_get_device();
9502#endif // ANI_BUS_TYPE_PLATFORM
9503
9504
9505 do {
9506 if (NULL == dev) {
9507 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: WLAN device not found!!",__func__);
9508 ret_status = -1;
9509 break;
9510 }
9511
Jeff Johnson295189b2012-06-20 16:38:30 -07009512#ifdef TIMER_MANAGER
9513 vos_timer_manager_init();
9514#endif
9515
9516 /* Preopen VOSS so that it is ready to start at least SAL */
9517 status = vos_preOpen(&pVosContext);
9518
9519 if (!VOS_IS_STATUS_SUCCESS(status))
9520 {
9521 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to preOpen VOSS", __func__);
9522 ret_status = -1;
9523 break;
9524 }
9525
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009526#ifndef MODULE
9527 /* For statically linked driver, call hdd_set_conparam to update curr_con_mode
9528 */
9529 hdd_set_conparam((v_UINT_t)con_mode);
9530#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009531
9532 // Call our main init function
Jeff Johnsonbc676b42013-02-14 16:04:08 -08009533 if (hdd_wlan_startup(dev))
9534 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009535 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WLAN Driver Initialization failed",
Jeff Johnsonbc676b42013-02-14 16:04:08 -08009536 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009537 vos_preClose( &pVosContext );
9538 ret_status = -1;
9539 break;
9540 }
9541
Jeff Johnson295189b2012-06-20 16:38:30 -07009542 } while (0);
9543
9544 if (0 != ret_status)
9545 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009546#ifdef TIMER_MANAGER
9547 vos_timer_exit();
9548#endif
9549#ifdef MEMORY_DEBUG
9550 vos_mem_exit();
9551#endif
9552
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009553#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07009554 wake_lock_destroy(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07009555#endif
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309556
9557#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9558 wlan_logging_sock_deinit_svc();
9559#endif
9560
Jeff Johnson295189b2012-06-20 16:38:30 -07009561 pr_err("%s: driver load failure\n", WLAN_MODULE_NAME);
9562 }
9563 else
9564 {
9565 //Send WLAN UP indication to Nlink Service
9566 send_btc_nlink_msg(WLAN_MODULE_UP_IND, 0);
9567
9568 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Jeff Johnson295189b2012-06-20 16:38:30 -07009569 }
9570
9571 EXIT();
9572
9573 return ret_status;
9574}
9575
Jeff Johnson32d95a32012-09-10 13:15:23 -07009576/**---------------------------------------------------------------------------
9577
9578 \brief hdd_module_init() - Init Function
9579
9580 This is the driver entry point (invoked when module is loaded using insmod)
9581
9582 \param - None
9583
9584 \return - 0 for success, non zero for failure
9585
9586 --------------------------------------------------------------------------*/
9587#ifdef MODULE
9588static int __init hdd_module_init ( void)
9589{
9590 return hdd_driver_init();
9591}
Jeff Johnson32d95a32012-09-10 13:15:23 -07009592#else /* #ifdef MODULE */
9593static int __init hdd_module_init ( void)
9594{
9595 /* Driver initialization is delayed to fwpath_changed_handler */
9596 return 0;
9597}
Jeff Johnson32d95a32012-09-10 13:15:23 -07009598#endif /* #ifdef MODULE */
9599
Jeff Johnson295189b2012-06-20 16:38:30 -07009600
9601/**---------------------------------------------------------------------------
9602
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009603 \brief hdd_driver_exit() - Exit function
Jeff Johnson295189b2012-06-20 16:38:30 -07009604
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009605 This is the driver exit point (invoked when module is unloaded using rmmod
9606 or con_mode was changed by userspace)
Jeff Johnson295189b2012-06-20 16:38:30 -07009607
9608 \param - None
9609
9610 \return - None
9611
9612 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009613static void hdd_driver_exit(void)
Jeff Johnson295189b2012-06-20 16:38:30 -07009614{
9615 hdd_context_t *pHddCtx = NULL;
9616 v_CONTEXT_t pVosContext = NULL;
Agarwal Ashish5e414792014-06-08 15:25:23 +05309617 v_REGDOMAIN_t regId;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05309618 unsigned long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07009619
9620 pr_info("%s: unloading driver v%s\n", WLAN_MODULE_NAME, QWLAN_VERSIONSTR);
9621
9622 //Get the global vos context
9623 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
9624
9625 if(!pVosContext)
9626 {
9627 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
9628 goto done;
9629 }
9630
9631 //Get the HDD context.
9632 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
9633
9634 if(!pHddCtx)
9635 {
9636 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: module exit called before probe",__func__);
9637 }
9638 else
9639 {
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05309640 INIT_COMPLETION(pHddCtx->ssr_comp_var);
9641
9642 if (pHddCtx->isLogpInProgress)
9643 {
Sameer Thalappil451ebb92013-06-28 15:49:58 -07009644 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05309645 "%s:SSR in Progress; block rmmod !!!", __func__);
9646 rc = wait_for_completion_timeout(&pHddCtx->ssr_comp_var,
9647 msecs_to_jiffies(30000));
9648 if(!rc)
9649 {
9650 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9651 "%s:SSR timedout, fatal error", __func__);
9652 VOS_BUG(0);
Sameer Thalappil451ebb92013-06-28 15:49:58 -07009653 }
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05309654 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009655
Vinay Krishna Erannae362b452014-09-23 13:09:46 +05309656 rtnl_lock();
Mihir Shete18156292014-03-11 15:38:30 +05309657 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07009658 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
Vinay Krishna Erannae362b452014-09-23 13:09:46 +05309659 rtnl_unlock();
Jeff Johnson295189b2012-06-20 16:38:30 -07009660
Agarwal Ashish8db39882014-07-30 21:56:07 +05309661 /* Driver Need to send country code 00 in below condition
9662 * 1) If gCountryCodePriority is set to 1; and last country
9663 * code set is through 11d. This needs to be done in case
9664 * when NV country code is 00.
9665 * This Needs to be done as when kernel store last country
9666 * code and if stored country code is not through 11d,
9667 * in sme_HandleChangeCountryCodeByUser we will disable 11d
9668 * in next load/unload as soon as we get any country through
9669 * 11d. In sme_HandleChangeCountryCodeByUser
9670 * pMsg->countryCode will be last countryCode and
9671 * pMac->scan.countryCode11d will be country through 11d so
9672 * due to mismatch driver will disable 11d.
9673 *
Agarwal Ashish8db39882014-07-30 21:56:07 +05309674 */
9675
9676 if ((eANI_BOOLEAN_TRUE == sme_Is11dCountrycode(pHddCtx->hHal) &&
Agarwal Ashish8dcd2862014-07-25 11:58:52 +05309677 pHddCtx->cfg_ini->fSupplicantCountryCodeHasPriority &&
Abhishek Singh2a705962014-10-30 14:47:28 +05309678 sme_Is11dSupported(pHddCtx->hHal)))
Agarwal Ashish5e414792014-06-08 15:25:23 +05309679 {
Agarwal Ashish8dcd2862014-07-25 11:58:52 +05309680 hddLog(VOS_TRACE_LEVEL_INFO,
9681 FL("CountryCode 00 is being set while unloading driver"));
Agarwal Ashish5e414792014-06-08 15:25:23 +05309682 vos_nv_getRegDomainFromCountryCode(&regId , "00", COUNTRY_USER);
9683 }
9684
Jeff Johnson295189b2012-06-20 16:38:30 -07009685 //Do all the cleanup before deregistering the driver
9686 hdd_wlan_exit(pHddCtx);
9687 }
9688
Jeff Johnson295189b2012-06-20 16:38:30 -07009689 vos_preClose( &pVosContext );
9690
9691#ifdef TIMER_MANAGER
9692 vos_timer_exit();
9693#endif
9694#ifdef MEMORY_DEBUG
9695 vos_mem_exit();
9696#endif
9697
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309698#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9699 wlan_logging_sock_deinit_svc();
9700#endif
9701
Jeff Johnson295189b2012-06-20 16:38:30 -07009702done:
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009703#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07009704 wake_lock_destroy(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07009705#endif
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309706
Jeff Johnson295189b2012-06-20 16:38:30 -07009707 pr_info("%s: driver unloaded\n", WLAN_MODULE_NAME);
9708}
9709
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009710/**---------------------------------------------------------------------------
9711
9712 \brief hdd_module_exit() - Exit function
9713
9714 This is the driver exit point (invoked when module is unloaded using rmmod)
9715
9716 \param - None
9717
9718 \return - None
9719
9720 --------------------------------------------------------------------------*/
9721static void __exit hdd_module_exit(void)
9722{
9723 hdd_driver_exit();
9724}
9725
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009726#ifdef MODULE
9727static int fwpath_changed_handler(const char *kmessage,
9728 struct kernel_param *kp)
9729{
Jeff Johnson76052702013-04-16 13:55:05 -07009730 return param_set_copystring(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009731}
9732
9733static int con_mode_handler(const char *kmessage,
9734 struct kernel_param *kp)
9735{
Madan Mohan Koyyalamudif2f8d8b2012-10-11 17:06:59 -07009736 return param_set_int(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009737}
9738#else /* #ifdef MODULE */
9739/**---------------------------------------------------------------------------
9740
Jeff Johnson76052702013-04-16 13:55:05 -07009741 \brief kickstart_driver
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009742
Jeff Johnson76052702013-04-16 13:55:05 -07009743 This is the driver entry point
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009744 - delayed driver initialization when driver is statically linked
Jeff Johnson76052702013-04-16 13:55:05 -07009745 - invoked when module parameter fwpath is modified from userspace to signal
9746 initializing the WLAN driver or when con_mode is modified from userspace
9747 to signal a switch in operating mode
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009748
9749 \return - 0 for success, non zero for failure
9750
9751 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -07009752static int kickstart_driver(void)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009753{
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07009754 int ret_status;
9755
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009756 if (!wlan_hdd_inited) {
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07009757 ret_status = hdd_driver_init();
9758 wlan_hdd_inited = ret_status ? 0 : 1;
9759 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009760 }
9761
9762 hdd_driver_exit();
Jeff Johnson76052702013-04-16 13:55:05 -07009763
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009764 msleep(200);
Jeff Johnson76052702013-04-16 13:55:05 -07009765
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07009766 ret_status = hdd_driver_init();
9767 wlan_hdd_inited = ret_status ? 0 : 1;
9768 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009769}
9770
Jeff Johnson295189b2012-06-20 16:38:30 -07009771/**---------------------------------------------------------------------------
9772
Jeff Johnson76052702013-04-16 13:55:05 -07009773 \brief fwpath_changed_handler() - Handler Function
9774
9775 Handle changes to the fwpath parameter
9776
9777 \return - 0 for success, non zero for failure
9778
9779 --------------------------------------------------------------------------*/
9780static int fwpath_changed_handler(const char *kmessage,
9781 struct kernel_param *kp)
9782{
9783 int ret;
9784
9785 ret = param_set_copystring(kmessage, kp);
9786 if (0 == ret)
9787 ret = kickstart_driver();
9788 return ret;
9789}
9790
9791/**---------------------------------------------------------------------------
9792
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009793 \brief con_mode_handler() -
9794
9795 Handler function for module param con_mode when it is changed by userspace
9796 Dynamically linked - do nothing
9797 Statically linked - exit and init driver, as in rmmod and insmod
9798
Jeff Johnson76052702013-04-16 13:55:05 -07009799 \param -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009800
Jeff Johnson76052702013-04-16 13:55:05 -07009801 \return -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009802
9803 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -07009804static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009805{
Jeff Johnson76052702013-04-16 13:55:05 -07009806 int ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009807
Jeff Johnson76052702013-04-16 13:55:05 -07009808 ret = param_set_int(kmessage, kp);
9809 if (0 == ret)
9810 ret = kickstart_driver();
9811 return ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009812}
9813#endif /* #ifdef MODULE */
9814
9815/**---------------------------------------------------------------------------
9816
Jeff Johnson295189b2012-06-20 16:38:30 -07009817 \brief hdd_get_conparam() -
9818
9819 This is the driver exit point (invoked when module is unloaded using rmmod)
9820
9821 \param - None
9822
9823 \return - tVOS_CON_MODE
9824
9825 --------------------------------------------------------------------------*/
9826tVOS_CON_MODE hdd_get_conparam ( void )
9827{
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009828#ifdef MODULE
Jeff Johnson295189b2012-06-20 16:38:30 -07009829 return (tVOS_CON_MODE)con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009830#else
9831 return (tVOS_CON_MODE)curr_con_mode;
9832#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009833}
9834void hdd_set_conparam ( v_UINT_t newParam )
9835{
9836 con_mode = newParam;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009837#ifndef MODULE
9838 curr_con_mode = con_mode;
9839#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009840}
9841/**---------------------------------------------------------------------------
9842
9843 \brief hdd_softap_sta_deauth() - function
9844
9845 This to take counter measure to handle deauth req from HDD
9846
9847 \param - pAdapter - Pointer to the HDD
9848
9849 \param - enable - boolean value
9850
9851 \return - None
9852
9853 --------------------------------------------------------------------------*/
9854
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309855VOS_STATUS hdd_softap_sta_deauth(hdd_adapter_t *pAdapter,
9856 struct tagCsrDelStaParams *pDelStaParams)
Jeff Johnson295189b2012-06-20 16:38:30 -07009857{
Jeff Johnson295189b2012-06-20 16:38:30 -07009858 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08009859 VOS_STATUS vosStatus = VOS_STATUS_E_FAULT;
Jeff Johnson295189b2012-06-20 16:38:30 -07009860
9861 ENTER();
9862
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07009863 hddLog(LOG1, "hdd_softap_sta_deauth:(%p, false)",
9864 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07009865
9866 //Ignore request to deauth bcmc station
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309867 if (pDelStaParams->peerMacAddr[0] & 0x1)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08009868 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -07009869
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309870 vosStatus = WLANSAP_DeauthSta(pVosContext, pDelStaParams);
Jeff Johnson295189b2012-06-20 16:38:30 -07009871
9872 EXIT();
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08009873 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -07009874}
9875
9876/**---------------------------------------------------------------------------
9877
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309878 \brief hdd_del_all_sta() - function
9879
9880 This function removes all the stations associated on stopping AP/P2P GO.
9881
9882 \param - pAdapter - Pointer to the HDD
9883
9884 \return - None
9885
9886 --------------------------------------------------------------------------*/
9887
9888int hdd_del_all_sta(hdd_adapter_t *pAdapter)
9889{
9890 v_U16_t i;
9891 VOS_STATUS vos_status;
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +05309892 v_CONTEXT_t pVosContext = ( WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
9893 ptSapContext pSapCtx = NULL;
9894 pSapCtx = VOS_GET_SAP_CB(pVosContext);
9895 if(pSapCtx == NULL){
9896 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9897 FL("psapCtx is NULL"));
9898 return 1;
9899 }
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309900 ENTER();
9901
9902 hddLog(VOS_TRACE_LEVEL_INFO,
9903 "%s: Delete all STAs associated.",__func__);
9904 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
9905 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
9906 )
9907 {
9908 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
9909 {
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +05309910 if ((pSapCtx->aStaInfo[i].isUsed) &&
9911 (!pSapCtx->aStaInfo[i].isDeauthInProgress))
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309912 {
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309913 struct tagCsrDelStaParams delStaParams;
9914
9915 WLANSAP_PopulateDelStaParams(
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +05309916 pSapCtx->aStaInfo[i].macAddrSTA.bytes,
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309917 eCsrForcedDeauthSta, SIR_MAC_MGMT_DEAUTH >> 4,
9918 &delStaParams);
9919 vos_status = hdd_softap_sta_deauth(pAdapter, &delStaParams);
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309920 if (VOS_IS_STATUS_SUCCESS(vos_status))
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +05309921 pSapCtx->aStaInfo[i].isDeauthInProgress = TRUE;
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309922 }
9923 }
9924 }
9925
9926 EXIT();
9927 return 0;
9928}
9929
9930/**---------------------------------------------------------------------------
9931
Jeff Johnson295189b2012-06-20 16:38:30 -07009932 \brief hdd_softap_sta_disassoc() - function
9933
9934 This to take counter measure to handle deauth req from HDD
9935
9936 \param - pAdapter - Pointer to the HDD
9937
9938 \param - enable - boolean value
9939
9940 \return - None
9941
9942 --------------------------------------------------------------------------*/
9943
9944void hdd_softap_sta_disassoc(hdd_adapter_t *pAdapter,v_U8_t *pDestMacAddress)
9945{
9946 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
9947
9948 ENTER();
9949
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05309950 hddLog( LOGE, "hdd_softap_sta_disassoc:(%p, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07009951
9952 //Ignore request to disassoc bcmc station
9953 if( pDestMacAddress[0] & 0x1 )
9954 return;
9955
9956 WLANSAP_DisassocSta(pVosContext,pDestMacAddress);
9957}
9958
9959void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *pAdapter,v_BOOL_t enable)
9960{
9961 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
9962
9963 ENTER();
9964
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05309965 hddLog( LOGE, "hdd_softap_tkip_mic_fail_counter_measure:(%p, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07009966
9967 WLANSAP_SetCounterMeasure(pVosContext, (v_BOOL_t)enable);
9968}
9969
Jeff Johnson295189b2012-06-20 16:38:30 -07009970/**---------------------------------------------------------------------------
9971 *
9972 * \brief hdd_get__concurrency_mode() -
9973 *
9974 *
9975 * \param - None
9976 *
9977 * \return - CONCURRENCY MODE
9978 *
9979 * --------------------------------------------------------------------------*/
9980tVOS_CONCURRENCY_MODE hdd_get_concurrency_mode ( void )
9981{
9982 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
9983 hdd_context_t *pHddCtx;
9984
9985 if (NULL != pVosContext)
9986 {
9987 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
9988 if (NULL != pHddCtx)
9989 {
9990 return (tVOS_CONCURRENCY_MODE)pHddCtx->concurrency_mode;
9991 }
9992 }
9993
9994 /* we are in an invalid state :( */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07009995 hddLog(LOGE, "%s: Invalid context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009996 return VOS_STA;
9997}
Sushant Kaushikabb7ee62014-07-18 16:20:12 +05309998v_BOOL_t
9999wlan_hdd_is_GO_power_collapse_allowed (hdd_context_t* pHddCtx)
10000{
10001 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010002
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010003 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_GO);
10004 if (pAdapter == NULL)
10005 {
10006 hddLog(VOS_TRACE_LEVEL_INFO,
10007 FL("GO doesn't exist"));
10008 return TRUE;
10009 }
10010 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10011 {
10012 hddLog(VOS_TRACE_LEVEL_INFO,
10013 FL("GO started"));
10014 return TRUE;
10015 }
10016 else
10017 /* wait till GO changes its interface to p2p device */
10018 hddLog(VOS_TRACE_LEVEL_INFO,
10019 FL("Del_bss called, avoid apps suspend"));
10020 return FALSE;
10021
10022}
Jeff Johnson295189b2012-06-20 16:38:30 -070010023/* Decide whether to allow/not the apps power collapse.
10024 * Allow apps power collapse if we are in connected state.
10025 * if not, allow only if we are in IMPS */
10026v_BOOL_t hdd_is_apps_power_collapse_allowed(hdd_context_t* pHddCtx)
10027{
10028 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
Srikant Kuppafef66a72013-01-30 17:32:44 -080010029 tANI_BOOLEAN scanRspPending = csrNeighborRoamScanRspPending(pHddCtx->hHal);
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080010030 tANI_BOOLEAN inMiddleOfRoaming = csrNeighborMiddleOfRoaming(pHddCtx->hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -070010031 hdd_config_t *pConfig = pHddCtx->cfg_ini;
10032 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10033 hdd_adapter_t *pAdapter = NULL;
10034 VOS_STATUS status;
Yathish9f22e662012-12-10 14:21:35 -080010035 tVOS_CONCURRENCY_MODE concurrent_state = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070010036
Jeff Johnson295189b2012-06-20 16:38:30 -070010037 if (VOS_STA_SAP_MODE == hdd_get_conparam())
10038 return TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -070010039
Yathish9f22e662012-12-10 14:21:35 -080010040 concurrent_state = hdd_get_concurrency_mode();
10041
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010042 if ((concurrent_state == (VOS_STA | VOS_P2P_GO)) &&
10043 !(wlan_hdd_is_GO_power_collapse_allowed(pHddCtx)))
10044 return FALSE;
Yathish9f22e662012-12-10 14:21:35 -080010045#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010046
Yathish9f22e662012-12-10 14:21:35 -080010047 if(((concurrent_state == (VOS_STA | VOS_P2P_CLIENT)) ||
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010048 (concurrent_state == (VOS_STA | VOS_P2P_GO)))&&
Yathish9f22e662012-12-10 14:21:35 -080010049 (IS_ACTIVEMODE_OFFLOAD_FEATURE_ENABLE))
10050 return TRUE;
10051#endif
10052
Jeff Johnson295189b2012-06-20 16:38:30 -070010053 /*loop through all adapters. TBD fix for Concurrency */
10054 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10055 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10056 {
10057 pAdapter = pAdapterNode->pAdapter;
10058 if ( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
10059 || (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
10060 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080010061 if (((pConfig->fIsImpsEnabled || pConfig->fIsBmpsEnabled)
c_hpothu4e8faac2014-05-16 17:38:44 +053010062 && (pmcState != IMPS && pmcState != BMPS && pmcState != UAPSD
Srikant Kuppafef66a72013-01-30 17:32:44 -080010063 && pmcState != STOPPED && pmcState != STANDBY)) ||
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080010064 (eANI_BOOLEAN_TRUE == scanRspPending) ||
10065 (eANI_BOOLEAN_TRUE == inMiddleOfRoaming))
Jeff Johnson295189b2012-06-20 16:38:30 -070010066 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080010067 hddLog( LOGE, "%s: do not allow APPS power collapse-"
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080010068 "pmcState = %d scanRspPending = %d inMiddleOfRoaming = %d",
10069 __func__, pmcState, scanRspPending, inMiddleOfRoaming );
Jeff Johnson295189b2012-06-20 16:38:30 -070010070 return FALSE;
10071 }
10072 }
10073 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10074 pAdapterNode = pNext;
10075 }
10076 return TRUE;
10077}
10078
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -080010079/* Decides whether to send suspend notification to Riva
10080 * if any adapter is in BMPS; then it is required */
10081v_BOOL_t hdd_is_suspend_notify_allowed(hdd_context_t* pHddCtx)
10082{
10083 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
10084 hdd_config_t *pConfig = pHddCtx->cfg_ini;
10085
10086 if (pConfig->fIsBmpsEnabled && (pmcState == BMPS))
10087 {
10088 return TRUE;
10089 }
10090 return FALSE;
10091}
10092
Jeff Johnson295189b2012-06-20 16:38:30 -070010093void wlan_hdd_set_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
10094{
10095 switch(mode)
10096 {
Chilam Ngc4244af2013-04-01 15:37:32 -070010097 case VOS_STA_MODE:
10098 case VOS_P2P_CLIENT_MODE:
10099 case VOS_P2P_GO_MODE:
10100 case VOS_STA_SAP_MODE:
Jeff Johnsone7245742012-09-05 17:12:55 -070010101 pHddCtx->concurrency_mode |= (1 << mode);
Agarwal Ashish51325b52014-06-16 16:50:49 +053010102 pHddCtx->no_of_open_sessions[mode]++;
Jeff Johnson295189b2012-06-20 16:38:30 -070010103 break;
10104 default:
10105 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070010106 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053010107 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
10108 "Number of open sessions for mode %d = %d"),
10109 pHddCtx->concurrency_mode, mode,
10110 pHddCtx->no_of_open_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070010111}
10112
10113
10114void wlan_hdd_clear_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
10115{
10116 switch(mode)
10117 {
Chilam Ngc4244af2013-04-01 15:37:32 -070010118 case VOS_STA_MODE:
10119 case VOS_P2P_CLIENT_MODE:
10120 case VOS_P2P_GO_MODE:
10121 case VOS_STA_SAP_MODE:
Agarwal Ashish51325b52014-06-16 16:50:49 +053010122 pHddCtx->no_of_open_sessions[mode]--;
10123 if (!(pHddCtx->no_of_open_sessions[mode]))
10124 pHddCtx->concurrency_mode &= (~(1 << mode));
Jeff Johnson295189b2012-06-20 16:38:30 -070010125 break;
10126 default:
10127 break;
10128 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053010129 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
10130 "Number of open sessions for mode %d = %d"),
10131 pHddCtx->concurrency_mode, mode, pHddCtx->no_of_open_sessions[mode]);
10132
10133}
10134/**---------------------------------------------------------------------------
10135 *
10136 * \brief wlan_hdd_incr_active_session()
10137 *
10138 * This function increments the number of active sessions
10139 * maintained per device mode
10140 * Incase of STA/P2P CLI/IBSS upon connection indication it is incremented
10141 * Incase of SAP/P2P GO upon bss start it is incremented
10142 *
10143 * \param pHddCtx - HDD Context
10144 * \param mode - device mode
10145 *
10146 * \return - None
10147 *
10148 * --------------------------------------------------------------------------*/
10149void wlan_hdd_incr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
10150{
10151 switch (mode) {
10152 case VOS_STA_MODE:
10153 case VOS_P2P_CLIENT_MODE:
10154 case VOS_P2P_GO_MODE:
10155 case VOS_STA_SAP_MODE:
10156 pHddCtx->no_of_active_sessions[mode]++;
10157 break;
10158 default:
10159 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
10160 break;
10161 }
10162 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
10163 mode,
10164 pHddCtx->no_of_active_sessions[mode]);
10165}
10166
10167/**---------------------------------------------------------------------------
10168 *
10169 * \brief wlan_hdd_decr_active_session()
10170 *
10171 * This function decrements the number of active sessions
10172 * maintained per device mode
10173 * Incase of STA/P2P CLI/IBSS upon disconnection it is decremented
10174 * Incase of SAP/P2P GO upon bss stop it is decremented
10175 *
10176 * \param pHddCtx - HDD Context
10177 * \param mode - device mode
10178 *
10179 * \return - None
10180 *
10181 * --------------------------------------------------------------------------*/
10182void wlan_hdd_decr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
10183{
10184 switch (mode) {
10185 case VOS_STA_MODE:
10186 case VOS_P2P_CLIENT_MODE:
10187 case VOS_P2P_GO_MODE:
10188 case VOS_STA_SAP_MODE:
Agarwal Ashish5325f522014-08-06 00:58:44 +053010189 if (pHddCtx->no_of_active_sessions[mode] > 0)
10190 pHddCtx->no_of_active_sessions[mode]--;
10191 else
10192 hddLog(VOS_TRACE_LEVEL_INFO, FL(" No.# of Active sessions"
10193 "is already Zero"));
Agarwal Ashish51325b52014-06-16 16:50:49 +053010194 break;
10195 default:
10196 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
10197 break;
10198 }
10199 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
10200 mode,
10201 pHddCtx->no_of_active_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070010202}
10203
Jeff Johnsone7245742012-09-05 17:12:55 -070010204/**---------------------------------------------------------------------------
10205 *
10206 * \brief wlan_hdd_restart_init
10207 *
10208 * This function initalizes restart timer/flag. An internal function.
10209 *
10210 * \param - pHddCtx
10211 *
10212 * \return - None
10213 *
10214 * --------------------------------------------------------------------------*/
10215
10216static void wlan_hdd_restart_init(hdd_context_t *pHddCtx)
10217{
10218 /* Initialize */
10219 pHddCtx->hdd_restart_retries = 0;
10220 atomic_set(&pHddCtx->isRestartInProgress, 0);
10221 vos_timer_init(&pHddCtx->hdd_restart_timer,
10222 VOS_TIMER_TYPE_SW,
10223 wlan_hdd_restart_timer_cb,
10224 pHddCtx);
10225}
10226/**---------------------------------------------------------------------------
10227 *
10228 * \brief wlan_hdd_restart_deinit
10229 *
10230 * This function cleans up the resources used. An internal function.
10231 *
10232 * \param - pHddCtx
10233 *
10234 * \return - None
10235 *
10236 * --------------------------------------------------------------------------*/
10237
10238static void wlan_hdd_restart_deinit(hdd_context_t* pHddCtx)
10239{
10240
10241 VOS_STATUS vos_status;
10242 /* Block any further calls */
10243 atomic_set(&pHddCtx->isRestartInProgress, 1);
10244 /* Cleanup */
10245 vos_status = vos_timer_stop( &pHddCtx->hdd_restart_timer );
10246 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010247 hddLog(LOGE, FL("Failed to stop HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070010248 vos_status = vos_timer_destroy(&pHddCtx->hdd_restart_timer);
10249 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010250 hddLog(LOGE, FL("Failed to destroy HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070010251
10252}
10253
10254/**---------------------------------------------------------------------------
10255 *
10256 * \brief wlan_hdd_framework_restart
10257 *
10258 * This function uses a cfg80211 API to start a framework initiated WLAN
10259 * driver module unload/load.
10260 *
10261 * Also this API keep retrying (WLAN_HDD_RESTART_RETRY_MAX_CNT).
10262 *
10263 *
10264 * \param - pHddCtx
10265 *
10266 * \return - VOS_STATUS_SUCCESS: Success
10267 * VOS_STATUS_E_EMPTY: Adapter is Empty
10268 * VOS_STATUS_E_NOMEM: No memory
10269
10270 * --------------------------------------------------------------------------*/
10271
10272static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx)
10273{
10274 VOS_STATUS status = VOS_STATUS_SUCCESS;
10275 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070010276 int len = (sizeof (struct ieee80211_mgmt));
10277 struct ieee80211_mgmt *mgmt = NULL;
10278
10279 /* Prepare the DEAUTH managment frame with reason code */
10280 mgmt = kzalloc(len, GFP_KERNEL);
10281 if(mgmt == NULL)
10282 {
10283 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
10284 "%s: memory allocation failed (%d bytes)", __func__, len);
10285 return VOS_STATUS_E_NOMEM;
10286 }
10287 mgmt->u.deauth.reason_code = WLAN_REASON_DISASSOC_LOW_ACK;
Jeff Johnsone7245742012-09-05 17:12:55 -070010288
10289 /* Iterate over all adapters/devices */
10290 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10291 do
10292 {
10293 if( (status == VOS_STATUS_SUCCESS) &&
10294 pAdapterNode &&
10295 pAdapterNode->pAdapter)
10296 {
10297 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
10298 "restarting the driver(intf:\'%s\' mode:%d :try %d)",
10299 pAdapterNode->pAdapter->dev->name,
10300 pAdapterNode->pAdapter->device_mode,
10301 pHddCtx->hdd_restart_retries + 1);
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070010302 /*
10303 * CFG80211 event to restart the driver
10304 *
10305 * 'cfg80211_send_unprot_deauth' sends a
10306 * NL80211_CMD_UNPROT_DEAUTHENTICATE event to supplicant at any state
10307 * of SME(Linux Kernel) state machine.
10308 *
10309 * Reason code WLAN_REASON_DISASSOC_LOW_ACK is currently used to restart
10310 * the driver.
10311 *
10312 */
10313
10314 cfg80211_send_unprot_deauth(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len );
Jeff Johnsone7245742012-09-05 17:12:55 -070010315 }
10316 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10317 pAdapterNode = pNext;
10318 } while((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status));
10319
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070010320
10321 /* Free the allocated management frame */
10322 kfree(mgmt);
10323
Jeff Johnsone7245742012-09-05 17:12:55 -070010324 /* Retry until we unload or reach max count */
10325 if(++pHddCtx->hdd_restart_retries < WLAN_HDD_RESTART_RETRY_MAX_CNT)
10326 vos_timer_start(&pHddCtx->hdd_restart_timer, WLAN_HDD_RESTART_RETRY_DELAY_MS);
10327
10328 return status;
10329
10330}
10331/**---------------------------------------------------------------------------
10332 *
10333 * \brief wlan_hdd_restart_timer_cb
10334 *
10335 * Restart timer callback. An internal function.
10336 *
10337 * \param - User data:
10338 *
10339 * \return - None
10340 *
10341 * --------------------------------------------------------------------------*/
10342
10343void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback)
10344{
10345 hdd_context_t *pHddCtx = usrDataForCallback;
10346 wlan_hdd_framework_restart(pHddCtx);
10347 return;
10348
10349}
10350
10351
10352/**---------------------------------------------------------------------------
10353 *
10354 * \brief wlan_hdd_restart_driver
10355 *
10356 * This function sends an event to supplicant to restart the WLAN driver.
10357 *
10358 * This function is called from vos_wlanRestart.
10359 *
10360 * \param - pHddCtx
10361 *
10362 * \return - VOS_STATUS_SUCCESS: Success
10363 * VOS_STATUS_E_EMPTY: Adapter is Empty
10364 * VOS_STATUS_E_ALREADY: Request already in progress
10365
10366 * --------------------------------------------------------------------------*/
10367VOS_STATUS wlan_hdd_restart_driver(hdd_context_t *pHddCtx)
10368{
10369 VOS_STATUS status = VOS_STATUS_SUCCESS;
10370
10371 /* A tight check to make sure reentrancy */
10372 if(atomic_xchg(&pHddCtx->isRestartInProgress, 1))
10373 {
Mihir Shetefd528652014-06-23 19:07:50 +053010374 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsone7245742012-09-05 17:12:55 -070010375 "%s: WLAN restart is already in progress", __func__);
10376
10377 return VOS_STATUS_E_ALREADY;
10378 }
Sameer Thalappil0c164f52013-03-28 15:27:56 -070010379 /* Send reset FIQ to WCNSS to invoke SSR. */
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -080010380#ifdef HAVE_WCNSS_RESET_INTR
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -070010381 wcnss_reset_intr();
10382#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070010383
Jeff Johnsone7245742012-09-05 17:12:55 -070010384 return status;
10385}
10386
Mihir Shetee1093ba2014-01-21 20:13:32 +053010387/**---------------------------------------------------------------------------
10388 *
10389 * \brief wlan_hdd_init_channels
10390 *
10391 * This function is used to initialize the channel list in CSR
10392 *
10393 * This function is called from hdd_wlan_startup
10394 *
10395 * \param - pHddCtx: HDD context
10396 *
10397 * \return - VOS_STATUS_SUCCESS: Success
10398 * VOS_STATUS_E_FAULT: Failure reported by SME
10399
10400 * --------------------------------------------------------------------------*/
10401static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx)
10402{
10403 eHalStatus status;
10404
10405 status = sme_InitChannels(pHddCtx->hHal);
10406 if (HAL_STATUS_SUCCESS(status))
10407 {
10408 return VOS_STATUS_SUCCESS;
10409 }
10410 else
10411 {
10412 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Channel initialization failed(%d)",
10413 __func__, status);
10414 return VOS_STATUS_E_FAULT;
10415 }
10416}
10417
Agarwal Ashish6db9d532014-09-30 18:19:10 +053010418VOS_STATUS wlan_hdd_init_channels_for_cc(hdd_context_t *pHddCtx, driver_load_type init )
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053010419{
10420 eHalStatus status;
10421
Agarwal Ashish6db9d532014-09-30 18:19:10 +053010422 status = sme_InitChannelsForCC(pHddCtx->hHal, init);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053010423 if (HAL_STATUS_SUCCESS(status))
10424 {
10425 return VOS_STATUS_SUCCESS;
10426 }
10427 else
10428 {
10429 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Issue reg hint failed(%d)",
10430 __func__, status);
10431 return VOS_STATUS_E_FAULT;
10432 }
10433}
Sudhir Sattayappa Kohallib1d8c3a2013-06-18 14:47:20 -070010434/*
10435 * API to find if there is any STA or P2P-Client is connected
10436 */
10437VOS_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *pHddCtx)
10438{
10439 return sme_isSta_p2p_clientConnected(pHddCtx->hHal);
10440}
Jeff Johnsone7245742012-09-05 17:12:55 -070010441
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010442int wlan_hdd_scan_abort(hdd_adapter_t *pAdapter)
10443{
10444 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10445 hdd_scaninfo_t *pScanInfo = NULL;
Girish Gowli4bf7a632014-06-12 13:42:11 +053010446 long status = 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010447
10448 pScanInfo = &pHddCtx->scan_info;
10449 if (pScanInfo->mScanPending)
10450 {
10451 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010452 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010453 eCSR_SCAN_ABORT_DEFAULT);
10454
10455 status = wait_for_completion_interruptible_timeout(
10456 &pScanInfo->abortscan_event_var,
10457 msecs_to_jiffies(5000));
Girish Gowli4bf7a632014-06-12 13:42:11 +053010458 if (0 >= status)
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010459 {
10460 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Girish Gowli4bf7a632014-06-12 13:42:11 +053010461 "%s: Timeout or Interrupt occurred while waiting for abort"
10462 "scan, status- %ld", __func__, status);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010463 return -ETIMEDOUT;
10464 }
10465 }
Girish Gowli4bf7a632014-06-12 13:42:11 +053010466 return 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010467}
10468
c_hpothu225aa7c2014-10-22 17:45:13 +053010469VOS_STATUS wlan_hdd_cancel_remain_on_channel(hdd_context_t *pHddCtx)
10470{
10471 hdd_adapter_t *pAdapter;
10472 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10473 VOS_STATUS vosStatus;
10474
10475 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10476 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
10477 {
10478 pAdapter = pAdapterNode->pAdapter;
10479 if (NULL != pAdapter)
10480 {
10481 if (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode ||
10482 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
10483 WLAN_HDD_P2P_GO == pAdapter->device_mode)
10484 {
10485 hddLog(LOG1, FL("abort ROC deviceMode: %d"),
10486 pAdapter->device_mode);
10487 if (VOS_STATUS_SUCCESS !=
10488 wlan_hdd_cancel_existing_remain_on_channel(pAdapter))
10489 {
10490 hddLog(LOGE, FL("failed to abort ROC"));
10491 return VOS_STATUS_E_FAILURE;
10492 }
10493 }
10494 }
10495 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10496 pAdapterNode = pNext;
10497 }
10498 return VOS_STATUS_SUCCESS;
10499}
Jeff Johnson295189b2012-06-20 16:38:30 -070010500//Register the module init/exit functions
10501module_init(hdd_module_init);
10502module_exit(hdd_module_exit);
10503
10504MODULE_LICENSE("Dual BSD/GPL");
10505MODULE_AUTHOR("Qualcomm Atheros, Inc.");
10506MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
10507
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070010508module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
10509 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Jeff Johnson32d95a32012-09-10 13:15:23 -070010510
Jeff Johnson76052702013-04-16 13:55:05 -070010511module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
Jeff Johnson32d95a32012-09-10 13:15:23 -070010512 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Arif Hussain66559122013-11-21 10:11:40 -080010513
10514module_param(enable_dfs_chan_scan, int,
10515 S_IRUSR | S_IRGRP | S_IROTH);
10516
10517module_param(enable_11d, int,
10518 S_IRUSR | S_IRGRP | S_IROTH);
10519
10520module_param(country_code, charp,
10521 S_IRUSR | S_IRGRP | S_IROTH);