summaryrefslogtreecommitdiff
path: root/wilink_6_1/stad/src/AirLink_Managment/SoftGemini.c
blob: e52e1db0e21b6eb84964f09fd2def3d5b0c35fb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
/*
 * SoftGemini.c
 *
 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.      
 * All rights reserved.                                                  
 *                                                                       
 * Redistribution and use in source and binary forms, with or without    
 * modification, are permitted provided that the following conditions    
 * are met:                                                              
 *                                                                       
 *  * Redistributions of source code must retain the above copyright     
 *    notice, this list of conditions and the following disclaimer.      
 *  * Redistributions in binary form must reproduce the above copyright  
 *    notice, this list of conditions and the following disclaimer in    
 *    the documentation and/or other materials provided with the         
 *    distribution.                                                      
 *  * Neither the name Texas Instruments nor the names of its            
 *    contributors may be used to endorse or promote products derived    
 *    from this software without specific prior written permission.      
 *                                                                       
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/** \file softGemini.c
 *  \brief BlueTooth-Wlan coexistence module interface
 *
 *  \see softGemini.h
 */

/****************************************************************************************************
*																									*
*		MODULE:		softGemini.c																	*
*		PURPOSE:	BlueTooth-Wlan coexistence module interface.							*
*					This module handles all data base (and Fw setting accordingly)					*
*					for Bluetooth-Wlan coexistence implementation.									*
*																						 			*
****************************************************************************************************/

#define __FILE_ID__  FILE_ID_5
#include "report.h"
#include "osApi.h"
#include "SoftGemini.h"
#include "DataCtrl_Api.h"
#include "scrApi.h"
#include "PowerMgr_API.h"
#include "ScanCncn.h"
#include "currBss.h"
#include "CmdDispatcher.h"
#include "TWDriver.h"
#include "DrvMainModules.h"
#include "bssTypes.h"
#include "sme.h"


#define SENSE_MODE_ENABLE		0x01
#define SENSE_MODE_DISABLE		0x00
#define PROTECTIVE_MODE_ON		0x01
#define PROTECTIVE_MODE_OFF		0x00

/********************************************************************************/
/*						Internal functions prototypes.							*/
/********************************************************************************/

static TI_STATUS SoftGemini_setEnableParam(TI_HANDLE hSoftGemini, ESoftGeminiEnableModes SoftGeminiEnable, TI_BOOL recovery);
static TI_STATUS SoftGemini_setParamsToFW(TI_HANDLE hSoftGemini, TSoftGeminiParams *SoftGeminiParam);
static TI_STATUS SoftGemini_EnableDriver(TI_HANDLE hSoftGemini);
static TI_STATUS SoftGemini_DisableDriver(TI_HANDLE hSoftGemini);
static TI_STATUS SoftGemini_SetPS(SoftGemini_t	 *pSoftGemini);
static TI_STATUS SoftGemini_unSetPS(SoftGemini_t *pSoftGemini);
static void SoftGemini_RemoveProtectiveModeParameters(TI_HANDLE hSoftGemini);
static void SoftGemini_setConfigParam(TI_HANDLE hSoftGemini, TI_UINT32 *param);
static void SoftGemini_EnableProtectiveMode(TI_HANDLE hSoftGemini);
static void SoftGemini_DisableProtectiveMode(TI_HANDLE hSoftGemini);
#ifdef REPORT_LOG
static char* SoftGemini_ConvertModeToString(ESoftGeminiEnableModes SoftGeminiEnable);
#endif

/********************************************************************************/
/*						Interface functions Implementation.						*/
/********************************************************************************/
/************************************************************************
 *                        SoftGemini_SetPSmode									*
 ************************************************************************
DESCRIPTION: SoftGemini module, called by the conn_Infra on connection
				performs the following:
				-	Enables SG if needed
                                -       Enables the SG power mode				                                                                                                   
INPUT:      hSoftGemini -		Handle to SoftGemini		

OUTPUT:		

RETURN:     

************************************************************************/
void SoftGemini_SetPSmode(TI_HANDLE hSoftGemini)
{
	SoftGemini_t *pSoftGemini = (SoftGemini_t *)hSoftGemini;

	if (pSoftGemini)
	{
		if (pSoftGemini->bDriverEnabled) 
		{
			/* Check if coexAutoPsMode is enabled to enter/exit P.S */
			if ( pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_PS_MODE])
			{
				SoftGemini_SetPS(pSoftGemini);
			}
		}
		if (pSoftGemini->bProtectiveMode) 
		{
			SoftGemini_EnableProtectiveMode(hSoftGemini);
		}
	}
	else 
        {
          TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_ERROR, "  SoftGemini_SetPSmode() - Error hSoftGemini= NULL \n");
        }
}

/************************************************************************
 *                        SoftGemini_unSetPSmode									*
 ************************************************************************
DESCRIPTION: SoftGemini module, called by the conn_Infra after disconnecting 
				performs the following:
				-	Disables the SG
                                -       Disables the SG power mode				                                                                                                   
INPUT:      hSoftGemini -		Handle to SoftGemini		

OUTPUT:		

RETURN:     

************************************************************************/
void SoftGemini_unSetPSmode(TI_HANDLE hSoftGemini)
{
	SoftGemini_t *pSoftGemini = (SoftGemini_t *)hSoftGemini;

    if (pSoftGemini)
	{
		if (pSoftGemini->bDriverEnabled) 
		{
			/* Check if coexAutoPsMode is enabled to enter/exit P.S */
			if ( pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_PS_MODE])
			{
				SoftGemini_unSetPS(pSoftGemini);
			}
		}
		if (pSoftGemini->bProtectiveMode) 
		{
			SoftGemini_RemoveProtectiveModeParameters(hSoftGemini);
		}
	}
    else
    {
		TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_ERROR, " SoftGemini_unSetPSmode() - Error hSoftGemini= NULL \n");
    }
}

/************************************************************************
 *                        SoftGemini_create									*
 ************************************************************************
DESCRIPTION: SoftGemini module creation function, called by the config mgr in creation phase 
				performs the following:
				-	Allocate the SoftGemini handle
				                                                                                                   
INPUT:      hOs -			Handle to OS		


OUTPUT:		

RETURN:     Handle to the SoftGemini module on success, NULL otherwise

************************************************************************/
TI_HANDLE SoftGemini_create(TI_HANDLE hOs)
{
	SoftGemini_t			*pSoftGemini = NULL;

	/* allocating the SoftGemini object */
	pSoftGemini = os_memoryAlloc(hOs,sizeof(SoftGemini_t));

	if (pSoftGemini == NULL)
		return NULL;				

	pSoftGemini->hOs = hOs;

	return pSoftGemini;
}

/************************************************************************
 *                        SoftGemini_config						*
 ************************************************************************
DESCRIPTION: SoftGemini module init function, called by the rvMain in init phase
				performs the following:
				-	Init local variables
				-	Init the handles to be used by the module
                                                                                                   
INPUT:       pStadHandles  - The driver modules handles		

OUTPUT:		

RETURN:      void
************************************************************************/
void SoftGemini_init (TStadHandlesList *pStadHandles)
{
	SoftGemini_t *pSoftGemini = (SoftGemini_t *)(pStadHandles->hSoftGemini);

	pSoftGemini->hCtrlData    = pStadHandles->hCtrlData;
	pSoftGemini->hTWD	      = pStadHandles->hTWD;
	pSoftGemini->hReport	  = pStadHandles->hReport;
	pSoftGemini->hSCR         = pStadHandles->hSCR;
	pSoftGemini->hPowerMgr    = pStadHandles->hPowerMgr;
	pSoftGemini->hCmdDispatch = pStadHandles->hCmdDispatch;
	pSoftGemini->hScanCncn    = pStadHandles->hScanCncn;
	pSoftGemini->hCurrBss	  = pStadHandles->hCurrBss;
    pSoftGemini->hSme         = pStadHandles->hSme;
}


TI_STATUS SoftGemini_SetDefaults (TI_HANDLE hSoftGemini, SoftGeminiInitParams_t *pSoftGeminiInitParams)
{
	SoftGemini_t *pSoftGemini = (SoftGemini_t *)hSoftGemini;
	TI_UINT8 i =0;
	TI_STATUS status;
	/*************************************/
	/* Getting SoftGemini init Params */
	/***********************************/

	pSoftGemini->SoftGeminiEnable = pSoftGeminiInitParams->SoftGeminiEnable;

	for (i =0; i< SOFT_GEMINI_PARAMS_MAX ; i++)
	{
		pSoftGemini->SoftGeminiParam.coexParams[i] = pSoftGeminiInitParams->coexParams[i];
	}

	pSoftGemini->SoftGeminiParam.paramIdx = 0xFF; /* signals to FW to config all the paramters */


    /* Send the configuration to the FW */
	status = SoftGemini_setParamsToFW(hSoftGemini, &pSoftGemini->SoftGeminiParam);

	/*******************************/
    /* register Indication interrupts  */
	/*****************************/

    TWD_RegisterEvent (pSoftGemini->hTWD, 
                       TWD_OWN_EVENT_SOFT_GEMINI_SENSE,
                       (void *)SoftGemini_SenseIndicationCB, 
                       hSoftGemini);
	TWD_RegisterEvent (pSoftGemini->hTWD, 
                       TWD_OWN_EVENT_SOFT_GEMINI_PREDIC,
                       (void *)SoftGemini_ProtectiveIndicationCB, 
                       hSoftGemini);

    TWD_EnableEvent (pSoftGemini->hTWD, TWD_OWN_EVENT_SOFT_GEMINI_SENSE);
	TWD_EnableEvent (pSoftGemini->hTWD, TWD_OWN_EVENT_SOFT_GEMINI_PREDIC);

	/* On system initialization SG is disabled but later calls to SoftGemini_setEnableParam() */
	pSoftGemini->bProtectiveMode = TI_FALSE;	
	pSoftGemini->SoftGeminiEnable = SG_DISABLE; 
	pSoftGemini->bDriverEnabled = TI_FALSE;
        pSoftGemini->bPsPollFailureActive = TI_FALSE;

	if ((TI_OK == status) && (pSoftGeminiInitParams->SoftGeminiEnable != SG_DISABLE))
	{	/* called only if different than SG_DISABLE */
		status = SoftGemini_setEnableParam(hSoftGemini, pSoftGeminiInitParams->SoftGeminiEnable, TI_FALSE);
	}

	if (status == TI_OK)
	{
TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INIT, "  SoftGemini_config() - configured successfully\n");
	}
	else
	{
TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_ERROR, "  SoftGemini_config() - Error configuring module \n");
	}

	return status;
}

/************************************************************************
 *                        SoftGemini_destroy							*
 ************************************************************************
DESCRIPTION: SoftGemini module destroy function, called by the config mgr in the destroy phase 
				performs the following:
				-	Free all memory aloocated by the module
                                                                                                   
INPUT:      hSoftGemini	-	SoftGemini handle.		


OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise

************************************************************************/
TI_STATUS SoftGemini_destroy(TI_HANDLE hSoftGemini)
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;

	if (pSoftGemini != NULL)
	{
		os_memoryFree( pSoftGemini->hOs, (TI_HANDLE)pSoftGemini , sizeof(SoftGemini_t));
	}
	
	return TI_OK;
}


/***********************************************************************
 *                        SoftGemini_setParam									
 ***********************************************************************
DESCRIPTION: SoftGemini set param function, called by the following:
			-	config mgr in order to set a parameter receiving from the OS abstraction layer.
			-	From inside the driver	
                                                                                                   
INPUT:      hSoftGemini	-	SoftGemini handle.
			pParam	-	Pointer to the parameter		

OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise

************************************************************************/
TI_STATUS SoftGemini_setParam(TI_HANDLE	hSoftGemini,
											paramInfo_t	*pParam)
{
	SoftGemini_t *pSoftGemini = (SoftGemini_t *)hSoftGemini;
	TI_STATUS return_value = TI_OK;

TRACE1(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "  SoftGemini_setParam() (0x%x)\n", pParam->paramType);
	
	switch(pParam->paramType)
	{

	case SOFT_GEMINI_SET_ENABLE:
		
		return_value = SoftGemini_setEnableParam(hSoftGemini,pParam->content.SoftGeminiEnable, TI_FALSE);
		break;

	case SOFT_GEMINI_SET_CONFIG:

		/* copy new params to SoftGemini module */
		SoftGemini_setConfigParam(hSoftGemini,pParam->content.SoftGeminiParamArray);

		/* set new params to FW */
		return_value = SoftGemini_setParamsToFW(hSoftGemini, &(pSoftGemini->SoftGeminiParam));

		if (pSoftGemini->bProtectiveMode == TI_TRUE)
		{
			/* set new configurations of scan to scancncn */
			scanCncn_SGconfigureScanParams(pSoftGemini->hScanCncn,TI_TRUE,
										   (TI_UINT8)pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_SCAN_PROBE_REQ],
										   pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_SCAN_COMPENSATION_MAX_TIME],
										   pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_SCAN_WINDOW]);
		}
		break;
		
	default:
TRACE1(pSoftGemini->hReport, REPORT_SEVERITY_ERROR, "  SoftGemini_setParam(), Params is not supported, %d\n\n", pParam->paramType);
		return PARAM_NOT_SUPPORTED;
	}

	return return_value;
}

/***********************************************************************
 *			      SoftGemini_getParam									
 ***********************************************************************
DESCRIPTION: SoftGemini get param function, called by the following:
			-	config mgr in order to get a parameter from the OS abstraction layer.
			-	From inside the dirver	
                                                                                                   
INPUT:      hSoftGemini	-	SoftGemini handle.
				

OUTPUT:		pParam	-	Pointer to the parameter	

RETURN:     TI_OK on success, TI_NOK otherwise

************************************************************************/
TI_STATUS SoftGemini_getParam(TI_HANDLE		hSoftGemini,
											paramInfo_t	*pParam)
{ 
		switch (pParam->paramType)
		{
			case SOFT_GEMINI_GET_CONFIG:
				SoftGemini_printParams(hSoftGemini);
				break;
		}

	return TI_OK;
}
 


/***************************************************************************
*					SoftGemini_setEnableParam					    	       *
****************************************************************************
* DESCRIPTION:	The function sets the  appropriate Enable value,
*				configures SCR , POWER MGR , DATA CTRL , FW.   
*
* INPUTS:		pSoftGemini - the object		
***************************************************************************/
static TI_STATUS SoftGemini_setEnableParam(TI_HANDLE hSoftGemini, ESoftGeminiEnableModes SoftGeminiEnable, TI_BOOL recovery)
{
	SoftGemini_t *pSoftGemini = (SoftGemini_t *)hSoftGemini;
	TTwdParamInfo	param;
	TI_STATUS return_value = TI_OK;

TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "  setSoftGeminiEnableParam() - Old value = , New value = \n");


    /*
     * PsPoll work around is active. Just save the value and configure it later
     */
    if ( pSoftGemini->bPsPollFailureActive )
    {
        TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "  setSoftGeminiEnableParam() - while PsPollFailure is active\n");

        pSoftGemini->PsPollFailureLastEnableValue = SoftGeminiEnable;
        return TI_OK;
    }

	/**********************************/
	/* Sanity check on enable values */
	/********************************/

	/*				Old Value						New Value		    */        
	/*					|							    |			    */        
	/*			  	   \|/							   \|/			    */        

	if ((pSoftGemini->SoftGeminiEnable == SoftGeminiEnable) && !recovery)
	{
TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_ERROR, "   - setting same value \n");
		return TI_NOK;
	}

	/*******************************/
	/* Make the necessary actions */
	/*****************************/
	
	switch (SoftGeminiEnable)
	{
	case SG_PROTECTIVE:
	case SG_OPPORTUNISTIC:
		
		/* set FW with SG_ENABLE */ 
		param.paramType = TWD_SG_ENABLE_PARAM_ID;
		param.content.SoftGeminiEnable = SoftGeminiEnable;
		return_value = TWD_SetParam (pSoftGemini->hTWD, &param);

		break;

	case SG_DISABLE:
		
		/* set FW with SG_DISABLE */
		param.paramType = TWD_SG_ENABLE_PARAM_ID;
		param.content.SoftGeminiEnable = SG_DISABLE;
		return_value = TWD_SetParam (pSoftGemini->hTWD, &param);

		if (pSoftGemini->bDriverEnabled)
		{	
			SoftGemini_DisableDriver(hSoftGemini);
		}
		
		break;

	default:
TRACE1(pSoftGemini->hReport, REPORT_SEVERITY_ERROR, " defualt :%d\n",SoftGeminiEnable);
		return TI_NOK;
	}

	/* Pass to the new enable state */
	pSoftGemini->SoftGeminiEnable = SoftGeminiEnable;

	if (TI_OK != return_value)
	{
TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_ERROR, " can't configure enable param to FW :\n");
	}
	
	return return_value;
}

/***************************************************************************
*					SoftGemini_setConfigParam				    	       *
****************************************************************************
* DESCRIPTION:	The function sets params 
*
* INPUTS:		pSoftGemini - the object
*				param       - params to be configured	
***************************************************************************/
static void SoftGemini_setConfigParam(TI_HANDLE hSoftGemini, TI_UINT32 *param)
{
	SoftGemini_t *pSoftGemini = (SoftGemini_t *)hSoftGemini;

	/* param[0] - SG parameter index, param[1] - SG parameter value */
	pSoftGemini->SoftGeminiParam.coexParams[(TI_UINT8)param[0]] = (TI_UINT32)param[1];
	pSoftGemini->SoftGeminiParam.paramIdx = (TI_UINT8)param[0];
}

/***************************************************************************
*					SoftGemini_printParams					    	       *
****************************************************************************
* DESCRIPTION:	Print SG Parameters.  
*
* INPUTS:		pSoftGemini - the object	
***************************************************************************/
void SoftGemini_printParams(TI_HANDLE hSoftGemini)
{
#ifdef REPORT_LOG

	SoftGemini_t *pSoftGemini = (SoftGemini_t *)hSoftGemini;
	TSoftGeminiParams *SoftGeminiParam = &pSoftGemini->SoftGeminiParam;

	WLAN_OS_REPORT(("[0]:  coexBtPerThreshold = %d\n", SoftGeminiParam->coexParams[SOFT_GEMINI_BT_PER_THRESHOLD]));
	WLAN_OS_REPORT(("[1]:  coexAutoScanCompensationMaxTime = %d (usec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_AUTO_SCAN_COMPENSATION_MAX_TIME]));
	WLAN_OS_REPORT(("[2]:  coexBtNfsSampleInterval = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_BT_NFS_SAMPLE_INTERVAL]));
	WLAN_OS_REPORT(("[3]:  coexBtLoadRatio = %d (%)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_BT_LOAD_RATIO]));
	WLAN_OS_REPORT(("[4]:  coexAutoPsMode = %s \n", (SoftGeminiParam->coexParams[SOFT_GEMINI_AUTO_PS_MODE]?"Enabled":"Disabled")));
	WLAN_OS_REPORT(("[5]:  coexAutoScanEnlargedNumOfProbeReqPercent = %d (%)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_AUTO_SCAN_PROBE_REQ]));
	WLAN_OS_REPORT(("[6]:  coexAutoScanEnlargedScanWindowPercent = %d (%)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_AUTO_SCAN_WINDOW]));
	WLAN_OS_REPORT(("[7]:  coexAntennaConfiguration = %s (0 = Single, 1 = Dual) \n", (SoftGeminiParam->coexParams[SOFT_GEMINI_ANTENNA_CONFIGURATION]?"Dual":"Single")));
	WLAN_OS_REPORT(("[8]:  coexMaxConsecutiveBeaconMissPrecent = %d (%)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_BEACON_MISS_PERCENT]));
	WLAN_OS_REPORT(("[9]:  coexAPRateAdapationThr = %d\n", SoftGeminiParam->coexParams[SOFT_GEMINI_RATE_ADAPT_THRESH]));
	WLAN_OS_REPORT(("[10]: coexAPRateAdapationSnr = %d\n", SoftGeminiParam->coexParams[SOFT_GEMINI_RATE_ADAPT_SNR]));
	WLAN_OS_REPORT(("[11]: coexWlanPsBtAclMasterMinBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_BT_ACL_MASTER_MIN_BR]));
	WLAN_OS_REPORT(("[12]: coexWlanPsBtAclMasterMaxBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_BT_ACL_MASTER_MAX_BR]));
	WLAN_OS_REPORT(("[13]: coexWlanPsMaxBtAclMasterBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_MAX_BT_ACL_MASTER_BR]));
    WLAN_OS_REPORT(("[14]: coexWlanPsBtAclSlaveMinBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_BT_ACL_SLAVE_MIN_BR]));
    WLAN_OS_REPORT(("[15]: coexWlanPsBtAclSlaveMaxBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_BT_ACL_SLAVE_MAX_BR]));
    WLAN_OS_REPORT(("[16]: coexWlanPsMaxBtAclSlaveBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_MAX_BT_ACL_SLAVE_BR]));
    WLAN_OS_REPORT(("[17]: coexWlanPsBtAclMasterMinEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_BT_ACL_MASTER_MIN_EDR]));
    WLAN_OS_REPORT(("[18]: coexWlanPsBtAclMasterMaxEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_BT_ACL_MASTER_MAX_EDR]));
    WLAN_OS_REPORT(("[19]: coexWlanPsMaxBtAclMasterEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_MAX_BT_ACL_MASTER_EDR]));
    WLAN_OS_REPORT(("[20]: coexWlanPsBtAclSlaveMinEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_BT_ACL_SLAVE_MIN_EDR]));
    WLAN_OS_REPORT(("[21]: coexWlanPsBtAclSlaveMaxEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_BT_ACL_SLAVE_MAX_EDR]));
    WLAN_OS_REPORT(("[22]: coexWlanPsMaxBtAclSlaveEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_PS_MAX_BT_ACL_SLAVE_EDR]));
	WLAN_OS_REPORT(("[23]: coexRxt = %d (usec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_RXT]));
	WLAN_OS_REPORT(("[24]: coexTxt = %d (usec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_TXT]));
	WLAN_OS_REPORT(("[25]: coexAdaptiveRxtTxt = %s \n", (SoftGeminiParam->coexParams[SOFT_GEMINI_ADAPTIVE_RXT_TXT]?"Enabled":"Disabled"))); 
	WLAN_OS_REPORT(("[26]: coexPsPollTimeout = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_PS_POLL_TIMEOUT]));
	WLAN_OS_REPORT(("[27]: coexUpsdTimeout = %d (msec) \n", SoftGeminiParam->coexParams[SOFT_GEMINI_UPSD_TIMEOUT]));
	WLAN_OS_REPORT(("[28]: coexWlanActiveBtAclMasterMinEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR]));
	WLAN_OS_REPORT(("[29]: coexWlanActiveBtAclMasterMaxEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR]));
	WLAN_OS_REPORT(("[30]: coexWlanActiveMaxBtAclMasterEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR]));
    WLAN_OS_REPORT(("[31]: coexWlanActiveBtAclSlaveMinEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR]));
	WLAN_OS_REPORT(("[32]: coexWlanActiveBtAclSlaveMaxEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR]));
    WLAN_OS_REPORT(("[33]: coexWlanActiveMaxBtAclSlaveEDR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR]));
    WLAN_OS_REPORT(("[34]: coexWlanActiveBtAclMinBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_BR]));
    WLAN_OS_REPORT(("[35]: coexWlanActiveBtAclMaxBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_BR]));
    WLAN_OS_REPORT(("[36]: coexWlanActiveMaxBtAclBR = %d (msec)\n", SoftGeminiParam->coexParams[SOFT_GEMINI_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_BR]));
    WLAN_OS_REPORT(("[37]: coexTempParam1 = %d \n", SoftGeminiParam->coexParams[SOFT_GEMINI_TEMP_PARAM_1]));
    WLAN_OS_REPORT(("[38]: coexTempParam2 = %d \n", SoftGeminiParam->coexParams[SOFT_GEMINI_TEMP_PARAM_2]));
    WLAN_OS_REPORT(("[39]: coexTempParam3 = %d \n", SoftGeminiParam->coexParams[SOFT_GEMINI_TEMP_PARAM_3]));
    WLAN_OS_REPORT(("[40]: coexTempParam4 = %d \n", SoftGeminiParam->coexParams[SOFT_GEMINI_TEMP_PARAM_4]));
    WLAN_OS_REPORT(("[41]: coexTempParam5 = %d \n", SoftGeminiParam->coexParams[SOFT_GEMINI_TEMP_PARAM_5]));
	WLAN_OS_REPORT(("Enable mode : %s\n", SoftGemini_ConvertModeToString(pSoftGemini->SoftGeminiEnable))); 
	WLAN_OS_REPORT(("Driver Enabled : %s\n",(pSoftGemini->bDriverEnabled ? "YES" : "NO"))); 
	WLAN_OS_REPORT(("Protective mode : %s\n", (pSoftGemini->bProtectiveMode ? "ON" : "OFF"))); 
    WLAN_OS_REPORT(("PsPoll failure active : %s\n", (pSoftGemini->bPsPollFailureActive ? "YES" : "NO"))); 

#endif
}

/***************************************************************************
*					SoftGemini_setParamsToFW					    	       *
****************************************************************************
* DESCRIPTION:	The function sets the FW with the appropriate parameters set.  
*
* INPUTS:		pSoftGemini - the object
*
*
* OUTPUT:			
* 
* RETURNS:		
***************************************************************************/
static TI_STATUS SoftGemini_setParamsToFW(TI_HANDLE hSoftGemini, TSoftGeminiParams *softGeminiParams)
{
	SoftGemini_t *pSoftGemini = (SoftGemini_t *)hSoftGemini;
	TTwdParamInfo param;

	os_memoryCopy(pSoftGemini->hOs,&param.content.SoftGeminiParam, softGeminiParams, sizeof(TSoftGeminiParams));
	param.paramType = TWD_SG_CONFIG_PARAM_ID;
	return TWD_SetParam (pSoftGemini->hTWD, &param);
}


/***************************************************************************
*					SoftGemini_EnableDriver  		    	       *
****************************************************************************
* DESCRIPTION:	Activated when SG is enabled (after CLI or FW command)
*
* INPUTS:		pSoftGemini - the object
*	
***************************************************************************/
static TI_STATUS SoftGemini_EnableDriver(TI_HANDLE hSoftGemini)
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;
	TI_STATUS return_value = TI_OK;

TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "\n");

	pSoftGemini->bDriverEnabled = TI_TRUE;

	/* Check if coexAutoPsMode - Co-ex is enabled to enter/exit P.S */
	if ( pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_PS_MODE])
	{
		SoftGemini_SetPS(pSoftGemini);
	}

	scr_setMode(pSoftGemini->hSCR, SCR_MID_SG);

	return return_value;
}

/***************************************************************************
*					SoftGemini_DisableDriver  		    	       *
****************************************************************************
* DESCRIPTION:	Activated when SG is disabled (after CLI or FW command)
*
* INPUTS:		pSoftGemini - the object
*	
***************************************************************************/
static TI_STATUS SoftGemini_DisableDriver(TI_HANDLE hSoftGemini)
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;
	TI_STATUS return_value = TI_OK;

TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "\n");

	pSoftGemini->bDriverEnabled = TI_FALSE;

	scr_setMode(pSoftGemini->hSCR, SCR_MID_NORMAL);


	/* Check if coexAutoPsMode - Co-ex is enabled to enter/exit P.S */
	if ( pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_PS_MODE])
	{
		SoftGemini_unSetPS(pSoftGemini);
	}

	/* Undo the changes that were made when Protective mode was on */
	if (pSoftGemini->bProtectiveMode)
	{
		SoftGemini_DisableProtectiveMode(hSoftGemini);
	}
	
	return return_value;
}

/***************************************************************************
*					SoftGemini_SetPS  		    						   *
****************************************************************************
* DESCRIPTION:	Set Always PS to PowerMgr
*
* INPUTS:		pSoftGemini - the object
*	
***************************************************************************/
static TI_STATUS SoftGemini_SetPS(SoftGemini_t	*pSoftGemini)
{
	paramInfo_t param;
	bssEntry_t *pBssInfo=NULL;

    if (pSoftGemini->hCurrBss)
	{
		pBssInfo = currBSS_getBssInfo(pSoftGemini->hCurrBss);
	}
    else
    {
		TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_ERROR, "SoftGemini_SetPS: hCurrBss = NULL!!!\n");
    }

    TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "\n");

	if (pBssInfo)
	{
		if ((pBssInfo->band == RADIO_BAND_2_4_GHZ))
		{
            TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, " SG-setPS: band == RADIO_BAND_2_4_GHZ");

	        /* Set Params to Power Mgr for SG priority */
	        param.paramType = POWER_MGR_POWER_MODE;
	        param.content.powerMngPowerMode.PowerMode = POWER_MODE_PS_ONLY;
	        param.content.powerMngPowerMode.PowerMngPriority = POWER_MANAGER_SG_PRIORITY;
	        powerMgr_setParam(pSoftGemini->hPowerMgr,&param);

	        /* enable SG priority for Power Mgr */
	        param.paramType = POWER_MGR_ENABLE_PRIORITY;
	        param.content.powerMngPriority = POWER_MANAGER_SG_PRIORITY;
	        return powerMgr_setParam(pSoftGemini->hPowerMgr,&param);
        }
        else
        {
            TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, " SG-setPS: band == RADIO_BAND_5_GHZ");
        }
	}
	return TI_OK;
}

/***************************************************************************
*					SoftGemini_unSetPS  		    						   *
****************************************************************************
* DESCRIPTION:	unSet Always PS to PowerMgr
*
* INPUTS:		pSoftGemini - the object
*	
***************************************************************************/
static TI_STATUS SoftGemini_unSetPS(SoftGemini_t	*pSoftGemini)
{
	paramInfo_t param;

TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, ", SG-unSetPS \n");

	/* disable SG priority for Power Mgr*/
	param.paramType = POWER_MGR_DISABLE_PRIORITY;
	param.content.powerMngPriority = POWER_MANAGER_SG_PRIORITY;
	return powerMgr_setParam(pSoftGemini->hPowerMgr,&param);
	
}

/***************************************************************************
*					SoftGemini_EnableProtectiveMode  		    	       *
****************************************************************************
* DESCRIPTION:	Activated when FW inform us that protective mode is ON
*				
*
* INPUTS:		pSoftGemini - the object
*	
***************************************************************************/
void SoftGemini_EnableProtectiveMode(TI_HANDLE hSoftGemini)
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;
	paramInfo_t 	param;

	pSoftGemini->bProtectiveMode = TI_TRUE;

	/* set new configurations of SG roaming parameters */

	/* This code should be removed on SG stage 2 integration
	 currBSS_SGconfigureBSSLoss(pSoftGemini->hCurrBss,pSoftGemini->BSSLossCompensationPercent,TI_TRUE); */

	/* set new configurations of scan to scancncn */
    scanCncn_SGconfigureScanParams(pSoftGemini->hScanCncn,TI_TRUE,
								   (TI_UINT8)pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_SCAN_PROBE_REQ],
								   pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_SCAN_COMPENSATION_MAX_TIME],
								   pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_SCAN_WINDOW]);

    /* Call the power manager to enter short doze */
TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, " SoftGemini_EnableProtectiveMode set SD");

	/* Set Params to Power Mgr for SG priority */
	param.paramType = POWER_MGR_POWER_MODE;
	param.content.powerMngPowerMode.PowerMode = POWER_MODE_SHORT_DOZE;
	param.content.powerMngPowerMode.PowerMngPriority = POWER_MANAGER_SG_PRIORITY;
	powerMgr_setParam(pSoftGemini->hPowerMgr,&param);
}

/***************************************************************************
*					SoftGemini_DisableProtectiveMode  		    	       *
****************************************************************************
* DESCRIPTION:	Activated when FW inform us that protective mode is OFF or SG is disabled
*
* INPUTS:		pSoftGemini - the object
*	
***************************************************************************/
void SoftGemini_DisableProtectiveMode(TI_HANDLE hSoftGemini)
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;

TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "\n");

	pSoftGemini->bProtectiveMode = TI_FALSE;

	SoftGemini_RemoveProtectiveModeParameters(hSoftGemini);
}

/***************************************************************************
*					SoftGemini_DisableProtectiveMode  		    	       *
****************************************************************************
* DESCRIPTION:	Called from SoftGemini_DisableProtectiveMode() when FW inform 
*				us that protective mode is OFF or SG is disabled, or from
*				SoftGemini_unSetPSmode() when driver disconnects from AP.
*
* INPUTS:		pSoftGemini - the object
*	
***************************************************************************/

void SoftGemini_RemoveProtectiveModeParameters(TI_HANDLE hSoftGemini)
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;
	paramInfo_t  	param;

TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "\n");

	/* don't use the SG roaming parameters */
	currBSS_SGconfigureBSSLoss(pSoftGemini->hCurrBss,0,TI_FALSE);

	/* don't use the SG scan parameters */
    scanCncn_SGconfigureScanParams(pSoftGemini->hScanCncn,TI_FALSE,0,0,0);

    /* Call the power manager to exit short doze */
	/* Set Params to Power Mgr for SG priority */
	param.paramType = POWER_MGR_POWER_MODE;
	param.content.powerMngPowerMode.PowerMode = POWER_MODE_PS_ONLY;
	param.content.powerMngPowerMode.PowerMngPriority = POWER_MANAGER_SG_PRIORITY;
	powerMgr_setParam(pSoftGemini->hPowerMgr,&param);
}

/***************************************************************************
*					SoftGemini_SenseIndicationCB  		    	       *
****************************************************************************
* DESCRIPTION:	This is the the function which is called for sense mode indication from FW
*				(i.e. we are in SENSE mode and FW detects BT activity )
*				SENSE_MODE_ENABLE - Indicates that FW detected BT activity
*				SENSE_MODE_DISABLE - Indicates that FW doesn't detect BT activity for a period of time
*
* INPUTS:		pSoftGemini - the object
* NOTE			This function is located in the API for debug purposes
***************************************************************************/

void SoftGemini_SenseIndicationCB( TI_HANDLE hSoftGemini, char* str, TI_UINT32 strLen )
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;

	if (pSoftGemini->SoftGeminiEnable == SG_DISABLE) {
TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_WARNING, ": SG is disabled, existing");
		return;
	}

	if ( (SENSE_MODE_ENABLE == *str) && (!pSoftGemini->bDriverEnabled) )
	{
			SoftGemini_EnableDriver(hSoftGemini);
	}
	else if ( (SENSE_MODE_DISABLE == *str) && (pSoftGemini->bDriverEnabled) )
	{
			SoftGemini_DisableDriver(hSoftGemini);
	}
}

/***************************************************************************
*					SoftGemini_ProtectiveIndicationCB  		    	       *
****************************************************************************
* DESCRIPTION:	This is the the function which is called when FW starts Protective mode (i.e BT voice) 
*
*				PROTECTIVE_MODE_ON - FW is activated on protective mode (BT voice is running)
*				PROTECTIVE_MODE_OFF - FW is not activated on protective mode
*
* INPUTS:		pSoftGemini - the object
* NOTE			This function is located in the API for debug purposes
***************************************************************************/

void SoftGemini_ProtectiveIndicationCB( TI_HANDLE hSoftGemini, char* str, TI_UINT32 strLen )
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;
	
TRACE1(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, " with 0x%x\n",*str);

	if (SG_DISABLE != pSoftGemini->SoftGeminiEnable)
	{
		if ((!pSoftGemini->bProtectiveMode) && (PROTECTIVE_MODE_ON == *str))
		{
			SoftGemini_EnableProtectiveMode(hSoftGemini);
		}
		else if ((pSoftGemini->bProtectiveMode) && (PROTECTIVE_MODE_OFF == *str))
		{
			SoftGemini_DisableProtectiveMode(hSoftGemini);
		}
		else
		{
TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, " : Protective mode  called when Protective mode is  \n");
		}
	}
	else
	{
TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_WARNING, " : Protective mode  called when SG mode is  ? \n");
	}
}

/***************************************************************************
*					SoftGemini_ConvertModeToString  		    	       *
****************************************************************************/
#ifdef REPORT_LOG

char* SoftGemini_ConvertModeToString(ESoftGeminiEnableModes SoftGeminiEnable)
{
	switch(SoftGeminiEnable)
	{
	case SG_PROTECTIVE:				return "SG_PROTECTIVE";
	case SG_DISABLE:			    return "SG_DISABLE";
	case SG_OPPORTUNISTIC:     return "SG_OPPORTUNISTIC";
	default:
		return "ERROR";
	}
}

#endif

/***************************************************************************
*					SoftGemini_getSGMode						  		    	       *
****************************************************************************/
ESoftGeminiEnableModes SoftGemini_getSGMode(TI_HANDLE hSoftGemini)
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;
	return pSoftGemini->SoftGeminiEnable;	
}

/***************************************************************************
*					SoftGemini_handleRecovery					    	       *
****************************************************************************
* DESCRIPTION:	The function reconfigures WHAL with the SG parameters.
*
* INPUTS:		pSoftGemini - the object		
***************************************************************************/
TI_STATUS SoftGemini_handleRecovery(TI_HANDLE hSoftGemini)
{
	SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;
	ESoftGeminiEnableModes       realSoftGeminiEnableMode;

	realSoftGeminiEnableMode = pSoftGemini->SoftGeminiEnable;
    /* Disable the SG */
    SoftGemini_setEnableParam(hSoftGemini, SG_DISABLE, TI_TRUE);
    TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "Disable SG \n");

	pSoftGemini->SoftGeminiEnable = realSoftGeminiEnableMode;
	/* Set enable param */

	SoftGemini_setEnableParam(hSoftGemini, pSoftGemini->SoftGeminiEnable, TI_TRUE);
    TRACE1(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "Set SG to-%d\n", pSoftGemini->SoftGeminiEnable);

	/* Config the params to FW */

	SoftGemini_setParamsToFW(hSoftGemini, &pSoftGemini->SoftGeminiParam);
	/*SoftGemini_printParams(hSoftGemini);*/
	return TI_OK;
}
/***************************************************************************
*					SoftGemini_startPsPollFailure					       *
****************************************************************************
* DESCRIPTION:	After Ps-Poll failure we disable the SG
*
* INPUTS:		pSoftGemini - the object		
***************************************************************************/
void SoftGemini_startPsPollFailure(TI_HANDLE hSoftGemini)
	{
    SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;

    TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "\n");

    if ( (!pSoftGemini->bPsPollFailureActive) && (pSoftGemini->SoftGeminiParam.coexParams[SOFT_GEMINI_AUTO_PS_MODE] == TI_TRUE) )
    {
        pSoftGemini->PsPollFailureLastEnableValue = pSoftGemini->SoftGeminiEnable;

        /* Disable SG if needed */
        if ( pSoftGemini->SoftGeminiEnable != SG_DISABLE )
        {	
            SoftGemini_setEnableParam(hSoftGemini, SG_DISABLE, TI_FALSE);
	}

        pSoftGemini->bPsPollFailureActive = TI_TRUE;
    }
    else /* Calling SoftGemini_startPsPollFailure twice ? */
	{
        TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_WARNING, "Calling  SoftGemini_startPsPollFailure while bPsPollFailureActive is TRUE\n");
    }
	}

/***************************************************************************
*					SoftGemini_endPsPollFailure					    	   *
****************************************************************************
* DESCRIPTION:	Return to normal behavior after the PsPoll failure 
*
* INPUTS:		pSoftGemini - the object		
***************************************************************************/
void SoftGemini_endPsPollFailure(TI_HANDLE hSoftGemini)
{
    SoftGemini_t	*pSoftGemini = (SoftGemini_t *)hSoftGemini;

    TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_INFORMATION, "\n");

    if ( pSoftGemini->bPsPollFailureActive ) 
    {
        pSoftGemini->bPsPollFailureActive = TI_FALSE;

        /* return to previous value */
        if ( pSoftGemini->PsPollFailureLastEnableValue != SG_DISABLE )
        {
			SoftGemini_setEnableParam(hSoftGemini, pSoftGemini->PsPollFailureLastEnableValue, TI_FALSE);
        }
    }
    else /* Calling SoftGemini_endPsPollFailure twice ? */
    {
        TRACE0(pSoftGemini->hReport, REPORT_SEVERITY_WARNING, "Calling  SoftGemini_endPsPollFailure while bPsPollFailureActive is FALSE\n");
    }
}