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 management 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 -------------------------*/
53 /*--------------------- Static Classes ----------------------------*/
55 /*--------------------- Static Variables --------------------------*/
56 static int msglevel =MSG_LEVEL_INFO;
57 /*--------------------- Static Functions --------------------------*/
59 /*--------------------- Export Variables --------------------------*/
61 /*--------------------- Export Functions --------------------------*/
65 * Routine Description:
66 * Enable hw power saving functions
73 void PSvEnablePowerSaving(void *hDeviceContext,
76 PSDevice pDevice = (PSDevice)hDeviceContext;
77 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
78 WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15;
80 // set period of power up before TBTT
81 MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT);
83 if (pDevice->eOPMode != OP_MODE_ADHOC) {
85 MACvWriteWord(pDevice, MAC_REG_AIDATIM, wAID);
88 //MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
91 //Warren:06-18-2004,the sequence must follow PSEN->AUTOSLEEP->GO2DOZE
92 // enable power saving hw function
93 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
95 MACvRegBitsOn(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
97 //Warren:MUST turn on this once before turn on AUTOSLEEP ,or the AUTOSLEEP doesn't work
98 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
101 if (wListenInterval >= 2) {
103 // clear always listen beacon
104 MACvRegBitsOff(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
105 // first time set listen next beacon
106 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
108 pMgmt->wCountToWakeUp = wListenInterval;
113 // always listen beacon
114 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
115 pMgmt->wCountToWakeUp = 0;
119 pDevice->bEnablePSMode = TRUE;
121 if (pDevice->eOPMode == OP_MODE_ADHOC) {
122 /* bMgrPrepareBeaconToSend((void *) pDevice, pMgmt); */
124 // We don't send null pkt in ad hoc mode since beacon will handle this.
125 else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
126 PSbSendNullPacket(pDevice);
128 pDevice->bPWBitOn = TRUE;
129 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n");
135 * Routine Description:
136 * Disable hw power saving functions
143 void PSvDisablePowerSaving(void *hDeviceContext)
145 PSDevice pDevice = (PSDevice)hDeviceContext;
146 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
149 // disable power saving hw function
150 CONTROLnsRequestOut(pDevice,
151 MESSAGE_TYPE_DISABLE_PS,
159 MACvRegBitsOff(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
161 // set always listen beacon
162 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
164 pDevice->bEnablePSMode = FALSE;
166 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
167 PSbSendNullPacket(pDevice);
169 pDevice->bPWBitOn = FALSE;
175 * Routine Description:
176 * Consider to power down when no more packets to tx or rx.
179 * TRUE, if power down success
183 BOOL PSbConsiderPowerDown(void *hDeviceContext,
185 BOOL bCheckCountToWakeUp)
187 PSDevice pDevice = (PSDevice)hDeviceContext;
188 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
192 // check if already in Doze mode
193 ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
194 if ( (byData & PSCTL_PS) != 0 )
197 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
198 // check if in TIM wake period
199 if (pMgmt->bInTIMWake)
204 if (pDevice->bCmdRunning)
208 if ( pDevice->bPSModeTxBurst )
212 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
214 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
215 if (bCheckCountToWakeUp &&
216 (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
221 pDevice->bPSRxBeacon = TRUE;
222 // no Tx, no Rx isr, now go to Doze
223 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
231 * Routine Description:
232 * Send PS-POLL packet
239 void PSvSendPSPOLL(void *hDeviceContext)
241 PSDevice pDevice = (PSDevice)hDeviceContext;
242 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
243 PSTxMgmtPacket pTxPacket = NULL;
246 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
247 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
248 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
249 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
251 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
252 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
253 WLAN_SET_FC_PWRMGT(0)
255 pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
256 memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
257 memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
258 pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
259 pTxPacket->cbPayloadLen = 0;
261 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n");
265 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
273 * Routine Description:
274 * Send NULL packet to AP for notification power state of STA
281 BOOL PSbSendNullPacket(void *hDeviceContext)
283 PSDevice pDevice = (PSDevice)hDeviceContext;
284 PSTxMgmtPacket pTxPacket = NULL;
285 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
289 if (pDevice->bLinkPass == FALSE) {
293 if ((pDevice->bEnablePSMode == FALSE) &&
294 (pDevice->fTxDataInSleep == FALSE)){
298 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
299 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
300 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
302 if (pDevice->bEnablePSMode) {
304 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
306 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
307 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
308 WLAN_SET_FC_PWRMGT(1)
312 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
314 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
315 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
316 WLAN_SET_FC_PWRMGT(0)
320 if(pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
321 pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_TODS(1));
324 memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
325 memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
326 memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
327 pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
328 pTxPacket->cbPayloadLen = 0;
330 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
335 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
344 * Routine Description:
345 * Check if Next TBTT must wake up
352 BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext)
355 PSDevice pDevice = (PSDevice)hDeviceContext;
356 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
357 BOOL bWakeUp = FALSE;
359 if (pMgmt->wListenInterval >= 2) {
360 if (pMgmt->wCountToWakeUp == 0) {
361 pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
364 pMgmt->wCountToWakeUp --;
366 if (pMgmt->wCountToWakeUp == 1) {
368 // Turn on wake up to listen next beacon
369 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
370 pDevice->bPSRxBeacon = FALSE;
373 } else if ( !pDevice->bPSRxBeacon ) {
374 //Listen until RxBeacon
375 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);