Forest Bond | 5449c68 | 2009-04-25 10:30:44 -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 | * |
Jim Lieb | 612822f | 2009-08-12 14:54:03 -0700 | [diff] [blame] | 19 | * |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 20 | * File: power.c |
| 21 | * |
Uwe Kleine-König | 658ce9d | 2009-07-23 08:33:56 +0200 | [diff] [blame] | 22 | * Purpose: Handles 802.11 power management functions |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -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 | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 40 | #include "ttype.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 41 | #include "mac.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 42 | #include "device.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 43 | #include "wmgr.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 44 | #include "power.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 45 | #include "wcmd.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 46 | #include "rxtx.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 47 | #include "card.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 48 | |
| 49 | /*--------------------- Static Definitions -------------------------*/ |
| 50 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 51 | /*--------------------- Static Classes ----------------------------*/ |
| 52 | |
| 53 | /*--------------------- Static Variables --------------------------*/ |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 54 | static int msglevel = MSG_LEVEL_INFO; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 55 | /*--------------------- Static Functions --------------------------*/ |
| 56 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 57 | /*--------------------- Export Variables --------------------------*/ |
| 58 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 59 | /*--------------------- Export Functions --------------------------*/ |
| 60 | |
| 61 | /*+ |
| 62 | * |
| 63 | * Routine Description: |
| 64 | * Enable hw power saving functions |
| 65 | * |
| 66 | * Return Value: |
| 67 | * None. |
| 68 | * |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 69 | -*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 70 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 71 | void |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 72 | PSvEnablePowerSaving( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 73 | void *hDeviceContext, |
| 74 | unsigned short wListenInterval |
| 75 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 76 | { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 77 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 78 | PSMgmtObject pMgmt = pDevice->pMgmt; |
| 79 | unsigned short wAID = pMgmt->wCurrAID | BIT14 | BIT15; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 80 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 81 | // set period of power up before TBTT |
| 82 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT); |
| 83 | if (pDevice->eOPMode != OP_MODE_ADHOC) { |
| 84 | // set AID |
| 85 | VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID); |
| 86 | } else { |
| 87 | // set ATIM Window |
| 88 | MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); |
| 89 | } |
| 90 | // Set AutoSleep |
| 91 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
| 92 | // Set HWUTSF |
| 93 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 94 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 95 | if (wListenInterval >= 2) { |
| 96 | // clear always listen beacon |
| 97 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
| 98 | //pDevice->wCFG &= ~CFG_ALB; |
| 99 | // first time set listen next beacon |
| 100 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); |
| 101 | pMgmt->wCountToWakeUp = wListenInterval; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 102 | } else { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 103 | // always listen beacon |
| 104 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
| 105 | //pDevice->wCFG |= CFG_ALB; |
| 106 | pMgmt->wCountToWakeUp = 0; |
| 107 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 108 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 109 | // enable power saving hw function |
| 110 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); |
| 111 | pDevice->bEnablePSMode = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 112 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 113 | if (pDevice->eOPMode == OP_MODE_ADHOC) { |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 114 | // bMgrPrepareBeaconToSend((void *)pDevice, pMgmt); |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 115 | } |
| 116 | // We don't send null pkt in ad hoc mode since beacon will handle this. |
| 117 | else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) { |
| 118 | PSbSendNullPacket(pDevice); |
| 119 | } |
| 120 | pDevice->bPWBitOn = true; |
| 121 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n"); |
| 122 | return; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 125 | /*+ |
| 126 | * |
| 127 | * Routine Description: |
| 128 | * Disable hw power saving functions |
| 129 | * |
| 130 | * Return Value: |
| 131 | * None. |
| 132 | * |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 133 | -*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 134 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 135 | void |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 136 | PSvDisablePowerSaving( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 137 | void *hDeviceContext |
| 138 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 139 | { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 140 | PSDevice pDevice = (PSDevice)hDeviceContext; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 141 | // PSMgmtObject pMgmt = pDevice->pMgmt; |
| 142 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 143 | // disable power saving hw function |
| 144 | MACbPSWakeup(pDevice->PortOffset); |
| 145 | //clear AutoSleep |
| 146 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
| 147 | //clear HWUTSF |
| 148 | MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); |
| 149 | // set always listen beacon |
| 150 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 151 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 152 | pDevice->bEnablePSMode = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 153 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 154 | if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) { |
| 155 | PSbSendNullPacket(pDevice); |
| 156 | } |
| 157 | pDevice->bPWBitOn = false; |
| 158 | return; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 159 | } |
| 160 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 161 | /*+ |
| 162 | * |
| 163 | * Routine Description: |
| 164 | * Consider to power down when no more packets to tx or rx. |
| 165 | * |
| 166 | * Return Value: |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 167 | * true, if power down success |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 168 | * false, if fail |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 169 | -*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 170 | |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 171 | bool |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 172 | PSbConsiderPowerDown( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 173 | void *hDeviceContext, |
| 174 | bool bCheckRxDMA, |
| 175 | bool bCheckCountToWakeUp |
| 176 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 177 | { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 178 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 179 | PSMgmtObject pMgmt = pDevice->pMgmt; |
| 180 | unsigned int uIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 181 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 182 | // check if already in Doze mode |
| 183 | if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) |
| 184 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 185 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 186 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { |
| 187 | // check if in TIM wake period |
| 188 | if (pMgmt->bInTIMWake) |
| 189 | return false; |
| 190 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 191 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 192 | // check scan state |
| 193 | if (pDevice->bCmdRunning) |
| 194 | return false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 195 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 196 | // Force PSEN on |
| 197 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 198 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 199 | // check if all TD are empty, |
| 200 | for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) { |
| 201 | if (pDevice->iTDUsed[uIdx] != 0) |
| 202 | return false; |
| 203 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 204 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 205 | // check if rx isr is clear |
| 206 | if (bCheckRxDMA && |
| 207 | ((pDevice->dwIsr & ISR_RXDMA0) != 0) && |
| 208 | ((pDevice->dwIsr & ISR_RXDMA1) != 0)) { |
| 209 | return false; |
| 210 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 211 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 212 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { |
| 213 | if (bCheckCountToWakeUp && |
| 214 | (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) { |
| 215 | return false; |
| 216 | } |
| 217 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 218 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 219 | // no Tx, no Rx isr, now go to Doze |
| 220 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE); |
| 221 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n"); |
| 222 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 223 | } |
| 224 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 225 | /*+ |
| 226 | * |
| 227 | * Routine Description: |
| 228 | * Send PS-POLL packet |
| 229 | * |
| 230 | * Return Value: |
| 231 | * None. |
| 232 | * |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 233 | -*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 234 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 235 | void |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 236 | PSvSendPSPOLL( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 237 | void *hDeviceContext |
| 238 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 239 | { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 240 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 241 | PSMgmtObject pMgmt = pDevice->pMgmt; |
| 242 | PSTxMgmtPacket pTxPacket = NULL; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 243 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 244 | memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN); |
| 245 | pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; |
| 246 | pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket)); |
| 247 | pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16( |
| 248 | ( |
| 249 | WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) | |
| 250 | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) | |
| 251 | WLAN_SET_FC_PWRMGT(0) |
| 252 | )); |
| 253 | pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15; |
| 254 | memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN); |
| 255 | memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN); |
| 256 | pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN; |
| 257 | pTxPacket->cbPayloadLen = 0; |
| 258 | // send the frame |
| 259 | if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { |
| 260 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n"); |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 261 | } else { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 262 | // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n"); |
Teodora Baluta | 88cc850 | 2013-11-10 17:12:45 +0200 | [diff] [blame] | 263 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 264 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 265 | return; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 266 | } |
| 267 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 268 | /*+ |
| 269 | * |
| 270 | * Routine Description: |
| 271 | * Send NULL packet to AP for notification power state of STA |
| 272 | * |
| 273 | * Return Value: |
| 274 | * None. |
| 275 | * |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 276 | -*/ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 277 | bool |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 278 | PSbSendNullPacket( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 279 | void *hDeviceContext |
| 280 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 281 | { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 282 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 283 | PSTxMgmtPacket pTxPacket = NULL; |
| 284 | PSMgmtObject pMgmt = pDevice->pMgmt; |
| 285 | unsigned int uIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 286 | |
Teodora Baluta | 1208f14 | 2013-11-10 17:12:42 +0200 | [diff] [blame] | 287 | if (!pDevice->bLinkPass) { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 288 | return false; |
| 289 | } |
| 290 | #ifdef TxInSleep |
Teodora Baluta | 1208f14 | 2013-11-10 17:12:42 +0200 | [diff] [blame] | 291 | if (!pDevice->bEnablePSMode && !pDevice->fTxDataInSleep) { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 292 | return false; |
| 293 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 294 | #else |
Teodora Baluta | 1208f14 | 2013-11-10 17:12:42 +0200 | [diff] [blame] | 295 | if (!pDevice->bEnablePSMode) { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 296 | return false; |
| 297 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 298 | #endif |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 299 | if (pDevice->bEnablePSMode) { |
| 300 | for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) { |
| 301 | if (pDevice->iTDUsed[uIdx] != 0) |
| 302 | return false; |
| 303 | } |
| 304 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 305 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 306 | memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN); |
| 307 | pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; |
| 308 | pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 309 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 310 | if (pDevice->bEnablePSMode) { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 311 | pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16( |
| 312 | ( |
| 313 | WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) | |
| 314 | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) | |
| 315 | WLAN_SET_FC_PWRMGT(1) |
| 316 | )); |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 317 | } else { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 318 | pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16( |
| 319 | ( |
| 320 | WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) | |
| 321 | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) | |
| 322 | WLAN_SET_FC_PWRMGT(0) |
| 323 | )); |
| 324 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 325 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 326 | if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { |
| 327 | pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_TODS(1)); |
| 328 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 329 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 330 | memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN); |
| 331 | memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN); |
| 332 | memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN); |
| 333 | pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN; |
| 334 | pTxPacket->cbPayloadLen = 0; |
| 335 | // send the frame |
| 336 | if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { |
| 337 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n"); |
| 338 | return false; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 339 | } else { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 340 | // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n"); |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 341 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 342 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 343 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /*+ |
| 347 | * |
| 348 | * Routine Description: |
| 349 | * Check if Next TBTT must wake up |
| 350 | * |
| 351 | * Return Value: |
| 352 | * None. |
| 353 | * |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 354 | -*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 355 | |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 356 | bool |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 357 | PSbIsNextTBTTWakeUp( |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 358 | void *hDeviceContext |
| 359 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 360 | { |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 361 | PSDevice pDevice = (PSDevice)hDeviceContext; |
| 362 | PSMgmtObject pMgmt = pDevice->pMgmt; |
| 363 | bool bWakeUp = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 364 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 365 | if (pMgmt->wListenInterval >= 2) { |
| 366 | if (pMgmt->wCountToWakeUp == 0) { |
| 367 | pMgmt->wCountToWakeUp = pMgmt->wListenInterval; |
| 368 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 369 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 370 | pMgmt->wCountToWakeUp--; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 371 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 372 | if (pMgmt->wCountToWakeUp == 1) { |
| 373 | // Turn on wake up to listen next beacon |
| 374 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); |
| 375 | bWakeUp = true; |
| 376 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 377 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 378 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 379 | |
Joe Perches | 474f0f8 | 2013-03-18 10:44:58 -0700 | [diff] [blame] | 380 | return bWakeUp; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 381 | } |