1/*
2 * TWDriver.c
3 *
4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 *  * Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *  * Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in
15 *    the documentation and/or other materials provided with the
16 *    distribution.
17 *  * Neither the name Texas Instruments nor the names of its
18 *    contributors may be used to endorse or promote products derived
19 *    from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35/** \file  TWDriver.c
36 *  \brief TI WLAN Hardware Access Driver
37 *
38 *  \see   TWDriver.h
39 */
40
41#define __FILE_ID__  FILE_ID_117
42#include "report.h"
43#include "TWDriver.h"
44#include "MacServices_api.h"
45#include "txCtrlBlk_api.h"
46#include "txHwQueue_api.h"
47#include "txXfer_api.h"
48#include "txResult_api.h"
49#include "rxXfer_api.h"
50#include "TwIf.h"
51#include "FwEvent_api.h"
52#include "CmdMBox_api.h"
53#include "CmdQueue_api.h"
54#include "eventMbox_api.h"
55#include "fwDebug_api.h"
56#include "osApi.h"
57#include "TWDriverInternal.h"
58#include "HwInit_api.h"
59#include "CmdBld.h"
60#include "RxQueue_api.h"
61
62/* remove the chipID check when WL6-PG1.0 becomes obsolete (temporary global variable!!) */
63extern TI_BOOL bChipIs1273Pg10;
64void TWD_CheckSRConfigParams(TTwd  *pTWD, ACXSmartReflexConfigParams_t *tSmartReflexParams);
65
66
67#define TWD_CB_MODULE_OWNER_MASK    0xff00
68#define TWD_CB_TYPE_MASK            0x00ff
69
70
71
72
73TI_HANDLE TWD_Create (TI_HANDLE hOs)
74{
75    TTwd *pTWD;
76
77    /* Allocate the TNETW_Driver module */
78    pTWD = (TTwd *)os_memoryAlloc (hOs, sizeof(TTwd));
79    if (pTWD == NULL)
80    {
81        return NULL;
82    }
83
84    os_memoryZero (hOs, pTWD, sizeof(TTwd));
85
86    pTWD->hOs = hOs;
87
88    /* Create TwIf module */
89    pTWD->hTwIf = twIf_Create (hOs);
90    if (pTWD->hTwIf == NULL)
91    {
92        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"twIf_Create failed\n");
93        WLAN_OS_REPORT(("twIf_Create failed\n"));
94        TWD_Destroy ((TI_HANDLE)pTWD);
95        return NULL;
96    }
97
98    /* Create command builder module */
99    pTWD->hCmdBld = cmdBld_Create (hOs);
100    if (pTWD->hCmdBld == NULL)
101    {
102        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"cmdBld_Create failed\n");
103        WLAN_OS_REPORT(("cmdBld_Create failed\n"));
104        TWD_Destroy ((TI_HANDLE)pTWD);
105        return NULL;
106    }
107
108    /* Create the MAC Services module */
109    pTWD->hMacServices = MacServices_create (hOs);
110    if (pTWD->hMacServices == NULL)
111    {
112        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD MacServices_create failed!!!\n");
113        WLAN_OS_REPORT(("TWD MacServices_create failed!!!\n"));
114        TWD_Destroy ((TI_HANDLE)pTWD);
115        return NULL;
116    }
117
118    /* Create the Ctrl module */
119    pTWD->hCmdQueue = cmdQueue_Create (hOs);
120    if (pTWD->hCmdQueue == NULL)
121    {
122        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD cmdQueue_Create failed!!!\n");
123        WLAN_OS_REPORT(("TWD cmdQueue_Create failed!!!\n"));
124        TWD_Destroy ((TI_HANDLE)pTWD);
125        return NULL;
126    }
127
128    /*
129     * Create the FW-Transfer modules:
130     */
131
132    pTWD->hTxXfer = txXfer_Create (hOs);
133    if (pTWD->hTxXfer == NULL)
134    {
135        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD txXfer_Create failed!!!\n");
136        WLAN_OS_REPORT(("TWD txXfer_Create failed!!!\n"));
137        TWD_Destroy ((TI_HANDLE)pTWD);
138        return NULL;
139    }
140
141    pTWD->hTxResult = txResult_Create (hOs);
142    if (pTWD->hTxResult == NULL)
143    {
144        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD txResult_Create failed!!!\n");
145        WLAN_OS_REPORT(("TWD txResult_Create failed!!!\n"));
146        TWD_Destroy ((TI_HANDLE)pTWD);
147        return NULL;
148    }
149
150    pTWD->hRxXfer = rxXfer_Create (hOs);
151    if (pTWD->hRxXfer == NULL)
152    {
153        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD rxXfer_Create failed!!!\n");
154        WLAN_OS_REPORT(("TWD rxXfer_Create failed!!!\n"));
155        TWD_Destroy ((TI_HANDLE)pTWD);
156        return NULL;
157    }
158
159    pTWD->hFwEvent = fwEvent_Create (hOs);
160    if (pTWD->hFwEvent == NULL)
161    {
162        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD fwEvent_Create failed!!!\n");
163        WLAN_OS_REPORT(("TWD fwEvent_Create failed!!!\n"));
164        TWD_Destroy ((TI_HANDLE)pTWD);
165        return NULL;
166    }
167
168    pTWD->hEventMbox = eventMbox_Create (hOs);
169    if (pTWD->hEventMbox == NULL)
170    {
171        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD eventMbox_Create failed!!!\n");
172        WLAN_OS_REPORT(("TWD eventMbox_Create failed!!!\n"));
173        TWD_Destroy ((TI_HANDLE)pTWD);
174        return NULL;
175    }
176
177#ifdef TI_DBG
178    pTWD->hFwDbg = fwDbg_Create (hOs);
179    if (pTWD->hFwDbg == NULL)
180    {
181        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD fwDbg_Create failed!!!\n");
182        WLAN_OS_REPORT(("TWD fwDbg_Create failed!!!\n"));
183        TWD_Destroy ((TI_HANDLE)pTWD);
184        return NULL;
185    }
186#endif /* TI_DBG */
187
188    pTWD->hCmdMbox = cmdMbox_Create (hOs);
189    if (pTWD->hCmdMbox == NULL)
190    {
191        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD cmdMbox_Create failed!!!\n");
192        WLAN_OS_REPORT(("TWD cmdMbox_Create failed!!!\n"));
193        TWD_Destroy ((TI_HANDLE)pTWD);
194        return NULL;
195    }
196
197    pTWD->hRxQueue = RxQueue_Create (hOs);
198    if (pTWD->hRxQueue == NULL)
199    {
200        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD RxQueue_Create failed!!!\n");
201        WLAN_OS_REPORT(("TWD RxQueue_Create failed!!!\n"));
202        TWD_Destroy ((TI_HANDLE)pTWD);
203        return NULL;
204    }
205
206
207    /*
208     * Create the Data-Services modules:
209     */
210
211    pTWD->hTxCtrlBlk = txCtrlBlk_Create (hOs);
212    if (pTWD->hTxCtrlBlk == NULL)
213    {
214        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD txCtrlBlk_Create failed!!!\n");
215        WLAN_OS_REPORT(("TWD txCtrlBlk_Create failed!!!\n"));
216        TWD_Destroy ((TI_HANDLE)pTWD);
217        return NULL;
218    }
219
220    pTWD->hTxHwQueue = txHwQueue_Create (hOs);
221    if (pTWD->hTxHwQueue == NULL)
222    {
223        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD txHwQueue_Create failed!!!\n");
224        WLAN_OS_REPORT(("TWD txHwQueue_Create failed!!!\n"));
225        TWD_Destroy ((TI_HANDLE)pTWD);
226        return NULL;
227    }
228
229    pTWD->hHwInit = hwInit_Create (hOs);
230    if (pTWD->hHwInit == NULL)
231    {
232        TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"wInit_Create failed!\n");
233        WLAN_OS_REPORT (("wInit_Create failed!\n"));
234        TWD_Destroy ((TI_HANDLE)pTWD);
235        return NULL;
236    }
237
238    WLAN_INIT_REPORT (("TWD_Create: CREATED !!!\n"));
239
240    return (TI_HANDLE)pTWD;
241}
242
243TI_STATUS TWD_Destroy (TI_HANDLE hTWD)
244{
245    TTwd *pTWD = (TTwd *)hTWD;
246
247    WLAN_INIT_REPORT(("TWD_Destroy: called\n"));
248    if (pTWD == NULL)
249    {
250        return TI_NOK;
251    }
252
253    if (pTWD->hTwIf != NULL)
254    {
255        twIf_Destroy (pTWD->hTwIf);
256        pTWD->hTwIf = NULL;
257    }
258
259    /* Free the Command Builder */
260    if (pTWD->hCmdBld != NULL)
261    {
262        cmdBld_Destroy (pTWD->hCmdBld);
263        pTWD->hCmdBld = NULL;
264    }
265    WLAN_INIT_REPORT(("TWD_Destroy: Command Builder released\n"));
266
267    /* Free the MAC Services */
268    if (pTWD->hMacServices != NULL)
269    {
270        MacServices_destroy(pTWD->hMacServices);
271        pTWD->hMacServices = NULL;
272    }
273    WLAN_INIT_REPORT(("TWD_Destroy: Mac Services released\n"));
274
275    /*
276     * Free the Ctrl modules
277     */
278    if (pTWD->hCmdQueue != NULL)
279    {
280        cmdQueue_Destroy(pTWD->hCmdQueue);
281        pTWD->hCmdQueue = NULL;
282    }
283
284    /*
285     * Free the FW-Transfer modules:
286     */
287    if (pTWD->hTxXfer != NULL)
288    {
289        txXfer_Destroy (pTWD->hTxXfer);
290        pTWD->hTxXfer = NULL;
291    }
292
293    if (pTWD->hTxResult != NULL)
294    {
295        txResult_Destroy (pTWD->hTxResult);
296        pTWD->hTxResult = NULL;
297    }
298
299    if (pTWD->hRxXfer != NULL)
300    {
301        rxXfer_Destroy (pTWD->hRxXfer);
302        pTWD->hRxXfer = NULL;
303    }
304
305    if (pTWD->hEventMbox != NULL)
306    {
307        eventMbox_Destroy (pTWD->hEventMbox);
308        pTWD->hEventMbox = NULL;
309    }
310
311#ifdef TI_DBG
312    if (pTWD->hFwDbg != NULL)
313    {
314        fwDbg_Destroy (pTWD->hFwDbg);
315        pTWD->hFwDbg = NULL;
316    }
317#endif /* TI_DBG */
318
319    if (pTWD->hFwEvent != NULL)
320    {
321        fwEvent_Destroy (pTWD->hFwEvent);
322        pTWD->hFwEvent = NULL;
323    }
324
325    if (pTWD->hCmdMbox != NULL)
326    {
327        cmdMbox_Destroy (pTWD->hCmdMbox);
328        pTWD->hCmdMbox = NULL;
329    }
330
331    if (pTWD->hRxQueue != NULL)
332    {
333        RxQueue_Destroy (pTWD->hRxQueue);
334		pTWD->hRxQueue = NULL;
335    }
336
337    /*
338     * Free the Data-Services modules:
339     */
340
341    if (pTWD->hTxCtrlBlk != NULL)
342    {
343        txCtrlBlk_Destroy (pTWD->hTxCtrlBlk);
344        pTWD->hTxCtrlBlk = NULL;
345    }
346
347    if (pTWD->hTxHwQueue != NULL)
348    {
349        txHwQueue_Destroy (pTWD->hTxHwQueue);
350        pTWD->hTxHwQueue = NULL;
351    }
352
353    if (pTWD->hHwInit != NULL)
354    {
355        hwInit_Destroy (pTWD->hHwInit);
356        pTWD->hHwInit = NULL;
357    }
358
359    os_memoryFree (pTWD->hOs, (TI_HANDLE)pTWD, sizeof(TTwd));
360
361    WLAN_INIT_REPORT(("TWD_Destroy pTNETW_Driver released!!!\n"));
362
363    return TI_OK;
364}
365
366
367/**
368 * \brief HW Init Callback
369 *
370 * \param  hTWD         - TWD module object handle
371 * \return void
372 *
373 * \par Description
374 * Static CB function
375 * Called during TWD Module Init by hwInit_Init in order to complete the HW Configuration init
376 *
377 * \sa     TWD_InitHw
378 */
379static void TWD_InitHwCb (TI_HANDLE hTWD)
380{
381    TTwd *pTWD = (TTwd *)hTWD;
382
383    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_InitHwCb: call fInitHwCb CB. In std drvMain_InitHwCb()\n");
384
385    hwInit_InitPolarity(pTWD->hHwInit);
386
387}
388
389void TWD_Init (TI_HANDLE    hTWD,
390			   TI_HANDLE 	hReport,
391               TI_HANDLE 	hUser,
392			   TI_HANDLE 	hTimer,
393			   TI_HANDLE 	hContext,
394			   TI_HANDLE 	hTxnQ,
395               TTwdCallback fInitHwCb,
396               TTwdCallback fInitFwCb,
397               TTwdCallback fConfigFwCb,
398			   TTwdCallback	fStopCb,
399			   TTwdCallback fInitFailCb)
400{
401    TTwd *pTWD 				= (TTwd *)hTWD;
402    pTWD->bInitSuccess 		= TI_FALSE;
403    pTWD->bRecoveryEnabled 	= TI_FALSE;
404    pTWD->hReport           = hReport;
405    pTWD->hUser 			= hUser;
406    pTWD->hTimer            = hTimer;
407    pTWD->hContext          = hContext;
408    pTWD->hTxnQ             = hTxnQ;
409    pTWD->fInitHwCb 		= fInitHwCb;
410    pTWD->fInitFwCb 		= fInitFwCb;
411    pTWD->fConfigFwCb 		= fConfigFwCb;
412    pTWD->fStopCb 			= fStopCb;
413    pTWD->fInitFailCb       = fInitFailCb;
414
415    TRACE1(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_Init: %x\n", hTWD);
416
417    /* FwEvent should be configured first */
418    fwEvent_Init (pTWD->hFwEvent, hTWD);
419
420    eventMbox_Config (pTWD->hEventMbox, pTWD->hTwIf, pTWD->hReport, pTWD->hFwEvent, pTWD->hCmdBld);
421
422    cmdQueue_Init (pTWD->hCmdQueue,
423                     pTWD->hCmdMbox,
424                     pTWD->hReport,
425                     pTWD->hTwIf,
426                     pTWD->hTimer);
427
428    /* Configure Command Builder */
429    cmdBld_Config (pTWD->hCmdBld,
430                   pTWD->hReport,
431                   (void *)TWD_FinalizeDownload,
432                   hTWD,
433                   pTWD->hEventMbox,
434                   pTWD->hCmdQueue,
435                   pTWD->hTwIf);
436
437    hwInit_Init (pTWD->hHwInit,
438                   pTWD->hReport,
439                   hTWD,
440	               hTWD,
441		           (TFinalizeCb)TWD_FinalizeDownload,
442                   TWD_InitHwCb);
443
444    /*
445     * Initialize the FW-Transfer modules
446     */
447    txXfer_Init (pTWD->hTxXfer, pTWD->hReport, pTWD->hTwIf);
448
449    txResult_Init (pTWD->hTxResult, pTWD->hReport, pTWD->hTwIf);
450
451    rxXfer_Init (pTWD->hRxXfer, pTWD->hFwEvent, pTWD->hReport, pTWD->hTwIf, pTWD->hRxQueue);
452
453    RxQueue_Init (pTWD->hRxQueue, pTWD->hReport);
454
455  #ifdef TI_DBG
456    fwDbg_Init (pTWD->hFwDbg, pTWD->hReport, pTWD->hTwIf);
457  #endif /* TI_DBG */
458
459    /* Initialize the MAC Services */
460    MacServices_init (pTWD->hMacServices,
461                      pTWD->hReport,
462                      hTWD,
463                      pTWD->hCmdBld,
464                      pTWD->hEventMbox,
465                      pTWD->hTimer);
466
467    /*
468     * Initialize the Data-Services modules
469     */
470    txCtrlBlk_Init (pTWD->hTxCtrlBlk, pTWD->hReport, pTWD->hContext);
471    txHwQueue_Init (pTWD->hTxHwQueue, pTWD->hReport);
472
473    /* Initialize the TwIf module */
474    twIf_Init (pTWD->hTwIf, pTWD->hReport, pTWD->hContext, pTWD->hTxnQ, (TRecoveryCb)TWD_StopComplete, hTWD);
475}
476
477 TI_STATUS TWD_InitHw (TI_HANDLE hTWD,
478					  TI_UINT8 *pbuf,
479					  TI_UINT32 length)
480{
481    TTwd *pTWD = (TTwd *)hTWD;
482    TI_STATUS eStatus;
483
484    TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_InitHw: called\n");
485
486    hwInit_SetNvsImage (pTWD->hHwInit, pbuf, length);
487
488    /*
489     * Update the TwIf that the HW is awake
490     * This will protect the initialization process from going to sleep
491     * After the firmware initializations completed (TWD_EnableExternalEvents), the sleep will be enabled
492     */
493    twIf_Awake (pTWD->hTwIf);
494    twIf_HwAvailable (pTWD->hTwIf);
495
496    /* This initiates the HW init sequence */
497    eStatus = hwInit_Boot(pTWD->hHwInit);
498    if (eStatus == TXN_STATUS_ERROR)
499    {
500        TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR , "TWD_InitHw: hwInit_Boot failed\n");
501        return TI_NOK;
502    }
503
504    return TI_OK;
505}
506
507TI_STATUS TWD_BusOpen (TI_HANDLE hTWD, void* pParams)
508{
509	TTwd *pTWD = (TTwd *)hTWD;
510	TI_STATUS uStatus;
511
512    TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_BusOpen: called\n");
513
514    /*uStatus = TNETWIF_Open(pTWD->hTNETWIF, pParams);*/
515    uStatus = TI_OK;
516
517	return uStatus;
518}
519
520TI_STATUS TWD_BusClose (TI_HANDLE hTWD)
521{
522	TTwd *pTWD = (TTwd *)hTWD;
523	TI_STATUS uStatus;
524
525    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_BusClose: called\n");
526
527	/*uStatus = TNETWIF_Close(pTWD->hTNETWIF);*/
528    uStatus = TI_OK;
529
530	return uStatus;
531}
532
533TI_STATUS TWD_InitFw (TI_HANDLE hTWD, TFileInfo *pFileInfo)
534{
535    TTwd *pTWD = (TTwd *)hTWD;
536    TI_STATUS status;
537
538    /* check Parameters */
539    if (( pTWD == NULL ) || ( pFileInfo == NULL ))
540    {
541        return (TI_NOK);
542    }
543
544	TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_InitFw: called\n");
545
546    hwInit_SetFwImage (pTWD->hHwInit, pFileInfo);
547
548    /* This will initiate the download to the FW */
549    status = hwInit_LoadFw(pTWD->hHwInit);
550
551    if (status == TXN_STATUS_ERROR)
552    {
553        TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR , "TWD_InitFw: failed to initialize FW\n");
554
555        return TI_NOK;
556    }
557
558    return TI_OK;
559}
560
561/**
562 * \brief  Propagate interrogate results
563 *
564 * \param  hTWD         - TWD module object handle
565 * \param  status       - callback status
566 * \return TI_OK on success or TI_NOK on failure
567 *
568 * \par Description
569 * Static CB function
570 * Propagate interrogate results between TX and RX modules
571 * Called by TWD_ConfigFw
572 *
573 * \sa
574 */
575static TI_STATUS TWD_ConfigFwCb (TI_HANDLE hTWD, TI_STATUS status)
576{
577    TTwd        *pTWD = (TTwd *)hTWD;
578    TDmaParams  *pDmaParams = &DB_DMA(pTWD->hCmdBld);
579
580    /*
581     * Store the addresses of the cyclic buffer (Rx/Tx)
582     * and the path status and control (Tx/Rx) in the corresponding modules
583     */
584    txResult_setHwInfo (pTWD->hTxResult, pDmaParams);
585
586    RxXfer_ReStart (pTWD->hRxXfer, bChipIs1273Pg10);
587    txXfer_Restart (pTWD->hTxXfer, bChipIs1273Pg10);
588
589    rxXfer_SetRxDirectAccessParams (pTWD->hRxXfer, pDmaParams);
590
591    /* Provide number of HW Tx-blocks and descriptors to Tx-HW-Queue module */
592    txHwQueue_SetHwInfo (pTWD->hTxHwQueue, pDmaParams);
593
594    /* If the configure complete function was registered, we call it here - end of TWD_Configure stage */
595    if (pTWD->fConfigFwCb)
596    {
597        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_ConfigFwCb: call TWD_OWNER_SELF_CONFIG CB. In std drvMain_ConfigFwCb()\n");
598
599        pTWD->fConfigFwCb (pTWD->hUser, TI_OK);
600    }
601
602    return TI_OK;
603}
604
605
606TI_STATUS TWD_SetDefaults (TI_HANDLE hTWD, TTwdInitParams *pInitParams)
607{
608    TTwd         *pTWD = (TTwd *)hTWD;
609
610    TWlanParams         *pWlanParams = &DB_WLAN(pTWD->hCmdBld);
611    TKeepAliveList      *pKlvParams = &DB_KLV(pTWD->hCmdBld);
612    IniFileRadioParam   *pRadioParams = &DB_RADIO(pTWD->hCmdBld);
613    IniFileGeneralParam *pGenParams = &DB_GEN(pTWD->hCmdBld);
614    TSmartReflexParams  *pSmartReflex = &DB_SR(pTWD->hCmdBld);
615	TRateMngParams      *pRateMngParams = &DB_RM(pTWD->hCmdBld);
616
617    TI_UINT32            k, uIndex;
618    int iParam;
619
620    TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_SetDefaults: called\n");
621
622    pTWD->bRecoveryEnabled = pInitParams->tGeneral.halCtrlRecoveryEnable;
623
624    pWlanParams->PacketDetectionThreshold   = pInitParams->tGeneral.packetDetectionThreshold;
625    pWlanParams->qosNullDataTemplateSize    = pInitParams->tGeneral.qosNullDataTemplateSize;
626    pWlanParams->PsPollTemplateSize         = pInitParams->tGeneral.PsPollTemplateSize;
627    pWlanParams->probeResponseTemplateSize  = pInitParams->tGeneral.probeResponseTemplateSize;
628    pWlanParams->probeRequestTemplateSize   = pInitParams->tGeneral.probeRequestTemplateSize;
629    pWlanParams->beaconTemplateSize         = pInitParams->tGeneral.beaconTemplateSize;
630    pWlanParams->nullTemplateSize           = pInitParams->tGeneral.nullTemplateSize;
631    pWlanParams->disconnTemplateSize        = pInitParams->tGeneral.disconnTemplateSize;
632    /* Beacon broadcast options */
633    pWlanParams->BcnBrcOptions.BeaconRxTimeout      = pInitParams->tGeneral.BeaconRxTimeout;
634    pWlanParams->BcnBrcOptions.BroadcastRxTimeout   = pInitParams->tGeneral.BroadcastRxTimeout;
635    pWlanParams->BcnBrcOptions.RxBroadcastInPs      = pInitParams->tGeneral.RxBroadcastInPs;
636    pWlanParams->ConsecutivePsPollDeliveryFailureThreshold = pInitParams->tGeneral.ConsecutivePsPollDeliveryFailureThreshold;
637
638    pWlanParams->RxDisableBroadcast         = pInitParams->tGeneral.halCtrlRxDisableBroadcast;
639    pWlanParams->calibrationChannel2_4      = pInitParams->tGeneral.halCtrlCalibrationChannel2_4;
640    pWlanParams->calibrationChannel5_0      = pInitParams->tGeneral.halCtrlCalibrationChannel5_0;
641
642    /* Not used but need by Palau */
643    pWlanParams->RtsThreshold               = pInitParams->tGeneral.halCtrlRtsThreshold;
644    pWlanParams->CtsToSelf                  = CTS_TO_SELF_DISABLE;
645
646    pWlanParams->WiFiWmmPS                  = pInitParams->tGeneral.WiFiWmmPS;
647
648    pWlanParams->MaxTxMsduLifetime          = pInitParams->tGeneral.halCtrlMaxTxMsduLifetime;
649    pWlanParams->MaxRxMsduLifetime          = pInitParams->tGeneral.halCtrlMaxRxMsduLifetime;
650
651    pWlanParams->rxTimeOut.psPoll           = pInitParams->tGeneral.rxTimeOut.psPoll;
652    pWlanParams->rxTimeOut.UPSD             = pInitParams->tGeneral.rxTimeOut.UPSD;
653
654    /* RSSI/SNR Weights for Average calculations */
655    pWlanParams->tRssiSnrWeights.rssiBeaconAverageWeight = pInitParams->tGeneral.uRssiBeaconAverageWeight;
656    pWlanParams->tRssiSnrWeights.rssiPacketAverageWeight = pInitParams->tGeneral.uRssiPacketAverageWeight;
657    pWlanParams->tRssiSnrWeights.snrBeaconAverageWeight  = pInitParams->tGeneral.uSnrBeaconAverageWeight ;
658    pWlanParams->tRssiSnrWeights.snrPacketAverageWeight  = pInitParams->tGeneral.uSnrPacketAverageWeight ;
659
660    /* PM config params */
661    pWlanParams->uHostClkSettlingTime       = pInitParams->tGeneral.uHostClkSettlingTime;
662    pWlanParams->uHostFastWakeupSupport     = pInitParams->tGeneral.uHostFastWakeupSupport;
663
664    /* No used */
665    pWlanParams->FragmentThreshold          = pInitParams->tGeneral.halCtrlFragThreshold;
666    pWlanParams->ListenInterval             = (TI_UINT8)pInitParams->tGeneral.halCtrlListenInterval;
667    pWlanParams->RateFallback               = pInitParams->tGeneral.halCtrlRateFallbackRetry;
668    pWlanParams->MacClock                   = pInitParams->tGeneral.halCtrlMacClock;
669    pWlanParams->ArmClock                   = pInitParams->tGeneral.halCtrlArmClock;
670
671    /* Data interrupts pacing */
672    pWlanParams->TxCompletePacingThreshold  = pInitParams->tGeneral.TxCompletePacingThreshold;
673    pWlanParams->TxCompletePacingTimeout    = pInitParams->tGeneral.TxCompletePacingTimeout;
674    pWlanParams->RxIntrPacingThreshold      = pInitParams->tGeneral.RxIntrPacingThreshold;
675    pWlanParams->RxIntrPacingTimeout        = pInitParams->tGeneral.RxIntrPacingTimeout;
676
677    /* Configure ARP IP */
678
679    pWlanParams->isArpIpFilteringEnabled    = pInitParams->tArpIpFilter.isFilterEnabled;
680    IP_COPY (pWlanParams->arp_IP_addr, pInitParams->tArpIpFilter.addr);
681
682    /* Configure address group */
683    pWlanParams->numGroupAddrs = pInitParams->tMacAddrFilter.numOfMacAddresses;
684    pWlanParams->isMacAddrFilteringnabled = pInitParams->tMacAddrFilter.isFilterEnabled;
685
686    for (k = 0; k < pWlanParams->numGroupAddrs; k++)
687    {
688        MAC_COPY (pWlanParams->aGroupAddr[k], pInitParams->tMacAddrFilter.macAddrTable[k]);
689    }
690
691
692    /* CoexActivity Table */
693    TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_SetDefaults: coex numOfElements %d\n", pInitParams->tGeneral.halCoexActivityTable.numOfElements);
694
695    pWlanParams->tWlanParamsCoexActivityTable.numOfElements = 0;
696    for (iParam=0; iParam < (int)pInitParams->tGeneral.halCoexActivityTable.numOfElements; iParam++)
697    {
698        TCoexActivity *pSaveCoex = &pWlanParams->tWlanParamsCoexActivityTable.entry[0];
699        TCoexActivity *pParmCoex = &pInitParams->tGeneral.halCoexActivityTable.entry[0];
700        int i, saveIndex;
701
702        /* Check if to overwrite existing entry or put on last index */
703        for (i=0; i<iParam; i++)
704        {
705            if ((pSaveCoex[i].activityId == pParmCoex[iParam].activityId) && (pSaveCoex[i].coexIp == pParmCoex[iParam].coexIp))
706            {
707                break;
708            }
709        }
710
711        if (i == iParam)
712        {
713            /* new entry */
714            saveIndex = pWlanParams->tWlanParamsCoexActivityTable.numOfElements;
715            pWlanParams->tWlanParamsCoexActivityTable.numOfElements++;
716        }
717        else
718        {
719            /* overwrite existing */
720            saveIndex = i;
721        }
722
723        TRACE4(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_SetDefaults: save coex Param %d in index %d, %d %d\n", iParam, saveIndex, pParmCoex[iParam].coexIp, pParmCoex[iParam].activityId);
724
725        pSaveCoex[saveIndex].coexIp          = pParmCoex[iParam].coexIp;
726        pSaveCoex[saveIndex].activityId      = pParmCoex[iParam].activityId;
727        pSaveCoex[saveIndex].defaultPriority = pParmCoex[iParam].defaultPriority;
728        pSaveCoex[saveIndex].raisedPriority  = pParmCoex[iParam].raisedPriority;
729        pSaveCoex[saveIndex].minService      = pParmCoex[iParam].minService;
730        pSaveCoex[saveIndex].maxService      = pParmCoex[iParam].maxService;
731    }
732
733    /* configure keep-alive default mode to enabled */
734    pKlvParams->enaDisFlag = TI_TRUE;
735    for (uIndex = 0; uIndex < KLV_MAX_TMPL_NUM; uIndex++)
736    {
737        pKlvParams->keepAliveParams[ uIndex ].enaDisFlag = TI_FALSE;
738    }
739
740    /* Configure the RxXfer module */
741    rxXfer_SetDefaults (pTWD->hRxXfer, pInitParams);
742
743    /* Configure the Tx-HW-Queue module */
744    txHwQueue_Config (pTWD->hTxHwQueue, pInitParams);
745
746    /* Configure the MAC services */
747    MacServices_config (pTWD->hMacServices, pInitParams);
748
749    /*
750     * 802.11n
751     */
752    pWlanParams->tTwdHtCapabilities.b11nEnable =            pInitParams->tGeneral.b11nEnable;
753    /* Configure HT capabilities setting */
754    pWlanParams->tTwdHtCapabilities.uChannelWidth =         CHANNEL_WIDTH_20MHZ;
755    pWlanParams->tTwdHtCapabilities.uRxSTBC =               RXSTBC_SUPPORTED_ONE_SPATIAL_STREAM;
756    pWlanParams->tTwdHtCapabilities.uMaxAMSDU =             MAX_MSDU_3839_OCTETS;
757    pWlanParams->tTwdHtCapabilities.uMaxAMPDU =             MAX_MPDU_8191_OCTETS;
758    pWlanParams->tTwdHtCapabilities.uAMPDUSpacing =         AMPDU_SPC_8_MICROSECONDS;
759    pWlanParams->tTwdHtCapabilities.aRxMCS[0] =             (MCS_SUPPORT_MCS_0 |
760                                                             MCS_SUPPORT_MCS_1 |
761                                                             MCS_SUPPORT_MCS_2 |
762                                                             MCS_SUPPORT_MCS_3 |
763                                                             MCS_SUPPORT_MCS_4 |
764                                                             MCS_SUPPORT_MCS_5 |
765                                                             MCS_SUPPORT_MCS_6 |
766                                                             MCS_SUPPORT_MCS_7);
767    os_memoryZero (pTWD->hOs, pWlanParams->tTwdHtCapabilities.aRxMCS + 1, RX_TX_MCS_BITMASK_SIZE - 1);
768    pWlanParams->tTwdHtCapabilities.aTxMCS[0]  =             (MCS_SUPPORT_MCS_0 |
769                                                              MCS_SUPPORT_MCS_1 |
770                                                              MCS_SUPPORT_MCS_2 |
771                                                              MCS_SUPPORT_MCS_3 |
772                                                              MCS_SUPPORT_MCS_4 |
773                                                              MCS_SUPPORT_MCS_5 |
774                                                              MCS_SUPPORT_MCS_6 |
775                                                              MCS_SUPPORT_MCS_7);
776    os_memoryZero (pTWD->hOs, pWlanParams->tTwdHtCapabilities.aTxMCS + 1, RX_TX_MCS_BITMASK_SIZE - 1);
777    pWlanParams->tTwdHtCapabilities.uRxMaxDataRate =         MCS_HIGHEST_SUPPORTED_RECEPTION_DATA_RATE_IN_MBIT_S;
778    pWlanParams->tTwdHtCapabilities.uPCOTransTime =          PCO_TRANS_TIME_NO_TRANSITION;
779    pWlanParams->tTwdHtCapabilities.uHTCapabilitiesBitMask = (CAP_BIT_MASK_GREENFIELD_FRAME_FORMAT |
780                                                              CAP_BIT_MASK_SHORT_GI_FOR_20MHZ_PACKETS);
781    pWlanParams->tTwdHtCapabilities.uMCSFeedback =           MCS_FEEDBACK_NO;
782
783    os_memoryCopy(pTWD->hOs, (void*)pRadioParams, (void*)&pInitParams->tIniFileRadioParams, sizeof(IniFileRadioParam));
784    os_memoryCopy(pTWD->hOs, (void*)pGenParams, (void*)&pInitParams->tPlatformGenParams, sizeof(IniFileGeneralParam));
785
786    os_memoryCopy (pTWD->hOs,
787                   (void*)&(pWlanParams->tFmCoexParams),
788                   (void*)&(pInitParams->tGeneral.tFmCoexParams),
789                   sizeof(TFmCoexParams));
790
791    pSmartReflex->tSmartReflexState = pInitParams ->tSmartReflexState;
792    os_memoryCopy(pTWD->hOs, (void*)&pSmartReflex->tSmartReflexParams, (void*)&pInitParams->tSmartReflexParams, sizeof(ACXSmartReflexConfigParams_t));
793    os_memoryCopy(pTWD->hOs, (void*)&pSmartReflex->tSmartReflexDebugParams, (void*)&pInitParams->tSmartReflexDebugParams, sizeof(ACXSmartReflexDebugParams_t));
794
795
796	/* Rate management params */
797	pRateMngParams->rateMngParams.InverseCuriosityFactor = pInitParams->tRateMngParams.InverseCuriosityFactor;
798	pRateMngParams->rateMngParams.MaxPer = pInitParams->tRateMngParams.MaxPer;
799	pRateMngParams->rateMngParams.PerAdd = pInitParams->tRateMngParams.PerAdd;
800	pRateMngParams->rateMngParams.PerAddShift = pInitParams->tRateMngParams.PerAddShift;
801	pRateMngParams->rateMngParams.PerAlphaShift = pInitParams->tRateMngParams.PerAlphaShift;
802	pRateMngParams->rateMngParams.PerBeta1Shift = pInitParams->tRateMngParams.PerBeta1Shift;
803	pRateMngParams->rateMngParams.PerBeta2Shift = pInitParams->tRateMngParams.PerBeta2Shift;
804	pRateMngParams->rateMngParams.PerTh1 = pInitParams->tRateMngParams.PerTh1;
805	pRateMngParams->rateMngParams.PerTh2 = pInitParams->tRateMngParams.PerTh2;
806	pRateMngParams->rateMngParams.RateCheckDown = pInitParams->tRateMngParams.RateCheckDown;
807	pRateMngParams->rateMngParams.RateCheckUp = pInitParams->tRateMngParams.RateCheckUp;
808	pRateMngParams->rateMngParams.RateRetryScore = pInitParams->tRateMngParams.RateRetryScore;
809	pRateMngParams->rateMngParams.TxFailHighTh = pInitParams->tRateMngParams.TxFailHighTh;
810	pRateMngParams->rateMngParams.TxFailLowTh = pInitParams->tRateMngParams.TxFailLowTh;
811
812	/* RATE_MNG_MAX_RETRY_POLICY_PARAMS_LEN */
813	for (uIndex = 0; uIndex < 13; uIndex++)
814	{
815        pRateMngParams->rateMngParams.RateRetryPolicy[uIndex] = pInitParams->tRateMngParams.RateRetryPolicy[uIndex];
816	}
817
818    return TI_OK;
819}
820
821TI_STATUS TWD_ConfigFw (TI_HANDLE hTWD)
822{
823    TTwd *pTWD = (TTwd *)hTWD;
824
825    TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_ConfigFw: called\n");
826
827    /*
828     * Configure the WLAN firmware after config all the hardware objects
829     */
830    if (cmdBld_ConfigFw (pTWD->hCmdBld, (void *)TWD_ConfigFwCb, hTWD) != TI_OK)
831    {
832        return TI_NOK;
833    }
834
835    return TI_OK;
836}
837
838void TWD_FinalizeDownload (TI_HANDLE hTWD)
839{
840    TTwd *pTWD = (TTwd *)hTWD;
841
842    TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_FinalizeDownload: called\n");
843
844	if ( pTWD == NULL )
845	{
846		return;
847	}
848    /* Here at the end call the Initialize Complete callback that will release the user Init semaphore */
849    TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT, "Before sending the Init Complet callback !!!!!\n");
850
851    /* Sign that init has succeeded */
852    pTWD->bInitSuccess = TI_TRUE;
853
854    /* Call user application configuration callback */
855    if (pTWD->fInitFwCb)
856    {
857        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_FinalizeDownload: call fInitFwCb CB. In std drvMain_InitFwCb()\n");
858
859        (*pTWD->fInitFwCb) (pTWD->hUser, TI_OK);
860    }
861}
862
863void TWD_FinalizeOnFailure (TI_HANDLE hTWD)
864{
865    TTwd  *pTWD = (TTwd *)hTWD;
866
867    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_FinalizeOnFailure: called\n");
868
869	/* Call the upper layer callback for init failure case */
870    if (pTWD->fInitFailCb)
871    {
872        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_FinalizeOnFailure: call fInitFailCb CB. In std drvMain_InitFailCb()\n");
873
874        pTWD->fInitFailCb (pTWD->hUser, TI_OK);
875    }
876}
877
878TI_STATUS TWD_CheckMailboxCb (TI_HANDLE hTWD, TI_UINT16 uMboxStatus, void *pItrParamBuf)
879{
880    TTwd *pTWD = (TTwd *)hTWD;
881
882    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_CheckMailboxCb: called\n");
883
884    if (uMboxStatus != TI_OK)
885    {
886        ++pTWD->uNumMboxFailures;
887        TRACE1(pTWD->hReport, REPORT_SEVERITY_WARNING, "TWD_CheckMailboxCb: Periodic intorregate check - Command mailbox failure was occur \n errors failure # %d", pTWD->uNumMboxFailures);
888
889        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_CheckMailboxCb: call TWD_INT_EVENT_FAILURE CB. In std healthMonitor_sendFailureEvent()\n");
890
891        /* Indicating Upper Layer about Mbox Error */
892        pTWD->fFailureEventCb (pTWD->hFailureEventCb, MBOX_FAILURE);
893    }
894
895    return TI_OK;
896}
897#ifdef RS_OVER_TWD
898extern	void (*gBusTxn_ErrorCb)(TI_HANDLE , int);
899extern  void *gBusTxn_ErrorHndle;
900#endif
901
902/**
903 * \brief Registers TWD Module Callbacks
904 *
905 * \param  hTWD         - TWD module object handle
906 * \param  uCallBackID  - Registered Callback ID
907 * \param  fCb 	        - Pointer to Input Registered CB function
908 * \param  hCb 	        - Handle to Input Registered CB parameters
909 * \return void
910 *
911 * \par Description
912 * Static CB function
913 * This CB Registers TWD CB functions for future use:
914 * CB which handles failure to the CMD Queue, MAC Service and TwIf
915 * CB which handles Command Complete for the CMD Queue
916 * Called by TWD_RegisterCb
917 *
918 * \sa TWD_RegisterCb
919 */
920static void TWD_RegisterOwnCb (TI_HANDLE hTWD, TI_UINT32 uCallBackID, void *fCb, TI_HANDLE hCb)
921{
922    TTwd *pTWD = (TTwd *)hTWD;
923
924    TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_RegisterOwnCB: callback ID=0x%x\n", uCallBackID);
925
926    switch (uCallBackID)
927    {
928    case TWD_INT_EVENT_FAILURE:
929        /* Save Health-Moitor callback */
930        pTWD->fFailureEventCb = (TFailureEventCb)fCb;
931        pTWD->hFailureEventCb = hCb;
932
933        /* Register For Error Of Mailbox in case of timeout */
934        cmdQueue_RegisterForErrorCb (pTWD->hCmdQueue, (void *)TWD_CheckMailboxCb, hTWD);
935
936        /* Forward the Health-Moitor callback to the MAC-Services modules */
937        MacServices_registerFailureEventCB(pTWD->hMacServices, fCb, hCb);
938
939        /* Forward the Health-Moitor callback to the TwIf for bus errors */
940        twIf_RegisterErrCb (pTWD->hTwIf, fCb, hCb);
941
942        /* Forward the Health-Moitor callback to the RxXfer for Rx packet errors */
943        rxXfer_RegisterErrCb (pTWD->hRxXfer, fCb, hCb);
944        break;
945
946    case TWD_INT_COMMAND_COMPLETE:
947        cmdQueue_RegisterCmdCompleteGenericCb (pTWD->hCmdQueue, fCb, hCb);
948        break;
949
950    default:
951        TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_RegisterOwnCb - Illegal value\n");
952    }
953}
954
955TI_STATUS TWD_RegisterCb (TI_HANDLE hTWD, TI_UINT32 event, TTwdCB *fCb, void *pData)
956{
957    TTwd *pTWD = (TTwd *)hTWD;
958    TI_UINT32 uModuleId    = event & TWD_CB_MODULE_OWNER_MASK;
959    TI_UINT32 uCallbackId  = event & TWD_CB_TYPE_MASK;
960
961	if ((fCb == NULL) || (pData == NULL))
962	{
963TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_Register_CB: Invalid NULL Parameter\n");
964
965	}
966
967    TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: (Value = 0x%x)\n", event);
968
969   /* First detect which module is the owner */
970
971    switch (uModuleId)
972    {
973    case TWD_OWNER_TX_HW_QUEUE:
974        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_TX_HW_QUEUE\n");
975        txHwQueue_RegisterCb (pTWD->hTxHwQueue, uCallbackId, fCb, pData);
976        break;
977
978    case TWD_OWNER_DRIVER_TX_XFER:
979        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_DRIVER_TX_XFER\n");
980        txXfer_RegisterCb (pTWD->hTxXfer, uCallbackId, fCb, pData);
981        break;
982
983    case TWD_OWNER_TX_RESULT:
984        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_TX_RESULT\n");
985        txResult_RegisterCb (pTWD->hTxResult, uCallbackId, fCb, pData);
986        break;
987
988    case TWD_OWNER_RX_XFER:
989        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_RX_XFER\n");
990        rxXfer_Register_CB(pTWD->hRxXfer, uCallbackId, fCb, pData);
991        break;
992
993    case TWD_OWNER_RX_QUEUE:
994        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_RX_QUEUE\n");
995        RxQueue_Register_CB(pTWD->hRxQueue, uCallbackId, fCb, pData);
996        break;
997
998    case TWD_OWNER_SELF:
999        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_SELF\n");
1000        TWD_RegisterOwnCb (hTWD, uCallbackId, fCb, pData);
1001        break;
1002
1003    case TWD_OWNER_MAC_SERVICES:
1004        switch (uCallbackId)
1005        {
1006        case TWD_OWN_EVENT_SCAN_CMPLT:
1007            MacServices_scanSRV_registerScanCompleteCB (pTWD->hMacServices, (TScanSrvCompleteCb)fCb, pData);
1008            break;
1009        default:
1010            TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_Register_CB: TWD_OWNER_MAC_SERVICES - Illegal value\n");
1011        }
1012        break;
1013
1014    case TWD_OWNER_SELF_CONFIG:
1015        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_SELF_CONFIG\n");
1016        pTWD->fConfigFwCb  = (TTwdCallback)fCb;
1017        break;
1018
1019    default:
1020        TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_Register_CB - Illegal value\n");
1021    }
1022
1023    return TI_OK;
1024}
1025
1026TI_STATUS TWD_ExitFromInitMode (TI_HANDLE hTWD)
1027{
1028    TTwd    *pTWD = (TTwd *)hTWD;
1029
1030    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_ExitFromInitMode: called\n");
1031
1032    /* Notify Event MailBox about init complete */
1033    eventMbox_InitComplete (pTWD->hEventMbox);
1034
1035    /* Enable Mailbox */
1036    cmdQueue_EnableMbox (pTWD->hCmdQueue);
1037
1038    return TI_OK;
1039}
1040
1041
1042#ifdef TI_DBG
1043TI_STATUS TWD_PrintTxInfo (TI_HANDLE hTWD, ETwdPrintInfoType ePrintInfo)
1044{
1045    TTwd *pTWD = (TTwd *)hTWD;
1046
1047    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_PrintTxInfo: called\n");
1048
1049    switch (ePrintInfo)
1050    {
1051        case TWD_PRINT_TX_CTRL_BLK_TBL:
1052            txCtrlBlk_PrintTable (pTWD->hTxCtrlBlk);
1053            break;
1054
1055        case TWD_PRINT_TX_HW_QUEUE_INFO:
1056            txHwQueue_PrintInfo (pTWD->hTxHwQueue);
1057            break;
1058
1059    case TWD_PRINT_TX_XFER_INFO:
1060            TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"No TxXfer information to show\n");
1061            WLAN_OS_REPORT(("No TxXfer information to show\n"));
1062            break;
1063
1064        case TWD_PRINT_TX_RESULT_INFO:
1065            txResult_PrintInfo (pTWD->hTxResult);
1066            break;
1067
1068        case TWD_CLEAR_TX_RESULT_INFO:
1069            txResult_ClearInfo (pTWD->hTxResult);
1070            break;
1071
1072        default:
1073            TRACE1(pTWD->hReport, REPORT_SEVERITY_ERROR, ": invalid print info request code: %d\n", ePrintInfo);
1074    }
1075
1076    return TI_OK;
1077}
1078
1079#endif /* TI_DBG */
1080
1081TI_STATUS TWD_InterruptRequest (TI_HANDLE hTWD)
1082{
1083    TTwd *pTWD = (TTwd *)hTWD;
1084
1085    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_InterruptRequest: called\n");
1086
1087    fwEvent_InterruptRequest (pTWD->hFwEvent);
1088
1089    return TI_OK;
1090}
1091
1092TI_STATUS TWD_RegisterEvent (TI_HANDLE hTWD, TI_UINT32 event, void *fCb, TI_HANDLE hCb)
1093{
1094    TTwd  *pTWD = (TTwd *)hTWD;
1095
1096    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_RegisterEvent: called\n");
1097
1098    return eventMbox_RegisterEvent (pTWD->hEventMbox, event, fCb, hCb);
1099}
1100
1101TI_STATUS TWD_DisableEvent (TI_HANDLE hTWD, TI_UINT32 event)
1102{
1103    TTwd  *pTWD = (TTwd *)hTWD;
1104
1105    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_DisableEvent: called\n");
1106
1107    return eventMbox_MaskEvent (pTWD->hEventMbox, event, NULL, NULL);
1108}
1109
1110TI_STATUS TWD_EnableEvent (TI_HANDLE hTWD, TI_UINT32 event)
1111{
1112    TTwd  *pTWD = (TTwd *)hTWD;
1113
1114    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_EnableEvent: called\n");
1115
1116    return eventMbox_UnMaskEvent (pTWD->hEventMbox, event, NULL, NULL);
1117}
1118
1119void TWD_StopComplete (TI_HANDLE hTWD)
1120{
1121    TTwd  *pTWD = (TTwd *)hTWD;
1122
1123    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopComplete: called\n");
1124
1125
1126    /* reinit last ELP mode flag in recovery */
1127    cmdBld_Restart(pTWD->hCmdBld);
1128
1129    /* Call upper layer callback */
1130    if (pTWD->fStopCb)
1131    {
1132        TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopComplete: call fStopCb CB. In std drvMain_TwdStopCb()\n");
1133
1134        (*pTWD->fStopCb) (pTWD->hUser, TI_OK);
1135    }
1136}
1137
1138TI_STATUS TWD_Stop (TI_HANDLE hTWD)
1139{
1140    TTwd        *pTWD = (TTwd *)hTWD;
1141    ETxnStatus   status;
1142
1143    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_Stop: called\n");
1144
1145    fwEvent_Stop (pTWD->hFwEvent);
1146
1147
1148    /* close all BA sessions */
1149    TWD_CloseAllBaSessions(hTWD);
1150
1151    cmdMbox_Restart (pTWD->hCmdMbox);
1152    cmdQueue_Restart (pTWD->hCmdQueue);
1153    cmdQueue_DisableMbox (pTWD->hCmdQueue);
1154    eventMbox_Stop (pTWD->hEventMbox);
1155    MacServices_restart (pTWD->hMacServices);
1156
1157    status = twIf_Restart(pTWD->hTwIf);
1158
1159    /* Call user stop callback */
1160    if (status != TXN_STATUS_PENDING)
1161    {
1162        TWD_StopComplete (hTWD);
1163    }
1164
1165    return TI_OK;
1166}
1167
1168void TWD_EnableExternalEvents (TI_HANDLE hTWD)
1169{
1170    TTwd        *pTWD = (TTwd *)hTWD;
1171
1172    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_EnableExternalEvents: called\n");
1173
1174    /*
1175     * Enable sleep after all firmware initializations completed
1176     * The awake was in the TWD_initHw phase
1177     */
1178    twIf_Sleep (pTWD->hTwIf);
1179
1180    fwEvent_EnableExternalEvents (pTWD->hFwEvent);
1181}
1182
1183TI_BOOL TWD_RecoveryEnabled (TI_HANDLE hTWD)
1184{
1185    TTwd  *pTWD = (TTwd *)hTWD;
1186
1187    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_RecoveryEnabled: called\n");
1188
1189    return pTWD->bRecoveryEnabled;
1190}
1191
1192TI_UINT32 TWD_GetMaxNumberOfCommandsInQueue (TI_HANDLE hTWD)
1193{
1194    TTwd *pTWD = (TTwd *)hTWD;
1195
1196    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_GetMaxNumberOfCommandsInQueue: called\n");
1197
1198    return cmdQueue_GetMaxNumberOfCommands (pTWD->hCmdQueue);
1199}
1200
1201TI_STATUS TWD_SetPsMode (TI_HANDLE                   hTWD,
1202						 E80211PsMode ePsMode,
1203						 TI_BOOL bSendNullDataOnExit,
1204                         TI_HANDLE                   hPowerSaveCompleteCb,
1205                         TPowerSaveCompleteCb        fPowerSaveCompleteCb,
1206                         TPowerSaveResponseCb        fPowerSaveResponseCb)
1207{
1208    TTwd *pTWD = (TTwd *)hTWD;
1209
1210    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_SetPsMode: called\n");
1211
1212    return MacServices_powerSrv_SetPsMode (pTWD->hMacServices,
1213                                           ePsMode,
1214                                           bSendNullDataOnExit,
1215                                           hPowerSaveCompleteCb,
1216                                           fPowerSaveCompleteCb,
1217                                           fPowerSaveResponseCb);
1218}
1219
1220TI_BOOL TWD_GetPsStatus (TI_HANDLE hTWD)
1221{
1222    TTwd *pTWD = (TTwd *)hTWD;
1223
1224    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_GetPsStatus: called\n");
1225
1226    return MacServices_powerSrv_getPsStatus (pTWD->hMacServices);
1227}
1228
1229TI_STATUS TWD_SetNullRateModulation (TI_HANDLE hTWD, TI_UINT16 rate)
1230{
1231    TTwd *pTWD = (TTwd *)hTWD;
1232
1233    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_SetRateModulation: called\n");
1234
1235    MacServices_powerSrv_SetRateModulation (pTWD->hMacServices, rate);
1236
1237    return TI_OK;
1238}
1239
1240void TWD_UpdateDtimTbtt (TI_HANDLE hTWD, TI_UINT8 uDtimPeriod, TI_UINT16 uBeaconInterval)
1241{
1242    TTwd *pTWD = (TTwd *)hTWD;
1243
1244    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_UpdateDtimTbtt: called\n");
1245
1246    MacServices_scanSrv_UpdateDtimTbtt (pTWD->hMacServices, uDtimPeriod, uBeaconInterval);
1247}
1248
1249TI_STATUS TWD_StartMeasurement (TI_HANDLE                   hTWD,
1250                                TMeasurementRequest        *pMsrRequest,
1251                                TI_UINT32                   uTimeToRequestExpiryMs,
1252                                TCmdResponseCb              fResponseCb,
1253                                TI_HANDLE                   hResponseCb,
1254                                TMeasurementSrvCompleteCb   fCompleteCb,
1255                                TI_HANDLE                   hCompleteCb)
1256{
1257    TTwd *pTWD = (TTwd *)hTWD;
1258
1259    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StartMeasurement: called\n");
1260
1261    return MacServices_measurementSRV_startMeasurement (pTWD->hMacServices,
1262                                                        pMsrRequest,
1263                                                        uTimeToRequestExpiryMs,
1264                                                        fResponseCb,
1265                                                        hResponseCb,
1266                                                        fCompleteCb,
1267                                                        hCompleteCb);
1268}
1269
1270TI_STATUS TWD_StopMeasurement (TI_HANDLE       	hTWD,
1271                               TI_BOOL        	bSendNullData,
1272                               TCmdResponseCb  	fResponseCb,
1273                               TI_HANDLE       	hResponseCb)
1274{
1275    TTwd *pTWD = (TTwd *)hTWD;
1276
1277    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopMeasurement: called\n");
1278
1279    return MacServices_measurementSRV_stopMeasurement (pTWD->hMacServices,
1280                                                       bSendNullData,
1281                                                       fResponseCb,
1282                                                       hResponseCb);
1283}
1284
1285TI_STATUS TWD_RegisterScanCompleteCb (TI_HANDLE            hTWD,
1286                                      TScanSrvCompleteCb   fScanCompleteCb,
1287                                      TI_HANDLE            hScanCompleteCb)
1288{
1289    TTwd *pTWD = (TTwd *)hTWD;
1290
1291    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_RegisterScanCompleteCb: called\n");
1292
1293    MacServices_scanSRV_registerScanCompleteCB (pTWD->hMacServices,
1294                                                fScanCompleteCb,
1295                                                hScanCompleteCb);
1296
1297    return TI_OK;
1298}
1299
1300#ifdef TI_DBG
1301TI_STATUS TWD_PrintMacServDebugStatus (TI_HANDLE hTWD)
1302{
1303    TTwd *pTWD = (TTwd *)hTWD;
1304
1305    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_PrintMacServDebugStatus: called\n");
1306
1307    MacServices_scanSrv_printDebugStatus (pTWD->hMacServices);
1308
1309    return TI_OK;
1310}
1311#endif
1312
1313TI_STATUS TWD_Scan (TI_HANDLE       hTWD,
1314                    TScanParams    	*pScanParams,
1315                    EScanResultTag 	eScanTag,
1316                    TI_BOOL        	bHighPriority,
1317                    TI_BOOL        	bDriverMode,
1318                    TI_BOOL        	bScanOnDriverModeError,
1319                    E80211PsMode   	ePsRequest,
1320                    TI_BOOL        	bSendNullData,
1321                    TCmdResponseCb 	fResponseCb,
1322                    TI_HANDLE      	hResponseCb)
1323{
1324    TTwd *pTWD = (TTwd *)hTWD;
1325
1326    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_Scan: called\n");
1327
1328    return MacServices_scanSRV_scan (pTWD->hMacServices,
1329                                     pScanParams,
1330                                     eScanTag,
1331                                     bHighPriority,
1332                                     bDriverMode,
1333                                     bScanOnDriverModeError,
1334                                     ePsRequest,
1335                                     bSendNullData,
1336                                     fResponseCb,
1337                                     hResponseCb);
1338}
1339
1340TI_STATUS TWD_StopScan (TI_HANDLE       hTWD,
1341                        EScanResultTag  eScanTag,
1342                        TI_BOOL         bSendNullData,
1343                        TCmdResponseCb  fScanCommandResponseCb,
1344                        TI_HANDLE       hCb)
1345{
1346    TTwd *pTWD = (TTwd *)hTWD;
1347
1348    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopScan: called\n");
1349
1350    return MacServices_scanSRV_stopScan (pTWD->hMacServices,
1351                                         eScanTag,
1352                                         bSendNullData,
1353                                         fScanCommandResponseCb,
1354                                         hCb);
1355}
1356
1357TI_STATUS TWD_StopScanOnFWReset (TI_HANDLE hTWD)
1358{
1359    TTwd *pTWD = (TTwd *)hTWD;
1360
1361    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopScanOnFWReset: called\n");
1362
1363    return MacServices_scanSRV_stopOnFWReset (pTWD->hMacServices);
1364}
1365
1366TI_STATUS TWD_StartConnectionScan (TI_HANDLE              hTWD,
1367                                 TPeriodicScanParams    *pPeriodicScanParams,
1368                                 EScanResultTag         eScanTag,
1369                                 TI_UINT32              uPassiveScanDfsDwellTimeMs,
1370                                 TCmdResponseCb         fResponseCb,
1371                                 TI_HANDLE              hResponseCb)
1372{
1373    TTwd *pTWD = (TTwd *)hTWD;
1374
1375    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StartConnectionScan: called\n");
1376
1377    return cmdBld_StartPeriodicScan (pTWD->hCmdBld, pPeriodicScanParams, eScanTag, uPassiveScanDfsDwellTimeMs,
1378                                     (void*)fResponseCb, hResponseCb);
1379}
1380
1381TI_STATUS TWD_StopPeriodicScan  (TI_HANDLE              hTWD,
1382                                 EScanResultTag         eScanTag,
1383                                 TCmdResponseCb         fResponseCb,
1384                                 TI_HANDLE              hResponseCb)
1385{
1386    TTwd *pTWD = (TTwd *)hTWD;
1387
1388    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopPeriodicScan: called\n");
1389
1390    return cmdBld_StopPeriodicScan (pTWD->hCmdBld, eScanTag, (void*)fResponseCb, hResponseCb);
1391}
1392
1393TI_STATUS TWD_readMem (TI_HANDLE hTWD, TFwDebugParams* pMemDebug, void* fCb, TI_HANDLE hCb)
1394{
1395    if (hTWD == NULL || pMemDebug == NULL)
1396	{
1397		return (TI_NOK);
1398	}
1399
1400	TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_INFORMATION , "TWD_readMem: called\n");
1401
1402	if (fwDbg_ReadAddr(((TTwd *)hTWD)->hFwDbg,pMemDebug->addr,pMemDebug->length,pMemDebug->UBuf.buf8,(TFwDubCallback)fCb,hCb) == TI_NOK)
1403	{
1404        TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_CONSOLE ,"TWD_readMem Error: fwDbg_handleCommand failed\n");
1405		WLAN_OS_REPORT(("TWD_readMem Error: fwDbg_handleCommand failed\n"));
1406		return TI_NOK;
1407	}
1408
1409	return (TI_OK);
1410}
1411
1412TI_STATUS TWD_writeMem (TI_HANDLE hTWD, TFwDebugParams* pMemDebug, void* fCb, TI_HANDLE hCb)
1413{
1414    if (hTWD == NULL || pMemDebug == NULL)
1415	{
1416		return (TI_NOK);
1417	}
1418
1419	TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_INFORMATION , "TWD_writeMem: called\n");
1420
1421	if (fwDbg_WriteAddr(((TTwd *)hTWD)->hFwDbg,pMemDebug->addr,pMemDebug->length,pMemDebug->UBuf.buf8,(TFwDubCallback)fCb,hCb) == TI_NOK)
1422	{
1423        TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_CONSOLE ,"TWD_writeMem Error: fwDbg_handleCommand failed\n");
1424		WLAN_OS_REPORT(("TWD_writeMem Error: fwDbg_handleCommand failed\n"));
1425		return TI_NOK;
1426	}
1427
1428	return(TI_OK);
1429}
1430
1431TI_BOOL TWD_isValidMemoryAddr (TI_HANDLE hTWD, TFwDebugParams* pMemDebug)
1432{
1433	if (hTWD == NULL || pMemDebug == NULL)
1434	{
1435		return TI_FALSE;
1436	}
1437
1438	TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_INFORMATION , "TWD_isValidMemoryAddr: called\n");
1439
1440	return fwDbg_isValidMemoryAddr(((TTwd *)hTWD)->hFwDbg,pMemDebug->addr,pMemDebug->length);
1441}
1442
1443TI_BOOL TWD_isValidRegAddr (TI_HANDLE hTWD, TFwDebugParams* pMemDebug)
1444{
1445    if (hTWD == NULL || pMemDebug == NULL )
1446	{
1447		return TI_FALSE;
1448	}
1449
1450	TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_INFORMATION , "TWD_isValidRegAddr: called\n");
1451
1452	return fwDbg_isValidRegAddr(((TTwd *)hTWD)->hFwDbg,pMemDebug->addr,pMemDebug->length);
1453}
1454
1455/**
1456 * \brief Set Template Frame
1457 *
1458 * \param hTWD 				- TWD module object handle
1459 * \param pMib      		- Pointer to Input MIB Structure
1460 * \return TI_OK on success or TI_NOK on failure
1461 *
1462 * \par Description
1463 * Static function
1464 * Configure/Interrogate/Modulate the Frame Rate if needed (according to Templete Type)
1465 * and then write the MIB TemplateFrame to the FW
1466 *
1467 * \sa
1468 */
1469static TI_STATUS TWD_WriteMibTemplateFrame (TI_HANDLE hTWD, TMib* pMib)
1470{
1471    TTwd  *pTWD = (TTwd *)hTWD;
1472    TSetTemplate  tSetTemplate;
1473    TI_UINT32  uRateMask = RATE_TO_MASK(pMib->aData.TemplateFrame.Rate);
1474
1475    /*
1476     * Construct the template MIB element
1477     */
1478    switch(pMib->aData.TemplateFrame.FrameType)
1479    {
1480    case TEMPLATE_TYPE_BEACON:
1481        tSetTemplate.type = BEACON_TEMPLATE;
1482        break;
1483
1484    case TEMPLATE_TYPE_PROBE_REQUEST:
1485        tSetTemplate.type = PROBE_REQUEST_TEMPLATE;
1486        tSetTemplate.eBand = RADIO_BAND_2_4_GHZ; /* needed for GWSI, if so band must also be passed to choose correct template (G or A) */
1487        break;
1488
1489    case TEMPLATE_TYPE_NULL_FRAME:
1490        tSetTemplate.type = NULL_DATA_TEMPLATE;
1491        MacServices_powerSrv_SetRateModulation (pTWD->hMacServices, (TI_UINT16)uRateMask);
1492        break;
1493
1494    case TEMPLATE_TYPE_PROBE_RESPONSE:
1495        tSetTemplate.type = PROBE_RESPONSE_TEMPLATE;
1496        break;
1497
1498    case TEMPLATE_TYPE_QOS_NULL_FRAME:
1499        tSetTemplate.type = QOS_NULL_DATA_TEMPLATE;
1500        break;
1501
1502    case TEMPLATE_TYPE_PS_POLL:
1503        tSetTemplate.type = PS_POLL_TEMPLATE;
1504        break;
1505
1506    default:
1507        TRACE1(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_WriteMibTemplateFrame - ERROR - template is not supported, %d\n", pMib->aData.TemplateFrame.FrameType);
1508        return PARAM_NOT_SUPPORTED;
1509    }
1510
1511    tSetTemplate.len = pMib->aData.TemplateFrame.Length;
1512    tSetTemplate.ptr = (TI_UINT8 *) &(pMib->aData.TemplateFrame.Data);
1513    tSetTemplate.uRateMask = uRateMask;
1514
1515    return TWD_CmdTemplate (hTWD, &tSetTemplate, NULL, NULL);
1516}
1517
1518/**
1519 * \brief Set Beacon Filter IE Table
1520 *
1521 * \param hTWD 				- TWD module object handle
1522 * \param pMib      		- Pointer to Input MIB Structure
1523 * \return TI_OK on success or TI_NOK on failure
1524 *
1525 * \par Description
1526 * Static function
1527 * Configure the MIB Beacon Filter IE table
1528 *
1529 * \sa
1530 */
1531static TI_STATUS TWD_WriteMibBeaconFilterIETable (TI_HANDLE hTWD, TMib *pMib)
1532{
1533    TTwd  *pTWD = (TTwd *)hTWD;
1534    TI_UINT8 numOf221IE = 0;
1535    TI_UINT8 i = 0;
1536    TI_UINT8 IETableLen = 0;
1537    TI_UINT8 numOfIEs = 0;
1538    TI_UINT8 *IETable = NULL;
1539
1540    numOfIEs = pMib->aData.BeaconFilter.iNumberOfIEs;
1541    IETable = pMib->aData.BeaconFilter.iIETable;
1542    /* Find the actual IETableLen */
1543    for (i = 0; i < numOfIEs; i++)
1544    {
1545        if (IETable[IETableLen] == 0xdd)
1546        {
1547             IETableLen += 8;
1548             numOf221IE++;
1549        }
1550        else
1551        {
1552            IETableLen += 2;
1553        }
1554    }
1555
1556    TRACE4(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_WriteMibBeaconFilterIETable: IETable=0x%x Num Of IE=%d ( including %d 221 ) - Table Len=%d\n", IETable, numOfIEs, numOf221IE, IETableLen);
1557
1558    return TWD_CfgBeaconFilterTable (hTWD, numOfIEs, IETable, IETableLen);
1559}
1560
1561/**
1562 * \brief Set Tx Rate Policy
1563 *
1564 * \param hTWD 				- TWD module object handle
1565 * \param pMib      		- Pointer to Input MIB Structure
1566 * \return TI_OK on success or TI_NOK on failure
1567 *
1568 * \par Description
1569 * Static function
1570 * Coordinates between legacy TxRatePolicy implementation and the MIB format:
1571 * Converts the pGwsi_txRatePolicy back to command builder commands.
1572 * Activates the TWD_set function.
1573 *
1574 * \sa
1575 */
1576static TI_STATUS TWD_WriteMibTxRatePolicy (TI_HANDLE hTWD, TMib* pMib)
1577{
1578    TTwd   *pTWD = (TTwd *)hTWD;
1579
1580#ifdef TI_DBG
1581    if (NULL == pMib)
1582    {
1583        TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "ERROR: TWD_WriteMibTxRatePolicy pMib=NULL !!!");
1584		return TI_NOK;
1585    }
1586#endif /* TI_DBG */
1587
1588    return cmdBld_CfgTxRatePolicy (pTWD->hCmdBld, &pMib->aData.txRatePolicy, NULL, NULL);
1589}
1590
1591TI_STATUS TWD_WriteMib (TI_HANDLE hTWD, TMib *pMib)
1592{
1593    TTwd *pTWD = (TTwd *)hTWD;
1594
1595#ifdef TI_DBG
1596    TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_WriteMib :pMib %p:\n",pMib);
1597
1598    TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_WriteMib :aMib %x:\n",pMib->aMib);
1599
1600    TRACE_INFO_HEX(pTWD->hReport, (TI_UINT8*)pMib, TI_MIN (sizeof(TMib), pMib->Length));
1601#endif /* TI_DBG */
1602
1603    if (NULL == pMib)
1604    {
1605        TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_WriteMib :pMib = NULL !!\n");
1606        return PARAM_VALUE_NOT_VALID;
1607    }
1608
1609    switch (pMib->aMib)
1610    {
1611    case MIB_dot11MaxReceiveLifetime:
1612        return cmdBld_CfgRxMsduLifeTime (pTWD->hCmdBld, pMib->aData.MaxReceiveLifeTime * 1024, (void *)NULL, (void *)NULL);
1613
1614    case MIB_ctsToSelf:
1615        return cmdBld_CfgCtsProtection (pTWD->hCmdBld, (TI_UINT8)pMib->aData.CTSToSelfEnable, (void *)NULL, (TI_HANDLE)NULL);
1616
1617    case MIB_dot11GroupAddressesTable:
1618        {
1619            if (NULL == pMib->aData.GroupAddressTable.aGroupTable)
1620            {
1621                TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_WriteMib(MIB_dot11GroupAddressesTable) :GroupTable = NULL !!\n");
1622                return PARAM_VALUE_NOT_VALID;
1623            }
1624
1625            return TWD_CfgGroupAddressTable (hTWD,
1626                                             pMib->aData.GroupAddressTable.nNumberOfAddresses,
1627                                             pMib->aData.GroupAddressTable.aGroupTable,
1628                                             pMib->aData.GroupAddressTable.bFilteringEnable);
1629        }
1630
1631    case MIB_arpIpAddressesTable:
1632        {
1633            TIpAddr IpAddress;
1634
1635            IP_COPY (IpAddress, pMib->aData.ArpIpAddressesTable.addr);
1636
1637            TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_WriteMib(MIB_arpIpAddressesTable) IpAddress:\n");
1638            TRACE_INFO_HEX(pTWD->hReport, (TI_UINT8*)&IpAddress, 4);
1639
1640            return cmdBld_CfgArpIpAddrTable (pTWD->hCmdBld,
1641                                             IpAddress,
1642                                             (TI_BOOL)pMib->aData.ArpIpAddressesTable.FilteringEnable,
1643                                             IP_VER_4,
1644                                             NULL,
1645                                             NULL);
1646        }
1647
1648    case MIB_templateFrame:
1649        return TWD_WriteMibTemplateFrame (hTWD, pMib);
1650
1651    case MIB_beaconFilterIETable:
1652        return TWD_WriteMibBeaconFilterIETable (hTWD, pMib);
1653
1654    case MIB_rxFilter:
1655        {
1656            TI_UINT32  uRxFilter = 0;
1657            TI_UINT8   uMibRxFilter = pMib->aData.RxFilter;
1658
1659            if (uMibRxFilter & MIB_RX_FILTER_PROMISCOUS_SET)
1660            {
1661                TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "\n TWD_WriteMib MIB_rxFilter - RX_CFG_ENABLE_ANY_DEST_MAC\n");
1662                uRxFilter = RX_CFG_ENABLE_ANY_DEST_MAC;
1663            }
1664            else
1665            {
1666                uRxFilter = RX_CFG_ENABLE_ONLY_MY_DEST_MAC;
1667                TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "\n halCtrl_WriteMib MIB_rxFilter - RX_CFG_ENABLE_ONLY_MY_DEST_MAC\n");
1668            }
1669
1670            if ((uMibRxFilter & MIB_RX_FILTER_BSSID_SET) != 0)
1671            {
1672                uRxFilter = uRxFilter | RX_CFG_ENABLE_ONLY_MY_BSSID;
1673                TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "\n halCtrl_WriteMib MIB_rxFilter - RX_CFG_ENABLE_ONLY_MY_BSSID\n");
1674            }
1675            else
1676            {
1677                uRxFilter = uRxFilter | RX_CFG_ENABLE_ANY_BSSID;
1678                TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "\n halCtrl_WriteMib MIB_rxFilter - RX_CFG_ENABLE_ANY_BSSID\n");
1679            }
1680
1681            /*
1682             * Activates the TWD_setRxFilters function
1683             */
1684            return TWD_CfgRx (hTWD, uRxFilter, RX_FILTER_OPTION_DEF);
1685        }
1686
1687    case MIB_txRatePolicy:
1688        return TWD_WriteMibTxRatePolicy (hTWD, pMib);
1689
1690    default:
1691        TRACE1(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_WriteMib - ERROR - MIB element not supported, %d\n", pMib->aMib);
1692
1693        return TI_NOK;
1694
1695    } /* switch */
1696}
1697
1698TI_STATUS TWD_ReadMib (TI_HANDLE hTWD, TI_HANDLE hCb, void* fCb, void* pCb)
1699{
1700    TTwd *pTWD = (TTwd *)hTWD;
1701
1702    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_ReadMib: called\n");
1703
1704    return cmdBld_ReadMib (pTWD->hCmdBld, hCb, fCb, pCb);
1705}
1706
1707void TWD_DisableInterrupts(TI_HANDLE hTWD)
1708{
1709    TTwd    *pTWD = (TTwd *)hTWD;
1710
1711    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_DisableInterrupts: called\n");
1712
1713    fwEvent_DisableInterrupts(pTWD->hFwEvent);
1714}
1715
1716void TWD_EnableInterrupts(TI_HANDLE hTWD)
1717{
1718    TTwd    *pTWD = (TTwd *)hTWD;
1719
1720    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_EnableInterrupts: called\n");
1721
1722    fwEvent_EnableInterrupts(pTWD->hFwEvent);
1723}
1724
1725TI_UINT32 TWD_TranslateToFwTime (TI_HANDLE hTWD, TI_UINT32 uHostTime)
1726{
1727    TTwd    *pTWD = (TTwd *)hTWD;
1728
1729    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_TranslateToFwTime: called\n");
1730
1731    return fwEvent_TranslateToFwTime (pTWD->hFwEvent, uHostTime);
1732}
1733
1734void TWD_GetTwdHtCapabilities (TI_HANDLE hTWD, TTwdHtCapabilities **pTwdHtCapabilities)
1735{
1736    TTwd        *pTWD        = (TTwd *)hTWD;
1737    TWlanParams *pWlanParams = &DB_WLAN(pTWD->hCmdBld);
1738
1739    TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_GetTwdHtCapabilities: called\n");
1740
1741    *pTwdHtCapabilities = &(pWlanParams->tTwdHtCapabilities);
1742}
1743
1744/**
1745 *  \brief TWD get FEM type
1746 *  *
1747 * \param  Handle        	- handle to object
1748 * \return uint8
1749 *
1750 * \par Description
1751 * The function return the Front end module that was read frm FW register *
1752 * \sa
1753 */
1754TI_UINT8 TWD_GetFEMType (TI_HANDLE hTWD)
1755{
1756  TTwd        *pTWD        = (TTwd *)hTWD;
1757  IniFileGeneralParam *pGenParams = &DB_GEN(pTWD->hCmdBld);
1758
1759  return pGenParams->TXBiPFEMManufacturer;
1760
1761}
1762
1763/**
1764 *  \brief TWD end function of read radio state machine
1765 *  *  *
1766 * \param  Handle        	- handle to object
1767 * \return void
1768 *
1769 * \par Description
1770 * The function calling to HwInit call back function, after finish reading FEM registers *
1771 * \sa
1772 */
1773void TWD_FinalizeFEMRead(TI_HANDLE hTWD)
1774{
1775  TTwd *pTWD = (TTwd *)hTWD;
1776
1777  (*pTWD->fInitHwCb) (pTWD->hUser, TI_OK);
1778}
1779
1780
1781
1782
1783void TWD_FinalizePolarityRead(TI_HANDLE hTWD)
1784{
1785  TTwd *pTWD = (TTwd *)hTWD;
1786  /*  allways read FEM type from Radio Registers */
1787   hwInit_ReadRadioParams(pTWD->hHwInit);
1788}
1789