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