WifiNative.java revision 7d6301ead19afdf3de37455e9ed133c25b4938cd
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; 22aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalleimport android.net.wifi.WifiLinkLayerStats; 2303cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidtimport android.net.wifi.WifiManager; 24e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndeimport android.net.wifi.WifiScanner; 2512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinheimport android.net.wifi.RttManager; 26155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.WpsInfo; 27155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.WifiP2pConfig; 28155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.WifiP2pGroup; 2903cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidtimport android.net.wifi.p2p.nsd.WifiP2pServiceInfo; 30f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalleimport android.os.SystemClock; 31155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.text.TextUtils; 32155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.LocalLog; 33155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.Log; 34155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 35155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.ArrayList; 36155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.List; 37155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.Locale; 38155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 39155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/** 40155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Native calls for bring up/shut down of the supplicant daemon and for 41155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * sending requests to the supplicant daemon 42155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 43155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * waitForEvent() is called on the monitor thread for events. All other methods 44155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * must be serialized from the framework. 45155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 46155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@hide} 47155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 48155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandepublic class WifiNative { 49155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 50ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle private static boolean DBG = false; 51155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private final String mTAG; 52155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private static final int DEFAULT_GROUP_OWNER_INTENT = 6; 53155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 54155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0; 55155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED = 1; 56155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2; 57155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 58155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int SCAN_WITHOUT_CONNECTION_SETUP = 1; 59155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final int SCAN_WITH_CONNECTION_SETUP = 2; 60155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 61155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Hold this lock before calling supplicant - it is required to 62155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // mutually exclude access from Wifi and P2p state machines 63155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static final Object mLock = new Object(); 64155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 65155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public final String mInterfaceName; 66155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public final String mInterfacePrefix; 67155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 68155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private boolean mSuspendOptEnabled = false; 69155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 70243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe private static final int EID_HT_OPERATION = 61; 71243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe private static final int EID_VHT_OPERATION = 192; 72243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe private static final int EID_EXTENDED_CAPS = 127; 73243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe private static final int RTT_RESP_ENABLE_BIT = 70; 74155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Register native functions */ 75155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 76155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static { 77155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Native functions are defined in libwifi-service.so */ 78155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande System.loadLibrary("wifi-service"); 79155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande registerNatives(); 80155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 81155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 82155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private static native int registerNatives(); 83155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 84155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean loadDriver(); 85155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 86155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean isDriverLoaded(); 87155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 88155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean unloadDriver(); 89155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 90155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean startSupplicant(boolean p2pSupported); 91155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 92155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Sends a kill signal to supplicant. To be used when we have lost connection 93155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande or when the supplicant is hung */ 94155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public native static boolean killSupplicant(boolean p2pSupported); 95155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 96155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native boolean connectToSupplicantNative(); 97155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 98155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native void closeSupplicantConnectionNative(); 99155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Wait for the supplicant to send an event, returning the event string. 102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return the event string sent by the supplicant. 103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native String waitForEventNative(); 105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native boolean doBooleanCommandNative(String command); 107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native int doIntCommandNative(String command); 109155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 110155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private native String doStringCommandNative(String command); 111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public WifiNative(String interfaceName) { 113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfaceName = interfaceName; 114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mTAG = "WifiNative-" + interfaceName; 115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!interfaceName.equals("p2p0")) { 116155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfacePrefix = "IFNAME=" + interfaceName + " "; 117155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 118155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // commands for p2p0 interface don't need prefix 119155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfacePrefix = ""; 120155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 121155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 122155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 123ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle void enableVerboseLogging(int verbose) { 124ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle if (verbose > 0) { 125ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle DBG = true; 126ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } else { 127ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle DBG = false; 128ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } 129ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } 130ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle 131155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private static final LocalLog mLocalLog = new LocalLog(1024); 132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 133155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // hold mLock before accessing mCmdIdLock 134b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sCmdId; 135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 136155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public LocalLog getLocalLog() { 137155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mLocalLog; 138155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 139155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 140b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int getNewCmdIdLocked() { 141b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande return sCmdId++; 142155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 143155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void localLog(String s) { 145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mLocalLog != null) 146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mLocalLog.log(mInterfaceName + ": " + s); 147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean connectToSupplicant() { 150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // No synchronization necessary .. it is implemented in WifiMonitor 151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande localLog(mInterfacePrefix + "connectToSupplicant"); 152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return connectToSupplicantNative(); 153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 154155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 155155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void closeSupplicantConnection() { 156155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande localLog(mInterfacePrefix + "closeSupplicantConnection"); 157155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande closeSupplicantConnectionNative(); 158155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 159155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 160155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String waitForEvent() { 161155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // No synchronization necessary .. it is implemented in WifiMonitor 162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return waitForEventNative(); 163155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 164155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 165155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private boolean doBooleanCommand(String command) { 166155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "doBoolean: " + command); 167155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 168155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int cmdId = getNewCmdIdLocked(); 1697b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle String toLog = Integer.toString(cmdId) + ":" + mInterfacePrefix + command; 170155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande boolean result = doBooleanCommandNative(mInterfacePrefix + command); 1717b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 1720888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) Log.d(mTAG, command + ": returned " + result); 173155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 174155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 175155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 176155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 177155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int doIntCommand(String command) { 178155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "doInt: " + command); 179155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 180155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int cmdId = getNewCmdIdLocked(); 1817b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle String toLog = Integer.toString(cmdId) + ":" + mInterfacePrefix + command; 182155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int result = doIntCommandNative(mInterfacePrefix + command); 1837b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 184155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, " returned " + result); 185155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 186155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 187155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 188155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 189155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String doStringCommand(String command) { 1900888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) { 1910888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle //GET_NETWORK commands flood the logs 1920888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (!command.startsWith("GET_NETWORK")) { 1930888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle Log.d(mTAG, "doString: [" + command + "]"); 1940888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 1950888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 196155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 197155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int cmdId = getNewCmdIdLocked(); 1987b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle String toLog = Integer.toString(cmdId) + ":" + mInterfacePrefix + command; 199155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String result = doStringCommandNative(mInterfacePrefix + command); 20040ff222cec1bd05879edb53abc75c6deead734cavandwalle if (result == null) { 20140ff222cec1bd05879edb53abc75c6deead734cavandwalle if (DBG) Log.d(mTAG, "doStringCommandNative no result"); 20240ff222cec1bd05879edb53abc75c6deead734cavandwalle } else { 2037b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle if (!command.startsWith("STATUS-")) { 2047b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 2057b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle } 20640ff222cec1bd05879edb53abc75c6deead734cavandwalle if (DBG) Log.d(mTAG, " returned " + result.replace("\n", " ")); 20740ff222cec1bd05879edb53abc75c6deead734cavandwalle } 208155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 209155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 210155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 211155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 212155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String doStringCommandWithoutLogging(String command) { 2130888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) { 2140888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle //GET_NETWORK commands flood the logs 2150888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (!command.startsWith("GET_NETWORK")) { 2160888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle Log.d(mTAG, "doString: [" + command + "]"); 2170888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 21827355a942653264388e909a4276196ee63e57811vandwalle } 21927355a942653264388e909a4276196ee63e57811vandwalle synchronized (mLock) { 220155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative(mInterfacePrefix + command); 221155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 222155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 223155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 224155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean ping() { 225155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String pong = doStringCommand("PING"); 226155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (pong != null && pong.equals("PONG")); 227155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 228155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 229ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle public void setSupplicantLogLevel(String level) { 230ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle doStringCommand("LOG_LEVEL " + level); 231ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle } 232ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle 233a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng public String getFreqCapability() { 234a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng return doStringCommand("GET_CAPABILITY freq"); 235a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng } 236a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng 237a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng public boolean scan(int type, String freqList) { 238155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (type == SCAN_WITHOUT_CONNECTION_SETUP) { 239a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (freqList == null) return doBooleanCommand("SCAN TYPE=ONLY"); 240a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng else return doBooleanCommand("SCAN TYPE=ONLY freq=" + freqList); 241155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (type == SCAN_WITH_CONNECTION_SETUP) { 242a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (freqList == null) return doBooleanCommand("SCAN"); 243a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng else return doBooleanCommand("SCAN freq=" + freqList); 244155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 245155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande throw new IllegalArgumentException("Invalid scan type"); 246155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 247155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 248155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 249155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Does a graceful shutdown of supplicant. Is a common stop function for both p2p and sta. 250155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 251155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Note that underneath we use a harsh-sounding "terminate" supplicant command 252155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * for a graceful stop and a mild-sounding "stop" interface 253155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * to kill the process 254155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 255155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopSupplicant() { 256155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("TERMINATE"); 257155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 258155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 259155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String listNetworks() { 260155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("LIST_NETWORKS"); 261155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 262155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 263e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande public String listNetworks(int last_id) { 264e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande return doStringCommand("LIST_NETWORKS LAST_ID=" + last_id); 265e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande } 266e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande 267155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int addNetwork() { 268155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doIntCommand("ADD_NETWORK"); 269155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 270155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 271155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setNetworkVariable(int netId, String name, String value) { 272155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(name) || TextUtils.isEmpty(value)) return false; 273155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET_NETWORK " + netId + " " + name + " " + value); 274155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 275155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 276155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getNetworkVariable(int netId, String name) { 277155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(name)) return null; 278155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 279155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // GET_NETWORK will likely flood the logs ... 280155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandWithoutLogging("GET_NETWORK " + netId + " " + name); 281155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 282155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 283155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean removeNetwork(int netId) { 284155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("REMOVE_NETWORK " + netId); 285155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 286155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 287f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 288f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle private void logDbg(String debug) { 289f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle long now = SystemClock.elapsedRealtimeNanos(); 290f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle String ts = String.format("[%,d us] ", now/1000); 291ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle Log.e("WifiNative: ", ts+debug+ " stack:" 292ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[2].getMethodName() +" - " 293ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[3].getMethodName() +" - " 294ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[4].getMethodName() +" - " 295ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[5].getMethodName()+" - " 296ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[6].getMethodName()); 297f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 298f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 299155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean enableNetwork(int netId, boolean disableOthers) { 300ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle if (DBG) logDbg("enableNetwork nid=" + Integer.toString(netId) 301ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + " disableOthers=" + disableOthers); 302155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (disableOthers) { 303155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SELECT_NETWORK " + netId); 304155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 305155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("ENABLE_NETWORK " + netId); 306155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 307155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 308155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 309155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean disableNetwork(int netId) { 310f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("disableNetwork nid=" + Integer.toString(netId)); 311155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DISABLE_NETWORK " + netId); 312155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 313155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 314155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean reconnect() { 315f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("RECONNECT "); 316155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("RECONNECT"); 317155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 318155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 319155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean reassociate() { 320f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("REASSOCIATE "); 321155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("REASSOCIATE"); 322155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 323155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 324155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean disconnect() { 32521bc54cb37a0085b1c909cb4d55ebb12a2facefbvandwalle if (DBG) logDbg("DISCONNECT "); 326155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DISCONNECT"); 327155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 328155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 329155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String status() { 33099d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return status(false); 331155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 332155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 33399d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle public String status(boolean noEvents) { 33499d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle if (noEvents) { 33599d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return doStringCommand("STATUS-NO_EVENTS"); 33699d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } else { 33799d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return doStringCommand("STATUS"); 33899d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } 33999d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } 34099d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle 341155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getMacAddress() { 342155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //Macaddr = XX.XX.XX.XX.XX.XX 343155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String ret = doStringCommand("DRIVER MACADDR"); 344155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!TextUtils.isEmpty(ret)) { 345155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens = ret.split(" = "); 346155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (tokens.length == 2) return tokens[1]; 347155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 348155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return null; 349155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 350155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 351a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 352a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 353155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 354155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Format of results: 355155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * ================= 356155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * id=1 357155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * bssid=68:7f:74:d7:1b:6e 358155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * freq=2412 359155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * level=-43 360155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * tsf=1344621975160944 361155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * age=2623 362155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * flags=[WPA2-PSK-CCMP][WPS][ESS] 363155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * ssid=zubyb 364155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * ==== 365155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 366155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RANGE=ALL gets all scan results 367155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RANGE=ID- gets results from ID 368155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * MASK=<N> see wpa_supplicant/src/common/wpa_ctrl.h for details 36977f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 0 1 0 2 37077f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_MESH_SCAN | WPA_BSS_MASK_DELIM | WPA_BSS_MASK_WIFI_DISPLAY 37177f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 0 0 1 1 -> 9 37277f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_INTERNETW | WPA_BSS_MASK_P2P_SCAN | WPA_BSS_MASK_WPS_SCAN | WPA_BSS_MASK_SSID 37377f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 1 0 0 1 9 -> d 37477f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_FLAGS | WPA_BSS_MASK_IE | WPA_BSS_MASK_AGE | WPA_BSS_MASK_TSF 37577f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 1 0 0 0 8 37677f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_LEVEL | WPA_BSS_MASK_NOISE | WPA_BSS_MASK_QUAL | WPA_BSS_MASK_CAPABILITIES 37777f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 1 1 1 7 37877f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_BEACON_INT | WPA_BSS_MASK_FREQ | WPA_BSS_MASK_BSSID | WPA_BSS_MASK_ID 37977f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 38077f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_INTERNETW adds ANQP info (ctrl_iface:4151-4176) 38177f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 38277f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * ctrl_iface.c:wpa_supplicant_ctrl_iface_process:7884 38377f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * wpa_supplicant_ctrl_iface_bss:4315 38477f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * print_bss_info 385155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 386155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String scanResults(int sid) { 38777f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist return doStringCommandWithoutLogging("BSS RANGE=" + sid + "- MASK=0x29d87"); 38877f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist } 38977f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist 39077f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist public String doCustomCommand(String command) { 39177f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist return doStringCommand(command); 392155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 393155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 394155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 395446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * Format of result: 396446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * id=1016 397446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * bssid=00:03:7f:40:84:10 398446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * freq=2462 399446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * beacon_int=200 400446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * capabilities=0x0431 401446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * qual=0 402446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * noise=0 403446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * level=-46 404446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * tsf=0000002669008476 405446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * age=5 406446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * ie=00105143412d485332302d52322d54455354010882848b960c12182403010b0706555... 407446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * flags=[WPA2-EAP-CCMP][ESS][P2P][HS20] 408446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * ssid=QCA-HS20-R2-TEST 409446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * p2p_device_name= 41056d0178183460eed9afbd85e5c0d215e27d5f5bcvandwalle * p2p_config_methods=0x0SET_NE 411446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_venue_name=02083d656e6757692d466920416c6c69616e63650a3239383920436f... 412446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_network_auth_type=010000 413446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_roaming_consortium=03506f9a05001bc504bd 414446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_ip_addr_type_availability=0c 415446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_nai_realm=0200300000246d61696c2e6578616d706c652e636f6d3b636973636f2... 416446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_3gpp=000600040132f465 417446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_domain_name=0b65786d61706c652e636f6d 418446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_operator_friendly_name=11656e6757692d466920416c6c69616e63650e636869... 419446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_wan_metrics=01c40900008001000000000a00 420446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_connection_capability=0100000006140001061600000650000106bb010106bb0... 421446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_osu_providers_list=0b5143412d4f53552d425353010901310015656e6757692d... 422446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng */ 423446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng public String scanResult(String bssid) { 424446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng return doStringCommand("BSS " + bssid); 425446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng } 426446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng 427446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng /** 428155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Format of command 429155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER WLS_BATCHING SET SCANFREQ=x MSCAN=r BESTN=y CHANNEL=<z, w, t> RTT=s 430155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * where x is an ascii representation of an integer number of seconds between scans 431155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * r is an ascii representation of an integer number of scans per batch 432155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * y is an ascii representation of an integer number of the max AP to remember per scan 433155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * z, w, t represent a 1..n size list of channel numbers and/or 'A', 'B' values 434155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * indicating entire ranges of channels 435155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * s is an ascii representation of an integer number of highest-strength AP 436155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * for which we'd like approximate distance reported 437155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 438155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The return value is an ascii integer representing a guess of the number of scans 439155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * the firmware can remember before it runs out of buffer space or -1 on error 440155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 441155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String setBatchedScanSettings(BatchedScanSettings settings) { 442155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (settings == null) { 443155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("DRIVER WLS_BATCHING STOP"); 444155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 445155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String cmd = "DRIVER WLS_BATCHING SET SCANFREQ=" + settings.scanIntervalSec; 446155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += " MSCAN=" + settings.maxScansPerBatch; 447155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (settings.maxApPerScan != BatchedScanSettings.UNSPECIFIED) { 448155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += " BESTN=" + settings.maxApPerScan; 449155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 450155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (settings.channelSet != null && !settings.channelSet.isEmpty()) { 451155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += " CHANNEL=<"; 452155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int i = 0; 453155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String channel : settings.channelSet) { 454155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += (i > 0 ? "," : "") + channel; 455155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ++i; 456155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 457155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += ">"; 458155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 459155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (settings.maxApForDistance != BatchedScanSettings.UNSPECIFIED) { 460155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande cmd += " RTT=" + settings.maxApForDistance; 461155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 462155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(cmd); 463155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 464155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 465155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getBatchedScanResults() { 466155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("DRIVER WLS_BATCHING GET"); 467155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 468155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 469155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startDriver() { 470155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER START"); 471155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 472155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 473155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopDriver() { 474155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER STOP"); 475155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 476155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 477155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 478155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 479155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Start filtering out Multicast V4 packets 480155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 481155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 482155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Multicast filtering rules work as follows: 483155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 484155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The driver can filter multicast (v4 and/or v6) and broadcast packets when in 485155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * a power optimized mode (typically when screen goes off). 486155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 487155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * In order to prevent the driver from filtering the multicast/broadcast packets, we have to 488155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * add a DRIVER RXFILTER-ADD rule followed by DRIVER RXFILTER-START to make the rule effective 489155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 490155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-ADD Num 491155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * where Num = 0 - Unicast, 1 - Broadcast, 2 - Mutil4 or 3 - Multi6 492155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 493155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * and DRIVER RXFILTER-START 494155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * In order to stop the usage of these rules, we do 495155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 496155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-STOP 497155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-REMOVE Num 498155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * where Num is as described for RXFILTER-ADD 499155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 500155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The SETSUSPENDOPT driver command overrides the filtering rules 501155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 502155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startFilteringMulticastV4Packets() { 503155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 504155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-REMOVE 2") 505155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 506155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 507155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 508155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 509155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Stop filtering out Multicast V4 packets. 510155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 511155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 512155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopFilteringMulticastV4Packets() { 513155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 514155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-ADD 2") 515155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 516155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 517155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 518155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 519155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Start filtering out Multicast V6 packets 520155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 521155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 522155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startFilteringMulticastV6Packets() { 523155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 524155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-REMOVE 3") 525155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 526155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 527155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 528155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 529155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Stop filtering out Multicast V6 packets. 530155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 531155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 532155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopFilteringMulticastV6Packets() { 533155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 534155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-ADD 3") 535155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 536155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 537155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 53803cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt /** 53903cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * Set the operational frequency band 54003cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * @param band One of 54103cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_AUTO}, 54203cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_5GHZ}, 54303cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_2GHZ}, 54403cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * @return {@code true} if the operation succeeded, {@code false} otherwise 54503cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt */ 546155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBand(int band) { 54703cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt String bandstr; 54803cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt 54903cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt if (band == WifiManager.WIFI_FREQUENCY_BAND_5GHZ) 55003cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "5G"; 55103cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt else if (band == WifiManager.WIFI_FREQUENCY_BAND_2GHZ) 55203cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "2G"; 55303cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt else 55403cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "AUTO"; 55503cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt return doBooleanCommand("SET SETBAND " + bandstr); 556155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 557155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 5587ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde /** 5597ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * Sets the bluetooth coexistence mode. 5607ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * 5617ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * @param mode One of {@link #BLUETOOTH_COEXISTENCE_MODE_DISABLED}, 5627ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * {@link #BLUETOOTH_COEXISTENCE_MODE_ENABLED}, or 5637ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}. 5647ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * @return Whether the mode was successfully set. 5657ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde */ 566155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBluetoothCoexistenceMode(int mode) { 567155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXMODE " + mode); 568155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 569155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 570155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 571155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Enable or disable Bluetooth coexistence scan mode. When this mode is on, 572155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * some of the low-level scan parameters used by the driver are changed to 573155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * reduce interference with A2DP streaming. 574155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 575155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param isSet whether to enable or disable this mode 576155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the command succeeded, {@code false} otherwise. 577155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 578155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) { 579155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (setCoexScanMode) { 580155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXSCAN-START"); 581155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 582155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXSCAN-STOP"); 583155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 584155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 585155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 5860a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde public void enableSaveConfig() { 5870a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde doBooleanCommand("SET update_config 1"); 5880a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde } 5890a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde 590155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean saveConfig() { 591155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SAVE_CONFIG"); 592155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 593155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 594155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean addToBlacklist(String bssid) { 595155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) return false; 596155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("BLACKLIST " + bssid); 597155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 598155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 599155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean clearBlacklist() { 600155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("BLACKLIST clear"); 601155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 602155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 603155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setSuspendOptimizations(boolean enabled) { 604f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle // if (mSuspendOptEnabled == enabled) return true; 605155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mSuspendOptEnabled = enabled; 606f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 607f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle Log.e("native", "do suspend " + enabled); 608155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 609155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER SETSUSPENDMODE 1"); 610155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 611155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER SETSUSPENDMODE 0"); 612155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 613155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 614155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 615155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setCountryCode(String countryCode) { 6160465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande if (countryCode != null) 6170465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return doBooleanCommand("DRIVER COUNTRY " + countryCode.toUpperCase(Locale.ROOT)); 6180465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande else 6190465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return doBooleanCommand("DRIVER COUNTRY"); 620155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 621155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 622155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void enableBackgroundScan(boolean enable) { 623155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enable) { 624155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET pno 1"); 625155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 626155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET pno 0"); 627155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 628155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 629155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 630f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle public void enableAutoConnect(boolean enable) { 631f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (enable) { 632f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle doBooleanCommand("STA_AUTOCONNECT 1"); 633f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } else { 634f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle doBooleanCommand("STA_AUTOCONNECT 0"); 635f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 636f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 637f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 638155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setScanInterval(int scanInterval) { 639155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SCAN_INTERVAL " + scanInterval); 640155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 641155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 642155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void startTdls(String macAddr, boolean enable) { 643155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enable) { 644155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("TDLS_DISCOVER " + macAddr); 645155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("TDLS_SETUP " + macAddr); 646155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 647155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("TDLS_TEARDOWN " + macAddr); 648155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 649155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 650155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 651155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** Example output: 652155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RSSI=-65 653155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * LINKSPEED=48 654155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * NOISE=9999 655155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * FREQUENCY=0 656155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 657155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String signalPoll() { 658155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandWithoutLogging("SIGNAL_POLL"); 659155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 660155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 661155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** Example outout: 662155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TXGOOD=396 663155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TXBAD=1 664155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 665155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String pktcntPoll() { 666155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("PKTCNT_POLL"); 667155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 668155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 669155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void bssFlush() { 670155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("BSS_FLUSH 0"); 671155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 672155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 673155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPbc(String bssid) { 674155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 675155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PBC"); 676155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 677155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PBC " + bssid); 678155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 679155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 680155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 681155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPbc(String iface, String bssid) { 682155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 683155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 684155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC"); 685155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 686155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid); 687155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 688155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 689155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 690155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 691155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPinKeypad(String pin) { 692155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(pin)) return false; 693155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PIN any " + pin); 694155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 695155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 696155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPinKeypad(String iface, String pin) { 697155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(pin)) return false; 698155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 699155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin); 700155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 701155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 702155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 703155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 704155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String startWpsPinDisplay(String bssid) { 705155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 706155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("WPS_PIN any"); 707155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 708155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("WPS_PIN " + bssid); 709155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 710155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 711155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 712155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String startWpsPinDisplay(String iface, String bssid) { 713155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 714155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 715155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any"); 716155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 717155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid); 718155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 719155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 720155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 721155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 72233b575ca6bee66183929f9474b5a161432918604Vinit Deshpande public boolean setExternalSim(boolean external) { 72333b575ca6bee66183929f9474b5a161432918604Vinit Deshpande synchronized (mLock) { 72433b575ca6bee66183929f9474b5a161432918604Vinit Deshpande String value = external ? "1" : "0"; 7254d701eca56d62586b0ab8af6ad864bac74a1dcd0Vinit Deshpande Log.d(TAG, "Setting external_sim to " + value); 7264d701eca56d62586b0ab8af6ad864bac74a1dcd0Vinit Deshpande return doBooleanCommand("SET external_sim " + value); 72733b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 72833b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 72933b575ca6bee66183929f9474b5a161432918604Vinit Deshpande 73033b575ca6bee66183929f9474b5a161432918604Vinit Deshpande public boolean simAuthResponse(int id, String response) { 73133b575ca6bee66183929f9474b5a161432918604Vinit Deshpande synchronized (mLock) { 732dbd6933aae99302b75683f8463cd17df554dc599Vinit Deshpande return doBooleanCommand("CTRL-RSP-SIM-" + id + ":GSM-AUTH" + response); 73333b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 73433b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 73533b575ca6bee66183929f9474b5a161432918604Vinit Deshpande 736155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Configures an access point connection */ 737155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsRegistrar(String bssid, String pin) { 738155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid) || TextUtils.isEmpty(pin)) return false; 739155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_REG " + bssid + " " + pin); 740155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 741155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 742155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean cancelWps() { 743155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_CANCEL"); 744155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 745155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 746155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setPersistentReconnect(boolean enabled) { 747155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int value = (enabled == true) ? 1 : 0; 748155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET persistent_reconnect " + value); 749155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 750155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 751155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setDeviceName(String name) { 752155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET device_name " + name); 753155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 754155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 755155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setDeviceType(String type) { 756155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET device_type " + type); 757155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 758155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 759155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setConfigMethods(String cfg) { 760155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET config_methods " + cfg); 761155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 762155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 763155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setManufacturer(String value) { 764155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET manufacturer " + value); 765155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 766155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 767155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setModelName(String value) { 768155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET model_name " + value); 769155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 770155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 771155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setModelNumber(String value) { 772155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET model_number " + value); 773155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 774155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 775155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setSerialNumber(String value) { 776155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET serial_number " + value); 777155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 778155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 779155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pSsidPostfix(String postfix) { 780155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET p2p_ssid_postfix " + postfix); 781155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 782155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 783155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pGroupIdle(String iface, int time) { 784155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 785155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time); 786155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 787155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 788155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 789155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setPowerSave(boolean enabled) { 790155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 791155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET ps 1"); 792155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 793155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET ps 0"); 794155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 795155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 796155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 797155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pPowerSave(String iface, boolean enabled) { 798155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 799155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 800155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1"); 801155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 802155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0"); 803155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 804155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 805155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 806155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 807155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setWfdEnable(boolean enable) { 808155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET wifi_display " + (enable ? "1" : "0")); 809155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 810155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 811155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setWfdDeviceInfo(String hex) { 812155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WFD_SUBELEM_SET 0 " + hex); 813155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 814155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 815155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 816155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * "sta" prioritizes STA connection over P2P and "p2p" prioritizes 817155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P connection over STA 818155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 819155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setConcurrencyPriority(String s) { 820155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SET conc_pref " + s); 821155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 822155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 823155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFind() { 824155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FIND"); 825155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 826155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 827155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFind(int timeout) { 828155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (timeout <= 0) { 829155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pFind(); 830155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 831155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FIND " + timeout); 832155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 833155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 834155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pStopFind() { 835155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_STOP_FIND"); 836155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 837155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 838155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pListen() { 839155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_LISTEN"); 840155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 841155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 842155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pListen(int timeout) { 843155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (timeout <= 0) { 844155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pListen(); 845155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 846155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_LISTEN " + timeout); 847155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 848155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 849155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pExtListen(boolean enable, int period, int interval) { 850155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enable && interval < period) { 851155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 852155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 853155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_EXT_LISTEN" 854155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + (enable ? (" " + period + " " + interval) : "")); 855155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 856155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 857155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pSetChannel(int lc, int oc) { 858155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "p2pSetChannel: lc="+lc+", oc="+oc); 859155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 860155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (lc >=1 && lc <= 11) { 861155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doBooleanCommand("P2P_SET listen_channel " + lc)) { 862155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 863155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 864155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (lc != 0) { 865155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 866155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 867155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 868155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (oc >= 1 && oc <= 165 ) { 869155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int freq = (oc <= 14 ? 2407 : 5000) + oc * 5; 870155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SET disallow_freq 1000-" 871155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + (freq - 5) + "," + (freq + 5) + "-6000"); 872155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (oc == 0) { 873155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* oc==0 disables "P2P_SET disallow_freq" (enables all freqs) */ 874155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SET disallow_freq \"\""); 875155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 876155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 877155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 878155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 879155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 880155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFlush() { 881155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FLUSH"); 882155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 883155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 884155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* p2p_connect <peer device address> <pbc|pin|PIN#> [label|display|keypad] 885155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande [persistent] [join|auth] [go_intent=<0..15>] [freq=<in MHz>] */ 886155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) { 887155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config == null) return null; 888155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande List<String> args = new ArrayList<String>(); 889155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WpsInfo wps = config.wps; 890155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(config.deviceAddress); 891155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 892155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch (wps.setup) { 893155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.PBC: 894155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("pbc"); 895155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 896155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.DISPLAY: 897155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(wps.pin)) { 898155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("pin"); 899155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 900155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 901155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 902155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("display"); 903155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 904155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.KEYPAD: 905155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 906155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("keypad"); 907155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 908155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.LABEL: 909155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 910155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("label"); 911155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande default: 912155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 913155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 914155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 915155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config.netId == WifiP2pGroup.PERSISTENT_NET_ID) { 916155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("persistent"); 917155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 918155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 919155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (joinExistingGroup) { 920155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("join"); 921155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 922155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //TODO: This can be adapted based on device plugged in state and 923155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //device battery state 924155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int groupOwnerIntent = config.groupOwnerIntent; 925155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (groupOwnerIntent < 0 || groupOwnerIntent > 15) { 926155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT; 927155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 928155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("go_intent=" + groupOwnerIntent); 929155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 930155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 931155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_CONNECT "; 932155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String s : args) command += s + " "; 933155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 934155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(command); 935155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 936155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 937155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pCancelConnect() { 938155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_CANCEL"); 939155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 940155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 941155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pProvisionDiscovery(WifiP2pConfig config) { 942155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config == null) return false; 943155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 944155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch (config.wps.setup) { 945155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.PBC: 946155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " pbc"); 947155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.DISPLAY: 948155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //We are doing display, so provision discovery is keypad 949155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " keypad"); 950155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.KEYPAD: 951155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //We are doing keypad, so provision discovery is display 952155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " display"); 953155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande default: 954155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 955155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 956155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 957155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 958155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 959155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupAdd(boolean persistent) { 960155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (persistent) { 961155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD persistent"); 962155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 963155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD"); 964155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 965155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 966155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupAdd(int netId) { 967155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD persistent=" + netId); 968155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 969155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 970155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupRemove(String iface) { 971155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(iface)) return false; 972155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 973155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface); 974155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 975155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 976155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 977155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pReject(String deviceAddress) { 978155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_REJECT " + deviceAddress); 979155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 980155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 981155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Invite a peer to a group */ 982155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) { 983155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress)) return false; 984155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 985155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (group == null) { 986155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE peer=" + deviceAddress); 987155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 988155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE group=" + group.getInterface() 989155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + " peer=" + deviceAddress + " go_dev_addr=" + group.getOwner().deviceAddress); 990155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 991155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 992155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 993155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Reinvoke a persistent connection */ 994155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pReinvoke(int netId, String deviceAddress) { 995155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress) || netId < 0) return false; 996155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 997155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE persistent=" + netId + " peer=" + deviceAddress); 998155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 999155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1000155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pGetSsid(String deviceAddress) { 1001155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pGetParam(deviceAddress, "oper_ssid"); 1002155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1003155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1004155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pGetDeviceAddress() { 100527f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande 100636286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande Log.d(TAG, "p2pGetDeviceAddress"); 100736286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 100827f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande String status = null; 100927f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande 101036286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande /* Explicitly calling the API without IFNAME= prefix to take care of the devices that 101136286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande don't have p2p0 interface. Supplicant seems to be returning the correct address anyway. */ 101236286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 101327f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande synchronized (mLock) { 101427f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande status = doStringCommandNative("STATUS"); 101527f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande } 101627f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande 101727f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande String result = ""; 101836286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (status != null) { 101936286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande String[] tokens = status.split("\n"); 102036286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande for (String token : tokens) { 102136286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (token.startsWith("p2p_device_address=")) { 102236286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande String[] nameValue = token.split("="); 102336286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (nameValue.length != 2) 102436286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande break; 102536286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande result = nameValue[1]; 102636286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande } 1027155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1028155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 102936286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 103036286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande Log.d(TAG, "p2pGetDeviceAddress returning " + result); 103136286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande return result; 1032155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1033155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1034155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int getGroupCapability(String deviceAddress) { 1035155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int gc = 0; 1036155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress)) return gc; 1037155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String peerInfo = p2pPeer(deviceAddress); 1038155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(peerInfo)) return gc; 1039155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1040155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens = peerInfo.split("\n"); 1041155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String token : tokens) { 1042155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (token.startsWith("group_capab=")) { 1043155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] nameValue = token.split("="); 1044155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (nameValue.length != 2) break; 1045155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1046155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return Integer.decode(nameValue[1]); 1047155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch(NumberFormatException e) { 1048155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return gc; 1049155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1050155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1051155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1052155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return gc; 1053155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1054155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1055155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pPeer(String deviceAddress) { 1056155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("P2P_PEER " + deviceAddress); 1057155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1058155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1059155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String p2pGetParam(String deviceAddress, String key) { 1060155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (deviceAddress == null) return null; 1061155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1062155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String peerInfo = p2pPeer(deviceAddress); 1063155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (peerInfo == null) return null; 1064155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens= peerInfo.split("\n"); 1065155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1066155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande key += "="; 1067155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String token : tokens) { 1068155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (token.startsWith(key)) { 1069155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] nameValue = token.split("="); 1070155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (nameValue.length != 2) break; 1071155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return nameValue[1]; 1072155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1073155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1074155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return null; 1075155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1076155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1077155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) { 1078155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 1079155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour <query hexdump> <RDATA hexdump> 1080155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp <version hex> <service> 1081155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1082155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * e.g) 1083155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * [Bonjour] 1084155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * # IP Printing over TCP (PTR) (RDATA=MyPrinter._ipp._tcp.local.) 1085155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027 1086155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * # IP Printing over TCP (TXT) (RDATA=txtvers=1,pdl=application/postscript) 1087155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 1088155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074 1089155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1090155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * [UPnP] 1091155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012 1092155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice 1093155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp 1094155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * -org:device:InternetGatewayDevice:1 1095155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9322-123456789012::urn:schemas-upnp 1096155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * -org:service:ContentDirectory:2 1097155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1098155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String s : servInfo.getSupplicantQueryList()) { 1099155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_SERVICE_ADD"; 1100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + s); 1101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doBooleanCommand(command)) { 1102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 1106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) { 1109155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 1110155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_DEL bonjour <query hexdump> 1111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_DEL upnp <version hex> <service> 1112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String s : servInfo.getSupplicantQueryList()) { 1114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_SERVICE_DEL "; 1115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1116155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] data = s.split(" "); 1117155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (data.length < 2) { 1118155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1119155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1120155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if ("upnp".equals(data[0])) { 1121155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += s; 1122155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if ("bonjour".equals(data[0])) { 1123155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += data[0]; 1124155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + data[1]); 1125155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1126155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1127155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1128155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doBooleanCommand(command)) { 1129155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1130155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1131155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 1133155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1134155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceFlush() { 1136155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SERVICE_FLUSH"); 1137155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1138155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1139155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pServDiscReq(String addr, String query) { 1140155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_SERV_DISC_REQ"; 1141155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + addr); 1142155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + query); 1143155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(command); 1145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServDiscCancelReq(String id) { 1148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id); 1149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Set the current mode of miracast operation. 1152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 0 = disabled 1153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1 = operating as source 1154155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 2 = operating as sink 1155155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1156155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setMiracastMode(int mode) { 1157155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Note: optional feature on the driver. It is ok for this to fail. 1158155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("DRIVER MIRACAST " + mode); 1159155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 11603f7ef65ab71619040032aee96b5599849881d6fdAndres Morales 1161446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng public boolean fetchAnqp(String bssid, String subtypes) { 1162446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng return doBooleanCommand("ANQP_GET " + bssid + " " + subtypes); 1163446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng } 1164446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng 11657f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde /* WIFI HAL support */ 11667f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1167b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static final String TAG = "WifiNative-HAL"; 1168aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static long sWifiHalHandle = 0; /* used by JNI to save wifi_handle */ 1169aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static long[] sWifiIfaceHandles = null; /* used by JNI to save interface handles */ 1170aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static int sWlan0Index = -1; 1171aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static int sP2p0Index = -1; 1172aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 1173aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static boolean sHalIsStarted = false; 1174cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande private static boolean sHalFailed = false; 11757f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1176b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean startHalNative(); 1177b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native void stopHalNative(); 1178b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native void waitForHalEventNative(); 11797f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1180b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static class MonitorThread extends Thread { 11817ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde public void run() { 1182b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.i(TAG, "Waiting for HAL events mWifiHalHandle=" + Long.toString(sWifiHalHandle)); 11837ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde waitForHalEventNative(); 11847ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 11857ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 11867ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 1187b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static boolean startHal() { 1188b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.i(TAG, "startHal"); 1189aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 1190cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande if (sHalFailed) 1191cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande return false; 1192cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande if (startHalNative() && (getInterfaces() != 0) && (sWlan0Index != -1)) { 1193aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle new MonitorThread().start(); 1194aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle sHalIsStarted = true; 1195aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return true; 1196aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } else { 1197b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.i(TAG, "Could not start hal"); 1198aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle sHalIsStarted = false; 1199cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande sHalFailed = true; 1200aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return false; 1201aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 12027ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 12037ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 12047ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 1205b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void stopHal() { 12067ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde stopHalNative(); 12077ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 12087f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1209b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native int getInterfacesNative(); 12107f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1211b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static int getInterfaces() { 1212aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 121302a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande if (sWifiIfaceHandles == null) { 121402a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande int num = getInterfacesNative(); 121502a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande int wifi_num = 0; 121602a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande for (int i = 0; i < num; i++) { 121702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande String name = getInterfaceNameNative(i); 121802a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande Log.i(TAG, "interface[" + i + "] = " + name); 121902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande if (name.equals("wlan0")) { 122002a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande sWlan0Index = i; 122102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande wifi_num++; 122202a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } else if (name.equals("p2p0")) { 122302a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande sP2p0Index = i; 122402a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande wifi_num++; 122502a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 1226aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 122702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande return wifi_num; 122802a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } else { 122902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande return sWifiIfaceHandles.length; 1230e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1231e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 12327f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 12337f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1234b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native String getInterfaceNameNative(int index); 1235a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande synchronized public static String getInterfaceName(int index) { 1236a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande return getInterfaceNameNative(index); 12377f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 12387f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1239e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ScanCapabilities { 1240e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_cache_size; // in number of scan results?? 1241e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_buckets; 1242e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_ap_cache_per_scan; 1243e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_rssi_sample_size; 1244e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_reporting_threshold; // in number of scan results?? 12457d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande public int max_hotlist_bssids; 1246e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_significant_wifi_change_aps; 1247e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1248e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1249b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static boolean getScanCapabilities(ScanCapabilities capabilities) { 1250aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return getScanCapabilitiesNative(sWlan0Index, capabilities); 1251e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1252e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1253b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean getScanCapabilitiesNative( 1254b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande int iface, ScanCapabilities capabilities); 1255e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1256b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean startScanNative(int iface, int id, ScanSettings settings); 1257b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean stopScanNative(int iface, int id); 125883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande private static native WifiScanner.ScanData[] getScanResultsNative(int iface, boolean flush); 1259b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native WifiLinkLayerStats getWifiLinkLayerStatsNative(int iface); 12607f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1261e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ChannelSettings { 1262e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int frequency; 1263e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int dwell_time_ms; 1264e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde boolean passive; 12657f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 12667f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1267e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class BucketSettings { 1268e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int bucket; 1269e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int band; 1270e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int period_ms; 1271e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int report_events; 1272e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int num_channels; 1273daac2ad767f6047409987bb22812ab5f295e54dfVinit Deshpande ChannelSettings channels[]; 1274e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 12757f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1276e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ScanSettings { 1277e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int base_period_ms; 1278e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int max_ap_per_scan; 127983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande int report_threshold_percent; 128083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande int report_threshold_num_scans; 1281e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int num_buckets; 1282daac2ad767f6047409987bb22812ab5f295e54dfVinit Deshpande BucketSettings buckets[]; 1283e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 12847f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1285b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface ScanEventHandler { 1286e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde void onScanResultsAvailable(); 1287476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande void onFullScanResult(ScanResult fullScanResult); 128883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande void onScanStatus(); 128983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande void onScanPaused(WifiScanner.ScanData[] data); 1290b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande void onScanRestarted(); 1291e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1292e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1293b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized static void onScanResultsAvailable(int id) { 1294b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (sScanEventHandler != null) { 1295b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande sScanEventHandler.onScanResultsAvailable(); 1296b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1297b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1298b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 1299b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande /* scan status, keep these values in sync with gscan.h */ 1300b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande private static int WIFI_SCAN_BUFFER_FULL = 0; 1301b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande private static int WIFI_SCAN_COMPLETE = 1; 1302b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 1303b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande synchronized static void onScanStatus(int status) { 1304b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande Log.i(TAG, "Got a scan status changed event, status = " + status); 1305b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 1306b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (status == WIFI_SCAN_BUFFER_FULL) { 1307b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande /* we have a separate event to take care of this */ 1308b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } else if (status == WIFI_SCAN_COMPLETE) { 1309b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (sScanEventHandler != null) { 131083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanEventHandler.onScanStatus(); 1311b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1312b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1313e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1314e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1315b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized static void onFullScanResult(int id, ScanResult result, byte bytes[]) { 1316b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (DBG) Log.i(TAG, "Got a full scan results event, ssid = " + result.SSID + ", " + 1317f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde "num = " + bytes.length); 1318f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 1319e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande if (sScanEventHandler == null) { 1320e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande return; 1321e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande } 1322e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande 1323f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde int num = 0; 1324f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde for (int i = 0; i < bytes.length; ) { 1325e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande int type = bytes[i] & 0xFF; 1326e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande int len = bytes[i + 1] & 0xFF; 1327e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande 1328e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande if (i + len + 2 > bytes.length) { 1329e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande Log.w(TAG, "bad length " + len + " of IE " + type + " from " + result.BSSID); 1330e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande Log.w(TAG, "ignoring the rest of the IEs"); 1331e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande break; 1332f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1333e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande num++; 1334f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde i += len + 2; 1335b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (DBG) Log.i(TAG, "bytes[" + i + "] = [" + type + ", " + len + "]" + ", " + 1336b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande "next = " + i); 1337f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1338f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 1339243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe int secondChanelOffset = 0; 1340243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe byte channelMode = 0; 1341243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe byte centerFreqIndex1 = 0; 1342243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe byte centerFreqIndex2 = 0; 1343243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.is80211McRTTResponder = false; 1344243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1345476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande ScanResult.InformationElement elements[] = new ScanResult.InformationElement[num]; 1346f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde for (int i = 0, index = 0; i < num; i++) { 1347e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande int type = bytes[index] & 0xFF; 1348e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande int len = bytes[index + 1] & 0xFF; 1349b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (DBG) Log.i(TAG, "index = " + index + ", type = " + type + ", len = " + len); 1350476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande ScanResult.InformationElement elem = new ScanResult.InformationElement(); 1351f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde elem.id = type; 1352f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde elem.bytes = new byte[len]; 1353f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde for (int j = 0; j < len; j++) { 1354f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde elem.bytes[j] = bytes[index + j + 2]; 1355f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1356f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde elements[i] = elem; 1357243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe int inforStart = index + 2; 1358f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde index += (len + 2); 1359243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1360243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if(type == EID_HT_OPERATION) { 1361243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe secondChanelOffset = bytes[inforStart + 1] & 0x3; 1362243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else if(type == EID_VHT_OPERATION) { 1363243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe channelMode = bytes[inforStart]; 1364243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe centerFreqIndex1 = bytes[inforStart + 1]; 1365243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe centerFreqIndex2 = bytes[inforStart + 2]; 1366243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else if (type == EID_EXTENDED_CAPS) { 1367243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe int tempIndex = RTT_RESP_ENABLE_BIT / 8; 1368243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe byte offset = RTT_RESP_ENABLE_BIT % 8; 1369243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1370243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if(len < tempIndex + 1) { 1371243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.is80211McRTTResponder = false; 1372243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1373243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if ((bytes[inforStart + tempIndex] & ((byte)0x1 << offset)) != 0) { 1374243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.is80211McRTTResponder = true; 1375243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1376243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.is80211McRTTResponder = false; 1377243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1378243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1379243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1380243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1381243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe //handle RTT related information 1382243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if (channelMode != 0) { 1383243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe // 80 or 160 MHz 1384243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.channelWidth = channelMode + 1; 1385243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1386243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe //convert channel index to frequency in MHz, channel 36 is 5180MHz 1387243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = (centerFreqIndex1 - 36) * 5 + 5180; 1388243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe 1389243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if(channelMode > 1) { //160MHz 1390243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = (centerFreqIndex2 - 36) * 5 + 5180; 1391243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1392243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = 0; 1393243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1394243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1395243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe //20 or 40 MHz 1396243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if (secondChanelOffset != 0) {//40MHz 1397243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.channelWidth = 1; 1398243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if (secondChanelOffset == 1) { 1399243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = result.frequency + 20; 1400243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else if (secondChanelOffset == 3) { 1401243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = result.frequency - 20; 1402243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1403243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = 0; 1404243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe Log.e(TAG, ": Error on secondChanelOffset"); 1405243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1406243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 1407243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq0 = 0; 1408243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = 0; 1409243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1410243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = 0; 1411243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1412243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if(DBG) { 1413243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe Log.d(TAG, ":SSID: " + result.SSID + "ChannelWidth is: " + result.channelWidth + 1414243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe " PrimaryFreq: " + result.frequency +" mCenterfreq0: " + result.centerFreq0 + 1415243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe " mCenterfreq1: " + result.centerFreq1 + (result.is80211McRTTResponder ? 1416243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe "Support RTT reponder: " : "Do not support RTT responder")); 1417f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1418f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 1419476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande result.informationElements = elements; 1420e7b9e74a9a699e74881e5c98c684567763dfaa35Vinit Deshpande sScanEventHandler.onFullScanResult(result); 14217f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 14227f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1423b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sScanCmdId = 0; 1424b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static ScanEventHandler sScanEventHandler; 1425b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static ScanSettings sScanSettings; 14267f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1427b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static boolean startScan( 1428b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande ScanSettings settings, ScanEventHandler eventHandler) { 14297f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde synchronized (mLock) { 1430b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1431b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sScanCmdId != 0) { 1432741953368eafa247f2820496aaa521bc0e86e9e1Navtej Singh Mann stopScan(); 1433b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } else if (sScanSettings != null || sScanEventHandler != null) { 1434b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande /* current scan is paused; no need to stop it */ 1435b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 14367f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1437b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanCmdId = getNewCmdIdLocked(); 1438e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1439b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanSettings = settings; 1440b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanEventHandler = eventHandler; 1441b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1442b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (startScanNative(sWlan0Index, sScanCmdId, settings) == false) { 1443b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanEventHandler = null; 1444b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanSettings = null; 144583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanCmdId = 0; 1446e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1447e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1448e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1449e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return true; 1450e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 14517f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 14527f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1453b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void stopScan() { 1454b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized (mLock) { 1455b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande stopScanNative(sWlan0Index, sScanCmdId); 1456b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanSettings = null; 1457b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanEventHandler = null; 1458b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanCmdId = 0; 1459b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1460b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1461b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1462b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void pauseScan() { 14637f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde synchronized (mLock) { 1464b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sScanCmdId != 0 && sScanSettings != null && sScanEventHandler != null) { 1465b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.d(TAG, "Pausing scan"); 146683a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande WifiScanner.ScanData scanData[] = getScanResultsNative(sWlan0Index, true); 1467b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande stopScanNative(sWlan0Index, sScanCmdId); 1468b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sScanCmdId = 0; 146983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanEventHandler.onScanPaused(scanData); 1470b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1471b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1472b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1473b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1474b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void restartScan() { 1475b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized (mLock) { 1476b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sScanCmdId == 0 && sScanSettings != null && sScanEventHandler != null) { 1477b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.d(TAG, "Restarting scan"); 147883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ScanEventHandler handler = sScanEventHandler; 147983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ScanSettings settings = sScanSettings; 148083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande if (startScan(sScanSettings, sScanEventHandler)) { 148183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanEventHandler.onScanRestarted(); 148283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande } else { 148383a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande /* we are still paused; don't change state */ 148483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanEventHandler = handler; 148583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sScanSettings = settings; 148683a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande } 1487b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1488e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1489e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1490e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 149183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande synchronized public static WifiScanner.ScanData[] getScanResults(boolean flush) { 1492aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 149383a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande return getScanResultsNative(sWlan0Index, flush); 1494aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1495e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1496e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1497b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface HotlistEventHandler { 1498d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande void onHotlistApFound (ScanResult[] result); 1499d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande void onHotlistApLost (ScanResult[] result); 1500e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1501e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1502b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sHotlistCmdId = 0; 1503b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static HotlistEventHandler sHotlistEventHandler; 1504e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1505b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private native static boolean setHotlistNative(int iface, int id, 1506e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde WifiScanner.HotlistSettings settings); 1507b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private native static boolean resetHotlistNative(int iface, int id); 1508e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1509b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static boolean setHotlist(WifiScanner.HotlistSettings settings, 1510aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle HotlistEventHandler eventHandler) { 1511e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 1512b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sHotlistCmdId != 0) { 1513e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1514e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } else { 1515b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistCmdId = getNewCmdIdLocked(); 1516e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1517e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1518b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistEventHandler = eventHandler; 1519b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (setHotlistNative(sWlan0Index, sScanCmdId, settings) == false) { 1520b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistEventHandler = null; 1521e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1522e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1523e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1524e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return true; 1525e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1526e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1527e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1528b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void resetHotlist() { 1529e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 1530b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sHotlistCmdId != 0) { 1531b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande resetHotlistNative(sWlan0Index, sHotlistCmdId); 1532b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistCmdId = 0; 1533b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sHotlistEventHandler = null; 1534e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 15357f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 15367f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 1537e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1538b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static void onHotlistApFound(int id, ScanResult[] results) { 1539aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 15401814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande if (sHotlistCmdId != 0) { 15411814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande sHotlistEventHandler.onHotlistApFound(results); 15421814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande } else { 15431814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande /* this can happen because of race conditions */ 1544d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande Log.d(TAG, "Ignoring hotlist AP found event"); 1545d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 1546d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 1547d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 1548d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 1549d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande synchronized public static void onHotlistApLost(int id, ScanResult[] results) { 1550d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande synchronized (mLock) { 1551d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande if (sHotlistCmdId != 0) { 1552d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande sHotlistEventHandler.onHotlistApLost(results); 1553d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } else { 1554d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande /* this can happen because of race conditions */ 1555d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande Log.d(TAG, "Ignoring hotlist AP lost event"); 15561814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande } 1557aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1558e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1559e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1560b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface SignificantWifiChangeEventHandler { 1561e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde void onChangesFound(ScanResult[] result); 1562e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1563e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1564b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static SignificantWifiChangeEventHandler sSignificantWifiChangeHandler; 1565b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sSignificantWifiChangeCmdId; 1566e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1567b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean trackSignificantWifiChangeNative( 1568e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int iface, int id, WifiScanner.WifiChangeSettings settings); 1569b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean untrackSignificantWifiChangeNative(int iface, int id); 1570e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1571b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized public static boolean trackSignificantWifiChange( 1572b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande WifiScanner.WifiChangeSettings settings, SignificantWifiChangeEventHandler handler) { 1573e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 1574b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sSignificantWifiChangeCmdId != 0) { 1575e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1576e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } else { 1577b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sSignificantWifiChangeCmdId = getNewCmdIdLocked(); 1578e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1579e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1580b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sSignificantWifiChangeHandler = handler; 1581b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (trackSignificantWifiChangeNative(sWlan0Index, sScanCmdId, settings) == false) { 15821814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande sSignificantWifiChangeHandler = null; 1583e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1584e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1585e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1586e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return true; 1587e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1588e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1589e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1590b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized static void untrackSignificantWifiChange() { 1591e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 1592b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande if (sSignificantWifiChangeCmdId != 0) { 1593b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande untrackSignificantWifiChangeNative(sWlan0Index, sSignificantWifiChangeCmdId); 1594b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sSignificantWifiChangeCmdId = 0; 1595b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande sSignificantWifiChangeHandler = null; 1596e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1597e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1598e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1599e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1600b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized static void onSignificantWifiChange(int id, ScanResult[] results) { 1601aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 16021814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande if (sSignificantWifiChangeCmdId != 0) { 16031814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande sSignificantWifiChangeHandler.onChangesFound(results); 16041814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande } else { 16051814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande /* this can happen because of race conditions */ 16061814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande Log.d(TAG, "Ignoring significant wifi change"); 16071814928371a30b11af31e2bbe5210c4337ed16f3Vinit Deshpande } 1608aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1609e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1610e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1611200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle synchronized public static WifiLinkLayerStats getWifiLinkLayerStats(String iface) { 1612200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle // TODO: use correct iface name to Index translation 1613200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle if (iface == null) return null; 1614aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 1615aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle if (!sHalIsStarted) 1616aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle startHal(); 1617aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle if (sHalIsStarted) 1618aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return getWifiLinkLayerStatsNative(sWlan0Index); 1619aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1620aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return null; 1621aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 16225c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16235c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales /* 16245c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales * NFC-related calls 16255c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales */ 16265c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public String getNfcWpsConfigurationToken(int netId) { 16275c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doStringCommand("WPS_NFC_CONFIG_TOKEN WPS " + netId); 16285c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16295c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16305c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public String getNfcHandoverRequest() { 16315c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doStringCommand("NFC_GET_HANDOVER_REQ NDEF P2P-CR"); 16325c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16335c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16345c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public String getNfcHandoverSelect() { 16355c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doStringCommand("NFC_GET_HANDOVER_SEL NDEF P2P-CR"); 16365c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16375c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16385c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public boolean initiatorReportNfcHandover(String selectMessage) { 16395c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doBooleanCommand("NFC_REPORT_HANDOVER INIT P2P 00 " + selectMessage); 16405c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16415c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 16425c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales public boolean responderReportNfcHandover(String requestMessage) { 16435c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales return doBooleanCommand("NFC_REPORT_HANDOVER RESP P2P " + requestMessage + " 00"); 16445c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 16455c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 1646c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande public static native int getSupportedFeatureSetNative(int iface); 1647a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande synchronized public static int getSupportedFeatureSet() { 1648c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande return getSupportedFeatureSetNative(sWlan0Index); 1649a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande } 1650143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1651143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande /* Rtt related commands/events */ 1652143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande public static interface RttEventHandler { 1653143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande void onRttResults(RttManager.RttResult[] result); 1654143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1655143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1656143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static RttEventHandler sRttEventHandler; 1657143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static int sRttCmdId; 1658143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1659143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized private static void onRttResults(int id, RttManager.RttResult[] results) { 1660143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (id == sRttCmdId) { 166102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande Log.d(TAG, "Received " + results.length + " rtt results"); 1662143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttEventHandler.onRttResults(results); 1663143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttCmdId = 0; 1664143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 1665143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande Log.d(TAG, "Received event for unknown cmd = " + id + ", current id = " + sRttCmdId); 1666143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1667143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1668143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1669143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static native boolean requestRangeNative( 1670143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande int iface, int id, RttManager.RttParams[] params); 1671143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static native boolean cancelRangeRequestNative( 1672143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande int iface, int id, RttManager.RttParams[] params); 1673143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1674143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized public static boolean requestRtt( 1675143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande RttManager.RttParams[] params, RttEventHandler handler) { 1676143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized (mLock) { 1677143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (sRttCmdId != 0) { 1678143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 1679143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 1680143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttCmdId = getNewCmdIdLocked(); 1681143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1682143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttEventHandler = handler; 1683143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return requestRangeNative(sWlan0Index, sRttCmdId, params); 1684143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1685143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1686143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1687143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized public static boolean cancelRtt(RttManager.RttParams[] params) { 1688143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized(mLock) { 1689143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (sRttCmdId == 0) { 1690143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 1691143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1692143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1693143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (cancelRangeRequestNative(sWlan0Index, sRttCmdId, params)) { 1694143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttEventHandler = null; 1695143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return true; 1696143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 1697143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 1698143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1699143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1700143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1701042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1702042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande private static native boolean setScanningMacOuiNative(int iface, byte[] oui); 1703042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1704042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande synchronized public static boolean setScanningMacOui(byte[] oui) { 1705042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande synchronized (mLock) { 1706042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande if (startHal()) { 1707042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande return setScanningMacOuiNative(sWlan0Index, oui); 1708042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } else { 1709042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande return false; 1710042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 1711042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 1712042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 1713efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 1714efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande private static native int[] getChannelsForBandNative( 1715efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande int iface, int band); 1716efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 1717efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande synchronized public static int [] getChannelsForBand(int band) { 1718efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande synchronized (mLock) { 1719efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande if (startHal()) { 1720efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande return getChannelsForBandNative(sWlan0Index, band); 1721efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } else { 1722efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande return null; 1723efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 1724efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 1725efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 17260465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande 17270465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande 17280465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande private static native boolean setDfsFlagNative(int iface, boolean dfsOn); 17290465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande synchronized public static boolean setDfsFlag(boolean dfsOn) { 17300465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande synchronized (mLock) { 17310465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande if (startHal()) { 17320465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return setDfsFlagNative(sWlan0Index, dfsOn); 17330465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } else { 17340465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return false; 17350465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 17360465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 17370465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 1738b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe 1739b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe private static native boolean toggleInterfaceNative(int on); 1740b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe synchronized public static boolean toggleInterface(int on) { 1741b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe synchronized (mLock) { 1742b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe if (startHal()) { 1743b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe return toggleInterfaceNative(0); 1744b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } else { 1745b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe 1746b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe return false; 1747b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 1748b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 1749b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 175012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 175112cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe private static native RttManager.RttCapabilities getRttCapabilitiesNative(int iface); 175212cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe synchronized public static RttManager.RttCapabilities getRttCapabilities() { 175312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe synchronized (mLock) { 175412cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe if (startHal()) { 175512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe return getRttCapabilitiesNative(sWlan0Index); 175612cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } else { 175712cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe return null; 175812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 175912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 176012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 1761a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle //--------------------------------------------------------------------------------- 1762a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1763a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle /* Wifi Logger commands/events */ 17647d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande 17657d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande private static native boolean startLogging(int iface); 17667d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande 1767a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle public static interface WifiLoggerEventHandler { 1768a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle void onDataAvailable(char data[], int len); 1769a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 1770a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1771a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle private static WifiLoggerEventHandler sWifiLoggerEventHandler = null; 1772a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1773a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle synchronized private static void onDataAvailable(char data[], int len) { 1774a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle if (sWifiLoggerEventHandler != null) { 1775a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle sWifiLoggerEventHandler.onDataAvailable(data, len); 1776a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 1777a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 1778155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 1779