summaryrefslogtreecommitdiff
path: root/sta_dk_4_0_4_32/common/src/TNETW_Driver/MacServices/src/PowerAuthorization/PowerAuthorization.c
blob: fe9471aff6615d7356b6a6d83ea6eac817a9ae2e (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
/****************************************************************************
**+-----------------------------------------------------------------------+**
**|                                                                       |**
**| Copyright(c) 1998 - 2008 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.  |**
**|                                                                       |**
**+-----------------------------------------------------------------------+**
****************************************************************************/
 
/**********************************************************************************/
/*                                                                                */
/*   MODULE:  PowerAuthorization.c                                                */
/*   PURPOSE: PowerAuthorization implementation module							  */
/*                                                                                */
/**********************************************************************************/
#include "whalCtrl_api.h"
#include "report.h"
#include "MacServices_api.h"
#include "MacServices.h"
#include "PowerAuthorization.h"
#include "PowerAuthorization_internal.h"

/****************************************************************************
 *                      powerAutho_Create()
 ****************************************************************************
 * DESCRIPTION:	
 * 
 * INPUTS:	hOs - the handle to the OS layer
 *			hReport - the handle to the report module
 *			hELPCtrl - the handle to the ELPCtrl module
 *		
 * 
 * OUTPUT:	the context of the PowerAuthorization module
 * 
 * RETURNS:	the context of the PowerAuthorization module (NULL if error)
 ****************************************************************************/
TI_HANDLE powerAutho_Create(TI_HANDLE hOs)
{		 
	powerAutho_t *pObj;

	pObj = os_memoryAlloc(hOs, sizeof(powerAutho_t));
	if (pObj == NULL)
	{
		WLAN_OS_REPORT(("FATAL ERROR: powerAutho_Create(): Error allocating context\n"));
		return NULL;		
	}

	os_memoryZero(hOs, pObj, sizeof(powerAutho_t));

	pObj->hOs = hOs;
	pObj->hReport = NULL;
	pObj->hHalCtrl = NULL;

	/* set as 'before init complete' */
	pObj->initComplete = FALSE; 
	
	pObj->m_AwakeRequired = 0;
	pObj->m_PowerPolicy = POWERAUTHO_POLICY_PD;
	pObj->m_MinPowerLevel = POWERAUTHO_POLICY_PD;

	return pObj;
}


/****************************************************************************
 *                      powerAutho_Destroy()
 ****************************************************************************
 * DESCRIPTION:	
 * 
 * INPUTS:	hPowerAutho - the handle to the PowerAuthorization module.
 *		
 * 
 * OUTPUT:	
 * 
 * RETURNS:	OK
 ****************************************************************************/
int powerAutho_Destroy(TI_HANDLE hPowerAutho)
{			
	powerAutho_t *pPowerAutho = (powerAutho_t*)hPowerAutho;

	if (pPowerAutho)
		os_memoryFree(pPowerAutho->hOs, pPowerAutho, sizeof(powerAutho_t));

	return OK;
}

/****************************************************************************
 *                      powerAutho_Configure()
 ****************************************************************************
 * DESCRIPTION:	
 * 
 * INPUTS:	hPowerAutho - the handle to the PowerAuthorization module.
 *			aPowerPolicy - the power policy to configure.
 *		
 * 
 * OUTPUT:	
 * 
 * RETURNS:	OK
 ****************************************************************************/
int powerAutho_Configure(TI_HANDLE hPowerAutho, TI_HANDLE hReport, TI_HANDLE hHalCtrl, powerAutho_PowerPolicy_e aPowerPolicy)
{
	powerAutho_t *pPowerAutho = (powerAutho_t*)hPowerAutho;

	pPowerAutho->m_PowerPolicy = aPowerPolicy;

	pPowerAutho->m_ElpCtrl_Mode_LUT[POWERAUTHO_POLICY_AWAKE] =	ELPCTRL_MODE_KEEP_AWAKE;
	pPowerAutho->m_ElpCtrl_Mode_LUT[POWERAUTHO_POLICY_PD] =		ELPCTRL_MODE_KEEP_AWAKE;
	pPowerAutho->m_ElpCtrl_Mode_LUT[POWERAUTHO_POLICY_ELP] =	ELPCTRL_MODE_NORMAL;

	pPowerAutho->hReport = hReport;
	pPowerAutho->hHalCtrl = hHalCtrl;

	return OK;
}

/****************************************************************************
 *                      powerAutho_PowerPolicyUpdate()
 ****************************************************************************
 * DESCRIPTION:	updates the PowerPolicy and calcs the new MinPowerPolicy of the sustem
 * 
 * INPUTS:	hMacServices - the handle to the MacServices module.
 *			aPowerPolicy - the new power policy.
 *		
 * 
 * OUTPUT:	none
 * 
 * RETURNS:	OK or NOK
 ****************************************************************************/
int MacServices_powerAutho_PowerPolicyUpdate(TI_HANDLE hMacServices, powerAutho_PowerPolicy_e aPowerPolicy)
{
	powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);

	WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
									("MacServices_powerAutho_PowerPolicyUpdate: PowerPolicy = %d\n",aPowerPolicy));

	pPowerAutho->m_PowerPolicy = aPowerPolicy;

	return powerAutho_CalcMinPowerLevel(pPowerAutho);	
}

/****************************************************************************
 *                      powerAutho_AwakeRequiredUpdate()
 ****************************************************************************
 * DESCRIPTION:	updates the AwakeRequired and calcs the new MinPowerPolicy of the sustem
 * 
 * INPUTS:	hMacServices - the handle to the MacServices module.
 *			aAwakeRequired - the awake required parameter,
 *				can be according to the enum required or not_required.	
 *			aAwakeReason - the reason that the HW is required
 * 
 * OUTPUT:	none
 * 
 * RETURNS:	OK or NOK
 ****************************************************************************/
int MacServices_powerAutho_AwakeRequiredUpdate(TI_HANDLE hMacServices, MacServices_powerAutho_AwakeRequired_e aAwakeRequired, MacServices_powerAutho_AwakeReason_e aAwakeReason)
{
	powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);

	if(aAwakeRequired == POWERAUTHO_AWAKE_REQUIRED)
	{
		pPowerAutho->m_AwakeRequired |= (1<<aAwakeReason);
	}
	else
	{ /* aAwakeRequired == POWERAUTHO_AWAKE_NOT_REQUIRED*/
		pPowerAutho->m_AwakeRequired &= ~(1<<aAwakeReason);
	}
	
	WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
									("MacServices_powerAutho_AwakeRequiredUpdate: awake required sent %d (reason %d) and the updated is %d\n", aAwakeRequired, aAwakeReason, pPowerAutho->m_AwakeRequired));
	
	return powerAutho_CalcMinPowerLevel(pPowerAutho);	
}

/****************************************************************************
 *                      powerAutho_CalcMinPowerLevel()
 ****************************************************************************
 * DESCRIPTION:	calculate the min power level
 * 
 * INPUTS:	hPowerAutho - the handle to the PowerAuthorization module.
 * 
 * OUTPUT:	none
 * 
 * RETURNS:	OK or NOK
 ****************************************************************************/
int powerAutho_CalcMinPowerLevel(TI_HANDLE hPowerAutho)
{
	powerAutho_t *pPowerAutho = (powerAutho_t*)hPowerAutho;
	powerAutho_PowerPolicy_e newMinPowerLevel;
	whalParamInfo_t ParamInfo;

	/* calc the new MinPowerLevel */
	if(pPowerAutho->m_AwakeRequired >  0)
		newMinPowerLevel = POWERAUTHO_POLICY_AWAKE;
	else
		newMinPowerLevel = pPowerAutho->m_PowerPolicy;

	/* check if the MinPowerLevel changed */
	if(pPowerAutho->m_MinPowerLevel != newMinPowerLevel)
	{
		WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
									("powerAutho_CalcMinPowerLevel - new MinPowerLevel is = %d\n",newMinPowerLevel));
			
		pPowerAutho->m_MinPowerLevel = newMinPowerLevel;

		/* we do the update of the FW only after the init complete*/
		if(pPowerAutho->initComplete == TRUE)
		{
			/* Update interface mode */
			whalCtrl_ElpCtrl_SetMode(pPowerAutho->hHalCtrl, pPowerAutho->m_ElpCtrl_Mode_LUT[newMinPowerLevel]);

			/* Send MIB with PowerPolicy */
			ParamInfo.paramType = (UINT32)HAL_CTRL_MIN_POWER_LEVEL;
			ParamInfo.paramLength = sizeof(powerAutho_PowerPolicy_e);
			ParamInfo.content.minPowerPolicy = newMinPowerLevel;
			whalCtrl_SetParam(pPowerAutho->hHalCtrl, &ParamInfo);
            return OK;
		}
	}

	return TNETWIF_COMPLETE;	
}

/****************************************************************************
 *                      powerAutho_PowerPolicyUpdate()
 ****************************************************************************
 * DESCRIPTION:	send the min power level to the FW for the first time
 * 
 * INPUTS:	hMacServices - the handle to the MacServices module.
 *		
 * 
 * OUTPUT:	none
 * 
 * RETURNS:	OK or NOK
 ****************************************************************************/
int MacServices_powerAutho_ExitFromInit(TI_HANDLE hMacServices)
{
	powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);
	whalParamInfo_t ParamInfo;

	WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
									("MacServices_powerAutho_ExitFromInit: PowerPolicy = %d\n",pPowerAutho->m_MinPowerLevel ));
	/* set as 'after init complete' */
	pPowerAutho->initComplete = TRUE;

	/* Update interface mode */
	whalCtrl_ElpCtrl_SetMode(pPowerAutho->hHalCtrl, pPowerAutho->m_ElpCtrl_Mode_LUT[pPowerAutho->m_MinPowerLevel]);

	/* Send MIB with PowerPolicy */
	ParamInfo.paramType = (UINT32)HAL_CTRL_MIN_POWER_LEVEL;
	ParamInfo.paramLength = sizeof(powerAutho_PowerPolicy_e);
	ParamInfo.content.minPowerPolicy = pPowerAutho->m_MinPowerLevel;
	whalCtrl_SetParam(pPowerAutho->hHalCtrl, &ParamInfo);

	return OK;
}


/****************************************************************************
 *                      MacServices_powerAutho_Endrecovery()
 ****************************************************************************
 * DESCRIPTION:	initialize module after recovery
 * 
 * INPUTS:	hMacServices - the handle to the MacServices module.
 *		
 * 
 * OUTPUT:	none
 * 
 * RETURNS:	OK or NOK
 ****************************************************************************/
int powerAutho_Restart(TI_HANDLE hMacServices)
{			
	powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);

		/* set as 'before init complete' */
	pPowerAutho->initComplete = FALSE; 
	
	pPowerAutho->m_PowerPolicy = POWERAUTHO_POLICY_AWAKE;
	pPowerAutho->m_MinPowerLevel = POWERAUTHO_POLICY_AWAKE;


	return pPowerAutho->m_MinPowerLevel;
}


/****************************************************************************
 *                      MacServices_powerAutho_Endrecovery()
 ****************************************************************************
 * DESCRIPTION:	updates the PowerPolicy and calcs the new MinPowerPolicy of the sustem
 * 
 * INPUTS:	hMacServices - the handle to the MacServices module.
 *		
 * 
 * OUTPUT:	none
 * 
 * RETURNS:	OK or NOK
 ****************************************************************************/
int MacServices_powerAutho_EndRecovery(TI_HANDLE hMacServices)
{
	powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);

	WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
									("MacServices_powerAutho_Endrecovery: PowerPolicy = %d\n",pPowerAutho->m_PowerPolicy));

	return powerAutho_CalcMinPowerLevel(pPowerAutho);	
}