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 | |
| 121 | if (pDevice->eOPMode == OP_MODE_ADHOC) { |
| 122 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 123 | /* bMgrPrepareBeaconToSend((void *) pDevice, pMgmt); */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 124 | |
| 125 | } |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 126 | /* We don't send null pkt in ad hoc mode since beacon will handle this. */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 127 | 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 Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 136 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 137 | * |
| 138 | * Routine Description: |
| 139 | * Disable hw power saving functions |
| 140 | * |
| 141 | * Return Value: |
| 142 | * None. |
| 143 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 144 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 145 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 146 | void PSvDisablePowerSaving(void *hDeviceContext) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 147 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 148 | PSDevice pDevice = (PSDevice)hDeviceContext; |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 149 | /* PSMgmtObject pMgmt = &(pDevice->sMgmtObj); */ |
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 | /* disable power saving hw function */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 152 | CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_DISABLE_PS, 0, |
| 153 | 0, 0, NULL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 154 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 155 | /* clear AutoSleep */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 156 | MACvRegBitsOff(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 157 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 158 | /* set always listen beacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 159 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); |
| 160 | pDevice->bEnablePSMode = FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 161 | |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame^] | 162 | if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 163 | PSbSendNullPacket(pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 164 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 165 | pDevice->bPWBitOn = FALSE; |
| 166 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 167 | } |
| 168 | |
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 | * |
| 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 Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 177 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 178 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 179 | BOOL PSbConsiderPowerDown(void *hDeviceContext, |
| 180 | BOOL bCheckRxDMA, |
| 181 | BOOL bCheckCountToWakeUp) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 182 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 183 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 184 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 185 | BYTE byData; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 186 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 187 | /* check if already in Doze mode */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 188 | ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, |
| 189 | MAC_REG_PSCTL, &byData); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 190 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 191 | if ( (byData & PSCTL_PS) != 0 ) |
| 192 | return TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 193 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 194 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 195 | /* check if in TIM wake period */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 196 | if (pMgmt->bInTIMWake) |
| 197 | return FALSE; |
| 198 | } |
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 | /* check scan state */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 201 | if (pDevice->bCmdRunning) |
| 202 | return FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 203 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 204 | /* Tx Burst */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 205 | if ( pDevice->bPSModeTxBurst ) |
| 206 | return FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 207 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 208 | /* Froce PSEN on */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 209 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 210 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 211 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { |
| 212 | if (bCheckCountToWakeUp && (pMgmt->wCountToWakeUp == 0 |
| 213 | || pMgmt->wCountToWakeUp == 1)) { |
| 214 | return FALSE; |
| 215 | } |
| 216 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 217 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 218 | pDevice->bPSRxBeacon = TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 219 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 220 | /* no Tx, no Rx isr, now go to Doze */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 221 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE); |
| 222 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n"); |
| 223 | return TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 224 | } |
| 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 | * |
| 228 | * Routine Description: |
| 229 | * Send PS-POLL packet |
| 230 | * |
| 231 | * Return Value: |
| 232 | * None. |
| 233 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 234 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 235 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 236 | void PSvSendPSPOLL(void *hDeviceContext) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 237 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 238 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 239 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 240 | PSTxMgmtPacket pTxPacket = NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 241 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 242 | 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 Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 251 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 252 | 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 Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 257 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 258 | /* send the frame */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 259 | 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 Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 262 | /* DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n"); */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 263 | }; |
| 264 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 265 | } |
| 266 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 267 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 268 | * |
| 269 | * Routine Description: |
| 270 | * Send NULL packet to AP for notification power state of STA |
| 271 | * |
| 272 | * Return Value: |
| 273 | * None. |
| 274 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 275 | */ |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 276 | |
| 277 | BOOL PSbSendNullPacket(void *hDeviceContext) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 278 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 279 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 280 | PSTxMgmtPacket pTxPacket = NULL; |
| 281 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 282 | |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame^] | 283 | if (pDevice->bLinkPass == FALSE) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 284 | return FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 285 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 286 | if ((pDevice->bEnablePSMode == FALSE) && |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame^] | 287 | (pDevice->fTxDataInSleep == FALSE)) { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 288 | return FALSE; |
| 289 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 290 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 291 | 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 Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 294 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 295 | 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 More | feaf03d | 2010-06-25 20:20:58 -0300 | [diff] [blame] | 310 | |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame^] | 311 | if(pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 312 | 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] | 313 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 314 | 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 Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 319 | /* send the frame */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 320 | 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 Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 324 | /* DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n"); */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 325 | } |
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 | return TRUE ; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 328 | } |
| 329 | |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 330 | /* |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 331 | * |
| 332 | * Routine Description: |
| 333 | * Check if Next TBTT must wake up |
| 334 | * |
| 335 | * Return Value: |
| 336 | * None. |
| 337 | * |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 338 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 339 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 340 | BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 341 | { |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 342 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 343 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 344 | BOOL bWakeUp = FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 345 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 346 | if (pMgmt->wListenInterval >= 2) { |
Philip Worrall | 036dba1 | 2011-03-02 14:34:41 +0000 | [diff] [blame^] | 347 | if (pMgmt->wCountToWakeUp == 0) |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 348 | pMgmt->wCountToWakeUp = pMgmt->wListenInterval; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 349 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 350 | pMgmt->wCountToWakeUp --; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 351 | |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 352 | if (pMgmt->wCountToWakeUp == 1) { |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 353 | /* Turn on wake up to listen next beacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 354 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); |
| 355 | pDevice->bPSRxBeacon = FALSE; |
| 356 | bWakeUp = TRUE; |
| 357 | } else if ( !pDevice->bPSRxBeacon ) { |
Philip Worrall | 7404eab | 2011-03-02 14:34:40 +0000 | [diff] [blame] | 358 | /* Listen until RxBeacon */ |
Philip Worrall | f9cfbe9 | 2011-03-02 14:34:39 +0000 | [diff] [blame] | 359 | MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); |
| 360 | } |
| 361 | } |
| 362 | return bWakeUp; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 363 | } |
| 364 | |