The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | |
| 17 | #define LOG_TAG "wifi" |
| 18 | |
| 19 | #include "jni.h" |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 20 | #include <ScopedUtfChars.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/misc.h> |
| 22 | #include <android_runtime/AndroidRuntime.h> |
| 23 | #include <utils/Log.h> |
Zheng BaoZhong | 038e315 | 2009-10-10 08:07:44 -0400 | [diff] [blame] | 24 | #include <utils/String16.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| 26 | #include "wifi.h" |
| 27 | |
| 28 | #define WIFI_PKG_NAME "android/net/wifi/WifiNative" |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 29 | #define BUF_SIZE 256 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 33 | static jboolean sScanModeActive = false; |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | static int doCommand(const char *cmd, char *replybuf, int replybuflen) |
| 36 | { |
| 37 | size_t reply_len = replybuflen - 1; |
| 38 | |
| 39 | if (::wifi_command(cmd, replybuf, &reply_len) != 0) |
| 40 | return -1; |
| 41 | else { |
| 42 | // Strip off trailing newline |
| 43 | if (reply_len > 0 && replybuf[reply_len-1] == '\n') |
| 44 | replybuf[reply_len-1] = '\0'; |
| 45 | else |
| 46 | replybuf[reply_len] = '\0'; |
| 47 | return 0; |
| 48 | } |
| 49 | } |
| 50 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 51 | static jint doIntCommand(const char* fmt, ...) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 53 | char buf[BUF_SIZE]; |
| 54 | va_list args; |
| 55 | va_start(args, fmt); |
| 56 | int byteCount = vsnprintf(buf, sizeof(buf), fmt, args); |
| 57 | va_end(args); |
| 58 | if (byteCount < 0 || byteCount >= BUF_SIZE) { |
| 59 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | } |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 61 | char reply[BUF_SIZE]; |
| 62 | if (doCommand(buf, reply, sizeof(reply)) != 0) { |
| 63 | return -1; |
| 64 | } |
| 65 | return static_cast<jint>(atoi(reply)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 68 | static jboolean doBooleanCommand(const char* expect, const char* fmt, ...) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 70 | char buf[BUF_SIZE]; |
| 71 | va_list args; |
| 72 | va_start(args, fmt); |
| 73 | int byteCount = vsnprintf(buf, sizeof(buf), fmt, args); |
| 74 | va_end(args); |
| 75 | if (byteCount < 0 || byteCount >= BUF_SIZE) { |
| 76 | return JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | } |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 78 | char reply[BUF_SIZE]; |
| 79 | if (doCommand(buf, reply, sizeof(reply)) != 0) { |
| 80 | return JNI_FALSE; |
| 81 | } |
| 82 | return (strcmp(reply, expect) == 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // Send a command to the supplicant, and return the reply as a String |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 86 | static jstring doStringCommand(JNIEnv* env, const char* fmt, ...) { |
| 87 | char buf[BUF_SIZE]; |
| 88 | va_list args; |
| 89 | va_start(args, fmt); |
| 90 | int byteCount = vsnprintf(buf, sizeof(buf), fmt, args); |
| 91 | va_end(args); |
| 92 | if (byteCount < 0 || byteCount >= BUF_SIZE) { |
| 93 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | } |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 95 | char reply[4096]; |
| 96 | if (doCommand(buf, reply, sizeof(reply)) != 0) { |
| 97 | return NULL; |
| 98 | } |
| 99 | // TODO: why not just NewStringUTF? |
| 100 | String16 str((char *)reply); |
| 101 | return env->NewString((const jchar *)str.string(), str.size()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 104 | static jboolean android_net_wifi_isDriverLoaded(JNIEnv* env, jobject) |
Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 105 | { |
| 106 | return (jboolean)(::is_wifi_driver_loaded() == 1); |
| 107 | } |
| 108 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 109 | static jboolean android_net_wifi_loadDriver(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | { |
| 111 | return (jboolean)(::wifi_load_driver() == 0); |
| 112 | } |
| 113 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 114 | static jboolean android_net_wifi_unloadDriver(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | { |
| 116 | return (jboolean)(::wifi_unload_driver() == 0); |
| 117 | } |
| 118 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 119 | static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | { |
| 121 | return (jboolean)(::wifi_start_supplicant() == 0); |
| 122 | } |
| 123 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 124 | static jboolean android_net_wifi_stopSupplicant(JNIEnv* env, jobject) |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 125 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 126 | return doBooleanCommand("OK", "TERMINATE"); |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 129 | static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | { |
| 131 | return (jboolean)(::wifi_stop_supplicant() == 0); |
| 132 | } |
| 133 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 134 | static jboolean android_net_wifi_connectToSupplicant(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | { |
| 136 | return (jboolean)(::wifi_connect_to_supplicant() == 0); |
| 137 | } |
| 138 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 139 | static void android_net_wifi_closeSupplicantConnection(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | { |
| 141 | ::wifi_close_supplicant_connection(); |
| 142 | } |
| 143 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 144 | static jstring android_net_wifi_waitForEvent(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | { |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 146 | char buf[BUF_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | |
| 148 | int nread = ::wifi_wait_for_event(buf, sizeof buf); |
| 149 | if (nread > 0) { |
| 150 | return env->NewStringUTF(buf); |
| 151 | } else { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 152 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 156 | static jstring android_net_wifi_listNetworksCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | { |
| 158 | return doStringCommand(env, "LIST_NETWORKS"); |
| 159 | } |
| 160 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 161 | static jint android_net_wifi_addNetworkCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | { |
| 163 | return doIntCommand("ADD_NETWORK"); |
| 164 | } |
| 165 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 166 | static jboolean android_net_wifi_wpsPbcCommand(JNIEnv* env, jobject, jstring javaBssid) |
Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 167 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 168 | ScopedUtfChars bssid(env, javaBssid); |
| 169 | if (bssid.c_str() == NULL) { |
| 170 | return JNI_FALSE; |
Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 171 | } |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 172 | return doBooleanCommand("OK", "WPS_PBC %s", bssid.c_str()); |
Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 175 | static jboolean android_net_wifi_wpsPinFromAccessPointCommand(JNIEnv* env, jobject, |
| 176 | jstring javaBssid, jstring javaApPin) |
Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 177 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 178 | ScopedUtfChars bssid(env, javaBssid); |
| 179 | if (bssid.c_str() == NULL) { |
| 180 | return JNI_FALSE; |
Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 181 | } |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 182 | ScopedUtfChars apPin(env, javaApPin); |
| 183 | if (apPin.c_str() == NULL) { |
| 184 | return JNI_FALSE; |
| 185 | } |
| 186 | return doBooleanCommand("OK", "WPS_REG %s %s", bssid.c_str(), apPin.c_str()); |
Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 189 | static jstring android_net_wifi_wpsPinFromDeviceCommand(JNIEnv* env, jobject, jstring javaBssid) |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 190 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 191 | ScopedUtfChars bssid(env, javaBssid); |
| 192 | if (bssid.c_str() == NULL) { |
Irfan Sheriff | 02fb46a | 2010-12-08 11:27:37 -0800 | [diff] [blame] | 193 | return NULL; |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 194 | } |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 195 | return doStringCommand(env, "WPS_PIN %s", bssid.c_str()); |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 198 | static jboolean android_net_wifi_setCountryCodeCommand(JNIEnv* env, jobject, jstring javaCountry) |
Irfan Sheriff | ed4f28b | 2010-10-29 15:32:10 -0700 | [diff] [blame] | 199 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 200 | ScopedUtfChars country(env, javaCountry); |
| 201 | if (country.c_str() == NULL) { |
| 202 | return JNI_FALSE; |
Irfan Sheriff | ed4f28b | 2010-10-29 15:32:10 -0700 | [diff] [blame] | 203 | } |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 204 | return doBooleanCommand("OK", "DRIVER COUNTRY %s", country.c_str()); |
Irfan Sheriff | ed4f28b | 2010-10-29 15:32:10 -0700 | [diff] [blame] | 205 | } |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | static jboolean android_net_wifi_setNetworkVariableCommand(JNIEnv* env, |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 208 | jobject, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | jint netId, |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 210 | jstring javaName, |
| 211 | jstring javaValue) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 213 | ScopedUtfChars name(env, javaName); |
| 214 | if (name.c_str() == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | return JNI_FALSE; |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 216 | } |
| 217 | ScopedUtfChars value(env, javaValue); |
| 218 | if (value.c_str() == NULL) { |
| 219 | return JNI_FALSE; |
| 220 | } |
| 221 | return doBooleanCommand("OK", "SET_NETWORK %d %s %s", netId, name.c_str(), value.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static jstring android_net_wifi_getNetworkVariableCommand(JNIEnv* env, |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 225 | jobject, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | jint netId, |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 227 | jstring javaName) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 229 | ScopedUtfChars name(env, javaName); |
| 230 | if (name.c_str() == NULL) { |
| 231 | return NULL; |
| 232 | } |
| 233 | return doStringCommand(env, "GET_NETWORK %d %s", netId, name.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 236 | static jboolean android_net_wifi_removeNetworkCommand(JNIEnv* env, jobject, jint netId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 238 | return doBooleanCommand("OK", "REMOVE_NETWORK %d", netId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static jboolean android_net_wifi_enableNetworkCommand(JNIEnv* env, |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 242 | jobject, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | jint netId, |
| 244 | jboolean disableOthers) |
| 245 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 246 | return doBooleanCommand("OK", "%s_NETWORK %d", disableOthers ? "SELECT" : "ENABLE", netId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 249 | static jboolean android_net_wifi_disableNetworkCommand(JNIEnv* env, jobject, jint netId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 251 | return doBooleanCommand("OK", "DISABLE_NETWORK %d", netId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 254 | static jstring android_net_wifi_statusCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | { |
| 256 | return doStringCommand(env, "STATUS"); |
| 257 | } |
| 258 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 259 | static jboolean android_net_wifi_pingCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 261 | return doBooleanCommand("PONG", "PING"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 264 | static jstring android_net_wifi_scanResultsCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | { |
| 266 | return doStringCommand(env, "SCAN_RESULTS"); |
| 267 | } |
| 268 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 269 | static jboolean android_net_wifi_disconnectCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 271 | return doBooleanCommand("OK", "DISCONNECT"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 274 | static jboolean android_net_wifi_reconnectCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 276 | return doBooleanCommand("OK", "RECONNECT"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | } |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 278 | static jboolean android_net_wifi_reassociateCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 280 | return doBooleanCommand("OK", "REASSOCIATE"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 283 | static jboolean doSetScanMode(jboolean setActive) |
| 284 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 285 | return doBooleanCommand("OK", (setActive ? "DRIVER SCAN-ACTIVE" : "DRIVER SCAN-PASSIVE")); |
Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 288 | static jboolean android_net_wifi_scanCommand(JNIEnv* env, jobject, jboolean forceActive) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | { |
| 290 | jboolean result; |
Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | // Ignore any error from setting the scan mode. |
| 293 | // The scan will still work. |
Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 294 | if (forceActive && !sScanModeActive) |
| 295 | doSetScanMode(true); |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 296 | result = doBooleanCommand("OK", "SCAN"); |
Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 297 | if (forceActive && !sScanModeActive) |
| 298 | doSetScanMode(sScanModeActive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | return result; |
| 300 | } |
| 301 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 302 | static jboolean android_net_wifi_setScanModeCommand(JNIEnv* env, jobject, jboolean setActive) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | { |
Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 304 | sScanModeActive = setActive; |
| 305 | return doSetScanMode(setActive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 308 | static jboolean android_net_wifi_startDriverCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 310 | return doBooleanCommand("OK", "DRIVER START"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 313 | static jboolean android_net_wifi_stopDriverCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 315 | return doBooleanCommand("OK", "DRIVER STOP"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 318 | static jboolean android_net_wifi_startPacketFiltering(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 320 | return doBooleanCommand("OK", "DRIVER RXFILTER-ADD 0") |
| 321 | && doBooleanCommand("OK", "DRIVER RXFILTER-ADD 1") |
| 322 | && doBooleanCommand("OK", "DRIVER RXFILTER-ADD 3") |
| 323 | && doBooleanCommand("OK", "DRIVER RXFILTER-START"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 326 | static jboolean android_net_wifi_stopPacketFiltering(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 328 | jboolean result = doBooleanCommand("OK", "DRIVER RXFILTER-STOP"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | if (result) { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 330 | (void)doBooleanCommand("OK", "DRIVER RXFILTER-REMOVE 3"); |
| 331 | (void)doBooleanCommand("OK", "DRIVER RXFILTER-REMOVE 1"); |
| 332 | (void)doBooleanCommand("OK", "DRIVER RXFILTER-REMOVE 0"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | return result; |
| 336 | } |
| 337 | |
Robert Greenwalt | 91f22f90 | 2009-06-08 18:15:21 -0700 | [diff] [blame] | 338 | static jint android_net_wifi_getRssiHelper(const char *cmd) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | { |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 340 | char reply[BUF_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | int rssi = -200; |
| 342 | |
Robert Greenwalt | 91f22f90 | 2009-06-08 18:15:21 -0700 | [diff] [blame] | 343 | if (doCommand(cmd, reply, sizeof(reply)) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | return (jint)-1; |
| 345 | } |
Robert Greenwalt | 91f22f90 | 2009-06-08 18:15:21 -0700 | [diff] [blame] | 346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | // reply comes back in the form "<SSID> rssi XX" where XX is the |
| 348 | // number we're interested in. if we're associating, it returns "OK". |
Mike Lockwood | c5ad0f4 | 2009-05-25 22:34:20 -0400 | [diff] [blame] | 349 | // beware - <SSID> can contain spaces. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | if (strcmp(reply, "OK") != 0) { |
Mike Lockwood | b20148b | 2009-08-04 11:32:52 -0400 | [diff] [blame] | 351 | // beware of trailing spaces |
| 352 | char* end = reply + strlen(reply); |
| 353 | while (end > reply && end[-1] == ' ') { |
| 354 | end--; |
| 355 | } |
| 356 | *end = 0; |
| 357 | |
Mike Lockwood | c5ad0f4 | 2009-05-25 22:34:20 -0400 | [diff] [blame] | 358 | char* lastSpace = strrchr(reply, ' '); |
| 359 | // lastSpace should be preceded by "rssi" and followed by the value |
Stan Chesnutt | 320b56d | 2011-02-08 14:50:30 -0800 | [diff] [blame] | 360 | if (lastSpace && !strncasecmp(lastSpace - 4, "rssi", 4)) { |
Mike Lockwood | c5ad0f4 | 2009-05-25 22:34:20 -0400 | [diff] [blame] | 361 | sscanf(lastSpace + 1, "%d", &rssi); |
| 362 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | } |
| 364 | return (jint)rssi; |
| 365 | } |
| 366 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 367 | static jint android_net_wifi_getRssiCommand(JNIEnv* env, jobject) |
Robert Greenwalt | 91f22f90 | 2009-06-08 18:15:21 -0700 | [diff] [blame] | 368 | { |
| 369 | return android_net_wifi_getRssiHelper("DRIVER RSSI"); |
| 370 | } |
| 371 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 372 | static jint android_net_wifi_getRssiApproxCommand(JNIEnv* env, jobject) |
Robert Greenwalt | 91f22f90 | 2009-06-08 18:15:21 -0700 | [diff] [blame] | 373 | { |
| 374 | return android_net_wifi_getRssiHelper("DRIVER RSSI-APPROX"); |
| 375 | } |
| 376 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 377 | static jint android_net_wifi_getLinkSpeedCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | { |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 379 | char reply[BUF_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | int linkspeed; |
| 381 | |
| 382 | if (doCommand("DRIVER LINKSPEED", reply, sizeof(reply)) != 0) { |
| 383 | return (jint)-1; |
| 384 | } |
| 385 | // reply comes back in the form "LinkSpeed XX" where XX is the |
| 386 | // number we're interested in. |
| 387 | sscanf(reply, "%*s %u", &linkspeed); |
| 388 | return (jint)linkspeed; |
| 389 | } |
| 390 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 391 | static jstring android_net_wifi_getMacAddressCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | { |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 393 | char reply[BUF_SIZE]; |
| 394 | char buf[BUF_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | |
| 396 | if (doCommand("DRIVER MACADDR", reply, sizeof(reply)) != 0) { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 397 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | } |
| 399 | // reply comes back in the form "Macaddr = XX.XX.XX.XX.XX.XX" where XX |
| 400 | // is the part of the string we're interested in. |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 401 | if (sscanf(reply, "%*s = %255s", buf) == 1) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | return env->NewStringUTF(buf); |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 403 | } |
| 404 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 407 | static jboolean android_net_wifi_setPowerModeCommand(JNIEnv* env, jobject, jint mode) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 409 | return doBooleanCommand("OK", "DRIVER POWERMODE %d", mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 412 | static jint android_net_wifi_getPowerModeCommand(JNIEnv* env, jobject) |
Mikael Kanstrup | ea8bd1d | 2010-04-07 16:45:58 +0200 | [diff] [blame] | 413 | { |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 414 | char reply[BUF_SIZE]; |
Mikael Kanstrup | ea8bd1d | 2010-04-07 16:45:58 +0200 | [diff] [blame] | 415 | int power; |
| 416 | |
| 417 | if (doCommand("DRIVER GETPOWER", reply, sizeof(reply)) != 0) { |
| 418 | return (jint)-1; |
| 419 | } |
| 420 | // reply comes back in the form "powermode = XX" where XX is the |
| 421 | // number we're interested in. |
Irfan Sheriff | 1a5b609 | 2011-05-04 14:16:44 -0700 | [diff] [blame] | 422 | if (sscanf(reply, "%*s = %u", &power) != 1) { |
| 423 | return (jint)-1; |
| 424 | } |
Mikael Kanstrup | ea8bd1d | 2010-04-07 16:45:58 +0200 | [diff] [blame] | 425 | return (jint)power; |
| 426 | } |
| 427 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 428 | static jboolean android_net_wifi_setBandCommand(JNIEnv* env, jobject, jint band) |
Irfan Sheriff | 25c9bf2 | 2010-09-02 12:48:20 -0700 | [diff] [blame] | 429 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 430 | return doBooleanCommand("OK", "DRIVER SETBAND %d", band); |
Irfan Sheriff | 25c9bf2 | 2010-09-02 12:48:20 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 433 | static jint android_net_wifi_getBandCommand(JNIEnv* env, jobject) |
Irfan Sheriff | 25c9bf2 | 2010-09-02 12:48:20 -0700 | [diff] [blame] | 434 | { |
| 435 | char reply[25]; |
| 436 | int band; |
| 437 | |
| 438 | if (doCommand("DRIVER GETBAND", reply, sizeof(reply)) != 0) { |
| 439 | return (jint)-1; |
| 440 | } |
| 441 | // reply comes back in the form "Band X" where X is the |
| 442 | // number we're interested in. |
| 443 | sscanf(reply, "%*s %u", &band); |
| 444 | return (jint)band; |
| 445 | } |
| 446 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 447 | static jboolean android_net_wifi_setBluetoothCoexistenceModeCommand(JNIEnv* env, jobject, jint mode) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 449 | return doBooleanCommand("OK", "DRIVER BTCOEXMODE %d", mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 452 | static jboolean android_net_wifi_setBluetoothCoexistenceScanModeCommand(JNIEnv* env, jobject, jboolean setCoexScanMode) |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 453 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 454 | return doBooleanCommand("OK", "DRIVER BTCOEXSCAN-%s", setCoexScanMode ? "START" : "STOP"); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 457 | static jboolean android_net_wifi_saveConfigCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | { |
| 459 | // Make sure we never write out a value for AP_SCAN other than 1 |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 460 | (void)doBooleanCommand("OK", "AP_SCAN 1"); |
| 461 | return doBooleanCommand("OK", "SAVE_CONFIG"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 464 | static jboolean android_net_wifi_reloadConfigCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 466 | return doBooleanCommand("OK", "RECONFIGURE"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 469 | static jboolean android_net_wifi_setScanResultHandlingCommand(JNIEnv* env, jobject, jint mode) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 471 | return doBooleanCommand("OK", "AP_SCAN %d", mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 474 | static jboolean android_net_wifi_addToBlacklistCommand(JNIEnv* env, jobject, jstring javaBssid) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 476 | ScopedUtfChars bssid(env, javaBssid); |
| 477 | if (bssid.c_str() == NULL) { |
| 478 | return JNI_FALSE; |
| 479 | } |
| 480 | return doBooleanCommand("OK", "BLACKLIST %s", bssid.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 483 | static jboolean android_net_wifi_clearBlacklistCommand(JNIEnv* env, jobject) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 485 | return doBooleanCommand("OK", "BLACKLIST clear"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 488 | static jboolean android_net_wifi_setSuspendOptimizationsCommand(JNIEnv* env, jobject, jboolean enabled) |
Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 489 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 490 | return doBooleanCommand("OK", "DRIVER SETSUSPENDOPT %d", enabled ? 0 : 1); |
Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 493 | static void android_net_wifi_enableBackgroundScanCommand(JNIEnv* env, jobject, jboolean enable) |
Irfan Sheriff | fcc0845 | 2011-02-17 16:44:54 -0800 | [diff] [blame] | 494 | { |
| 495 | //Note: BGSCAN-START and BGSCAN-STOP are documented in core/res/res/values/config.xml |
| 496 | //and will need an update if the names are changed |
| 497 | if (enable) { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 498 | doBooleanCommand("OK", "DRIVER BGSCAN-START"); |
| 499 | } else { |
| 500 | doBooleanCommand("OK", "DRIVER BGSCAN-STOP"); |
Irfan Sheriff | fcc0845 | 2011-02-17 16:44:54 -0800 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 504 | static void android_net_wifi_setScanIntervalCommand(JNIEnv* env, jobject, jint scanInterval) |
Irfan Sheriff | 2b7f638 | 2011-03-25 14:29:19 -0700 | [diff] [blame] | 505 | { |
Elliott Hughes | f17b971 | 2011-04-12 16:12:09 -0700 | [diff] [blame] | 506 | doBooleanCommand("OK", "SCAN_INTERVAL %d", scanInterval); |
Irfan Sheriff | 2b7f638 | 2011-03-25 14:29:19 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | // ---------------------------------------------------------------------------- |
| 511 | |
| 512 | /* |
| 513 | * JNI registration. |
| 514 | */ |
| 515 | static JNINativeMethod gWifiMethods[] = { |
| 516 | /* name, signature, funcPtr */ |
| 517 | |
| 518 | { "loadDriver", "()Z", (void *)android_net_wifi_loadDriver }, |
Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 519 | { "isDriverLoaded", "()Z", (void *)android_net_wifi_isDriverLoaded}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | { "unloadDriver", "()Z", (void *)android_net_wifi_unloadDriver }, |
| 521 | { "startSupplicant", "()Z", (void *)android_net_wifi_startSupplicant }, |
Irfan Sheriff | 5d001ea | 2010-12-15 10:29:49 -0800 | [diff] [blame] | 522 | { "stopSupplicant", "()Z", (void*) android_net_wifi_stopSupplicant }, |
Irfan Sheriff | 96071a7 | 2010-12-14 11:29:23 -0800 | [diff] [blame] | 523 | { "killSupplicant", "()Z", (void *)android_net_wifi_killSupplicant }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | { "connectToSupplicant", "()Z", (void *)android_net_wifi_connectToSupplicant }, |
| 525 | { "closeSupplicantConnection", "()V", (void *)android_net_wifi_closeSupplicantConnection }, |
| 526 | |
| 527 | { "listNetworksCommand", "()Ljava/lang/String;", |
| 528 | (void*) android_net_wifi_listNetworksCommand }, |
| 529 | { "addNetworkCommand", "()I", (void*) android_net_wifi_addNetworkCommand }, |
| 530 | { "setNetworkVariableCommand", "(ILjava/lang/String;Ljava/lang/String;)Z", |
| 531 | (void*) android_net_wifi_setNetworkVariableCommand }, |
| 532 | { "getNetworkVariableCommand", "(ILjava/lang/String;)Ljava/lang/String;", |
| 533 | (void*) android_net_wifi_getNetworkVariableCommand }, |
| 534 | { "removeNetworkCommand", "(I)Z", (void*) android_net_wifi_removeNetworkCommand }, |
| 535 | { "enableNetworkCommand", "(IZ)Z", (void*) android_net_wifi_enableNetworkCommand }, |
| 536 | { "disableNetworkCommand", "(I)Z", (void*) android_net_wifi_disableNetworkCommand }, |
| 537 | { "waitForEvent", "()Ljava/lang/String;", (void*) android_net_wifi_waitForEvent }, |
| 538 | { "statusCommand", "()Ljava/lang/String;", (void*) android_net_wifi_statusCommand }, |
| 539 | { "scanResultsCommand", "()Ljava/lang/String;", (void*) android_net_wifi_scanResultsCommand }, |
| 540 | { "pingCommand", "()Z", (void *)android_net_wifi_pingCommand }, |
| 541 | { "disconnectCommand", "()Z", (void *)android_net_wifi_disconnectCommand }, |
| 542 | { "reconnectCommand", "()Z", (void *)android_net_wifi_reconnectCommand }, |
| 543 | { "reassociateCommand", "()Z", (void *)android_net_wifi_reassociateCommand }, |
Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 544 | { "scanCommand", "(Z)Z", (void*) android_net_wifi_scanCommand }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | { "setScanModeCommand", "(Z)Z", (void*) android_net_wifi_setScanModeCommand }, |
| 546 | { "startDriverCommand", "()Z", (void*) android_net_wifi_startDriverCommand }, |
| 547 | { "stopDriverCommand", "()Z", (void*) android_net_wifi_stopDriverCommand }, |
| 548 | { "startPacketFiltering", "()Z", (void*) android_net_wifi_startPacketFiltering }, |
| 549 | { "stopPacketFiltering", "()Z", (void*) android_net_wifi_stopPacketFiltering }, |
| 550 | { "setPowerModeCommand", "(I)Z", (void*) android_net_wifi_setPowerModeCommand }, |
Mikael Kanstrup | ea8bd1d | 2010-04-07 16:45:58 +0200 | [diff] [blame] | 551 | { "getPowerModeCommand", "()I", (void*) android_net_wifi_getPowerModeCommand }, |
Irfan Sheriff | 25c9bf2 | 2010-09-02 12:48:20 -0700 | [diff] [blame] | 552 | { "setBandCommand", "(I)Z", (void*) android_net_wifi_setBandCommand}, |
| 553 | { "getBandCommand", "()I", (void*) android_net_wifi_getBandCommand}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | { "setBluetoothCoexistenceModeCommand", "(I)Z", |
| 555 | (void*) android_net_wifi_setBluetoothCoexistenceModeCommand }, |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 556 | { "setBluetoothCoexistenceScanModeCommand", "(Z)Z", |
| 557 | (void*) android_net_wifi_setBluetoothCoexistenceScanModeCommand }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | { "getRssiCommand", "()I", (void*) android_net_wifi_getRssiCommand }, |
Robert Greenwalt | 91f22f90 | 2009-06-08 18:15:21 -0700 | [diff] [blame] | 559 | { "getRssiApproxCommand", "()I", |
| 560 | (void*) android_net_wifi_getRssiApproxCommand}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | { "getLinkSpeedCommand", "()I", (void*) android_net_wifi_getLinkSpeedCommand }, |
| 562 | { "getMacAddressCommand", "()Ljava/lang/String;", (void*) android_net_wifi_getMacAddressCommand }, |
| 563 | { "saveConfigCommand", "()Z", (void*) android_net_wifi_saveConfigCommand }, |
| 564 | { "reloadConfigCommand", "()Z", (void*) android_net_wifi_reloadConfigCommand }, |
| 565 | { "setScanResultHandlingCommand", "(I)Z", (void*) android_net_wifi_setScanResultHandlingCommand }, |
| 566 | { "addToBlacklistCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_addToBlacklistCommand }, |
| 567 | { "clearBlacklistCommand", "()Z", (void*) android_net_wifi_clearBlacklistCommand }, |
Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 568 | { "startWpsPbcCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_wpsPbcCommand }, |
Irfan Sheriff | 02fb46a | 2010-12-08 11:27:37 -0800 | [diff] [blame] | 569 | { "startWpsWithPinFromAccessPointCommand", "(Ljava/lang/String;Ljava/lang/String;)Z", |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 570 | (void*) android_net_wifi_wpsPinFromAccessPointCommand }, |
Irfan Sheriff | 02fb46a | 2010-12-08 11:27:37 -0800 | [diff] [blame] | 571 | { "startWpsWithPinFromDeviceCommand", "(Ljava/lang/String;)Ljava/lang/String;", |
Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 572 | (void*) android_net_wifi_wpsPinFromDeviceCommand }, |
Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 573 | { "setSuspendOptimizationsCommand", "(Z)Z", |
| 574 | (void*) android_net_wifi_setSuspendOptimizationsCommand}, |
Irfan Sheriff | ed4f28b | 2010-10-29 15:32:10 -0700 | [diff] [blame] | 575 | { "setCountryCodeCommand", "(Ljava/lang/String;)Z", |
| 576 | (void*) android_net_wifi_setCountryCodeCommand}, |
Irfan Sheriff | 2b7f638 | 2011-03-25 14:29:19 -0700 | [diff] [blame] | 577 | { "enableBackgroundScanCommand", "(Z)V", (void*) android_net_wifi_enableBackgroundScanCommand}, |
| 578 | { "setScanIntervalCommand", "(I)V", (void*) android_net_wifi_setScanIntervalCommand}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | }; |
| 580 | |
| 581 | int register_android_net_wifi_WifiManager(JNIEnv* env) |
| 582 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | return AndroidRuntime::registerNativeMethods(env, |
| 584 | WIFI_PKG_NAME, gWifiMethods, NELEM(gWifiMethods)); |
| 585 | } |
| 586 | |
| 587 | }; // namespace android |