blob: 942f371eaf672f01b1c35692a9aed38e682b3b91 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: power.c
21 *
Uwe Kleine-König0d743952010-06-11 12:17:04 +020022 * Purpose: Handles 802.11 power management functions
Forest Bond92b96792009-06-13 07:38:31 -040023 *
24 * Author: Lyndon Chen
25 *
26 * Date: July 17, 2002
27 *
28 * Functions:
29 * PSvEnablePowerSaving - Enable Power Saving Mode
30 * PSvDiasblePowerSaving - Disable Power Saving Mode
31 * PSbConsiderPowerDown - Decide if we can Power Down
32 * PSvSendPSPOLL - Send PS-POLL packet
33 * PSbSendNullPacket - Send Null packet
34 * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon
35 *
36 * Revision History:
37 *
38 */
39
Forest Bond92b96792009-06-13 07:38:31 -040040#include "ttype.h"
Forest Bond92b96792009-06-13 07:38:31 -040041#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040043#include "wmgr.h"
Forest Bond92b96792009-06-13 07:38:31 -040044#include "power.h"
Forest Bond92b96792009-06-13 07:38:31 -040045#include "wcmd.h"
Forest Bond92b96792009-06-13 07:38:31 -040046#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040047#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040048#include "control.h"
Forest Bond92b96792009-06-13 07:38:31 -040049#include "rndis.h"
Forest Bond92b96792009-06-13 07:38:31 -040050
51/*--------------------- Static Definitions -------------------------*/
52
Forest Bond92b96792009-06-13 07:38:31 -040053/*--------------------- Static Classes ----------------------------*/
54
55/*--------------------- Static Variables --------------------------*/
Philip Worrallf9cfbe92011-03-02 14:34:39 +000056static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040057/*--------------------- Static Functions --------------------------*/
58
Forest Bond92b96792009-06-13 07:38:31 -040059/*--------------------- Export Variables --------------------------*/
60
Forest Bond92b96792009-06-13 07:38:31 -040061/*--------------------- Export Functions --------------------------*/
62
Philip Worrall7404eab2011-03-02 14:34:40 +000063/*
Forest Bond92b96792009-06-13 07:38:31 -040064 *
65 * Routine Description:
66 * Enable hw power saving functions
67 *
68 * Return Value:
69 * None.
70 *
Philip Worrall7404eab2011-03-02 14:34:40 +000071 */
Forest Bond92b96792009-06-13 07:38:31 -040072
Andres More0cbd8d92010-05-06 20:34:29 -030073void PSvEnablePowerSaving(void *hDeviceContext,
74 WORD wListenInterval)
Forest Bond92b96792009-06-13 07:38:31 -040075{
Philip Worrallf9cfbe92011-03-02 14:34:39 +000076 PSDevice pDevice = (PSDevice)hDeviceContext;
77 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
78 WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15;
Forest Bond92b96792009-06-13 07:38:31 -040079
Philip Worrallf9cfbe92011-03-02 14:34:39 +000080 /* set period of power up before TBTT */
81 MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT);
Forest Bond92b96792009-06-13 07:38:31 -040082
Philip Worrallf9cfbe92011-03-02 14:34:39 +000083 if (pDevice->eOPMode != OP_MODE_ADHOC) {
84 /* set AID */
85 MACvWriteWord(pDevice, MAC_REG_AIDATIM, wAID);
86 } else {
Philip Worrall7404eab2011-03-02 14:34:40 +000087 /* set ATIM Window */
88 /* MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); */
Philip Worrallf9cfbe92011-03-02 14:34:39 +000089 }
Forest Bond92b96792009-06-13 07:38:31 -040090
Philip Worrall7404eab2011-03-02 14:34:40 +000091 /* Warren:06-18-2004,the sequence must follow PSEN->AUTOSLEEP->GO2DOZE */
92 /* enable power saving hw function */
Philip Worrallf9cfbe92011-03-02 14:34:39 +000093 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond92b96792009-06-13 07:38:31 -040094
Philip Worrall7404eab2011-03-02 14:34:40 +000095 /* Set AutoSleep */
Philip Worrallf9cfbe92011-03-02 14:34:39 +000096 MACvRegBitsOn(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
Forest Bond92b96792009-06-13 07:38:31 -040097
Philip Worrall7404eab2011-03-02 14:34:40 +000098 /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the AUTOSLEEP doesn't work */
Philip Worrallf9cfbe92011-03-02 14:34:39 +000099 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
Forest Bond92b96792009-06-13 07:38:31 -0400100
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000101 if (wListenInterval >= 2) {
Forest Bond92b96792009-06-13 07:38:31 -0400102
Philip Worrall7404eab2011-03-02 14:34:40 +0000103 /* clear always listen beacon */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000104 MACvRegBitsOff(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
Forest Bond92b96792009-06-13 07:38:31 -0400105
Philip Worrall7404eab2011-03-02 14:34:40 +0000106 /* first time set listen next beacon */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000107 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
Forest Bond92b96792009-06-13 07:38:31 -0400108
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000109 pMgmt->wCountToWakeUp = wListenInterval;
Forest Bond92b96792009-06-13 07:38:31 -0400110
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000111 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400112
Philip Worrall7404eab2011-03-02 14:34:40 +0000113 /* always listen beacon */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000114 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
Forest Bond92b96792009-06-13 07:38:31 -0400115
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000116 pMgmt->wCountToWakeUp = 0;
117 }
Forest Bond92b96792009-06-13 07:38:31 -0400118
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000119 pDevice->bEnablePSMode = TRUE;
120
121 if (pDevice->eOPMode == OP_MODE_ADHOC) {
122
Andres More0cbd8d92010-05-06 20:34:29 -0300123 /* bMgrPrepareBeaconToSend((void *) pDevice, pMgmt); */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000124
125 }
Philip Worrall7404eab2011-03-02 14:34:40 +0000126 /* We don't send null pkt in ad hoc mode since beacon will handle this. */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000127 else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
128 PSbSendNullPacket(pDevice);
129 }
130
131 pDevice->bPWBitOn = TRUE;
132 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n");
133 return;
Forest Bond92b96792009-06-13 07:38:31 -0400134}
135
Philip Worrall7404eab2011-03-02 14:34:40 +0000136/*
Forest Bond92b96792009-06-13 07:38:31 -0400137 *
138 * Routine Description:
139 * Disable hw power saving functions
140 *
141 * Return Value:
142 * None.
143 *
Philip Worrall7404eab2011-03-02 14:34:40 +0000144 */
Forest Bond92b96792009-06-13 07:38:31 -0400145
Andres More0cbd8d92010-05-06 20:34:29 -0300146void PSvDisablePowerSaving(void *hDeviceContext)
Forest Bond92b96792009-06-13 07:38:31 -0400147{
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000148 PSDevice pDevice = (PSDevice)hDeviceContext;
Philip Worrall7404eab2011-03-02 14:34:40 +0000149 /* PSMgmtObject pMgmt = &(pDevice->sMgmtObj); */
Forest Bond92b96792009-06-13 07:38:31 -0400150
Philip Worrall7404eab2011-03-02 14:34:40 +0000151 /* disable power saving hw function */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000152 CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_DISABLE_PS, 0,
153 0, 0, NULL);
Forest Bond92b96792009-06-13 07:38:31 -0400154
Philip Worrall7404eab2011-03-02 14:34:40 +0000155 /* clear AutoSleep */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000156 MACvRegBitsOff(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
Forest Bond92b96792009-06-13 07:38:31 -0400157
Philip Worrall7404eab2011-03-02 14:34:40 +0000158 /* set always listen beacon */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000159 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
160 pDevice->bEnablePSMode = FALSE;
Forest Bond92b96792009-06-13 07:38:31 -0400161
Philip Worrall036dba12011-03-02 14:34:41 +0000162 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000163 PSbSendNullPacket(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -0400164
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000165 pDevice->bPWBitOn = FALSE;
166 return;
Forest Bond92b96792009-06-13 07:38:31 -0400167}
168
Philip Worrall7404eab2011-03-02 14:34:40 +0000169/*
Forest Bond92b96792009-06-13 07:38:31 -0400170 *
171 * Routine Description:
172 * Consider to power down when no more packets to tx or rx.
173 *
174 * Return Value:
175 * TRUE, if power down success
176 * FALSE, if fail
Philip Worrall7404eab2011-03-02 14:34:40 +0000177 */
Forest Bond92b96792009-06-13 07:38:31 -0400178
Andres More0cbd8d92010-05-06 20:34:29 -0300179BOOL PSbConsiderPowerDown(void *hDeviceContext,
180 BOOL bCheckRxDMA,
181 BOOL bCheckCountToWakeUp)
Forest Bond92b96792009-06-13 07:38:31 -0400182{
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000183 PSDevice pDevice = (PSDevice)hDeviceContext;
184 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
185 BYTE byData;
Forest Bond92b96792009-06-13 07:38:31 -0400186
Philip Worrall7404eab2011-03-02 14:34:40 +0000187 /* check if already in Doze mode */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000188 ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG,
189 MAC_REG_PSCTL, &byData);
Forest Bond92b96792009-06-13 07:38:31 -0400190
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000191 if ( (byData & PSCTL_PS) != 0 )
192 return TRUE;
Forest Bond92b96792009-06-13 07:38:31 -0400193
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000194 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
Philip Worrall7404eab2011-03-02 14:34:40 +0000195 /* check if in TIM wake period */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000196 if (pMgmt->bInTIMWake)
197 return FALSE;
198 }
Forest Bond92b96792009-06-13 07:38:31 -0400199
Philip Worrall7404eab2011-03-02 14:34:40 +0000200 /* check scan state */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000201 if (pDevice->bCmdRunning)
202 return FALSE;
Forest Bond92b96792009-06-13 07:38:31 -0400203
Philip Worrall7404eab2011-03-02 14:34:40 +0000204 /* Tx Burst */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000205 if ( pDevice->bPSModeTxBurst )
206 return FALSE;
Forest Bond92b96792009-06-13 07:38:31 -0400207
Philip Worrall7404eab2011-03-02 14:34:40 +0000208 /* Froce PSEN on */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000209 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond92b96792009-06-13 07:38:31 -0400210
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000211 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
212 if (bCheckCountToWakeUp && (pMgmt->wCountToWakeUp == 0
213 || pMgmt->wCountToWakeUp == 1)) {
214 return FALSE;
215 }
216 }
Forest Bond92b96792009-06-13 07:38:31 -0400217
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000218 pDevice->bPSRxBeacon = TRUE;
Forest Bond92b96792009-06-13 07:38:31 -0400219
Philip Worrall7404eab2011-03-02 14:34:40 +0000220 /* no Tx, no Rx isr, now go to Doze */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000221 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
223 return TRUE;
Forest Bond92b96792009-06-13 07:38:31 -0400224}
225
Philip Worrall7404eab2011-03-02 14:34:40 +0000226/*
Forest Bond92b96792009-06-13 07:38:31 -0400227 *
228 * Routine Description:
229 * Send PS-POLL packet
230 *
231 * Return Value:
232 * None.
233 *
Philip Worrall7404eab2011-03-02 14:34:40 +0000234 */
Forest Bond92b96792009-06-13 07:38:31 -0400235
Andres More0cbd8d92010-05-06 20:34:29 -0300236void PSvSendPSPOLL(void *hDeviceContext)
Forest Bond92b96792009-06-13 07:38:31 -0400237{
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000238 PSDevice pDevice = (PSDevice)hDeviceContext;
239 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
240 PSTxMgmtPacket pTxPacket = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400241
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000242 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
243 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
244 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
245 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
246 (
247 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
248 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
249 WLAN_SET_FC_PWRMGT(0)
250 ));
Forest Bond92b96792009-06-13 07:38:31 -0400251
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000252 pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
253 memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
254 memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
255 pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
256 pTxPacket->cbPayloadLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400257
Philip Worrall7404eab2011-03-02 14:34:40 +0000258 /* send the frame */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000259 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
260 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n");
261 } else {
Philip Worrall7404eab2011-03-02 14:34:40 +0000262 /* DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n"); */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000263 };
264 return;
Forest Bond92b96792009-06-13 07:38:31 -0400265}
266
Philip Worrall7404eab2011-03-02 14:34:40 +0000267/*
Forest Bond92b96792009-06-13 07:38:31 -0400268 *
269 * Routine Description:
270 * Send NULL packet to AP for notification power state of STA
271 *
272 * Return Value:
273 * None.
274 *
Philip Worrall7404eab2011-03-02 14:34:40 +0000275 */
Andres More0cbd8d92010-05-06 20:34:29 -0300276
277BOOL PSbSendNullPacket(void *hDeviceContext)
Forest Bond92b96792009-06-13 07:38:31 -0400278{
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000279 PSDevice pDevice = (PSDevice)hDeviceContext;
280 PSTxMgmtPacket pTxPacket = NULL;
281 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
Forest Bond92b96792009-06-13 07:38:31 -0400282
Philip Worrall036dba12011-03-02 14:34:41 +0000283 if (pDevice->bLinkPass == FALSE)
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000284 return FALSE;
Forest Bond92b96792009-06-13 07:38:31 -0400285
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000286 if ((pDevice->bEnablePSMode == FALSE) &&
Philip Worrall036dba12011-03-02 14:34:41 +0000287 (pDevice->fTxDataInSleep == FALSE)) {
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000288 return FALSE;
289 }
Forest Bond92b96792009-06-13 07:38:31 -0400290
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000291 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
292 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
293 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
Forest Bond92b96792009-06-13 07:38:31 -0400294
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000295 if (pDevice->bEnablePSMode) {
296 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
297 (
298 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
299 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
300 WLAN_SET_FC_PWRMGT(1)
301 ));
302 } else {
303 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
304 (
305 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
306 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
307 WLAN_SET_FC_PWRMGT(0)
308 ));
309 }
Andres Morefeaf03d2010-06-25 20:20:58 -0300310
Philip Worrall036dba12011-03-02 14:34:41 +0000311 if(pMgmt->eCurrMode != WMAC_MODE_IBSS_STA)
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000312 pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_TODS(1));
Forest Bond92b96792009-06-13 07:38:31 -0400313
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000314 memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
315 memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
316 memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
317 pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
318 pTxPacket->cbPayloadLen = 0;
Philip Worrall7404eab2011-03-02 14:34:40 +0000319 /* send the frame */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000320 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
321 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
322 return FALSE;
323 } else {
Philip Worrall7404eab2011-03-02 14:34:40 +0000324 /* DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n"); */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000325 }
Forest Bond92b96792009-06-13 07:38:31 -0400326
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000327 return TRUE ;
Forest Bond92b96792009-06-13 07:38:31 -0400328}
329
Philip Worrall7404eab2011-03-02 14:34:40 +0000330/*
Forest Bond92b96792009-06-13 07:38:31 -0400331 *
332 * Routine Description:
333 * Check if Next TBTT must wake up
334 *
335 * Return Value:
336 * None.
337 *
Philip Worrall7404eab2011-03-02 14:34:40 +0000338 */
Forest Bond92b96792009-06-13 07:38:31 -0400339
Andres More0cbd8d92010-05-06 20:34:29 -0300340BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext)
Forest Bond92b96792009-06-13 07:38:31 -0400341{
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000342 PSDevice pDevice = (PSDevice)hDeviceContext;
343 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
344 BOOL bWakeUp = FALSE;
Forest Bond92b96792009-06-13 07:38:31 -0400345
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000346 if (pMgmt->wListenInterval >= 2) {
Philip Worrall036dba12011-03-02 14:34:41 +0000347 if (pMgmt->wCountToWakeUp == 0)
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000348 pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
Forest Bond92b96792009-06-13 07:38:31 -0400349
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000350 pMgmt->wCountToWakeUp --;
Forest Bond92b96792009-06-13 07:38:31 -0400351
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000352 if (pMgmt->wCountToWakeUp == 1) {
Philip Worrall7404eab2011-03-02 14:34:40 +0000353 /* Turn on wake up to listen next beacon */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000354 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
355 pDevice->bPSRxBeacon = FALSE;
356 bWakeUp = TRUE;
357 } else if ( !pDevice->bPSRxBeacon ) {
Philip Worrall7404eab2011-03-02 14:34:40 +0000358 /* Listen until RxBeacon */
Philip Worrallf9cfbe92011-03-02 14:34:39 +0000359 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
360 }
361 }
362 return bWakeUp;
Forest Bond92b96792009-06-13 07:38:31 -0400363}
364