blob: 4aed3cf7d19107c9e5019dac00b9f3838b1bc325 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * Copyright (c) 2012-2013, 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/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
42/*========================================================================
43
44 \file wlan_hdd_main.c
45
46 \brief WLAN Host Device Driver implementation
47
48 Copyright 2008 (c) Qualcomm, Incorporated. All Rights Reserved.
49
50 Qualcomm Confidential and Proprietary.
51
52 ========================================================================*/
53
54/**=========================================================================
55
56 EDIT HISTORY FOR FILE
57
58
59 This section contains comments describing changes made to the module.
60 Notice that changes are listed in reverse chronological order.
61
62
63 $Header:$ $DateTime: $ $Author: $
64
65
66 when who what, where, why
67 -------- --- --------------------------------------------------------
68 04/5/09 Shailender Created module.
69 02/24/10 Sudhir.S.Kohalli Added to support param for SoftAP module
70 06/03/10 js - Added support to hostapd driven deauth/disassoc/mic failure
71 ==========================================================================*/
72
73/*--------------------------------------------------------------------------
74 Include Files
75 ------------------------------------------------------------------------*/
76//#include <wlan_qct_driver.h>
77#include <wlan_hdd_includes.h>
78#ifdef ANI_BUS_TYPE_SDIO
79#include <wlan_sal_misc.h>
80#endif // ANI_BUS_TYPE_SDIO
81#include <vos_api.h>
82#include <vos_sched.h>
83#include <vos_power.h>
84#include <linux/etherdevice.h>
85#include <linux/firmware.h>
86#ifdef ANI_BUS_TYPE_SDIO
87#include <linux/mmc/sdio_func.h>
88#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32))
89// added in 2.6.32, need to define locally if using an earlier kernel
90#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
91#endif
92#endif // ANI_BUS_TYPE_SDIO
93#ifdef ANI_BUS_TYPE_PLATFORM
94#include <linux/wcnss_wlan.h>
95#endif //ANI_BUS_TYPE_PLATFORM
96#ifdef ANI_BUS_TYPE_PCI
97#include "wcnss_wlan.h"
98#endif /* ANI_BUS_TYPE_PCI */
99#include <wlan_hdd_tx_rx.h>
100#include <palTimer.h>
101#include <wniApi.h>
102#include <wlan_nlink_srv.h>
103#include <wlan_btc_svc.h>
104#include <wlan_hdd_cfg.h>
105#include <wlan_ptt_sock_svc.h>
106#include <wlan_hdd_wowl.h>
107#include <wlan_hdd_misc.h>
108#include <wlan_hdd_wext.h>
109#ifdef WLAN_BTAMP_FEATURE
110#include <bap_hdd_main.h>
111#include <bapInternal.h>
112#endif // WLAN_BTAMP_FEATURE
113
114#ifdef CONFIG_CFG80211
115#include <linux/wireless.h>
116#include <net/cfg80211.h>
117#include "wlan_hdd_cfg80211.h"
118#include "wlan_hdd_p2p.h"
119#endif
120#include <linux/rtnetlink.h>
121#ifdef ANI_MANF_DIAG
122int wlan_hdd_ftm_start(hdd_context_t *pAdapter);
123#endif
124#ifdef WLAN_SOFTAP_FEATURE
125#include "sapApi.h"
126#include <linux/semaphore.h>
127#include <mach/subsystem_restart.h>
128#include <wlan_hdd_hostapd.h>
129#include <wlan_hdd_softap_tx_rx.h>
130#endif
131#ifdef FEATURE_WLAN_INTEGRATED_SOC
132#include "cfgApi.h"
133#endif
134#include "wlan_hdd_dev_pwr.h"
135#ifdef WLAN_BTAMP_FEATURE
136#include "bap_hdd_misc.h"
137#endif
138#ifdef FEATURE_WLAN_INTEGRATED_SOC
139#include "wlan_qct_pal_trace.h"
140#endif /* FEATURE_WLAN_INTEGRATED_SOC */
141#include "qwlan_version.h"
Yathish9f22e662012-12-10 14:21:35 -0800142#include "wlan_qct_wda.h"
Chilam NG571c65a2013-01-19 12:27:36 +0530143#ifdef FEATURE_WLAN_TDLS
144#include "wlan_hdd_tdls.h"
145#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700146
147#ifdef MODULE
148#define WLAN_MODULE_NAME module_name(THIS_MODULE)
149#else
150#define WLAN_MODULE_NAME "wlan"
151#endif
152
153#ifdef TIMER_MANAGER
154#define TIMER_MANAGER_STR " +TIMER_MANAGER"
155#else
156#define TIMER_MANAGER_STR ""
157#endif
158
159#ifdef MEMORY_DEBUG
160#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
161#else
162#define MEMORY_DEBUG_STR ""
163#endif
164
165/* the Android framework expects this param even though we don't use it */
166#define BUF_LEN 20
167static char fwpath[BUF_LEN];
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700168#ifndef MODULE
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700169static int wlan_hdd_inited;
Madan Mohan Koyyalamudi05f313c2012-09-18 19:19:15 -0700170#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700171
Jeff Johnsone7245742012-09-05 17:12:55 -0700172/*
173 * The rate at which the driver sends RESTART event to supplicant
174 * once the function 'vos_wlanRestart()' is called
175 *
176 */
177#define WLAN_HDD_RESTART_RETRY_DELAY_MS 5000 /* 5 second */
178#define WLAN_HDD_RESTART_RETRY_MAX_CNT 5 /* 5 retries */
179#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5))
Jeff Johnson295189b2012-06-20 16:38:30 -0700180static struct wake_lock wlan_wake_lock;
Jeff Johnsone7245742012-09-05 17:12:55 -0700181#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700182/* set when SSR is needed after unload */
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -0700183static e_hdd_ssr_required isSsrRequired = HDD_SSR_NOT_REQUIRED;
Jeff Johnson295189b2012-06-20 16:38:30 -0700184
185//internal function declaration
Jeff Johnsone7245742012-09-05 17:12:55 -0700186static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx);
187static void wlan_hdd_restart_init(hdd_context_t *pHddCtx);
188static void wlan_hdd_restart_deinit(hdd_context_t *pHddCtx);
189void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback);
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800190void hdd_set_wlan_suspend_mode(bool suspend);
Jeff Johnsone7245742012-09-05 17:12:55 -0700191
Jeff Johnson295189b2012-06-20 16:38:30 -0700192v_U16_t hdd_select_queue(struct net_device *dev,
193 struct sk_buff *skb);
194
195#ifdef WLAN_FEATURE_PACKET_FILTERING
196static void hdd_set_multicast_list(struct net_device *dev);
197#endif
198
199void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter);
200
201extern int hdd_setBand_helper(struct net_device *dev, tANI_U8* ptr);
202
203static int hdd_netdev_notifier_call(struct notifier_block * nb,
204 unsigned long state,
205 void *ndev)
206{
207 struct net_device *dev = ndev;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700208 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
209 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -0700210#ifdef WLAN_BTAMP_FEATURE
211 VOS_STATUS status;
212 hdd_context_t *pHddCtx;
213#endif
214
215 //Make sure that this callback corresponds to our device.
216 if((strncmp( dev->name, "wlan", 4 )) &&
Jeff Johnsone7245742012-09-05 17:12:55 -0700217 (strncmp( dev->name, "p2p", 3))
Jeff Johnson295189b2012-06-20 16:38:30 -0700218 )
219 return NOTIFY_DONE;
220
221#ifdef CONFIG_CFG80211
222 if (!dev->ieee80211_ptr)
223 return NOTIFY_DONE;
224#endif
225
Jeff Johnson295189b2012-06-20 16:38:30 -0700226
227 if(NULL == pAdapter)
228 {
Jeff Johnsona8a1a482012-12-12 16:49:33 -0800229 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Adapter Null Pointer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700230 VOS_ASSERT(0);
231 return NOTIFY_DONE;
232 }
233
234 hddLog(VOS_TRACE_LEVEL_INFO,"%s: New Net Device State = %lu", __func__, state);
235
236 switch (state) {
237 case NETDEV_REGISTER:
238 break;
239
240 case NETDEV_UNREGISTER:
241 break;
242
243 case NETDEV_UP:
244 break;
245
246 case NETDEV_DOWN:
247 break;
248
249 case NETDEV_CHANGE:
Jeff Johnsone7245742012-09-05 17:12:55 -0700250 if(TRUE == pAdapter->isLinkUpSvcNeeded)
251 complete(&pAdapter->linkup_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700252 break;
253
254 case NETDEV_GOING_DOWN:
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700255 if( pHddCtx->scan_info.mScanPending != FALSE )
Jeff Johnson295189b2012-06-20 16:38:30 -0700256 {
257 int result;
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -0800258 INIT_COMPLETION(pHddCtx->scan_info.abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700259 hdd_abort_mac_scan(pAdapter->pHddCtx);
260 result = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -0800261 &pHddCtx->scan_info.abortscan_event_var,
Jeff Johnson295189b2012-06-20 16:38:30 -0700262 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
263 if(!result)
264 {
265 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson902c9832012-12-10 14:28:09 -0800266 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700267 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700268 }
269 }
270 else
271 {
272 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700273 "%s: Scan is not Pending from user" , __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700274 }
275#ifdef WLAN_BTAMP_FEATURE
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700276 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s: disabling AMP", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700277 status = WLANBAP_StopAmp();
278 if(VOS_STATUS_SUCCESS != status )
279 {
280 pHddCtx->isAmpAllowed = VOS_TRUE;
281 hddLog(VOS_TRACE_LEVEL_FATAL,
282 "%s: Failed to stop AMP", __func__);
283 }
284 else
285 {
286 //a state m/c implementation in PAL is TBD to avoid this delay
287 msleep(500);
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700288 if ( pHddCtx->isAmpAllowed )
289 {
290 WLANBAP_DeregisterFromHCI();
291 pHddCtx->isAmpAllowed = VOS_FALSE;
292 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700293 }
294#endif //WLAN_BTAMP_FEATURE
295 break;
296
297 default:
298 break;
299 }
300
301 return NOTIFY_DONE;
302}
303
304struct notifier_block hdd_netdev_notifier = {
305 .notifier_call = hdd_netdev_notifier_call,
306};
307
308/*---------------------------------------------------------------------------
309 * Function definitions
310 *-------------------------------------------------------------------------*/
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800311int isWDresetInProgress(void);
Jeff Johnson295189b2012-06-20 16:38:30 -0700312void hdd_unregister_mcast_bcast_filter(hdd_context_t *pHddCtx);
313void hdd_register_mcast_bcast_filter(hdd_context_t *pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -0700314//variable to hold the insmod parameters
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700315static int con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -0700316#ifndef MODULE
317/* current con_mode - used only for statically linked driver
318 * con_mode is changed by userspace to indicate a mode change which will
319 * result in calling the module exit and init functions. The module
320 * exit function will clean up based on the value of con_mode prior to it
321 * being changed by userspace. So curr_con_mode records the current con_mode
322 * for exit when con_mode becomes the next mode for init
323 */
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -0700324static int curr_con_mode;
Jeff Johnson295189b2012-06-20 16:38:30 -0700325#endif
326
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -0800327/**---------------------------------------------------------------------------
328
329 \brief hdd_vos_trace_enable() - Configure initial VOS Trace enable
330
331 Called immediately after the cfg.ini is read in order to configure
332 the desired trace levels.
333
334 \param - moduleId - module whose trace level is being configured
335 \param - bitmask - bitmask of log levels to be enabled
336
337 \return - void
338
339 --------------------------------------------------------------------------*/
340static void hdd_vos_trace_enable(VOS_MODULE_ID moduleId, v_U32_t bitmask)
341{
342 wpt_tracelevel level;
343
344 /* if the bitmask is the default value, then a bitmask was not
345 specified in cfg.ini, so leave the logging level alone (it
346 will remain at the "compiled in" default value) */
347 if (CFG_VOS_TRACE_ENABLE_DEFAULT == bitmask)
348 {
349 return;
350 }
351
352 /* a mask was specified. start by disabling all logging */
353 vos_trace_setValue(moduleId, VOS_TRACE_LEVEL_NONE, 0);
354
355 /* now cycle through the bitmask until all "set" bits are serviced */
356 level = VOS_TRACE_LEVEL_FATAL;
357 while (0 != bitmask)
358 {
359 if (bitmask & 1)
360 {
361 vos_trace_setValue(moduleId, level, 1);
362 }
363 level++;
364 bitmask >>= 1;
365 }
366}
367
368
Jeff Johnson295189b2012-06-20 16:38:30 -0700369#ifdef FEATURE_WLAN_INTEGRATED_SOC
370/**---------------------------------------------------------------------------
371
372 \brief hdd_wdi_trace_enable() - Configure initial WDI Trace enable
373
374 Called immediately after the cfg.ini is read in order to configure
375 the desired trace levels in the WDI.
376
377 \param - moduleId - module whose trace level is being configured
378 \param - bitmask - bitmask of log levels to be enabled
379
380 \return - void
381
382 --------------------------------------------------------------------------*/
383static void hdd_wdi_trace_enable(wpt_moduleid moduleId, v_U32_t bitmask)
384{
385 wpt_tracelevel level;
386
387 /* if the bitmask is the default value, then a bitmask was not
388 specified in cfg.ini, so leave the logging level alone (it
389 will remain at the "compiled in" default value) */
390 if (CFG_WDI_TRACE_ENABLE_DEFAULT == bitmask)
391 {
392 return;
393 }
394
395 /* a mask was specified. start by disabling all logging */
396 wpalTraceSetLevel(moduleId, eWLAN_PAL_TRACE_LEVEL_NONE, 0);
397
398 /* now cycle through the bitmask until all "set" bits are serviced */
399 level = eWLAN_PAL_TRACE_LEVEL_FATAL;
400 while (0 != bitmask)
401 {
402 if (bitmask & 1)
403 {
404 wpalTraceSetLevel(moduleId, level, 1);
405 }
406 level++;
407 bitmask >>= 1;
408 }
409}
410#endif /* FEATURE_WLAN_INTEGRATED_SOC */
411
412int hdd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
413{
414 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
415 hdd_priv_data_t priv_data;
416 tANI_U8 *command = NULL;
417 int ret = 0;
418
419 if (NULL == pAdapter)
420 {
421 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700422 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700423 ret = -ENODEV;
424 goto exit;
425 }
426
Jeff Johnsone7245742012-09-05 17:12:55 -0700427 if ((!ifr) || (!ifr->ifr_data))
Jeff Johnson295189b2012-06-20 16:38:30 -0700428 {
429 ret = -EINVAL;
430 goto exit;
431 }
432
433 if (copy_from_user(&priv_data, ifr->ifr_data, sizeof(hdd_priv_data_t)))
434 {
435 ret = -EFAULT;
436 goto exit;
437 }
438
439 command = kmalloc(priv_data.total_len, GFP_KERNEL);
440 if (!command)
441 {
442 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700443 "%s: failed to allocate memory\n", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700444 ret = -ENOMEM;
445 goto exit;
446 }
447
448 if (copy_from_user(command, priv_data.buf, priv_data.total_len))
449 {
450 ret = -EFAULT;
451 goto exit;
452 }
453
454 if ((SIOCDEVPRIVATE + 1) == cmd)
455 {
456 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
457
458 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -0700459 "%s: Received %s cmd from Wi-Fi GUI***", __func__, command);
Jeff Johnson295189b2012-06-20 16:38:30 -0700460
461 if (strncmp(command, "P2P_DEV_ADDR", 12) == 0 )
462 {
463 if (copy_to_user(priv_data.buf, pHddCtx->p2pDeviceAddress.bytes,
464 sizeof(tSirMacAddr)))
465 {
466 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700467 "%s: failed to copy data to user buffer\n", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700468 ret = -EFAULT;
469 }
470 }
Amar Singhal0974e402013-02-12 14:27:46 -0800471 else if(strncmp(command, "SETBAND", 7) == 0)
Jeff Johnson295189b2012-06-20 16:38:30 -0700472 {
Amar Singhal0974e402013-02-12 14:27:46 -0800473 tANI_U8 *ptr = command ;
Jeff Johnson295189b2012-06-20 16:38:30 -0700474 int ret = 0 ;
475
476 /* Change band request received */
477
478 /* First 8 bytes will have "SETBAND " and
479 * 9 byte will have band setting value */
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -0700480 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Amar Singhal0974e402013-02-12 14:27:46 -0800481 "%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 -0700482
483 /* Change band request received */
484 ret = hdd_setBand_helper(dev, ptr);
485 }
Jeff Johnson32d95a32012-09-10 13:15:23 -0700486 else if ( strncasecmp(command, "COUNTRY", 7) == 0 )
487 {
488 char *country_code;
489
490 country_code = command + 8;
491 ret = (int)sme_ChangeCountryCode(pHddCtx->hHal, NULL, country_code,
492 pAdapter, pHddCtx->pvosContext);
493 if( 0 != ret )
494 {
495 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
496 "%s: SME Change Country code fail ret=%d\n",__func__, ret);
497
498 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700499 }
500 /*
501 command should be a string having format
502 SET_SAP_CHANNEL_LIST <num of channels> <the channels seperated by spaces>
503 */
Amar Singhal0974e402013-02-12 14:27:46 -0800504 else if(strncmp(command, "SET_SAP_CHANNEL_LIST", 20) == 0)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700505 {
Amar Singhal0974e402013-02-12 14:27:46 -0800506 tANI_U8 *ptr = command;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700507
508 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700509 " Received Command to Set Preferred Channels for SAP in %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700510
511 ret = sapSetPreferredChannel(dev, ptr);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700512 }
Sameer Thalappil45931fb2013-02-01 11:18:05 -0800513 else if(strncmp(command, "SETSUSPENDMODE", 14) == 0)
514 {
515 int suspend = 0;
516 tANI_U8 *ptr = (tANI_U8*)command + 15;
517
518 suspend = *ptr - '0';
519 hdd_set_wlan_suspend_mode(suspend);
520 }
Madan Mohan Koyyalamudif9bdd4e2012-10-30 18:05:03 -0700521 else {
522 hddLog( VOS_TRACE_LEVEL_WARN, "%s: Unsupported GUI command %s",
523 __func__, command);
524 }
525
Jeff Johnson295189b2012-06-20 16:38:30 -0700526 }
527exit:
528 if (command)
529 {
530 kfree(command);
531 }
532 return ret;
533}
534
535/**---------------------------------------------------------------------------
536
537 \brief hdd_open() - HDD Open function
538
539 This is called in response to ifconfig up
540
541 \param - dev Pointer to net_device structure
542
543 \return - 0 for success non-zero for failure
544
545 --------------------------------------------------------------------------*/
546int hdd_open (struct net_device *dev)
547{
548 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
549 hdd_context_t *pHddCtx;
550 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
551 VOS_STATUS status;
552 v_BOOL_t in_standby = TRUE;
553
554 if (NULL == pAdapter)
555 {
556 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700557 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700558 return -ENODEV;
559 }
560
561 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
562 if (NULL == pHddCtx)
563 {
564 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700565 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700566 return -ENODEV;
567 }
568
569 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
570 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
571 {
572 if( pAdapterNode->pAdapter->event_flags & DEVICE_IFACE_OPENED)
573 {
574 hddLog(VOS_TRACE_LEVEL_INFO, "%s: chip already out of "
575 "standby", __func__, pAdapter->device_mode);
576 in_standby = FALSE;
577 break;
578 }
579 else
580 {
581 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
582 pAdapterNode = pNext;
583 }
584 }
585
586 if (TRUE == in_standby)
587 {
588 if (VOS_STATUS_SUCCESS != wlan_hdd_exit_lowpower(pHddCtx, pAdapter))
589 {
590 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to bring "
591 "wlan out of power save", __func__);
592 return -EINVAL;
593 }
594 }
595
596 pAdapter->event_flags |= DEVICE_IFACE_OPENED;
597 if (hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
598 {
599 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700600 "%s: Enabling Tx Queues", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700601 /* Enable TX queues only when we are connected */
602 netif_tx_start_all_queues(dev);
603 }
604
605 return 0;
606}
607
608int hdd_mon_open (struct net_device *dev)
609{
610 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
611
612 if(pAdapter == NULL) {
613 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700614 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -0800615 return -EINVAL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700616 }
617
618 netif_start_queue(dev);
619
620 return 0;
621}
622/**---------------------------------------------------------------------------
623
624 \brief hdd_stop() - HDD stop function
625
626 This is called in response to ifconfig down
627
628 \param - dev Pointer to net_device structure
629
630 \return - 0 for success non-zero for failure
631
632 --------------------------------------------------------------------------*/
633
634int hdd_stop (struct net_device *dev)
635{
636 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
637 hdd_context_t *pHddCtx;
638 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
639 VOS_STATUS status;
640 v_BOOL_t enter_standby = TRUE;
641
642 ENTER();
643
644 if (NULL == pAdapter)
645 {
646 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700647 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700648 return -ENODEV;
649 }
650
651 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
652 if (NULL == pHddCtx)
653 {
654 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700655 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700656 return -ENODEV;
657 }
658
659 pAdapter->event_flags &= ~(DEVICE_IFACE_OPENED);
660 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disabling OS Tx queues", __func__);
661 netif_tx_disable(pAdapter->dev);
662 netif_carrier_off(pAdapter->dev);
663
664
665 /* SoftAP ifaces should never go in power save mode
666 making sure same here. */
667 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode )
668 || (WLAN_HDD_MONITOR == pAdapter->device_mode )
669#ifdef WLAN_FEATURE_P2P
670 || (WLAN_HDD_P2P_GO == pAdapter->device_mode )
671#endif
672 )
673 {
674 /* SoftAP mode, so return from here */
675 EXIT();
676 return 0;
677 }
678
679 /* Find if any iface is up then
680 if any iface is up then can't put device to sleep/ power save mode. */
681 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
682 while ( (NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status) )
683 {
684 if ( pAdapterNode->pAdapter->event_flags & DEVICE_IFACE_OPENED)
685 {
686 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Still other ifaces are up cannot "
687 "put device to sleep", __func__, pAdapter->device_mode);
688 enter_standby = FALSE;
689 break;
690 }
691 else
692 {
693 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
694 pAdapterNode = pNext;
695 }
696 }
697
698 if (TRUE == enter_standby)
699 {
700 hddLog(VOS_TRACE_LEVEL_INFO, "%s: All Interfaces are Down "
701 "entering standby", __func__);
702 if (VOS_STATUS_SUCCESS != wlan_hdd_enter_lowpower(pHddCtx))
703 {
704 /*log and return success*/
705 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Failed to put "
706 "wlan in power save", __func__);
707 }
708 }
709
710 EXIT();
711 return 0;
712}
713
714/**---------------------------------------------------------------------------
715
716 \brief hdd_uninit() - HDD uninit function
717
718 This is called during the netdev unregister to uninitialize all data
719associated with the device
720
721 \param - dev Pointer to net_device structure
722
723 \return - void
724
725 --------------------------------------------------------------------------*/
726static void hdd_uninit (struct net_device *dev)
727{
728 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
729
730 ENTER();
731
732 do
733 {
734 if (NULL == pAdapter)
735 {
736 hddLog(VOS_TRACE_LEVEL_FATAL,
737 "%s: NULL pAdapter", __func__);
738 break;
739 }
740
741 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
742 {
743 hddLog(VOS_TRACE_LEVEL_FATAL,
744 "%s: Invalid magic", __func__);
745 break;
746 }
747
748 if (NULL == pAdapter->pHddCtx)
749 {
750 hddLog(VOS_TRACE_LEVEL_FATAL,
751 "%s: NULL pHddCtx", __func__);
752 break;
753 }
754
755 if (dev != pAdapter->dev)
756 {
757 hddLog(VOS_TRACE_LEVEL_FATAL,
758 "%s: Invalid device reference", __func__);
759 /* we haven't validated all cases so let this go for now */
760 }
761
762 hdd_deinit_adapter(pAdapter->pHddCtx, pAdapter);
763
764 /* after uninit our adapter structure will no longer be valid */
765 pAdapter->dev = NULL;
766 pAdapter->magic = 0;
767 } while (0);
768
769 EXIT();
770}
771
772/**---------------------------------------------------------------------------
773
774 \brief hdd_release_firmware() -
775
776 This function calls the release firmware API to free the firmware buffer.
777
778 \param - pFileName Pointer to the File Name.
779 pCtx - Pointer to the adapter .
780
781
782 \return - 0 for success, non zero for failure
783
784 --------------------------------------------------------------------------*/
785
786VOS_STATUS hdd_release_firmware(char *pFileName,v_VOID_t *pCtx)
787{
788 VOS_STATUS status = VOS_STATUS_SUCCESS;
789 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
790 ENTER();
791
792
793 if (!strcmp(WLAN_FW_FILE, pFileName)) {
794
795 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"%s: Loaded firmware file is %s",__func__,pFileName);
796
797 if(pHddCtx->fw) {
798 release_firmware(pHddCtx->fw);
799 pHddCtx->fw = NULL;
800 }
801 else
802 status = VOS_STATUS_E_FAILURE;
803 }
804 else if (!strcmp(WLAN_NV_FILE,pFileName)) {
805 if(pHddCtx->nv) {
806 release_firmware(pHddCtx->nv);
807 pHddCtx->nv = NULL;
808 }
809 else
810 status = VOS_STATUS_E_FAILURE;
811
812 }
813
814 EXIT();
815 return status;
816}
817
818/**---------------------------------------------------------------------------
819
820 \brief hdd_request_firmware() -
821
822 This function reads the firmware file using the request firmware
823 API and returns the the firmware data and the firmware file size.
824
825 \param - pfileName - Pointer to the file name.
826 - pCtx - Pointer to the adapter .
827 - ppfw_data - Pointer to the pointer of the firmware data.
828 - pSize - Pointer to the file size.
829
830 \return - VOS_STATUS_SUCCESS for success, VOS_STATUS_E_FAILURE for failure
831
832 --------------------------------------------------------------------------*/
833
834
835VOS_STATUS hdd_request_firmware(char *pfileName,v_VOID_t *pCtx,v_VOID_t **ppfw_data, v_SIZE_t *pSize)
836{
837 int status;
838 VOS_STATUS retval = VOS_STATUS_SUCCESS;
839 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
840 ENTER();
841
842 if( (!strcmp(WLAN_FW_FILE, pfileName)) ) {
843
844 status = request_firmware(&pHddCtx->fw, pfileName, pHddCtx->parent_dev);
845
846 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
847 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Firmware %s download failed",
848 __func__, pfileName);
849 retval = VOS_STATUS_E_FAILURE;
850 }
851
852 else {
853 *ppfw_data = (v_VOID_t *)pHddCtx->fw->data;
854 *pSize = pHddCtx->fw->size;
855 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Firmware size = %d",
856 __func__, *pSize);
857 }
858 }
859 else if(!strcmp(WLAN_NV_FILE, pfileName)) {
860
861 status = request_firmware(&pHddCtx->nv, pfileName, pHddCtx->parent_dev);
862
863 if(status || !pHddCtx->nv || !pHddCtx->nv->data) {
864 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: nv %s download failed",
865 __func__, pfileName);
866 retval = VOS_STATUS_E_FAILURE;
867 }
868
869 else {
870 *ppfw_data = (v_VOID_t *)pHddCtx->nv->data;
871 *pSize = pHddCtx->nv->size;
872 hddLog(VOS_TRACE_LEVEL_INFO, "%s: nv file size = %d",
873 __func__, *pSize);
874 }
875 }
876
877 EXIT();
878 return retval;
879}
880/**---------------------------------------------------------------------------
881 \brief hdd_full_pwr_cbk() - HDD full power callbackfunction
882
883 This is the function invoked by SME to inform the result of a full power
884 request issued by HDD
885
886 \param - callbackcontext - Pointer to cookie
887 status - result of request
888
889 \return - None
890
891--------------------------------------------------------------------------*/
892void hdd_full_pwr_cbk(void *callbackContext, eHalStatus status)
893{
894 hdd_context_t *pHddCtx = (hdd_context_t*)callbackContext;
895
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -0700896 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"HDD full Power callback status = %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700897 if(&pHddCtx->full_pwr_comp_var)
898 {
899 complete(&pHddCtx->full_pwr_comp_var);
900 }
901}
902
903/**---------------------------------------------------------------------------
904
905 \brief hdd_req_bmps_cbk() - HDD Request BMPS callback function
906
907 This is the function invoked by SME to inform the result of BMPS
908 request issued by HDD
909
910 \param - callbackcontext - Pointer to cookie
911 status - result of request
912
913 \return - None
914
915--------------------------------------------------------------------------*/
916void hdd_req_bmps_cbk(void *callbackContext, eHalStatus status)
917{
918
919 struct completion *completion_var = (struct completion*) callbackContext;
920
921 hddLog(VOS_TRACE_LEVEL_ERROR, "HDD BMPS request Callback, status = %d\n", status);
922 if(completion_var != NULL)
923 {
924 complete(completion_var);
925 }
926}
927
928/**---------------------------------------------------------------------------
929
930 \brief hdd_get_cfg_file_size() -
931
932 This function reads the configuration file using the request firmware
933 API and returns the configuration file size.
934
935 \param - pCtx - Pointer to the adapter .
936 - pFileName - Pointer to the file name.
937 - pBufSize - Pointer to the buffer size.
938
939 \return - 0 for success, non zero for failure
940
941 --------------------------------------------------------------------------*/
942
943VOS_STATUS hdd_get_cfg_file_size(v_VOID_t *pCtx, char *pFileName, v_SIZE_t *pBufSize)
944{
945 int status;
946 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
947
948 ENTER();
949
950 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
951
952 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
953 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
954 status = VOS_STATUS_E_FAILURE;
955 }
956 else {
957 *pBufSize = pHddCtx->fw->size;
958 hddLog(VOS_TRACE_LEVEL_INFO, "%s: CFG size = %d", __func__, *pBufSize);
959 release_firmware(pHddCtx->fw);
960 pHddCtx->fw = NULL;
961 }
962
963 EXIT();
964 return VOS_STATUS_SUCCESS;
965}
966
967/**---------------------------------------------------------------------------
968
969 \brief hdd_read_cfg_file() -
970
971 This function reads the configuration file using the request firmware
972 API and returns the cfg data and the buffer size of the configuration file.
973
974 \param - pCtx - Pointer to the adapter .
975 - pFileName - Pointer to the file name.
976 - pBuffer - Pointer to the data buffer.
977 - pBufSize - Pointer to the buffer size.
978
979 \return - 0 for success, non zero for failure
980
981 --------------------------------------------------------------------------*/
982
983VOS_STATUS hdd_read_cfg_file(v_VOID_t *pCtx, char *pFileName,
984 v_VOID_t *pBuffer, v_SIZE_t *pBufSize)
985{
986 int status;
987 hdd_context_t *pHddCtx = (hdd_context_t*)pCtx;
988
989 ENTER();
990
991 status = request_firmware(&pHddCtx->fw, pFileName, pHddCtx->parent_dev);
992
993 if(status || !pHddCtx->fw || !pHddCtx->fw->data) {
994 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: CFG download failed",__func__);
995 return VOS_STATUS_E_FAILURE;
996 }
997 else {
998 if(*pBufSize != pHddCtx->fw->size) {
999 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Caller sets invalid CFG "
1000 "file size", __func__);
1001 release_firmware(pHddCtx->fw);
1002 pHddCtx->fw = NULL;
1003 return VOS_STATUS_E_FAILURE;
1004 }
1005 else {
1006 if(pBuffer) {
1007 vos_mem_copy(pBuffer,pHddCtx->fw->data,*pBufSize);
1008 }
1009 release_firmware(pHddCtx->fw);
1010 pHddCtx->fw = NULL;
1011 }
1012 }
1013
1014 EXIT();
1015
1016 return VOS_STATUS_SUCCESS;
1017}
1018
1019/**---------------------------------------------------------------------------
1020
1021 \brief hdd_set_mac_addr_cb() -
1022
1023 This function is the call back function for setting the station
1024 mac adrress called by ccm module to indicate the
1025 success/failure result.
1026
1027 \param - hHal - Pointer to the hal module.
1028 - result - returns the result of the set mac address.
1029
1030 \return - void
1031
1032 --------------------------------------------------------------------------*/
1033#ifndef FEATURE_WLAN_INTEGRATED_SOC
1034static void hdd_set_mac_addr_cb( tHalHandle hHal, tANI_S32 result )
1035{
1036 // ignore the STA_ID response for now.
1037
1038 VOS_ASSERT( CCM_IS_RESULT_SUCCESS( result ) );
1039}
1040#endif
1041
1042
1043/**---------------------------------------------------------------------------
1044
1045 \brief hdd_set_mac_address() -
1046
1047 This function sets the user specified mac address using
1048 the command ifconfig wlanX hw ether <mac adress>.
1049
1050 \param - dev - Pointer to the net device.
1051 - addr - Pointer to the sockaddr.
1052 \return - 0 for success, non zero for failure
1053
1054 --------------------------------------------------------------------------*/
1055
1056static int hdd_set_mac_address(struct net_device *dev, void *addr)
1057{
1058 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
1059 struct sockaddr *psta_mac_addr = addr;
1060 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
1061
1062 ENTER();
1063
1064 memcpy(&pAdapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
1065
1066#ifdef HDD_SESSIONIZE
1067 // set the MAC address though the STA ID CFG.
1068 halStatus = ccmCfgSetStr( pAdapter->hHal, WNI_CFG_STA_ID,
1069 (v_U8_t *)&pAdapter->macAddressCurrent,
1070 sizeof( pAdapter->macAddressCurrent ),
1071 hdd_set_mac_addr_cb, VOS_FALSE );
1072#endif
1073
1074 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
1075
1076 EXIT();
1077 return halStatus;
1078}
1079
1080tANI_U8* wlan_hdd_get_intf_addr(hdd_context_t* pHddCtx)
1081{
1082 int i;
1083 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
1084 {
1085 if( 0 == (pHddCtx->cfg_ini->intfAddrMask >> i))
1086 break;
1087 }
1088
1089 if( VOS_MAX_CONCURRENCY_PERSONA == i)
1090 return NULL;
1091
1092 pHddCtx->cfg_ini->intfAddrMask |= (1 << i);
1093 return &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0];
1094}
1095
1096void wlan_hdd_release_intf_addr(hdd_context_t* pHddCtx, tANI_U8* releaseAddr)
1097{
1098 int i;
1099 for ( i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
1100 {
1101 if ( !memcmp(releaseAddr, &pHddCtx->cfg_ini->intfMacAddr[i].bytes[0], 6) )
1102 {
1103 pHddCtx->cfg_ini->intfAddrMask &= ~(1 << i);
1104 break;
1105 }
1106 }
1107 return;
1108}
1109
1110#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
1111 static struct net_device_ops wlan_drv_ops = {
1112 .ndo_open = hdd_open,
1113 .ndo_stop = hdd_stop,
1114 .ndo_uninit = hdd_uninit,
1115 .ndo_start_xmit = hdd_hard_start_xmit,
1116 .ndo_tx_timeout = hdd_tx_timeout,
1117 .ndo_get_stats = hdd_stats,
1118 .ndo_do_ioctl = hdd_ioctl,
1119 .ndo_set_mac_address = hdd_set_mac_address,
1120 .ndo_select_queue = hdd_select_queue,
1121#ifdef WLAN_FEATURE_PACKET_FILTERING
1122#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0))
1123 .ndo_set_rx_mode = hdd_set_multicast_list,
1124#else
1125 .ndo_set_multicast_list = hdd_set_multicast_list,
1126#endif //LINUX_VERSION_CODE
1127#endif
1128 };
1129#ifdef CONFIG_CFG80211
1130 static struct net_device_ops wlan_mon_drv_ops = {
1131 .ndo_open = hdd_mon_open,
1132 .ndo_stop = hdd_stop,
1133 .ndo_uninit = hdd_uninit,
1134 .ndo_start_xmit = hdd_mon_hard_start_xmit,
1135 .ndo_tx_timeout = hdd_tx_timeout,
1136 .ndo_get_stats = hdd_stats,
1137 .ndo_do_ioctl = hdd_ioctl,
1138 .ndo_set_mac_address = hdd_set_mac_address,
1139 };
1140#endif
1141
1142#endif
1143
1144void hdd_set_station_ops( struct net_device *pWlanDev )
1145{
1146#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
1147 pWlanDev->tx_queue_len = NET_DEV_TX_QUEUE_LEN,
1148 pWlanDev->netdev_ops = &wlan_drv_ops;
1149#else
1150 pWlanDev->open = hdd_open;
1151 pWlanDev->stop = hdd_stop;
1152 pWlanDev->uninit = hdd_uninit;
1153 pWlanDev->hard_start_xmit = NULL;
1154 pWlanDev->tx_timeout = hdd_tx_timeout;
1155 pWlanDev->get_stats = hdd_stats;
1156 pWlanDev->do_ioctl = hdd_ioctl;
1157 pWlanDev->tx_queue_len = NET_DEV_TX_QUEUE_LEN;
1158 pWlanDev->set_mac_address = hdd_set_mac_address;
1159#endif
1160}
1161
Jeff Johnsoneed415b2013-01-18 16:11:20 -08001162static hdd_adapter_t* hdd_alloc_station_adapter( hdd_context_t *pHddCtx, tSirMacAddr macAddr, const char* name )
Jeff Johnson295189b2012-06-20 16:38:30 -07001163{
1164 struct net_device *pWlanDev = NULL;
1165 hdd_adapter_t *pAdapter = NULL;
1166#ifdef CONFIG_CFG80211
1167 /*
1168 * cfg80211 initialization and registration....
1169 */
1170 pWlanDev = alloc_netdev_mq(sizeof( hdd_adapter_t ), name, ether_setup, NUM_TX_QUEUES);
1171
1172#else
1173 //Allocate the net_device and private data (station ctx)
1174 pWlanDev = alloc_etherdev_mq(sizeof( hdd_adapter_t ), NUM_TX_QUEUES);
1175
1176#endif
1177
1178 if(pWlanDev != NULL)
1179 {
1180
1181 //Save the pointer to the net_device in the HDD adapter
1182 pAdapter = (hdd_adapter_t*) netdev_priv( pWlanDev );
1183
1184#ifndef CONFIG_CFG80211
1185 //Init the net_device structure
1186 ether_setup(pWlanDev);
1187#endif
1188
1189 vos_mem_zero( pAdapter, sizeof( hdd_adapter_t ) );
1190
1191 pAdapter->dev = pWlanDev;
1192 pAdapter->pHddCtx = pHddCtx;
1193 pAdapter->magic = WLAN_HDD_ADAPTER_MAGIC;
1194
1195 init_completion(&pAdapter->session_open_comp_var);
1196 init_completion(&pAdapter->session_close_comp_var);
1197 init_completion(&pAdapter->disconnect_comp_var);
1198 init_completion(&pAdapter->linkup_event_var);
1199 init_completion(&pAdapter->cancel_rem_on_chan_var);
1200 init_completion(&pAdapter->rem_on_chan_ready_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07001201#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
1202 init_completion(&pAdapter->offchannel_tx_event);
1203#endif
1204#ifdef CONFIG_CFG80211
1205 init_completion(&pAdapter->tx_action_cnf_event);
1206#endif
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001207#ifdef FEATURE_WLAN_TDLS
1208 init_completion(&pAdapter->tdls_add_station_comp);
1209#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001210 init_completion(&pHddCtx->mc_sus_event_var);
1211 init_completion(&pHddCtx->tx_sus_event_var);
1212
Jeff Johnson295189b2012-06-20 16:38:30 -07001213 pAdapter->isLinkUpSvcNeeded = FALSE;
1214 pAdapter->higherDtimTransition = eANI_BOOLEAN_TRUE;
1215 //Init the net_device structure
1216 strlcpy(pWlanDev->name, name, IFNAMSIZ);
1217
1218 vos_mem_copy(pWlanDev->dev_addr, (void *)macAddr, sizeof(tSirMacAddr));
1219 vos_mem_copy( pAdapter->macAddressCurrent.bytes, macAddr, sizeof(tSirMacAddr));
1220 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
1221 pWlanDev->hard_header_len += LIBRA_HW_NEEDED_HEADROOM;
1222
1223 hdd_set_station_ops( pAdapter->dev );
1224
1225 pWlanDev->destructor = free_netdev;
1226#ifdef CONFIG_CFG80211
1227 pWlanDev->ieee80211_ptr = &pAdapter->wdev ;
1228 pAdapter->wdev.wiphy = pHddCtx->wiphy;
1229 pAdapter->wdev.netdev = pWlanDev;
1230#endif
1231 /* set pWlanDev's parent to underlying device */
1232 SET_NETDEV_DEV(pWlanDev, pHddCtx->parent_dev);
1233 }
1234
1235 return pAdapter;
1236}
1237
1238VOS_STATUS hdd_register_interface( hdd_adapter_t *pAdapter, tANI_U8 rtnl_lock_held )
1239{
1240 struct net_device *pWlanDev = pAdapter->dev;
1241 //hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
1242 //hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
1243 //eHalStatus halStatus = eHAL_STATUS_SUCCESS;
1244
1245 if( rtnl_lock_held )
1246 {
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -08001247 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001248 if( dev_alloc_name(pWlanDev, pWlanDev->name) < 0 )
1249 {
1250 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:dev_alloc_name",__func__);
1251 return VOS_STATUS_E_FAILURE;
1252 }
1253 }
1254 if (register_netdevice(pWlanDev))
1255 {
1256 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:register_netdev",__func__);
1257 return VOS_STATUS_E_FAILURE;
1258 }
1259 }
1260 else
1261 {
1262 if(register_netdev(pWlanDev))
1263 {
1264 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed:register_netdev",__func__);
1265 return VOS_STATUS_E_FAILURE;
1266 }
1267 }
1268 set_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags);
1269
1270 return VOS_STATUS_SUCCESS;
1271}
1272
1273eHalStatus hdd_smeCloseSessionCallback(void *pContext)
1274{
1275 if(pContext != NULL)
1276 {
1277 clear_bit(SME_SESSION_OPENED, &((hdd_adapter_t*)pContext)->event_flags);
1278
1279 /* need to make sure all of our scheduled work has completed.
1280 * This callback is called from MC thread context, so it is safe to
1281 * to call below flush workqueue API from here.
1282 */
1283 flush_scheduled_work();
1284 complete(&((hdd_adapter_t*)pContext)->session_close_comp_var);
1285 }
1286 return eHAL_STATUS_SUCCESS;
1287}
1288
1289VOS_STATUS hdd_init_station_mode( hdd_adapter_t *pAdapter )
1290{
1291 struct net_device *pWlanDev = pAdapter->dev;
1292 hdd_station_ctx_t *pHddStaCtx = &pAdapter->sessionCtx.station;
1293 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
1294 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
1295 VOS_STATUS status = VOS_STATUS_E_FAILURE;
1296 int rc = 0;
1297
1298 INIT_COMPLETION(pAdapter->session_open_comp_var);
1299 //Open a SME session for future operation
1300 halStatus = sme_OpenSession( pHddCtx->hHal, hdd_smeRoamCallback, pAdapter,
1301 (tANI_U8 *)&pAdapter->macAddressCurrent, &pAdapter->sessionId );
1302 if ( !HAL_STATUS_SUCCESS( halStatus ) )
1303 {
1304 hddLog(VOS_TRACE_LEVEL_FATAL,
1305 "sme_OpenSession() failed with status code %08d [x%08lx]",
1306 halStatus, halStatus );
1307 status = VOS_STATUS_E_FAILURE;
1308 goto error_sme_open;
1309 }
1310
1311 //Block on a completion variable. Can't wait forever though.
1312 rc = wait_for_completion_interruptible_timeout(
1313 &pAdapter->session_open_comp_var,
1314 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
1315 if (!rc)
1316 {
1317 hddLog(VOS_TRACE_LEVEL_FATAL,
1318 "Session is not opened within timeout period code %08d", rc );
1319 status = VOS_STATUS_E_FAILURE;
1320 goto error_sme_open;
1321 }
1322
1323 // Register wireless extensions
1324 if( eHAL_STATUS_SUCCESS != (halStatus = hdd_register_wext(pWlanDev)))
1325 {
1326 hddLog(VOS_TRACE_LEVEL_FATAL,
1327 "hdd_register_wext() failed with status code %08d [x%08lx]",
1328 halStatus, halStatus );
1329 status = VOS_STATUS_E_FAILURE;
1330 goto error_register_wext;
1331 }
1332 //Safe to register the hard_start_xmit function again
1333#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
1334 wlan_drv_ops.ndo_start_xmit = hdd_hard_start_xmit;
1335#else
1336 pWlanDev->hard_start_xmit = hdd_hard_start_xmit;
1337#endif
1338
1339 //Set the Connection State to Not Connected
1340 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
1341
1342 //Set the default operation channel
1343 pHddStaCtx->conn_info.operationChannel = pHddCtx->cfg_ini->OperatingChannel;
1344
1345 /* Make the default Auth Type as OPEN*/
1346 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
1347
1348 if( VOS_STATUS_SUCCESS != ( status = hdd_init_tx_rx( pAdapter ) ) )
1349 {
1350 hddLog(VOS_TRACE_LEVEL_FATAL,
1351 "hdd_init_tx_rx() failed with status code %08d [x%08lx]",
1352 status, status );
1353 goto error_init_txrx;
1354 }
1355
1356 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
1357
1358 if( VOS_STATUS_SUCCESS != ( status = hdd_wmm_adapter_init( pAdapter ) ) )
1359 {
1360 hddLog(VOS_TRACE_LEVEL_FATAL,
1361 "hdd_wmm_adapter_init() failed with status code %08d [x%08lx]",
1362 status, status );
1363 goto error_wmm_init;
1364 }
1365
1366 set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
1367
1368 return VOS_STATUS_SUCCESS;
1369
1370error_wmm_init:
1371 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
1372 hdd_deinit_tx_rx(pAdapter);
1373error_init_txrx:
1374 hdd_UnregisterWext(pWlanDev);
1375error_register_wext:
1376 if(test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
1377 {
1378 INIT_COMPLETION(pAdapter->session_close_comp_var);
1379 if( eHAL_STATUS_SUCCESS == sme_CloseSession( pHddCtx->hHal,
1380 pAdapter->sessionId,
1381 hdd_smeCloseSessionCallback, pAdapter ) )
1382 {
1383 //Block on a completion variable. Can't wait forever though.
1384 wait_for_completion_interruptible_timeout(
1385 &pAdapter->session_close_comp_var,
1386 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
1387 }
1388}
1389error_sme_open:
1390 return status;
1391}
1392
Jeff Johnson295189b2012-06-20 16:38:30 -07001393#ifdef CONFIG_CFG80211
1394void hdd_cleanup_actionframe( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
1395{
1396 hdd_cfg80211_state_t *cfgState;
1397
1398 cfgState = WLAN_HDD_GET_CFG_STATE_PTR( pAdapter );
1399
1400 if( NULL != cfgState->buf )
1401 {
1402 int rc;
1403 INIT_COMPLETION(pAdapter->tx_action_cnf_event);
1404 rc = wait_for_completion_interruptible_timeout(
1405 &pAdapter->tx_action_cnf_event,
1406 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
1407 if(!rc)
1408 {
Sudhir Sattayappa Kohalli8ee532d2013-02-15 13:16:26 -08001409 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07001410 ("ERROR: HDD Wait for Action Confirmation Failed!!\n"));
1411 }
1412 }
1413 return;
1414}
1415#endif
1416
1417void hdd_deinit_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
1418{
1419 ENTER();
1420 switch ( pAdapter->device_mode )
1421 {
1422 case WLAN_HDD_INFRA_STATION:
1423 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07001424 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07001425 {
1426 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
1427 {
1428 hdd_deinit_tx_rx( pAdapter );
1429 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
1430 }
1431
1432 if(test_bit(WMM_INIT_DONE, &pAdapter->event_flags))
1433 {
1434 hdd_wmm_adapter_close( pAdapter );
1435 clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
1436 }
1437
1438#ifdef CONFIG_CFG80211
1439 hdd_cleanup_actionframe(pHddCtx, pAdapter);
1440#endif
1441
1442 break;
1443 }
1444
1445 case WLAN_HDD_SOFTAP:
1446 case WLAN_HDD_P2P_GO:
1447#ifdef WLAN_SOFTAP_FEATURE
1448 {
1449#ifdef CONFIG_CFG80211
1450 hdd_cleanup_actionframe(pHddCtx, pAdapter);
1451#endif
1452
1453 hdd_unregister_hostapd(pAdapter);
1454 hdd_set_conparam( 0 );
1455#ifdef CONFIG_CFG80211
1456 wlan_hdd_set_monitor_tx_adapter( WLAN_HDD_GET_CTX(pAdapter), NULL );
1457#endif
1458 break;
1459 }
1460
1461 case WLAN_HDD_MONITOR:
1462 {
1463#ifdef CONFIG_CFG80211
1464 hdd_adapter_t* pAdapterforTx = pAdapter->sessionCtx.monitor.pAdapterForTx;
1465#endif
1466 if(test_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags))
1467 {
1468 hdd_deinit_tx_rx( pAdapter );
1469 clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
1470 }
1471#ifdef CONFIG_CFG80211
1472 if(NULL != pAdapterforTx)
1473 {
1474 hdd_cleanup_actionframe(pHddCtx, pAdapterforTx);
1475 }
1476#endif
1477#endif //WLAN_SOFTAP_FEATURE
1478 break;
1479 }
1480
1481
1482 default:
1483 break;
1484 }
1485
1486 EXIT();
1487}
1488
1489void hdd_cleanup_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter, tANI_U8 rtnl_held )
1490{
1491 struct net_device *pWlanDev = pAdapter->dev;
1492
1493 if(test_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags)) {
1494 if( rtnl_held )
1495 {
1496 unregister_netdevice(pWlanDev);
1497 }
1498 else
1499 {
1500 unregister_netdev(pWlanDev);
1501 }
1502 // note that the pAdapter is no longer valid at this point
1503 // since the memory has been reclaimed
1504 }
1505
1506}
1507
1508VOS_STATUS hdd_enable_bmps_imps(hdd_context_t *pHddCtx)
1509{
1510 VOS_STATUS status = VOS_STATUS_SUCCESS;
1511
1512 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
1513 {
1514 sme_EnablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
1515 }
1516
1517 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
1518 {
1519 sme_StartAutoBmpsTimer(pHddCtx->hHal);
1520 }
1521
1522 if (pHddCtx->cfg_ini->fIsImpsEnabled)
1523 {
1524 sme_EnablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
1525 }
1526
1527 return status;
1528}
1529
1530VOS_STATUS hdd_disable_bmps_imps(hdd_context_t *pHddCtx, tANI_U8 session_type)
1531{
1532 hdd_adapter_t *pAdapter = NULL;
1533 eHalStatus halStatus;
1534 VOS_STATUS status = VOS_STATUS_E_INVAL;
1535 v_BOOL_t disableBmps = FALSE;
1536 v_BOOL_t disableImps = FALSE;
1537
1538 switch(session_type)
1539 {
1540 case WLAN_HDD_INFRA_STATION:
1541 case WLAN_HDD_SOFTAP:
1542#ifdef WLAN_FEATURE_P2P
1543 case WLAN_HDD_P2P_CLIENT:
1544 case WLAN_HDD_P2P_GO:
1545#endif
1546 //Exit BMPS -> Is Sta/P2P Client is already connected
1547 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
1548 if((NULL != pAdapter)&&
1549 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
1550 {
1551 disableBmps = TRUE;
1552 }
1553
1554 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_CLIENT);
1555 if((NULL != pAdapter)&&
1556 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR(pAdapter)))
1557 {
1558 disableBmps = TRUE;
1559 }
1560
1561 //Exit both Bmps and Imps incase of Go/SAP Mode
1562 if((WLAN_HDD_SOFTAP == session_type) ||
1563 (WLAN_HDD_P2P_GO == session_type))
1564 {
1565 disableBmps = TRUE;
1566 disableImps = TRUE;
1567 }
1568
1569 if(TRUE == disableImps)
1570 {
1571 if (pHddCtx->cfg_ini->fIsImpsEnabled)
1572 {
1573 sme_DisablePowerSave (pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
1574 }
1575 }
1576
1577 if(TRUE == disableBmps)
1578 {
1579 if(pHddCtx->cfg_ini->fIsBmpsEnabled)
1580 {
1581 halStatus = sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
1582
1583 if(eHAL_STATUS_SUCCESS != halStatus)
1584 {
1585 status = VOS_STATUS_E_FAILURE;
1586 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Disable Power Save\n", __func__);
1587 VOS_ASSERT(0);
1588 return status;
1589 }
1590 }
1591
1592 if(pHddCtx->cfg_ini->fIsAutoBmpsTimerEnabled)
1593 {
1594 halStatus = sme_StopAutoBmpsTimer(pHddCtx->hHal);
1595
1596 if(eHAL_STATUS_SUCCESS != halStatus)
1597 {
1598 status = VOS_STATUS_E_FAILURE;
1599 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Fail to Stop Auto Bmps Timer\n", __func__);
1600 VOS_ASSERT(0);
1601 return status;
1602 }
1603 }
1604 }
1605
1606 if((TRUE == disableBmps) ||
1607 (TRUE == disableImps))
1608 {
1609 /* Now, get the chip into Full Power now */
1610 INIT_COMPLETION(pHddCtx->full_pwr_comp_var);
1611 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_pwr_cbk,
1612 pHddCtx, eSME_FULL_PWR_NEEDED_BY_HDD);
1613
1614 if(halStatus != eHAL_STATUS_SUCCESS)
1615 {
1616 if(halStatus == eHAL_STATUS_PMC_PENDING)
1617 {
1618 //Block on a completion variable. Can't wait forever though
1619 wait_for_completion_interruptible_timeout(
1620 &pHddCtx->full_pwr_comp_var, msecs_to_jiffies(1000));
1621 }
1622 else
1623 {
1624 status = VOS_STATUS_E_FAILURE;
1625 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Request for Full Power failed\n", __func__);
1626 VOS_ASSERT(0);
1627 return status;
1628 }
1629 }
1630
1631 status = VOS_STATUS_SUCCESS;
1632 }
1633
1634 break;
1635 }
1636 return status;
1637}
1638
1639hdd_adapter_t* hdd_open_adapter( hdd_context_t *pHddCtx, tANI_U8 session_type,
Jeff Johnsoneed415b2013-01-18 16:11:20 -08001640 const char *iface_name, tSirMacAddr macAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -07001641 tANI_U8 rtnl_held )
1642{
1643 hdd_adapter_t *pAdapter = NULL;
1644 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
1645 VOS_STATUS status = VOS_STATUS_E_FAILURE;
1646 VOS_STATUS exitbmpsStatus;
1647
1648 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s iface =%s type = %d\n",__func__,iface_name,session_type);
1649
1650 //Disable BMPS incase of Concurrency
1651 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, session_type);
1652
1653 if(VOS_STATUS_E_FAILURE == exitbmpsStatus)
1654 {
1655 //Fail to Exit BMPS
1656 VOS_ASSERT(0);
1657 return NULL;
1658 }
1659
1660 switch(session_type)
1661 {
1662 case WLAN_HDD_INFRA_STATION:
1663#ifdef WLAN_FEATURE_P2P
1664 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07001665 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07001666#endif
1667 {
1668 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
1669
1670 if( NULL == pAdapter )
1671 return NULL;
1672
1673#ifdef CONFIG_CFG80211
Jeff Johnsone7245742012-09-05 17:12:55 -07001674 pAdapter->wdev.iftype = (session_type == WLAN_HDD_P2P_CLIENT) ?
1675 NL80211_IFTYPE_P2P_CLIENT:
1676 NL80211_IFTYPE_STATION;
Jeff Johnson295189b2012-06-20 16:38:30 -07001677#endif
1678
Jeff Johnson295189b2012-06-20 16:38:30 -07001679 pAdapter->device_mode = session_type;
1680
1681 status = hdd_init_station_mode( pAdapter );
1682 if( VOS_STATUS_SUCCESS != status )
1683 goto err_free_netdev;
1684
1685 status = hdd_register_interface( pAdapter, rtnl_held );
1686 if( VOS_STATUS_SUCCESS != status )
1687 {
1688 hdd_deinit_adapter(pHddCtx, pAdapter);
1689 goto err_free_netdev;
1690 }
1691 //Stop the Interface TX queue.
1692 netif_tx_disable(pAdapter->dev);
1693 //netif_tx_disable(pWlanDev);
1694 netif_carrier_off(pAdapter->dev);
1695
1696 break;
1697 }
1698
1699#ifdef WLAN_FEATURE_P2P
1700 case WLAN_HDD_P2P_GO:
1701#endif
1702 case WLAN_HDD_SOFTAP:
1703 {
1704 pAdapter = hdd_wlan_create_ap_dev( pHddCtx, macAddr, (tANI_U8 *)iface_name );
1705 if( NULL == pAdapter )
1706 return NULL;
1707
1708#ifdef CONFIG_CFG80211
1709 pAdapter->wdev.iftype = (session_type == WLAN_HDD_SOFTAP) ?
1710 NL80211_IFTYPE_AP:
1711 NL80211_IFTYPE_P2P_GO;
1712#endif
1713 pAdapter->device_mode = session_type;
1714
1715 status = hdd_init_ap_mode(pAdapter);
1716 if( VOS_STATUS_SUCCESS != status )
1717 goto err_free_netdev;
1718
1719 status = hdd_register_hostapd( pAdapter, rtnl_held );
1720 if( VOS_STATUS_SUCCESS != status )
1721 {
1722 hdd_deinit_adapter(pHddCtx, pAdapter);
1723 goto err_free_netdev;
1724 }
1725
1726 netif_tx_disable(pAdapter->dev);
1727 netif_carrier_off(pAdapter->dev);
1728
1729 hdd_set_conparam( 1 );
1730 break;
1731 }
1732 case WLAN_HDD_MONITOR:
1733 {
1734#ifdef CONFIG_CFG80211
1735 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
1736 if( NULL == pAdapter )
1737 return NULL;
1738
1739 pAdapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
1740 pAdapter->device_mode = session_type;
1741 status = hdd_register_interface( pAdapter, rtnl_held );
1742#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29)
1743 pAdapter->dev->netdev_ops = &wlan_mon_drv_ops;
1744#else
1745 pAdapter->dev->open = hdd_mon_open;
1746 pAdapter->dev->hard_start_xmit = hdd_mon_hard_start_xmit;
1747#endif
1748 hdd_init_tx_rx( pAdapter );
1749 set_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
1750 //Set adapter to be used for data tx. It will use either GO or softap.
1751 pAdapter->sessionCtx.monitor.pAdapterForTx =
1752 hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_SOFTAP);
1753#ifdef WLAN_FEATURE_P2P
1754 if (NULL == pAdapter->sessionCtx.monitor.pAdapterForTx)
1755 {
1756 pAdapter->sessionCtx.monitor.pAdapterForTx =
1757 hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_GO);
1758 }
1759#endif
1760 /* This workqueue will be used to transmit management packet over
1761 * monitor interface. */
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07001762 if (NULL == pAdapter->sessionCtx.monitor.pAdapterForTx) {
1763 hddLog(VOS_TRACE_LEVEL_ERROR,"%s:Failed:hdd_get_adapter",__func__);
1764 return NULL;
1765 }
Madan Mohan Koyyalamudi9f40ceb2012-10-18 19:22:56 -07001766
Jeff Johnson295189b2012-06-20 16:38:30 -07001767 INIT_WORK(&pAdapter->sessionCtx.monitor.pAdapterForTx->monTxWorkQueue,
1768 hdd_mon_tx_work_queue);
1769#endif
1770 }
1771 break;
1772#ifdef ANI_MANF_DIAG
1773 case WLAN_HDD_FTM:
1774 {
1775 pAdapter = hdd_alloc_station_adapter( pHddCtx, macAddr, iface_name );
1776
1777 if( NULL == pAdapter )
1778 return NULL;
1779 /* Assign NL80211_IFTYPE_STATION as interface type to resolve Kernel Warning
1780 * message while loading driver in FTM mode. */
1781 pAdapter->wdev.iftype = NL80211_IFTYPE_STATION;
1782 pAdapter->device_mode = session_type;
1783 status = hdd_register_interface( pAdapter, rtnl_held );
1784 }
1785 break;
1786#endif
1787 default:
1788 {
1789 VOS_ASSERT(0);
1790 return NULL;
1791 }
1792 }
1793
1794
1795 if( VOS_STATUS_SUCCESS == status )
1796 {
1797 //Add it to the hdd's session list.
1798 pHddAdapterNode = vos_mem_malloc( sizeof( hdd_adapter_list_node_t ) );
1799 if( NULL == pHddAdapterNode )
1800 {
1801 status = VOS_STATUS_E_NOMEM;
1802 }
1803 else
1804 {
1805 pHddAdapterNode->pAdapter = pAdapter;
1806 status = hdd_add_adapter_back ( pHddCtx,
1807 pHddAdapterNode );
1808 }
1809 }
1810
1811 if( VOS_STATUS_SUCCESS != status )
1812 {
1813 if( NULL != pAdapter )
1814 {
1815 hdd_cleanup_adapter( pHddCtx, pAdapter, rtnl_held );
1816 pAdapter = NULL;
1817 }
1818 if( NULL != pHddAdapterNode )
1819 {
1820 vos_mem_free( pHddAdapterNode );
1821 }
1822
1823 goto resume_bmps;
1824 }
1825
1826 if(VOS_STATUS_SUCCESS == status)
1827 {
1828 wlan_hdd_set_concurrency_mode(pHddCtx, session_type);
1829
1830#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
1831 /* If there are concurrent session enable SW frame translation
1832 * for all registered STA
1833 * This is not required in case of PRIMA as HW frame translation
1834 * is disabled in PRIMA*/
1835 if (vos_concurrent_sessions_running())
1836 {
1837 WLANTL_ConfigureSwFrameTXXlationForAll(pHddCtx->pvosContext, TRUE);
1838 }
1839#endif
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -07001840 //Initialize the WoWL service
1841 if(!hdd_init_wowl(pAdapter))
1842 {
1843 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_init_wowl failed",__func__);
1844 goto err_free_netdev;
1845 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001846 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001847 return pAdapter;
1848
1849err_free_netdev:
1850 free_netdev(pAdapter->dev);
1851 wlan_hdd_release_intf_addr( pHddCtx,
1852 pAdapter->macAddressCurrent.bytes );
1853
1854resume_bmps:
1855 //If bmps disabled enable it
1856 if(VOS_STATUS_SUCCESS == exitbmpsStatus)
1857 {
1858 hdd_enable_bmps_imps(pHddCtx);
1859 }
1860 return NULL;
1861}
1862
1863VOS_STATUS hdd_close_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter,
1864 tANI_U8 rtnl_held )
1865{
1866 hdd_adapter_list_node_t *pAdapterNode, *pCurrent, *pNext;
1867 VOS_STATUS status;
1868
1869 status = hdd_get_front_adapter ( pHddCtx, &pCurrent );
1870 if( VOS_STATUS_SUCCESS != status )
1871 return status;
1872
1873 while ( pCurrent->pAdapter != pAdapter )
1874 {
1875 status = hdd_get_next_adapter ( pHddCtx, pCurrent, &pNext );
1876 if( VOS_STATUS_SUCCESS != status )
1877 break;
1878
1879 pCurrent = pNext;
1880 }
1881 pAdapterNode = pCurrent;
1882 if( VOS_STATUS_SUCCESS == status )
1883 {
1884 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
1885 hdd_cleanup_adapter( pHddCtx, pAdapterNode->pAdapter, rtnl_held );
1886 hdd_remove_adapter( pHddCtx, pAdapterNode );
1887 vos_mem_free( pAdapterNode );
1888
1889#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
1890 /* If there is no concurrent session disable SW frame translation
1891 * for all registered STA */
1892 /* This is not required in case of PRIMA as HW frame translation
1893 * is disabled in PRIMA*/
1894 if (!vos_concurrent_sessions_running())
1895 {
1896 WLANTL_ConfigureSwFrameTXXlationForAll(pHddCtx->pvosContext, FALSE);
1897 }
1898#endif
1899
1900 /* If there is a single session of STA/P2P client, re-enable BMPS */
1901 if ((!vos_concurrent_sessions_running()) &&
1902 ((pHddCtx->no_of_sessions[VOS_STA_MODE] >= 1) ||
1903 (pHddCtx->no_of_sessions[VOS_P2P_CLIENT_MODE] >= 1)))
1904 {
1905 hdd_enable_bmps_imps(pHddCtx);
1906 }
1907
1908 return VOS_STATUS_SUCCESS;
1909 }
1910
1911 return VOS_STATUS_E_FAILURE;
1912}
1913
1914VOS_STATUS hdd_close_all_adapters( hdd_context_t *pHddCtx )
1915{
1916 hdd_adapter_list_node_t *pHddAdapterNode;
1917 VOS_STATUS status;
1918
1919 ENTER();
1920
1921 do
1922 {
1923 status = hdd_remove_front_adapter( pHddCtx, &pHddAdapterNode );
1924 if( pHddAdapterNode && VOS_STATUS_SUCCESS == status )
1925 {
1926 hdd_cleanup_adapter( pHddCtx, pHddAdapterNode->pAdapter, FALSE );
1927 vos_mem_free( pHddAdapterNode );
1928 }
1929 }while( NULL != pHddAdapterNode && VOS_STATUS_E_EMPTY != status );
1930
1931 EXIT();
1932
1933 return VOS_STATUS_SUCCESS;
1934}
1935
1936void wlan_hdd_reset_prob_rspies(hdd_adapter_t* pHostapdAdapter)
1937{
1938 v_U8_t addIE[1] = {0};
1939
1940 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1941 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,(tANI_U8*)addIE, 0, NULL,
1942 eANI_BOOLEAN_FALSE) )
1943 {
1944 hddLog(LOGE,
1945 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM\n");
1946 }
1947
1948 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1949 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1950 eANI_BOOLEAN_FALSE) )
1951 {
1952 hddLog(LOGE,
1953 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1954 }
1955
1956 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1957 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1958 eANI_BOOLEAN_FALSE) )
1959 {
1960 hddLog(LOGE,
1961 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1962 }
1963}
1964
1965VOS_STATUS hdd_stop_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
1966{
1967 eHalStatus halStatus = eHAL_STATUS_SUCCESS;
1968 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1969 union iwreq_data wrqu;
1970
1971 ENTER();
1972
1973 switch(pAdapter->device_mode)
1974 {
1975 case WLAN_HDD_INFRA_STATION:
1976 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07001977 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07001978 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
1979 {
1980 if (pWextState->roamProfile.BSSType == eCSR_BSS_TYPE_START_IBSS)
1981 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
1982 pAdapter->sessionId,
1983 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
1984 else
1985 halStatus = sme_RoamDisconnect(pHddCtx->hHal,
1986 pAdapter->sessionId,
1987 eCSR_DISCONNECT_REASON_UNSPECIFIED);
1988 //success implies disconnect command got queued up successfully
1989 if(halStatus == eHAL_STATUS_SUCCESS)
1990 {
1991 wait_for_completion_interruptible_timeout(&pAdapter->disconnect_comp_var,
1992 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
1993 }
1994 memset(&wrqu, '\0', sizeof(wrqu));
1995 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1996 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
1997 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
1998 }
1999 else
2000 {
2001 hdd_abort_mac_scan(pHddCtx);
2002 }
2003
2004 if (test_bit(SME_SESSION_OPENED, &pAdapter->event_flags))
2005 {
2006 INIT_COMPLETION(pAdapter->session_close_comp_var);
2007 if (eHAL_STATUS_SUCCESS ==
2008 sme_CloseSession(pHddCtx->hHal, pAdapter->sessionId,
2009 hdd_smeCloseSessionCallback, pAdapter))
2010 {
2011 //Block on a completion variable. Can't wait forever though.
2012 wait_for_completion_interruptible_timeout(
2013 &pAdapter->session_close_comp_var,
2014 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
2015 }
2016 }
2017
2018 break;
2019
2020 case WLAN_HDD_SOFTAP:
2021 case WLAN_HDD_P2P_GO:
2022 //Any softap specific cleanup here...
2023 mutex_lock(&pHddCtx->sap_lock);
2024 if (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2025 {
2026 VOS_STATUS status;
2027 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2028
2029 //Stop Bss.
2030 status = WLANSAP_StopBss(pHddCtx->pvosContext);
2031 if (VOS_IS_STATUS_SUCCESS(status))
2032 {
2033 hdd_hostapd_state_t *pHostapdState =
2034 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2035
2036 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2037
2038 if (!VOS_IS_STATUS_SUCCESS(status))
2039 {
2040 hddLog(LOGE, "%s: failure waiting for WLANSAP_StopBss",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002041 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002042 }
2043 }
2044 else
2045 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002046 hddLog(LOGE, "%s: failure in WLANSAP_StopBss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002047 }
2048 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2049
2050 if (eHAL_STATUS_FAILURE ==
2051 ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG,
2052 0, NULL, eANI_BOOLEAN_FALSE))
2053 {
2054 hddLog(LOGE,
2055 "%s: Failed to set WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002056 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002057 }
2058
2059 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pAdapter))->hHal,
2060 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2061 eANI_BOOLEAN_FALSE) )
2062 {
2063 hddLog(LOGE,
2064 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
2065 }
2066
2067 // Reset WNI_CFG_PROBE_RSP Flags
2068 wlan_hdd_reset_prob_rspies(pAdapter);
2069 kfree(pAdapter->sessionCtx.ap.beacon);
2070 pAdapter->sessionCtx.ap.beacon = NULL;
2071 }
2072 mutex_unlock(&pHddCtx->sap_lock);
2073 break;
2074 case WLAN_HDD_MONITOR:
2075 break;
2076 default:
2077 break;
2078 }
2079
2080 EXIT();
2081 return VOS_STATUS_SUCCESS;
2082}
2083
2084VOS_STATUS hdd_stop_all_adapters( hdd_context_t *pHddCtx )
2085{
2086 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2087 VOS_STATUS status;
2088 hdd_adapter_t *pAdapter;
2089
2090 ENTER();
2091
2092 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2093
2094 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2095 {
2096 pAdapter = pAdapterNode->pAdapter;
2097 netif_tx_disable(pAdapter->dev);
2098 netif_carrier_off(pAdapter->dev);
2099
2100 hdd_stop_adapter( pHddCtx, pAdapter );
2101
2102 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2103 pAdapterNode = pNext;
2104 }
2105
2106 EXIT();
2107
2108 return VOS_STATUS_SUCCESS;
2109}
2110
2111VOS_STATUS hdd_reset_all_adapters( hdd_context_t *pHddCtx )
2112{
2113 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2114 VOS_STATUS status;
2115 hdd_adapter_t *pAdapter;
2116
2117 ENTER();
2118
2119 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2120
2121 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2122 {
2123 pAdapter = pAdapterNode->pAdapter;
2124 netif_tx_disable(pAdapter->dev);
2125 netif_carrier_off(pAdapter->dev);
2126
2127 //Record whether STA is associated
2128 pAdapter->sessionCtx.station.bSendDisconnect =
2129 hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) ?
2130 VOS_TRUE : VOS_FALSE;
2131
2132 hdd_deinit_tx_rx(pAdapter);
2133 hdd_wmm_adapter_close(pAdapter);
2134
2135 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2136 pAdapterNode = pNext;
2137 }
2138
2139 EXIT();
2140
2141 return VOS_STATUS_SUCCESS;
2142}
2143
2144VOS_STATUS hdd_start_all_adapters( hdd_context_t *pHddCtx )
2145{
2146 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2147 VOS_STATUS status;
2148 hdd_adapter_t *pAdapter;
2149 v_MACADDR_t bcastMac = VOS_MAC_ADDR_BROADCAST_INITIALIZER;
2150
2151 ENTER();
2152
2153 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2154
2155 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2156 {
2157 pAdapter = pAdapterNode->pAdapter;
2158
2159 switch(pAdapter->device_mode)
2160 {
2161 case WLAN_HDD_INFRA_STATION:
2162 case WLAN_HDD_P2P_CLIENT:
Jeff Johnsone7245742012-09-05 17:12:55 -07002163 case WLAN_HDD_P2P_DEVICE:
Jeff Johnson295189b2012-06-20 16:38:30 -07002164 hdd_init_station_mode(pAdapter);
2165 /* Open the gates for HDD to receive Wext commands */
2166 pAdapter->isLinkUpSvcNeeded = FALSE;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002167 pHddCtx->scan_info.mScanPending = FALSE;
2168 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002169
2170 //Trigger the initial scan
2171 hdd_wlan_initial_scan(pAdapter);
2172
2173 //Indicate disconnect event to supplicant if associated previously
2174 if(pAdapter->sessionCtx.station.bSendDisconnect)
2175 {
2176 union iwreq_data wrqu;
2177 memset(&wrqu, '\0', sizeof(wrqu));
2178 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2179 memset(wrqu.ap_addr.sa_data,'\0',ETH_ALEN);
2180 wireless_send_event(pAdapter->dev, SIOCGIWAP, &wrqu, NULL);
2181 pAdapter->sessionCtx.station.bSendDisconnect = VOS_FALSE;
2182
2183#ifdef CONFIG_CFG80211
2184 /* indicate disconnected event to nl80211 */
2185 cfg80211_disconnected(pAdapter->dev, WLAN_REASON_UNSPECIFIED,
2186 NULL, 0, GFP_KERNEL);
2187#endif
2188 }
2189 break;
2190
2191 case WLAN_HDD_SOFTAP:
2192 /* softAP can handle SSR */
2193 break;
2194
2195 case WLAN_HDD_P2P_GO:
2196#ifdef CONFIG_CFG80211
2197 hddLog(VOS_TRACE_LEVEL_ERROR, "%s [SSR] send restart supplicant",
2198 __func__);
2199 /* event supplicant to restart */
2200 cfg80211_del_sta(pAdapter->dev,
2201 (const u8 *)&bcastMac.bytes[0], GFP_KERNEL);
2202#endif
2203 break;
2204
2205 case WLAN_HDD_MONITOR:
2206 /* monitor interface start */
2207 break;
2208 default:
2209 break;
2210 }
2211
2212 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2213 pAdapterNode = pNext;
2214 }
2215
2216 EXIT();
2217
2218 return VOS_STATUS_SUCCESS;
2219}
2220
2221VOS_STATUS hdd_reconnect_all_adapters( hdd_context_t *pHddCtx )
2222{
2223 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2224 hdd_adapter_t *pAdapter;
2225 VOS_STATUS status;
2226 v_U32_t roamId;
2227
2228 ENTER();
2229
2230 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2231
2232 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2233 {
2234 pAdapter = pAdapterNode->pAdapter;
2235
2236 if( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
2237 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
2238 {
2239 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2240 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2241
2242 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
2243 init_completion(&pAdapter->disconnect_comp_var);
2244 sme_RoamDisconnect(pHddCtx->hHal, pAdapter->sessionId,
2245 eCSR_DISCONNECT_REASON_UNSPECIFIED);
2246
2247 wait_for_completion_interruptible_timeout(
2248 &pAdapter->disconnect_comp_var,
2249 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2250
2251 pWextState->roamProfile.csrPersona = pAdapter->device_mode;
2252 pHddCtx->isAmpAllowed = VOS_FALSE;
2253 sme_RoamConnect(pHddCtx->hHal,
2254 pAdapter->sessionId, &(pWextState->roamProfile),
2255 &roamId);
2256 }
2257
2258 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2259 pAdapterNode = pNext;
2260 }
2261
2262 EXIT();
2263
2264 return VOS_STATUS_SUCCESS;
2265}
2266
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07002267bool hdd_is_ssr_required( void)
Jeff Johnson295189b2012-06-20 16:38:30 -07002268{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07002269 return (isSsrRequired == HDD_SSR_REQUIRED);
Jeff Johnson295189b2012-06-20 16:38:30 -07002270}
2271
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07002272/* Once SSR is disabled then it cannot be set. */
2273void hdd_set_ssr_required( e_hdd_ssr_required value)
Jeff Johnson295189b2012-06-20 16:38:30 -07002274{
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07002275 if (HDD_SSR_DISABLED == isSsrRequired)
2276 return;
2277
Jeff Johnson295189b2012-06-20 16:38:30 -07002278 isSsrRequired = value;
2279}
2280
2281VOS_STATUS hdd_get_front_adapter( hdd_context_t *pHddCtx,
2282 hdd_adapter_list_node_t** ppAdapterNode)
2283{
2284 VOS_STATUS status;
2285 spin_lock(&pHddCtx->hddAdapters.lock);
2286 status = hdd_list_peek_front ( &pHddCtx->hddAdapters,
2287 (hdd_list_node_t**) ppAdapterNode );
2288 spin_unlock(&pHddCtx->hddAdapters.lock);
2289 return status;
2290}
2291
2292VOS_STATUS hdd_get_next_adapter( hdd_context_t *pHddCtx,
2293 hdd_adapter_list_node_t* pAdapterNode,
2294 hdd_adapter_list_node_t** pNextAdapterNode)
2295{
2296 VOS_STATUS status;
2297 spin_lock(&pHddCtx->hddAdapters.lock);
2298 status = hdd_list_peek_next ( &pHddCtx->hddAdapters,
2299 (hdd_list_node_t*) pAdapterNode,
2300 (hdd_list_node_t**)pNextAdapterNode );
2301
2302 spin_unlock(&pHddCtx->hddAdapters.lock);
2303 return status;
2304}
2305
2306VOS_STATUS hdd_remove_adapter( hdd_context_t *pHddCtx,
2307 hdd_adapter_list_node_t* pAdapterNode)
2308{
2309 VOS_STATUS status;
2310 spin_lock(&pHddCtx->hddAdapters.lock);
2311 status = hdd_list_remove_node ( &pHddCtx->hddAdapters,
2312 &pAdapterNode->node );
2313 spin_unlock(&pHddCtx->hddAdapters.lock);
2314 return status;
2315}
2316
2317VOS_STATUS hdd_remove_front_adapter( hdd_context_t *pHddCtx,
2318 hdd_adapter_list_node_t** ppAdapterNode)
2319{
2320 VOS_STATUS status;
2321 spin_lock(&pHddCtx->hddAdapters.lock);
2322 status = hdd_list_remove_front( &pHddCtx->hddAdapters,
2323 (hdd_list_node_t**) ppAdapterNode );
2324 spin_unlock(&pHddCtx->hddAdapters.lock);
2325 return status;
2326}
2327
2328VOS_STATUS hdd_add_adapter_back( hdd_context_t *pHddCtx,
2329 hdd_adapter_list_node_t* pAdapterNode)
2330{
2331 VOS_STATUS status;
2332 spin_lock(&pHddCtx->hddAdapters.lock);
2333 status = hdd_list_insert_back ( &pHddCtx->hddAdapters,
2334 (hdd_list_node_t*) pAdapterNode );
2335 spin_unlock(&pHddCtx->hddAdapters.lock);
2336 return status;
2337}
2338
2339VOS_STATUS hdd_add_adapter_front( hdd_context_t *pHddCtx,
2340 hdd_adapter_list_node_t* pAdapterNode)
2341{
2342 VOS_STATUS status;
2343 spin_lock(&pHddCtx->hddAdapters.lock);
2344 status = hdd_list_insert_front ( &pHddCtx->hddAdapters,
2345 (hdd_list_node_t*) pAdapterNode );
2346 spin_unlock(&pHddCtx->hddAdapters.lock);
2347 return status;
2348}
2349
2350hdd_adapter_t * hdd_get_adapter_by_macaddr( hdd_context_t *pHddCtx,
2351 tSirMacAddr macAddr )
2352{
2353 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2354 hdd_adapter_t *pAdapter;
2355 VOS_STATUS status;
2356
2357 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2358
2359 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2360 {
2361 pAdapter = pAdapterNode->pAdapter;
2362
2363 if( pAdapter && vos_mem_compare( pAdapter->macAddressCurrent.bytes,
2364 macAddr, sizeof(tSirMacAddr) ) )
2365 {
2366 return pAdapter;
2367 }
2368 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2369 pAdapterNode = pNext;
2370 }
2371
2372 return NULL;
2373
2374}
2375
2376hdd_adapter_t * hdd_get_adapter_by_name( hdd_context_t *pHddCtx, tANI_U8 *name )
2377{
2378 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2379 hdd_adapter_t *pAdapter;
2380 VOS_STATUS status;
2381
2382 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2383
2384 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2385 {
2386 pAdapter = pAdapterNode->pAdapter;
2387
2388 if( pAdapter && !strncmp( pAdapter->dev->name, (const char *)name,
2389 IFNAMSIZ ) )
2390 {
2391 return pAdapter;
2392 }
2393 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2394 pAdapterNode = pNext;
2395 }
2396
2397 return NULL;
2398
2399}
2400
2401hdd_adapter_t * hdd_get_adapter( hdd_context_t *pHddCtx, device_mode_t mode )
2402{
2403 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2404 hdd_adapter_t *pAdapter;
2405 VOS_STATUS status;
2406
2407 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2408
2409 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2410 {
2411 pAdapter = pAdapterNode->pAdapter;
2412
2413 if( pAdapter && (mode == pAdapter->device_mode) )
2414 {
2415 return pAdapter;
2416 }
2417 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2418 pAdapterNode = pNext;
2419 }
2420
2421 return NULL;
2422
2423}
2424
2425//Remove this function later
2426hdd_adapter_t * hdd_get_mon_adapter( hdd_context_t *pHddCtx )
2427{
2428 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2429 hdd_adapter_t *pAdapter;
2430 VOS_STATUS status;
2431
2432 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2433
2434 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2435 {
2436 pAdapter = pAdapterNode->pAdapter;
2437
2438 if( pAdapter && WLAN_HDD_MONITOR == pAdapter->device_mode )
2439 {
2440 return pAdapter;
2441 }
2442
2443 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2444 pAdapterNode = pNext;
2445 }
2446
2447 return NULL;
2448
2449}
2450
2451#ifdef CONFIG_CFG80211
2452/**---------------------------------------------------------------------------
2453
2454 \brief hdd_set_monitor_tx_adapter() -
2455
2456 This API initializes the adapter to be used while transmitting on monitor
2457 adapter.
2458
2459 \param - pHddCtx - Pointer to the HDD context.
2460 pAdapter - Adapter that will used for TX. This can be NULL.
2461 \return - None.
2462 --------------------------------------------------------------------------*/
2463void wlan_hdd_set_monitor_tx_adapter( hdd_context_t *pHddCtx, hdd_adapter_t *pAdapter )
2464{
2465 hdd_adapter_t *pMonAdapter;
2466
2467 pMonAdapter = hdd_get_adapter( pHddCtx, WLAN_HDD_MONITOR );
2468
2469 if( NULL != pMonAdapter )
2470 {
2471 pMonAdapter->sessionCtx.monitor.pAdapterForTx = pAdapter;
2472 }
2473}
2474#endif
2475/**---------------------------------------------------------------------------
2476
2477 \brief hdd_select_queue() -
2478
2479 This API returns the operating channel of the requested device mode
2480
2481 \param - pHddCtx - Pointer to the HDD context.
2482 - mode - Device mode for which operating channel is required
2483 suported modes - WLAN_HDD_INFRA_STATION, WLAN_HDD_P2P_CLIENT
2484 WLAN_HDD_SOFTAP, WLAN_HDD_P2P_GO.
2485 \return - channel number. "0" id the requested device is not found OR it is not connected.
2486 --------------------------------------------------------------------------*/
2487v_U8_t hdd_get_operating_channel( hdd_context_t *pHddCtx, device_mode_t mode )
2488{
2489 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2490 VOS_STATUS status;
2491 hdd_adapter_t *pAdapter;
2492 v_U8_t operatingChannel = 0;
2493
2494 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2495
2496 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2497 {
2498 pAdapter = pAdapterNode->pAdapter;
2499
2500 if( mode == pAdapter->device_mode )
2501 {
2502 switch(pAdapter->device_mode)
2503 {
2504 case WLAN_HDD_INFRA_STATION:
2505 case WLAN_HDD_P2P_CLIENT:
2506 if( hdd_connIsConnected( WLAN_HDD_GET_STATION_CTX_PTR( pAdapter )) )
2507 operatingChannel = (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.operationChannel;
2508 break;
2509 case WLAN_HDD_SOFTAP:
2510 case WLAN_HDD_P2P_GO:
2511 /*softap connection info */
2512 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2513 operatingChannel = (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->operatingChannel;
2514 break;
2515 default:
2516 break;
2517 }
2518
2519 break; //Found the device of interest. break the loop
2520 }
2521
2522 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2523 pAdapterNode = pNext;
2524 }
2525 return operatingChannel;
2526}
2527
2528#ifdef WLAN_FEATURE_PACKET_FILTERING
2529/**---------------------------------------------------------------------------
2530
2531 \brief hdd_set_multicast_list() -
2532
2533 This used to set the multicast address list.
2534
2535 \param - dev - Pointer to the WLAN device.
2536 - skb - Pointer to OS packet (sk_buff).
2537 \return - success/fail
2538
2539 --------------------------------------------------------------------------*/
2540static void hdd_set_multicast_list(struct net_device *dev)
2541{
2542 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2543 hdd_context_t *pHddCtx;
2544 int mc_count;
2545 int i = 0;
2546 struct netdev_hw_addr *ha;
2547 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
2548 if (NULL == pHddCtx)
2549 {
2550 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002551 "%s: HDD context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002552 return;
2553 }
2554
2555 if (dev->flags & IFF_ALLMULTI)
2556 {
2557 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002558 "%s: allow all multicast frames", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002559 pHddCtx->mc_addr_list.mc_cnt = 0;
2560 }
2561 else
2562 {
2563 mc_count = netdev_mc_count(dev);
2564 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002565 "%s: mc_count = %u", __func__, mc_count);
Jeff Johnson295189b2012-06-20 16:38:30 -07002566 if (mc_count > WLAN_HDD_MAX_MC_ADDR_LIST)
2567 {
2568 hddLog(VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002569 "%s: No free filter available; allow all multicast frames", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002570 pHddCtx->mc_addr_list.mc_cnt = 0;
2571 return;
2572 }
2573
2574 pHddCtx->mc_addr_list.mc_cnt = mc_count;
2575
2576 netdev_for_each_mc_addr(ha, dev) {
2577 if (i == mc_count)
2578 break;
2579 memset(&(pHddCtx->mc_addr_list.addr[i][0]), 0, ETH_ALEN);
2580 memcpy(&(pHddCtx->mc_addr_list.addr[i][0]), ha->addr, ETH_ALEN);
2581 hddLog(VOS_TRACE_LEVEL_INFO, "\n%s: mlist[%d] = %02x:%02x:%02x:%02x:%02x:%02x",
2582 __func__, i,
2583 pHddCtx->mc_addr_list.addr[i][0], pHddCtx->mc_addr_list.addr[i][1],
2584 pHddCtx->mc_addr_list.addr[i][2], pHddCtx->mc_addr_list.addr[i][3],
2585 pHddCtx->mc_addr_list.addr[i][4], pHddCtx->mc_addr_list.addr[i][5]);
2586 i++;
2587 }
2588 }
2589 return;
2590}
2591#endif
2592
2593/**---------------------------------------------------------------------------
2594
2595 \brief hdd_select_queue() -
2596
2597 This function is registered with the Linux OS for network
2598 core to decide which queue to use first.
2599
2600 \param - dev - Pointer to the WLAN device.
2601 - skb - Pointer to OS packet (sk_buff).
2602 \return - ac, Queue Index/access category corresponding to UP in IP header
2603
2604 --------------------------------------------------------------------------*/
2605v_U16_t hdd_select_queue(struct net_device *dev,
2606 struct sk_buff *skb)
2607{
2608 return hdd_wmm_select_queue(dev, skb);
2609}
2610
2611
2612/**---------------------------------------------------------------------------
2613
2614 \brief hdd_wlan_initial_scan() -
2615
2616 This function triggers the initial scan
2617
2618 \param - pAdapter - Pointer to the HDD adapter.
2619
2620 --------------------------------------------------------------------------*/
2621void hdd_wlan_initial_scan(hdd_adapter_t *pAdapter)
2622{
2623 tCsrScanRequest scanReq;
2624 tCsrChannelInfo channelInfo;
2625 eHalStatus halStatus;
2626 unsigned long scanId;
2627 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2628
2629 vos_mem_zero(&scanReq, sizeof(tCsrScanRequest));
2630 vos_mem_set(&scanReq.bssid, sizeof(tCsrBssid), 0xff);
2631 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
2632
2633 if(sme_Is11dSupported(pHddCtx->hHal))
2634 {
2635 halStatus = sme_ScanGetBaseChannels( pHddCtx->hHal, &channelInfo );
2636 if ( HAL_STATUS_SUCCESS( halStatus ) )
2637 {
2638 scanReq.ChannelInfo.ChannelList = vos_mem_malloc(channelInfo.numOfChannels);
2639 if( !scanReq.ChannelInfo.ChannelList )
2640 {
2641 hddLog(VOS_TRACE_LEVEL_ERROR, "%s kmalloc failed", __func__);
2642 vos_mem_free(channelInfo.ChannelList);
2643 return;
2644 }
2645 vos_mem_copy(scanReq.ChannelInfo.ChannelList, channelInfo.ChannelList,
2646 channelInfo.numOfChannels);
2647 scanReq.ChannelInfo.numOfChannels = channelInfo.numOfChannels;
2648 vos_mem_free(channelInfo.ChannelList);
2649 }
2650
2651 scanReq.scanType = eSIR_PASSIVE_SCAN;
2652 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
2653 scanReq.maxChnTime = pHddCtx->cfg_ini->nPassiveMaxChnTime;
2654 scanReq.minChnTime = pHddCtx->cfg_ini->nPassiveMinChnTime;
2655 }
2656 else
2657 {
2658 scanReq.scanType = eSIR_ACTIVE_SCAN;
2659 scanReq.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
2660 scanReq.maxChnTime = pHddCtx->cfg_ini->nActiveMaxChnTime;
2661 scanReq.minChnTime = pHddCtx->cfg_ini->nActiveMinChnTime;
2662 }
2663
2664 halStatus = sme_ScanRequest(pHddCtx->hHal, pAdapter->sessionId, &scanReq, &scanId, NULL, NULL);
2665 if ( !HAL_STATUS_SUCCESS( halStatus ) )
2666 {
2667 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_ScanRequest failed status code %d",
2668 __func__, halStatus );
2669 }
2670
2671 if(sme_Is11dSupported(pHddCtx->hHal))
2672 vos_mem_free(scanReq.ChannelInfo.ChannelList);
2673}
2674
2675struct fullPowerContext
2676{
2677 struct completion completion;
2678 unsigned int magic;
2679};
2680#define POWER_CONTEXT_MAGIC 0x504F5752 //POWR
2681
2682/**---------------------------------------------------------------------------
2683
2684 \brief hdd_full_power_callback() - HDD full power callback function
2685
2686 This is the function invoked by SME to inform the result of a full power
2687 request issued by HDD
2688
2689 \param - callbackcontext - Pointer to cookie
2690 \param - status - result of request
2691
2692 \return - None
2693
2694 --------------------------------------------------------------------------*/
2695static void hdd_full_power_callback(void *callbackContext, eHalStatus status)
2696{
2697 struct fullPowerContext *pContext = callbackContext;
2698
2699 hddLog(VOS_TRACE_LEVEL_INFO,
2700 "%s: context = %p, status = %d", pContext, status);
2701
2702 if (NULL == callbackContext)
2703 {
2704 hddLog(VOS_TRACE_LEVEL_ERROR,
2705 "%s: Bad param, context [%p]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002706 __func__, callbackContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07002707 return;
2708 }
2709
2710 /* there is a race condition that exists between this callback function
2711 and the caller since the caller could time out either before or
2712 while this code is executing. we'll assume the timeout hasn't
2713 occurred, but we'll verify that right before we save our work */
2714
2715 if (POWER_CONTEXT_MAGIC != pContext->magic)
2716 {
2717 /* the caller presumably timed out so there is nothing we can do */
2718 hddLog(VOS_TRACE_LEVEL_WARN,
2719 "%s: Invalid context, magic [%08x]",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002720 __func__, pContext->magic);
Jeff Johnson295189b2012-06-20 16:38:30 -07002721 return;
2722 }
2723
2724 /* the race is on. caller could have timed out immediately after
2725 we verified the magic, but if so, caller will wait a short time
2726 for us to notify the caller, so the context will stay valid */
2727 complete(&pContext->completion);
2728}
2729
2730/**---------------------------------------------------------------------------
2731
2732 \brief hdd_wlan_exit() - HDD WLAN exit function
2733
2734 This is the driver exit point (invoked during rmmod)
2735
2736 \param - pHddCtx - Pointer to the HDD Context
2737
2738 \return - None
2739
2740 --------------------------------------------------------------------------*/
2741void hdd_wlan_exit(hdd_context_t *pHddCtx)
2742{
2743 eHalStatus halStatus;
2744 v_CONTEXT_t pVosContext = pHddCtx->pvosContext;
2745 VOS_STATUS vosStatus;
2746#ifdef ANI_BUS_TYPE_SDIO
2747 struct sdio_func *sdio_func_dev = NULL;
2748#endif // ANI_BUS_TYPE_SDIO
2749#ifdef CONFIG_CFG80211
2750 struct wiphy *wiphy = pHddCtx->wiphy;
2751#endif
2752#ifdef FEATURE_WLAN_INTEGRATED_SOC
2753 hdd_adapter_t* pAdapter;
2754#endif
2755 struct fullPowerContext powerContext;
2756 long lrc;
2757
2758 ENTER();
2759
Ng Chilam1322ea32012-12-27 17:33:08 -08002760#ifdef ANI_MANF_DIAG
2761 if (VOS_FTM_MODE != hdd_get_conparam())
2762#endif /* ANI_MANF_DIAG */
2763 {
2764 // Unloading, restart logic is no more required.
2765 wlan_hdd_restart_deinit(pHddCtx);
2766 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002767
Jeff Johnson295189b2012-06-20 16:38:30 -07002768#ifdef CONFIG_CFG80211
2769#ifdef WLAN_SOFTAP_FEATURE
2770 if (VOS_STA_SAP_MODE != hdd_get_conparam())
2771#endif
2772 {
2773#ifdef ANI_MANF_DIAG
2774 if (VOS_FTM_MODE != hdd_get_conparam())
2775#endif /* ANI_MANF_DIAG */
2776 {
2777 hdd_adapter_t* pAdapter = hdd_get_adapter(pHddCtx,
2778 WLAN_HDD_INFRA_STATION);
2779 if (pAdapter == NULL)
2780 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_CLIENT);
2781
2782 if (pAdapter != NULL)
2783 {
2784 wlan_hdd_cfg80211_pre_voss_stop(pAdapter);
2785 hdd_UnregisterWext(pAdapter->dev);
2786 }
2787 }
2788 }
2789#endif
2790
2791#ifdef ANI_MANF_DIAG
2792 if (VOS_FTM_MODE == hdd_get_conparam())
2793 {
2794 wlan_hdd_ftm_close(pHddCtx);
2795 goto free_hdd_ctx;
2796 }
2797#endif
2798 //Stop the Interface TX queue.
2799 //netif_tx_disable(pWlanDev);
2800 //netif_carrier_off(pWlanDev);
2801
Jeff Johnson295189b2012-06-20 16:38:30 -07002802#ifdef FEATURE_WLAN_INTEGRATED_SOC
2803#ifdef WLAN_SOFTAP_FEATURE
2804 if (VOS_STA_SAP_MODE == hdd_get_conparam())
2805 {
2806 pAdapter = hdd_get_adapter(pHddCtx,
2807 WLAN_HDD_SOFTAP);
2808 }
2809 else
2810 {
2811#endif
2812#ifdef ANI_MANF_DIAG
2813 if (VOS_FTM_MODE != hdd_get_conparam())
2814#endif /* ANI_MANF_DIAG */
2815 {
2816 pAdapter = hdd_get_adapter(pHddCtx,
2817 WLAN_HDD_INFRA_STATION);
2818 }
2819#ifdef WLAN_SOFTAP_FEATURE
2820 }
2821#endif
2822 /* DeRegister with platform driver as client for Suspend/Resume */
2823 vosStatus = hddDeregisterPmOps(pHddCtx);
2824 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
2825 {
2826 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDeregisterPmOps failed",__func__);
2827 VOS_ASSERT(0);
2828 }
2829
2830 vosStatus = hddDevTmUnregisterNotifyCallback(pHddCtx);
2831 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
2832 {
2833 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
2834 }
2835#endif //FEATURE_WLAN_INTEGRATED_SOC
2836
Chilam NG571c65a2013-01-19 12:27:36 +05302837#ifdef FEATURE_WLAN_TDLS
2838 wlan_hdd_tdls_exit();
2839#endif
2840
Jeff Johnson295189b2012-06-20 16:38:30 -07002841 // Cancel any outstanding scan requests. We are about to close all
2842 // of our adapters, but an adapter structure is what SME passes back
2843 // to our callback function. Hence if there are any outstanding scan
2844 // requests then there is a race condition between when the adapter
2845 // is closed and when the callback is invoked. We try to resolve that
2846 // race condition here by canceling any outstanding scans before we
2847 // close the adapters.
2848 // Note that the scans may be cancelled in an asynchronous manner, so
2849 // ideally there needs to be some kind of synchronization. Rather than
2850 // introduce a new synchronization here, we will utilize the fact that
2851 // we are about to Request Full Power, and since that is synchronized,
2852 // the expectation is that by the time Request Full Power has completed,
2853 // all scans will be cancelled.
2854 hdd_abort_mac_scan( pHddCtx );
2855
2856 //Disable IMPS/BMPS as we do not want the device to enter any power
2857 //save mode during shutdown
2858 sme_DisablePowerSave(pHddCtx->hHal, ePMC_IDLE_MODE_POWER_SAVE);
2859 sme_DisablePowerSave(pHddCtx->hHal, ePMC_BEACON_MODE_POWER_SAVE);
2860 sme_DisablePowerSave(pHddCtx->hHal, ePMC_UAPSD_MODE_POWER_SAVE);
2861
2862 //Ensure that device is in full power as we will touch H/W during vos_Stop
2863 init_completion(&powerContext.completion);
2864 powerContext.magic = POWER_CONTEXT_MAGIC;
2865
2866 halStatus = sme_RequestFullPower(pHddCtx->hHal, hdd_full_power_callback,
2867 &powerContext, eSME_FULL_PWR_NEEDED_BY_HDD);
2868
2869 if (eHAL_STATUS_SUCCESS != halStatus)
2870 {
2871 if (eHAL_STATUS_PMC_PENDING == halStatus)
2872 {
2873 /* request was sent -- wait for the response */
2874 lrc = wait_for_completion_interruptible_timeout(
2875 &powerContext.completion,
2876 msecs_to_jiffies(WLAN_WAIT_TIME_POWER));
2877 /* either we have a response or we timed out
2878 either way, first invalidate our magic */
2879 powerContext.magic = 0;
2880 if (lrc <= 0)
2881 {
2882 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: %s while requesting full power",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002883 __func__, (0 == lrc) ? "timeout" : "interrupt");
Jeff Johnson295189b2012-06-20 16:38:30 -07002884 /* there is a race condition such that the callback
2885 function could be executing at the same time we are. of
2886 primary concern is if the callback function had already
2887 verified the "magic" but hasn't yet set the completion
2888 variable. Since the completion variable is on our
2889 stack, we'll delay just a bit to make sure the data is
2890 still valid if that is the case */
2891 msleep(50);
2892 }
2893 }
2894 else
2895 {
2896 hddLog(VOS_TRACE_LEVEL_ERROR,
2897 "%s: Request for Full Power failed, status %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002898 __func__, halStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07002899 VOS_ASSERT(0);
2900 /* continue -- need to clean up as much as possible */
2901 }
2902 }
2903
2904 // Unregister the Net Device Notifier
2905 unregister_netdevice_notifier(&hdd_netdev_notifier);
2906
Jeff Johnson295189b2012-06-20 16:38:30 -07002907 hdd_stop_all_adapters( pHddCtx );
2908
2909#ifdef ANI_BUS_TYPE_SDIO
2910 sdio_func_dev = libra_getsdio_funcdev();
2911
2912 if(sdio_func_dev == NULL)
2913 {
2914 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: sdio_func_dev is NULL!",__func__);
2915 VOS_ASSERT(0);
2916 return;
2917 }
2918
2919 sd_claim_host(sdio_func_dev);
2920
2921 /* Disable SDIO IRQ since we are exiting */
2922 libra_enable_sdio_irq(sdio_func_dev, 0);
2923
2924 sd_release_host(sdio_func_dev);
2925#endif // ANI_BUS_TYPE_SDIO
2926
2927#ifdef WLAN_BTAMP_FEATURE
2928 vosStatus = WLANBAP_Stop(pVosContext);
2929 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
2930 {
2931 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
2932 "%s: Failed to stop BAP",__func__);
2933 }
2934#endif //WLAN_BTAMP_FEATURE
2935
2936 //Stop all the modules
2937 vosStatus = vos_stop( pVosContext );
2938 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
2939 {
2940 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2941 "%s: Failed to stop VOSS",__func__);
2942 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
2943 }
2944
2945#ifdef ANI_BUS_TYPE_SDIO
2946 vosStatus = WLANBAL_Stop( pVosContext );
2947
2948 hddLog(VOS_TRACE_LEVEL_ERROR,"WLAN BAL STOP\n");
2949 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
2950 {
2951 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2952 "%s: Failed to stop BAL",__func__);
2953 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
2954 }
2955
2956 msleep(50);
2957 //Put the chip is standby before asserting deep sleep
2958 vosStatus = WLANBAL_SuspendChip( pVosContext );
2959
2960 hddLog(VOS_TRACE_LEVEL_ERROR,"WLAN Suspend Chip\n");
2961
2962 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
2963 {
2964 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2965 "%s: Failed to suspend chip ",__func__);
2966 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
2967 }
2968 //Invoke SAL stop
2969 vosStatus = WLANSAL_Stop( pVosContext );
2970 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
2971 {
2972 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2973 "%s: Failed to stop SAL",__func__);
2974 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
2975 }
2976
2977#endif // ANI_BUS_TYPE_SDIO
2978
2979 //Assert Deep sleep signal now to put Libra HW in lowest power state
2980 vosStatus = vos_chipAssertDeepSleep( NULL, NULL, NULL );
2981 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
2982
2983 //Vote off any PMIC voltage supplies
2984 vos_chipPowerDown(NULL, NULL, NULL);
2985
2986 vos_chipVoteOffXOBuffer(NULL, NULL, NULL);
2987
2988 //Clean up HDD Nlink Service
2989 send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0);
2990 nl_srv_exit();
2991
2992 //This requires pMac access, Call this before vos_close().
Jeff Johnson295189b2012-06-20 16:38:30 -07002993 hdd_unregister_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002994
2995 //Close the scheduler before calling vos_close to make sure no thread is
2996 // scheduled after the each module close is called i.e after all the data
2997 // structures are freed.
2998 vosStatus = vos_sched_close( pVosContext );
2999 if (!VOS_IS_STATUS_SUCCESS(vosStatus)) {
3000 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
3001 "%s: Failed to close VOSS Scheduler",__func__);
3002 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
3003 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003004
3005#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
3006 /* Destroy the wake lock */
3007 wake_lock_destroy(&pHddCtx->rx_wake_lock);
3008#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -08003009 /* Destroy the wake lock */
3010 wake_lock_destroy(&pHddCtx->sap_wake_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -07003011
3012 //Close VOSS
3013 //This frees pMac(HAL) context. There should not be any call that requires pMac access after this.
3014 vos_close(pVosContext);
3015
3016#ifdef ANI_BUS_TYPE_SDIO
3017 vosStatus = WLANBAL_Close(pVosContext);
3018 if (!VOS_IS_STATUS_SUCCESS(vosStatus))
3019 {
3020 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3021 "%s: Failed to close BAL",__func__);
3022 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
3023 }
3024 hddLog(VOS_TRACE_LEVEL_ERROR,"Returned WLAN BAL CLOSE\n\n\n\n");
3025#endif // ANI_BUS_TYPE_SDIO
3026
3027 //Close Watchdog
3028 if(pHddCtx->cfg_ini->fIsLogpEnabled)
3029 vos_watchdog_close(pVosContext);
3030
3031 /* Cancel the vote for XO Core ON.
3032 * This is done here to ensure there is no race condition since MC, TX and WD threads have
3033 * exited at this point
3034 */
3035 hddLog(VOS_TRACE_LEVEL_WARN, "In module exit: Cancel the vote for XO Core ON"
3036 " when WLAN is turned OFF\n");
3037 if (vos_chipVoteXOCore(NULL, NULL, NULL, VOS_FALSE) != VOS_STATUS_SUCCESS)
3038 {
3039 hddLog(VOS_TRACE_LEVEL_ERROR, "Could not cancel the vote for XO Core ON."
3040 " Not returning failure."
3041 " Power consumed will be high\n");
3042 }
3043
3044 hdd_close_all_adapters( pHddCtx );
3045
3046
3047 //Free up dynamically allocated members inside HDD Adapter
3048 kfree(pHddCtx->cfg_ini);
3049 pHddCtx->cfg_ini= NULL;
3050
3051 /* free the power on lock from platform driver */
3052 if (free_riva_power_on_lock("wlan"))
3053 {
3054 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to free power on lock",
3055 __func__);
3056 }
3057
3058#ifdef ANI_MANF_DIAG
3059free_hdd_ctx:
3060#endif
3061#ifdef CONFIG_CFG80211
3062 wiphy_unregister(wiphy) ;
3063 wiphy_free(wiphy) ;
3064#else
3065 vos_mem_free( pHddCtx );
3066#endif
3067 if (hdd_is_ssr_required())
3068 {
3069 /* WDI timeout had happened during unload, so SSR is needed here */
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -07003070 subsystem_restart("wcnss");
Jeff Johnson295189b2012-06-20 16:38:30 -07003071 msleep(5000);
3072 }
3073 hdd_set_ssr_required (VOS_FALSE);
3074}
3075
3076
3077/**---------------------------------------------------------------------------
3078
3079 \brief hdd_update_config_from_nv() - Function to update the contents of
3080 the running configuration with parameters taken from NV storage
3081
3082 \param - pHddCtx - Pointer to the HDD global context
3083
3084 \return - VOS_STATUS_SUCCESS if successful
3085
3086 --------------------------------------------------------------------------*/
3087static VOS_STATUS hdd_update_config_from_nv(hdd_context_t* pHddCtx)
3088{
3089#ifndef FEATURE_WLAN_INTEGRATED_SOC
3090 eHalStatus halStatus;
3091#endif
3092
3093#ifdef FEATURE_WLAN_INTEGRATED_SOC
3094 v_BOOL_t itemIsValid = VOS_FALSE;
3095 VOS_STATUS status;
3096 v_MACADDR_t macFromNV[VOS_MAX_CONCURRENCY_PERSONA];
3097 v_U8_t macLoop;
3098
3099 /*If the NV is valid then get the macaddress from nv else get it from qcom_cfg.ini*/
3100 status = vos_nv_getValidity(VNV_FIELD_IMAGE, &itemIsValid);
3101 if(status != VOS_STATUS_SUCCESS)
3102 {
3103 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_getValidity() failed\n ");
3104 return VOS_STATUS_E_FAILURE;
3105 }
3106
3107 if (itemIsValid == VOS_TRUE)
3108 {
3109 hddLog(VOS_TRACE_LEVEL_INFO_HIGH," Reading the Macaddress from NV\n ");
3110 status = vos_nv_readMultiMacAddress((v_U8_t *)&macFromNV[0].bytes[0],
3111 VOS_MAX_CONCURRENCY_PERSONA);
3112 if(status != VOS_STATUS_SUCCESS)
3113 {
3114 /* Get MAC from NV fail, not update CFG info
3115 * INI MAC value will be used for MAC setting */
3116 hddLog(VOS_TRACE_LEVEL_ERROR," vos_nv_readMacAddress() failed\n ");
3117 return VOS_STATUS_E_FAILURE;
3118 }
3119
3120 /* If first MAC is not valid, treat all others are not valid
3121 * Then all MACs will be got from ini file */
3122 if(vos_is_macaddr_zero(&macFromNV[0]))
3123 {
3124 /* MAC address in NV file is not configured yet */
3125 hddLog(VOS_TRACE_LEVEL_WARN, "Invalid MAC in NV file");
3126 return VOS_STATUS_E_INVAL;
3127 }
3128
3129 /* Get MAC address from NV, update CFG info */
3130 for(macLoop = 0; macLoop < VOS_MAX_CONCURRENCY_PERSONA; macLoop++)
3131 {
3132 if(vos_is_macaddr_zero(&macFromNV[macLoop]))
3133 {
3134 printk(KERN_ERR "not valid MAC from NV for %d", macLoop);
3135 /* This MAC is not valid, skip it
3136 * This MAC will be got from ini file */
3137 }
3138 else
3139 {
3140 vos_mem_copy((v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[macLoop].bytes[0],
3141 (v_U8_t *)&macFromNV[macLoop].bytes[0],
3142 VOS_MAC_ADDR_SIZE);
3143 }
3144 }
3145 }
3146 else
3147 {
3148 hddLog(VOS_TRACE_LEVEL_ERROR, "NV ITEM, MAC Not valid");
3149 return VOS_STATUS_E_FAILURE;
3150 }
3151#endif /* FEATURE_WLAN_INTEGRATED_SOC */
3152
3153#ifndef FEATURE_WLAN_INTEGRATED_SOC
3154#if 1 /* need to fix for concurrency */
3155 // Set the MAC Address
3156 // Currently this is used by HAL to add self sta. Remove this once self sta is added as part of session open.
3157 halStatus = ccmCfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
3158 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
3159 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]),
3160 hdd_set_mac_addr_cb, VOS_FALSE );
3161
3162 if (!HAL_STATUS_SUCCESS( halStatus ))
3163 {
3164 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
3165 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
3166 return VOS_STATUS_E_FAILURE;
3167 }
3168#endif
3169#endif
3170
3171 return VOS_STATUS_SUCCESS;
3172}
3173
3174/**---------------------------------------------------------------------------
3175
3176 \brief hdd_post_voss_start_config() - HDD post voss start config helper
3177
3178 \param - pAdapter - Pointer to the HDD
3179
3180 \return - None
3181
3182 --------------------------------------------------------------------------*/
3183VOS_STATUS hdd_post_voss_start_config(hdd_context_t* pHddCtx)
3184{
3185 eHalStatus halStatus;
3186 v_U32_t listenInterval;
3187
3188#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
3189 /* In the non-integrated architecture we update the configuration from
3190 the INI file and from NV after vOSS has been started
3191 */
3192
3193 // Apply the cfg.ini to cfg.dat
3194 if (FALSE == hdd_update_config_dat(pHddCtx))
3195 {
3196 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
3197 return VOS_STATUS_E_FAILURE;
3198 }
3199
3200 // Apply the NV to cfg.dat
3201 if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
3202 {
3203 hddLog(VOS_TRACE_LEVEL_FATAL,
3204 "%s: config update from NV failed", __func__ );
3205 return VOS_STATUS_E_FAILURE;
3206 }
3207#endif // FEATURE_WLAN_NON_INTEGRATED_SOC
3208
3209 // Send ready indication to the HDD. This will kick off the MAC
3210 // into a 'running' state and should kick off an initial scan.
3211 halStatus = sme_HDDReadyInd( pHddCtx->hHal );
3212 if ( !HAL_STATUS_SUCCESS( halStatus ) )
3213 {
3214 hddLog(VOS_TRACE_LEVEL_ERROR,"%S: sme_HDDReadyInd() failed with status "
3215 "code %08d [x%08x]",__func__, halStatus, halStatus );
3216 return VOS_STATUS_E_FAILURE;
3217 }
3218
3219 // Set default LI into HDD context,
3220 // otherwise under some race condition, HDD will set 0 LI value into RIVA,
3221 // And RIVA will crash
3222 wlan_cfgGetInt(pHddCtx->hHal, WNI_CFG_LISTEN_INTERVAL, &listenInterval);
3223 pHddCtx->hdd_actual_LI_value = listenInterval;
3224
3225 return VOS_STATUS_SUCCESS;
3226}
3227
3228#ifdef ANI_BUS_TYPE_SDIO
3229
3230#ifndef ANI_MANF_DIAG
3231// Routine to initialize the PMU
3232void wlan_hdd_enable_deepsleep(v_VOID_t * pVosContext)
3233{
3234/*-------------- Need to fix this correctly while doing Deepsleep testing
3235 tANI_U32 regValue = 0;
3236
3237 regValue = QWLAN_PMU_LDO_CTRL_REG_PMU_ANA_DEEP_SLEEP_EN_MASK |
3238 QWLAN_PMU_LDO_CTRL_REG_PMU_ANA_1P23_LPM_AON_MASK_MASK |
3239 QWLAN_PMU_LDO_CTRL_REG_PMU_ANA_1P23_LPM_SW_MASK_MASK |
3240 QWLAN_PMU_LDO_CTRL_REG_PMU_ANA_2P3_LPM_MASK_MASK;
3241
3242 WLANBAL_WriteRegister(pVosContext, QWLAN_PMU_LDO_CTRL_REG_REG, regValue);
3243---------------------*/
3244
3245 return;
3246}
3247#endif
3248#endif
3249
3250/* wake lock APIs for HDD */
3251void hdd_prevent_suspend(void)
3252{
Jeff Johnsone7245742012-09-05 17:12:55 -07003253#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5))
Jeff Johnson295189b2012-06-20 16:38:30 -07003254 wake_lock(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07003255#else
3256 wcnss_prevent_suspend();
3257#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003258}
3259
3260void hdd_allow_suspend(void)
3261{
Jeff Johnsone7245742012-09-05 17:12:55 -07003262#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5))
Jeff Johnson295189b2012-06-20 16:38:30 -07003263 wake_unlock(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07003264#else
3265 wcnss_allow_suspend();
3266#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003267}
3268
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07003269void hdd_allow_suspend_timeout(v_U32_t timeout)
3270{
3271#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5))
3272 wake_lock_timeout(&wlan_wake_lock, timeout);
3273#else
3274 /* Do nothing as there is no API in wcnss for timeout*/
3275#endif
3276}
3277
Jeff Johnson295189b2012-06-20 16:38:30 -07003278/**---------------------------------------------------------------------------
3279
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003280 \brief hdd_exchange_version_and_caps() - HDD function to exchange version and capability
3281 information between Host and Riva
3282
3283 This function gets reported version of FW
3284 It also finds the version of Riva headers used to compile the host
3285 It compares the above two and prints a warning if they are different
3286 It gets the SW and HW version string
3287 Finally, it exchanges capabilities between host and Riva i.e. host and riva exchange a msg
3288 indicating the features they support through a bitmap
3289
3290 \param - pHddCtx - Pointer to HDD context
3291
3292 \return - void
3293
3294 --------------------------------------------------------------------------*/
3295
3296void hdd_exchange_version_and_caps(hdd_context_t *pHddCtx)
3297{
3298
3299 tSirVersionType versionCompiled;
3300 tSirVersionType versionReported;
3301 tSirVersionString versionString;
3302 tANI_U8 fwFeatCapsMsgSupported = 0;
3303 VOS_STATUS vstatus;
3304
3305 /* retrieve and display WCNSS version information */
3306 do {
3307
3308 vstatus = sme_GetWcnssWlanCompiledVersion(pHddCtx->hHal,
3309 &versionCompiled);
3310 if (!VOS_IS_STATUS_SUCCESS(vstatus))
3311 {
3312 hddLog(VOS_TRACE_LEVEL_FATAL,
3313 "%s: unable to retrieve WCNSS WLAN compiled version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07003314 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003315 break;
3316 }
3317
3318 vstatus = sme_GetWcnssWlanReportedVersion(pHddCtx->hHal,
3319 &versionReported);
3320 if (!VOS_IS_STATUS_SUCCESS(vstatus))
3321 {
3322 hddLog(VOS_TRACE_LEVEL_FATAL,
3323 "%s: unable to retrieve WCNSS WLAN reported version",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07003324 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003325 break;
3326 }
3327
3328 if ((versionCompiled.major != versionReported.major) ||
3329 (versionCompiled.minor != versionReported.minor) ||
3330 (versionCompiled.version != versionReported.version) ||
3331 (versionCompiled.revision != versionReported.revision))
3332 {
3333 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
3334 "Host expected %u.%u.%u.%u\n",
3335 WLAN_MODULE_NAME,
3336 (int)versionReported.major,
3337 (int)versionReported.minor,
3338 (int)versionReported.version,
3339 (int)versionReported.revision,
3340 (int)versionCompiled.major,
3341 (int)versionCompiled.minor,
3342 (int)versionCompiled.version,
3343 (int)versionCompiled.revision);
3344 }
3345 else
3346 {
3347 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
3348 WLAN_MODULE_NAME,
3349 (int)versionReported.major,
3350 (int)versionReported.minor,
3351 (int)versionReported.version,
3352 (int)versionReported.revision);
3353 }
3354
3355 vstatus = sme_GetWcnssSoftwareVersion(pHddCtx->hHal,
3356 versionString,
3357 sizeof(versionString));
3358 if (!VOS_IS_STATUS_SUCCESS(vstatus))
3359 {
3360 hddLog(VOS_TRACE_LEVEL_FATAL,
3361 "%s: unable to retrieve WCNSS software version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07003362 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003363 break;
3364 }
3365
3366 pr_info("%s: WCNSS software version %s\n",
3367 WLAN_MODULE_NAME, versionString);
3368
3369 vstatus = sme_GetWcnssHardwareVersion(pHddCtx->hHal,
3370 versionString,
3371 sizeof(versionString));
3372 if (!VOS_IS_STATUS_SUCCESS(vstatus))
3373 {
3374 hddLog(VOS_TRACE_LEVEL_FATAL,
3375 "%s: unable to retrieve WCNSS hardware version string",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07003376 __func__);
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003377 break;
3378 }
3379
3380 pr_info("%s: WCNSS hardware version %s\n",
3381 WLAN_MODULE_NAME, versionString);
3382
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07003383 /* 1.Check if FW version is greater than 0.1.1.0. Only then send host-FW capability exchange message
3384 2.Host-FW capability exchange message is only present on riva 1.1 so
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003385 send the message only if it the riva is 1.1
3386 minor numbers for different riva branches:
3387 0 -> (1.0)Mainline Build
3388 1 -> (1.1)Mainline Build
3389 2->(1.04) Stability Build
3390 */
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07003391 if (((versionReported.major>0) || (versionReported.minor>1) ||
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003392 ((versionReported.minor>=1) && (versionReported.version>=1)))
3393 && ((versionReported.major == 1) && (versionReported.minor >= 1)))
3394 fwFeatCapsMsgSupported = 1;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07003395
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003396 if (fwFeatCapsMsgSupported)
Yathish9f22e662012-12-10 14:21:35 -08003397 {
3398#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
3399 if(!pHddCtx->cfg_ini->fEnableActiveModeOffload)
3400 sme_disableFeatureCapablity(WLANACTIVE_OFFLOAD);
3401#endif
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003402 sme_featureCapsExchange(pHddCtx->hHal);
Yathish9f22e662012-12-10 14:21:35 -08003403 }
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003404
3405 } while (0);
3406
3407}
3408
3409/**---------------------------------------------------------------------------
3410
Jeff Johnson295189b2012-06-20 16:38:30 -07003411 \brief hdd_wlan_startup() - HDD init function
3412
3413 This is the driver startup code executed once a WLAN device has been detected
3414
3415 \param - dev - Pointer to the underlying device
3416
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08003417 \return - 0 for success, < 0 for failure
Jeff Johnson295189b2012-06-20 16:38:30 -07003418
3419 --------------------------------------------------------------------------*/
3420
3421int hdd_wlan_startup(struct device *dev )
3422{
3423 VOS_STATUS status;
3424 hdd_adapter_t *pAdapter = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07003425 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07003426 hdd_context_t *pHddCtx = NULL;
3427 v_CONTEXT_t pVosContext= NULL;
3428#ifdef WLAN_BTAMP_FEATURE
3429 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
3430 WLANBAP_ConfigType btAmpConfig;
3431 hdd_config_t *pConfig;
3432#endif
3433 int ret;
3434#ifdef CONFIG_CFG80211
3435 struct wiphy *wiphy;
3436#endif
3437#ifdef ANI_BUS_TYPE_SDIO
3438 struct sdio_func *sdio_func_dev = dev_to_sdio_func(dev);
3439#endif //ANI_BUS_TYPE_SDIO
3440
3441 ENTER();
3442#ifdef CONFIG_CFG80211
3443 /*
3444 * cfg80211: wiphy allocation
3445 */
3446 wiphy = wlan_hdd_cfg80211_init(sizeof(hdd_context_t)) ;
3447
3448 if(wiphy == NULL)
3449 {
3450 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08003451 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07003452 }
3453
3454 pHddCtx = wiphy_priv(wiphy);
3455
3456#else
3457
3458 pHddCtx = vos_mem_malloc ( sizeof( hdd_context_t ) );
3459 if(pHddCtx == NULL)
3460 {
3461 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cfg80211 init failed", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08003462 return -ENOMEM;
Jeff Johnson295189b2012-06-20 16:38:30 -07003463 }
3464
3465#endif
3466 //Initialize the adapter context to zeros.
3467 vos_mem_zero(pHddCtx, sizeof( hdd_context_t ));
3468
3469#ifdef CONFIG_CFG80211
3470 pHddCtx->wiphy = wiphy;
3471#endif
3472 hdd_prevent_suspend();
3473 pHddCtx->isLoadUnloadInProgress = TRUE;
3474
3475 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
3476
3477 /*Get vos context here bcoz vos_open requires it*/
3478 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
3479
Madan Mohan Koyyalamudi0b78e152012-11-28 15:46:51 -08003480 if(pVosContext == NULL)
3481 {
3482 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed vos_get_global_context",__func__);
3483 goto err_free_hdd_context;
3484 }
3485
Jeff Johnson295189b2012-06-20 16:38:30 -07003486 //Save the Global VOSS context in adapter context for future.
3487 pHddCtx->pvosContext = pVosContext;
3488
3489 //Save the adapter context in global context for future.
3490 ((VosContextType*)(pVosContext))->pHDDContext = (v_VOID_t*)pHddCtx;
3491
3492#ifdef ANI_BUS_TYPE_SDIO
3493 // Set the private data for the device to our adapter.
3494 libra_sdio_setprivdata (sdio_func_dev, pHddCtx);
3495 atomic_set(&pHddCtx->sdio_claim_count, 0);
3496#endif // ANI_BUS_TYPE_SDIO
3497
3498 pHddCtx->parent_dev = dev;
3499
3500 init_completion(&pHddCtx->full_pwr_comp_var);
3501 init_completion(&pHddCtx->standby_comp_var);
3502 init_completion(&pHddCtx->req_bmps_comp_var);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07003503 init_completion(&pHddCtx->scan_info.scan_req_completion_event);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08003504 init_completion(&pHddCtx->scan_info.abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07003505
3506 hdd_list_init( &pHddCtx->hddAdapters, MAX_NUMBER_OF_ADAPTERS );
3507
3508 // Load all config first as TL config is needed during vos_open
3509 pHddCtx->cfg_ini = (hdd_config_t*) kmalloc(sizeof(hdd_config_t), GFP_KERNEL);
3510 if(pHddCtx->cfg_ini == NULL)
3511 {
3512 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed kmalloc hdd_config_t",__func__);
3513 goto err_free_hdd_context;
3514 }
3515
3516 vos_mem_zero(pHddCtx->cfg_ini, sizeof( hdd_config_t ));
3517
3518 // Read and parse the qcom_cfg.ini file
3519 status = hdd_parse_config_ini( pHddCtx );
3520 if ( VOS_STATUS_SUCCESS != status )
3521 {
3522 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: error parsing %s",
3523 __func__, WLAN_INI_FILE);
3524 goto err_config;
3525 }
3526
3527#ifdef CONFIG_CFG80211
3528 /*
3529 * cfg80211: Initialization and registration ...
3530 */
3531 if (0 < wlan_hdd_cfg80211_register(dev, wiphy, pHddCtx->cfg_ini))
3532 {
3533 hddLog(VOS_TRACE_LEVEL_FATAL,
3534 "%s: wlan_hdd_cfg80211_register return failure", __func__);
3535 goto err_wiphy_reg;
3536 }
3537#endif
3538
Varun Reddy Yeturu587e6802013-01-24 12:21:41 -08003539 // Update VOS trace levels based upon the cfg.ini
3540 hdd_vos_trace_enable(VOS_MODULE_ID_BAP,
3541 pHddCtx->cfg_ini->vosTraceEnableBAP);
3542 hdd_vos_trace_enable(VOS_MODULE_ID_TL,
3543 pHddCtx->cfg_ini->vosTraceEnableTL);
3544 hdd_vos_trace_enable(VOS_MODULE_ID_WDI,
3545 pHddCtx->cfg_ini->vosTraceEnableWDI);
3546 hdd_vos_trace_enable(VOS_MODULE_ID_HDD,
3547 pHddCtx->cfg_ini->vosTraceEnableHDD);
3548 hdd_vos_trace_enable(VOS_MODULE_ID_SME,
3549 pHddCtx->cfg_ini->vosTraceEnableSME);
3550 hdd_vos_trace_enable(VOS_MODULE_ID_PE,
3551 pHddCtx->cfg_ini->vosTraceEnablePE);
3552 hdd_vos_trace_enable(VOS_MODULE_ID_WDA,
3553 pHddCtx->cfg_ini->vosTraceEnableWDA);
3554 hdd_vos_trace_enable(VOS_MODULE_ID_SYS,
3555 pHddCtx->cfg_ini->vosTraceEnableSYS);
3556 hdd_vos_trace_enable(VOS_MODULE_ID_VOSS,
3557 pHddCtx->cfg_ini->vosTraceEnableVOSS);
3558#ifdef WLAN_SOFTAP_FEATURE
3559 hdd_vos_trace_enable(VOS_MODULE_ID_SAP,
3560 pHddCtx->cfg_ini->vosTraceEnableSAP);
3561 hdd_vos_trace_enable(VOS_MODULE_ID_HDD_SOFTAP,
3562 pHddCtx->cfg_ini->vosTraceEnableHDDSAP);
3563#endif
3564
Jeff Johnson295189b2012-06-20 16:38:30 -07003565#ifdef FEATURE_WLAN_INTEGRATED_SOC
3566 // Update WDI trace levels based upon the cfg.ini
3567 hdd_wdi_trace_enable(eWLAN_MODULE_DAL,
3568 pHddCtx->cfg_ini->wdiTraceEnableDAL);
3569 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_CTRL,
3570 pHddCtx->cfg_ini->wdiTraceEnableCTL);
3571 hdd_wdi_trace_enable(eWLAN_MODULE_DAL_DATA,
3572 pHddCtx->cfg_ini->wdiTraceEnableDAT);
3573 hdd_wdi_trace_enable(eWLAN_MODULE_PAL,
3574 pHddCtx->cfg_ini->wdiTraceEnablePAL);
3575#endif /* FEATURE_WLAN_INTEGRATED_SOC */
3576
3577#ifdef ANI_MANF_DIAG
3578 if(VOS_FTM_MODE == hdd_get_conparam())
3579 {
3580 if ( VOS_STATUS_SUCCESS != wlan_hdd_ftm_open(pHddCtx) )
3581 {
3582 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_ftm_open Failed",__func__);
3583 goto err_free_hdd_context;
3584 }
3585 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: FTM driver loaded success fully",__func__);
3586 return VOS_STATUS_SUCCESS;
3587 }
3588#endif
3589
3590 //Open watchdog module
3591 if(pHddCtx->cfg_ini->fIsLogpEnabled)
3592 {
3593 status = vos_watchdog_open(pVosContext,
3594 &((VosContextType*)pVosContext)->vosWatchdog, sizeof(VosWatchdogContext));
3595
3596 if(!VOS_IS_STATUS_SUCCESS( status ))
3597 {
3598 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_watchdog_open failed",__func__);
3599#ifdef CONFIG_CFG80211
3600 goto err_wiphy_reg;
3601#else
3602 goto err_config;
3603#endif
3604 }
3605 }
3606
3607 pHddCtx->isLogpInProgress = FALSE;
3608 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
3609
3610#ifdef ANI_BUS_TYPE_SDIO
3611 status = WLANBAL_Open(pHddCtx->pvosContext);
3612 if(!VOS_IS_STATUS_SUCCESS(status))
3613 {
3614 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3615 "%s: Failed to open BAL",__func__);
3616 goto err_wdclose;
3617 }
3618#endif // ANI_BUS_TYPE_SDIO
3619
3620 status = vos_chipVoteOnXOBuffer(NULL, NULL, NULL);
3621 if(!VOS_IS_STATUS_SUCCESS(status))
3622 {
3623 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed to configure 19.2 MHz Clock", __func__);
3624#ifdef ANI_BUS_TYPE_SDIO
3625 goto err_balclose;
3626#else
3627 goto err_wdclose;
3628#endif
3629 }
3630
3631
3632#ifdef ANI_BUS_TYPE_SDIO
3633 status = WLANSAL_Start(pHddCtx->pvosContext);
3634 if (!VOS_IS_STATUS_SUCCESS(status))
3635 {
3636 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed to start SAL",__func__);
3637 goto err_clkvote;
3638 }
3639
3640 /* Start BAL */
3641 status = WLANBAL_Start(pHddCtx->pvosContext);
3642
3643 if (!VOS_IS_STATUS_SUCCESS(status))
3644 {
3645 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3646 "%s: Failed to start BAL",__func__);
3647 goto err_salstop;
3648 }
3649#endif // ANI_BUS_TYPE_SDIO
3650
3651#ifdef MSM_PLATFORM_7x30
3652 /* FIXME: Volans 2.0 configuration. Reconfigure 1.3v SW supply to 1.3v. It will be configured to
3653 * 1.4v in vos_ChipPowerup() routine above
3654 */
3655#endif
3656
3657 status = vos_open( &pVosContext, 0);
3658 if ( !VOS_IS_STATUS_SUCCESS( status ))
3659 {
3660 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_open failed",__func__);
3661 goto err_balstop;
3662 }
3663
3664 /* Save the hal context in Adapter */
3665 pHddCtx->hHal = (tHalHandle)vos_get_context( VOS_MODULE_ID_SME, pVosContext );
3666
3667 if ( NULL == pHddCtx->hHal )
3668 {
3669 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HAL context is null",__func__);
3670 goto err_vosclose;
3671 }
3672
Jeff Johnsone7245742012-09-05 17:12:55 -07003673#ifdef FEATURE_WLAN_INTEGRATED_SOC
3674 /* Vos preStart is calling */
3675 /* vos preStart which does cfg download should be called before set sme config which accesses/sets some cfgs */
3676 status = vos_preStart( pHddCtx->pvosContext );
3677 if ( !VOS_IS_STATUS_SUCCESS( status ) )
3678 {
3679 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_preStart failed",__func__);
3680 goto err_vosclose;
3681 }
3682#endif
3683
Jeff Johnson295189b2012-06-20 16:38:30 -07003684 // Set the SME configuration parameters...
3685 status = hdd_set_sme_config( pHddCtx );
3686
3687 if ( VOS_STATUS_SUCCESS != status )
3688 {
3689 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed hdd_set_sme_config",__func__);
3690 goto err_vosclose;
3691 }
3692
3693 //Initialize the WMM module
3694 status = hdd_wmm_init(pHddCtx);
3695 if (!VOS_IS_STATUS_SUCCESS(status))
3696 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07003697 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: hdd_wmm_init failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07003698 goto err_vosclose;
3699 }
3700
3701#ifdef FEATURE_WLAN_INTEGRATED_SOC
Jeff Johnson295189b2012-06-20 16:38:30 -07003702 /* In the integrated architecture we update the configuration from
3703 the INI file and from NV before vOSS has been started so that
3704 the final contents are available to send down to the cCPU */
3705
3706 // Apply the cfg.ini to cfg.dat
3707 if (FALSE == hdd_update_config_dat(pHddCtx))
3708 {
3709 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: config update failed",__func__ );
3710 goto err_vosclose;
3711 }
3712
3713 // Apply the NV to cfg.dat
3714 /* Prima Update MAC address only at here */
3715 if (VOS_STATUS_SUCCESS != hdd_update_config_from_nv(pHddCtx))
3716 {
3717#ifdef WLAN_AUTOGEN_MACADDR_FEATURE
3718 /* There was not a valid set of MAC Addresses in NV. See if the
3719 default addresses were modified by the cfg.ini settings. If so,
3720 we'll use them, but if not, we'll autogenerate a set of MAC
3721 addresses based upon the device serial number */
3722
3723 static const v_MACADDR_t default_address =
3724 {{0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}};
3725 unsigned int serialno;
3726 int i;
3727
3728 serialno = wcnss_get_serial_number();
3729 if ((0 != serialno) &&
3730 (0 == memcmp(&default_address, &pHddCtx->cfg_ini->intfMacAddr[0],
3731 sizeof(default_address))))
3732 {
3733 /* cfg.ini has the default address, invoke autogen logic */
3734
3735 /* MAC address has 3 bytes of OUI so we have a maximum of 3
3736 bytes of the serial number that can be used to generate
3737 the other 3 bytes of the MAC address. Mask off all but
3738 the lower 3 bytes (this will also make sure we don't
3739 overflow in the next step) */
3740 serialno &= 0x00FFFFFF;
3741
3742 /* we need a unique address for each session */
3743 serialno *= VOS_MAX_CONCURRENCY_PERSONA;
3744
3745 /* autogen all addresses */
3746 for (i = 0; i < VOS_MAX_CONCURRENCY_PERSONA; i++)
3747 {
3748 /* start with the entire default address */
3749 pHddCtx->cfg_ini->intfMacAddr[i] = default_address;
3750 /* then replace the lower 3 bytes */
3751 pHddCtx->cfg_ini->intfMacAddr[i].bytes[3] = (serialno >> 16) & 0xFF;
3752 pHddCtx->cfg_ini->intfMacAddr[i].bytes[4] = (serialno >> 8) & 0xFF;
3753 pHddCtx->cfg_ini->intfMacAddr[i].bytes[5] = serialno & 0xFF;
3754
3755 serialno++;
3756 }
3757
3758 pr_info("wlan: Invalid MAC addresses in NV, autogenerated "
3759 MAC_ADDRESS_STR,
3760 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
3761 }
3762 else
3763#endif //WLAN_AUTOGEN_MACADDR_FEATURE
3764 {
3765 hddLog(VOS_TRACE_LEVEL_ERROR,
3766 "%s: Invalid MAC address in NV, using MAC from ini file "
3767 MAC_ADDRESS_STR, __func__,
3768 MAC_ADDR_ARRAY(pHddCtx->cfg_ini->intfMacAddr[0].bytes));
3769 }
3770 }
3771 {
3772 eHalStatus halStatus;
3773 // Set the MAC Address
3774 // Currently this is used by HAL to add self sta. Remove this once self sta is added as part of session open.
3775 halStatus = cfgSetStr( pHddCtx->hHal, WNI_CFG_STA_ID,
3776 (v_U8_t *)&pHddCtx->cfg_ini->intfMacAddr[0],
3777 sizeof( pHddCtx->cfg_ini->intfMacAddr[0]) );
3778
3779 if (!HAL_STATUS_SUCCESS( halStatus ))
3780 {
3781 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Failed to set MAC Address. "
3782 "HALStatus is %08d [x%08x]",__func__, halStatus, halStatus );
Madan Mohan Koyyalamudib8b126b2012-11-15 17:37:30 -08003783 goto err_vosclose;
Jeff Johnson295189b2012-06-20 16:38:30 -07003784 }
3785 }
3786#endif // FEATURE_WLAN_INTEGRATED_SOC
3787
3788 /*Start VOSS which starts up the SME/MAC/HAL modules and everything else
3789 Note: Firmware image will be read and downloaded inside vos_start API */
3790 status = vos_start( pHddCtx->pvosContext );
3791 if ( !VOS_IS_STATUS_SUCCESS( status ) )
3792 {
3793 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: vos_start failed",__func__);
3794 goto err_vosclose;
3795 }
3796
Madan Mohan Koyyalamudi8612ec92012-09-28 15:53:07 -07003797 /* Exchange capability info between Host and FW and also get versioning info from FW */
3798 hdd_exchange_version_and_caps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07003799
3800 status = hdd_post_voss_start_config( pHddCtx );
3801 if ( !VOS_IS_STATUS_SUCCESS( status ) )
3802 {
3803 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hdd_post_voss_start_config failed",
3804 __func__);
3805 goto err_vosstop;
3806 }
3807
3808#ifdef WLAN_SOFTAP_FEATURE
3809 if (VOS_STA_SAP_MODE == hdd_get_conparam())
3810 {
3811 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_SOFTAP, "softap.%d",
3812 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
3813 }
3814 else
3815 {
3816#endif
3817 pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_INFRA_STATION, "wlan%d",
3818 wlan_hdd_get_intf_addr(pHddCtx), FALSE );
3819 if (pAdapter != NULL)
3820 {
3821#ifdef WLAN_FEATURE_P2P
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05303822 if ( pHddCtx->cfg_ini->isP2pDeviceAddrAdministrated )
Jeff Johnson295189b2012-06-20 16:38:30 -07003823 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05303824 vos_mem_copy( pHddCtx->p2pDeviceAddress.bytes,
3825 pHddCtx->cfg_ini->intfMacAddr[0].bytes,
3826 sizeof(tSirMacAddr));
Madan Mohan Koyyalamudiedfc1b72012-10-18 20:25:55 -07003827
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05303828 /* Generate the P2P Device Address. This consists of the device's
3829 * primary MAC address with the locally administered bit set.
3830 */
3831 pHddCtx->p2pDeviceAddress.bytes[0] |= 0x02;
Jeff Johnsone7245742012-09-05 17:12:55 -07003832 }
3833 else
3834 {
Gopichand Nakkala49f96f62013-02-06 14:38:17 +05303835 tANI_U8* p2p_dev_addr = wlan_hdd_get_intf_addr(pHddCtx);
3836 if (p2p_dev_addr != NULL)
3837 {
3838 vos_mem_copy(&pHddCtx->p2pDeviceAddress.bytes[0],
3839 p2p_dev_addr, VOS_MAC_ADDR_SIZE);
3840 }
3841 else
3842 {
3843 hddLog(VOS_TRACE_LEVEL_FATAL,
3844 "%s: Failed to allocate mac_address for p2p_device",
3845 __func__);
3846 goto err_close_adapter;
3847 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003848 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003849
3850 pP2pAdapter = hdd_open_adapter( pHddCtx, WLAN_HDD_P2P_DEVICE, "p2p%d",
3851 &pHddCtx->p2pDeviceAddress.bytes[0], FALSE );
3852 if ( NULL == pP2pAdapter )
3853 {
3854 hddLog(VOS_TRACE_LEVEL_FATAL,
3855 "%s: Failed to do hdd_open_adapter for P2P Device Interface",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07003856 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07003857 goto err_close_adapter;
3858 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003859#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003860 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003861#ifdef WLAN_SOFTAP_FEATURE
3862 }
3863#endif
3864
3865 if( pAdapter == NULL )
3866 {
3867 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: hdd_open_adapter failed",__func__);
3868#ifdef ANI_BUS_TYPE_SDIO
3869 goto err_balstop;
3870#else
3871 goto err_clkvote;
3872#endif
3873 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003874
Jeff Johnson295189b2012-06-20 16:38:30 -07003875#ifdef WLAN_BTAMP_FEATURE
3876 vStatus = WLANBAP_Open(pVosContext);
3877 if(!VOS_IS_STATUS_SUCCESS(vStatus))
3878 {
3879 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3880 "%s: Failed to open BAP",__func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07003881 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07003882 }
3883
3884 vStatus = BSL_Init(pVosContext);
3885 if(!VOS_IS_STATUS_SUCCESS(vStatus))
3886 {
3887 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3888 "%s: Failed to Init BSL",__func__);
3889 goto err_bap_close;
3890 }
3891 vStatus = WLANBAP_Start(pVosContext);
3892 if (!VOS_IS_STATUS_SUCCESS(vStatus))
3893 {
3894 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3895 "%s: Failed to start TL",__func__);
3896 goto err_bap_close;
3897 }
3898
3899 pConfig = pHddCtx->cfg_ini;
3900 btAmpConfig.ucPreferredChannel = pConfig->preferredChannel;
3901 status = WLANBAP_SetConfig(&btAmpConfig);
3902
3903#endif //WLAN_BTAMP_FEATURE
Jeff Johnsone7245742012-09-05 17:12:55 -07003904
Jeff Johnson295189b2012-06-20 16:38:30 -07003905#ifdef FEATURE_WLAN_SCAN_PNO
3906 /*SME must send channel update configuration to RIVA*/
3907 sme_UpdateChannelConfig(pHddCtx->hHal);
3908#endif
3909
3910#ifdef FEATURE_WLAN_INTEGRATED_SOC
3911 /* Register with platform driver as client for Suspend/Resume */
3912 status = hddRegisterPmOps(pHddCtx);
3913 if ( !VOS_IS_STATUS_SUCCESS( status ) )
3914 {
3915 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddRegisterPmOps failed",__func__);
3916#ifdef WLAN_BTAMP_FEATURE
3917 goto err_bap_stop;
3918#else
Jeff Johnsone7245742012-09-05 17:12:55 -07003919 goto err_close_adapter;
Jeff Johnson295189b2012-06-20 16:38:30 -07003920#endif //WLAN_BTAMP_FEATURE
3921 }
3922
3923 /* Register TM level change handler function to the platform */
3924 status = hddDevTmRegisterNotifyCallback(pHddCtx);
3925 if ( !VOS_IS_STATUS_SUCCESS( status ) )
3926 {
3927 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmRegisterNotifyCallback failed",__func__);
3928 goto err_unregister_pmops;
3929 }
3930#endif
3931
3932 /* register for riva power on lock to platform driver */
3933 if (req_riva_power_on_lock("wlan"))
3934 {
3935 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: req riva power on lock failed",
3936 __func__);
3937 goto err_unregister_pmops;
3938 }
3939
Jeff Johnson295189b2012-06-20 16:38:30 -07003940 // register net device notifier for device change notification
3941 ret = register_netdevice_notifier(&hdd_netdev_notifier);
3942
3943 if(ret < 0)
3944 {
3945 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: register_netdevice_notifier failed",__func__);
3946 goto err_free_power_on_lock;
3947 }
3948
3949 //Initialize the nlink service
3950 if(nl_srv_init() != 0)
3951 {
3952 hddLog(VOS_TRACE_LEVEL_FATAL,"%S: nl_srv_init failed",__func__);
3953 goto err_reg_netdev;
3954 }
3955
3956 //Initialize the BTC service
3957 if(btc_activate_service(pHddCtx) != 0)
3958 {
3959 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: btc_activate_service failed",__func__);
3960 goto err_nl_srv;
3961 }
3962
3963#ifdef PTT_SOCK_SVC_ENABLE
3964 //Initialize the PTT service
3965 if(ptt_sock_activate_svc(pHddCtx) != 0)
3966 {
3967 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: ptt_sock_activate_svc failed",__func__);
3968 goto err_nl_srv;
3969 }
3970#endif
3971
Jeff Johnson295189b2012-06-20 16:38:30 -07003972 hdd_register_mcast_bcast_filter(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07003973#ifdef CONFIG_CFG80211
3974#ifdef WLAN_SOFTAP_FEATURE
3975 if (VOS_STA_SAP_MODE != hdd_get_conparam())
3976#endif
3977 {
Madan Mohan Koyyalamudic537df22012-10-22 15:07:08 -07003978 /* Action frame registered in one adapter which will
3979 * applicable to all interfaces
3980 */
Madan Mohan Koyyalamudie233e292012-09-18 17:38:02 -07003981 wlan_hdd_cfg80211_post_voss_start(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003982 }
3983#endif
3984
3985 mutex_init(&pHddCtx->sap_lock);
3986
3987 pHddCtx->isLoadUnloadInProgress = FALSE;
3988
Jeff Johnsone7245742012-09-05 17:12:55 -07003989#ifdef WLAN_FEATURE_HOLD_RX_WAKELOCK
3990 /* Initialize the wake lcok */
3991 wake_lock_init(&pHddCtx->rx_wake_lock,
3992 WAKE_LOCK_SUSPEND,
3993 "qcom_rx_wakelock");
3994#endif
Madan Mohan Koyyalamudi69fc3ad2012-11-28 16:04:56 -08003995 /* Initialize the wake lcok */
3996 wake_lock_init(&pHddCtx->sap_wake_lock,
3997 WAKE_LOCK_SUSPEND,
3998 "qcom_sap_wakelock");
Jeff Johnsone7245742012-09-05 17:12:55 -07003999
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004000 vos_event_init(&pHddCtx->scan_info.scan_finished_event);
4001 pHddCtx->scan_info.scan_pending_option = WEXT_SCAN_PENDING_GIVEUP;
Jeff Johnson295189b2012-06-20 16:38:30 -07004002
4003 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, FALSE);
4004 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004005
4006 // Initialize the restart logic
4007 wlan_hdd_restart_init(pHddCtx);
Chilam NG571c65a2013-01-19 12:27:36 +05304008
4009#ifdef FEATURE_WLAN_TDLS
Hoonki Lee387663d2013-02-05 18:08:43 -08004010 if(0 != wlan_hdd_tdls_init(pAdapter->dev))
4011 {
4012 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_tdls_init failed",__func__);
4013 goto err_nl_srv;
4014 }
Chilam NG571c65a2013-01-19 12:27:36 +05304015#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004016
4017 goto success;
4018
4019err_nl_srv:
4020 nl_srv_exit();
4021
4022err_reg_netdev:
4023 unregister_netdevice_notifier(&hdd_netdev_notifier);
4024
4025err_free_power_on_lock:
4026 free_riva_power_on_lock("wlan");
4027
4028err_unregister_pmops:
4029 hddDevTmUnregisterNotifyCallback(pHddCtx);
4030 hddDeregisterPmOps(pHddCtx);
4031
4032#ifdef WLAN_BTAMP_FEATURE
4033err_bap_stop:
4034 WLANBAP_Stop(pVosContext);
4035#endif
4036
4037#ifdef WLAN_BTAMP_FEATURE
4038err_bap_close:
4039 WLANBAP_Close(pVosContext);
4040#endif
4041
Jeff Johnson295189b2012-06-20 16:38:30 -07004042err_close_adapter:
4043 hdd_close_all_adapters( pHddCtx );
4044
4045err_vosstop:
4046 vos_stop(pVosContext);
4047
4048err_vosclose:
4049 status = vos_sched_close( pVosContext );
4050 if (!VOS_IS_STATUS_SUCCESS(status)) {
4051 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
4052 "%s: Failed to close VOSS Scheduler", __func__);
4053 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status ) );
4054 }
4055 vos_close(pVosContext );
4056
4057err_balstop:
4058#ifdef ANI_BUS_TYPE_SDIO
4059#ifndef ANI_MANF_DIAG
4060 wlan_hdd_enable_deepsleep(pHddCtx->pvosContext);
4061#endif
4062
4063 WLANBAL_Stop(pHddCtx->pvosContext);
4064 WLANBAL_SuspendChip(pHddCtx->pvosContext);
4065#endif
4066
4067#ifdef ANI_BUS_TYPE_SDIO
4068err_salstop:
4069 WLANSAL_Stop(pHddCtx->pvosContext);
4070
4071#endif
4072err_clkvote:
4073 vos_chipVoteOffXOBuffer(NULL, NULL, NULL);
4074
4075#ifdef ANI_BUS_TYPE_SDIO
4076err_balclose:
4077 WLANBAL_Close(pHddCtx->pvosContext);
4078#endif // ANI_BUS_TYPE_SDIO
4079
4080err_wdclose:
4081 if(pHddCtx->cfg_ini->fIsLogpEnabled)
4082 vos_watchdog_close(pVosContext);
4083
4084#ifdef CONFIG_CFG80211
4085err_wiphy_reg:
4086 wiphy_unregister(wiphy) ;
4087#endif
4088
4089err_config:
4090 kfree(pHddCtx->cfg_ini);
4091 pHddCtx->cfg_ini= NULL;
4092
4093err_free_hdd_context:
4094 hdd_allow_suspend();
4095#ifdef CONFIG_CFG80211
4096 wiphy_free(wiphy) ;
4097 //kfree(wdev) ;
4098#else
4099 vos_mem_free( pHddCtx );
4100#endif
4101 VOS_BUG(1);
4102
Madan Mohan Koyyalamudid57ae632012-11-06 18:42:48 -08004103 if (hdd_is_ssr_required())
4104 {
4105 /* WDI timeout had happened during load, so SSR is needed here */
4106 subsystem_restart("wcnss");
4107 msleep(5000);
4108 }
4109 hdd_set_ssr_required (VOS_FALSE);
4110
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08004111 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07004112
4113success:
4114 EXIT();
4115 return 0;
4116}
4117
4118/**---------------------------------------------------------------------------
4119
Jeff Johnson32d95a32012-09-10 13:15:23 -07004120 \brief hdd_driver_init() - Core Driver Init Function
Jeff Johnson295189b2012-06-20 16:38:30 -07004121
Jeff Johnson32d95a32012-09-10 13:15:23 -07004122 This is the driver entry point - called in different timeline depending
4123 on whether the driver is statically or dynamically linked
Jeff Johnson295189b2012-06-20 16:38:30 -07004124
4125 \param - None
4126
4127 \return - 0 for success, non zero for failure
4128
4129 --------------------------------------------------------------------------*/
Jeff Johnson32d95a32012-09-10 13:15:23 -07004130static int hdd_driver_init( void)
Jeff Johnson295189b2012-06-20 16:38:30 -07004131{
4132 VOS_STATUS status;
4133 v_CONTEXT_t pVosContext = NULL;
4134#ifdef ANI_BUS_TYPE_SDIO
4135 struct sdio_func *sdio_func_dev = NULL;
4136 unsigned int attempts = 0;
4137#endif // ANI_BUS_TYPE_SDIO
4138 struct device *dev = NULL;
4139 int ret_status = 0;
4140
4141 ENTER();
4142
Jeff Johnsone7245742012-09-05 17:12:55 -07004143#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5))
Jeff Johnson295189b2012-06-20 16:38:30 -07004144 wake_lock_init(&wlan_wake_lock, WAKE_LOCK_SUSPEND, "wlan");
Jeff Johnsone7245742012-09-05 17:12:55 -07004145#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004146
4147 pr_info("%s: loading driver v%s\n", WLAN_MODULE_NAME,
4148 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
4149
4150 //Power Up Libra WLAN card first if not already powered up
4151 status = vos_chipPowerUp(NULL,NULL,NULL);
4152 if (!VOS_IS_STATUS_SUCCESS(status))
4153 {
4154 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Libra WLAN not Powered Up. "
4155 "exiting", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08004156 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07004157 }
4158
4159#ifdef ANI_BUS_TYPE_SDIO
4160 //SDIO Polling should be turned on for card detection. When using Android Wi-Fi GUI
4161 //users need not trigger SDIO polling explicitly. However when loading drivers via
4162 //command line (Adb shell), users must turn on SDIO polling prior to loading WLAN.
4163 do {
4164 sdio_func_dev = libra_getsdio_funcdev();
4165 if (NULL == sdio_func_dev) {
4166 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Libra WLAN not detected yet.",__func__);
4167 attempts++;
4168 }
4169 else {
4170 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Libra WLAN detecton succeeded",__func__);
4171 dev = &sdio_func_dev->dev;
4172 break;
4173 }
4174
4175 if(attempts == 7)
4176 break;
4177
4178 msleep(250);
4179
4180 }while (attempts < 7);
4181
4182 //Retry to detect the card again by Powering Down the chip and Power up the chip
4183 //again. This retry is done to recover from CRC Error
4184 if (NULL == sdio_func_dev) {
4185
4186 attempts = 0;
4187
4188 //Vote off any PMIC voltage supplies
4189 vos_chipPowerDown(NULL, NULL, NULL);
4190
4191 msleep(1000);
4192
4193 //Power Up Libra WLAN card first if not already powered up
4194 status = vos_chipPowerUp(NULL,NULL,NULL);
4195 if (!VOS_IS_STATUS_SUCCESS(status))
4196 {
4197 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Retry Libra WLAN not Powered Up. "
4198 "exiting", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08004199 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07004200 }
4201
4202 do {
4203 sdio_func_dev = libra_getsdio_funcdev();
4204 if (NULL == sdio_func_dev) {
4205 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Retry Libra WLAN not detected yet.",__func__);
4206 attempts++;
4207 }
4208 else {
4209 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Retry Libra WLAN detecton succeeded",__func__);
4210 dev = &sdio_func_dev->dev;
4211 break;
4212 }
4213
4214 if(attempts == 2)
4215 break;
4216
4217 msleep(1000);
4218
4219 }while (attempts < 3);
4220 }
4221
4222#endif // ANI_BUS_TYPE_SDIO
4223
4224#ifdef ANI_BUS_TYPE_PCI
4225
4226 dev = wcnss_wlan_get_device();
4227
4228#endif // ANI_BUS_TYPE_PCI
4229
4230#ifdef ANI_BUS_TYPE_PLATFORM
4231 dev = wcnss_wlan_get_device();
4232#endif // ANI_BUS_TYPE_PLATFORM
4233
4234
4235 do {
4236 if (NULL == dev) {
4237 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: WLAN device not found!!",__func__);
4238 ret_status = -1;
4239 break;
4240 }
4241
4242#ifdef MEMORY_DEBUG
4243 vos_mem_init();
4244#endif
4245
4246#ifdef TIMER_MANAGER
4247 vos_timer_manager_init();
4248#endif
4249
4250 /* Preopen VOSS so that it is ready to start at least SAL */
4251 status = vos_preOpen(&pVosContext);
4252
4253 if (!VOS_IS_STATUS_SUCCESS(status))
4254 {
4255 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to preOpen VOSS", __func__);
4256 ret_status = -1;
4257 break;
4258 }
4259
4260#ifdef ANI_BUS_TYPE_SDIO
4261 /* Now Open SAL */
4262 status = WLANSAL_Open(pVosContext, 0);
4263
4264 if(!VOS_IS_STATUS_SUCCESS(status))
4265 {
4266 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Failed to open SAL", __func__);
4267
4268 /* If unable to open, cleanup and return failure */
4269 vos_preClose( &pVosContext );
4270 ret_status = -1;
4271 break;
4272 }
4273#endif // ANI_BUS_TYPE_SDIO
4274
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004275#ifndef MODULE
4276 /* For statically linked driver, call hdd_set_conparam to update curr_con_mode
4277 */
4278 hdd_set_conparam((v_UINT_t)con_mode);
4279#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004280
4281 // Call our main init function
4282 if(hdd_wlan_startup(dev)) {
4283 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: WLAN Driver Initialization failed",
4284 __func__);
4285#ifdef ANI_BUS_TYPE_SDIO
4286 WLANSAL_Close(pVosContext);
4287#endif // ANI_BUS_TYPE_SDIO
4288 vos_preClose( &pVosContext );
4289 ret_status = -1;
4290 break;
4291 }
4292
4293 /* Cancel the vote for XO Core ON
4294 * This is done here for safety purposes in case we re-initialize without turning
4295 * it OFF in any error scenario.
4296 */
Madan Mohan Koyyalamudi8b7f1e62012-10-05 14:56:51 -07004297 hddLog(VOS_TRACE_LEVEL_INFO, "In module init: Ensure Force XO Core is OFF"
Jeff Johnson295189b2012-06-20 16:38:30 -07004298 " when WLAN is turned ON so Core toggles"
Madan Mohan Koyyalamudi8b7f1e62012-10-05 14:56:51 -07004299 " unless we enter PSD");
Jeff Johnson295189b2012-06-20 16:38:30 -07004300 if (vos_chipVoteXOCore(NULL, NULL, NULL, VOS_FALSE) != VOS_STATUS_SUCCESS)
4301 {
4302 hddLog(VOS_TRACE_LEVEL_ERROR, "Could not cancel XO Core ON vote. Not returning failure."
4303 " Power consumed will be high\n");
4304 }
4305 } while (0);
4306
4307 if (0 != ret_status)
4308 {
4309 //Assert Deep sleep signal now to put Libra HW in lowest power state
4310 status = vos_chipAssertDeepSleep( NULL, NULL, NULL );
4311 VOS_ASSERT( VOS_IS_STATUS_SUCCESS( status) );
4312
4313 //Vote off any PMIC voltage supplies
4314 vos_chipPowerDown(NULL, NULL, NULL);
4315#ifdef TIMER_MANAGER
4316 vos_timer_exit();
4317#endif
4318#ifdef MEMORY_DEBUG
4319 vos_mem_exit();
4320#endif
4321
Jeff Johnsone7245742012-09-05 17:12:55 -07004322#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5))
Jeff Johnson295189b2012-06-20 16:38:30 -07004323 wake_lock_destroy(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07004324#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004325 pr_err("%s: driver load failure\n", WLAN_MODULE_NAME);
4326 }
4327 else
4328 {
4329 //Send WLAN UP indication to Nlink Service
4330 send_btc_nlink_msg(WLAN_MODULE_UP_IND, 0);
4331
4332 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
4333
4334 }
4335
4336 EXIT();
4337
4338 return ret_status;
4339}
4340
Jeff Johnson32d95a32012-09-10 13:15:23 -07004341/**---------------------------------------------------------------------------
4342
4343 \brief hdd_module_init() - Init Function
4344
4345 This is the driver entry point (invoked when module is loaded using insmod)
4346
4347 \param - None
4348
4349 \return - 0 for success, non zero for failure
4350
4351 --------------------------------------------------------------------------*/
4352#ifdef MODULE
4353static int __init hdd_module_init ( void)
4354{
4355 return hdd_driver_init();
4356}
Jeff Johnson32d95a32012-09-10 13:15:23 -07004357#else /* #ifdef MODULE */
4358static int __init hdd_module_init ( void)
4359{
4360 /* Driver initialization is delayed to fwpath_changed_handler */
4361 return 0;
4362}
Jeff Johnson32d95a32012-09-10 13:15:23 -07004363#endif /* #ifdef MODULE */
4364
Jeff Johnson295189b2012-06-20 16:38:30 -07004365
4366/**---------------------------------------------------------------------------
4367
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004368 \brief hdd_driver_exit() - Exit function
Jeff Johnson295189b2012-06-20 16:38:30 -07004369
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004370 This is the driver exit point (invoked when module is unloaded using rmmod
4371 or con_mode was changed by userspace)
Jeff Johnson295189b2012-06-20 16:38:30 -07004372
4373 \param - None
4374
4375 \return - None
4376
4377 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004378static void hdd_driver_exit(void)
Jeff Johnson295189b2012-06-20 16:38:30 -07004379{
4380 hdd_context_t *pHddCtx = NULL;
4381 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004382
4383 pr_info("%s: unloading driver v%s\n", WLAN_MODULE_NAME, QWLAN_VERSIONSTR);
4384
4385 //Get the global vos context
4386 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
4387
4388 if(!pVosContext)
4389 {
4390 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
4391 goto done;
4392 }
4393
4394 //Get the HDD context.
4395 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
4396
4397 if(!pHddCtx)
4398 {
4399 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: module exit called before probe",__func__);
4400 }
4401 else
4402 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004403 /* module exit should never proceed if SSR is not completed */
Jeff Johnson295189b2012-06-20 16:38:30 -07004404 while(isWDresetInProgress()){
Jeff Johnsone7245742012-09-05 17:12:55 -07004405 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:SSR in Progress; block rmmod for 1 second!!!",__func__);
4406 msleep(1000);
Jeff Johnson295189b2012-06-20 16:38:30 -07004407 }
4408
4409 pHddCtx->isLoadUnloadInProgress = TRUE;
4410 vos_set_load_unload_in_progress(VOS_MODULE_ID_VOSS, TRUE);
4411
4412 //Do all the cleanup before deregistering the driver
4413 hdd_wlan_exit(pHddCtx);
4414 }
4415
4416#ifdef ANI_BUS_TYPE_SDIO
4417 WLANSAL_Close(pVosContext);
4418#endif // ANI_BUS_TYPE_SDIO
4419
4420 vos_preClose( &pVosContext );
4421
4422#ifdef TIMER_MANAGER
4423 vos_timer_exit();
4424#endif
4425#ifdef MEMORY_DEBUG
4426 vos_mem_exit();
4427#endif
4428
4429done:
Jeff Johnsone7245742012-09-05 17:12:55 -07004430#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5))
Jeff Johnson295189b2012-06-20 16:38:30 -07004431 wake_lock_destroy(&wlan_wake_lock);
Jeff Johnsone7245742012-09-05 17:12:55 -07004432#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004433 pr_info("%s: driver unloaded\n", WLAN_MODULE_NAME);
4434}
4435
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004436/**---------------------------------------------------------------------------
4437
4438 \brief hdd_module_exit() - Exit function
4439
4440 This is the driver exit point (invoked when module is unloaded using rmmod)
4441
4442 \param - None
4443
4444 \return - None
4445
4446 --------------------------------------------------------------------------*/
4447static void __exit hdd_module_exit(void)
4448{
4449 hdd_driver_exit();
4450}
4451
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07004452#ifdef MODULE
4453static int fwpath_changed_handler(const char *kmessage,
4454 struct kernel_param *kp)
4455{
4456 /* nothing to do when driver is DLKM */
4457 return 0;
4458}
4459
4460static int con_mode_handler(const char *kmessage,
4461 struct kernel_param *kp)
4462{
Madan Mohan Koyyalamudif2f8d8b2012-10-11 17:06:59 -07004463 return param_set_int(kmessage, kp);
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07004464}
4465#else /* #ifdef MODULE */
4466/**---------------------------------------------------------------------------
4467
4468 \brief fwpath_changed_handler() - Handler Function
4469
4470 This is the driver entry point
4471 - delayed driver initialization when driver is statically linked
4472 - invoked when module parameter fwpath is modified from userpspace to signal
4473 initializing the WLAN driver
4474
4475 \return - 0 for success, non zero for failure
4476
4477 --------------------------------------------------------------------------*/
4478static int fwpath_changed_handler(const char *kmessage,
4479 struct kernel_param *kp)
4480{
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07004481 int ret_status;
4482
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07004483 if (!wlan_hdd_inited) {
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07004484 ret_status = hdd_driver_init();
4485 wlan_hdd_inited = ret_status ? 0 : 1;
4486 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07004487 }
4488
4489 hdd_driver_exit();
4490
4491 msleep(200);
4492
Madan Mohan Koyyalamudi62e60052012-10-05 14:27:22 -07004493 ret_status = hdd_driver_init();
4494 wlan_hdd_inited = ret_status ? 0 : 1;
4495 return ret_status;
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07004496}
4497
Jeff Johnson295189b2012-06-20 16:38:30 -07004498/**---------------------------------------------------------------------------
4499
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004500 \brief con_mode_handler() -
4501
4502 Handler function for module param con_mode when it is changed by userspace
4503 Dynamically linked - do nothing
4504 Statically linked - exit and init driver, as in rmmod and insmod
4505
4506 \param -
4507
4508 \return -
4509
4510 --------------------------------------------------------------------------*/
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004511static int con_mode_handler(const char *kmessage,
4512 struct kernel_param *kp)
4513{
4514 int ret = param_set_int(kmessage, kp);
4515
4516 if (ret)
4517 return ret;
4518
Madan Mohan Koyyalamudic2ec3bd2012-09-18 19:49:40 -07004519 return fwpath_changed_handler(kmessage, kp);
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004520}
4521#endif /* #ifdef MODULE */
4522
4523/**---------------------------------------------------------------------------
4524
Jeff Johnson295189b2012-06-20 16:38:30 -07004525 \brief hdd_get_conparam() -
4526
4527 This is the driver exit point (invoked when module is unloaded using rmmod)
4528
4529 \param - None
4530
4531 \return - tVOS_CON_MODE
4532
4533 --------------------------------------------------------------------------*/
4534tVOS_CON_MODE hdd_get_conparam ( void )
4535{
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004536#ifdef MODULE
Jeff Johnson295189b2012-06-20 16:38:30 -07004537 return (tVOS_CON_MODE)con_mode;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004538#else
4539 return (tVOS_CON_MODE)curr_con_mode;
4540#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004541}
4542void hdd_set_conparam ( v_UINT_t newParam )
4543{
4544 con_mode = newParam;
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004545#ifndef MODULE
4546 curr_con_mode = con_mode;
4547#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004548}
4549/**---------------------------------------------------------------------------
4550
4551 \brief hdd_softap_sta_deauth() - function
4552
4553 This to take counter measure to handle deauth req from HDD
4554
4555 \param - pAdapter - Pointer to the HDD
4556
4557 \param - enable - boolean value
4558
4559 \return - None
4560
4561 --------------------------------------------------------------------------*/
4562
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08004563VOS_STATUS hdd_softap_sta_deauth(hdd_adapter_t *pAdapter, v_U8_t *pDestMacAddress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004564{
Jeff Johnson295189b2012-06-20 16:38:30 -07004565 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08004566 VOS_STATUS vosStatus = VOS_STATUS_E_FAULT;
Jeff Johnson295189b2012-06-20 16:38:30 -07004567#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
4568 tHalHandle hHalHandle;
4569#endif
4570
4571 ENTER();
4572
4573 hddLog( LOGE, "hdd_softap_sta_deauth:(0x%x, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
4574
4575 //Ignore request to deauth bcmc station
4576 if( pDestMacAddress[0] & 0x1 )
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08004577 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -07004578
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08004579 vosStatus = WLANSAP_DeauthSta(pVosContext,pDestMacAddress);
Jeff Johnson295189b2012-06-20 16:38:30 -07004580
4581 EXIT();
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08004582 return vosStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -07004583}
4584
4585/**---------------------------------------------------------------------------
4586
4587 \brief hdd_softap_sta_disassoc() - function
4588
4589 This to take counter measure to handle deauth req from HDD
4590
4591 \param - pAdapter - Pointer to the HDD
4592
4593 \param - enable - boolean value
4594
4595 \return - None
4596
4597 --------------------------------------------------------------------------*/
4598
4599void hdd_softap_sta_disassoc(hdd_adapter_t *pAdapter,v_U8_t *pDestMacAddress)
4600{
4601 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
4602
4603 ENTER();
4604
4605 hddLog( LOGE, "hdd_softap_sta_disassoc:(0x%x, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
4606
4607 //Ignore request to disassoc bcmc station
4608 if( pDestMacAddress[0] & 0x1 )
4609 return;
4610
4611 WLANSAP_DisassocSta(pVosContext,pDestMacAddress);
4612}
4613
4614void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *pAdapter,v_BOOL_t enable)
4615{
4616 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
4617
4618 ENTER();
4619
4620 hddLog( LOGE, "hdd_softap_tkip_mic_fail_counter_measure:(0x%x, false)", (WLAN_HDD_GET_CTX(pAdapter))->pvosContext);
4621
4622 WLANSAP_SetCounterMeasure(pVosContext, (v_BOOL_t)enable);
4623}
4624
Jeff Johnson295189b2012-06-20 16:38:30 -07004625/**---------------------------------------------------------------------------
4626 *
4627 * \brief hdd_get__concurrency_mode() -
4628 *
4629 *
4630 * \param - None
4631 *
4632 * \return - CONCURRENCY MODE
4633 *
4634 * --------------------------------------------------------------------------*/
4635tVOS_CONCURRENCY_MODE hdd_get_concurrency_mode ( void )
4636{
4637 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
4638 hdd_context_t *pHddCtx;
4639
4640 if (NULL != pVosContext)
4641 {
4642 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
4643 if (NULL != pHddCtx)
4644 {
4645 return (tVOS_CONCURRENCY_MODE)pHddCtx->concurrency_mode;
4646 }
4647 }
4648
4649 /* we are in an invalid state :( */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004650 hddLog(LOGE, "%s: Invalid context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004651 return VOS_STA;
4652}
4653
4654/* Decide whether to allow/not the apps power collapse.
4655 * Allow apps power collapse if we are in connected state.
4656 * if not, allow only if we are in IMPS */
4657v_BOOL_t hdd_is_apps_power_collapse_allowed(hdd_context_t* pHddCtx)
4658{
4659 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
Srikant Kuppafef66a72013-01-30 17:32:44 -08004660 tANI_BOOLEAN scanRspPending = csrNeighborRoamScanRspPending(pHddCtx->hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004661 hdd_config_t *pConfig = pHddCtx->cfg_ini;
4662 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4663 hdd_adapter_t *pAdapter = NULL;
4664 VOS_STATUS status;
Yathish9f22e662012-12-10 14:21:35 -08004665 tVOS_CONCURRENCY_MODE concurrent_state = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004666
4667#ifdef WLAN_SOFTAP_FEATURE
4668 if (VOS_STA_SAP_MODE == hdd_get_conparam())
4669 return TRUE;
4670#endif
4671
Yathish9f22e662012-12-10 14:21:35 -08004672 concurrent_state = hdd_get_concurrency_mode();
4673
4674#ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
4675 if(((concurrent_state == (VOS_STA | VOS_P2P_CLIENT)) ||
4676 (concurrent_state == (VOS_STA | VOS_P2P_GO))) &&
4677 (IS_ACTIVEMODE_OFFLOAD_FEATURE_ENABLE))
4678 return TRUE;
4679#endif
4680
Jeff Johnson295189b2012-06-20 16:38:30 -07004681 /*loop through all adapters. TBD fix for Concurrency */
4682 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4683 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4684 {
4685 pAdapter = pAdapterNode->pAdapter;
4686 if ( (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
4687 || (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
4688 {
Srikant Kuppafef66a72013-01-30 17:32:44 -08004689 if (((pConfig->fIsImpsEnabled || pConfig->fIsBmpsEnabled)
Jeff Johnson295189b2012-06-20 16:38:30 -07004690 && (pmcState != IMPS && pmcState != BMPS
Srikant Kuppafef66a72013-01-30 17:32:44 -08004691 && pmcState != STOPPED && pmcState != STANDBY)) ||
4692 (eANI_BOOLEAN_TRUE == scanRspPending))
Jeff Johnson295189b2012-06-20 16:38:30 -07004693 {
Srikant Kuppafef66a72013-01-30 17:32:44 -08004694 hddLog( LOGE, "%s: do not allow APPS power collapse-"
4695 "pmcState = %d scanRspPending = %d",
4696 __func__, pmcState, scanRspPending );
Jeff Johnson295189b2012-06-20 16:38:30 -07004697 return FALSE;
4698 }
4699 }
4700 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4701 pAdapterNode = pNext;
4702 }
4703 return TRUE;
4704}
4705
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -08004706/* Decides whether to send suspend notification to Riva
4707 * if any adapter is in BMPS; then it is required */
4708v_BOOL_t hdd_is_suspend_notify_allowed(hdd_context_t* pHddCtx)
4709{
4710 tPmcState pmcState = pmcGetPmcState(pHddCtx->hHal);
4711 hdd_config_t *pConfig = pHddCtx->cfg_ini;
4712
4713 if (pConfig->fIsBmpsEnabled && (pmcState == BMPS))
4714 {
4715 return TRUE;
4716 }
4717 return FALSE;
4718}
4719
Jeff Johnson295189b2012-06-20 16:38:30 -07004720void wlan_hdd_set_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
4721{
4722 switch(mode)
4723 {
4724 case WLAN_HDD_INFRA_STATION:
4725#ifdef WLAN_FEATURE_P2P
4726 case WLAN_HDD_P2P_CLIENT:
4727 case WLAN_HDD_P2P_GO:
4728#endif
4729 case WLAN_HDD_SOFTAP:
Jeff Johnsone7245742012-09-05 17:12:55 -07004730 pHddCtx->concurrency_mode |= (1 << mode);
4731 pHddCtx->no_of_sessions[mode]++;
Jeff Johnson295189b2012-06-20 16:38:30 -07004732 break;
4733 default:
4734 break;
4735
4736 }
4737 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: concurrency_mode = 0x%x NumberofSessions for mode %d = %d",
4738 __func__,pHddCtx->concurrency_mode,mode,pHddCtx->no_of_sessions[mode]);
4739}
4740
4741
4742void wlan_hdd_clear_concurrency_mode(hdd_context_t *pHddCtx, tVOS_CON_MODE mode)
4743{
4744 switch(mode)
4745 {
4746 case WLAN_HDD_INFRA_STATION:
4747#ifdef WLAN_FEATURE_P2P
4748 case WLAN_HDD_P2P_CLIENT:
4749 case WLAN_HDD_P2P_GO:
4750#endif
4751 case WLAN_HDD_SOFTAP:
4752 pHddCtx->no_of_sessions[mode]--;
4753 if (!(pHddCtx->no_of_sessions[mode]))
4754 pHddCtx->concurrency_mode &= (~(1 << mode));
4755 break;
4756 default:
4757 break;
4758 }
4759 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: concurrency_mode = 0x%x NumberofSessions for mode %d = %d",
4760 __func__,pHddCtx->concurrency_mode,mode,pHddCtx->no_of_sessions[mode]);
4761}
4762
Jeff Johnsone7245742012-09-05 17:12:55 -07004763/**---------------------------------------------------------------------------
4764 *
4765 * \brief wlan_hdd_restart_init
4766 *
4767 * This function initalizes restart timer/flag. An internal function.
4768 *
4769 * \param - pHddCtx
4770 *
4771 * \return - None
4772 *
4773 * --------------------------------------------------------------------------*/
4774
4775static void wlan_hdd_restart_init(hdd_context_t *pHddCtx)
4776{
4777 /* Initialize */
4778 pHddCtx->hdd_restart_retries = 0;
4779 atomic_set(&pHddCtx->isRestartInProgress, 0);
4780 vos_timer_init(&pHddCtx->hdd_restart_timer,
4781 VOS_TIMER_TYPE_SW,
4782 wlan_hdd_restart_timer_cb,
4783 pHddCtx);
4784}
4785/**---------------------------------------------------------------------------
4786 *
4787 * \brief wlan_hdd_restart_deinit
4788 *
4789 * This function cleans up the resources used. An internal function.
4790 *
4791 * \param - pHddCtx
4792 *
4793 * \return - None
4794 *
4795 * --------------------------------------------------------------------------*/
4796
4797static void wlan_hdd_restart_deinit(hdd_context_t* pHddCtx)
4798{
4799
4800 VOS_STATUS vos_status;
4801 /* Block any further calls */
4802 atomic_set(&pHddCtx->isRestartInProgress, 1);
4803 /* Cleanup */
4804 vos_status = vos_timer_stop( &pHddCtx->hdd_restart_timer );
4805 if (!VOS_IS_STATUS_SUCCESS(vos_status))
Madan Mohan Koyyalamudi8b7f1e62012-10-05 14:56:51 -07004806 hddLog(LOGW, FL("Failed to stop HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -07004807 vos_status = vos_timer_destroy(&pHddCtx->hdd_restart_timer);
4808 if (!VOS_IS_STATUS_SUCCESS(vos_status))
Madan Mohan Koyyalamudi8b7f1e62012-10-05 14:56:51 -07004809 hddLog(LOGW, FL("Failed to destroy HDD restart timer"));
Jeff Johnsone7245742012-09-05 17:12:55 -07004810
4811}
4812
4813/**---------------------------------------------------------------------------
4814 *
4815 * \brief wlan_hdd_framework_restart
4816 *
4817 * This function uses a cfg80211 API to start a framework initiated WLAN
4818 * driver module unload/load.
4819 *
4820 * Also this API keep retrying (WLAN_HDD_RESTART_RETRY_MAX_CNT).
4821 *
4822 *
4823 * \param - pHddCtx
4824 *
4825 * \return - VOS_STATUS_SUCCESS: Success
4826 * VOS_STATUS_E_EMPTY: Adapter is Empty
4827 * VOS_STATUS_E_NOMEM: No memory
4828
4829 * --------------------------------------------------------------------------*/
4830
4831static VOS_STATUS wlan_hdd_framework_restart(hdd_context_t *pHddCtx)
4832{
4833 VOS_STATUS status = VOS_STATUS_SUCCESS;
4834 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4835 int len = (sizeof (struct ieee80211_mgmt));
4836 struct ieee80211_mgmt *mgmt = NULL;
4837
4838 /* Prepare the DEAUTH managment frame with reason code */
4839 mgmt = kzalloc(len, GFP_KERNEL);
4840 if(mgmt == NULL)
4841 {
4842 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Jeff Johnson1250df42012-12-10 14:31:52 -08004843 "%s: memory allocation failed (%d bytes)", __func__, len);
Jeff Johnsone7245742012-09-05 17:12:55 -07004844 return VOS_STATUS_E_NOMEM;
4845 }
4846 mgmt->u.deauth.reason_code = WLAN_REASON_DISASSOC_LOW_ACK;
4847
4848 /* Iterate over all adapters/devices */
4849 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4850 do
4851 {
4852 if( (status == VOS_STATUS_SUCCESS) &&
4853 pAdapterNode &&
4854 pAdapterNode->pAdapter)
4855 {
4856 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4857 "restarting the driver(intf:\'%s\' mode:%d :try %d)",
4858 pAdapterNode->pAdapter->dev->name,
4859 pAdapterNode->pAdapter->device_mode,
4860 pHddCtx->hdd_restart_retries + 1);
4861 /*
4862 * CFG80211 event to restart the driver
4863 *
4864 * 'cfg80211_send_unprot_deauth' sends a
4865 * NL80211_CMD_UNPROT_DEAUTHENTICATE event to supplicant at any state
4866 * of SME(Linux Kernel) state machine.
4867 *
4868 * Reason code WLAN_REASON_DISASSOC_LOW_ACK is currently used to restart
4869 * the driver.
4870 *
4871 */
4872
4873 cfg80211_send_unprot_deauth(pAdapterNode->pAdapter->dev, (u_int8_t*)mgmt, len );
4874 }
4875 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4876 pAdapterNode = pNext;
4877 } while((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status));
4878
4879
4880 /* Free the allocated management frame */
4881 kfree(mgmt);
4882
4883 /* Retry until we unload or reach max count */
4884 if(++pHddCtx->hdd_restart_retries < WLAN_HDD_RESTART_RETRY_MAX_CNT)
4885 vos_timer_start(&pHddCtx->hdd_restart_timer, WLAN_HDD_RESTART_RETRY_DELAY_MS);
4886
4887 return status;
4888
4889}
4890/**---------------------------------------------------------------------------
4891 *
4892 * \brief wlan_hdd_restart_timer_cb
4893 *
4894 * Restart timer callback. An internal function.
4895 *
4896 * \param - User data:
4897 *
4898 * \return - None
4899 *
4900 * --------------------------------------------------------------------------*/
4901
4902void wlan_hdd_restart_timer_cb(v_PVOID_t usrDataForCallback)
4903{
4904 hdd_context_t *pHddCtx = usrDataForCallback;
4905 wlan_hdd_framework_restart(pHddCtx);
4906 return;
4907
4908}
4909
4910
4911/**---------------------------------------------------------------------------
4912 *
4913 * \brief wlan_hdd_restart_driver
4914 *
4915 * This function sends an event to supplicant to restart the WLAN driver.
4916 *
4917 * This function is called from vos_wlanRestart.
4918 *
4919 * \param - pHddCtx
4920 *
4921 * \return - VOS_STATUS_SUCCESS: Success
4922 * VOS_STATUS_E_EMPTY: Adapter is Empty
4923 * VOS_STATUS_E_ALREADY: Request already in progress
4924
4925 * --------------------------------------------------------------------------*/
4926VOS_STATUS wlan_hdd_restart_driver(hdd_context_t *pHddCtx)
4927{
4928 VOS_STATUS status = VOS_STATUS_SUCCESS;
4929
4930 /* A tight check to make sure reentrancy */
4931 if(atomic_xchg(&pHddCtx->isRestartInProgress, 1))
4932 {
4933 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
4934 "%s: WLAN restart is already in progress", __func__);
4935
4936 return VOS_STATUS_E_ALREADY;
4937 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07004938 /* when WLAN driver is statically linked, then invoke SSR by sending
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -07004939 * the reset interrupt. If it is DLKM, then use restart API
4940 */
4941#ifdef MODULE
Jeff Johnsone7245742012-09-05 17:12:55 -07004942 status = wlan_hdd_framework_restart(pHddCtx);
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -07004943#else
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -08004944#ifdef HAVE_WCNSS_RESET_INTR
Madan Mohan Koyyalamudibb8f0172012-09-28 15:36:06 -07004945 wcnss_reset_intr();
4946#endif
Madan Mohan Koyyalamudie388b342012-11-08 15:03:16 -08004947#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07004948
Jeff Johnsone7245742012-09-05 17:12:55 -07004949 return status;
4950}
4951
4952
Jeff Johnson295189b2012-06-20 16:38:30 -07004953//Register the module init/exit functions
4954module_init(hdd_module_init);
4955module_exit(hdd_module_exit);
4956
4957MODULE_LICENSE("Dual BSD/GPL");
4958MODULE_AUTHOR("Qualcomm Atheros, Inc.");
4959MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
4960
Madan Mohan Koyyalamudi2331c8a2012-09-18 18:14:48 -07004961module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
4962 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Jeff Johnson32d95a32012-09-10 13:15:23 -07004963
4964module_param_call(fwpath, fwpath_changed_handler, param_get_string, fwpath,
4965 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);