WifiNative.java revision 476bee2fef10d060c25c35858b1f7f60803d9f49
1155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/*
2155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Copyright (C) 2008 The Android Open Source Project
3155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande *
4155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Licensed under the Apache License, Version 2.0 (the "License");
5155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * you may not use this file except in compliance with the License.
6155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * You may obtain a copy of the License at
7155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande *
8155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande *      http://www.apache.org/licenses/LICENSE-2.0
9155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande *
10155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Unless required by applicable law or agreed to in writing, software
11155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * distributed under the License is distributed on an "AS IS" BASIS,
12155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * See the License for the specific language governing permissions and
14155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * limitations under the License.
15155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */
16155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
17155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandepackage com.android.server.wifi;
18155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
19155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.BatchedScanSettings;
20e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndeimport android.net.wifi.ScanResult;
21aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalleimport android.net.wifi.WifiLinkLayerStats;
22e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndeimport android.net.wifi.WifiScanner;
23155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.WpsInfo;
24155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.WifiP2pConfig;
25155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.WifiP2pGroup;
26f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalleimport android.os.SystemClock;
27155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.text.TextUtils;
28155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.wifi.p2p.nsd.WifiP2pServiceInfo;
29155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.LocalLog;
30155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.Log;
31155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
32155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.ArrayList;
33155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.List;
34155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.Locale;
35155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
36155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/**
37155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Native calls for bring up/shut down of the supplicant daemon and for
38155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * sending requests to the supplicant daemon
39155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande *
40155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * waitForEvent() is called on the monitor thread for events. All other methods
41155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * must be serialized from the framework.
42155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande *
43155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@hide}
44155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */
45155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandepublic class WifiNative {
46155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
47ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle    private static boolean DBG = false;
48155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private final String mTAG;
49155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private static final int DEFAULT_GROUP_OWNER_INTENT     = 6;
50155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
51155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED     = 0;
52155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED    = 1;
53155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    static final int BLUETOOTH_COEXISTENCE_MODE_SENSE       = 2;
54155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
55155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    static final int SCAN_WITHOUT_CONNECTION_SETUP          = 1;
56155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    static final int SCAN_WITH_CONNECTION_SETUP             = 2;
57155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
58155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    // Hold this lock before calling supplicant - it is required to
59155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    // mutually exclude access from Wifi and P2p state machines
60155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    static final Object mLock = new Object();
61155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
62155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public final String mInterfaceName;
63155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public final String mInterfacePrefix;
64155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
65155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private boolean mSuspendOptEnabled = false;
66155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
67155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /* Register native functions */
68155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
69155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    static {
70155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        /* Native functions are defined in libwifi-service.so */
71155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        System.loadLibrary("wifi-service");
72155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        registerNatives();
73155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
74155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
75155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private static native int registerNatives();
76155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
77155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public native static boolean loadDriver();
78155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
79155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public native static boolean isDriverLoaded();
80155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
81155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public native static boolean unloadDriver();
82155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
83155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public native static boolean startSupplicant(boolean p2pSupported);
84155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
85155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /* Sends a kill signal to supplicant. To be used when we have lost connection
86155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande       or when the supplicant is hung */
87155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public native static boolean killSupplicant(boolean p2pSupported);
88155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
89155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private native boolean connectToSupplicantNative();
90155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
91155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private native void closeSupplicantConnectionNative();
92155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
93155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
94155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Wait for the supplicant to send an event, returning the event string.
95155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * @return the event string sent by the supplicant.
96155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
97155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private native String waitForEventNative();
98155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
99155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private native boolean doBooleanCommandNative(String command);
100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private native int doIntCommandNative(String command);
102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private native String doStringCommandNative(String command);
104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public WifiNative(String interfaceName) {
106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        mInterfaceName = interfaceName;
107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        mTAG = "WifiNative-" + interfaceName;
108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (!interfaceName.equals("p2p0")) {
109155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            mInterfacePrefix = "IFNAME=" + interfaceName + " ";
110155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            // commands for p2p0 interface don't need prefix
112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            mInterfacePrefix = "";
113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
116ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle    void enableVerboseLogging(int verbose) {
117ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle        if (verbose > 0) {
118ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle            DBG = true;
119ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle        } else {
120ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle            DBG = false;
121ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle        }
122ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle    }
123ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle
124155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private static final LocalLog mLocalLog = new LocalLog(1024);
125155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
126155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    // hold mLock before accessing mCmdIdLock
127b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static int sCmdId;
128155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
129155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public LocalLog getLocalLog() {
130155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return mLocalLog;
131155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
133b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static int getNewCmdIdLocked() {
134b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        return sCmdId++;
135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
136155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
137155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private void localLog(String s) {
138155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (mLocalLog != null)
139155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            mLocalLog.log(mInterfaceName + ": " + s);
140155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
141155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
142155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean connectToSupplicant() {
143155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        // No synchronization necessary .. it is implemented in WifiMonitor
144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        localLog(mInterfacePrefix + "connectToSupplicant");
145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return connectToSupplicantNative();
146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public void closeSupplicantConnection() {
149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        localLog(mInterfacePrefix + "closeSupplicantConnection");
150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        closeSupplicantConnectionNative();
151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String waitForEvent() {
154155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        // No synchronization necessary .. it is implemented in WifiMonitor
155155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return waitForEventNative();
156155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
157155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
158155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private boolean doBooleanCommand(String command) {
159155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (DBG) Log.d(mTAG, "doBoolean: " + command);
160155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
161155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            int cmdId = getNewCmdIdLocked();
162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            localLog(cmdId + "->" + mInterfacePrefix + command);
163155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            boolean result = doBooleanCommandNative(mInterfacePrefix + command);
164155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            localLog(cmdId + "<-" + result);
1650888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle            if (DBG) Log.d(mTAG, command + ": returned " + result);
166155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return result;
167155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
168155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
169155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
170155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private int doIntCommand(String command) {
171155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (DBG) Log.d(mTAG, "doInt: " + command);
172155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
173155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            int cmdId = getNewCmdIdLocked();
174155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            localLog(cmdId + "->" + mInterfacePrefix + command);
175155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            int result = doIntCommandNative(mInterfacePrefix + command);
176155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            localLog(cmdId + "<-" + result);
177155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (DBG) Log.d(mTAG, "   returned " + result);
178155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return result;
179155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
180155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
181155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
182155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private String doStringCommand(String command) {
1830888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle        if (DBG) {
1840888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle            //GET_NETWORK commands flood the logs
1850888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle            if (!command.startsWith("GET_NETWORK")) {
1860888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle                Log.d(mTAG, "doString: [" + command + "]");
1870888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle            }
1880888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle        }
189155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
190155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            int cmdId = getNewCmdIdLocked();
191155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            localLog(cmdId + "->" + mInterfacePrefix + command);
192155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            String result = doStringCommandNative(mInterfacePrefix + command);
193155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            localLog(cmdId + "<-" + result);
194155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (DBG) Log.d(mTAG, "   returned " + result);
195155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return result;
196155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
197155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
198155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
199155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private String doStringCommandWithoutLogging(String command) {
2000888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle        if (DBG) {
2010888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle            //GET_NETWORK commands flood the logs
2020888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle            if (!command.startsWith("GET_NETWORK")) {
2030888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle                Log.d(mTAG, "doString: [" + command + "]");
2040888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle            }
2050888ce6f90bdaeee799dd8361ea4781e23a33b87vandwalle        }        synchronized (mLock) {
206155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doStringCommandNative(mInterfacePrefix + command);
207155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
208155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
209155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
210155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean ping() {
211155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String pong = doStringCommand("PING");
212155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return (pong != null && pong.equals("PONG"));
213155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
214155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
215a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng    public String getFreqCapability() {
216a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng        return doStringCommand("GET_CAPABILITY freq");
217a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng    }
218a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng
219a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng    public boolean scan(int type, String freqList) {
220155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (type == SCAN_WITHOUT_CONNECTION_SETUP) {
221a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng            if (freqList == null) return doBooleanCommand("SCAN TYPE=ONLY");
222a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng            else return doBooleanCommand("SCAN TYPE=ONLY freq=" + freqList);
223155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else if (type == SCAN_WITH_CONNECTION_SETUP) {
224a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng            if (freqList == null) return doBooleanCommand("SCAN");
225a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng            else return doBooleanCommand("SCAN freq=" + freqList);
226155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
227155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            throw new IllegalArgumentException("Invalid scan type");
228155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
229155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
230155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
231155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /* Does a graceful shutdown of supplicant. Is a common stop function for both p2p and sta.
232155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
233155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Note that underneath we use a harsh-sounding "terminate" supplicant command
234155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * for a graceful stop and a mild-sounding "stop" interface
235155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * to kill the process
236155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
237155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean stopSupplicant() {
238155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("TERMINATE");
239155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
240155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
241155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String listNetworks() {
242155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommand("LIST_NETWORKS");
243155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
244155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
245155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public int addNetwork() {
246155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doIntCommand("ADD_NETWORK");
247155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
248155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
249155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setNetworkVariable(int netId, String name, String value) {
250155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(name) || TextUtils.isEmpty(value)) return false;
251155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET_NETWORK " + netId + " " + name + " " + value);
252155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
253155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
254155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String getNetworkVariable(int netId, String name) {
255155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(name)) return null;
256155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
257155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        // GET_NETWORK will likely flood the logs ...
258155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommandWithoutLogging("GET_NETWORK " + netId + " " + name);
259155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
260155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
261155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean removeNetwork(int netId) {
262155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("REMOVE_NETWORK " + netId);
263155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
264155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
265f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle
266f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle    private void logDbg(String debug) {
267f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        long now = SystemClock.elapsedRealtimeNanos();
268f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        String ts = String.format("[%,d us] ", now/1000);
269ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle        Log.e("WifiNative: ", ts+debug+ " stack:"
270ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle                + Thread.currentThread().getStackTrace()[2].getMethodName() +" - "
271ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle                + Thread.currentThread().getStackTrace()[3].getMethodName() +" - "
272ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle                + Thread.currentThread().getStackTrace()[4].getMethodName() +" - "
273ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle                + Thread.currentThread().getStackTrace()[5].getMethodName()+" - "
274ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle                + Thread.currentThread().getStackTrace()[6].getMethodName());
275f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle
276f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle    }
277155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean enableNetwork(int netId, boolean disableOthers) {
278ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle        if (DBG) logDbg("enableNetwork nid=" + Integer.toString(netId)
279ecd2b88214b5d214fd1f63a9560caff9058912ddvandwalle                + " disableOthers=" + disableOthers);
280155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (disableOthers) {
281155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("SELECT_NETWORK " + netId);
282155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
283155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("ENABLE_NETWORK " + netId);
284155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
285155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
286155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
287155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean disableNetwork(int netId) {
288f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        if (DBG) logDbg("disableNetwork nid=" + Integer.toString(netId));
289155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DISABLE_NETWORK " + netId);
290155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
291155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
292155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean reconnect() {
293f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        if (DBG) logDbg("RECONNECT ");
294155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("RECONNECT");
295155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
296155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
297155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean reassociate() {
298f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        if (DBG) logDbg("REASSOCIATE ");
299155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("REASSOCIATE");
300155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
301155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
302155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean disconnect() {
30321bc54cb37a0085b1c909cb4d55ebb12a2facefbvandwalle        if (DBG) logDbg("DISCONNECT ");
304155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DISCONNECT");
305155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
306155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
307155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String status() {
308155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommand("STATUS");
309155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
310155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
311155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String getMacAddress() {
312155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        //Macaddr = XX.XX.XX.XX.XX.XX
313155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String ret = doStringCommand("DRIVER MACADDR");
314155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (!TextUtils.isEmpty(ret)) {
315155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            String[] tokens = ret.split(" = ");
316155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (tokens.length == 2) return tokens[1];
317155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
318155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return null;
319155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
320155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
321155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
322155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Format of results:
323155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * =================
324155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * id=1
325155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * bssid=68:7f:74:d7:1b:6e
326155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * freq=2412
327155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * level=-43
328155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * tsf=1344621975160944
329155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * age=2623
330155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * flags=[WPA2-PSK-CCMP][WPS][ESS]
331155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * ssid=zubyb
332155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * ====
333155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
334155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * RANGE=ALL gets all scan results
335155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * RANGE=ID- gets results from ID
336155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * MASK=<N> see wpa_supplicant/src/common/wpa_ctrl.h for details
337155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
338155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String scanResults(int sid) {
339155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommandWithoutLogging("BSS RANGE=" + sid + "- MASK=0x21987");
340155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
341155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
342155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
343446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * Format of result:
344446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * id=1016
345446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * bssid=00:03:7f:40:84:10
346446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * freq=2462
347446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * beacon_int=200
348446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * capabilities=0x0431
349446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * qual=0
350446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * noise=0
351446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * level=-46
352446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * tsf=0000002669008476
353446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * age=5
354446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * ie=00105143412d485332302d52322d54455354010882848b960c12182403010b0706555...
355446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * flags=[WPA2-EAP-CCMP][ESS][P2P][HS20]
356446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * ssid=QCA-HS20-R2-TEST
357446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * p2p_device_name=
358446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * p2p_config_methods=0x0
359446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * anqp_venue_name=02083d656e6757692d466920416c6c69616e63650a3239383920436f...
360446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * anqp_network_auth_type=010000
361446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * anqp_roaming_consortium=03506f9a05001bc504bd
362446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * anqp_ip_addr_type_availability=0c
363446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * anqp_nai_realm=0200300000246d61696c2e6578616d706c652e636f6d3b636973636f2...
364446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * anqp_3gpp=000600040132f465
365446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * anqp_domain_name=0b65786d61706c652e636f6d
366446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * hs20_operator_friendly_name=11656e6757692d466920416c6c69616e63650e636869...
367446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * hs20_wan_metrics=01c40900008001000000000a00
368446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * hs20_connection_capability=0100000006140001061600000650000106bb010106bb0...
369446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     * hs20_osu_providers_list=0b5143412d4f53552d425353010901310015656e6757692d...
370446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng     */
371446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng    public String scanResult(String bssid) {
372446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng        return doStringCommand("BSS " + bssid);
373446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng    }
374446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng
375446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng    /**
376155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Format of command
377155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * DRIVER WLS_BATCHING SET SCANFREQ=x MSCAN=r BESTN=y CHANNEL=<z, w, t> RTT=s
378155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * where x is an ascii representation of an integer number of seconds between scans
379155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *       r is an ascii representation of an integer number of scans per batch
380155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *       y is an ascii representation of an integer number of the max AP to remember per scan
381155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *       z, w, t represent a 1..n size list of channel numbers and/or 'A', 'B' values
382155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *           indicating entire ranges of channels
383155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *       s is an ascii representation of an integer number of highest-strength AP
384155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *           for which we'd like approximate distance reported
385155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
386155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * The return value is an ascii integer representing a guess of the number of scans
387155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * the firmware can remember before it runs out of buffer space or -1 on error
388155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
389155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String setBatchedScanSettings(BatchedScanSettings settings) {
390155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (settings == null) {
391155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doStringCommand("DRIVER WLS_BATCHING STOP");
392155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
393155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String cmd = "DRIVER WLS_BATCHING SET SCANFREQ=" + settings.scanIntervalSec;
394155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        cmd += " MSCAN=" + settings.maxScansPerBatch;
395155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (settings.maxApPerScan != BatchedScanSettings.UNSPECIFIED) {
396155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            cmd += " BESTN=" + settings.maxApPerScan;
397155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
398155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (settings.channelSet != null && !settings.channelSet.isEmpty()) {
399155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            cmd += " CHANNEL=<";
400155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            int i = 0;
401155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            for (String channel : settings.channelSet) {
402155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                cmd += (i > 0 ? "," : "") + channel;
403155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                ++i;
404155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
405155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            cmd += ">";
406155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
407155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (settings.maxApForDistance != BatchedScanSettings.UNSPECIFIED) {
408155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            cmd += " RTT=" + settings.maxApForDistance;
409155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
410155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommand(cmd);
411155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
412155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
413155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String getBatchedScanResults() {
414155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommand("DRIVER WLS_BATCHING GET");
415155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
416155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
417155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean startDriver() {
418155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER START");
419155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
420155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
421155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean stopDriver() {
422155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER STOP");
423155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
424155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
425155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
426155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
427155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Start filtering out Multicast V4 packets
428155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * @return {@code true} if the operation succeeded, {@code false} otherwise
429155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
430155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Multicast filtering rules work as follows:
431155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
432155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * The driver can filter multicast (v4 and/or v6) and broadcast packets when in
433155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * a power optimized mode (typically when screen goes off).
434155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
435155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * In order to prevent the driver from filtering the multicast/broadcast packets, we have to
436155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * add a DRIVER RXFILTER-ADD rule followed by DRIVER RXFILTER-START to make the rule effective
437155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
438155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * DRIVER RXFILTER-ADD Num
439155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *   where Num = 0 - Unicast, 1 - Broadcast, 2 - Mutil4 or 3 - Multi6
440155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
441155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * and DRIVER RXFILTER-START
442155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * In order to stop the usage of these rules, we do
443155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
444155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * DRIVER RXFILTER-STOP
445155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * DRIVER RXFILTER-REMOVE Num
446155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *   where Num is as described for RXFILTER-ADD
447155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
448155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * The  SETSUSPENDOPT driver command overrides the filtering rules
449155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
450155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean startFilteringMulticastV4Packets() {
451155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER RXFILTER-STOP")
452155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            && doBooleanCommand("DRIVER RXFILTER-REMOVE 2")
453155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            && doBooleanCommand("DRIVER RXFILTER-START");
454155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
455155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
456155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
457155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Stop filtering out Multicast V4 packets.
458155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * @return {@code true} if the operation succeeded, {@code false} otherwise
459155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
460155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean stopFilteringMulticastV4Packets() {
461155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER RXFILTER-STOP")
462155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            && doBooleanCommand("DRIVER RXFILTER-ADD 2")
463155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            && doBooleanCommand("DRIVER RXFILTER-START");
464155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
465155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
466155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
467155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Start filtering out Multicast V6 packets
468155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * @return {@code true} if the operation succeeded, {@code false} otherwise
469155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
470155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean startFilteringMulticastV6Packets() {
471155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER RXFILTER-STOP")
472155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            && doBooleanCommand("DRIVER RXFILTER-REMOVE 3")
473155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            && doBooleanCommand("DRIVER RXFILTER-START");
474155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
475155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
476155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
477155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Stop filtering out Multicast V6 packets.
478155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * @return {@code true} if the operation succeeded, {@code false} otherwise
479155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
480155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean stopFilteringMulticastV6Packets() {
481155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER RXFILTER-STOP")
482155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            && doBooleanCommand("DRIVER RXFILTER-ADD 3")
483155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            && doBooleanCommand("DRIVER RXFILTER-START");
484155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
485155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
486155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public int getBand() {
487155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande       String ret = doStringCommand("DRIVER GETBAND");
488155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (!TextUtils.isEmpty(ret)) {
489155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            //reply is "BAND X" where X is the band
490155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            String[] tokens = ret.split(" ");
491155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            try {
492155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                if (tokens.length == 2) return Integer.parseInt(tokens[1]);
493155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            } catch (NumberFormatException e) {
494155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return -1;
495155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
496155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
497155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return -1;
498155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
499155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
500155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setBand(int band) {
501155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER SETBAND " + band);
502155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
503155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
5047ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde    /**
5057ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde      * Sets the bluetooth coexistence mode.
5067ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde      *
5077ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde      * @param mode One of {@link #BLUETOOTH_COEXISTENCE_MODE_DISABLED},
5087ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde      *            {@link #BLUETOOTH_COEXISTENCE_MODE_ENABLED}, or
5097ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde      *            {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}.
5107ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde      * @return Whether the mode was successfully set.
5117ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde      */
512155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setBluetoothCoexistenceMode(int mode) {
513155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER BTCOEXMODE " + mode);
514155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
515155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
516155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
517155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * Enable or disable Bluetooth coexistence scan mode. When this mode is on,
518155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * some of the low-level scan parameters used by the driver are changed to
519155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * reduce interference with A2DP streaming.
520155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *
521155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * @param isSet whether to enable or disable this mode
522155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * @return {@code true} if the command succeeded, {@code false} otherwise.
523155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
524155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) {
525155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (setCoexScanMode) {
526155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("DRIVER BTCOEXSCAN-START");
527155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
528155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("DRIVER BTCOEXSCAN-STOP");
529155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
530155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
531155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
5320a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde    public void enableSaveConfig() {
5330a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde        doBooleanCommand("SET update_config 1");
5340a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde    }
5350a696d168d7ad98ab5084d2a16e3d02c545a85aaVinit Deshapnde
536155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean saveConfig() {
537155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SAVE_CONFIG");
538155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
539155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
540155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean addToBlacklist(String bssid) {
541155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(bssid)) return false;
542155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("BLACKLIST " + bssid);
543155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
544155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
545155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean clearBlacklist() {
546155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("BLACKLIST clear");
547155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
548155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
549155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setSuspendOptimizations(boolean enabled) {
550f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle       // if (mSuspendOptEnabled == enabled) return true;
551155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        mSuspendOptEnabled = enabled;
552f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle
553f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        Log.e("native", "do suspend " + enabled);
554155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (enabled) {
555155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("DRIVER SETSUSPENDMODE 1");
556155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
557155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("DRIVER SETSUSPENDMODE 0");
558155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
559155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
560155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
561155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setCountryCode(String countryCode) {
562155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("DRIVER COUNTRY " + countryCode.toUpperCase(Locale.ROOT));
563155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
564155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
565155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public void enableBackgroundScan(boolean enable) {
566155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (enable) {
567155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            doBooleanCommand("SET pno 1");
568155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
569155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            doBooleanCommand("SET pno 0");
570155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
571155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
572155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
573f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle    public void enableAutoConnect(boolean enable) {
574f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        if (enable) {
575f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle            doBooleanCommand("STA_AUTOCONNECT 1");
576f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        } else {
577f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle            doBooleanCommand("STA_AUTOCONNECT 0");
578f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle        }
579f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle    }
580f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle
581155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public void setScanInterval(int scanInterval) {
582155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        doBooleanCommand("SCAN_INTERVAL " + scanInterval);
583155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
584155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
585155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public void startTdls(String macAddr, boolean enable) {
586155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (enable) {
587155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            doBooleanCommand("TDLS_DISCOVER " + macAddr);
588155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            doBooleanCommand("TDLS_SETUP " + macAddr);
589155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
590155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            doBooleanCommand("TDLS_TEARDOWN " + macAddr);
591155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
592155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
593155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
594155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /** Example output:
595155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * RSSI=-65
596155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * LINKSPEED=48
597155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * NOISE=9999
598155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * FREQUENCY=0
599155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
600155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String signalPoll() {
601155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommandWithoutLogging("SIGNAL_POLL");
602155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
603155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
604155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /** Example outout:
605155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * TXGOOD=396
606155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * TXBAD=1
607155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
608155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String pktcntPoll() {
609155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommand("PKTCNT_POLL");
610155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
611155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
612155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public void bssFlush() {
613155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        doBooleanCommand("BSS_FLUSH 0");
614155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
615155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
616155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean startWpsPbc(String bssid) {
617155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(bssid)) {
618155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("WPS_PBC");
619155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
620155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("WPS_PBC " + bssid);
621155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
622155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
623155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
624155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean startWpsPbc(String iface, String bssid) {
625155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
626155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (TextUtils.isEmpty(bssid)) {
627155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC");
628155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            } else {
629155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid);
630155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
631155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
632155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
633155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
634155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean startWpsPinKeypad(String pin) {
635155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(pin)) return false;
636155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("WPS_PIN any " + pin);
637155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
638155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
639155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean startWpsPinKeypad(String iface, String pin) {
640155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(pin)) return false;
641155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
642155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin);
643155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
644155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
645155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
646155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
647155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String startWpsPinDisplay(String bssid) {
648155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(bssid)) {
649155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doStringCommand("WPS_PIN any");
650155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
651155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doStringCommand("WPS_PIN " + bssid);
652155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
653155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
654155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
655155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String startWpsPinDisplay(String iface, String bssid) {
656155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
657155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (TextUtils.isEmpty(bssid)) {
658155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any");
659155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            } else {
660155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid);
661155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
662155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
663155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
664155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
665155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /* Configures an access point connection */
666155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean startWpsRegistrar(String bssid, String pin) {
667155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(bssid) || TextUtils.isEmpty(pin)) return false;
668155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("WPS_REG " + bssid + " " + pin);
669155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
670155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
671155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean cancelWps() {
672155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("WPS_CANCEL");
673155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
674155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
675155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setPersistentReconnect(boolean enabled) {
676155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        int value = (enabled == true) ? 1 : 0;
677155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET persistent_reconnect " + value);
678155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
679155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
680155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setDeviceName(String name) {
681155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET device_name " + name);
682155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
683155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
684155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setDeviceType(String type) {
685155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET device_type " + type);
686155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
687155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
688155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setConfigMethods(String cfg) {
689155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET config_methods " + cfg);
690155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
691155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
692155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setManufacturer(String value) {
693155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET manufacturer " + value);
694155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
695155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
696155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setModelName(String value) {
697155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET model_name " + value);
698155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
699155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
700155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setModelNumber(String value) {
701155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET model_number " + value);
702155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
703155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
704155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setSerialNumber(String value) {
705155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET serial_number " + value);
706155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
707155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
708155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setP2pSsidPostfix(String postfix) {
709155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET p2p_ssid_postfix " + postfix);
710155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
711155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
712155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setP2pGroupIdle(String iface, int time) {
713155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
714155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time);
715155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
716155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
717155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
718155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public void setPowerSave(boolean enabled) {
719155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (enabled) {
720155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            doBooleanCommand("SET ps 1");
721155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
722155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            doBooleanCommand("SET ps 0");
723155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
724155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
725155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
726155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setP2pPowerSave(String iface, boolean enabled) {
727155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
728155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (enabled) {
729155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1");
730155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            } else {
731155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0");
732155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
733155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
734155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
735155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
736155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setWfdEnable(boolean enable) {
737155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("SET wifi_display " + (enable ? "1" : "0"));
738155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
739155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
740155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setWfdDeviceInfo(String hex) {
741155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("WFD_SUBELEM_SET 0 " + hex);
742155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
743155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
744155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /**
745155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * "sta" prioritizes STA connection over P2P and "p2p" prioritizes
746155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     * P2P connection over STA
747155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
748155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean setConcurrencyPriority(String s) {
749155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_SET conc_pref " + s);
750155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
751155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
752155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pFind() {
753155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_FIND");
754155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
755155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
756155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pFind(int timeout) {
757155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (timeout <= 0) {
758155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return p2pFind();
759155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
760155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_FIND " + timeout);
761155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
762155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
763155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pStopFind() {
764155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande       return doBooleanCommand("P2P_STOP_FIND");
765155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
766155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
767155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pListen() {
768155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_LISTEN");
769155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
770155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
771155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pListen(int timeout) {
772155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (timeout <= 0) {
773155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return p2pListen();
774155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
775155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_LISTEN " + timeout);
776155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
777155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
778155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pExtListen(boolean enable, int period, int interval) {
779155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (enable && interval < period) {
780155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return false;
781155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
782155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_EXT_LISTEN"
783155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                    + (enable ? (" " + period + " " + interval) : ""));
784155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
785155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
786155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pSetChannel(int lc, int oc) {
787155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (DBG) Log.d(mTAG, "p2pSetChannel: lc="+lc+", oc="+oc);
788155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
789155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (lc >=1 && lc <= 11) {
790155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (!doBooleanCommand("P2P_SET listen_channel " + lc)) {
791155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return false;
792155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
793155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else if (lc != 0) {
794155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return false;
795155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
796155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
797155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (oc >= 1 && oc <= 165 ) {
798155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            int freq = (oc <= 14 ? 2407 : 5000) + oc * 5;
799155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("P2P_SET disallow_freq 1000-"
800155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                    + (freq - 5) + "," + (freq + 5) + "-6000");
801155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else if (oc == 0) {
802155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            /* oc==0 disables "P2P_SET disallow_freq" (enables all freqs) */
803155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("P2P_SET disallow_freq \"\"");
804155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
805155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
806155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return false;
807155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
808155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
809155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pFlush() {
810155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_FLUSH");
811155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
812155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
813155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /* p2p_connect <peer device address> <pbc|pin|PIN#> [label|display|keypad]
814155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        [persistent] [join|auth] [go_intent=<0..15>] [freq=<in MHz>] */
815155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) {
816155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (config == null) return null;
817155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        List<String> args = new ArrayList<String>();
818155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        WpsInfo wps = config.wps;
819155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        args.add(config.deviceAddress);
820155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
821155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        switch (wps.setup) {
822155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            case WpsInfo.PBC:
823155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                args.add("pbc");
824155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                break;
825155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            case WpsInfo.DISPLAY:
826155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                if (TextUtils.isEmpty(wps.pin)) {
827155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                    args.add("pin");
828155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                } else {
829155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                    args.add(wps.pin);
830155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                }
831155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                args.add("display");
832155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                break;
833155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            case WpsInfo.KEYPAD:
834155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                args.add(wps.pin);
835155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                args.add("keypad");
836155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                break;
837155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            case WpsInfo.LABEL:
838155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                args.add(wps.pin);
839155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                args.add("label");
840155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            default:
841155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                break;
842155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
843155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
844155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (config.netId == WifiP2pGroup.PERSISTENT_NET_ID) {
845155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            args.add("persistent");
846155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
847155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
848155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (joinExistingGroup) {
849155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            args.add("join");
850155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
851155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            //TODO: This can be adapted based on device plugged in state and
852155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            //device battery state
853155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            int groupOwnerIntent = config.groupOwnerIntent;
854155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (groupOwnerIntent < 0 || groupOwnerIntent > 15) {
855155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT;
856155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
857155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            args.add("go_intent=" + groupOwnerIntent);
858155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
859155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
860155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String command = "P2P_CONNECT ";
861155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        for (String s : args) command += s + " ";
862155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
863155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommand(command);
864155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
865155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
866155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pCancelConnect() {
867155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_CANCEL");
868155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
869155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
870155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pProvisionDiscovery(WifiP2pConfig config) {
871155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (config == null) return false;
872155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
873155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        switch (config.wps.setup) {
874155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            case WpsInfo.PBC:
875155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " pbc");
876155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            case WpsInfo.DISPLAY:
877155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                //We are doing display, so provision discovery is keypad
878155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " keypad");
879155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            case WpsInfo.KEYPAD:
880155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                //We are doing keypad, so provision discovery is display
881155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " display");
882155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            default:
883155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                break;
884155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
885155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return false;
886155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
887155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
888155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pGroupAdd(boolean persistent) {
889155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (persistent) {
890155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("P2P_GROUP_ADD persistent");
891155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
892155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_GROUP_ADD");
893155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
894155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
895155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pGroupAdd(int netId) {
896155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_GROUP_ADD persistent=" + netId);
897155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
898155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
899155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pGroupRemove(String iface) {
900155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(iface)) return false;
901155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        synchronized (mLock) {
902155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface);
903155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
904155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
905155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
906155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pReject(String deviceAddress) {
907155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_REJECT " + deviceAddress);
908155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
909155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
910155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /* Invite a peer to a group */
911155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) {
912155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(deviceAddress)) return false;
913155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
914155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (group == null) {
915155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("P2P_INVITE peer=" + deviceAddress);
916155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        } else {
917155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            return doBooleanCommand("P2P_INVITE group=" + group.getInterface()
918155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                    + " peer=" + deviceAddress + " go_dev_addr=" + group.getOwner().deviceAddress);
919155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
920155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
921155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
922155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /* Reinvoke a persistent connection */
923155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pReinvoke(int netId, String deviceAddress) {
924155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(deviceAddress) || netId < 0) return false;
925155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
926155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_INVITE persistent=" + netId + " peer=" + deviceAddress);
927155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
928155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
929155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String p2pGetSsid(String deviceAddress) {
930155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return p2pGetParam(deviceAddress, "oper_ssid");
931155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
932155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
933155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String p2pGetDeviceAddress() {
934155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String status = status();
935155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (status == null) return "";
936155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
937155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String[] tokens = status.split("\n");
938155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        for (String token : tokens) {
939155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (token.startsWith("p2p_device_address=")) {
940155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                String[] nameValue = token.split("=");
941155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                if (nameValue.length != 2) break;
942155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return nameValue[1];
943155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
944155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
945155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return "";
946155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
947155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
948155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public int getGroupCapability(String deviceAddress) {
949155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        int gc = 0;
950155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(deviceAddress)) return gc;
951155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String peerInfo = p2pPeer(deviceAddress);
952155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (TextUtils.isEmpty(peerInfo)) return gc;
953155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
954155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String[] tokens = peerInfo.split("\n");
955155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        for (String token : tokens) {
956155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (token.startsWith("group_capab=")) {
957155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                String[] nameValue = token.split("=");
958155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                if (nameValue.length != 2) break;
959155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                try {
960155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                    return Integer.decode(nameValue[1]);
961155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                } catch(NumberFormatException e) {
962155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                    return gc;
963155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                }
964155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
965155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
966155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return gc;
967155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
968155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
969155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String p2pPeer(String deviceAddress) {
970155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommand("P2P_PEER " + deviceAddress);
971155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
972155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
973155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    private String p2pGetParam(String deviceAddress, String key) {
974155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (deviceAddress == null) return null;
975155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
976155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String peerInfo = p2pPeer(deviceAddress);
977155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        if (peerInfo == null) return null;
978155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String[] tokens= peerInfo.split("\n");
979155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
980155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        key += "=";
981155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        for (String token : tokens) {
982155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (token.startsWith(key)) {
983155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                String[] nameValue = token.split("=");
984155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                if (nameValue.length != 2) break;
985155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return nameValue[1];
986155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
987155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
988155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return null;
989155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
990155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
991155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) {
992155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        /*
993155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_ADD bonjour <query hexdump> <RDATA hexdump>
994155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_ADD upnp <version hex> <service>
995155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         *
996155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * e.g)
997155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * [Bonjour]
998155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * # IP Printing over TCP (PTR) (RDATA=MyPrinter._ipp._tcp.local.)
999155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027
1000155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * # IP Printing over TCP (TXT) (RDATA=txtvers=1,pdl=application/postscript)
1001155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001
1002155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         *  09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074
1003155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         *
1004155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * [UPnP]
1005155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012
1006155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice
1007155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp
1008155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * -org:device:InternetGatewayDevice:1
1009155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9322-123456789012::urn:schemas-upnp
1010155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * -org:service:ContentDirectory:2
1011155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         */
1012155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        for (String s : servInfo.getSupplicantQueryList()) {
1013155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            String command = "P2P_SERVICE_ADD";
1014155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            command += (" " + s);
1015155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (!doBooleanCommand(command)) {
1016155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return false;
1017155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
1018155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
1019155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return true;
1020155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
1021155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
1022155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) {
1023155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        /*
1024155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_DEL bonjour <query hexdump>
1025155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         * P2P_SERVICE_DEL upnp <version hex> <service>
1026155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande         */
1027155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        for (String s : servInfo.getSupplicantQueryList()) {
1028155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            String command = "P2P_SERVICE_DEL ";
1029155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
1030155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            String[] data = s.split(" ");
1031155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (data.length < 2) {
1032155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return false;
1033155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
1034155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if ("upnp".equals(data[0])) {
1035155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                command += s;
1036155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            } else if ("bonjour".equals(data[0])) {
1037155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                command += data[0];
1038155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                command += (" " + data[1]);
1039155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            } else {
1040155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return false;
1041155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
1042155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            if (!doBooleanCommand(command)) {
1043155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande                return false;
1044155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande            }
1045155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        }
1046155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return true;
1047155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
1048155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
1049155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pServiceFlush() {
1050155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_SERVICE_FLUSH");
1051155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
1052155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
1053155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public String p2pServDiscReq(String addr, String query) {
1054155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        String command = "P2P_SERV_DISC_REQ";
1055155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        command += (" " + addr);
1056155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        command += (" " + query);
1057155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
1058155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doStringCommand(command);
1059155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
1060155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
1061155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public boolean p2pServDiscCancelReq(String id) {
1062155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id);
1063155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
1064155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande
1065155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    /* Set the current mode of miracast operation.
1066155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *  0 = disabled
1067155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *  1 = operating as source
1068155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     *  2 = operating as sink
1069155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande     */
1070155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    public void setMiracastMode(int mode) {
1071155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        // Note: optional feature on the driver. It is ok for this to fail.
1072155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande        doBooleanCommand("DRIVER MIRACAST " + mode);
1073155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande    }
10743f7ef65ab71619040032aee96b5599849881d6fdAndres Morales
10753f7ef65ab71619040032aee96b5599849881d6fdAndres Morales    public String getNfcWpsConfigurationToken(int netId) {
10763f7ef65ab71619040032aee96b5599849881d6fdAndres Morales        return doStringCommand("WPS_NFC_CONFIG_TOKEN WPS " + netId);
10773f7ef65ab71619040032aee96b5599849881d6fdAndres Morales    }
10787ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde
1079446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng    public boolean fetchAnqp(String bssid, String subtypes) {
1080446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng        return doBooleanCommand("ANQP_GET " + bssid + " " + subtypes);
1081446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng    }
1082446db2d5457456743e4476029e14d7c3bb9f5bccYuhao Zheng
10837ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde
10847f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde    /* WIFI HAL support */
10857f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1086b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static final String TAG = "WifiNative-HAL";
1087aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle    private static long sWifiHalHandle = 0;  /* used by JNI to save wifi_handle */
1088aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle    private static long[] sWifiIfaceHandles = null;  /* used by JNI to save interface handles */
1089aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle    private static int sWlan0Index = -1;
1090aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle    private static int sP2p0Index = -1;
1091aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle
1092aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle    private static boolean sHalIsStarted = false;
10937f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1094b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native boolean startHalNative();
1095b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native void stopHalNative();
1096b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native void waitForHalEventNative();
10977f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1098b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static class MonitorThread extends Thread {
10997ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde        public void run() {
1100b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            Log.i(TAG, "Waiting for HAL events mWifiHalHandle=" + Long.toString(sWifiHalHandle));
11017ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde            waitForHalEventNative();
11027ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde        }
11037ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde    }
11047ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde
1105b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static boolean startHal() {
1106b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        Log.i(TAG, "startHal");
1107aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        synchronized (mLock) {
1108aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            if (sHalIsStarted)
1109aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                return true;
1110aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            if (startHalNative()) {
1111aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                new MonitorThread().start();
1112aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                sHalIsStarted = true;
1113aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                return true;
1114aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            } else {
1115b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                Log.i(TAG, "Could not start hal");
1116aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                sHalIsStarted = false;
1117aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                return false;
1118aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            }
11197ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde        }
11207ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde    }
11217ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde
1122b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static void stopHal() {
11237ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde        stopHalNative();
11247ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde    }
11257f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1126b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native int getInterfacesNative();
11277f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1128b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static int getInterfaces() {
1129aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        synchronized (mLock) {
1130aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            int num = getInterfacesNative();
1131aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            for (int i = 0; i < num; i++) {
1132aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                String name = getInterfaceNameNative(i);
1133b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                Log.i(TAG, "interface[" + i + "] = " + name);
1134aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                if (name.equals("wlan0")) {
1135aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                    sWlan0Index = i;
1136aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                } else if (name.equals("p2p0")) {
1137aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                    sP2p0Index = i;
1138aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                }
1139e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            }
1140aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            return num;
1141e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        }
11427f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde    }
11437f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1144b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native String getInterfaceNameNative(int index);
11457f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1146b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    public static void printInterfaceNames() {
1147aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        synchronized (mLock) {
1148aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            for (int i = 0; i < sWifiIfaceHandles.length; i++) {
1149aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                String name = getInterfaceNameNative(i);
1150b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                Log.i(TAG, "interface[" + i + "] = " + name);
1151aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            }
11527f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde        }
11537f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde    }
11547f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1155e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    public static class ScanCapabilities {
1156e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        public int  max_scan_cache_size;                 // in number of scan results??
1157e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        public int  max_scan_buckets;
1158e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        public int  max_ap_cache_per_scan;
1159e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        public int  max_rssi_sample_size;
1160e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        public int  max_scan_reporting_threshold;        // in number of scan results??
1161e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        public int  max_hotlist_aps;
1162e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        public int  max_significant_wifi_change_aps;
1163e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1164e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1165b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    public static boolean getScanCapabilities(ScanCapabilities capabilities) {
1166aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        return getScanCapabilitiesNative(sWlan0Index, capabilities);
1167e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1168e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1169b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native boolean getScanCapabilitiesNative(
1170b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            int iface, ScanCapabilities capabilities);
1171e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1172b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native boolean startScanNative(int iface, int id, ScanSettings settings);
1173b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native boolean stopScanNative(int iface, int id);
1174b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native ScanResult[] getScanResultsNative(int iface, boolean flush);
1175b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native WifiLinkLayerStats getWifiLinkLayerStatsNative(int iface);
11767f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1177e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    public static class ChannelSettings {
1178e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int frequency;
1179e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int dwell_time_ms;
1180e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        boolean passive;
11817f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde    }
11827f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1183e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    public static class BucketSettings {
1184e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int bucket;
1185e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int band;
1186e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int period_ms;
1187e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int report_events;
1188e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int num_channels;
1189e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        ChannelSettings channels[] = new ChannelSettings[8];
1190e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
11917f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1192e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    public static class ScanSettings {
1193e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int base_period_ms;
1194e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int max_ap_per_scan;
1195e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int report_threshold;
1196e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        int num_buckets;
1197e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        BucketSettings buckets[] = new BucketSettings[8];
1198e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
11997f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1200b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    public static interface ScanEventHandler {
1201e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        void onScanResultsAvailable();
1202476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande        void onFullScanResult(ScanResult fullScanResult);
1203b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        void onScanPaused();
1204b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        void onScanRestarted();
1205e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1206e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1207b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized static void onScanResultsAvailable(int id) {
1208b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        sScanEventHandler.onScanResultsAvailable();
1209e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1210e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1211b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized static void onFullScanResult(int id, ScanResult result, byte bytes[]) {
1212b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        Log.i(TAG, "Got a full scan results event, ssid = " + result.SSID + ", " +
1213f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde                "num = " + bytes.length);
1214f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde
1215f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde        int num = 0;
1216f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde        for (int i = 0; i < bytes.length; ) {
1217f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            num++;
1218f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            int type  = (int) bytes[i] & 0xFF;
1219f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            int len = (int) bytes[i + 1] & 0xFF;
1220f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            if (len < 0) {
1221b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                Log.e(TAG, "bad length; returning");
1222f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde                return;
1223f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            }
1224f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            i += len + 2;
1225b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            Log.i(TAG, "bytes[" + i + "] = [" + type + ", " + len + "]" + ", next = " + i);
1226f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde        }
1227f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde
1228476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande        ScanResult.InformationElement elements[] = new ScanResult.InformationElement[num];
1229f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde        for (int i = 0, index = 0; i < num; i++) {
1230f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            int type  = (int) bytes[index] & 0xFF;
1231f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            int len = (int) bytes[index + 1] & 0xFF;
1232b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            Log.i(TAG, "index = " + index + ", type = " + type + ", len = " + len);
1233476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande            ScanResult.InformationElement elem = new ScanResult.InformationElement();
1234f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            elem.id = type;
1235f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            elem.bytes = new byte[len];
1236f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            for (int j = 0; j < len; j++) {
1237f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde                elem.bytes[j] = bytes[index + j + 2];
1238f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            }
1239f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            elements[i] = elem;
1240f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde            index += (len + 2);
1241f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde        }
1242f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde
1243476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande        result.informationElements = elements;
1244476bee2fef10d060c25c35858b1f7f60803d9f49Vinit Deshpande        sScanEventHandler.onFullScanResult(result);
12457f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde    }
12467f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1247b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static int sScanCmdId = 0;
1248b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static ScanEventHandler sScanEventHandler;
1249b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static ScanSettings sScanSettings;
12507f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1251b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static boolean startScan(
1252b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            ScanSettings settings, ScanEventHandler eventHandler) {
12537f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde        synchronized (mLock) {
1254b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande
1255b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (sScanCmdId != 0) {
1256741953368eafa247f2820496aaa521bc0e86e9e1Navtej Singh Mann                stopScan();
1257b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            } else if (sScanSettings != null || sScanEventHandler != null) {
1258b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                /* current scan is paused; no need to stop it */
1259b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            }
12607f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1261b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sScanCmdId = getNewCmdIdLocked();
1262e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1263b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sScanSettings = settings;
1264b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sScanEventHandler = eventHandler;
1265b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande
1266b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (startScanNative(sWlan0Index, sScanCmdId, settings) == false) {
1267b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sScanEventHandler = null;
1268b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sScanSettings = null;
1269e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde                return false;
1270e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            }
1271e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1272e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            return true;
1273e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        }
12747f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde    }
12757f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde
1276b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static void stopScan() {
1277b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        synchronized (mLock) {
1278b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            stopScanNative(sWlan0Index, sScanCmdId);
1279b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sScanSettings = null;
1280b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sScanEventHandler = null;
1281b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sScanCmdId = 0;
1282b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        }
1283b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    }
1284b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande
1285b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static void pauseScan() {
12867f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde        synchronized (mLock) {
1287b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (sScanCmdId != 0 && sScanSettings != null && sScanEventHandler != null) {
1288b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                Log.d(TAG, "Pausing scan");
1289b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                stopScanNative(sWlan0Index, sScanCmdId);
1290b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sScanCmdId = 0;
1291b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sScanEventHandler.onScanPaused();
1292b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            }
1293b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        }
1294b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    }
1295b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande
1296b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static void restartScan() {
1297b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande        synchronized (mLock) {
1298b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (sScanCmdId == 0 && sScanSettings != null && sScanEventHandler != null) {
1299b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                Log.d(TAG, "Restarting scan");
1300b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                startScan(sScanSettings, sScanEventHandler);
1301b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sScanEventHandler.onScanRestarted();
1302b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            }
1303e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        }
1304e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1305e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1306b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static ScanResult[] getScanResults() {
1307aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        synchronized (mLock) {
1308aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            return getScanResultsNative(sWlan0Index, /* flush = */ false);
1309aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        }
1310e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1311e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1312b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    public static interface HotlistEventHandler {
1313aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        void onHotlistApFound (ScanResult[]result);
1314e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1315e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1316b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static int sHotlistCmdId = 0;
1317b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static HotlistEventHandler sHotlistEventHandler;
1318e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1319b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private native static boolean setHotlistNative(int iface, int id,
1320e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            WifiScanner.HotlistSettings settings);
1321b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private native static boolean resetHotlistNative(int iface, int id);
1322e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1323b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static boolean setHotlist(WifiScanner.HotlistSettings settings,
1324aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                                    HotlistEventHandler eventHandler) {
1325e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        synchronized (mLock) {
1326b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (sHotlistCmdId != 0) {
1327e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde                return false;
1328e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            } else {
1329b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sHotlistCmdId = getNewCmdIdLocked();
1330e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            }
1331e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1332b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sHotlistEventHandler = eventHandler;
1333b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (setHotlistNative(sWlan0Index, sScanCmdId, settings) == false) {
1334b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sHotlistEventHandler = null;
1335e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde                return false;
1336e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            }
1337e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1338e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            return true;
1339e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        }
1340e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1341e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1342b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static void resetHotlist() {
1343e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        synchronized (mLock) {
1344b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (sHotlistCmdId != 0) {
1345b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                resetHotlistNative(sWlan0Index, sHotlistCmdId);
1346b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sHotlistCmdId = 0;
1347b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sHotlistEventHandler = null;
1348e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            }
13497f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde        }
13507f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde    }
1351e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1352b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static void onHotlistApFound(int id, ScanResult[] results) {
1353aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        synchronized (mLock) {
1354b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sHotlistEventHandler.onHotlistApFound(results);
1355aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        }
1356e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1357e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1358b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    public static interface SignificantWifiChangeEventHandler {
1359e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        void onChangesFound(ScanResult[] result);
1360e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1361e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1362b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static SignificantWifiChangeEventHandler sSignificantWifiChangeHandler;
1363b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static int sSignificantWifiChangeCmdId;
1364e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1365b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native boolean trackSignificantWifiChangeNative(
1366e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            int iface, int id, WifiScanner.WifiChangeSettings settings);
1367b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    private static native boolean untrackSignificantWifiChangeNative(int iface, int id);
1368e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1369b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static boolean trackSignificantWifiChange(
1370b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            WifiScanner.WifiChangeSettings settings, SignificantWifiChangeEventHandler handler) {
1371e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        synchronized (mLock) {
1372b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (sSignificantWifiChangeCmdId != 0) {
1373e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde                return false;
1374e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            } else {
1375b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sSignificantWifiChangeCmdId = getNewCmdIdLocked();
1376e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            }
1377e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1378b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sSignificantWifiChangeHandler = handler;
1379b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (trackSignificantWifiChangeNative(sWlan0Index, sScanCmdId, settings) == false) {
1380b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sHotlistEventHandler = null;
1381e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde                return false;
1382e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            }
1383e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1384e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            return true;
1385e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        }
1386e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1387e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1388b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized static void untrackSignificantWifiChange() {
1389e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        synchronized (mLock) {
1390b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            if (sSignificantWifiChangeCmdId != 0) {
1391b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                untrackSignificantWifiChangeNative(sWlan0Index, sSignificantWifiChangeCmdId);
1392b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sSignificantWifiChangeCmdId = 0;
1393b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande                sSignificantWifiChangeHandler = null;
1394e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde            }
1395e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde        }
1396e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1397e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1398b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized static void onSignificantWifiChange(int id, ScanResult[] results) {
1399aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        synchronized (mLock) {
1400b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande            sSignificantWifiChangeHandler.onChangesFound(results);
1401aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        }
1402e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde    }
1403e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde
1404b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande    synchronized public static WifiLinkLayerStats getWifiLinkLayerStats() {
1405aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        synchronized (mLock) {
1406aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            if (!sHalIsStarted)
1407aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                startHal();
1408aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle            if (sHalIsStarted)
1409aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle                return getWifiLinkLayerStatsNative(sWlan0Index);
1410aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        }
1411aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle        return null;
1412aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle    }
1413155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande}
1414