Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1 | /* |
| 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önig | 0d74395 | 2010-06-11 12:17:04 +0200 | [diff] [blame] | 22 | * Purpose: Handles 802.11 power management functions |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 23 | * |
| 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 Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 40 | #include "ttype.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 41 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 42 | #include "device.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 43 | #include "wmgr.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 44 | #include "power.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 45 | #include "wcmd.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 46 | #include "rxtx.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 47 | #include "card.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 48 | #include "control.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 49 | #include "rndis.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 50 | |
| 51 | /*--------------------- Static Definitions -------------------------*/ |
| 52 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 53 | /*--------------------- Static Classes ----------------------------*/ |
| 54 | |
| 55 | /*--------------------- Static Variables --------------------------*/ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 56 | static int msglevel = MSG_LEVEL_INFO; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 57 | /*--------------------- Static Functions --------------------------*/ |
| 58 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 59 | /*--------------------- Export Variables --------------------------*/ |
| 60 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 61 | /*--------------------- Export Functions --------------------------*/ |
| 62 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 63 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 64 | * |
| 65 | * Routine Description: |
| 66 | * Enable hw power saving functions |
| 67 | * |
| 68 | * Return Value: |
| 69 | * None. |
| 70 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 71 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 72 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 73 | void PSvEnablePowerSaving(void *hDeviceContext, |
| 74 | WORD wListenInterval) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 75 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 76 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 77 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 78 | WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 79 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 80 | /* set period of power up before TBTT */ |
| 81 | MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 82 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 83 | if (pDevice->eOPMode != OP_MODE_ADHOC) { |
| 84 | /* set AID */ |
| 85 | MACvWriteWord(pDevice, MAC_REG_AIDATIM, wAID); |
| 86 | } else { |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 87 | /* set ATIM Window */ |
| 88 | /* MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 89 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 90 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 91 | /* Warren:06-18-2004,the sequence must follow PSEN->AUTOSLEEP->GO2DOZE */ |
| 92 | /* enable power saving hw function */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 93 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 94 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 95 | /* Set AutoSleep */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 96 | MACvRegBitsOn(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 97 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 98 | /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the AUTOSLEEP doesn't work */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 99 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 100 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 101 | if (wListenInterval >= 2) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 102 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 103 | /* clear always listen beacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 104 | MACvRegBitsOff(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 105 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 106 | /* first time set listen next beacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 107 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 108 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 109 | pMgmt->wCountToWakeUp = wListenInterval; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 110 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 111 | } else { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 112 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 113 | /* always listen beacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 114 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 115 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 116 | pMgmt->wCountToWakeUp = 0; |
| 117 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 118 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 119 | pDevice->bEnablePSMode = TRUE; |
| 120 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 121 | /* We don't send null pkt in ad hoc mode since beacon will handle this. */ |
Philip Worrall | 8c81161 | 2011-03-02 14:34:45 +0000 | [diff] [blame^] | 122 | if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 123 | PSbSendNullPacket(pDevice); |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 124 | |
| 125 | pDevice->bPWBitOn = TRUE; |
Philip Worrall | c5b0b5f | 2011-03-02 14:34:43 +0000 | [diff] [blame] | 126 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable...\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 129 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 130 | * |
| 131 | * Routine Description: |
| 132 | * Disable hw power saving functions |
| 133 | * |
| 134 | * Return Value: |
| 135 | * None. |
| 136 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 137 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 138 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 139 | void PSvDisablePowerSaving(void *hDeviceContext) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 140 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 141 | PSDevice pDevice = (PSDevice)hDeviceContext; |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 142 | /* PSMgmtObject pMgmt = &(pDevice->sMgmtObj); */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 143 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 144 | /* disable power saving hw function */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 145 | CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_DISABLE_PS, 0, |
| 146 | 0, 0, NULL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 147 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 148 | /* clear AutoSleep */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 149 | MACvRegBitsOff(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 150 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 151 | /* set always listen beacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 152 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); |
| 153 | pDevice->bEnablePSMode = FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 154 | |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame] | 155 | if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 156 | PSbSendNullPacket(pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 157 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 158 | pDevice->bPWBitOn = FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 159 | } |
| 160 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 161 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 162 | * |
| 163 | * Routine Description: |
| 164 | * Consider to power down when no more packets to tx or rx. |
| 165 | * |
| 166 | * Return Value: |
| 167 | * TRUE, if power down success |
| 168 | * FALSE, if fail |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 169 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 170 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 171 | BOOL PSbConsiderPowerDown(void *hDeviceContext, |
| 172 | BOOL bCheckRxDMA, |
| 173 | BOOL bCheckCountToWakeUp) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 174 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 175 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 176 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 177 | BYTE byData; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 178 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 179 | /* check if already in Doze mode */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 180 | ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, |
| 181 | MAC_REG_PSCTL, &byData); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 182 | |
Philip Worrall | c5b0b5f | 2011-03-02 14:34:43 +0000 | [diff] [blame] | 183 | if ((byData & PSCTL_PS) != 0) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 184 | return TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 185 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 186 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 187 | /* check if in TIM wake period */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 188 | if (pMgmt->bInTIMWake) |
| 189 | return FALSE; |
| 190 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 191 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 192 | /* check scan state */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 193 | if (pDevice->bCmdRunning) |
| 194 | return FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 195 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 196 | /* Tx Burst */ |
Philip Worrall | c5b0b5f | 2011-03-02 14:34:43 +0000 | [diff] [blame] | 197 | if (pDevice->bPSModeTxBurst) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 198 | return FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 199 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 200 | /* Froce PSEN on */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 201 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 202 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 203 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { |
| 204 | if (bCheckCountToWakeUp && (pMgmt->wCountToWakeUp == 0 |
| 205 | || pMgmt->wCountToWakeUp == 1)) { |
| 206 | return FALSE; |
| 207 | } |
| 208 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 209 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 210 | pDevice->bPSRxBeacon = TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 211 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 212 | /* no Tx, no Rx isr, now go to Doze */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 213 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE); |
| 214 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n"); |
| 215 | return TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 216 | } |
| 217 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 218 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 219 | * |
| 220 | * Routine Description: |
| 221 | * Send PS-POLL packet |
| 222 | * |
| 223 | * Return Value: |
| 224 | * None. |
| 225 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 226 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 227 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 228 | void PSvSendPSPOLL(void *hDeviceContext) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 229 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 230 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 231 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 232 | PSTxMgmtPacket pTxPacket = NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 233 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 234 | memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN); |
| 235 | pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; |
| 236 | pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); |
| 237 | pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16( |
| 238 | ( |
| 239 | WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) | |
| 240 | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) | |
| 241 | WLAN_SET_FC_PWRMGT(0) |
| 242 | )); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 243 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 244 | pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15; |
| 245 | memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN); |
| 246 | memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN); |
| 247 | pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN; |
| 248 | pTxPacket->cbPayloadLen = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 249 | |
Philip Worrall | e25b75e | 2011-03-02 14:34:42 +0000 | [diff] [blame] | 250 | /* log failure if sending failed */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 251 | if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { |
| 252 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n"); |
Philip Worrall | e25b75e | 2011-03-02 14:34:42 +0000 | [diff] [blame] | 253 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 256 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 257 | * |
| 258 | * Routine Description: |
| 259 | * Send NULL packet to AP for notification power state of STA |
| 260 | * |
| 261 | * Return Value: |
| 262 | * None. |
| 263 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 264 | */ |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 265 | |
| 266 | BOOL PSbSendNullPacket(void *hDeviceContext) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 267 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 268 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 269 | PSTxMgmtPacket pTxPacket = NULL; |
| 270 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
Philip Worrall | b898cf2 | 2011-03-02 17:36:35 +0000 | [diff] [blame] | 271 | u16 flags = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 272 | |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame] | 273 | if (pDevice->bLinkPass == FALSE) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 274 | return FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 275 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 276 | if ((pDevice->bEnablePSMode == FALSE) && |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame] | 277 | (pDevice->fTxDataInSleep == FALSE)) { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 278 | return FALSE; |
| 279 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 280 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 281 | memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN); |
| 282 | pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; |
| 283 | pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 284 | |
Philip Worrall | b898cf2 | 2011-03-02 17:36:35 +0000 | [diff] [blame] | 285 | flags = WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) | |
| 286 | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL); |
| 287 | |
| 288 | if (pDevice->bEnablePSMode) |
| 289 | flags |= WLAN_SET_FC_PWRMGT(1); |
| 290 | else |
| 291 | flags |= WLAN_SET_FC_PWRMGT(0); |
| 292 | |
| 293 | pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(flags); |
Andres More | feaf03d | 2010-06-25 20:20:58 -0300 | [diff] [blame] | 294 | |
Philip Worrall | c5b0b5f | 2011-03-02 14:34:43 +0000 | [diff] [blame] | 295 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 296 | pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_TODS(1)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 297 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 298 | memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN); |
| 299 | memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN); |
| 300 | memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN); |
| 301 | pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN; |
| 302 | pTxPacket->cbPayloadLen = 0; |
Philip Worrall | e25b75e | 2011-03-02 14:34:42 +0000 | [diff] [blame] | 303 | /* log error if sending failed */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 304 | if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { |
| 305 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n"); |
| 306 | return FALSE; |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 307 | } |
Philip Worrall | e25b75e | 2011-03-02 14:34:42 +0000 | [diff] [blame] | 308 | return TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 309 | } |
| 310 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 311 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 312 | * |
| 313 | * Routine Description: |
| 314 | * Check if Next TBTT must wake up |
| 315 | * |
| 316 | * Return Value: |
| 317 | * None. |
| 318 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 319 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 320 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 321 | BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 322 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 323 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 324 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 325 | BOOL bWakeUp = FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 326 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 327 | if (pMgmt->wListenInterval >= 2) { |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame] | 328 | if (pMgmt->wCountToWakeUp == 0) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 329 | pMgmt->wCountToWakeUp = pMgmt->wListenInterval; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 330 | |
Philip Worrall | c5b0b5f | 2011-03-02 14:34:43 +0000 | [diff] [blame] | 331 | pMgmt->wCountToWakeUp--; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 332 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 333 | if (pMgmt->wCountToWakeUp == 1) { |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 334 | /* Turn on wake up to listen next beacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 335 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); |
| 336 | pDevice->bPSRxBeacon = FALSE; |
| 337 | bWakeUp = TRUE; |
Philip Worrall | c5b0b5f | 2011-03-02 14:34:43 +0000 | [diff] [blame] | 338 | } else if (!pDevice->bPSRxBeacon) { |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 339 | /* Listen until RxBeacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 340 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); |
| 341 | } |
| 342 | } |
| 343 | return bWakeUp; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 344 | } |
| 345 | |