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(struct vnt_private
*pDevice
, u16 wListenInterval
)
75 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
76 u16 wAID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
78 /* set period of power up before TBTT */
79 MACvWriteWord(pDevice
, MAC_REG_PWBT
, C_PWBT
);
81 if (pDevice
->eOPMode
!= OP_MODE_ADHOC
) {
83 MACvWriteWord(pDevice
, MAC_REG_AIDATIM
, wAID
);
86 /* MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); */
89 /* Warren:06-18-2004,the sequence must follow PSEN->AUTOSLEEP->GO2DOZE */
90 /* enable power saving hw function */
91 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_PSEN
);
94 MACvRegBitsOn(pDevice
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
96 /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the AUTOSLEEP doesn't work */
97 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
99 if (wListenInterval
>= 2) {
101 /* clear always listen beacon */
102 MACvRegBitsOff(pDevice
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
104 /* first time set listen next beacon */
105 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_LNBCN
);
107 pMgmt
->wCountToWakeUp
= wListenInterval
;
111 /* always listen beacon */
112 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
114 pMgmt
->wCountToWakeUp
= 0;
117 pDevice
->bEnablePSMode
= true;
119 /* We don't send null pkt in ad hoc mode since beacon will handle this. */
120 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
)
121 PSbSendNullPacket(pDevice
);
123 pDevice
->bPWBitOn
= true;
124 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PS:Power Saving Mode Enable...\n");
129 * Routine Description:
130 * Disable hw power saving functions
137 void PSvDisablePowerSaving(struct vnt_private
*pDevice
)
140 /* disable power saving hw function */
141 CONTROLnsRequestOut(pDevice
, MESSAGE_TYPE_DISABLE_PS
, 0,
144 /* clear AutoSleep */
145 MACvRegBitsOff(pDevice
, MAC_REG_PSCFG
, PSCFG_AUTOSLEEP
);
147 /* set always listen beacon */
148 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_ALBCN
);
149 pDevice
->bEnablePSMode
= false;
151 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
)
152 PSbSendNullPacket(pDevice
);
154 pDevice
->bPWBitOn
= false;
159 * Routine Description:
160 * Consider to power down when no more packets to tx or rx.
163 * true, if power down success
167 int PSbConsiderPowerDown(struct vnt_private
*pDevice
, int bCheckRxDMA
,
168 int bCheckCountToWakeUp
)
170 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
173 /* check if already in Doze mode */
174 ControlvReadByte(pDevice
, MESSAGE_REQUEST_MACREG
,
175 MAC_REG_PSCTL
, &byData
);
177 if ((byData
& PSCTL_PS
) != 0)
180 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
181 /* check if in TIM wake period */
182 if (pMgmt
->bInTIMWake
)
186 /* check scan state */
187 if (pDevice
->bCmdRunning
)
191 if (pDevice
->bPSModeTxBurst
)
195 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_PSEN
);
197 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
) {
198 if (bCheckCountToWakeUp
&& (pMgmt
->wCountToWakeUp
== 0
199 || pMgmt
->wCountToWakeUp
== 1)) {
204 pDevice
->bPSRxBeacon
= true;
206 /* no Tx, no Rx isr, now go to Doze */
207 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_GO2DOZE
);
208 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Go to Doze ZZZZZZZZZZZZZZZ\n");
214 * Routine Description:
215 * Send PS-POLL packet
222 void PSvSendPSPOLL(struct vnt_private
*pDevice
)
224 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
225 struct vnt_tx_mgmt
*pTxPacket
= NULL
;
227 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(struct vnt_tx_mgmt
)
228 + WLAN_HDR_ADDR2_LEN
);
229 pTxPacket
= (struct vnt_tx_mgmt
*)pMgmt
->pbyPSPacketPool
;
230 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((u8
*)pTxPacket
231 + sizeof(struct vnt_tx_mgmt
));
233 pTxPacket
->p80211Header
->sA2
.wFrameCtl
= cpu_to_le16(
235 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL
) |
236 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL
) |
237 WLAN_SET_FC_PWRMGT(0)
240 pTxPacket
->p80211Header
->sA2
.wDurationID
= pMgmt
->wCurrAID
| BIT14
| BIT15
;
241 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
242 memcpy(pTxPacket
->p80211Header
->sA2
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
243 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR2_LEN
;
244 pTxPacket
->cbPayloadLen
= 0;
246 /* log failure if sending failed */
247 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
248 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send PS-Poll packet failed..\n");
254 * Routine Description:
255 * Send NULL packet to AP for notification power state of STA
262 int PSbSendNullPacket(struct vnt_private
*pDevice
)
264 struct vnt_tx_mgmt
*pTxPacket
= NULL
;
265 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
268 if (pDevice
->bLinkPass
== false)
271 if ((pDevice
->bEnablePSMode
== false) &&
272 (pDevice
->fTxDataInSleep
== false)) {
276 memset(pMgmt
->pbyPSPacketPool
, 0, sizeof(struct vnt_tx_mgmt
)
277 + WLAN_NULLDATA_FR_MAXLEN
);
278 pTxPacket
= (struct vnt_tx_mgmt
*)pMgmt
->pbyPSPacketPool
;
279 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((u8
*)pTxPacket
280 + sizeof(struct vnt_tx_mgmt
));
282 flags
= WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA
) |
283 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL
);
285 if (pDevice
->bEnablePSMode
)
286 flags
|= WLAN_SET_FC_PWRMGT(1);
288 flags
|= WLAN_SET_FC_PWRMGT(0);
290 pTxPacket
->p80211Header
->sA3
.wFrameCtl
= cpu_to_le16(flags
);
292 if (pMgmt
->eCurrMode
!= WMAC_MODE_IBSS_STA
)
293 pTxPacket
->p80211Header
->sA3
.wFrameCtl
|= cpu_to_le16((u16
)WLAN_SET_FC_TODS(1));
295 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr1
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
296 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
297 memcpy(pTxPacket
->p80211Header
->sA3
.abyAddr3
, pMgmt
->abyCurrBSSID
, WLAN_BSSID_LEN
);
298 pTxPacket
->cbMPDULen
= WLAN_HDR_ADDR3_LEN
;
299 pTxPacket
->cbPayloadLen
= 0;
300 /* log error if sending failed */
301 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
302 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send Null Packet failed !\n");
310 * Routine Description:
311 * Check if Next TBTT must wake up
318 int PSbIsNextTBTTWakeUp(struct vnt_private
*pDevice
)
320 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
323 if (pMgmt
->wListenInterval
>= 2) {
324 if (pMgmt
->wCountToWakeUp
== 0)
325 pMgmt
->wCountToWakeUp
= pMgmt
->wListenInterval
;
327 pMgmt
->wCountToWakeUp
--;
329 if (pMgmt
->wCountToWakeUp
== 1) {
330 /* Turn on wake up to listen next beacon */
331 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_LNBCN
);
332 pDevice
->bPSRxBeacon
= false;
334 } else if (!pDevice
->bPSRxBeacon
) {
335 /* Listen until RxBeacon */
336 MACvRegBitsOn(pDevice
, MAC_REG_PSCTL
, PSCTL_LNBCN
);
This page took 0.052329 seconds and 5 git commands to generate.