blob: 7ddcf393783b93450c1bf78e03122a9b621b64f8 [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;
Jeff Johnson295189b2012-06-20 16:38:30 -07007087
Agarwal Ashish3a38bd12014-06-12 15:16:52 +05307088 hdd_stop_adapter( pHddCtx, pAdapter, VOS_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07007089
7090 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7091 pAdapterNode = pNext;
7092 }
7093
7094 EXIT();
7095
7096 return VOS_STATUS_SUCCESS;
7097}
7098
Rajeev Kumarf999e582014-01-09 17:33:29 -08007099
7100#ifdef FEATURE_WLAN_BATCH_SCAN
7101/**---------------------------------------------------------------------------
7102
7103 \brief hdd_deinit_batch_scan () - This function cleans up batch scan data
7104 structures
7105
7106 \param - pAdapter Pointer to HDD adapter
7107
7108 \return - None
7109
7110 --------------------------------------------------------------------------*/
7111void hdd_deinit_batch_scan(hdd_adapter_t *pAdapter)
7112{
7113 tHddBatchScanRsp *pNode;
7114 tHddBatchScanRsp *pPrev;
7115
Siddharth Bhalb3e9b792014-02-24 15:14:16 +05307116 if (NULL == pAdapter)
Rajeev Kumarf999e582014-01-09 17:33:29 -08007117 {
Siddharth Bhalb3e9b792014-02-24 15:14:16 +05307118 hddLog(VOS_TRACE_LEVEL_ERROR,
7119 "%s: Adapter context is Null", __func__);
7120 return;
7121 }
7122
7123 pNode = pAdapter->pBatchScanRsp;
7124 while (pNode)
7125 {
7126 pPrev = pNode;
7127 pNode = pNode->pNext;
7128 vos_mem_free((v_VOID_t * )pPrev);
Rajeev Kumarf999e582014-01-09 17:33:29 -08007129 }
7130
7131 pAdapter->pBatchScanRsp = NULL;
7132 pAdapter->numScanList = 0;
7133 pAdapter->batchScanState = eHDD_BATCH_SCAN_STATE_STOPPED;
7134 pAdapter->prev_batch_id = 0;
7135
7136 return;
7137}
7138#endif
7139
7140
Jeff Johnson295189b2012-06-20 16:38:30 -07007141VOS_STATUS hdd_reset_all_adapters( hdd_context_t *pHddCtx )
7142{
7143 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7144 VOS_STATUS status;
7145 hdd_adapter_t *pAdapter;
7146
7147 ENTER();
7148
7149 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7150
7151 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7152 {
7153 pAdapter = pAdapterNode->pAdapter;
7154 netif_tx_disable(pAdapter->dev);
7155 netif_carrier_off(pAdapter->dev);
7156
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -07007157 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
7158
Jeff Johnson295189b2012-06-20 16:38:30 -07007159 hdd_deinit_tx_rx(pAdapter);
Agarwal Ashish6267caa2014-08-06 19:16:21 +05307160
7161 wlan_hdd_decr_active_session(pHddCtx, pAdapter->device_mode);
7162
Madan Mohan Koyyalamudi8c6dec82013-09-26 15:56:13 +05307163 if (test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
7164 {
7165 hdd_wmm_adapter_close( pAdapter );
7166 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
7167 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007168
Rajeev Kumarf999e582014-01-09 17:33:29 -08007169#ifdef FEATURE_WLAN_BATCH_SCAN
7170 if (eHDD_BATCH_SCAN_STATE_STARTED == pAdapter->batchScanState)
7171 {
7172 hdd_deinit_batch_scan(pAdapter);
7173 }
7174#endif
7175
Jeff Johnson295189b2012-06-20 16:38:30 -07007176 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7177 pAdapterNode = pNext;
7178 }
7179
7180 EXIT();
7181
7182 return VOS_STATUS_SUCCESS;
7183}
7184
7185VOS_STATUS hdd_start_all_adapters( hdd_context_t *pHddCtx )
7186{
7187 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7188 VOS_STATUS status;
7189 hdd_adapter_t *pAdapter;
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05307190 eConnectionState connState;
Jeff Johnson295189b2012-06-20 16:38:30 -07007191
7192 ENTER();
7193
7194 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7195
7196 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7197 {
7198 pAdapter = pAdapterNode->pAdapter;
7199
Kumar Anand82c009f2014-05-29 00:29:42 -07007200 hdd_wmm_init( pAdapter );
7201
Jeff Johnson295189b2012-06-20 16:38:30 -07007202 switch(pAdapter->device_mode)
7203 {
7204 case WLAN_HDD_INFRA_STATION:
7205 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07007206 case WLAN_HDD_P2P_DEVICE:
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05307207
7208 connState = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState;
7209
Jeff Johnson295189b2012-06-20 16:38:30 -07007210 hdd_init_station_mode(pAdapter);
7211 /* Open the gates for HDD to receive Wext commands */
7212 pAdapter->isLinkUpSvcNeeded = FALSE;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07007213 pHddCtx->scan_info.mScanPending = FALSE;
7214 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007215
7216 //Trigger the initial scan
7217 hdd_wlan_initial_scan(pAdapter);
7218
7219 //Indicate disconnect event to supplicant if associated previously
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05307220 if (eConnectionState_Associated == connState ||
7221 eConnectionState_IbssConnected == connState )
Jeff Johnson295189b2012-06-20 16:38:30 -07007222 {
7223 union iwreq_data wrqu;
7224 memset(&wrqu, '\0', sizeof(wrqu));
7225 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
7226 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
7227 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
Srinivas Girigowda66c05eb2013-07-14 13:06:01 -07007228 pAdapter->sessionCtx.station.hdd_ReassocScenario = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007229
Jeff Johnson295189b2012-06-20 16:38:30 -07007230 /* indicate disconnected event to nl80211 */
7231 cfg80211_disconnected(pAdapter->dev, WLAN_REASON_UNSPECIFIED,
7232 NULL, 0, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07007233 }
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05307234 else if (eConnectionState_Connecting == connState)
7235 {
7236 /*
7237 * Indicate connect failure to supplicant if we were in the
7238 * process of connecting
7239 */
7240 cfg80211_connect_result(pAdapter->dev, NULL,
7241 NULL, 0, NULL, 0,
7242 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
7243 GFP_KERNEL);
7244 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007245 break;
7246
7247 case WLAN_HDD_SOFTAP:
7248 /* softAP can handle SSR */
7249 break;
7250
7251 case WLAN_HDD_P2P_GO:
Sameer Thalappiledf0d792013-08-09 14:31:03 -07007252 hddLog(VOS_TRACE_LEVEL_ERROR, "%s [SSR] send stop ap to supplicant",
Jeff Johnson295189b2012-06-20 16:38:30 -07007253 __func__);
Sameer Thalappiledf0d792013-08-09 14:31:03 -07007254 cfg80211_ap_stopped(pAdapter->dev, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -07007255 break;
7256
7257 case WLAN_HDD_MONITOR:
7258 /* monitor interface start */
7259 break;
7260 default:
7261 break;
7262 }
7263
7264 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7265 pAdapterNode = pNext;
7266 }
7267
7268 EXIT();
7269
7270 return VOS_STATUS_SUCCESS;
7271}
7272
7273VOS_STATUS hdd_reconnect_all_adapters( hdd_context_t *pHddCtx )
7274{
7275 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7276 hdd_adapter_t *pAdapter;
7277 VOS_STATUS status;
7278 v_U32_t roamId;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307279 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07007280
7281 ENTER();
7282
7283 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7284
7285 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7286 {
7287 pAdapter = pAdapterNode->pAdapter;
7288
7289 if( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
7290 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
7291 {
7292 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7293 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
7294
Abhishek Singhf4669da2014-05-26 15:07:49 +05307295 hddLog(VOS_TRACE_LEVEL_INFO,
7296 "%s: Set HDD connState to eConnectionState_NotConnected",
7297 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007298 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
7299 init_completion(&pAdapter->disconnect_comp_var);
7300 sme_RoamDisconnect(pHddCtx->hHal, pAdapter->sessionId,
7301 eCSR_DISCONNECT_REASON_UNSPECIFIED);
7302
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307303 ret = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07007304 &pAdapter->disconnect_comp_var,
7305 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307306 if (0 >= ret)
7307 hddLog(LOGE, "%s: failure waiting for disconnect_comp_var %ld",
7308 __func__, ret);
Jeff Johnson295189b2012-06-20 16:38:30 -07007309
7310 pWextState->roamProfile.csrPersona = pAdapter->device_mode;
7311 pHddCtx->isAmpAllowed = VOS_FALSE;
7312 sme_RoamConnect(pHddCtx->hHal,
7313 pAdapter->sessionId, &(pWextState->roamProfile),
7314 &roamId);
7315 }
7316
7317 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7318 pAdapterNode = pNext;
7319 }
7320
7321 EXIT();
7322
7323 return VOS_STATUS_SUCCESS;
7324}
7325
Sudhir Sattayappa Kohalli90e4c752013-03-21 14:25:04 -07007326void hdd_dump_concurrency_info(hdd_context_t *pHddCtx)
7327{
7328 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7329 VOS_STATUS status;
7330 hdd_adapter_t *pAdapter;
7331 hdd_station_ctx_t *pHddStaCtx;
7332 hdd_ap_ctx_t *pHddApCtx;
7333 hdd_hostapd_state_t * pHostapdState;
7334 tCsrBssid staBssid = { 0 }, p2pBssid = { 0 }, apBssid = { 0 };
7335 v_U8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
7336 const char *p2pMode = "DEV";
7337 const char *ccMode = "Standalone";
7338 int n;
7339
7340 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7341 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7342 {
7343 pAdapter = pAdapterNode->pAdapter;
7344 switch (pAdapter->device_mode) {
7345 case WLAN_HDD_INFRA_STATION:
7346 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7347 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
7348 staChannel = pHddStaCtx->conn_info.operationChannel;
7349 memcpy(staBssid, pHddStaCtx->conn_info.bssId, sizeof(staBssid));
7350 }
7351 break;
7352 case WLAN_HDD_P2P_CLIENT:
7353 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7354 if (eConnectionState_Associated == pHddStaCtx->conn_info.connState) {
7355 p2pChannel = pHddStaCtx->conn_info.operationChannel;
7356 memcpy(p2pBssid, pHddStaCtx->conn_info.bssId, sizeof(p2pBssid));
7357 p2pMode = "CLI";
7358 }
7359 break;
7360 case WLAN_HDD_P2P_GO:
7361 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
7362 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
7363 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
7364 p2pChannel = pHddApCtx->operatingChannel;
7365 memcpy(p2pBssid, pAdapter->macAddressCurrent.bytes, sizeof(p2pBssid));
7366 }
7367 p2pMode = "GO";
7368 break;
7369 case WLAN_HDD_SOFTAP:
7370 pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
7371 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
7372 if (pHostapdState->bssState == BSS_START && pHostapdState->vosStatus==VOS_STATUS_SUCCESS) {
7373 apChannel = pHddApCtx->operatingChannel;
7374 memcpy(apBssid, pAdapter->macAddressCurrent.bytes, sizeof(apBssid));
7375 }
7376 break;
7377 default:
7378 break;
7379 }
7380 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7381 pAdapterNode = pNext;
7382 }
7383 if (staChannel > 0 && (apChannel > 0 || p2pChannel > 0)) {
7384 ccMode = (p2pChannel==staChannel||apChannel==staChannel) ? "SCC" : "MCC";
7385 }
7386 n = pr_info("wlan(%d) " MAC_ADDRESS_STR " %s",
7387 staChannel, MAC_ADDR_ARRAY(staBssid), ccMode);
7388 if (p2pChannel > 0) {
7389 n += pr_info("p2p-%s(%d) " MAC_ADDRESS_STR,
7390 p2pMode, p2pChannel, MAC_ADDR_ARRAY(p2pBssid));
7391 }
7392 if (apChannel > 0) {
7393 n += pr_info("AP(%d) " MAC_ADDRESS_STR,
7394 apChannel, MAC_ADDR_ARRAY(apBssid));
7395 }
7396
7397 if (p2pChannel > 0 && apChannel > 0) {
7398 hddLog(VOS_TRACE_LEVEL_ERROR, "Error concurrent SAP %d and P2P %d which is not support", apChannel, p2pChannel);
7399 }
7400}
7401
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07007402bool hdd_is_ssr_required( void)
Jeff Johnson295189b2012-06-20 16:38:30 -07007403{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07007404 return (isSsrRequired == HDD_SSR_REQUIRED);
Jeff Johnson295189b2012-06-20 16:38:30 -07007405}
7406
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07007407/* Once SSR is disabled then it cannot be set. */
7408void hdd_set_ssr_required( e_hdd_ssr_required value)
Jeff Johnson295189b2012-06-20 16:38:30 -07007409{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07007410 if (HDD_SSR_DISABLED == isSsrRequired)
7411 return;
7412
Jeff Johnson295189b2012-06-20 16:38:30 -07007413 isSsrRequired = value;
7414}
7415
7416VOS_STATUS hdd_get_front_adapter( hdd_context_t *pHddCtx,
7417 hdd_adapter_list_node_t** ppAdapterNode)
7418{
7419 VOS_STATUS status;
7420 spin_lock(&pHddCtx->hddAdapters.lock);
7421 status = hdd_list_peek_front ( &pHddCtx->hddAdapters,
7422 (hdd_list_node_t**) ppAdapterNode );
7423 spin_unlock(&pHddCtx->hddAdapters.lock);
7424 return status;
7425}
7426
7427VOS_STATUS hdd_get_next_adapter( hdd_context_t *pHddCtx,
7428 hdd_adapter_list_node_t* pAdapterNode,
7429 hdd_adapter_list_node_t** pNextAdapterNode)
7430{
7431 VOS_STATUS status;
7432 spin_lock(&pHddCtx->hddAdapters.lock);
7433 status = hdd_list_peek_next ( &pHddCtx->hddAdapters,
7434 (hdd_list_node_t*) pAdapterNode,
7435 (hdd_list_node_t**)pNextAdapterNode );
7436
7437 spin_unlock(&pHddCtx->hddAdapters.lock);
7438 return status;
7439}
7440
7441VOS_STATUS hdd_remove_adapter( hdd_context_t *pHddCtx,
7442 hdd_adapter_list_node_t* pAdapterNode)
7443{
7444 VOS_STATUS status;
7445 spin_lock(&pHddCtx->hddAdapters.lock);
7446 status = hdd_list_remove_node ( &pHddCtx->hddAdapters,
7447 &pAdapterNode->node );
7448 spin_unlock(&pHddCtx->hddAdapters.lock);
7449 return status;
7450}
7451
7452VOS_STATUS hdd_remove_front_adapter( hdd_context_t *pHddCtx,
7453 hdd_adapter_list_node_t** ppAdapterNode)
7454{
7455 VOS_STATUS status;
7456 spin_lock(&pHddCtx->hddAdapters.lock);
7457 status = hdd_list_remove_front( &pHddCtx->hddAdapters,
7458 (hdd_list_node_t**) ppAdapterNode );
7459 spin_unlock(&pHddCtx->hddAdapters.lock);
7460 return status;
7461}
7462
7463VOS_STATUS hdd_add_adapter_back( hdd_context_t *pHddCtx,
7464 hdd_adapter_list_node_t* pAdapterNode)
7465{
7466 VOS_STATUS status;
7467 spin_lock(&pHddCtx->hddAdapters.lock);
7468 status = hdd_list_insert_back ( &pHddCtx->hddAdapters,
7469 (hdd_list_node_t*) pAdapterNode );
7470 spin_unlock(&pHddCtx->hddAdapters.lock);
7471 return status;
7472}
7473
7474VOS_STATUS hdd_add_adapter_front( hdd_context_t *pHddCtx,
7475 hdd_adapter_list_node_t* pAdapterNode)
7476{
7477 VOS_STATUS status;
7478 spin_lock(&pHddCtx->hddAdapters.lock);
7479 status = hdd_list_insert_front ( &pHddCtx->hddAdapters,
7480 (hdd_list_node_t*) pAdapterNode );
7481 spin_unlock(&pHddCtx->hddAdapters.lock);
7482 return status;
7483}
7484
7485hdd_adapter_t * hdd_get_adapter_by_macaddr( hdd_context_t *pHddCtx,
7486 tSirMacAddr macAddr )
7487{
7488 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7489 hdd_adapter_t *pAdapter;
7490 VOS_STATUS status;
7491
7492 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7493
7494 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7495 {
7496 pAdapter = pAdapterNode->pAdapter;
7497
7498 if( pAdapter && vos_mem_compare( pAdapter->macAddressCurrent.bytes,
7499 macAddr, sizeof(tSirMacAddr) ) )
7500 {
7501 return pAdapter;
7502 }
7503 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7504 pAdapterNode = pNext;
7505 }
7506
7507 return NULL;
7508
7509}
7510
7511hdd_adapter_t * hdd_get_adapter_by_name( hdd_context_t *pHddCtx, tANI_U8 *name )
7512{
7513 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7514 hdd_adapter_t *pAdapter;
7515 VOS_STATUS status;
7516
7517 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7518
7519 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7520 {
7521 pAdapter = pAdapterNode->pAdapter;
7522
7523 if( pAdapter && !strncmp( pAdapter->dev->name, (const char *)name,
7524 IFNAMSIZ ) )
7525 {
7526 return pAdapter;
7527 }
7528 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7529 pAdapterNode = pNext;
7530 }
7531
7532 return NULL;
7533
7534}
7535
7536hdd_adapter_t * hdd_get_adapter( hdd_context_t *pHddCtx, device_mode_t mode )
7537{
7538 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7539 hdd_adapter_t *pAdapter;
7540 VOS_STATUS status;
7541
7542 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7543
7544 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7545 {
7546 pAdapter = pAdapterNode->pAdapter;
7547
7548 if( pAdapter && (mode == pAdapter->device_mode) )
7549 {
7550 return pAdapter;
7551 }
7552 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7553 pAdapterNode = pNext;
7554 }
7555
7556 return NULL;
7557
7558}
7559
7560//Remove this function later
7561hdd_adapter_t * hdd_get_mon_adapter( hdd_context_t *pHddCtx )
7562{
7563 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7564 hdd_adapter_t *pAdapter;
7565 VOS_STATUS status;
7566
7567 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7568
7569 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7570 {
7571 pAdapter = pAdapterNode->pAdapter;
7572
7573 if( pAdapter && WLAN_HDD_MONITOR == pAdapter->device_mode )
7574 {
7575 return pAdapter;
7576 }
7577
7578 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7579 pAdapterNode = pNext;
7580 }
7581
7582 return NULL;
7583
7584}
7585
Jeff Johnson295189b2012-06-20 16:38:30 -07007586/**---------------------------------------------------------------------------
7587
7588 \brief hdd_set_monitor_tx_adapter() -
7589
7590 This API initializes the adapter to be used while transmitting on monitor
7591 adapter.
7592
7593 \param - pHddCtx - Pointer to the HDD context.
7594 pAdapter - Adapter that will used for TX. This can be NULL.
7595 \return - None.
7596 --------------------------------------------------------------------------*/
7597void wlan_hdd_set_monitor_tx_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
7598{
7599 hdd_adapter_t *pMonAdapter;
7600
7601 pMonAdapter = hdd_get_adapter( pHddCtx, WLAN_HDD_MONITOR );
7602
7603 if( NULL != pMonAdapter )
7604 {
7605 pMonAdapter->sessionCtx.monitor.pAdapterForTx = pAdapter;
7606 }
7607}
Jeff Johnson295189b2012-06-20 16:38:30 -07007608/**---------------------------------------------------------------------------
7609
Mahesh A Saptasgar64534612014-09-23 13:13:33 +05307610 \brief hdd_get_operating_channel() -
Jeff Johnson295189b2012-06-20 16:38:30 -07007611
7612 This API returns the operating channel of the requested device mode
7613
7614 \param - pHddCtx - Pointer to the HDD context.
7615 - mode - Device mode for which operating channel is required
7616 suported modes - WLAN_HDD_INFRA_STATION, WLAN_HDD_P2P_CLIENT
7617 WLAN_HDD_SOFTAP, WLAN_HDD_P2P_GO.
7618 \return - channel number. "0" id the requested device is not found OR it is not connected.
7619 --------------------------------------------------------------------------*/
7620v_U8_t hdd_get_operating_channel( hdd_context_t *pHddCtx, device_mode_t mode )
7621{
7622 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7623 VOS_STATUS status;
7624 hdd_adapter_t *pAdapter;
7625 v_U8_t operatingChannel = 0;
7626
7627 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7628
7629 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
7630 {
7631 pAdapter = pAdapterNode->pAdapter;
7632
7633 if( mode == pAdapter->device_mode )
7634 {
7635 switch(pAdapter->device_mode)
7636 {
7637 case WLAN_HDD_INFRA_STATION:
7638 case WLAN_HDD_P2P_CLIENT:
7639 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
7640 operatingChannel = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.operationChannel;
7641 break;
7642 case WLAN_HDD_SOFTAP:
7643 case WLAN_HDD_P2P_GO:
7644 /*softap connection info */
7645 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
7646 operatingChannel = (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->operatingChannel;
7647 break;
7648 default:
7649 break;
7650 }
7651
7652 break; //Found the device of interest. break the loop
7653 }
7654
7655 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7656 pAdapterNode = pNext;
7657 }
7658 return operatingChannel;
7659}
7660
7661#ifdef WLAN_FEATURE_PACKET_FILTERING
7662/**---------------------------------------------------------------------------
7663
7664 \brief hdd_set_multicast_list() -
7665
7666 This used to set the multicast address list.
7667
7668 \param - dev - Pointer to the WLAN device.
7669 - skb - Pointer to OS packet (sk_buff).
7670 \return - success/fail
7671
7672 --------------------------------------------------------------------------*/
7673static void hdd_set_multicast_list(struct net_device *dev)
7674{
7675 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07007676 int mc_count;
7677 int i = 0;
7678 struct netdev_hw_addr *ha;
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307679
7680 if (NULL == pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -07007681 {
7682 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307683 "%s: Adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007684 return;
7685 }
7686
7687 if (dev->flags & IFF_ALLMULTI)
7688 {
7689 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007690 "%s: allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307691 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007692 }
7693 else
7694 {
7695 mc_count = netdev_mc_count(dev);
7696 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007697 "%s: mc_count = %u", __func__, mc_count);
Jeff Johnson295189b2012-06-20 16:38:30 -07007698 if (mc_count > WLAN_HDD_MAX_MC_ADDR_LIST)
7699 {
7700 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007701 "%s: No free filter available; allow all multicast frames", __func__);
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307702 pAdapter->mc_addr_list.mc_cnt = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007703 return;
7704 }
7705
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307706 pAdapter->mc_addr_list.mc_cnt = mc_count;
Jeff Johnson295189b2012-06-20 16:38:30 -07007707
7708 netdev_for_each_mc_addr(ha, dev) {
7709 if (i == mc_count)
7710 break;
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307711 memset(&(pAdapter->mc_addr_list.addr[i][0]), 0, ETH_ALEN);
7712 memcpy(&(pAdapter->mc_addr_list.addr[i][0]), ha->addr, ETH_ALEN);
Arif Hussain6d2a3322013-11-17 19:50:10 -08007713 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mlist[%d] = "MAC_ADDRESS_STR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007714 __func__, i,
Gopichand Nakkala0f276812013-02-24 14:45:51 +05307715 MAC_ADDR_ARRAY(pAdapter->mc_addr_list.addr[i]));
Jeff Johnson295189b2012-06-20 16:38:30 -07007716 i++;
7717 }
7718 }
7719 return;
7720}
7721#endif
7722
7723/**---------------------------------------------------------------------------
7724
7725 \brief hdd_select_queue() -
7726
7727 This function is registered with the Linux OS for network
7728 core to decide which queue to use first.
7729
7730 \param - dev - Pointer to the WLAN device.
7731 - skb - Pointer to OS packet (sk_buff).
7732 \return - ac, Queue Index/access category corresponding to UP in IP header
7733
7734 --------------------------------------------------------------------------*/
7735v_U16_t hdd_select_queue(struct net_device *dev,
7736 struct sk_buff *skb)
7737{
7738 return hdd_wmm_select_queue(dev, skb);
7739}
7740
7741
7742/**---------------------------------------------------------------------------
7743
7744 \brief hdd_wlan_initial_scan() -
7745
7746 This function triggers the initial scan
7747
7748 \param - pAdapter - Pointer to the HDD adapter.
7749
7750 --------------------------------------------------------------------------*/
7751void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter)
7752{
7753 tCsrScanRequest scanReq;
7754 tCsrChannelInfo channelInfo;
7755 eHalStatus halStatus;
Jeff Johnson02797792013-10-26 19:17:13 -07007756 tANI_U32 scanId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007757 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7758
7759 vos_mem_zero(&scanReq, sizeof(tCsrScanRequest));
7760 vos_mem_set(&scanReq.bssid, sizeof(tCsrBssid), 0xff);
7761 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
7762
7763 if(sme_Is11dSupported(pHddCtx->hHal))
7764 {
7765 halStatus = sme_ScanGetBaseChannels( pHddCtx->hHal, &channelInfo );
7766 if ( HAL_STATUS_SUCCESS( halStatus ) )
7767 {
7768 scanReq.ChannelInfo.ChannelList = vos_mem_malloc(channelInfo.numOfChannels);
7769 if( !scanReq.ChannelInfo.ChannelList )
7770 {
7771 hddLog(VOS_TRACE_LEVEL_ERROR, "%s kmalloc failed", __func__);
7772 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08007773 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007774 return;
7775 }
7776 vos_mem_copy(scanReq.ChannelInfo.ChannelList, channelInfo.ChannelList,
7777 channelInfo.numOfChannels);
7778 scanReq.ChannelInfo.numOfChannels = channelInfo.numOfChannels;
7779 vos_mem_free(channelInfo.ChannelList);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -08007780 channelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007781 }
7782
7783 scanReq.scanType = eSIR_PASSIVE_SCAN;
7784 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
7785 scanReq.maxChnTime = pHddCtx->cfg_ini->nPassiveMaxChnTime;
7786 scanReq.minChnTime = pHddCtx->cfg_ini->nPassiveMinChnTime;
7787 }
7788 else
7789 {
7790 scanReq.scanType = eSIR_ACTIVE_SCAN;
7791 scanReq.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
7792 scanReq.maxChnTime = pHddCtx->cfg_ini->nActiveMaxChnTime;
7793 scanReq.minChnTime = pHddCtx->cfg_ini->nActiveMinChnTime;
7794 }
7795
7796 halStatus = sme_ScanRequest(pHddCtx->hHal, pAdapter->sessionId, &scanReq, &scanId, NULL, NULL);
7797 if ( !HAL_STATUS_SUCCESS( halStatus ) )
7798 {
7799 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_ScanRequest failed status code %d",
7800 __func__, halStatus );
7801 }
7802
7803 if(sme_Is11dSupported(pHddCtx->hHal))
7804 vos_mem_free(scanReq.ChannelInfo.ChannelList);
7805}
7806
Jeff Johnson295189b2012-06-20 16:38:30 -07007807/**---------------------------------------------------------------------------
7808
7809 \brief hdd_full_power_callback() - HDD full power callback function
7810
7811 This is the function invoked by SME to inform the result of a full power
7812 request issued by HDD
7813
7814 \param - callbackcontext - Pointer to cookie
7815 \param - status - result of request
7816
7817 \return - None
7818
7819 --------------------------------------------------------------------------*/
7820static void hdd_full_power_callback(void *callbackContext, eHalStatus status)
7821{
Jeff Johnson72a40512013-12-19 10:14:15 -08007822 struct statsContext *pContext = callbackContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07007823
7824 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05307825 "%s: context = %p, status = %d", __func__, pContext, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007826
7827 if (NULL == callbackContext)
7828 {
7829 hddLog(VOS_TRACE_LEVEL_ERROR,
7830 "%s: Bad param, context [%p]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007831 __func__, callbackContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07007832 return;
7833 }
7834
Jeff Johnson72a40512013-12-19 10:14:15 -08007835 /* there is a race condition that exists between this callback
7836 function and the caller since the caller could time out either
7837 before or while this code is executing. we use a spinlock to
7838 serialize these actions */
7839 spin_lock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07007840
7841 if (POWER_CONTEXT_MAGIC != pContext->magic)
7842 {
7843 /* the caller presumably timed out so there is nothing we can do */
Jeff Johnson72a40512013-12-19 10:14:15 -08007844 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07007845 hddLog(VOS_TRACE_LEVEL_WARN,
7846 "%s: Invalid context, magic [%08x]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007847 __func__, pContext->magic);
Jeff Johnson295189b2012-06-20 16:38:30 -07007848 return;
7849 }
7850
Jeff Johnson72a40512013-12-19 10:14:15 -08007851 /* context is valid so caller is still waiting */
7852
7853 /* paranoia: invalidate the magic */
7854 pContext->magic = 0;
7855
7856 /* notify the caller */
Jeff Johnson295189b2012-06-20 16:38:30 -07007857 complete(&pContext->completion);
Jeff Johnson72a40512013-12-19 10:14:15 -08007858
7859 /* serialization is complete */
7860 spin_unlock(&hdd_context_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07007861}
7862
7863/**---------------------------------------------------------------------------
7864
7865 \brief hdd_wlan_exit() - HDD WLAN exit function
7866
7867 This is the driver exit point (invoked during rmmod)
7868
7869 \param - pHddCtx - Pointer to the HDD Context
7870
7871 \return - None
7872
7873 --------------------------------------------------------------------------*/
7874void hdd_wlan_exit(hdd_context_t *pHddCtx)
7875{
7876 eHalStatus halStatus;
7877 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
7878 VOS_STATUS vosStatus;
Gopichand Nakkala66923aa2013-03-06 23:17:24 +05307879 struct wiphy *wiphy = pHddCtx->wiphy;
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08007880 hdd_adapter_t* pAdapter = NULL;
Jeff Johnson72a40512013-12-19 10:14:15 -08007881 struct statsContext powerContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07007882 long lrc;
c_hpothu5ab05e92014-06-13 17:34:05 +05307883 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007884
7885 ENTER();
7886
Jeff Johnson88ba7742013-02-27 14:36:02 -08007887 if (VOS_FTM_MODE != hdd_get_conparam())
7888 {
7889 // Unloading, restart logic is no more required.
7890 wlan_hdd_restart_deinit(pHddCtx);
Jeff Johnsone7245742012-09-05 17:12:55 -07007891
c_hpothu5ab05e92014-06-13 17:34:05 +05307892 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
7893 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
Jeff Johnson295189b2012-06-20 16:38:30 -07007894 {
c_hpothu5ab05e92014-06-13 17:34:05 +05307895 pAdapter = pAdapterNode->pAdapter;
7896 if (NULL != pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -07007897 {
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05307898 /* Disable TX on the interface, after this hard_start_xmit() will
7899 * not be called on that interface
7900 */
7901 netif_tx_disable(pAdapter->dev);
7902
7903 /* Mark the interface status as "down" for outside world */
7904 netif_carrier_off(pAdapter->dev);
7905
7906 /* DeInit the adapter. This ensures that all data packets
7907 * are freed.
7908 */
7909 hdd_deinit_adapter(pHddCtx, pAdapter);
7910
c_hpothu5ab05e92014-06-13 17:34:05 +05307911 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
7912 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
7913 {
7914 wlan_hdd_cfg80211_deregister_frames(pAdapter);
7915 hdd_UnregisterWext(pAdapter->dev);
7916 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +05307917
Jeff Johnson295189b2012-06-20 16:38:30 -07007918 }
c_hpothu5ab05e92014-06-13 17:34:05 +05307919 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7920 pAdapterNode = pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -07007921 }
Kaushik, Sushant4975a572014-10-21 16:07:48 +05307922 // Cancel any outstanding scan requests. We are about to close all
7923 // of our adapters, but an adapter structure is what SME passes back
7924 // to our callback function. Hence if there are any outstanding scan
7925 // requests then there is a race condition between when the adapter
7926 // is closed and when the callback is invoked.We try to resolve that
7927 // race condition here by canceling any outstanding scans before we
7928 // close the adapters.
7929 // Note that the scans may be cancelled in an asynchronous manner,
7930 // so ideally there needs to be some kind of synchronization. Rather
7931 // than introduce a new synchronization here, we will utilize the
7932 // fact that we are about to Request Full Power, and since that is
7933 // synchronized, the expectation is that by the time Request Full
7934 // Power has completed all scans will be cancelled.
7935 if (pHddCtx->scan_info.mScanPending)
7936 {
7937 hddLog(VOS_TRACE_LEVEL_INFO,
7938 FL("abort scan mode: %d sessionId: %d"),
7939 pAdapter->device_mode,
7940 pAdapter->sessionId);
7941 hdd_abort_mac_scan(pHddCtx,
7942 pHddCtx->scan_info.sessionId,
7943 eCSR_SCAN_ABORT_DEFAULT);
7944 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007945 }
c_hpothu5ab05e92014-06-13 17:34:05 +05307946 else
Jeff Johnson88ba7742013-02-27 14:36:02 -08007947 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307948 hddLog(VOS_TRACE_LEVEL_INFO,"%s: FTM MODE",__func__);
Jeff Johnson88ba7742013-02-27 14:36:02 -08007949 wlan_hdd_ftm_close(pHddCtx);
7950 goto free_hdd_ctx;
7951 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307952
Jeff Johnson295189b2012-06-20 16:38:30 -07007953 /* DeRegister with platform driver as client for Suspend/Resume */
7954 vosStatus = hddDeregisterPmOps(pHddCtx);
7955 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
7956 {
7957 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDeregisterPmOps failed",__func__);
7958 VOS_ASSERT(0);
7959 }
7960
7961 vosStatus = hddDevTmUnregisterNotifyCallback(pHddCtx);
7962 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
7963 {
7964 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
7965 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007966
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07007967 //Stop the traffic monitor timer
7968 if ( VOS_TIMER_STATE_RUNNING ==
7969 vos_timer_getCurrentState(&pHddCtx->tx_rx_trafficTmr))
7970 {
7971 vos_timer_stop(&pHddCtx->tx_rx_trafficTmr);
7972 }
7973
7974 // Destroy the traffic monitor timer
7975 if (!VOS_IS_STATUS_SUCCESS(vos_timer_destroy(
7976 &pHddCtx->tx_rx_trafficTmr)))
7977 {
7978 hddLog(VOS_TRACE_LEVEL_ERROR,
7979 "%s: Cannot deallocate Traffic monitor timer", __func__);
7980 }
7981
Jeff Johnson295189b2012-06-20 16:38:30 -07007982 //Disable IMPS/BMPS as we do not want the device to enter any power
7983 //save mode during shutdown
7984 sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
7985 sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
7986 sme_DisablePowerSave(pHddCtx->hHal, ePMC_UAPSD_MODE_POWER_SAVE);
7987
7988 //Ensure that device is in full power as we will touch H/W during vos_Stop
7989 init_completion(&powerContext.completion);
7990 powerContext.magic = POWER_CONTEXT_MAGIC;
7991
7992 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_power_callback,
7993 &powerContext, eSME_FULL_PWR_NEEDED_BY_HDD);
7994
7995 if (eHAL_STATUS_SUCCESS != halStatus)
7996 {
7997 if (eHAL_STATUS_PMC_PENDING == halStatus)
7998 {
7999 /* request was sent -- wait for the response */
8000 lrc = wait_for_completion_interruptible_timeout(
8001 &powerContext.completion,
8002 msecs_to_jiffies(WLAN_WAIT_TIME_POWER));
Jeff Johnson295189b2012-06-20 16:38:30 -07008003 if (lrc <= 0)
8004 {
8005 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: %s while requesting full power",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008006 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson295189b2012-06-20 16:38:30 -07008007 }
8008 }
8009 else
8010 {
8011 hddLog(VOS_TRACE_LEVEL_ERROR,
8012 "%s: Request for Full Power failed, status %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008013 __func__, halStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07008014 /* continue -- need to clean up as much as possible */
8015 }
8016 }
8017
Jeff Johnson72a40512013-12-19 10:14:15 -08008018 /* either we never sent a request, we sent a request and received a
8019 response or we sent a request and timed out. if we never sent a
8020 request or if we sent a request and got a response, we want to
8021 clear the magic out of paranoia. if we timed out there is a
8022 race condition such that the callback function could be
8023 executing at the same time we are. of primary concern is if the
8024 callback function had already verified the "magic" but had not
8025 yet set the completion variable when a timeout occurred. we
8026 serialize these activities by invalidating the magic while
8027 holding a shared spinlock which will cause us to block if the
8028 callback is currently executing */
8029 spin_lock(&hdd_context_lock);
8030 powerContext.magic = 0;
8031 spin_unlock(&hdd_context_lock);
8032
Yue Ma0d4891e2013-08-06 17:01:45 -07008033 hdd_debugfs_exit(pHddCtx);
8034
Jeff Johnson295189b2012-06-20 16:38:30 -07008035 // Unregister the Net Device Notifier
8036 unregister_netdevice_notifier(&hdd_netdev_notifier);
8037
Jeff Johnson295189b2012-06-20 16:38:30 -07008038 hdd_stop_all_adapters( pHddCtx );
8039
Jeff Johnson295189b2012-06-20 16:38:30 -07008040#ifdef WLAN_BTAMP_FEATURE
8041 vosStatus = WLANBAP_Stop(pVosContext);
8042 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
8043 {
8044 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
8045 "%s: Failed to stop BAP",__func__);
8046 }
8047#endif //WLAN_BTAMP_FEATURE
8048
8049 //Stop all the modules
8050 vosStatus = vos_stop( pVosContext );
8051 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
8052 {
8053 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8054 "%s: Failed to stop VOSS",__func__);
8055 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
8056 }
8057
Jeff Johnson295189b2012-06-20 16:38:30 -07008058 //This requires pMac access, Call this before vos_close().
Jeff Johnson295189b2012-06-20 16:38:30 -07008059 hdd_unregister_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07008060
8061 //Close the scheduler before calling vos_close to make sure no thread is
8062 // scheduled after the each module close is called i.e after all the data
8063 // structures are freed.
8064 vosStatus = vos_sched_close( pVosContext );
8065 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
8066 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
8067 "%s: Failed to close VOSS Scheduler",__func__);
8068 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
8069 }
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008070#ifdef WLAN_OPEN_SOURCE
Jeff Johnsone7245742012-09-05 17:12:55 -07008071#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
8072 /* Destroy the wake lock */
8073 wake_lock_destroy(&pHddCtx->rx_wake_lock);
8074#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -08008075 /* Destroy the wake lock */
8076 wake_lock_destroy(&pHddCtx->sap_wake_lock);
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008077#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008078
Mihir Shete7a24b5f2013-12-21 12:18:31 +05308079#ifdef CONFIG_ENABLE_LINUX_REG
8080 vosStatus = vos_nv_close();
8081 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
8082 {
8083 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
8084 "%s: Failed to close NV", __func__);
8085 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
8086 }
8087#endif
8088
Jeff Johnson295189b2012-06-20 16:38:30 -07008089 //Close VOSS
8090 //This frees pMac(HAL) context. There should not be any call that requires pMac access after this.
8091 vos_close(pVosContext);
8092
Jeff Johnson295189b2012-06-20 16:38:30 -07008093 //Close Watchdog
8094 if(pHddCtx->cfg_ini->fIsLogpEnabled)
8095 vos_watchdog_close(pVosContext);
8096
Gopichand Nakkalaa0358482013-06-12 17:05:47 +05308097 //Clean up HDD Nlink Service
8098 send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0);
Gopichand Nakkalaa0358482013-06-12 17:05:47 +05308099
Vinay Krishna Erannad938c422014-03-10 17:14:21 +05308100#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05308101 if (pHddCtx->cfg_ini->wlanLoggingEnable)
Vinay Krishna Erannad938c422014-03-10 17:14:21 +05308102 {
8103 wlan_logging_sock_deactivate_svc();
8104 }
8105#endif
8106
Vinay Krishna Erannaef30b522014-08-26 17:48:16 +05308107#ifdef WLAN_KD_READY_NOTIFIER
8108 nl_srv_exit(pHddCtx->ptt_pid);
8109#else
8110 nl_srv_exit();
8111#endif /* WLAN_KD_READY_NOTIFIER */
8112
8113
Jeff Johnson295189b2012-06-20 16:38:30 -07008114 hdd_close_all_adapters( pHddCtx );
8115
Jeff Johnson295189b2012-06-20 16:38:30 -07008116 /* free the power on lock from platform driver */
8117 if (free_riva_power_on_lock("wlan"))
8118 {
8119 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to free power on lock",
8120 __func__);
8121 }
8122
Jeff Johnson88ba7742013-02-27 14:36:02 -08008123free_hdd_ctx:
c_hpothu78c7b602014-05-17 17:35:49 +05308124
8125 //Free up dynamically allocated members inside HDD Adapter
8126 if (pHddCtx->cfg_ini)
8127 {
8128 kfree(pHddCtx->cfg_ini);
8129 pHddCtx->cfg_ini= NULL;
8130 }
8131
Leo Changf04ddad2013-09-18 13:46:38 -07008132 /* FTM mode, WIPHY did not registered
8133 If un-register here, system crash will happen */
8134 if (VOS_FTM_MODE != hdd_get_conparam())
8135 {
8136 wiphy_unregister(wiphy) ;
8137 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008138 wiphy_free(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -07008139 if (hdd_is_ssr_required())
8140 {
8141 /* WDI timeout had happened during unload, so SSR is needed here */
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -07008142 subsystem_restart("wcnss");
Jeff Johnson295189b2012-06-20 16:38:30 -07008143 msleep(5000);
8144 }
8145 hdd_set_ssr_required (VOS_FALSE);
8146}
8147
8148
8149/**---------------------------------------------------------------------------
8150
8151 \brief hdd_update_config_from_nv() - Function to update the contents of
8152 the running configuration with parameters taken from NV storage
8153
8154 \param - pHddCtx - Pointer to the HDD global context
8155
8156 \return - VOS_STATUS_SUCCESS if successful
8157
8158 --------------------------------------------------------------------------*/
8159static VOS_STATUS hdd_update_config_from_nv(hdd_context_t* pHddCtx)
8160{
Jeff Johnson295189b2012-06-20 16:38:30 -07008161 v_BOOL_t itemIsValid = VOS_FALSE;
8162 VOS_STATUS status;
8163 v_MACADDR_t macFromNV[VOS_MAX_CONCURRENCY_PERSONA];
8164 v_U8_t macLoop;
8165
8166 /*If the NV is valid then get the macaddress from nv else get it from qcom_cfg.ini*/
8167 status = vos_nv_getValidity(VNV_FIELD_IMAGE, &itemIsValid);
8168 if(status != VOS_STATUS_SUCCESS)
8169 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008170 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_getValidity() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07008171 return VOS_STATUS_E_FAILURE;
8172 }
8173
8174 if (itemIsValid == VOS_TRUE)
8175 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008176 hddLog(VOS_TRACE_LEVEL_INFO_HIGH," Reading the Macaddress from NV");
Jeff Johnson295189b2012-06-20 16:38:30 -07008177 status = vos_nv_readMultiMacAddress((v_U8_t *)&macFromNV[0].bytes[0],
8178 VOS_MAX_CONCURRENCY_PERSONA);
8179 if(status != VOS_STATUS_SUCCESS)
8180 {
8181 /* Get MAC from NV fail, not update CFG info
8182 * INI MAC value will be used for MAC setting */
Arif Hussain6d2a3322013-11-17 19:50:10 -08008183 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_readMacAddress() failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07008184 return VOS_STATUS_E_FAILURE;
8185 }
8186
8187 /* If first MAC is not valid, treat all others are not valid
8188 * Then all MACs will be got from ini file */
8189 if(vos_is_macaddr_zero(&macFromNV[0]))
8190 {
8191 /* MAC address in NV file is not configured yet */
8192 hddLog(VOS_TRACE_LEVEL_WARN, "Invalid MAC in NV file");
8193 return VOS_STATUS_E_INVAL;
8194 }
8195
8196 /* Get MAC address from NV, update CFG info */
8197 for(macLoop = 0; macLoop < VOS_MAX_CONCURRENCY_PERSONA; macLoop++)
8198 {
8199 if(vos_is_macaddr_zero(&macFromNV[macLoop]))
8200 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308201 hddLog(VOS_TRACE_LEVEL_ERROR,"not valid MAC from NV for %d", macLoop);
Jeff Johnson295189b2012-06-20 16:38:30 -07008202 /* This MAC is not valid, skip it
8203 * This MAC will be got from ini file */
8204 }
8205 else
8206 {
8207 vos_mem_copy((v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[macLoop].bytes[0],
8208 (v_U8_t *)&macFromNV[macLoop].bytes[0],
8209 VOS_MAC_ADDR_SIZE);
8210 }
8211 }
8212 }
8213 else
8214 {
8215 hddLog(VOS_TRACE_LEVEL_ERROR, "NV ITEM, MAC Not valid");
8216 return VOS_STATUS_E_FAILURE;
8217 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008218
Jeff Johnson295189b2012-06-20 16:38:30 -07008219
8220 return VOS_STATUS_SUCCESS;
8221}
8222
8223/**---------------------------------------------------------------------------
8224
8225 \brief hdd_post_voss_start_config() - HDD post voss start config helper
8226
8227 \param - pAdapter - Pointer to the HDD
8228
8229 \return - None
8230
8231 --------------------------------------------------------------------------*/
8232VOS_STATUS hdd_post_voss_start_config(hdd_context_t* pHddCtx)
8233{
8234 eHalStatus halStatus;
8235 v_U32_t listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308236 tANI_U32 ignoreDtim;
Jeff Johnson295189b2012-06-20 16:38:30 -07008237
Jeff Johnson295189b2012-06-20 16:38:30 -07008238
8239 // Send ready indication to the HDD. This will kick off the MAC
8240 // into a 'running' state and should kick off an initial scan.
8241 halStatus = sme_HDDReadyInd( pHddCtx->hHal );
8242 if ( !HAL_STATUS_SUCCESS( halStatus ) )
8243 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05308244 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: sme_HDDReadyInd() failed with status "
Jeff Johnson295189b2012-06-20 16:38:30 -07008245 "code %08d [x%08x]",__func__, halStatus, halStatus );
8246 return VOS_STATUS_E_FAILURE;
8247 }
8248
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308249 // Set default LI and ignoreDtim into HDD context,
Jeff Johnson295189b2012-06-20 16:38:30 -07008250 // otherwise under some race condition, HDD will set 0 LI value into RIVA,
8251 // And RIVA will crash
8252 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, &listenInterval);
8253 pHddCtx->hdd_actual_LI_value = listenInterval;
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05308254 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_IGNORE_DTIM, &ignoreDtim);
8255 pHddCtx->hdd_actual_ignore_DTIM_value = ignoreDtim;
8256
8257
Jeff Johnson295189b2012-06-20 16:38:30 -07008258 return VOS_STATUS_SUCCESS;
8259}
8260
Jeff Johnson295189b2012-06-20 16:38:30 -07008261/* wake lock APIs for HDD */
8262void hdd_prevent_suspend(void)
8263{
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008264#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07008265 wake_lock(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07008266#else
8267 wcnss_prevent_suspend();
8268#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008269}
8270
8271void hdd_allow_suspend(void)
8272{
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008273#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07008274 wake_unlock(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07008275#else
8276 wcnss_allow_suspend();
8277#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008278}
8279
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05308280void hdd_prevent_suspend_timeout(v_U32_t timeout)
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07008281{
Sameer Thalappil50dc0092013-02-19 17:23:33 -08008282#ifdef WLAN_OPEN_SOURCE
Amar Singhal6144c002013-05-03 16:11:42 -07008283 wake_lock_timeout(&wlan_wake_lock, msecs_to_jiffies(timeout));
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07008284#else
8285 /* Do nothing as there is no API in wcnss for timeout*/
8286#endif
8287}
8288
Jeff Johnson295189b2012-06-20 16:38:30 -07008289/**---------------------------------------------------------------------------
8290
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008291 \brief hdd_exchange_version_and_caps() - HDD function to exchange version and capability
8292 information between Host and Riva
8293
8294 This function gets reported version of FW
8295 It also finds the version of Riva headers used to compile the host
8296 It compares the above two and prints a warning if they are different
8297 It gets the SW and HW version string
8298 Finally, it exchanges capabilities between host and Riva i.e. host and riva exchange a msg
8299 indicating the features they support through a bitmap
8300
8301 \param - pHddCtx - Pointer to HDD context
8302
8303 \return - void
8304
8305 --------------------------------------------------------------------------*/
8306
8307void hdd_exchange_version_and_caps(hdd_context_t *pHddCtx)
8308{
8309
8310 tSirVersionType versionCompiled;
8311 tSirVersionType versionReported;
8312 tSirVersionString versionString;
8313 tANI_U8 fwFeatCapsMsgSupported = 0;
8314 VOS_STATUS vstatus;
8315
Mingcheng Zhu87f22fc2014-01-30 19:23:32 -08008316 memset(&versionCompiled, 0, sizeof(versionCompiled));
8317 memset(&versionReported, 0, sizeof(versionReported));
8318
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008319 /* retrieve and display WCNSS version information */
8320 do {
8321
8322 vstatus = sme_GetWcnssWlanCompiledVersion(pHddCtx->hHal,
8323 &versionCompiled);
8324 if (!VOS_IS_STATUS_SUCCESS(vstatus))
8325 {
8326 hddLog(VOS_TRACE_LEVEL_FATAL,
8327 "%s: unable to retrieve WCNSS WLAN compiled version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008328 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008329 break;
8330 }
8331
8332 vstatus = sme_GetWcnssWlanReportedVersion(pHddCtx->hHal,
8333 &versionReported);
8334 if (!VOS_IS_STATUS_SUCCESS(vstatus))
8335 {
8336 hddLog(VOS_TRACE_LEVEL_FATAL,
8337 "%s: unable to retrieve WCNSS WLAN reported version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008338 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008339 break;
8340 }
8341
8342 if ((versionCompiled.major != versionReported.major) ||
8343 (versionCompiled.minor != versionReported.minor) ||
8344 (versionCompiled.version != versionReported.version) ||
8345 (versionCompiled.revision != versionReported.revision))
8346 {
8347 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
8348 "Host expected %u.%u.%u.%u\n",
8349 WLAN_MODULE_NAME,
8350 (int)versionReported.major,
8351 (int)versionReported.minor,
8352 (int)versionReported.version,
8353 (int)versionReported.revision,
8354 (int)versionCompiled.major,
8355 (int)versionCompiled.minor,
8356 (int)versionCompiled.version,
8357 (int)versionCompiled.revision);
8358 }
8359 else
8360 {
8361 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
8362 WLAN_MODULE_NAME,
8363 (int)versionReported.major,
8364 (int)versionReported.minor,
8365 (int)versionReported.version,
8366 (int)versionReported.revision);
8367 }
8368
8369 vstatus = sme_GetWcnssSoftwareVersion(pHddCtx->hHal,
8370 versionString,
8371 sizeof(versionString));
8372 if (!VOS_IS_STATUS_SUCCESS(vstatus))
8373 {
8374 hddLog(VOS_TRACE_LEVEL_FATAL,
8375 "%s: unable to retrieve WCNSS software version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008376 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008377 break;
8378 }
8379
8380 pr_info("%s: WCNSS software version %s\n",
8381 WLAN_MODULE_NAME, versionString);
8382
8383 vstatus = sme_GetWcnssHardwareVersion(pHddCtx->hHal,
8384 versionString,
8385 sizeof(versionString));
8386 if (!VOS_IS_STATUS_SUCCESS(vstatus))
8387 {
8388 hddLog(VOS_TRACE_LEVEL_FATAL,
8389 "%s: unable to retrieve WCNSS hardware version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008390 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008391 break;
8392 }
8393
8394 pr_info("%s: WCNSS hardware version %s\n",
8395 WLAN_MODULE_NAME, versionString);
8396
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07008397 /* 1.Check if FW version is greater than 0.1.1.0. Only then send host-FW capability exchange message
8398 2.Host-FW capability exchange message is only present on riva 1.1 so
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008399 send the message only if it the riva is 1.1
8400 minor numbers for different riva branches:
8401 0 -> (1.0)Mainline Build
8402 1 -> (1.1)Mainline Build
8403 2->(1.04) Stability Build
8404 */
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07008405 if (((versionReported.major>0) || (versionReported.minor>1) ||
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008406 ((versionReported.minor>=1) && (versionReported.version>=1)))
8407 && ((versionReported.major == 1) && (versionReported.minor >= 1)))
8408 fwFeatCapsMsgSupported = 1;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07008409
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008410 if (fwFeatCapsMsgSupported)
Yathish9f22e662012-12-10 14:21:35 -08008411 {
8412#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
8413 if(!pHddCtx->cfg_ini->fEnableActiveModeOffload)
8414 sme_disableFeatureCapablity(WLANACTIVE_OFFLOAD);
8415#endif
Ravi Joshid2ca7c42013-07-23 08:37:49 -07008416 /* Indicate if IBSS heartbeat monitoring needs to be offloaded */
8417 if (!pHddCtx->cfg_ini->enableIbssHeartBeatOffload)
8418 {
8419 sme_disableFeatureCapablity(IBSS_HEARTBEAT_OFFLOAD);
8420 }
8421
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008422 sme_featureCapsExchange(pHddCtx->hHal);
Yathish9f22e662012-12-10 14:21:35 -08008423 }
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008424
8425 } while (0);
8426
8427}
Neelansh Mittaledafed22014-09-04 18:54:39 +05308428void wlan_hdd_send_svc_nlink_msg(int type, void *data, int len)
8429{
8430 struct sk_buff *skb;
8431 struct nlmsghdr *nlh;
8432 tAniMsgHdr *ani_hdr;
8433
8434 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), GFP_KERNEL);
8435
8436 if(skb == NULL) {
8437 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8438 "%s: alloc_skb failed", __func__);
8439 return;
8440 }
8441
8442 nlh = (struct nlmsghdr *)skb->data;
8443 nlh->nlmsg_pid = 0; /* from kernel */
8444 nlh->nlmsg_flags = 0;
8445 nlh->nlmsg_seq = 0;
8446 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
8447
8448 ani_hdr = NLMSG_DATA(nlh);
8449 ani_hdr->type = type;
8450
8451 switch(type) {
8452 case WLAN_SVC_SAP_RESTART_IND:
8453 ani_hdr->length = 0;
8454 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
8455 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr)));
8456 break;
8457 default:
8458 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8459 "Attempt to send unknown nlink message %d", type);
8460 kfree_skb(skb);
8461 return;
8462 }
8463
8464 nl_srv_bcast(skb);
8465
8466 return;
8467}
8468
8469
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07008470
8471/**---------------------------------------------------------------------------
8472
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308473 \brief hdd_is_5g_supported() - HDD function to know if hardware supports 5GHz
8474
8475 \param - pHddCtx - Pointer to the hdd context
8476
8477 \return - true if hardware supports 5GHz
8478
8479 --------------------------------------------------------------------------*/
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +05308480boolean hdd_is_5g_supported(hdd_context_t * pHddCtx)
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308481{
8482 /* If wcnss_wlan_iris_xo_mode() returns WCNSS_XO_48MHZ(1);
8483 * then hardware support 5Ghz.
8484 */
8485 if (WCNSS_XO_48MHZ == wcnss_wlan_iris_xo_mode())
8486 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308487 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Hardware supports 5Ghz", __func__);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308488 return true;
8489 }
8490 else
8491 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308492 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Hardware doesn't supports 5Ghz",
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308493 __func__);
8494 return false;
8495 }
8496}
8497
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308498/**---------------------------------------------------------------------------
8499
8500 \brief hdd_generate_iface_mac_addr_auto() - HDD Mac Interface Auto
8501 generate function
8502
8503 This is generate the random mac address for WLAN interface
8504
8505 \param - pHddCtx - Pointer to HDD context
8506 idx - Start interface index to get auto
8507 generated mac addr.
8508 mac_addr - Mac address
8509
8510 \return - 0 for success, < 0 for failure
8511
8512 --------------------------------------------------------------------------*/
8513
8514static int hdd_generate_iface_mac_addr_auto(hdd_context_t *pHddCtx,
8515 int idx, v_MACADDR_t mac_addr)
8516{
8517 int i;
8518 unsigned int serialno;
8519 serialno = wcnss_get_serial_number();
8520
8521 if (0 != serialno)
8522 {
8523 /* MAC address has 3 bytes of OUI so we have a maximum of 3
8524 bytes of the serial number that can be used to generate
8525 the other 3 bytes of the MAC address. Mask off all but
8526 the lower 3 bytes (this will also make sure we don't
8527 overflow in the next step) */
8528 serialno &= 0x00FFFFFF;
8529
8530 /* we need a unique address for each session */
8531 serialno *= VOS_MAX_CONCURRENCY_PERSONA;
8532
8533 /* autogen other Mac addresses */
8534 for (i = idx; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
8535 {
8536 /* start with the entire default address */
8537 pHddCtx->cfg_ini->intfMacAddr[i] = mac_addr;
8538 /* then replace the lower 3 bytes */
8539 pHddCtx->cfg_ini->intfMacAddr[i].bytes[3] = (serialno >> 16) & 0xFF;
8540 pHddCtx->cfg_ini->intfMacAddr[i].bytes[4] = (serialno >> 8) & 0xFF;
8541 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] = serialno & 0xFF;
8542
8543 serialno++;
8544 hddLog(VOS_TRACE_LEVEL_ERROR,
8545 "%s: Derived Mac Addr: "
8546 MAC_ADDRESS_STR, __func__,
8547 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[i].bytes));
8548 }
8549
8550 }
8551 else
8552 {
8553 hddLog(LOGE, FL("Failed to Get Serial NO"));
8554 return -1;
8555 }
8556 return 0;
8557}
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308558
8559/**---------------------------------------------------------------------------
8560
Mihir Shetefc7ff5b2014-01-27 11:30:05 +05308561 \brief hdd_11d_scan_done - callback to be executed when 11d scan is
8562 completed to flush out the scan results
8563
8564 11d scan is done during driver load and is a passive scan on all
8565 channels supported by the device, 11d scans may find some APs on
8566 frequencies which are forbidden to be used in the regulatory domain
8567 the device is operating in. If these APs are notified to the supplicant
8568 it may try to connect to these APs, thus flush out all the scan results
8569 which are present in SME after 11d scan is done.
8570
8571 \return - eHalStatus
8572
8573 --------------------------------------------------------------------------*/
8574static eHalStatus hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
8575 tANI_U32 scanId, eCsrScanStatus status)
8576{
8577 ENTER();
8578
8579 sme_ScanFlushResult(halHandle, 0);
8580
8581 EXIT();
8582
8583 return eHAL_STATUS_SUCCESS;
8584}
8585
8586/**---------------------------------------------------------------------------
8587
Jeff Johnson295189b2012-06-20 16:38:30 -07008588 \brief hdd_wlan_startup() - HDD init function
8589
8590 This is the driver startup code executed once a WLAN device has been detected
8591
8592 \param - dev - Pointer to the underlying device
8593
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08008594 \return - 0 for success, < 0 for failure
Jeff Johnson295189b2012-06-20 16:38:30 -07008595
8596 --------------------------------------------------------------------------*/
8597
8598int hdd_wlan_startup(struct device *dev )
8599{
8600 VOS_STATUS status;
8601 hdd_adapter_t *pAdapter = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07008602 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008603 hdd_context_t *pHddCtx = NULL;
8604 v_CONTEXT_t pVosContext= NULL;
8605#ifdef WLAN_BTAMP_FEATURE
8606 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
8607 WLANBAP_ConfigType btAmpConfig;
8608 hdd_config_t *pConfig;
8609#endif
8610 int ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07008611 struct wiphy *wiphy;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308612 v_MACADDR_t mac_addr;
Jeff Johnson295189b2012-06-20 16:38:30 -07008613
8614 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07008615 /*
8616 * cfg80211: wiphy allocation
8617 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05308618 wiphy = wlan_hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t)) ;
Jeff Johnson295189b2012-06-20 16:38:30 -07008619
8620 if(wiphy == NULL)
8621 {
8622 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08008623 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07008624 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008625 pHddCtx = wiphy_priv(wiphy);
8626
Jeff Johnson295189b2012-06-20 16:38:30 -07008627 //Initialize the adapter context to zeros.
8628 vos_mem_zero(pHddCtx, sizeof( hdd_context_t ));
8629
Jeff Johnson295189b2012-06-20 16:38:30 -07008630 pHddCtx->wiphy = wiphy;
Jeff Johnson295189b2012-06-20 16:38:30 -07008631 hdd_prevent_suspend();
Mihir Shete18156292014-03-11 15:38:30 +05308632 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_LOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008633
8634 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
8635
8636 /*Get vos context here bcoz vos_open requires it*/
8637 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
8638
Madan Mohan Koyyalamudi0b78e152012-11-28 15:46:51 -08008639 if(pVosContext == NULL)
8640 {
8641 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed vos_get_global_context",__func__);
8642 goto err_free_hdd_context;
8643 }
8644
Jeff Johnson295189b2012-06-20 16:38:30 -07008645 //Save the Global VOSS context in adapter context for future.
8646 pHddCtx->pvosContext = pVosContext;
8647
8648 //Save the adapter context in global context for future.
8649 ((VosContextType*)(pVosContext))->pHDDContext = (v_VOID_t*)pHddCtx;
8650
Jeff Johnson295189b2012-06-20 16:38:30 -07008651 pHddCtx->parent_dev = dev;
8652
8653 init_completion(&pHddCtx->full_pwr_comp_var);
8654 init_completion(&pHddCtx->standby_comp_var);
8655 init_completion(&pHddCtx->req_bmps_comp_var);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07008656 init_completion(&pHddCtx->scan_info.scan_req_completion_event);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08008657 init_completion(&pHddCtx->scan_info.abortscan_event_var);
Kiet Lam46b8e4e2013-11-06 21:49:53 +05308658 init_completion(&pHddCtx->wiphy_channel_update_event);
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05308659 init_completion(&pHddCtx->ssr_comp_var);
Amar Singhala49cbc52013-10-08 18:37:44 -07008660
8661#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhalfddc28c2013-09-05 13:03:40 -07008662 init_completion(&pHddCtx->linux_reg_req);
Amar Singhala49cbc52013-10-08 18:37:44 -07008663#else
8664 init_completion(&pHddCtx->driver_crda_req);
8665#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008666
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308667 spin_lock_init(&pHddCtx->schedScan_lock);
8668
Jeff Johnson295189b2012-06-20 16:38:30 -07008669 hdd_list_init( &pHddCtx->hddAdapters, MAX_NUMBER_OF_ADAPTERS );
8670
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308671#ifdef FEATURE_WLAN_TDLS
8672 /* tdls_lock is initialized before an hdd_open_adapter ( which is
8673 * invoked by other instances also) to protect the concurrent
8674 * access for the Adapters by TDLS module.
8675 */
8676 mutex_init(&pHddCtx->tdls_lock);
8677#endif
Siddharth Bhal76972212014-10-15 16:22:51 +05308678 mutex_init(&pHddCtx->spoofMacAddr.macSpoofingLock);
Agarwal Ashish1f422872014-07-22 00:11:55 +05308679 /* By default Strict Regulatory For FCC should be false */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308680
Agarwal Ashish1f422872014-07-22 00:11:55 +05308681 pHddCtx->nEnableStrictRegulatoryForFCC = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07008682 // Load all config first as TL config is needed during vos_open
8683 pHddCtx->cfg_ini = (hdd_config_t*) kmalloc(sizeof(hdd_config_t), GFP_KERNEL);
8684 if(pHddCtx->cfg_ini == NULL)
8685 {
8686 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed kmalloc hdd_config_t",__func__);
8687 goto err_free_hdd_context;
8688 }
8689
8690 vos_mem_zero(pHddCtx->cfg_ini, sizeof( hdd_config_t ));
8691
8692 // Read and parse the qcom_cfg.ini file
8693 status = hdd_parse_config_ini( pHddCtx );
8694 if ( VOS_STATUS_SUCCESS != status )
8695 {
8696 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: error parsing %s",
8697 __func__, WLAN_INI_FILE);
8698 goto err_config;
8699 }
Arif Hussaind5218912013-12-05 01:10:55 -08008700#ifdef MEMORY_DEBUG
8701 if (pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled)
8702 vos_mem_init();
8703
8704 hddLog(VOS_TRACE_LEVEL_INFO, "%s: gEnableMemoryDebug=%d",
8705 __func__, pHddCtx->cfg_ini->IsMemoryDebugSupportEnabled);
8706#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008707
Gopichand Nakkalab8f0f1a2013-05-23 18:19:48 +05308708 /* INI has been read, initialise the configuredMcastBcastFilter with
8709 * INI value as this will serve as the default value
8710 */
8711 pHddCtx->configuredMcastBcastFilter = pHddCtx->cfg_ini->mcastBcastFilterSetting;
8712 hddLog(VOS_TRACE_LEVEL_INFO, "Setting configuredMcastBcastFilter: %d",
8713 pHddCtx->cfg_ini->mcastBcastFilterSetting);
Gopichand Nakkalafce506f2013-07-03 23:55:16 +05308714
8715 if (false == hdd_is_5g_supported(pHddCtx))
8716 {
8717 //5Ghz is not supported.
8718 if (1 != pHddCtx->cfg_ini->nBandCapability)
8719 {
8720 hddLog(VOS_TRACE_LEVEL_INFO,
8721 "%s: Setting pHddCtx->cfg_ini->nBandCapability = 1", __func__);
8722 pHddCtx->cfg_ini->nBandCapability = 1;
8723 }
8724 }
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308725
8726 /* If SNR Monitoring is enabled, FW has to parse all beacons
8727 * for calcaluting and storing the average SNR, so set Nth beacon
8728 * filter to 1 to enable FW to parse all the beaocons
8729 */
8730 if (1 == pHddCtx->cfg_ini->fEnableSNRMonitoring)
8731 {
8732 /* The log level is deliberately set to WARN as overriding
8733 * nthBeaconFilter to 1 will increase power cosumption and this
8734 * might just prove helpful to detect the power issue.
8735 */
8736 hddLog(VOS_TRACE_LEVEL_WARN,
8737 "%s: Setting pHddCtx->cfg_ini->nthBeaconFilter = 1", __func__);
8738 pHddCtx->cfg_ini->nthBeaconFilter = 1;
8739 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008740 /*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05308741 * cfg80211: Initialization ...
Jeff Johnson295189b2012-06-20 16:38:30 -07008742 */
Manjunathappa Prakasheec4ddf2014-01-13 18:23:51 -08008743 if (VOS_FTM_MODE != hdd_get_conparam())
Jeff Johnson295189b2012-06-20 16:38:30 -07008744 {
Manjunathappa Prakasheec4ddf2014-01-13 18:23:51 -08008745 if (0 < wlan_hdd_cfg80211_init(dev, wiphy, pHddCtx->cfg_ini))
8746 {
8747 hddLog(VOS_TRACE_LEVEL_FATAL,
8748 "%s: wlan_hdd_cfg80211_init return failure", __func__);
8749 goto err_config;
8750 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008751 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008752
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08008753 // Update VOS trace levels based upon the cfg.ini
8754 hdd_vos_trace_enable(VOS_MODULE_ID_BAP,
8755 pHddCtx->cfg_ini->vosTraceEnableBAP);
8756 hdd_vos_trace_enable(VOS_MODULE_ID_TL,
8757 pHddCtx->cfg_ini->vosTraceEnableTL);
8758 hdd_vos_trace_enable(VOS_MODULE_ID_WDI,
8759 pHddCtx->cfg_ini->vosTraceEnableWDI);
8760 hdd_vos_trace_enable(VOS_MODULE_ID_HDD,
8761 pHddCtx->cfg_ini->vosTraceEnableHDD);
8762 hdd_vos_trace_enable(VOS_MODULE_ID_SME,
8763 pHddCtx->cfg_ini->vosTraceEnableSME);
8764 hdd_vos_trace_enable(VOS_MODULE_ID_PE,
8765 pHddCtx->cfg_ini->vosTraceEnablePE);
Katya Nigam70d68332013-09-16 16:49:45 +05308766 hdd_vos_trace_enable(VOS_MODULE_ID_PMC,
8767 pHddCtx->cfg_ini->vosTraceEnablePMC);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08008768 hdd_vos_trace_enable(VOS_MODULE_ID_WDA,
8769 pHddCtx->cfg_ini->vosTraceEnableWDA);
8770 hdd_vos_trace_enable(VOS_MODULE_ID_SYS,
8771 pHddCtx->cfg_ini->vosTraceEnableSYS);
8772 hdd_vos_trace_enable(VOS_MODULE_ID_VOSS,
8773 pHddCtx->cfg_ini->vosTraceEnableVOSS);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08008774 hdd_vos_trace_enable(VOS_MODULE_ID_SAP,
8775 pHddCtx->cfg_ini->vosTraceEnableSAP);
8776 hdd_vos_trace_enable(VOS_MODULE_ID_HDD_SOFTAP,
8777 pHddCtx->cfg_ini->vosTraceEnableHDDSAP);
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08008778
Jeff Johnson295189b2012-06-20 16:38:30 -07008779 // Update WDI trace levels based upon the cfg.ini
8780 hdd_wdi_trace_enable(eWLAN_MODULE_DAL,
8781 pHddCtx->cfg_ini->wdiTraceEnableDAL);
8782 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_CTRL,
8783 pHddCtx->cfg_ini->wdiTraceEnableCTL);
8784 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_DATA,
8785 pHddCtx->cfg_ini->wdiTraceEnableDAT);
8786 hdd_wdi_trace_enable(eWLAN_MODULE_PAL,
8787 pHddCtx->cfg_ini->wdiTraceEnablePAL);
Jeff Johnson295189b2012-06-20 16:38:30 -07008788
Jeff Johnson88ba7742013-02-27 14:36:02 -08008789 if (VOS_FTM_MODE == hdd_get_conparam())
8790 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008791 if ( VOS_STATUS_SUCCESS != wlan_hdd_ftm_open(pHddCtx) )
8792 {
8793 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_ftm_open Failed",__func__);
8794 goto err_free_hdd_context;
8795 }
8796 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: FTM driver loaded success fully",__func__);
c_hpothu2de0ef62014-04-15 16:16:15 +05308797
8798 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -07008799 return VOS_STATUS_SUCCESS;
Jeff Johnson88ba7742013-02-27 14:36:02 -08008800 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008801
Jeff Johnson88ba7742013-02-27 14:36:02 -08008802 //Open watchdog module
Jeff Johnson295189b2012-06-20 16:38:30 -07008803 if(pHddCtx->cfg_ini->fIsLogpEnabled)
8804 {
8805 status = vos_watchdog_open(pVosContext,
8806 &((VosContextType*)pVosContext)->vosWatchdog, sizeof(VosWatchdogContext));
8807
8808 if(!VOS_IS_STATUS_SUCCESS( status ))
8809 {
8810 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_watchdog_open failed",__func__);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05308811 goto err_wdclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07008812 }
8813 }
8814
8815 pHddCtx->isLogpInProgress = FALSE;
8816 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
8817
Amar Singhala49cbc52013-10-08 18:37:44 -07008818#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -07008819 /* initialize the NV module. This is required so that
8820 we can initialize the channel information in wiphy
8821 from the NV.bin data. The channel information in
8822 wiphy needs to be initialized before wiphy registration */
8823
8824 status = vos_nv_open();
8825 if (!VOS_IS_STATUS_SUCCESS(status))
8826 {
8827 /* NV module cannot be initialized */
8828 hddLog( VOS_TRACE_LEVEL_FATAL,
8829 "%s: vos_nv_open failed", __func__);
Vinay Krishna Eranna2025d892014-09-18 16:51:42 +05308830 goto err_wdclose;
Amar Singhal0a402232013-10-11 20:57:16 -07008831 }
8832
8833 status = vos_init_wiphy_from_nv_bin();
8834 if (!VOS_IS_STATUS_SUCCESS(status))
8835 {
8836 /* NV module cannot be initialized */
8837 hddLog( VOS_TRACE_LEVEL_FATAL,
8838 "%s: vos_init_wiphy failed", __func__);
8839 goto err_vos_nv_close;
8840 }
8841
Amar Singhala49cbc52013-10-08 18:37:44 -07008842#endif
8843
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +05308844 status = vos_open( &pVosContext, pHddCtx->parent_dev);
Jeff Johnson295189b2012-06-20 16:38:30 -07008845 if ( !VOS_IS_STATUS_SUCCESS( status ))
8846 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008847 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_open failed", __func__);
Mihir Shetee1093ba2014-01-21 20:13:32 +05308848 goto err_vos_nv_close;
Jeff Johnson295189b2012-06-20 16:38:30 -07008849 }
8850
Jeff Johnson295189b2012-06-20 16:38:30 -07008851 pHddCtx->hHal = (tHalHandle)vos_get_context( VOS_MODULE_ID_SME, pVosContext );
8852
8853 if ( NULL == pHddCtx->hHal )
8854 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008855 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: HAL context is null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07008856 goto err_vosclose;
8857 }
8858
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008859 status = vos_preStart( pHddCtx->pvosContext );
8860 if ( !VOS_IS_STATUS_SUCCESS( status ) )
8861 {
8862 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: vos_preStart failed", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308863 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008864 }
Jeff Johnsone7245742012-09-05 17:12:55 -07008865
Arif Hussaineaf68602013-12-30 23:10:44 -08008866 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan)
8867 {
8868 pHddCtx->cfg_ini->enableDFSChnlScan = enable_dfs_chan_scan;
8869 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_dfs_chan_scan set to %d",
8870 __func__, enable_dfs_chan_scan);
8871 }
8872 if (0 == enable_11d || 1 == enable_11d)
8873 {
8874 pHddCtx->cfg_ini->Is11dSupportEnabled = enable_11d;
8875 hddLog(VOS_TRACE_LEVEL_INFO, "%s: module enable_11d set to %d",
8876 __func__, enable_11d);
8877 }
8878
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008879 /* Note that the vos_preStart() sequence triggers the cfg download.
8880 The cfg download must occur before we update the SME config
8881 since the SME config operation must access the cfg database */
Jeff Johnson295189b2012-06-20 16:38:30 -07008882 status = hdd_set_sme_config( pHddCtx );
8883
8884 if ( VOS_STATUS_SUCCESS != status )
8885 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008886 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed hdd_set_sme_config", __func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308887 goto err_vosclose;
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008888 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008889
Jeff Johnson295189b2012-06-20 16:38:30 -07008890 /* In the integrated architecture we update the configuration from
8891 the INI file and from NV before vOSS has been started so that
8892 the final contents are available to send down to the cCPU */
8893
8894 // Apply the cfg.ini to cfg.dat
8895 if (FALSE == hdd_update_config_dat(pHddCtx))
8896 {
8897 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308898 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07008899 }
8900
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308901 // Get mac addr from platform driver
8902 ret = wcnss_get_wlan_mac_address((char*)&mac_addr.bytes);
8903
8904 if ((0 == ret) && (!vos_is_macaddr_zero(&mac_addr)))
Jeff Johnson295189b2012-06-20 16:38:30 -07008905 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308906 /* Store the mac addr for first interface */
8907 pHddCtx->cfg_ini->intfMacAddr[0] = mac_addr;
8908
8909 hddLog(VOS_TRACE_LEVEL_ERROR,
8910 "%s: WLAN Mac Addr: "
8911 MAC_ADDRESS_STR, __func__,
8912 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
8913
8914 /* Here, passing Arg2 as 1 because we do not want to change the
8915 last 3 bytes (means non OUI bytes) of first interface mac
8916 addr.
8917 */
8918 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 1, mac_addr))
8919 {
8920 hddLog(VOS_TRACE_LEVEL_ERROR,
8921 "%s: Failed to generate wlan interface mac addr "
8922 "using MAC from ini file ", __func__);
8923 }
8924 }
8925 else if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
8926 {
8927 // Apply the NV to cfg.dat
8928 /* Prima Update MAC address only at here */
Jeff Johnson295189b2012-06-20 16:38:30 -07008929#ifdef WLAN_AUTOGEN_MACADDR_FEATURE
8930 /* There was not a valid set of MAC Addresses in NV. See if the
8931 default addresses were modified by the cfg.ini settings. If so,
8932 we'll use them, but if not, we'll autogenerate a set of MAC
8933 addresses based upon the device serial number */
8934
8935 static const v_MACADDR_t default_address =
8936 {{0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}};
Jeff Johnson295189b2012-06-20 16:38:30 -07008937
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308938 if (0 == memcmp(&default_address, &pHddCtx->cfg_ini->intfMacAddr[0],
8939 sizeof(default_address)))
Jeff Johnson295189b2012-06-20 16:38:30 -07008940 {
8941 /* cfg.ini has the default address, invoke autogen logic */
8942
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308943 /* Here, passing Arg2 as 0 because we want to change the
8944 last 3 bytes (means non OUI bytes) of all the interfaces
8945 mac addr.
8946 */
8947 if (0 != hdd_generate_iface_mac_addr_auto(pHddCtx, 0,
8948 default_address))
Jeff Johnson295189b2012-06-20 16:38:30 -07008949 {
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308950 hddLog(VOS_TRACE_LEVEL_ERROR,
8951 "%s: Failed to generate wlan interface mac addr "
8952 "using MAC from ini file " MAC_ADDRESS_STR, __func__,
8953 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
Jeff Johnson295189b2012-06-20 16:38:30 -07008954 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008955 }
8956 else
8957#endif //WLAN_AUTOGEN_MACADDR_FEATURE
8958 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08008959 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07008960 "%s: Invalid MAC address in NV, using MAC from ini file "
8961 MAC_ADDRESS_STR, __func__,
8962 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
8963 }
8964 }
8965 {
8966 eHalStatus halStatus;
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308967
8968 /* Set the MAC Address Currently this is used by HAL to
8969 * add self sta. Remove this once self sta is added as
8970 * part of session open.
8971 */
Jeff Johnson295189b2012-06-20 16:38:30 -07008972 halStatus = cfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
8973 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
8974 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]) );
Hardik Kantilal Patel4d7982a2013-12-02 18:53:30 +05308975
Jeff Johnson295189b2012-06-20 16:38:30 -07008976 if (!HAL_STATUS_SUCCESS( halStatus ))
8977 {
8978 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
8979 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308980 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07008981 }
8982 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008983
8984 /*Start VOSS which starts up the SME/MAC/HAL modules and everything else
8985 Note: Firmware image will be read and downloaded inside vos_start API */
8986 status = vos_start( pHddCtx->pvosContext );
8987 if ( !VOS_IS_STATUS_SUCCESS( status ) )
8988 {
8989 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05308990 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07008991 }
8992
Leo Chang6cec3e22014-01-21 15:33:49 -08008993#ifdef FEATURE_WLAN_CH_AVOID
8994 /* Plug in avoid channel notification callback
8995 * This should happen before ADD_SELF_STA
8996 * FW will send first IND with ADD_SELF_STA REQ from host */
Pradeep Reddy POTTETI5c2e16d2014-06-27 16:47:38 +05308997
8998 /* check the Channel Avoidance is enabled */
8999 if (TRUE == pHddCtx->cfg_ini->fenableCHAvoidance)
9000 {
9001 sme_AddChAvoidCallback(pHddCtx->hHal,
9002 hdd_hostapd_ch_avoid_cb);
9003 }
Leo Chang6cec3e22014-01-21 15:33:49 -08009004#endif /* FEATURE_WLAN_CH_AVOID */
9005
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07009006 /* Exchange capability info between Host and FW and also get versioning info from FW */
9007 hdd_exchange_version_and_caps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07009008
Agarwal Ashishad9281b2014-06-10 14:57:30 +05309009#ifdef CONFIG_ENABLE_LINUX_REG
9010 status = wlan_hdd_init_channels(pHddCtx);
9011 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9012 {
9013 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels failed",
9014 __func__);
9015 goto err_vosstop;
9016 }
9017#endif
9018
Jeff Johnson295189b2012-06-20 16:38:30 -07009019 status = hdd_post_voss_start_config( pHddCtx );
9020 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9021 {
9022 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_post_voss_start_config failed",
9023 __func__);
9024 goto err_vosstop;
9025 }
Amar Singhala49cbc52013-10-08 18:37:44 -07009026
9027#ifndef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05309028 wlan_hdd_cfg80211_update_reg_info( wiphy );
9029
9030 /* registration of wiphy dev with cfg80211 */
9031 if (0 > wlan_hdd_cfg80211_register(wiphy))
9032 {
9033 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
9034 goto err_vosstop;
9035 }
Amar Singhala49cbc52013-10-08 18:37:44 -07009036#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009037
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05309038#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05309039 /* registration of wiphy dev with cfg80211 */
9040 if (0 > wlan_hdd_cfg80211_register(wiphy))
9041 {
9042 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
9043 goto err_vosstop;
9044 }
9045
Agarwal Ashish6db9d532014-09-30 18:19:10 +05309046 status = wlan_hdd_init_channels_for_cc(pHddCtx, INIT);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05309047 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9048 {
9049 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: wlan_hdd_init_channels_for_cc failed",
9050 __func__);
9051 goto err_unregister_wiphy;
9052 }
9053#endif
9054
Jeff Johnson295189b2012-06-20 16:38:30 -07009055 if (VOS_STA_SAP_MODE == hdd_get_conparam())
9056 {
9057 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP, "softap.%d",
9058 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
9059 }
9060 else
9061 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009062 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_INFRA_STATION, "wlan%d",
9063 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
9064 if (pAdapter != NULL)
9065 {
Katya Nigama7d81d72014-11-12 12:44:34 +05309066 if (pHddCtx->cfg_ini->isP2pDeviceAddrAdministrated && !(pHddCtx->cfg_ini->intfMacAddr[0].bytes[0] & 0x02))
Jeff Johnson295189b2012-06-20 16:38:30 -07009067 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05309068 vos_mem_copy( pHddCtx->p2pDeviceAddress.bytes,
9069 pHddCtx->cfg_ini->intfMacAddr[0].bytes,
9070 sizeof(tSirMacAddr));
Madan Mohan Koyyalamudiedfc1b72012-10-18 20:25:55 -07009071
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05309072 /* Generate the P2P Device Address. This consists of the device's
9073 * primary MAC address with the locally administered bit set.
9074 */
9075 pHddCtx->p2pDeviceAddress.bytes[0] |= 0x02;
Jeff Johnsone7245742012-09-05 17:12:55 -07009076 }
9077 else
9078 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05309079 tANI_U8* p2p_dev_addr = wlan_hdd_get_intf_addr(pHddCtx);
9080 if (p2p_dev_addr != NULL)
9081 {
9082 vos_mem_copy(&pHddCtx->p2pDeviceAddress.bytes[0],
9083 p2p_dev_addr, VOS_MAC_ADDR_SIZE);
9084 }
9085 else
9086 {
9087 hddLog(VOS_TRACE_LEVEL_FATAL,
9088 "%s: Failed to allocate mac_address for p2p_device",
9089 __func__);
9090 goto err_close_adapter;
9091 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009092 }
Jeff Johnsone7245742012-09-05 17:12:55 -07009093
9094 pP2pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_P2P_DEVICE, "p2p%d",
9095 &pHddCtx->p2pDeviceAddress.bytes[0], FALSE );
9096 if ( NULL == pP2pAdapter )
9097 {
9098 hddLog(VOS_TRACE_LEVEL_FATAL,
9099 "%s: Failed to do hdd_open_adapter for P2P Device Interface",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07009100 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07009101 goto err_close_adapter;
9102 }
Jeff Johnsone7245742012-09-05 17:12:55 -07009103 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009104 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009105
9106 if( pAdapter == NULL )
9107 {
Jeff Johnsonbc676b42013-02-14 16:04:08 -08009108 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", __func__);
9109 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07009110 }
Jeff Johnsone7245742012-09-05 17:12:55 -07009111
Arif Hussain66559122013-11-21 10:11:40 -08009112 if (country_code)
9113 {
9114 eHalStatus ret;
Arif Hussaincb607082013-12-20 11:57:42 -08009115 INIT_COMPLETION(pAdapter->change_country_code);
Arif Hussain66559122013-11-21 10:11:40 -08009116 hdd_checkandupdate_dfssetting(pAdapter, country_code);
9117#ifndef CONFIG_ENABLE_LINUX_REG
9118 hdd_checkandupdate_phymode(pAdapter, country_code);
9119#endif
Arif Hussaineaf68602013-12-30 23:10:44 -08009120 ret = sme_ChangeCountryCode(pHddCtx->hHal,
9121 (void *)(tSmeChangeCountryCallback)
9122 wlan_hdd_change_country_code_callback,
Arif Hussain66559122013-11-21 10:11:40 -08009123 country_code,
9124 pAdapter, pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +05309125 eSIR_TRUE, eSIR_TRUE);
Arif Hussain66559122013-11-21 10:11:40 -08009126 if (eHAL_STATUS_SUCCESS == ret)
9127 {
Arif Hussaincb607082013-12-20 11:57:42 -08009128 ret = wait_for_completion_interruptible_timeout(
9129 &pAdapter->change_country_code,
9130 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
9131
9132 if (0 >= ret)
9133 {
9134 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9135 "%s: SME while setting country code timed out", __func__);
9136 }
Arif Hussain66559122013-11-21 10:11:40 -08009137 }
9138 else
9139 {
Arif Hussaincb607082013-12-20 11:57:42 -08009140 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9141 "%s: SME Change Country code from module param fail ret=%d",
9142 __func__, ret);
Arif Hussain66559122013-11-21 10:11:40 -08009143 }
9144 }
9145
Jeff Johnson295189b2012-06-20 16:38:30 -07009146#ifdef WLAN_BTAMP_FEATURE
9147 vStatus = WLANBAP_Open(pVosContext);
9148 if(!VOS_IS_STATUS_SUCCESS(vStatus))
9149 {
9150 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9151 "%s: Failed to open BAP",__func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07009152 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07009153 }
9154
9155 vStatus = BSL_Init(pVosContext);
9156 if(!VOS_IS_STATUS_SUCCESS(vStatus))
9157 {
9158 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9159 "%s: Failed to Init BSL",__func__);
9160 goto err_bap_close;
9161 }
9162 vStatus = WLANBAP_Start(pVosContext);
9163 if (!VOS_IS_STATUS_SUCCESS(vStatus))
9164 {
9165 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9166 "%s: Failed to start TL",__func__);
9167 goto err_bap_close;
9168 }
9169
9170 pConfig = pHddCtx->cfg_ini;
9171 btAmpConfig.ucPreferredChannel = pConfig->preferredChannel;
9172 status = WLANBAP_SetConfig(&btAmpConfig);
9173
9174#endif //WLAN_BTAMP_FEATURE
Jeff Johnsone7245742012-09-05 17:12:55 -07009175
Mihir Shete9c238772014-10-15 14:35:16 +05309176 /*
9177 * UapsdMask is 0xf if U-APSD is enbaled for all AC's...
9178 * The value of CFG_QOS_WMM_UAPSD_MASK_DEFAULT is 0xaa(Magic Value)
9179 * which is greater than 0xf. So the below check is safe to make
9180 * sure that there is no entry for UapsdMask in the ini
9181 */
9182 if (CFG_QOS_WMM_UAPSD_MASK_DEFAULT == pHddCtx->cfg_ini->UapsdMask)
9183 {
9184 if(IS_DYNAMIC_WMM_PS_ENABLED)
9185 {
9186 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Enable UAPSD for VI & VO",
9187 __func__);
9188 pHddCtx->cfg_ini->UapsdMask =
9189 CFG_QOS_WMM_UAPSD_MASK_DYMANIC_WMM_PS_DEFAULT;
9190 }
9191 else
9192 {
9193 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: Do not enable UAPSD",
9194 __func__);
9195 pHddCtx->cfg_ini->UapsdMask =
9196 CFG_QOS_WMM_UAPSD_MASK_LEGACY_WMM_PS_DEFAULT;
9197 }
9198 }
9199
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07009200#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
9201 if(!(IS_ROAM_SCAN_OFFLOAD_FEATURE_ENABLE))
9202 {
9203 hddLog(VOS_TRACE_LEVEL_DEBUG,"%s: ROAM_SCAN_OFFLOAD Feature not supported",__func__);
9204 pHddCtx->cfg_ini->isRoamOffloadScanEnabled = 0;
9205 sme_UpdateRoamScanOffloadEnabled((tHalHandle)(pHddCtx->hHal),
9206 pHddCtx->cfg_ini->isRoamOffloadScanEnabled);
9207 }
9208#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009209
Agarwal Ashish4b87f922014-06-18 03:03:21 +05309210 wlan_hdd_tdls_init(pHddCtx);
9211
Mihir Shetefc7ff5b2014-01-27 11:30:05 +05309212 sme_Register11dScanDoneCallback(pHddCtx->hHal, hdd_11d_scan_done);
9213
Jeff Johnson295189b2012-06-20 16:38:30 -07009214 /* Register with platform driver as client for Suspend/Resume */
9215 status = hddRegisterPmOps(pHddCtx);
9216 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9217 {
9218 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddRegisterPmOps failed",__func__);
9219#ifdef WLAN_BTAMP_FEATURE
9220 goto err_bap_stop;
9221#else
Jeff Johnsone7245742012-09-05 17:12:55 -07009222 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07009223#endif //WLAN_BTAMP_FEATURE
9224 }
9225
Yue Ma0d4891e2013-08-06 17:01:45 -07009226 /* Open debugfs interface */
9227 if (VOS_STATUS_SUCCESS != hdd_debugfs_init(pAdapter))
9228 {
9229 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
9230 "%s: hdd_debugfs_init failed!", __func__);
Yue Ma0d4891e2013-08-06 17:01:45 -07009231 }
9232
Jeff Johnson295189b2012-06-20 16:38:30 -07009233 /* Register TM level change handler function to the platform */
9234 status = hddDevTmRegisterNotifyCallback(pHddCtx);
9235 if ( !VOS_IS_STATUS_SUCCESS( status ) )
9236 {
9237 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmRegisterNotifyCallback failed",__func__);
9238 goto err_unregister_pmops;
9239 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009240
9241 /* register for riva power on lock to platform driver */
9242 if (req_riva_power_on_lock("wlan"))
9243 {
9244 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: req riva power on lock failed",
9245 __func__);
9246 goto err_unregister_pmops;
9247 }
9248
Jeff Johnson295189b2012-06-20 16:38:30 -07009249 // register net device notifier for device change notification
9250 ret = register_netdevice_notifier(&hdd_netdev_notifier);
9251
9252 if(ret < 0)
9253 {
9254 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: register_netdevice_notifier failed",__func__);
9255 goto err_free_power_on_lock;
9256 }
9257
9258 //Initialize the nlink service
9259 if(nl_srv_init() != 0)
9260 {
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05309261 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: nl_srv_init failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009262 goto err_reg_netdev;
9263 }
9264
Leo Chang4ce1cc52013-10-21 18:27:15 -07009265#ifdef WLAN_KD_READY_NOTIFIER
9266 pHddCtx->kd_nl_init = 1;
9267#endif /* WLAN_KD_READY_NOTIFIER */
9268
Jeff Johnson295189b2012-06-20 16:38:30 -07009269 //Initialize the BTC service
9270 if(btc_activate_service(pHddCtx) != 0)
9271 {
9272 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: btc_activate_service failed",__func__);
9273 goto err_nl_srv;
9274 }
9275
9276#ifdef PTT_SOCK_SVC_ENABLE
9277 //Initialize the PTT service
9278 if(ptt_sock_activate_svc(pHddCtx) != 0)
9279 {
9280 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: ptt_sock_activate_svc failed",__func__);
9281 goto err_nl_srv;
9282 }
9283#endif
9284
Vinay Krishna Erannad938c422014-03-10 17:14:21 +05309285#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9286 if(pHddCtx->cfg_ini && pHddCtx->cfg_ini->wlanLoggingEnable)
9287 {
Deepthi Gowri78083a32014-11-04 12:55:51 +05309288 if(wlan_logging_sock_activate_svc(
9289 pHddCtx->cfg_ini->wlanLoggingFEToConsole,
9290 pHddCtx->cfg_ini->wlanLoggingNumBuf))
9291 {
9292 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wlan_logging_sock_activate_svc"
9293 " failed", __func__);
9294 goto err_nl_srv;
9295 }
9296 //TODO: To Remove enableDhcpDebug and use gEnableDebugLog for
9297 //EAPOL and DHCP
9298 pHddCtx->cfg_ini->enableDhcpDebug = CFG_DEBUG_DHCP_ENABLE;
9299 pHddCtx->cfg_ini->gEnableDebugLog = VOS_PKT_PROTO_TYPE_EAPOL;
Vinay Krishna Erannad938c422014-03-10 17:14:21 +05309300 }
9301#endif
9302
Jeff Johnson295189b2012-06-20 16:38:30 -07009303 hdd_register_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07009304 if (VOS_STA_SAP_MODE != hdd_get_conparam())
Jeff Johnson295189b2012-06-20 16:38:30 -07009305 {
Madan Mohan Koyyalamudic537df22012-10-22 15:07:08 -07009306 /* Action frame registered in one adapter which will
9307 * applicable to all interfaces
9308 */
Agarwal Ashish8fa0e9a2014-05-23 00:40:12 +05309309 wlan_hdd_cfg80211_register_frames(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07009310 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009311
9312 mutex_init(&pHddCtx->sap_lock);
Mahesh A Saptasagar60627942014-10-13 13:55:14 +05309313 mutex_init(&pHddCtx->roc_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07009314
Jeff Johnson295189b2012-06-20 16:38:30 -07009315
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009316#ifdef WLAN_OPEN_SOURCE
Jeff Johnsone7245742012-09-05 17:12:55 -07009317#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
9318 /* Initialize the wake lcok */
9319 wake_lock_init(&pHddCtx->rx_wake_lock,
9320 WAKE_LOCK_SUSPEND,
9321 "qcom_rx_wakelock");
9322#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -08009323 /* Initialize the wake lcok */
9324 wake_lock_init(&pHddCtx->sap_wake_lock,
9325 WAKE_LOCK_SUSPEND,
9326 "qcom_sap_wakelock");
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009327#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07009328
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07009329 vos_event_init(&pHddCtx->scan_info.scan_finished_event);
9330 pHddCtx->scan_info.scan_pending_option = WEXT_SCAN_PENDING_GIVEUP;
Jeff Johnson295189b2012-06-20 16:38:30 -07009331
Katya Nigam5c306ea2014-06-19 15:39:54 +05309332 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_NO_LOAD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07009333 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
9334 hdd_allow_suspend();
Katya Nigam5c306ea2014-06-19 15:39:54 +05309335
9336#ifdef FEATURE_WLAN_SCAN_PNO
9337 /*SME must send channel update configuration to RIVA*/
9338 sme_UpdateChannelConfig(pHddCtx->hHal);
9339#endif
Abhishek Singhf644b272014-08-21 02:59:39 +05309340 /* Send the update default channel list to the FW*/
9341 sme_UpdateChannelList(pHddCtx->hHal);
Abhishek Singha306a442013-11-07 18:39:01 +05309342#ifndef CONFIG_ENABLE_LINUX_REG
9343 /*updating wiphy so that regulatory user hints can be processed*/
9344 if (wiphy)
9345 {
9346 regulatory_hint(wiphy, "00");
9347 }
9348#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07009349 // Initialize the restart logic
9350 wlan_hdd_restart_init(pHddCtx);
Chilam NG571c65a2013-01-19 12:27:36 +05309351
Sudhir Sattayappa Kohalli37620692013-08-05 14:02:26 -07009352 //Register the traffic monitor timer now
9353 if ( pHddCtx->cfg_ini->dynSplitscan)
9354 {
9355 vos_timer_init(&pHddCtx->tx_rx_trafficTmr,
9356 VOS_TIMER_TYPE_SW,
9357 hdd_tx_rx_pkt_cnt_stat_timer_handler,
9358 (void *)pHddCtx);
9359 }
Dino Mycle6fb96c12014-06-10 11:52:40 +05309360#ifdef WLAN_FEATURE_EXTSCAN
9361 sme_EXTScanRegisterCallback(pHddCtx->hHal,
9362 wlan_hdd_cfg80211_extscan_callback,
9363 pHddCtx);
9364#endif /* WLAN_FEATURE_EXTSCAN */
Jeff Johnson295189b2012-06-20 16:38:30 -07009365 goto success;
9366
9367err_nl_srv:
Leo Chang59cdc7e2013-07-10 10:08:21 -07009368#ifdef WLAN_KD_READY_NOTIFIER
9369 nl_srv_exit(pHddCtx->ptt_pid);
9370#else
Jeff Johnson295189b2012-06-20 16:38:30 -07009371 nl_srv_exit();
Leo Chang59cdc7e2013-07-10 10:08:21 -07009372#endif /* WLAN_KD_READY_NOTIFIER */
Jeff Johnson295189b2012-06-20 16:38:30 -07009373err_reg_netdev:
9374 unregister_netdevice_notifier(&hdd_netdev_notifier);
9375
9376err_free_power_on_lock:
9377 free_riva_power_on_lock("wlan");
9378
9379err_unregister_pmops:
9380 hddDevTmUnregisterNotifyCallback(pHddCtx);
9381 hddDeregisterPmOps(pHddCtx);
9382
Yue Ma0d4891e2013-08-06 17:01:45 -07009383 hdd_debugfs_exit(pHddCtx);
9384
Jeff Johnson295189b2012-06-20 16:38:30 -07009385#ifdef WLAN_BTAMP_FEATURE
9386err_bap_stop:
9387 WLANBAP_Stop(pVosContext);
9388#endif
9389
9390#ifdef WLAN_BTAMP_FEATURE
9391err_bap_close:
9392 WLANBAP_Close(pVosContext);
9393#endif
9394
Jeff Johnson295189b2012-06-20 16:38:30 -07009395err_close_adapter:
9396 hdd_close_all_adapters( pHddCtx );
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +05309397#ifdef CONFIG_ENABLE_LINUX_REG
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +05309398err_unregister_wiphy:
Mahesh A Saptasagar9ecefe42014-07-15 18:43:49 +05309399#endif
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05309400 wiphy_unregister(wiphy) ;
Jeff Johnson295189b2012-06-20 16:38:30 -07009401err_vosstop:
9402 vos_stop(pVosContext);
9403
Amar Singhala49cbc52013-10-08 18:37:44 -07009404err_vosclose:
Jeff Johnson295189b2012-06-20 16:38:30 -07009405 status = vos_sched_close( pVosContext );
9406 if (!VOS_IS_STATUS_SUCCESS(status)) {
9407 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
9408 "%s: Failed to close VOSS Scheduler", __func__);
9409 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
9410 }
Amar Singhala49cbc52013-10-08 18:37:44 -07009411 vos_close(pVosContext );
9412
Amar Singhal0a402232013-10-11 20:57:16 -07009413err_vos_nv_close:
9414
c_hpothue6a36282014-03-19 12:27:38 +05309415#ifdef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -07009416 vos_nv_close();
9417
c_hpothu70f8d812014-03-22 22:59:23 +05309418#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009419
9420err_wdclose:
9421 if(pHddCtx->cfg_ini->fIsLogpEnabled)
9422 vos_watchdog_close(pVosContext);
9423
Jeff Johnson295189b2012-06-20 16:38:30 -07009424err_config:
9425 kfree(pHddCtx->cfg_ini);
9426 pHddCtx->cfg_ini= NULL;
9427
9428err_free_hdd_context:
9429 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07009430 wiphy_free(wiphy) ;
9431 //kfree(wdev) ;
Jeff Johnson295189b2012-06-20 16:38:30 -07009432 VOS_BUG(1);
9433
Madan Mohan Koyyalamudid57ae632012-11-06 18:42:48 -08009434 if (hdd_is_ssr_required())
9435 {
9436 /* WDI timeout had happened during load, so SSR is needed here */
9437 subsystem_restart("wcnss");
9438 msleep(5000);
9439 }
9440 hdd_set_ssr_required (VOS_FALSE);
9441
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08009442 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07009443
9444success:
9445 EXIT();
9446 return 0;
9447}
9448
9449/**---------------------------------------------------------------------------
9450
Jeff Johnson32d95a32012-09-10 13:15:23 -07009451 \brief hdd_driver_init() - Core Driver Init Function
Jeff Johnson295189b2012-06-20 16:38:30 -07009452
Jeff Johnson32d95a32012-09-10 13:15:23 -07009453 This is the driver entry point - called in different timeline depending
9454 on whether the driver is statically or dynamically linked
Jeff Johnson295189b2012-06-20 16:38:30 -07009455
9456 \param - None
9457
9458 \return - 0 for success, non zero for failure
9459
9460 --------------------------------------------------------------------------*/
Jeff Johnson32d95a32012-09-10 13:15:23 -07009461static int hdd_driver_init( void)
Jeff Johnson295189b2012-06-20 16:38:30 -07009462{
9463 VOS_STATUS status;
9464 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07009465 struct device *dev = NULL;
9466 int ret_status = 0;
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -07009467#ifdef HAVE_WCNSS_CAL_DOWNLOAD
9468 int max_retries = 0;
9469#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009470
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309471#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9472 wlan_logging_sock_init_svc();
9473#endif
9474
Jeff Johnson295189b2012-06-20 16:38:30 -07009475 ENTER();
9476
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009477#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07009478 wake_lock_init(&wlan_wake_lock, WAKE_LOCK_SUSPEND, "wlan");
Jeff Johnsone7245742012-09-05 17:12:55 -07009479#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009480
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05309481 hddTraceInit();
Jeff Johnson295189b2012-06-20 16:38:30 -07009482 pr_info("%s: loading driver v%s\n", WLAN_MODULE_NAME,
9483 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
9484
Jeff Johnson295189b2012-06-20 16:38:30 -07009485#ifdef ANI_BUS_TYPE_PCI
9486
9487 dev = wcnss_wlan_get_device();
9488
9489#endif // ANI_BUS_TYPE_PCI
9490
9491#ifdef ANI_BUS_TYPE_PLATFORM
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -07009492
9493#ifdef HAVE_WCNSS_CAL_DOWNLOAD
9494 /* wait until WCNSS driver downloads NV */
9495 while (!wcnss_device_ready() && 5 >= ++max_retries) {
9496 msleep(1000);
9497 }
9498 if (max_retries >= 5) {
9499 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WCNSS driver not ready", __func__);
madan mohan koyyalamudi8c96ce12013-07-10 19:14:39 +05309500#ifdef WLAN_OPEN_SOURCE
9501 wake_lock_destroy(&wlan_wake_lock);
9502#endif
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309503
9504#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9505 wlan_logging_sock_deinit_svc();
9506#endif
9507
Sameer Thalappilf58d7ec2013-04-25 20:17:12 -07009508 return -ENODEV;
9509 }
9510#endif
9511
Jeff Johnson295189b2012-06-20 16:38:30 -07009512 dev = wcnss_wlan_get_device();
9513#endif // ANI_BUS_TYPE_PLATFORM
9514
9515
9516 do {
9517 if (NULL == dev) {
9518 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: WLAN device not found!!",__func__);
9519 ret_status = -1;
9520 break;
9521 }
9522
Jeff Johnson295189b2012-06-20 16:38:30 -07009523#ifdef TIMER_MANAGER
9524 vos_timer_manager_init();
9525#endif
9526
9527 /* Preopen VOSS so that it is ready to start at least SAL */
9528 status = vos_preOpen(&pVosContext);
9529
9530 if (!VOS_IS_STATUS_SUCCESS(status))
9531 {
9532 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to preOpen VOSS", __func__);
9533 ret_status = -1;
9534 break;
9535 }
9536
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009537#ifndef MODULE
9538 /* For statically linked driver, call hdd_set_conparam to update curr_con_mode
9539 */
9540 hdd_set_conparam((v_UINT_t)con_mode);
9541#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009542
9543 // Call our main init function
Jeff Johnsonbc676b42013-02-14 16:04:08 -08009544 if (hdd_wlan_startup(dev))
9545 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009546 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WLAN Driver Initialization failed",
Jeff Johnsonbc676b42013-02-14 16:04:08 -08009547 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07009548 vos_preClose( &pVosContext );
9549 ret_status = -1;
9550 break;
9551 }
9552
Jeff Johnson295189b2012-06-20 16:38:30 -07009553 } while (0);
9554
9555 if (0 != ret_status)
9556 {
Jeff Johnson295189b2012-06-20 16:38:30 -07009557#ifdef TIMER_MANAGER
9558 vos_timer_exit();
9559#endif
9560#ifdef MEMORY_DEBUG
9561 vos_mem_exit();
9562#endif
9563
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009564#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07009565 wake_lock_destroy(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07009566#endif
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309567
9568#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9569 wlan_logging_sock_deinit_svc();
9570#endif
9571
Jeff Johnson295189b2012-06-20 16:38:30 -07009572 pr_err("%s: driver load failure\n", WLAN_MODULE_NAME);
9573 }
9574 else
9575 {
9576 //Send WLAN UP indication to Nlink Service
9577 send_btc_nlink_msg(WLAN_MODULE_UP_IND, 0);
9578
9579 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Jeff Johnson295189b2012-06-20 16:38:30 -07009580 }
9581
9582 EXIT();
9583
9584 return ret_status;
9585}
9586
Jeff Johnson32d95a32012-09-10 13:15:23 -07009587/**---------------------------------------------------------------------------
9588
9589 \brief hdd_module_init() - Init Function
9590
9591 This is the driver entry point (invoked when module is loaded using insmod)
9592
9593 \param - None
9594
9595 \return - 0 for success, non zero for failure
9596
9597 --------------------------------------------------------------------------*/
9598#ifdef MODULE
9599static int __init hdd_module_init ( void)
9600{
9601 return hdd_driver_init();
9602}
Jeff Johnson32d95a32012-09-10 13:15:23 -07009603#else /* #ifdef MODULE */
9604static int __init hdd_module_init ( void)
9605{
9606 /* Driver initialization is delayed to fwpath_changed_handler */
9607 return 0;
9608}
Jeff Johnson32d95a32012-09-10 13:15:23 -07009609#endif /* #ifdef MODULE */
9610
Jeff Johnson295189b2012-06-20 16:38:30 -07009611
9612/**---------------------------------------------------------------------------
9613
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009614 \brief hdd_driver_exit() - Exit function
Jeff Johnson295189b2012-06-20 16:38:30 -07009615
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009616 This is the driver exit point (invoked when module is unloaded using rmmod
9617 or con_mode was changed by userspace)
Jeff Johnson295189b2012-06-20 16:38:30 -07009618
9619 \param - None
9620
9621 \return - None
9622
9623 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009624static void hdd_driver_exit(void)
Jeff Johnson295189b2012-06-20 16:38:30 -07009625{
9626 hdd_context_t *pHddCtx = NULL;
9627 v_CONTEXT_t pVosContext = NULL;
Agarwal Ashish5e414792014-06-08 15:25:23 +05309628 v_REGDOMAIN_t regId;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05309629 unsigned long rc = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07009630
9631 pr_info("%s: unloading driver v%s\n", WLAN_MODULE_NAME, QWLAN_VERSIONSTR);
9632
9633 //Get the global vos context
9634 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
9635
9636 if(!pVosContext)
9637 {
9638 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
9639 goto done;
9640 }
9641
9642 //Get the HDD context.
9643 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
9644
9645 if(!pHddCtx)
9646 {
9647 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: module exit called before probe",__func__);
9648 }
9649 else
9650 {
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05309651 INIT_COMPLETION(pHddCtx->ssr_comp_var);
9652
9653 if (pHddCtx->isLogpInProgress)
9654 {
Sameer Thalappil451ebb92013-06-28 15:49:58 -07009655 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05309656 "%s:SSR in Progress; block rmmod !!!", __func__);
9657 rc = wait_for_completion_timeout(&pHddCtx->ssr_comp_var,
9658 msecs_to_jiffies(30000));
9659 if(!rc)
9660 {
9661 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9662 "%s:SSR timedout, fatal error", __func__);
9663 VOS_BUG(0);
Sameer Thalappil451ebb92013-06-28 15:49:58 -07009664 }
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +05309665 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009666
Vinay Krishna Erannae362b452014-09-23 13:09:46 +05309667 rtnl_lock();
Mihir Shete18156292014-03-11 15:38:30 +05309668 pHddCtx->isLoadUnloadInProgress = WLAN_HDD_UNLOAD_IN_PROGRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07009669 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
Vinay Krishna Erannae362b452014-09-23 13:09:46 +05309670 rtnl_unlock();
Jeff Johnson295189b2012-06-20 16:38:30 -07009671
Agarwal Ashish8db39882014-07-30 21:56:07 +05309672 /* Driver Need to send country code 00 in below condition
9673 * 1) If gCountryCodePriority is set to 1; and last country
9674 * code set is through 11d. This needs to be done in case
9675 * when NV country code is 00.
9676 * This Needs to be done as when kernel store last country
9677 * code and if stored country code is not through 11d,
9678 * in sme_HandleChangeCountryCodeByUser we will disable 11d
9679 * in next load/unload as soon as we get any country through
9680 * 11d. In sme_HandleChangeCountryCodeByUser
9681 * pMsg->countryCode will be last countryCode and
9682 * pMac->scan.countryCode11d will be country through 11d so
9683 * due to mismatch driver will disable 11d.
9684 *
Agarwal Ashish8db39882014-07-30 21:56:07 +05309685 */
9686
9687 if ((eANI_BOOLEAN_TRUE == sme_Is11dCountrycode(pHddCtx->hHal) &&
Agarwal Ashish8dcd2862014-07-25 11:58:52 +05309688 pHddCtx->cfg_ini->fSupplicantCountryCodeHasPriority &&
Abhishek Singh2a705962014-10-30 14:47:28 +05309689 sme_Is11dSupported(pHddCtx->hHal)))
Agarwal Ashish5e414792014-06-08 15:25:23 +05309690 {
Agarwal Ashish8dcd2862014-07-25 11:58:52 +05309691 hddLog(VOS_TRACE_LEVEL_INFO,
9692 FL("CountryCode 00 is being set while unloading driver"));
Agarwal Ashish5e414792014-06-08 15:25:23 +05309693 vos_nv_getRegDomainFromCountryCode(&regId , "00", COUNTRY_USER);
9694 }
9695
Jeff Johnson295189b2012-06-20 16:38:30 -07009696 //Do all the cleanup before deregistering the driver
9697 hdd_wlan_exit(pHddCtx);
9698 }
9699
Jeff Johnson295189b2012-06-20 16:38:30 -07009700 vos_preClose( &pVosContext );
9701
9702#ifdef TIMER_MANAGER
9703 vos_timer_exit();
9704#endif
9705#ifdef MEMORY_DEBUG
9706 vos_mem_exit();
9707#endif
9708
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309709#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9710 wlan_logging_sock_deinit_svc();
9711#endif
9712
Jeff Johnson295189b2012-06-20 16:38:30 -07009713done:
Sameer Thalappil50dc0092013-02-19 17:23:33 -08009714#ifdef WLAN_OPEN_SOURCE
Jeff Johnson295189b2012-06-20 16:38:30 -07009715 wake_lock_destroy(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07009716#endif
Vinay Krishna Eranna273ec5a2014-05-10 18:05:25 +05309717
Jeff Johnson295189b2012-06-20 16:38:30 -07009718 pr_info("%s: driver unloaded\n", WLAN_MODULE_NAME);
9719}
9720
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009721/**---------------------------------------------------------------------------
9722
9723 \brief hdd_module_exit() - Exit function
9724
9725 This is the driver exit point (invoked when module is unloaded using rmmod)
9726
9727 \param - None
9728
9729 \return - None
9730
9731 --------------------------------------------------------------------------*/
9732static void __exit hdd_module_exit(void)
9733{
9734 hdd_driver_exit();
9735}
9736
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009737#ifdef MODULE
9738static int fwpath_changed_handler(const char *kmessage,
9739 struct kernel_param *kp)
9740{
Jeff Johnson76052702013-04-16 13:55:05 -07009741 return param_set_copystring(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009742}
9743
9744static int con_mode_handler(const char *kmessage,
9745 struct kernel_param *kp)
9746{
Madan Mohan Koyyalamudif2f8d8b2012-10-11 17:06:59 -07009747 return param_set_int(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009748}
9749#else /* #ifdef MODULE */
9750/**---------------------------------------------------------------------------
9751
Jeff Johnson76052702013-04-16 13:55:05 -07009752 \brief kickstart_driver
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009753
Jeff Johnson76052702013-04-16 13:55:05 -07009754 This is the driver entry point
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009755 - delayed driver initialization when driver is statically linked
Jeff Johnson76052702013-04-16 13:55:05 -07009756 - invoked when module parameter fwpath is modified from userspace to signal
9757 initializing the WLAN driver or when con_mode is modified from userspace
9758 to signal a switch in operating mode
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009759
9760 \return - 0 for success, non zero for failure
9761
9762 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -07009763static int kickstart_driver(void)
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009764{
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07009765 int ret_status;
9766
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009767 if (!wlan_hdd_inited) {
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07009768 ret_status = hdd_driver_init();
9769 wlan_hdd_inited = ret_status ? 0 : 1;
9770 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009771 }
9772
9773 hdd_driver_exit();
Jeff Johnson76052702013-04-16 13:55:05 -07009774
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009775 msleep(200);
Jeff Johnson76052702013-04-16 13:55:05 -07009776
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07009777 ret_status = hdd_driver_init();
9778 wlan_hdd_inited = ret_status ? 0 : 1;
9779 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07009780}
9781
Jeff Johnson295189b2012-06-20 16:38:30 -07009782/**---------------------------------------------------------------------------
9783
Jeff Johnson76052702013-04-16 13:55:05 -07009784 \brief fwpath_changed_handler() - Handler Function
9785
9786 Handle changes to the fwpath parameter
9787
9788 \return - 0 for success, non zero for failure
9789
9790 --------------------------------------------------------------------------*/
9791static int fwpath_changed_handler(const char *kmessage,
9792 struct kernel_param *kp)
9793{
9794 int ret;
9795
9796 ret = param_set_copystring(kmessage, kp);
9797 if (0 == ret)
9798 ret = kickstart_driver();
9799 return ret;
9800}
9801
9802/**---------------------------------------------------------------------------
9803
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009804 \brief con_mode_handler() -
9805
9806 Handler function for module param con_mode when it is changed by userspace
9807 Dynamically linked - do nothing
9808 Statically linked - exit and init driver, as in rmmod and insmod
9809
Jeff Johnson76052702013-04-16 13:55:05 -07009810 \param -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009811
Jeff Johnson76052702013-04-16 13:55:05 -07009812 \return -
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009813
9814 --------------------------------------------------------------------------*/
Jeff Johnson76052702013-04-16 13:55:05 -07009815static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009816{
Jeff Johnson76052702013-04-16 13:55:05 -07009817 int ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009818
Jeff Johnson76052702013-04-16 13:55:05 -07009819 ret = param_set_int(kmessage, kp);
9820 if (0 == ret)
9821 ret = kickstart_driver();
9822 return ret;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009823}
9824#endif /* #ifdef MODULE */
9825
9826/**---------------------------------------------------------------------------
9827
Jeff Johnson295189b2012-06-20 16:38:30 -07009828 \brief hdd_get_conparam() -
9829
9830 This is the driver exit point (invoked when module is unloaded using rmmod)
9831
9832 \param - None
9833
9834 \return - tVOS_CON_MODE
9835
9836 --------------------------------------------------------------------------*/
9837tVOS_CON_MODE hdd_get_conparam ( void )
9838{
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009839#ifdef MODULE
Jeff Johnson295189b2012-06-20 16:38:30 -07009840 return (tVOS_CON_MODE)con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009841#else
9842 return (tVOS_CON_MODE)curr_con_mode;
9843#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009844}
9845void hdd_set_conparam ( v_UINT_t newParam )
9846{
9847 con_mode = newParam;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07009848#ifndef MODULE
9849 curr_con_mode = con_mode;
9850#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009851}
9852/**---------------------------------------------------------------------------
9853
9854 \brief hdd_softap_sta_deauth() - function
9855
9856 This to take counter measure to handle deauth req from HDD
9857
9858 \param - pAdapter - Pointer to the HDD
9859
9860 \param - enable - boolean value
9861
9862 \return - None
9863
9864 --------------------------------------------------------------------------*/
9865
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309866VOS_STATUS hdd_softap_sta_deauth(hdd_adapter_t *pAdapter,
9867 struct tagCsrDelStaParams *pDelStaParams)
Jeff Johnson295189b2012-06-20 16:38:30 -07009868{
Jeff Johnson295189b2012-06-20 16:38:30 -07009869 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08009870 VOS_STATUS vosStatus = VOS_STATUS_E_FAULT;
Jeff Johnson295189b2012-06-20 16:38:30 -07009871
9872 ENTER();
9873
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07009874 hddLog(LOG1, "hdd_softap_sta_deauth:(%p, false)",
9875 (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07009876
9877 //Ignore request to deauth bcmc station
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309878 if (pDelStaParams->peerMacAddr[0] & 0x1)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08009879 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -07009880
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309881 vosStatus = WLANSAP_DeauthSta(pVosContext, pDelStaParams);
Jeff Johnson295189b2012-06-20 16:38:30 -07009882
9883 EXIT();
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08009884 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -07009885}
9886
9887/**---------------------------------------------------------------------------
9888
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309889 \brief hdd_del_all_sta() - function
9890
9891 This function removes all the stations associated on stopping AP/P2P GO.
9892
9893 \param - pAdapter - Pointer to the HDD
9894
9895 \return - None
9896
9897 --------------------------------------------------------------------------*/
9898
9899int hdd_del_all_sta(hdd_adapter_t *pAdapter)
9900{
9901 v_U16_t i;
9902 VOS_STATUS vos_status;
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +05309903 v_CONTEXT_t pVosContext = ( WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
9904 ptSapContext pSapCtx = NULL;
9905 pSapCtx = VOS_GET_SAP_CB(pVosContext);
9906 if(pSapCtx == NULL){
9907 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9908 FL("psapCtx is NULL"));
9909 return 1;
9910 }
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309911 ENTER();
9912
9913 hddLog(VOS_TRACE_LEVEL_INFO,
9914 "%s: Delete all STAs associated.",__func__);
9915 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
9916 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
9917 )
9918 {
9919 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
9920 {
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +05309921 if ((pSapCtx->aStaInfo[i].isUsed) &&
9922 (!pSapCtx->aStaInfo[i].isDeauthInProgress))
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309923 {
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309924 struct tagCsrDelStaParams delStaParams;
9925
9926 WLANSAP_PopulateDelStaParams(
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +05309927 pSapCtx->aStaInfo[i].macAddrSTA.bytes,
Hanumantha Reddy Pothulabfd06f72014-10-31 14:03:37 +05309928 eCsrForcedDeauthSta, SIR_MAC_MGMT_DEAUTH >> 4,
9929 &delStaParams);
9930 vos_status = hdd_softap_sta_deauth(pAdapter, &delStaParams);
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309931 if (VOS_IS_STATUS_SUCCESS(vos_status))
Sachin Ahujabcb0b7e2014-11-07 13:01:24 +05309932 pSapCtx->aStaInfo[i].isDeauthInProgress = TRUE;
Rashmi Ramanna1f0948d2014-08-28 15:33:48 +05309933 }
9934 }
9935 }
9936
9937 EXIT();
9938 return 0;
9939}
9940
9941/**---------------------------------------------------------------------------
9942
Jeff Johnson295189b2012-06-20 16:38:30 -07009943 \brief hdd_softap_sta_disassoc() - function
9944
9945 This to take counter measure to handle deauth req from HDD
9946
9947 \param - pAdapter - Pointer to the HDD
9948
9949 \param - enable - boolean value
9950
9951 \return - None
9952
9953 --------------------------------------------------------------------------*/
9954
9955void hdd_softap_sta_disassoc(hdd_adapter_t *pAdapter,v_U8_t *pDestMacAddress)
9956{
9957 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
9958
9959 ENTER();
9960
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05309961 hddLog( LOGE, "hdd_softap_sta_disassoc:(%p, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07009962
9963 //Ignore request to disassoc bcmc station
9964 if( pDestMacAddress[0] & 0x1 )
9965 return;
9966
9967 WLANSAP_DisassocSta(pVosContext,pDestMacAddress);
9968}
9969
9970void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *pAdapter,v_BOOL_t enable)
9971{
9972 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
9973
9974 ENTER();
9975
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05309976 hddLog( LOGE, "hdd_softap_tkip_mic_fail_counter_measure:(%p, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07009977
9978 WLANSAP_SetCounterMeasure(pVosContext, (v_BOOL_t)enable);
9979}
9980
Jeff Johnson295189b2012-06-20 16:38:30 -07009981/**---------------------------------------------------------------------------
9982 *
9983 * \brief hdd_get__concurrency_mode() -
9984 *
9985 *
9986 * \param - None
9987 *
9988 * \return - CONCURRENCY MODE
9989 *
9990 * --------------------------------------------------------------------------*/
9991tVOS_CONCURRENCY_MODE hdd_get_concurrency_mode ( void )
9992{
9993 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
9994 hdd_context_t *pHddCtx;
9995
9996 if (NULL != pVosContext)
9997 {
9998 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
9999 if (NULL != pHddCtx)
10000 {
10001 return (tVOS_CONCURRENCY_MODE)pHddCtx->concurrency_mode;
10002 }
10003 }
10004
10005 /* we are in an invalid state :( */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070010006 hddLog(LOGE, "%s: Invalid context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070010007 return VOS_STA;
10008}
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010009v_BOOL_t
10010wlan_hdd_is_GO_power_collapse_allowed (hdd_context_t* pHddCtx)
10011{
10012 hdd_adapter_t *pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -070010013
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010014 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_GO);
10015 if (pAdapter == NULL)
10016 {
10017 hddLog(VOS_TRACE_LEVEL_INFO,
10018 FL("GO doesn't exist"));
10019 return TRUE;
10020 }
10021 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
10022 {
10023 hddLog(VOS_TRACE_LEVEL_INFO,
10024 FL("GO started"));
10025 return TRUE;
10026 }
10027 else
10028 /* wait till GO changes its interface to p2p device */
10029 hddLog(VOS_TRACE_LEVEL_INFO,
10030 FL("Del_bss called, avoid apps suspend"));
10031 return FALSE;
10032
10033}
Jeff Johnson295189b2012-06-20 16:38:30 -070010034/* Decide whether to allow/not the apps power collapse.
10035 * Allow apps power collapse if we are in connected state.
10036 * if not, allow only if we are in IMPS */
10037v_BOOL_t hdd_is_apps_power_collapse_allowed(hdd_context_t* pHddCtx)
10038{
10039 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
Srikant Kuppafef66a72013-01-30 17:32:44 -080010040 tANI_BOOLEAN scanRspPending = csrNeighborRoamScanRspPending(pHddCtx->hHal);
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080010041 tANI_BOOLEAN inMiddleOfRoaming = csrNeighborMiddleOfRoaming(pHddCtx->hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -070010042 hdd_config_t *pConfig = pHddCtx->cfg_ini;
10043 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10044 hdd_adapter_t *pAdapter = NULL;
10045 VOS_STATUS status;
Yathish9f22e662012-12-10 14:21:35 -080010046 tVOS_CONCURRENCY_MODE concurrent_state = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -070010047
Jeff Johnson295189b2012-06-20 16:38:30 -070010048 if (VOS_STA_SAP_MODE == hdd_get_conparam())
10049 return TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -070010050
Yathish9f22e662012-12-10 14:21:35 -080010051 concurrent_state = hdd_get_concurrency_mode();
10052
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010053 if ((concurrent_state == (VOS_STA | VOS_P2P_GO)) &&
10054 !(wlan_hdd_is_GO_power_collapse_allowed(pHddCtx)))
10055 return FALSE;
Yathish9f22e662012-12-10 14:21:35 -080010056#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010057
Yathish9f22e662012-12-10 14:21:35 -080010058 if(((concurrent_state == (VOS_STA | VOS_P2P_CLIENT)) ||
Sushant Kaushikabb7ee62014-07-18 16:20:12 +053010059 (concurrent_state == (VOS_STA | VOS_P2P_GO)))&&
Yathish9f22e662012-12-10 14:21:35 -080010060 (IS_ACTIVEMODE_OFFLOAD_FEATURE_ENABLE))
10061 return TRUE;
10062#endif
10063
Jeff Johnson295189b2012-06-20 16:38:30 -070010064 /*loop through all adapters. TBD fix for Concurrency */
10065 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10066 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10067 {
10068 pAdapter = pAdapterNode->pAdapter;
10069 if ( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
10070 || (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
10071 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080010072 if (((pConfig->fIsImpsEnabled || pConfig->fIsBmpsEnabled)
c_hpothu4e8faac2014-05-16 17:38:44 +053010073 && (pmcState != IMPS && pmcState != BMPS && pmcState != UAPSD
Srikant Kuppafef66a72013-01-30 17:32:44 -080010074 && pmcState != STOPPED && pmcState != STANDBY)) ||
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080010075 (eANI_BOOLEAN_TRUE == scanRspPending) ||
10076 (eANI_BOOLEAN_TRUE == inMiddleOfRoaming))
Jeff Johnson295189b2012-06-20 16:38:30 -070010077 {
Srikant Kuppafef66a72013-01-30 17:32:44 -080010078 hddLog( LOGE, "%s: do not allow APPS power collapse-"
Srinivas Girigowdaa553c462013-03-07 19:42:52 -080010079 "pmcState = %d scanRspPending = %d inMiddleOfRoaming = %d",
10080 __func__, pmcState, scanRspPending, inMiddleOfRoaming );
Jeff Johnson295189b2012-06-20 16:38:30 -070010081 return FALSE;
10082 }
10083 }
10084 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10085 pAdapterNode = pNext;
10086 }
10087 return TRUE;
10088}
10089
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -080010090/* Decides whether to send suspend notification to Riva
10091 * if any adapter is in BMPS; then it is required */
10092v_BOOL_t hdd_is_suspend_notify_allowed(hdd_context_t* pHddCtx)
10093{
10094 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
10095 hdd_config_t *pConfig = pHddCtx->cfg_ini;
10096
10097 if (pConfig->fIsBmpsEnabled && (pmcState == BMPS))
10098 {
10099 return TRUE;
10100 }
10101 return FALSE;
10102}
10103
Jeff Johnson295189b2012-06-20 16:38:30 -070010104void wlan_hdd_set_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
10105{
10106 switch(mode)
10107 {
Chilam Ngc4244af2013-04-01 15:37:32 -070010108 case VOS_STA_MODE:
10109 case VOS_P2P_CLIENT_MODE:
10110 case VOS_P2P_GO_MODE:
10111 case VOS_STA_SAP_MODE:
Jeff Johnsone7245742012-09-05 17:12:55 -070010112 pHddCtx->concurrency_mode |= (1 << mode);
Agarwal Ashish51325b52014-06-16 16:50:49 +053010113 pHddCtx->no_of_open_sessions[mode]++;
Jeff Johnson295189b2012-06-20 16:38:30 -070010114 break;
10115 default:
10116 break;
Jeff Johnson295189b2012-06-20 16:38:30 -070010117 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053010118 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
10119 "Number of open sessions for mode %d = %d"),
10120 pHddCtx->concurrency_mode, mode,
10121 pHddCtx->no_of_open_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070010122}
10123
10124
10125void wlan_hdd_clear_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
10126{
10127 switch(mode)
10128 {
Chilam Ngc4244af2013-04-01 15:37:32 -070010129 case VOS_STA_MODE:
10130 case VOS_P2P_CLIENT_MODE:
10131 case VOS_P2P_GO_MODE:
10132 case VOS_STA_SAP_MODE:
Agarwal Ashish51325b52014-06-16 16:50:49 +053010133 pHddCtx->no_of_open_sessions[mode]--;
10134 if (!(pHddCtx->no_of_open_sessions[mode]))
10135 pHddCtx->concurrency_mode &= (~(1 << mode));
Jeff Johnson295189b2012-06-20 16:38:30 -070010136 break;
10137 default:
10138 break;
10139 }
Agarwal Ashish51325b52014-06-16 16:50:49 +053010140 hddLog(VOS_TRACE_LEVEL_INFO, FL("concurrency_mode = 0x%x "
10141 "Number of open sessions for mode %d = %d"),
10142 pHddCtx->concurrency_mode, mode, pHddCtx->no_of_open_sessions[mode]);
10143
10144}
10145/**---------------------------------------------------------------------------
10146 *
10147 * \brief wlan_hdd_incr_active_session()
10148 *
10149 * This function increments the number of active sessions
10150 * maintained per device mode
10151 * Incase of STA/P2P CLI/IBSS upon connection indication it is incremented
10152 * Incase of SAP/P2P GO upon bss start it is incremented
10153 *
10154 * \param pHddCtx - HDD Context
10155 * \param mode - device mode
10156 *
10157 * \return - None
10158 *
10159 * --------------------------------------------------------------------------*/
10160void wlan_hdd_incr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
10161{
10162 switch (mode) {
10163 case VOS_STA_MODE:
10164 case VOS_P2P_CLIENT_MODE:
10165 case VOS_P2P_GO_MODE:
10166 case VOS_STA_SAP_MODE:
10167 pHddCtx->no_of_active_sessions[mode]++;
10168 break;
10169 default:
10170 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
10171 break;
10172 }
10173 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
10174 mode,
10175 pHddCtx->no_of_active_sessions[mode]);
10176}
10177
10178/**---------------------------------------------------------------------------
10179 *
10180 * \brief wlan_hdd_decr_active_session()
10181 *
10182 * This function decrements the number of active sessions
10183 * maintained per device mode
10184 * Incase of STA/P2P CLI/IBSS upon disconnection it is decremented
10185 * Incase of SAP/P2P GO upon bss stop it is decremented
10186 *
10187 * \param pHddCtx - HDD Context
10188 * \param mode - device mode
10189 *
10190 * \return - None
10191 *
10192 * --------------------------------------------------------------------------*/
10193void wlan_hdd_decr_active_session(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
10194{
10195 switch (mode) {
10196 case VOS_STA_MODE:
10197 case VOS_P2P_CLIENT_MODE:
10198 case VOS_P2P_GO_MODE:
10199 case VOS_STA_SAP_MODE:
Agarwal Ashish5325f522014-08-06 00:58:44 +053010200 if (pHddCtx->no_of_active_sessions[mode] > 0)
10201 pHddCtx->no_of_active_sessions[mode]--;
10202 else
10203 hddLog(VOS_TRACE_LEVEL_INFO, FL(" No.# of Active sessions"
10204 "is already Zero"));
Agarwal Ashish51325b52014-06-16 16:50:49 +053010205 break;
10206 default:
10207 hddLog(VOS_TRACE_LEVEL_INFO, FL("Not Expected Mode %d"), mode);
10208 break;
10209 }
10210 hddLog(VOS_TRACE_LEVEL_INFO, FL("No.# of active sessions for mode %d = %d"),
10211 mode,
10212 pHddCtx->no_of_active_sessions[mode]);
Jeff Johnson295189b2012-06-20 16:38:30 -070010213}
10214
Jeff Johnsone7245742012-09-05 17:12:55 -070010215/**---------------------------------------------------------------------------
10216 *
10217 * \brief wlan_hdd_restart_init
10218 *
10219 * This function initalizes restart timer/flag. An internal function.
10220 *
10221 * \param - pHddCtx
10222 *
10223 * \return - None
10224 *
10225 * --------------------------------------------------------------------------*/
10226
10227static void wlan_hdd_restart_init(hdd_context_t *pHddCtx)
10228{
10229 /* Initialize */
10230 pHddCtx->hdd_restart_retries = 0;
10231 atomic_set(&pHddCtx->isRestartInProgress, 0);
10232 vos_timer_init(&pHddCtx->hdd_restart_timer,
10233 VOS_TIMER_TYPE_SW,
10234 wlan_hdd_restart_timer_cb,
10235 pHddCtx);
10236}
10237/**---------------------------------------------------------------------------
10238 *
10239 * \brief wlan_hdd_restart_deinit
10240 *
10241 * This function cleans up the resources used. An internal function.
10242 *
10243 * \param - pHddCtx
10244 *
10245 * \return - None
10246 *
10247 * --------------------------------------------------------------------------*/
10248
10249static void wlan_hdd_restart_deinit(hdd_context_t* pHddCtx)
10250{
10251
10252 VOS_STATUS vos_status;
10253 /* Block any further calls */
10254 atomic_set(&pHddCtx->isRestartInProgress, 1);
10255 /* Cleanup */
10256 vos_status = vos_timer_stop( &pHddCtx->hdd_restart_timer );
10257 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010258 hddLog(LOGE, FL("Failed to stop HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070010259 vos_status = vos_timer_destroy(&pHddCtx->hdd_restart_timer);
10260 if (!VOS_IS_STATUS_SUCCESS(vos_status))
c_hpothu6ff1c3c2013-10-01 19:01:57 +053010261 hddLog(LOGE, FL("Failed to destroy HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -070010262
10263}
10264
10265/**---------------------------------------------------------------------------
10266 *
10267 * \brief wlan_hdd_framework_restart
10268 *
10269 * This function uses a cfg80211 API to start a framework initiated WLAN
10270 * driver module unload/load.
10271 *
10272 * Also this API keep retrying (WLAN_HDD_RESTART_RETRY_MAX_CNT).
10273 *
10274 *
10275 * \param - pHddCtx
10276 *
10277 * \return - VOS_STATUS_SUCCESS: Success
10278 * VOS_STATUS_E_EMPTY: Adapter is Empty
10279 * VOS_STATUS_E_NOMEM: No memory
10280
10281 * --------------------------------------------------------------------------*/
10282
10283static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx)
10284{
10285 VOS_STATUS status = VOS_STATUS_SUCCESS;
10286 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070010287 int len = (sizeof (struct ieee80211_mgmt));
10288 struct ieee80211_mgmt *mgmt = NULL;
10289
10290 /* Prepare the DEAUTH managment frame with reason code */
10291 mgmt = kzalloc(len, GFP_KERNEL);
10292 if(mgmt == NULL)
10293 {
10294 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
10295 "%s: memory allocation failed (%d bytes)", __func__, len);
10296 return VOS_STATUS_E_NOMEM;
10297 }
10298 mgmt->u.deauth.reason_code = WLAN_REASON_DISASSOC_LOW_ACK;
Jeff Johnsone7245742012-09-05 17:12:55 -070010299
10300 /* Iterate over all adapters/devices */
10301 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10302 do
10303 {
10304 if( (status == VOS_STATUS_SUCCESS) &&
10305 pAdapterNode &&
10306 pAdapterNode->pAdapter)
10307 {
10308 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
10309 "restarting the driver(intf:\'%s\' mode:%d :try %d)",
10310 pAdapterNode->pAdapter->dev->name,
10311 pAdapterNode->pAdapter->device_mode,
10312 pHddCtx->hdd_restart_retries + 1);
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070010313 /*
10314 * CFG80211 event to restart the driver
10315 *
10316 * 'cfg80211_send_unprot_deauth' sends a
10317 * NL80211_CMD_UNPROT_DEAUTHENTICATE event to supplicant at any state
10318 * of SME(Linux Kernel) state machine.
10319 *
10320 * Reason code WLAN_REASON_DISASSOC_LOW_ACK is currently used to restart
10321 * the driver.
10322 *
10323 */
10324
10325 cfg80211_send_unprot_deauth(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len );
Jeff Johnsone7245742012-09-05 17:12:55 -070010326 }
10327 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10328 pAdapterNode = pNext;
10329 } while((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status));
10330
Madan Mohan Koyyalamudifc19e442013-05-09 18:24:08 -070010331
10332 /* Free the allocated management frame */
10333 kfree(mgmt);
10334
Jeff Johnsone7245742012-09-05 17:12:55 -070010335 /* Retry until we unload or reach max count */
10336 if(++pHddCtx->hdd_restart_retries < WLAN_HDD_RESTART_RETRY_MAX_CNT)
10337 vos_timer_start(&pHddCtx->hdd_restart_timer, WLAN_HDD_RESTART_RETRY_DELAY_MS);
10338
10339 return status;
10340
10341}
10342/**---------------------------------------------------------------------------
10343 *
10344 * \brief wlan_hdd_restart_timer_cb
10345 *
10346 * Restart timer callback. An internal function.
10347 *
10348 * \param - User data:
10349 *
10350 * \return - None
10351 *
10352 * --------------------------------------------------------------------------*/
10353
10354void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback)
10355{
10356 hdd_context_t *pHddCtx = usrDataForCallback;
10357 wlan_hdd_framework_restart(pHddCtx);
10358 return;
10359
10360}
10361
10362
10363/**---------------------------------------------------------------------------
10364 *
10365 * \brief wlan_hdd_restart_driver
10366 *
10367 * This function sends an event to supplicant to restart the WLAN driver.
10368 *
10369 * This function is called from vos_wlanRestart.
10370 *
10371 * \param - pHddCtx
10372 *
10373 * \return - VOS_STATUS_SUCCESS: Success
10374 * VOS_STATUS_E_EMPTY: Adapter is Empty
10375 * VOS_STATUS_E_ALREADY: Request already in progress
10376
10377 * --------------------------------------------------------------------------*/
10378VOS_STATUS wlan_hdd_restart_driver(hdd_context_t *pHddCtx)
10379{
10380 VOS_STATUS status = VOS_STATUS_SUCCESS;
10381
10382 /* A tight check to make sure reentrancy */
10383 if(atomic_xchg(&pHddCtx->isRestartInProgress, 1))
10384 {
Mihir Shetefd528652014-06-23 19:07:50 +053010385 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsone7245742012-09-05 17:12:55 -070010386 "%s: WLAN restart is already in progress", __func__);
10387
10388 return VOS_STATUS_E_ALREADY;
10389 }
Sameer Thalappil0c164f52013-03-28 15:27:56 -070010390 /* Send reset FIQ to WCNSS to invoke SSR. */
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -080010391#ifdef HAVE_WCNSS_RESET_INTR
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -070010392 wcnss_reset_intr();
10393#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070010394
Jeff Johnsone7245742012-09-05 17:12:55 -070010395 return status;
10396}
10397
Mihir Shetee1093ba2014-01-21 20:13:32 +053010398/**---------------------------------------------------------------------------
10399 *
10400 * \brief wlan_hdd_init_channels
10401 *
10402 * This function is used to initialize the channel list in CSR
10403 *
10404 * This function is called from hdd_wlan_startup
10405 *
10406 * \param - pHddCtx: HDD context
10407 *
10408 * \return - VOS_STATUS_SUCCESS: Success
10409 * VOS_STATUS_E_FAULT: Failure reported by SME
10410
10411 * --------------------------------------------------------------------------*/
10412static VOS_STATUS wlan_hdd_init_channels(hdd_context_t *pHddCtx)
10413{
10414 eHalStatus status;
10415
10416 status = sme_InitChannels(pHddCtx->hHal);
10417 if (HAL_STATUS_SUCCESS(status))
10418 {
10419 return VOS_STATUS_SUCCESS;
10420 }
10421 else
10422 {
10423 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Channel initialization failed(%d)",
10424 __func__, status);
10425 return VOS_STATUS_E_FAULT;
10426 }
10427}
10428
Agarwal Ashish6db9d532014-09-30 18:19:10 +053010429VOS_STATUS wlan_hdd_init_channels_for_cc(hdd_context_t *pHddCtx, driver_load_type init )
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053010430{
10431 eHalStatus status;
10432
Agarwal Ashish6db9d532014-09-30 18:19:10 +053010433 status = sme_InitChannelsForCC(pHddCtx->hHal, init);
Mahesh A Saptasagar74289d22014-05-14 12:43:37 +053010434 if (HAL_STATUS_SUCCESS(status))
10435 {
10436 return VOS_STATUS_SUCCESS;
10437 }
10438 else
10439 {
10440 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Issue reg hint failed(%d)",
10441 __func__, status);
10442 return VOS_STATUS_E_FAULT;
10443 }
10444}
Sudhir Sattayappa Kohallib1d8c3a2013-06-18 14:47:20 -070010445/*
10446 * API to find if there is any STA or P2P-Client is connected
10447 */
10448VOS_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *pHddCtx)
10449{
10450 return sme_isSta_p2p_clientConnected(pHddCtx->hHal);
10451}
Jeff Johnsone7245742012-09-05 17:12:55 -070010452
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010453int wlan_hdd_scan_abort(hdd_adapter_t *pAdapter)
10454{
10455 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
10456 hdd_scaninfo_t *pScanInfo = NULL;
Girish Gowli4bf7a632014-06-12 13:42:11 +053010457 long status = 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010458
10459 pScanInfo = &pHddCtx->scan_info;
10460 if (pScanInfo->mScanPending)
10461 {
10462 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Kaushik, Sushant4975a572014-10-21 16:07:48 +053010463 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010464 eCSR_SCAN_ABORT_DEFAULT);
10465
10466 status = wait_for_completion_interruptible_timeout(
10467 &pScanInfo->abortscan_event_var,
10468 msecs_to_jiffies(5000));
Girish Gowli4bf7a632014-06-12 13:42:11 +053010469 if (0 >= status)
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010470 {
10471 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Girish Gowli4bf7a632014-06-12 13:42:11 +053010472 "%s: Timeout or Interrupt occurred while waiting for abort"
10473 "scan, status- %ld", __func__, status);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010474 return -ETIMEDOUT;
10475 }
10476 }
Girish Gowli4bf7a632014-06-12 13:42:11 +053010477 return 0;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +053010478}
10479
c_hpothu225aa7c2014-10-22 17:45:13 +053010480VOS_STATUS wlan_hdd_cancel_remain_on_channel(hdd_context_t *pHddCtx)
10481{
10482 hdd_adapter_t *pAdapter;
10483 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
10484 VOS_STATUS vosStatus;
10485
10486 vosStatus = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10487 while (NULL != pAdapterNode && VOS_STATUS_E_EMPTY != vosStatus)
10488 {
10489 pAdapter = pAdapterNode->pAdapter;
10490 if (NULL != pAdapter)
10491 {
10492 if (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode ||
10493 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode ||
10494 WLAN_HDD_P2P_GO == pAdapter->device_mode)
10495 {
10496 hddLog(LOG1, FL("abort ROC deviceMode: %d"),
10497 pAdapter->device_mode);
10498 if (VOS_STATUS_SUCCESS !=
10499 wlan_hdd_cancel_existing_remain_on_channel(pAdapter))
10500 {
10501 hddLog(LOGE, FL("failed to abort ROC"));
10502 return VOS_STATUS_E_FAILURE;
10503 }
10504 }
10505 }
10506 vosStatus = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10507 pAdapterNode = pNext;
10508 }
10509 return VOS_STATUS_SUCCESS;
10510}
Jeff Johnson295189b2012-06-20 16:38:30 -070010511//Register the module init/exit functions
10512module_init(hdd_module_init);
10513module_exit(hdd_module_exit);
10514
10515MODULE_LICENSE("Dual BSD/GPL");
10516MODULE_AUTHOR("Qualcomm Atheros, Inc.");
10517MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
10518
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -070010519module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
10520 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Jeff Johnson32d95a32012-09-10 13:15:23 -070010521
Jeff Johnson76052702013-04-16 13:55:05 -070010522module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
Jeff Johnson32d95a32012-09-10 13:15:23 -070010523 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Arif Hussain66559122013-11-21 10:11:40 -080010524
10525module_param(enable_dfs_chan_scan, int,
10526 S_IRUSR | S_IRGRP | S_IROTH);
10527
10528module_param(enable_11d, int,
10529 S_IRUSR | S_IRGRP | S_IROTH);
10530
10531module_param(country_code, charp,
10532 S_IRUSR | S_IRGRP | S_IROTH);