diff options
Diffstat (limited to 'service/java/com/android/server/wifi/WifiNative.java')
-rw-r--r-- | service/java/com/android/server/wifi/WifiNative.java | 157 |
1 files changed, 151 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 899529ddd..620f8b505 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -36,6 +36,8 @@ import android.util.Base64; import android.util.LocalLog; import android.util.Log; +import com.android.server.connectivity.KeepalivePacketData; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; @@ -654,8 +656,47 @@ public class WifiNative { return doBooleanCommand("DRIVER COUNTRY"); } - public boolean enableBackgroundScan(boolean enable) { + /** + * Object holding the network ID and the corresponding priority to be set before enabling/ + * disabling PNO. + */ + public static class PnoNetworkPriority { + public int networkId; + public int priority; + + PnoNetworkPriority(int networkId, int priority) { + this.networkId = networkId; + this.priority = priority; + } + + @Override + public String toString() { + StringBuilder sbuf = new StringBuilder(); + sbuf.append(" Network ID=").append(this.networkId); + sbuf.append(" Priority=").append(this.priority); + return sbuf.toString(); + } + } + + public boolean enableBackgroundScan( + boolean enable, + List<PnoNetworkPriority> pnoNetworkList) { boolean ret; + // TODO: Couple of cases yet to be handled: + // 1. What if the network priority update fails, should we bail out of PNO setting? + // 2. If PNO setting fails below, should we go back and revert this priority change? + if (pnoNetworkList != null) { + if (DBG) Log.i(mTAG, "Update priorities for PNO. Enable: " + enable); + for (PnoNetworkPriority pnoNetwork : pnoNetworkList) { + // What if this fails? Should we bail out? + boolean isSuccess = setNetworkVariable(pnoNetwork.networkId, + WifiConfiguration.priorityVarName, + Integer.toString(pnoNetwork.priority)); + if (!isSuccess) { + Log.e(mTAG, "Update priority failed for :" + pnoNetwork.networkId); + } + } + } if (enable) { ret = doBooleanCommand("SET pno 1"); } else { @@ -676,6 +717,14 @@ public class WifiNative { doBooleanCommand("SCAN_INTERVAL " + scanInterval); } + public void setHs20(boolean hs20) { + if (hs20) { + doBooleanCommand("SET HS20 1"); + } else { + doBooleanCommand("SET HS20 0"); + } + } + public void startTdls(String macAddr, boolean enable) { if (enable) { doBooleanCommand("TDLS_DISCOVER " + macAddr); @@ -1466,8 +1515,8 @@ public class WifiNative { int secondChanelOffset = 0; byte channelMode = 0; - byte centerFreqIndex1 = 0; - byte centerFreqIndex2 = 0; + int centerFreqIndex1 = 0; + int centerFreqIndex2 = 0; boolean is80211McRTTResponder = false; @@ -1490,8 +1539,8 @@ public class WifiNative { secondChanelOffset = bytes[inforStart + 1] & 0x3; } else if(type == EID_VHT_OPERATION) { channelMode = bytes[inforStart]; - centerFreqIndex1 = bytes[inforStart + 1]; - centerFreqIndex2 = bytes[inforStart + 2]; + centerFreqIndex1 = bytes[inforStart + 1] & 0xFF; + centerFreqIndex2 = bytes[inforStart + 2] & 0xFF; } else if (type == EID_EXTENDED_CAPS) { int tempIndex = RTT_RESP_ENABLE_BIT / 8; byte offset = RTT_RESP_ENABLE_BIT % 8; @@ -1604,7 +1653,9 @@ public class WifiNative { synchronized public static void stopScan() { synchronized (mLock) { if (isHalStarted()) { - stopScanNative(sWlan0Index, sScanCmdId); + if (sScanCmdId != 0) { + stopScanNative(sWlan0Index, sScanCmdId); + } sScanSettings = null; sScanEventHandler = null; sScanCmdId = 0; @@ -2391,4 +2442,98 @@ public class WifiNative { } } } + + private native static int startSendingOffloadedPacketNative(int iface, int idx, + byte[] srcMac, byte[] dstMac, byte[] pktData, int period); + + synchronized public int + startSendingOffloadedPacket(int slot, KeepalivePacketData keepAlivePacket, int period) { + Log.d(TAG, "startSendingOffloadedPacket slot=" + slot + " period=" + period); + + String[] macAddrStr = getMacAddress().split(":"); + byte[] srcMac = new byte[6]; + for(int i = 0; i < 6; i++) { + Integer hexVal = Integer.parseInt(macAddrStr[i], 16); + srcMac[i] = hexVal.byteValue(); + } + synchronized (mLock) { + if (isHalStarted()) { + return startSendingOffloadedPacketNative(sWlan0Index, slot, srcMac, + keepAlivePacket.dstMac, keepAlivePacket.data, period); + } else { + return -1; + } + } + } + + private native static int stopSendingOffloadedPacketNative(int iface, int idx); + + synchronized public int + stopSendingOffloadedPacket(int slot) { + Log.d(TAG, "stopSendingOffloadedPacket " + slot); + synchronized (mLock) { + if (isHalStarted()) { + return stopSendingOffloadedPacketNative(sWlan0Index, slot); + } else { + return -1; + } + } + } + + public static interface WifiRssiEventHandler { + void onRssiThresholdBreached(byte curRssi); + } + + private static WifiRssiEventHandler sWifiRssiEventHandler; + + synchronized static void onRssiThresholdBreached(int id, byte curRssi) { + sWifiRssiEventHandler.onRssiThresholdBreached(curRssi); + } + + private native static int startRssiMonitoringNative(int iface, int id, + byte maxRssi, byte minRssi); + + private static int sRssiMonitorCmdId = 0; + + synchronized public int startRssiMonitoring(byte maxRssi, byte minRssi, + WifiRssiEventHandler rssiEventHandler) { + Log.d(TAG, "startRssiMonitoring: maxRssi=" + maxRssi + " minRssi=" + minRssi); + sWifiRssiEventHandler = rssiEventHandler; + synchronized (mLock) { + if (isHalStarted()) { + if (sRssiMonitorCmdId != 0) { + stopRssiMonitoring(); + } + + sRssiMonitorCmdId = getNewCmdIdLocked(); + Log.d(TAG, "sRssiMonitorCmdId = " + sRssiMonitorCmdId); + int ret = startRssiMonitoringNative(sWlan0Index, sRssiMonitorCmdId, + maxRssi, minRssi); + if (ret != 0) { // if not success + sRssiMonitorCmdId = 0; + } + return ret; + } else { + return -1; + } + } + } + + private native static int stopRssiMonitoringNative(int iface, int idx); + + synchronized public int stopRssiMonitoring() { + Log.d(TAG, "stopRssiMonitoring, cmdId " + sRssiMonitorCmdId); + synchronized (mLock) { + if (isHalStarted()) { + int ret = 0; + if (sRssiMonitorCmdId != 0) { + ret = stopRssiMonitoringNative(sWlan0Index, sRssiMonitorCmdId); + } + sRssiMonitorCmdId = 0; + return ret; + } else { + return -1; + } + } + } } |