Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [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" |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 20 | #include "JniConstants.h" |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 21 | #include <ScopedUtfChars.h> |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 22 | #include <ScopedBytes.h> |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 23 | //#include <utils/misc.h> |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 24 | #include <android_runtime/AndroidRuntime.h> |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 25 | //#include <utils/Log.h> |
| 26 | //#include <utils/String16.h> |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 27 | #include <ctype.h> |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 28 | #include <sys/socket.h> |
| 29 | #include <linux/if.h> |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 30 | #include "wifi.h" |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 31 | #include "wifi_hal.h" |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 32 | #include "jni_helper.h" |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 33 | #include "rtt.h" |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 34 | #include "wifi_hal_stub.h" |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 35 | #define REPLY_BUF_SIZE 4096 // wpa_supplicant's maximum size. |
| 36 | #define EVENT_BUF_SIZE 2048 |
| 37 | |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 38 | #define CONVERT_LINE_LEN 2048 |
| 39 | #define CHARSET_CN ("gbk") |
| 40 | |
| 41 | #include "com_android_server_wifi_Gbk2Utf.h" |
| 42 | |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 43 | namespace android { |
| 44 | |
| 45 | static jint DBG = false; |
| 46 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 47 | //Please put all HAL function call here and call from the function table instead of directly call |
| 48 | static wifi_hal_fn hal_fn; |
| 49 | int init_wifi_hal_func_table(wifi_hal_fn *hal_fn) { |
| 50 | if (hal_fn == NULL) { |
| 51 | return -1; |
| 52 | } |
| 53 | hal_fn->wifi_initialize = wifi_initialize_stub; |
| 54 | hal_fn->wifi_cleanup = wifi_cleanup_stub; |
| 55 | hal_fn->wifi_event_loop = wifi_event_loop_stub; |
| 56 | hal_fn->wifi_get_error_info = wifi_get_error_info_stub; |
| 57 | hal_fn->wifi_get_supported_feature_set = wifi_get_supported_feature_set_stub; |
| 58 | hal_fn->wifi_get_concurrency_matrix = wifi_get_concurrency_matrix_stub; |
| 59 | hal_fn->wifi_set_scanning_mac_oui = wifi_set_scanning_mac_oui_stub; |
| 60 | hal_fn->wifi_get_supported_channels = wifi_get_supported_channels_stub; |
| 61 | hal_fn->wifi_is_epr_supported = wifi_is_epr_supported_stub; |
| 62 | hal_fn->wifi_get_ifaces = wifi_get_ifaces_stub; |
| 63 | hal_fn->wifi_get_iface_name = wifi_get_iface_name_stub; |
| 64 | hal_fn->wifi_reset_iface_event_handler = wifi_reset_iface_event_handler_stub; |
| 65 | hal_fn->wifi_start_gscan = wifi_start_gscan_stub; |
| 66 | hal_fn->wifi_stop_gscan = wifi_stop_gscan_stub; |
xin He | 6f7fe1c | 2015-04-02 21:10:12 +0000 | [diff] [blame] | 67 | hal_fn->wifi_get_cached_gscan_results = wifi_get_cached_gscan_results_stub; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 68 | hal_fn->wifi_set_bssid_hotlist = wifi_set_bssid_hotlist_stub; |
| 69 | hal_fn->wifi_reset_bssid_hotlist = wifi_reset_bssid_hotlist_stub; |
| 70 | hal_fn->wifi_set_significant_change_handler = wifi_set_significant_change_handler_stub; |
| 71 | hal_fn->wifi_reset_significant_change_handler = wifi_reset_significant_change_handler_stub; |
| 72 | hal_fn->wifi_get_gscan_capabilities = wifi_get_gscan_capabilities_stub; |
| 73 | hal_fn->wifi_set_link_stats = wifi_set_link_stats_stub; |
| 74 | hal_fn->wifi_get_link_stats = wifi_get_link_stats_stub; |
| 75 | hal_fn->wifi_clear_link_stats = wifi_clear_link_stats_stub; |
| 76 | hal_fn->wifi_get_valid_channels = wifi_get_valid_channels_stub; |
| 77 | hal_fn->wifi_rtt_range_request = wifi_rtt_range_request_stub; |
| 78 | hal_fn->wifi_rtt_range_cancel = wifi_rtt_range_cancel_stub; |
| 79 | hal_fn->wifi_get_rtt_capabilities = wifi_get_rtt_capabilities_stub; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 80 | hal_fn->wifi_start_logging = wifi_start_logging_stub; |
| 81 | hal_fn->wifi_set_epno_list = wifi_set_epno_list_stub; |
| 82 | hal_fn->wifi_set_country_code = wifi_set_country_code_stub; |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 83 | hal_fn->wifi_enable_tdls = wifi_enable_tdls_stub; |
| 84 | hal_fn->wifi_disable_tdls = wifi_disable_tdls_stub; |
| 85 | hal_fn->wifi_get_tdls_status = wifi_get_tdls_status_stub; |
| 86 | hal_fn->wifi_get_tdls_capabilities = wifi_get_tdls_capabilities_stub; |
Vinit Deshpande | 6f59b02 | 2015-05-05 11:39:47 -0700 | [diff] [blame] | 87 | hal_fn->wifi_set_nodfs_flag = wifi_set_nodfs_flag_stub; |
xinhe | 21602b3 | 2015-04-24 09:32:13 -0700 | [diff] [blame] | 88 | hal_fn->wifi_get_firmware_memory_dump = wifi_get_firmware_memory_dump_stub; |
| 89 | hal_fn->wifi_set_log_handler = wifi_set_log_handler_stub; |
JerryLee | 32cbc7a | 2015-06-17 19:19:30 -0700 | [diff] [blame] | 90 | hal_fn->wifi_reset_log_handler = wifi_reset_log_handler_stub; |
xinhe | 21602b3 | 2015-04-24 09:32:13 -0700 | [diff] [blame] | 91 | hal_fn->wifi_set_alert_handler = wifi_set_alert_handler_stub; |
Jerry Lee | 370ad50 | 2015-07-13 13:42:21 -0700 | [diff] [blame] | 92 | hal_fn->wifi_reset_alert_handler = wifi_reset_alert_handler_stub; |
xinhe | 21602b3 | 2015-04-24 09:32:13 -0700 | [diff] [blame] | 93 | hal_fn->wifi_get_firmware_version = wifi_get_firmware_version_stub; |
| 94 | hal_fn->wifi_get_ring_buffers_status = wifi_get_ring_buffers_status_stub; |
| 95 | hal_fn->wifi_get_logger_supported_feature_set = wifi_get_logger_supported_feature_set_stub; |
| 96 | hal_fn->wifi_get_ring_data = wifi_get_ring_data_stub; |
| 97 | hal_fn->wifi_get_driver_version = wifi_get_driver_version_stub; |
Vinit Deshpande | e5bf4b8 | 2015-05-13 18:38:10 -0700 | [diff] [blame] | 98 | hal_fn->wifi_set_ssid_white_list = wifi_set_ssid_white_list_stub; |
| 99 | hal_fn->wifi_set_gscan_roam_params = wifi_set_gscan_roam_params_stub; |
| 100 | hal_fn->wifi_set_bssid_preference = wifi_set_bssid_preference_stub; |
| 101 | hal_fn->wifi_enable_lazy_roam = wifi_enable_lazy_roam_stub; |
| 102 | hal_fn->wifi_set_bssid_blacklist = wifi_set_bssid_blacklist_stub; |
Ecco Park | 2723d99 | 2015-06-18 17:08:23 -0700 | [diff] [blame] | 103 | hal_fn->wifi_start_sending_offloaded_packet = wifi_start_sending_offloaded_packet_stub; |
| 104 | hal_fn->wifi_stop_sending_offloaded_packet = wifi_stop_sending_offloaded_packet_stub; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 108 | extern struct accessPointObjectItem *g_pItemList; |
| 109 | extern struct accessPointObjectItem *g_pLastNode; |
| 110 | extern pthread_mutex_t *g_pItemListMutex; |
| 111 | extern String8 *g_pCurrentSSID; |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 112 | static bool doCommand(JNIEnv* env, jstring javaCommand, |
| 113 | char* reply, size_t reply_len) { |
| 114 | ScopedUtfChars command(env, javaCommand); |
| 115 | if (command.c_str() == NULL) { |
| 116 | return false; // ScopedUtfChars already threw on error. |
| 117 | } |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 118 | if(strstr(command.c_str(), "SET_NETWORK")) { |
| 119 | if(!setNetworkVariable((char *)command.c_str())) { |
| 120 | return false; |
| 121 | } |
| 122 | } |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 123 | if (DBG) { |
| 124 | ALOGD("doCommand: %s", command.c_str()); |
| 125 | } |
| 126 | |
| 127 | --reply_len; // Ensure we have room to add NUL termination. |
| 128 | if (::wifi_command(command.c_str(), reply, &reply_len) != 0) { |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | // Strip off trailing newline. |
| 133 | if (reply_len > 0 && reply[reply_len-1] == '\n') { |
| 134 | reply[reply_len-1] = '\0'; |
| 135 | } else { |
| 136 | reply[reply_len] = '\0'; |
| 137 | } |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | static jint doIntCommand(JNIEnv* env, jstring javaCommand) { |
| 142 | char reply[REPLY_BUF_SIZE]; |
| 143 | if (!doCommand(env, javaCommand, reply, sizeof(reply))) { |
| 144 | return -1; |
| 145 | } |
| 146 | return static_cast<jint>(atoi(reply)); |
| 147 | } |
| 148 | |
| 149 | static jboolean doBooleanCommand(JNIEnv* env, jstring javaCommand) { |
| 150 | char reply[REPLY_BUF_SIZE]; |
| 151 | if (!doCommand(env, javaCommand, reply, sizeof(reply))) { |
| 152 | return JNI_FALSE; |
| 153 | } |
| 154 | return (strcmp(reply, "OK") == 0); |
| 155 | } |
| 156 | |
| 157 | // Send a command to the supplicant, and return the reply as a String. |
| 158 | static jstring doStringCommand(JNIEnv* env, jstring javaCommand) { |
| 159 | char reply[REPLY_BUF_SIZE]; |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 160 | ScopedUtfChars command(env, javaCommand); |
| 161 | if (command.c_str() == NULL) { |
| 162 | return NULL; |
| 163 | } |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 164 | if (!doCommand(env, javaCommand, reply, sizeof(reply))) { |
| 165 | return NULL; |
| 166 | } |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 167 | if (DBG) ALOGD("cmd = %s, reply: %s", command.c_str(), reply); |
| 168 | String16 str; |
| 169 | if (strstr(command.c_str(),"BSS RANGE=")) { |
| 170 | parseScanResults(str,reply); |
| 171 | } else if (strstr(command.c_str(),"GET_NETWORK") && |
| 172 | strstr(command.c_str(),"ssid") && !strstr(command.c_str(),"bssid") |
| 173 | && !strstr(command.c_str(),"scan_ssid")){ |
| 174 | constructSsid(str, reply); |
| 175 | } else { |
| 176 | str += String16((char *)reply); |
| 177 | } |
| 178 | return env->NewString((const jchar *)str.string(), str.size()); |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static jboolean android_net_wifi_isDriverLoaded(JNIEnv* env, jobject) |
| 182 | { |
| 183 | return (::is_wifi_driver_loaded() == 1); |
| 184 | } |
| 185 | |
| 186 | static jboolean android_net_wifi_loadDriver(JNIEnv* env, jobject) |
| 187 | { |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 188 | g_pItemListMutex = new pthread_mutex_t; |
| 189 | if (NULL == g_pItemListMutex) { |
| 190 | ALOGE("Failed to allocate memory for g_pItemListMutex!"); |
| 191 | return JNI_FALSE; |
| 192 | } |
| 193 | pthread_mutex_init(g_pItemListMutex, NULL); |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 194 | return (::wifi_load_driver() == 0); |
| 195 | } |
| 196 | |
| 197 | static jboolean android_net_wifi_unloadDriver(JNIEnv* env, jobject) |
| 198 | { |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 199 | if (g_pItemListMutex != NULL) { |
| 200 | pthread_mutex_lock(g_pItemListMutex); |
| 201 | struct accessPointObjectItem *pCurrentNode = g_pItemList; |
| 202 | struct accessPointObjectItem *pNextNode = NULL; |
| 203 | while (pCurrentNode) { |
| 204 | pNextNode = pCurrentNode->pNext; |
| 205 | if (NULL != pCurrentNode->ssid) { |
| 206 | delete pCurrentNode->ssid; |
| 207 | pCurrentNode->ssid = NULL; |
| 208 | } |
| 209 | if (NULL != pCurrentNode->ssid_utf8) { |
| 210 | delete pCurrentNode->ssid_utf8; |
| 211 | pCurrentNode->ssid_utf8 = NULL; |
| 212 | } |
| 213 | delete pCurrentNode; |
| 214 | pCurrentNode = pNextNode; |
| 215 | } |
| 216 | g_pItemList = NULL; |
| 217 | g_pLastNode = NULL; |
| 218 | pthread_mutex_unlock(g_pItemListMutex); |
| 219 | pthread_mutex_destroy(g_pItemListMutex); |
| 220 | delete g_pItemListMutex; |
| 221 | g_pItemListMutex = NULL; |
| 222 | } |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 223 | return (::wifi_unload_driver() == 0); |
| 224 | } |
| 225 | |
| 226 | static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jobject, jboolean p2pSupported) |
| 227 | { |
| 228 | return (::wifi_start_supplicant(p2pSupported) == 0); |
| 229 | } |
| 230 | |
| 231 | static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject, jboolean p2pSupported) |
| 232 | { |
| 233 | return (::wifi_stop_supplicant(p2pSupported) == 0); |
| 234 | } |
| 235 | |
| 236 | static jboolean android_net_wifi_connectToSupplicant(JNIEnv* env, jobject) |
| 237 | { |
| 238 | return (::wifi_connect_to_supplicant() == 0); |
| 239 | } |
| 240 | |
| 241 | static void android_net_wifi_closeSupplicantConnection(JNIEnv* env, jobject) |
| 242 | { |
| 243 | ::wifi_close_supplicant_connection(); |
| 244 | } |
| 245 | |
| 246 | static jstring android_net_wifi_waitForEvent(JNIEnv* env, jobject) |
| 247 | { |
| 248 | char buf[EVENT_BUF_SIZE]; |
| 249 | int nread = ::wifi_wait_for_event(buf, sizeof buf); |
| 250 | if (nread > 0) { |
Sravanthi Palakonda | 1a0319f | 2015-07-27 16:38:09 +0530 | [diff] [blame^] | 251 | if (strstr(buf, " SSID=") || strstr(buf, " SSID ")){ |
| 252 | constructEventSsid(buf); |
| 253 | } |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 254 | return env->NewStringUTF(buf); |
| 255 | } else { |
| 256 | return NULL; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | static jboolean android_net_wifi_doBooleanCommand(JNIEnv* env, jobject, jstring javaCommand) { |
| 261 | return doBooleanCommand(env, javaCommand); |
| 262 | } |
| 263 | |
| 264 | static jint android_net_wifi_doIntCommand(JNIEnv* env, jobject, jstring javaCommand) { |
| 265 | return doIntCommand(env, javaCommand); |
| 266 | } |
| 267 | |
| 268 | static jstring android_net_wifi_doStringCommand(JNIEnv* env, jobject, jstring javaCommand) { |
| 269 | return doStringCommand(env,javaCommand); |
| 270 | } |
| 271 | |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 272 | /* wifi_hal <==> WifiNative bridge */ |
| 273 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 274 | static jclass mCls; /* saved WifiNative object */ |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 275 | static JavaVM *mVM; /* saved JVM pointer */ |
| 276 | |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 277 | static const char *WifiHandleVarName = "sWifiHalHandle"; |
| 278 | static const char *WifiIfaceHandleVarName = "sWifiIfaceHandles"; |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 279 | static jmethodID OnScanResultsMethodID; |
| 280 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 281 | static wifi_handle getWifiHandle(JNIHelper &helper, jclass cls) { |
| 282 | return (wifi_handle) helper.getStaticLongField(cls, WifiHandleVarName); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 285 | static wifi_interface_handle getIfaceHandle(JNIHelper &helper, jclass cls, jint index) { |
| 286 | return (wifi_interface_handle) helper.getStaticLongArrayField(cls, WifiIfaceHandleVarName, index); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 289 | jboolean setSSIDField(JNIHelper helper, jobject scanResult, const char *rawSsid) { |
xinhe | 5cfd8d8 | 2015-07-28 16:34:37 -0700 | [diff] [blame] | 290 | |
| 291 | int len = strlen(rawSsid); |
| 292 | |
| 293 | if (len > 0) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 294 | JNIObject<jbyteArray> ssidBytes = helper.newByteArray(len); |
| 295 | helper.setByteArrayRegion(ssidBytes, 0, len, (jbyte *) rawSsid); |
| 296 | jboolean ret = helper.callStaticMethod(mCls, |
| 297 | "setSsid", "([BLandroid/net/wifi/ScanResult;)Z", ssidBytes.get(), scanResult); |
xinhe | 5cfd8d8 | 2015-07-28 16:34:37 -0700 | [diff] [blame] | 298 | return ret; |
| 299 | } else { |
| 300 | //empty SSID or SSID start with \0 |
| 301 | return true; |
| 302 | } |
| 303 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 304 | static JNIObject<jobject> createScanResult(JNIHelper &helper, wifi_scan_result *result) { |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 305 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 306 | // ALOGD("creating scan result"); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 307 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 308 | JNIObject<jobject> scanResult = helper.createObject("android/net/wifi/ScanResult"); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 309 | if (scanResult == NULL) { |
| 310 | ALOGE("Error in creating scan result"); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 311 | return JNIObject<jobject>(helper, NULL); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Vinit Deshpande | e73629f | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 314 | ALOGV("setting SSID to %s", result->ssid); |
xinhe | 5cfd8d8 | 2015-07-28 16:34:37 -0700 | [diff] [blame] | 315 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 316 | if (!setSSIDField(helper, scanResult, result->ssid)) { |
xinhe | 5cfd8d8 | 2015-07-28 16:34:37 -0700 | [diff] [blame] | 317 | ALOGE("Error on set SSID"); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 318 | return JNIObject<jobject>(helper, NULL); |
xinhe | 5cfd8d8 | 2015-07-28 16:34:37 -0700 | [diff] [blame] | 319 | } |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 320 | |
| 321 | char bssid[32]; |
Vinit Deshpande | b7cc309 | 2014-07-30 18:07:03 -0700 | [diff] [blame] | 322 | sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result->bssid[0], result->bssid[1], |
| 323 | result->bssid[2], result->bssid[3], result->bssid[4], result->bssid[5]); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 324 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 325 | helper.setStringField(scanResult, "BSSID", bssid); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 326 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 327 | helper.setIntField(scanResult, "level", result->rssi); |
| 328 | helper.setIntField(scanResult, "frequency", result->channel); |
| 329 | helper.setLongField(scanResult, "timestamp", result->ts); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 330 | |
| 331 | return scanResult; |
| 332 | } |
| 333 | |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 334 | int set_iface_flags(const char *ifname, int dev_up) { |
| 335 | struct ifreq ifr; |
| 336 | int ret; |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 337 | int sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 338 | if (sock < 0) { |
| 339 | ALOGD("Bad socket: %d\n", sock); |
| 340 | return -errno; |
| 341 | } |
| 342 | |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 343 | //ALOGD("setting interface %s flags (%s)\n", ifname, dev_up ? "UP" : "DOWN"); |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 344 | |
| 345 | memset(&ifr, 0, sizeof(ifr)); |
| 346 | strlcpy(ifr.ifr_name, ifname, IFNAMSIZ); |
| 347 | |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 348 | //ALOGD("reading old value\n"); |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 349 | |
| 350 | if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) { |
| 351 | ret = errno ? -errno : -999; |
Vinit Deshpande | bb6942c | 2015-04-10 18:10:29 -0700 | [diff] [blame] | 352 | ALOGE("Could not read interface %s flags: %d\n", ifname, errno); |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 353 | close(sock); |
| 354 | return ret; |
| 355 | } else { |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 356 | //ALOGD("writing new value\n"); |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | if (dev_up) { |
| 360 | if (ifr.ifr_flags & IFF_UP) { |
Vinit Deshpande | bb6942c | 2015-04-10 18:10:29 -0700 | [diff] [blame] | 361 | // ALOGD("interface %s is already up\n", ifname); |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 362 | close(sock); |
| 363 | return 0; |
| 364 | } |
| 365 | ifr.ifr_flags |= IFF_UP; |
| 366 | } else { |
| 367 | if (!(ifr.ifr_flags & IFF_UP)) { |
Vinit Deshpande | bb6942c | 2015-04-10 18:10:29 -0700 | [diff] [blame] | 368 | // ALOGD("interface %s is already down\n", ifname); |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 369 | close(sock); |
| 370 | return 0; |
| 371 | } |
| 372 | ifr.ifr_flags &= ~IFF_UP; |
| 373 | } |
| 374 | |
| 375 | if (ioctl(sock, SIOCSIFFLAGS, &ifr) != 0) { |
Vinit Deshpande | 6414301 | 2015-06-25 12:41:57 -0700 | [diff] [blame] | 376 | ALOGE("Could not set interface %s flags: %d\n", ifname, errno); |
| 377 | ret = errno ? -errno : -999; |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 378 | close(sock); |
| 379 | return ret; |
| 380 | } else { |
| 381 | ALOGD("set interface %s flags (%s)\n", ifname, dev_up ? "UP" : "DOWN"); |
| 382 | } |
| 383 | close(sock); |
| 384 | return 0; |
| 385 | } |
| 386 | |
xinhe | b830d76 | 2015-02-11 17:14:17 -0800 | [diff] [blame] | 387 | static jboolean android_net_wifi_toggle_interface(JNIEnv* env, jclass cls, int toggle) { |
| 388 | return(set_iface_flags("wlan0", toggle) == 0); |
| 389 | } |
| 390 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 391 | static jboolean android_net_wifi_startHal(JNIEnv* env, jclass cls) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 392 | JNIHelper helper(env); |
| 393 | wifi_handle halHandle = getWifiHandle(helper, cls); |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 394 | if (halHandle == NULL) { |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 395 | |
| 396 | if(init_wifi_hal_func_table(&hal_fn) != 0 ) { |
| 397 | ALOGD("Can not initialize the basic function pointer table"); |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | wifi_error res = init_wifi_vendor_hal_func_table(&hal_fn); |
| 402 | if (res != WIFI_SUCCESS) { |
| 403 | ALOGD("Can not initialize the vendor function pointer table"); |
| 404 | return false; |
| 405 | } |
| 406 | |
xinhe | be3b27a | 2015-01-30 17:56:24 -0800 | [diff] [blame] | 407 | int ret = set_iface_flags("wlan0", 1); |
| 408 | if(ret != 0) { |
| 409 | return false; |
| 410 | } |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 411 | |
| 412 | res = hal_fn.wifi_initialize(&halHandle); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 413 | if (res == WIFI_SUCCESS) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 414 | helper.setStaticLongField(cls, WifiHandleVarName, (jlong)halHandle); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 415 | ALOGD("Did set static halHandle = %p", halHandle); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 416 | } |
| 417 | env->GetJavaVM(&mVM); |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 418 | mCls = (jclass) env->NewGlobalRef(cls); |
| 419 | ALOGD("halHandle = %p, mVM = %p, mCls = %p", halHandle, mVM, mCls); |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 420 | return res == WIFI_SUCCESS; |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 421 | } else { |
xinhe | 8262822 | 2015-02-04 16:39:45 -0800 | [diff] [blame] | 422 | return (set_iface_flags("wlan0", 1) == 0); |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 423 | } |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | void android_net_wifi_hal_cleaned_up_handler(wifi_handle handle) { |
| 427 | ALOGD("In wifi cleaned up handler"); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 428 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 429 | JNIHelper helper(mVM); |
| 430 | helper.setStaticLongField(mCls, WifiHandleVarName, 0); |
| 431 | |
| 432 | helper.deleteGlobalRef(mCls); |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 433 | mCls = NULL; |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 434 | mVM = NULL; |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 437 | static void android_net_wifi_stopHal(JNIEnv* env, jclass cls) { |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 438 | ALOGD("In wifi stop Hal"); |
xinhe | b830d76 | 2015-02-11 17:14:17 -0800 | [diff] [blame] | 439 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 440 | JNIHelper helper(env); |
| 441 | wifi_handle halHandle = getWifiHandle(helper, cls); |
Vinit Deshpande | f49a59b | 2015-05-27 11:24:47 -0700 | [diff] [blame] | 442 | if (halHandle == NULL) |
| 443 | return; |
| 444 | |
| 445 | ALOGD("halHandle = %p, mVM = %p, mCls = %p", halHandle, mVM, mCls); |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 446 | hal_fn.wifi_cleanup(halHandle, android_net_wifi_hal_cleaned_up_handler); |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 449 | static void android_net_wifi_waitForHalEvents(JNIEnv* env, jclass cls) { |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 450 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 451 | ALOGD("waitForHalEvents called, vm = %p, obj = %p, env = %p", mVM, mCls, env); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 452 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 453 | JNIHelper helper(env); |
| 454 | wifi_handle halHandle = getWifiHandle(helper, cls); |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 455 | hal_fn.wifi_event_loop(halHandle); |
Vinit Deshpande | f49a59b | 2015-05-27 11:24:47 -0700 | [diff] [blame] | 456 | set_iface_flags("wlan0", 0); |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 459 | static int android_net_wifi_getInterfaces(JNIEnv *env, jclass cls) { |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 460 | int n = 0; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 461 | |
| 462 | JNIHelper helper(env); |
| 463 | |
| 464 | wifi_handle halHandle = getWifiHandle(helper, cls); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 465 | wifi_interface_handle *ifaceHandles = NULL; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 466 | int result = hal_fn.wifi_get_ifaces(halHandle, &n, &ifaceHandles); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 467 | if (result < 0) { |
| 468 | return result; |
| 469 | } |
| 470 | |
Vinit Deshpande | 07ce33c | 2014-08-14 12:04:35 -0700 | [diff] [blame] | 471 | if (n < 0) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 472 | THROW(helper,"android_net_wifi_getInterfaces no interfaces"); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | if (ifaceHandles == NULL) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 477 | THROW(helper,"android_net_wifi_getInterfaces null interface array"); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | |
Vinit Deshpande | 07ce33c | 2014-08-14 12:04:35 -0700 | [diff] [blame] | 481 | if (n > 8) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 482 | THROW(helper,"Too many interfaces"); |
Vinit Deshpande | 07ce33c | 2014-08-14 12:04:35 -0700 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 486 | jlongArray array = (env)->NewLongArray(n); |
| 487 | if (array == NULL) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 488 | THROW(helper,"Error in accessing array"); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | jlong elems[8]; |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 493 | for (int i = 0; i < n; i++) { |
| 494 | elems[i] = reinterpret_cast<jlong>(ifaceHandles[i]); |
| 495 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 496 | |
| 497 | helper.setLongArrayRegion(array, 0, n, elems); |
| 498 | helper.setStaticLongArrayField(cls, WifiIfaceHandleVarName, array); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 499 | |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 500 | return (result < 0) ? result : n; |
| 501 | } |
| 502 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 503 | static jstring android_net_wifi_getInterfaceName(JNIEnv *env, jclass cls, jint i) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 504 | |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 505 | char buf[EVENT_BUF_SIZE]; |
| 506 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 507 | JNIHelper helper(env); |
| 508 | |
| 509 | jlong value = helper.getStaticLongArrayField(cls, WifiIfaceHandleVarName, i); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 510 | wifi_interface_handle handle = (wifi_interface_handle) value; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 511 | int result = hal_fn.wifi_get_iface_name(handle, buf, sizeof(buf)); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 512 | if (result < 0) { |
| 513 | return NULL; |
| 514 | } else { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 515 | JNIObject<jstring> name = helper.newStringUTF(buf); |
| 516 | return name.detach(); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | |
Vinit Deshpande | b7cc309 | 2014-07-30 18:07:03 -0700 | [diff] [blame] | 520 | |
Vinit Deshapnde | 766cb4b | 2014-05-07 18:00:44 -0700 | [diff] [blame] | 521 | static void onScanResultsAvailable(wifi_request_id id, unsigned num_results) { |
| 522 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 523 | JNIHelper helper(mVM); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 524 | |
Vinit Deshpande | c5cdba4 | 2015-06-03 15:51:55 -0700 | [diff] [blame] | 525 | // ALOGD("onScanResultsAvailable called, vm = %p, obj = %p, env = %p", mVM, mCls, env); |
Vinit Deshapnde | 766cb4b | 2014-05-07 18:00:44 -0700 | [diff] [blame] | 526 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 527 | helper.reportEvent(mCls, "onScanResultsAvailable", "(I)V", id); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 528 | } |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 529 | |
Vinit Deshpande | b7cc309 | 2014-07-30 18:07:03 -0700 | [diff] [blame] | 530 | static void onScanEvent(wifi_scan_event event, unsigned status) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 531 | |
| 532 | JNIHelper helper(mVM); |
Vinit Deshpande | b7cc309 | 2014-07-30 18:07:03 -0700 | [diff] [blame] | 533 | |
Vinit Deshpande | c5cdba4 | 2015-06-03 15:51:55 -0700 | [diff] [blame] | 534 | // ALOGD("onScanStatus called, vm = %p, obj = %p, env = %p", mVM, mCls, env); |
Vinit Deshpande | b7cc309 | 2014-07-30 18:07:03 -0700 | [diff] [blame] | 535 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 536 | helper.reportEvent(mCls, "onScanStatus", "(I)V", event); |
Vinit Deshpande | b7cc309 | 2014-07-30 18:07:03 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 539 | static void onFullScanResult(wifi_request_id id, wifi_scan_result *result) { |
| 540 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 541 | JNIHelper helper(mVM); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 542 | |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 543 | //ALOGD("onFullScanResult called, vm = %p, obj = %p, env = %p", mVM, mCls, env); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 544 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 545 | JNIObject<jobject> scanResult = createScanResult(helper, result); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 546 | |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 547 | //ALOGD("Creating a byte array of length %d", result->ie_length); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 548 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 549 | JNIObject<jbyteArray> elements = helper.newByteArray(result->ie_length); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 550 | if (elements == NULL) { |
| 551 | ALOGE("Error in allocating array"); |
| 552 | return; |
| 553 | } |
| 554 | |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 555 | // ALOGD("Setting byte array"); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 556 | |
| 557 | jbyte *bytes = (jbyte *)&(result->ie_data[0]); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 558 | helper.setByteArrayRegion(elements, 0, result->ie_length, bytes); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 559 | |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 560 | // ALOGD("Returning result"); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 561 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 562 | helper.reportEvent(mCls, "onFullScanResult", "(ILandroid/net/wifi/ScanResult;[B)V", id, |
| 563 | scanResult.get(), elements.get()); |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 566 | static jboolean android_net_wifi_startScan( |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 567 | JNIEnv *env, jclass cls, jint iface, jint id, jobject settings) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 568 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 569 | JNIHelper helper(env); |
| 570 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | d7cbebf | 2015-05-11 14:07:13 -0700 | [diff] [blame] | 571 | // ALOGD("starting scan on interface[%d] = %p", iface, handle); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 572 | |
| 573 | wifi_scan_cmd_params params; |
| 574 | memset(¶ms, 0, sizeof(params)); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 575 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 576 | params.base_period = helper.getIntField(settings, "base_period_ms"); |
| 577 | params.max_ap_per_scan = helper.getIntField(settings, "max_ap_per_scan"); |
| 578 | params.report_threshold_percent = helper.getIntField(settings, "report_threshold_percent"); |
| 579 | params.report_threshold_num_scans = helper.getIntField(settings, "report_threshold_num_scans"); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 580 | |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 581 | ALOGD("Initialized common fields %d, %d, %d, %d", params.base_period, params.max_ap_per_scan, |
| 582 | params.report_threshold_percent, params.report_threshold_num_scans); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 583 | |
| 584 | const char *bucket_array_type = "[Lcom/android/server/wifi/WifiNative$BucketSettings;"; |
| 585 | const char *channel_array_type = "[Lcom/android/server/wifi/WifiNative$ChannelSettings;"; |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 586 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 587 | params.num_buckets = helper.getIntField(settings, "num_buckets"); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 588 | |
Vinit Deshpande | d7cbebf | 2015-05-11 14:07:13 -0700 | [diff] [blame] | 589 | // ALOGD("Initialized num_buckets to %d", params.num_buckets); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 590 | |
| 591 | for (int i = 0; i < params.num_buckets; i++) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 592 | JNIObject<jobject> bucket = helper.getObjectArrayField( |
| 593 | settings, "buckets", bucket_array_type, i); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 594 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 595 | params.buckets[i].bucket = helper.getIntField(bucket, "bucket"); |
| 596 | params.buckets[i].band = (wifi_band) helper.getIntField(bucket, "band"); |
| 597 | params.buckets[i].period = helper.getIntField(bucket, "period_ms"); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 598 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 599 | int report_events = helper.getIntField(bucket, "report_events"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 600 | params.buckets[i].report_events = report_events; |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 601 | |
Vinit Deshpande | d7cbebf | 2015-05-11 14:07:13 -0700 | [diff] [blame] | 602 | ALOGD("bucket[%d] = %d:%d:%d:%d", i, params.buckets[i].bucket, |
| 603 | params.buckets[i].band, params.buckets[i].period, report_events); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 604 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 605 | params.buckets[i].num_channels = helper.getIntField(bucket, "num_channels"); |
Vinit Deshpande | d7cbebf | 2015-05-11 14:07:13 -0700 | [diff] [blame] | 606 | // ALOGD("Initialized num_channels to %d", params.buckets[i].num_channels); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 607 | |
| 608 | for (int j = 0; j < params.buckets[i].num_channels; j++) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 609 | JNIObject<jobject> channel = helper.getObjectArrayField( |
| 610 | bucket, "channels", channel_array_type, j); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 611 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 612 | params.buckets[i].channels[j].channel = helper.getIntField(channel, "frequency"); |
| 613 | params.buckets[i].channels[j].dwellTimeMs = helper.getIntField(channel, "dwell_time_ms"); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 614 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 615 | bool passive = helper.getBoolField(channel, "passive"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 616 | params.buckets[i].channels[j].passive = (passive ? 1 : 0); |
| 617 | |
Vinit Deshpande | bb6942c | 2015-04-10 18:10:29 -0700 | [diff] [blame] | 618 | // ALOGD("Initialized channel %d", params.buckets[i].channels[j].channel); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 622 | // ALOGD("Initialized all fields"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 623 | |
| 624 | wifi_scan_result_handler handler; |
| 625 | memset(&handler, 0, sizeof(handler)); |
| 626 | handler.on_scan_results_available = &onScanResultsAvailable; |
Vinit Deshapnde | f1daf93 | 2014-05-13 15:44:05 -0700 | [diff] [blame] | 627 | handler.on_full_scan_result = &onFullScanResult; |
Vinit Deshpande | b7cc309 | 2014-07-30 18:07:03 -0700 | [diff] [blame] | 628 | handler.on_scan_event = &onScanEvent; |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 629 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 630 | return hal_fn.wifi_start_gscan(id, handle, params, handler) == WIFI_SUCCESS; |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 633 | static jboolean android_net_wifi_stopScan(JNIEnv *env, jclass cls, jint iface, jint id) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 634 | |
| 635 | JNIHelper helper(env); |
| 636 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | d7cbebf | 2015-05-11 14:07:13 -0700 | [diff] [blame] | 637 | // ALOGD("stopping scan on interface[%d] = %p", iface, handle); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 638 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 639 | return hal_fn.wifi_stop_gscan(id, handle) == WIFI_SUCCESS; |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 642 | static int compare_scan_result_timestamp(const void *v1, const void *v2) { |
| 643 | const wifi_scan_result *result1 = static_cast<const wifi_scan_result *>(v1); |
| 644 | const wifi_scan_result *result2 = static_cast<const wifi_scan_result *>(v2); |
| 645 | return result1->ts - result2->ts; |
| 646 | } |
| 647 | |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 648 | static jobject android_net_wifi_getScanResults( |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 649 | JNIEnv *env, jclass cls, jint iface, jboolean flush) { |
Navtej Singh Mann | c8b61ce | 2015-04-16 18:54:10 -0700 | [diff] [blame] | 650 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 651 | JNIHelper helper(env); |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 652 | wifi_cached_scan_results scan_data[64]; |
| 653 | int num_scan_data = 64; |
Navtej Singh Mann | c8b61ce | 2015-04-16 18:54:10 -0700 | [diff] [blame] | 654 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 655 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 656 | // ALOGD("getting scan results on interface[%d] = %p", iface, handle); |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 657 | |
Navtej Singh Mann | c8b61ce | 2015-04-16 18:54:10 -0700 | [diff] [blame] | 658 | byte b = flush ? 0xFF : 0; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 659 | int result = hal_fn.wifi_get_cached_gscan_results(handle, b, num_scan_data, scan_data, &num_scan_data); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 660 | if (result == WIFI_SUCCESS) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 661 | JNIObject<jobjectArray> scanData = helper.createObjectArray( |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 662 | "android/net/wifi/WifiScanner$ScanData", num_scan_data); |
| 663 | if (scanData == NULL) { |
| 664 | ALOGE("Error in allocating array of scanData"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 665 | return NULL; |
| 666 | } |
| 667 | |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 668 | for (int i = 0; i < num_scan_data; i++) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 669 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 670 | JNIObject<jobject> data = helper.createObject("android/net/wifi/WifiScanner$ScanData"); |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 671 | if (data == NULL) { |
| 672 | ALOGE("Error in allocating scanData"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 673 | return NULL; |
| 674 | } |
| 675 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 676 | helper.setIntField(data, "mId", scan_data[i].scan_id); |
| 677 | helper.setIntField(data, "mFlags", scan_data[i].flags); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 678 | |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 679 | /* sort all scan results by timestamp */ |
| 680 | qsort(scan_data[i].results, scan_data[i].num_results, |
| 681 | sizeof(wifi_scan_result), compare_scan_result_timestamp); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 682 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 683 | JNIObject<jobjectArray> scanResults = helper.createObjectArray( |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 684 | "android/net/wifi/ScanResult", scan_data[i].num_results); |
| 685 | if (scanResults == NULL) { |
| 686 | ALOGE("Error in allocating scanResult array"); |
| 687 | return NULL; |
| 688 | } |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 689 | |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 690 | wifi_scan_result *results = scan_data[i].results; |
| 691 | for (int j = 0; j < scan_data[i].num_results; j++) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 692 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 693 | JNIObject<jobject> scanResult = createScanResult(helper, &results[j]); |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 694 | if (scanResult == NULL) { |
| 695 | ALOGE("Error in creating scan result"); |
| 696 | return NULL; |
| 697 | } |
| 698 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 699 | helper.setObjectArrayElement(scanResults, j, scanResult); |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 702 | helper.setObjectField(data, "mResults", "[Landroid/net/wifi/ScanResult;", scanResults); |
| 703 | helper.setObjectArrayElement(scanData, i, data); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Vinit Deshpande | c5cdba4 | 2015-06-03 15:51:55 -0700 | [diff] [blame] | 706 | // ALOGD("retrieved %d scan data from interface[%d] = %p", num_scan_data, iface, handle); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 707 | return scanData.detach(); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 708 | } else { |
| 709 | return NULL; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | |
| 714 | static jboolean android_net_wifi_getScanCapabilities( |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 715 | JNIEnv *env, jclass cls, jint iface, jobject capabilities) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 716 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 717 | JNIHelper helper(env); |
| 718 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 719 | // ALOGD("getting scan capabilities on interface[%d] = %p", iface, handle); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 720 | |
| 721 | wifi_gscan_capabilities c; |
| 722 | memset(&c, 0, sizeof(c)); |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 723 | int result = hal_fn.wifi_get_gscan_capabilities(handle, &c); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 724 | if (result != WIFI_SUCCESS) { |
| 725 | ALOGD("failed to get capabilities : %d", result); |
| 726 | return JNI_FALSE; |
| 727 | } |
| 728 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 729 | helper.setIntField(capabilities, "max_scan_cache_size", c.max_scan_cache_size); |
| 730 | helper.setIntField(capabilities, "max_scan_buckets", c.max_scan_buckets); |
| 731 | helper.setIntField(capabilities, "max_ap_cache_per_scan", c.max_ap_cache_per_scan); |
| 732 | helper.setIntField(capabilities, "max_rssi_sample_size", c.max_rssi_sample_size); |
| 733 | helper.setIntField(capabilities, "max_scan_reporting_threshold", c.max_scan_reporting_threshold); |
| 734 | helper.setIntField(capabilities, "max_hotlist_bssids", c.max_hotlist_bssids); |
| 735 | helper.setIntField(capabilities, "max_significant_wifi_change_aps", |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 736 | c.max_significant_wifi_change_aps); |
| 737 | |
| 738 | return JNI_TRUE; |
| 739 | } |
| 740 | |
| 741 | |
| 742 | static byte parseHexChar(char ch) { |
| 743 | if (isdigit(ch)) |
| 744 | return ch - '0'; |
| 745 | else if ('A' <= ch && ch <= 'F') |
| 746 | return ch - 'A' + 10; |
| 747 | else if ('a' <= ch && ch <= 'f') |
| 748 | return ch - 'a' + 10; |
| 749 | else { |
| 750 | ALOGE("invalid character in bssid %c", ch); |
| 751 | return 0; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | static byte parseHexByte(const char * &str) { |
| 756 | byte b = parseHexChar(str[0]); |
| 757 | if (str[1] == ':' || str[1] == '\0') { |
| 758 | str += 2; |
| 759 | return b; |
| 760 | } else { |
| 761 | b = b << 4 | parseHexChar(str[1]); |
| 762 | str += 3; |
| 763 | return b; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | static void parseMacAddress(const char *str, mac_addr addr) { |
| 768 | addr[0] = parseHexByte(str); |
| 769 | addr[1] = parseHexByte(str); |
| 770 | addr[2] = parseHexByte(str); |
| 771 | addr[3] = parseHexByte(str); |
| 772 | addr[4] = parseHexByte(str); |
| 773 | addr[5] = parseHexByte(str); |
| 774 | } |
| 775 | |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 776 | static bool parseMacAddress(JNIEnv *env, jobject obj, mac_addr addr) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 777 | JNIHelper helper(env); |
| 778 | JNIObject<jstring> macAddrString = helper.getStringField(obj, "bssid"); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 779 | if (macAddrString == NULL) { |
| 780 | ALOGE("Error getting bssid field"); |
| 781 | return false; |
| 782 | } |
| 783 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 784 | ScopedUtfChars chars(env, macAddrString); |
| 785 | const char *bssid = chars.c_str(); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 786 | if (bssid == NULL) { |
| 787 | ALOGE("Error getting bssid"); |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | parseMacAddress(bssid, addr); |
| 792 | return true; |
| 793 | } |
| 794 | |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 795 | static void onHotlistApFound(wifi_request_id id, |
| 796 | unsigned num_results, wifi_scan_result *results) { |
| 797 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 798 | JNIHelper helper(mVM); |
| 799 | ALOGD("onHotlistApFound called, vm = %p, obj = %p, num_results = %d", mVM, mCls, num_results); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 800 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 801 | JNIObject<jobjectArray> scanResults = helper.newObjectArray(num_results, |
| 802 | "android/net/wifi/ScanResult", NULL); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 803 | if (scanResults == NULL) { |
| 804 | ALOGE("Error in allocating array"); |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | for (unsigned i = 0; i < num_results; i++) { |
| 809 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 810 | JNIObject<jobject> scanResult = createScanResult(helper, &results[i]); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 811 | if (scanResult == NULL) { |
| 812 | ALOGE("Error in creating scan result"); |
| 813 | return; |
| 814 | } |
| 815 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 816 | helper.setObjectArrayElement(scanResults, i, scanResult); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 817 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 818 | ALOGD("Found AP %32s", results[i].ssid); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 821 | helper.reportEvent(mCls, "onHotlistApFound", "(I[Landroid/net/wifi/ScanResult;)V", |
| 822 | id, scanResults.get()); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 825 | static void onHotlistApLost(wifi_request_id id, |
| 826 | unsigned num_results, wifi_scan_result *results) { |
| 827 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 828 | JNIHelper helper(mVM); |
| 829 | ALOGD("onHotlistApLost called, vm = %p, obj = %p, num_results = %d", mVM, mCls, num_results); |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 830 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 831 | JNIObject<jobjectArray> scanResults = helper.newObjectArray(num_results, |
| 832 | "android/net/wifi/ScanResult", NULL); |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 833 | if (scanResults == NULL) { |
| 834 | ALOGE("Error in allocating array"); |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | for (unsigned i = 0; i < num_results; i++) { |
| 839 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 840 | JNIObject<jobject> scanResult = createScanResult(helper, &results[i]); |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 841 | if (scanResult == NULL) { |
| 842 | ALOGE("Error in creating scan result"); |
| 843 | return; |
| 844 | } |
| 845 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 846 | helper.setObjectArrayElement(scanResults, i, scanResult); |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 847 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 848 | ALOGD("Lost AP %32s", results[i].ssid); |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 851 | helper.reportEvent(mCls, "onHotlistApLost", "(I[Landroid/net/wifi/ScanResult;)V", |
| 852 | id, scanResults.get()); |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 856 | static jboolean android_net_wifi_setHotlist( |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 857 | JNIEnv *env, jclass cls, jint iface, jint id, jobject ap) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 858 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 859 | JNIHelper helper(env); |
| 860 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 861 | ALOGD("setting hotlist on interface[%d] = %p", iface, handle); |
| 862 | |
| 863 | wifi_bssid_hotlist_params params; |
| 864 | memset(¶ms, 0, sizeof(params)); |
| 865 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 866 | params.lost_ap_sample_size = helper.getIntField(ap, "apLostThreshold"); |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 867 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 868 | JNIObject<jobjectArray> array = helper.getArrayField( |
| 869 | ap, "bssidInfos", "[Landroid/net/wifi/WifiScanner$BssidInfo;"); |
| 870 | params.num_bssid = helper.getArrayLength(array); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 871 | |
Pierre Vandwalle | c03c146 | 2015-03-18 19:16:30 -0700 | [diff] [blame] | 872 | if (params.num_bssid == 0) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 873 | ALOGE("Error in accesing array"); |
| 874 | return false; |
| 875 | } |
| 876 | |
Pierre Vandwalle | c03c146 | 2015-03-18 19:16:30 -0700 | [diff] [blame] | 877 | for (int i = 0; i < params.num_bssid; i++) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 878 | JNIObject<jobject> objAp = helper.getObjectArrayElement(array, i); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 879 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 880 | JNIObject<jstring> macAddrString = helper.getStringField(objAp, "bssid"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 881 | if (macAddrString == NULL) { |
| 882 | ALOGE("Error getting bssid field"); |
| 883 | return false; |
| 884 | } |
| 885 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 886 | ScopedUtfChars chars(env, macAddrString); |
| 887 | const char *bssid = chars.c_str(); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 888 | if (bssid == NULL) { |
| 889 | ALOGE("Error getting bssid"); |
| 890 | return false; |
| 891 | } |
Vinit Deshpande | a59fae6 | 2014-05-23 15:59:35 -0700 | [diff] [blame] | 892 | parseMacAddress(bssid, params.ap[i].bssid); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 893 | |
| 894 | mac_addr addr; |
Vinit Deshpande | a59fae6 | 2014-05-23 15:59:35 -0700 | [diff] [blame] | 895 | memcpy(addr, params.ap[i].bssid, sizeof(mac_addr)); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 896 | |
| 897 | char bssidOut[32]; |
| 898 | sprintf(bssidOut, "%0x:%0x:%0x:%0x:%0x:%0x", addr[0], addr[1], |
| 899 | addr[2], addr[3], addr[4], addr[5]); |
| 900 | |
| 901 | ALOGD("Added bssid %s", bssidOut); |
| 902 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 903 | params.ap[i].low = helper.getIntField(objAp, "low"); |
| 904 | params.ap[i].high = helper.getIntField(objAp, "high"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | wifi_hotlist_ap_found_handler handler; |
| 908 | memset(&handler, 0, sizeof(handler)); |
| 909 | |
| 910 | handler.on_hotlist_ap_found = &onHotlistApFound; |
Vinit Deshpande | e9fa5dc | 2014-08-11 21:51:25 -0700 | [diff] [blame] | 911 | handler.on_hotlist_ap_lost = &onHotlistApLost; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 912 | return hal_fn.wifi_set_bssid_hotlist(id, handle, params, handler) == WIFI_SUCCESS; |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 915 | static jboolean android_net_wifi_resetHotlist(JNIEnv *env, jclass cls, jint iface, jint id) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 916 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 917 | JNIHelper helper(env); |
| 918 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 919 | ALOGD("resetting hotlist on interface[%d] = %p", iface, handle); |
| 920 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 921 | return hal_fn.wifi_reset_bssid_hotlist(id, handle) == WIFI_SUCCESS; |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Vinit Deshpande | a59fae6 | 2014-05-23 15:59:35 -0700 | [diff] [blame] | 924 | void onSignificantWifiChange(wifi_request_id id, |
| 925 | unsigned num_results, wifi_significant_change_result **results) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 926 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 927 | JNIHelper helper(mVM); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 928 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 929 | ALOGD("onSignificantWifiChange called, vm = %p, obj = %p", mVM, mCls); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 930 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 931 | JNIObject<jobjectArray> scanResults = helper.newObjectArray( |
| 932 | num_results, "android/net/wifi/ScanResult", NULL); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 933 | if (scanResults == NULL) { |
| 934 | ALOGE("Error in allocating array"); |
| 935 | return; |
| 936 | } |
| 937 | |
| 938 | for (unsigned i = 0; i < num_results; i++) { |
| 939 | |
Greg Hackmann | d31a40e | 2015-02-22 21:39:38 -0800 | [diff] [blame] | 940 | wifi_significant_change_result &result = *(results[i]); |
Vinit Deshpande | a59fae6 | 2014-05-23 15:59:35 -0700 | [diff] [blame] | 941 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 942 | JNIObject<jobject> scanResult = helper.createObject("android/net/wifi/ScanResult"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 943 | if (scanResult == NULL) { |
| 944 | ALOGE("Error in creating scan result"); |
| 945 | return; |
| 946 | } |
| 947 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 948 | // helper.setStringField(scanResult, "SSID", results[i].ssid); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 949 | |
| 950 | char bssid[32]; |
Vinit Deshpande | a59fae6 | 2014-05-23 15:59:35 -0700 | [diff] [blame] | 951 | sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result.bssid[0], result.bssid[1], |
| 952 | result.bssid[2], result.bssid[3], result.bssid[4], result.bssid[5]); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 953 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 954 | helper.setStringField(scanResult, "BSSID", bssid); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 955 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 956 | helper.setIntField(scanResult, "level", result.rssi[0]); |
| 957 | helper.setIntField(scanResult, "frequency", result.channel); |
| 958 | // helper.setLongField(scanResult, "timestamp", result.ts); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 959 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 960 | helper.setObjectArrayElement(scanResults, i, scanResult); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 963 | helper.reportEvent(mCls, "onSignificantWifiChange", "(I[Landroid/net/wifi/ScanResult;)V", |
| 964 | id, scanResults.get()); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 965 | |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 968 | static jboolean android_net_wifi_trackSignificantWifiChange( |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 969 | JNIEnv *env, jclass cls, jint iface, jint id, jobject settings) { |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 970 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 971 | JNIHelper helper(env); |
| 972 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 973 | ALOGD("tracking significant wifi change on interface[%d] = %p", iface, handle); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 974 | |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 975 | wifi_significant_change_params params; |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 976 | memset(¶ms, 0, sizeof(params)); |
| 977 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 978 | params.rssi_sample_size = helper.getIntField(settings, "rssiSampleSize"); |
| 979 | params.lost_ap_sample_size = helper.getIntField(settings, "lostApSampleSize"); |
| 980 | params.min_breaching = helper.getIntField(settings, "minApsBreachingThreshold"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 981 | |
Vinit Deshpande | b7cc309 | 2014-07-30 18:07:03 -0700 | [diff] [blame] | 982 | const char *bssid_info_array_type = "[Landroid/net/wifi/WifiScanner$BssidInfo;"; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 983 | JNIObject<jobjectArray> bssids = helper.getArrayField( |
| 984 | settings, "bssidInfos", bssid_info_array_type); |
| 985 | params.num_bssid = helper.getArrayLength(bssids); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 986 | |
Pierre Vandwalle | c03c146 | 2015-03-18 19:16:30 -0700 | [diff] [blame] | 987 | if (params.num_bssid == 0) { |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 988 | ALOGE("Error in accessing array"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 989 | return false; |
| 990 | } |
| 991 | |
| 992 | ALOGD("Initialized common fields %d, %d, %d, %d", params.rssi_sample_size, |
Pierre Vandwalle | c03c146 | 2015-03-18 19:16:30 -0700 | [diff] [blame] | 993 | params.lost_ap_sample_size, params.min_breaching, params.num_bssid); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 994 | |
Pierre Vandwalle | c03c146 | 2015-03-18 19:16:30 -0700 | [diff] [blame] | 995 | for (int i = 0; i < params.num_bssid; i++) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 996 | JNIObject<jobject> objAp = helper.getObjectArrayElement(bssids, i); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 997 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 998 | JNIObject<jstring> macAddrString = helper.getStringField(objAp, "bssid"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 999 | if (macAddrString == NULL) { |
| 1000 | ALOGE("Error getting bssid field"); |
| 1001 | return false; |
| 1002 | } |
| 1003 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1004 | ScopedUtfChars chars(env, macAddrString.get()); |
| 1005 | const char *bssid = chars.c_str(); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1006 | if (bssid == NULL) { |
| 1007 | ALOGE("Error getting bssid"); |
| 1008 | return false; |
| 1009 | } |
| 1010 | |
| 1011 | mac_addr addr; |
| 1012 | parseMacAddress(bssid, addr); |
Vinit Deshpande | a59fae6 | 2014-05-23 15:59:35 -0700 | [diff] [blame] | 1013 | memcpy(params.ap[i].bssid, addr, sizeof(mac_addr)); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1014 | |
| 1015 | char bssidOut[32]; |
Vinit Deshpande | 4dbfefd | 2014-08-10 18:19:13 -0700 | [diff] [blame] | 1016 | sprintf(bssidOut, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1017 | addr[2], addr[3], addr[4], addr[5]); |
| 1018 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1019 | params.ap[i].low = helper.getIntField(objAp, "low"); |
| 1020 | params.ap[i].high = helper.getIntField(objAp, "high"); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1021 | |
Vinit Deshpande | a59fae6 | 2014-05-23 15:59:35 -0700 | [diff] [blame] | 1022 | ALOGD("Added bssid %s, [%04d, %04d]", bssidOut, params.ap[i].low, params.ap[i].high); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Pierre Vandwalle | c03c146 | 2015-03-18 19:16:30 -0700 | [diff] [blame] | 1025 | ALOGD("Added %d bssids", params.num_bssid); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1026 | |
| 1027 | wifi_significant_change_handler handler; |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 1028 | memset(&handler, 0, sizeof(handler)); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 1029 | |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1030 | handler.on_significant_change = &onSignificantWifiChange; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1031 | return hal_fn.wifi_set_significant_change_handler(id, handle, params, handler) == WIFI_SUCCESS; |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1034 | static jboolean android_net_wifi_untrackSignificantWifiChange( |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 1035 | JNIEnv *env, jclass cls, jint iface, jint id) { |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1036 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1037 | JNIHelper helper(env); |
| 1038 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1039 | ALOGD("resetting significant wifi change on interface[%d] = %p", iface, handle); |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 1040 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1041 | return hal_fn.wifi_reset_significant_change_handler(id, handle) == WIFI_SUCCESS; |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 1042 | } |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 1043 | |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1044 | wifi_iface_stat link_stat; |
vandwalle | 200e8ee | 2014-07-18 18:44:32 -0700 | [diff] [blame] | 1045 | wifi_radio_stat radio_stat; // L release has support for only one radio |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1046 | |
| 1047 | void onLinkStatsResults(wifi_request_id id, wifi_iface_stat *iface_stat, |
vandwalle | 200e8ee | 2014-07-18 18:44:32 -0700 | [diff] [blame] | 1048 | int num_radios, wifi_radio_stat *radio_stats) |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1049 | { |
vandwalle | 200e8ee | 2014-07-18 18:44:32 -0700 | [diff] [blame] | 1050 | if (iface_stat != 0) { |
| 1051 | memcpy(&link_stat, iface_stat, sizeof(wifi_iface_stat)); |
| 1052 | } else { |
| 1053 | memset(&link_stat, 0, sizeof(wifi_iface_stat)); |
| 1054 | } |
vandwalle | 200e8ee | 2014-07-18 18:44:32 -0700 | [diff] [blame] | 1055 | |
| 1056 | if (num_radios > 0 && radio_stats != 0) { |
| 1057 | memcpy(&radio_stat, radio_stats, sizeof(wifi_radio_stat)); |
| 1058 | } else { |
| 1059 | memset(&radio_stat, 0, sizeof(wifi_radio_stat)); |
| 1060 | } |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Pierre Vandwalle | d745a52 | 2015-06-11 17:48:58 -0700 | [diff] [blame] | 1063 | static void android_net_wifi_setLinkLayerStats (JNIEnv *env, jclass cls, jint iface, int enable) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1064 | JNIHelper helper(env); |
| 1065 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Pierre Vandwalle | d745a52 | 2015-06-11 17:48:58 -0700 | [diff] [blame] | 1066 | |
| 1067 | wifi_link_layer_params params; |
| 1068 | params.aggressive_statistics_gathering = enable; |
| 1069 | params.mpdu_size_threshold = 128; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1070 | |
| 1071 | ALOGD("android_net_wifi_setLinkLayerStats: %u\n", enable); |
Pierre Vandwalle | d745a52 | 2015-06-11 17:48:58 -0700 | [diff] [blame] | 1072 | |
| 1073 | hal_fn.wifi_set_link_stats(handle, params); |
| 1074 | } |
| 1075 | |
Vinit Deshpande | b0b1d59 | 2014-05-29 16:37:24 -0700 | [diff] [blame] | 1076 | static jobject android_net_wifi_getLinkLayerStats (JNIEnv *env, jclass cls, jint iface) { |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1077 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1078 | JNIHelper helper(env); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1079 | wifi_stats_result_handler handler; |
| 1080 | memset(&handler, 0, sizeof(handler)); |
| 1081 | handler.on_link_stats_results = &onLinkStatsResults; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1082 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1083 | int result = hal_fn.wifi_get_link_stats(0, handle, handler); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1084 | if (result < 0) { |
vandwalle | 200e8ee | 2014-07-18 18:44:32 -0700 | [diff] [blame] | 1085 | ALOGE("android_net_wifi_getLinkLayerStats: failed to get link statistics\n"); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1086 | return NULL; |
| 1087 | } |
| 1088 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1089 | JNIObject<jobject> wifiLinkLayerStats = helper.createObject( |
| 1090 | "android/net/wifi/WifiLinkLayerStats"); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1091 | if (wifiLinkLayerStats == NULL) { |
| 1092 | ALOGE("Error in allocating wifiLinkLayerStats"); |
| 1093 | return NULL; |
| 1094 | } |
| 1095 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1096 | helper.setIntField(wifiLinkLayerStats, "beacon_rx", link_stat.beacon_rx); |
| 1097 | helper.setIntField(wifiLinkLayerStats, "rssi_mgmt", link_stat.rssi_mgmt); |
| 1098 | helper.setLongField(wifiLinkLayerStats, "rxmpdu_be", link_stat.ac[WIFI_AC_BE].rx_mpdu); |
| 1099 | helper.setLongField(wifiLinkLayerStats, "rxmpdu_bk", link_stat.ac[WIFI_AC_BK].rx_mpdu); |
| 1100 | helper.setLongField(wifiLinkLayerStats, "rxmpdu_vi", link_stat.ac[WIFI_AC_VI].rx_mpdu); |
| 1101 | helper.setLongField(wifiLinkLayerStats, "rxmpdu_vo", link_stat.ac[WIFI_AC_VO].rx_mpdu); |
| 1102 | helper.setLongField(wifiLinkLayerStats, "txmpdu_be", link_stat.ac[WIFI_AC_BE].tx_mpdu); |
| 1103 | helper.setLongField(wifiLinkLayerStats, "txmpdu_bk", link_stat.ac[WIFI_AC_BK].tx_mpdu); |
| 1104 | helper.setLongField(wifiLinkLayerStats, "txmpdu_vi", link_stat.ac[WIFI_AC_VI].tx_mpdu); |
| 1105 | helper.setLongField(wifiLinkLayerStats, "txmpdu_vo", link_stat.ac[WIFI_AC_VO].tx_mpdu); |
| 1106 | helper.setLongField(wifiLinkLayerStats, "lostmpdu_be", link_stat.ac[WIFI_AC_BE].mpdu_lost); |
| 1107 | helper.setLongField(wifiLinkLayerStats, "lostmpdu_bk", link_stat.ac[WIFI_AC_BK].mpdu_lost); |
| 1108 | helper.setLongField(wifiLinkLayerStats, "lostmpdu_vi", link_stat.ac[WIFI_AC_VI].mpdu_lost); |
| 1109 | helper.setLongField(wifiLinkLayerStats, "lostmpdu_vo", link_stat.ac[WIFI_AC_VO].mpdu_lost); |
| 1110 | helper.setLongField(wifiLinkLayerStats, "retries_be", link_stat.ac[WIFI_AC_BE].retries); |
| 1111 | helper.setLongField(wifiLinkLayerStats, "retries_bk", link_stat.ac[WIFI_AC_BK].retries); |
| 1112 | helper.setLongField(wifiLinkLayerStats, "retries_vi", link_stat.ac[WIFI_AC_VI].retries); |
| 1113 | helper.setLongField(wifiLinkLayerStats, "retries_vo", link_stat.ac[WIFI_AC_VO].retries); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1114 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1115 | helper.setIntField(wifiLinkLayerStats, "on_time", radio_stat.on_time); |
| 1116 | helper.setIntField(wifiLinkLayerStats, "tx_time", radio_stat.tx_time); |
| 1117 | helper.setIntField(wifiLinkLayerStats, "rx_time", radio_stat.rx_time); |
| 1118 | helper.setIntField(wifiLinkLayerStats, "on_time_scan", radio_stat.on_time_scan); |
vandwalle | 200e8ee | 2014-07-18 18:44:32 -0700 | [diff] [blame] | 1119 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1120 | return wifiLinkLayerStats.detach(); |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 1121 | } |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 1122 | |
Vinit Deshpande | c35361d | 2014-08-07 16:24:10 -0700 | [diff] [blame] | 1123 | static jint android_net_wifi_getSupportedFeatures(JNIEnv *env, jclass cls, jint iface) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1124 | |
| 1125 | JNIHelper helper(env); |
| 1126 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | a632d8a | 2014-07-01 14:12:13 -0700 | [diff] [blame] | 1127 | feature_set set = 0; |
| 1128 | |
| 1129 | wifi_error result = WIFI_SUCCESS; |
Vinit Deshpande | c35361d | 2014-08-07 16:24:10 -0700 | [diff] [blame] | 1130 | /* |
Vinit Deshpande | a632d8a | 2014-07-01 14:12:13 -0700 | [diff] [blame] | 1131 | set = WIFI_FEATURE_INFRA |
| 1132 | | WIFI_FEATURE_INFRA_5G |
| 1133 | | WIFI_FEATURE_HOTSPOT |
| 1134 | | WIFI_FEATURE_P2P |
| 1135 | | WIFI_FEATURE_SOFT_AP |
| 1136 | | WIFI_FEATURE_GSCAN |
| 1137 | | WIFI_FEATURE_PNO |
| 1138 | | WIFI_FEATURE_TDLS |
| 1139 | | WIFI_FEATURE_EPR; |
Vinit Deshpande | c35361d | 2014-08-07 16:24:10 -0700 | [diff] [blame] | 1140 | */ |
Vinit Deshpande | a632d8a | 2014-07-01 14:12:13 -0700 | [diff] [blame] | 1141 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1142 | result = hal_fn.wifi_get_supported_feature_set(handle, &set); |
Vinit Deshpande | a632d8a | 2014-07-01 14:12:13 -0700 | [diff] [blame] | 1143 | if (result == WIFI_SUCCESS) { |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 1144 | // ALOGD("wifi_get_supported_feature_set returned set = 0x%x", set); |
Vinit Deshpande | a632d8a | 2014-07-01 14:12:13 -0700 | [diff] [blame] | 1145 | return set; |
| 1146 | } else { |
Vinit Deshpande | f3bc3c6 | 2015-04-23 15:06:46 -0700 | [diff] [blame] | 1147 | ALOGE("wifi_get_supported_feature_set returned error = 0x%x", result); |
Vinit Deshpande | a632d8a | 2014-07-01 14:12:13 -0700 | [diff] [blame] | 1148 | return 0; |
| 1149 | } |
| 1150 | } |
| 1151 | |
xinhe | 06a3eba | 2015-03-18 20:17:17 -0700 | [diff] [blame] | 1152 | static void onRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result* results[]) { |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1153 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1154 | JNIHelper helper(mVM); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1155 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1156 | ALOGD("onRttResults called, vm = %p, obj = %p", mVM, mCls); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1157 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1158 | JNIObject<jobjectArray> rttResults = helper.newObjectArray( |
| 1159 | num_results, "android/net/wifi/RttManager$RttResult", NULL); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1160 | if (rttResults == NULL) { |
| 1161 | ALOGE("Error in allocating array"); |
| 1162 | return; |
| 1163 | } |
| 1164 | |
| 1165 | for (unsigned i = 0; i < num_results; i++) { |
| 1166 | |
xinhe | 06a3eba | 2015-03-18 20:17:17 -0700 | [diff] [blame] | 1167 | wifi_rtt_result *result = results[i]; |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1168 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1169 | JNIObject<jobject> rttResult = helper.createObject("android/net/wifi/RttManager$RttResult"); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1170 | if (rttResult == NULL) { |
| 1171 | ALOGE("Error in creating rtt result"); |
| 1172 | return; |
| 1173 | } |
| 1174 | |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1175 | char bssid[32]; |
xinhe | 06a3eba | 2015-03-18 20:17:17 -0700 | [diff] [blame] | 1176 | sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result->addr[0], result->addr[1], |
| 1177 | result->addr[2], result->addr[3], result->addr[4], result->addr[5]); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1178 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1179 | helper.setStringField(rttResult, "bssid", bssid); |
| 1180 | helper.setIntField( rttResult, "burstNumber", result->burst_num); |
| 1181 | helper.setIntField( rttResult, "measurementFrameNumber", result->measurement_number); |
| 1182 | helper.setIntField( rttResult, "successMeasurementFrameNumber", result->success_number); |
| 1183 | helper.setIntField(rttResult, "frameNumberPerBurstPeer", result->number_per_burst_peer); |
| 1184 | helper.setIntField( rttResult, "status", result->status); |
| 1185 | helper.setIntField( rttResult, "measurementType", result->type); |
| 1186 | helper.setIntField(rttResult, "retryAfterDuration", result->retry_after_duration); |
| 1187 | helper.setLongField(rttResult, "ts", result->ts); |
| 1188 | helper.setIntField( rttResult, "rssi", result->rssi); |
| 1189 | helper.setIntField( rttResult, "rssiSpread", result->rssi_spread); |
| 1190 | helper.setIntField( rttResult, "txRate", result->tx_rate.bitrate); |
| 1191 | helper.setIntField( rttResult, "rxRate", result->rx_rate.bitrate); |
| 1192 | helper.setLongField(rttResult, "rtt", result->rtt); |
| 1193 | helper.setLongField(rttResult, "rttStandardDeviation", result->rtt_sd); |
| 1194 | helper.setIntField( rttResult, "distance", result->distance); |
| 1195 | helper.setIntField( rttResult, "distanceStandardDeviation", result->distance_sd); |
| 1196 | helper.setIntField( rttResult, "distanceSpread", result->distance_spread); |
| 1197 | helper.setIntField( rttResult, "burstDuration", result->burst_duration); |
| 1198 | helper.setIntField( rttResult, "negotiatedBurstNum", result->negotiated_burst_num); |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1199 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1200 | JNIObject<jobject> LCI = helper.createObject( |
| 1201 | "android/net/wifi/RttManager$WifiInformationElement"); |
| 1202 | if (result->LCI != NULL && result->LCI->len > 0) { |
| 1203 | ALOGD("Add LCI in result"); |
| 1204 | helper.setByteField(LCI, "id", result->LCI->id); |
| 1205 | JNIObject<jbyteArray> elements = helper.newByteArray(result->LCI->len); |
| 1206 | jbyte *bytes = (jbyte *)&(result->LCI->data[0]); |
| 1207 | helper.setByteArrayRegion(elements, 0, result->LCI->len, bytes); |
| 1208 | helper.setObjectField(LCI, "data", "[B", elements); |
| 1209 | } else { |
| 1210 | ALOGD("No LCI in result"); |
| 1211 | helper.setByteField(LCI, "id", (byte)(0xff)); |
| 1212 | } |
| 1213 | helper.setObjectField(rttResult, "LCI", |
| 1214 | "Landroid/net/wifi/RttManager$WifiInformationElement;", LCI); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1215 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1216 | JNIObject<jobject> LCR = helper.createObject( |
| 1217 | "android/net/wifi/RttManager$WifiInformationElement"); |
| 1218 | if (result->LCR != NULL && result->LCR->len > 0) { |
| 1219 | ALOGD("Add LCR in result"); |
| 1220 | helper.setByteField(LCR, "id", result->LCR->id); |
| 1221 | JNIObject<jbyteArray> elements = helper.newByteArray(result->LCI->len); |
| 1222 | jbyte *bytes = (jbyte *)&(result->LCR->data[0]); |
| 1223 | helper.setByteArrayRegion(elements, 0, result->LCI->len, bytes); |
| 1224 | helper.setObjectField(LCR, "data", "[B", elements); |
| 1225 | } else { |
| 1226 | ALOGD("No LCR in result"); |
| 1227 | helper.setByteField(LCR, "id", (byte)(0xff)); |
| 1228 | } |
| 1229 | helper.setObjectField(rttResult, "LCR", |
| 1230 | "Landroid/net/wifi/RttManager$WifiInformationElement;", LCR); |
| 1231 | |
| 1232 | helper.setObjectArrayElement(rttResults, i, rttResult); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1235 | helper.reportEvent(mCls, "onRttResults", "(I[Landroid/net/wifi/RttManager$RttResult;)V", |
| 1236 | id, rttResults.get()); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1239 | const int MaxRttConfigs = 16; |
| 1240 | |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1241 | static jboolean android_net_wifi_requestRange( |
| 1242 | JNIEnv *env, jclass cls, jint iface, jint id, jobject params) { |
| 1243 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1244 | JNIHelper helper(env); |
| 1245 | |
| 1246 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1247 | ALOGD("sending rtt request [%d] = %p", id, handle); |
| 1248 | |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1249 | wifi_rtt_config configs[MaxRttConfigs]; |
| 1250 | memset(&configs, 0, sizeof(configs)); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1251 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1252 | int len = helper.getArrayLength((jobjectArray)params); |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1253 | if (len > MaxRttConfigs) { |
| 1254 | return false; |
| 1255 | } |
| 1256 | |
| 1257 | for (int i = 0; i < len; i++) { |
| 1258 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1259 | JNIObject<jobject> param = helper.getObjectArrayElement((jobjectArray)params, i); |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1260 | if (param == NULL) { |
| 1261 | ALOGD("could not get element %d", i); |
| 1262 | continue; |
| 1263 | } |
| 1264 | |
| 1265 | wifi_rtt_config &config = configs[i]; |
| 1266 | |
| 1267 | parseMacAddress(env, param, config.addr); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1268 | config.type = (wifi_rtt_type)helper.getIntField(param, "requestType"); |
| 1269 | config.peer = (rtt_peer_type)helper.getIntField(param, "deviceType"); |
| 1270 | config.channel.center_freq = helper.getIntField(param, "frequency"); |
| 1271 | config.channel.width = (wifi_channel_width) helper.getIntField(param, "channelWidth"); |
| 1272 | config.channel.center_freq0 = helper.getIntField(param, "centerFreq0"); |
| 1273 | config.channel.center_freq1 = helper.getIntField(param, "centerFreq1"); |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1274 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1275 | config.num_burst = helper.getIntField(param, "numberBurst"); |
| 1276 | config.burst_period = (unsigned) helper.getIntField(param, "interval"); |
| 1277 | config.num_frames_per_burst = (unsigned) helper.getIntField(param, "numSamplesPerBurst"); |
| 1278 | config.num_retries_per_rtt_frame = (unsigned) helper.getIntField(param, |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1279 | "numRetriesPerMeasurementFrame"); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1280 | config.num_retries_per_ftmr = (unsigned) helper.getIntField(param, "numRetriesPerFTMR"); |
| 1281 | config.LCI_request = helper.getBoolField(param, "LCIRequest") ? 1 : 0; |
| 1282 | config.LCR_request = helper.getBoolField(param, "LCRRequest") ? 1 : 0; |
| 1283 | config.burst_duration = (unsigned) helper.getIntField(param, "burstTimeout"); |
| 1284 | config.preamble = (wifi_rtt_preamble) helper.getIntField(param, "preamble"); |
| 1285 | config.bw = (wifi_rtt_bw) helper.getIntField(param, "bandwidth"); |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1286 | |
| 1287 | ALOGD("RTT request destination %d: type is %d, peer is %d, bw is %d, center_freq is %d ", i, |
Wei Wang | 3cd3ccd | 2015-06-09 14:00:57 -0700 | [diff] [blame] | 1288 | config.type,config.peer, config.channel.width, config.channel.center_freq); |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1289 | ALOGD("center_freq0 is %d, center_freq1 is %d, num_burst is %d,interval is %d", |
| 1290 | config.channel.center_freq0, config.channel.center_freq1, config.num_burst, |
xinhe | c96feb8 | 2015-04-01 18:52:59 -0700 | [diff] [blame] | 1291 | config.burst_period); |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1292 | ALOGD("frames_per_burst is %d, retries of measurement frame is %d, retries_per_ftmr is %d", |
xinhe | c96feb8 | 2015-04-01 18:52:59 -0700 | [diff] [blame] | 1293 | config.num_frames_per_burst, config.num_retries_per_rtt_frame, |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1294 | config.num_retries_per_ftmr); |
| 1295 | ALOGD("LCI_requestis %d, LCR_request is %d, burst_timeout is %d, preamble is %d, bw is %d", |
xinhe | c96feb8 | 2015-04-01 18:52:59 -0700 | [diff] [blame] | 1296 | config.LCI_request, config.LCR_request, config.burst_duration, config.preamble, |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1297 | config.bw); |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1298 | } |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1299 | |
| 1300 | wifi_rtt_event_handler handler; |
| 1301 | handler.on_rtt_results = &onRttResults; |
| 1302 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1303 | return hal_fn.wifi_rtt_range_request(id, handle, len, configs, handler) == WIFI_SUCCESS; |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | static jboolean android_net_wifi_cancelRange( |
Vinit Deshpande | 042c54b | 2014-08-21 13:52:21 -0700 | [diff] [blame] | 1307 | JNIEnv *env, jclass cls, jint iface, jint id, jobject params) { |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1308 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1309 | JNIHelper helper(env); |
| 1310 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1311 | ALOGD("cancelling rtt request [%d] = %p", id, handle); |
| 1312 | |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1313 | mac_addr addrs[MaxRttConfigs]; |
| 1314 | memset(&addrs, 0, sizeof(addrs)); |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1315 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1316 | int len = helper.getArrayLength((jobjectArray)params); |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1317 | if (len > MaxRttConfigs) { |
| 1318 | return false; |
| 1319 | } |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1320 | |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1321 | for (int i = 0; i < len; i++) { |
| 1322 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1323 | JNIObject<jobject> param = helper.getObjectArrayElement(params, i); |
Vinit Deshpande | 02a1f98 | 2014-07-25 17:44:39 -0700 | [diff] [blame] | 1324 | if (param == NULL) { |
| 1325 | ALOGD("could not get element %d", i); |
| 1326 | continue; |
| 1327 | } |
| 1328 | |
| 1329 | parseMacAddress(env, param, addrs[i]); |
| 1330 | } |
| 1331 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1332 | return hal_fn.wifi_rtt_range_cancel(id, handle, len, addrs) == WIFI_SUCCESS; |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Vinit Deshpande | 042c54b | 2014-08-21 13:52:21 -0700 | [diff] [blame] | 1335 | static jboolean android_net_wifi_setScanningMacOui(JNIEnv *env, jclass cls, |
| 1336 | jint iface, jbyteArray param) { |
| 1337 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1338 | JNIHelper helper(env); |
| 1339 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | 042c54b | 2014-08-21 13:52:21 -0700 | [diff] [blame] | 1340 | ALOGD("setting scan oui %p", handle); |
| 1341 | |
| 1342 | static const unsigned oui_len = 3; /* OUI is upper 3 bytes of mac_address */ |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1343 | int len = helper.getArrayLength(param); |
Vinit Deshpande | 042c54b | 2014-08-21 13:52:21 -0700 | [diff] [blame] | 1344 | if (len != oui_len) { |
| 1345 | ALOGE("invalid oui length %d", len); |
| 1346 | return false; |
| 1347 | } |
| 1348 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1349 | ScopedBytesRO paramBytes(env, param); |
| 1350 | const jbyte* bytes = paramBytes.get(); |
Vinit Deshpande | 042c54b | 2014-08-21 13:52:21 -0700 | [diff] [blame] | 1351 | if (bytes == NULL) { |
| 1352 | ALOGE("failed to get array"); |
| 1353 | return false; |
| 1354 | } |
| 1355 | |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1356 | return hal_fn.wifi_set_scanning_mac_oui(handle, (byte *)bytes) == WIFI_SUCCESS; |
Vinit Deshpande | 042c54b | 2014-08-21 13:52:21 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
xinhe | ee0a013 | 2015-08-04 14:27:27 -0700 | [diff] [blame] | 1359 | static jboolean android_net_wifi_is_get_channels_for_band_supported(JNIEnv *env, jclass cls){ |
| 1360 | return (hal_fn.wifi_get_valid_channels == wifi_get_valid_channels_stub); |
| 1361 | } |
| 1362 | |
Vinit Deshpande | efa77c1 | 2014-09-05 20:44:49 -0700 | [diff] [blame] | 1363 | static jintArray android_net_wifi_getValidChannels(JNIEnv *env, jclass cls, |
| 1364 | jint iface, jint band) { |
| 1365 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1366 | JNIHelper helper(env); |
| 1367 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | efa77c1 | 2014-09-05 20:44:49 -0700 | [diff] [blame] | 1368 | ALOGD("getting valid channels %p", handle); |
| 1369 | |
| 1370 | static const int MaxChannels = 64; |
| 1371 | wifi_channel channels[64]; |
| 1372 | int num_channels = 0; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1373 | wifi_error result = hal_fn.wifi_get_valid_channels(handle, band, MaxChannels, |
Vinit Deshpande | efa77c1 | 2014-09-05 20:44:49 -0700 | [diff] [blame] | 1374 | channels, &num_channels); |
| 1375 | |
| 1376 | if (result == WIFI_SUCCESS) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1377 | JNIObject<jintArray> channelArray = helper.newIntArray(num_channels); |
Vinit Deshpande | efa77c1 | 2014-09-05 20:44:49 -0700 | [diff] [blame] | 1378 | if (channelArray == NULL) { |
| 1379 | ALOGE("failed to allocate channel list"); |
| 1380 | return NULL; |
| 1381 | } |
| 1382 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1383 | helper.setIntArrayRegion(channelArray, 0, num_channels, channels); |
| 1384 | return channelArray.detach(); |
Vinit Deshpande | efa77c1 | 2014-09-05 20:44:49 -0700 | [diff] [blame] | 1385 | } else { |
| 1386 | ALOGE("failed to get channel list : %d", result); |
| 1387 | return NULL; |
| 1388 | } |
| 1389 | } |
| 1390 | |
Vinit Deshpande | 90b902d | 2014-10-13 13:21:47 -0700 | [diff] [blame] | 1391 | static jboolean android_net_wifi_setDfsFlag(JNIEnv *env, jclass cls, jint iface, jboolean dfs) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1392 | |
| 1393 | JNIHelper helper(env); |
| 1394 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | 90b902d | 2014-10-13 13:21:47 -0700 | [diff] [blame] | 1395 | ALOGD("setting dfs flag to %s, %p", dfs ? "true" : "false", handle); |
| 1396 | |
| 1397 | u32 nodfs = dfs ? 0 : 1; |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1398 | wifi_error result = hal_fn.wifi_set_nodfs_flag(handle, nodfs); |
Vinit Deshpande | 90b902d | 2014-10-13 13:21:47 -0700 | [diff] [blame] | 1399 | return result == WIFI_SUCCESS; |
| 1400 | } |
| 1401 | |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1402 | static jobject android_net_wifi_get_rtt_capabilities(JNIEnv *env, jclass cls, jint iface) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1403 | |
| 1404 | JNIHelper helper(env); |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1405 | wifi_rtt_capabilities rtt_capabilities; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1406 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | ec61e77 | 2015-03-30 18:39:12 -0700 | [diff] [blame] | 1407 | wifi_error ret = hal_fn.wifi_get_rtt_capabilities(handle, &rtt_capabilities); |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1408 | |
| 1409 | if(WIFI_SUCCESS == ret) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1410 | JNIObject<jobject> capabilities = helper.createObject( |
| 1411 | "android/net/wifi/RttManager$RttCapabilities"); |
| 1412 | helper.setBooleanField(capabilities, "oneSidedRttSupported", |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1413 | rtt_capabilities.rtt_one_sided_supported == 1); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1414 | helper.setBooleanField(capabilities, "twoSided11McRttSupported", |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1415 | rtt_capabilities.rtt_ftm_supported == 1); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1416 | helper.setBooleanField(capabilities, "lciSupported", |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1417 | rtt_capabilities.lci_support); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1418 | helper.setBooleanField(capabilities, "lcrSupported", |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1419 | rtt_capabilities.lcr_support); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1420 | helper.setIntField(capabilities, "preambleSupported", |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1421 | rtt_capabilities.preamble_support); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1422 | helper.setIntField(capabilities, "bwSupported", |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1423 | rtt_capabilities.bw_support); |
| 1424 | ALOGD("One side RTT is: %s", rtt_capabilities.rtt_one_sided_supported ==1 ? "support" : |
| 1425 | "not support"); |
| 1426 | ALOGD("Two side RTT is: %s", rtt_capabilities.rtt_ftm_supported == 1 ? "support" : |
| 1427 | "not support"); |
| 1428 | ALOGD("LCR is: %s", rtt_capabilities.lcr_support == 1 ? "support" : "not support"); |
| 1429 | |
| 1430 | ALOGD("LCI is: %s", rtt_capabilities.lci_support == 1 ? "support" : "not support"); |
| 1431 | |
| 1432 | ALOGD("Support Preamble is : %d support BW is %d", rtt_capabilities.preamble_support, |
| 1433 | rtt_capabilities.bw_support); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1434 | return capabilities.detach(); |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 1435 | } else { |
| 1436 | return NULL; |
| 1437 | } |
| 1438 | } |
| 1439 | |
xinhe | 939177f | 2015-03-23 14:43:03 -0700 | [diff] [blame] | 1440 | static jboolean android_net_wifi_set_Country_Code_Hal(JNIEnv *env,jclass cls, jint iface, |
| 1441 | jstring country_code) { |
| 1442 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1443 | JNIHelper helper(env); |
| 1444 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
| 1445 | |
| 1446 | ScopedUtfChars chars(env, country_code); |
| 1447 | const char *country = chars.c_str(); |
xinhe | 939177f | 2015-03-23 14:43:03 -0700 | [diff] [blame] | 1448 | |
| 1449 | ALOGD("set country code: %s", country); |
xinhe | 44787b5 | 2015-04-02 09:41:57 -0700 | [diff] [blame] | 1450 | wifi_error res = hal_fn.wifi_set_country_code(handle, country); |
xinhe | 939177f | 2015-03-23 14:43:03 -0700 | [diff] [blame] | 1451 | return res == WIFI_SUCCESS; |
| 1452 | } |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1453 | |
| 1454 | static jboolean android_net_wifi_enable_disable_tdls(JNIEnv *env,jclass cls, jint iface, |
| 1455 | jboolean enable, jstring addr) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1456 | |
| 1457 | JNIHelper helper(env); |
| 1458 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1459 | |
| 1460 | mac_addr address; |
| 1461 | parseMacAddress(env, addr, address); |
| 1462 | wifi_tdls_handler tdls_handler; |
| 1463 | //tdls_handler.on_tdls_state_changed = &on_tdls_state_changed; |
| 1464 | |
| 1465 | if(enable) { |
| 1466 | return (hal_fn.wifi_enable_tdls(handle, address, NULL, tdls_handler) == WIFI_SUCCESS); |
| 1467 | } else { |
| 1468 | return (hal_fn.wifi_disable_tdls(handle, address) == WIFI_SUCCESS); |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | static void on_tdls_state_changed(mac_addr addr, wifi_tdls_status status) { |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1473 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1474 | JNIHelper helper(mVM); |
| 1475 | |
| 1476 | ALOGD("on_tdls_state_changed is called: vm = %p, obj = %p", mVM, mCls); |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1477 | |
| 1478 | char mac[32]; |
| 1479 | sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], |
| 1480 | addr[5]); |
| 1481 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1482 | JNIObject<jstring> mac_address = helper.newStringUTF(mac); |
| 1483 | helper.reportEvent(mCls, "onTdlsStatus", "(Ljava/lang/StringII;)V", |
| 1484 | mac_address.get(), status.state, status.reason); |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1485 | |
| 1486 | } |
| 1487 | |
| 1488 | static jobject android_net_wifi_get_tdls_status(JNIEnv *env,jclass cls, jint iface,jstring addr) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1489 | |
| 1490 | JNIHelper helper(env); |
| 1491 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1492 | |
| 1493 | mac_addr address; |
| 1494 | parseMacAddress(env, addr, address); |
| 1495 | |
| 1496 | wifi_tdls_status status; |
| 1497 | |
| 1498 | wifi_error ret; |
| 1499 | ret = hal_fn.wifi_get_tdls_status(handle, address, &status ); |
| 1500 | |
| 1501 | if (ret != WIFI_SUCCESS) { |
| 1502 | return NULL; |
| 1503 | } else { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1504 | JNIObject<jobject> tdls_status = helper.createObject( |
| 1505 | "com/android/server/wifi/WifiNative$TdlsStatus"); |
| 1506 | helper.setIntField(tdls_status, "channel", status.channel); |
| 1507 | helper.setIntField(tdls_status, "global_operating_class", status.global_operating_class); |
| 1508 | helper.setIntField(tdls_status, "state", status.state); |
| 1509 | helper.setIntField(tdls_status, "reason", status.reason); |
| 1510 | return tdls_status.detach(); |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | static jobject android_net_wifi_get_tdls_capabilities(JNIEnv *env, jclass cls, jint iface) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1515 | |
| 1516 | JNIHelper helper(env); |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1517 | wifi_tdls_capabilities tdls_capabilities; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1518 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1519 | wifi_error ret = hal_fn.wifi_get_tdls_capabilities(handle, &tdls_capabilities); |
| 1520 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1521 | if (WIFI_SUCCESS == ret) { |
| 1522 | JNIObject<jobject> capabilities = helper.createObject( |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1523 | "com/android/server/wifi/WifiNative$TdlsCapabilities"); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1524 | helper.setIntField(capabilities, "maxConcurrentTdlsSessionNumber", |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1525 | tdls_capabilities.max_concurrent_tdls_session_num); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1526 | helper.setBooleanField(capabilities, "isGlobalTdlsSupported", |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1527 | tdls_capabilities.is_global_tdls_supported == 1); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1528 | helper.setBooleanField(capabilities, "isPerMacTdlsSupported", |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1529 | tdls_capabilities.is_per_mac_tdls_supported == 1); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1530 | helper.setBooleanField(capabilities, "isOffChannelTdlsSupported", |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1531 | tdls_capabilities.is_off_channel_tdls_supported); |
| 1532 | |
| 1533 | ALOGD("TDLS Max Concurrent Tdls Session Number is: %d", |
| 1534 | tdls_capabilities.max_concurrent_tdls_session_num); |
| 1535 | ALOGD("Global Tdls is: %s", tdls_capabilities.is_global_tdls_supported == 1 ? "support" : |
| 1536 | "not support"); |
| 1537 | ALOGD("Per Mac Tdls is: %s", tdls_capabilities.is_per_mac_tdls_supported == 1 ? "support" : |
| 1538 | "not support"); |
| 1539 | ALOGD("Off Channel Tdls is: %s", tdls_capabilities.is_off_channel_tdls_supported == 1 ? |
| 1540 | "support" : "not support"); |
| 1541 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1542 | return capabilities.detach(); |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 1543 | } else { |
| 1544 | return NULL; |
| 1545 | } |
| 1546 | } |
| 1547 | |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 1548 | // ---------------------------------------------------------------------------- |
Pierre Vandwalle | a0d34d3 | 2015-03-18 17:19:01 -0700 | [diff] [blame] | 1549 | // Debug framework |
| 1550 | // ---------------------------------------------------------------------------- |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1551 | static jint android_net_wifi_get_supported_logger_feature(JNIEnv *env, jclass cls, jint iface){ |
| 1552 | //Not implemented yet |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1553 | JNIHelper helper(env); |
| 1554 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1555 | return -1; |
| 1556 | } |
| 1557 | |
| 1558 | static jobject android_net_wifi_get_driver_version(JNIEnv *env, jclass cls, jint iface) { |
| 1559 | //Need to be fixed. The memory should be allocated from lower layer |
| 1560 | //char *buffer = NULL; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1561 | JNIHelper helper(env); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1562 | int buffer_length = 256; |
xinhe | 6d0cd10 | 2015-05-05 11:10:08 -0700 | [diff] [blame] | 1563 | char *buffer = (char *)malloc(buffer_length); |
| 1564 | if (!buffer) return NULL; |
| 1565 | memset(buffer, 0, buffer_length); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1566 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1567 | |
| 1568 | ALOGD("android_net_wifi_get_driver_version = %p", handle); |
Pierre Vandwalle | a0d34d3 | 2015-03-18 17:19:01 -0700 | [diff] [blame] | 1569 | |
| 1570 | if (handle == 0) { |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1571 | return NULL; |
Pierre Vandwalle | a0d34d3 | 2015-03-18 17:19:01 -0700 | [diff] [blame] | 1572 | } |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1573 | |
xinhe | 6d0cd10 | 2015-05-05 11:10:08 -0700 | [diff] [blame] | 1574 | wifi_error result = hal_fn.wifi_get_driver_version(handle, buffer, buffer_length); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1575 | |
| 1576 | if (result == WIFI_SUCCESS) { |
| 1577 | ALOGD("buffer is %p, length is %d", buffer, buffer_length); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1578 | JNIObject<jstring> driver_version = helper.newStringUTF(buffer); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1579 | free(buffer); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1580 | return driver_version.detach(); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1581 | } else { |
| 1582 | ALOGD("Fail to get driver version"); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1583 | free(buffer); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1584 | return NULL; |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | static jobject android_net_wifi_get_firmware_version(JNIEnv *env, jclass cls, jint iface) { |
| 1589 | |
| 1590 | //char *buffer = NULL; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1591 | JNIHelper helper(env); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1592 | int buffer_length = 256; |
| 1593 | char *buffer = (char *)malloc(buffer_length); |
xinhe | 6d0cd10 | 2015-05-05 11:10:08 -0700 | [diff] [blame] | 1594 | if (!buffer) return NULL; |
| 1595 | memset(buffer, 0, buffer_length); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1596 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1597 | |
| 1598 | ALOGD("android_net_wifi_get_firmware_version = %p", handle); |
| 1599 | |
| 1600 | if (handle == 0) { |
| 1601 | return NULL; |
| 1602 | } |
| 1603 | |
xinhe | 6d0cd10 | 2015-05-05 11:10:08 -0700 | [diff] [blame] | 1604 | wifi_error result = hal_fn.wifi_get_firmware_version(handle, buffer, buffer_length); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1605 | |
| 1606 | if (result == WIFI_SUCCESS) { |
| 1607 | ALOGD("buffer is %p, length is %d", buffer, buffer_length); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1608 | JNIObject<jstring> firmware_version = helper.newStringUTF(buffer); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1609 | free(buffer); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1610 | return firmware_version.detach(); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1611 | } else { |
| 1612 | ALOGD("Fail to get Firmware version"); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1613 | free(buffer); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1614 | return NULL; |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | static jobject android_net_wifi_get_ring_buffer_status (JNIEnv *env, jclass cls, jint iface) { |
| 1619 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1620 | JNIHelper helper(env); |
| 1621 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1622 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1623 | ALOGD("android_net_wifi_get_ring_buffer_status = %p", handle); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1624 | |
| 1625 | if (handle == 0) { |
| 1626 | return NULL; |
| 1627 | } |
| 1628 | |
| 1629 | //wifi_ring_buffer_status *status = NULL; |
| 1630 | u32 num_rings = 10; |
| 1631 | wifi_ring_buffer_status *status = |
| 1632 | (wifi_ring_buffer_status *)malloc(sizeof(wifi_ring_buffer_status) * num_rings); |
xinhe | 6d0cd10 | 2015-05-05 11:10:08 -0700 | [diff] [blame] | 1633 | if (!status) return NULL; |
| 1634 | memset(status, 0, sizeof(wifi_ring_buffer_status) * num_rings); |
| 1635 | wifi_error result = hal_fn.wifi_get_ring_buffers_status(handle, &num_rings, status); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1636 | if (result == WIFI_SUCCESS) { |
| 1637 | ALOGD("status is %p, number is %d", status, num_rings); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1638 | |
| 1639 | JNIObject<jobjectArray> ringBuffersStatus = helper.newObjectArray( |
| 1640 | num_rings, "com/android/server/wifi/WifiNative$RingBufferStatus", NULL); |
| 1641 | |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1642 | wifi_ring_buffer_status *tmp = status; |
| 1643 | |
| 1644 | for(u32 i = 0; i < num_rings; i++, tmp++) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1645 | |
| 1646 | JNIObject<jobject> ringStatus = helper.createObject( |
Vinit Deshpande | 0bf150b | 2015-06-01 14:13:04 -0700 | [diff] [blame] | 1647 | "com/android/server/wifi/WifiNative$RingBufferStatus"); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1648 | |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1649 | if (ringStatus == NULL) { |
| 1650 | ALOGE("Error in creating ringBufferStatus"); |
| 1651 | free(status); |
| 1652 | return NULL; |
| 1653 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1654 | |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1655 | char name[32]; |
| 1656 | for(int j = 0; j < 32; j++) { |
| 1657 | name[j] = tmp->name[j]; |
| 1658 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1659 | |
| 1660 | helper.setStringField(ringStatus, "name", name); |
| 1661 | helper.setIntField(ringStatus, "flag", tmp->flags); |
| 1662 | helper.setIntField(ringStatus, "ringBufferId", tmp->ring_id); |
| 1663 | helper.setIntField(ringStatus, "ringBufferByteSize", tmp->ring_buffer_byte_size); |
| 1664 | helper.setIntField(ringStatus, "verboseLevel", tmp->verbose_level); |
| 1665 | helper.setIntField(ringStatus, "writtenBytes", tmp->written_bytes); |
| 1666 | helper.setIntField(ringStatus, "readBytes", tmp->read_bytes); |
| 1667 | helper.setIntField(ringStatus, "writtenRecords", tmp->written_records); |
| 1668 | |
| 1669 | helper.setObjectArrayElement(ringBuffersStatus, i, ringStatus); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1670 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1671 | |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1672 | free(status); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1673 | return ringBuffersStatus.detach(); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1674 | } else { |
xinhe | 6d0cd10 | 2015-05-05 11:10:08 -0700 | [diff] [blame] | 1675 | free(status); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1676 | return NULL; |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | static void on_ring_buffer_data(char *ring_name, char *buffer, int buffer_size, |
| 1681 | wifi_ring_buffer_status *status) { |
Vinit Deshpande | 0bf150b | 2015-06-01 14:13:04 -0700 | [diff] [blame] | 1682 | |
Jerry Lee | 6111ff7 | 2015-05-11 15:10:03 -0700 | [diff] [blame] | 1683 | if (!ring_name || !buffer || !status || |
| 1684 | (unsigned int)buffer_size <= sizeof(wifi_ring_buffer_entry)) { |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1685 | ALOGE("Error input for on_ring_buffer_data!"); |
Vinit Deshpande | 0bf150b | 2015-06-01 14:13:04 -0700 | [diff] [blame] | 1686 | return; |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1687 | } |
Vinit Deshpande | 0bf150b | 2015-06-01 14:13:04 -0700 | [diff] [blame] | 1688 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1689 | |
| 1690 | JNIHelper helper(mVM); |
Vinit Deshpande | 6414301 | 2015-06-25 12:41:57 -0700 | [diff] [blame] | 1691 | /* ALOGD("on_ring_buffer_data called, vm = %p, obj = %p, env = %p buffer size = %d", mVM, |
| 1692 | mCls, env, buffer_size); */ |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1693 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1694 | JNIObject<jobject> ringStatus = helper.createObject( |
Vinit Deshpande | 0bf150b | 2015-06-01 14:13:04 -0700 | [diff] [blame] | 1695 | "com/android/server/wifi/WifiNative$RingBufferStatus"); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1696 | if (status == NULL) { |
| 1697 | ALOGE("Error in creating ringBufferStatus"); |
| 1698 | return; |
| 1699 | } |
| 1700 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1701 | helper.setStringField(ringStatus, "name", ring_name); |
| 1702 | helper.setIntField(ringStatus, "flag", status->flags); |
| 1703 | helper.setIntField(ringStatus, "ringBufferId", status->ring_id); |
| 1704 | helper.setIntField(ringStatus, "ringBufferByteSize", status->ring_buffer_byte_size); |
| 1705 | helper.setIntField(ringStatus, "verboseLevel", status->verbose_level); |
| 1706 | helper.setIntField(ringStatus, "writtenBytes", status->written_bytes); |
| 1707 | helper.setIntField(ringStatus, "readBytes", status->read_bytes); |
| 1708 | helper.setIntField(ringStatus, "writtenRecords", status->written_records); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1709 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1710 | JNIObject<jbyteArray> bytes = helper.newByteArray(buffer_size); |
| 1711 | helper.setByteArrayRegion(bytes, 0, buffer_size, (jbyte*)buffer); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1712 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1713 | helper.reportEvent(mCls,"onRingBufferData", |
| 1714 | "(Lcom/android/server/wifi/WifiNative$RingBufferStatus;[B)V", |
| 1715 | ringStatus.get(), bytes.get()); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | static void on_alert_data(wifi_request_id id, char *buffer, int buffer_size, int err_code){ |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1719 | |
| 1720 | JNIHelper helper(mVM); |
| 1721 | ALOGD("on_alert_data called, vm = %p, obj = %p, buffer_size = %d, error code = %d" |
| 1722 | , mVM, mCls, buffer_size, err_code); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1723 | |
| 1724 | if (buffer_size > 0) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1725 | JNIObject<jbyteArray> records = helper.newByteArray(buffer_size); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1726 | jbyte *bytes = (jbyte *) buffer; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1727 | helper.setByteArrayRegion(records, 0,buffer_size, bytes); |
| 1728 | helper.reportEvent(mCls,"onWifiAlert","([BI)V", records.get(), err_code); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1729 | } else { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1730 | helper.reportEvent(mCls,"onWifiAlert","([BI)V", NULL, err_code); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | |
Pierre Vandwalle | b0b0cc2 | 2015-05-06 13:57:06 -0700 | [diff] [blame] | 1734 | |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1735 | static jboolean android_net_wifi_start_logging_ring_buffer(JNIEnv *env, jclass cls, jint iface, |
| 1736 | jint verbose_level,jint flags, jint max_interval,jint min_data_size, jstring ring_name) { |
| 1737 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1738 | JNIHelper helper(env); |
| 1739 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1740 | |
| 1741 | ALOGD("android_net_wifi_start_logging_ring_buffer = %p", handle); |
| 1742 | |
| 1743 | if (handle == 0) { |
| 1744 | return false; |
| 1745 | } |
| 1746 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1747 | ScopedUtfChars chars(env, ring_name); |
| 1748 | const char* ring_name_const_char = chars.c_str(); |
| 1749 | int ret = hal_fn.wifi_start_logging(handle, verbose_level, |
| 1750 | flags, max_interval, min_data_size, const_cast<char *>(ring_name_const_char)); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1751 | |
| 1752 | if (ret != WIFI_SUCCESS) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1753 | ALOGE("Fail to start logging for ring %s", ring_name_const_char); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1754 | } else { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1755 | ALOGD("start logging for ring %s", ring_name_const_char); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1756 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1757 | |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1758 | return ret == WIFI_SUCCESS; |
| 1759 | } |
| 1760 | |
| 1761 | static jboolean android_net_wifi_get_ring_buffer_data(JNIEnv *env, jclass cls, jint iface, |
| 1762 | jstring ring_name) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1763 | |
| 1764 | JNIHelper helper(env); |
| 1765 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | 6414301 | 2015-06-25 12:41:57 -0700 | [diff] [blame] | 1766 | // ALOGD("android_net_wifi_get_ring_buffer_data = %p", handle); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1767 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1768 | ScopedUtfChars chars(env, ring_name); |
| 1769 | const char* ring_name_const_char = chars.c_str(); |
| 1770 | int result = hal_fn.wifi_get_ring_data(handle, const_cast<char *>(ring_name_const_char)); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1771 | return result == WIFI_SUCCESS; |
| 1772 | } |
| 1773 | |
| 1774 | |
| 1775 | void on_firmware_memory_dump(char *buffer, int buffer_size) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1776 | |
| 1777 | JNIHelper helper(mVM); |
Vinit Deshpande | 6414301 | 2015-06-25 12:41:57 -0700 | [diff] [blame] | 1778 | /* ALOGD("on_firmware_memory_dump called, vm = %p, obj = %p, env = %p buffer_size = %d" |
| 1779 | , mVM, mCls, env, buffer_size); */ |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1780 | |
| 1781 | if (buffer_size > 0) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1782 | JNIObject<jbyteArray> dump = helper.newByteArray(buffer_size); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1783 | jbyte *bytes = (jbyte *) (buffer); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1784 | helper.setByteArrayRegion(dump, 0, buffer_size, bytes); |
| 1785 | helper.reportEvent(mCls,"onWifiFwMemoryAvailable","([B)V", dump.get()); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1786 | } |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | static jboolean android_net_wifi_get_fw_memory_dump(JNIEnv *env, jclass cls, jint iface){ |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1790 | |
| 1791 | JNIHelper helper(env); |
| 1792 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Vinit Deshpande | 6414301 | 2015-06-25 12:41:57 -0700 | [diff] [blame] | 1793 | // ALOGD("android_net_wifi_get_fw_memory_dump = %p", handle); |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1794 | |
| 1795 | if (handle == NULL) { |
| 1796 | ALOGE("Can not get wifi_interface_handle"); |
| 1797 | return false; |
| 1798 | } |
| 1799 | |
| 1800 | wifi_firmware_memory_dump_handler fw_dump_handle; |
| 1801 | fw_dump_handle.on_firmware_memory_dump = on_firmware_memory_dump; |
| 1802 | int result = hal_fn.wifi_get_firmware_memory_dump(handle, fw_dump_handle); |
| 1803 | return result == WIFI_SUCCESS; |
| 1804 | |
Pierre Vandwalle | a0d34d3 | 2015-03-18 17:19:01 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
xinhe | b797893 | 2015-06-25 17:57:21 -0700 | [diff] [blame] | 1807 | static jboolean android_net_wifi_set_log_handler(JNIEnv *env, jclass cls, jint iface, jint id) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1808 | |
| 1809 | JNIHelper helper(env); |
| 1810 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
xinhe | b797893 | 2015-06-25 17:57:21 -0700 | [diff] [blame] | 1811 | ALOGD("android_net_wifi_set_log_handler = %p", handle); |
| 1812 | |
| 1813 | //initialize the handler on first time |
| 1814 | wifi_ring_buffer_data_handler handler; |
| 1815 | handler.on_ring_buffer_data = &on_ring_buffer_data; |
| 1816 | int result = hal_fn.wifi_set_log_handler(id, handle, handler); |
| 1817 | if (result != WIFI_SUCCESS) { |
| 1818 | ALOGE("Fail to set logging handler"); |
| 1819 | return false; |
| 1820 | } |
| 1821 | |
| 1822 | //set alter handler This will start alert too |
| 1823 | wifi_alert_handler alert_handler; |
| 1824 | alert_handler.on_alert = &on_alert_data; |
| 1825 | result = hal_fn.wifi_set_alert_handler(id, handle, alert_handler); |
| 1826 | if (result != WIFI_SUCCESS) { |
| 1827 | ALOGE(" Fail to set alert handler"); |
| 1828 | return false; |
| 1829 | } |
| 1830 | |
| 1831 | return true; |
| 1832 | } |
| 1833 | |
| 1834 | static jboolean android_net_wifi_reset_log_handler(JNIEnv *env, jclass cls, jint iface, jint id) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1835 | |
| 1836 | JNIHelper helper(env); |
| 1837 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Jerry Lee | 370ad50 | 2015-07-13 13:42:21 -0700 | [diff] [blame] | 1838 | |
| 1839 | //reset alter handler |
| 1840 | ALOGD("android_net_wifi_reset_alert_handler = %p", handle); |
| 1841 | int result = hal_fn.wifi_reset_alert_handler(id, handle); |
| 1842 | if (result != WIFI_SUCCESS) { |
| 1843 | ALOGE(" Fail to reset alert handler"); |
| 1844 | return false; |
| 1845 | } |
| 1846 | |
| 1847 | //reset log handler |
xinhe | b797893 | 2015-06-25 17:57:21 -0700 | [diff] [blame] | 1848 | ALOGD("android_net_wifi_reset_log_handler = %p", handle); |
Jerry Lee | 370ad50 | 2015-07-13 13:42:21 -0700 | [diff] [blame] | 1849 | result = hal_fn.wifi_reset_log_handler(id, handle); |
| 1850 | if (result != WIFI_SUCCESS) { |
| 1851 | ALOGE("Fail to reset logging handler"); |
| 1852 | return false; |
| 1853 | } |
| 1854 | |
| 1855 | return true; |
xinhe | b797893 | 2015-06-25 17:57:21 -0700 | [diff] [blame] | 1856 | } |
Jerry Lee | 370ad50 | 2015-07-13 13:42:21 -0700 | [diff] [blame] | 1857 | |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1858 | // ---------------------------------------------------------------------------- |
| 1859 | // ePno framework |
| 1860 | // ---------------------------------------------------------------------------- |
| 1861 | |
| 1862 | |
| 1863 | static void onPnoNetworkFound(wifi_request_id id, |
| 1864 | unsigned num_results, wifi_scan_result *results) { |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1865 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1866 | JNIHelper helper(mVM); |
| 1867 | |
| 1868 | ALOGD("onPnoNetworkFound called, vm = %p, obj = %p, num_results %u", mVM, mCls, num_results); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1869 | |
| 1870 | if (results == 0 || num_results == 0) { |
| 1871 | ALOGE("onPnoNetworkFound: Error no results"); |
| 1872 | return; |
| 1873 | } |
| 1874 | |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1875 | jbyte *bytes; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1876 | JNIObject<jobjectArray> scanResults(helper, NULL); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1877 | //jbyteArray elements; |
| 1878 | |
| 1879 | for (unsigned i=0; i<num_results; i++) { |
| 1880 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1881 | JNIObject<jobject> scanResult = createScanResult(helper, &results[i]); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1882 | if (i == 0) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1883 | scanResults = helper.newObjectArray( |
| 1884 | num_results, "android/net/wifi/ScanResult", scanResult); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1885 | if (scanResults == 0) { |
| 1886 | ALOGD("cant allocate array"); |
| 1887 | } else { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1888 | ALOGD("allocated array %u", helper.getArrayLength(scanResults)); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1889 | } |
| 1890 | } else { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1891 | helper.setObjectArrayElement(scanResults, i, scanResult); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 1894 | ALOGD("Scan result with ie length %d, i %u, <%s> rssi=%d %02x:%02x:%02x:%02x:%02x:%02x", |
xinhe | 6d0cd10 | 2015-05-05 11:10:08 -0700 | [diff] [blame] | 1895 | results->ie_length, i, results[i].ssid, results[i].rssi, results[i].bssid[0], |
| 1896 | results[i].bssid[1],results[i].bssid[2], results[i].bssid[3], results[i].bssid[4], |
| 1897 | results[i].bssid[5]); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1898 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1899 | /*elements = helper.newByteArray(results->ie_length); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1900 | if (elements == NULL) { |
| 1901 | ALOGE("Error in allocating array"); |
| 1902 | return; |
| 1903 | }*/ |
| 1904 | |
| 1905 | //ALOGD("onPnoNetworkFound: Setting byte array"); |
| 1906 | |
| 1907 | //bytes = (jbyte *)&(results->ie_data[0]); |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1908 | //helper.setByteArrayRegion(elements, 0, results->ie_length, bytes); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1909 | |
| 1910 | //ALOGD("onPnoNetworkFound: Returning result"); |
| 1911 | } |
| 1912 | |
| 1913 | |
| 1914 | ALOGD("calling report"); |
| 1915 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1916 | helper.reportEvent(mCls, "onPnoNetworkFound", "(I[Landroid/net/wifi/ScanResult;)V", id, |
| 1917 | scanResults.get()); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1918 | ALOGD("free ref"); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | static jboolean android_net_wifi_setPnoListNative( |
| 1922 | JNIEnv *env, jclass cls, jint iface, jint id, jobject list) { |
| 1923 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1924 | JNIHelper helper(env); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1925 | wifi_epno_handler handler; |
| 1926 | handler.on_network_found = &onPnoNetworkFound; |
| 1927 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1928 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1929 | ALOGD("configure ePno list request [%d] = %p", id, handle); |
| 1930 | |
| 1931 | if (list == NULL) { |
| 1932 | // stop pno |
| 1933 | int result = hal_fn.wifi_set_epno_list(id, handle, 0, NULL, handler); |
| 1934 | ALOGE(" setPnoListNative: STOP result = %d", result); |
Pierre Vandwalle | b0b0cc2 | 2015-05-06 13:57:06 -0700 | [diff] [blame] | 1935 | return result >= 0; |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | wifi_epno_network net_list[MAX_PNO_SSID]; |
| 1939 | memset(&net_list, 0, sizeof(net_list)); |
| 1940 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1941 | size_t len = helper.getArrayLength((jobjectArray)list); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1942 | if (len > (size_t)MAX_PNO_SSID) { |
| 1943 | return false; |
| 1944 | } |
| 1945 | |
| 1946 | for (unsigned int i = 0; i < len; i++) { |
| 1947 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1948 | JNIObject<jobject> pno_net = helper.getObjectArrayElement((jobjectArray)list, i); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1949 | if (pno_net == NULL) { |
| 1950 | ALOGD("setPnoListNative: could not get element %d", i); |
| 1951 | continue; |
| 1952 | } |
| 1953 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1954 | JNIObject<jstring> sssid = helper.getStringField(pno_net, "SSID"); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1955 | if (sssid == NULL) { |
| 1956 | ALOGE("Error setPnoListNative: getting ssid field"); |
| 1957 | return false; |
| 1958 | } |
| 1959 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1960 | ScopedUtfChars chars(env, (jstring)sssid.get()); |
| 1961 | const char *ssid = chars.c_str(); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1962 | if (ssid == NULL) { |
| 1963 | ALOGE("Error setPnoListNative: getting ssid"); |
| 1964 | return false; |
| 1965 | } |
| 1966 | int ssid_len = strnlen((const char*)ssid, 33); |
| 1967 | if (ssid_len > 32) { |
| 1968 | ALOGE("Error setPnoListNative: long ssid %u", strnlen((const char*)ssid, 256)); |
| 1969 | return false; |
| 1970 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1971 | |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1972 | if (ssid_len > 1 && ssid[0] == '"' && ssid[ssid_len-1]) |
| 1973 | { |
| 1974 | // strip leading and trailing '"' |
| 1975 | ssid++; |
| 1976 | ssid_len-=2; |
| 1977 | } |
| 1978 | if (ssid_len == 0) { |
| 1979 | ALOGE("Error setPnoListNative: zero length ssid, skip it"); |
| 1980 | continue; |
| 1981 | } |
| 1982 | memcpy(net_list[i].ssid, ssid, ssid_len); |
| 1983 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1984 | int rssit = helper.getIntField(pno_net, "rssi_threshold"); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1985 | net_list[i].rssi_threshold = (byte)rssit; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1986 | int a = helper.getIntField(pno_net, "auth"); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1987 | net_list[i].auth_bit_field = a; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 1988 | int f = helper.getIntField(pno_net, "flags"); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1989 | net_list[i].flags = f; |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1990 | ALOGE(" setPnoListNative: idx %u rssi %d/%d auth %x/%x flags %x/%x [%s]", i, |
Vinit Deshpande | e5bf4b8 | 2015-05-13 18:38:10 -0700 | [diff] [blame] | 1991 | (signed)net_list[i].rssi_threshold, net_list[i].rssi_threshold, |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 1992 | net_list[i].auth_bit_field, a, net_list[i].flags, f, net_list[i].ssid); |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | int result = hal_fn.wifi_set_epno_list(id, handle, len, net_list, handler); |
| 1996 | ALOGE(" setPnoListNative: result %d", result); |
| 1997 | |
| 1998 | return result >= 0; |
| 1999 | } |
Pierre Vandwalle | a0d34d3 | 2015-03-18 17:19:01 -0700 | [diff] [blame] | 2000 | |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 2001 | static jboolean android_net_wifi_setLazyRoam( |
| 2002 | JNIEnv *env, jclass cls, jint iface, jint id, jboolean enabled, jobject roam_param) { |
| 2003 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2004 | JNIHelper helper(env); |
Vinit Deshpande | f49a59b | 2015-05-27 11:24:47 -0700 | [diff] [blame] | 2005 | wifi_error status = WIFI_SUCCESS; |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 2006 | wifi_roam_params params; |
| 2007 | memset(¶ms, 0, sizeof(params)); |
| 2008 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2009 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 2010 | ALOGD("configure lazy roam request [%d] = %p", id, handle); |
| 2011 | |
| 2012 | if (roam_param != NULL) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2013 | params.A_band_boost_threshold = helper.getIntField(roam_param, "A_band_boost_threshold"); |
| 2014 | params.A_band_penalty_threshold = helper.getIntField(roam_param, "A_band_penalty_threshold"); |
| 2015 | params.A_band_boost_factor = helper.getIntField(roam_param, "A_band_boost_factor"); |
| 2016 | params.A_band_penalty_factor = helper.getIntField(roam_param, "A_band_penalty_factor"); |
| 2017 | params.A_band_max_boost = helper.getIntField(roam_param, "A_band_max_boost"); |
| 2018 | params.lazy_roam_hysteresis = helper.getIntField(roam_param, "lazy_roam_hysteresis"); |
| 2019 | params.alert_roam_rssi_trigger = helper.getIntField(roam_param, "alert_roam_rssi_trigger"); |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 2020 | status = hal_fn.wifi_set_gscan_roam_params(id, handle, ¶ms); |
| 2021 | } |
Pierre Vandwalle | b0b0cc2 | 2015-05-06 13:57:06 -0700 | [diff] [blame] | 2022 | ALOGE("android_net_wifi_setLazyRoam configured params status=%d\n", status); |
| 2023 | |
| 2024 | if (status >= 0) { |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 2025 | int doEnable = enabled ? 1 : 0; |
| 2026 | status = hal_fn.wifi_enable_lazy_roam(id, handle, doEnable); |
Pierre Vandwalle | b0b0cc2 | 2015-05-06 13:57:06 -0700 | [diff] [blame] | 2027 | ALOGE("android_net_wifi_setLazyRoam enabled roam status=%d\n", status); |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 2028 | } |
Pierre Vandwalle | b0b0cc2 | 2015-05-06 13:57:06 -0700 | [diff] [blame] | 2029 | return status >= 0; |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Pierre Vandwalle | 9ccffbb | 2015-05-15 16:34:17 -0700 | [diff] [blame] | 2032 | static jboolean android_net_wifi_setBssidBlacklist( |
| 2033 | JNIEnv *env, jclass cls, jint iface, jint id, jobject list) { |
| 2034 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2035 | JNIHelper helper(env); |
| 2036 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2037 | ALOGD("configure BSSID black list request [%d] = %p", id, handle); |
Pierre Vandwalle | 9ccffbb | 2015-05-15 16:34:17 -0700 | [diff] [blame] | 2038 | |
| 2039 | wifi_bssid_params params; |
| 2040 | memset(¶ms, 0, sizeof(params)); |
| 2041 | |
| 2042 | if (list != NULL) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2043 | size_t len = helper.getArrayLength((jobjectArray)list); |
Pierre Vandwalle | 9ccffbb | 2015-05-15 16:34:17 -0700 | [diff] [blame] | 2044 | if (len > (size_t)MAX_BLACKLIST_BSSID) { |
| 2045 | return false; |
| 2046 | } |
| 2047 | for (unsigned int i = 0; i < len; i++) { |
| 2048 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2049 | JNIObject<jobject> jbssid = helper.getObjectArrayElement(list, i); |
Pierre Vandwalle | 9ccffbb | 2015-05-15 16:34:17 -0700 | [diff] [blame] | 2050 | if (jbssid == NULL) { |
| 2051 | ALOGD("configure BSSID blacklist: could not get element %d", i); |
| 2052 | continue; |
| 2053 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2054 | |
| 2055 | ScopedUtfChars chars(env, (jstring)jbssid.get()); |
| 2056 | const char *bssid = chars.c_str(); |
Pierre Vandwalle | 9ccffbb | 2015-05-15 16:34:17 -0700 | [diff] [blame] | 2057 | if (bssid == NULL) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2058 | ALOGE("Error getting bssid"); |
| 2059 | return false; |
Pierre Vandwalle | 9ccffbb | 2015-05-15 16:34:17 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | mac_addr addr; |
| 2063 | parseMacAddress(bssid, addr); |
| 2064 | memcpy(params.bssids[i], addr, sizeof(mac_addr)); |
| 2065 | |
| 2066 | char bssidOut[32]; |
| 2067 | sprintf(bssidOut, "%0x:%0x:%0x:%0x:%0x:%0x", addr[0], addr[1], |
| 2068 | addr[2], addr[3], addr[4], addr[5]); |
| 2069 | |
| 2070 | ALOGD("BSSID blacklist: added bssid %s", bssidOut); |
| 2071 | |
| 2072 | params.num_bssid++; |
Pierre Vandwalle | 9ccffbb | 2015-05-15 16:34:17 -0700 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | ALOGD("Added %d bssids", params.num_bssid); |
| 2077 | return hal_fn.wifi_set_bssid_blacklist(id, handle, params) == WIFI_SUCCESS; |
| 2078 | } |
| 2079 | |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2080 | static jboolean android_net_wifi_setSsidWhitelist( |
| 2081 | JNIEnv *env, jclass cls, jint iface, jint id, jobject list) { |
| 2082 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2083 | JNIHelper helper(env); |
| 2084 | wifi_interface_handle handle = getIfaceHandle(helper, cls, iface); |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2085 | ALOGD("configure SSID white list request [%d] = %p", id, handle); |
| 2086 | wifi_ssid *ssids = NULL; |
| 2087 | int num_ssids = 0; |
| 2088 | if (list != NULL) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2089 | size_t len = helper.getArrayLength((jobjectArray)list); |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2090 | if (len > 0) { |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2091 | ssids = (wifi_ssid *)malloc(len * sizeof (wifi_ssid)); |
| 2092 | if (!ssids) return false; |
| 2093 | memset(ssids, 0, len * sizeof (wifi_ssid)); |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2094 | for (unsigned int i = 0; i < len; i++) { |
| 2095 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2096 | JNIObject<jobject> jssid = helper.getObjectArrayElement(list, i); |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2097 | if (jssid == NULL) { |
| 2098 | ALOGD("configure SSID whitelist: could not get element %d", i); |
| 2099 | free(ssids); |
| 2100 | return false; |
| 2101 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2102 | |
| 2103 | ScopedUtfChars chars(env, (jstring)jssid.get()); |
| 2104 | const char *utf = chars.c_str(); |
| 2105 | if (utf == NULL) { |
| 2106 | ALOGE("Error getting sssid"); |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2107 | free(ssids); |
| 2108 | return false; |
| 2109 | } |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2110 | |
| 2111 | int slen = strnlen(utf, 33); |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2112 | if (slen <= 0 || slen > 32) { |
| 2113 | ALOGE("Error wrong ssid length %d", slen); |
| 2114 | free(ssids); |
| 2115 | return false; |
| 2116 | } |
| 2117 | |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2118 | memcpy(ssids[i].ssid, utf, slen); |
Pierre Vandwalle | be2981a | 2015-05-20 18:20:45 -0700 | [diff] [blame] | 2119 | num_ssids++; |
Vinit Deshpande | 7d519b6 | 2015-08-04 16:43:09 -0700 | [diff] [blame] | 2120 | ALOGD("SSID white list: added ssid %s", utf); |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | ALOGD("android_net_wifi_setSsidWhitelist Added %d sssids", num_ssids); |
| 2126 | return hal_fn.wifi_set_ssid_white_list(id, handle, num_ssids, ssids) == WIFI_SUCCESS; |
| 2127 | } |
| 2128 | |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 2129 | // ---------------------------------------------------------------------------- |
| 2130 | |
| 2131 | /* |
| 2132 | * JNI registration. |
| 2133 | */ |
| 2134 | static JNINativeMethod gWifiMethods[] = { |
| 2135 | /* name, signature, funcPtr */ |
| 2136 | |
| 2137 | { "loadDriver", "()Z", (void *)android_net_wifi_loadDriver }, |
| 2138 | { "isDriverLoaded", "()Z", (void *)android_net_wifi_isDriverLoaded }, |
| 2139 | { "unloadDriver", "()Z", (void *)android_net_wifi_unloadDriver }, |
| 2140 | { "startSupplicant", "(Z)Z", (void *)android_net_wifi_startSupplicant }, |
| 2141 | { "killSupplicant", "(Z)Z", (void *)android_net_wifi_killSupplicant }, |
| 2142 | { "connectToSupplicantNative", "()Z", (void *)android_net_wifi_connectToSupplicant }, |
| 2143 | { "closeSupplicantConnectionNative", "()V", |
| 2144 | (void *)android_net_wifi_closeSupplicantConnection }, |
| 2145 | { "waitForEventNative", "()Ljava/lang/String;", (void*)android_net_wifi_waitForEvent }, |
| 2146 | { "doBooleanCommandNative", "(Ljava/lang/String;)Z", (void*)android_net_wifi_doBooleanCommand }, |
| 2147 | { "doIntCommandNative", "(Ljava/lang/String;)I", (void*)android_net_wifi_doIntCommand }, |
| 2148 | { "doStringCommandNative", "(Ljava/lang/String;)Ljava/lang/String;", |
| 2149 | (void*) android_net_wifi_doStringCommand }, |
Vinit Deshapnde | 7ef73dd | 2014-02-28 08:42:14 -0800 | [diff] [blame] | 2150 | { "startHalNative", "()Z", (void*) android_net_wifi_startHal }, |
| 2151 | { "stopHalNative", "()V", (void*) android_net_wifi_stopHal }, |
| 2152 | { "waitForHalEventNative", "()V", (void*) android_net_wifi_waitForHalEvents }, |
Vinit Deshapnde | 7f9a15d | 2014-05-07 16:29:44 -0700 | [diff] [blame] | 2153 | { "getInterfacesNative", "()I", (void*) android_net_wifi_getInterfaces}, |
| 2154 | { "getInterfaceNameNative", "(I)Ljava/lang/String;", (void*) android_net_wifi_getInterfaceName}, |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 2155 | { "getScanCapabilitiesNative", "(ILcom/android/server/wifi/WifiNative$ScanCapabilities;)Z", |
| 2156 | (void *) android_net_wifi_getScanCapabilities}, |
| 2157 | { "startScanNative", "(IILcom/android/server/wifi/WifiNative$ScanSettings;)Z", |
| 2158 | (void*) android_net_wifi_startScan}, |
| 2159 | { "stopScanNative", "(II)Z", (void*) android_net_wifi_stopScan}, |
Vinit Deshpande | c591ab3 | 2014-10-31 11:15:26 -0700 | [diff] [blame] | 2160 | { "getScanResultsNative", "(IZ)[Landroid/net/wifi/WifiScanner$ScanData;", |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 2161 | (void *) android_net_wifi_getScanResults}, |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 2162 | { "setHotlistNative", "(IILandroid/net/wifi/WifiScanner$HotlistSettings;)Z", |
| 2163 | (void*) android_net_wifi_setHotlist}, |
| 2164 | { "resetHotlistNative", "(II)Z", (void*) android_net_wifi_resetHotlist}, |
Vinit Deshapnde | e4e3750 | 2014-05-05 11:32:21 -0700 | [diff] [blame] | 2165 | { "trackSignificantWifiChangeNative", "(IILandroid/net/wifi/WifiScanner$WifiChangeSettings;)Z", |
| 2166 | (void*) android_net_wifi_trackSignificantWifiChange}, |
| 2167 | { "untrackSignificantWifiChangeNative", "(II)Z", |
vandwalle | aabe7a9 | 2014-05-09 18:11:02 -0700 | [diff] [blame] | 2168 | (void*) android_net_wifi_untrackSignificantWifiChange}, |
| 2169 | { "getWifiLinkLayerStatsNative", "(I)Landroid/net/wifi/WifiLinkLayerStats;", |
Vinit Deshpande | a632d8a | 2014-07-01 14:12:13 -0700 | [diff] [blame] | 2170 | (void*) android_net_wifi_getLinkLayerStats}, |
Pierre Vandwalle | d745a52 | 2015-06-11 17:48:58 -0700 | [diff] [blame] | 2171 | { "setWifiLinkLayerStatsNative", "(II)V", |
| 2172 | (void*) android_net_wifi_setLinkLayerStats}, |
Vinit Deshpande | c35361d | 2014-08-07 16:24:10 -0700 | [diff] [blame] | 2173 | { "getSupportedFeatureSetNative", "(I)I", |
Vinit Deshpande | 1436573 | 2014-06-30 15:23:23 -0700 | [diff] [blame] | 2174 | (void*) android_net_wifi_getSupportedFeatures}, |
| 2175 | { "requestRangeNative", "(II[Landroid/net/wifi/RttManager$RttParams;)Z", |
| 2176 | (void*) android_net_wifi_requestRange}, |
| 2177 | { "cancelRangeRequestNative", "(II[Landroid/net/wifi/RttManager$RttParams;)Z", |
Vinit Deshpande | 042c54b | 2014-08-21 13:52:21 -0700 | [diff] [blame] | 2178 | (void*) android_net_wifi_cancelRange}, |
Vinit Deshpande | 90b902d | 2014-10-13 13:21:47 -0700 | [diff] [blame] | 2179 | { "setScanningMacOuiNative", "(I[B)Z", (void*) android_net_wifi_setScanningMacOui}, |
| 2180 | { "getChannelsForBandNative", "(II)[I", (void*) android_net_wifi_getValidChannels}, |
xinhe | b830d76 | 2015-02-11 17:14:17 -0800 | [diff] [blame] | 2181 | { "setDfsFlagNative", "(IZ)Z", (void*) android_net_wifi_setDfsFlag}, |
xinhe | 12cf388 | 2015-03-12 18:38:54 -0700 | [diff] [blame] | 2182 | { "toggleInterfaceNative", "(I)Z", (void*) android_net_wifi_toggle_interface}, |
| 2183 | { "getRttCapabilitiesNative", "(I)Landroid/net/wifi/RttManager$RttCapabilities;", |
Pierre Vandwalle | a0d34d3 | 2015-03-18 17:19:01 -0700 | [diff] [blame] | 2184 | (void*) android_net_wifi_get_rtt_capabilities}, |
xinhe | 939177f | 2015-03-23 14:43:03 -0700 | [diff] [blame] | 2185 | {"setCountryCodeHalNative", "(ILjava/lang/String;)Z", |
Pierre Vandwalle | dd490cf | 2015-03-20 18:43:31 -0700 | [diff] [blame] | 2186 | (void*) android_net_wifi_set_Country_Code_Hal}, |
| 2187 | { "setPnoListNative", "(II[Lcom/android/server/wifi/WifiNative$WifiPnoNetwork;)Z", |
xinhe | d57f630 | 2015-04-15 13:23:43 -0700 | [diff] [blame] | 2188 | (void*) android_net_wifi_setPnoListNative}, |
| 2189 | {"enableDisableTdlsNative", "(IZLjava/lang/String;)Z", |
| 2190 | (void*) android_net_wifi_enable_disable_tdls}, |
| 2191 | {"getTdlsStatusNative", "(ILjava/lang/String;)Lcom/android/server/wifi/WifiNative$TdlsStatus;", |
| 2192 | (void*) android_net_wifi_get_tdls_status}, |
| 2193 | {"getTdlsCapabilitiesNative", "(I)Lcom/android/server/wifi/WifiNative$TdlsCapabilities;", |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 2194 | (void*) android_net_wifi_get_tdls_capabilities}, |
| 2195 | {"getSupportedLoggerFeatureSetNative","(I)I", |
| 2196 | (void*) android_net_wifi_get_supported_logger_feature}, |
| 2197 | {"getDriverVersionNative", "(I)Ljava/lang/String;", |
| 2198 | (void*) android_net_wifi_get_driver_version}, |
| 2199 | {"getFirmwareVersionNative", "(I)Ljava/lang/String;", |
| 2200 | (void*) android_net_wifi_get_firmware_version}, |
Vinit Deshpande | 0bf150b | 2015-06-01 14:13:04 -0700 | [diff] [blame] | 2201 | {"getRingBufferStatusNative", "(I)[Lcom/android/server/wifi/WifiNative$RingBufferStatus;", |
xinhe | 03ba4a5 | 2015-04-28 14:40:44 -0700 | [diff] [blame] | 2202 | (void*) android_net_wifi_get_ring_buffer_status}, |
| 2203 | {"startLoggingRingBufferNative", "(IIIIILjava/lang/String;)Z", |
| 2204 | (void*) android_net_wifi_start_logging_ring_buffer}, |
| 2205 | {"getRingBufferDataNative", "(ILjava/lang/String;)Z", |
| 2206 | (void*) android_net_wifi_get_ring_buffer_data}, |
Pierre Vandwalle | d4c25fd | 2015-04-17 13:50:41 -0700 | [diff] [blame] | 2207 | {"getFwMemoryDumpNative","(I)Z", (void*) android_net_wifi_get_fw_memory_dump}, |
Pierre Vandwalle | 9ccffbb | 2015-05-15 16:34:17 -0700 | [diff] [blame] | 2208 | { "setLazyRoamNative", "(IIZLcom/android/server/wifi/WifiNative$WifiLazyRoamParams;)Z", |
| 2209 | (void*) android_net_wifi_setLazyRoam}, |
| 2210 | { "setBssidBlacklistNative", "(II[Ljava/lang/String;)Z", |
Pierre Vandwalle | 5caa43b | 2015-05-15 17:42:46 -0700 | [diff] [blame] | 2211 | (void*)android_net_wifi_setBssidBlacklist}, |
| 2212 | { "setSsidWhitelistNative", "(II[Ljava/lang/String;)Z", |
xinhe | ee0a013 | 2015-08-04 14:27:27 -0700 | [diff] [blame] | 2213 | (void*)android_net_wifi_setSsidWhitelist}, |
xinhe | b797893 | 2015-06-25 17:57:21 -0700 | [diff] [blame] | 2214 | {"setLoggingEventHandlerNative", "(II)Z", (void *) android_net_wifi_set_log_handler}, |
xinhe | ee0a013 | 2015-08-04 14:27:27 -0700 | [diff] [blame] | 2215 | {"resetLogHandlerNative", "(II)Z", (void *) android_net_wifi_reset_log_handler}, |
| 2216 | {"isGetChannelsForBandSupportedNative", "()Z", |
| 2217 | (void*)android_net_wifi_is_get_channels_for_band_supported} |
Vinit Deshpande | 155b9d0 | 2014-01-08 23:46:46 +0000 | [diff] [blame] | 2218 | }; |
| 2219 | |
| 2220 | int register_android_net_wifi_WifiNative(JNIEnv* env) { |
| 2221 | return AndroidRuntime::registerNativeMethods(env, |
| 2222 | "com/android/server/wifi/WifiNative", gWifiMethods, NELEM(gWifiMethods)); |
| 2223 | } |
| 2224 | |
| 2225 | |
| 2226 | /* User to register native functions */ |
| 2227 | extern "C" |
| 2228 | jint Java_com_android_server_wifi_WifiNative_registerNatives(JNIEnv* env, jclass clazz) { |
| 2229 | return AndroidRuntime::registerNativeMethods(env, |
| 2230 | "com/android/server/wifi/WifiNative", gWifiMethods, NELEM(gWifiMethods)); |
| 2231 | } |
| 2232 | |
| 2233 | }; // namespace android |