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