WifiNative.java revision 9ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2
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 19143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpandeimport android.net.wifi.RttManager; 20e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndeimport android.net.wifi.ScanResult; 21dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalleimport android.net.wifi.WifiConfiguration; 2218786eca942042388748b0d98979f21c9dff4a89Mitchell Willsimport android.net.wifi.WifiEnterpriseConfig; 23aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalleimport android.net.wifi.WifiLinkLayerStats; 2403cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidtimport android.net.wifi.WifiManager; 25e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndeimport android.net.wifi.WifiScanner; 26dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalleimport android.net.wifi.WifiSsid; 27155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.WpsInfo; 28155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.WifiP2pConfig; 29155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.WifiP2pGroup; 3003cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidtimport android.net.wifi.p2p.nsd.WifiP2pServiceInfo; 31f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalleimport android.os.SystemClock; 3218786eca942042388748b0d98979f21c9dff4a89Mitchell Willsimport android.os.SystemProperties; 33155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.text.TextUtils; 34155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.LocalLog; 35155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.Log; 36e26ad459b63271548abbdeba4f8d77fcca9f88bdxinheimport android.content.Context; 37e26ad459b63271548abbdeba4f8d77fcca9f88bdxinheimport android.content.Intent; 3818786eca942042388748b0d98979f21c9dff4a89Mitchell Willsimport android.app.AlarmManager; 39e26ad459b63271548abbdeba4f8d77fcca9f88bdxinheimport android.app.PendingIntent; 40e26ad459b63271548abbdeba4f8d77fcca9f88bdxinheimport android.content.IntentFilter; 41e26ad459b63271548abbdeba4f8d77fcca9f88bdxinheimport android.content.BroadcastReceiver; 42c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadhamimport com.android.server.connectivity.KeepalivePacketData; 432afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Willsimport com.android.server.wifi.hotspot2.NetworkDetail; 442afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Willsimport com.android.server.wifi.hotspot2.SupplicantBridge; 452afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Willsimport com.android.server.wifi.hotspot2.Utils; 465d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Willsimport com.android.server.wifi.util.InformationElementUtil; 47c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham 4818786eca942042388748b0d98979f21c9dff4a89Mitchell Willsimport libcore.util.HexEncoding; 4918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 505cfd8d8b9f241dcad874125a1b5538ee0d6860fexinheimport java.nio.ByteBuffer; 515cfd8d8b9f241dcad874125a1b5538ee0d6860fexinheimport java.nio.CharBuffer; 525cfd8d8b9f241dcad874125a1b5538ee0d6860fexinheimport java.nio.charset.CharacterCodingException; 535cfd8d8b9f241dcad874125a1b5538ee0d6860fexinheimport java.nio.charset.CharsetDecoder; 545cfd8d8b9f241dcad874125a1b5538ee0d6860fexinheimport java.nio.charset.StandardCharsets; 55155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.ArrayList; 56155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.List; 57155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.Locale; 589ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Willsimport java.util.Set; 5918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 60155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/** 61155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Native calls for bring up/shut down of the supplicant daemon and for 62155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * sending requests to the supplicant daemon 63155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 64155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * waitForEvent() is called on the monitor thread for events. All other methods 65155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * must be serialized from the framework. 66155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 67155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@hide} 68155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 69155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandepublic class WifiNative { 70b66b29a00da970ee75052e24f592c8d6c16bd0edxinhe private static boolean DBG = false; 71155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 7218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /** 7318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills * Hold this lock before calling supplicant or HAL methods 7418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills * it is required to mutually exclude access to the driver 7518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills */ 7618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static final Object mLock = new Object(); 77155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 7818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static final LocalLog mLocalLog = new LocalLog(16384); 79155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 8018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static LocalLog getLocalLog() { 8118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return mLocalLog; 8218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 83155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 84155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Register native functions */ 85155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande static { 86155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Native functions are defined in libwifi-service.so */ 87155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande System.loadLibrary("wifi-service"); 88155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande registerNatives(); 89155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 90155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 91155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private static native int registerNatives(); 92155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 9318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* 9418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills * Singleton WifiNative instances 95155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 9618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static WifiNative wlanNativeInterface = 9718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills new WifiNative(SystemProperties.get("wifi.interface", "wlan0")); 9818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static WifiNative getWlanNativeInterface() { 9918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return wlanNativeInterface; 10018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 10218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills //STOPSHIP: get interface name from native side 10318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static WifiNative p2pNativeInterface = new WifiNative("p2p0"); 10418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static WifiNative getP2pNativeInterface() { 10518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return p2pNativeInterface; 10618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 10918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private final String mTAG; 11018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private final String mInterfaceName; 11118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private final String mInterfacePrefix; 11218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 11318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private Context mContext = null; 11418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private PnoMonitor mPnoMonitor = null; 11518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public void initContext(Context context) { 11618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (mContext == null && context != null) { 11718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills mContext = context; 11818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills mPnoMonitor = new PnoMonitor(); 11918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 12018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 121155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 12218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private WifiNative(String interfaceName) { 123155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfaceName = interfaceName; 124155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mTAG = "WifiNative-" + interfaceName; 125e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe 126155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!interfaceName.equals("p2p0")) { 127155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfacePrefix = "IFNAME=" + interfaceName + " "; 128155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 129155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // commands for p2p0 interface don't need prefix 130155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfacePrefix = ""; 131155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 133155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 13418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public String getInterfaceName() { 13518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return mInterfaceName; 136e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 137e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe 13818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Note this affects logging on for all interfaces 139ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle void enableVerboseLogging(int verbose) { 140ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle if (verbose > 0) { 141ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle DBG = true; 142ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } else { 143ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle DBG = false; 144ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } 145ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } 146ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle 14718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private void localLog(String s) { 14818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (mLocalLog != null) 14918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills mLocalLog.log(mInterfaceName + ": " + s); 15018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 15318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 15418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* 15518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills * Driver and Supplicant management 15618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills */ 15718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native static boolean loadDriverNative(); 15818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean loadDriver() { 15918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 16018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return loadDriverNative(); 16118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 163155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 16418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native static boolean isDriverLoadedNative(); 16518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean isDriverLoaded() { 16618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 16718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return isDriverLoadedNative(); 16818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 169155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 170155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 17118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native static boolean unloadDriverNative(); 17218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean unloadDriver() { 17318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 17418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return unloadDriverNative(); 17518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 17618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 17718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 17818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native static boolean startSupplicantNative(boolean p2pSupported); 17918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean startSupplicant(boolean p2pSupported) { 18018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 18118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return startSupplicantNative(p2pSupported); 18218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 18318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 18418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 18518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* Sends a kill signal to supplicant. To be used when we have lost connection 18618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills or when the supplicant is hung */ 18718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native static boolean killSupplicantNative(boolean p2pSupported); 18818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean killSupplicant(boolean p2pSupported) { 18918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 19018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return killSupplicantNative(p2pSupported); 19118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 192155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 193155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 19418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native static boolean connectToSupplicantNative(); 195155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean connectToSupplicant() { 19618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 197b577f391af2c484e443c19b3df1d62cc0924692aVinit Deshpande localLog(mInterfacePrefix + "connectToSupplicant"); 198b577f391af2c484e443c19b3df1d62cc0924692aVinit Deshpande return connectToSupplicantNative(); 199b577f391af2c484e443c19b3df1d62cc0924692aVinit Deshpande } 200155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 201155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 20218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native static void closeSupplicantConnectionNative(); 203155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void closeSupplicantConnection() { 20418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 205b577f391af2c484e443c19b3df1d62cc0924692aVinit Deshpande localLog(mInterfacePrefix + "closeSupplicantConnection"); 206b577f391af2c484e443c19b3df1d62cc0924692aVinit Deshpande closeSupplicantConnectionNative(); 207b577f391af2c484e443c19b3df1d62cc0924692aVinit Deshpande } 208155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 209155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 21018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /** 21118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills * Wait for the supplicant to send an event, returning the event string. 21218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills * @return the event string sent by the supplicant. 21318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills */ 21418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native static String waitForEventNative(); 215155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String waitForEvent() { 216155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // No synchronization necessary .. it is implemented in WifiMonitor 217155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return waitForEventNative(); 218155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 219155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 22018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 22118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* 22218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills * Supplicant Command Primitives 22318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills */ 22418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native boolean doBooleanCommandNative(String command); 22518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 22618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native int doIntCommandNative(String command); 22718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 22818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private native String doStringCommandNative(String command); 22918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 230155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private boolean doBooleanCommand(String command) { 231155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "doBoolean: " + command); 232155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 23318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills String toLog = mInterfacePrefix + command; 234155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande boolean result = doBooleanCommandNative(mInterfacePrefix + command); 2357b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 2360888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) Log.d(mTAG, command + ": returned " + result); 237155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 238155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 239155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 240155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 241a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham private boolean doBooleanCommandWithoutLogging(String command) { 242a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham if (DBG) Log.d(mTAG, "doBooleanCommandWithoutLogging: " + command); 243a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham synchronized (mLock) { 244a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham boolean result = doBooleanCommandNative(mInterfacePrefix + command); 245a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham if (DBG) Log.d(mTAG, command + ": returned " + result); 246a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham return result; 247a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham } 248a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham } 249a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham 250155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int doIntCommand(String command) { 251155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "doInt: " + command); 252155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 25318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills String toLog = mInterfacePrefix + command; 254155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int result = doIntCommandNative(mInterfacePrefix + command); 2557b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 256155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, " returned " + result); 257155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 258155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 259155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 260155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 261155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String doStringCommand(String command) { 2620888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) { 2630888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle //GET_NETWORK commands flood the logs 2640888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (!command.startsWith("GET_NETWORK")) { 2650888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle Log.d(mTAG, "doString: [" + command + "]"); 2660888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 2670888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 268155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 26918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills String toLog = mInterfacePrefix + command; 270155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String result = doStringCommandNative(mInterfacePrefix + command); 27140ff222cec1bd05879edb53abc75c6deead734cavandwalle if (result == null) { 27240ff222cec1bd05879edb53abc75c6deead734cavandwalle if (DBG) Log.d(mTAG, "doStringCommandNative no result"); 27340ff222cec1bd05879edb53abc75c6deead734cavandwalle } else { 2747b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle if (!command.startsWith("STATUS-")) { 2757b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle localLog(toLog + " -> " + result); 2767b581f46f6c9bc6edf0edd287d47106712fb2144vandwalle } 27740ff222cec1bd05879edb53abc75c6deead734cavandwalle if (DBG) Log.d(mTAG, " returned " + result.replace("\n", " ")); 27840ff222cec1bd05879edb53abc75c6deead734cavandwalle } 279155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return result; 280155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 281155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 282155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 283155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String doStringCommandWithoutLogging(String command) { 2840888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (DBG) { 2850888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle //GET_NETWORK commands flood the logs 2860888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle if (!command.startsWith("GET_NETWORK")) { 2870888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle Log.d(mTAG, "doString: [" + command + "]"); 2880888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle } 28927355a942653264388e909a4276196ee63e57811vandwalle } 29027355a942653264388e909a4276196ee63e57811vandwalle synchronized (mLock) { 291155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative(mInterfacePrefix + command); 292155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 293155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 294155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 29518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public String doCustomSupplicantCommand(String command) { 29618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return doStringCommand(command); 29718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 29818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 29918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* 30018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills * Wrappers for supplicant commands 30118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills */ 302155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean ping() { 303155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String pong = doStringCommand("PING"); 304155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (pong != null && pong.equals("PONG")); 305155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 306155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 307ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle public void setSupplicantLogLevel(String level) { 308ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle doStringCommand("LOG_LEVEL " + level); 309ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle } 310ad7319939c424d42fa6a3791c47f613db8ef3cd8vandwalle 311a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng public String getFreqCapability() { 312a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng return doStringCommand("GET_CAPABILITY freq"); 313a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng } 314a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng 31518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 31618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static final int SCAN_WITHOUT_CONNECTION_SETUP = 1; 31718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static final int SCAN_WITH_CONNECTION_SETUP = 2; 31818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 3199ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills public boolean scan(int type, Set<Integer> freqs) { 3209ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills if(freqs == null) { 3219ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills return scan(type, (String)null); 3229ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills } 3239ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills else if (freqs.size() != 0) { 3249ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills StringBuilder freqList = new StringBuilder(); 3259ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills boolean first = true; 3269ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills for (Integer freq : freqs) { 3279ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills if (!first) 3289ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills freqList.append(","); 3299ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills freqList.append(freq.toString()); 3309ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills first = false; 3319ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills } 3329ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills return scan(type, freqList.toString()); 3339ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills } 3349ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills else { 3359ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills return false; 3369ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills } 3379ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills } 3389ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills 3399ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills private boolean scan(int type, String freqList) { 340155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (type == SCAN_WITHOUT_CONNECTION_SETUP) { 341a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (freqList == null) return doBooleanCommand("SCAN TYPE=ONLY"); 342a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng else return doBooleanCommand("SCAN TYPE=ONLY freq=" + freqList); 343155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (type == SCAN_WITH_CONNECTION_SETUP) { 344a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (freqList == null) return doBooleanCommand("SCAN"); 345a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng else return doBooleanCommand("SCAN freq=" + freqList); 346155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 347155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande throw new IllegalArgumentException("Invalid scan type"); 348155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 349155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 350155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 351155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Does a graceful shutdown of supplicant. Is a common stop function for both p2p and sta. 352155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 353155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Note that underneath we use a harsh-sounding "terminate" supplicant command 354155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * for a graceful stop and a mild-sounding "stop" interface 355155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * to kill the process 356155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 357155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopSupplicant() { 358155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("TERMINATE"); 359155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 360155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 361155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String listNetworks() { 362155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("LIST_NETWORKS"); 363155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 364155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 365e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande public String listNetworks(int last_id) { 366e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande return doStringCommand("LIST_NETWORKS LAST_ID=" + last_id); 367e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande } 368e3939cb40d9ba3842be105a6e85172dc06e14758Vinit Deshpande 369155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int addNetwork() { 370155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doIntCommand("ADD_NETWORK"); 371155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 372155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 373155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setNetworkVariable(int netId, String name, String value) { 374155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(name) || TextUtils.isEmpty(value)) return false; 375a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham if (name.equals(WifiConfiguration.pskVarName) 376a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham || name.equals(WifiEnterpriseConfig.PASSWORD_KEY)) { 377a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham return doBooleanCommandWithoutLogging("SET_NETWORK " + netId + " " + name + " " + value); 378a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham } else { 379a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham return doBooleanCommand("SET_NETWORK " + netId + " " + name + " " + value); 380a6777abfc90496801e9942f57fbfa091ba85ae82Prerepa Viswanadham } 381155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 382155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 383155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getNetworkVariable(int netId, String name) { 384155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(name)) return null; 385155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 386155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // GET_NETWORK will likely flood the logs ... 387155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandWithoutLogging("GET_NETWORK " + netId + " " + name); 388155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 389155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 390155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean removeNetwork(int netId) { 391155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("REMOVE_NETWORK " + netId); 392155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 393155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 394f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 395f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle private void logDbg(String debug) { 396f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle long now = SystemClock.elapsedRealtimeNanos(); 397f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle String ts = String.format("[%,d us] ", now/1000); 398ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle Log.e("WifiNative: ", ts+debug+ " stack:" 399ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[2].getMethodName() +" - " 400ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[3].getMethodName() +" - " 401ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[4].getMethodName() +" - " 402ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[5].getMethodName()+" - " 403ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + Thread.currentThread().getStackTrace()[6].getMethodName()); 404f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 405f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 406155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean enableNetwork(int netId, boolean disableOthers) { 407ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle if (DBG) logDbg("enableNetwork nid=" + Integer.toString(netId) 408ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle + " disableOthers=" + disableOthers); 409155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (disableOthers) { 410155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SELECT_NETWORK " + netId); 411155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 412155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("ENABLE_NETWORK " + netId); 413155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 414155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 415155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 416155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean disableNetwork(int netId) { 417f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("disableNetwork nid=" + Integer.toString(netId)); 418155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DISABLE_NETWORK " + netId); 419155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 420155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 4210047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande public boolean selectNetwork(int netId) { 4220047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande if (DBG) logDbg("selectNetwork nid=" + Integer.toString(netId)); 4230047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande return doBooleanCommand("SELECT_NETWORK " + netId); 4240047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande } 4250047ccf563baa288777e06c6fe95d3681fcf5ccdVinit Deshpande 426155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean reconnect() { 427f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("RECONNECT "); 428155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("RECONNECT"); 429155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 430155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 431155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean reassociate() { 432f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (DBG) logDbg("REASSOCIATE "); 433155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("REASSOCIATE"); 434155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 435155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 436155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean disconnect() { 43721bc54cb37a0085b1c909cb4d55ebb12a2facefbvandwalle if (DBG) logDbg("DISCONNECT "); 438155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DISCONNECT"); 439155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 440155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 441155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String status() { 44299d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return status(false); 443155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 444155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 44599d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle public String status(boolean noEvents) { 44699d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle if (noEvents) { 44799d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return doStringCommand("STATUS-NO_EVENTS"); 44899d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } else { 44999d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle return doStringCommand("STATUS"); 45099d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } 45199d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle } 45299d385e3b4d34841d6efcfd7cc9bf1d5ae25de14vandwalle 453155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getMacAddress() { 454155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //Macaddr = XX.XX.XX.XX.XX.XX 455155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String ret = doStringCommand("DRIVER MACADDR"); 456155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!TextUtils.isEmpty(ret)) { 457155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens = ret.split(" = "); 458155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (tokens.length == 2) return tokens[1]; 459155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 460155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return null; 461155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 462155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 463a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 464a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 465155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 466155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Format of results: 467155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * ================= 468155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * id=1 4692afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * bssid=68:7f:76:d7:1a:6e 470155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * freq=2412 4712afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * level=-44 4722afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * tsf=1344626243700342 473155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * flags=[WPA2-PSK-CCMP][WPS][ESS] 4742afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * ssid=zfdy 4752afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * ==== 4762afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * id=2 4772afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * bssid=68:5f:74:d7:1a:6f 4782afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * freq=5180 4792afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * level=-73 4802afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * tsf=1344626243700373 4812afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * flags=[WPA2-PSK-CCMP][WPS][ESS] 4822afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * ssid=zuby 483155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * ==== 484155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 485155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RANGE=ALL gets all scan results 486155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RANGE=ID- gets results from ID 487155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * MASK=<N> see wpa_supplicant/src/common/wpa_ctrl.h for details 48877f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 0 1 0 2 48977f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_MESH_SCAN | WPA_BSS_MASK_DELIM | WPA_BSS_MASK_WIFI_DISPLAY 49077f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 0 0 1 1 -> 9 49177f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_INTERNETW | WPA_BSS_MASK_P2P_SCAN | WPA_BSS_MASK_WPS_SCAN | WPA_BSS_MASK_SSID 49277f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 1 0 0 1 9 -> d 49377f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_FLAGS | WPA_BSS_MASK_IE | WPA_BSS_MASK_AGE | WPA_BSS_MASK_TSF 49477f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 1 0 0 0 8 49577f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_LEVEL | WPA_BSS_MASK_NOISE | WPA_BSS_MASK_QUAL | WPA_BSS_MASK_CAPABILITIES 49677f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 0 1 1 1 7 49777f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_BEACON_INT | WPA_BSS_MASK_FREQ | WPA_BSS_MASK_BSSID | WPA_BSS_MASK_ID 49877f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 49977f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * WPA_BSS_MASK_INTERNETW adds ANQP info (ctrl_iface:4151-4176) 50077f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * 50177f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * ctrl_iface.c:wpa_supplicant_ctrl_iface_process:7884 50277f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * wpa_supplicant_ctrl_iface_bss:4315 50377f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist * print_bss_info 504155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 5052afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private String getRawScanResults(String range) { 5062afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills return doStringCommandWithoutLogging("BSS RANGE=" + range + " MASK=0x29d87"); 5072afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 5082afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 5092afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_IE_STR = "ie="; 5102afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_ID_STR = "id="; 5112afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_BSSID_STR = "bssid="; 5122afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_FREQ_STR = "freq="; 5132afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_LEVEL_STR = "level="; 5142afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_TSF_STR = "tsf="; 5152afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_FLAGS_STR = "flags="; 5162afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_SSID_STR = "ssid="; 5172afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_DELIMITER_STR = "===="; 5182afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills private static final String BSS_END_STR = "####"; 5192afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 5202afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills public ArrayList<ScanDetail> getScanResults() { 5212afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills int next_sid = 0; 5222afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills ArrayList<ScanDetail> results = new ArrayList<>(); 5232afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills while(next_sid >= 0) { 5242afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills String rawResult = getRawScanResults(next_sid+"-"); 5252afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills next_sid = -1; 5262afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 5272afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills if (TextUtils.isEmpty(rawResult)) 5282afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills break; 5292afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 5302afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills String[] lines = rawResult.split("\n"); 5312afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 5322afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 5332afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills // note that all these splits and substrings keep references to the original 5342afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills // huge string buffer while the amount we really want is generally pretty small 5352afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills // so make copies instead (one example b/11087956 wasted 400k of heap here). 5362afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills final int bssidStrLen = BSS_BSSID_STR.length(); 5372afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills final int flagLen = BSS_FLAGS_STR.length(); 5382afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 5392afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills String bssid = ""; 5402afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills int level = 0; 5412afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills int freq = 0; 5422afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills long tsf = 0; 5432afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills String flags = ""; 5442afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills WifiSsid wifiSsid = null; 5455d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills String infoElementsStr = null; 5462afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills List<String> anqpLines = null; 5472afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 5482afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills for (String line : lines) { 5492afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills if (line.startsWith(BSS_ID_STR)) { // Will find the last id line 5502afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills try { 5512afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills next_sid = Integer.parseInt(line.substring(BSS_ID_STR.length())) + 1; 5522afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } catch (NumberFormatException e) { 5532afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills // Nothing to do 5542afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 5552afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (line.startsWith(BSS_BSSID_STR)) { 5562afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills bssid = new String(line.getBytes(), bssidStrLen, line.length() - bssidStrLen); 5572afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (line.startsWith(BSS_FREQ_STR)) { 5582afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills try { 5592afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills freq = Integer.parseInt(line.substring(BSS_FREQ_STR.length())); 5602afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } catch (NumberFormatException e) { 5612afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills freq = 0; 5622afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 5632afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (line.startsWith(BSS_LEVEL_STR)) { 5642afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills try { 5652afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills level = Integer.parseInt(line.substring(BSS_LEVEL_STR.length())); 5662afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills /* some implementations avoid negative values by adding 256 5672afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills * so we need to adjust for that here. 5682afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills */ 5692afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills if (level > 0) level -= 256; 5702afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } catch (NumberFormatException e) { 5712afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills level = 0; 5722afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 5732afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (line.startsWith(BSS_TSF_STR)) { 5742afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills try { 5752afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills tsf = Long.parseLong(line.substring(BSS_TSF_STR.length())); 5762afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } catch (NumberFormatException e) { 5772afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills tsf = 0; 5782afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 5792afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (line.startsWith(BSS_FLAGS_STR)) { 5802afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills flags = new String(line.getBytes(), flagLen, line.length() - flagLen); 5812afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (line.startsWith(BSS_SSID_STR)) { 5822afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills wifiSsid = WifiSsid.createFromAsciiEncoded( 5832afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills line.substring(BSS_SSID_STR.length())); 5842afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (line.startsWith(BSS_IE_STR)) { 5855d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills infoElementsStr = line; 5862afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (SupplicantBridge.isAnqpAttribute(line)) { 5872afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills if (anqpLines == null) { 5882afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills anqpLines = new ArrayList<>(); 5892afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 5902afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills anqpLines.add(line); 5912afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } else if (line.startsWith(BSS_DELIMITER_STR) || line.startsWith(BSS_END_STR)) { 5922afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills if (bssid != null) { 5932afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills try { 5945d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills if (infoElementsStr == null) { 5955d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills throw new IllegalArgumentException("Null information element data"); 5965d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills } 5975d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills int seperator = infoElementsStr.indexOf('='); 5985d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills if (seperator < 0) { 5995d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills throw new IllegalArgumentException("No element separator"); 6005d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills } 6015d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills 6025d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills ScanResult.InformationElement[] infoElements = 6035d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills InformationElementUtil.parseInformationElements( 6045d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills Utils.hexToBytes(infoElementsStr.substring(seperator + 1))); 6055d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills 6065d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills NetworkDetail networkDetail = new NetworkDetail(bssid, 6075d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills infoElements, anqpLines, freq); 6082afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 6092afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills String xssid = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE; 6102afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills if (!xssid.equals(networkDetail.getTrimmedSSID())) { 6112afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills Log.d(TAG, String.format( 6122afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills "Inconsistent SSID on BSSID '%s': '%s' vs '%s': %s", 6135d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills bssid, xssid, networkDetail.getSSID(), infoElementsStr)); 6142afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 6152afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills 6162afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills if (networkDetail.hasInterworking()) { 6172afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills Log.d(TAG, "HSNwk: '" + networkDetail); 6182afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 6199ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills ScanDetail scan = new ScanDetail(networkDetail, wifiSsid, bssid, flags, 6209ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills level, freq, tsf); 6219ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills scan.getScanResult().informationElements = infoElements; 6229ec71f6499e0e3d6f52310a41ff4a59d2fa4f8b2Mitchell Wills results.add(scan); 6232afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } catch (IllegalArgumentException iae) { 6242afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills Log.d(TAG, "Failed to parse information elements: " + iae); 6252afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 6262afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 6272afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills bssid = null; 6282afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills level = 0; 6292afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills freq = 0; 6302afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills tsf = 0; 6312afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills flags = ""; 6322afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills wifiSsid = null; 6335d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills infoElementsStr = null; 6342afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills anqpLines = null; 6352afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 6362afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 6372afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills } 6382afa54e3c8fa1153302a0d57b0e9b7bee35406ffMitchell Wills return results; 63977f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist } 64077f2b82a2e80af8da52c22d69a76def6d4209757Jan Nordqvist 641155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 642446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * Format of result: 643446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * id=1016 644446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * bssid=00:03:7f:40:84:10 645446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * freq=2462 646446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * beacon_int=200 647446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * capabilities=0x0431 648446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * qual=0 649446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * noise=0 650446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * level=-46 651446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * tsf=0000002669008476 652446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * age=5 653446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * ie=00105143412d485332302d52322d54455354010882848b960c12182403010b0706555... 654446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * flags=[WPA2-EAP-CCMP][ESS][P2P][HS20] 655446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * ssid=QCA-HS20-R2-TEST 656446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * p2p_device_name= 65756d0178183460eed9afbd85e5c0d215e27d5f5bcvandwalle * p2p_config_methods=0x0SET_NE 658446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_venue_name=02083d656e6757692d466920416c6c69616e63650a3239383920436f... 659446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_network_auth_type=010000 660446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_roaming_consortium=03506f9a05001bc504bd 661446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_ip_addr_type_availability=0c 662446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_nai_realm=0200300000246d61696c2e6578616d706c652e636f6d3b636973636f2... 663446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_3gpp=000600040132f465 664446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * anqp_domain_name=0b65786d61706c652e636f6d 665446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_operator_friendly_name=11656e6757692d466920416c6c69616e63650e636869... 666446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_wan_metrics=01c40900008001000000000a00 667446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_connection_capability=0100000006140001061600000650000106bb010106bb0... 668446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng * hs20_osu_providers_list=0b5143412d4f53552d425353010901310015656e6757692d... 669446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng */ 670446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng public String scanResult(String bssid) { 671446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng return doStringCommand("BSS " + bssid); 672446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng } 673446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng 674155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startDriver() { 675155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER START"); 676155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 677155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 678155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopDriver() { 679155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER STOP"); 680155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 681155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 682155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 683155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 684155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Start filtering out Multicast V4 packets 685155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 686155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 687155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Multicast filtering rules work as follows: 688155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 689155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The driver can filter multicast (v4 and/or v6) and broadcast packets when in 690155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * a power optimized mode (typically when screen goes off). 691155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 692155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * In order to prevent the driver from filtering the multicast/broadcast packets, we have to 693155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * add a DRIVER RXFILTER-ADD rule followed by DRIVER RXFILTER-START to make the rule effective 694155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 695155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-ADD Num 696155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * where Num = 0 - Unicast, 1 - Broadcast, 2 - Mutil4 or 3 - Multi6 697155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 698155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * and DRIVER RXFILTER-START 699155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * In order to stop the usage of these rules, we do 700155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 701155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-STOP 702155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * DRIVER RXFILTER-REMOVE Num 703155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * where Num is as described for RXFILTER-ADD 704155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 705155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The SETSUSPENDOPT driver command overrides the filtering rules 706155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 707155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startFilteringMulticastV4Packets() { 708155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 709155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-REMOVE 2") 710155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 711155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 712155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 713155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 714155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Stop filtering out Multicast V4 packets. 715155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 716155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 717155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopFilteringMulticastV4Packets() { 718155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 719155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-ADD 2") 720155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 721155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 722155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 723155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 724155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Start filtering out Multicast V6 packets 725155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 726155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 727155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startFilteringMulticastV6Packets() { 728155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 729155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-REMOVE 3") 730155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 731155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 732155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 733155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 734155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Stop filtering out Multicast V6 packets. 735155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded, {@code false} otherwise 736155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 737155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean stopFilteringMulticastV6Packets() { 738155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER RXFILTER-STOP") 739155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-ADD 3") 740155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && doBooleanCommand("DRIVER RXFILTER-START"); 741155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 742155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 74303cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt /** 74403cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * Set the operational frequency band 74503cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * @param band One of 74603cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_AUTO}, 74703cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_5GHZ}, 74803cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * {@link WifiManager#WIFI_FREQUENCY_BAND_2GHZ}, 74903cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt * @return {@code true} if the operation succeeded, {@code false} otherwise 75003cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt */ 751155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBand(int band) { 75203cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt String bandstr; 75303cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt 75403cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt if (band == WifiManager.WIFI_FREQUENCY_BAND_5GHZ) 75503cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "5G"; 75603cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt else if (band == WifiManager.WIFI_FREQUENCY_BAND_2GHZ) 75703cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "2G"; 75803cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt else 75903cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt bandstr = "AUTO"; 76003cdd624f5da6d62cb731304aa7505921566f69dDmitry Shmidt return doBooleanCommand("SET SETBAND " + bandstr); 761155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 762155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 76318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0; 76418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED = 1; 76518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2; 7667ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde /** 7677ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * Sets the bluetooth coexistence mode. 7687ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * 7697ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * @param mode One of {@link #BLUETOOTH_COEXISTENCE_MODE_DISABLED}, 7707ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * {@link #BLUETOOTH_COEXISTENCE_MODE_ENABLED}, or 7717ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}. 7727ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde * @return Whether the mode was successfully set. 7737ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde */ 774155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBluetoothCoexistenceMode(int mode) { 775155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXMODE " + mode); 776155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 777155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 778155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 779155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Enable or disable Bluetooth coexistence scan mode. When this mode is on, 780155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * some of the low-level scan parameters used by the driver are changed to 781155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * reduce interference with A2DP streaming. 782155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 783155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param isSet whether to enable or disable this mode 784155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the command succeeded, {@code false} otherwise. 785155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 786155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) { 787155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (setCoexScanMode) { 788155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXSCAN-START"); 789155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 790155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER BTCOEXSCAN-STOP"); 791155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 792155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 793155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 7940a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde public void enableSaveConfig() { 7950a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde doBooleanCommand("SET update_config 1"); 7960a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde } 7970a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde 798155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean saveConfig() { 799155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SAVE_CONFIG"); 800155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 801155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 802155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean addToBlacklist(String bssid) { 803155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) return false; 804155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("BLACKLIST " + bssid); 805155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 806155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 807155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean clearBlacklist() { 808155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("BLACKLIST clear"); 809155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 810155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 811155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setSuspendOptimizations(boolean enabled) { 812155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 813155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER SETSUSPENDMODE 1"); 814155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 815155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("DRIVER SETSUSPENDMODE 0"); 816155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 817155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 818155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 819155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setCountryCode(String countryCode) { 8200465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande if (countryCode != null) 8210465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return doBooleanCommand("DRIVER COUNTRY " + countryCode.toUpperCase(Locale.ROOT)); 8220465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande else 8230465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return doBooleanCommand("DRIVER COUNTRY"); 824155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 825155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 826e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe //PNO Monitor 827e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe private class PnoMonitor { 828e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe private static final int MINIMUM_PNO_GAP = 5 * 1000; 829e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe private static final String ACTION_TOGGLE_PNO = 830e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe "com.android.server.Wifi.action.TOGGLE_PNO"; 831e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe long mLastPnoChangeTimeStamp = -1L; 832e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe boolean mExpectedPnoState = false; 833e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe boolean mCurrentPnoState = false;; 834e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe boolean mWaitForTimer = false; 835e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe final Object mPnoLock = new Object(); 836e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe private final AlarmManager mAlarmManager = 837e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); 838e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe private final PendingIntent mPnoIntent; 839e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe 840e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe public PnoMonitor() { 841e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe Intent intent = new Intent(ACTION_TOGGLE_PNO, null); 842e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe intent.setPackage("android"); 843e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mPnoIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); 844e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe 845e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mContext.registerReceiver( 846e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe new BroadcastReceiver() { 847e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe @Override 848e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe public void onReceive(Context context, Intent intent) { 849e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe synchronized(mPnoLock) { 850e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (DBG) Log.d(mTAG, "PNO timer expire, PNO should change to " + 851e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mExpectedPnoState); 852e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (mCurrentPnoState != mExpectedPnoState) { 853e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (DBG) Log.d(mTAG, "change PNO from " + mCurrentPnoState + " to " 854e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe + mExpectedPnoState); 855e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe boolean ret = setPno(mExpectedPnoState); 856e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (!ret) { 857e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe Log.e(mTAG, "set PNO failure"); 858e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 859e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } else { 860e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (DBG) Log.d(mTAG, "Do not change PNO since current is expected"); 861e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 862e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mWaitForTimer = false; 863e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 864e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 865e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe }, 866e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe new IntentFilter(ACTION_TOGGLE_PNO)); 867e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 868e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe 869e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe private boolean setPno(boolean enable) { 870e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe String cmd = enable ? "SET pno 1" : "SET pno 0"; 871e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe boolean ret = doBooleanCommand(cmd); 872e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mLastPnoChangeTimeStamp = System.currentTimeMillis(); 873e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (ret) { 874e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mCurrentPnoState = enable; 875e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 876e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe return ret; 877e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 878e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe 879e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe public boolean enableBackgroundScan(boolean enable) { 880e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe synchronized(mPnoLock) { 881e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (mWaitForTimer) { 882e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe //already has a timer 883e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mExpectedPnoState = enable; 884e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (DBG) Log.d(mTAG, "update expected PNO to " + mExpectedPnoState); 885e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } else { 886e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (mCurrentPnoState == enable) { 887e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe return true; 888e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 889e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe long timeDifference = System.currentTimeMillis() - mLastPnoChangeTimeStamp; 890e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (timeDifference >= MINIMUM_PNO_GAP) { 891e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe return setPno(enable); 892e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } else { 893e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mExpectedPnoState = enable; 894e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mWaitForTimer = true; 895e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (DBG) Log.d(mTAG, "start PNO timer with delay:" + timeDifference); 896e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe mAlarmManager.set(AlarmManager.RTC_WAKEUP, 897e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe System.currentTimeMillis() + timeDifference, mPnoIntent); 898e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 899e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 900e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe return true; 901e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 902e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 903e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe } 904e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe 905c97b98d6877f6603a6a0eee820576f59e7da5e52Pierre Vandwalle public boolean enableBackgroundScan(boolean enable) { 906e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe if (mPnoMonitor != null) { 907e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe return mPnoMonitor.enableBackgroundScan(enable); 908155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 909e26ad459b63271548abbdeba4f8d77fcca9f88bdxinhe return false; 910155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 911155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 912155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 913f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle public void enableAutoConnect(boolean enable) { 914f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle if (enable) { 915f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle doBooleanCommand("STA_AUTOCONNECT 1"); 916f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } else { 917f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle doBooleanCommand("STA_AUTOCONNECT 0"); 918f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 919f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle } 920f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle 921155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setScanInterval(int scanInterval) { 922155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SCAN_INTERVAL " + scanInterval); 923155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 924155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 92556845c30ef2bc7ccfd92764e4c7352aee03ec3a8Vinit Deshpande public void setHs20(boolean hs20) { 92656845c30ef2bc7ccfd92764e4c7352aee03ec3a8Vinit Deshpande if (hs20) { 92756845c30ef2bc7ccfd92764e4c7352aee03ec3a8Vinit Deshpande doBooleanCommand("SET HS20 1"); 92856845c30ef2bc7ccfd92764e4c7352aee03ec3a8Vinit Deshpande } else { 92956845c30ef2bc7ccfd92764e4c7352aee03ec3a8Vinit Deshpande doBooleanCommand("SET HS20 0"); 93056845c30ef2bc7ccfd92764e4c7352aee03ec3a8Vinit Deshpande } 93156845c30ef2bc7ccfd92764e4c7352aee03ec3a8Vinit Deshpande } 93256845c30ef2bc7ccfd92764e4c7352aee03ec3a8Vinit Deshpande 933155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void startTdls(String macAddr, boolean enable) { 934155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enable) { 93518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 93618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills doBooleanCommand("TDLS_DISCOVER " + macAddr); 93718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills doBooleanCommand("TDLS_SETUP " + macAddr); 93818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 939155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 940155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("TDLS_TEARDOWN " + macAddr); 941155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 942155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 943155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 944155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** Example output: 945155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * RSSI=-65 946155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * LINKSPEED=48 947155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * NOISE=9999 948155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * FREQUENCY=0 949155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 950155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String signalPoll() { 951155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandWithoutLogging("SIGNAL_POLL"); 952155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 953155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 954155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** Example outout: 955155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TXGOOD=396 956155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TXBAD=1 957155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 958155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String pktcntPoll() { 959155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("PKTCNT_POLL"); 960155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 961155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 962155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void bssFlush() { 963155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("BSS_FLUSH 0"); 964155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 965155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 966155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPbc(String bssid) { 967155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 968155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PBC"); 969155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 970155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PBC " + bssid); 971155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 972155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 973155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 974155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPbc(String iface, String bssid) { 975155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 976155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 977155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC"); 978155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 979155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid); 980155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 981155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 982155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 983155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 984155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPinKeypad(String pin) { 985155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(pin)) return false; 986155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_PIN any " + pin); 987155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 988155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 989155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsPinKeypad(String iface, String pin) { 990155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(pin)) return false; 991155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 992155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin); 993155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 994155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 995155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 996155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 997155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String startWpsPinDisplay(String bssid) { 998155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 999155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("WPS_PIN any"); 1000155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1001155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("WPS_PIN " + bssid); 1002155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1003155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1004155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1005155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String startWpsPinDisplay(String iface, String bssid) { 1006155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 1007155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid)) { 1008155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any"); 1009155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1010155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid); 1011155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1012155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1013155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1014155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 101533b575ca6bee66183929f9474b5a161432918604Vinit Deshpande public boolean setExternalSim(boolean external) { 101618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills String value = external ? "1" : "0"; 101718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills Log.d(TAG, "Setting external_sim to " + value); 101818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return doBooleanCommand("SET external_sim " + value); 101933b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 102033b575ca6bee66183929f9474b5a161432918604Vinit Deshpande 1021f97140d51d14ce0659d381f443c08dbd94dfea28Honore Tricot public boolean simAuthResponse(int id, String type, String response) { 1022f97140d51d14ce0659d381f443c08dbd94dfea28Honore Tricot // with type = GSM-AUTH, UMTS-AUTH or UMTS-AUTS 102318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return doBooleanCommand("CTRL-RSP-SIM-" + id + ":" + type + response); 102433b575ca6bee66183929f9474b5a161432918604Vinit Deshpande } 102533b575ca6bee66183929f9474b5a161432918604Vinit Deshpande 1026ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot public boolean simIdentityResponse(int id, String response) { 102718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return doBooleanCommand("CTRL-RSP-IDENTITY-" + id + ":" + response); 1028ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot } 1029ad607d99c372160c7d4b38e755e1b47d6419856eHonore Tricot 1030155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Configures an access point connection */ 1031155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean startWpsRegistrar(String bssid, String pin) { 1032155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(bssid) || TextUtils.isEmpty(pin)) return false; 1033155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_REG " + bssid + " " + pin); 1034155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1035155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1036155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean cancelWps() { 1037155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WPS_CANCEL"); 1038155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1039155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1040155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setPersistentReconnect(boolean enabled) { 1041155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int value = (enabled == true) ? 1 : 0; 1042155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET persistent_reconnect " + value); 1043155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1044155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1045155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setDeviceName(String name) { 1046155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET device_name " + name); 1047155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1048155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1049155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setDeviceType(String type) { 1050155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET device_type " + type); 1051155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1052155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1053155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setConfigMethods(String cfg) { 1054155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET config_methods " + cfg); 1055155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1056155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1057155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setManufacturer(String value) { 1058155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET manufacturer " + value); 1059155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1060155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1061155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setModelName(String value) { 1062155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET model_name " + value); 1063155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1064155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1065155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setModelNumber(String value) { 1066155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET model_number " + value); 1067155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1068155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1069155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setSerialNumber(String value) { 1070155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET serial_number " + value); 1071155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1072155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1073155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pSsidPostfix(String postfix) { 1074155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET p2p_ssid_postfix " + postfix); 1075155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1076155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1077155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pGroupIdle(String iface, int time) { 1078155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 1079155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time); 1080155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1081155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1082155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1083155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setPowerSave(boolean enabled) { 1084155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 1085155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET ps 1"); 1086155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1087155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("SET ps 0"); 1088155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1089155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1090155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1091155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setP2pPowerSave(String iface, boolean enabled) { 1092155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 1093155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enabled) { 1094155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1"); 1095155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1096155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0"); 1097155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1098155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1099155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setWfdEnable(boolean enable) { 1102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("SET wifi_display " + (enable ? "1" : "0")); 1103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setWfdDeviceInfo(String hex) { 1106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("WFD_SUBELEM_SET 0 " + hex); 1107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1109155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1110155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * "sta" prioritizes STA connection over P2P and "p2p" prioritizes 1111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P connection over STA 1112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean setConcurrencyPriority(String s) { 1114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SET conc_pref " + s); 1115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1116155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1117155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFind() { 1118155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FIND"); 1119155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1120155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1121155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFind(int timeout) { 1122155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (timeout <= 0) { 1123155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pFind(); 1124155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1125155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FIND " + timeout); 1126155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1127155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1128155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pStopFind() { 1129155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_STOP_FIND"); 1130155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1131155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pListen() { 1133155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_LISTEN"); 1134155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1136155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pListen(int timeout) { 1137155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (timeout <= 0) { 1138155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pListen(); 1139155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1140155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_LISTEN " + timeout); 1141155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1142155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1143155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pExtListen(boolean enable, int period, int interval) { 1144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (enable && interval < period) { 1145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_EXT_LISTEN" 1148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + (enable ? (" " + period + " " + interval) : "")); 1149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pSetChannel(int lc, int oc) { 1152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Log.d(mTAG, "p2pSetChannel: lc="+lc+", oc="+oc); 1153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 115418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 115518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (lc >=1 && lc <= 11) { 115618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (!doBooleanCommand("P2P_SET listen_channel " + lc)) { 115718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return false; 115818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 115918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else if (lc != 0) { 1160155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1161155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 116318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (oc >= 1 && oc <= 165 ) { 116418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills int freq = (oc <= 14 ? 2407 : 5000) + oc * 5; 116518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return doBooleanCommand("P2P_SET disallow_freq 1000-" 116618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills + (freq - 5) + "," + (freq + 5) + "-6000"); 116718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else if (oc == 0) { 116818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* oc==0 disables "P2P_SET disallow_freq" (enables all freqs) */ 116918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return doBooleanCommand("P2P_SET disallow_freq \"\""); 117018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 1171155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1172155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1173155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1174155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1175155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pFlush() { 1176155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_FLUSH"); 1177155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1178155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 117918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static final int DEFAULT_GROUP_OWNER_INTENT = 6; 1180155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* p2p_connect <peer device address> <pbc|pin|PIN#> [label|display|keypad] 1181155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande [persistent] [join|auth] [go_intent=<0..15>] [freq=<in MHz>] */ 1182155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) { 1183155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config == null) return null; 1184155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande List<String> args = new ArrayList<String>(); 1185155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WpsInfo wps = config.wps; 1186155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(config.deviceAddress); 1187155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1188155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch (wps.setup) { 1189155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.PBC: 1190155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("pbc"); 1191155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1192155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.DISPLAY: 1193155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(wps.pin)) { 1194155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("pin"); 1195155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1196155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 1197155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1198155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("display"); 1199155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1200155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.KEYPAD: 1201155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 1202155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("keypad"); 1203155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1204155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.LABEL: 1205155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add(wps.pin); 1206155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("label"); 1207155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande default: 1208155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1209155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1210155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1211155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config.netId == WifiP2pGroup.PERSISTENT_NET_ID) { 1212155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("persistent"); 1213155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1214155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1215155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (joinExistingGroup) { 1216155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("join"); 1217155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1218155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //TODO: This can be adapted based on device plugged in state and 1219155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //device battery state 1220155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int groupOwnerIntent = config.groupOwnerIntent; 1221155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (groupOwnerIntent < 0 || groupOwnerIntent > 15) { 1222155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT; 1223155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1224155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande args.add("go_intent=" + groupOwnerIntent); 1225155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1226155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1227155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_CONNECT "; 1228155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String s : args) command += s + " "; 1229155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1230155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(command); 1231155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1232155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1233155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pCancelConnect() { 1234155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_CANCEL"); 1235155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1236155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1237155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pProvisionDiscovery(WifiP2pConfig config) { 1238155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (config == null) return false; 1239155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1240155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch (config.wps.setup) { 1241155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.PBC: 1242155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " pbc"); 1243155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.DISPLAY: 1244155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //We are doing display, so provision discovery is keypad 1245155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " keypad"); 1246155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WpsInfo.KEYPAD: 1247155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //We are doing keypad, so provision discovery is display 1248155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " display"); 1249155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande default: 1250155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1251155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1252155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1253155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1254155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1255155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupAdd(boolean persistent) { 1256155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (persistent) { 1257155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD persistent"); 1258155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1259155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD"); 1260155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1261155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1262155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupAdd(int netId) { 1263155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_GROUP_ADD persistent=" + netId); 1264155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1265155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1266155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pGroupRemove(String iface) { 1267155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(iface)) return false; 1268155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLock) { 1269155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface); 1270155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1271155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1272155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1273155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pReject(String deviceAddress) { 1274155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_REJECT " + deviceAddress); 1275155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1276155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1277155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Invite a peer to a group */ 1278155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) { 1279155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress)) return false; 1280155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1281155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (group == null) { 1282155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE peer=" + deviceAddress); 1283155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1284155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE group=" + group.getInterface() 1285155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + " peer=" + deviceAddress + " go_dev_addr=" + group.getOwner().deviceAddress); 1286155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1287155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1288155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1289155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Reinvoke a persistent connection */ 1290155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pReinvoke(int netId, String deviceAddress) { 1291155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress) || netId < 0) return false; 1292155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1293155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_INVITE persistent=" + netId + " peer=" + deviceAddress); 1294155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1295155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1296155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pGetSsid(String deviceAddress) { 1297155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return p2pGetParam(deviceAddress, "oper_ssid"); 1298155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1299155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1300155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pGetDeviceAddress() { 130136286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande Log.d(TAG, "p2pGetDeviceAddress"); 130236286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 130327f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande String status = null; 130427f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande 130536286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande /* Explicitly calling the API without IFNAME= prefix to take care of the devices that 130636286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande don't have p2p0 interface. Supplicant seems to be returning the correct address anyway. */ 130736286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 130827f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande synchronized (mLock) { 130927f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande status = doStringCommandNative("STATUS"); 131027f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande } 131127f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande 131227f4b0c6ea9533e91863da48cefc80f8b5a88d1eVinit Deshpande String result = ""; 131336286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (status != null) { 131436286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande String[] tokens = status.split("\n"); 131536286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande for (String token : tokens) { 131636286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (token.startsWith("p2p_device_address=")) { 131736286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande String[] nameValue = token.split("="); 131836286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande if (nameValue.length != 2) 131936286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande break; 132036286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande result = nameValue[1]; 132136286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande } 1322155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1323155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 132436286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande 132536286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande Log.d(TAG, "p2pGetDeviceAddress returning " + result); 132636286b23c4e30f042ed753a670c2b462ebf13a48Vinit Deshpande return result; 1327155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1328155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1329155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int getGroupCapability(String deviceAddress) { 1330155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int gc = 0; 1331155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(deviceAddress)) return gc; 1332155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String peerInfo = p2pPeer(deviceAddress); 1333155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (TextUtils.isEmpty(peerInfo)) return gc; 1334155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1335155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens = peerInfo.split("\n"); 1336155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String token : tokens) { 1337155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (token.startsWith("group_capab=")) { 1338155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] nameValue = token.split("="); 1339155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (nameValue.length != 2) break; 1340155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1341155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return Integer.decode(nameValue[1]); 1342155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch(NumberFormatException e) { 1343155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return gc; 1344155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1345155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1346155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1347155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return gc; 1348155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1349155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1350155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pPeer(String deviceAddress) { 1351155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand("P2P_PEER " + deviceAddress); 1352155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1353155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1354155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String p2pGetParam(String deviceAddress, String key) { 1355155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (deviceAddress == null) return null; 1356155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1357155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String peerInfo = p2pPeer(deviceAddress); 1358155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (peerInfo == null) return null; 1359155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens= peerInfo.split("\n"); 1360155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1361155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande key += "="; 1362155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (String token : tokens) { 1363155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (token.startsWith(key)) { 1364155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] nameValue = token.split("="); 1365155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (nameValue.length != 2) break; 1366155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return nameValue[1]; 1367155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1368155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1369155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return null; 1370155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1371155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1372155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) { 1373155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 1374155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour <query hexdump> <RDATA hexdump> 1375155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp <version hex> <service> 1376155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1377155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * e.g) 1378155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * [Bonjour] 1379155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * # IP Printing over TCP (PTR) (RDATA=MyPrinter._ipp._tcp.local.) 1380155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027 1381155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * # IP Printing over TCP (TXT) (RDATA=txtvers=1,pdl=application/postscript) 1382155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 1383155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074 1384155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1385155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * [UPnP] 1386155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012 1387155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice 1388155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp 1389155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * -org:device:InternetGatewayDevice:1 1390155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9322-123456789012::urn:schemas-upnp 1391155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * -org:service:ContentDirectory:2 1392155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 139318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 139418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills for (String s : servInfo.getSupplicantQueryList()) { 139518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills String command = "P2P_SERVICE_ADD"; 139618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills command += (" " + s); 139718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (!doBooleanCommand(command)) { 139818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return false; 139918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 1400155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1401155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1402155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 1403155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1404155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1405155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) { 1406155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 1407155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_DEL bonjour <query hexdump> 1408155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * P2P_SERVICE_DEL upnp <version hex> <service> 1409155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 141018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 141118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills for (String s : servInfo.getSupplicantQueryList()) { 141218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills String command = "P2P_SERVICE_DEL "; 1413155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 141418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills String[] data = s.split(" "); 141518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (data.length < 2) { 141618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return false; 141718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 141818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if ("upnp".equals(data[0])) { 141918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills command += s; 142018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else if ("bonjour".equals(data[0])) { 142118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills command += data[0]; 142218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills command += (" " + data[1]); 142318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 142418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return false; 142518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 142618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (!doBooleanCommand(command)) { 142718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return false; 142818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 1429155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1430155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1431155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 1432155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1433155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1434155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServiceFlush() { 1435155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SERVICE_FLUSH"); 1436155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1437155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1438155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String p2pServDiscReq(String addr, String query) { 1439155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String command = "P2P_SERV_DISC_REQ"; 1440155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + addr); 1441155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande command += (" " + query); 1442155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1443155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(command); 1444155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1445155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1446155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean p2pServDiscCancelReq(String id) { 1447155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id); 1448155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1449155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1450155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Set the current mode of miracast operation. 1451155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 0 = disabled 1452155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1 = operating as source 1453155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 2 = operating as sink 1454155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1455155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setMiracastMode(int mode) { 1456155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Note: optional feature on the driver. It is ok for this to fail. 1457155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande doBooleanCommand("DRIVER MIRACAST " + mode); 1458155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 14593f7ef65ab71619040032aee96b5599849881d6fdAndres Morales 1460446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng public boolean fetchAnqp(String bssid, String subtypes) { 1461446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng return doBooleanCommand("ANQP_GET " + bssid + " " + subtypes); 1462446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng } 1463446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng 1464f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande /* 1465f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande * NFC-related calls 1466f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande */ 1467f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande public String getNfcWpsConfigurationToken(int netId) { 1468f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return doStringCommand("WPS_NFC_CONFIG_TOKEN WPS " + netId); 1469f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1470f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande 1471f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande public String getNfcHandoverRequest() { 1472f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return doStringCommand("NFC_GET_HANDOVER_REQ NDEF P2P-CR"); 1473f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1474f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande 1475f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande public String getNfcHandoverSelect() { 1476f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return doStringCommand("NFC_GET_HANDOVER_SEL NDEF P2P-CR"); 1477f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1478f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande 1479f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande public boolean initiatorReportNfcHandover(String selectMessage) { 1480f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return doBooleanCommand("NFC_REPORT_HANDOVER INIT P2P 00 " + selectMessage); 1481f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1482f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande 1483f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande public boolean responderReportNfcHandover(String requestMessage) { 1484f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return doBooleanCommand("NFC_REPORT_HANDOVER RESP P2P " + requestMessage + " 00"); 1485f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1486f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande 14877f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde /* WIFI HAL support */ 14887f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 148918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // HAL command ids 149018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int sCmdId = 1; 149118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int getNewCmdIdLocked() { 149218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return sCmdId++; 149318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 149418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 1495b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static final String TAG = "WifiNative-HAL"; 1496f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande private static long sWifiHalHandle = 0; /* used by JNI to save wifi_handle */ 1497f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande private static long[] sWifiIfaceHandles = null; /* used by JNI to save interface handles */ 1498aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static int sWlan0Index = -1; 1499aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle private static int sP2p0Index = -1; 1500f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande private static MonitorThread sThread; 1501f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande private static final int STOP_HAL_TIMEOUT_MS = 1000; 15027f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1503b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean startHalNative(); 1504b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native void stopHalNative(); 1505b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native void waitForHalEventNative(); 15067f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1507b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static class MonitorThread extends Thread { 15087ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde public void run() { 1509b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande Log.i(TAG, "Waiting for HAL events mWifiHalHandle=" + Long.toString(sWifiHalHandle)); 15107ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde waitForHalEventNative(); 15117ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 15127ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 15137ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 151418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean startHal() { 1515d6307b404302949f6dadd14fa0860ff1aec432dcxinhe String debugLog = "startHal stack: "; 1516d6307b404302949f6dadd14fa0860ff1aec432dcxinhe java.lang.StackTraceElement[] elements = Thread.currentThread().getStackTrace(); 1517d6307b404302949f6dadd14fa0860ff1aec432dcxinhe for (int i = 2; i < elements.length && i <= 7; i++ ) { 1518d6307b404302949f6dadd14fa0860ff1aec432dcxinhe debugLog = debugLog + " - " + elements[i].getMethodName(); 1519d6307b404302949f6dadd14fa0860ff1aec432dcxinhe } 1520d6307b404302949f6dadd14fa0860ff1aec432dcxinhe 1521f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande mLocalLog.log(debugLog); 1522d6307b404302949f6dadd14fa0860ff1aec432dcxinhe 1523aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 1524cce360ad854cabb238ba0d9290785c26e837749cVinit Deshpande if (startHalNative() && (getInterfaces() != 0) && (sWlan0Index != -1)) { 1525f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sThread = new MonitorThread(); 1526f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sThread.start(); 1527aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return true; 1528aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } else { 1529f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (DBG) mLocalLog.log("Could not start hal"); 1530f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande Log.e(TAG, "Could not start hal"); 1531aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return false; 1532aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 15337ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 15347ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 15357ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 153618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public void stopHal() { 1537f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande synchronized (mLock) { 153871d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1539f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande stopHalNative(); 1540f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande try { 1541f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sThread.join(STOP_HAL_TIMEOUT_MS); 1542f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande Log.d(TAG, "HAL event thread stopped successfully"); 1543f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } catch (InterruptedException e) { 1544f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande Log.e(TAG, "Could not stop HAL cleanly"); 1545f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1546f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sThread = null; 1547f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sWifiHalHandle = 0; 1548f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sWifiIfaceHandles = null; 1549f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sWlan0Index = -1; 1550f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sP2p0Index = -1; 1551f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1552f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 15537ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 15547f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 155518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean isHalStarted() { 155671d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe return (sWifiHalHandle != 0); 155771d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe } 1558b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native int getInterfacesNative(); 15597f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 156018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public int getInterfaces() { 1561aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 156271d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1563f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sWifiIfaceHandles == null) { 1564f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande int num = getInterfacesNative(); 1565f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande int wifi_num = 0; 1566f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande for (int i = 0; i < num; i++) { 1567f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande String name = getInterfaceNameNative(i); 1568f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande Log.i(TAG, "interface[" + i + "] = " + name); 1569f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (name.equals("wlan0")) { 1570f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sWlan0Index = i; 1571f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande wifi_num++; 1572f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else if (name.equals("p2p0")) { 1573f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sP2p0Index = i; 1574f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande wifi_num++; 1575f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 157602a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 1577f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return wifi_num; 1578f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 1579f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return sWifiIfaceHandles.length; 1580aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 158102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } else { 1582f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return 0; 1583e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1584e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 15857f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 15867f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1587b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native String getInterfaceNameNative(int index); 158818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public String getInterfaceName(int index) { 158918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 159018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return getInterfaceNameNative(index); 159118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 15927f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 15937f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1594e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ScanCapabilities { 1595e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_cache_size; // in number of scan results?? 1596e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_buckets; 1597e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_ap_cache_per_scan; 1598e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_rssi_sample_size; 1599e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_scan_reporting_threshold; // in number of scan results?? 16007d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande public int max_hotlist_bssids; 1601e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public int max_significant_wifi_change_aps; 1602e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1603e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 160418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean getScanCapabilities(ScanCapabilities capabilities) { 1605af5b49884f189bb171c9dc6c6a4405d97e7912acVinit Deshpande synchronized (mLock) { 1606af5b49884f189bb171c9dc6c6a4405d97e7912acVinit Deshpande return isHalStarted() && getScanCapabilitiesNative(sWlan0Index, capabilities); 1607af5b49884f189bb171c9dc6c6a4405d97e7912acVinit Deshpande } 1608e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1609e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1610b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean getScanCapabilitiesNative( 1611b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande int iface, ScanCapabilities capabilities); 1612e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1613b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean startScanNative(int iface, int id, ScanSettings settings); 1614b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean stopScanNative(int iface, int id); 161583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande private static native WifiScanner.ScanData[] getScanResultsNative(int iface, boolean flush); 1616b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native WifiLinkLayerStats getWifiLinkLayerStatsNative(int iface); 1617d745a52dc4f929d4a4030f205ed173bdf60eaf10Pierre Vandwalle private static native void setWifiLinkLayerStatsNative(int iface, int enable); 16187f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1619e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ChannelSettings { 1620e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int frequency; 1621e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int dwell_time_ms; 1622e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde boolean passive; 16237f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 16247f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1625e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class BucketSettings { 1626e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int bucket; 1627e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int band; 1628e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int period_ms; 1629e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int report_events; 1630e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int num_channels; 1631daac2ad767f6047409987bb22812ab5f295e54dfVinit Deshpande ChannelSettings channels[]; 1632e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 16337f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1634e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde public static class ScanSettings { 1635e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int base_period_ms; 1636e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int max_ap_per_scan; 163783a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande int report_threshold_percent; 163883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande int report_threshold_num_scans; 1639e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int num_buckets; 1640daac2ad767f6047409987bb22812ab5f295e54dfVinit Deshpande BucketSettings buckets[]; 1641e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 16427f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1643b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface ScanEventHandler { 1644e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde void onScanResultsAvailable(); 1645476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande void onFullScanResult(ScanResult fullScanResult); 164683a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande void onScanStatus(); 164783a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande void onScanPaused(WifiScanner.ScanData[] data); 1648b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande void onScanRestarted(); 1649e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1650e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 165118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 165218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onScanResultsAvailable(int id) { 165318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills ScanEventHandler handler = sScanEventHandler; 165418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) { 165518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onScanResultsAvailable(); 1656b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1657b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1658b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 1659b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande /* scan status, keep these values in sync with gscan.h */ 1660b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande private static int WIFI_SCAN_BUFFER_FULL = 0; 1661b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande private static int WIFI_SCAN_COMPLETE = 1; 1662b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 166318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 166418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onScanStatus(int status) { 166518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills ScanEventHandler handler = sScanEventHandler; 1666b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande if (status == WIFI_SCAN_BUFFER_FULL) { 1667b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande /* we have a separate event to take care of this */ 1668b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } else if (status == WIFI_SCAN_COMPLETE) { 166918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) { 167018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onScanStatus(); 1671b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1672b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande } 1673e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1674e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 167518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static WifiSsid createWifiSsid(byte[] rawSsid) { 16765cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe String ssidHexString = String.valueOf(HexEncoding.encode(rawSsid)); 16775cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 16785cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe if (ssidHexString == null) { 16795cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe return null; 16805cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe } 16815cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 16825cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe WifiSsid wifiSsid = WifiSsid.createFromHex(ssidHexString); 16835cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 16845cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe return wifiSsid; 16855cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe } 16865cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 16875cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe public static String ssidConvert(byte[] rawSsid) { 16885cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe String ssid; 16895cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 16905cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder(); 16915cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe try { 16925cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe CharBuffer decoded = decoder.decode(ByteBuffer.wrap(rawSsid)); 16935cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe ssid = decoded.toString(); 16945cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe } catch (CharacterCodingException cce) { 16955cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe ssid = null; 16965cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe } 16975cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 16985cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe if (ssid == null) { 16995cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe ssid = new String(rawSsid, StandardCharsets.ISO_8859_1); 17005cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe } 17015cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 17025cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe return ssid; 17035cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe } 17045cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 170518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Called from native 17065cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe public static boolean setSsid(byte[] rawSsid, ScanResult result) { 17075cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe if (rawSsid == null || rawSsid.length == 0 || result == null) { 17085cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe return false; 17095cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe } 17105cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 17115cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe result.SSID = ssidConvert(rawSsid); 17125cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe result.wifiSsid = createWifiSsid(rawSsid); 17135cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe return true; 17145cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe } 17155cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe 171618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void populateScanResult(ScanResult result, byte bytes[], String dbg) { 1717dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (bytes == null) return; 1718dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (dbg == null) dbg = ""; 17195d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills 17205d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills InformationElementUtil.HtOperation htOperation = new InformationElementUtil.HtOperation(); 17215d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills InformationElementUtil.VhtOperation vhtOperation = 17225d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills new InformationElementUtil.VhtOperation(); 17235d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills InformationElementUtil.ExtendedCapabilities extendedCaps = 17245d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills new InformationElementUtil.ExtendedCapabilities(); 17255d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills 17265d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills ScanResult.InformationElement elements[] = 17275d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills InformationElementUtil.parseInformationElements(bytes); 17285d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills for (ScanResult.InformationElement ie : elements) { 17295d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills if(ie.id == ScanResult.InformationElement.EID_HT_OPERATION) { 17305d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills htOperation.from(ie); 17315d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills } else if(ie.id == ScanResult.InformationElement.EID_VHT_OPERATION) { 17325d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills vhtOperation.from(ie); 17335d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills } else if (ie.id == ScanResult.InformationElement.EID_EXTENDED_CAPS) { 17345d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills extendedCaps.from(ie); 1735243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1736243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1737d9f37b2f3df18e96246db93ec4c2a5159b5d3915Vinit Deshpande 17385d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills if (extendedCaps.is80211McRTTResponder) { 1739d9f37b2f3df18e96246db93ec4c2a5159b5d3915Vinit Deshpande result.setFlag(ScanResult.FLAG_80211mc_RESPONDER); 1740d9f37b2f3df18e96246db93ec4c2a5159b5d3915Vinit Deshpande } else { 1741d9f37b2f3df18e96246db93ec4c2a5159b5d3915Vinit Deshpande result.clearFlag(ScanResult.FLAG_80211mc_RESPONDER); 1742d9f37b2f3df18e96246db93ec4c2a5159b5d3915Vinit Deshpande } 1743d9f37b2f3df18e96246db93ec4c2a5159b5d3915Vinit Deshpande 1744243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe //handle RTT related information 17455d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills if (vhtOperation.isValid()) { 17465d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills result.channelWidth = vhtOperation.getChannelWidth(); 17475d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills result.centerFreq0 = vhtOperation.getCenterFreq0(); 17485d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills result.centerFreq1 = vhtOperation.getCenterFreq1(); 1749243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } else { 17505d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills result.channelWidth = htOperation.getChannelWidth(); 17515d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills result.centerFreq0 = htOperation.getCenterFreq0(result.frequency); 1752243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe result.centerFreq1 = 0; 1753243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe } 1754243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe if(DBG) { 1755dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.d(TAG, dbg + "SSID: " + result.SSID + " ChannelWidth is: " + result.channelWidth + 1756243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe " PrimaryFreq: " + result.frequency +" mCenterfreq0: " + result.centerFreq0 + 17575d31cedf4024e0f038b4dfc2081016c8631ee8feMitchell Wills " mCenterfreq1: " + result.centerFreq1 + (extendedCaps.is80211McRTTResponder ? 1758243931f3474f6235cfcf5c1a55fa2f192ee264aexinhe "Support RTT reponder: " : "Do not support RTT responder")); 1759f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 1760f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 1761476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande result.informationElements = elements; 1762dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1763dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 176418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 176518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onFullScanResult(int id, ScanResult result, byte bytes[]) { 1766dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (DBG) Log.i(TAG, "Got a full scan results event, ssid = " + result.SSID + ", " + 1767dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle "num = " + bytes.length); 1768dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 176918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills ScanEventHandler handler = sScanEventHandler; 177018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) { 177118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills populateScanResult(result, bytes, " onFullScanResult "); 177218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onFullScanResult(result); 1773dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 17747f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 17757f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1776b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sScanCmdId = 0; 1777b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static ScanEventHandler sScanEventHandler; 1778b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static ScanSettings sScanSettings; 17797f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 178018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean startScan(ScanSettings settings, ScanEventHandler eventHandler) { 17817f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde synchronized (mLock) { 178271d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1783f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sScanCmdId != 0) { 1784f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande stopScan(); 1785f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else if (sScanSettings != null || sScanEventHandler != null) { 1786b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande /* current scan is paused; no need to stop it */ 1787f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 17887f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1789f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanCmdId = getNewCmdIdLocked(); 1790e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1791f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanSettings = settings; 1792f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanEventHandler = eventHandler; 1793b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 1794f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (startScanNative(sWlan0Index, sScanCmdId, settings) == false) { 1795f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanEventHandler = null; 1796f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanSettings = null; 1797f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanCmdId = 0; 1798f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 1799f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1800f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande 1801f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return true; 1802f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 1803e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1804e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1805e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 18067f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 18077f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 180818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public void stopScan() { 1809b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized (mLock) { 181071d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1811ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills if (sScanCmdId != 0) { 1812ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills stopScanNative(sWlan0Index, sScanCmdId); 1813ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills } 1814f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanSettings = null; 1815f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanEventHandler = null; 1816f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanCmdId = 0; 1817f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1818b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1819b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1820b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 182118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public void pauseScan() { 18227f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde synchronized (mLock) { 182371d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1824f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sScanCmdId != 0 && sScanSettings != null && sScanEventHandler != null) { 1825f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande Log.d(TAG, "Pausing scan"); 1826f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande WifiScanner.ScanData scanData[] = getScanResultsNative(sWlan0Index, true); 1827f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande stopScanNative(sWlan0Index, sScanCmdId); 1828f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanCmdId = 0; 1829f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanEventHandler.onScanPaused(scanData); 1830f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1831b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1832b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1833b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1834b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande 183518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public void restartScan() { 1836b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande synchronized (mLock) { 183771d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1838f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sScanCmdId == 0 && sScanSettings != null && sScanEventHandler != null) { 18396f3626faf50499dd95aa299bb1011c27ab05776dPierre Vandwalle Log.d(TAG, "Restarting scan"); 1840f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande ScanEventHandler handler = sScanEventHandler; 1841f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande ScanSettings settings = sScanSettings; 1842f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (startScan(sScanSettings, sScanEventHandler)) { 1843f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanEventHandler.onScanRestarted(); 1844f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 184583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande /* we are still paused; don't change state */ 1846f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanEventHandler = handler; 1847f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sScanSettings = settings; 1848f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 184983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande } 1850b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande } 1851e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1852e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1853e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 185418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public WifiScanner.ScanData[] getScanResults(boolean flush) { 1855aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 185671d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1857f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return getScanResultsNative(sWlan0Index, flush); 1858f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 1859f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return null; 1860f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1861aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1862e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1863e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1864b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface HotlistEventHandler { 1865d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande void onHotlistApFound (ScanResult[] result); 1866d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande void onHotlistApLost (ScanResult[] result); 1867e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1868e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1869b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sHotlistCmdId = 0; 1870b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static HotlistEventHandler sHotlistEventHandler; 1871e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1872b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private native static boolean setHotlistNative(int iface, int id, 1873e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde WifiScanner.HotlistSettings settings); 1874b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private native static boolean resetHotlistNative(int iface, int id); 1875e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 187618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setHotlist(WifiScanner.HotlistSettings settings, 187718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills HotlistEventHandler eventHandler) { 1878e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 187971d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1880f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sHotlistCmdId != 0) { 1881f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 1882f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 1883f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sHotlistCmdId = getNewCmdIdLocked(); 1884f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1885f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande 1886f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sHotlistEventHandler = eventHandler; 1887f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (setHotlistNative(sWlan0Index, sHotlistCmdId, settings) == false) { 1888f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sHotlistEventHandler = null; 1889f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 1890f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1891e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1892f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return true; 1893f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 1894e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1895e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1896e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1897e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1898e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 189918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public void resetHotlist() { 1900e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 190171d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1902f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sHotlistCmdId != 0) { 1903f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande resetHotlistNative(sWlan0Index, sHotlistCmdId); 1904f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sHotlistCmdId = 0; 1905f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sHotlistEventHandler = null; 1906f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1907e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 19087f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 19097f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 1910e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 191118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 191218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onHotlistApFound(int id, ScanResult[] results) { 191318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills HotlistEventHandler handler = sHotlistEventHandler; 191418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) { 191518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onHotlistApFound(results); 191618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 191718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* this can happen because of race conditions */ 191818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills Log.d(TAG, "Ignoring hotlist AP found event"); 1919d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 1920d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 1921d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 192218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 192318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onHotlistApLost(int id, ScanResult[] results) { 192418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills HotlistEventHandler handler = sHotlistEventHandler; 192518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) { 192618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onHotlistApLost(results); 192718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 192818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* this can happen because of race conditions */ 192918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills Log.d(TAG, "Ignoring hotlist AP lost event"); 1930aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1931e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1932e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1933b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande public static interface SignificantWifiChangeEventHandler { 1934e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde void onChangesFound(ScanResult[] result); 1935e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1936e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1937b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static SignificantWifiChangeEventHandler sSignificantWifiChangeHandler; 1938b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static int sSignificantWifiChangeCmdId; 1939e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1940b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean trackSignificantWifiChangeNative( 1941e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int iface, int id, WifiScanner.WifiChangeSettings settings); 1942b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande private static native boolean untrackSignificantWifiChangeNative(int iface, int id); 1943e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 194418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean trackSignificantWifiChange( 1945b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande WifiScanner.WifiChangeSettings settings, SignificantWifiChangeEventHandler handler) { 1946e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 194771d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1948f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sSignificantWifiChangeCmdId != 0) { 1949f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 1950f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 1951f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sSignificantWifiChangeCmdId = getNewCmdIdLocked(); 1952f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1953f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande 1954f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sSignificantWifiChangeHandler = handler; 1955851075f4f345d98de885bd2f6b833944b282097eMitchell Wills if (trackSignificantWifiChangeNative(sWlan0Index, sSignificantWifiChangeCmdId, 1956851075f4f345d98de885bd2f6b833944b282097eMitchell Wills settings) == false) { 1957f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sSignificantWifiChangeHandler = null; 1958f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 1959f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1960e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1961f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return true; 1962f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 1963e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 1964e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1965e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1966e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1967e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1968e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 196918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public void untrackSignificantWifiChange() { 1970e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde synchronized (mLock) { 197171d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1972f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sSignificantWifiChangeCmdId != 0) { 1973f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande untrackSignificantWifiChangeNative(sWlan0Index, sSignificantWifiChangeCmdId); 1974f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sSignificantWifiChangeCmdId = 0; 1975f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sSignificantWifiChangeHandler = null; 1976f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 1977e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1978e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1979e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1980e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 198118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 198218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onSignificantWifiChange(int id, ScanResult[] results) { 198318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills SignificantWifiChangeEventHandler handler = sSignificantWifiChangeHandler; 198418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) { 198518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onChangesFound(results); 198618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 1987f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande /* this can happen because of race conditions */ 198818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills Log.d(TAG, "Ignoring significant wifi change"); 1989aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1990e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 1991e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 199218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public WifiLinkLayerStats getWifiLinkLayerStats(String iface) { 1993200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle // TODO: use correct iface name to Index translation 1994200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle if (iface == null) return null; 1995aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle synchronized (mLock) { 199671d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 1997aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return getWifiLinkLayerStatsNative(sWlan0Index); 1998f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 1999f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return null; 2000f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 2001aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 20025c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales } 20035c08cc119b92af69997af194cc8b6d0111e37d31Andres Morales 200418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public void setWifiLinkLayerStats(String iface, int enable) { 2005d745a52dc4f929d4a4030f205ed173bdf60eaf10Pierre Vandwalle if (iface == null) return; 2006d745a52dc4f929d4a4030f205ed173bdf60eaf10Pierre Vandwalle synchronized (mLock) { 200771d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2008d745a52dc4f929d4a4030f205ed173bdf60eaf10Pierre Vandwalle setWifiLinkLayerStatsNative(sWlan0Index, enable); 2009d745a52dc4f929d4a4030f205ed173bdf60eaf10Pierre Vandwalle } 2010d745a52dc4f929d4a4030f205ed173bdf60eaf10Pierre Vandwalle } 2011d745a52dc4f929d4a4030f205ed173bdf60eaf10Pierre Vandwalle } 2012d745a52dc4f929d4a4030f205ed173bdf60eaf10Pierre Vandwalle 2013c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande public static native int getSupportedFeatureSetNative(int iface); 201418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public int getSupportedFeatureSet() { 2015f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande synchronized (mLock) { 201671d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2017f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return getSupportedFeatureSetNative(sWlan0Index); 2018f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 2019f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande Log.d(TAG, "Failing getSupportedFeatureset because HAL isn't started"); 2020f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return 0; 2021f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 2022f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 2023a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande } 2024143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 2025143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande /* Rtt related commands/events */ 2026143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande public static interface RttEventHandler { 2027143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande void onRttResults(RttManager.RttResult[] result); 2028143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2029143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 2030143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static RttEventHandler sRttEventHandler; 2031143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static int sRttCmdId; 2032143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 203318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 203418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onRttResults(int id, RttManager.RttResult[] results) { 203518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills RttEventHandler handler = sRttEventHandler; 203618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null && id == sRttCmdId) { 203702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande Log.d(TAG, "Received " + results.length + " rtt results"); 203818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onRttResults(results); 2039143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande sRttCmdId = 0; 2040143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 204118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills Log.d(TAG, "RTT Received event for unknown cmd = " + id + 204218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills ", current id = " + sRttCmdId); 2043143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2044143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2045143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 2046143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static native boolean requestRangeNative( 2047143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande int iface, int id, RttManager.RttParams[] params); 2048143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande private static native boolean cancelRangeRequestNative( 2049143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande int iface, int id, RttManager.RttParams[] params); 2050143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 205118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean requestRtt( 2052143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande RttManager.RttParams[] params, RttEventHandler handler) { 2053143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande synchronized (mLock) { 205471d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2055f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sRttCmdId != 0) { 2056f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande Log.v("TAG", "Last one is still under measurement!"); 2057f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 2058f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 2059f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sRttCmdId = getNewCmdIdLocked(); 2060f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 2061f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sRttEventHandler = handler; 2062f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande Log.v(TAG, "native issue RTT request"); 2063f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return requestRangeNative(sWlan0Index, sRttCmdId, params); 2064143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 2065f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 2066143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2067143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2068143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2069143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 207018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean cancelRtt(RttManager.RttParams[] params) { 207118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills synchronized (mLock) { 207271d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2073f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (sRttCmdId == 0) { 2074f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 2075f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 2076143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 2077f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sRttCmdId = 0; 2078f95649f33db0a328cb4c0bb5e10c7075e6c828f8xinhe 2079f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (cancelRangeRequestNative(sWlan0Index, sRttCmdId, params)) { 2080f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sRttEventHandler = null; 20815cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe Log.v(TAG, "RTT cancel Request Successfully"); 2082f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return true; 2083f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 20845cfd8d8b9f241dcad874125a1b5538ee0d6860fexinhe Log.e(TAG, "RTT cancel Request failed"); 2085f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 2086f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 2087143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } else { 2088143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 2089143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2090143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2091143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 2092042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 2093042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande private static native boolean setScanningMacOuiNative(int iface, byte[] oui); 2094042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 209518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setScanningMacOui(byte[] oui) { 2096042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande synchronized (mLock) { 209771d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2098042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande return setScanningMacOuiNative(sWlan0Index, oui); 2099042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } else { 2100042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande return false; 2101042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 2102042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 2103042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 2104efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 2105efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande private static native int[] getChannelsForBandNative( 2106efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande int iface, int band); 2107efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 210818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public int [] getChannelsForBand(int band) { 2109efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande synchronized (mLock) { 2110ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe if (isHalStarted()) { 2111ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe return getChannelsForBandNative(sWlan0Index, band); 211218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 2113ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe return null; 2114ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe } 2115efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 2116efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 21170465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande 2118ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe private static native boolean isGetChannelsForBandSupportedNative(); 211918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean isGetChannelsForBandSupported(){ 2120ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe synchronized (mLock) { 2121ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe if (isHalStarted()) { 2122ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe return isGetChannelsForBandSupportedNative(); 212318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 2124ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe return false; 2125ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe } 2126ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe } 2127ee0a0132ebb0d7e9baf42e778ea9c094966ffb14xinhe } 21280465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande 21290465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande private static native boolean setDfsFlagNative(int iface, boolean dfsOn); 213018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setDfsFlag(boolean dfsOn) { 21310465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande synchronized (mLock) { 213271d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 21330465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return setDfsFlagNative(sWlan0Index, dfsOn); 21340465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } else { 21350465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return false; 21360465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 21370465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 21380465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande } 2139b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe 2140b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe private static native boolean toggleInterfaceNative(int on); 214118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean toggleInterface(int on) { 2142b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe synchronized (mLock) { 214371d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 214418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return toggleInterfaceNative(on); 2145b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } else { 2146b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe return false; 2147b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 2148b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 2149b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe } 215012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 215112cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe private static native RttManager.RttCapabilities getRttCapabilitiesNative(int iface); 215218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public RttManager.RttCapabilities getRttCapabilities() { 215312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe synchronized (mLock) { 215471d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 215512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe return getRttCapabilitiesNative(sWlan0Index); 215618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 215712cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe return null; 215812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 215912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 216012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 2161939177ff615062ec826601d536466875d8457375xinhe 2162939177ff615062ec826601d536466875d8457375xinhe private static native boolean setCountryCodeHalNative(int iface, String CountryCode); 216318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setCountryCodeHal(String CountryCode) { 2164939177ff615062ec826601d536466875d8457375xinhe synchronized (mLock) { 216571d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2166939177ff615062ec826601d536466875d8457375xinhe return setCountryCodeHalNative(sWlan0Index, CountryCode); 2167939177ff615062ec826601d536466875d8457375xinhe } else { 2168939177ff615062ec826601d536466875d8457375xinhe return false; 2169939177ff615062ec826601d536466875d8457375xinhe } 2170939177ff615062ec826601d536466875d8457375xinhe } 2171939177ff615062ec826601d536466875d8457375xinhe } 2172939177ff615062ec826601d536466875d8457375xinhe 2173d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe /* Rtt related commands/events */ 2174d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe public abstract class TdlsEventHandler { 2175d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe abstract public void onTdlsStatus(String macAddr, int status, int reason); 2176d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2177d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 2178d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe private static TdlsEventHandler sTdlsEventHandler; 2179d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 2180d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe private static native boolean enableDisableTdlsNative(int iface, boolean enable, 2181d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe String macAddr); 218218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean enableDisableTdls(boolean enable, String macAdd, TdlsEventHandler tdlsCallBack) { 2183d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized (mLock) { 2184f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sTdlsEventHandler = tdlsCallBack; 2185f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return enableDisableTdlsNative(sWlan0Index, enable, macAdd); 2186d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2187d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2188d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 2189d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe // Once TDLS per mac and event feature is implemented, this class definition should be 2190d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe // moved to the right place, like WifiManager etc 2191d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe public static class TdlsStatus { 2192d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int channel; 2193d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int global_operating_class; 2194d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int state; 2195d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int reason; 2196d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2197d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe private static native TdlsStatus getTdlsStatusNative(int iface, String macAddr); 219818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public TdlsStatus getTdlsStatus(String macAdd) { 2199d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized (mLock) { 220071d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2201d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return getTdlsStatusNative(sWlan0Index, macAdd); 2202d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 2203d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return null; 2204d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2205d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2206d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2207d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 2208d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe //ToFix: Once TDLS per mac and event feature is implemented, this class definition should be 2209d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe // moved to the right place, like WifiStateMachine etc 2210d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe public static class TdlsCapabilities { 2211d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe /* Maximum TDLS session number can be supported by the Firmware and hardware */ 2212d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe int maxConcurrentTdlsSessionNumber; 2213d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe boolean isGlobalTdlsSupported; 2214d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe boolean isPerMacTdlsSupported; 2215d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe boolean isOffChannelTdlsSupported; 2216d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2217d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 2218d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 2219d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 2220d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe private static native TdlsCapabilities getTdlsCapabilitiesNative(int iface); 222118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public TdlsCapabilities getTdlsCapabilities () { 2222d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe synchronized (mLock) { 222371d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2224d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return getTdlsCapabilitiesNative(sWlan0Index); 2225d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 2226d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return null; 2227d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2228d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2229d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2230d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 223118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static boolean onTdlsStatus(String macAddr, int status, int reason) { 223218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills TdlsEventHandler handler = sTdlsEventHandler; 223318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler == null) { 223418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return false; 223518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 223618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onTdlsStatus(macAddr, status, reason); 223718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills return true; 223818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 2239d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 2240d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 2241a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle //--------------------------------------------------------------------------------- 2242a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 2243a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle /* Wifi Logger commands/events */ 22447d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande 2245a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle public static interface WifiLoggerEventHandler { 22460bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande void onRingBufferData(RingBufferStatus status, byte[] buffer); 22470bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande void onWifiAlert(int errorCode, byte[] buffer); 2248a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 2249a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 2250a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle private static WifiLoggerEventHandler sWifiLoggerEventHandler = null; 2251a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 225218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 22530bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande private static void onRingBufferData(RingBufferStatus status, byte[] buffer) { 225418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills WifiLoggerEventHandler handler = sWifiLoggerEventHandler; 225518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) 225618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onRingBufferData(status, buffer); 225703ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 225803ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 225918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 22600bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande private static void onWifiAlert(byte[] buffer, int errorCode) { 226118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills WifiLoggerEventHandler handler = sWifiLoggerEventHandler; 226218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) 226318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onWifiAlert(errorCode, buffer); 226403ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 226503ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 2266b797893fc1966803d0c013faac42e6396a37a384xinhe private static int sLogCmdId = -1; 2267b797893fc1966803d0c013faac42e6396a37a384xinhe private static native boolean setLoggingEventHandlerNative(int iface, int id); 226818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setLoggingEventHandler(WifiLoggerEventHandler handler) { 22690bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande synchronized (mLock) { 2270b797893fc1966803d0c013faac42e6396a37a384xinhe if (isHalStarted()) { 2271b797893fc1966803d0c013faac42e6396a37a384xinhe int oldId = sLogCmdId; 2272b797893fc1966803d0c013faac42e6396a37a384xinhe sLogCmdId = getNewCmdIdLocked(); 2273b797893fc1966803d0c013faac42e6396a37a384xinhe if (!setLoggingEventHandlerNative(sWlan0Index, sLogCmdId)) { 2274b797893fc1966803d0c013faac42e6396a37a384xinhe sLogCmdId = oldId; 2275b797893fc1966803d0c013faac42e6396a37a384xinhe return false; 2276b797893fc1966803d0c013faac42e6396a37a384xinhe } 2277b797893fc1966803d0c013faac42e6396a37a384xinhe sWifiLoggerEventHandler = handler; 2278b797893fc1966803d0c013faac42e6396a37a384xinhe return true; 2279b797893fc1966803d0c013faac42e6396a37a384xinhe } else { 2280b797893fc1966803d0c013faac42e6396a37a384xinhe return false; 2281b797893fc1966803d0c013faac42e6396a37a384xinhe } 228203ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 228303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 228403ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 228503ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe private static native boolean startLoggingRingBufferNative(int iface, int verboseLevel, 22860bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande int flags, int minIntervalSec ,int minDataSize, String ringName); 228718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean startLoggingRingBuffer(int verboseLevel, int flags, int maxInterval, 228803ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe int minDataSize, String ringName){ 228903ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe synchronized (mLock) { 229071d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 229103ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return startLoggingRingBufferNative(sWlan0Index, verboseLevel, flags, maxInterval, 229203ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe minDataSize, ringName); 229303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } else { 229403ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return false; 229503ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 229603ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 229703ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 229803ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 229903ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe private static native int getSupportedLoggerFeatureSetNative(int iface); 230018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public int getSupportedLoggerFeatureSet() { 230103ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe synchronized (mLock) { 230271d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 230303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return getSupportedLoggerFeatureSetNative(sWlan0Index); 230403ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } else { 2305f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return 0; 230603ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 230703ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 230803ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 230903ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 2310b797893fc1966803d0c013faac42e6396a37a384xinhe private static native boolean resetLogHandlerNative(int iface, int id); 231118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean resetLogHandler() { 2312b797893fc1966803d0c013faac42e6396a37a384xinhe synchronized (mLock) { 2313b797893fc1966803d0c013faac42e6396a37a384xinhe if (isHalStarted()) { 2314b797893fc1966803d0c013faac42e6396a37a384xinhe if (sLogCmdId == -1) { 2315b797893fc1966803d0c013faac42e6396a37a384xinhe Log.e(TAG,"Can not reset handler Before set any handler"); 2316b797893fc1966803d0c013faac42e6396a37a384xinhe return false; 2317b797893fc1966803d0c013faac42e6396a37a384xinhe } 2318b797893fc1966803d0c013faac42e6396a37a384xinhe sWifiLoggerEventHandler = null; 2319b797893fc1966803d0c013faac42e6396a37a384xinhe if (resetLogHandlerNative(sWlan0Index, sLogCmdId)) { 2320b797893fc1966803d0c013faac42e6396a37a384xinhe sLogCmdId = -1; 2321b797893fc1966803d0c013faac42e6396a37a384xinhe return true; 2322b797893fc1966803d0c013faac42e6396a37a384xinhe } else { 2323b797893fc1966803d0c013faac42e6396a37a384xinhe return false; 2324b797893fc1966803d0c013faac42e6396a37a384xinhe } 2325b797893fc1966803d0c013faac42e6396a37a384xinhe } else { 2326b797893fc1966803d0c013faac42e6396a37a384xinhe return false; 2327b797893fc1966803d0c013faac42e6396a37a384xinhe } 2328b797893fc1966803d0c013faac42e6396a37a384xinhe } 2329b797893fc1966803d0c013faac42e6396a37a384xinhe } 2330b797893fc1966803d0c013faac42e6396a37a384xinhe 233103ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe private static native String getDriverVersionNative(int iface); 233218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public String getDriverVersion() { 233303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe synchronized (mLock) { 233471d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 233503ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return getDriverVersionNative(sWlan0Index); 233603ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } else { 2337f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return ""; 233803ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 233903ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 234003ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 234103ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 234203ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 234303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe private static native String getFirmwareVersionNative(int iface); 234418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public String getFirmwareVersion() { 234503ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe synchronized (mLock) { 234671d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 234703ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return getFirmwareVersionNative(sWlan0Index); 234803ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } else { 2349f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return ""; 235003ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 235103ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 235203ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 235303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 23540bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande public static class RingBufferStatus{ 23550bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande String name; 23560bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande int flag; 23570bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande int ringBufferId; 23580bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande int ringBufferByteSize; 23590bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande int verboseLevel; 23600bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande int writtenBytes; 23610bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande int readBytes; 23620bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande int writtenRecords; 23630bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande 23640bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande @Override 23650bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande public String toString() { 23660bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande return "name: " + name + " flag: " + flag + " ringBufferId: " + ringBufferId + 23670bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande " ringBufferByteSize: " +ringBufferByteSize + " verboseLevel: " +verboseLevel + 23680bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande " writtenBytes: " + writtenBytes + " readBytes: " + readBytes + 23690bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande " writtenRecords: " + writtenRecords; 23700bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande } 23710bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande } 23720bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande 23730bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande private static native RingBufferStatus[] getRingBufferStatusNative(int iface); 237418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public RingBufferStatus[] getRingBufferStatus() { 237503ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe synchronized (mLock) { 237671d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 237703ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return getRingBufferStatusNative(sWlan0Index); 237803ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } else { 237903ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return null; 238003ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 238103ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 238203ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 238303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 238403ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe private static native boolean getRingBufferDataNative(int iface, String ringName); 238518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean getRingBufferData(String ringName) { 238603ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe synchronized (mLock) { 238771d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 238803ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return getRingBufferDataNative(sWlan0Index, ringName); 238903ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } else { 239003ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe return false; 239103ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 239203ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 239303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 239403ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe 239518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static byte[] mFwMemoryDump; 239618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 239703ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe private static void onWifiFwMemoryAvailable(byte[] buffer) { 239898dca3397c0049d3cfb9c97e2b021c5ee3a2e1bdxinhe mFwMemoryDump = buffer; 239998dca3397c0049d3cfb9c97e2b021c5ee3a2e1bdxinhe if (DBG) { 240098dca3397c0049d3cfb9c97e2b021c5ee3a2e1bdxinhe Log.d(TAG, "onWifiFwMemoryAvailable is called and buffer length is: " + 240198dca3397c0049d3cfb9c97e2b021c5ee3a2e1bdxinhe (buffer == null ? 0 : buffer.length)); 240298dca3397c0049d3cfb9c97e2b021c5ee3a2e1bdxinhe } 240303ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 2404127f7244183786e6ccae09e81eeccdac31973e69xinhe 240503ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe private static native boolean getFwMemoryDumpNative(int iface); 240618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public byte[] getFwMemoryDump() { 240703ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe synchronized (mLock) { 240871d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 24090bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande if(getFwMemoryDumpNative(sWlan0Index)) { 24100bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande byte[] fwMemoryDump = mFwMemoryDump; 241103ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe mFwMemoryDump = null; 24120bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande return fwMemoryDump; 24130bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande } else { 24140bf150b2d69ec62df905bc6f8603437dc4caee1fVinit Deshpande return null; 241503ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 241603ba4a5b108ab2bbdb5d0e7be46ac45c00a6d9ffxinhe } 2417f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return null; 2418a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 2419a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 2420dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2421dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //--------------------------------------------------------------------------------- 2422dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle /* Configure ePNO */ 2423dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 242418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* pno flags, keep these values in sync with gscan.h */ 242518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int WIFI_PNO_AUTH_CODE_OPEN = 1; // open 242618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int WIFI_PNO_AUTH_CODE_PSK = 2; // WPA_PSK or WPA2PSK 242718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int WIFI_PNO_AUTH_CODE_EAPOL = 4; // any EAPOL 242818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 242918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Whether directed scan needs to be performed (for hidden SSIDs) 243018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int WIFI_PNO_FLAG_DIRECTED_SCAN = 1; 243118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Whether PNO event shall be triggered if the network is found on A band 243218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int WIFI_PNO_FLAG_A_BAND = 2; 243318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Whether PNO event shall be triggered if the network is found on G band 243418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int WIFI_PNO_FLAG_G_BAND = 4; 243518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Whether strict matching is required (i.e. firmware shall not match on the entire SSID) 243618786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static int WIFI_PNO_FLAG_STRICT_MATCH = 8; 243718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 243818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static class WifiPnoNetwork { 2439dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle String SSID; 2440dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int rssi_threshold; 2441dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int flags; 2442dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int auth; 2443dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle String configKey; // kept for reference 2444dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2445dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle WifiPnoNetwork(WifiConfiguration config, int threshold) { 2446dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (config.SSID == null) { 2447dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle this.SSID = ""; 244818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills this.flags = WIFI_PNO_FLAG_DIRECTED_SCAN; 2449dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 2450dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle this.SSID = config.SSID; 2451dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2452dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle this.rssi_threshold = threshold; 2453dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK)) { 245418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills auth |= WIFI_PNO_AUTH_CODE_PSK; 2455dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP) || 2456dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.IEEE8021X)) { 245718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills auth |= WIFI_PNO_AUTH_CODE_EAPOL; 2458dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else if (config.wepKeys[0] != null) { 245918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills auth |= WIFI_PNO_AUTH_CODE_OPEN; 2460dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 246118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills auth |= WIFI_PNO_AUTH_CODE_OPEN; 2462dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 246318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 246418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills flags |= WIFI_PNO_FLAG_A_BAND | WIFI_PNO_FLAG_G_BAND; 2465dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle configKey = config.configKey(); 2466dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2467dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2468dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle @Override 2469dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle public String toString() { 2470dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle StringBuilder sbuf = new StringBuilder(); 2471dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sbuf.append(this.SSID); 2472dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sbuf.append(" flags=").append(this.flags); 2473dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sbuf.append(" rssi=").append(this.rssi_threshold); 2474dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle sbuf.append(" auth=").append(this.auth); 2475dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return sbuf.toString(); 2476dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2477dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2478dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2479dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle public static interface WifiPnoEventHandler { 2480dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle void onPnoNetworkFound(ScanResult results[]); 2481dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2482dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2483dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle private static WifiPnoEventHandler sWifiPnoEventHandler; 2484dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2485dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle private static int sPnoCmdId = 0; 2486dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2487dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle private native static boolean setPnoListNative(int iface, int id, WifiPnoNetwork list[]); 2488dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 248918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setPnoList(WifiPnoNetwork list[], 2490dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle WifiPnoEventHandler eventHandler) { 2491dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.e(TAG, "setPnoList cmd " + sPnoCmdId); 2492dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2493dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle synchronized (mLock) { 249471d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2495dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2496f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sPnoCmdId = getNewCmdIdLocked(); 2497dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2498f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sWifiPnoEventHandler = eventHandler; 2499f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande if (setPnoListNative(sWlan0Index, sPnoCmdId, list)) { 2500f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return true; 2501f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } 2502dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2503dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2504f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sWifiPnoEventHandler = null; 2505f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return false; 2506dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2507dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2508dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 250918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 251018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onPnoNetworkFound(int id, ScanResult[] results) { 2511dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (results == null) { 2512dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.e(TAG, "onPnoNetworkFound null results"); 2513dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return; 2514dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2515dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2516dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle Log.d(TAG, "WifiNative.onPnoNetworkFound result " + results.length); 2517dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 251818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills WifiPnoEventHandler handler = sWifiPnoEventHandler; 251918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (sPnoCmdId != 0 && handler != null) { 252018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills for (int i=0; i<results.length; i++) { 252118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills Log.e(TAG, "onPnoNetworkFound SSID " + results[i].SSID 252218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills + " " + results[i].level + " " + results[i].frequency); 2523dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 252418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills populateScanResult(results[i], results[i].bytes, "onPnoNetworkFound "); 252518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills results[i].wifiSsid = WifiSsid.createFromAsciiEncoded(results[i].SSID); 2526dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 252718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills 252818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onPnoNetworkFound(results); 252918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } else { 253018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills /* this can happen because of race conditions */ 253118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills Log.d(TAG, "Ignoring Pno Network found event"); 2532dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 2533d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle } 2534d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle 253518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public static class WifiLazyRoamParams { 2536d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle int A_band_boost_threshold; 2537d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle int A_band_penalty_threshold; 2538d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle int A_band_boost_factor; 2539d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle int A_band_penalty_factor; 2540d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle int A_band_max_boost; 2541d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle int lazy_roam_hysteresis; 2542d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle int alert_roam_rssi_trigger; 2543dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 2544d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle WifiLazyRoamParams() { 2545d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle } 2546d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle 2547d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle @Override 2548d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle public String toString() { 2549d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle StringBuilder sbuf = new StringBuilder(); 2550d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle sbuf.append(" A_band_boost_threshold=").append(this.A_band_boost_threshold); 2551d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle sbuf.append(" A_band_penalty_threshold=").append(this.A_band_penalty_threshold); 2552d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle sbuf.append(" A_band_boost_factor=").append(this.A_band_boost_factor); 2553d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle sbuf.append(" A_band_penalty_factor=").append(this.A_band_penalty_factor); 2554d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle sbuf.append(" A_band_max_boost=").append(this.A_band_max_boost); 2555d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle sbuf.append(" lazy_roam_hysteresis=").append(this.lazy_roam_hysteresis); 2556d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle sbuf.append(" alert_roam_rssi_trigger=").append(this.alert_roam_rssi_trigger); 2557d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle return sbuf.toString(); 2558d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle } 2559d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle } 2560d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle 25619ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle private native static boolean setLazyRoamNative(int iface, int id, 2562d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle boolean enabled, WifiLazyRoamParams param); 2563d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle 256418786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setLazyRoam(boolean enabled, WifiLazyRoamParams params) { 2565d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle synchronized (mLock) { 256671d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2567d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle sPnoCmdId = getNewCmdIdLocked(); 25689ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle return setLazyRoamNative(sWlan0Index, sPnoCmdId, enabled, params); 2569d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle } else { 2570d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle return false; 2571d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle } 2572d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle } 2573d4c25fd76644d5490700ae69fada4669de5193a1Pierre Vandwalle } 25749ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle 25759ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle private native static boolean setBssidBlacklistNative(int iface, int id, 25769ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle String list[]); 25779ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle 257818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setBssidBlacklist(String list[]) { 25799ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle int size = 0; 25809ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle if (list != null) { 25819ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle size = list.length; 25829ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle } 25839ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle Log.e(TAG, "setBssidBlacklist cmd " + sPnoCmdId + " size " + size); 25849ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle 25859ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle synchronized (mLock) { 258671d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2587f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sPnoCmdId = getNewCmdIdLocked(); 2588f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return setBssidBlacklistNative(sWlan0Index, sPnoCmdId, list); 2589f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 25909ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle return false; 25919ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle } 25929ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle } 25939ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle } 25949ccffbb6c3fe8eaa7d70cc3076d0dc3c6a9073e7Pierre Vandwalle 25955caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle private native static boolean setSsidWhitelistNative(int iface, int id, String list[]); 25965caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle 259718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public boolean setSsidWhitelist(String list[]) { 25985caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle int size = 0; 25995caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle if (list != null) { 26005caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle size = list.length; 26015caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle } 26025caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle Log.e(TAG, "setSsidWhitelist cmd " + sPnoCmdId + " size " + size); 26035caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle 26045caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle synchronized (mLock) { 260571d0be16c79791a005d60f9d5fa7d2d81e1f8c80xinhe if (isHalStarted()) { 2606f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande sPnoCmdId = getNewCmdIdLocked(); 26075caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle 2608f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande return setSsidWhitelistNative(sWlan0Index, sPnoCmdId, list); 2609f49a59bda006b13e0118d144e0a4a5f569b2251eVinit Deshpande } else { 26105caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle return false; 26115caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle } 26125caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle } 26135caa43b34e0445ff08bff5931b84ffbc850b2a66Pierre Vandwalle } 2614c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham 2615c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham private native static int startSendingOffloadedPacketNative(int iface, int idx, 2616c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham byte[] srcMac, byte[] dstMac, byte[] pktData, int period); 2617c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham 261818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public int 2619c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham startSendingOffloadedPacket(int slot, KeepalivePacketData keepAlivePacket, int period) { 2620c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham Log.d(TAG, "startSendingOffloadedPacket slot=" + slot + " period=" + period); 26213bd22cebc41ed0786d0e7bd2970a634a8bb0093ePrerepa Viswanadham 26223bd22cebc41ed0786d0e7bd2970a634a8bb0093ePrerepa Viswanadham String[] macAddrStr = getMacAddress().split(":"); 26233bd22cebc41ed0786d0e7bd2970a634a8bb0093ePrerepa Viswanadham byte[] srcMac = new byte[6]; 26243bd22cebc41ed0786d0e7bd2970a634a8bb0093ePrerepa Viswanadham for(int i = 0; i < 6; i++) { 26253bd22cebc41ed0786d0e7bd2970a634a8bb0093ePrerepa Viswanadham Integer hexVal = Integer.parseInt(macAddrStr[i], 16); 26263bd22cebc41ed0786d0e7bd2970a634a8bb0093ePrerepa Viswanadham srcMac[i] = hexVal.byteValue(); 26273bd22cebc41ed0786d0e7bd2970a634a8bb0093ePrerepa Viswanadham } 2628c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham synchronized (mLock) { 2629c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham if (isHalStarted()) { 2630c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham return startSendingOffloadedPacketNative(sWlan0Index, slot, srcMac, 263118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills keepAlivePacket.dstMac, keepAlivePacket.data, period); 2632c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham } else { 2633c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham return -1; 2634c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham } 2635c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham } 2636c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham } 2637c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham 2638c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham private native static int stopSendingOffloadedPacketNative(int iface, int idx); 2639c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham 264018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public int 2641c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham stopSendingOffloadedPacket(int slot) { 2642c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham Log.d(TAG, "stopSendingOffloadedPacket " + slot); 2643c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham synchronized (mLock) { 2644c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham if (isHalStarted()) { 2645c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham return stopSendingOffloadedPacketNative(sWlan0Index, slot); 2646c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham } else { 2647c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham return -1; 2648c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham } 2649c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham } 2650c55e88163b223db0ca6a99ed6ffe91845c30a576Prerepa Viswanadham } 2651aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham 2652aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham public static interface WifiRssiEventHandler { 2653aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham void onRssiThresholdBreached(byte curRssi); 2654aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } 2655aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham 2656aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham private static WifiRssiEventHandler sWifiRssiEventHandler; 2657aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham 265818786eca942042388748b0d98979f21c9dff4a89Mitchell Wills // Callback from native 265918786eca942042388748b0d98979f21c9dff4a89Mitchell Wills private static void onRssiThresholdBreached(int id, byte curRssi) { 266018786eca942042388748b0d98979f21c9dff4a89Mitchell Wills WifiRssiEventHandler handler = sWifiRssiEventHandler; 266118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills if (handler != null) { 266218786eca942042388748b0d98979f21c9dff4a89Mitchell Wills handler.onRssiThresholdBreached(curRssi); 266318786eca942042388748b0d98979f21c9dff4a89Mitchell Wills } 2664aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } 2665aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham 2666aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham private native static int startRssiMonitoringNative(int iface, int id, 2667aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham byte maxRssi, byte minRssi); 2668aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham 2669aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham private static int sRssiMonitorCmdId = 0; 2670aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham 267118786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public int startRssiMonitoring(byte maxRssi, byte minRssi, 2672aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham WifiRssiEventHandler rssiEventHandler) { 2673aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham Log.d(TAG, "startRssiMonitoring: maxRssi=" + maxRssi + " minRssi=" + minRssi); 2674aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham synchronized (mLock) { 267518786eca942042388748b0d98979f21c9dff4a89Mitchell Wills sWifiRssiEventHandler = rssiEventHandler; 2676aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham if (isHalStarted()) { 2677ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills if (sRssiMonitorCmdId != 0) { 2678ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills stopRssiMonitoring(); 2679ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills } 2680ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills 2681aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham sRssiMonitorCmdId = getNewCmdIdLocked(); 2682aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham Log.d(TAG, "sRssiMonitorCmdId = " + sRssiMonitorCmdId); 2683ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills int ret = startRssiMonitoringNative(sWlan0Index, sRssiMonitorCmdId, 2684ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills maxRssi, minRssi); 2685ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills if (ret != 0) { // if not success 2686ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills sRssiMonitorCmdId = 0; 2687ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills } 2688ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills return ret; 2689aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } else { 2690aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham return -1; 2691aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } 2692aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } 2693aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } 2694aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham 2695aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham private native static int stopRssiMonitoringNative(int iface, int idx); 2696aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham 269718786eca942042388748b0d98979f21c9dff4a89Mitchell Wills public int stopRssiMonitoring() { 2698aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham Log.d(TAG, "stopRssiMonitoring, cmdId " + sRssiMonitorCmdId); 2699aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham synchronized (mLock) { 2700aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham if (isHalStarted()) { 2701ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills int ret = 0; 2702ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills if (sRssiMonitorCmdId != 0) { 2703ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills ret = stopRssiMonitoringNative(sWlan0Index, sRssiMonitorCmdId); 2704ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills } 2705ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills sRssiMonitorCmdId = 0; 2706ed34692d4c4e202748d41f90db397f1cc3dc8320Mitchell Wills return ret; 2707aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } else { 2708aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham return -1; 2709aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } 2710aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } 2711aed5cb65d8eefb2eee56a29e33ac3cd8b03312e7Prerepa Viswanadham } 2712155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 2713