The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Vinit Deshapnde | ffadfb9 | 2013-12-06 15:12:41 -0800 | [diff] [blame] | 17 | package com.android.server.wifi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Vinit Deshapnde | ffadfb9 | 2013-12-06 15:12:41 -0800 | [diff] [blame] | 19 | import android.net.wifi.BatchedScanSettings; |
| 20 | import android.net.wifi.WpsInfo; |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 21 | import android.net.wifi.p2p.WifiP2pConfig; |
| 22 | import android.net.wifi.p2p.WifiP2pGroup; |
Irfan Sheriff | 618455f | 2011-11-18 14:33:09 -0800 | [diff] [blame] | 23 | import android.text.TextUtils; |
Irfan Sheriff | 21ba815 | 2012-04-04 16:22:21 -0700 | [diff] [blame] | 24 | import android.net.wifi.p2p.nsd.WifiP2pServiceInfo; |
Vinit Deshapnde | e8fabf9 | 2013-08-23 11:53:40 -0700 | [diff] [blame] | 25 | import android.util.LocalLog; |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 26 | import android.util.Log; |
| 27 | |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 28 | import java.util.ArrayList; |
| 29 | import java.util.List; |
Vinit Deshapnde | 2c385ec | 2013-09-09 16:28:31 -0700 | [diff] [blame] | 30 | import java.util.Locale; |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | /** |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 33 | * Native calls for bring up/shut down of the supplicant daemon and for |
| 34 | * sending requests to the supplicant daemon |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | * |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 36 | * waitForEvent() is called on the monitor thread for events. All other methods |
| 37 | * must be serialized from the framework. |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 38 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | * {@hide} |
| 40 | */ |
| 41 | public class WifiNative { |
| 42 | |
Irfan Sheriff | 7d6d9c0 | 2012-01-10 15:50:45 -0800 | [diff] [blame] | 43 | private static final boolean DBG = false; |
| 44 | private final String mTAG; |
Irfan Sheriff | bcc97ca | 2013-02-21 14:15:18 -0800 | [diff] [blame] | 45 | private static final int DEFAULT_GROUP_OWNER_INTENT = 6; |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 46 | |
Irfan Sheriff | bcc97ca | 2013-02-21 14:15:18 -0800 | [diff] [blame] | 47 | static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0; |
| 48 | static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED = 1; |
| 49 | static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2; |
| 50 | |
| 51 | static final int SCAN_WITHOUT_CONNECTION_SETUP = 1; |
| 52 | static final int SCAN_WITH_CONNECTION_SETUP = 2; |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 53 | |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 54 | // Hold this lock before calling supplicant - it is required to |
| 55 | // mutually exclude access from Wifi and P2p state machines |
| 56 | static final Object mLock = new Object(); |
| 57 | |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 58 | public final String mInterfaceName; |
| 59 | public final String mInterfacePrefix; |
| 60 | |
Irfan Sheriff | 633fe60 | 2012-09-14 14:35:44 -0700 | [diff] [blame] | 61 | private boolean mSuspendOptEnabled = false; |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 62 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | public native static boolean loadDriver(); |
Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 64 | |
| 65 | public native static boolean isDriverLoaded(); |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | public native static boolean unloadDriver(); |
| 68 | |
Irfan Sheriff | 7d6d9c0 | 2012-01-10 15:50:45 -0800 | [diff] [blame] | 69 | public native static boolean startSupplicant(boolean p2pSupported); |
Irfan Sheriff | f42c39b | 2011-08-26 14:45:23 -0700 | [diff] [blame] | 70 | |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 71 | /* Sends a kill signal to supplicant. To be used when we have lost connection |
| 72 | or when the supplicant is hung */ |
Irfan Sheriff | 511d534 | 2012-11-03 23:20:38 -0700 | [diff] [blame] | 73 | public native static boolean killSupplicant(boolean p2pSupported); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 75 | private native boolean connectToSupplicantNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 77 | private native void closeSupplicantConnectionNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Wait for the supplicant to send an event, returning the event string. |
| 81 | * @return the event string sent by the supplicant. |
| 82 | */ |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 83 | private native String waitForEventNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 85 | private native boolean doBooleanCommandNative(String command); |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 86 | |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 87 | private native int doIntCommandNative(String command); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 89 | private native String doStringCommandNative(String command); |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 90 | |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 91 | public WifiNative(String interfaceName) { |
| 92 | mInterfaceName = interfaceName; |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 93 | mTAG = "WifiNative-" + interfaceName; |
Dmitry Shmidt | 2de3a57 | 2013-08-14 12:59:23 -0700 | [diff] [blame] | 94 | if (!interfaceName.equals("p2p0")) { |
| 95 | mInterfacePrefix = "IFNAME=" + interfaceName + " "; |
| 96 | } else { |
| 97 | // commands for p2p0 interface don't need prefix |
| 98 | mInterfacePrefix = ""; |
| 99 | } |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Vinit Deshapnde | 48c4747 | 2013-08-28 13:13:40 -0700 | [diff] [blame] | 102 | private static final LocalLog mLocalLog = new LocalLog(1024); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 103 | |
| 104 | // hold mLock before accessing mCmdIdLock |
Vinit Deshapnde | 48c4747 | 2013-08-28 13:13:40 -0700 | [diff] [blame] | 105 | private int mCmdId; |
Vinit Deshapnde | e8fabf9 | 2013-08-23 11:53:40 -0700 | [diff] [blame] | 106 | |
Vinit Deshapnde | 48c4747 | 2013-08-28 13:13:40 -0700 | [diff] [blame] | 107 | public LocalLog getLocalLog() { |
| 108 | return mLocalLog; |
| 109 | } |
| 110 | |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 111 | private int getNewCmdIdLocked() { |
| 112 | return mCmdId++; |
Vinit Deshapnde | e8fabf9 | 2013-08-23 11:53:40 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | private void localLog(String s) { |
| 116 | if (mLocalLog != null) |
| 117 | mLocalLog.log(mInterfaceName + ": " + s); |
| 118 | } |
| 119 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 120 | public boolean connectToSupplicant() { |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 121 | // No synchronization necessary .. it is implemented in WifiMonitor |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 122 | localLog(mInterfacePrefix + "connectToSupplicant"); |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 123 | return connectToSupplicantNative(); |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 126 | public void closeSupplicantConnection() { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 127 | localLog(mInterfacePrefix + "closeSupplicantConnection"); |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 128 | closeSupplicantConnectionNative(); |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 131 | public String waitForEvent() { |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 132 | // No synchronization necessary .. it is implemented in WifiMonitor |
Vinit Deshapnde | c249c2c | 2013-08-08 10:38:53 -0700 | [diff] [blame] | 133 | return waitForEventNative(); |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 136 | private boolean doBooleanCommand(String command) { |
Irfan Sheriff | 7d6d9c0 | 2012-01-10 15:50:45 -0800 | [diff] [blame] | 137 | if (DBG) Log.d(mTAG, "doBoolean: " + command); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 138 | synchronized (mLock) { |
| 139 | int cmdId = getNewCmdIdLocked(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 140 | localLog(cmdId + "->" + mInterfacePrefix + command); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 141 | boolean result = doBooleanCommandNative(mInterfacePrefix + command); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 142 | localLog(cmdId + "<-" + result); |
Robert Greenwalt | 126755c | 2013-09-05 18:32:12 -0700 | [diff] [blame] | 143 | if (DBG) Log.d(mTAG, " returned " + result); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 144 | return result; |
| 145 | } |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 148 | private int doIntCommand(String command) { |
Irfan Sheriff | 7d6d9c0 | 2012-01-10 15:50:45 -0800 | [diff] [blame] | 149 | if (DBG) Log.d(mTAG, "doInt: " + command); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 150 | synchronized (mLock) { |
| 151 | int cmdId = getNewCmdIdLocked(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 152 | localLog(cmdId + "->" + mInterfacePrefix + command); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 153 | int result = doIntCommandNative(mInterfacePrefix + command); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 154 | localLog(cmdId + "<-" + result); |
Robert Greenwalt | 126755c | 2013-09-05 18:32:12 -0700 | [diff] [blame] | 155 | if (DBG) Log.d(mTAG, " returned " + result); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 156 | return result; |
| 157 | } |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 160 | private String doStringCommand(String command) { |
Irfan Sheriff | 7d6d9c0 | 2012-01-10 15:50:45 -0800 | [diff] [blame] | 161 | if (DBG) Log.d(mTAG, "doString: " + command); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 162 | synchronized (mLock) { |
| 163 | int cmdId = getNewCmdIdLocked(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 164 | localLog(cmdId + "->" + mInterfacePrefix + command); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 165 | String result = doStringCommandNative(mInterfacePrefix + command); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 166 | localLog(cmdId + "<-" + result); |
Robert Greenwalt | 126755c | 2013-09-05 18:32:12 -0700 | [diff] [blame] | 167 | if (DBG) Log.d(mTAG, " returned " + result); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 168 | return result; |
| 169 | } |
Vinit Deshapnde | 48c4747 | 2013-08-28 13:13:40 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | private String doStringCommandWithoutLogging(String command) { |
| 173 | if (DBG) Log.d(mTAG, "doString: " + command); |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 174 | synchronized (mLock) { |
| 175 | return doStringCommandNative(mInterfacePrefix + command); |
| 176 | } |
Irfan Sheriff | 44b330d | 2011-12-28 13:00:28 -0800 | [diff] [blame] | 177 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 179 | public boolean ping() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 180 | String pong = doStringCommand("PING"); |
| 181 | return (pong != null && pong.equals("PONG")); |
| 182 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | |
Irfan Sheriff | bcc97ca | 2013-02-21 14:15:18 -0800 | [diff] [blame] | 184 | public boolean scan(int type) { |
| 185 | if (type == SCAN_WITHOUT_CONNECTION_SETUP) { |
| 186 | return doBooleanCommand("SCAN TYPE=ONLY"); |
| 187 | } else if (type == SCAN_WITH_CONNECTION_SETUP) { |
| 188 | return doBooleanCommand("SCAN"); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 189 | } else { |
Irfan Sheriff | bcc97ca | 2013-02-21 14:15:18 -0800 | [diff] [blame] | 190 | throw new IllegalArgumentException("Invalid scan type"); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 191 | } |
| 192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 194 | /* Does a graceful shutdown of supplicant. Is a common stop function for both p2p and sta. |
| 195 | * |
| 196 | * Note that underneath we use a harsh-sounding "terminate" supplicant command |
| 197 | * for a graceful stop and a mild-sounding "stop" interface |
| 198 | * to kill the process |
| 199 | */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 200 | public boolean stopSupplicant() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 201 | return doBooleanCommand("TERMINATE"); |
| 202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 204 | public String listNetworks() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 205 | return doStringCommand("LIST_NETWORKS"); |
| 206 | } |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 207 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 208 | public int addNetwork() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 209 | return doIntCommand("ADD_NETWORK"); |
| 210 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 212 | public boolean setNetworkVariable(int netId, String name, String value) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 213 | if (TextUtils.isEmpty(name) || TextUtils.isEmpty(value)) return false; |
| 214 | return doBooleanCommand("SET_NETWORK " + netId + " " + name + " " + value); |
| 215 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 217 | public String getNetworkVariable(int netId, String name) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 218 | if (TextUtils.isEmpty(name)) return null; |
Vinit Deshapnde | 48c4747 | 2013-08-28 13:13:40 -0700 | [diff] [blame] | 219 | |
| 220 | // GET_NETWORK will likely flood the logs ... |
| 221 | return doStringCommandWithoutLogging("GET_NETWORK " + netId + " " + name); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 222 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 224 | public boolean removeNetwork(int netId) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 225 | return doBooleanCommand("REMOVE_NETWORK " + netId); |
| 226 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 228 | public boolean enableNetwork(int netId, boolean disableOthers) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 229 | if (disableOthers) { |
| 230 | return doBooleanCommand("SELECT_NETWORK " + netId); |
| 231 | } else { |
| 232 | return doBooleanCommand("ENABLE_NETWORK " + netId); |
| 233 | } |
| 234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 236 | public boolean disableNetwork(int netId) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 237 | return doBooleanCommand("DISABLE_NETWORK " + netId); |
| 238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 240 | public boolean reconnect() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 241 | return doBooleanCommand("RECONNECT"); |
| 242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 244 | public boolean reassociate() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 245 | return doBooleanCommand("REASSOCIATE"); |
| 246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 248 | public boolean disconnect() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 249 | return doBooleanCommand("DISCONNECT"); |
| 250 | } |
| 251 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 252 | public String status() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 253 | return doStringCommand("STATUS"); |
| 254 | } |
| 255 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 256 | public String getMacAddress() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 257 | //Macaddr = XX.XX.XX.XX.XX.XX |
| 258 | String ret = doStringCommand("DRIVER MACADDR"); |
| 259 | if (!TextUtils.isEmpty(ret)) { |
| 260 | String[] tokens = ret.split(" = "); |
| 261 | if (tokens.length == 2) return tokens[1]; |
| 262 | } |
| 263 | return null; |
| 264 | } |
| 265 | |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 266 | /** |
| 267 | * Format of results: |
| 268 | * ================= |
Iliyan Malchev | 9233fc0 | 2013-06-21 03:09:44 +0000 | [diff] [blame] | 269 | * id=1 |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 270 | * bssid=68:7f:74:d7:1b:6e |
| 271 | * freq=2412 |
| 272 | * level=-43 |
| 273 | * tsf=1344621975160944 |
| 274 | * age=2623 |
| 275 | * flags=[WPA2-PSK-CCMP][WPS][ESS] |
| 276 | * ssid=zubyb |
Dmitry Shmidt | 14b628a | 2013-03-01 09:37:00 -0800 | [diff] [blame] | 277 | * ==== |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 278 | * |
| 279 | * RANGE=ALL gets all scan results |
Iliyan Malchev | 9233fc0 | 2013-06-21 03:09:44 +0000 | [diff] [blame] | 280 | * RANGE=ID- gets results from ID |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 281 | * MASK=<N> see wpa_supplicant/src/common/wpa_ctrl.h for details |
| 282 | */ |
Iliyan Malchev | 9233fc0 | 2013-06-21 03:09:44 +0000 | [diff] [blame] | 283 | public String scanResults(int sid) { |
Vinit Deshapnde | 48c4747 | 2013-08-28 13:13:40 -0700 | [diff] [blame] | 284 | return doStringCommandWithoutLogging("BSS RANGE=" + sid + "- MASK=0x21987"); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 287 | /** |
| 288 | * Format of command |
Robert Greenwalt | 126755c | 2013-09-05 18:32:12 -0700 | [diff] [blame] | 289 | * DRIVER WLS_BATCHING SET SCANFREQ=x MSCAN=r BESTN=y CHANNEL=<z, w, t> RTT=s |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 290 | * where x is an ascii representation of an integer number of seconds between scans |
Robert Greenwalt | 8e628da | 2013-08-14 16:07:44 -0700 | [diff] [blame] | 291 | * r is an ascii representation of an integer number of scans per batch |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 292 | * y is an ascii representation of an integer number of the max AP to remember per scan |
| 293 | * z, w, t represent a 1..n size list of channel numbers and/or 'A', 'B' values |
| 294 | * indicating entire ranges of channels |
| 295 | * s is an ascii representation of an integer number of highest-strength AP |
| 296 | * for which we'd like approximate distance reported |
| 297 | * |
| 298 | * The return value is an ascii integer representing a guess of the number of scans |
| 299 | * the firmware can remember before it runs out of buffer space or -1 on error |
| 300 | */ |
| 301 | public String setBatchedScanSettings(BatchedScanSettings settings) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 302 | if (settings == null) { |
| 303 | return doStringCommand("DRIVER WLS_BATCHING STOP"); |
| 304 | } |
Robert Greenwalt | 126755c | 2013-09-05 18:32:12 -0700 | [diff] [blame] | 305 | String cmd = "DRIVER WLS_BATCHING SET SCANFREQ=" + settings.scanIntervalSec; |
Robert Greenwalt | 8e628da | 2013-08-14 16:07:44 -0700 | [diff] [blame] | 306 | cmd += " MSCAN=" + settings.maxScansPerBatch; |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 307 | if (settings.maxApPerScan != BatchedScanSettings.UNSPECIFIED) { |
Robert Greenwalt | 8e628da | 2013-08-14 16:07:44 -0700 | [diff] [blame] | 308 | cmd += " BESTN=" + settings.maxApPerScan; |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 309 | } |
| 310 | if (settings.channelSet != null && !settings.channelSet.isEmpty()) { |
| 311 | cmd += " CHANNEL=<"; |
Sreeram Ramachandran | 268f329 | 2013-08-27 14:49:23 -0700 | [diff] [blame] | 312 | int i = 0; |
| 313 | for (String channel : settings.channelSet) { |
| 314 | cmd += (i > 0 ? "," : "") + channel; |
| 315 | ++i; |
| 316 | } |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 317 | cmd += ">"; |
| 318 | } |
| 319 | if (settings.maxApForDistance != BatchedScanSettings.UNSPECIFIED) { |
| 320 | cmd += " RTT=" + settings.maxApForDistance; |
| 321 | } |
| 322 | return doStringCommand(cmd); |
| 323 | } |
| 324 | |
| 325 | public String getBatchedScanResults() { |
| 326 | return doStringCommand("DRIVER WLS_BATCHING GET"); |
| 327 | } |
| 328 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 329 | public boolean startDriver() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 330 | return doBooleanCommand("DRIVER START"); |
| 331 | } |
| 332 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 333 | public boolean stopDriver() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 334 | return doBooleanCommand("DRIVER STOP"); |
| 335 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | |
| 338 | /** |
Irfan Sheriff | b0c1b80f | 2011-07-19 15:44:25 -0700 | [diff] [blame] | 339 | * Start filtering out Multicast V4 packets |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | * @return {@code true} if the operation succeeded, {@code false} otherwise |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 341 | * |
| 342 | * Multicast filtering rules work as follows: |
| 343 | * |
| 344 | * The driver can filter multicast (v4 and/or v6) and broadcast packets when in |
| 345 | * a power optimized mode (typically when screen goes off). |
| 346 | * |
| 347 | * In order to prevent the driver from filtering the multicast/broadcast packets, we have to |
| 348 | * add a DRIVER RXFILTER-ADD rule followed by DRIVER RXFILTER-START to make the rule effective |
| 349 | * |
| 350 | * DRIVER RXFILTER-ADD Num |
| 351 | * where Num = 0 - Unicast, 1 - Broadcast, 2 - Mutil4 or 3 - Multi6 |
| 352 | * |
| 353 | * and DRIVER RXFILTER-START |
| 354 | * In order to stop the usage of these rules, we do |
| 355 | * |
| 356 | * DRIVER RXFILTER-STOP |
| 357 | * DRIVER RXFILTER-REMOVE Num |
| 358 | * where Num is as described for RXFILTER-ADD |
| 359 | * |
| 360 | * The SETSUSPENDOPT driver command overrides the filtering rules |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 362 | public boolean startFilteringMulticastV4Packets() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 363 | return doBooleanCommand("DRIVER RXFILTER-STOP") |
| 364 | && doBooleanCommand("DRIVER RXFILTER-REMOVE 2") |
| 365 | && doBooleanCommand("DRIVER RXFILTER-START"); |
| 366 | } |
Irfan Sheriff | b0c1b80f | 2011-07-19 15:44:25 -0700 | [diff] [blame] | 367 | |
| 368 | /** |
| 369 | * Stop filtering out Multicast V4 packets. |
| 370 | * @return {@code true} if the operation succeeded, {@code false} otherwise |
| 371 | */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 372 | public boolean stopFilteringMulticastV4Packets() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 373 | return doBooleanCommand("DRIVER RXFILTER-STOP") |
| 374 | && doBooleanCommand("DRIVER RXFILTER-ADD 2") |
| 375 | && doBooleanCommand("DRIVER RXFILTER-START"); |
| 376 | } |
Irfan Sheriff | b0c1b80f | 2011-07-19 15:44:25 -0700 | [diff] [blame] | 377 | |
| 378 | /** |
| 379 | * Start filtering out Multicast V6 packets |
| 380 | * @return {@code true} if the operation succeeded, {@code false} otherwise |
| 381 | */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 382 | public boolean startFilteringMulticastV6Packets() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 383 | return doBooleanCommand("DRIVER RXFILTER-STOP") |
| 384 | && doBooleanCommand("DRIVER RXFILTER-REMOVE 3") |
| 385 | && doBooleanCommand("DRIVER RXFILTER-START"); |
| 386 | } |
Irfan Sheriff | b0c1b80f | 2011-07-19 15:44:25 -0700 | [diff] [blame] | 387 | |
| 388 | /** |
| 389 | * Stop filtering out Multicast V6 packets. |
| 390 | * @return {@code true} if the operation succeeded, {@code false} otherwise |
| 391 | */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 392 | public boolean stopFilteringMulticastV6Packets() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 393 | return doBooleanCommand("DRIVER RXFILTER-STOP") |
| 394 | && doBooleanCommand("DRIVER RXFILTER-ADD 3") |
| 395 | && doBooleanCommand("DRIVER RXFILTER-START"); |
| 396 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 398 | public int getBand() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 399 | String ret = doStringCommand("DRIVER GETBAND"); |
| 400 | if (!TextUtils.isEmpty(ret)) { |
| 401 | //reply is "BAND X" where X is the band |
| 402 | String[] tokens = ret.split(" "); |
| 403 | try { |
| 404 | if (tokens.length == 2) return Integer.parseInt(tokens[1]); |
| 405 | } catch (NumberFormatException e) { |
| 406 | return -1; |
| 407 | } |
| 408 | } |
| 409 | return -1; |
| 410 | } |
Irfan Sheriff | 25c9bf2 | 2010-09-02 12:48:20 -0700 | [diff] [blame] | 411 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 412 | public boolean setBand(int band) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 413 | return doBooleanCommand("DRIVER SETBAND " + band); |
| 414 | } |
Mikael Kanstrup | ea8bd1d | 2010-04-07 16:45:58 +0200 | [diff] [blame] | 415 | |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 416 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | * Sets the bluetooth coexistence mode. |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 418 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | * @param mode One of {@link #BLUETOOTH_COEXISTENCE_MODE_DISABLED}, |
| 420 | * {@link #BLUETOOTH_COEXISTENCE_MODE_ENABLED}, or |
| 421 | * {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}. |
| 422 | * @return Whether the mode was successfully set. |
| 423 | */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 424 | public boolean setBluetoothCoexistenceMode(int mode) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 425 | return doBooleanCommand("DRIVER BTCOEXMODE " + mode); |
| 426 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * Enable or disable Bluetooth coexistence scan mode. When this mode is on, |
| 430 | * some of the low-level scan parameters used by the driver are changed to |
| 431 | * reduce interference with A2DP streaming. |
| 432 | * |
| 433 | * @param isSet whether to enable or disable this mode |
| 434 | * @return {@code true} if the command succeeded, {@code false} otherwise. |
| 435 | */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 436 | public boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 437 | if (setCoexScanMode) { |
| 438 | return doBooleanCommand("DRIVER BTCOEXSCAN-START"); |
| 439 | } else { |
| 440 | return doBooleanCommand("DRIVER BTCOEXSCAN-STOP"); |
| 441 | } |
| 442 | } |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 443 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 444 | public boolean saveConfig() { |
Irfan Sheriff | bcc97ca | 2013-02-21 14:15:18 -0800 | [diff] [blame] | 445 | return doBooleanCommand("SAVE_CONFIG"); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 448 | public boolean addToBlacklist(String bssid) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 449 | if (TextUtils.isEmpty(bssid)) return false; |
| 450 | return doBooleanCommand("BLACKLIST " + bssid); |
| 451 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 453 | public boolean clearBlacklist() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 454 | return doBooleanCommand("BLACKLIST clear"); |
| 455 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 457 | public boolean setSuspendOptimizations(boolean enabled) { |
Irfan Sheriff | 633fe60 | 2012-09-14 14:35:44 -0700 | [diff] [blame] | 458 | if (mSuspendOptEnabled == enabled) return true; |
| 459 | mSuspendOptEnabled = enabled; |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 460 | if (enabled) { |
Irfan Sheriff | 262f766 | 2012-03-26 23:48:53 -0700 | [diff] [blame] | 461 | return doBooleanCommand("DRIVER SETSUSPENDMODE 1"); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 462 | } else { |
Irfan Sheriff | 262f766 | 2012-03-26 23:48:53 -0700 | [diff] [blame] | 463 | return doBooleanCommand("DRIVER SETSUSPENDMODE 0"); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 464 | } |
| 465 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 467 | public boolean setCountryCode(String countryCode) { |
Vinit Deshapnde | 2c385ec | 2013-09-09 16:28:31 -0700 | [diff] [blame] | 468 | return doBooleanCommand("DRIVER COUNTRY " + countryCode.toUpperCase(Locale.ROOT)); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 469 | } |
Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 470 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 471 | public void enableBackgroundScan(boolean enable) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 472 | if (enable) { |
Irfan Sheriff | e2639d7 | 2012-04-27 12:20:00 -0700 | [diff] [blame] | 473 | doBooleanCommand("SET pno 1"); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 474 | } else { |
Irfan Sheriff | e2639d7 | 2012-04-27 12:20:00 -0700 | [diff] [blame] | 475 | doBooleanCommand("SET pno 0"); |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 476 | } |
| 477 | } |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 478 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 479 | public void setScanInterval(int scanInterval) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 480 | doBooleanCommand("SCAN_INTERVAL " + scanInterval); |
| 481 | } |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 482 | |
Vinit Deshapnde | 64f0d5b | 2013-07-11 15:12:44 -0700 | [diff] [blame] | 483 | public void startTdls(String macAddr, boolean enable) { |
Dmitry Shmidt | 5ab422b | 2013-07-16 12:41:22 -0700 | [diff] [blame] | 484 | if (enable) { |
| 485 | doBooleanCommand("TDLS_DISCOVER " + macAddr); |
Vinit Deshapnde | 64f0d5b | 2013-07-11 15:12:44 -0700 | [diff] [blame] | 486 | doBooleanCommand("TDLS_SETUP " + macAddr); |
Dmitry Shmidt | 5ab422b | 2013-07-16 12:41:22 -0700 | [diff] [blame] | 487 | } else { |
Vinit Deshapnde | 64f0d5b | 2013-07-11 15:12:44 -0700 | [diff] [blame] | 488 | doBooleanCommand("TDLS_TEARDOWN " + macAddr); |
Dmitry Shmidt | 5ab422b | 2013-07-16 12:41:22 -0700 | [diff] [blame] | 489 | } |
Vinit Deshapnde | 64f0d5b | 2013-07-11 15:12:44 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Irfan Sheriff | 921df5c | 2011-09-26 16:30:15 -0700 | [diff] [blame] | 492 | /** Example output: |
| 493 | * RSSI=-65 |
| 494 | * LINKSPEED=48 |
| 495 | * NOISE=9999 |
| 496 | * FREQUENCY=0 |
| 497 | */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 498 | public String signalPoll() { |
Vinit Deshapnde | 48c4747 | 2013-08-28 13:13:40 -0700 | [diff] [blame] | 499 | return doStringCommandWithoutLogging("SIGNAL_POLL"); |
Irfan Sheriff | 921df5c | 2011-09-26 16:30:15 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Yuhao Zheng | b33227d | 2012-07-20 10:55:17 -0700 | [diff] [blame] | 502 | /** Example outout: |
| 503 | * TXGOOD=396 |
| 504 | * TXBAD=1 |
| 505 | */ |
| 506 | public String pktcntPoll() { |
| 507 | return doStringCommand("PKTCNT_POLL"); |
| 508 | } |
| 509 | |
Vinit Deshapnde | b8d116a | 2013-07-09 10:42:38 -0700 | [diff] [blame] | 510 | public void bssFlush() { |
Dmitry Shmidt | 8e7c1b1 | 2013-09-06 14:25:14 -0700 | [diff] [blame] | 511 | doBooleanCommand("BSS_FLUSH 0"); |
Vinit Deshapnde | b8d116a | 2013-07-09 10:42:38 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 514 | public boolean startWpsPbc(String bssid) { |
Irfan Sheriff | 86a5f5b | 2012-02-28 17:03:56 -0800 | [diff] [blame] | 515 | if (TextUtils.isEmpty(bssid)) { |
| 516 | return doBooleanCommand("WPS_PBC"); |
| 517 | } else { |
| 518 | return doBooleanCommand("WPS_PBC " + bssid); |
| 519 | } |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 522 | public boolean startWpsPbc(String iface, String bssid) { |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 523 | synchronized (mLock) { |
| 524 | if (TextUtils.isEmpty(bssid)) { |
| 525 | return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC"); |
| 526 | } else { |
| 527 | return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid); |
| 528 | } |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 532 | public boolean startWpsPinKeypad(String pin) { |
Irfan Sheriff | 86a5f5b | 2012-02-28 17:03:56 -0800 | [diff] [blame] | 533 | if (TextUtils.isEmpty(pin)) return false; |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 534 | return doBooleanCommand("WPS_PIN any " + pin); |
| 535 | } |
| 536 | |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 537 | public boolean startWpsPinKeypad(String iface, String pin) { |
| 538 | if (TextUtils.isEmpty(pin)) return false; |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 539 | synchronized (mLock) { |
| 540 | return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin); |
| 541 | } |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 545 | public String startWpsPinDisplay(String bssid) { |
Irfan Sheriff | 86a5f5b | 2012-02-28 17:03:56 -0800 | [diff] [blame] | 546 | if (TextUtils.isEmpty(bssid)) { |
| 547 | return doStringCommand("WPS_PIN any"); |
| 548 | } else { |
| 549 | return doStringCommand("WPS_PIN " + bssid); |
| 550 | } |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 551 | } |
| 552 | |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 553 | public String startWpsPinDisplay(String iface, String bssid) { |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 554 | synchronized (mLock) { |
| 555 | if (TextUtils.isEmpty(bssid)) { |
| 556 | return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any"); |
| 557 | } else { |
| 558 | return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid); |
| 559 | } |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 563 | /* Configures an access point connection */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 564 | public boolean startWpsRegistrar(String bssid, String pin) { |
Irfan Sheriff | 86a5f5b | 2012-02-28 17:03:56 -0800 | [diff] [blame] | 565 | if (TextUtils.isEmpty(bssid) || TextUtils.isEmpty(pin)) return false; |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 566 | return doBooleanCommand("WPS_REG " + bssid + " " + pin); |
| 567 | } |
| 568 | |
Irfan Sheriff | 86a5f5b | 2012-02-28 17:03:56 -0800 | [diff] [blame] | 569 | public boolean cancelWps() { |
| 570 | return doBooleanCommand("WPS_CANCEL"); |
| 571 | } |
| 572 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 573 | public boolean setPersistentReconnect(boolean enabled) { |
Irfan Sheriff | 9322687 | 2011-08-29 10:36:05 -0700 | [diff] [blame] | 574 | int value = (enabled == true) ? 1 : 0; |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 575 | return doBooleanCommand("SET persistent_reconnect " + value); |
Irfan Sheriff | 9322687 | 2011-08-29 10:36:05 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 578 | public boolean setDeviceName(String name) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 579 | return doBooleanCommand("SET device_name " + name); |
Irfan Sheriff | 9322687 | 2011-08-29 10:36:05 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 582 | public boolean setDeviceType(String type) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 583 | return doBooleanCommand("SET device_type " + type); |
Irfan Sheriff | 9322687 | 2011-08-29 10:36:05 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 586 | public boolean setConfigMethods(String cfg) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 587 | return doBooleanCommand("SET config_methods " + cfg); |
Irfan Sheriff | 618455f | 2011-11-18 14:33:09 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Irfan Sheriff | 4dd5a25 | 2012-05-22 12:53:47 -0700 | [diff] [blame] | 590 | public boolean setManufacturer(String value) { |
| 591 | return doBooleanCommand("SET manufacturer " + value); |
| 592 | } |
| 593 | |
| 594 | public boolean setModelName(String value) { |
| 595 | return doBooleanCommand("SET model_name " + value); |
| 596 | } |
| 597 | |
| 598 | public boolean setModelNumber(String value) { |
| 599 | return doBooleanCommand("SET model_number " + value); |
| 600 | } |
| 601 | |
| 602 | public boolean setSerialNumber(String value) { |
| 603 | return doBooleanCommand("SET serial_number " + value); |
| 604 | } |
| 605 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 606 | public boolean setP2pSsidPostfix(String postfix) { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 607 | return doBooleanCommand("SET p2p_ssid_postfix " + postfix); |
Irfan Sheriff | 530040e | 2011-11-30 17:20:47 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Irfan Sheriff | 10ca870 | 2012-05-10 16:52:49 -0700 | [diff] [blame] | 610 | public boolean setP2pGroupIdle(String iface, int time) { |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 611 | synchronized (mLock) { |
| 612 | return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time); |
| 613 | } |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Irfan Sheriff | e2639d7 | 2012-04-27 12:20:00 -0700 | [diff] [blame] | 616 | public void setPowerSave(boolean enabled) { |
| 617 | if (enabled) { |
| 618 | doBooleanCommand("SET ps 1"); |
| 619 | } else { |
| 620 | doBooleanCommand("SET ps 0"); |
| 621 | } |
| 622 | } |
| 623 | |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 624 | public boolean setP2pPowerSave(String iface, boolean enabled) { |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 625 | synchronized (mLock) { |
| 626 | if (enabled) { |
| 627 | return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1"); |
| 628 | } else { |
| 629 | return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0"); |
| 630 | } |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
Andreas Huber | ab4cd45 | 2012-08-15 16:16:31 -0700 | [diff] [blame] | 634 | public boolean setWfdEnable(boolean enable) { |
| 635 | return doBooleanCommand("SET wifi_display " + (enable ? "1" : "0")); |
| 636 | } |
| 637 | |
| 638 | public boolean setWfdDeviceInfo(String hex) { |
| 639 | return doBooleanCommand("WFD_SUBELEM_SET 0 " + hex); |
| 640 | } |
| 641 | |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 642 | /** |
| 643 | * "sta" prioritizes STA connection over P2P and "p2p" prioritizes |
| 644 | * P2P connection over STA |
| 645 | */ |
| 646 | public boolean setConcurrencyPriority(String s) { |
Irfan Sheriff | de1e9fa9 | 2012-05-01 16:15:23 -0700 | [diff] [blame] | 647 | return doBooleanCommand("P2P_SET conc_pref " + s); |
Irfan Sheriff | 55bfa42 | 2012-04-06 15:25:41 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 650 | public boolean p2pFind() { |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 651 | return doBooleanCommand("P2P_FIND"); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 654 | public boolean p2pFind(int timeout) { |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 655 | if (timeout <= 0) { |
| 656 | return p2pFind(); |
| 657 | } |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 658 | return doBooleanCommand("P2P_FIND " + timeout); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Irfan Sheriff | 7d6d9c0 | 2012-01-10 15:50:45 -0800 | [diff] [blame] | 661 | public boolean p2pStopFind() { |
| 662 | return doBooleanCommand("P2P_STOP_FIND"); |
| 663 | } |
| 664 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 665 | public boolean p2pListen() { |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 666 | return doBooleanCommand("P2P_LISTEN"); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 669 | public boolean p2pListen(int timeout) { |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 670 | if (timeout <= 0) { |
| 671 | return p2pListen(); |
| 672 | } |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 673 | return doBooleanCommand("P2P_LISTEN " + timeout); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 676 | public boolean p2pExtListen(boolean enable, int period, int interval) { |
| 677 | if (enable && interval < period) { |
| 678 | return false; |
| 679 | } |
| 680 | return doBooleanCommand("P2P_EXT_LISTEN" |
| 681 | + (enable ? (" " + period + " " + interval) : "")); |
| 682 | } |
| 683 | |
| 684 | public boolean p2pSetChannel(int lc, int oc) { |
| 685 | if (DBG) Log.d(mTAG, "p2pSetChannel: lc="+lc+", oc="+oc); |
| 686 | |
| 687 | if (lc >=1 && lc <= 11) { |
| 688 | if (!doBooleanCommand("P2P_SET listen_channel " + lc)) { |
| 689 | return false; |
| 690 | } |
| 691 | } else if (lc != 0) { |
| 692 | return false; |
| 693 | } |
| 694 | |
| 695 | if (oc >= 1 && oc <= 165 ) { |
| 696 | int freq = (oc <= 14 ? 2407 : 5000) + oc * 5; |
| 697 | return doBooleanCommand("P2P_SET disallow_freq 1000-" |
| 698 | + (freq - 5) + "," + (freq + 5) + "-6000"); |
| 699 | } else if (oc == 0) { |
| 700 | /* oc==0 disables "P2P_SET disallow_freq" (enables all freqs) */ |
| 701 | return doBooleanCommand("P2P_SET disallow_freq \"\""); |
| 702 | } |
| 703 | |
| 704 | return false; |
| 705 | } |
| 706 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 707 | public boolean p2pFlush() { |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 708 | return doBooleanCommand("P2P_FLUSH"); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* p2p_connect <peer device address> <pbc|pin|PIN#> [label|display|keypad] |
| 712 | [persistent] [join|auth] [go_intent=<0..15>] [freq=<in MHz>] */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 713 | public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) { |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 714 | if (config == null) return null; |
| 715 | List<String> args = new ArrayList<String>(); |
Irfan Sheriff | 651cdfc | 2011-09-07 00:31:20 -0700 | [diff] [blame] | 716 | WpsInfo wps = config.wps; |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 717 | args.add(config.deviceAddress); |
| 718 | |
Irfan Sheriff | 6f7d385 | 2011-09-06 21:48:04 -0700 | [diff] [blame] | 719 | switch (wps.setup) { |
Irfan Sheriff | 651cdfc | 2011-09-07 00:31:20 -0700 | [diff] [blame] | 720 | case WpsInfo.PBC: |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 721 | args.add("pbc"); |
| 722 | break; |
Irfan Sheriff | 651cdfc | 2011-09-07 00:31:20 -0700 | [diff] [blame] | 723 | case WpsInfo.DISPLAY: |
Irfan Sheriff | 618455f | 2011-11-18 14:33:09 -0800 | [diff] [blame] | 724 | if (TextUtils.isEmpty(wps.pin)) { |
| 725 | args.add("pin"); |
| 726 | } else { |
| 727 | args.add(wps.pin); |
| 728 | } |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 729 | args.add("display"); |
| 730 | break; |
Irfan Sheriff | 651cdfc | 2011-09-07 00:31:20 -0700 | [diff] [blame] | 731 | case WpsInfo.KEYPAD: |
Irfan Sheriff | 6f7d385 | 2011-09-06 21:48:04 -0700 | [diff] [blame] | 732 | args.add(wps.pin); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 733 | args.add("keypad"); |
| 734 | break; |
Irfan Sheriff | 651cdfc | 2011-09-07 00:31:20 -0700 | [diff] [blame] | 735 | case WpsInfo.LABEL: |
Irfan Sheriff | 6f7d385 | 2011-09-06 21:48:04 -0700 | [diff] [blame] | 736 | args.add(wps.pin); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 737 | args.add("label"); |
| 738 | default: |
| 739 | break; |
| 740 | } |
| 741 | |
Yoshihiko Ikenaga | 0879d03 | 2012-08-16 23:37:36 +0900 | [diff] [blame] | 742 | if (config.netId == WifiP2pGroup.PERSISTENT_NET_ID) { |
| 743 | args.add("persistent"); |
| 744 | } |
Irfan Sheriff | f9cb1d7 | 2011-08-29 17:01:33 -0700 | [diff] [blame] | 745 | |
Irfan Sheriff | de1e9fa9 | 2012-05-01 16:15:23 -0700 | [diff] [blame] | 746 | if (joinExistingGroup) { |
| 747 | args.add("join"); |
| 748 | } else { |
| 749 | //TODO: This can be adapted based on device plugged in state and |
| 750 | //device battery state |
| 751 | int groupOwnerIntent = config.groupOwnerIntent; |
| 752 | if (groupOwnerIntent < 0 || groupOwnerIntent > 15) { |
| 753 | groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT; |
| 754 | } |
| 755 | args.add("go_intent=" + groupOwnerIntent); |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 756 | } |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 757 | |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 758 | String command = "P2P_CONNECT "; |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 759 | for (String s : args) command += s + " "; |
| 760 | |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 761 | return doStringCommand(command); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 764 | public boolean p2pCancelConnect() { |
Irfan Sheriff | 651cdfc | 2011-09-07 00:31:20 -0700 | [diff] [blame] | 765 | return doBooleanCommand("P2P_CANCEL"); |
| 766 | } |
| 767 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 768 | public boolean p2pProvisionDiscovery(WifiP2pConfig config) { |
Irfan Sheriff | 618455f | 2011-11-18 14:33:09 -0800 | [diff] [blame] | 769 | if (config == null) return false; |
| 770 | |
| 771 | switch (config.wps.setup) { |
| 772 | case WpsInfo.PBC: |
| 773 | return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " pbc"); |
| 774 | case WpsInfo.DISPLAY: |
| 775 | //We are doing display, so provision discovery is keypad |
| 776 | return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " keypad"); |
| 777 | case WpsInfo.KEYPAD: |
| 778 | //We are doing keypad, so provision discovery is display |
| 779 | return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " display"); |
| 780 | default: |
| 781 | break; |
| 782 | } |
| 783 | return false; |
| 784 | } |
| 785 | |
Yoshihiko Ikenaga | 0879d03 | 2012-08-16 23:37:36 +0900 | [diff] [blame] | 786 | public boolean p2pGroupAdd(boolean persistent) { |
| 787 | if (persistent) { |
| 788 | return doBooleanCommand("P2P_GROUP_ADD persistent"); |
| 789 | } |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 790 | return doBooleanCommand("P2P_GROUP_ADD"); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Yoshihiko Ikenaga | 0879d03 | 2012-08-16 23:37:36 +0900 | [diff] [blame] | 793 | public boolean p2pGroupAdd(int netId) { |
| 794 | return doBooleanCommand("P2P_GROUP_ADD persistent=" + netId); |
| 795 | } |
| 796 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 797 | public boolean p2pGroupRemove(String iface) { |
Irfan Sheriff | 86a5f5b | 2012-02-28 17:03:56 -0800 | [diff] [blame] | 798 | if (TextUtils.isEmpty(iface)) return false; |
Vinit Deshapnde | fab5c2b | 2013-08-30 12:31:25 -0700 | [diff] [blame] | 799 | synchronized (mLock) { |
| 800 | return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface); |
| 801 | } |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 804 | public boolean p2pReject(String deviceAddress) { |
repo sync | 2b8edd0 | 2011-08-16 21:39:24 -0700 | [diff] [blame] | 805 | return doBooleanCommand("P2P_REJECT " + deviceAddress); |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /* Invite a peer to a group */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 809 | public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) { |
Irfan Sheriff | 86a5f5b | 2012-02-28 17:03:56 -0800 | [diff] [blame] | 810 | if (TextUtils.isEmpty(deviceAddress)) return false; |
Irfan Sheriff | ea5b16a | 2011-08-24 12:30:20 -0700 | [diff] [blame] | 811 | |
| 812 | if (group == null) { |
| 813 | return doBooleanCommand("P2P_INVITE peer=" + deviceAddress); |
| 814 | } else { |
| 815 | return doBooleanCommand("P2P_INVITE group=" + group.getInterface() |
| 816 | + " peer=" + deviceAddress + " go_dev_addr=" + group.getOwner().deviceAddress); |
| 817 | } |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 818 | } |
repo sync | 8c57bcd | 2011-08-18 16:56:36 -0700 | [diff] [blame] | 819 | |
Irfan Sheriff | ea5b16a | 2011-08-24 12:30:20 -0700 | [diff] [blame] | 820 | /* Reinvoke a persistent connection */ |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 821 | public boolean p2pReinvoke(int netId, String deviceAddress) { |
Irfan Sheriff | 86a5f5b | 2012-02-28 17:03:56 -0800 | [diff] [blame] | 822 | if (TextUtils.isEmpty(deviceAddress) || netId < 0) return false; |
Irfan Sheriff | ea5b16a | 2011-08-24 12:30:20 -0700 | [diff] [blame] | 823 | |
| 824 | return doBooleanCommand("P2P_INVITE persistent=" + netId + " peer=" + deviceAddress); |
| 825 | } |
| 826 | |
Yoshihiko Ikenaga | 0879d03 | 2012-08-16 23:37:36 +0900 | [diff] [blame] | 827 | public String p2pGetSsid(String deviceAddress) { |
| 828 | return p2pGetParam(deviceAddress, "oper_ssid"); |
| 829 | } |
Irfan Sheriff | ea5b16a | 2011-08-24 12:30:20 -0700 | [diff] [blame] | 830 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 831 | public String p2pGetDeviceAddress() { |
Irfan Sheriff | 1f09586 | 2011-12-21 12:14:05 -0800 | [diff] [blame] | 832 | String status = status(); |
Irfan Sheriff | 4be4d31 | 2011-09-03 11:03:23 -0700 | [diff] [blame] | 833 | if (status == null) return ""; |
| 834 | |
| 835 | String[] tokens = status.split("\n"); |
| 836 | for (String token : tokens) { |
| 837 | if (token.startsWith("p2p_device_address=")) { |
| 838 | String[] nameValue = token.split("="); |
| 839 | if (nameValue.length != 2) break; |
| 840 | return nameValue[1]; |
| 841 | } |
| 842 | } |
| 843 | return ""; |
| 844 | } |
| 845 | |
Irfan Sheriff | 57e42f4 | 2012-06-06 12:03:33 -0700 | [diff] [blame] | 846 | public int getGroupCapability(String deviceAddress) { |
| 847 | int gc = 0; |
| 848 | if (TextUtils.isEmpty(deviceAddress)) return gc; |
| 849 | String peerInfo = p2pPeer(deviceAddress); |
| 850 | if (TextUtils.isEmpty(peerInfo)) return gc; |
| 851 | |
| 852 | String[] tokens = peerInfo.split("\n"); |
| 853 | for (String token : tokens) { |
| 854 | if (token.startsWith("group_capab=")) { |
| 855 | String[] nameValue = token.split("="); |
| 856 | if (nameValue.length != 2) break; |
| 857 | try { |
| 858 | return Integer.decode(nameValue[1]); |
| 859 | } catch(NumberFormatException e) { |
| 860 | return gc; |
| 861 | } |
| 862 | } |
| 863 | } |
| 864 | return gc; |
| 865 | } |
| 866 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 867 | public String p2pPeer(String deviceAddress) { |
repo sync | 8c57bcd | 2011-08-18 16:56:36 -0700 | [diff] [blame] | 868 | return doStringCommand("P2P_PEER " + deviceAddress); |
| 869 | } |
Irfan Sheriff | 21ba815 | 2012-04-04 16:22:21 -0700 | [diff] [blame] | 870 | |
Yoshihiko Ikenaga | 0879d03 | 2012-08-16 23:37:36 +0900 | [diff] [blame] | 871 | private String p2pGetParam(String deviceAddress, String key) { |
| 872 | if (deviceAddress == null) return null; |
| 873 | |
| 874 | String peerInfo = p2pPeer(deviceAddress); |
| 875 | if (peerInfo == null) return null; |
| 876 | String[] tokens= peerInfo.split("\n"); |
| 877 | |
| 878 | key += "="; |
| 879 | for (String token : tokens) { |
| 880 | if (token.startsWith(key)) { |
| 881 | String[] nameValue = token.split("="); |
| 882 | if (nameValue.length != 2) break; |
| 883 | return nameValue[1]; |
| 884 | } |
| 885 | } |
| 886 | return null; |
| 887 | } |
| 888 | |
Irfan Sheriff | 21ba815 | 2012-04-04 16:22:21 -0700 | [diff] [blame] | 889 | public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) { |
| 890 | /* |
| 891 | * P2P_SERVICE_ADD bonjour <query hexdump> <RDATA hexdump> |
| 892 | * P2P_SERVICE_ADD upnp <version hex> <service> |
| 893 | * |
| 894 | * e.g) |
| 895 | * [Bonjour] |
| 896 | * # IP Printing over TCP (PTR) (RDATA=MyPrinter._ipp._tcp.local.) |
| 897 | * P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027 |
| 898 | * # IP Printing over TCP (TXT) (RDATA=txtvers=1,pdl=application/postscript) |
| 899 | * P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 |
| 900 | * 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074 |
| 901 | * |
| 902 | * [UPnP] |
| 903 | * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012 |
| 904 | * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice |
| 905 | * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp |
| 906 | * -org:device:InternetGatewayDevice:1 |
| 907 | * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9322-123456789012::urn:schemas-upnp |
| 908 | * -org:service:ContentDirectory:2 |
| 909 | */ |
| 910 | for (String s : servInfo.getSupplicantQueryList()) { |
| 911 | String command = "P2P_SERVICE_ADD"; |
| 912 | command += (" " + s); |
| 913 | if (!doBooleanCommand(command)) { |
| 914 | return false; |
| 915 | } |
| 916 | } |
| 917 | return true; |
| 918 | } |
| 919 | |
| 920 | public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) { |
| 921 | /* |
| 922 | * P2P_SERVICE_DEL bonjour <query hexdump> |
| 923 | * P2P_SERVICE_DEL upnp <version hex> <service> |
| 924 | */ |
| 925 | for (String s : servInfo.getSupplicantQueryList()) { |
| 926 | String command = "P2P_SERVICE_DEL "; |
| 927 | |
| 928 | String[] data = s.split(" "); |
| 929 | if (data.length < 2) { |
| 930 | return false; |
| 931 | } |
| 932 | if ("upnp".equals(data[0])) { |
| 933 | command += s; |
| 934 | } else if ("bonjour".equals(data[0])) { |
| 935 | command += data[0]; |
| 936 | command += (" " + data[1]); |
| 937 | } else { |
| 938 | return false; |
| 939 | } |
| 940 | if (!doBooleanCommand(command)) { |
| 941 | return false; |
| 942 | } |
| 943 | } |
| 944 | return true; |
| 945 | } |
| 946 | |
| 947 | public boolean p2pServiceFlush() { |
| 948 | return doBooleanCommand("P2P_SERVICE_FLUSH"); |
| 949 | } |
| 950 | |
| 951 | public String p2pServDiscReq(String addr, String query) { |
| 952 | String command = "P2P_SERV_DISC_REQ"; |
| 953 | command += (" " + addr); |
| 954 | command += (" " + query); |
| 955 | |
| 956 | return doStringCommand(command); |
| 957 | } |
| 958 | |
| 959 | public boolean p2pServDiscCancelReq(String id) { |
| 960 | return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id); |
| 961 | } |
Irfan Sheriff | 8b485ad | 2013-03-28 10:15:44 -0700 | [diff] [blame] | 962 | |
| 963 | /* Set the current mode of miracast operation. |
| 964 | * 0 = disabled |
| 965 | * 1 = operating as source |
| 966 | * 2 = operating as sink |
| 967 | */ |
| 968 | public void setMiracastMode(int mode) { |
| 969 | // Note: optional feature on the driver. It is ok for this to fail. |
| 970 | doBooleanCommand("DRIVER MIRACAST " + mode); |
| 971 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | } |