1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DrvMain.c
3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * All rights reserved.
6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Redistribution and use in source and binary forms, with or without
8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * modification, are permitted provided that the following conditions
9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * are met:
10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions of source code must retain the above copyright
12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer.
13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions in binary form must reproduce the above copyright
14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer in
15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    the documentation and/or other materials provided with the
16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    distribution.
17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Neither the name Texas Instruments nor the names of its
18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    contributors may be used to endorse or promote products derived
19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    from this software without specific prior written permission.
20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \file   DrvMain.c
36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \brief  The DrvMain module. Handles driver init, stop and recovery processes.
37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \see    DrvMain.h
39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define __FILE_ID__  FILE_ID_49
42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "tidef.h"
43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "osApi.h"
44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "report.h"
45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "context.h"
46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "timer.h"
47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "CmdHndlr.h"
48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "DrvMain.h"
49981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "scrApi.h"
50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "EvHandler.h"
51981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "connApi.h"
52981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "siteMgrApi.h"
53981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "sme.h"
54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "SoftGeminiApi.h"
55981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "roamingMngrApi.h"
56981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "qosMngr_API.h"
57981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "TrafficMonitor.h"
58981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "PowerMgr_API.h"
59981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "EvHandler.h"
60981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "apConn.h"
61981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "currBss.h"
62981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "SwitchChannelApi.h"
63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "ScanCncn.h"
64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "healthMonitor.h"
65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "scanMngrApi.h"
66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "regulatoryDomainApi.h"
67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "measurementMgrApi.h"
68981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef XCC_MODULE_INCLUDED
69981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "XCCMngr.h"
70981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
71981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "TxnQueue.h"
72981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "TWDriver.h"
73981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "debug.h"
74981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "host_platform.h"
75981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "StaCap.h"
76981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "WlanDrvCommon.h"
77981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "DrvMainModules.h"
78981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "CmdDispatcher.h"
79981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
80981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
81981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define SM_WATCHDOG_TIME_MS     20000  /* SM processes timeout is 20 sec. */
82981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
83653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define SDIO_CONNECT_THRESHOLD  8
84653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
85981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
86981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Handle failure status from the SM callbacks by triggering the SM with FAILURE event */
87981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define HANDLE_CALLBACKS_FAILURE_STATUS(hDrvMain, eStatus)      \
88981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (eStatus != TI_OK) { drvMain_SmEvent (hDrvMain, SM_EVENT_FAILURE);  return; }
89981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
90981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* The DrvMain SM states */
91981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef enum
92981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  0 */ SM_STATE_IDLE,
94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  1 */ SM_STATE_WAIT_INI_FILE,
95981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  2 */ SM_STATE_WAIT_NVS_FILE,
96981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  3 */ SM_STATE_HW_INIT,
97653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    /*  4 */ SM_STATE_DOWNLOAD_FW_FILE,
98981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  5 */ SM_STATE_WAIT_FW_FILE,
99981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  6 */ SM_STATE_FW_INIT,
100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  7 */ SM_STATE_FW_CONFIG,
101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  8 */ SM_STATE_OPERATIONAL,
102981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  9 */ SM_STATE_DISCONNECTING,
103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* 10 */ SM_STATE_STOPPING,
104981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* 11 */ SM_STATE_STOPPED,
105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* 12 */ SM_STATE_STOPPING_ON_FAIL,
106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* 13 */ SM_STATE_FAILED
107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} ESmState;
109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* The DrvMain SM events */
111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef enum
112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  0 */ SM_EVENT_START,
114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  1 */ SM_EVENT_INI_FILE_READY,
115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  2 */ SM_EVENT_NVS_FILE_READY,
116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  3 */ SM_EVENT_HW_INIT_COMPLETE,
117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  4 */ SM_EVENT_FW_FILE_READY,
118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  5 */ SM_EVENT_FW_INIT_COMPLETE,
119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  6 */ SM_EVENT_FW_CONFIG_COMPLETE,
120981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  7 */ SM_EVENT_STOP,
121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  8 */ SM_EVENT_RECOVERY,
122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*  9 */ SM_EVENT_DISCONNECTED,
123981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* 10 */ SM_EVENT_STOP_COMPLETE,
124981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* 11 */ SM_EVENT_FAILURE
125981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
126981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} ESmEvent;
127981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
128981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* The module's object */
129981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef struct
130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TStadHandlesList  tStadHandles; /* All STAD modules handles (distributed in driver init process) */
132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_BOOL           bRecovery;    /* Indicates if we are during recovery process */
133981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ESmState          eSmState;     /* The DrvMain SM state. */
134981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ESmEvent          ePendingEvent;/* A pending event issued when the SM is busy */
135981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32         uPendingEventsCount; /* Counts the number of events pending for SM execution */
136981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TFileInfo         tFileInfo;    /* Information of last file retrieved by os_GetFile() */
137981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32         uContextId;   /* ID allocated to this module on registration to context module */
138981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    EActionType       eAction;      /* The last action (start/stop) inserted to the driver */
139981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    void             *hSignalObj;   /* The signal object used for waiting for action completion */
140981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE         hWatchdogTimer;/* SM Watchdog timer - expires upon deadlock in Start/Stop/Recovery processes. */
141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBusDrvCfg        tBusDrvCfg;   /* A union (struc per each supported bus type) for the bus driver configuration */
142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
143981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} TDrvMain;
144981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
145981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
146981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_Init (TI_HANDLE hDrvMain);
147981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InitHwCb (TI_HANDLE hDrvMain, TI_STATUS eStatus);
148981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InitFwCb (TI_HANDLE hDrvMain, TI_STATUS eStatus);
149981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_ConfigFwCb (TI_HANDLE hDrvMain, TI_STATUS eStatus);
150981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_TwdStopCb (TI_HANDLE hDrvMain, TI_STATUS eStatus);
151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InitFailCb (TI_HANDLE hDrvMain, TI_STATUS eStatus);
152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InitLocals (TDrvMain *pDrvMain);
153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* static void drvMain_SmWatchdogTimeout (TI_HANDLE hDrvMain); */
154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_SmEvent (TI_HANDLE hDrvMain, ESmEvent eEvent);
155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_Sm (TI_HANDLE hDrvMain, ESmEvent eEvent);
156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* External functions prototypes */
158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \brief WLAN Driver I/F Get file
160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hOs         - OS module object handle
162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pFileInfo   - Pointer to output file information
163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK on success or TI_NOK on failure
164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \par Description
166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * This function provides access to a requested init file:
167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * It provides the requested file information and call the requester callback.
168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Note that in Linux the files were previously loaded to driver memory by the loader
169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
171981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtextern int  wlanDrvIf_GetFile (TI_HANDLE hOs, TFileInfo *pFileInfo);
173981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \brief WLAN Driver I/F Update Driver State
174981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
175653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  hOs          - OS module object handle
176653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  eDriverState - New Driver State
177981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
178981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
179981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \par Description
180981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * This function Update the driver state (Idle | Running | Stopped |Failed):
181981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
183981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
184981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtextern void wlanDrvIf_UpdateDriverState (TI_HANDLE hOs, EDriverSteadyState eDriverState);
185981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \brief WLAN Driver I/F Set MAC Address
186981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
187653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  hOs          - OS module object handle
188653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  pMacAddr     - Pointer to MAC address to set
189981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
190981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
191981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \par Description
192981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * This function Update the driver MAC address by copy it to the network interface structure
193981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
194981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
195981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
196981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtextern void wlanDrvIf_SetMacAddress (TI_HANDLE hOs, TI_UINT8 *pMacAddr);
197981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \brief OS Init Table INI File
198981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
199653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  hOs              - OS module object handle
200653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  InitTable        - Pointer to initialization table
201653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  file_buf         - Pointer to Input buffer from INI file
202653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  file_length      - Length of input buffer from INI file
203981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
204981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
205981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \par Description
206981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * This function perform Initializing of init table accrding to data from INI file and driver defaults
207981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
208981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
209981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
210981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtextern int  osInitTable_IniFile (TI_HANDLE hOs, TInitTable *InitTable, char *file_buf, int file_length);
211981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
212981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
213981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
214981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
215981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_Create
216981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Create the driver modules
217981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
218981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Create all STAD and TWD modules.
219981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Then call all modules init functions which initializes their handles and variables.
220981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
221981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
222981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hOs          - Handle to the Os Abstraction Layer
223981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pDrvMainHndl - Pointer for returning the DrvMain handle.
224981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pCmdHndlr    - Pointer for returning the CmdHndlr handle.
225981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pContext     - Pointer for returning the Context handle.
226981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pTxDataQ     - Pointer for returning the TxDataQ handle.
227981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pTxMgmtQ     - Pointer for returning the TxMgmtQ handle.
228981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pTxCtrl      - Pointer for returning the TxCtrl handle.
229981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pTwd         - Pointer for returning the TWD handle.
230981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pEvHandler   - Pointer for returning the EvHndler handle.
231981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return Handle to the DrvMain module (NULL if failed)
232981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
233981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
234981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS drvMain_Create (TI_HANDLE  hOs,
235981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          TI_HANDLE *pDrvMainHndl,
236981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          TI_HANDLE *pCmdHndlr,
237981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          TI_HANDLE *pContext,
238981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          TI_HANDLE *pTxDataQ,
239981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          TI_HANDLE *pTxMgmtQ,
240981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          TI_HANDLE *pTxCtrl,
241981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          TI_HANDLE *pTwd,
242981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          TI_HANDLE *pEvHandler)
243981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
244981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Create the DrvMain module object. */
245981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain *pDrvMain = (TDrvMain *) os_memoryAlloc (hOs, sizeof(TDrvMain));
246981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
247981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain == NULL)
248981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
249981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
250981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
251981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
252981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_memoryZero (hOs, (void *)pDrvMain, sizeof(TDrvMain));
253981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
254981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hDrvMain = (TI_HANDLE)pDrvMain;
255981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hOs = hOs;
256981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
257981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Create watchdog timer to detect deadlocks in the DrvMain SM processes. */
258981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* return thr timer later on */
259981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*pDrvMain->hWatchdogTimer = os_timerCreate (hOs, drvMain_SmWatchdogTimeout, (TI_HANDLE)pDrvMain);
260981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->hWatchdogTimer == NULL)
261981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
262981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
263981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
264981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }*/
265981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
266981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
267981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *   Create all driver modules
268981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *   =========================
269981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
270981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
271981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hContext = context_Create (hOs);
272981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hContext == NULL)
273981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
274981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
275981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
276981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
277981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
278981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hTimer = tmr_Create (hOs);
279981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTimer == NULL)
280981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
281981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
282981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
283981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
284981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
285981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hSCR = scr_create (hOs);
286981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSCR == NULL)
287981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
288981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
289981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
290981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
291981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
292981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hTxnQ = txnQ_Create (hOs);
293981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxnQ == NULL)
294981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
295981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
296981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
297981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
298981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
299981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hEvHandler = EvHandler_Create (hOs);
300981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hEvHandler == NULL)
301653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    {
302653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        drvMain_Destroy (pDrvMain);
303653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        return TI_NOK;
304653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    }
305981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
306653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->tStadHandles.hReport = report_Create (hOs);
307653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    if (pDrvMain->tStadHandles.hReport == NULL)
308981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
309981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
310981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
311981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
312981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
313981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hConn = conn_create (hOs);
314981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hConn == NULL)
315981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
316981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
317981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
318981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
319981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
320981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hScanCncn = scanCncn_Create (hOs);
321981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hScanCncn == NULL)
322981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
323981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
324981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
325981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
326981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
327981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hSme = sme_Create (hOs);
328981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSme == NULL)
329981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
330981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
331981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
332981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
333981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
334981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hSiteMgr = siteMgr_create (hOs);
335981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSiteMgr == NULL)
336981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
337981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
338981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
339981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
340981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
341981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hMlmeSm = mlme_create (hOs);
342981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hMlmeSm == NULL)
343981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
344981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
345981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
346981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
347981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
348981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hAuth = auth_create (hOs);
349981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hAuth == NULL)
350981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
351981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
352981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
353981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
354981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
355981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hAssoc = assoc_create (hOs);
356981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hAssoc == NULL)
357981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
358981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
359981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
360981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
361981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
362981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hRxData = rxData_create (hOs);
363981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hRxData == NULL)
364981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
365981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
366981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
367981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
368981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
369981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hTxCtrl = txCtrl_Create (hOs);
370981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxCtrl == NULL)
371981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
372981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
373981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
374981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
375981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
376981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hTxDataQ = txDataQ_Create(hOs);
377981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxDataQ == NULL)
378981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
379981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
380981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
381981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
382981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
383981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hTxMgmtQ = txMgmtQ_Create(hOs);
384981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxMgmtQ == NULL)
385981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
386981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
387981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
388981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
389981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
390981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hTxPort = txPort_create (hOs);
391981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxPort == NULL)
392981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
393981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
394981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
395981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
396981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
397981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hCtrlData = ctrlData_create (hOs);
398981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hCtrlData == NULL)
399981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
400981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
401981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
402981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
403981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
404981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hTrafficMon = TrafficMonitor_create (hOs);
405981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTrafficMon == NULL)
406981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
407981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
408981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
409981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
410981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
411981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hRsn = rsn_create (hOs);
412981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hRsn == NULL)
413981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
414981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
415981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
416981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
417981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
418981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hRegulatoryDomain = regulatoryDomain_create (hOs);
419981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hRegulatoryDomain == NULL)
420981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
421981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
422981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
423981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
424981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
425981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hMeasurementMgr = measurementMgr_create (hOs);
426981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hMeasurementMgr == NULL)
427981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
428981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
429981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
430981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
431981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
432981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hSoftGemini = SoftGemini_create (hOs);
433981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSoftGemini == NULL)
434981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
435981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
436981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
437981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
438981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
439981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef XCC_MODULE_INCLUDED
440981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hXCCMngr = XCCMngr_create (hOs);
441981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hXCCMngr == NULL)
442981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
443981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
444981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
445981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
446981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#else
447981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hXCCMngr = NULL;
448981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
449981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
450981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hRoamingMngr = roamingMngr_create (hOs);
451981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hRoamingMngr == NULL)
452981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
453981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
454981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
455981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
456981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
457981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hAPConnection = apConn_create (hOs);
458981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hAPConnection == NULL)
459981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
460981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
461981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
462981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
463981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
464981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hCurrBss = currBSS_create (hOs);
465981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hCurrBss == NULL)
466981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
467981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
468981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
469981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
470981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
471981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hQosMngr = qosMngr_create (hOs);
472981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hQosMngr == NULL)
473981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
474981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
475981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
476981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
477981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
478981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hPowerMgr = PowerMgr_create (hOs);
479981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hPowerMgr == NULL)
480981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
481981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
482981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
483981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
484981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
485981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hSwitchChannel = switchChannel_create (hOs);
486981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSwitchChannel == NULL)
487981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
488981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
489981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
490981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
491981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
492981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hScanMngr = scanMngr_create (hOs);
493981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (NULL == pDrvMain->tStadHandles.hScanMngr)
494981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
495981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
496981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
497981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
498981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
499981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hHealthMonitor = healthMonitor_create (hOs);
500981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (NULL == pDrvMain->tStadHandles.hHealthMonitor)
501981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
502981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
503981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
504981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
505981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
506981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hTWD = TWD_Create (hOs);
507981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTWD == NULL)
508981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
509981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
510981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
511981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
512981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
513653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->tStadHandles.hCmdHndlr = cmdHndlr_Create (hOs, pDrvMain->tStadHandles.hEvHandler);
514981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hCmdHndlr == NULL)
515981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
516981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
517981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
518981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
519981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
520981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hCmdDispatch = cmdDispatch_Create (hOs);
521981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hCmdDispatch == NULL)
522981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
523981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
524981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
525981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
526981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
527981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tStadHandles.hStaCap = StaCap_Create (hOs);
528981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hStaCap == NULL)
529981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
530981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Destroy (pDrvMain);
531981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
532981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
533981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
534981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Bind all modules handles */
535981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_Init ((TI_HANDLE)pDrvMain);
536981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
537981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
538981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Provide required handles to the OAL */
539981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pDrvMainHndl = (TI_HANDLE)pDrvMain;
540981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pCmdHndlr    = pDrvMain->tStadHandles.hCmdHndlr;
541981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pContext     = pDrvMain->tStadHandles.hContext;
542981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pTxDataQ     = pDrvMain->tStadHandles.hTxDataQ;
543981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pTxMgmtQ     = pDrvMain->tStadHandles.hTxMgmtQ;
544981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pTxCtrl      = pDrvMain->tStadHandles.hTxCtrl;
545981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pTwd         = pDrvMain->tStadHandles.hTWD;
546981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pEvHandler   = pDrvMain->tStadHandles.hEvHandler;
547981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
548981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    WLAN_INIT_REPORT (("drvMain_Create: success\n"));
549981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
550981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
551981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
552981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
553981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
554981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_Destroy
555981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Destroy driver
556981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
557981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Destroy all STAD and TWD modules and resources.
558981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
559981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
560981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
561981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK if succeeded, TI_NOK if failed.
562981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     drvMain_Create
563981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
564981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS drvMain_Destroy (TI_HANDLE  hDrvMain)
565981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
566981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain *pDrvMain = (TDrvMain *)hDrvMain;
567981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
568981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    hPlatform_Wlan_Hardware_DeInit ();
569981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
570981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain == NULL)
571981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
572981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
573981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
574981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
575981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hScanMngr != NULL)
576981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
577981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        scanMngr_unload (pDrvMain->tStadHandles.hScanMngr);
578981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
579981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
580981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSiteMgr != NULL)
581981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
582981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        siteMgr_unLoad (pDrvMain->tStadHandles.hSiteMgr);
583981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
584981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
585981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSme != NULL)
586981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
587981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        sme_Destroy (pDrvMain->tStadHandles.hSme);
588981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
589981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
590981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hConn != NULL)
591981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
592981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        conn_unLoad (pDrvMain->tStadHandles.hConn);
593981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
594981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
595981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTWD != NULL)
596981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
597981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TWD_Destroy (pDrvMain->tStadHandles.hTWD);
598981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
599981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
600981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hScanCncn != NULL)
601981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
602981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        scanCncn_Destroy (pDrvMain->tStadHandles.hScanCncn);
603981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
604981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
605981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTrafficMon != NULL)
606981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
607981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TrafficMonitor_Destroy (pDrvMain->tStadHandles.hTrafficMon);
608981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
609981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
610981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hCtrlData != NULL)
611981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
612981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        ctrlData_unLoad (pDrvMain->tStadHandles.hCtrlData);
613981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
614981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
615981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxCtrl != NULL)
616981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
617981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        txCtrl_Unload (pDrvMain->tStadHandles.hTxCtrl);
618981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
619981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
620981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxDataQ != NULL)
621981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
622981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        txDataQ_Destroy (pDrvMain->tStadHandles.hTxDataQ);
623981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
624981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
625981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxMgmtQ != NULL)
626981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
627981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        txMgmtQ_Destroy (pDrvMain->tStadHandles.hTxMgmtQ);
628981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
629981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
630981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTxPort != NULL)
631981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
632981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        txPort_unLoad (pDrvMain->tStadHandles.hTxPort);
633981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
634981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
635981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hRxData != NULL)
636981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
637981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        rxData_unLoad (pDrvMain->tStadHandles.hRxData);
638981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
639981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
640981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hAssoc != NULL)
641981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
642981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        assoc_unload (pDrvMain->tStadHandles.hAssoc);
643981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
644981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
645981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hAuth != NULL)
646981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
647981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        auth_unload (pDrvMain->tStadHandles.hAuth);
648981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
649981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
650981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hMlmeSm != NULL)
651981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
652981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        mlme_unload (pDrvMain->tStadHandles.hMlmeSm);
653981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
654981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
655981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSCR != NULL)
656981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
657981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        scr_release (pDrvMain->tStadHandles.hSCR);
658981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
659981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
660bad6fbebd4588d035d2cde5da6c021200481559aDmitry Shmidt    if (pDrvMain->tStadHandles.hTxnQ != NULL)
661bad6fbebd4588d035d2cde5da6c021200481559aDmitry Shmidt    {
662bad6fbebd4588d035d2cde5da6c021200481559aDmitry Shmidt        txnQ_Destroy (pDrvMain->tStadHandles.hTxnQ);
663bad6fbebd4588d035d2cde5da6c021200481559aDmitry Shmidt    }
664bad6fbebd4588d035d2cde5da6c021200481559aDmitry Shmidt
665981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hRsn != NULL)
666981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
667981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        rsn_unload (pDrvMain->tStadHandles.hRsn);
668981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
669981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
670981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hRegulatoryDomain != NULL)
671981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
672981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        regulatoryDomain_destroy (pDrvMain->tStadHandles.hRegulatoryDomain);
673981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
674981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
675981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hMeasurementMgr != NULL)
676981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
677981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        measurementMgr_destroy (pDrvMain->tStadHandles.hMeasurementMgr);
678981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
679981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
680981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSoftGemini != NULL)
681981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
682981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        SoftGemini_destroy (pDrvMain->tStadHandles.hSoftGemini);
683981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
684981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
685981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef XCC_MODULE_INCLUDED
686981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hXCCMngr != NULL)
687981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
688981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        XCCMngr_unload (pDrvMain->tStadHandles.hXCCMngr);
689981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
690981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
691981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
692981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hRoamingMngr != NULL)
693981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
694981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        roamingMngr_unload (pDrvMain->tStadHandles.hRoamingMngr);
695981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
696981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
697981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hQosMngr != NULL)
698981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
699981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        qosMngr_destroy (pDrvMain->tStadHandles.hQosMngr);
700981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
701981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
702981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hPowerMgr != NULL)
703981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
704981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        PowerMgr_destroy (pDrvMain->tStadHandles.hPowerMgr);
705981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
706981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
707981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hAPConnection != NULL)
708981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
709981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        apConn_unload (pDrvMain->tStadHandles.hAPConnection);
710981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
711981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
712981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hCurrBss != NULL)
713981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
714981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        currBSS_unload (pDrvMain->tStadHandles.hCurrBss);
715981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
716981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
717981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hSwitchChannel != NULL)
718981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
719981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        switchChannel_unload (pDrvMain->tStadHandles.hSwitchChannel);
720981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
721981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
722981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hHealthMonitor != NULL)
723981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
724981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        healthMonitor_unload (pDrvMain->tStadHandles.hHealthMonitor);
725981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
726981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
727653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    if (pDrvMain->tStadHandles.hCmdHndlr && pDrvMain->tStadHandles.hEvHandler)
728653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    {
729653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        cmdHndlr_Destroy (pDrvMain->tStadHandles.hCmdHndlr, pDrvMain->tStadHandles.hEvHandler);
730653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    }
731981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
7325e861de5ad899e72ec6582efb27da588b7583775Dmitry Shmidt    if (pDrvMain->tStadHandles.hEvHandler != NULL)
7335e861de5ad899e72ec6582efb27da588b7583775Dmitry Shmidt    {
7345e861de5ad899e72ec6582efb27da588b7583775Dmitry Shmidt         EvHandlerUnload (pDrvMain->tStadHandles.hEvHandler);
7355e861de5ad899e72ec6582efb27da588b7583775Dmitry Shmidt    }
7365e861de5ad899e72ec6582efb27da588b7583775Dmitry Shmidt
737981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hCmdDispatch)
738981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
739981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        cmdDispatch_Destroy (pDrvMain->tStadHandles.hCmdDispatch);
740981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
741981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
742981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Note: The Timer module must be destroyed last, so all created timers are already destroyed!! */
743981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->tStadHandles.hTimer != NULL)
744981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
745981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        tmr_Destroy (pDrvMain->tStadHandles.hTimer);
746981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
747981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
748981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Destroy the SM watchdog timer */
749981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->hWatchdogTimer != NULL)
750981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
751981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_timerDestroy (pDrvMain->tStadHandles.hOs, pDrvMain->hWatchdogTimer);
752981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
753981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
7544b7f4a460e6745305106cd931a435a9d02f0311dDmitry Shmidt    /* Note: Moved after timers for locks */
7554b7f4a460e6745305106cd931a435a9d02f0311dDmitry Shmidt    if (pDrvMain->tStadHandles.hContext != NULL)
7564b7f4a460e6745305106cd931a435a9d02f0311dDmitry Shmidt    {
7574b7f4a460e6745305106cd931a435a9d02f0311dDmitry Shmidt        context_Destroy (pDrvMain->tStadHandles.hContext);
7584b7f4a460e6745305106cd931a435a9d02f0311dDmitry Shmidt    }
7594b7f4a460e6745305106cd931a435a9d02f0311dDmitry Shmidt
760bad6fbebd4588d035d2cde5da6c021200481559aDmitry Shmidt    if (pDrvMain->tStadHandles.hStaCap != NULL)
761981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
762981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        StaCap_Destroy (pDrvMain->tStadHandles.hStaCap);
763981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
764981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
765653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    if (pDrvMain->tStadHandles.hReport != NULL)
766981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
767981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        report_Unload (pDrvMain->tStadHandles.hReport);
768981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
769981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
770981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Destroy the DrvMain object */
771981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_memoryFree (pDrvMain->tStadHandles.hOs, hDrvMain, sizeof(TDrvMain));
772981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
773981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
774981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
775981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
776981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid drvMain_SmeStop (TI_HANDLE hDrvMain)
777981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
778981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_SmEvent (hDrvMain, SM_EVENT_DISCONNECTED);
779981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
780981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
781981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
782981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
783981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_Init
784981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Init driver modules
785981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
786981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Called from OS context following the driver creation.
787981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Calls all STAD and TWD modules Init functions, which are saving other modules handles,
788981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     registering to other modules and initializing their variables.
789981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
790981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
791981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
792981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
793981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     drvMain_Create
794981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
795981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_Init (TI_HANDLE hDrvMain)
796981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
797981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain    *pDrvMain = (TDrvMain *) hDrvMain;
798981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TStadHandlesList *pModules = &pDrvMain->tStadHandles; /* The STAD modules handles list */
799981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
800981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
801981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  Init all modules handles, variables and registries
802981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
803981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    context_Init (pModules->hContext, pModules->hOs, pModules->hReport);
804981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tmr_Init (pModules->hTimer, pModules->hOs, pModules->hReport, pModules->hContext);
805981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txnQ_Init (pModules->hTxnQ, pModules->hOs, pModules->hReport, pModules->hContext);
806981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scr_init (pModules);
807981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    conn_init (pModules);
808981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ctrlData_init (pModules,
809981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 #ifdef XCC_MODULE_INCLUDED
810981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                   XCCMngr_LinkTestRetriesUpdate, pModules->hXCCMngr);
811981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 #else
812981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                   NULL, NULL);
813981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 #endif
814981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    siteMgr_init (pModules);
815981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    regulatoryDomain_init (pModules);
816981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scanCncn_Init (pModules);
817981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    auth_init (pModules);
818981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    mlme_init (pModules);
819981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    assoc_init (pModules);
820981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    rxData_init (pModules);
821981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txCtrl_Init (pModules);
822981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txDataQ_Init (pModules);
823981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txMgmtQ_Init (pModules);
824981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txPort_init (pModules);
825981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TrafficMonitor_Init (pModules, 1000 /* pInitTable->trafficMonitorMinIntervalPercentage */);
826981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    sme_Init (pModules);
827981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    rsn_init (pModules);
828981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    measurementMgr_init (pModules);
829981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef XCC_MODULE_INCLUDED
830981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    XCCMngr_init (pModules);
831981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
832981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scanMngr_init (pModules);
833981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    currBSS_init (pModules);
834981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    apConn_init (pModules);
835981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    roamingMngr_init (pModules);
836981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    qosMngr_init (pModules);
837981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switchChannel_init (pModules);
838981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    healthMonitor_init (pModules);
839981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PowerMgr_init (pModules);
840981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    SoftGemini_init (pModules);
841981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cmdDispatch_Init (pModules);
842981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    StaCap_Init (pModules);
843981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cmdHndlr_Init (pModules);
844981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
845981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Init TWD component (handles, variables and registries) and provide callbacks for next steps */
846981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TWD_Init (pModules->hTWD,
847981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              pModules->hReport,
848981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              pModules->hDrvMain,
849981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              pModules->hTimer,
850981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              pModules->hContext,
851981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              pModules->hTxnQ,
852981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              (TTwdCallback)drvMain_InitHwCb,
853981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              (TTwdCallback)drvMain_InitFwCb,
854981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              (TTwdCallback)drvMain_ConfigFwCb,
855981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              (TTwdCallback)drvMain_TwdStopCb,
856981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              (TTwdCallback)drvMain_InitFailCb);
857981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
858981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Init DrvMain module local variables */
859981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_InitLocals (pDrvMain);
860981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
861981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
862981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
863981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
864981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_SetDefaults
865981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Set driver default configuration
866981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
867981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Configure all STAD and TWD modules with their default settings from the ini-file.
868981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Timers creation is also done at this stage.
869981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
870981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
871981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
872981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pBuf     - The ini-file data.
873981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  uLength  - The ini-file length.
874981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK if succeeded, TI_NOK if failed.
875981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     drvMain_Init
876981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
877981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS drvMain_SetDefaults (TI_HANDLE hDrvMain, TI_UINT8 *pBuf, TI_UINT32 uLength)
878981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
879981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain   *pDrvMain = (TDrvMain *) hDrvMain;
880981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TInitTable *pInitTable;
881981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS   eStatus;
882981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
883981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pInitTable = os_memoryAlloc (pDrvMain->tStadHandles.hOs, sizeof(TInitTable));
884981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
885981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Parse defaults */
886981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    eStatus = osInitTable_IniFile (pDrvMain->tStadHandles.hOs, pInitTable, (char*)pBuf, (int)uLength);
887981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
888981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
889981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  Configure modules with their default settings
890981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
891981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    report_SetDefaults (pDrvMain->tStadHandles.hReport, &pInitTable->tReport);
892981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    context_SetDefaults (pDrvMain->tStadHandles.hContext, &pInitTable->tContextInitParams);
893981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TWD_SetDefaults (pDrvMain->tStadHandles.hTWD, &pInitTable->twdInitParams);
894981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    conn_SetDefaults (pDrvMain->tStadHandles.hConn, &pInitTable->connInitParams);
895981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ctrlData_SetDefaults (pDrvMain->tStadHandles.hCtrlData, &pInitTable->ctrlDataInitParams);
896981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    siteMgr_SetDefaults (pDrvMain->tStadHandles.hSiteMgr, &pInitTable->siteMgrInitParams);
897981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    regulatoryDomain_SetDefaults (pDrvMain->tStadHandles.hRegulatoryDomain, &pInitTable->regulatoryDomainInitParams);
898981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scanCncn_SetDefaults (pDrvMain->tStadHandles.hScanCncn, &pInitTable->tScanCncnInitParams);
899981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    auth_SetDefaults (pDrvMain->tStadHandles.hAuth, &pInitTable->authInitParams);
900981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    assoc_SetDefaults (pDrvMain->tStadHandles.hAssoc, &pInitTable->assocInitParams);
901981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    rxData_SetDefaults (pDrvMain->tStadHandles.hRxData, &pInitTable->rxDataInitParams);
902981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    sme_SetDefaults (pDrvMain->tStadHandles.hSme, &pInitTable->tSmeModifiedInitParams, &pInitTable->tSmeInitParams);
903981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    rsn_SetDefaults (pDrvMain->tStadHandles.hRsn, &pInitTable->rsnInitParams);
904981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    measurementMgr_SetDefaults (pDrvMain->tStadHandles.hMeasurementMgr, &pInitTable->measurementInitParams);
905981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef XCC_MODULE_INCLUDED
906981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    XCCMngr_SetDefaults (pDrvMain->tStadHandles.hXCCMngr, &pInitTable->XCCMngrParams);
907981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif /*XCC_MODULE_INCLUDED*/
908981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    apConn_SetDefaults (pDrvMain->tStadHandles.hAPConnection, &pInitTable->apConnParams);
909981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    qosMngr_SetDefaults (pDrvMain->tStadHandles.hQosMngr, &pInitTable->qosMngrInitParams);
910981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switchChannel_SetDefaults (pDrvMain->tStadHandles.hSwitchChannel, &pInitTable->SwitchChannelInitParams);
911981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    healthMonitor_SetDefaults (pDrvMain->tStadHandles.hHealthMonitor, &pInitTable->healthMonitorInitParams);
912981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PowerMgr_SetDefaults (pDrvMain->tStadHandles.hPowerMgr, &pInitTable->PowerMgrInitParams);
913981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    SoftGemini_SetDefaults (pDrvMain->tStadHandles.hSoftGemini, &pInitTable->SoftGeminiInitParams);
914981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txDataQ_SetDefaults (pDrvMain->tStadHandles.hTxDataQ, &pInitTable->txDataInitParams);
915981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txCtrl_SetDefaults (pDrvMain->tStadHandles.hTxCtrl, &pInitTable->txDataInitParams);
916981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    currBSS_SetDefaults (pDrvMain->tStadHandles.hCurrBss, &pInitTable->tCurrBssInitParams);
917981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    mlme_SetDefaults (pDrvMain->tStadHandles.hMlmeSm, &pInitTable->tMlmeInitParams);
918981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
919653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    scanMngr_SetDefaults(pDrvMain->tStadHandles.hScanMngr, &pInitTable->tRoamScanMngrInitParams);
920653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    roamingMngr_setDefaults(pDrvMain->tStadHandles.hRoamingMngr, &pInitTable->tRoamScanMngrInitParams);
921653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
922981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Set DrvMain local defaults */
923981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tBusDrvCfg.tSdioCfg.uBlkSizeShift         = pInitTable->tDrvMainParams.uSdioBlkSizeShift;
924981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->tBusDrvCfg.tSdioCfg.uBusDrvThreadPriority = pInitTable->tDrvMainParams.uBusDrvThreadPriority;
925981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_SetDrvThreadPriority (pDrvMain->tStadHandles.hOs, pInitTable->tDrvMainParams.uWlanDrvThreadPriority);
926981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
927981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Release the init table memory */
928981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_memoryFree (pDrvMain->tStadHandles.hOs, pInitTable, sizeof(TInitTable));
929981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
930981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return eStatus;
931981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
932981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
933981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
934981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
935981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_xxx...Cb
936981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Callback functions for the init/stop stages completion
937981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
938981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * The following callback functions are called from other modules (most from TWD)
939981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     when the current init/stop step is completed.
940981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Note that the callbacks are called anyway, either in the original context (if completed), or
941981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     in another context if pending.
942981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * The first case (same context) may lead to a recursion of the SM, so a special handling is added
943981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     to the SM to prevent recursion (see drvMain_Sm).
944981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
945981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_InitHwCb   - HW init completion callback
946981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_InitFwCb   - FW init (mainly download) completion callback
947981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_ConfigFwCb - FW configuration completion callback
948981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_TwdStopCb  - TWD stopping completion callback
949981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_InitFailCb - FW init faulty completion callback
950981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_SmeStopCb  - SME stopping completion callback
951981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_GetFileCb  - Getting-file completion callback
952981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
953981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
954981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
955981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  eStatus  - The process result (TI_OK if succeeded, TI_NOK if failed)
956981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
957981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     drvMain_Create
958981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
959981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InitHwCb (TI_HANDLE hDrvMain, TI_STATUS eStatus)
960981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
961981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    HANDLE_CALLBACKS_FAILURE_STATUS(hDrvMain, eStatus);
962981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_SmEvent (hDrvMain, SM_EVENT_HW_INIT_COMPLETE);
963981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
964981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
965981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InitFwCb (TI_HANDLE hDrvMain, TI_STATUS eStatus)
966981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
967981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    HANDLE_CALLBACKS_FAILURE_STATUS(hDrvMain, eStatus);
968981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_SmEvent (hDrvMain, SM_EVENT_FW_INIT_COMPLETE);
969981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
970981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
971981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_ConfigFwCb (TI_HANDLE hDrvMain, TI_STATUS eStatus)
972981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
973981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    HANDLE_CALLBACKS_FAILURE_STATUS(hDrvMain, eStatus);
974981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_SmEvent (hDrvMain, SM_EVENT_FW_CONFIG_COMPLETE);
975981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
976981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
977981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_TwdStopCb (TI_HANDLE hDrvMain, TI_STATUS eStatus)
978981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
979981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    HANDLE_CALLBACKS_FAILURE_STATUS(hDrvMain, eStatus);
980981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_SmEvent (hDrvMain, SM_EVENT_STOP_COMPLETE);
981981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
982981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
983981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InitFailCb (TI_HANDLE hDrvMain, TI_STATUS eStatus)
984981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
985981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_SmEvent (hDrvMain, SM_EVENT_FAILURE);
986981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
987981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * Note that this call will pass the SM to the FAILED state, since this event
988981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *     is not handled by any state.
989981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
990981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
991981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
992981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InvokeAction (TI_HANDLE hDrvMain)
993981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
994981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain *pDrvMain = (TDrvMain *)hDrvMain;
995981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
996981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switch (pDrvMain->eAction)
997981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
998653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    case ACTION_TYPE_START:
999653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        drvMain_SmEvent (hDrvMain, SM_EVENT_START);
1000653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        break;
1001653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    case ACTION_TYPE_STOP:
1002653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        drvMain_SmEvent (hDrvMain, SM_EVENT_STOP);
1003653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        break;
1004981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        default:
1005981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE1(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR , "drvMain_InvokeAction(): Action=%d\n", pDrvMain->eAction);
1006981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1007981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1008981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1009981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_GetFileCb (TI_HANDLE hDrvMain)
1010981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1011981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain *pDrvMain = (TDrvMain *)hDrvMain;
1012981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ESmEvent  eSmEvent;
1013981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1014981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switch (pDrvMain->tFileInfo.eFileType)
1015981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1016981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case FILE_TYPE_INI:     eSmEvent = SM_EVENT_INI_FILE_READY;    break;
1017981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case FILE_TYPE_NVS:     eSmEvent = SM_EVENT_NVS_FILE_READY;    break;
1018981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case FILE_TYPE_FW:      eSmEvent = SM_EVENT_FW_FILE_READY;     break;
1019981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case FILE_TYPE_FW_NEXT: eSmEvent = SM_EVENT_FW_FILE_READY;     break;
1020981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        default:
1021981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE1(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR , "drvMain_GetFileCb(): Unknown eFileType=%d\n", pDrvMain->tFileInfo.eFileType);
1022981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return;
1023981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1024981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_SmEvent (hDrvMain, eSmEvent);
1025981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1026981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1027981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1028981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1029981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_InitLocals
1030981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Init DrvMain module
1031981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1032981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Init the DrvMain variables, register to other modules and set device power to off.
1033981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1034981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1035981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pDrvMain - The DrvMain object
1036981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
1037981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     drvMain_Init
1038981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1039981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_InitLocals (TDrvMain *pDrvMain)
1040981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1041653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    /* Initialize the module's local varniables to default values */
1042653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->tFileInfo.eFileType   = FILE_TYPE_INI;
1043653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->tFileInfo.fCbFunc     = drvMain_GetFileCb;
1044653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->tFileInfo.hCbHndl     = (TI_HANDLE)pDrvMain;
1045653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->eSmState              = SM_STATE_IDLE;
1046653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->uPendingEventsCount   = 0;
1047653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->bRecovery             = TI_FALSE;
1048653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->eAction               = ACTION_TYPE_NONE;
1049653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
1050653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    /* Register the Action callback to the context engine and get the client ID */
1051653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->uContextId = context_RegisterClient (pDrvMain->tStadHandles.hContext,
1052981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                                   drvMain_InvokeAction,
1053981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                                   (TI_HANDLE)pDrvMain,
1054981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                                   TI_TRUE,
1055981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                                   "ACTION",
1056981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                                   sizeof("ACTION"));
1057981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1058653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    /* Platform specific HW preparations */
105912d754a18612383f03b960dfad4dbcaba72df370Dmitry Shmidt	hPlatform_Wlan_Hardware_Init(pDrvMain->tStadHandles.hOs);
1060981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1061653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    /* Insure that device power is off (expected to be) */
1062653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    hPlatform_DevicePowerOff ();
1063981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1064981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1065981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1066981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1067981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_InitHw & drvMain_InitFw
1068981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Init HW and Init FW sequences
1069981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1070981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_InitHw - HW init sequence which writes and reads some HW registers
1071981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      that are needed prior to FW download.
1072981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * drvMain_InitFw - FW init sequence which downloads the FW image and waits for
1073981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      FW init-complete indication.
1074981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1075981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1076981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
1077981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pBuf     - The file data (NVS for HW-init, FW-Image for FW-init).
1078981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  uLength  - The file length.
1079981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK if succeeded, TI_NOK if failed.
1080981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
1081981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1082981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS drvMain_InitHw (TI_HANDLE hDrvMain, TI_UINT8 *pbuf, TI_UINT32 uLength)
1083981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1084981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain   *pDrvMain = (TDrvMain *) hDrvMain;
1085981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1086981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TWD_InitHw (pDrvMain->tStadHandles.hTWD, pbuf, uLength);
1087981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1088981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1089981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS drvMain_InitFw (TI_HANDLE hDrvMain, TFileInfo *pFileInfo)
1090981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1091981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain   *pDrvMain = (TDrvMain *) hDrvMain;
1092981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1093981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TWD_InitFw (pDrvMain->tStadHandles.hTWD, pFileInfo);
1094981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1095981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1096981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1097981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1098981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_ConfigFw
1099981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Configure the FW
1100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * The step that follows the FW Init (mainly FW download).
1102981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * The Command-Mailbox interface is enabled here and the FW is configured.
1103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1104981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pDrvMain - The DrvMain object
1106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK
1107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     drvMain_Init
1108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS drvMain_ConfigFw (TI_HANDLE hDrvMain)
1110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain    *pDrvMain = (TDrvMain *) hDrvMain;
1112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* get pointer to FW static info (already in driver memory) */
1114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TFwInfo     *pFwInfo  = TWD_GetFWInfo (pDrvMain->tStadHandles.hTWD);
1115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8    *pMacAddr = (TI_UINT8 *)pFwInfo->macAddress; /* STA MAC address */
1116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Update driver's MAC address */
1118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    wlanDrvIf_SetMacAddress (pDrvMain->tStadHandles.hOs, pMacAddr);
1119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1120981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
1121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  Exit from init mode should be before smeSM starts. this enable us to send
1122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  command to the MboxQueue(that store the command) while the interrupts are masked.
1123981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  the interrupt would be enable at the end of the init process.
1124981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
1125981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TWD_ExitFromInitMode (pDrvMain->tStadHandles.hTWD);
1126981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1127981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Configure the FW from the TWD DB */
1128981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TWD_ConfigFw (pDrvMain->tStadHandles.hTWD);
1129981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TRACE0(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_INIT , "EXIT FROM INIT\n");
1131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Print the driver and firmware version and the mac address */
1133bfca3da19996ce011eb0db38690f93e21ad2495aDmitry Shmidt    os_printf("\n");
1134bfca3da19996ce011eb0db38690f93e21ad2495aDmitry Shmidt    os_printf("-----------------------------------------------------\n");
1135bfca3da19996ce011eb0db38690f93e21ad2495aDmitry Shmidt    os_printf("Driver Version  : %s\n", SW_VERSION_STR);
1136bfca3da19996ce011eb0db38690f93e21ad2495aDmitry Shmidt    os_printf("Firmware Version: %s\n", pFwInfo->fwVer);
1137bfca3da19996ce011eb0db38690f93e21ad2495aDmitry Shmidt    os_printf("Station ID      : %02X-%02X-%02X-%02X-%02X-%02X\n",
1138bfca3da19996ce011eb0db38690f93e21ad2495aDmitry Shmidt              pMacAddr[0], pMacAddr[1], pMacAddr[2], pMacAddr[3], pMacAddr[4], pMacAddr[5]);
1139bfca3da19996ce011eb0db38690f93e21ad2495aDmitry Shmidt    os_printf("-----------------------------------------------------\n");
1140bfca3da19996ce011eb0db38690f93e21ad2495aDmitry Shmidt    os_printf("\n");
1141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
1143981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1144981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1145981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1146981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1147981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_StopActivities
1148981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Freeze driver activities
1149981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1150981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Freeze all driver activities due to stop command or recovery process.
1151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pDrvMain - The DrvMain object
1154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK if succeeded, TI_NOK if failed.
1155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     drvMain_EnableActivities
1156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS drvMain_StopActivities (TDrvMain *pDrvMain)
1158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txPort_suspendTx (pDrvMain->tStadHandles.hTxPort);
1160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Disable External Inputs (IRQs and commands) */
1162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TWD_DisableInterrupts(pDrvMain->tStadHandles.hTWD);
1163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cmdHndlr_Disable (pDrvMain->tStadHandles.hCmdHndlr);
1164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Initiate TWD Restart */
1166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TWD_Stop (pDrvMain->tStadHandles.hTWD);
1167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1171981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_EnableActivities
1172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Enable driver activities
1173981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1174981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Enable driver activities after init or recovery process completion.
1175981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1176981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1177981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pDrvMain - The DrvMain object
1178981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
1179981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     drvMain_StopActivities
1180981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1181981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_EnableActivities (TDrvMain *pDrvMain)
1182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1183981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txPort_resumeTx (pDrvMain->tStadHandles.hTxPort);
1184981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1185981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt   /* Enable External Inputs (IRQ is enabled elsewhere) */
1186981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cmdHndlr_Enable (pDrvMain->tStadHandles.hCmdHndlr);
1187981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1188981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Enable external events from FW */
1189981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TWD_EnableExternalEvents (pDrvMain->tStadHandles.hTWD);
1190981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1191981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1192981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1193981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1194981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1195981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1196981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_ClearQueuedEvents
1197981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Enable driver activities
1198981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1199981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Clear all external events queues (Tx, commands and timers) upon driver stop.
1200981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1201981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1202981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pDrvMain - The DrvMain object
1203981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
1204981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
1205981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1206981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_ClearQueuedEvents (TDrvMain *pDrvMain)
1207981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1208981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txDataQ_ClearQueues (pDrvMain->tStadHandles.hTxDataQ);
1209981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txMgmtQ_ClearQueues (pDrvMain->tStadHandles.hTxMgmtQ);
1210981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cmdHndlr_ClearQueue (pDrvMain->tStadHandles.hCmdHndlr);
1211981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tmr_ClearOperQueue (pDrvMain->tStadHandles.hTimer);
1212981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1213981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1214981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1215981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1216981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_InsertAction
1217981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Get start/stop action and trigger handling
1218981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1219981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Get start or stop action command from OAL, save it and trigger driver task
1220981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     for handling it.
1221981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Wait on a signal object until the requested process is completed.
1222981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1223981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1224981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
1225981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  eAction  - The requested action
1226981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
1227981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
1228981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1229981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS drvMain_InsertAction (TI_HANDLE hDrvMain, EActionType eAction)
1230981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1231981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain *pDrvMain = (TDrvMain *) hDrvMain;
1232981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
123304635cee59642c3439608797ad2351ab37ca2840Dmitry Shmidt    context_EnterCriticalSection(pDrvMain->tStadHandles.hContext);
1234981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->eAction == eAction)
123504635cee59642c3439608797ad2351ab37ca2840Dmitry Shmidt    {
123604635cee59642c3439608797ad2351ab37ca2840Dmitry Shmidt        context_LeaveCriticalSection(pDrvMain->tStadHandles.hContext);
1237981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_CONSOLE, "Action is identical to last action!\n");
1238b9c472e425a823df929150475a9f340ad4decca3Dmitry Shmidt        WLAN_OS_REPORT(("Action %d is identical to last action!\n", eAction));
1239981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
1240981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1241981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1242981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Save the requested action */
1243981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->eAction = eAction;
124404635cee59642c3439608797ad2351ab37ca2840Dmitry Shmidt    context_LeaveCriticalSection(pDrvMain->tStadHandles.hContext);
1245981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1246981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Create signal object */
1247981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
1248981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * Notice that we must create the signal object before asking for ReSchedule,
1249981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * because we might receive it immidiatly, and then we will be in a different context
1250981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * with null signal object.
1251981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
1252653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    pDrvMain->hSignalObj = os_SignalObjectCreate (pDrvMain->tStadHandles.hOs);
1253981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->hSignalObj == NULL)
1254981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1255981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR , "drvMain_InsertAction(): Couldn't allocate signal object!\n");
1256981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
1257981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1258981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1259981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Request driver task schedule for action handling */
1260981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    context_RequestSchedule (pDrvMain->tStadHandles.hContext, pDrvMain->uContextId);
1261981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1262981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Wait for the action processing completion */
1263653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    os_SignalObjectWait (pDrvMain->tStadHandles.hOs, pDrvMain->hSignalObj);
1264981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1265653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    /* After "wait" - the action has already been processed in the driver's context */
1266981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1267653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    /* Free signalling object */
1268653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    os_SignalObjectFree (pDrvMain->tStadHandles.hOs, pDrvMain->hSignalObj);
126909dfaca5ecb53aec34a69fe9ebc2fe31e49bd4d9Dmitry Shmidt    pDrvMain->hSignalObj = NULL;
1270981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1271981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->eSmState == SM_STATE_FAILED)
1272981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_NOK;
1273981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1274981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
1275981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1276981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1277981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1278981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1279981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_Recovery
1280981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Initiate recovery process
1281981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1282981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Initiate recovery process upon HW/FW error detection (in the Health-Monitor).
1283981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1284981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1285981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
1286981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK if started recovery, TI_NOK if recovery is already in progress.
1287981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
1288981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1289981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS drvMain_Recovery (TI_HANDLE hDrvMain)
1290981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1291981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain         *pDrvMain = (TDrvMain *) hDrvMain;
1292981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1293981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!pDrvMain->bRecovery)
1294981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1295981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE1(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_CONSOLE,".....drvMain_Recovery, ts=%d\n", os_timeStampMs(pDrvMain->tStadHandles.hOs));
129609dfaca5ecb53aec34a69fe9ebc2fe31e49bd4d9Dmitry Shmidt#ifdef REPORT_LOG
1297981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        WLAN_OS_REPORT((".....drvMain_Recovery, ts=%d\n", os_timeStampMs(pDrvMain->tStadHandles.hOs)));
129809dfaca5ecb53aec34a69fe9ebc2fe31e49bd4d9Dmitry Shmidt#else
129909dfaca5ecb53aec34a69fe9ebc2fe31e49bd4d9Dmitry Shmidt        printk("%s\n",__func__);
130009dfaca5ecb53aec34a69fe9ebc2fe31e49bd4d9Dmitry Shmidt#endif
1301981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pDrvMain->bRecovery = TI_TRUE;
1302981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_SmEvent (hDrvMain, SM_EVENT_RECOVERY);
1303981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_OK;
1304981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1305981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
1306981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1307981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR, "drvMain_Recovery: ****  Recovery already in progress!  ****\n");
1308981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
1309981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1310981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1311981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1312981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1313981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1314981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_RecoveryNotify
1315981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Notify STAD modules about recovery
1316981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1317981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Notify the relevant STAD modules that recovery took place (after completed).
1318981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1319981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1320981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pDrvMain - The DrvMain object
1321981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
1322981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
1323981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1324981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_RecoveryNotify (TDrvMain *pDrvMain)
1325981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1326981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    txCtrl_NotifyFwReset (pDrvMain->tStadHandles.hTxCtrl);
1327981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scr_notifyFWReset (pDrvMain->tStadHandles.hSCR);
1328981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PowerMgr_notifyFWReset (pDrvMain->tStadHandles.hPowerMgr);
1329981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1330981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TRACE1(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_CONSOLE, ".....drvMain_RecoveryNotify: End Of Recovery, ts=%d\n", os_timeStampMs(pDrvMain->tStadHandles.hOs));
1331981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    WLAN_OS_REPORT((".....drvMain_RecoveryNotify: End Of Recovery, ts=%d\n", os_timeStampMs(pDrvMain->tStadHandles.hOs)));
1332981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1333981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1334981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1335981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1336981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_SmWatchdogTimeout
1337981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  SM watchdog timer expiry handler
1338981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1339981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * This is the callback function called upon expiartion of the watchdog timer.
1340981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * It is called by the OS-API in timer expiry context, and it issues a failure event to the SM.
1341981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Note that we can't switch to the driver task as for other timers, since we are using
1342981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     this timer to protect the init processes, and anyway we just need to stop the driver.
1343981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1344981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
1345981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
1346981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
1347981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
1348981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1349981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1350981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#if 0
1351981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_SmWatchdogTimeout (TI_HANDLE hDrvMain)
1352981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1353981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain *pDrvMain = (TDrvMain *)hDrvMain;
1354981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1355981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TRACE1(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR , "drvMain_SmWatchdogTimeout():  State = %d\n", pDrvMain->eSmState);
1356981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1357981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Send failure event directly to the SM (so the drvMain_SmEvent won't block it).  */
1358981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1359981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    drvMain_Sm ((TI_HANDLE)pDrvMain, SM_EVENT_FAILURE);
1360981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1361981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
1362981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1363981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1364981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_SmEvent
1365981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Issue DrvMain SM event
1366981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1367981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Each event that is handled by the DrvMain state machine, is introduced through this function.
1368981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * To prevent SM recursion, the SM is invoeked only if it's not already handling the
1369981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *      previous event.
1370981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * If the SM is busy, the current event is saved until the previous handling is completed.
1371981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1372981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note   Recursion may happen because some SM activities generate SM events in the same context.
1373981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
1374981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  eEvent   - The event issued to the SM
1375981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
1376981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
1377981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1378981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_SmEvent (TI_HANDLE hDrvMain, ESmEvent eEvent)
1379981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1380981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain *pDrvMain = (TDrvMain *)hDrvMain;
1381981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1382981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Increment pending events counter and save last event. */
1383981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->uPendingEventsCount++;
1384981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pDrvMain->ePendingEvent = eEvent;
1385981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1386981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* If the SM is busy, save event and exit (will be handled when current event is finished) */
1387981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pDrvMain->uPendingEventsCount > 1)
1388981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1389981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Only one pending event is expected (in addition to the handled one, so two together). */
1390981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (pDrvMain->uPendingEventsCount > 2)
1391981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1392981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE3(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR , "drvMain_SmEvent():  Multiple pending events (%d), State = %d, Event = %d\n", pDrvMain->uPendingEventsCount, pDrvMain->eSmState, eEvent);
1393981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1394981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1395981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Exit. The current event will be handled by the following while loop of the first instance. */
1396981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return;
1397981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1398981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1399981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Invoke the SM with the current event and further events issued by the last SM invocation. */
1400981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while (pDrvMain->uPendingEventsCount > 0)
1401981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1402981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_Sm (hDrvMain, pDrvMain->ePendingEvent);
1403981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1404981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1405981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Note: The SM may issue another event by calling this function and incrementing
1406981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *           the counter.
1407981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *       In this case, only the upper part of this function is run, and the pending
1408981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *           event is hanlded in the next while loo[.
1409981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1410981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1411981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pDrvMain->uPendingEventsCount--;
1412981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1413981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1414981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1415981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1416981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
1417981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     drvMain_Sm
1418981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  The DrvMain state machine
1419981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1420981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * The DrvMain state machine, which handles all driver init, recovery and stop processes.
1421981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1422981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note   Since the SM may be called back from its own context, recursion is prevented
1423981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *             by postponing the last event.
1424981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hDrvMain - The DrvMain object
1425981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  eEvent   - The event that triggers the SM
1426981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
1427981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
1428981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
1429981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void drvMain_Sm (TI_HANDLE hDrvMain, ESmEvent eEvent)
1430981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1431981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TDrvMain    *pDrvMain   = (TDrvMain *)hDrvMain;
1432981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS    eStatus    = TI_NOK;
1433981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE    hOs        = pDrvMain->tStadHandles.hOs;
1434653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    TI_UINT32    uSdioConIndex = 0;
1435981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1436981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TRACE2(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_INFORMATION , "drvMain_Sm():  State = %d, Event = %d\n", pDrvMain->eSmState, eEvent);
1437981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1438981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
1439981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  General explenations:
1440981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  =====================
1441981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  1) This SM calls some functions that may complete their processing in another context.
1442981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *     All of these functions (wlanDrvIf_GetFile, drvMain_InitHw, drvMain_InitFw, drvMain_ConfigFw,
1443981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *         drvMain_StopActivities, smeSm_start, smeSm_stop) are provided with a callback which
1444981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *         they always call upon completion, even if they are completed in the original (SM) context.
1445981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *     Since these callbacks are calling the SM, a simple mechanism is added to prevent
1446981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *         recursion, by postponing the last event if the SM is still in the previous event's context.
1447981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  2) In any case of unexpected event, the eStatus remains TI_NOK, leading to the FAILED state!
1448981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *     FAILED state is also reached if any of the functions listed in note 1 returns TI_NOK.
1449981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *     Note that if these functions detect a failure in another context, they may call their callback
1450981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *         with the eStatus parameter set to TI_NOK, or call the drvMain_InitFailCb callback.
1451981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *     All these cases lead to FAILED state which terminates all driver activities and wait for destroy.
1452981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  3) Note that the wlanDrvIf_GetFile is always completed in the original context, and the
1453981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *         option of completion in a later context is only for future use.
1454981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *  4) All processes (Start, Stop, Relcovery) are protected by a watchdog timer to let
1455981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     *         the user free the driver in case of deadlock during the process.
1456981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
1457981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1458981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switch (pDrvMain->eSmState)
1459981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1460981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_IDLE:
1461981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1462981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * We get a START action after all modules are created and linked.
1463981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Disable further actions, start watchdog timer and request for the ini-file.
1464981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1465981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (eEvent == SM_EVENT_START)
1466981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1467981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* return thr timer later on */
1468981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*os_timerStart (hOs, pDrvMain->hWatchdogTimer, SM_WATCHDOG_TIME_MS);*/
1469981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_WAIT_INI_FILE;
1470981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            context_DisableClient (pDrvMain->tStadHandles.hContext, pDrvMain->uContextId);
1471981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->tFileInfo.eFileType = FILE_TYPE_INI;
1472981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = wlanDrvIf_GetFile (hOs, &pDrvMain->tFileInfo);
1473981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1474981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1475981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_WAIT_INI_FILE:
1476981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1477981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * We've got the ini-file.
1478981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Set STAD and TWD modules defaults according to the ini-file,
1479981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *     turn on the device and request for the NVS file.
1480981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1481981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (eEvent == SM_EVENT_INI_FILE_READY)
1482981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1483981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_WAIT_NVS_FILE;
1484981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            drvMain_SetDefaults (hDrvMain, pDrvMain->tFileInfo.pBuffer, pDrvMain->tFileInfo.uLength);
1485981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            hPlatform_DevicePowerOn ();
1486981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1487981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->tFileInfo.eFileType = FILE_TYPE_NVS;
1488981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = wlanDrvIf_GetFile (hOs, &pDrvMain->tFileInfo);
1489981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1490981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1491981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1492981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_WAIT_NVS_FILE:
1493981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1494653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        /* SDBus Connect connection validation  */
1495653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        for(uSdioConIndex=0; (uSdioConIndex < SDIO_CONNECT_THRESHOLD) && (eStatus != TI_OK); uSdioConIndex++)
1496981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1497653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			/* : We should split the call to txnQ_ConnectBus to other state in order to support Async bus connection */
1498653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            eStatus = txnQ_ConnectBus(pDrvMain->tStadHandles.hTxnQ, &pDrvMain->tBusDrvCfg, NULL, NULL);
1499653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
1500653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			if((eStatus != TI_OK) &&
1501653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			   (uSdioConIndex < (SDIO_CONNECT_THRESHOLD - 1)))
1502653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            {
1503653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                     TRACE0(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_WARNING , "SDBus Connect Failed\n");
1504653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                     WLAN_OS_REPORT(("Try to SDBus Connect again...\n"));
1505653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                     if (uSdioConIndex > 1)
1506653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt						hPlatform_DevicePowerOffSetLongerDelay();
1507653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt					 else
1508653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt						hPlatform_DevicePowerOff();
1509653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                     hPlatform_DevicePowerOn();
1510653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            }
1511981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1512981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1513653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt		if(eStatus != TI_OK)
1514653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt		{
1515653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			WLAN_OS_REPORT(("SDBus Connect Failed, Set Object Event !!\r\n"));
1516653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			TRACE0(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR , "SDBus Connect Failed, Set Object Event !!\r\n");
1517b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt			if (!pDrvMain->bRecovery)
1518b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt			{
1519b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt				os_SignalObjectSet(hOs, pDrvMain->hSignalObj);
1520b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt			}
1521b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt                        else
1522b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt			{
1523b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt				/* in case recovery fails, stop the sme which will send disassociation event to os */
1524b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt				sme_Stop(pDrvMain->tStadHandles.hSme);
1525b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt			}
1526653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt		}
1527653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt		else /* SDBus Connect success */
1528981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1529653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            /*
1530653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             * We've got the NVS file.
1531653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             * Start HW-Init process providing the NVS file.
1532653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             */
1533653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			if (eEvent == SM_EVENT_NVS_FILE_READY)
1534653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            {
1535653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                pDrvMain->eSmState = SM_STATE_HW_INIT;
1536653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                eStatus = drvMain_InitHw (hDrvMain, pDrvMain->tFileInfo.pBuffer, pDrvMain->tFileInfo.uLength);
1537653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            }
1538981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1539981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1540981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_HW_INIT:
1541b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        /*
1542981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * HW-Init process is completed.
1543981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Request for the FW image file.
1544981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1545b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        if (eEvent == SM_EVENT_HW_INIT_COMPLETE)
1546981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1547981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->tFileInfo.eFileType = FILE_TYPE_FW;
1548981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_DOWNLOAD_FW_FILE;
1549981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = wlanDrvIf_GetFile (hOs, &pDrvMain->tFileInfo);
1550981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1551981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1552653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    case SM_STATE_DOWNLOAD_FW_FILE:
1553b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        if (eEvent == SM_EVENT_FW_FILE_READY)
1554981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1555653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pDrvMain->tFileInfo.eFileType = FILE_TYPE_FW_NEXT;
1556653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            if (pDrvMain->tFileInfo.bLast == TI_TRUE)
1557653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            {
1558981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_FW_INIT;
1559653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            }
1560653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            else
1561653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            {
1562653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                pDrvMain->eSmState = SM_STATE_WAIT_FW_FILE;
1563653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            }
1564653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            /*
1565653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             * We've got the FW image file.
1566653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             * Start FW-Init process (mainly FW image download) providing the FW image file.
1567653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             */
1568653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            eStatus = drvMain_InitFw (hDrvMain, &pDrvMain->tFileInfo);
1569653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        }
1570653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        break;
1571981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_WAIT_FW_FILE:
1572b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        if (eEvent == SM_EVENT_FW_INIT_COMPLETE)
1573981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1574653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pDrvMain->eSmState = SM_STATE_DOWNLOAD_FW_FILE;
1575653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            eStatus = wlanDrvIf_GetFile (hOs, &pDrvMain->tFileInfo);
1576981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1577981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1578981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_FW_INIT:
1579b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        /*
1580981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * FW-Init process is completed.
1581981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Free the semaphore of the START action to enable the OS interface.
1582981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Enable interrupts (or polling for debug).
1583981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Start FW-Configuration process, and free the semaphore of the START action.
1584981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *
1585981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Note that in some OSs, the semaphore must be released in order to enable the
1586981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *     interrupts, and the interrupts are needed for the configuration process!
1587981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1588b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        if (eEvent == SM_EVENT_FW_INIT_COMPLETE)
1589981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1590981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_FW_CONFIG;
1591981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TWD_EnableInterrupts(pDrvMain->tStadHandles.hTWD);
1592981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          #ifdef PRIODIC_INTERRUPT
1593981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Start periodic interrupts. It means that every period of time the FwEvent SM will be called */
1594981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_periodicIntrTimerStart (hOs);
1595981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          #endif
1596981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = drvMain_ConfigFw (hDrvMain);
1597981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1598981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1599981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_FW_CONFIG:
1600b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        /*
1601981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * FW-configuration process is completed.
1602981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Stop watchdog timer.
1603981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * For recovery, notify the relevant STAD modules.
1604981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * For regular start, start the SME which handles the connection process.
1605981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Update timer and OAL about entering OPERATIONAL state (OAL ignores recovery)
1606981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Enable driver activities and external events.
1607981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Enable STOP action
1608981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * We are now in OPERATIONAL state, i.e. the driver is fully operational!
1609981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1610981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1611981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (eEvent == SM_EVENT_FW_CONFIG_COMPLETE)
1612981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1613981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_OPERATIONAL;
1614981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* return thr timer later on */
1615981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*os_timerStop (hOs, pDrvMain->hWatchdogTimer);*/
1616981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pDrvMain->bRecovery)
1617981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1618981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                drvMain_RecoveryNotify (pDrvMain);
1619981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pDrvMain->bRecovery = TI_FALSE;
1620981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1621981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1622981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1623981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                sme_Start (pDrvMain->tStadHandles.hSme);
1624981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                wlanDrvIf_UpdateDriverState (hOs, DRV_STATE_RUNNING);
1625981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1626981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            tmr_UpdateDriverState (pDrvMain->tStadHandles.hTimer, TI_TRUE);
1627981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            drvMain_EnableActivities (pDrvMain);
1628981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            context_EnableClient (pDrvMain->tStadHandles.hContext, pDrvMain->uContextId);
1629981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = TI_OK;
1630981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1631981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
163213a774123712fc5ce1e4033292ffc631c00b3ea5Dmitry Shmidt        if (!pDrvMain->bRecovery)
163313a774123712fc5ce1e4033292ffc631c00b3ea5Dmitry Shmidt        {
163413a774123712fc5ce1e4033292ffc631c00b3ea5Dmitry Shmidt            os_SignalObjectSet(hOs, pDrvMain->hSignalObj);
163513a774123712fc5ce1e4033292ffc631c00b3ea5Dmitry Shmidt        }
1636981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1637981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_OPERATIONAL:
1638981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1639981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Disable start/stop commands and start watchdog timer.
1640981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Update timer and OAL about exiting OPERATIONAL state (OAL ignores recovery).
1641981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * For STOP, stop SME (handle disconnection) and move to DISCONNECTING state.
1642981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * For recovery, stop driver activities and move to STOPPING state.
1643981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Note that driver-stop process may be Async if we are during Async bus transaction.
1644981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1645981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1646981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        context_DisableClient (pDrvMain->tStadHandles.hContext, pDrvMain->uContextId);
1647981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* return thr timer later on */
1648981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*os_timerStart (hOs, pDrvMain->hWatchdogTimer, SM_WATCHDOG_TIME_MS);*/
1649981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        tmr_UpdateDriverState (pDrvMain->tStadHandles.hTimer, TI_FALSE);
1650981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (eEvent == SM_EVENT_STOP)
1651981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1652981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_DISCONNECTING;
1653981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            wlanDrvIf_UpdateDriverState (hOs, DRV_STATE_STOPING);
1654981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            sme_Stop (pDrvMain->tStadHandles.hSme);
1655981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = TI_OK;
1656981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1657981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else if (eEvent == SM_EVENT_RECOVERY)
1658981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1659981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_STOPPING;
1660981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = drvMain_StopActivities (pDrvMain);
1661981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1662981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1663981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1664981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_DISCONNECTING:
1665981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1666981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Note that this state is not relevant for recovery.
1667981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * SME stop is completed
1668981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Stop driver activities and move to STOPPING state.
1669981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Note that driver stop process may be Async if we are during Async bus transaction.
1670981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1671981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1672981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (eEvent == SM_EVENT_DISCONNECTED)
1673981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1674981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_STOPPING;
1675981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = drvMain_StopActivities (pDrvMain);
1676981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1677981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1678981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_STOPPING:
1679981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1680981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Driver stopping process is done.
1681981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Turn device power off.
1682981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * For recovery, turn device power back on, request NVS file and continue with
1683981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *     the init process (recover back all the way to OPERATIONAL state).
1684981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * For STOP process, the driver is now fully stopped (STOPPED state), so stop watchdog timer,
1685981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *     clear all events queues, free the semaphore of the STOP action and enable START action.
1686981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1687981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1688981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (eEvent == SM_EVENT_STOP_COMPLETE)
1689981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1690981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            txnQ_DisconnectBus (pDrvMain->tStadHandles.hTxnQ);
1691981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            hPlatform_DevicePowerOff ();
1692981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pDrvMain->bRecovery)
1693981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1694981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                hPlatform_DevicePowerOn ();
1695981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pDrvMain->eSmState = SM_STATE_WAIT_NVS_FILE;
1696981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pDrvMain->tFileInfo.eFileType = FILE_TYPE_NVS;
1697981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                eStatus = wlanDrvIf_GetFile (hOs, &pDrvMain->tFileInfo);
1698981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1699981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1700981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1701981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pDrvMain->eSmState = SM_STATE_STOPPED;
1702981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* return thr timer later on */
1703981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /*os_timerStop (hOs, pDrvMain->hWatchdogTimer);*/
1704981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                drvMain_ClearQueuedEvents (pDrvMain);
1705653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                scr_notifyFWReset(pDrvMain->tStadHandles.hSCR);
1706981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_SignalObjectSet (hOs, pDrvMain->hSignalObj);
1707981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                context_EnableClient (pDrvMain->tStadHandles.hContext, pDrvMain->uContextId);
1708981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                wlanDrvIf_UpdateDriverState (hOs, DRV_STATE_STOPPED);
1709981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                eStatus = TI_OK;
1710981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1711981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1712981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1713981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1714981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_STOPPED:
1715981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1716981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * A START action command was inserted, so we go through the init process.
1717981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Disable further actions, start watchdog timer, turn on device and request NVS file.
1718981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1719981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1720981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        context_DisableClient (pDrvMain->tStadHandles.hContext, pDrvMain->uContextId);
1721981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* return thr timer later on */
1722981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*os_timerStart (hOs, pDrvMain->hWatchdogTimer, SM_WATCHDOG_TIME_MS);*/
1723981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (eEvent == SM_EVENT_START)
1724981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1725981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            hPlatform_DevicePowerOn ();
1726981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->eSmState = SM_STATE_WAIT_NVS_FILE;
1727981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pDrvMain->tFileInfo.eFileType = FILE_TYPE_NVS;
1728981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            eStatus = wlanDrvIf_GetFile (hOs, &pDrvMain->tFileInfo);
1729981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1730981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1731981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_STOPPING_ON_FAIL:
1732981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1733981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Driver stopping process upon failure is completed.
1734981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Turn off the device and move to FAILED state.
1735981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1736981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1737981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pDrvMain->eSmState = SM_STATE_FAILED;
1738981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        txnQ_DisconnectBus (pDrvMain->tStadHandles.hTxnQ);
1739981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        hPlatform_DevicePowerOff ();
1740981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        WLAN_OS_REPORT(("[WLAN] Exit application\n"));
1741b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        if (!pDrvMain->bRecovery)
1742b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        {
1743b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt            os_SignalObjectSet (hOs, pDrvMain->hSignalObj);
1744b1c7adde70f3a7dd380758004b9d274dc9abe9eaDmitry Shmidt        }
1745981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1746981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case SM_STATE_FAILED:
1747981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Nothing to do except waiting for Destroy */
1748981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1749981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt default:
1750981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE2(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR , "drvMain_Sm: Unknown state, eEvent=%u at state=%u\n", eEvent, pDrvMain->eSmState);
1751981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Note: Handled below as a failure since the status remains TI_NOK */
1752981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        break;
1753981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1754981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1755981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Handle failures (status = NOK) if not handled yet */
1756981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ((eStatus == TI_NOK) &&
1757981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        (pDrvMain->eSmState != SM_STATE_FAILED) &&
1758981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        (pDrvMain->eSmState != SM_STATE_STOPPING_ON_FAIL))
1759981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1760981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE3(pDrvMain->tStadHandles.hReport, REPORT_SEVERITY_ERROR , "drvMain_Sm: eEvent=%u at state=%u, status=%d\n", eEvent, pDrvMain->eSmState, eStatus);
1761981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pDrvMain->eSmState = SM_STATE_STOPPING_ON_FAIL;
1762981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        wlanDrvIf_UpdateDriverState (hOs, DRV_STATE_FAILED);
1763981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1764981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1765981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Stop all activities. This may be completed in a different context if
1766981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *     we should wait for an Async bus transaction completion.
1767981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * The drvMain_TwdStopCb is called from the TWD in any case to pass
1768981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *     us to the SM_STATE_FAILED state (where we wait for Destroy).
1769981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1770981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        eStatus = drvMain_StopActivities (pDrvMain);
1771981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1772981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1773