WifiNative.java revision d57f630f6a7a5fca872d2b96fc4cce1905daee5d
1155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/* 2155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Copyright (C) 2008 The Android Open Source Project 3155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 4155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Licensed under the Apache License, Version 2.0 (the "License"); 5155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * you may not use this file except in compliance with the License. 6155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * You may obtain a copy of the License at 7155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 8155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * http://www.apache.org/licenses/LICENSE-2.0 9155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 10155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Unless required by applicable law or agreed to in writing, software 11155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * distributed under the License is distributed on an "AS IS" BASIS, 12155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * See the License for the specific language governing permissions and 14155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * limitations under the License. 15155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 16155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 17155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandepackage com.android.server.wifi; 18155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 19155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.BatchedScanSettings; 20143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpandeimport android.net.wifi.RttManager; 21e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndeimport android.net.wifi.ScanResult; 22dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalleimport android.net.wifi.WifiConfiguration; 23aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalleimport android.net.wifi.WifiLinkLayerStats; 2403cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidtimport android.net.wifi.WifiManager; 25e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndeimport android.net.wifi.WifiScanner; 2612cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinheimport android.net.wifi.RttManager; 27dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalleimport android.net.wifi.WifiSsid; 28155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.WpsInfo; 29155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.WifiP2pConfig; 30155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.WifiP2pGroup; 3103cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidtimport android.net.wifi.p2p.nsd.WifiP2pServiceInfo; 32f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalleimport android.os.SystemClock; 33155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.text.TextUtils; 34155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.LocalLog; 35155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.Log; 36155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 37155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.ArrayList; 38155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.List; 39155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.Locale; 40155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 41155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/** 42155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Native calls for bring up/shut down of the supplicant daemon and for 43155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * sending requests to the supplicant daemon 44155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 45155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * waitForEvent() is called on the monitor thread for events. All other methods 46155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * must be serialized from the framework. 47155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 48155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@hide} 49155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 50155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandepublic class WifiNative { 51155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 52ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle private static boolean DBG = false; 53155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private final String mTAG; 54155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private static final int DEFAULT_GROUP_OWNER_INTENT = 6; 55155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 56155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0; 57155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED = 1; 58155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2; 59155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 60155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int SCAN_WITHOUT_CONNECTION_SETUP = 1; 61155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int SCAN_WITH_CONNECTION_SETUP = 2; 62155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 63155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Hold this lock before calling supplicant - it is required to 64155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // mutually exclude access from Wifi and P2p state machines 65155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final Object mLock = new Object(); 66155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 67155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public final String mInterfaceName; 68155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public final String mInterfacePrefix; 69155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 70155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private boolean mSuspendOptEnabled = false; 71155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 72243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe private static final int EID_HT_OPERATION = 61; 73243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe private static final int EID_VHT_OPERATION = 192; 74243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe private static final int EID_EXTENDED_CAPS = 127; 75243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe private static final int RTT_RESP_ENABLE_BIT = 70; 76155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Register native functions */ 77155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 78155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static { 79155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Native functions are defined in libwifi-service.so */ 80155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande System.loadLibrary("wifi-service"); 81155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande registerNatives(); 82155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 83155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 84155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private static native int registerNatives(); 85155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 86155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean loadDriver(); 87155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 88155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean isDriverLoaded(); 89155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 90155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean unloadDriver(); 91155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 92155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean startSupplicant(boolean p2pSupported); 93155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 94155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Sends a kill signal to supplicant. To be used when we have lost connection 95155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande or when the supplicant is hung */ 96155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean killSupplicant(boolean p2pSupported); 97155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 98155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native boolean connectToSupplicantNative(); 99155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native void closeSupplicantConnectionNative(); 101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Wait for the supplicant to send an event, returning the event string. 104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return the event string sent by the supplicant. 105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native String waitForEventNative(); 107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native boolean doBooleanCommandNative(String command); 109155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 110155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native int doIntCommandNative(String command); 111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native String doStringCommandNative(String command); 113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public WifiNative(String interfaceName) { 115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfaceName = interfaceName; 116155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mTAG = "WifiNative-" + interfaceName; 117155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!interfaceName.equals("p2p0")) { 118155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfacePrefix = "IFNAME=" + interfaceName + " "; 119155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 120155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // commands for p2p0 interface don't need prefix 121155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfacePrefix = ""; 122155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 123155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 124155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 125ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle void enableVerboseLogging(int verbose) { 126ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle if (verbose > 0) { 127ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle DBG = true; 128ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } else { 129ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle DBG = false; 130ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } 131ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } 132ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle 133155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private static final LocalLog mLocalLog = new LocalLog(1024); 134155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // hold mLock before accessing mCmdIdLock 136b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sCmdId; 137155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 138155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public LocalLog getLocalLog() { 139155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mLocalLog; 140155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 141155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 142b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int getNewCmdIdLocked() { 143b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande return sCmdId++; 144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void localLog(String s) { 147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mLocalLog != null) 148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mLocalLog.log(mInterfaceName + ": " + s); 149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean connectToSupplicant() { 152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // No synchronization necessary .. it is implemented in WifiMonitor 153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande localLog(mInterfacePrefix + "connectToSupplicant"); 154155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return connectToSupplicantNative(); 155155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 156155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 157155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void closeSupplicantConnection() { 158155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande localLog(mInterfacePrefix + "closeSupplicantConnection"); 159155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande closeSupplicantConnectionNative(); 160155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 161155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String waitForEvent() { 163155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // No synchronization necessary .. it is implemented in WifiMonitor 164155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return waitForEventNative(); 165155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 166155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 167155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private boolean doBooleanCommand(String command) { 168155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "doBoolean: " + command); 169155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 170155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int cmdId = getNewCmdIdLocked(); 1717b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle String toLog = Integer.toString(cmdId) + ":" + mInterfacePrefix + command; 172155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande boolean result = doBooleanCommandNative(mInterfacePrefix + command); 1737b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 1740888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) Log.d(mTAG, command + ": returned " + result); 175155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 176155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 177155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 178155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 179155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int doIntCommand(String command) { 180155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "doInt: " + command); 181155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 182155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int cmdId = getNewCmdIdLocked(); 1837b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle String toLog = Integer.toString(cmdId) + ":" + mInterfacePrefix + command; 184155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int result = doIntCommandNative(mInterfacePrefix + command); 1857b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 186155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, " returned " + result); 187155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 188155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 189155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 190155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 191155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String doStringCommand(String command) { 1920888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) { 1930888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle //GET_NETWORK commands flood the logs 1940888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (!command.startsWith("GET_NETWORK")) { 1950888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle Log.d(mTAG, "doString: [" + command + "]"); 1960888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 1970888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 198155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 199155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int cmdId = getNewCmdIdLocked(); 2007b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle String toLog = Integer.toString(cmdId) + ":" + mInterfacePrefix + command; 201155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String result = doStringCommandNative(mInterfacePrefix + command); 20240ff222cec1bd05879edb53abc75c6deead734cavandwalle if (result == null) { 20340ff222cec1bd05879edb53abc75c6deead734cavandwalle if (DBG) Log.d(mTAG, "doStringCommandNative no result"); 20440ff222cec1bd05879edb53abc75c6deead734cavandwalle } else { 2057b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle if (!command.startsWith("STATUS-")) { 2067b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 2077b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle } 20840ff222cec1bd05879edb53abc75c6deead734cavandwalle if (DBG) Log.d(mTAG, " returned " + result.replace("\n", " ")); 20940ff222cec1bd05879edb53abc75c6deead734cavandwalle } 210155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 211155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 212155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 213155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 214155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String doStringCommandWithoutLogging(String command) { 2150888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) { 2160888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle //GET_NETWORK commands flood the logs 2170888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (!command.startsWith("GET_NETWORK")) { 2180888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle Log.d(mTAG, "doString: [" + command + "]"); 2190888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 22027355a942653264388e909a4276196ee63e57811vandwalle } 22127355a942653264388e909a4276196ee63e57811vandwalle synchronized (mLock) { 222155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative(mInterfacePrefix + command); 223155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 224155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 225155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 226155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean ping() { 227155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String pong = doStringCommand("PING"); 228155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (pong != null && pong.equals("PONG")); 229155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 230155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 231ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle public void setSupplicantLogLevel(String level) { 232ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle doStringCommand("LOG_LEVEL " + level); 233ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle } 234ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle 235a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng public String getFreqCapability() { 236a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng return doStringCommand("GET_CAPABILITY freq"); 237a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng } 238a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng 239a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng public boolean scan(int type, String freqList) { 240155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (type == SCAN_WITHOUT_CONNECTION_SETUP) { 241a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (freqList == null) return doBooleanCommand("SCAN TYPE=ONLY"); 242a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng else return doBooleanCommand("SCAN TYPE=ONLY freq=" + freqList); 243155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (type == SCAN_WITH_CONNECTION_SETUP) { 244a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (freqList == null) return doBooleanCommand("SCAN"); 245a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng else return doBooleanCommand("SCAN freq=" + freqList); 246155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 247155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande throw new IllegalArgumentException("Invalid scan type"); 248155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 249155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 250155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 251155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Does a graceful shutdown of supplicant. Is a common stop function for both p2p and sta. 252155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 253155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Note that underneath we use a harsh-sounding "terminate" supplicant command 254155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * for a graceful stop and a mild-sounding "stop" interface 255155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * to kill the process 256155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 257155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopSupplicant() { 258155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("TERMINATE"); 259155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 260155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 261155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String listNetworks() { 262155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("LIST_NETWORKS"); 263155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 264155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 265e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande public String listNetworks(int last_id) { 266e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande return doStringCommand("LIST_NETWORKS LAST_ID=" + last_id); 267e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande } 268e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande 269155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int addNetwork() { 270155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doIntCommand("ADD_NETWORK"); 271155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 272155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 273155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setNetworkVariable(int netId, String name, String value) { 274155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(name) || TextUtils.isEmpty(value)) return false; 275155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET_NETWORK " + netId + " " + name + " " + value); 276155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 277155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 278155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getNetworkVariable(int netId, String name) { 279155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(name)) return null; 280155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 281155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // GET_NETWORK will likely flood the logs ... 282155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandWithoutLogging("GET_NETWORK " + netId + " " + name); 283155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 284155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 285155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean removeNetwork(int netId) { 286155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("REMOVE_NETWORK " + netId); 287155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 288155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 289f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 290f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle private void logDbg(String debug) { 291f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle long now = SystemClock.elapsedRealtimeNanos(); 292f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle String ts = String.format("[%,d us] ", now/1000); 293ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle Log.e("WifiNative: ", ts+debug+ " stack:" 294ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[2].getMethodName() +" - " 295ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[3].getMethodName() +" - " 296ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[4].getMethodName() +" - " 297ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[5].getMethodName()+" - " 298ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[6].getMethodName()); 299f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 300f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 301155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean enableNetwork(int netId, boolean disableOthers) { 302ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle if (DBG) logDbg("enableNetwork nid=" + Integer.toString(netId) 303ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + " disableOthers=" + disableOthers); 304155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (disableOthers) { 305155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SELECT_NETWORK " + netId); 306155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 307155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("ENABLE_NETWORK " + netId); 308155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 309155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 310155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 311155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean disableNetwork(int netId) { 312f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("disableNetwork nid=" + Integer.toString(netId)); 313155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DISABLE_NETWORK " + netId); 314155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 315155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 3160047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande public boolean selectNetwork(int netId) { 3170047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande if (DBG) logDbg("selectNetwork nid=" + Integer.toString(netId)); 3180047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande return doBooleanCommand("SELECT_NETWORK " + netId); 3190047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande } 3200047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande 321155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean reconnect() { 322f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("RECONNECT "); 323155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("RECONNECT"); 324155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 325155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 326155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean reassociate() { 327f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("REASSOCIATE "); 328155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("REASSOCIATE"); 329155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 330155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 331155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean disconnect() { 33221bc54cb37a0085b1c909cb4d55ebb12a2facefbvandwalle if (DBG) logDbg("DISCONNECT "); 333155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DISCONNECT"); 334155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 335155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 336155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String status() { 33799d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return status(false); 338155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 339155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 34099d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle public String status(boolean noEvents) { 34199d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle if (noEvents) { 34299d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return doStringCommand("STATUS-NO_EVENTS"); 34399d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } else { 34499d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return doStringCommand("STATUS"); 34599d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } 34699d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } 34799d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle 348155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getMacAddress() { 349155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //Macaddr = XX.XX.XX.XX.XX.XX 350155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String ret = doStringCommand("DRIVER MACADDR"); 351155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!TextUtils.isEmpty(ret)) { 352155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens = ret.split(" = "); 353155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (tokens.length == 2) return tokens[1]; 354155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 355155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return null; 356155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 357155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 358a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 359a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 360155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 361155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Format of results: 362155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * ================= 363155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * id=1 364155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * bssid=68:7f:74:d7:1b:6e 365155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * freq=2412 366155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * level=-43 367155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * tsf=1344621975160944 368155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * age=2623 369155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * flags=[WPA2-PSK-CCMP][WPS][ESS] 370155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * ssid=zubyb 371155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * ==== 372155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 373155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RANGE=ALL gets all scan results 374155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RANGE=ID- gets results from ID 375155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * MASK=<N> see wpa_supplicant/src/common/wpa_ctrl.h for details 37677f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 0 1 0 2 37777f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_MESH_SCAN | WPA_BSS_MASK_DELIM | WPA_BSS_MASK_WIFI_DISPLAY 37877f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 0 0 1 1 -> 9 37977f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_INTERNETW | WPA_BSS_MASK_P2P_SCAN | WPA_BSS_MASK_WPS_SCAN | WPA_BSS_MASK_SSID 38077f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 1 0 0 1 9 -> d 38177f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_FLAGS | WPA_BSS_MASK_IE | WPA_BSS_MASK_AGE | WPA_BSS_MASK_TSF 38277f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 1 0 0 0 8 38377f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_LEVEL | WPA_BSS_MASK_NOISE | WPA_BSS_MASK_QUAL | WPA_BSS_MASK_CAPABILITIES 38477f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 1 1 1 7 38577f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_BEACON_INT | WPA_BSS_MASK_FREQ | WPA_BSS_MASK_BSSID | WPA_BSS_MASK_ID 38677f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 38777f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_INTERNETW adds ANQP info (ctrl_iface:4151-4176) 38877f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 38977f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * ctrl_iface.c:wpa_supplicant_ctrl_iface_process:7884 39077f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * wpa_supplicant_ctrl_iface_bss:4315 39177f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * print_bss_info 392155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 393155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String scanResults(int sid) { 39477f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist return doStringCommandWithoutLogging("BSS RANGE=" + sid + "- MASK=0x29d87"); 39577f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist } 39677f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist 39777f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist public String doCustomCommand(String command) { 39877f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist return doStringCommand(command); 399155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 400155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 401155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 402446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * Format of result: 403446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * id=1016 404446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * bssid=00:03:7f:40:84:10 405446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * freq=2462 406446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * beacon_int=200 407446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * capabilities=0x0431 408446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * qual=0 409446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * noise=0 410446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * level=-46 411446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * tsf=0000002669008476 412446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * age=5 413446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * ie=00105143412d485332302d52322d54455354010882848b960c12182403010b0706555... 414446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * flags=[WPA2-EAP-CCMP][ESS][P2P][HS20] 415446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * ssid=QCA-HS20-R2-TEST 416446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * p2p_device_name= 41756d0178183460eed9afbd85e5c0d215e27d5f5bcvandwalle * p2p_config_methods=0x0SET_NE 418446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_venue_name=02083d656e6757692d466920416c6c69616e63650a3239383920436f... 419446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_network_auth_type=010000 420446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_roaming_consortium=03506f9a05001bc504bd 421446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_ip_addr_type_availability=0c 422446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_nai_realm=0200300000246d61696c2e6578616d706c652e636f6d3b636973636f2... 423446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_3gpp=000600040132f465 424446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_domain_name=0b65786d61706c652e636f6d 425446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_operator_friendly_name=11656e6757692d466920416c6c69616e63650e636869... 426446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_wan_metrics=01c40900008001000000000a00 427446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_connection_capability=0100000006140001061600000650000106bb010106bb0... 428446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_osu_providers_list=0b5143412d4f53552d425353010901310015656e6757692d... 429446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng */ 430446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng public String scanResult(String bssid) { 431446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng return doStringCommand("BSS " + bssid); 432446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng } 433446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng 434446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng /** 435155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Format of command 436155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER WLS_BATCHING SET SCANFREQ=x MSCAN=r BESTN=y CHANNEL=<z, w, t> RTT=s 437155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * where x is an ascii representation of an integer number of seconds between scans 438155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * r is an ascii representation of an integer number of scans per batch 439155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * y is an ascii representation of an integer number of the max AP to remember per scan 440155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * z, w, t represent a 1..n size list of channel numbers and/or 'A', 'B' values 441155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * indicating entire ranges of channels 442155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * s is an ascii representation of an integer number of highest-strength AP 443155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * for which we'd like approximate distance reported 444155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 445155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The return value is an ascii integer representing a guess of the number of scans 446155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * the firmware can remember before it runs out of buffer space or -1 on error 447155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 448155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String setBatchedScanSettings(BatchedScanSettings settings) { 449155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (settings == null) { 450155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("DRIVER WLS_BATCHING STOP"); 451155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 452155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String cmd = "DRIVER WLS_BATCHING SET SCANFREQ=" + settings.scanIntervalSec; 453155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += " MSCAN=" + settings.maxScansPerBatch; 454155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (settings.maxApPerScan != BatchedScanSettings.UNSPECIFIED) { 455155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += " BESTN=" + settings.maxApPerScan; 456155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 457155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (settings.channelSet != null && !settings.channelSet.isEmpty()) { 458155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += " CHANNEL=<"; 459155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int i = 0; 460155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String channel : settings.channelSet) { 461155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += (i > 0 ? "," : "") + channel; 462155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ++i; 463155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 464155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += ">"; 465155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 466155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (settings.maxApForDistance != BatchedScanSettings.UNSPECIFIED) { 467155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += " RTT=" + settings.maxApForDistance; 468155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 469155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(cmd); 470155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 471155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 472155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getBatchedScanResults() { 473155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("DRIVER WLS_BATCHING GET"); 474155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 475155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 476155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startDriver() { 477155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER START"); 478155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 479155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 480155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopDriver() { 481155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER STOP"); 482155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 483155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 484155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 485155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 486155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Start filtering out Multicast V4 packets 487155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 488155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 489155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Multicast filtering rules work as follows: 490155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 491155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The driver can filter multicast (v4 and/or v6) and broadcast packets when in 492155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * a power optimized mode (typically when screen goes off). 493155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 494155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * In order to prevent the driver from filtering the multicast/broadcast packets, we have to 495155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * add a DRIVER RXFILTER-ADD rule followed by DRIVER RXFILTER-START to make the rule effective 496155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 497155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-ADD Num 498155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * where Num = 0 - Unicast, 1 - Broadcast, 2 - Mutil4 or 3 - Multi6 499155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 500155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * and DRIVER RXFILTER-START 501155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * In order to stop the usage of these rules, we do 502155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 503155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-STOP 504155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-REMOVE Num 505155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * where Num is as described for RXFILTER-ADD 506155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 507155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The SETSUSPENDOPT driver command overrides the filtering rules 508155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 509155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startFilteringMulticastV4Packets() { 510155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 511155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-REMOVE 2") 512155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 513155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 514155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 515155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 516155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Stop filtering out Multicast V4 packets. 517155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 518155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 519155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopFilteringMulticastV4Packets() { 520155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 521155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-ADD 2") 522155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 523155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 524155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 525155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 526155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Start filtering out Multicast V6 packets 527155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 528155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 529155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startFilteringMulticastV6Packets() { 530155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 531155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-REMOVE 3") 532155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 533155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 534155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 535155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 536155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Stop filtering out Multicast V6 packets. 537155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 538155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 539155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopFilteringMulticastV6Packets() { 540155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 541155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-ADD 3") 542155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 543155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 544155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 54503cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt /** 54603cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * Set the operational frequency band 54703cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * @param band One of 54803cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_AUTO}, 54903cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_5GHZ}, 55003cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_2GHZ}, 55103cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * @return {@code true} if the operation succeeded, {@code false} otherwise 55203cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt */ 553155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBand(int band) { 55403cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt String bandstr; 55503cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt 55603cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt if (band == WifiManager.WIFI_FREQUENCY_BAND_5GHZ) 55703cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "5G"; 55803cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt else if (band == WifiManager.WIFI_FREQUENCY_BAND_2GHZ) 55903cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "2G"; 56003cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt else 56103cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "AUTO"; 56203cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt return doBooleanCommand("SET SETBAND " + bandstr); 563155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 564155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 5657ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde /** 5667ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * Sets the bluetooth coexistence mode. 5677ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * 5687ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * @param mode One of {@link #BLUETOOTH_COEXISTENCE_MODE_DISABLED}, 5697ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * {@link #BLUETOOTH_COEXISTENCE_MODE_ENABLED}, or 5707ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}. 5717ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * @return Whether the mode was successfully set. 5727ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde */ 573155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBluetoothCoexistenceMode(int mode) { 574155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXMODE " + mode); 575155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 576155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 577155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 578155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Enable or disable Bluetooth coexistence scan mode. When this mode is on, 579155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * some of the low-level scan parameters used by the driver are changed to 580155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * reduce interference with A2DP streaming. 581155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 582155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param isSet whether to enable or disable this mode 583155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the command succeeded, {@code false} otherwise. 584155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 585155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) { 586155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (setCoexScanMode) { 587155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXSCAN-START"); 588155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 589155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXSCAN-STOP"); 590155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 591155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 592155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 5930a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde public void enableSaveConfig() { 5940a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde doBooleanCommand("SET update_config 1"); 5950a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde } 5960a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde 597155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean saveConfig() { 598155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SAVE_CONFIG"); 599155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 600155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 601155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean addToBlacklist(String bssid) { 602155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) return false; 603155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("BLACKLIST " + bssid); 604155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 605155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 606155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean clearBlacklist() { 607155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("BLACKLIST clear"); 608155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 609155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 610155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setSuspendOptimizations(boolean enabled) { 611f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle // if (mSuspendOptEnabled == enabled) return true; 612155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mSuspendOptEnabled = enabled; 613f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 614f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle Log.e("native", "do suspend " + enabled); 615155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 616155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER SETSUSPENDMODE 1"); 617155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 618155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER SETSUSPENDMODE 0"); 619155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 620155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 621155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 622155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setCountryCode(String countryCode) { 6230465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande if (countryCode != null) 6240465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return doBooleanCommand("DRIVER COUNTRY " + countryCode.toUpperCase(Locale.ROOT)); 6250465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande else 6260465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return doBooleanCommand("DRIVER COUNTRY"); 627155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 628155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 629155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void enableBackgroundScan(boolean enable) { 630155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enable) { 631155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET pno 1"); 632155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 633155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET pno 0"); 634155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 635155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 636155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 637f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle public void enableAutoConnect(boolean enable) { 638f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (enable) { 639f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle doBooleanCommand("STA_AUTOCONNECT 1"); 640f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } else { 641f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle doBooleanCommand("STA_AUTOCONNECT 0"); 642f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 643f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 644f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 645155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setScanInterval(int scanInterval) { 646155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SCAN_INTERVAL " + scanInterval); 647155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 648155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 649155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void startTdls(String macAddr, boolean enable) { 650155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enable) { 651155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("TDLS_DISCOVER " + macAddr); 652155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("TDLS_SETUP " + macAddr); 653155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 654155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("TDLS_TEARDOWN " + macAddr); 655155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 656155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 657155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 658155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** Example output: 659155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RSSI=-65 660155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * LINKSPEED=48 661155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * NOISE=9999 662155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * FREQUENCY=0 663155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 664155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String signalPoll() { 665155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandWithoutLogging("SIGNAL_POLL"); 666155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 667155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 668155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** Example outout: 669155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TXGOOD=396 670155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TXBAD=1 671155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 672155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String pktcntPoll() { 673155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("PKTCNT_POLL"); 674155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 675155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 676155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void bssFlush() { 677155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("BSS_FLUSH 0"); 678155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 679155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 680155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPbc(String bssid) { 681155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 682155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PBC"); 683155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 684155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PBC " + bssid); 685155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 686155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 687155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 688155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPbc(String iface, String bssid) { 689155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 690155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 691155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC"); 692155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 693155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid); 694155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 695155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 696155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 697155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 698155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPinKeypad(String pin) { 699155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(pin)) return false; 700155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PIN any " + pin); 701155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 702155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 703155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPinKeypad(String iface, String pin) { 704155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(pin)) return false; 705155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 706155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin); 707155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 708155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 709155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 710155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 711155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String startWpsPinDisplay(String bssid) { 712155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 713155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("WPS_PIN any"); 714155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 715155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("WPS_PIN " + bssid); 716155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 717155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 718155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 719155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String startWpsPinDisplay(String iface, String bssid) { 720155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 721155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 722155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any"); 723155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 724155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid); 725155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 726155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 727155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 728155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 72933b575ca6bee66183929f9474b5a161432918604Vinit Deshpande public boolean setExternalSim(boolean external) { 73033b575ca6bee66183929f9474b5a161432918604Vinit Deshpande synchronized (mLock) { 73133b575ca6bee66183929f9474b5a161432918604Vinit Deshpande String value = external ? "1" : "0"; 7324d701eca56d62586b0ab8af6ad864bac74a1dcd0Vinit Deshpande Log.d(TAG, "Setting external_sim to " + value); 7334d701eca56d62586b0ab8af6ad864bac74a1dcd0Vinit Deshpande return doBooleanCommand("SET external_sim " + value); 73433b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 73533b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 73633b575ca6bee66183929f9474b5a161432918604Vinit Deshpande 737f97140d51d14ce0659d381f443c08dbd94dfea28Honore Tricot public boolean simAuthResponse(int id, String type, String response) { 738f97140d51d14ce0659d381f443c08dbd94dfea28Honore Tricot // with type = GSM-AUTH, UMTS-AUTH or UMTS-AUTS 73933b575ca6bee66183929f9474b5a161432918604Vinit Deshpande synchronized (mLock) { 740f97140d51d14ce0659d381f443c08dbd94dfea28Honore Tricot return doBooleanCommand("CTRL-RSP-SIM-" + id + ":" + type + response); 74133b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 74233b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 74333b575ca6bee66183929f9474b5a161432918604Vinit Deshpande 744ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot public boolean simIdentityResponse(int id, String response) { 745ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot synchronized (mLock) { 746ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot return doBooleanCommand("CTRL-RSP-IDENTITY-" + id + ":" + response); 747ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot } 748ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot } 749ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot 750155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Configures an access point connection */ 751155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsRegistrar(String bssid, String pin) { 752155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid) || TextUtils.isEmpty(pin)) return false; 753155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_REG " + bssid + " " + pin); 754155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 755155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 756155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean cancelWps() { 757155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_CANCEL"); 758155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 759155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 760155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setPersistentReconnect(boolean enabled) { 761155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int value = (enabled == true) ? 1 : 0; 762155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET persistent_reconnect " + value); 763155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 764155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 765155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setDeviceName(String name) { 766155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET device_name " + name); 767155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 768155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 769155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setDeviceType(String type) { 770155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET device_type " + type); 771155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 772155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 773155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setConfigMethods(String cfg) { 774155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET config_methods " + cfg); 775155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 776155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 777155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setManufacturer(String value) { 778155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET manufacturer " + value); 779155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 780155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 781155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setModelName(String value) { 782155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET model_name " + value); 783155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 784155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 785155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setModelNumber(String value) { 786155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET model_number " + value); 787155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 788155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 789155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setSerialNumber(String value) { 790155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET serial_number " + value); 791155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 792155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 793155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pSsidPostfix(String postfix) { 794155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET p2p_ssid_postfix " + postfix); 795155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 796155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 797155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pGroupIdle(String iface, int time) { 798155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 799155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time); 800155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 801155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 802155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 803155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setPowerSave(boolean enabled) { 804155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 805155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET ps 1"); 806155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 807155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET ps 0"); 808155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 809155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 810155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 811155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pPowerSave(String iface, boolean enabled) { 812155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 813155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 814155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1"); 815155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 816155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0"); 817155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 818155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 819155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 820155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 821155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setWfdEnable(boolean enable) { 822155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET wifi_display " + (enable ? "1" : "0")); 823155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 824155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 825155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setWfdDeviceInfo(String hex) { 826155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WFD_SUBELEM_SET 0 " + hex); 827155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 828155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 829155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 830155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * "sta" prioritizes STA connection over P2P and "p2p" prioritizes 831155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P connection over STA 832155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 833155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setConcurrencyPriority(String s) { 834155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SET conc_pref " + s); 835155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 836155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 837155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFind() { 838155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FIND"); 839155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 840155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 841155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFind(int timeout) { 842155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (timeout <= 0) { 843155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pFind(); 844155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 845155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FIND " + timeout); 846155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 847155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 848155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pStopFind() { 849155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_STOP_FIND"); 850155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 851155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 852155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pListen() { 853155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_LISTEN"); 854155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 855155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 856155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pListen(int timeout) { 857155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (timeout <= 0) { 858155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pListen(); 859155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 860155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_LISTEN " + timeout); 861155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 862155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 863155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pExtListen(boolean enable, int period, int interval) { 864155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enable && interval < period) { 865155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 866155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 867155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_EXT_LISTEN" 868155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + (enable ? (" " + period + " " + interval) : "")); 869155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 870155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 871155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pSetChannel(int lc, int oc) { 872155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "p2pSetChannel: lc="+lc+", oc="+oc); 873155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 874155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (lc >=1 && lc <= 11) { 875155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doBooleanCommand("P2P_SET listen_channel " + lc)) { 876155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 877155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 878155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (lc != 0) { 879155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 880155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 881155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 882155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (oc >= 1 && oc <= 165 ) { 883155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int freq = (oc <= 14 ? 2407 : 5000) + oc * 5; 884155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SET disallow_freq 1000-" 885155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + (freq - 5) + "," + (freq + 5) + "-6000"); 886155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (oc == 0) { 887155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* oc==0 disables "P2P_SET disallow_freq" (enables all freqs) */ 888155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SET disallow_freq \"\""); 889155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 890155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 891155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 892155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 893155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 894155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFlush() { 895155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FLUSH"); 896155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 897155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 898155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* p2p_connect <peer device address> <pbc|pin|PIN#> [label|display|keypad] 899155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande [persistent] [join|auth] [go_intent=<0..15>] [freq=<in MHz>] */ 900155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) { 901155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config == null) return null; 902155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande List<String> args = new ArrayList<String>(); 903155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WpsInfo wps = config.wps; 904155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(config.deviceAddress); 905155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 906155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch (wps.setup) { 907155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.PBC: 908155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("pbc"); 909155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 910155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.DISPLAY: 911155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(wps.pin)) { 912155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("pin"); 913155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 914155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 915155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 916155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("display"); 917155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 918155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.KEYPAD: 919155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 920155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("keypad"); 921155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 922155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.LABEL: 923155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 924155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("label"); 925155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande default: 926155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 927155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 928155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 929155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config.netId == WifiP2pGroup.PERSISTENT_NET_ID) { 930155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("persistent"); 931155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 932155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 933155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (joinExistingGroup) { 934155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("join"); 935155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 936155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //TODO: This can be adapted based on device plugged in state and 937155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //device battery state 938155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int groupOwnerIntent = config.groupOwnerIntent; 939155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (groupOwnerIntent < 0 || groupOwnerIntent > 15) { 940155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT; 941155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 942155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("go_intent=" + groupOwnerIntent); 943155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 944155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 945155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_CONNECT "; 946155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String s : args) command += s + " "; 947155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 948155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(command); 949155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 950155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 951155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pCancelConnect() { 952155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_CANCEL"); 953155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 954155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 955155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pProvisionDiscovery(WifiP2pConfig config) { 956155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config == null) return false; 957155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 958155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch (config.wps.setup) { 959155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.PBC: 960155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " pbc"); 961155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.DISPLAY: 962155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //We are doing display, so provision discovery is keypad 963155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " keypad"); 964155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.KEYPAD: 965155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //We are doing keypad, so provision discovery is display 966155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " display"); 967155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande default: 968155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 969155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 970155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 971155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 972155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 973155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupAdd(boolean persistent) { 974155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (persistent) { 975155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD persistent"); 976155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 977155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD"); 978155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 979155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 980155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupAdd(int netId) { 981155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD persistent=" + netId); 982155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 983155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 984155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupRemove(String iface) { 985155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(iface)) return false; 986155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 987155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface); 988155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 989155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 990155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 991155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pReject(String deviceAddress) { 992155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_REJECT " + deviceAddress); 993155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 994155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 995155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Invite a peer to a group */ 996155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) { 997155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress)) return false; 998155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 999155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (group == null) { 1000155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE peer=" + deviceAddress); 1001155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1002155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE group=" + group.getInterface() 1003155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + " peer=" + deviceAddress + " go_dev_addr=" + group.getOwner().deviceAddress); 1004155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1005155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1006155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1007155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Reinvoke a persistent connection */ 1008155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pReinvoke(int netId, String deviceAddress) { 1009155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress) || netId < 0) return false; 1010155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1011155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE persistent=" + netId + " peer=" + deviceAddress); 1012155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1013155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1014155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pGetSsid(String deviceAddress) { 1015155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pGetParam(deviceAddress, "oper_ssid"); 1016155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1017155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1018155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pGetDeviceAddress() { 101927f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande 102036286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande Log.d(TAG, "p2pGetDeviceAddress"); 102136286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 102227f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande String status = null; 102327f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande 102436286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande /* Explicitly calling the API without IFNAME= prefix to take care of the devices that 102536286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande don't have p2p0 interface. Supplicant seems to be returning the correct address anyway. */ 102636286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 102727f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande synchronized (mLock) { 102827f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande status = doStringCommandNative("STATUS"); 102927f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande } 103027f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande 103127f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande String result = ""; 103236286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (status != null) { 103336286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande String[] tokens = status.split("\n"); 103436286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande for (String token : tokens) { 103536286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (token.startsWith("p2p_device_address=")) { 103636286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande String[] nameValue = token.split("="); 103736286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (nameValue.length != 2) 103836286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande break; 103936286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande result = nameValue[1]; 104036286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande } 1041155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1042155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 104336286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 104436286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande Log.d(TAG, "p2pGetDeviceAddress returning " + result); 104536286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande return result; 1046155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1047155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1048155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int getGroupCapability(String deviceAddress) { 1049155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int gc = 0; 1050155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress)) return gc; 1051155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String peerInfo = p2pPeer(deviceAddress); 1052155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(peerInfo)) return gc; 1053155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1054155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens = peerInfo.split("\n"); 1055155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String token : tokens) { 1056155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (token.startsWith("group_capab=")) { 1057155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] nameValue = token.split("="); 1058155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (nameValue.length != 2) break; 1059155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1060155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return Integer.decode(nameValue[1]); 1061155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch(NumberFormatException e) { 1062155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return gc; 1063155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1064155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1065155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1066155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return gc; 1067155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1068155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1069155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pPeer(String deviceAddress) { 1070155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("P2P_PEER " + deviceAddress); 1071155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1072155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1073155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String p2pGetParam(String deviceAddress, String key) { 1074155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (deviceAddress == null) return null; 1075155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1076155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String peerInfo = p2pPeer(deviceAddress); 1077155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (peerInfo == null) return null; 1078155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens= peerInfo.split("\n"); 1079155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1080155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande key += "="; 1081155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String token : tokens) { 1082155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (token.startsWith(key)) { 1083155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] nameValue = token.split("="); 1084155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (nameValue.length != 2) break; 1085155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return nameValue[1]; 1086155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1087155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1088155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return null; 1089155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1090155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1091155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) { 1092155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 1093155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour <query hexdump> <RDATA hexdump> 1094155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp <version hex> <service> 1095155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1096155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * e.g) 1097155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * [Bonjour] 1098155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * # IP Printing over TCP (PTR) (RDATA=MyPrinter._ipp._tcp.local.) 1099155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027 1100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * # IP Printing over TCP (TXT) (RDATA=txtvers=1,pdl=application/postscript) 1101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 1102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074 1103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * [UPnP] 1105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012 1106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice 1107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp 1108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * -org:device:InternetGatewayDevice:1 1109155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9322-123456789012::urn:schemas-upnp 1110155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * -org:service:ContentDirectory:2 1111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String s : servInfo.getSupplicantQueryList()) { 1113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_SERVICE_ADD"; 1114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + s); 1115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doBooleanCommand(command)) { 1116155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1117155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1118155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1119155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 1120155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1121155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1122155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) { 1123155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 1124155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_DEL bonjour <query hexdump> 1125155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_DEL upnp <version hex> <service> 1126155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1127155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String s : servInfo.getSupplicantQueryList()) { 1128155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_SERVICE_DEL "; 1129155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1130155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] data = s.split(" "); 1131155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (data.length < 2) { 1132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1133155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1134155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if ("upnp".equals(data[0])) { 1135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += s; 1136155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if ("bonjour".equals(data[0])) { 1137155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += data[0]; 1138155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + data[1]); 1139155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1140155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1141155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1142155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doBooleanCommand(command)) { 1143155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 1147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceFlush() { 1150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SERVICE_FLUSH"); 1151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pServDiscReq(String addr, String query) { 1154155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_SERV_DISC_REQ"; 1155155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + addr); 1156155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + query); 1157155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1158155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(command); 1159155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1160155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1161155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServDiscCancelReq(String id) { 1162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id); 1163155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1164155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1165155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Set the current mode of miracast operation. 1166155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 0 = disabled 1167155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1 = operating as source 1168155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 2 = operating as sink 1169155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1170155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setMiracastMode(int mode) { 1171155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Note: optional feature on the driver. It is ok for this to fail. 1172155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("DRIVER MIRACAST " + mode); 1173155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 11743f7ef65ab71619040032aee96b5599849881d6fdAndres Morales 1175446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng public boolean fetchAnqp(String bssid, String subtypes) { 1176446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng return doBooleanCommand("ANQP_GET " + bssid + " " + subtypes); 1177446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng } 1178446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng 11797f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde /* WIFI HAL support */ 11807f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1181b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static final String TAG = "WifiNative-HAL"; 1182aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static long sWifiHalHandle = 0; /* used by JNI to save wifi_handle */ 1183aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static long[] sWifiIfaceHandles = null; /* used by JNI to save interface handles */ 1184aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static int sWlan0Index = -1; 1185aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static int sP2p0Index = -1; 1186aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 1187aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static boolean sHalIsStarted = false; 1188cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande private static boolean sHalFailed = false; 11897f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1190b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean startHalNative(); 1191b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native void stopHalNative(); 1192b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native void waitForHalEventNative(); 11937f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1194b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static class MonitorThread extends Thread { 11957ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde public void run() { 1196b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.i(TAG, "Waiting for HAL events mWifiHalHandle=" + Long.toString(sWifiHalHandle)); 11977ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde waitForHalEventNative(); 11987ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 11997ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 12007ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 1201b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static boolean startHal() { 1202d6307b404302949f6dadd14fa0860ff1aec432dcxinhe 1203d6307b404302949f6dadd14fa0860ff1aec432dcxinhe String debugLog = "startHal stack: "; 1204d6307b404302949f6dadd14fa0860ff1aec432dcxinhe java.lang.StackTraceElement[] elements = Thread.currentThread().getStackTrace(); 1205d6307b404302949f6dadd14fa0860ff1aec432dcxinhe for (int i = 2; i < elements.length && i <= 7; i++ ) { 1206d6307b404302949f6dadd14fa0860ff1aec432dcxinhe debugLog = debugLog + " - " + elements[i].getMethodName(); 1207d6307b404302949f6dadd14fa0860ff1aec432dcxinhe } 1208d6307b404302949f6dadd14fa0860ff1aec432dcxinhe 1209d6307b404302949f6dadd14fa0860ff1aec432dcxinhe Log.i(TAG,debugLog); 1210d6307b404302949f6dadd14fa0860ff1aec432dcxinhe 1211aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 1212cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande if (sHalFailed) 1213cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande return false; 1214cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande if (startHalNative() && (getInterfaces() != 0) && (sWlan0Index != -1)) { 1215aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle new MonitorThread().start(); 1216aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle sHalIsStarted = true; 1217aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return true; 1218aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } else { 1219b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.i(TAG, "Could not start hal"); 1220aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle sHalIsStarted = false; 1221cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande sHalFailed = true; 1222aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return false; 1223aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 12247ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 12257ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 12267ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 1227b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void stopHal() { 12287ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde stopHalNative(); 12297ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 12307f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1231b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native int getInterfacesNative(); 12327f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1233b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static int getInterfaces() { 1234aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 123502a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande if (sWifiIfaceHandles == null) { 123602a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande int num = getInterfacesNative(); 123702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande int wifi_num = 0; 123802a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande for (int i = 0; i < num; i++) { 123902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande String name = getInterfaceNameNative(i); 124002a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande Log.i(TAG, "interface[" + i + "] = " + name); 124102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande if (name.equals("wlan0")) { 124202a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande sWlan0Index = i; 124302a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande wifi_num++; 124402a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } else if (name.equals("p2p0")) { 124502a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande sP2p0Index = i; 124602a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande wifi_num++; 124702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 1248aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 124902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande return wifi_num; 125002a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } else { 125102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande return sWifiIfaceHandles.length; 1252e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1253e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 12547f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 12557f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1256b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native String getInterfaceNameNative(int index); 1257a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande synchronized public static String getInterfaceName(int index) { 1258a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande return getInterfaceNameNative(index); 12597f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 12607f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1261e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ScanCapabilities { 1262e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_cache_size; // in number of scan results?? 1263e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_buckets; 1264e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_ap_cache_per_scan; 1265e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_rssi_sample_size; 1266e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_reporting_threshold; // in number of scan results?? 12677d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande public int max_hotlist_bssids; 1268e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_significant_wifi_change_aps; 1269e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1270e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1271b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static boolean getScanCapabilities(ScanCapabilities capabilities) { 1272aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return getScanCapabilitiesNative(sWlan0Index, capabilities); 1273e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1274e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1275b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean getScanCapabilitiesNative( 1276b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande int iface, ScanCapabilities capabilities); 1277e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1278b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean startScanNative(int iface, int id, ScanSettings settings); 1279b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean stopScanNative(int iface, int id); 128083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande private static native WifiScanner.ScanData[] getScanResultsNative(int iface, boolean flush); 1281b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native WifiLinkLayerStats getWifiLinkLayerStatsNative(int iface); 12827f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1283e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ChannelSettings { 1284e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int frequency; 1285e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int dwell_time_ms; 1286e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde boolean passive; 12877f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 12887f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1289e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class BucketSettings { 1290e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int bucket; 1291e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int band; 1292e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int period_ms; 1293e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int report_events; 1294e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int num_channels; 1295daac2ad767f6047409987bb22812ab5f295e54dfVinit Deshpande ChannelSettings channels[]; 1296e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 12977f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1298e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ScanSettings { 1299e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int base_period_ms; 1300e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int max_ap_per_scan; 130183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande int report_threshold_percent; 130283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande int report_threshold_num_scans; 1303e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int num_buckets; 1304daac2ad767f6047409987bb22812ab5f295e54dfVinit Deshpande BucketSettings buckets[]; 1305e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 13067f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1307b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface ScanEventHandler { 1308e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde void onScanResultsAvailable(); 1309476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande void onFullScanResult(ScanResult fullScanResult); 131083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande void onScanStatus(); 131183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande void onScanPaused(WifiScanner.ScanData[] data); 1312b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande void onScanRestarted(); 1313e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1314e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1315b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized static void onScanResultsAvailable(int id) { 1316b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (sScanEventHandler != null) { 1317b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande sScanEventHandler.onScanResultsAvailable(); 1318b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1319b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1320b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 1321b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande /* scan status, keep these values in sync with gscan.h */ 1322b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande private static int WIFI_SCAN_BUFFER_FULL = 0; 1323b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande private static int WIFI_SCAN_COMPLETE = 1; 1324b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 1325b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande synchronized static void onScanStatus(int status) { 1326b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande Log.i(TAG, "Got a scan status changed event, status = " + status); 1327b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 1328b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (status == WIFI_SCAN_BUFFER_FULL) { 1329b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande /* we have a separate event to take care of this */ 1330b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } else if (status == WIFI_SCAN_COMPLETE) { 1331b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (sScanEventHandler != null) { 133283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanEventHandler.onScanStatus(); 1333b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1334b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1335e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1336e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1337dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle static void populateScanResult(ScanResult result, byte bytes[], String dbg) { 1338f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde int num = 0; 1339dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (bytes == null) return; 1340dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (dbg == null) dbg = ""; 1341f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde for (int i = 0; i < bytes.length; ) { 1342e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande int type = bytes[i] & 0xFF; 1343e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande int len = bytes[i + 1] & 0xFF; 1344e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande 1345e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande if (i + len + 2 > bytes.length) { 1346dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.w(TAG, dbg + "bad length " + len + " of IE " + type + " from " + result.BSSID); 1347dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.w(TAG, dbg + "ignoring the rest of the IEs"); 1348e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande break; 1349f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1350e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande num++; 1351f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde i += len + 2; 1352dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (DBG) Log.i(TAG, dbg + "bytes[" + i + "] = [" + type + ", " + len + "]" + ", " + 1353b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande "next = " + i); 1354f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1355f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 1356243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe int secondChanelOffset = 0; 1357243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe byte channelMode = 0; 1358243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe byte centerFreqIndex1 = 0; 1359243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe byte centerFreqIndex2 = 0; 1360243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.is80211McRTTResponder = false; 1361243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1362476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande ScanResult.InformationElement elements[] = new ScanResult.InformationElement[num]; 1363f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde for (int i = 0, index = 0; i < num; i++) { 1364e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande int type = bytes[index] & 0xFF; 1365e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande int len = bytes[index + 1] & 0xFF; 1366dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (DBG) Log.i(TAG, dbg + "index = " + index + ", type = " + type + ", len = " + len); 1367476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande ScanResult.InformationElement elem = new ScanResult.InformationElement(); 1368f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde elem.id = type; 1369f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde elem.bytes = new byte[len]; 1370f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde for (int j = 0; j < len; j++) { 1371f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde elem.bytes[j] = bytes[index + j + 2]; 1372f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1373f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde elements[i] = elem; 1374243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe int inforStart = index + 2; 1375f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde index += (len + 2); 1376243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1377243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if(type == EID_HT_OPERATION) { 1378243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe secondChanelOffset = bytes[inforStart + 1] & 0x3; 1379243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else if(type == EID_VHT_OPERATION) { 1380243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe channelMode = bytes[inforStart]; 1381243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe centerFreqIndex1 = bytes[inforStart + 1]; 1382243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe centerFreqIndex2 = bytes[inforStart + 2]; 1383243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else if (type == EID_EXTENDED_CAPS) { 1384dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int tempIndex = RTT_RESP_ENABLE_BIT / 8; 1385dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle byte offset = RTT_RESP_ENABLE_BIT % 8; 1386dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1387dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if(len < tempIndex + 1) { 1388dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle result.is80211McRTTResponder = false; 1389dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 1390dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if ((bytes[inforStart + tempIndex] & ((byte)0x1 << offset)) != 0) { 1391dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle result.is80211McRTTResponder = true; 1392dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 1393dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle result.is80211McRTTResponder = false; 1394dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1395dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1396243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1397243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1398243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe //handle RTT related information 1399243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if (channelMode != 0) { 1400243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe // 80 or 160 MHz 1401243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.channelWidth = channelMode + 1; 1402243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1403243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe //convert channel index to frequency in MHz, channel 36 is 5180MHz 1404243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = (centerFreqIndex1 - 36) * 5 + 5180; 1405243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1406243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if(channelMode > 1) { //160MHz 1407243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = (centerFreqIndex2 - 36) * 5 + 5180; 1408243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1409243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = 0; 1410243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1411243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1412243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe //20 or 40 MHz 1413243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if (secondChanelOffset != 0) {//40MHz 1414243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.channelWidth = 1; 1415243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if (secondChanelOffset == 1) { 1416243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = result.frequency + 20; 1417243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else if (secondChanelOffset == 3) { 1418243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = result.frequency - 20; 1419243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1420243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = 0; 1421dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.e(TAG, dbg + ": Error on secondChanelOffset"); 1422243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1423243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1424243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = 0; 1425243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = 0; 1426243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1427243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = 0; 1428243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1429243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if(DBG) { 1430dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.d(TAG, dbg + "SSID: " + result.SSID + " ChannelWidth is: " + result.channelWidth + 1431243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe " PrimaryFreq: " + result.frequency +" mCenterfreq0: " + result.centerFreq0 + 1432243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe " mCenterfreq1: " + result.centerFreq1 + (result.is80211McRTTResponder ? 1433243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe "Support RTT reponder: " : "Do not support RTT responder")); 1434f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1435f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 1436476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande result.informationElements = elements; 1437dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1438dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1439dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle synchronized static void onFullScanResult(int id, ScanResult result, byte bytes[]) { 1440dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (DBG) Log.i(TAG, "Got a full scan results event, ssid = " + result.SSID + ", " + 1441dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle "num = " + bytes.length); 1442dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1443dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (sScanEventHandler == null) { 1444dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return; 1445dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1446dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle populateScanResult(result, bytes, " onFullScanResult "); 1447dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1448e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande sScanEventHandler.onFullScanResult(result); 14497f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 14507f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1451b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sScanCmdId = 0; 1452b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static ScanEventHandler sScanEventHandler; 1453b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static ScanSettings sScanSettings; 14547f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1455b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static boolean startScan( 1456b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande ScanSettings settings, ScanEventHandler eventHandler) { 14577f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde synchronized (mLock) { 1458b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1459b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sScanCmdId != 0) { 1460741953368eafa247f2820496aaa521bc0e86e9e1Navtej Singh Mann stopScan(); 1461b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } else if (sScanSettings != null || sScanEventHandler != null) { 1462b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande /* current scan is paused; no need to stop it */ 1463b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 14647f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1465b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanCmdId = getNewCmdIdLocked(); 1466e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1467b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanSettings = settings; 1468b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanEventHandler = eventHandler; 1469b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1470b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (startScanNative(sWlan0Index, sScanCmdId, settings) == false) { 1471b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanEventHandler = null; 1472b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanSettings = null; 147383a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanCmdId = 0; 1474e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1475e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1476e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1477e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return true; 1478e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 14797f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 14807f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1481b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void stopScan() { 1482b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized (mLock) { 1483b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande stopScanNative(sWlan0Index, sScanCmdId); 1484b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanSettings = null; 1485b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanEventHandler = null; 1486b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanCmdId = 0; 1487b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1488b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1489b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1490b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void pauseScan() { 14917f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde synchronized (mLock) { 1492b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sScanCmdId != 0 && sScanSettings != null && sScanEventHandler != null) { 1493b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.d(TAG, "Pausing scan"); 149483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande WifiScanner.ScanData scanData[] = getScanResultsNative(sWlan0Index, true); 1495b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande stopScanNative(sWlan0Index, sScanCmdId); 1496b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanCmdId = 0; 149783a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanEventHandler.onScanPaused(scanData); 1498b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1499b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1500b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1501b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1502b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void restartScan() { 1503b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized (mLock) { 1504b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sScanCmdId == 0 && sScanSettings != null && sScanEventHandler != null) { 1505b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.d(TAG, "Restarting scan"); 150683a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ScanEventHandler handler = sScanEventHandler; 150783a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ScanSettings settings = sScanSettings; 150883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande if (startScan(sScanSettings, sScanEventHandler)) { 150983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanEventHandler.onScanRestarted(); 151083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande } else { 151183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande /* we are still paused; don't change state */ 151283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanEventHandler = handler; 151383a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanSettings = settings; 151483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande } 1515b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1516e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1517e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1518e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 151983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande synchronized public static WifiScanner.ScanData[] getScanResults(boolean flush) { 1520aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 152183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande return getScanResultsNative(sWlan0Index, flush); 1522aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1523e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1524e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1525b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface HotlistEventHandler { 1526d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande void onHotlistApFound (ScanResult[] result); 1527d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande void onHotlistApLost (ScanResult[] result); 1528e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1529e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1530b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sHotlistCmdId = 0; 1531b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static HotlistEventHandler sHotlistEventHandler; 1532e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1533b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private native static boolean setHotlistNative(int iface, int id, 1534e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde WifiScanner.HotlistSettings settings); 1535b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private native static boolean resetHotlistNative(int iface, int id); 1536e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1537b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static boolean setHotlist(WifiScanner.HotlistSettings settings, 1538aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle HotlistEventHandler eventHandler) { 1539e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 1540b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sHotlistCmdId != 0) { 1541e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1542e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } else { 1543b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistCmdId = getNewCmdIdLocked(); 1544e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1545e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1546b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistEventHandler = eventHandler; 1547b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (setHotlistNative(sWlan0Index, sScanCmdId, settings) == false) { 1548b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistEventHandler = null; 1549e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1550e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1551e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1552e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return true; 1553e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1554e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1555e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1556b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void resetHotlist() { 1557e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 1558b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sHotlistCmdId != 0) { 1559b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande resetHotlistNative(sWlan0Index, sHotlistCmdId); 1560b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistCmdId = 0; 1561b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistEventHandler = null; 1562e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 15637f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 15647f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 1565e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1566b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void onHotlistApFound(int id, ScanResult[] results) { 1567aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 15681814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande if (sHotlistCmdId != 0) { 15691814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande sHotlistEventHandler.onHotlistApFound(results); 15701814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande } else { 15711814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande /* this can happen because of race conditions */ 1572d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande Log.d(TAG, "Ignoring hotlist AP found event"); 1573d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 1574d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 1575d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 1576d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 1577d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande synchronized public static void onHotlistApLost(int id, ScanResult[] results) { 1578d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande synchronized (mLock) { 1579d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande if (sHotlistCmdId != 0) { 1580d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande sHotlistEventHandler.onHotlistApLost(results); 1581d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } else { 1582d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande /* this can happen because of race conditions */ 1583d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande Log.d(TAG, "Ignoring hotlist AP lost event"); 15841814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande } 1585aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1586e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1587e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1588b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface SignificantWifiChangeEventHandler { 1589e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde void onChangesFound(ScanResult[] result); 1590e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1591e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1592b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static SignificantWifiChangeEventHandler sSignificantWifiChangeHandler; 1593b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sSignificantWifiChangeCmdId; 1594e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1595b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean trackSignificantWifiChangeNative( 1596e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int iface, int id, WifiScanner.WifiChangeSettings settings); 1597b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean untrackSignificantWifiChangeNative(int iface, int id); 1598e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1599b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static boolean trackSignificantWifiChange( 1600b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande WifiScanner.WifiChangeSettings settings, SignificantWifiChangeEventHandler handler) { 1601e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 1602b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sSignificantWifiChangeCmdId != 0) { 1603e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1604e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } else { 1605b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sSignificantWifiChangeCmdId = getNewCmdIdLocked(); 1606e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1607e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1608b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sSignificantWifiChangeHandler = handler; 1609b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (trackSignificantWifiChangeNative(sWlan0Index, sScanCmdId, settings) == false) { 16101814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande sSignificantWifiChangeHandler = null; 1611e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1612e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1613e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1614e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return true; 1615e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1616e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1617e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1618b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized static void untrackSignificantWifiChange() { 1619e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 1620b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sSignificantWifiChangeCmdId != 0) { 1621b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande untrackSignificantWifiChangeNative(sWlan0Index, sSignificantWifiChangeCmdId); 1622b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sSignificantWifiChangeCmdId = 0; 1623b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sSignificantWifiChangeHandler = null; 1624e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1625e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1626e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1627e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1628b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized static void onSignificantWifiChange(int id, ScanResult[] results) { 1629aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 16301814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande if (sSignificantWifiChangeCmdId != 0) { 16311814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande sSignificantWifiChangeHandler.onChangesFound(results); 16321814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande } else { 16331814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande /* this can happen because of race conditions */ 16341814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande Log.d(TAG, "Ignoring significant wifi change"); 16351814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande } 1636aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1637e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1638e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1639200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle synchronized public static WifiLinkLayerStats getWifiLinkLayerStats(String iface) { 1640200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle // TODO: use correct iface name to Index translation 1641200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle if (iface == null) return null; 1642aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 1643aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle if (!sHalIsStarted) 1644aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle startHal(); 1645aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle if (sHalIsStarted) 1646aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return getWifiLinkLayerStatsNative(sWlan0Index); 1647aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1648aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return null; 1649aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 16505c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16515c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales /* 16525c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales * NFC-related calls 16535c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales */ 16545c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public String getNfcWpsConfigurationToken(int netId) { 16555c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doStringCommand("WPS_NFC_CONFIG_TOKEN WPS " + netId); 16565c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16575c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16585c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public String getNfcHandoverRequest() { 16595c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doStringCommand("NFC_GET_HANDOVER_REQ NDEF P2P-CR"); 16605c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16615c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16625c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public String getNfcHandoverSelect() { 16635c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doStringCommand("NFC_GET_HANDOVER_SEL NDEF P2P-CR"); 16645c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16655c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16665c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public boolean initiatorReportNfcHandover(String selectMessage) { 16675c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doBooleanCommand("NFC_REPORT_HANDOVER INIT P2P 00 " + selectMessage); 16685c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16695c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16705c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public boolean responderReportNfcHandover(String requestMessage) { 16715c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doBooleanCommand("NFC_REPORT_HANDOVER RESP P2P " + requestMessage + " 00"); 16725c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16735c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 1674c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande public static native int getSupportedFeatureSetNative(int iface); 1675a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande synchronized public static int getSupportedFeatureSet() { 1676c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande return getSupportedFeatureSetNative(sWlan0Index); 1677a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande } 1678143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1679143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande /* Rtt related commands/events */ 1680143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande public static interface RttEventHandler { 1681143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande void onRttResults(RttManager.RttResult[] result); 1682143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1683143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1684143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static RttEventHandler sRttEventHandler; 1685143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static int sRttCmdId; 1686143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1687143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized private static void onRttResults(int id, RttManager.RttResult[] results) { 1688143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (id == sRttCmdId) { 168902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande Log.d(TAG, "Received " + results.length + " rtt results"); 1690143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttEventHandler.onRttResults(results); 1691143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttCmdId = 0; 1692143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 1693f95649f33db0a328cb4c0bb5e10c7075e6c828f8xinhe Log.d(TAG, "RTT Received event for unknown cmd = " + id + ", current id = " + sRttCmdId); 1694143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1695143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1696143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1697143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static native boolean requestRangeNative( 1698143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande int iface, int id, RttManager.RttParams[] params); 1699143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static native boolean cancelRangeRequestNative( 1700143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande int iface, int id, RttManager.RttParams[] params); 1701143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1702143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized public static boolean requestRtt( 1703143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande RttManager.RttParams[] params, RttEventHandler handler) { 1704143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized (mLock) { 1705143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (sRttCmdId != 0) { 1706f95649f33db0a328cb4c0bb5e10c7075e6c828f8xinhe Log.v("TAG", "Last one is still under measurement!"); 1707143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 1708143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 1709143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttCmdId = getNewCmdIdLocked(); 1710143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1711143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttEventHandler = handler; 1712f95649f33db0a328cb4c0bb5e10c7075e6c828f8xinhe Log.v(TAG, "native issue RTT request"); 1713143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return requestRangeNative(sWlan0Index, sRttCmdId, params); 1714143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1715143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1716143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1717143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized public static boolean cancelRtt(RttManager.RttParams[] params) { 1718143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized(mLock) { 1719143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (sRttCmdId == 0) { 1720143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 1721143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1722143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1723f95649f33db0a328cb4c0bb5e10c7075e6c828f8xinhe sRttCmdId = 0; 1724f95649f33db0a328cb4c0bb5e10c7075e6c828f8xinhe 1725143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (cancelRangeRequestNative(sWlan0Index, sRttCmdId, params)) { 1726143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttEventHandler = null; 1727f95649f33db0a328cb4c0bb5e10c7075e6c828f8xinhe Log.v(TAG, "Xin: RTT cancel Request Successfully"); 1728143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return true; 1729143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 1730f95649f33db0a328cb4c0bb5e10c7075e6c828f8xinhe Log.e(TAG, "Xin:RTT cancel Request failed"); 1731143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 1732143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1733143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1734143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1735042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1736042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande private static native boolean setScanningMacOuiNative(int iface, byte[] oui); 1737042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1738042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande synchronized public static boolean setScanningMacOui(byte[] oui) { 1739042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande synchronized (mLock) { 1740042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande if (startHal()) { 1741042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande return setScanningMacOuiNative(sWlan0Index, oui); 1742042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } else { 1743042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande return false; 1744042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 1745042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 1746042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 1747efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 1748efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande private static native int[] getChannelsForBandNative( 1749efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande int iface, int band); 1750efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 1751efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande synchronized public static int [] getChannelsForBand(int band) { 1752efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande synchronized (mLock) { 1753efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande if (startHal()) { 1754efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande return getChannelsForBandNative(sWlan0Index, band); 1755efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } else { 1756efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande return null; 1757efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 1758efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 1759efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 17600465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande 17610465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande 17620465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande private static native boolean setDfsFlagNative(int iface, boolean dfsOn); 17630465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande synchronized public static boolean setDfsFlag(boolean dfsOn) { 17640465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande synchronized (mLock) { 17650465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande if (startHal()) { 17660465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return setDfsFlagNative(sWlan0Index, dfsOn); 17670465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } else { 17680465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return false; 17690465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 17700465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 17710465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 1772b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe 1773b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe private static native boolean toggleInterfaceNative(int on); 1774b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe synchronized public static boolean toggleInterface(int on) { 1775b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe synchronized (mLock) { 1776b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe if (startHal()) { 1777b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe return toggleInterfaceNative(0); 1778b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } else { 1779b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe 1780b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe return false; 1781b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 1782b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 1783b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 178412cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 178512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe private static native RttManager.RttCapabilities getRttCapabilitiesNative(int iface); 178612cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe synchronized public static RttManager.RttCapabilities getRttCapabilities() { 178712cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe synchronized (mLock) { 178812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe if (startHal()) { 178912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe return getRttCapabilitiesNative(sWlan0Index); 179012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } else { 179112cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe return null; 179212cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 179312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 179412cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 1795939177ff615062ec826601d536466875d8457375xinhe 1796939177ff615062ec826601d536466875d8457375xinhe private static native boolean setCountryCodeHalNative(int iface, String CountryCode); 1797939177ff615062ec826601d536466875d8457375xinhe synchronized public static boolean setCountryCodeHal( String CountryCode) { 1798939177ff615062ec826601d536466875d8457375xinhe synchronized (mLock) { 1799939177ff615062ec826601d536466875d8457375xinhe if (startHal()) { 1800939177ff615062ec826601d536466875d8457375xinhe return setCountryCodeHalNative(sWlan0Index, CountryCode); 1801939177ff615062ec826601d536466875d8457375xinhe } else { 1802939177ff615062ec826601d536466875d8457375xinhe return false; 1803939177ff615062ec826601d536466875d8457375xinhe } 1804939177ff615062ec826601d536466875d8457375xinhe } 1805939177ff615062ec826601d536466875d8457375xinhe } 1806939177ff615062ec826601d536466875d8457375xinhe 1807d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe /* Rtt related commands/events */ 1808d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe public abstract class TdlsEventHandler { 1809d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe abstract public void onTdlsStatus(String macAddr, int status, int reason); 1810d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1811d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1812d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe private static TdlsEventHandler sTdlsEventHandler; 1813d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1814d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1815d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe private static native boolean enableDisableTdlsNative(int iface, boolean enable, 1816d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe String macAddr); 1817d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized public static boolean enableDisableTdls(boolean enable, String macAdd, 1818d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe TdlsEventHandler tdlsCallBack) { 1819d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized (mLock) { 1820d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe if (startHal()) { 1821d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe sTdlsEventHandler = tdlsCallBack; 1822d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return enableDisableTdlsNative(sWlan0Index, enable, macAdd); 1823d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 1824d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return false; 1825d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1826d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1827d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1828d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1829d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe // Once TDLS per mac and event feature is implemented, this class definition should be 1830d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe // moved to the right place, like WifiManager etc 1831d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe public static class TdlsStatus { 1832d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int channel; 1833d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int global_operating_class; 1834d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int state; 1835d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int reason; 1836d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1837d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe private static native TdlsStatus getTdlsStatusNative(int iface, String macAddr); 1838d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized public static TdlsStatus getTdlsStatus (String macAdd) { 1839d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized (mLock) { 1840d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe if (startHal()) { 1841d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return getTdlsStatusNative(sWlan0Index, macAdd); 1842d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 1843d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return null; 1844d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1845d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1846d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1847d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1848d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe //ToFix: Once TDLS per mac and event feature is implemented, this class definition should be 1849d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe // moved to the right place, like WifiStateMachine etc 1850d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe public static class TdlsCapabilities { 1851d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe /* Maximum TDLS session number can be supported by the Firmware and hardware */ 1852d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int maxConcurrentTdlsSessionNumber; 1853d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe boolean isGlobalTdlsSupported; 1854d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe boolean isPerMacTdlsSupported; 1855d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe boolean isOffChannelTdlsSupported; 1856d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1857d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1858d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1859d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1860d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe private static native TdlsCapabilities getTdlsCapabilitiesNative(int iface); 1861d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized public static TdlsCapabilities getTdlsCapabilities () { 1862d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized (mLock) { 1863d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe if (startHal()) { 1864d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return getTdlsCapabilitiesNative(sWlan0Index); 1865d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 1866d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return null; 1867d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1868d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1869d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1870d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1871d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized private static boolean onTdlsStatus(String macAddr, int status, int reason) { 1872d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe if (sTdlsEventHandler == null) { 1873d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return false; 1874d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 1875d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe sTdlsEventHandler.onTdlsStatus(macAddr, status, reason); 1876d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return true; 1877d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1878d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1879d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1880a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle //--------------------------------------------------------------------------------- 1881a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1882a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle /* Wifi Logger commands/events */ 18837d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande 18847d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande private static native boolean startLogging(int iface); 18857d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande 1886a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle public static interface WifiLoggerEventHandler { 1887a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle void onDataAvailable(char data[], int len); 1888a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 1889a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1890a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle private static WifiLoggerEventHandler sWifiLoggerEventHandler = null; 1891a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1892a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle synchronized private static void onDataAvailable(char data[], int len) { 1893a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle if (sWifiLoggerEventHandler != null) { 1894a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle sWifiLoggerEventHandler.onDataAvailable(data, len); 1895a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 1896a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 1897dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1898dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //--------------------------------------------------------------------------------- 1899dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle /* Configure ePNO */ 1900dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1901dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle public class WifiPnoNetwork { 1902dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle String SSID; 1903dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int rssi_threshold; 1904dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int flags; 1905dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int auth; 1906dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle String configKey; // kept for reference 1907dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1908dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle WifiPnoNetwork(WifiConfiguration config, int threshold) { 1909dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (config.SSID == null) { 1910dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle this.SSID = ""; 1911dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle this.flags = 1; 1912dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 1913dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle this.SSID = config.SSID; 1914dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1915dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle this.rssi_threshold = threshold; 1916dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK)) { 1917dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle auth |= 2; 1918dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP) || 1919dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.IEEE8021X)) { 1920dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle auth |= 4; 1921dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else if (config.wepKeys[0] != null) { 1922dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle auth |= 1; 1923dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 1924dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle auth |= 1; 1925dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1926dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle// auth = 0; 1927dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle flags |= 6; //A and G 1928dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle configKey = config.configKey(); 1929dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1930dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1931dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle @Override 1932dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle public String toString() { 1933dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle StringBuilder sbuf = new StringBuilder(); 1934dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sbuf.append(this.SSID); 1935dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sbuf.append(" flags=").append(this.flags); 1936dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sbuf.append(" rssi=").append(this.rssi_threshold); 1937dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sbuf.append(" auth=").append(this.auth); 1938dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return sbuf.toString(); 1939dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1940dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1941dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1942dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle public static interface WifiPnoEventHandler { 1943dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle void onPnoNetworkFound(ScanResult results[]); 1944dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1945dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1946dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle private static WifiPnoEventHandler sWifiPnoEventHandler; 1947dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1948dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle private static int sPnoCmdId = 0; 1949dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1950dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle private native static boolean setPnoListNative(int iface, int id, WifiPnoNetwork list[]); 1951dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1952dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle synchronized public static boolean setPnoList(WifiPnoNetwork list[], 1953dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle WifiPnoEventHandler eventHandler) { 1954dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.e(TAG, "setPnoList cmd " + sPnoCmdId); 1955dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1956dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle synchronized (mLock) { 1957dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1958dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sPnoCmdId = getNewCmdIdLocked(); 1959dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1960dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sWifiPnoEventHandler = eventHandler; 1961dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (setPnoListNative(sWlan0Index, sPnoCmdId, list) == false) { 1962dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sWifiPnoEventHandler = null; 1963dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return false; 1964dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1965dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1966dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return true; 1967dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1968dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1969dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1970dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle synchronized public static void onPnoNetworkFound(int id, ScanResult[] results) { 1971dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1972dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (results == null) { 1973dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.e(TAG, "onPnoNetworkFound null results"); 1974dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return; 1975dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1976dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1977dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.d(TAG, "WifiNative.onPnoNetworkFound result " + results.length); 1978dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1979dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //Log.e(TAG, "onPnoNetworkFound length " + results.length); 1980dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //return; 1981dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle for (int i=0; i<results.length; i++) { 1982dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.e(TAG, "onPnoNetworkFound SSID " + results[i].SSID 1983dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle + " " + results[i].level + " " + results[i].frequency); 1984dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1985dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle populateScanResult(results[i], results[i].bytes, "onPnoNetworkFound "); 1986dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle results[i].wifiSsid = WifiSsid.createFromAsciiEncoded(results[i].SSID); 1987dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1988dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle synchronized (mLock) { 1989dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (sPnoCmdId != 0 && sWifiPnoEventHandler != null) { 1990dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sWifiPnoEventHandler.onPnoNetworkFound(results); 1991dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 1992dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle /* this can happen because of race conditions */ 1993dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.d(TAG, "Ignoring Pno Network found event"); 1994dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1995dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1996dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle} 1997dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1998155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 1999