2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
22 * Purpose: Handles 802.11 power managment 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
51 /*--------------------- Static Definitions -------------------------*/
56 /*--------------------- Static Classes ----------------------------*/
58 /*--------------------- Static Variables --------------------------*/
59 static int msglevel =MSG_LEVEL_INFO;
60 /*--------------------- Static Functions --------------------------*/
63 /*--------------------- Export Variables --------------------------*/
66 /*--------------------- Export Functions --------------------------*/
70 * Routine Description:
71 * Enable hw power saving functions
81 IN HANDLE hDeviceContext,
82 IN WORD wListenInterval
85 PSDevice pDevice = (PSDevice)hDeviceContext;
86 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
87 WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15;
89 // set period of power up before TBTT
90 MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT);
92 if (pDevice->eOPMode != OP_MODE_ADHOC) {
94 MACvWriteWord(pDevice, MAC_REG_AIDATIM, wAID);
97 //MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
100 //Warren:06-18-2004,the sequence must follow PSEN->AUTOSLEEP->GO2DOZE
101 // enable power saving hw function
102 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
104 MACvRegBitsOn(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
106 //Warren:MUST turn on this once before turn on AUTOSLEEP ,or the AUTOSLEEP doesn't work
107 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
110 if (wListenInterval >= 2) {
112 // clear always listen beacon
113 MACvRegBitsOff(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
114 // first time set listen next beacon
115 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
117 pMgmt->wCountToWakeUp = wListenInterval;
122 // always listen beacon
123 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
124 pMgmt->wCountToWakeUp = 0;
128 pDevice->bEnablePSMode = TRUE;
130 if (pDevice->eOPMode == OP_MODE_ADHOC) {
131 // bMgrPrepareBeaconToSend((HANDLE)pDevice, pMgmt);
133 // We don't send null pkt in ad hoc mode since beacon will handle this.
134 else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
135 PSbSendNullPacket(pDevice);
137 pDevice->bPWBitOn = TRUE;
138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n");
149 * Routine Description:
150 * Disable hw power saving functions
158 PSvDisablePowerSaving(
159 IN HANDLE hDeviceContext
162 PSDevice pDevice = (PSDevice)hDeviceContext;
163 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
166 // disable power saving hw function
167 CONTROLnsRequestOut(pDevice,
168 MESSAGE_TYPE_DISABLE_PS,
176 MACvRegBitsOff(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
178 // set always listen beacon
179 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
181 pDevice->bEnablePSMode = FALSE;
183 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
184 PSbSendNullPacket(pDevice);
186 pDevice->bPWBitOn = FALSE;
193 * Routine Description:
194 * Consider to power down when no more packets to tx or rx.
197 * TRUE, if power down success
203 PSbConsiderPowerDown(
204 IN HANDLE hDeviceContext,
206 IN BOOL bCheckCountToWakeUp
209 PSDevice pDevice = (PSDevice)hDeviceContext;
210 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
214 // check if already in Doze mode
215 ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
216 if ( (byData & PSCTL_PS) != 0 )
219 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
220 // check if in TIM wake period
221 if (pMgmt->bInTIMWake)
226 if (pDevice->bCmdRunning)
230 if ( pDevice->bPSModeTxBurst )
234 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
236 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
237 if (bCheckCountToWakeUp &&
238 (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
243 pDevice->bPSRxBeacon = TRUE;
244 // no Tx, no Rx isr, now go to Doze
245 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
255 * Routine Description:
256 * Send PS-POLL packet
267 IN HANDLE hDeviceContext
270 PSDevice pDevice = (PSDevice)hDeviceContext;
271 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
272 PSTxMgmtPacket pTxPacket = NULL;
275 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
276 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
277 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
278 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
280 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
281 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
282 WLAN_SET_FC_PWRMGT(0)
284 pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
285 memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
286 memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
287 pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
288 pTxPacket->cbPayloadLen = 0;
290 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
291 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n");
294 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
304 * Routine Description:
305 * Send NULL packet to AP for notification power state of STA
313 IN HANDLE hDeviceContext
316 PSDevice pDevice = (PSDevice)hDeviceContext;
317 PSTxMgmtPacket pTxPacket = NULL;
318 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
322 if (pDevice->bLinkPass == FALSE) {
326 //2007-0115-03<Add>by MikeLiu
328 if ((pDevice->bEnablePSMode == FALSE) &&
329 (pDevice->fTxDataInSleep == FALSE)){
333 if (pDevice->bEnablePSMode == FALSE) {
337 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
338 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
339 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
341 if (pDevice->bEnablePSMode) {
343 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
345 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
346 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
347 WLAN_SET_FC_PWRMGT(1)
351 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
353 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
354 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
355 WLAN_SET_FC_PWRMGT(0)
359 if(pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
360 pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_TODS(1));
363 memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
364 memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
365 memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
366 pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
367 pTxPacket->cbPayloadLen = 0;
369 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
374 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
383 * Routine Description:
384 * Check if Next TBTT must wake up
393 IN HANDLE hDeviceContext
397 PSDevice pDevice = (PSDevice)hDeviceContext;
398 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
399 BOOL bWakeUp = FALSE;
401 if (pMgmt->wListenInterval >= 2) {
402 if (pMgmt->wCountToWakeUp == 0) {
403 pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
406 pMgmt->wCountToWakeUp --;
408 if (pMgmt->wCountToWakeUp == 1) {
410 // Turn on wake up to listen next beacon
411 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
412 pDevice->bPSRxBeacon = FALSE;
415 } else if ( !pDevice->bPSRxBeacon ) {
416 //Listen until RxBeacon
417 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);